@withbuddi/buddi 0.1.0-pre.29 → 0.1.0-pre.30

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 (455) hide show
  1. package/extension/manifest.json +2 -2
  2. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  3. package/node_modules/@buddi/cli/dist/args.d.ts +6 -1
  4. package/node_modules/@buddi/cli/dist/args.d.ts.map +1 -1
  5. package/node_modules/@buddi/cli/dist/args.js +7 -2
  6. package/node_modules/@buddi/cli/dist/args.js.map +1 -1
  7. package/node_modules/@buddi/cli/dist/commands.d.ts.map +1 -1
  8. package/node_modules/@buddi/cli/dist/commands.js +13 -3
  9. package/node_modules/@buddi/cli/dist/commands.js.map +1 -1
  10. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  11. package/node_modules/@buddi/cli/dist/doctor-probes.js +2 -1
  12. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  13. package/node_modules/@buddi/cli/dist/jobs-cmd.d.ts +4 -0
  14. package/node_modules/@buddi/cli/dist/jobs-cmd.d.ts.map +1 -1
  15. package/node_modules/@buddi/cli/dist/jobs-cmd.js +53 -4
  16. package/node_modules/@buddi/cli/dist/jobs-cmd.js.map +1 -1
  17. package/node_modules/@buddi/cli/dist/main.d.ts.map +1 -1
  18. package/node_modules/@buddi/cli/dist/main.js +5 -1
  19. package/node_modules/@buddi/cli/dist/main.js.map +1 -1
  20. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  21. package/node_modules/@buddi/core/dist/lock.d.ts +8 -2
  22. package/node_modules/@buddi/core/dist/lock.d.ts.map +1 -1
  23. package/node_modules/@buddi/core/dist/lock.js +20 -5
  24. package/node_modules/@buddi/core/dist/lock.js.map +1 -1
  25. package/node_modules/@buddi/core/dist/pages.d.ts +3 -1
  26. package/node_modules/@buddi/core/dist/pages.d.ts.map +1 -1
  27. package/node_modules/@buddi/core/dist/pages.js +6 -1
  28. package/node_modules/@buddi/core/dist/pages.js.map +1 -1
  29. package/node_modules/@buddi/core/dist/plugin/index.d.ts +1 -1
  30. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  31. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  32. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  33. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  34. package/node_modules/@buddi/core/dist/queue/failures.d.ts +84 -0
  35. package/node_modules/@buddi/core/dist/queue/failures.d.ts.map +1 -0
  36. package/node_modules/@buddi/core/dist/queue/failures.js +195 -0
  37. package/node_modules/@buddi/core/dist/queue/failures.js.map +1 -0
  38. package/node_modules/@buddi/core/dist/queue/index.d.ts +1 -0
  39. package/node_modules/@buddi/core/dist/queue/index.d.ts.map +1 -1
  40. package/node_modules/@buddi/core/dist/queue/index.js +1 -0
  41. package/node_modules/@buddi/core/dist/queue/index.js.map +1 -1
  42. package/node_modules/@buddi/core/dist/queue/jobs.d.ts +39 -3
  43. package/node_modules/@buddi/core/dist/queue/jobs.d.ts.map +1 -1
  44. package/node_modules/@buddi/core/dist/queue/jobs.js +54 -4
  45. package/node_modules/@buddi/core/dist/queue/jobs.js.map +1 -1
  46. package/node_modules/@buddi/core/dist/queue/types.d.ts +20 -0
  47. package/node_modules/@buddi/core/dist/queue/types.d.ts.map +1 -1
  48. package/node_modules/@buddi/core/dist/queue/types.js +17 -0
  49. package/node_modules/@buddi/core/dist/queue/types.js.map +1 -1
  50. package/node_modules/@buddi/core/dist/secrets/settings.d.ts.map +1 -1
  51. package/node_modules/@buddi/core/dist/secrets/settings.js +23 -3
  52. package/node_modules/@buddi/core/dist/secrets/settings.js.map +1 -1
  53. package/node_modules/@buddi/core/dist/sentinels/digest.d.ts +8 -1
  54. package/node_modules/@buddi/core/dist/sentinels/digest.d.ts.map +1 -1
  55. package/node_modules/@buddi/core/dist/sentinels/digest.js +10 -3
  56. package/node_modules/@buddi/core/dist/sentinels/digest.js.map +1 -1
  57. package/node_modules/@buddi/core/dist/sentinels/index.d.ts +1 -0
  58. package/node_modules/@buddi/core/dist/sentinels/index.d.ts.map +1 -1
  59. package/node_modules/@buddi/core/dist/sentinels/index.js +1 -0
  60. package/node_modules/@buddi/core/dist/sentinels/index.js.map +1 -1
  61. package/node_modules/@buddi/core/dist/sentinels/mutes.d.ts +51 -0
  62. package/node_modules/@buddi/core/dist/sentinels/mutes.d.ts.map +1 -0
  63. package/node_modules/@buddi/core/dist/sentinels/mutes.js +86 -0
  64. package/node_modules/@buddi/core/dist/sentinels/mutes.js.map +1 -0
  65. package/node_modules/@buddi/core/dist/sentinels/run.d.ts +14 -4
  66. package/node_modules/@buddi/core/dist/sentinels/run.d.ts.map +1 -1
  67. package/node_modules/@buddi/core/dist/sentinels/run.js +64 -20
  68. package/node_modules/@buddi/core/dist/sentinels/run.js.map +1 -1
  69. package/node_modules/@buddi/core/dist/sentinels/types.d.ts +152 -2
  70. package/node_modules/@buddi/core/dist/sentinels/types.d.ts.map +1 -1
  71. package/node_modules/@buddi/core/dist/sentinels/types.js +126 -2
  72. package/node_modules/@buddi/core/dist/sentinels/types.js.map +1 -1
  73. package/node_modules/@buddi/core/dist/views.d.ts +112 -112
  74. package/node_modules/@buddi/core/dist/views.d.ts.map +1 -1
  75. package/node_modules/@buddi/core/dist/views.js +2 -0
  76. package/node_modules/@buddi/core/dist/views.js.map +1 -1
  77. package/node_modules/@buddi/core/migrations/066_alert_decisions.sql +45 -0
  78. package/node_modules/@buddi/core/migrations/067_job_acknowledged.sql +21 -0
  79. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  80. package/node_modules/@buddi/gateway/dist/chat/conversations.d.ts.map +1 -1
  81. package/node_modules/@buddi/gateway/dist/chat/conversations.js +8 -2
  82. package/node_modules/@buddi/gateway/dist/chat/conversations.js.map +1 -1
  83. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  84. package/node_modules/@buddi/gateway/dist/missions/execute.js +36 -2
  85. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  86. package/node_modules/@buddi/gateway/dist/missions/goals.d.ts +12 -1
  87. package/node_modules/@buddi/gateway/dist/missions/goals.d.ts.map +1 -1
  88. package/node_modules/@buddi/gateway/dist/missions/goals.js +21 -1
  89. package/node_modules/@buddi/gateway/dist/missions/goals.js.map +1 -1
  90. package/node_modules/@buddi/gateway/dist/missions/sentinel-wake.d.ts +3 -0
  91. package/node_modules/@buddi/gateway/dist/missions/sentinel-wake.d.ts.map +1 -1
  92. package/node_modules/@buddi/gateway/dist/missions/sentinel-wake.js +4 -1
  93. package/node_modules/@buddi/gateway/dist/missions/sentinel-wake.js.map +1 -1
  94. package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.d.ts +17 -0
  95. package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.d.ts.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.js +27 -0
  97. package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.js.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/web/alerts.d.ts +179 -0
  99. package/node_modules/@buddi/gateway/dist/web/alerts.d.ts.map +1 -0
  100. package/node_modules/@buddi/gateway/dist/web/alerts.js +363 -0
  101. package/node_modules/@buddi/gateway/dist/web/alerts.js.map +1 -0
  102. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  103. package/node_modules/@buddi/gateway/dist/web/api-routes.js +45 -6
  104. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  105. package/node_modules/@buddi/gateway/dist/web/chat.d.ts +1 -0
  106. package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
  107. package/node_modules/@buddi/gateway/dist/web/chat.js +4 -3
  108. package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
  109. package/node_modules/@buddi/gateway/dist/web/lock.d.ts +7 -4
  110. package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
  111. package/node_modules/@buddi/gateway/dist/web/lock.js +20 -14
  112. package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
  113. package/node_modules/@buddi/gateway/dist/web/plugins.d.ts.map +1 -1
  114. package/node_modules/@buddi/gateway/dist/web/plugins.js +17 -3
  115. package/node_modules/@buddi/gateway/dist/web/plugins.js.map +1 -1
  116. package/node_modules/@buddi/gateway/dist/web/read.d.ts +52 -26
  117. package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
  118. package/node_modules/@buddi/gateway/dist/web/read.js +52 -36
  119. package/node_modules/@buddi/gateway/dist/web/read.js.map +1 -1
  120. package/node_modules/@buddi/gateway/dist/web/secrets.d.ts +61 -1
  121. package/node_modules/@buddi/gateway/dist/web/secrets.d.ts.map +1 -1
  122. package/node_modules/@buddi/gateway/dist/web/secrets.js +111 -3
  123. package/node_modules/@buddi/gateway/dist/web/secrets.js.map +1 -1
  124. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  125. package/node_modules/@buddi/gateway/dist/web/server.js +125 -9
  126. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  127. package/node_modules/@buddi/gateway/dist/web/widgets.d.ts +1 -0
  128. package/node_modules/@buddi/gateway/dist/web/widgets.d.ts.map +1 -1
  129. package/node_modules/@buddi/gateway/dist/web/widgets.js +6 -1
  130. package/node_modules/@buddi/gateway/dist/web/widgets.js.map +1 -1
  131. package/node_modules/@buddi/gateway/dist/web/write.d.ts +23 -0
  132. package/node_modules/@buddi/gateway/dist/web/write.d.ts.map +1 -1
  133. package/node_modules/@buddi/gateway/dist/web/write.js +46 -1
  134. package/node_modules/@buddi/gateway/dist/web/write.js.map +1 -1
  135. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  136. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  137. package/node_modules/@buddi/runtime/dist/anthropic.d.ts +6 -0
  138. package/node_modules/@buddi/runtime/dist/anthropic.d.ts.map +1 -1
  139. package/node_modules/@buddi/runtime/dist/anthropic.js.map +1 -1
  140. package/node_modules/@buddi/runtime/dist/openai.d.ts +34 -1
  141. package/node_modules/@buddi/runtime/dist/openai.d.ts.map +1 -1
  142. package/node_modules/@buddi/runtime/dist/openai.js +66 -12
  143. package/node_modules/@buddi/runtime/dist/openai.js.map +1 -1
  144. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  145. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  146. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  147. package/node_modules/@buddi/tool-email/dist/agent.js +1 -1
  148. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.d.ts +8 -0
  149. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.d.ts.map +1 -1
  150. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.js +59 -4
  151. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.js.map +1 -1
  152. package/node_modules/@buddi/tool-email/dist/mail.d.ts +42 -0
  153. package/node_modules/@buddi/tool-email/dist/mail.d.ts.map +1 -1
  154. package/node_modules/@buddi/tool-email/dist/mail.js +116 -0
  155. package/node_modules/@buddi/tool-email/dist/mail.js.map +1 -1
  156. package/node_modules/@buddi/tool-email/dist/mailbox/select.d.ts +6 -0
  157. package/node_modules/@buddi/tool-email/dist/mailbox/select.d.ts.map +1 -1
  158. package/node_modules/@buddi/tool-email/dist/mailbox/select.js +11 -0
  159. package/node_modules/@buddi/tool-email/dist/mailbox/select.js.map +1 -1
  160. package/node_modules/@buddi/tool-email/dist/metrics.d.ts +5 -6
  161. package/node_modules/@buddi/tool-email/dist/metrics.d.ts.map +1 -1
  162. package/node_modules/@buddi/tool-email/dist/metrics.js +4 -5
  163. package/node_modules/@buddi/tool-email/dist/metrics.js.map +1 -1
  164. package/node_modules/@buddi/tool-email/dist/needs-you.d.ts +58 -0
  165. package/node_modules/@buddi/tool-email/dist/needs-you.d.ts.map +1 -0
  166. package/node_modules/@buddi/tool-email/dist/needs-you.js +97 -0
  167. package/node_modules/@buddi/tool-email/dist/needs-you.js.map +1 -0
  168. package/node_modules/@buddi/tool-email/dist/pages/descriptors.d.ts.map +1 -1
  169. package/node_modules/@buddi/tool-email/dist/pages/descriptors.js +110 -78
  170. package/node_modules/@buddi/tool-email/dist/pages/descriptors.js.map +1 -1
  171. package/node_modules/@buddi/tool-email/dist/pages/drafts-tools.d.ts +2 -2
  172. package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts +7 -0
  173. package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts.map +1 -1
  174. package/node_modules/@buddi/tool-email/dist/pages/queries.js +31 -3
  175. package/node_modules/@buddi/tool-email/dist/pages/queries.js.map +1 -1
  176. package/node_modules/@buddi/tool-email/dist/ports.d.ts +8 -0
  177. package/node_modules/@buddi/tool-email/dist/ports.d.ts.map +1 -1
  178. package/node_modules/@buddi/tool-email/dist/ports.js.map +1 -1
  179. package/node_modules/@buddi/tool-email/dist/sentinels/suspicious-sender.d.ts.map +1 -1
  180. package/node_modules/@buddi/tool-email/dist/sentinels/suspicious-sender.js +4 -1
  181. package/node_modules/@buddi/tool-email/dist/sentinels/suspicious-sender.js.map +1 -1
  182. package/node_modules/@buddi/tool-email/dist/sentinels/waiting-on-me.d.ts +18 -21
  183. package/node_modules/@buddi/tool-email/dist/sentinels/waiting-on-me.d.ts.map +1 -1
  184. package/node_modules/@buddi/tool-email/dist/sentinels/waiting-on-me.js +39 -63
  185. package/node_modules/@buddi/tool-email/dist/sentinels/waiting-on-me.js.map +1 -1
  186. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.d.ts.map +1 -1
  187. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js +3 -2
  188. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js.map +1 -1
  189. package/node_modules/@buddi/tool-email/dist/suspicions-store.d.ts +6 -0
  190. package/node_modules/@buddi/tool-email/dist/suspicions-store.d.ts.map +1 -1
  191. package/node_modules/@buddi/tool-email/dist/suspicions-store.js +16 -1
  192. package/node_modules/@buddi/tool-email/dist/suspicions-store.js.map +1 -1
  193. package/node_modules/@buddi/tool-email/dist/threads.d.ts +17 -2
  194. package/node_modules/@buddi/tool-email/dist/threads.d.ts.map +1 -1
  195. package/node_modules/@buddi/tool-email/dist/threads.js +35 -14
  196. package/node_modules/@buddi/tool-email/dist/threads.js.map +1 -1
  197. package/node_modules/@buddi/tool-email/dist/tools/mailbox.d.ts +3 -0
  198. package/node_modules/@buddi/tool-email/dist/tools/mailbox.d.ts.map +1 -1
  199. package/node_modules/@buddi/tool-email/dist/tools/mailbox.js +5 -0
  200. package/node_modules/@buddi/tool-email/dist/tools/mailbox.js.map +1 -1
  201. package/node_modules/@buddi/tool-email/dist/tools/threads.d.ts +7 -3
  202. package/node_modules/@buddi/tool-email/dist/tools/threads.d.ts.map +1 -1
  203. package/node_modules/@buddi/tool-email/dist/tools/threads.js +18 -5
  204. package/node_modules/@buddi/tool-email/dist/tools/threads.js.map +1 -1
  205. package/node_modules/@buddi/tool-email/dist/watchers.d.ts +91 -7
  206. package/node_modules/@buddi/tool-email/dist/watchers.d.ts.map +1 -1
  207. package/node_modules/@buddi/tool-email/dist/watchers.js +164 -1
  208. package/node_modules/@buddi/tool-email/dist/watchers.js.map +1 -1
  209. package/node_modules/@buddi/tool-email/dist/widgets.d.ts +3 -2
  210. package/node_modules/@buddi/tool-email/dist/widgets.d.ts.map +1 -1
  211. package/node_modules/@buddi/tool-email/dist/widgets.js +2 -2
  212. package/node_modules/@buddi/tool-email/dist/widgets.js.map +1 -1
  213. package/node_modules/@buddi/tool-email/migrations/023_attention.sql +100 -0
  214. package/node_modules/@buddi/tool-email/migrations/024_auth_domain.sql +9 -0
  215. package/node_modules/@buddi/tool-email/migrations/025_thread_ignore.sql +77 -0
  216. package/node_modules/@buddi/tool-email/package.json +1 -1
  217. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  218. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  219. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  220. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  221. package/node_modules/ip-address/README.md +34 -34
  222. package/node_modules/ip-address/dist/ipv4.js +7 -0
  223. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  224. package/node_modules/ip-address/package.json +1 -1
  225. package/package.json +2 -2
  226. package/packages/cli/dist/.tsbuildinfo +1 -1
  227. package/packages/cli/dist/args.d.ts +6 -1
  228. package/packages/cli/dist/args.d.ts.map +1 -1
  229. package/packages/cli/dist/args.js +7 -2
  230. package/packages/cli/dist/args.js.map +1 -1
  231. package/packages/cli/dist/commands.d.ts.map +1 -1
  232. package/packages/cli/dist/commands.js +13 -3
  233. package/packages/cli/dist/commands.js.map +1 -1
  234. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  235. package/packages/cli/dist/doctor-probes.js +2 -1
  236. package/packages/cli/dist/doctor-probes.js.map +1 -1
  237. package/packages/cli/dist/jobs-cmd.d.ts +4 -0
  238. package/packages/cli/dist/jobs-cmd.d.ts.map +1 -1
  239. package/packages/cli/dist/jobs-cmd.js +53 -4
  240. package/packages/cli/dist/jobs-cmd.js.map +1 -1
  241. package/packages/cli/dist/main.d.ts.map +1 -1
  242. package/packages/cli/dist/main.js +5 -1
  243. package/packages/cli/dist/main.js.map +1 -1
  244. package/packages/core/dist/.tsbuildinfo +1 -1
  245. package/packages/core/dist/lock.d.ts +8 -2
  246. package/packages/core/dist/lock.d.ts.map +1 -1
  247. package/packages/core/dist/lock.js +20 -5
  248. package/packages/core/dist/lock.js.map +1 -1
  249. package/packages/core/dist/pages.d.ts +3 -1
  250. package/packages/core/dist/pages.d.ts.map +1 -1
  251. package/packages/core/dist/pages.js +6 -1
  252. package/packages/core/dist/pages.js.map +1 -1
  253. package/packages/core/dist/plugin/index.d.ts +1 -1
  254. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  255. package/packages/core/dist/plugin/index.js.map +1 -1
  256. package/packages/core/dist/plugin/version.d.ts +1 -1
  257. package/packages/core/dist/plugin/version.js +1 -1
  258. package/packages/core/dist/queue/failures.d.ts +84 -0
  259. package/packages/core/dist/queue/failures.d.ts.map +1 -0
  260. package/packages/core/dist/queue/failures.js +195 -0
  261. package/packages/core/dist/queue/failures.js.map +1 -0
  262. package/packages/core/dist/queue/index.d.ts +1 -0
  263. package/packages/core/dist/queue/index.d.ts.map +1 -1
  264. package/packages/core/dist/queue/index.js +1 -0
  265. package/packages/core/dist/queue/index.js.map +1 -1
  266. package/packages/core/dist/queue/jobs.d.ts +39 -3
  267. package/packages/core/dist/queue/jobs.d.ts.map +1 -1
  268. package/packages/core/dist/queue/jobs.js +54 -4
  269. package/packages/core/dist/queue/jobs.js.map +1 -1
  270. package/packages/core/dist/queue/types.d.ts +20 -0
  271. package/packages/core/dist/queue/types.d.ts.map +1 -1
  272. package/packages/core/dist/queue/types.js +17 -0
  273. package/packages/core/dist/queue/types.js.map +1 -1
  274. package/packages/core/dist/secrets/settings.d.ts.map +1 -1
  275. package/packages/core/dist/secrets/settings.js +23 -3
  276. package/packages/core/dist/secrets/settings.js.map +1 -1
  277. package/packages/core/dist/sentinels/digest.d.ts +8 -1
  278. package/packages/core/dist/sentinels/digest.d.ts.map +1 -1
  279. package/packages/core/dist/sentinels/digest.js +10 -3
  280. package/packages/core/dist/sentinels/digest.js.map +1 -1
  281. package/packages/core/dist/sentinels/index.d.ts +1 -0
  282. package/packages/core/dist/sentinels/index.d.ts.map +1 -1
  283. package/packages/core/dist/sentinels/index.js +1 -0
  284. package/packages/core/dist/sentinels/index.js.map +1 -1
  285. package/packages/core/dist/sentinels/mutes.d.ts +51 -0
  286. package/packages/core/dist/sentinels/mutes.d.ts.map +1 -0
  287. package/packages/core/dist/sentinels/mutes.js +86 -0
  288. package/packages/core/dist/sentinels/mutes.js.map +1 -0
  289. package/packages/core/dist/sentinels/run.d.ts +14 -4
  290. package/packages/core/dist/sentinels/run.d.ts.map +1 -1
  291. package/packages/core/dist/sentinels/run.js +64 -20
  292. package/packages/core/dist/sentinels/run.js.map +1 -1
  293. package/packages/core/dist/sentinels/types.d.ts +152 -2
  294. package/packages/core/dist/sentinels/types.d.ts.map +1 -1
  295. package/packages/core/dist/sentinels/types.js +126 -2
  296. package/packages/core/dist/sentinels/types.js.map +1 -1
  297. package/packages/core/dist/views.d.ts +112 -112
  298. package/packages/core/dist/views.d.ts.map +1 -1
  299. package/packages/core/dist/views.js +2 -0
  300. package/packages/core/dist/views.js.map +1 -1
  301. package/packages/core/migrations/066_alert_decisions.sql +45 -0
  302. package/packages/core/migrations/067_job_acknowledged.sql +21 -0
  303. package/packages/gateway/dist/.tsbuildinfo +1 -1
  304. package/packages/gateway/dist/chat/conversations.d.ts.map +1 -1
  305. package/packages/gateway/dist/chat/conversations.js +8 -2
  306. package/packages/gateway/dist/chat/conversations.js.map +1 -1
  307. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  308. package/packages/gateway/dist/missions/execute.js +36 -2
  309. package/packages/gateway/dist/missions/execute.js.map +1 -1
  310. package/packages/gateway/dist/missions/goals.d.ts +12 -1
  311. package/packages/gateway/dist/missions/goals.d.ts.map +1 -1
  312. package/packages/gateway/dist/missions/goals.js +21 -1
  313. package/packages/gateway/dist/missions/goals.js.map +1 -1
  314. package/packages/gateway/dist/missions/sentinel-wake.d.ts +3 -0
  315. package/packages/gateway/dist/missions/sentinel-wake.d.ts.map +1 -1
  316. package/packages/gateway/dist/missions/sentinel-wake.js +4 -1
  317. package/packages/gateway/dist/missions/sentinel-wake.js.map +1 -1
  318. package/packages/gateway/dist/surfaces/offered-actions.d.ts +17 -0
  319. package/packages/gateway/dist/surfaces/offered-actions.d.ts.map +1 -1
  320. package/packages/gateway/dist/surfaces/offered-actions.js +27 -0
  321. package/packages/gateway/dist/surfaces/offered-actions.js.map +1 -1
  322. package/packages/gateway/dist/web/alerts.d.ts +179 -0
  323. package/packages/gateway/dist/web/alerts.d.ts.map +1 -0
  324. package/packages/gateway/dist/web/alerts.js +363 -0
  325. package/packages/gateway/dist/web/alerts.js.map +1 -0
  326. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  327. package/packages/gateway/dist/web/api-routes.js +45 -6
  328. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  329. package/packages/gateway/dist/web/chat.d.ts +1 -0
  330. package/packages/gateway/dist/web/chat.d.ts.map +1 -1
  331. package/packages/gateway/dist/web/chat.js +4 -3
  332. package/packages/gateway/dist/web/chat.js.map +1 -1
  333. package/packages/gateway/dist/web/lock.d.ts +7 -4
  334. package/packages/gateway/dist/web/lock.d.ts.map +1 -1
  335. package/packages/gateway/dist/web/lock.js +20 -14
  336. package/packages/gateway/dist/web/lock.js.map +1 -1
  337. package/packages/gateway/dist/web/plugins.d.ts.map +1 -1
  338. package/packages/gateway/dist/web/plugins.js +17 -3
  339. package/packages/gateway/dist/web/plugins.js.map +1 -1
  340. package/packages/gateway/dist/web/read.d.ts +52 -26
  341. package/packages/gateway/dist/web/read.d.ts.map +1 -1
  342. package/packages/gateway/dist/web/read.js +52 -36
  343. package/packages/gateway/dist/web/read.js.map +1 -1
  344. package/packages/gateway/dist/web/secrets.d.ts +61 -1
  345. package/packages/gateway/dist/web/secrets.d.ts.map +1 -1
  346. package/packages/gateway/dist/web/secrets.js +111 -3
  347. package/packages/gateway/dist/web/secrets.js.map +1 -1
  348. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  349. package/packages/gateway/dist/web/server.js +125 -9
  350. package/packages/gateway/dist/web/server.js.map +1 -1
  351. package/packages/gateway/dist/web/widgets.d.ts +1 -0
  352. package/packages/gateway/dist/web/widgets.d.ts.map +1 -1
  353. package/packages/gateway/dist/web/widgets.js +6 -1
  354. package/packages/gateway/dist/web/widgets.js.map +1 -1
  355. package/packages/gateway/dist/web/write.d.ts +23 -0
  356. package/packages/gateway/dist/web/write.d.ts.map +1 -1
  357. package/packages/gateway/dist/web/write.js +46 -1
  358. package/packages/gateway/dist/web/write.js.map +1 -1
  359. package/packages/install/dist/.tsbuildinfo +1 -1
  360. package/packages/runtime/dist/.tsbuildinfo +1 -1
  361. package/packages/runtime/dist/anthropic.d.ts +6 -0
  362. package/packages/runtime/dist/anthropic.d.ts.map +1 -1
  363. package/packages/runtime/dist/anthropic.js.map +1 -1
  364. package/packages/runtime/dist/openai.d.ts +34 -1
  365. package/packages/runtime/dist/openai.d.ts.map +1 -1
  366. package/packages/runtime/dist/openai.js +66 -12
  367. package/packages/runtime/dist/openai.js.map +1 -1
  368. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  369. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  370. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  371. package/packages/tools/email/dist/agent.js +1 -1
  372. package/packages/tools/email/dist/imap/imapflow-client.d.ts +8 -0
  373. package/packages/tools/email/dist/imap/imapflow-client.d.ts.map +1 -1
  374. package/packages/tools/email/dist/imap/imapflow-client.js +59 -4
  375. package/packages/tools/email/dist/imap/imapflow-client.js.map +1 -1
  376. package/packages/tools/email/dist/mail.d.ts +42 -0
  377. package/packages/tools/email/dist/mail.d.ts.map +1 -1
  378. package/packages/tools/email/dist/mail.js +116 -0
  379. package/packages/tools/email/dist/mail.js.map +1 -1
  380. package/packages/tools/email/dist/mailbox/select.d.ts +6 -0
  381. package/packages/tools/email/dist/mailbox/select.d.ts.map +1 -1
  382. package/packages/tools/email/dist/mailbox/select.js +11 -0
  383. package/packages/tools/email/dist/mailbox/select.js.map +1 -1
  384. package/packages/tools/email/dist/metrics.d.ts +5 -6
  385. package/packages/tools/email/dist/metrics.d.ts.map +1 -1
  386. package/packages/tools/email/dist/metrics.js +4 -5
  387. package/packages/tools/email/dist/metrics.js.map +1 -1
  388. package/packages/tools/email/dist/needs-you.d.ts +58 -0
  389. package/packages/tools/email/dist/needs-you.d.ts.map +1 -0
  390. package/packages/tools/email/dist/needs-you.js +97 -0
  391. package/packages/tools/email/dist/needs-you.js.map +1 -0
  392. package/packages/tools/email/dist/pages/descriptors.d.ts.map +1 -1
  393. package/packages/tools/email/dist/pages/descriptors.js +110 -78
  394. package/packages/tools/email/dist/pages/descriptors.js.map +1 -1
  395. package/packages/tools/email/dist/pages/drafts-tools.d.ts +2 -2
  396. package/packages/tools/email/dist/pages/queries.d.ts +7 -0
  397. package/packages/tools/email/dist/pages/queries.d.ts.map +1 -1
  398. package/packages/tools/email/dist/pages/queries.js +31 -3
  399. package/packages/tools/email/dist/pages/queries.js.map +1 -1
  400. package/packages/tools/email/dist/ports.d.ts +8 -0
  401. package/packages/tools/email/dist/ports.d.ts.map +1 -1
  402. package/packages/tools/email/dist/ports.js.map +1 -1
  403. package/packages/tools/email/dist/sentinels/suspicious-sender.d.ts.map +1 -1
  404. package/packages/tools/email/dist/sentinels/suspicious-sender.js +4 -1
  405. package/packages/tools/email/dist/sentinels/suspicious-sender.js.map +1 -1
  406. package/packages/tools/email/dist/sentinels/waiting-on-me.d.ts +18 -21
  407. package/packages/tools/email/dist/sentinels/waiting-on-me.d.ts.map +1 -1
  408. package/packages/tools/email/dist/sentinels/waiting-on-me.js +39 -63
  409. package/packages/tools/email/dist/sentinels/waiting-on-me.js.map +1 -1
  410. package/packages/tools/email/dist/sources/inbox-poll.d.ts.map +1 -1
  411. package/packages/tools/email/dist/sources/inbox-poll.js +3 -2
  412. package/packages/tools/email/dist/sources/inbox-poll.js.map +1 -1
  413. package/packages/tools/email/dist/suspicions-store.d.ts +6 -0
  414. package/packages/tools/email/dist/suspicions-store.d.ts.map +1 -1
  415. package/packages/tools/email/dist/suspicions-store.js +16 -1
  416. package/packages/tools/email/dist/suspicions-store.js.map +1 -1
  417. package/packages/tools/email/dist/threads.d.ts +17 -2
  418. package/packages/tools/email/dist/threads.d.ts.map +1 -1
  419. package/packages/tools/email/dist/threads.js +35 -14
  420. package/packages/tools/email/dist/threads.js.map +1 -1
  421. package/packages/tools/email/dist/tools/mailbox.d.ts +3 -0
  422. package/packages/tools/email/dist/tools/mailbox.d.ts.map +1 -1
  423. package/packages/tools/email/dist/tools/mailbox.js +5 -0
  424. package/packages/tools/email/dist/tools/mailbox.js.map +1 -1
  425. package/packages/tools/email/dist/tools/threads.d.ts +7 -3
  426. package/packages/tools/email/dist/tools/threads.d.ts.map +1 -1
  427. package/packages/tools/email/dist/tools/threads.js +18 -5
  428. package/packages/tools/email/dist/tools/threads.js.map +1 -1
  429. package/packages/tools/email/dist/watchers.d.ts +91 -7
  430. package/packages/tools/email/dist/watchers.d.ts.map +1 -1
  431. package/packages/tools/email/dist/watchers.js +164 -1
  432. package/packages/tools/email/dist/watchers.js.map +1 -1
  433. package/packages/tools/email/dist/widgets.d.ts +3 -2
  434. package/packages/tools/email/dist/widgets.d.ts.map +1 -1
  435. package/packages/tools/email/dist/widgets.js +2 -2
  436. package/packages/tools/email/dist/widgets.js.map +1 -1
  437. package/packages/tools/email/migrations/023_attention.sql +100 -0
  438. package/packages/tools/email/migrations/024_auth_domain.sql +9 -0
  439. package/packages/tools/email/migrations/025_thread_ignore.sql +77 -0
  440. package/packages/tools/email/package.json +1 -1
  441. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  442. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  443. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  444. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  445. package/packages/web/dist/assets/earth-2560-Ce3xs8Cb.webp +0 -0
  446. package/packages/web/dist/assets/earth-phone-BqC7cDhk.webp +0 -0
  447. package/packages/web/dist/assets/index-WS4UjGsy.js +129 -0
  448. package/packages/web/dist/assets/index-Zrt_o2UG.css +1 -0
  449. package/packages/web/dist/assets/{lottie_light-Cdn77Osu.js → lottie_light-Ls7i1ATS.js} +1 -1
  450. package/packages/web/dist/build.json +1 -1
  451. package/packages/web/dist/index.html +2 -2
  452. package/packages/web/dist/precache.json +4 -4
  453. package/packages/web/dist/sw.js +3 -2
  454. package/packages/web/dist/assets/index-D8_tmf2k.js +0 -131
  455. package/packages/web/dist/assets/index-DYQyioa6.css +0 -1
@@ -1,131 +0,0 @@
1
- var ew=e=>{throw TypeError(e)};var tw=(e,t,s)=>t.has(e)||ew("Cannot "+s);var hn=(e,t,s)=>(tw(e,t,"read from private field"),s?s.call(e):t.get(e)),nw=(e,t,s)=>t.has(e)?ew("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),_h=(e,t,s,r)=>(tw(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function LR(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 fY=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function _R(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Bk={exports:{}},Id={},Wk={exports:{}},Qe={};/**
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 Zo=Symbol.for("react.element"),FR=Symbol.for("react.portal"),zR=Symbol.for("react.fragment"),UR=Symbol.for("react.strict_mode"),BR=Symbol.for("react.profiler"),WR=Symbol.for("react.provider"),HR=Symbol.for("react.context"),KR=Symbol.for("react.forward_ref"),VR=Symbol.for("react.suspense"),GR=Symbol.for("react.memo"),YR=Symbol.for("react.lazy"),sw=Symbol.iterator;function qR(e){return e===null||typeof e!="object"?null:(e=sw&&e[sw]||e["@@iterator"],typeof e=="function"?e:null)}var Hk={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Kk=Object.assign,Vk={};function ol(e,t,s){this.props=e,this.context=t,this.refs=Vk,this.updater=s||Hk}ol.prototype.isReactComponent={};ol.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")};ol.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Gk(){}Gk.prototype=ol.prototype;function _g(e,t,s){this.props=e,this.context=t,this.refs=Vk,this.updater=s||Hk}var Fg=_g.prototype=new Gk;Fg.constructor=_g;Kk(Fg,ol.prototype);Fg.isPureReactComponent=!0;var rw=Array.isArray,Yk=Object.prototype.hasOwnProperty,zg={current:null},qk={key:!0,ref:!0,__self:!0,__source:!0};function Qk(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)Yk.call(t,r)&&!qk.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:Zo,type:e,key:a,ref:l,props:i,_owner:zg.current}}function QR(e,t){return{$$typeof:Zo,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Ug(e){return typeof e=="object"&&e!==null&&e.$$typeof===Zo}function XR(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var iw=/\/+/g;function Fh(e,t){return typeof e=="object"&&e!==null&&e.key!=null?XR(""+e.key):t.toString(36)}function mu(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 Zo:case FR:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+Fh(l,0):r,rw(i)?(s="",e!=null&&(s=e.replace(iw,"$&/")+"/"),mu(i,t,s,"",function(u){return u})):i!=null&&(Ug(i)&&(i=QR(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(iw,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",rw(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+Fh(a,o);l+=mu(a,t,s,c,i)}else if(c=qR(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+Fh(a,o++),l+=mu(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 Cc(e,t,s){if(e==null)return e;var r=[],i=0;return mu(e,r,"","",function(a){return t.call(s,a,i++)}),r}function JR(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 Cn={current:null},pu={transition:null},ZR={ReactCurrentDispatcher:Cn,ReactCurrentBatchConfig:pu,ReactCurrentOwner:zg};function Xk(){throw Error("act(...) is not supported in production builds of React.")}Qe.Children={map:Cc,forEach:function(e,t,s){Cc(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return Cc(e,function(){t++}),t},toArray:function(e){return Cc(e,function(t){return t})||[]},only:function(e){if(!Ug(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};Qe.Component=ol;Qe.Fragment=zR;Qe.Profiler=BR;Qe.PureComponent=_g;Qe.StrictMode=UR;Qe.Suspense=VR;Qe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=ZR;Qe.act=Xk;Qe.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=Kk({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=zg.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)Yk.call(t,c)&&!qk.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:Zo,type:e.type,key:i,ref:a,props:r,_owner:l}};Qe.createContext=function(e){return e={$$typeof:HR,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:WR,_context:e},e.Consumer=e};Qe.createElement=Qk;Qe.createFactory=function(e){var t=Qk.bind(null,e);return t.type=e,t};Qe.createRef=function(){return{current:null}};Qe.forwardRef=function(e){return{$$typeof:KR,render:e}};Qe.isValidElement=Ug;Qe.lazy=function(e){return{$$typeof:YR,_payload:{_status:-1,_result:e},_init:JR}};Qe.memo=function(e,t){return{$$typeof:GR,type:e,compare:t===void 0?null:t}};Qe.startTransition=function(e){var t=pu.transition;pu.transition={};try{e()}finally{pu.transition=t}};Qe.unstable_act=Xk;Qe.useCallback=function(e,t){return Cn.current.useCallback(e,t)};Qe.useContext=function(e){return Cn.current.useContext(e)};Qe.useDebugValue=function(){};Qe.useDeferredValue=function(e){return Cn.current.useDeferredValue(e)};Qe.useEffect=function(e,t){return Cn.current.useEffect(e,t)};Qe.useId=function(){return Cn.current.useId()};Qe.useImperativeHandle=function(e,t,s){return Cn.current.useImperativeHandle(e,t,s)};Qe.useInsertionEffect=function(e,t){return Cn.current.useInsertionEffect(e,t)};Qe.useLayoutEffect=function(e,t){return Cn.current.useLayoutEffect(e,t)};Qe.useMemo=function(e,t){return Cn.current.useMemo(e,t)};Qe.useReducer=function(e,t,s){return Cn.current.useReducer(e,t,s)};Qe.useRef=function(e){return Cn.current.useRef(e)};Qe.useState=function(e){return Cn.current.useState(e)};Qe.useSyncExternalStore=function(e,t,s){return Cn.current.useSyncExternalStore(e,t,s)};Qe.useTransition=function(){return Cn.current.useTransition()};Qe.version="18.3.1";Wk.exports=Qe;var d=Wk.exports;const e$=_R(d),cl=LR({__proto__:null,default:e$},[d]);/**
10
- * @license React
11
- * react-jsx-runtime.production.min.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var t$=d,n$=Symbol.for("react.element"),s$=Symbol.for("react.fragment"),r$=Object.prototype.hasOwnProperty,i$=t$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a$={key:!0,ref:!0,__self:!0,__source:!0};function Jk(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)r$.call(t,r)&&!a$.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:n$,type:e,key:a,ref:l,props:i,_owner:i$.current}}Id.Fragment=s$;Id.jsx=Jk;Id.jsxs=Jk;Bk.exports=Id;var n=Bk.exports,Zk={exports:{}},Jn={},e0={exports:{}},t0={};/**
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(L,W){var O=L.length;L.push(W);e:for(;0<O;){var V=O-1>>>1,X=L[V];if(0<i(X,W))L[V]=W,L[O]=X,O=V;else break e}}function s(L){return L.length===0?null:L[0]}function r(L){if(L.length===0)return null;var W=L[0],O=L.pop();if(O!==W){L[0]=O;e:for(var V=0,X=L.length,G=X>>>1;V<G;){var Z=2*(V+1)-1,z=L[Z],q=Z+1,Q=L[q];if(0>i(z,O))q<X&&0>i(Q,z)?(L[V]=Q,L[q]=O,V=q):(L[V]=z,L[Z]=O,V=Z);else if(q<X&&0>i(Q,O))L[V]=Q,L[q]=O,V=q;else break e}}return W}function i(L,W){var O=L.sortIndex-W.sortIndex;return O!==0?O:L.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,f=null,m=3,p=!1,g=!1,v=!1,b=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,x=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(L){for(var W=s(u);W!==null;){if(W.callback===null)r(u);else if(W.startTime<=L)r(u),W.sortIndex=W.expirationTime,t(c,W);else break;W=s(u)}}function y(L){if(v=!1,w(L),!g)if(s(c)!==null)g=!0,P(k);else{var W=s(u);W!==null&&U(y,W.startTime-L)}}function k(L,W){g=!1,v&&(v=!1,j(C),C=-1),p=!0;var O=m;try{for(w(W),f=s(c);f!==null&&(!(f.expirationTime>W)||L&&!I());){var V=f.callback;if(typeof V=="function"){f.callback=null,m=f.priorityLevel;var X=V(f.expirationTime<=W);W=e.unstable_now(),typeof X=="function"?f.callback=X:f===s(c)&&r(c),w(W)}else r(c);f=s(c)}if(f!==null)var G=!0;else{var Z=s(u);Z!==null&&U(y,Z.startTime-W),G=!1}return G}finally{f=null,m=O,p=!1}}var N=!1,S=null,C=-1,$=5,R=-1;function I(){return!(e.unstable_now()-R<$)}function F(){if(S!==null){var L=e.unstable_now();R=L;var W=!0;try{W=S(!0,L)}finally{W?_():(N=!1,S=null)}}else N=!1}var _;if(typeof x=="function")_=function(){x(F)};else if(typeof MessageChannel<"u"){var E=new MessageChannel,M=E.port2;E.port1.onmessage=F,_=function(){M.postMessage(null)}}else _=function(){b(F,0)};function P(L){S=L,N||(N=!0,_())}function U(L,W){C=b(function(){L(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(L){L.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,P(k))},e.unstable_forceFrameRate=function(L){0>L||125<L?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<L?Math.floor(1e3/L):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(L){switch(m){case 1:case 2:case 3:var W=3;break;default:W=m}var O=m;m=W;try{return L()}finally{m=O}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(L,W){switch(L){case 1:case 2:case 3:case 4:case 5:break;default:L=3}var O=m;m=L;try{return W()}finally{m=O}},e.unstable_scheduleCallback=function(L,W,O){var V=e.unstable_now();switch(typeof O=="object"&&O!==null?(O=O.delay,O=typeof O=="number"&&0<O?V+O:V):O=V,L){case 1:var X=-1;break;case 2:X=250;break;case 5:X=1073741823;break;case 4:X=1e4;break;default:X=5e3}return X=O+X,L={id:h++,callback:W,priorityLevel:L,startTime:O,expirationTime:X,sortIndex:-1},O>V?(L.sortIndex=O,t(u,L),s(c)===null&&L===s(u)&&(v?(j(C),C=-1):v=!0,U(y,O-V))):(L.sortIndex=X,t(c,L),g||p||(g=!0,P(k))),L},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(L){var W=m;return function(){var O=m;m=W;try{return L.apply(this,arguments)}finally{m=O}}}})(t0);e0.exports=t0;var l$=e0.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 o$=d,Qn=l$;function fe(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 n0=new Set,po={};function ea(e,t){Ka(e,t),Ka(e+"Capture",t)}function Ka(e,t){for(po[e]=t,e=0;e<t.length;e++)n0.add(t[e])}var Er=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),fm=Object.prototype.hasOwnProperty,c$=/^[: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]*$/,aw={},lw={};function u$(e){return fm.call(lw,e)?!0:fm.call(aw,e)?!1:c$.test(e)?lw[e]=!0:(aw[e]=!0,!1)}function d$(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 h$(e,t,s,r){if(t===null||typeof t>"u"||d$(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 En(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 on={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){on[e]=new En(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];on[t]=new En(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){on[e]=new En(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){on[e]=new En(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){on[e]=new En(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){on[e]=new En(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){on[e]=new En(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){on[e]=new En(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){on[e]=new En(e,5,!1,e.toLowerCase(),null,!1,!1)});var Bg=/[\-:]([a-z])/g;function Wg(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(Bg,Wg);on[t]=new En(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(Bg,Wg);on[t]=new En(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(Bg,Wg);on[t]=new En(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){on[e]=new En(e,1,!1,e.toLowerCase(),null,!1,!1)});on.xlinkHref=new En("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){on[e]=new En(e,1,!1,e.toLowerCase(),null,!0,!0)});function Hg(e,t,s,r){var i=on.hasOwnProperty(t)?on[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(h$(t,s,i,r)&&(s=null),r||i===null?u$(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 Or=o$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Ec=Symbol.for("react.element"),wa=Symbol.for("react.portal"),ya=Symbol.for("react.fragment"),Kg=Symbol.for("react.strict_mode"),mm=Symbol.for("react.profiler"),s0=Symbol.for("react.provider"),r0=Symbol.for("react.context"),Vg=Symbol.for("react.forward_ref"),pm=Symbol.for("react.suspense"),gm=Symbol.for("react.suspense_list"),Gg=Symbol.for("react.memo"),Br=Symbol.for("react.lazy"),i0=Symbol.for("react.offscreen"),ow=Symbol.iterator;function Pl(e){return e===null||typeof e!="object"?null:(e=ow&&e[ow]||e["@@iterator"],typeof e=="function"?e:null)}var It=Object.assign,zh;function Yl(e){if(zh===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);zh=t&&t[1]||""}return`
34
- `+zh+e}var Uh=!1;function Bh(e,t){if(!e||Uh)return"";Uh=!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{Uh=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Yl(e):""}function f$(e){switch(e.tag){case 5:return Yl(e.type);case 16:return Yl("Lazy");case 13:return Yl("Suspense");case 19:return Yl("SuspenseList");case 0:case 2:case 15:return e=Bh(e.type,!1),e;case 11:return e=Bh(e.type.render,!1),e;case 1:return e=Bh(e.type,!0),e;default:return""}}function xm(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 ya:return"Fragment";case wa:return"Portal";case mm:return"Profiler";case Kg:return"StrictMode";case pm:return"Suspense";case gm:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case r0:return(e.displayName||"Context")+".Consumer";case s0:return(e._context.displayName||"Context")+".Provider";case Vg:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Gg:return t=e.displayName||null,t!==null?t:xm(e.type)||"Memo";case Br:t=e._payload,e=e._init;try{return xm(e(t))}catch{}}return null}function m$(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 xm(t);case 8:return t===Kg?"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 li(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function a0(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function p$(e){var t=a0(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 Ac(e){e._valueTracker||(e._valueTracker=p$(e))}function l0(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=a0(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function zu(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 vm(e,t){var s=t.checked;return It({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function cw(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=li(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 o0(e,t){t=t.checked,t!=null&&Hg(e,"checked",t,!1)}function jm(e,t){o0(e,t);var s=li(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")?wm(e,t.type,s):t.hasOwnProperty("defaultValue")&&wm(e,t.type,li(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function uw(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 wm(e,t,s){(t!=="number"||zu(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var ql=Array.isArray;function Pa(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=""+li(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 ym(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(fe(91));return It({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function dw(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(fe(92));if(ql(s)){if(1<s.length)throw Error(fe(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:li(s)}}function c0(e,t){var s=li(t.value),r=li(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 hw(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function u0(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 bm(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?u0(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Tc,d0=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(Tc=Tc||document.createElement("div"),Tc.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=Tc.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function go(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var to={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},g$=["Webkit","ms","Moz","O"];Object.keys(to).forEach(function(e){g$.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),to[t]=to[e]})});function h0(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||to.hasOwnProperty(e)&&to[e]?(""+t).trim():t+"px"}function f0(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=h0(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var x$=It({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 km(e,t){if(t){if(x$[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(fe(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(fe(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(fe(61))}if(t.style!=null&&typeof t.style!="object")throw Error(fe(62))}}function Nm(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 Sm=null;function Yg(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Cm=null,Ma=null,Da=null;function fw(e){if(e=nc(e)){if(typeof Cm!="function")throw Error(fe(280));var t=e.stateNode;t&&(t=Ld(t),Cm(e.stateNode,e.type,t))}}function m0(e){Ma?Da?Da.push(e):Da=[e]:Ma=e}function p0(){if(Ma){var e=Ma,t=Da;if(Da=Ma=null,fw(e),t)for(e=0;e<t.length;e++)fw(t[e])}}function g0(e,t){return e(t)}function x0(){}var Wh=!1;function v0(e,t,s){if(Wh)return e(t,s);Wh=!0;try{return g0(e,t,s)}finally{Wh=!1,(Ma!==null||Da!==null)&&(x0(),p0())}}function xo(e,t){var s=e.stateNode;if(s===null)return null;var r=Ld(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(fe(231,t,typeof s));return s}var Em=!1;if(Er)try{var Ml={};Object.defineProperty(Ml,"passive",{get:function(){Em=!0}}),window.addEventListener("test",Ml,Ml),window.removeEventListener("test",Ml,Ml)}catch{Em=!1}function v$(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 no=!1,Uu=null,Bu=!1,Am=null,j$={onError:function(e){no=!0,Uu=e}};function w$(e,t,s,r,i,a,l,o,c){no=!1,Uu=null,v$.apply(j$,arguments)}function y$(e,t,s,r,i,a,l,o,c){if(w$.apply(this,arguments),no){if(no){var u=Uu;no=!1,Uu=null}else throw Error(fe(198));Bu||(Bu=!0,Am=u)}}function ta(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 j0(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 mw(e){if(ta(e)!==e)throw Error(fe(188))}function b$(e){var t=e.alternate;if(!t){if(t=ta(e),t===null)throw Error(fe(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 mw(i),e;if(a===r)return mw(i),t;a=a.sibling}throw Error(fe(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(fe(189))}}if(s.alternate!==r)throw Error(fe(190))}if(s.tag!==3)throw Error(fe(188));return s.stateNode.current===s?e:t}function w0(e){return e=b$(e),e!==null?y0(e):null}function y0(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=y0(e);if(t!==null)return t;e=e.sibling}return null}var b0=Qn.unstable_scheduleCallback,pw=Qn.unstable_cancelCallback,k$=Qn.unstable_shouldYield,N$=Qn.unstable_requestPaint,Ot=Qn.unstable_now,S$=Qn.unstable_getCurrentPriorityLevel,qg=Qn.unstable_ImmediatePriority,k0=Qn.unstable_UserBlockingPriority,Wu=Qn.unstable_NormalPriority,C$=Qn.unstable_LowPriority,N0=Qn.unstable_IdlePriority,Pd=null,Js=null;function E$(e){if(Js&&typeof Js.onCommitFiberRoot=="function")try{Js.onCommitFiberRoot(Pd,e,void 0,(e.current.flags&128)===128)}catch{}}var Es=Math.clz32?Math.clz32:R$,A$=Math.log,T$=Math.LN2;function R$(e){return e>>>=0,e===0?32:31-(A$(e)/T$|0)|0}var Rc=64,$c=4194304;function Ql(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 Hu(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=Ql(o):(a&=l,a!==0&&(r=Ql(a)))}else l=s&~i,l!==0?r=Ql(l):a!==0&&(r=Ql(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-Es(t),i=1<<s,r|=e[s],t&=~i;return r}function $$(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 I$(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-Es(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=$$(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function Tm(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function S0(){var e=Rc;return Rc<<=1,!(Rc&4194240)&&(Rc=64),e}function Hh(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function ec(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Es(t),e[t]=s}function P$(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-Es(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function Qg(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-Es(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var ht=0;function C0(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var E0,Xg,A0,T0,R0,Rm=!1,Ic=[],Qr=null,Xr=null,Jr=null,vo=new Map,jo=new Map,Hr=[],M$="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 gw(e,t){switch(e){case"focusin":case"focusout":Qr=null;break;case"dragenter":case"dragleave":Xr=null;break;case"mouseover":case"mouseout":Jr=null;break;case"pointerover":case"pointerout":vo.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":jo.delete(t.pointerId)}}function Dl(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=nc(t),t!==null&&Xg(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function D$(e,t,s,r,i){switch(t){case"focusin":return Qr=Dl(Qr,e,t,s,r,i),!0;case"dragenter":return Xr=Dl(Xr,e,t,s,r,i),!0;case"mouseover":return Jr=Dl(Jr,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return vo.set(a,Dl(vo.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,jo.set(a,Dl(jo.get(a)||null,e,t,s,r,i)),!0}return!1}function $0(e){var t=Di(e.target);if(t!==null){var s=ta(t);if(s!==null){if(t=s.tag,t===13){if(t=j0(s),t!==null){e.blockedOn=t,R0(e.priority,function(){A0(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 gu(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=$m(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Sm=r,s.target.dispatchEvent(r),Sm=null}else return t=nc(s),t!==null&&Xg(t),e.blockedOn=s,!1;t.shift()}return!0}function xw(e,t,s){gu(e)&&s.delete(t)}function O$(){Rm=!1,Qr!==null&&gu(Qr)&&(Qr=null),Xr!==null&&gu(Xr)&&(Xr=null),Jr!==null&&gu(Jr)&&(Jr=null),vo.forEach(xw),jo.forEach(xw)}function Ol(e,t){e.blockedOn===t&&(e.blockedOn=null,Rm||(Rm=!0,Qn.unstable_scheduleCallback(Qn.unstable_NormalPriority,O$)))}function wo(e){function t(i){return Ol(i,e)}if(0<Ic.length){Ol(Ic[0],e);for(var s=1;s<Ic.length;s++){var r=Ic[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Qr!==null&&Ol(Qr,e),Xr!==null&&Ol(Xr,e),Jr!==null&&Ol(Jr,e),vo.forEach(t),jo.forEach(t),s=0;s<Hr.length;s++)r=Hr[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Hr.length&&(s=Hr[0],s.blockedOn===null);)$0(s),s.blockedOn===null&&Hr.shift()}var Oa=Or.ReactCurrentBatchConfig,Ku=!0;function L$(e,t,s,r){var i=ht,a=Oa.transition;Oa.transition=null;try{ht=1,Jg(e,t,s,r)}finally{ht=i,Oa.transition=a}}function _$(e,t,s,r){var i=ht,a=Oa.transition;Oa.transition=null;try{ht=4,Jg(e,t,s,r)}finally{ht=i,Oa.transition=a}}function Jg(e,t,s,r){if(Ku){var i=$m(e,t,s,r);if(i===null)ef(e,t,r,Vu,s),gw(e,r);else if(D$(i,e,t,s,r))r.stopPropagation();else if(gw(e,r),t&4&&-1<M$.indexOf(e)){for(;i!==null;){var a=nc(i);if(a!==null&&E0(a),a=$m(e,t,s,r),a===null&&ef(e,t,r,Vu,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else ef(e,t,r,null,s)}}var Vu=null;function $m(e,t,s,r){if(Vu=null,e=Yg(r),e=Di(e),e!==null)if(t=ta(e),t===null)e=null;else if(s=t.tag,s===13){if(e=j0(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 Vu=e,null}function I0(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(S$()){case qg:return 1;case k0:return 4;case Wu:case C$:return 16;case N0:return 536870912;default:return 16}default:return 16}}var Vr=null,Zg=null,xu=null;function P0(){if(xu)return xu;var e,t=Zg,s=t.length,r,i="value"in Vr?Vr.value:Vr.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 xu=i.slice(e,1<r?1-r:void 0)}function vu(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 Pc(){return!0}function vw(){return!1}function Zn(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)?Pc:vw,this.isPropagationStopped=vw,this}return It(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=Pc)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=Pc)},persist:function(){},isPersistent:Pc}),t}var ul={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},ex=Zn(ul),tc=It({},ul,{view:0,detail:0}),F$=Zn(tc),Kh,Vh,Ll,Md=It({},tc,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:tx,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!==Ll&&(Ll&&e.type==="mousemove"?(Kh=e.screenX-Ll.screenX,Vh=e.screenY-Ll.screenY):Vh=Kh=0,Ll=e),Kh)},movementY:function(e){return"movementY"in e?e.movementY:Vh}}),jw=Zn(Md),z$=It({},Md,{dataTransfer:0}),U$=Zn(z$),B$=It({},tc,{relatedTarget:0}),Gh=Zn(B$),W$=It({},ul,{animationName:0,elapsedTime:0,pseudoElement:0}),H$=Zn(W$),K$=It({},ul,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),V$=Zn(K$),G$=It({},ul,{data:0}),ww=Zn(G$),Y$={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},q$={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"},Q$={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function X$(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=Q$[e])?!!t[e]:!1}function tx(){return X$}var J$=It({},tc,{key:function(e){if(e.key){var t=Y$[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=vu(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?q$[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:tx,charCode:function(e){return e.type==="keypress"?vu(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?vu(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),Z$=Zn(J$),eI=It({},Md,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),yw=Zn(eI),tI=It({},tc,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:tx}),nI=Zn(tI),sI=It({},ul,{propertyName:0,elapsedTime:0,pseudoElement:0}),rI=Zn(sI),iI=It({},Md,{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}),aI=Zn(iI),lI=[9,13,27,32],nx=Er&&"CompositionEvent"in window,so=null;Er&&"documentMode"in document&&(so=document.documentMode);var oI=Er&&"TextEvent"in window&&!so,M0=Er&&(!nx||so&&8<so&&11>=so),bw=" ",kw=!1;function D0(e,t){switch(e){case"keyup":return lI.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function O0(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ba=!1;function cI(e,t){switch(e){case"compositionend":return O0(t);case"keypress":return t.which!==32?null:(kw=!0,bw);case"textInput":return e=t.data,e===bw&&kw?null:e;default:return null}}function uI(e,t){if(ba)return e==="compositionend"||!nx&&D0(e,t)?(e=P0(),xu=Zg=Vr=null,ba=!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 M0&&t.locale!=="ko"?null:t.data;default:return null}}var dI={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 Nw(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!dI[e.type]:t==="textarea"}function L0(e,t,s,r){m0(r),t=Gu(t,"onChange"),0<t.length&&(s=new ex("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var ro=null,yo=null;function hI(e){Y0(e,0)}function Dd(e){var t=Sa(e);if(l0(t))return e}function fI(e,t){if(e==="change")return t}var _0=!1;if(Er){var Yh;if(Er){var qh="oninput"in document;if(!qh){var Sw=document.createElement("div");Sw.setAttribute("oninput","return;"),qh=typeof Sw.oninput=="function"}Yh=qh}else Yh=!1;_0=Yh&&(!document.documentMode||9<document.documentMode)}function Cw(){ro&&(ro.detachEvent("onpropertychange",F0),yo=ro=null)}function F0(e){if(e.propertyName==="value"&&Dd(yo)){var t=[];L0(t,yo,e,Yg(e)),v0(hI,t)}}function mI(e,t,s){e==="focusin"?(Cw(),ro=t,yo=s,ro.attachEvent("onpropertychange",F0)):e==="focusout"&&Cw()}function pI(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Dd(yo)}function gI(e,t){if(e==="click")return Dd(t)}function xI(e,t){if(e==="input"||e==="change")return Dd(t)}function vI(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var $s=typeof Object.is=="function"?Object.is:vI;function bo(e,t){if($s(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(!fm.call(t,i)||!$s(e[i],t[i]))return!1}return!0}function Ew(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Aw(e,t){var s=Ew(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=Ew(s)}}function z0(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?z0(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function U0(){for(var e=window,t=zu();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=zu(e.document)}return t}function sx(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 jI(e){var t=U0(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&z0(s.ownerDocument.documentElement,s)){if(r!==null&&sx(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=Aw(s,a);var l=Aw(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 wI=Er&&"documentMode"in document&&11>=document.documentMode,ka=null,Im=null,io=null,Pm=!1;function Tw(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Pm||ka==null||ka!==zu(r)||(r=ka,"selectionStart"in r&&sx(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}),io&&bo(io,r)||(io=r,r=Gu(Im,"onSelect"),0<r.length&&(t=new ex("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=ka)))}function Mc(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var Na={animationend:Mc("Animation","AnimationEnd"),animationiteration:Mc("Animation","AnimationIteration"),animationstart:Mc("Animation","AnimationStart"),transitionend:Mc("Transition","TransitionEnd")},Qh={},B0={};Er&&(B0=document.createElement("div").style,"AnimationEvent"in window||(delete Na.animationend.animation,delete Na.animationiteration.animation,delete Na.animationstart.animation),"TransitionEvent"in window||delete Na.transitionend.transition);function Od(e){if(Qh[e])return Qh[e];if(!Na[e])return e;var t=Na[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in B0)return Qh[e]=t[s];return e}var W0=Od("animationend"),H0=Od("animationiteration"),K0=Od("animationstart"),V0=Od("transitionend"),G0=new Map,Rw="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 gi(e,t){G0.set(e,t),ea(t,[e])}for(var Xh=0;Xh<Rw.length;Xh++){var Jh=Rw[Xh],yI=Jh.toLowerCase(),bI=Jh[0].toUpperCase()+Jh.slice(1);gi(yI,"on"+bI)}gi(W0,"onAnimationEnd");gi(H0,"onAnimationIteration");gi(K0,"onAnimationStart");gi("dblclick","onDoubleClick");gi("focusin","onFocus");gi("focusout","onBlur");gi(V0,"onTransitionEnd");Ka("onMouseEnter",["mouseout","mouseover"]);Ka("onMouseLeave",["mouseout","mouseover"]);Ka("onPointerEnter",["pointerout","pointerover"]);Ka("onPointerLeave",["pointerout","pointerover"]);ea("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ea("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ea("onBeforeInput",["compositionend","keypress","textInput","paste"]);ea("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ea("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ea("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Xl="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(" "),kI=new Set("cancel close invalid load scroll toggle".split(" ").concat(Xl));function $w(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,y$(r,t,void 0,e),e.currentTarget=null}function Y0(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;$w(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;$w(i,o,u),a=c}}}if(Bu)throw e=Am,Bu=!1,Am=null,e}function yt(e,t){var s=t[_m];s===void 0&&(s=t[_m]=new Set);var r=e+"__bubble";s.has(r)||(q0(t,e,2,!1),s.add(r))}function Zh(e,t,s){var r=0;t&&(r|=4),q0(s,e,r,t)}var Dc="_reactListening"+Math.random().toString(36).slice(2);function ko(e){if(!e[Dc]){e[Dc]=!0,n0.forEach(function(s){s!=="selectionchange"&&(kI.has(s)||Zh(s,!1,e),Zh(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[Dc]||(t[Dc]=!0,Zh("selectionchange",!1,t))}}function q0(e,t,s,r){switch(I0(t)){case 1:var i=L$;break;case 4:i=_$;break;default:i=Jg}s=i.bind(null,t,s,e),i=void 0,!Em||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 ef(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=Di(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}v0(function(){var u=a,h=Yg(s),f=[];e:{var m=G0.get(e);if(m!==void 0){var p=ex,g=e;switch(e){case"keypress":if(vu(s)===0)break e;case"keydown":case"keyup":p=Z$;break;case"focusin":g="focus",p=Gh;break;case"focusout":g="blur",p=Gh;break;case"beforeblur":case"afterblur":p=Gh;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=jw;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=U$;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=nI;break;case W0:case H0:case K0:p=H$;break;case V0:p=rI;break;case"scroll":p=F$;break;case"wheel":p=aI;break;case"copy":case"cut":case"paste":p=V$;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=yw}var v=(t&4)!==0,b=!v&&e==="scroll",j=v?m!==null?m+"Capture":null:m;v=[];for(var x=u,w;x!==null;){w=x;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,j!==null&&(y=xo(x,j),y!=null&&v.push(No(x,y,w)))),b)break;x=x.return}0<v.length&&(m=new p(m,g,null,s,h),f.push({event:m,listeners:v}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Sm&&(g=s.relatedTarget||s.fromElement)&&(Di(g)||g[Ar]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Di(g):null,g!==null&&(b=ta(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(v=jw,y="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(v=yw,y="onPointerLeave",j="onPointerEnter",x="pointer"),b=p==null?m:Sa(p),w=g==null?m:Sa(g),m=new v(y,x+"leave",p,s,h),m.target=b,m.relatedTarget=w,y=null,Di(h)===u&&(v=new v(j,x+"enter",g,s,h),v.target=w,v.relatedTarget=b,y=v),b=y,p&&g)t:{for(v=p,j=g,x=0,w=v;w;w=ha(w))x++;for(w=0,y=j;y;y=ha(y))w++;for(;0<x-w;)v=ha(v),x--;for(;0<w-x;)j=ha(j),w--;for(;x--;){if(v===j||j!==null&&v===j.alternate)break t;v=ha(v),j=ha(j)}v=null}else v=null;p!==null&&Iw(f,m,p,v,!1),g!==null&&b!==null&&Iw(f,b,g,v,!0)}}e:{if(m=u?Sa(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=fI;else if(Nw(m))if(_0)k=xI;else{k=pI;var N=mI}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=gI);if(k&&(k=k(e,u))){L0(f,k,s,h);break e}N&&N(e,m,u),e==="focusout"&&(N=m._wrapperState)&&N.controlled&&m.type==="number"&&wm(m,"number",m.value)}switch(N=u?Sa(u):window,e){case"focusin":(Nw(N)||N.contentEditable==="true")&&(ka=N,Im=u,io=null);break;case"focusout":io=Im=ka=null;break;case"mousedown":Pm=!0;break;case"contextmenu":case"mouseup":case"dragend":Pm=!1,Tw(f,s,h);break;case"selectionchange":if(wI)break;case"keydown":case"keyup":Tw(f,s,h)}var S;if(nx)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 ba?D0(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(M0&&s.locale!=="ko"&&(ba||C!=="onCompositionStart"?C==="onCompositionEnd"&&ba&&(S=P0()):(Vr=h,Zg="value"in Vr?Vr.value:Vr.textContent,ba=!0)),N=Gu(u,C),0<N.length&&(C=new ww(C,e,null,s,h),f.push({event:C,listeners:N}),S?C.data=S:(S=O0(s),S!==null&&(C.data=S)))),(S=oI?cI(e,s):uI(e,s))&&(u=Gu(u,"onBeforeInput"),0<u.length&&(h=new ww("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}Y0(f,t)})}function No(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Gu(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=xo(e,s),a!=null&&r.unshift(No(e,a,i)),a=xo(e,t),a!=null&&r.push(No(e,a,i))),e=e.return}return r}function ha(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Iw(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=xo(s,a),c!=null&&l.unshift(No(s,c,o))):i||(c=xo(s,a),c!=null&&l.push(No(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var NI=/\r\n?/g,SI=/\u0000|\uFFFD/g;function Pw(e){return(typeof e=="string"?e:""+e).replace(NI,`
38
- `).replace(SI,"")}function Oc(e,t,s){if(t=Pw(t),Pw(e)!==t&&s)throw Error(fe(425))}function Yu(){}var Mm=null,Dm=null;function Om(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 Lm=typeof setTimeout=="function"?setTimeout:void 0,CI=typeof clearTimeout=="function"?clearTimeout:void 0,Mw=typeof Promise=="function"?Promise:void 0,EI=typeof queueMicrotask=="function"?queueMicrotask:typeof Mw<"u"?function(e){return Mw.resolve(null).then(e).catch(AI)}:Lm;function AI(e){setTimeout(function(){throw e})}function tf(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),wo(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);wo(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 Dw(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 dl=Math.random().toString(36).slice(2),Ys="__reactFiber$"+dl,So="__reactProps$"+dl,Ar="__reactContainer$"+dl,_m="__reactEvents$"+dl,TI="__reactListeners$"+dl,RI="__reactHandles$"+dl;function Di(e){var t=e[Ys];if(t)return t;for(var s=e.parentNode;s;){if(t=s[Ar]||s[Ys]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=Dw(e);e!==null;){if(s=e[Ys])return s;e=Dw(e)}return t}e=s,s=e.parentNode}return null}function nc(e){return e=e[Ys]||e[Ar],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Sa(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(fe(33))}function Ld(e){return e[So]||null}var Fm=[],Ca=-1;function xi(e){return{current:e}}function bt(e){0>Ca||(e.current=Fm[Ca],Fm[Ca]=null,Ca--)}function vt(e,t){Ca++,Fm[Ca]=e.current,e.current=t}var oi={},jn=xi(oi),Pn=xi(!1),Wi=oi;function Va(e,t){var s=e.type.contextTypes;if(!s)return oi;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 Mn(e){return e=e.childContextTypes,e!=null}function qu(){bt(Pn),bt(jn)}function Ow(e,t,s){if(jn.current!==oi)throw Error(fe(168));vt(jn,t),vt(Pn,s)}function Q0(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(fe(108,m$(e)||"Unknown",i));return It({},s,r)}function Qu(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||oi,Wi=jn.current,vt(jn,e),vt(Pn,Pn.current),!0}function Lw(e,t,s){var r=e.stateNode;if(!r)throw Error(fe(169));s?(e=Q0(e,t,Wi),r.__reactInternalMemoizedMergedChildContext=e,bt(Pn),bt(jn),vt(jn,e)):bt(Pn),vt(Pn,s)}var pr=null,_d=!1,nf=!1;function X0(e){pr===null?pr=[e]:pr.push(e)}function $I(e){_d=!0,X0(e)}function vi(){if(!nf&&pr!==null){nf=!0;var e=0,t=ht;try{var s=pr;for(ht=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}pr=null,_d=!1}catch(i){throw pr!==null&&(pr=pr.slice(e+1)),b0(qg,vi),i}finally{ht=t,nf=!1}}return null}var Ea=[],Aa=0,Xu=null,Ju=0,ls=[],os=0,Hi=null,jr=1,wr="";function Ri(e,t){Ea[Aa++]=Ju,Ea[Aa++]=Xu,Xu=e,Ju=t}function J0(e,t,s){ls[os++]=jr,ls[os++]=wr,ls[os++]=Hi,Hi=e;var r=jr;e=wr;var i=32-Es(r)-1;r&=~(1<<i),s+=1;var a=32-Es(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,jr=1<<32-Es(t)+i|s<<i|r,wr=a+e}else jr=1<<a|s<<i|r,wr=e}function rx(e){e.return!==null&&(Ri(e,1),J0(e,1,0))}function ix(e){for(;e===Xu;)Xu=Ea[--Aa],Ea[Aa]=null,Ju=Ea[--Aa],Ea[Aa]=null;for(;e===Hi;)Hi=ls[--os],ls[os]=null,wr=ls[--os],ls[os]=null,jr=ls[--os],ls[os]=null}var Yn=null,Vn=null,kt=!1,Ss=null;function Z0(e,t){var s=hs(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 _w(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,Yn=e,Vn=Zr(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,Yn=e,Vn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=Hi!==null?{id:jr,overflow:wr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=hs(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,Yn=e,Vn=null,!0):!1;default:return!1}}function zm(e){return(e.mode&1)!==0&&(e.flags&128)===0}function Um(e){if(kt){var t=Vn;if(t){var s=t;if(!_w(e,t)){if(zm(e))throw Error(fe(418));t=Zr(s.nextSibling);var r=Yn;t&&_w(e,t)?Z0(r,s):(e.flags=e.flags&-4097|2,kt=!1,Yn=e)}}else{if(zm(e))throw Error(fe(418));e.flags=e.flags&-4097|2,kt=!1,Yn=e}}}function Fw(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Yn=e}function Lc(e){if(e!==Yn)return!1;if(!kt)return Fw(e),kt=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!Om(e.type,e.memoizedProps)),t&&(t=Vn)){if(zm(e))throw eN(),Error(fe(418));for(;t;)Z0(e,t),t=Zr(t.nextSibling)}if(Fw(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(fe(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Vn=Zr(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Vn=null}}else Vn=Yn?Zr(e.stateNode.nextSibling):null;return!0}function eN(){for(var e=Vn;e;)e=Zr(e.nextSibling)}function Ga(){Vn=Yn=null,kt=!1}function ax(e){Ss===null?Ss=[e]:Ss.push(e)}var II=Or.ReactCurrentBatchConfig;function _l(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(fe(309));var r=s.stateNode}if(!r)throw Error(fe(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(fe(284));if(!s._owner)throw Error(fe(290,e))}return e}function _c(e,t){throw e=Object.prototype.toString.call(t),Error(fe(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function zw(e){var t=e._init;return t(e._payload)}function tN(e){function t(j,x){if(e){var w=j.deletions;w===null?(j.deletions=[x],j.flags|=16):w.push(x)}}function s(j,x){if(!e)return null;for(;x!==null;)t(j,x),x=x.sibling;return null}function r(j,x){for(j=new Map;x!==null;)x.key!==null?j.set(x.key,x):j.set(x.index,x),x=x.sibling;return j}function i(j,x){return j=si(j,x),j.index=0,j.sibling=null,j}function a(j,x,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<x?(j.flags|=2,x):w):(j.flags|=2,x)):(j.flags|=1048576,x)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,x,w,y){return x===null||x.tag!==6?(x=uf(w,j.mode,y),x.return=j,x):(x=i(x,w),x.return=j,x)}function c(j,x,w,y){var k=w.type;return k===ya?h(j,x,w.props.children,y,w.key):x!==null&&(x.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Br&&zw(k)===x.type)?(y=i(x,w.props),y.ref=_l(j,x,w),y.return=j,y):(y=Su(w.type,w.key,w.props,null,j.mode,y),y.ref=_l(j,x,w),y.return=j,y)}function u(j,x,w,y){return x===null||x.tag!==4||x.stateNode.containerInfo!==w.containerInfo||x.stateNode.implementation!==w.implementation?(x=df(w,j.mode,y),x.return=j,x):(x=i(x,w.children||[]),x.return=j,x)}function h(j,x,w,y,k){return x===null||x.tag!==7?(x=zi(w,j.mode,y,k),x.return=j,x):(x=i(x,w),x.return=j,x)}function f(j,x,w){if(typeof x=="string"&&x!==""||typeof x=="number")return x=uf(""+x,j.mode,w),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case Ec:return w=Su(x.type,x.key,x.props,null,j.mode,w),w.ref=_l(j,null,x),w.return=j,w;case wa:return x=df(x,j.mode,w),x.return=j,x;case Br:var y=x._init;return f(j,y(x._payload),w)}if(ql(x)||Pl(x))return x=zi(x,j.mode,w,null),x.return=j,x;_c(j,x)}return null}function m(j,x,w,y){var k=x!==null?x.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return k!==null?null:o(j,x,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case Ec:return w.key===k?c(j,x,w,y):null;case wa:return w.key===k?u(j,x,w,y):null;case Br:return k=w._init,m(j,x,k(w._payload),y)}if(ql(w)||Pl(w))return k!==null?null:h(j,x,w,y,null);_c(j,w)}return null}function p(j,x,w,y,k){if(typeof y=="string"&&y!==""||typeof y=="number")return j=j.get(w)||null,o(x,j,""+y,k);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Ec:return j=j.get(y.key===null?w:y.key)||null,c(x,j,y,k);case wa:return j=j.get(y.key===null?w:y.key)||null,u(x,j,y,k);case Br:var N=y._init;return p(j,x,w,N(y._payload),k)}if(ql(y)||Pl(y))return j=j.get(w)||null,h(x,j,y,k,null);_c(x,y)}return null}function g(j,x,w,y){for(var k=null,N=null,S=x,C=x=0,$=null;S!==null&&C<w.length;C++){S.index>C?($=S,S=null):$=S.sibling;var R=m(j,S,w[C],y);if(R===null){S===null&&(S=$);break}e&&S&&R.alternate===null&&t(j,S),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R,S=$}if(C===w.length)return s(j,S),kt&&Ri(j,C),k;if(S===null){for(;C<w.length;C++)S=f(j,w[C],y),S!==null&&(x=a(S,x,C),N===null?k=S:N.sibling=S,N=S);return kt&&Ri(j,C),k}for(S=r(j,S);C<w.length;C++)$=p(S,j,C,w[C],y),$!==null&&(e&&$.alternate!==null&&S.delete($.key===null?C:$.key),x=a($,x,C),N===null?k=$:N.sibling=$,N=$);return e&&S.forEach(function(I){return t(j,I)}),kt&&Ri(j,C),k}function v(j,x,w,y){var k=Pl(w);if(typeof k!="function")throw Error(fe(150));if(w=k.call(w),w==null)throw Error(fe(151));for(var N=k=null,S=x,C=x=0,$=null,R=w.next();S!==null&&!R.done;C++,R=w.next()){S.index>C?($=S,S=null):$=S.sibling;var I=m(j,S,R.value,y);if(I===null){S===null&&(S=$);break}e&&S&&I.alternate===null&&t(j,S),x=a(I,x,C),N===null?k=I:N.sibling=I,N=I,S=$}if(R.done)return s(j,S),kt&&Ri(j,C),k;if(S===null){for(;!R.done;C++,R=w.next())R=f(j,R.value,y),R!==null&&(x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return kt&&Ri(j,C),k}for(S=r(j,S);!R.done;C++,R=w.next())R=p(S,j,C,R.value,y),R!==null&&(e&&R.alternate!==null&&S.delete(R.key===null?C:R.key),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return e&&S.forEach(function(F){return t(j,F)}),kt&&Ri(j,C),k}function b(j,x,w,y){if(typeof w=="object"&&w!==null&&w.type===ya&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case Ec:e:{for(var k=w.key,N=x;N!==null;){if(N.key===k){if(k=w.type,k===ya){if(N.tag===7){s(j,N.sibling),x=i(N,w.props.children),x.return=j,j=x;break e}}else if(N.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Br&&zw(k)===N.type){s(j,N.sibling),x=i(N,w.props),x.ref=_l(j,N,w),x.return=j,j=x;break e}s(j,N);break}else t(j,N);N=N.sibling}w.type===ya?(x=zi(w.props.children,j.mode,y,w.key),x.return=j,j=x):(y=Su(w.type,w.key,w.props,null,j.mode,y),y.ref=_l(j,x,w),y.return=j,j=y)}return l(j);case wa:e:{for(N=w.key;x!==null;){if(x.key===N)if(x.tag===4&&x.stateNode.containerInfo===w.containerInfo&&x.stateNode.implementation===w.implementation){s(j,x.sibling),x=i(x,w.children||[]),x.return=j,j=x;break e}else{s(j,x);break}else t(j,x);x=x.sibling}x=df(w,j.mode,y),x.return=j,j=x}return l(j);case Br:return N=w._init,b(j,x,N(w._payload),y)}if(ql(w))return g(j,x,w,y);if(Pl(w))return v(j,x,w,y);_c(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,x!==null&&x.tag===6?(s(j,x.sibling),x=i(x,w),x.return=j,j=x):(s(j,x),x=uf(w,j.mode,y),x.return=j,j=x),l(j)):s(j,x)}return b}var Ya=tN(!0),nN=tN(!1),Zu=xi(null),ed=null,Ta=null,lx=null;function ox(){lx=Ta=ed=null}function cx(e){var t=Zu.current;bt(Zu),e._currentValue=t}function Bm(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 La(e,t){ed=e,lx=Ta=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(In=!0),e.firstContext=null)}function ps(e){var t=e._currentValue;if(lx!==e)if(e={context:e,memoizedValue:t,next:null},Ta===null){if(ed===null)throw Error(fe(308));Ta=e,ed.dependencies={lanes:0,firstContext:e}}else Ta=Ta.next=e;return t}var Oi=null;function ux(e){Oi===null?Oi=[e]:Oi.push(e)}function sN(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,ux(t)):(s.next=i.next,i.next=s),t.interleaved=s,Tr(e,r)}function Tr(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 Wr=!1;function dx(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function rN(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 br(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function ei(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,st&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,Tr(e,s)}return i=r.interleaved,i===null?(t.next=t,ux(r)):(t.next=i.next,i.next=t),r.interleaved=t,Tr(e,s)}function ju(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,Qg(e,s)}}function Uw(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 td(e,t,s,r){var i=e.updateQueue;Wr=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(a!==null){var f=i.baseState;l=0,h=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,v=o;switch(m=t,p=s,v.tag){case 1:if(g=v.payload,typeof g=="function"){f=g.call(p,f,m);break e}f=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=v.payload,m=typeof g=="function"?g.call(p,f,m):g,m==null)break e;f=It({},f,m);break e;case 2:Wr=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=f):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(h===null&&(c=f),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=h,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);Vi|=l,e.lanes=l,e.memoizedState=f}}function Bw(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(fe(191,i));i.call(r)}}}var sc={},Zs=xi(sc),Co=xi(sc),Eo=xi(sc);function Li(e){if(e===sc)throw Error(fe(174));return e}function hx(e,t){switch(vt(Eo,t),vt(Co,e),vt(Zs,sc),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:bm(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=bm(t,e)}bt(Zs),vt(Zs,t)}function qa(){bt(Zs),bt(Co),bt(Eo)}function iN(e){Li(Eo.current);var t=Li(Zs.current),s=bm(t,e.type);t!==s&&(vt(Co,e),vt(Zs,s))}function fx(e){Co.current===e&&(bt(Zs),bt(Co))}var At=xi(0);function nd(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 sf=[];function mx(){for(var e=0;e<sf.length;e++)sf[e]._workInProgressVersionPrimary=null;sf.length=0}var wu=Or.ReactCurrentDispatcher,rf=Or.ReactCurrentBatchConfig,Ki=0,Rt=null,Ht=null,Xt=null,sd=!1,ao=!1,Ao=0,PI=0;function fn(){throw Error(fe(321))}function px(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!$s(e[s],t[s]))return!1;return!0}function gx(e,t,s,r,i,a){if(Ki=a,Rt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,wu.current=e===null||e.memoizedState===null?LI:_I,e=s(r,i),ao){a=0;do{if(ao=!1,Ao=0,25<=a)throw Error(fe(301));a+=1,Xt=Ht=null,t.updateQueue=null,wu.current=FI,e=s(r,i)}while(ao)}if(wu.current=rd,t=Ht!==null&&Ht.next!==null,Ki=0,Xt=Ht=Rt=null,sd=!1,t)throw Error(fe(300));return e}function xx(){var e=Ao!==0;return Ao=0,e}function Vs(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Xt===null?Rt.memoizedState=Xt=e:Xt=Xt.next=e,Xt}function gs(){if(Ht===null){var e=Rt.alternate;e=e!==null?e.memoizedState:null}else e=Ht.next;var t=Xt===null?Rt.memoizedState:Xt.next;if(t!==null)Xt=t,Ht=e;else{if(e===null)throw Error(fe(310));Ht=e,e={memoizedState:Ht.memoizedState,baseState:Ht.baseState,baseQueue:Ht.baseQueue,queue:Ht.queue,next:null},Xt===null?Rt.memoizedState=Xt=e:Xt=Xt.next=e}return Xt}function To(e,t){return typeof t=="function"?t(e):t}function af(e){var t=gs(),s=t.queue;if(s===null)throw Error(fe(311));s.lastRenderedReducer=e;var r=Ht,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((Ki&h)===h)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var f={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,Rt.lanes|=h,Vi|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,$s(r,t.memoizedState)||(In=!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,Rt.lanes|=a,Vi|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function lf(e){var t=gs(),s=t.queue;if(s===null)throw Error(fe(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);$s(a,t.memoizedState)||(In=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function aN(){}function lN(e,t){var s=Rt,r=gs(),i=t(),a=!$s(r.memoizedState,i);if(a&&(r.memoizedState=i,In=!0),r=r.queue,vx(uN.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||Xt!==null&&Xt.memoizedState.tag&1){if(s.flags|=2048,Ro(9,cN.bind(null,s,r,i,t),void 0,null),en===null)throw Error(fe(349));Ki&30||oN(s,t,i)}return i}function oN(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=Rt.updateQueue,t===null?(t={lastEffect:null,stores:null},Rt.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function cN(e,t,s,r){t.value=s,t.getSnapshot=r,dN(t)&&hN(e)}function uN(e,t,s){return s(function(){dN(t)&&hN(e)})}function dN(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!$s(e,s)}catch{return!0}}function hN(e){var t=Tr(e,1);t!==null&&As(t,e,1,-1)}function Ww(e){var t=Vs();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:To,lastRenderedState:e},t.queue=e,e=e.dispatch=OI.bind(null,Rt,e),[t.memoizedState,e]}function Ro(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=Rt.updateQueue,t===null?(t={lastEffect:null,stores:null},Rt.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 fN(){return gs().memoizedState}function yu(e,t,s,r){var i=Vs();Rt.flags|=e,i.memoizedState=Ro(1|t,s,void 0,r===void 0?null:r)}function Fd(e,t,s,r){var i=gs();r=r===void 0?null:r;var a=void 0;if(Ht!==null){var l=Ht.memoizedState;if(a=l.destroy,r!==null&&px(r,l.deps)){i.memoizedState=Ro(t,s,a,r);return}}Rt.flags|=e,i.memoizedState=Ro(1|t,s,a,r)}function Hw(e,t){return yu(8390656,8,e,t)}function vx(e,t){return Fd(2048,8,e,t)}function mN(e,t){return Fd(4,2,e,t)}function pN(e,t){return Fd(4,4,e,t)}function gN(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 xN(e,t,s){return s=s!=null?s.concat([e]):null,Fd(4,4,gN.bind(null,t,e),s)}function jx(){}function vN(e,t){var s=gs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&px(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function jN(e,t){var s=gs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&px(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function wN(e,t,s){return Ki&21?($s(s,t)||(s=S0(),Rt.lanes|=s,Vi|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,In=!0),e.memoizedState=s)}function MI(e,t){var s=ht;ht=s!==0&&4>s?s:4,e(!0);var r=rf.transition;rf.transition={};try{e(!1),t()}finally{ht=s,rf.transition=r}}function yN(){return gs().memoizedState}function DI(e,t,s){var r=ni(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},bN(e))kN(t,s);else if(s=sN(e,t,s,r),s!==null){var i=Nn();As(s,e,r,i),NN(s,t,r)}}function OI(e,t,s){var r=ni(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(bN(e))kN(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,$s(o,l)){var c=t.interleaved;c===null?(i.next=i,ux(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=sN(e,t,i,r),s!==null&&(i=Nn(),As(s,e,r,i),NN(s,t,r))}}function bN(e){var t=e.alternate;return e===Rt||t!==null&&t===Rt}function kN(e,t){ao=sd=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function NN(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,Qg(e,s)}}var rd={readContext:ps,useCallback:fn,useContext:fn,useEffect:fn,useImperativeHandle:fn,useInsertionEffect:fn,useLayoutEffect:fn,useMemo:fn,useReducer:fn,useRef:fn,useState:fn,useDebugValue:fn,useDeferredValue:fn,useTransition:fn,useMutableSource:fn,useSyncExternalStore:fn,useId:fn,unstable_isNewReconciler:!1},LI={readContext:ps,useCallback:function(e,t){return Vs().memoizedState=[e,t===void 0?null:t],e},useContext:ps,useEffect:Hw,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,yu(4194308,4,gN.bind(null,t,e),s)},useLayoutEffect:function(e,t){return yu(4194308,4,e,t)},useInsertionEffect:function(e,t){return yu(4,2,e,t)},useMemo:function(e,t){var s=Vs();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Vs();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=DI.bind(null,Rt,e),[r.memoizedState,e]},useRef:function(e){var t=Vs();return e={current:e},t.memoizedState=e},useState:Ww,useDebugValue:jx,useDeferredValue:function(e){return Vs().memoizedState=e},useTransition:function(){var e=Ww(!1),t=e[0];return e=MI.bind(null,e[1]),Vs().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=Rt,i=Vs();if(kt){if(s===void 0)throw Error(fe(407));s=s()}else{if(s=t(),en===null)throw Error(fe(349));Ki&30||oN(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,Hw(uN.bind(null,r,a,e),[e]),r.flags|=2048,Ro(9,cN.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Vs(),t=en.identifierPrefix;if(kt){var s=wr,r=jr;s=(r&~(1<<32-Es(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=Ao++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=PI++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},_I={readContext:ps,useCallback:vN,useContext:ps,useEffect:vx,useImperativeHandle:xN,useInsertionEffect:mN,useLayoutEffect:pN,useMemo:jN,useReducer:af,useRef:fN,useState:function(){return af(To)},useDebugValue:jx,useDeferredValue:function(e){var t=gs();return wN(t,Ht.memoizedState,e)},useTransition:function(){var e=af(To)[0],t=gs().memoizedState;return[e,t]},useMutableSource:aN,useSyncExternalStore:lN,useId:yN,unstable_isNewReconciler:!1},FI={readContext:ps,useCallback:vN,useContext:ps,useEffect:vx,useImperativeHandle:xN,useInsertionEffect:mN,useLayoutEffect:pN,useMemo:jN,useReducer:lf,useRef:fN,useState:function(){return lf(To)},useDebugValue:jx,useDeferredValue:function(e){var t=gs();return Ht===null?t.memoizedState=e:wN(t,Ht.memoizedState,e)},useTransition:function(){var e=lf(To)[0],t=gs().memoizedState;return[e,t]},useMutableSource:aN,useSyncExternalStore:lN,useId:yN,unstable_isNewReconciler:!1};function ks(e,t){if(e&&e.defaultProps){t=It({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function Wm(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:It({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var zd={isMounted:function(e){return(e=e._reactInternals)?ta(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=Nn(),i=ni(e),a=br(r,i);a.payload=t,s!=null&&(a.callback=s),t=ei(e,a,i),t!==null&&(As(t,e,i,r),ju(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=Nn(),i=ni(e),a=br(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=ei(e,a,i),t!==null&&(As(t,e,i,r),ju(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=Nn(),r=ni(e),i=br(s,r);i.tag=2,t!=null&&(i.callback=t),t=ei(e,i,r),t!==null&&(As(t,e,r,s),ju(t,e,r))}};function Kw(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?!bo(s,r)||!bo(i,a):!0}function SN(e,t,s){var r=!1,i=oi,a=t.contextType;return typeof a=="object"&&a!==null?a=ps(a):(i=Mn(t)?Wi:jn.current,r=t.contextTypes,a=(r=r!=null)?Va(e,i):oi),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=zd,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Vw(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&&zd.enqueueReplaceState(t,t.state,null)}function Hm(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},dx(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=ps(a):(a=Mn(t)?Wi:jn.current,i.context=Va(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(Wm(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&&zd.enqueueReplaceState(i,i.state,null),td(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function Qa(e,t){try{var s="",r=t;do s+=f$(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 of(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function Km(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var zI=typeof WeakMap=="function"?WeakMap:Map;function CN(e,t,s){s=br(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){ad||(ad=!0,tp=r),Km(e,t)},s}function EN(e,t,s){s=br(-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(){Km(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){Km(e,t),typeof r!="function"&&(ti===null?ti=new Set([this]):ti.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function Gw(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new zI;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=eP.bind(null,e,t,s),t.then(e,e))}function Yw(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 qw(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=br(-1,1),t.tag=2,ei(s,t,1))),s.lanes|=1),e)}var UI=Or.ReactCurrentOwner,In=!1;function bn(e,t,s,r){t.child=e===null?nN(t,null,s,r):Ya(t,e.child,s,r)}function Qw(e,t,s,r,i){s=s.render;var a=t.ref;return La(t,i),r=gx(e,t,s,r,a,i),s=xx(),e!==null&&!In?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Rr(e,t,i)):(kt&&s&&rx(t),t.flags|=1,bn(e,t,r,i),t.child)}function Xw(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Ex(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,AN(e,t,a,r,i)):(e=Su(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:bo,s(l,r)&&e.ref===t.ref)return Rr(e,t,i)}return t.flags|=1,e=si(a,r),e.ref=t.ref,e.return=t,t.child=e}function AN(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(bo(a,r)&&e.ref===t.ref)if(In=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(In=!0);else return t.lanes=e.lanes,Rr(e,t,i)}return Vm(e,t,s,r,i)}function TN(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},vt($a,Hn),Hn|=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,vt($a,Hn),Hn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,vt($a,Hn),Hn|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,vt($a,Hn),Hn|=r;return bn(e,t,i,s),t.child}function RN(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function Vm(e,t,s,r,i){var a=Mn(s)?Wi:jn.current;return a=Va(t,a),La(t,i),s=gx(e,t,s,r,a,i),r=xx(),e!==null&&!In?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Rr(e,t,i)):(kt&&r&&rx(t),t.flags|=1,bn(e,t,s,i),t.child)}function Jw(e,t,s,r,i){if(Mn(s)){var a=!0;Qu(t)}else a=!1;if(La(t,i),t.stateNode===null)bu(e,t),SN(t,s,r),Hm(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=ps(u):(u=Mn(s)?Wi:jn.current,u=Va(t,u));var h=s.getDerivedStateFromProps,f=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Vw(t,l,r,u),Wr=!1;var m=t.memoizedState;l.state=m,td(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Pn.current||Wr?(typeof h=="function"&&(Wm(t,s,h,r),c=t.memoizedState),(o=Wr||Kw(t,s,o,r,m,c,u))?(f||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(t.flags|=4194308)):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{l=t.stateNode,rN(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:ks(t.type,o),l.props=u,f=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=ps(c):(c=Mn(s)?Wi:jn.current,c=Va(t,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&Vw(t,l,r,c),Wr=!1,m=t.memoizedState,l.state=m,td(t,r,l,i);var g=t.memoizedState;o!==f||m!==g||Pn.current||Wr?(typeof p=="function"&&(Wm(t,s,p,r),g=t.memoizedState),(u=Wr||Kw(t,s,u,r,m,g,c)||!1)?(h||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,g,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,g,c)),typeof l.componentDidUpdate=="function"&&(t.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),r=!1)}return Gm(e,t,s,r,a,i)}function Gm(e,t,s,r,i,a){RN(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&Lw(t,s,!1),Rr(e,t,a);r=t.stateNode,UI.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=Ya(t,e.child,null,a),t.child=Ya(t,null,o,a)):bn(e,t,o,a),t.memoizedState=r.state,i&&Lw(t,s,!0),t.child}function $N(e){var t=e.stateNode;t.pendingContext?Ow(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Ow(e,t.context,!1),hx(e,t.containerInfo)}function Zw(e,t,s,r,i){return Ga(),ax(i),t.flags|=256,bn(e,t,s,r),t.child}var Ym={dehydrated:null,treeContext:null,retryLane:0};function qm(e){return{baseLanes:e,cachePool:null,transitions:null}}function IN(e,t,s){var r=t.pendingProps,i=At.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),vt(At,i&1),e===null)return Um(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=Wd(l,r,0,null),e=zi(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=qm(s),t.memoizedState=Ym,e):wx(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return BI(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=si(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=si(o,a):(a=zi(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?qm(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=Ym,r}return a=e.child,e=a.sibling,r=si(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 wx(e,t){return t=Wd({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Fc(e,t,s,r){return r!==null&&ax(r),Ya(t,e.child,null,s),e=wx(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function BI(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=of(Error(fe(422))),Fc(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Wd({mode:"visible",children:r.children},i,0,null),a=zi(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&Ya(t,e.child,null,l),t.child.memoizedState=qm(l),t.memoizedState=Ym,a);if(!(t.mode&1))return Fc(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(fe(419)),r=of(a,r,void 0),Fc(e,t,l,r)}if(o=(l&e.childLanes)!==0,In||o){if(r=en,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,Tr(e,i),As(r,e,i,-1))}return Cx(),r=of(Error(fe(421))),Fc(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=tP.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Vn=Zr(i.nextSibling),Yn=t,kt=!0,Ss=null,e!==null&&(ls[os++]=jr,ls[os++]=wr,ls[os++]=Hi,jr=e.id,wr=e.overflow,Hi=t),t=wx(t,r.children),t.flags|=4096,t)}function ey(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Bm(e.return,t,s)}function cf(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 PN(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(bn(e,t,r.children,s),r=At.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&&ey(e,s,t);else if(e.tag===19)ey(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(vt(At,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&&nd(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),cf(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&&nd(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}cf(t,!0,s,null,a);break;case"together":cf(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function bu(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Rr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),Vi|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(fe(153));if(t.child!==null){for(e=t.child,s=si(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=si(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function WI(e,t,s){switch(t.tag){case 3:$N(t),Ga();break;case 5:iN(t);break;case 1:Mn(t.type)&&Qu(t);break;case 4:hx(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;vt(Zu,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(vt(At,At.current&1),t.flags|=128,null):s&t.child.childLanes?IN(e,t,s):(vt(At,At.current&1),e=Rr(e,t,s),e!==null?e.sibling:null);vt(At,At.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return PN(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),vt(At,At.current),r)break;return null;case 22:case 23:return t.lanes=0,TN(e,t,s)}return Rr(e,t,s)}var MN,Qm,DN,ON;MN=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}};Qm=function(){};DN=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Li(Zs.current);var a=null;switch(s){case"input":i=vm(e,i),r=vm(e,r),a=[];break;case"select":i=It({},i,{value:void 0}),r=It({},r,{value:void 0}),a=[];break;case"textarea":i=ym(e,i),r=ym(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Yu)}km(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"&&(po.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"&&(po.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&yt("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)}};ON=function(e,t,s,r){s!==r&&(t.flags|=4)};function Fl(e,t){if(!kt)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 mn(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 HI(e,t,s){var r=t.pendingProps;switch(ix(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return mn(t),null;case 1:return Mn(t.type)&&qu(),mn(t),null;case 3:return r=t.stateNode,qa(),bt(Pn),bt(jn),mx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Lc(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ss!==null&&(rp(Ss),Ss=null))),Qm(e,t),mn(t),null;case 5:fx(t);var i=Li(Eo.current);if(s=t.type,e!==null&&t.stateNode!=null)DN(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(fe(166));return mn(t),null}if(e=Li(Zs.current),Lc(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[Ys]=t,r[So]=a,e=(t.mode&1)!==0,s){case"dialog":yt("cancel",r),yt("close",r);break;case"iframe":case"object":case"embed":yt("load",r);break;case"video":case"audio":for(i=0;i<Xl.length;i++)yt(Xl[i],r);break;case"source":yt("error",r);break;case"img":case"image":case"link":yt("error",r),yt("load",r);break;case"details":yt("toggle",r);break;case"input":cw(r,a),yt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},yt("invalid",r);break;case"textarea":dw(r,a),yt("invalid",r)}km(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&&Oc(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&Oc(r.textContent,o,e),i=["children",""+o]):po.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&yt("scroll",r)}switch(s){case"input":Ac(r),uw(r,a,!0);break;case"textarea":Ac(r),hw(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Yu)}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=u0(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[Ys]=t,e[So]=r,MN(e,t,!1,!1),t.stateNode=e;e:{switch(l=Nm(s,r),s){case"dialog":yt("cancel",e),yt("close",e),i=r;break;case"iframe":case"object":case"embed":yt("load",e),i=r;break;case"video":case"audio":for(i=0;i<Xl.length;i++)yt(Xl[i],e);i=r;break;case"source":yt("error",e),i=r;break;case"img":case"image":case"link":yt("error",e),yt("load",e),i=r;break;case"details":yt("toggle",e),i=r;break;case"input":cw(e,r),i=vm(e,r),yt("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=It({},r,{value:void 0}),yt("invalid",e);break;case"textarea":dw(e,r),i=ym(e,r),yt("invalid",e);break;default:i=r}km(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?f0(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&d0(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&go(e,c):typeof c=="number"&&go(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(po.hasOwnProperty(a)?c!=null&&a==="onScroll"&&yt("scroll",e):c!=null&&Hg(e,a,c,l))}switch(s){case"input":Ac(e),uw(e,r,!1);break;case"textarea":Ac(e),hw(e);break;case"option":r.value!=null&&e.setAttribute("value",""+li(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?Pa(e,!!r.multiple,a,!1):r.defaultValue!=null&&Pa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Yu)}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 mn(t),null;case 6:if(e&&t.stateNode!=null)ON(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(fe(166));if(s=Li(Eo.current),Li(Zs.current),Lc(t)){if(r=t.stateNode,s=t.memoizedProps,r[Ys]=t,(a=r.nodeValue!==s)&&(e=Yn,e!==null))switch(e.tag){case 3:Oc(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Oc(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Ys]=t,t.stateNode=r}return mn(t),null;case 13:if(bt(At),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(kt&&Vn!==null&&t.mode&1&&!(t.flags&128))eN(),Ga(),t.flags|=98560,a=!1;else if(a=Lc(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(fe(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(fe(317));a[Ys]=t}else Ga(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;mn(t),a=!1}else Ss!==null&&(rp(Ss),Ss=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||At.current&1?Gt===0&&(Gt=3):Cx())),t.updateQueue!==null&&(t.flags|=4),mn(t),null);case 4:return qa(),Qm(e,t),e===null&&ko(t.stateNode.containerInfo),mn(t),null;case 10:return cx(t.type._context),mn(t),null;case 17:return Mn(t.type)&&qu(),mn(t),null;case 19:if(bt(At),a=t.memoizedState,a===null)return mn(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)Fl(a,!1);else{if(Gt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=nd(e),l!==null){for(t.flags|=128,Fl(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 vt(At,At.current&1|2),t.child}e=e.sibling}a.tail!==null&&Ot()>Xa&&(t.flags|=128,r=!0,Fl(a,!1),t.lanes=4194304)}else{if(!r)if(e=nd(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),Fl(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!kt)return mn(t),null}else 2*Ot()-a.renderingStartTime>Xa&&s!==1073741824&&(t.flags|=128,r=!0,Fl(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=Ot(),t.sibling=null,s=At.current,vt(At,r?s&1|2:s&1),t):(mn(t),null);case 22:case 23:return Sx(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Hn&1073741824&&(mn(t),t.subtreeFlags&6&&(t.flags|=8192)):mn(t),null;case 24:return null;case 25:return null}throw Error(fe(156,t.tag))}function KI(e,t){switch(ix(t),t.tag){case 1:return Mn(t.type)&&qu(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return qa(),bt(Pn),bt(jn),mx(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return fx(t),null;case 13:if(bt(At),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(fe(340));Ga()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return bt(At),null;case 4:return qa(),null;case 10:return cx(t.type._context),null;case 22:case 23:return Sx(),null;case 24:return null;default:return null}}var zc=!1,pn=!1,VI=typeof WeakSet=="function"?WeakSet:Set,Ce=null;function Ra(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Mt(e,t,r)}else s.current=null}function Xm(e,t,s){try{s()}catch(r){Mt(e,t,r)}}var ty=!1;function GI(e,t){if(Mm=Ku,e=U0(),sx(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,f=e,m=null;t:for(;;){for(var p;f!==s||i!==0&&f.nodeType!==3||(o=l+i),f!==a||r!==0&&f.nodeType!==3||(c=l+r),f.nodeType===3&&(l+=f.nodeValue.length),(p=f.firstChild)!==null;)m=f,f=p;for(;;){if(f===e)break t;if(m===s&&++u===i&&(o=l),m===a&&++h===r&&(c=l),(p=f.nextSibling)!==null)break;f=m,m=f.parentNode}f=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(Dm={focusedElem:e,selectionRange:s},Ku=!1,Ce=t;Ce!==null;)if(t=Ce,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Ce=e;else for(;Ce!==null;){t=Ce;try{var g=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var v=g.memoizedProps,b=g.memoizedState,j=t.stateNode,x=j.getSnapshotBeforeUpdate(t.elementType===t.type?v:ks(t.type,v),b);j.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(fe(163))}}catch(y){Mt(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,Ce=e;break}Ce=t.return}return g=ty,ty=!1,g}function lo(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 Ud(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 Jm(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 LN(e){var t=e.alternate;t!==null&&(e.alternate=null,LN(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ys],delete t[So],delete t[_m],delete t[TI],delete t[RI])),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 _N(e){return e.tag===5||e.tag===3||e.tag===4}function ny(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||_N(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 Zm(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=Yu));else if(r!==4&&(e=e.child,e!==null))for(Zm(e,t,s),e=e.sibling;e!==null;)Zm(e,t,s),e=e.sibling}function ep(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(ep(e,t,s),e=e.sibling;e!==null;)ep(e,t,s),e=e.sibling}var an=null,Ns=!1;function zr(e,t,s){for(s=s.child;s!==null;)FN(e,t,s),s=s.sibling}function FN(e,t,s){if(Js&&typeof Js.onCommitFiberUnmount=="function")try{Js.onCommitFiberUnmount(Pd,s)}catch{}switch(s.tag){case 5:pn||Ra(s,t);case 6:var r=an,i=Ns;an=null,zr(e,t,s),an=r,Ns=i,an!==null&&(Ns?(e=an,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):an.removeChild(s.stateNode));break;case 18:an!==null&&(Ns?(e=an,s=s.stateNode,e.nodeType===8?tf(e.parentNode,s):e.nodeType===1&&tf(e,s),wo(e)):tf(an,s.stateNode));break;case 4:r=an,i=Ns,an=s.stateNode.containerInfo,Ns=!0,zr(e,t,s),an=r,Ns=i;break;case 0:case 11:case 14:case 15:if(!pn&&(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)}zr(e,t,s);break;case 1:if(!pn&&(Ra(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Mt(s,t,o)}zr(e,t,s);break;case 21:zr(e,t,s);break;case 22:s.mode&1?(pn=(r=pn)||s.memoizedState!==null,zr(e,t,s),pn=r):zr(e,t,s);break;default:zr(e,t,s)}}function sy(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new VI),t.forEach(function(r){var i=nP.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function bs(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:an=o.stateNode,Ns=!1;break e;case 3:an=o.stateNode.containerInfo,Ns=!0;break e;case 4:an=o.stateNode.containerInfo,Ns=!0;break e}o=o.return}if(an===null)throw Error(fe(160));FN(a,l,i),an=null,Ns=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Mt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)zN(t,e),t=t.sibling}function zN(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(bs(t,e),Bs(e),r&4){try{lo(3,e,e.return),Ud(3,e)}catch(v){Mt(e,e.return,v)}try{lo(5,e,e.return)}catch(v){Mt(e,e.return,v)}}break;case 1:bs(t,e),Bs(e),r&512&&s!==null&&Ra(s,s.return);break;case 5:if(bs(t,e),Bs(e),r&512&&s!==null&&Ra(s,s.return),e.flags&32){var i=e.stateNode;try{go(i,"")}catch(v){Mt(e,e.return,v)}}if(r&4&&(i=e.stateNode,i!=null)){var a=e.memoizedProps,l=s!==null?s.memoizedProps:a,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&a.type==="radio"&&a.name!=null&&o0(i,a),Nm(o,l);var u=Nm(o,a);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?f0(i,f):h==="dangerouslySetInnerHTML"?d0(i,f):h==="children"?go(i,f):Hg(i,h,f,u)}switch(o){case"input":jm(i,a);break;case"textarea":c0(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?Pa(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?Pa(i,!!a.multiple,a.defaultValue,!0):Pa(i,!!a.multiple,a.multiple?[]:"",!1))}i[So]=a}catch(v){Mt(e,e.return,v)}}break;case 6:if(bs(t,e),Bs(e),r&4){if(e.stateNode===null)throw Error(fe(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(v){Mt(e,e.return,v)}}break;case 3:if(bs(t,e),Bs(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{wo(t.containerInfo)}catch(v){Mt(e,e.return,v)}break;case 4:bs(t,e),Bs(e);break;case 13:bs(t,e),Bs(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(kx=Ot())),r&4&&sy(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(pn=(u=pn)||h,bs(t,e),pn=u):bs(t,e),Bs(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(Ce=e,h=e.child;h!==null;){for(f=Ce=h;Ce!==null;){switch(m=Ce,p=m.child,m.tag){case 0:case 11:case 14:case 15:lo(4,m,m.return);break;case 1:Ra(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{t=r,g.props=t.memoizedProps,g.state=t.memoizedState,g.componentWillUnmount()}catch(v){Mt(r,s,v)}}break;case 5:Ra(m,m.return);break;case 22:if(m.memoizedState!==null){iy(f);continue}}p!==null?(p.return=m,Ce=p):iy(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{i=f.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=h0("display",l))}catch(v){Mt(e,e.return,v)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(v){Mt(e,e.return,v)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;h===f&&(h=null),f=f.return}h===f&&(h=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:bs(t,e),Bs(e),r&4&&sy(e);break;case 21:break;default:bs(t,e),Bs(e)}}function Bs(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(_N(s)){var r=s;break e}s=s.return}throw Error(fe(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(go(i,""),r.flags&=-33);var a=ny(e);ep(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=ny(e);Zm(e,o,l);break;default:throw Error(fe(161))}}catch(c){Mt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function YI(e,t,s){Ce=e,UN(e)}function UN(e,t,s){for(var r=(e.mode&1)!==0;Ce!==null;){var i=Ce,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||zc;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||pn;o=zc;var u=pn;if(zc=l,(pn=c)&&!u)for(Ce=i;Ce!==null;)l=Ce,c=l.child,l.tag===22&&l.memoizedState!==null?ay(i):c!==null?(c.return=l,Ce=c):ay(i);for(;a!==null;)Ce=a,UN(a),a=a.sibling;Ce=i,zc=o,pn=u}ry(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,Ce=a):ry(e)}}function ry(e){for(;Ce!==null;){var t=Ce;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:pn||Ud(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!pn)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:ks(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&Bw(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}Bw(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var f=h.dehydrated;f!==null&&wo(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(fe(163))}pn||t.flags&512&&Jm(t)}catch(m){Mt(t,t.return,m)}}if(t===e){Ce=null;break}if(s=t.sibling,s!==null){s.return=t.return,Ce=s;break}Ce=t.return}}function iy(e){for(;Ce!==null;){var t=Ce;if(t===e){Ce=null;break}var s=t.sibling;if(s!==null){s.return=t.return,Ce=s;break}Ce=t.return}}function ay(e){for(;Ce!==null;){var t=Ce;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{Ud(4,t)}catch(c){Mt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Mt(t,i,c)}}var a=t.return;try{Jm(t)}catch(c){Mt(t,a,c)}break;case 5:var l=t.return;try{Jm(t)}catch(c){Mt(t,l,c)}}}catch(c){Mt(t,t.return,c)}if(t===e){Ce=null;break}var o=t.sibling;if(o!==null){o.return=t.return,Ce=o;break}Ce=t.return}}var qI=Math.ceil,id=Or.ReactCurrentDispatcher,yx=Or.ReactCurrentOwner,fs=Or.ReactCurrentBatchConfig,st=0,en=null,Ft=null,ln=0,Hn=0,$a=xi(0),Gt=0,$o=null,Vi=0,Bd=0,bx=0,oo=null,$n=null,kx=0,Xa=1/0,fr=null,ad=!1,tp=null,ti=null,Uc=!1,Gr=null,ld=0,co=0,np=null,ku=-1,Nu=0;function Nn(){return st&6?Ot():ku!==-1?ku:ku=Ot()}function ni(e){return e.mode&1?st&2&&ln!==0?ln&-ln:II.transition!==null?(Nu===0&&(Nu=S0()),Nu):(e=ht,e!==0||(e=window.event,e=e===void 0?16:I0(e.type)),e):1}function As(e,t,s,r){if(50<co)throw co=0,np=null,Error(fe(185));ec(e,s,r),(!(st&2)||e!==en)&&(e===en&&(!(st&2)&&(Bd|=s),Gt===4&&Kr(e,ln)),Dn(e,r),s===1&&st===0&&!(t.mode&1)&&(Xa=Ot()+500,_d&&vi()))}function Dn(e,t){var s=e.callbackNode;I$(e,t);var r=Hu(e,e===en?ln:0);if(r===0)s!==null&&pw(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&pw(s),t===1)e.tag===0?$I(ly.bind(null,e)):X0(ly.bind(null,e)),EI(function(){!(st&6)&&vi()}),s=null;else{switch(C0(r)){case 1:s=qg;break;case 4:s=k0;break;case 16:s=Wu;break;case 536870912:s=N0;break;default:s=Wu}s=qN(s,BN.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function BN(e,t){if(ku=-1,Nu=0,st&6)throw Error(fe(327));var s=e.callbackNode;if(_a()&&e.callbackNode!==s)return null;var r=Hu(e,e===en?ln:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=od(e,r);else{t=r;var i=st;st|=2;var a=HN();(en!==e||ln!==t)&&(fr=null,Xa=Ot()+500,Fi(e,t));do try{JI();break}catch(o){WN(e,o)}while(!0);ox(),id.current=a,st=i,Ft!==null?t=0:(en=null,ln=0,t=Gt)}if(t!==0){if(t===2&&(i=Tm(e),i!==0&&(r=i,t=sp(e,i))),t===1)throw s=$o,Fi(e,0),Kr(e,r),Dn(e,Ot()),s;if(t===6)Kr(e,r);else{if(i=e.current.alternate,!(r&30)&&!QI(i)&&(t=od(e,r),t===2&&(a=Tm(e),a!==0&&(r=a,t=sp(e,a))),t===1))throw s=$o,Fi(e,0),Kr(e,r),Dn(e,Ot()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(fe(345));case 2:$i(e,$n,fr);break;case 3:if(Kr(e,r),(r&130023424)===r&&(t=kx+500-Ot(),10<t)){if(Hu(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){Nn(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=Lm($i.bind(null,e,$n,fr),t);break}$i(e,$n,fr);break;case 4:if(Kr(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-Es(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=Ot()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*qI(r/1960))-r,10<r){e.timeoutHandle=Lm($i.bind(null,e,$n,fr),r);break}$i(e,$n,fr);break;case 5:$i(e,$n,fr);break;default:throw Error(fe(329))}}}return Dn(e,Ot()),e.callbackNode===s?BN.bind(null,e):null}function sp(e,t){var s=oo;return e.current.memoizedState.isDehydrated&&(Fi(e,t).flags|=256),e=od(e,t),e!==2&&(t=$n,$n=s,t!==null&&rp(t)),e}function rp(e){$n===null?$n=e:$n.push.apply($n,e)}function QI(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(!$s(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 Kr(e,t){for(t&=~bx,t&=~Bd,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-Es(t),r=1<<s;e[s]=-1,t&=~r}}function ly(e){if(st&6)throw Error(fe(327));_a();var t=Hu(e,0);if(!(t&1))return Dn(e,Ot()),null;var s=od(e,t);if(e.tag!==0&&s===2){var r=Tm(e);r!==0&&(t=r,s=sp(e,r))}if(s===1)throw s=$o,Fi(e,0),Kr(e,t),Dn(e,Ot()),s;if(s===6)throw Error(fe(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,$i(e,$n,fr),Dn(e,Ot()),null}function Nx(e,t){var s=st;st|=1;try{return e(t)}finally{st=s,st===0&&(Xa=Ot()+500,_d&&vi())}}function Gi(e){Gr!==null&&Gr.tag===0&&!(st&6)&&_a();var t=st;st|=1;var s=fs.transition,r=ht;try{if(fs.transition=null,ht=1,e)return e()}finally{ht=r,fs.transition=s,st=t,!(st&6)&&vi()}}function Sx(){Hn=$a.current,bt($a)}function Fi(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,CI(s)),Ft!==null)for(s=Ft.return;s!==null;){var r=s;switch(ix(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&qu();break;case 3:qa(),bt(Pn),bt(jn),mx();break;case 5:fx(r);break;case 4:qa();break;case 13:bt(At);break;case 19:bt(At);break;case 10:cx(r.type._context);break;case 22:case 23:Sx()}s=s.return}if(en=e,Ft=e=si(e.current,null),ln=Hn=t,Gt=0,$o=null,bx=Bd=Vi=0,$n=oo=null,Oi!==null){for(t=0;t<Oi.length;t++)if(s=Oi[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}Oi=null}return e}function WN(e,t){do{var s=Ft;try{if(ox(),wu.current=rd,sd){for(var r=Rt.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}sd=!1}if(Ki=0,Xt=Ht=Rt=null,ao=!1,Ao=0,yx.current=null,s===null||s.return===null){Gt=1,$o=t,Ft=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=ln,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,f=h.tag;if(!(h.mode&1)&&(f===0||f===11||f===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=Yw(l);if(p!==null){p.flags&=-257,qw(p,l,o,a,t),p.mode&1&&Gw(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var v=new Set;v.add(c),t.updateQueue=v}else g.add(c);break e}else{if(!(t&1)){Gw(a,u,t),Cx();break e}c=Error(fe(426))}}else if(kt&&o.mode&1){var b=Yw(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),qw(b,l,o,a,t),ax(Qa(c,o));break e}}a=c=Qa(c,o),Gt!==4&&(Gt=2),oo===null?oo=[a]:oo.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var j=CN(a,c,t);Uw(a,j);break e;case 1:o=c;var x=a.type,w=a.stateNode;if(!(a.flags&128)&&(typeof x.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(ti===null||!ti.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=EN(a,o,t);Uw(a,y);break e}}a=a.return}while(a!==null)}VN(s)}catch(k){t=k,Ft===s&&s!==null&&(Ft=s=s.return);continue}break}while(!0)}function HN(){var e=id.current;return id.current=rd,e===null?rd:e}function Cx(){(Gt===0||Gt===3||Gt===2)&&(Gt=4),en===null||!(Vi&268435455)&&!(Bd&268435455)||Kr(en,ln)}function od(e,t){var s=st;st|=2;var r=HN();(en!==e||ln!==t)&&(fr=null,Fi(e,t));do try{XI();break}catch(i){WN(e,i)}while(!0);if(ox(),st=s,id.current=r,Ft!==null)throw Error(fe(261));return en=null,ln=0,Gt}function XI(){for(;Ft!==null;)KN(Ft)}function JI(){for(;Ft!==null&&!k$();)KN(Ft)}function KN(e){var t=YN(e.alternate,e,Hn);e.memoizedProps=e.pendingProps,t===null?VN(e):Ft=t,yx.current=null}function VN(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=KI(s,t),s!==null){s.flags&=32767,Ft=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Gt=6,Ft=null;return}}else if(s=HI(s,t,Hn),s!==null){Ft=s;return}if(t=t.sibling,t!==null){Ft=t;return}Ft=t=e}while(t!==null);Gt===0&&(Gt=5)}function $i(e,t,s){var r=ht,i=fs.transition;try{fs.transition=null,ht=1,ZI(e,t,s,r)}finally{fs.transition=i,ht=r}return null}function ZI(e,t,s,r){do _a();while(Gr!==null);if(st&6)throw Error(fe(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(fe(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(P$(e,a),e===en&&(Ft=en=null,ln=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||Uc||(Uc=!0,qN(Wu,function(){return _a(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=fs.transition,fs.transition=null;var l=ht;ht=1;var o=st;st|=4,yx.current=null,GI(e,s),zN(s,e),jI(Dm),Ku=!!Mm,Dm=Mm=null,e.current=s,YI(s),N$(),st=o,ht=l,fs.transition=a}else e.current=s;if(Uc&&(Uc=!1,Gr=e,ld=i),a=e.pendingLanes,a===0&&(ti=null),E$(s.stateNode),Dn(e,Ot()),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(ad)throw ad=!1,e=tp,tp=null,e;return ld&1&&e.tag!==0&&_a(),a=e.pendingLanes,a&1?e===np?co++:(co=0,np=e):co=0,vi(),null}function _a(){if(Gr!==null){var e=C0(ld),t=fs.transition,s=ht;try{if(fs.transition=null,ht=16>e?16:e,Gr===null)var r=!1;else{if(e=Gr,Gr=null,ld=0,st&6)throw Error(fe(331));var i=st;for(st|=4,Ce=e.current;Ce!==null;){var a=Ce,l=a.child;if(Ce.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(Ce=u;Ce!==null;){var h=Ce;switch(h.tag){case 0:case 11:case 15:lo(8,h,a)}var f=h.child;if(f!==null)f.return=h,Ce=f;else for(;Ce!==null;){h=Ce;var m=h.sibling,p=h.return;if(LN(h),h===u){Ce=null;break}if(m!==null){m.return=p,Ce=m;break}Ce=p}}}var g=a.alternate;if(g!==null){var v=g.child;if(v!==null){g.child=null;do{var b=v.sibling;v.sibling=null,v=b}while(v!==null)}}Ce=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,Ce=l;else e:for(;Ce!==null;){if(a=Ce,a.flags&2048)switch(a.tag){case 0:case 11:case 15:lo(9,a,a.return)}var j=a.sibling;if(j!==null){j.return=a.return,Ce=j;break e}Ce=a.return}}var x=e.current;for(Ce=x;Ce!==null;){l=Ce;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Ce=w;else e:for(l=x;Ce!==null;){if(o=Ce,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Ud(9,o)}}catch(k){Mt(o,o.return,k)}if(o===l){Ce=null;break e}var y=o.sibling;if(y!==null){y.return=o.return,Ce=y;break e}Ce=o.return}}if(st=i,vi(),Js&&typeof Js.onPostCommitFiberRoot=="function")try{Js.onPostCommitFiberRoot(Pd,e)}catch{}r=!0}return r}finally{ht=s,fs.transition=t}}return!1}function oy(e,t,s){t=Qa(s,t),t=CN(e,t,1),e=ei(e,t,1),t=Nn(),e!==null&&(ec(e,1,t),Dn(e,t))}function Mt(e,t,s){if(e.tag===3)oy(e,e,s);else for(;t!==null;){if(t.tag===3){oy(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ti===null||!ti.has(r))){e=Qa(s,e),e=EN(t,e,1),t=ei(t,e,1),e=Nn(),t!==null&&(ec(t,1,e),Dn(t,e));break}}t=t.return}}function eP(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=Nn(),e.pingedLanes|=e.suspendedLanes&s,en===e&&(ln&s)===s&&(Gt===4||Gt===3&&(ln&130023424)===ln&&500>Ot()-kx?Fi(e,0):bx|=s),Dn(e,t)}function GN(e,t){t===0&&(e.mode&1?(t=$c,$c<<=1,!($c&130023424)&&($c=4194304)):t=1);var s=Nn();e=Tr(e,t),e!==null&&(ec(e,t,s),Dn(e,s))}function tP(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),GN(e,s)}function nP(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(fe(314))}r!==null&&r.delete(t),GN(e,s)}var YN;YN=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Pn.current)In=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return In=!1,WI(e,t,s);In=!!(e.flags&131072)}else In=!1,kt&&t.flags&1048576&&J0(t,Ju,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;bu(e,t),e=t.pendingProps;var i=Va(t,jn.current);La(t,s),i=gx(null,t,r,e,i,s);var a=xx();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,Mn(r)?(a=!0,Qu(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,dx(t),i.updater=zd,t.stateNode=i,i._reactInternals=t,Hm(t,r,e,s),t=Gm(null,t,r,!0,a,s)):(t.tag=0,kt&&a&&rx(t),bn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(bu(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=rP(r),e=ks(r,e),i){case 0:t=Vm(null,t,r,e,s);break e;case 1:t=Jw(null,t,r,e,s);break e;case 11:t=Qw(null,t,r,e,s);break e;case 14:t=Xw(null,t,r,ks(r.type,e),s);break e}throw Error(fe(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:ks(r,i),Vm(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:ks(r,i),Jw(e,t,r,i,s);case 3:e:{if($N(t),e===null)throw Error(fe(387));r=t.pendingProps,a=t.memoizedState,i=a.element,rN(e,t),td(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=Qa(Error(fe(423)),t),t=Zw(e,t,r,s,i);break e}else if(r!==i){i=Qa(Error(fe(424)),t),t=Zw(e,t,r,s,i);break e}else for(Vn=Zr(t.stateNode.containerInfo.firstChild),Yn=t,kt=!0,Ss=null,s=nN(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Ga(),r===i){t=Rr(e,t,s);break e}bn(e,t,r,s)}t=t.child}return t;case 5:return iN(t),e===null&&Um(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,Om(r,i)?l=null:a!==null&&Om(r,a)&&(t.flags|=32),RN(e,t),bn(e,t,l,s),t.child;case 6:return e===null&&Um(t),null;case 13:return IN(e,t,s);case 4:return hx(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Ya(t,null,r,s):bn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:ks(r,i),Qw(e,t,r,i,s);case 7:return bn(e,t,t.pendingProps,s),t.child;case 8:return bn(e,t,t.pendingProps.children,s),t.child;case 12:return bn(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,vt(Zu,r._currentValue),r._currentValue=l,a!==null)if($s(a.value,l)){if(a.children===i.children&&!Pn.current){t=Rr(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=br(-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),Bm(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(fe(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),Bm(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}bn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,La(t,s),i=ps(i),r=r(i),t.flags|=1,bn(e,t,r,s),t.child;case 14:return r=t.type,i=ks(r,t.pendingProps),i=ks(r.type,i),Xw(e,t,r,i,s);case 15:return AN(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:ks(r,i),bu(e,t),t.tag=1,Mn(r)?(e=!0,Qu(t)):e=!1,La(t,s),SN(t,r,i),Hm(t,r,i,s),Gm(null,t,r,!0,e,s);case 19:return PN(e,t,s);case 22:return TN(e,t,s)}throw Error(fe(156,t.tag))};function qN(e,t){return b0(e,t)}function sP(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 hs(e,t,s,r){return new sP(e,t,s,r)}function Ex(e){return e=e.prototype,!(!e||!e.isReactComponent)}function rP(e){if(typeof e=="function")return Ex(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Vg)return 11;if(e===Gg)return 14}return 2}function si(e,t){var s=e.alternate;return s===null?(s=hs(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 Su(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Ex(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case ya:return zi(s.children,i,a,t);case Kg:l=8,i|=8;break;case mm:return e=hs(12,s,t,i|2),e.elementType=mm,e.lanes=a,e;case pm:return e=hs(13,s,t,i),e.elementType=pm,e.lanes=a,e;case gm:return e=hs(19,s,t,i),e.elementType=gm,e.lanes=a,e;case i0:return Wd(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case s0:l=10;break e;case r0:l=9;break e;case Vg:l=11;break e;case Gg:l=14;break e;case Br:l=16,r=null;break e}throw Error(fe(130,e==null?e:typeof e,""))}return t=hs(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function zi(e,t,s,r){return e=hs(7,e,r,t),e.lanes=s,e}function Wd(e,t,s,r){return e=hs(22,e,r,t),e.elementType=i0,e.lanes=s,e.stateNode={isHidden:!1},e}function uf(e,t,s){return e=hs(6,e,null,t),e.lanes=s,e}function df(e,t,s){return t=hs(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function iP(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=Hh(0),this.expirationTimes=Hh(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Hh(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Ax(e,t,s,r,i,a,l,o,c){return e=new iP(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=hs(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},dx(a),e}function aP(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:wa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function QN(e){if(!e)return oi;e=e._reactInternals;e:{if(ta(e)!==e||e.tag!==1)throw Error(fe(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Mn(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(fe(171))}if(e.tag===1){var s=e.type;if(Mn(s))return Q0(e,s,t)}return t}function XN(e,t,s,r,i,a,l,o,c){return e=Ax(s,r,!0,e,i,a,l,o,c),e.context=QN(null),s=e.current,r=Nn(),i=ni(s),a=br(r,i),a.callback=t??null,ei(s,a,i),e.current.lanes=i,ec(e,i,r),Dn(e,r),e}function Hd(e,t,s,r){var i=t.current,a=Nn(),l=ni(i);return s=QN(s),t.context===null?t.context=s:t.pendingContext=s,t=br(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=ei(i,t,l),e!==null&&(As(e,i,l,a),ju(e,i,l)),l}function cd(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 cy(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function Tx(e,t){cy(e,t),(e=e.alternate)&&cy(e,t)}function lP(){return null}var JN=typeof reportError=="function"?reportError:function(e){console.error(e)};function Rx(e){this._internalRoot=e}Kd.prototype.render=Rx.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(fe(409));Hd(e,t,null,null)};Kd.prototype.unmount=Rx.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Gi(function(){Hd(null,e,null,null)}),t[Ar]=null}};function Kd(e){this._internalRoot=e}Kd.prototype.unstable_scheduleHydration=function(e){if(e){var t=T0();e={blockedOn:null,target:e,priority:t};for(var s=0;s<Hr.length&&t!==0&&t<Hr[s].priority;s++);Hr.splice(s,0,e),s===0&&$0(e)}};function $x(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Vd(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function uy(){}function oP(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=cd(l);a.call(u)}}var l=XN(t,r,e,0,null,!1,!1,"",uy);return e._reactRootContainer=l,e[Ar]=l.current,ko(e.nodeType===8?e.parentNode:e),Gi(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=cd(c);o.call(u)}}var c=Ax(e,0,!1,null,null,!1,!1,"",uy);return e._reactRootContainer=c,e[Ar]=c.current,ko(e.nodeType===8?e.parentNode:e),Gi(function(){Hd(t,c,s,r)}),c}function Gd(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=cd(l);o.call(c)}}Hd(t,l,e,i)}else l=oP(s,t,e,i,r);return cd(l)}E0=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=Ql(t.pendingLanes);s!==0&&(Qg(t,s|1),Dn(t,Ot()),!(st&6)&&(Xa=Ot()+500,vi()))}break;case 13:Gi(function(){var r=Tr(e,1);if(r!==null){var i=Nn();As(r,e,1,i)}}),Tx(e,1)}};Xg=function(e){if(e.tag===13){var t=Tr(e,134217728);if(t!==null){var s=Nn();As(t,e,134217728,s)}Tx(e,134217728)}};A0=function(e){if(e.tag===13){var t=ni(e),s=Tr(e,t);if(s!==null){var r=Nn();As(s,e,t,r)}Tx(e,t)}};T0=function(){return ht};R0=function(e,t){var s=ht;try{return ht=e,t()}finally{ht=s}};Cm=function(e,t,s){switch(t){case"input":if(jm(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=Ld(r);if(!i)throw Error(fe(90));l0(r),jm(r,i)}}}break;case"textarea":c0(e,s);break;case"select":t=s.value,t!=null&&Pa(e,!!s.multiple,t,!1)}};g0=Nx;x0=Gi;var cP={usingClientEntryPoint:!1,Events:[nc,Sa,Ld,m0,p0,Nx]},zl={findFiberByHostInstance:Di,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},uP={bundleType:zl.bundleType,version:zl.version,rendererPackageName:zl.rendererPackageName,rendererConfig:zl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Or.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=w0(e),e===null?null:e.stateNode},findFiberByHostInstance:zl.findFiberByHostInstance||lP,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 Bc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Bc.isDisabled&&Bc.supportsFiber)try{Pd=Bc.inject(uP),Js=Bc}catch{}}Jn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=cP;Jn.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!$x(t))throw Error(fe(200));return aP(e,t,null,s)};Jn.createRoot=function(e,t){if(!$x(e))throw Error(fe(299));var s=!1,r="",i=JN;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Ax(e,1,!1,null,null,s,!1,r,i),e[Ar]=t.current,ko(e.nodeType===8?e.parentNode:e),new Rx(t)};Jn.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(fe(188)):(e=Object.keys(e).join(","),Error(fe(268,e)));return e=w0(t),e=e===null?null:e.stateNode,e};Jn.flushSync=function(e){return Gi(e)};Jn.hydrate=function(e,t,s){if(!Vd(t))throw Error(fe(200));return Gd(null,e,t,!0,s)};Jn.hydrateRoot=function(e,t,s){if(!$x(e))throw Error(fe(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=JN;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=XN(t,null,e,1,s??null,i,!1,a,l),e[Ar]=t.current,ko(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 Kd(t)};Jn.render=function(e,t,s){if(!Vd(t))throw Error(fe(200));return Gd(null,e,t,!1,s)};Jn.unmountComponentAtNode=function(e){if(!Vd(e))throw Error(fe(40));return e._reactRootContainer?(Gi(function(){Gd(null,null,e,!1,function(){e._reactRootContainer=null,e[Ar]=null})}),!0):!1};Jn.unstable_batchedUpdates=Nx;Jn.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Vd(s))throw Error(fe(200));if(e==null||e._reactInternals===void 0)throw Error(fe(38));return Gd(e,t,s,!1,r)};Jn.version="18.3.1-next-f1338f8080-20240426";function ZN(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(ZN)}catch(e){console.error(e)}}ZN(),Zk.exports=Jn;var hl=Zk.exports,eS,dy=hl;eS=dy.createRoot,dy.hydrateRoot;var dP=Object.defineProperty,fl=(e,t)=>dP(e,"name",{value:t,configurable:!0}),tS=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ie(e,t,{checkForDefaultPrevented:s=!0}={}){return fl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}fl(Ie,"composeEventHandlers");function hP(e){var t;if(!tS)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}fl(hP,"getOwnerWindow");function ip(e){if(!tS)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}fl(ip,"getOwnerDocument");function nS(e,t=!1){const{activeElement:s}=ip(e);if(!(s!=null&&s.nodeName))return null;if(sS(s)&&s.contentDocument)return nS(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=ip(s).getElementById(r);if(i)return i}}return s}fl(nS,"getActiveElement");function sS(e){return e.tagName==="IFRAME"}fl(sS,"isFrame");var fP=Object.defineProperty,Ix=(e,t)=>fP(e,"name",{value:t,configurable:!0});function ap(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Ix(ap,"setRef");function rS(...e){return t=>{let s=!1;const r=e.map(i=>{const a=ap(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():ap(e[i],null)}}}}Ix(rS,"composeRefs");function jt(...e){return d.useCallback(rS(...e),e)}Ix(jt,"useComposedRefs");var mP=Object.defineProperty,ds=(e,t)=>mP(e,"name",{value:t,configurable:!0});function pP(e,t){const s=d.createContext(t);s.displayName=e+"Context";const r=ds(a=>{const{children:l,...o}=a,c=d.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=d.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return ds(i,"useContext"),[r,i]}ds(pP,"createContext");function Ms(e,t=[]){let s=[];function r(a,l){const o=d.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=ds(f=>{var j;const{scope:m,children:p,...g}=f,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=d.useMemo(()=>g,Object.values(g));return n.jsx(v.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function h(f,m,p={}){var j;const{optional:g=!1}=p,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=d.useContext(v);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${a}\``)}return ds(h,"useContext"),[u,h]}ds(r,"createContext");const i=ds(()=>{const a=s.map(l=>d.createContext(l));return ds(function(o){const c=(o==null?void 0:o[e])||a;return d.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,iS(i,...t)]}ds(Ms,"createContextScope");function iS(...e){const t=e[0];if(e.length===1)return t;const s=ds(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return ds(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...o,...f}},{});return d.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}ds(iS,"composeContextScopes");var gP=Object.defineProperty,Ds=(e,t)=>gP(e,"name",{value:t,configurable:!0});function ci(e){const t=d.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];lp(i)&&typeof Wc=="function"&&(i=Wc(i._payload)),d.Children.forEach(i,m=>{var p;if(uS(m)){o=!0;const g=m;let v="child"in g.props?g.props.child:g.props.children;lp(v)&&typeof Wc=="function"&&(v=Wc(v._payload)),l=xP(g,v),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(i)===1&&d.isValidElement(i)&&(l=i);const u=l?cS(l):void 0,h=jt(r,u);if(!l){if(i||i===0)throw new Error(o?wP(e):jP(e));return i}const f=oS(a,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return t.displayName=`${e}.Slot`,t}Ds(ci,"createSlot");var aS=Symbol.for("radix.slottable");function lS(e){const t=Ds(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=aS,t}Ds(lS,"createSlottable");var xP=Ds((e,t)=>{if("child"in e.props){const s=e.props.child;return d.isValidElement(s)?d.cloneElement(s,void 0,e.props.children(s.props.children)):null}return d.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function oS(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}}Ds(oS,"mergeProps");function cS(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)}Ds(cS,"getElementRef");function uS(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===aS}Ds(uS,"isSlottable");var vP=Symbol.for("react.lazy");function lp(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===vP&&"_payload"in e&&dS(e._payload)}Ds(lp,"isLazyComponent");function dS(e){return typeof e=="object"&&e!==null&&"then"in e}Ds(dS,"isPromiseLike");var jP=Ds(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),wP=Ds(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Wc=cl[" use ".trim().toString()],yP=Object.defineProperty,Jt=(e,t)=>yP(e,"name",{value:t,configurable:!0});function Yd(e){const t=e+"CollectionProvider",[s,r]=Ms(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=Jt(v=>{const{scope:b,children:j}=v,x=d.useRef(null),w=d.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:w,collectionRef:x,children:j})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=ci(o),u=d.forwardRef((v,b)=>{const{scope:j,children:x}=v,w=a(o,j),y=jt(b,w.collectionRef);return n.jsx(c,{ref:y,children:x})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=ci(h),p=d.forwardRef((v,b)=>{const{scope:j,children:x,...w}=v,y=d.useRef(null),k=jt(b,y),N=a(h,j);return d.useEffect(()=>(N.itemMap.set(y,{ref:y,...w}),()=>void N.itemMap.delete(y))),n.jsx(m,{[f]:"",ref:k,children:x})});p.displayName=h;function g(v){const b=a(e+"CollectionConsumer",v);return d.useCallback(()=>{const x=b.collectionRef.current;if(!x)return[];const w=Array.from(x.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((N,S)=>w.indexOf(N.ref.current)-w.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return Jt(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}Jt(Yd,"createCollection");var hy=new WeakMap,_t,Kn,hf=(Kn=class extends Map{constructor(s){super(s);nw(this,_t);_h(this,_t,[...super.keys()]),hy.set(this,!0)}set(s,r){return hy.get(this)&&(this.has(s)?hn(this,_t)[hn(this,_t).indexOf(s)]=s:hn(this,_t).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=hn(this,_t).length,o=Px(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||a&&u===this.size-1||u===-1)return this.set(r,i),this;const h=this.size+(a?0:1);o<0&&c++;const f=[...hn(this,_t)];let m,p=!1;for(let g=c;g<h;g++)if(c===g){let v=f[g];f[g]===r&&(v=f[g+1]),a&&this.delete(r),m=this.get(v),this.set(r,i)}else{!p&&f[g-1]===r&&(p=!0);const v=f[p?g:g-1],b=m;m=this.get(v),this.delete(v),this.set(v,b)}return this}with(s,r,i){const a=new Kn(this);return a.insert(s,r,i),a}before(s){const r=hn(this,_t).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=hn(this,_t).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=hn(this,_t).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=hn(this,_t).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return _h(this,_t,[]),super.clear()}delete(s){const r=super.delete(s);return r&&hn(this,_t).splice(hn(this,_t).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=Cu(hn(this,_t),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=Cu(hn(this,_t),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return hn(this,_t).indexOf(s)}keyAt(s){return Cu(hn(this,_t),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 Kn(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 Kn(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 Kn(r)}toReversed(){const s=new Kn;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 Kn(r)}slice(s,r){const i=new Kn;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}},_t=new WeakMap,Jt(Kn,"OrderedDict"),Kn);function Cu(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=hS(e,t);return s===-1?void 0:e[s]}Jt(Cu,"at");function hS(e,t){const s=e.length,r=Px(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}Jt(hS,"toSafeIndex");function Px(e){return e!==e||e===0?0:Math.trunc(e)}Jt(Px,"toSafeInteger");function bP(e){const t=e+"CollectionProvider",[s,r]=Ms(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new hf,setItemMap:Jt(()=>{},"setItemMap")}),l=Jt(({state:w,...y})=>w?n.jsx(c,{...y,state:w}):n.jsx(o,{...y}),"CollectionProvider");l.displayName=t;const o=Jt(w=>{const y=b();return n.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=t+"Init";const c=Jt(w=>{const{scope:y,children:k,state:N}=w,S=d.useRef(null),[C,$]=d.useState(null),R=jt(S,$),[I,F]=N;return d.useEffect(()=>{if(!C)return;const _=pS(()=>{});return _.observe(C,{childList:!0,subtree:!0}),()=>{_.disconnect()}},[C]),n.jsx(i,{scope:y,itemMap:I,setItemMap:F,collectionRef:R,collectionRefObject:S,collectionElement:C,children:k})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",h=ci(u),f=d.forwardRef((w,y)=>{const{scope:k,children:N}=w,S=a(u,k),C=jt(y,S.collectionRef);return n.jsx(h,{ref:C,children:N})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=ci(m),v=d.forwardRef((w,y)=>{const{scope:k,children:N,...S}=w,C=d.useRef(null),[$,R]=d.useState(null),I=jt(y,C,R),F=a(m,k),{setItemMap:_}=F,E=d.useRef(S);fS(E.current,S)||(E.current=S);const M=E.current;return d.useEffect(()=>{const P=M;return _(U=>$?U.has($)?U.set($,{...P,element:$}).toSorted(op):(U.set($,{...P,element:$}),U.toSorted(op)):U),()=>{_(U=>!$||!U.has($)?U:(U.delete($),new hf(U)))}},[$,M,_]),n.jsx(g,{[p]:"",ref:I,children:N})});v.displayName=m;function b(){return d.useState(new hf)}Jt(b,"useInitCollection");function j(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return Jt(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:v},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}Jt(bP,"createCollection");function fS(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}Jt(fS,"shallowEqual");function mS(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Jt(mS,"isElementPreceding");function op(e,t){return!e[1].element||!t[1].element?0:mS(e[1].element,t[1].element)?-1:1}Jt(op,"sortByDocumentPosition");function pS(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Jt(pS,"getChildListObserver");var kP=Object.defineProperty,NP=(e,t)=>kP(e,"name",{value:t,configurable:!0}),SP=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],mt=SP.reduce((e,t)=>{const s=ci(`Primitive.${t}`),r=d.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function qd(e,t){e&&hl.flushSync(()=>e.dispatchEvent(t))}NP(qd,"dispatchDiscreteCustomEvent");var CP=Object.defineProperty,EP=(e,t)=>CP(e,"name",{value:t,configurable:!0});function Sn(e){const t=d.useRef(e);return d.useEffect(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}EP(Sn,"useCallbackRef");var AP=Object.defineProperty,Kt=(e,t)=>AP(e,"name",{value:t,configurable:!0}),cp="dismissableLayer.update",TP="dismissableLayer.pointerDownOutside",RP="dismissableLayer.focusOutside",fy,Mx=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Qd=d.forwardRef(Kt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=t,f=d.useContext(Mx),[m,p]=d.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,v]=d.useState({}),b=jt(s,p),j=Array.from(f.layers),[x]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=x?j.indexOf(x):-1,y=m?j.indexOf(m):-1,k=f.layersWithOutsidePointerEventsDisabled.size>0,N=y>=w,S=d.useRef(!1),C=xS(F=>{l==null||l(F),c==null||c(F),F.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(F=>{if(!(F instanceof Node))return!1;const _=[...f.branches].some(E=>E.contains(F));return N&&!_},[f.branches,N])}),$=vS(F=>{if(i&&S.current)return;const _=F.target;[...f.branches].some(M=>M.contains(_))||(o==null||o(F),c==null||c(F),F.defaultPrevented||u==null||u())},g),R=m?y===j.length-1:!1,I=Sn(F=>{F.key==="Escape"&&(a==null||a(F),!F.defaultPrevented&&u&&(F.preventDefault(),u()))});return d.useEffect(()=>{if(R)return g.addEventListener("keydown",I,{capture:!0}),()=>g.removeEventListener("keydown",I,{capture:!0})},[g,R,I]),d.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(fy=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),up(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=fy))}},[m,g,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),up())},[m,f]),d.useEffect(()=>{const F=Kt(()=>v({}),"handleUpdate");return document.addEventListener(cp,F),()=>document.removeEventListener(cp,F)},[]),n.jsx(mt.div,{...h,ref:b,style:{pointerEvents:k?N?"auto":"none":void 0,...t.style},onFocusCapture:Ie(t.onFocusCapture,$.onFocusCapture),onBlurCapture:Ie(t.onBlurCapture,$.onBlurCapture),onPointerDownCapture:Ie(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),$P=d.forwardRef(Kt(function(t,s){const r=d.useContext(Mx),i=d.useRef(null),a=jt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(mt.div,{...t,ref:a})},"DismissableLayerBranch"));function gS(){const e=d.useContext(Mx),[t,s]=d.useState(null);return d.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Kt(gS,"useDismissableLayerSurface");var IP=Kt(()=>!0,"IS_TRUE");function xS(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=IP}=t,o=Sn(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),f=d.useRef(()=>{});return d.useEffect(()=>{function m(){u.current=!1,i.current=!1,h.current.clear()}Kt(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}Kt(p,"isOutsideInteractionIntercepted");function g(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...a].some(N=>N.contains(y))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}Kt(g,"handleInteractionCapture");function v(w){u.current&&h.current.set(w.type,!1)}Kt(v,"handleInteractionBubble");const b=Kt(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",f.current);const N=p();m(),N||Dx(TP,o,k,{discrete:!0})};if(Kt(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const k={originalEvent:w};u.current=!0,i.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?y():(s.removeEventListener("click",f.current),f.current=y,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),m();c.current=!1},"handlePointerDown"),j=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of j)s.addEventListener(w,g,!0),s.addEventListener(w,v);const x=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(x),s.removeEventListener("pointerdown",b),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,g,!0),s.removeEventListener(w,v)}},[s,o,r,i,a,l]),{onPointerDownCapture:Kt(()=>c.current=!0,"onPointerDownCapture")}}Kt(xS,"usePointerDownOutside");function vS(e,t=globalThis==null?void 0:globalThis.document){const s=Sn(e),r=d.useRef(!1);return d.useEffect(()=>{const i=Kt(a=>{a.target&&!r.current&&Dx(RP,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:Kt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Kt(()=>r.current=!1,"onBlurCapture")}}Kt(vS,"useFocusOutside");function up(){const e=new CustomEvent(cp);document.dispatchEvent(e)}Kt(up,"dispatchUpdate");function Dx(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?qd(i,a):i.dispatchEvent(a)}Kt(Dx,"handleAndDispatchCustomEvent");var PP=Qd,MP=$P,On=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},DP=Object.defineProperty,OP=(e,t)=>DP(e,"name",{value:t,configurable:!0}),Xd=d.forwardRef(OP(function(t,s){var c;const{container:r,...i}=t,[a,l]=d.useState(!1);On(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?hl.createPortal(n.jsx(mt.div,{...i,ref:s}),o):null},"Portal")),LP=Object.defineProperty,$r=(e,t)=>LP(e,"name",{value:t,configurable:!0});function jS(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}$r(jS,"useStateMachine");var lr=$r(e=>{const{present:t,children:s}=e,r=wS(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=yS(r.ref,bS(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null},"Presence");function wS(e){const[t,s]=d.useState(),r=d.useRef(null),i=d.useRef(e),a=d.useRef("none"),l=d.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=jS(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{c==="mounted"?(a.current=l.current??ja(r.current),l.current=void 0):a.current="none"},[c]),On(()=>{const h=r.current,f=i.current;if(f!==e){const p=a.current,g=ja(h);e?(l.current=g,u("MOUNT")):g==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),On(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=$r(g=>{const b=ja(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(u("ANIMATION_END"),!i.current)){const j=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},"handleAnimationEnd"),p=$r(g=>{g.target===t&&(a.current=ja(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=ja(f)}else r.current=null;s(h)},[])}}$r(wS,"usePresence");function dp(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}$r(dp,"setRef");function yS(...e){const t=d.useRef(e);return t.current=e,d.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=dp(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():dp(r[l],null)}}},[])}$r(yS,"useStableComposedRefs");function ja(e){return(e==null?void 0:e.animationName)||"none"}$r(ja,"getAnimationName");function bS(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)}$r(bS,"getElementRef");var _P=Object.defineProperty,FP=(e,t)=>_P(e,"name",{value:t,configurable:!0}),my=cl[" useEffectEvent ".trim().toString()],py=cl[" useInsertionEffect ".trim().toString()];function kS(e){if(typeof my=="function")return my(e);const t=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof py=="function"?py(()=>{t.current=e}):On(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}FP(kS,"useEffectEvent");var zP=Object.defineProperty,rc=(e,t)=>zP(e,"name",{value:t,configurable:!0}),UP=cl[" useInsertionEffect ".trim().toString()]||On;function ji({prop:e,defaultProp:t,onChange:s=rc(()=>{},"onChange"),caller:r}){const[i,a,l]=NS({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=d.useCallback(h=>{var f;if(o){const m=SS(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}rc(ji,"useControllableState");function NS({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return UP(()=>{a.current=t},[t]),d.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}rc(NS,"useUncontrolledState");function SS(e){return typeof e=="function"}rc(SS,"isFunction");var gy=Symbol("RADIX:SYNC_STATE");function BP(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=kS(l),h=[{...s,state:a}];r&&h.push(r);const[f,m]=d.useReducer((b,j)=>{if(j.type===gy)return{...b,state:j.state};const x=e(b,j);return c&&!Object.is(x.state,b.state)&&u(x.state),x},...h),p=f.state,g=d.useRef(p);d.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const v=d.useMemo(()=>i!==void 0?{...f,state:i}:f,[f,i]);return d.useEffect(()=>{c&&!Object.is(i,f.state)&&m({type:gy,state:i})},[i,f.state,c]),[v,m]}rc(BP,"useControllableStateReducer");var WP=Object.defineProperty,HP=(e,t)=>WP(e,"name",{value:t,configurable:!0}),KP=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"}),Ox=d.forwardRef(HP(function(t,s){return n.jsx(mt.span,{...t,ref:s,style:{...KP,...t.style}})},"VisuallyHidden")),VP=Ox,GP=Object.defineProperty,gt=(e,t)=>GP(e,"name",{value:t,configurable:!0}),CS="ToastProvider",[Lx,ES,YP]=Yd("Toast"),[AS,mY]=Ms("Toast",[YP]),[qP,Jd]=AS(CS),QP=gt(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=d.useState(null),[h,f]=d.useState(0),m=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${CS}\`. Expected non-empty \`string\`.`),n.jsx(Lx.Provider,{scope:t,children:n.jsx(qP,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>f(p=>p+1),[]),onToastRemove:d.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),XP="ToastViewport",JP=["F8"],hp="toast.viewportPause",fp="toast.viewportResume",ZP=d.forwardRef(gt(function(t,s){const{__scopeToast:r,hotkey:i=JP,label:a="Notifications ({hotkey})",...l}=t,o=Jd(XP,r),c=ES(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=jt(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=o.toastCount>0;d.useEffect(()=>{const j=gt(x=>{var y;i.length!==0&&i.every(k=>x[k]||x.code===k)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[i]),d.useEffect(()=>{const j=u.current,x=m.current;if(v&&j&&x){const w=gt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(hp);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=gt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(fp);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),k=gt(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),N=gt(()=>{j.contains(document.activeElement)||y()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",k),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",N),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",k),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",N),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[v,o.isClosePausedRef]);const b=d.useCallback(({tabbingDirection:j})=>{const w=c().map(y=>{const k=y.ref.current,N=[k,...IS(k)];return j==="forwards"?N:N.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return d.useEffect(()=>{const j=m.current;if(j){const x=gt(w=>{var N,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const $=document.activeElement,R=w.shiftKey;if(w.target===j&&R){(N=h.current)==null||N.focus();return}const _=b({tabbingDirection:R?"backwards":"forwards"}),E=_.findIndex(M=>M===$);Eu(_.slice(E+1))?w.preventDefault():R?(S=h.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",x),()=>j.removeEventListener("keydown",x)}},[c,b]),n.jsxs(MP,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&n.jsx(xy,{ref:h,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});Eu(j)}}),n.jsx(Lx.Slot,{scope:r,children:n.jsx(mt.ol,{tabIndex:-1,...l,ref:p})}),v&&n.jsx(xy,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});Eu(j)}})]})},"ToastViewport")),e2="ToastFocusProxy",xy=d.forwardRef(gt(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=Jd(e2,r);return n.jsx(Ox,{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")),Zd="Toast",t2="toast.swipeStart",n2="toast.swipeMove",s2="toast.swipeCancel",r2="toast.swipeEnd",i2=d.forwardRef(gt(function(t,s){const{forceMount:r,open:i,defaultOpen:a,onOpenChange:l,...o}=t,[c,u]=ji({prop:i,defaultProp:a??!0,onChange:l,caller:Zd});return n.jsx(lr,{present:r||c,children:n.jsx(o2,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Sn(t.onPause),onResume:Sn(t.onResume),onSwipeStart:Ie(t.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Ie(t.onSwipeMove,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:Ie(t.onSwipeCancel,h=>{h.currentTarget.setAttribute("data-swipe","cancel"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Ie(t.onSwipeEnd,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","end"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[a2,l2]=AS(Zd,{onClose(){}}),o2=d.forwardRef(gt(function(t,s){const{__scopeToast:r,type:i="foreground",duration:a,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...v}=t,b=Jd(Zd,r),j=ES(r),[x,w]=d.useState(null),y=jt(s,w),k=d.useRef(null),N=d.useRef(null),S=a||b.duration,C=d.useRef(0),$=d.useRef(S),R=d.useRef(0),{onToastAdd:I,onToastRemove:F}=b,_=Sn(()=>{var U;(x==null?void 0:x.contains(document.activeElement))&&((U=b.viewport)==null||U.focus()),o()}),E=d.useCallback(P=>{!P||P===1/0||(window.clearTimeout(R.current),C.current=new Date().getTime(),R.current=window.setTimeout(_,P))},[_]);d.useEffect(()=>{const P=b.viewport;if(P){const U=gt(()=>{E($.current),h==null||h()},"handleResume"),L=gt(()=>{const W=new Date().getTime()-C.current;$.current=$.current-W,window.clearTimeout(R.current),u==null||u()},"handlePause");return P.addEventListener(hp,L),P.addEventListener(fp,U),()=>{P.removeEventListener(hp,L),P.removeEventListener(fp,U)}}},[b.viewport,S,u,h,E]),d.useEffect(()=>{l&&!b.isClosePausedRef.current&&E(S)},[l,S,b.isClosePausedRef,E]),d.useEffect(()=>()=>{window.clearTimeout(R.current)},[]),d.useEffect(()=>(I(),()=>F()),[I,F]);const M=d.useMemo(()=>x?_x(x):null,[x]);return b.viewport?n.jsxs(n.Fragment,{children:[M&&n.jsx(c2,{__scopeToast:r,role:"status","aria-live":i==="foreground"?"assertive":"polite",children:M}),n.jsx(a2,{scope:r,onClose:_,children:hl.createPortal(n.jsx(Lx.ItemSlot,{scope:r,children:n.jsx(PP,{asChild:!0,onEscapeKeyDown:Ie(c,P=>{j().some(L=>{var W;return(W=L.ref.current)==null?void 0:W.contains(P.target)})||_()}),children:n.jsx(mt.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":b.swipeDirection,...v,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:Ie(t.onKeyDown,P=>{P.key==="Escape"&&(c==null||c(P.nativeEvent),P.nativeEvent.defaultPrevented||_())}),onPointerDown:Ie(t.onPointerDown,P=>{P.button===0&&(k.current={x:P.clientX,y:P.clientY})}),onPointerMove:Ie(t.onPointerMove,P=>{if(!k.current)return;const U=P.clientX-k.current.x,L=P.clientY-k.current.y,W=!!N.current,O=["left","right"].includes(b.swipeDirection),V=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,X=O?V(0,U):0,G=O?0:V(0,L),Z=P.pointerType==="touch"?10:2,z={x:X,y:G},q={originalEvent:P,delta:z};W?(N.current=z,Jl(n2,m,q,{discrete:!1})):vy(z,b.swipeDirection,Z)?(N.current=z,Jl(t2,f,q,{discrete:!1}),P.target.setPointerCapture(P.pointerId)):(Math.abs(U)>Z||Math.abs(L)>Z)&&(k.current=null)}),onPointerUp:Ie(t.onPointerUp,P=>{const U=N.current,L=P.target;if(L.hasPointerCapture(P.pointerId)&&L.releasePointerCapture(P.pointerId),N.current=null,k.current=null,U){const W=P.currentTarget,O={originalEvent:P,delta:U};vy(U,b.swipeDirection,b.swipeThreshold)?Jl(r2,g,O,{discrete:!0}):Jl(s2,p,O,{discrete:!0}),W.addEventListener("click",V=>V.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),c2=gt(e=>{const{__scopeToast:t,children:s,...r}=e,i=Jd(Zd,t),[a,l]=d.useState(!1),[o,c]=d.useState(!1);return RS(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:n.jsx(Xd,{asChild:!0,container:i.announcerContainer||void 0,children:n.jsx(Ox,{...r,children:a&&n.jsxs(n.Fragment,{children:[i.label," ",s]})})})},"ToastAnnounce"),u2=d.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(mt.div,{...i,ref:s})},"ToastTitle")),d2=d.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(mt.div,{...i,ref:s})},"ToastDescription")),h2="ToastAction",f2=d.forwardRef(gt(function(t,s){const{altText:r,...i}=t;return r.trim()?n.jsx(TS,{altText:r,asChild:!0,children:n.jsx(p2,{...i,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${h2}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),m2="ToastClose",p2=d.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t,a=l2(m2,r);return n.jsx(TS,{asChild:!0,children:n.jsx(mt.button,{type:"button",...i,ref:s,onClick:Ie(t.onClick,a.onClose)})})},"ToastClose")),TS=d.forwardRef(gt(function(t,s){const{__scopeToast:r,altText:i,...a}=t;return n.jsx(mt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":i||void 0,...a,ref:s})},"ToastAnnounceExclude"));function _x(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),$S(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(..._x(r))}}),t}gt(_x,"getAnnounceTextContent");function Jl(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?qd(i,a):i.dispatchEvent(a)}gt(Jl,"handleAndDispatchCustomEvent");var vy=gt((e,t,s=0)=>{const r=Math.abs(e.x),i=Math.abs(e.y),a=r>i;return t==="left"||t==="right"?a&&r>s:!a&&i>s},"isDeltaInDirection");function RS(e=()=>{}){const t=Sn(e);On(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}gt(RS,"useNextFrame");function $S(e){return e.nodeType===e.ELEMENT_NODE}gt($S,"isHTMLElement");function IS(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:gt(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}gt(IS,"getTabbableCandidates");function Eu(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}gt(Eu,"focusFirst");var jy=QP,wy=ZP,g2=i2,x2=u2,v2=d2,j2=f2,w2=Object.defineProperty,y2=(e,t)=>w2(e,"name",{value:t,configurable:!0}),b2=cl[" useId ".trim().toString()]||(()=>{}),k2=0;function Ts(e){const[t,s]=d.useState(b2());return On(()=>{e||s(r=>r??String(k2++))},[e]),e||(t?`radix-${t}`:"")}y2(Ts,"useId");const N2=["top","right","bottom","left"],ui=Math.min,kr=Math.max,ud=Math.round,Hc=Math.floor,Nr=e=>({x:e,y:e}),S2={left:"right",right:"left",bottom:"top",top:"bottom"};function PS(e,t,s){return kr(e,ui(t,s))}function Ir(e,t){return typeof e=="function"?e(t):e}function di(e){return e.split("-")[0]}function ml(e){return e.split("-")[1]}function Fx(e){return e==="x"?"y":"x"}function zx(e){return e==="y"?"height":"width"}function Qs(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Ux(e){return Fx(Qs(e))}function C2(e,t,s){s===void 0&&(s=!1);const r=ml(e),i=Ux(e),a=zx(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=dd(l)),[l,dd(l)]}function E2(e){const t=dd(e);return[mp(e),t,mp(t)]}function mp(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const yy=["left","right"],by=["right","left"],A2=["top","bottom"],T2=["bottom","top"];function R2(e,t,s){switch(e){case"top":case"bottom":return s?t?by:yy:t?yy:by;case"left":case"right":return t?A2:T2;default:return[]}}function $2(e,t,s,r){const i=ml(e);let a=R2(di(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(mp)))),a}function dd(e){const t=di(e);return S2[t]+e.slice(t.length)}function I2(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 MS(e){return typeof e!="number"?I2(e):{top:e,right:e,bottom:e,left:e}}function hd(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 ky(e,t,s){let{reference:r,floating:i}=e;const a=Qs(t),l=Ux(t),o=zx(l),c=di(t),u=a==="y",h=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-i.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-i.width,y:f};break;default:p={x:r.x,y:r.y}}const g=ml(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function P2(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=Ir(t,e),g=MS(p),b=o[m?f==="floating"?"reference":"floating":f],j=hd(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),x=f==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),y=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},k=hd(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:x,offsetParent:w,strategy:c}):x);return{top:(j.top-k.top+g.top)/y.y,bottom:(k.bottom-j.bottom+g.bottom)/y.y,left:(j.left-k.left+g.left)/y.x,right:(k.right-j.right+g.right)/y.x}}const M2=50,D2=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:P2},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:f}=ky(u,r,c),m=r,p=0;const g={};for(let v=0;v<a.length;v++){const b=a[v];if(!b)continue;const{name:j,fn:x}=b,{x:w,y,data:k,reset:N}=await x({x:h,y:f,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});h=w??h,f=y??f,g[j]={...g[j],...k},N&&p<M2&&(p++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(u=N.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:h,y:f}=ky(u,m,c)),v=-1)}return{x:h,y:f,placement:m,strategy:i,middlewareData:g}},O2=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}=Ir(e,t)||{};if(u==null)return{};const f=MS(h),m={x:s,y:r},p=Ux(i),g=zx(p),v=await l.getDimensions(u),b=p==="y",j=b?"top":"left",x=b?"bottom":"right",w=b?"clientHeight":"clientWidth",y=a.reference[g]+a.reference[p]-m[p]-a.floating[g],k=m[p]-a.reference[p],N=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=N?N[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(N)))&&(S=o.floating[w]||a.floating[g]);const C=y/2-k/2,$=S/2-v[g]/2-1,R=ui(f[j],$),I=ui(f[x],$),F=S-v[g]-I,_=S/2-v[g]/2+C,E=PS(R,_,F),M=!c.arrow&&ml(i)!=null&&_!==E&&a.reference[g]/2-(_<R?R:I)-v[g]/2<0,P=M?_<R?_-R:_-F:0;return{[p]:m[p]+P,data:{[p]:E,centerOffset:_-E-P,...M&&{alignmentOffset:P}},reset:M}}}),L2=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:v=!0,...b}=Ir(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const j=di(i),x=Qs(o),w=di(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),k=m||(w||!v?[dd(o)]:E2(o)),N=g!=="none";!m&&N&&k.push(...$2(o,v,g,y));const S=[o,...k],C=await c.detectOverflow(t,b),$=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&$.push(C[j]),f){const E=C2(i,l,y);$.push(C[E[0]],C[E[1]])}if(R=[...R,{placement:i,overflows:$}],!$.every(E=>E<=0)){var I,F;const E=(((I=a.flip)==null?void 0:I.index)||0)+1,M=S[E];if(M&&(!(f==="alignment"?x!==Qs(M):!1)||R.every(L=>Qs(L.placement)===x?L.overflows[0]>0:!0)))return{data:{index:E,overflows:R},reset:{placement:M}};let P=(F=R.filter(U=>U.overflows[0]<=0).sort((U,L)=>U.overflows[1]-L.overflows[1])[0])==null?void 0:F.placement;if(!P)switch(p){case"bestFit":{var _;const U=(_=R.filter(L=>{if(N){const W=Qs(L.placement);return W===x||W==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(W=>W>0).reduce((W,O)=>W+O,0)]).sort((L,W)=>L[1]-W[1])[0])==null?void 0:_[0];U&&(P=U);break}case"initialPlacement":P=o;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function Ny(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Sy(e){return N2.some(t=>e[t]>=0)}const _2=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=Ir(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=Ny(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:Sy(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=Ny(l,s.floating);return{data:{escapedOffsets:o,escaped:Sy(o)}}}default:return{}}}}},DS=new Set(["left","top"]);async function F2(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=di(s),o=ml(s),c=Qs(s)==="y",u=DS.has(l)?-1:1,h=a&&c?-1:1,f=Ir(t,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof g=="number"&&(p=o==="end"?g*-1:g),c?{x:p*h,y:m*u}:{x:m*u,y:p*h}}const z2=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 F2(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}}}}},U2=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:x=>{let{x:w,y}=x;return{x:w,y}}},...u}=Ir(e,t),h={x:s,y:r},f=await a.detectOverflow(t,u),m=Qs(i),p=Fx(m);let g=h[p],v=h[m];const b=(x,w)=>PS(w+f[x==="y"?"top":"left"],w,w-f[x==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(v=b(m,v));const j=c.fn({...t,[p]:g,[m]:v});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},B2=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:h=!0,crossAxis:f=!0}=Ir(e,t),m={x:i,y:a},p=Qs(l),g=Fx(p);let v=m[g],b=m[p];const j=Ir(u,t),x=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){const k=g==="y"?"height":"width",N=o.reference[g]-o.floating[k]+x.mainAxis,S=o.reference[g]+o.reference[k]-x.mainAxis;v<N?v=N:v>S&&(v=S)}if(f){var w,y;const k=g==="y"?"width":"height",N=DS.has(di(l)),S=o.reference[p]-o.floating[k]+(N&&((w=c.offset)==null?void 0:w[p])||0)+(N?0:x.crossAxis),C=o.reference[p]+o.reference[k]+(N?0:((y=c.offset)==null?void 0:y[p])||0)-(N?x.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[g]:v,[p]:b}}}},W2=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}=Ir(e,t),c=await i.detectOverflow(t,o),u=di(s),h=ml(s),f=Qs(s)==="y",{width:m,height:p}=r.floating;let g,v;u==="top"||u==="bottom"?(g=u,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=u,g=h==="end"?"top":"bottom");const b=p-c.top-c.bottom,j=m-c.left-c.right,x=ui(p-c[g],b),w=ui(m-c[v],j),y=t.middlewareData.shift,k=!y;let N=x,S=w;y!=null&&y.enabled.x&&(S=j),y!=null&&y.enabled.y&&(N=b),k&&!h&&(f?S=m-2*kr(c.left,c.right):N=p-2*kr(c.top,c.bottom)),await l({...t,availableWidth:S,availableHeight:N});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function eh(){return typeof window<"u"}function pl(e){return OS(e)?(e.nodeName||"").toLowerCase():"#document"}function Ln(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Lr(e){var t;return(t=(OS(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function OS(e){return eh()?e instanceof Node||e instanceof Ln(e).Node:!1}function nr(e){return eh()?e instanceof Element||e instanceof Ln(e).Element:!1}function wi(e){return eh()?e instanceof HTMLElement||e instanceof Ln(e).HTMLElement:!1}function Cy(e){return!eh()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ln(e).ShadowRoot}function th(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=sr(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function H2(e){return/^(table|td|th)$/.test(pl(e))}function nh(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const K2=/transform|translate|scale|rotate|perspective|filter/,V2=/paint|layout|strict|content/,Ai=e=>!!e&&e!=="none";let ff;function Bx(e){const t=nr(e)?sr(e):e;return Ai(t.transform)||Ai(t.translate)||Ai(t.scale)||Ai(t.rotate)||Ai(t.perspective)||!Wx()&&(Ai(t.backdropFilter)||Ai(t.filter))||K2.test(t.willChange||"")||V2.test(t.contain||"")}function G2(e){let t=Yi(e);for(;wi(t)&&!Io(t);){if(Bx(t))return t;if(nh(t))return null;t=Yi(t)}return null}function Wx(){return ff==null&&(ff=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),ff}function Io(e){return/^(html|body|#document)$/.test(pl(e))}function sr(e){return Ln(e).getComputedStyle(e)}function sh(e){return nr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Yi(e){if(pl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Cy(e)&&e.host||Lr(e);return Cy(t)?t.host:t}function LS(e){const t=Yi(e);return Io(t)?(e.ownerDocument||e).body:wi(t)&&th(t)?t:LS(t)}function Po(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=LS(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Ln(i);if(a){const o=pp(l);return t.concat(l,l.visualViewport||[],th(i)?i:[],o&&s?Po(o):[])}else return t.concat(i,Po(i,[],s))}function pp(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function _S(e){const t=sr(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=wi(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=ud(s)!==a||ud(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function Hx(e){return nr(e)?e:e.contextElement}function Fa(e){const t=Hx(e);if(!wi(t))return Nr(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=_S(t);let l=(a?ud(s.width):s.width)/r,o=(a?ud(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const Y2=Nr(0);function FS(e){const t=Ln(e);return!Wx()||!t.visualViewport?Y2:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function q2(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Ln(e)}function qi(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=Hx(e);let l=Nr(1);t&&(r?nr(r)&&(l=Fa(r)):l=Fa(e));const o=q2(a,s,r)?FS(a):Nr(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,h=i.width/l.x,f=i.height/l.y;if(a&&r){const m=Ln(a),p=nr(r)?Ln(r):r;let g=m,v=pp(g);for(;v&&p!==g;){const b=Fa(v),j=v.getBoundingClientRect(),x=sr(v),w=j.left+(v.clientLeft+parseFloat(x.paddingLeft))*b.x,y=j.top+(v.clientTop+parseFloat(x.paddingTop))*b.y;c*=b.x,u*=b.y,h*=b.x,f*=b.y,c+=w,u+=y,g=Ln(v),v=pp(g)}}return hd({width:h,height:f,x:c,y:u})}function rh(e,t){const s=sh(e).scrollLeft;return t?t.left+s:qi(Lr(e)).left+s}function zS(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-rh(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function Q2(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=Lr(r),o=t?nh(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=Nr(1);const h=Nr(0),f=wi(r);if((f||!a)&&((pl(r)!=="body"||th(l))&&(c=sh(r)),f)){const p=qi(r);u=Fa(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!a?zS(l,c):Nr(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 X2(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function J2(e){const t=sh(e),s=e.ownerDocument.body,r=kr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=kr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+rh(e);const l=-t.scrollTop;return sr(s).direction==="rtl"&&(a+=kr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const Z2=25;function eM(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Ln(e),a=Lr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!Wx()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(rh(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),v=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-v),j=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;j<=Z2&&(o-=j)}return{width:o,height:c,x:u,y:h}}function tM(e,t){const s=qi(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=Fa(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 Ey(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=eM(e,s,t);else if(t==="document")r=J2(Lr(e));else if(nr(t))r=tM(t,s);else{const i=FS(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return hd(r)}function nM(e,t){const s=t.get(e);if(s)return s;let r=Po(e,[],!1).filter(o=>nr(o)&&pl(o)!=="body"),i=null;const a=sr(e).position==="fixed";let l=a?Yi(e):e;for(;nr(l)&&!Io(l);){const o=sr(l),c=Bx(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):i=o,l=Yi(l)}return t.set(e,r),r}function sM(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?nh(t)?[]:nM(t,this._c):[].concat(s),r],o=Ey(t,l[0],i);let c=o.top,u=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=Ey(t,l[m],i);c=kr(p.top,c),u=ui(p.right,u),h=ui(p.bottom,h),f=kr(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function rM(e){const{width:t,height:s}=_S(e);return{width:t,height:s}}function iM(e,t,s){const r=wi(t),i=Lr(t),a=s==="fixed",l=qi(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=Nr(0);if((r||!a)&&((pl(t)!=="body"||th(i))&&(o=sh(t)),r)){const m=qi(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=rh(i));const u=i&&!r&&!a?zS(i,o):Nr(0),h=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:h,y:f,width:l.width,height:l.height}}function mf(e){return sr(e).position==="static"}function Ay(e,t){if(!wi(e)||sr(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return Lr(e)===s&&(s=s.ownerDocument.body),s}function US(e,t){const s=Ln(e);if(nh(e))return s;if(!wi(e)){let i=Yi(e);for(;i&&!Io(i);){if(nr(i)&&!mf(i))return i;i=Yi(i)}return s}let r=Ay(e,t);for(;r&&H2(r)&&mf(r);)r=Ay(r,t);return r&&Io(r)&&mf(r)&&!Bx(r)?s:r||G2(e)||s}const aM=async function(e){const t=this.getOffsetParent||US,s=this.getDimensions,r=await s(e.floating);return{reference:iM(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function lM(e){return sr(e).direction==="rtl"}const oM={convertOffsetParentRelativeRectToViewportRelativeRect:Q2,getDocumentElement:Lr,getClippingRect:sM,getOffsetParent:US,getElementRects:aM,getClientRects:X2,getDimensions:rM,getScale:Fa,isElement:nr,isRTL:lM};function BS(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function cM(e,t,s){let r=null,i;const a=Lr(e);function l(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function o(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:v,height:b}=m;if(h||t(),!v||!b)return;const j=Hc(g),x=Hc(a.clientWidth-(p+v)),w=Hc(a.clientHeight-(g+b)),y=Hc(p),N={rootMargin:-j+"px "+-x+"px "+-w+"px "+-y+"px",threshold:kr(0,ui(1,f))||1};let S=!0;function C($){const R=$[0].intersectionRatio;if(!BS(m,e.getBoundingClientRect()))return o();if(R!==f){if(!S)return o();R?o(!1,R):i=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...N,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,N)}r.observe(e)}const c=Ln(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function uM(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=Hx(e),h=i||a?[...u?Po(u):[],...t?Po(t):[]]:[];h.forEach(j=>{i&&j.addEventListener("scroll",s),a&&j.addEventListener("resize",s)});const f=u&&o?cM(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[x]=j;x&&x.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,v=c?qi(e):null;c&&b();function b(){const j=qi(e);v&&!BS(v,j)&&s(),v=j,g=requestAnimationFrame(b)}return s(),()=>{var j;h.forEach(x=>{i&&x.removeEventListener("scroll",s),a&&x.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const dM=z2,hM=U2,fM=L2,mM=W2,pM=_2,Ty=O2,gM=B2,xM=(e,t,s)=>{const r=new Map,i=s??{},a={...oM,...i.platform,_c:r};return D2(e,t,{...i,platform:a})};var vM=typeof document<"u",jM=function(){},Au=vM?d.useLayoutEffect:jM;function fd(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(!fd(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)&&!fd(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function WS(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ry(e,t){const s=WS(e);return Math.round(t*s)/s}function pf(e){const t=d.useRef(e);return Au(()=>{t.current=e}),t}function wM(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,f]=d.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=d.useState(r);fd(m,r)||p(r);const[g,v]=d.useState(null),[b,j]=d.useState(null),x=d.useCallback(L=>{L!==N.current&&(N.current=L,v(L))},[]),w=d.useCallback(L=>{L!==S.current&&(S.current=L,j(L))},[]),y=a||g,k=l||b,N=d.useRef(null),S=d.useRef(null),C=d.useRef(h),$=c!=null,R=pf(c),I=pf(i),F=pf(u),_=d.useCallback(()=>{if(!N.current||!S.current)return;const L={placement:t,strategy:s,middleware:m};I.current&&(L.platform=I.current),xM(N.current,S.current,L).then(W=>{const O={...W,isPositioned:F.current!==!1};E.current&&!fd(C.current,O)&&(C.current=O,hl.flushSync(()=>{f(O)}))})},[m,t,s,I,F]);Au(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[u]);const E=d.useRef(!1);Au(()=>(E.current=!0,()=>{E.current=!1}),[]),Au(()=>{if(y&&(N.current=y),k&&(S.current=k),y&&k){if(R.current)return R.current(y,k,_);_()}},[y,k,_,R,$]);const M=d.useMemo(()=>({reference:N,floating:S,setReference:x,setFloating:w}),[x,w]),P=d.useMemo(()=>({reference:y,floating:k}),[y,k]),U=d.useMemo(()=>{const L={position:s,left:0,top:0};if(!P.floating)return L;const W=Ry(P.floating,h.x),O=Ry(P.floating,h.y);return o?{...L,transform:"translate("+W+"px, "+O+"px)",...WS(P.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:W,top:O}},[s,o,P.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:_,refs:M,elements:P,floatingStyles:U}),[h,_,M,P,U])}const yM=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?Ty({element:r.current,padding:i}).fn(s):{}:r?Ty({element:r,padding:i}).fn(s):{}}}},bM=(e,t)=>{const s=dM(e);return{name:s.name,fn:s.fn,options:[e,t]}},kM=(e,t)=>{const s=hM(e);return{name:s.name,fn:s.fn,options:[e,t]}},NM=(e,t)=>({fn:gM(e).fn,options:[e,t]}),SM=(e,t)=>{const s=fM(e);return{name:s.name,fn:s.fn,options:[e,t]}},CM=(e,t)=>{const s=mM(e);return{name:s.name,fn:s.fn,options:[e,t]}},EM=(e,t)=>{const s=pM(e);return{name:s.name,fn:s.fn,options:[e,t]}},AM=(e,t)=>{const s=yM(e);return{name:s.name,fn:s.fn,options:[e,t]}};var TM=Object.defineProperty,RM=(e,t)=>TM(e,"name",{value:t,configurable:!0});function HS(e){const[t,s]=d.useState(void 0);return On(()=>{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}RM(HS,"useSize");var $M=Object.defineProperty,ri=(e,t)=>$M(e,"name",{value:t,configurable:!0}),KS="Popper",[VS,ih]=Ms(KS),[IM,GS]=VS(KS),PM=ri(e=>{const{__scopePopper:t,children:s}=e,[r,i]=d.useState(null),[a,l]=d.useState(void 0);return n.jsx(IM,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),MM="PopperAnchor",DM=d.forwardRef(ri(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=GS(MM,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(v=>{o.current=v,v&&c(v)},[c]),h=jt(s,u),f=d.useRef(null);d.useEffect(()=>{if(!i)return;const v=f.current;f.current=i.current,v!==f.current&&c(f.current)});const m=l.placementState&&ah(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(mt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:h})},"PopperAnchor")),YS="PopperContent",[OM,pY]=VS(YS),LM=d.forwardRef(ri(function(t,s){var Pe,Te,Le,J,ke,ne,Ae;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:v,...b}=t,j=GS(YS,r),[x,w]=d.useState(null),y=jt(s,w),[k,N]=d.useState(null),S=HS(k),C=(S==null?void 0:S.width)??0,$=(S==null?void 0:S.height)??0,R=i+(l!=="center"?"-"+l:""),I=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},F=Array.isArray(h)?h:[h],_=F.length>0,E={padding:I,boundary:F.filter(qS),altBoundary:_},{refs:M,floatingStyles:P,placement:U,isPositioned:L,middlewareData:W}=wM({strategy:"fixed",placement:R,whileElementsMounted:ri((...de)=>uM(...de,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[bM({mainAxis:a+$,alignmentAxis:o}),u&&kM({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?NM():void 0,...E}),u&&SM({...E}),CM({...E,apply:ri(({elements:de,rects:Re,availableWidth:De,availableHeight:Ve})=>{const{width:he,height:ze}=Re.reference,Ge=de.floating.style;Ge.setProperty("--radix-popper-available-width",`${De}px`),Ge.setProperty("--radix-popper-available-height",`${Ve}px`),Ge.setProperty("--radix-popper-anchor-width",`${he}px`),Ge.setProperty("--radix-popper-anchor-height",`${ze}px`)},"apply")}),k&&AM({element:k,padding:c}),_M({arrowWidth:C,arrowHeight:$}),p&&EM({strategy:"referenceHidden",...E,boundary:_?E.boundary:void 0})]}),O=j.setPlacementState;On(()=>(O(U),()=>{O(void 0)}),[U,O]);const[V,X]=ah(U),G=Sn(v);On(()=>{L&&(G==null||G())},[L,G]);const Z=(Pe=W.arrow)==null?void 0:Pe.x,z=(Te=W.arrow)==null?void 0:Te.y,q=((Le=W.arrow)==null?void 0:Le.centerOffset)!==0,[Q,ce]=d.useState();return On(()=>{x&&ce(window.getComputedStyle(x).zIndex)},[x]),n.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:L?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Q,"--radix-popper-transform-origin":[(J=W.transformOrigin)==null?void 0:J.x,(ke=W.transformOrigin)==null?void 0:ke.y].join(" "),...((ne=W.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(OM,{scope:r,placedSide:V,placedAlign:X,onArrowChange:N,arrowX:Z,arrowY:z,shouldHideArrow:q,children:n.jsx(mt.div,{"data-side":V,"data-align":X,...b,ref:y,style:{...b.style,animation:L?(Ae=b.style)==null?void 0:Ae.animation:"none"}})})})},"PopperContent"));function qS(e){return e!==null}ri(qS,"isNotNull");var _M=ri(e=>({name:"transformOrigin",options:e,fn(t){var b,j,x;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=ah(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=i.arrow)==null?void 0:j.x)??0)+o/2,p=(((x=i.arrow)==null?void 0:x.y)??0)+c/2;let g="",v="";return u==="bottom"?(g=l?f:`${m}px`,v=`${-c}px`):u==="top"?(g=l?f:`${m}px`,v=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,v=l?f:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,v=l?f:`${p}px`),{data:{x:g,y:v}}}}),"transformOrigin");function ah(e){const[t,s="center"]=e.split("-");return[t,s]}ri(ah,"getSideAndAlignFromPlacement");var Kx=PM,QS=DM,XS=LM,FM=Object.defineProperty,Zt=(e,t)=>FM(e,"name",{value:t,configurable:!0}),[Vx,gY]=Ms("Tooltip",[ih]),Gx=ih(),zM="TooltipProvider",UM=700,gp="tooltip.open",[BM,Yx]=Vx(zM),WM=Zt(e=>{const{__scopeTooltip:t,delayDuration:s=UM,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=d.useRef(!0),o=d.useRef(!1),c=d.useRef(0);return d.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(BM,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:d.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),xp="Tooltip",[HM,ic]=Vx(xp),KM=Zt(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=Yx(xp,e.__scopeTooltip),u=Gx(t),[h,f]=d.useState(null),[m,p]=d.useState(void 0),g=Ts(),v=d.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,x=d.useRef(!1),[w,y]=ji({prop:r,defaultProp:i??!1,onChange:Zt(R=>{R?(c.onOpen(),document.dispatchEvent(new CustomEvent(gp))):c.onClose(),a==null||a(R)},"onChange"),caller:xp}),k=d.useMemo(()=>w?x.current?"delayed-open":"instant-open":"closed",[w]),N=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,y(!0)},[y]),S=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,y(!1)},[y]),C=d.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,y(!0),v.current=0},j)},[j,y]);d.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]);const $=m??g;return n.jsx(Kx,{...u,children:n.jsx(HM,{scope:t,contentId:$,setContentId:p,open:w,stateAttribute:k,trigger:h,onTriggerChange:f,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():N()},[c.isOpenDelayedRef,C,N]),onTriggerLeave:d.useCallback(()=>{b?S():(window.clearTimeout(v.current),v.current=0)},[S,b]),onOpen:N,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),$y="TooltipTrigger",VM=d.forwardRef(Zt(function(t,s){const{__scopeTooltip:r,...i}=t,a=ic($y,r),l=Yx($y,r),o=Gx(r),c=d.useRef(null),u=jt(s,c,a.onTriggerChange),h=d.useRef(!1),f=d.useRef(!1),m=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx(QS,{asChild:!0,...o,children:n.jsx(mt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Ie(t.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),f.current=!0)}),onPointerLeave:Ie(t.onPointerLeave,()=>{a.onTriggerLeave(),f.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")),JS="TooltipPortal",[GM,YM]=Vx(JS,{forceMount:void 0}),qM=Zt(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=ic(JS,t);return n.jsx(GM,{scope:t,forceMount:s,children:n.jsx(lr,{present:s||a.open,children:n.jsx(Xd,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),Mo="TooltipContent",QM=d.forwardRef(Zt(function(t,s){const r=YM(Mo,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=ic(Mo,t.__scopeTooltip);return n.jsx(lr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(ZS,{side:a,...l,ref:s}):n.jsx(XM,{side:a,...l,ref:s})})},"TooltipContent")),XM=d.forwardRef(Zt(function(t,s){const r=ic(Mo,t.__scopeTooltip),i=Yx(Mo,t.__scopeTooltip),a=d.useRef(null),l=jt(s,a),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,f=a.current,{onPointerInTransitChange:m}=i,p=d.useCallback(()=>{c(null),m(!1)},[m]),g=d.useCallback((v,b)=>{const j=v.currentTarget,x={x:v.clientX,y:v.clientY},w=eC(x,j.getBoundingClientRect()),y=tC(x,w),k=nC(b.getBoundingClientRect()),N=rC([...y,...k]);c(N),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const v=Zt(j=>g(j,f),"handleTriggerLeave"),b=Zt(j=>g(j,u),"handleContentLeave");return u.addEventListener("pointerleave",v),f.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",v),f.removeEventListener("pointerleave",b)}}},[u,f,g,p]),d.useEffect(()=>{if(o){const v=Zt(b=>{const j=b.target,x={x:b.clientX,y:b.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),y=!sC(x,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[u,f,o,h,p]),n.jsx(ZS,{...t,ref:l})},"TooltipContentHoverable")),JM=lS("TooltipContent"),ZS=d.forwardRef(Zt(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=ic(Mo,r),f=Gx(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener(gp,m),()=>document.removeEventListener(gp,m)),[m]),d.useEffect(()=>{if(h.trigger){const g=Zt(v=>{v.target instanceof Node&&v.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return On(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(Qd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(XS,{"data-state":h.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:h.contentId,...f,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[n.jsx(JM,{children:i}),a?n.jsx(VP,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function eC(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")}}Zt(eC,"getExitSideFromRect");function tC(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}Zt(tC,"getPaddedExitPoints");function nC(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}]}Zt(nC,"getPointsFromRect");function sC(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}Zt(sC,"isPointInPolygon");function rC(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),iC(t)}Zt(rC,"getHull");function iC(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)}Zt(iC,"getHullPresorted");var Iy=WM,Do=KM,Oo=VM,Lo=qM,_o=QM;let zt={time:"auto",date:"auto",locale:void 0};function qx(e){const t=e.timeFormat===void 0?zt.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?zt.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";zt={time:t,date:s,locale:e.locale??zt.locale}}function aC(){return{time:zt.time,date:zt.date}}function ac(e,t){const s=zt;qx(e);try{return t()}finally{zt=s}}const vp="buddi:formats";function lc(){if(zt.locale)return zt.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const Py=new Map;function gl(e,t){const s=`${e}|${JSON.stringify(t)}`;let r=Py.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,t)}catch{r=new Intl.DateTimeFormat(e,{...t,timeZone:"UTC"})}Py.set(s,r)}return r}function gf(e,t,s,r){return Object.fromEntries(gl(s,{timeZone:t,...r}).formatToParts(e).map(i=>[i.type,i.value]))}function ZM(){return zt.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:zt.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Xx()?"numeric":"2-digit",minute:"2-digit"}}function eD(){return zt.time==="auto"?lc():"en-US"}function Ut(e,t){return Number.isNaN(e.getTime())?"—":gl(eD(),{timeZone:t,...ZM()}).format(e)}function Qx(e){return e>=1440&&!Xx()?"24:00":Ut(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Xx(){var e;return zt.time!=="auto"?zt.time==="12h":((e=gl(lc(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function tD(){if(zt.date!=="auto")return zt.date==="short";const e=gl(lc(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(t=>t.type);return e.indexOf("month")<e.indexOf("day")}function or(e,t,s={}){return nD(e,t,s).replace(/\bSept\b/g,"Sep")}function nD(e,t,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:i=!1,compact:a=!1}=s;switch(zt.date){case"iso":{const l=gf(e,t,"en-CA",{year:"numeric",month:"2-digit",day:"2-digit",...r?{weekday:a?"short":"long"}:{}}),o=`${l.year}-${l.month}-${l.day}`;return r?`${l.weekday} ${o}`:o}case"short":{const l=gf(e,t,"en-US",{month:"short",day:"numeric",year:"numeric",weekday:"short"});return`${r?`${l.weekday}, `:""}${l.month} ${l.day}${i?`, ${l.year}`:""}`}case"long":{const l=gf(e,t,"en-GB",{month:a?"short":"long",day:"numeric",year:"numeric",weekday:a?"short":"long"});return`${r?`${l.weekday}, `:""}${l.day} ${l.month}${i?` ${l.year}`:""}`}default:return gl(lc(),{timeZone:t,month:a?"short":"long",day:"numeric",...i?{year:"numeric"}:{},...r?{weekday:a?"short":"long"}:{}}).format(e)}}function lC(e,t){if(zt.date==="iso")return`${e}-${String(t).padStart(2,"0")}`;const s=new Date(Date.UTC(e,t-1,15)),r=zt.date==="auto"?lc():"en-GB";return gl(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function lh(e,t={}){const s=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!s)return e;const r=new Date(`${s[0]}T12:00:00Z`);return Number.isNaN(r.getTime())?e:or(r,"UTC",t)}function Ze(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${or(s,t,{year:!0,compact:!0})}, ${Ut(s,t)}`}function oC(e,t){return`${or(e,t,{weekday:!0,compact:!0})}, ${Ut(e,t)}`}function He(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 Jx(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 sD(e,t=Date.now()){const s=Jx(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function rD(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 Vt(e){return new Intl.NumberFormat("en-US").format(e)}function jp(e){return[...e.cacheRead?[`cached ${Vt(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Vt(e.cacheWrite)}`]:[]].join(", ")}function iD(e){const t=jp(e);return`${Vt(e.input)} in${t?` (${t})`:""} / ${Vt(e.output)} out`}function _n(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Fo(e,t=8){return e.length<=t?e:e.slice(0,t)}function rr(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function Ja(e){return e.replace(/<<<[^<>]*>>>/g,"")}function zo(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}const My="buddi_csrf",xl="x-buddi-csrf",Uo="buddi:agents-changed",Zl="buddi:status-changed",Dy=e=>(window.dispatchEvent(new Event(Zl)),e),wp="buddi:locked",aD="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 na(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${My}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${My}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const md="buddi isn't answering.";let yp=null;const bp=new Set;function Ul(e){if(e!==(yp===null)){yp=e?null:Date.now();for(const t of bp)t()}}function kp(){return yp}function cC(e){return bp.add(e),()=>bp.delete(e)}function Np(e){return e instanceof pe&&(e.status===0||e.status===502||e.status===503)&&e.message===md}async function sa(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:(Ul(!1),new pe(0,md,o))}if(s.status===401)throw Ul(!0),new pe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Ul(!0),window.dispatchEvent(new Event(wp)),new pe(423,"This dashboard is locked.");const r=await s.text(),i=r===""?null:lD(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 Ul(!1),new pe(s.status,md,i);if(Ul(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?aD:`request failed (${s.status})`);throw new pe(s.status,c,i)}return i}function lD(e){try{return JSON.parse(e)}catch{return null}}function xf(){return aC().time==="auto"?{hour:Xx()?"12":"24"}:{}}function xe(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 sa(`/api${e}${r?`?${r}`:""}`)}function Sp(e,t){return sa(`/api${e}`,{method:"POST",headers:{[xl]:na()},body:t})}function gr(e){return sa(`/api${e}`,{method:"DELETE",headers:{[xl]:na()}})}function ie(e,t={}){return sa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[xl]:na()},body:JSON.stringify(t??{})})}function uC(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return sa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[xl]:na(),"X-Filename":i,...r},body:t})}function Oy(e,t,s){return uC(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function oD(e,t={}){return sa(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[xl]:na()},body:JSON.stringify(t??{})})}function Ws(e,t={}){return sa(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[xl]:na()},body:JSON.stringify(t??{})})}function cD(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 Tu="gpt-oss:120b",uD=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Cp=["mon","tue","wed","thu","fri","sat","sun"],Be={agents:()=>xe("/chat/agents"),views:()=>xe("/chat/views"),conversations:(e,t)=>xe(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>ie(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>xe(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>gr(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,t)=>ie(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>ie(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>ie(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),Sp("/chat/attachments",t)},transcribe:e=>ie("/speech/transcribe",e),say:e=>ie("/speech/say",e),discardAttachment:e=>gr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>xe("/groups"),group:e=>xe(`/groups/${encodeURIComponent(e)}`),createGroup:e=>ie("/groups",e),updateGroup:(e,t)=>oD(`/groups/${encodeURIComponent(e)}`,t),deleteGroup:e=>gr(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>ie(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>ie(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>xe(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>ie(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>ie(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function Zx(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const A={providers:()=>xe("/providers"),providerAccounts:()=>xe("/provider-accounts"),probeModels:e=>ie("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>ie(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>ie("/provider-accounts/save",e),testProviderAccount:e=>ie(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>ie(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>ie(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>ie(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>ie(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>ie(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>ie(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>ie(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>ie(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>ie(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>ie(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>ie(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>xe("/host/browser-profiles",{app:e}),installedApps:()=>xe("/host/apps"),browser:e=>xe(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>ie(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>ie("/browser/settings",e),computerPermissions:(e=!1)=>ie("/browser/permissions",{prompt:e}),browserInstall:()=>ie("/browser/install",{}),browserCheck:()=>ie("/browser/check",{}),previewLink:(e,t)=>xe(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>xe(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>xe("/extension"),pairExtension:e=>ie("/extension/pair",{code:e}),forgetExtension:()=>gr("/extension/pair"),session:()=>xe("/session"),overview:()=>xe("/overview"),events:e=>xe("/events",e),eventKinds:()=>xe("/events/kinds"),conversations:()=>xe("/conversations"),conversation:e=>xe(`/conversations/${encodeURIComponent(e)}`),missions:()=>xe("/missions"),jobs:(e={})=>xe("/jobs",e),approvals:()=>xe("/approvals"),approval:e=>xe(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>xe("/offers"),dismissOffer:e=>ie(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>ie("/offers/dismiss-all",{ids:e}),agentOffers:()=>xe("/agent-offers"),teammates:()=>xe("/teammates"),dismissAgentOffer:(e,t)=>ie(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>xe("/proposals"),setDigestSchedule:(e,t)=>ie("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>ie(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),keepAllProposals:e=>ie("/proposals/keep-all",{ids:e}),discardProposal:(e,t)=>ie(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>xe("/reminders"),sentinels:()=>xe("/sentinels"),setSentinelEnabled:(e,t)=>ie(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),widgets:(e="home")=>xe("/widgets",{...e==="lock"?{surface:e}:{},...xf()}),saveWidgets:(e,t)=>Ws(`/widgets/${e}`,{placements:t.map(({key:s,widget:r,size:i,settings:a})=>({...s?{key:s}:{},widget:r,size:i,settings:a}))}),widgetSettings:e=>xe(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>ie("/widgets/preview",{...e,...xf()}),refreshWidget:(e,t="home")=>ie(`/widgets/${encodeURIComponent(e)}/refresh${t==="lock"?"?surface=lock":""}`),setGlanceHidden:(e,t)=>ie(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>xe("/rail"),setRailHidden:(e,t,s)=>ie(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlert:(e,t)=>ie(`/alerts/${encodeURIComponent(e)}/snooze`,{snoozed:t}),agents:()=>xe("/agents"),library:e=>xe("/artifacts",e),libraryEntry:(e,t=0)=>xe(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>xe("/onboarding"),onboardingStep:(e,t={})=>ie("/onboarding/step",{step:e,...t}),takeOn:e=>ie("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>xe("/onboarding/take-on"),completeOnboarding:()=>ie("/onboarding/complete"),skipOnboarding:()=>ie("/onboarding/skip"),createFirstAgent:e=>ie("/onboarding/agent",e),ollama:()=>xe("/onboarding/ollama"),mlxh:()=>xe("/onboarding/mlxh"),firstAgentPersona:()=>xe("/onboarding/agent"),updateFirstAgent:e=>ie("/onboarding/agent/update",e),bindBrain:e=>ie("/onboarding/brain",e),pages:()=>xe("/pages"),pageQuery:(e,t,s={})=>xe(`/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)=>ie(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>xe("/telegram"),saveTelegramToken:e=>ie("/telegram/token",{token:e}),telegramPairing:()=>ie("/telegram/pairing"),telegramBot:()=>xe("/telegram/bot"),telegramDevices:()=>xe("/telegram/devices"),unpairTelegramDevice:e=>gr(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>xe("/notifications",{limit:e}),notificationSeen:e=>ie(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>xe("/notifications/settings"),saveNotificationSettings:e=>Ws("/notifications/settings",e),focus:()=>xe("/notifications/focus"),lockState:()=>xe("/lock"),lockScreen:()=>xe("/lock/screen",xf()),lockNow:(e="owner")=>ie("/lock",{reason:e}),unlock:e=>ie("/lock/unlock",{pin:e}),lockActivity:()=>ie("/lock/activity"),setPin:(e,t)=>Ws("/lock/pin",t===void 0?{pin:e}:{pin:e,current:t}),removePin:e=>ie("/lock/pin/remove",{current:e}),setLockSettings:e=>Ws("/lock/settings",e),uploadLockBackground:e=>{const t=new FormData;return t.append("file",e),Sp("/lock/background",t)},removeLockBackground:()=>gr("/lock/background"),setFocus:(e,t)=>Ws("/notifications/focus",t?{mode:e,duration:t}:{mode:e}).then(Dy),testChannel:e=>ie("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>ie("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>xe(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>xe("/tips"),restoreTip:e=>ie(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>ie(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>ie(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>ie("/tips/seen-page",{page:e}),tipsSettings:()=>xe("/tips/settings"),saveTipsSettings:e=>Ws("/tips/settings",{enabled:e}),presence:e=>ie("/presence",{state:e}),owner:()=>xe("/owner"),setOwner:e=>ie("/owner",e),findPlace:e=>ie("/owner/places/find",{address:e}),savePlace:e=>ie("/owner/places",e),removePlace:e=>ie("/owner/places/remove",{id:e}),memory:e=>xe(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>ie("/memory/preferences",e),forgetPreference:e=>ie("/memory/preferences/forget",e),updateNote:(e,t)=>ie(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>ie(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>ie(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>xe(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>xe(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>ie(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>xe("/host",{agentId:e,conversationId:t}),connections:()=>xe("/connections"),connection:e=>xe(`/connections/${e}`),addConnection:(e,t)=>ie("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>ie("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>ie(`/connections/${e}/program`,t),connectionConsent:(e,t)=>ie(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>ie(`/connections/${e}/token`,t),connectionDevice:e=>ie(`/connections/${e}/device`,{}),connectionCallback:e=>ie("/connections/callback",e),connectionReview:e=>xe(`/connections/${e}/review`),saveConnectionReview:(e,t)=>ie(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>ie(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>ie(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>gr(`/connections/${e}`),connectionSignals:()=>xe("/connections/signals"),connectionTools:e=>xe(`/connections/${e}/tools`),rememberedApprovals:e=>xe(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>ie("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>xe("/secrets"),secretUses:(e,t)=>xe("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>ie("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>ie("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>ie("/host/revoke",{id:e}),decide:(e,t,s,r)=>ie(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>ie("/pause",{paused:e}).then(Dy),service:()=>xe("/service"),serviceAction:e=>ie(`/service/${e}`),version:()=>xe("/version"),checkVersion:()=>ie("/version/check"),setVersionCheck:e=>Ws("/version/check",{enabled:e}),tailscale:()=>xe("/tailscale"),setTailscale:e=>Ws("/tailscale",e),apiTokens:()=>xe("/api-tokens"),createApiToken:e=>ie("/api-tokens",{name:e}),revokeApiToken:e=>gr(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>ie("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>xe(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>xe("/backups"),startBackup:e=>ie("/backups",{encrypt:e}),verifyArchive:e=>ie("/backups/verify",{name:e}),restoreArchive:e=>ie("/backups/restore",e),restoreUpload:(e,t)=>Oy("/backups/restore",e,t),backupJob:e=>xe(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>xe("/backups/schedule"),setBackupSchedule:e=>Ws("/backups/schedule",e),backupPassphrase:()=>xe("/backups/passphrase"),setBackupPassphrase:e=>Ws("/backups/passphrase",{passphrase:e}),plugins:()=>xe("/plugins"),market:(e=!1)=>xe(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>xe("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>ie("/plugins/stage",{spec:e}),uploadPlugin:e=>uC("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>xe(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>ie(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>ie(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>ie(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,t,s)=>ie(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>ie(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>ie(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>ie(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>xe("/recovery"),leaveRecovery:e=>ie("/recovery/leave",e),firstRunRestore:(e,t)=>Oy("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>ie(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),setMisfirePolicy:(e,t,s)=>ie(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>ie(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>ie(`/jobs/${encodeURIComponent(e)}/cancel`),setDefaultAgent:e=>ie("/agents/default",{agentId:e}),agentTools:e=>xe(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>xe(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),Sp(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>gr(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>ie(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>ie(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>ie(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>ie(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})};function dC(e){return e==="anthropic"||e==="openai"}function hC(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 dD="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var hD=Object.defineProperty,fD=(e,t)=>hD(e,"name",{value:t,configurable:!0}),mD=d.createContext(void 0);function oh(e){const t=d.useContext(mD);return e||t||"ltr"}fD(oh,"useDirection");var pD=Object.defineProperty,ev=(e,t)=>pD(e,"name",{value:t,configurable:!0}),Kc=0,Hs=null;function gD(e){return ch(),e.children}ev(gD,"FocusGuards");function ch(){d.useEffect(()=>{Hs||(Hs={start:Ep(),end:Ep()});const{start:e,end:t}=Hs;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Kc++,()=>{Kc===1&&(Hs==null||Hs.start.remove(),Hs==null||Hs.end.remove(),Hs=null),Kc=Math.max(0,Kc-1)}},[])}ev(ch,"useFocusGuards");function Ep(){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}ev(Ep,"createFocusGuard");var xD=Object.defineProperty,kn=(e,t)=>xD(e,"name",{value:t,configurable:!0}),vf="focusScope.autoFocusOnMount",jf="focusScope.autoFocusOnUnmount",Ly={bubbles:!1,cancelable:!0},fC=d.forwardRef(kn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=d.useState(null),h=Sn(a),f=Sn(l),m=d.useRef(null),p=jt(s,u),g=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(i){let b=function(y){if(g.paused||!c)return;const k=y.target;c.contains(k)?m.current=k:mr(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const k=y.relatedTarget;k!==null&&(c.contains(k)||mr(m.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const N of y)N.removedNodes.length>0&&mr(c)};kn(b,"handleFocusIn"),kn(j,"handleFocusOut"),kn(x,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",j);const w=new MutationObserver(x);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",j),w.disconnect()}}},[i,c,g.paused]),d.useEffect(()=>{if(c){_y.add(g);const b=document.activeElement;if(!c.contains(b)){const x=new CustomEvent(vf,Ly);c.addEventListener(vf,h),c.dispatchEvent(x),x.defaultPrevented||(mC(jC(tv(c)),{select:!0}),document.activeElement===b&&mr(c))}return()=>{c.removeEventListener(vf,h),setTimeout(()=>{const x=new CustomEvent(jf,Ly);c.addEventListener(jf,f),c.dispatchEvent(x),x.defaultPrevented||mr(b??document.body,{select:!0}),c.removeEventListener(jf,f),_y.remove(g)},0)}}},[c,h,f,g]);const v=d.useCallback(b=>{if(!r&&!i||g.paused)return;const j=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,x=document.activeElement;if(j&&x){const w=b.currentTarget,[y,k]=pC(w);y&&k?!b.shiftKey&&x===k?(b.preventDefault(),r&&mr(y,{select:!0})):b.shiftKey&&x===y&&(b.preventDefault(),r&&mr(k,{select:!0})):x===w&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(mt.div,{tabIndex:-1,...o,ref:p,onKeyDown:v})},"FocusScope"));function mC(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(mr(r,{select:t}),document.activeElement!==s)return}kn(mC,"focusFirst");function pC(e){const t=tv(e),s=Ap(t,e),r=Ap(t.reverse(),e);return[s,r]}kn(pC,"getTabbableEdges");function tv(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:kn(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}kn(tv,"getTabbableCandidates");function Ap(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):gC(r,{upTo:t})))return r}kn(Ap,"findVisible");function gC(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}kn(gC,"isHidden");function xC(e){return e instanceof HTMLInputElement&&"select"in e}kn(xC,"isSelectableInput");function mr(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&xC(e)&&t&&e.select()}}kn(mr,"focus");var _y=vC();function vC(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Tp(e,t),e.unshift(t)},remove(t){var s;e=Tp(e,t),(s=e[0])==null||s.resume()}}}kn(vC,"createFocusScopesStack");function Tp(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}kn(Tp,"arrayRemove");function jC(e){return e.filter(t=>t.tagName!=="A")}kn(jC,"removeLinks");var vD=Object.defineProperty,nv=(e,t)=>vD(e,"name",{value:t,configurable:!0}),wf=!1;function wC(){const[e,t]=d.useState(wf);return d.useEffect(()=>{wf||(wf=!0,t(!0))},[]),e}nv(wC,"useIsHydrated");var yC=cl[" useSyncExternalStore ".trim().toString()];function bC(){return()=>{}}nv(bC,"subscribe");function kC(){return yC(bC,()=>!0,()=>!1)}nv(kC,"useIsHydratedModern");var jD=typeof yC=="function"?kC:wC,wD=Object.defineProperty,ra=(e,t)=>wD(e,"name",{value:t,configurable:!0}),yf="rovingFocusGroup.onEntryFocus",yD={bubbles:!1,cancelable:!0},uh="RovingFocusGroup",[Rp,NC,bD]=Yd(uh),[kD,dh]=Ms(uh,[bD]),[ND,SD]=kD(uh),CD=d.forwardRef(ra(function(t,s){return n.jsx(Rp.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Rp.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(ED,{...t,ref:s})})})},"RovingFocusGroup")),ED=d.forwardRef(ra(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=t,p=d.useRef(null),g=jt(s,p),v=oh(l),[b,j]=ji({prop:o,defaultProp:c??null,onChange:u,caller:uh}),[x,w]=d.useState(!1),y=Sn(h),k=NC(r),N=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const $=p.current;if($)return $.addEventListener(yf,y),()=>$.removeEventListener(yf,y)},[y]),n.jsx(ND,{scope:r,orientation:i,dir:v,loop:a,currentTabStopId:b,onItemFocus:d.useCallback($=>j($),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C($=>$+1),[]),onFocusableItemRemove:d.useCallback(()=>C($=>$-1),[]),children:n.jsx(mt.div,{tabIndex:x||S===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Ie(t.onMouseDown,()=>{N.current=!0}),onFocus:Ie(t.onFocus,$=>{const R=!N.current;if($.target===$.currentTarget&&R&&!x){const I=new CustomEvent(yf,yD);if($.currentTarget.dispatchEvent(I),!I.defaultPrevented){const F=k().filter(U=>U.focusable),_=F.find(U=>U.active),E=F.find(U=>U.id===b),P=[_,E,...F].filter(Boolean).map(U=>U.ref.current);sv(P,f)}}N.current=!1}),onBlur:Ie(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),AD="RovingFocusGroupItem",TD=d.forwardRef(ra(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=Ts(),h=l||u,f=SD(AD,r),m=f.currentTabStopId===h,p=NC(r),{onFocusableItemAdd:g,onFocusableItemRemove:v,currentTabStopId:b}=f,j=jD();return On(()=>{if(!(!j||!i))return g(),()=>v()},[j,i,g,v]),d.useEffect(()=>{if(!(j||!i))return g(),()=>v()},[j,i,g,v]),n.jsx(Rp.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(mt.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:Ie(t.onMouseDown,x=>{i?f.onItemFocus(h):x.preventDefault()}),onFocus:Ie(t.onFocus,()=>f.onItemFocus(h)),onKeyDown:Ie(t.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){f.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const w=CC(x,f.orientation,f.dir);if(w!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let k=p().filter(N=>N.focusable).map(N=>N.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const N=k.indexOf(x.currentTarget);k=f.loop?EC(k,N+1):k.slice(N+1)}setTimeout(()=>sv(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),RD={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function SC(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}ra(SC,"getDirectionAwareKey");function CC(e,t,s){const r=SC(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return RD[r]}ra(CC,"getFocusIntent");function sv(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}ra(sv,"focusFirst");function EC(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ra(EC,"wrapArray");var AC=CD,TC=TD,$D=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},fa=new WeakMap,Vc=new WeakMap,Gc={},bf=0,RC=function(e){return e&&(e.host||RC(e.parentNode))},ID=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=RC(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})},PD=function(e,t,s,r){var i=ID(t,Array.isArray(e)?e:[e]);Gc[s]||(Gc[s]=new WeakMap);var a=Gc[s],l=[],o=new Set,c=new Set(i),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};i.forEach(u);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",v=(fa.get(m)||0)+1,b=(a.get(m)||0)+1;fa.set(m,v),a.set(m,b),l.push(m),v===1&&g&&Vc.set(m,!0),b===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return h(t),o.clear(),bf++,function(){l.forEach(function(f){var m=fa.get(f)-1,p=a.get(f)-1;fa.set(f,m),a.set(f,p),m||(Vc.has(f)||f.removeAttribute(r),Vc.delete(f)),p||f.removeAttribute(s)}),bf--,bf||(fa=new WeakMap,fa=new WeakMap,Vc=new WeakMap,Gc={})}},$C=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=$D(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),PD(r,i,s,"aria-hidden")):function(){return null}},qs=function(){return qs=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},qs.apply(this,arguments)};function IC(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 MD(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 Ru="right-scroll-bar-position",$u="width-before-scroll-bar",DD="with-scroll-bars-hidden",OD="--removed-body-scroll-bar-size";function kf(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function LD(e,t){var s=d.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var _D=typeof window<"u"?d.useLayoutEffect:d.useEffect,Fy=new WeakMap;function FD(e,t){var s=LD(null,function(r){return e.forEach(function(i){return kf(i,r)})});return _D(function(){var r=Fy.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||kf(o,null)}),a.forEach(function(o){i.has(o)||kf(o,l)})}Fy.set(s,e)},[e]),s}function zD(e){return e}function UD(e,t){t===void 0&&(t=zD);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 BD(e){e===void 0&&(e={});var t=UD(null);return t.options=qs({async:!0,ssr:!1},e),t}var PC=function(e){var t=e.sideCar,s=IC(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return d.createElement(r,qs({},s))};PC.isSideCarExport=!0;function WD(e,t){return e.useMedium(t),PC}var MC=BD(),Nf=function(){},hh=d.forwardRef(function(e,t){var s=d.useRef(null),r=d.useState({onScrollCapture:Nf,onWheelCapture:Nf,onTouchMoveCapture:Nf}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,v=e.inert,b=e.allowPinchZoom,j=e.as,x=j===void 0?"div":j,w=e.gapMode,y=IC(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,N=FD([s,t]),S=qs(qs({},y),i);return d.createElement(d.Fragment,null,h&&d.createElement(k,{sideCar:MC,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:v,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:w}),l?d.cloneElement(d.Children.only(o),qs(qs({},S),{ref:N})):d.createElement(x,qs({},S,{className:c,ref:N}),o))});hh.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};hh.classNames={fullWidth:$u,zeroRight:Ru};var HD=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function KD(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=HD();return t&&e.setAttribute("nonce",t),e}function VD(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function GD(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var YD=function(){var e=0,t=null;return{add:function(s){e==0&&(t=KD())&&(VD(t,s),GD(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},qD=function(){var e=YD();return function(t,s){d.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},DC=function(){var e=qD(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},QD={left:0,top:0,right:0,gap:0},Sf=function(e){return parseInt(e||"",10)||0},XD=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[Sf(s),Sf(r),Sf(i)]},JD=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return QD;var t=XD(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])}},ZD=DC(),za="data-scroll-locked",eO=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(DD,` {
42
- overflow: hidden `).concat(r,`;
43
- padding-right: `).concat(o,"px ").concat(r,`;
44
- }
45
- body[`).concat(za,`] {
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(Ru,` {
59
- right: `).concat(o,"px ").concat(r,`;
60
- }
61
-
62
- .`).concat($u,` {
63
- margin-right: `).concat(o,"px ").concat(r,`;
64
- }
65
-
66
- .`).concat(Ru," .").concat(Ru,` {
67
- right: 0 `).concat(r,`;
68
- }
69
-
70
- .`).concat($u," .").concat($u,` {
71
- margin-right: 0 `).concat(r,`;
72
- }
73
-
74
- body[`).concat(za,`] {
75
- `).concat(OD,": ").concat(o,`px;
76
- }
77
- `)},zy=function(){var e=parseInt(document.body.getAttribute(za)||"0",10);return isFinite(e)?e:0},tO=function(){d.useEffect(function(){return document.body.setAttribute(za,(zy()+1).toString()),function(){var e=zy()-1;e<=0?document.body.removeAttribute(za):document.body.setAttribute(za,e.toString())}},[])},nO=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;tO();var a=d.useMemo(function(){return JD(i)},[i]);return d.createElement(ZD,{styles:eO(a,!t,i,s?"":"!important")})},$p=!1;if(typeof window<"u")try{var Yc=Object.defineProperty({},"passive",{get:function(){return $p=!0,!0}});window.addEventListener("test",Yc,Yc),window.removeEventListener("test",Yc,Yc)}catch{$p=!1}var ma=$p?{passive:!1}:!1,sO=function(e){return e.tagName==="TEXTAREA"},OC=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!sO(e)&&s[t]==="visible")},rO=function(e){return OC(e,"overflowY")},iO=function(e){return OC(e,"overflowX")},Uy=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=LC(e,r);if(i){var a=_C(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},aO=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},lO=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},LC=function(e,t){return e==="v"?rO(t):iO(t)},_C=function(e,t){return e==="v"?aO(t):lO(t)},oO=function(e,t){return e==="h"&&t==="rtl"?-1:1},cO=function(e,t,s,r,i){var a=oO(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=_C(e,o),g=p[0],v=p[1],b=p[2],j=v-b-a*g;(g||j)&&LC(e,o)&&(f+=j,m+=g);var x=o.parentNode;o=x&&x.nodeType===Node.DOCUMENT_FRAGMENT_NODE?x.host:x}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(u=!0),u},qc=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},By=function(e){return[e.deltaX,e.deltaY]},Wy=function(e){return e&&"current"in e?e.current:e},uO=function(e,t){return e[0]===t[0]&&e[1]===t[1]},dO=function(e){return`
78
- .block-interactivity-`.concat(e,` {pointer-events: none;}
79
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
80
- `)},hO=0,pa=[];function fO(e){var t=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),i=d.useState(hO++)[0],a=d.useState(DC)[0],l=d.useRef(e);d.useEffect(function(){l.current=e},[e]),d.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var v=MD([e.lockRef.current],(e.shards||[]).map(Wy),!0).filter(Boolean);return v.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(v,b){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!l.current.allowPinchZoom;var j=qc(v),x=s.current,w="deltaX"in v?v.deltaX:x[0]-j[0],y="deltaY"in v?v.deltaY:x[1]-j[1],k,N=v.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in v&&S==="h"&&N.type==="range")return!1;var C=window.getSelection(),$=C&&C.anchorNode,R=$?$===N||$.contains(N):!1;if(R)return!1;var I=Uy(S,N);if(!I)return!0;if(I?k=S:(k=S==="v"?"h":"v",I=Uy(S,N)),!I)return!1;if(!r.current&&"changedTouches"in v&&(w||y)&&(r.current=k),!k)return!0;var F=r.current||k;return cO(F,b,v,F==="h"?w:y)},[]),c=d.useCallback(function(v){var b=v;if(!(!pa.length||pa[pa.length-1]!==a)){var j="deltaY"in b?By(b):qc(b),x=t.current.filter(function(k){return k.name===b.type&&(k.target===b.target||b.target===k.shadowParent)&&uO(k.delta,j)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var w=(l.current.shards||[]).map(Wy).filter(Boolean).filter(function(k){return k.contains(b.target)}),y=w.length>0?o(b,w[0]):!l.current.noIsolation;y&&b.cancelable&&b.preventDefault()}}},[]),u=d.useCallback(function(v,b,j,x){var w={name:v,delta:b,target:j,should:x,shadowParent:mO(j)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(y){return y!==w})},1)},[]),h=d.useCallback(function(v){s.current=qc(v),r.current=void 0},[]),f=d.useCallback(function(v){u(v.type,By(v),v.target,o(v,e.lockRef.current))},[]),m=d.useCallback(function(v){u(v.type,qc(v),v.target,o(v,e.lockRef.current))},[]);d.useEffect(function(){return pa.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,ma),document.addEventListener("touchmove",c,ma),document.addEventListener("touchstart",h,ma),function(){pa=pa.filter(function(v){return v!==a}),document.removeEventListener("wheel",c,ma),document.removeEventListener("touchmove",c,ma),document.removeEventListener("touchstart",h,ma)}},[]);var p=e.removeScrollBar,g=e.inert;return d.createElement(d.Fragment,null,g?d.createElement(a,{styles:dO(i)}):null,p?d.createElement(nO,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function mO(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const pO=WD(MC,fO);var rv=d.forwardRef(function(e,t){return d.createElement(hh,qs({},e,{ref:t,sideCar:pO}))});rv.classNames=hh.classNames;var gO=Object.defineProperty,rt=(e,t)=>gO(e,"name",{value:t,configurable:!0}),Ip=["Enter"," "],xO=["ArrowDown","PageUp","Home"],FC=["ArrowUp","PageDown","End"],vO=[...xO,...FC],jO={ltr:[...Ip,"ArrowRight"],rtl:[...Ip,"ArrowLeft"]},wO={ltr:["ArrowLeft"],rtl:["ArrowRight"]},fh="Menu",[Bo,yO,bO]=Yd(fh),[ia,zC]=Ms(fh,[bO,ih,dh]),mh=ih(),UC=dh(),[BC,yi]=ia(fh),[kO,oc]=ia(fh),NO=rt(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=mh(t),[c,u]=d.useState(null),h=d.useRef(!1),f=Sn(a),m=oh(i);return d.useEffect(()=>{const p=rt(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=rt(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),d.useEffect(()=>{if(!s)return;const p=rt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),n.jsx(Kx,{...o,children:n.jsx(BC,{scope:t,open:s,onOpenChange:f,content:c,onContentChange:u,children:n.jsx(kO,{scope:t,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),WC=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,...i}=t,a=mh(r);return n.jsx(QS,{...a,...i,ref:s})},"MenuAnchor")),HC="MenuPortal",[SO,KC]=ia(HC,{forceMount:void 0}),CO=rt(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=yi(HC,t);return n.jsx(SO,{scope:t,forceMount:s,children:n.jsx(lr,{present:s||a.open,children:n.jsx(Xd,{asChild:!0,container:i,children:r})})})},"MenuPortal"),Rs="MenuContent",[EO,iv]=ia(Rs),AO=d.forwardRef(rt(function(t,s){const r=KC(Rs,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=yi(Rs,t.__scopeMenu),o=oc(Rs,t.__scopeMenu);return n.jsx(Bo.Provider,{scope:t.__scopeMenu,children:n.jsx(lr,{present:i||l.open,children:n.jsx(Bo.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(TO,{...a,ref:s}):n.jsx(RO,{...a,ref:s})})})})},"MenuContent")),TO=d.forwardRef(rt(function(t,s){const r=yi(Rs,t.__scopeMenu),i=d.useRef(null),a=jt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return $C(l)},[]),n.jsx(av,{...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")),RO=d.forwardRef(rt(function(t,s){const r=yi(Rs,t.__scopeMenu);return n.jsx(av,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),$O=ci("MenuContent.ScrollLock"),av=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:v,...b}=t,j=yi(Rs,r),x=oc(Rs,r),w=mh(r),y=UC(r),k=yO(r),[N,S]=d.useState(null),C=d.useRef(null),$=jt(s,C,j.onContentChange),R=d.useRef(0),I=d.useRef(""),F=d.useRef(0),_=d.useRef(null),E=d.useRef("right"),M=d.useRef(0),P=v?rv:d.Fragment,U=v?{as:$O,allowPinchZoom:!0}:void 0,L=rt(O=>{var ce,Pe;const V=I.current+O,X=k().filter(Te=>!Te.disabled),G=document.activeElement,Z=(ce=X.find(Te=>Te.ref.current===G))==null?void 0:ce.textValue,z=X.map(Te=>Te.textValue),q=t1(z,V,Z),Q=(Pe=X.find(Te=>Te.textValue===q))==null?void 0:Pe.ref.current;rt(function Te(Le){I.current=Le,window.clearTimeout(R.current),Le!==""&&(R.current=window.setTimeout(()=>Te(""),1e3))},"updateSearch")(V),Q&&setTimeout(()=>Q.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(R.current),[]),ch();const W=d.useCallback(O=>{var X,G;return E.current===((X=_.current)==null?void 0:X.side)&&s1(O,(G=_.current)==null?void 0:G.area)},[]);return n.jsx(EO,{scope:r,searchRef:I,onItemEnter:d.useCallback(O=>{W(O)&&O.preventDefault()},[W]),onItemLeave:d.useCallback(O=>{var V;W(O)||((V=C.current)==null||V.focus(),S(null))},[W]),onTriggerLeave:d.useCallback(O=>{W(O)&&O.preventDefault()},[W]),pointerGraceTimerRef:F,onPointerGraceIntentChange:d.useCallback(O=>{_.current=O},[]),children:n.jsx(P,{...U,children:n.jsx(fC,{asChild:!0,trapped:a,onMountAutoFocus:Ie(l,O=>{var V;O.preventDefault(),(V=C.current)==null||V.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(Qd,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(AC,{asChild:!0,...y,dir:x.dir,orientation:"vertical",loop:i,currentTabStopId:N,onCurrentTabStopIdChange:S,onEntryFocus:Ie(u,O=>{x.isUsingKeyboardRef.current||O.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(XS,{role:"menu","aria-orientation":"vertical","data-state":lv(j.open),"data-radix-menu-content":"",dir:x.dir,...w,...b,ref:$,style:{outline:"none",...b.style},onKeyDown:Ie(b.onKeyDown,O=>{const X=O.target.closest("[data-radix-menu-content]")===O.currentTarget,G=O.ctrlKey||O.altKey||O.metaKey,Z=O.key.length===1;X&&(O.key==="Tab"&&O.preventDefault(),!G&&Z&&L(O.key));const z=C.current;if(O.target!==z||!vO.includes(O.key))return;O.preventDefault();const Q=k().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);FC.includes(O.key)&&Q.reverse(),ZC(Q)}),onBlur:Ie(t.onBlur,O=>{O.currentTarget.contains(O.target)||(window.clearTimeout(R.current),I.current="")}),onPointerMove:Ie(t.onPointerMove,Za(O=>{const V=O.target,X=M.current!==O.clientX;if(O.currentTarget.contains(V)&&X){const G=O.clientX>M.current?"right":"left";E.current=G,M.current=O.clientX}}))})})})})})})},"MenuContentImpl")),VC=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(mt.div,{role:"group",...i,ref:s})},"MenuGroup")),IO=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(mt.div,{...i,ref:s})},"MenuLabel")),Pp="MenuItem",Hy="menu.itemSelect",GC=d.forwardRef(rt(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=d.useRef(null),o=oc(Pp,t.__scopeMenu),c=iv(Pp,t.__scopeMenu),u=jt(s,l),h=d.useRef(!1),f=rt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(Hy,{bubbles:!0,cancelable:!0});m.addEventListener(Hy,g=>i==null?void 0:i(g),{once:!0}),qd(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(YC,{...a,ref:u,disabled:r,onClick:Ie(t.onClick,f),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===" "||Ip.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),YC=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=iv(Pp,r),c=UC(r),u=d.useRef(null),h=jt(s,u),[f,m]=d.useState(!1),[p,g]=d.useState("");return d.useEffect(()=>{const v=u.current;v&&g((v.textContent??"").trim())},[l.children]),n.jsx(Bo.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(TC,{asChild:!0,...c,focusable:!i,children:n.jsx(mt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:h,onPointerMove:Ie(t.onPointerMove,Za(v=>{i?o.onItemLeave(v):(o.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ie(t.onPointerLeave,Za(v=>o.onItemLeave(v))),onFocus:Ie(t.onFocus,()=>m(!0)),onBlur:Ie(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),PO="MenuRadioGroup",[MO,DO]=ia(PO,{value:void 0,onValueChange:rt(()=>{},"onValueChange")}),OO=d.forwardRef(rt(function(t,s){const{value:r,onValueChange:i,...a}=t,l=Sn(i);return n.jsx(MO,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(VC,{...a,ref:s})})},"MenuRadioGroup")),LO="MenuRadioItem",_O=d.forwardRef(rt(function(t,s){const{value:r,...i}=t,a=DO(LO,t.__scopeMenu),l=r===a.value;return n.jsx(zO,{scope:t.__scopeMenu,checked:l,children:n.jsx(GC,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":JC(l),onSelect:Ie(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),FO="MenuItemIndicator",[zO,xY]=ia(FO,{checked:!1}),UO=d.forwardRef(rt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(mt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),qC="MenuSub",[BO,QC]=ia(qC),WO=rt(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=yi(qC,t),l=mh(t),[o,c]=d.useState(null),[u,h]=d.useState(null),f=Sn(i);return d.useEffect(()=>(a.open===!1&&f(!1),()=>f(!1)),[a.open,f]),n.jsx(Kx,{...l,children:n.jsx(BC,{scope:t,open:r,onOpenChange:f,content:u,onContentChange:h,children:n.jsx(BO,{scope:t,contentId:Ts(),triggerId:Ts(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Qc="MenuSubTrigger",HO=d.forwardRef(rt(function(t,s){const r=yi(Qc,t.__scopeMenu),i=oc(Qc,t.__scopeMenu),a=QC(Qc,t.__scopeMenu),l=iv(Qc,t.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:t.__scopeMenu},f=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>f,[f]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=jt(s,a.onTriggerChange);return n.jsx(WC,{asChild:!0,...h,children:n.jsx(YC,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":lv(r.open),...t,ref:m,onClick:p=>{var g;(g=t.onClick)==null||g.call(t,p),!(t.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Ie(t.onPointerMove,Za(p=>{l.onItemEnter(p),!p.defaultPrevented&&!t.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),f()},100))})),onPointerLeave:Ie(t.onPointerLeave,Za(p=>{var v,b;f();const g=(v=r.content)==null?void 0:v.getBoundingClientRect();if(g){const j=(b=r.content)==null?void 0:b.dataset.side,x=j==="right",w=x?-5:5,y=g[x?"left":"right"],k=g[x?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:y,y:g.bottom}],side:j}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Ie(t.onKeyDown,p=>{var v;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||jO[i.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})},"MenuSubTrigger")),KO="MenuSubContent",VO=d.forwardRef(rt(function(t,s){const r=KC(Rs,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=yi(Rs,t.__scopeMenu),c=oc(Rs,t.__scopeMenu),u=QC(KO,t.__scopeMenu),h=d.useRef(null),f=jt(s,h);return n.jsx(Bo.Provider,{scope:t.__scopeMenu,children:n.jsx(lr,{present:i||o.open,children:n.jsx(Bo.Slot,{scope:t.__scopeMenu,children:n.jsx(av,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside: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 v;const p=m.currentTarget.contains(m.target),g=wO[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(v=u.trigger)==null||v.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function lv(e){return e?"open":"closed"}rt(lv,"getOpenState");function XC(e){return e==="indeterminate"}rt(XC,"isIndeterminate");function JC(e){return XC(e)?"indeterminate":e?"checked":"unchecked"}rt(JC,"getCheckedState");function ZC(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}rt(ZC,"focusFirst");function e1(e,t){return e.map((s,r)=>e[(t+r)%e.length])}rt(e1,"wrapArray");function t1(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=e1(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}rt(t1,"getNextMatch");function n1(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}rt(n1,"isPointInPolygon");function s1(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return n1(s,t)}rt(s1,"isPointerInGraceArea");function Za(e){return t=>t.pointerType==="mouse"?e(t):void 0}rt(Za,"whenMouse");var GO=NO,YO=WC,qO=CO,QO=AO,XO=VC,JO=IO,ZO=GC,eL=OO,tL=_O,nL=UO,sL=WO,rL=HO,iL=VO,aL=Object.defineProperty,es=(e,t)=>aL(e,"name",{value:t,configurable:!0}),ov="DropdownMenu",[lL,vY]=Ms(ov,[zC]),ts=zC(),[oL,r1]=lL(ov),cL=es(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=ts(t),u=d.useRef(null),[h,f]=ji({prop:i,defaultProp:a??!1,onChange:l,caller:ov});return n.jsx(oL,{scope:t,triggerId:Ts(),triggerRef:u,contentId:Ts(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:n.jsx(GO,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),uL="DropdownMenuTrigger",dL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=r1(uL,r),o=ts(r),c=jt(s,l.triggerRef);return n.jsx(YO,{asChild:!0,...o,children:n.jsx(mt.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")),hL=es(e=>{const{__scopeDropdownMenu:t,...s}=e,r=ts(t);return n.jsx(qO,{...r,...s})},"DropdownMenuPortal"),fL="DropdownMenuContent",mL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=r1(fL,r),l=ts(r),o=d.useRef(!1);return n.jsx(QO,{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,f=u.button===2||h;(!a.modal||f)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),pL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(XO,{...a,...i,ref:s})},"DropdownMenuGroup")),gL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(JO,{...a,...i,ref:s})},"DropdownMenuLabel")),xL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(ZO,{...a,...i,ref:s})},"DropdownMenuItem")),vL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(eL,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),jL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(tL,{...a,...i,ref:s})},"DropdownMenuRadioItem")),wL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(nL,{...a,...i,ref:s})},"DropdownMenuSeparator")),yL=es(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=ts(t),[o,c]=ji({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(sL,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),bL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(rL,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),kL=d.forwardRef(es(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ts(r);return n.jsx(iL,{...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")),cc=cL,uc=dL,vl=hL,dc=mL,i1=pL,Qi=gL,cs=xL,NL=vL,SL=jL,yr=wL,CL=yL,EL=bL,AL=kL,TL=Object.defineProperty,jl=(e,t)=>TL(e,"name",{value:t,configurable:!0}),cv="Tabs",[RL,jY]=Ms(cv,[dh]),a1=dh(),[$L,uv]=RL(cv),IL=d.forwardRef(jl(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,f=oh(c),[m,p]=ji({prop:i,onChange:a,defaultProp:l??"",caller:cv});return n.jsx($L,{scope:r,baseId:Ts(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:n.jsx(mt.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),PL="TabsList",ML=d.forwardRef(jl(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=uv(PL,r),o=a1(r);return n.jsx(AC,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(mt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),DL="TabsTrigger",OL=d.forwardRef(jl(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=uv(DL,r),c=a1(r),u=dv(o.baseId,i),h=hv(o.baseId,i),f=i===o.value;return n.jsx(TC,{asChild:!0,...c,focusable:!a,active:f,children:n.jsx(mt.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown: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";!f&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),LL="TabsContent",_L=d.forwardRef(jl(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=uv(LL,r),u=dv(c.baseId,i),h=hv(c.baseId,i),f=i===c.value,m=d.useRef(f);return d.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(lr,{present:a||f,children:({present:p})=>n.jsx(mt.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function dv(e,t){return`${e}-trigger-${t}`}jl(dv,"makeTriggerId");function hv(e,t){return`${e}-content-${t}`}jl(hv,"makeContentId");var FL=IL,zL=ML,UL=OL,BL=_L;function qt(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?WL(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${Ky(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Vt(r):Ky(r):String(e)}case"date":return HL(String(e));default:return typeof e=="string"?e:typeof e=="number"?Vt(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function WL(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return rD(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function HL(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?lh(t[0],{year:!0,compact:!0}):e}function Mp(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?lh(t[0],{compact:!0}):e}function Ky(e){return String(Math.round(e*100)/100)}function pd(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 KL({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:qt(a.value,e.unit,e.currency)})]},a.category)})})}const VL=/^(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 )/,GL=/^(… |\.\.\. |\(no change\)$|\)/;function YL(e){return e.replace(/\n$/,"").split(`
81
- `).map(s=>({kind:qL(s),text:s}))}function qL(e){return e.startsWith("@@")?"hunk":VL.test(e)||GL.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function QL({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 gd({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=YL(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(QL,{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 XL({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:qt(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(gd,{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 tn="#/",fv="#/needs",ii="#/chat",Nt="#/agents",xt="#/activity",gn="#/settings",Xi="#/files",JL="#/welcome";function Iu(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function Xc(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`${Xi}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function ZL(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 at(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function e_(e){if(l1(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 Ii(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function l1(e){const t=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{groupId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{}}}catch{return null}}function St(e,t,s){return`${Nt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function t_(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 el(e){return`${xt}/conversations/${encodeURIComponent(e)}`}const n_="#/p";function Pr(e,t,s){const r=`${n_}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function mv(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 s_="p.";function Ji(e,t,s){return`${gn}/${encodeURIComponent(c1(e,t))}`}function o1(e){const t=e.indexOf("?");if(t===-1)return{};try{const s={};for(const[r,i]of new URLSearchParams(e.slice(t+1)))i!==""&&(s[r]=i);return s}catch{return{}}}function r_(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 c1(e,t){return`${s_}${e}${t===e?"":`.${t}`}`}function _e(e){return e?`${gn}/${e}`:gn}function i_(e){return`${_e("accounts")}?account=${encodeURIComponent(e)}`}function a_(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function u1(e,t,s){const r=new RegExp(`^#/settings/${t}\\?(.*)$`).exec(e);if(!r)return null;try{return new URLSearchParams(r[1]).get(s)||null}catch{return null}}function l_(e){return`${_e("connections")}?connection=${encodeURIComponent(e)}`}function o_(e){return u1(e,"connections","connection")}function c_(e){return u1(e,"secrets","secret")}function u_(e){return`${_e("plugins")}?install=${encodeURIComponent(e)}`}const d_=`${_e("plugins")}?tab=browse`;function h_(e){return`${_e("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function f_(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function d1(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function m_(e){var s,r;const t=(r=(s=d1(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Vy(e){const t=d1(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const p_=[{route:tn,label:"Home"},{route:ii,label:"Chat"},{route:Nt,label:"Agents"},{route:xt,label:"Activity"},{route:Xi,label:"Files"},{route:gn,label:"Settings"}],g_=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],x_=[{id:"you",label:"Profile",group:"you"},{id:"appearance",label:"Appearance",group:"you"},{id:"notifications",label:"Notifications",group:"you"},{id:"telegram",label:"Telegram",group:"you"},{id:"memory",label:"Memory",group:"you"},{id:"proposals",label:"Proposals",group:"you"},{id:"accounts",label:"Model accounts",group:"access"},{id:"computer",label:"Computer & browser",group:"access"},{id:"secrets",label:"Keys and secrets",group:"access"},{id:"connections",label:"Connections",group:"access"},{id:"lock",label:"Lock screen",group:"access"},{id:"api",label:"API tokens",group:"access"},{id:"watchers",label:"Watchers",group:"running"},{id:"backup",label:"Backup",group:"running"},{id:"system",label:"System",group:"running"},{id:"plugins",label:"All plugins",group:"plugins"}];function v_(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const h1="#/settings/notifications/recent",j_=_e("backup");function w_(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return el(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return Pr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return Pr("email","mail")}return e==="#/settings/email"?Ji("email","settings"):{"#/overview":tn,"#/approvals":tn,"#/events":`${xt}/events`,"#/jobs":`${xt}/jobs`,"#/conversations":xt,"#/missions":`${Nt}?tab=missions`,"#/offers":`${Nt}?tab=offers`,"#/reminders":`${Nt}?tab=reminders`,"#/providers":_e("accounts"),"#/browser":_e("computer"),"#/sentinels":_e("watchers"),"#/settings/sentinels":_e("watchers")}[e]??null}function f1(e){if(e===""||e==="#"||e===tn)return tn;if(e.startsWith(ii))return ii;if(e.startsWith(Nt))return Nt;if(e.startsWith(xt))return xt;if(e.startsWith(Xi))return Xi;if(e.startsWith(gn))return gn;const t=mv(e);return t?Pr(t.plugin,t.page):tn}const y_="#/chat?group=new";function b_(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 pv="front-desk",gv=[{id:pv,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."}],m1=new Set(gv.map(e=>e.id)),Gy=e=>m1.has(e);function Yy(e,t){const s=t.filter(r=>!m1.has(r));return[...gv.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function k_(e,t){return e.find(s=>(s.roles??[]).includes(t))}const qy=["coding","finance","mail","research","calendar","files","memory"],N_={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[pv]:"buddi"},S_=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function C_(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of S_)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Dp=null;function E_(e){Dp=e}function hc(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=N_[s];if(r)return{key:r}}const t=C_(e.tools??[]);return t?{key:t}:Dp!==null&&e.id===Dp?{key:"buddi"}:{key:qy[A_(e.id)%qy.length]??"coding"}}function fc(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function A_(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const T_=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","ping"];function R_(e){const s=e.replace(/\r\n/g,`
82
- `).split(`
83
-
84
- `),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
85
- `)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),f=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:T_.includes(o)?o:"ping",data:$_(c.join(`
86
- `))})}return{events:i,rest:r}}function $_(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function ph(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,h,f,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await t(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...i===null?{}:{"Last-Event-ID":i}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const v=g.body.getReader(),b=new TextDecoder;let j="";for(;;){const{done:x,value:w}=await v.read();if(x)break;j+=b.decode(w,{stream:!0});const{events:y,rest:k}=R_(j);j=k;for(const N of y)e.onEvent(N),N.id!==null&&(i=N.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const xv="0.1.0+b9c737b";function vv(e,t=xv){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function I_(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const P_=5*6e4,M_=6e4,D_=5e3,Op="buddi:stream-reconnected",p1="buddi.autoReloadedFor";function O_(){window.dispatchEvent(new Event(Op))}const Qy=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let jv=Date.now(),Jc=0;const Xy=()=>{jv=Date.now()};function L_(){if(Jc===0){jv=Date.now();for(const e of Qy)window.addEventListener(e,Xy,{capture:!0,passive:!0})}return Jc+=1,()=>{if(Jc-=1,Jc===0)for(const e of Qy)window.removeEventListener(e,Xy,{capture:!0})}}function __(e=Date.now()){return e-jv}function F_(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 z_(e){return e.hidden?!0:e.idleMs>=M_&&!e.busy}function U_(e){try{return window.sessionStorage.getItem(p1)===e}catch{return!1}}function B_(e){try{window.sessionStorage.setItem(p1,e)}catch{}}function W_(e){const t=d.useRef(e);t.current=e,d.useEffect(()=>{const s=()=>t.current();return window.addEventListener(Op,s),()=>window.removeEventListener(Op,s)},[])}function H_(e,t=()=>window.location.reload(),s=xv){const r=vv(e,s),i=d.useRef(t);i.current=t,d.useEffect(()=>L_(),[]),d.useEffect(()=>{if(!r||e===void 0||U_(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";z_({hidden:c,idleMs:__(),busy:F_()})&&(a=!0,B_(e),i.current())};l();const o=window.setInterval(l,D_);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const K_="/api/chat/attention/stream";function g1(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 x1(e,t){const s=g1(e,t);return[...s.top,...s.middle,...s.bottom]}function gh(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 V_(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 G_(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function Y_(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function q_(){const[e,t]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{xe("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=ph({url:K_,onEvent:()=>r(),onReconnect:O_});return()=>{s=!0,i.close()}},[]),Y_(e)}const xh="maker";function wv(e){return e.filter(t=>t.available&&!t.roles.includes(xh))}function v1(e){return wv(e).length>=2}function Q_(e){var t;return((t=e.find(s=>s.roles.includes(xh)))==null?void 0:t.name)??"the agent maker"}const X_="{{default}}";function J_(e,t){return e.split(X_).join(t??"your assistant")}function Z_(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>J_(s,t))}function eF(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 tF(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 j1(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 nF="Settings → Model accounts",sF="Install it in Settings → Plugins";function Lp(e){return e!=null&&e.heldBack?{section:"plugins",label:sF}:{section:"accounts",label:nF}}const rF={home:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),n.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),n.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),n.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),n.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),n.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,n.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),n.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),n.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),n.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),n.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),n.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,n.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),n.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),n.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),n.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),n.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],terminal:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),n.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),n.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],briefcase:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"6",width:"14.4",height:"10.2",rx:"1.6"}),n.jsx("path",{d:"M7.4 6V4.6a1 1 0 0 1 1-1h3.2a1 1 0 0 1 1 1V6M2.8 10.4h14.4"})]})],pin:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M10 17.2s5.2-4.9 5.2-9a5.2 5.2 0 0 0-10.4 0c0 4.1 5.2 9 5.2 9Z"}),n.jsx("circle",{cx:"10",cy:"8.2",r:"1.9"})]})],sun:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),n.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),n.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),n.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),n.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],lock:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"4",y:"8.6",width:"12",height:"8.6",rx:"2.2"}),n.jsx("path",{d:"M6.8 8.6V6.2a3.2 3.2 0 0 1 6.4 0v2.4"})]})],eye:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),n.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),n.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),n.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),n.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,n.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,n.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,n.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,n.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],clock:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M10 5.8V10l2.8 1.8"})]})],dot:[20,1.6,n.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),n.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,n.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),n.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),n.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,n.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,n.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,n.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],thought:[13,1.4,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),n.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,n.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),n.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,n.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,n.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,n.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,n.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),n.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,n.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,n.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,n.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],grip:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"6",cy:"4",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"4",r:"1.2"}),n.jsx("circle",{cx:"6",cy:"8",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"8",r:"1.2"}),n.jsx("circle",{cx:"6",cy:"12",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"12",r:"1.2"})]})],more:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,n.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,n.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),n.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),n.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,n.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,n.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,n.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,n.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,n.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,n.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,n.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,n.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],"shape-structured":[16,1.4,n.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function me({name:e,size:t,className:s,...r}){const[i,a,l,o]=rF[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 w1="buddi.rosterCollapsed";function iF(){try{return window.localStorage.getItem(w1)==="1"}catch{return!1}}function aF(e){try{window.localStorage.setItem(w1,e?"1":"0")}catch{}}function y1({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const f=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=d.useState(iF),v=b=>n.jsx(lF,{agent:b,active:b.id===t,attention:s.get(b.id),side:m,onSelect:r,lastAt:(a==null?void 0:a.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return n.jsxs("nav",{className:i==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":i==="vertical"&&p?"true":void 0,children:[e.top.map(v),e.top.length>0&&e.middle.length>0?n.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,i==="vertical"&&!p&&e.middle.length>0?n.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,n.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(v),u&&v1(f)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:n.jsx(me,{name:"plus"})}):null]}),o.map(b=>n.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":b.id===c?"true":void 0,"aria-current":b.id===c?"true":void 0,"aria-label":`${b.name}, ${b.members.length} agents`,onClick:()=>u(b.id),children:[n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(j=>{const x=f.find(w=>w.id===j);return n.jsx(jh,{className:"wb-group-chip",id:j,name:(x==null?void 0:x.name)??"?",face:x,initials:1},j)})}),n.jsxs("span",{className:"wb-face-text",children:[n.jsx("span",{className:"wb-face-name",children:b.name}),n.jsx("span",{className:"wb-face-status",children:b.members.map(j=>{var x;return((x=f.find(w=>w.id===j))==null?void 0:x.name)??j}).join(", ")})]})]},b.id))]}):u?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsx("div",{className:"wb-groups-head",children:n.jsx("span",{className:"wb-groups-label",children:"Groups"})}),n.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",n.jsx("a",{href:Nt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(v),i==="vertical"?n.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":p?"Show agent names":"Hide agent names","aria-pressed":p,onClick:()=>g(b=>(aF(!b),!b)),children:n.jsx(me,{name:p?"chevron-right":"chevron-left"})}):null]})}function lF({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=gh(s),c=V_(s)??(e.available?a?sD(a):e.description:e.unavailableReason??"Cannot run right now"),u=G_(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",f=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(Do,{children:[n.jsx(Oo,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...fc(hc(e)),"data-active":t?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":f,"aria-current":t?"true":void 0,disabled:!e.available,onClick:()=>e.available&&i(e.id),children:[n.jsxs("span",{className:"wb-face-frame",children:[n.jsx(jh,{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(me,{name:"out"})})]})}),n.jsx(Lo,{children:n.jsxs(_o,{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:oF(o)}):null]})})]})}function oF(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function cF(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const uF="modulepreload",dF=function(e,t){return new URL(e,t).href},Jy={},hF=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=dF(u,r),u in Jy)return;Jy[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const v=l[g];if(v.href===u&&(!h||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":uF,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((g,v)=>{p.addEventListener("load",g),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})},fF="buddi",mF=["core","coding","finance","garage","mail","maker","playground","research"],aa=e=>`./mascot/${e}.png`,pF=["core"],_p=(e,t)=>pF.includes(e)?`./mascot/anim/${e}-${t}.json`:null,gF=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],xF="Introduce yourself by name and say one thing you can do today.",vF=["Hello","A brain","What I take on","Reach me","Your assistant"],Bl=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Cf=e=>e.charAt(0).toUpperCase()+e.slice(1),jF=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Ua=[{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."}],wF=["days","mail"],Zy=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],D={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:vF,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 ${Bl(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${Bl(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":Cf(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":Cf(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: ${Bl(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 ${Bl(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=>`${jF[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Cf(Bl(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 Zc=null;const eb=new Map;function yF(){return Zc??(Zc=hF(()=>import("./lottie_light-Cdn77Osu.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Zc.catch(()=>{Zc=null}),Zc}function bF(e){let t=eb.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),eb.set(e,t)),t}const tb="(prefers-reduced-motion: reduce)";function b1(){const[e,t]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(tb).matches);return d.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(tb),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 vh({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=d.useRef(null),o=b1(),[c,u]=d.useState(!1),h=s==="xs"?null:_p(e,t);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([yF(),bF(h)]).then(([p,g])=>{if(f||!g||!l.current)return;const v=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?v.pause():v.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),v.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[o,h]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??aa(e),alt:"",onError:a})})}async function nb(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 k1(e,t="core"){const s=b1(),r=e!==null&&kF(e,t),[i,a]=d.useState(!1);return d.useEffect(()=>{if(a(!1),!e||r||!s||!_p(t,"idle"))return;let l=!1;return Promise.all([nb(e),nb(aa(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&_p(t,"idle")!==null&&(r||i)}function kF(e,t){const s=aa(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 jh({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=d.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=h?"image":f==null?void 0:f.kind,p=t?fc(hc({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?n.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(f==null?void 0:f.kind)==="image"?n.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:tF(s).slice(0,o)})}function Os({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(jh,{className:"ui-avatar",id:e,tint:cF(e),name:t,size:s,unavailable:r,face:i})}function xn({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Os,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const N1=d.createContext(null);function NF({picture:e,children:t}){return n.jsx(N1.Provider,{value:e??null,children:t})}function S1({size:e,anim:t}){const s=d.useContext(N1),[r,i]=d.useState(null),a=k1(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(vh,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const C1=d.createContext([]);function Mr({text:e,className:t}){const s=Fp(e.replace(/\r\n/g,`
88
- `).split(`
89
- `));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(zp,{block:r},i))})}const sb=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,rb=/^(#{1,6})\s+(.*?)\s*#*\s*$/,ib=/^\s*([-*_])(\s*\1){2,}\s*$/,eu=/^(\s*)([-*+])\s+(.*)$/,Wl=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,tu=/^\s*>\s?(.*)$/,Ef=/^\s*\|.*\|\s*$/,ab=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Fp(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=sb.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=rb.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(ib.test(r)){t.push({type:"hr"}),s+=1;continue}if(tu.test(r)){const o=[];for(;s<e.length&&tu.test(e[s]);)o.push(tu.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:Fp(o),raw:o.join(`
91
- `)});continue}if(Ef.test(r)&&s+1<e.length&&ab.test(e[s+1])){const o=Tf(r),c=Tf(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&Ef.test(e[s]);)u.push(Tf(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(eu.test(r)||Wl.test(r)){const o=Wl.exec(r)??eu.exec(r),c=Wl.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?Wl.exec(e[s]):eu.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],v=g.trim()!==""&&Af(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Af(e[s+1])>u;if(!v&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(Af(g),u+2))),s+=1}f.push(Fp(p))}t.push({type:"list",ordered:c,start:h,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||sb.test(o)||rb.test(o)||ib.test(o)||tu.test(o)||eu.test(o)||Wl.test(o)||Ef.test(o)&&s+1<e.length&&ab.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 Af(e){return e.length-e.trimStart().length}function Tf(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 zp({block:e}){switch(e.type){case"p":return n.jsx("p",{children:Cs(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:Cs(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(lb,{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(zp,{block:t},s))}),n.jsx(lb,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(d.Fragment,{children:Cs(i.text)},a):n.jsx(zp,{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:Cs(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:Cs(r)},i))},s))})]})})}}function lb({text:e,what:t,always:s=!1}){const[r,i]=d.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function SF({handle:e}){const s=d.useContext(C1).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(Do,{children:[n.jsx(Oo,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:at(s.id),children:["@",s.handle]})}),n.jsx(Lo,{children:n.jsxs(_o,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Os,{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 CF=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 Cs(e){const t=[];let s=e,r=0;for(;s!=="";){const i=CF.exec(s);if(!i){t.push(...ob(s,r));break}i.index>0&&t.push(...ob(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:Cs(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:Cs(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:Cs(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:Cs(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:Cs(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:Cs(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(SF,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function ob(e,t){return e.split(`
93
- `).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function EF({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:qt(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 AF=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear","check","clock"];function Se(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 We(e,t){if(t)return"const"in t?t.const:Se(e,t.path)}function qn(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 ut(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function ai(e){return Array.isArray(e)?e:[]}function TF(e,t){const s=ai(Se(e,t.points)).map(i=>{const a=qn(Se(i,t.y)),l=ut(Se(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=qn(We(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:ut(We(e,t.currency)),label:ut(We(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:qn(We(e,t.shadeBelow)),events:RF(e,t)}}function RF(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=ut(Se(a,s.label));if(o===null)return;const c=ut(Se(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?qn(Se(a,s.amount)):null})};if(s.parent){for(const a of ai(Se(e,t.points))){const l=ut(Se(a,t.x));for(const o of ai(Se(a,s.parent)))i(o,l)}return r}for(const a of ai(Se(e,s.path??t.points)))i(a,null);return r}function $F(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=Se(o,c.key);let h=null;if(c.bar){const f=qn(We(o,c.bar.max))??qn(We(e,c.bar.max)),m=qn(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:PF(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:ut(We(o,c.currency))??ut(We(e,c.currency)),bar:h}}),i=ai(Se(e,t.rows)),a=t.groupBy?IF(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:We(e,o.value),unit:o.unit??"text",currency:ut(We(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function IF(e,t,s){const r=new Map;for(const i of e){const a=String(Se(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 PF(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 MF(e,t){return{bars:ai(Se(e,t.bars)).map(r=>{const i=qn(Se(r,t.value)),a=ut(Se(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:ut(We(e,t.currency))}}function DF(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:We(e,r.value),unit:r.unit??"text",currency:ut(We(e,r.currency)),tone:r.tone??"neutral"}))};const s=Se(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:vn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const OF=new Set(["good","warning","critical","neutral","accent"]),LF=new Set(AF);function Up(e){return typeof e=="string"&&LF.has(e)?e:null}function yv(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=ut(Se(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:Up(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:ai(Se(e,t.items)).map(l=>{const o=ut(Se(l,t.value))??"",c=ut(Se(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?ut(Se(l,t.tone)):null;return{icon:Up(We(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>ut(Se(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&OF.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function _F(e,t){const s=ut(We(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?ut(Se(e,t.src)):null;return{kind:r,text:t.text?ut(Se(e,t.text)):null,src:i&&A1(i)?i:null,title:ut(We(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:We(e,a.value),unit:a.unit??"text"}))}}function FF(e,t){const s=t.diff?Se(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:ut(We(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:We(e,r.value),unit:r.unit??"text"}))}}function zF(e,t){const s=t.output?Se(e,t.output):void 0,r=l=>{const o=l?Se(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?Se(e,t.elapsedMs):void 0;return{command:ut(We(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:We(e,l.value),unit:l.unit??"text"}))}}const UF=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function E1(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&UF.test(t)?t.toLowerCase():null}function BF(e,t){return{artifactId:t.src?E1(Se(e,t.src)):null,title:ut(We(e,t.title)),caption:ut(We(e,t.caption)),...t.captionLabel?{captionLabel:ut(We(e,t.captionLabel))}:{}}}function cb(e){if(!A1(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 WF(e,t){const s=t.src?ut(Se(e,t.src)):null,r=t.port?Se(e,t.port):null,i=t.awaiting?ut(Se(e,t.awaiting)):null;return{target:s?cb(s):null,title:ut(We(e,t.title)),output:t.output?ut(Se(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?cb(i):null,reloadsItself:t.reloadsItself?Se(e,t.reloadsItself)===!0:!1,ports:t.ports?HF(Se(e,t.ports)):[]}}function HF(e){const t=ai(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function A1(e){return e.startsWith("/")&&!e.startsWith("//")}function vn(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 T1(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:TF(t,s)};case"table":return{renderer:"table",props:$F(t,s)};case"bars":return{renderer:"bars",props:MF(t,s)};case"keyvalue":return{renderer:"keyvalue",props:DF(t,s)};case"tiles":return{renderer:"tiles",props:yv(t,s,e.tool)};case"document":return{renderer:"document",props:_F(t,s)};case"diff":return{renderer:"diff",props:FF(t,s)};case"terminal":return{renderer:"terminal",props:zF(t,s)};case"image":return{renderer:"image",props:BF(t,s)};case"preview":return{renderer:"preview",props:WF(t,s)};default:return{renderer:"structured",props:{value:t}}}}var KF=Object.defineProperty,Ls=(e,t)=>KF(e,"name",{value:t,configurable:!0}),bv="Dialog",[R1,wY]=Ms(bv),[VF,_r]=R1(bv),kv=Ls(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=d.useRef(null),c=d.useRef(null),[u,h]=ji({prop:r,defaultProp:i??!1,onChange:a,caller:bv}),[f,m]=d.useState(0),[p,g]=d.useState(0);return n.jsx(VF,{scope:t,triggerRef:o,contentRef:c,contentId:Ts(),titleId:Ts(),descriptionId:Ts(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(v=>!v),[h]),modal:l,children:s})},"Dialog"),$1="DialogPortal",[GF,I1]=R1($1,{forceMount:void 0}),Nv=Ls(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=_r($1,t);return n.jsx(GF,{scope:t,forceMount:s,children:d.Children.map(r,l=>n.jsx(lr,{present:s||a.open,children:n.jsx(Xd,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),Bp="DialogOverlay",P1=d.forwardRef(Ls(function(t,s){const r=I1(Bp,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=_r(Bp,t.__scopeDialog);return l.modal?n.jsx(lr,{present:i||l.open,children:n.jsx(qF,{...a,ref:s})}):null},"DialogOverlay")),YF=ci("DialogOverlay.RemoveScroll"),qF=d.forwardRef(Ls(function(t,s){const{__scopeDialog:r,...i}=t,a=_r(Bp,r),l=gS(),o=jt(s,l);return n.jsx(rv,{as:YF,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(mt.div,{"data-state":Ev(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),Wo="DialogContent",Sv=d.forwardRef(Ls(function(t,s){const r=I1(Wo,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=_r(Wo,t.__scopeDialog);return n.jsx(lr,{present:i||l.open,children:l.modal?n.jsx(QF,{...a,ref:s}):n.jsx(XF,{...a,ref:s})})},"DialogContent")),QF=d.forwardRef(Ls(function(t,s){const r=_r(Wo,t.__scopeDialog),i=d.useRef(null),a=jt(s,r.contentRef,i);return d.useEffect(()=>{const l=i.current;if(l)return $C(l)},[]),n.jsx(M1,{...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")),XF=d.forwardRef(Ls(function(t,s){const r=_r(Wo,t.__scopeDialog),i=d.useRef(!1),a=d.useRef(!1);return n.jsx(M1,{...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")),M1=d.forwardRef(Ls(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=_r(Wo,r);return ch(),n.jsx(n.Fragment,{children:n.jsx(fC,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(Qd,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Ev(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),JF="DialogTitle",Cv=d.forwardRef(Ls(function(t,s){const{__scopeDialog:r,...i}=t,a=_r(JF,r),{setTitleCount:l}=a;return On(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(mt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),ZF="DialogClose",D1=d.forwardRef(Ls(function(t,s){const{__scopeDialog:r,...i}=t,a=_r(ZF,r);return n.jsx(mt.button,{type:"button",...i,ref:s,onClick:Ie(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function Ev(e){return e?"open":"closed"}Ls(Ev,"getState");const e4=5;function ue(e,t,s){const[r,i]=d.useState(void 0),[a,l]=d.useState(null),[o,c]=d.useState(!0),[u,h]=d.useState(0),[f,m]=d.useState(0),p=d.useRef(e);return p.current=e,d.useEffect(()=>{let g=!1;return c(!0),p.current().then(v=>{g||(i(v),l(null),m(0))}).catch(v=>{g||(l(v instanceof pe?v.message:String(v)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),d.useEffect(()=>{if(!s||f>=e4)return;const g=window.setTimeout(()=>h(v=>v+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:a,loading:o,reload:()=>{m(0),h(g=>g+1)}}}const O1={width:480,height:160,top:10,right:10,bottom:22,left:40},L1={width:1200,height:180,top:10,right:40,bottom:22,left:40};function t4({xs:e,series:t}){const s=L1,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=_=>_.filter(E=>E!==null&&Number.isFinite(E)),l=t.filter(_=>_.type!=="bar"),o=t.filter(_=>_.type==="bar"),c=l.flatMap(_=>a(_.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let f=u,m=h;if(f===m)f-=1,m+=1;else{const _=(m-f)*.08;f-=_,m+=_}const p=_=>us(s.top+i-(_-f)/(m-f)*i),g=o.length>0&&o.every(_=>_.unit==="percent"),v=g?100:Math.max(1,...o.flatMap(_=>a(_.values))),b=_=>us(s.top+i-Math.max(0,_)/v*i),j=e.length,x=j>0?r/j:r,w=_=>us(s.left+x*(_+.5)),y=t.map(_=>{if(_.type==="bar")return"";let E="M";const M=[];return _.values.forEach((P,U)=>{if(P===null||!Number.isFinite(P)){E="M";return}M.push(`${E}${w(U)},${p(P)}`),E="L"}),M.join(" ")}),k=[],N=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((_,E)=>{if(_.type!=="bar")return;const M=C++;_.values.forEach((P,U)=>{if(P===null||!Number.isFinite(P)||P<=0)return;const L=b(P);k.push({series:E,index:U,x:us(w(U)-x*.3+N*M),y:L,width:us(N),height:us(S-L)})})});const $=c.length>0?pd(u,h,2).map(_=>({value:_,y:p(_)})):[],R=o.length===0?[]:(g?[0,50,100]:pd(0,v,2)).map(_=>({value:_,y:b(_),percent:g})),I=Math.max(1,Math.ceil(j/8)),F=e.flatMap((_,E)=>E%I===0?[{index:E,x:w(E)}]:[]);return{lines:y,bars:k,targetY:null,ticks:$,xLabels:F,rightTicks:R}}function n4({xs:e,series:t,type:s="line",target:r=null}){const i=O1,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=>us(i.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?a/f:a,p=w=>us(s==="bar"?i.left+m*(w+.5):i.left+(f<=1?a/2:w/(f-1)*a)),g=s==="line"?t.map(w=>{let y="M";const k=[];return w.values.forEach((N,S)=>{if(N===null||!Number.isFinite(N)){y="M";return}k.push(`${y}${p(S)},${h(N)}`),y="L"}),k.join(" ")}):[],v=[];if(s==="bar"&&f>0){const w=m*.7,y=w/Math.max(1,t.length),k=h(0);t.forEach((N,S)=>{N.values.forEach((C,$)=>{if(C===null||!Number.isFinite(C))return;const R=h(C);v.push({series:S,index:$,x:us(i.left+m*$+(m-w)/2+y*S),y:Math.min(R,k),width:us(y),height:us(Math.abs(k-R))})})})}const j=(o.length>0?pd(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),x=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:g,bars:v,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:j,xLabels:x.map(w=>({index:w,x:p(w)}))}}function s4(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 r4({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?L1:O1,u=o?t4({xs:e,series:t}):n4({xs:e,series:t,type:s,target:r}),h=s4({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),n.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>n.jsx("text",{x:c.width-c.right+6,y:f.y,textAnchor:"start",dominantBaseline:"middle",children:f.percent?`${f.value}%`:l(f.value)},`r-${f.value}`)),n.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(f=>n.jsx("rect",{className:"ui-chart-bar","data-series":f.series,x:f.x,y:f.y,width:f.width,height:f.height},`${f.series}-${f.index}`)),u.lines.map((f,m)=>f?n.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?n.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(f=>n.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&f.index===0?"start":f.index===e.length-1&&e.length>1?"end":"middle",children:a(e[f.index])},f.index))]}),n.jsx("figcaption",{className:"sr-only",children:h}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((f,m)=>n.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function us(e){return Math.round(e*10)/10}function bi(...e){return e.filter(Boolean).join(" ")}function T({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:bi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Tt({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:bi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function re({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:bi("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function Bt(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function ae({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=d.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function Is({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 ve({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:bi("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 Ba({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function mc({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(ve,{tone:t,children:e})}function K({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 oe({message:e}){return e?n.jsx(K,{tone:"critical",role:"alert",children:e}):null}function ge({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(S1,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function cn({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(me,{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 i4({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function wh({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 An({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(i4,{children:[n.jsx(wh,{title:t,lede:s,actions:r}),i]})}function le({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 lt({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 vs({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 se({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 a4({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function yh({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function Xs({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 nn({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 Fn({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function _1({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 $t({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function Ct({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:bi("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 pt({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(kv,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(Nv,{children:[n.jsx(P1,{className:"ui-sheet-overlay"}),n.jsxs(Sv,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(Cv,{className:"ui-sheet-title",children:e}),n.jsx(D1,{asChild:!0,children:n.jsx(T,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function xs({title:e,onClose:t,foot:s,children:r}){return n.jsx(kv,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(Nv,{children:[n.jsx(P1,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(Sv,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(Cv,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function bh({label:e,items:t,note:s,trigger:r}){const i=l=>l.stopPropagation(),a=d.useRef(!1);return n.jsxs(cc,{modal:!1,onOpenChange:l=>{l&&(a.current=!1)},children:[n.jsx(uc,{asChild:!0,children:r??n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:i,children:n.jsx(me,{name:"more"})})}),n.jsx(vl,{children:n.jsxs(dc,{className:"ui-menu",align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:l=>{a.current&&l.preventDefault()},children:[s?n.jsx(Qi,{className:"ui-menu-label",children:s}):null,t.map((l,o)=>l?l==="separator"?n.jsx(yr,{className:"ui-menu-sep"},`sep-${o}`):"heading"in l?n.jsx(Qi,{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs(cs,{className:"ui-menu-item","data-tone":l.tone,onSelect:()=>{a.current=!0,l.onSelect()},children:[n.jsx("span",{children:l.label}),l.hint?n.jsx("span",{className:"ui-menu-item-hint",children:l.hint}):null]},o):null)]})})]})}function l4({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(kv,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(Nv,{children:n.jsxs(Sv,{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(Cv,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(D1,{asChild:!0,children:n.jsx(T,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function pc({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function tl({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 sn({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 ft({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function ct({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 F1({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 z1({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:bi("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 xd({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 o4=8;function c4({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(0),p=d.useRef(null),g=d.useRef(null),v=d.useRef(null),b=d.useRef(null),j=d.useId(),x=E=>{var M;return((M=t.find(P=>P.value===E))==null?void 0:M.label)??E},w=i!==void 0&&s.length>=i,y=t.filter(E=>!s.includes(E.value)),k=t.length>o4,N=u.trim().toLowerCase(),S=N===""?y:y.filter(E=>E.label.toLowerCase().includes(N)),C=Math.min(f,Math.max(0,S.length-1)),$=E=>{var M;c(!1),h(""),m(0),E&&((M=g.current)==null||M.focus())};d.useEffect(()=>{var M;if(!o)return;(M=k?v.current:b.current)==null||M.focus();const E=P=>{p.current&&!p.current.contains(P.target)&&$(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[o,k]);const R=E=>{const M=[...s,E];r(M),h(""),m(0);const P=i!==void 0&&M.length>=i;(P||M.length>=t.length)&&$(!P)},I=E=>{if(E.key==="Escape")E.preventDefault(),$(!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 M=S[C];M&&R(M.value)}else E.key==="Backspace"&&u===""&&s.length>0&&(E.preventDefault(),r(s.slice(0,-1)))},F=E=>`${j}-${E}`,_=o&&S.length>0?F(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(E=>n.jsx(xd,{label:x(E),disabled:a,onRemove:()=>r(s.filter(M=>M!==E)),children:x(E)},E)),n.jsxs("div",{className:"ui-chippicker-add",children:[n.jsx("button",{ref:g,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?j:void 0,disabled:a||w||y.length===0,onClick:()=>o?$(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[k?n.jsx("input",{ref:v,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":_,value:u,onChange:E=>{h(E.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":k?void 0:_,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[S.map((E,M)=>n.jsx("div",{id:F(M),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":M===C?"":void 0,onMouseEnter:()=>m(M),onMouseDown:P=>P.preventDefault(),onClick:()=>R(E.value),children:E.label},E.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function u4({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 U1({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 hi({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(me,{name:t})})}function B1({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(me,{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 W1({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(T,{"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 Ho({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function H1({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:bi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function d4({dock:e,className:t,children:s}){return n.jsxs("div",{className:bi("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 h4(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function Av(e){const[t,s]=d.useState({}),r=e??[],i={...h4(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(ae,{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 f4({props:e,timezone:t="UTC",onDecided:s}){var w;const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let y=!1;return i(null),l(null),A.approval(e.approvalId).then(k=>{y||i(k)}).catch(k=>{y||l(k instanceof pe?k.message:String(k))}),()=>{y=!0}},[e.approvalId]);const{values:f,controls:m}=Av(r==null?void 0:r.choices),p=(y,k)=>{h(y),l(null),(f&&y==="approve"?A.decide(e.approvalId,y,k,f):A.decide(e.approvalId,y,k)).then(N=>{i(N.action),s==null||s(N.action)}).catch(N=>l(N instanceof pe?N.message:String(N))).finally(()=>h(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",v=(w=r.permissionScopes)==null?void 0:w.includes("always"),b=m4(r),j=(r.preview??"").split(`
94
- `).length>12||(r.preview??"").length>900,x=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>vn(y)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[g?n.jsx(ve,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(mc,{state:r.state}),!g&&x?n.jsxs("span",{className:"wb-envelope-note",children:[" ",x]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children:Ze(g?r.expiresAt:r.decidedAt,t)})]}),n.jsxs("div",{className:"envelope-body","data-clamp":j&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",j&&!o?n.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),n.jsx(oe,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:v?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),n.jsxs("div",{className:"wb-envelope-buttons",children:[n.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),v?n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,n.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":v?"Allow once":"Approve"})]})]}):null,n.jsxs("details",{className:"ui-details",children:[n.jsx("summary",{children:"The envelope, field by field"}),n.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(y=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:y.label}),y.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:y.value})}):n.jsx("dd",{className:y.mono?"mono":void 0,children:y.value})]},y.label))})]})]})}function m4(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(ub(vn(i),a));else s!=null&&t.push({label:"Envelope",value:Tv(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 · ${vn(i)}`;t.some(o=>o.label===l)||t.push(ub(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 ub(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:Tv(t)}}function Tv(e){return e==null?"—":Array.isArray(e)?e.map(t=>Tv(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):qt(e,"text",null)}const p4=new Set(["image/png","image/jpeg","image/gif","image/webp"]),g4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function vd(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"||!g4.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 Rv(e){return p4.has(e.toLowerCase())}function Dr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function fi(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function zn(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 $v(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 Ui={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function Pu(e){return`artifact:${e}`}function x4(e){const t=$v(e.mime,e.filename);return{id:Pu(e.artifactId),tool:Ui[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function v4({props:e}){const t=E1(e.artifactId),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{if(t===null)return;let h=!0;return r(null),a(null),o(!1),A.libraryEntry(t).then(f=>{h&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[t]),t===null)return n.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?zn(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:Dr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:Dr(t),alt:e.caption??c,onLoad:h=>{const f=h.currentTarget;f.naturalWidth>0&&a({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(re,{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(Tt,{size:"sm",href:fi(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(Ct,{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 j4({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:qt(t.value,t.unit,t.currency)})]},t.label))})}const w4=8;function K1({text:e,label:t="Output",className:s}){const r=d.useRef(null),i=d.useRef(!0);return d.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=w4},children:e})}function y4(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 b4({text:e}){const[t,s]=d.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.jsx(T,{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 k4({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(re,{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(ve,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:y4(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(b4,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",zn(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(K1,{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:qt(s.value,s.unit,null)})]},s.label))}):null]})}function N4(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function db(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function S4(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function C4({props:e}){var k;const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=((k=e.target)==null?void 0:k.plugin)??null,h=S4(e),[f,m]=d.useState(null),p=f!==null&&h.includes(f)?f:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,v=e.changes??0,b=d.useRef(v),[j,x]=d.useState(0);d.useEffect(()=>{v<=b.current||(b.current=v,e.reloadsItself||x(N=>N+1))},[v,e.reloadsItself]),d.useEffect(()=>{if(u===null||g===null)return;let N=!0;return s(null),i(null),l(null),x(0),A.previewLink(u,g).then(S=>{N&&(s(S.url),i(db(S.url)))}).catch(S=>{N&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{N=!1}},[u,g]);const w=()=>{u===null||g===null||A.previewLink(u,g).then(N=>i(N.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:N=>m(Number(N.target.value)),children:h.map(N=>n.jsxs("option",{value:N,children:[":",N]},N))}):null,y?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(N=>!N),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&N4()?n.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),n.jsxs("div",{className:"wb-preview-body",children:[t?n.jsx("iframe",{className:"wb-preview-frame",src:j===0?t:db(t),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},j):n.jsx("p",{className:"wb-empty wb-preview-frame",children:a??"Opening the preview…"}),y&&o?n.jsx(K1,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const E4=50,A4=9,T4=24,R4=.6,$4=48,I4=/(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,P4=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,M4=/^id$|(^|[a-z0-9])Id$|_id$/;function Ia(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Gn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function V1(...e){for(const t of e)if(Gn(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 G1(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&&I4.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&P4.test(i))?"date":"text"}function D4(e,t){if(!M4.test(e))return!1;const s=t.filter(r=>!wl(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function wl(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:Gn(e)?Object.keys(e).length===0:!1}function hb(e,t){const s=e.filter(Gn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,E4),i=new Map,a=[];for(const h of r)for(const f of Object.keys(h))i.has(f)||a.push(f),i.set(f,(i.get(f)??0)+1);if(i.size===0||i.size>T4||[...i.values()].reduce((h,f)=>h+f,0)/(i.size*r.length)<R4)return null;const o=[...i.keys()].sort((h,f)=>{const m=(i.get(f)??0)-(i.get(h)??0);return m!==0?m:a.indexOf(h)-a.indexOf(f)}),c=[],u=[];for(const h of o){const f=r.map(v=>v[h]),m=f.filter(v=>!wl(v));if(m.length===0||D4(h,f))continue;const p=V1(r[0],t),g=G1(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(v=>Ia(v)&&v===f[0])){u.push({label:vn(h),value:f[0],type:g,currency:p});continue}if(c.push({key:h,label:vn(h),type:g,currency:g==="currency"?p:null}),c.length===A4)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function O4(e,t,s){const r=V1(s);return{label:vn(e),value:t,type:G1(e,[t],r),currency:r}}function Y1(e){return typeof e=="string"&&e.length>$4}function L4(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.":Gn(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Wp(e){if(typeof e=="string"&&e.trim()!=="")return e;if(Gn(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(Gn(s)){const r=Wp(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Iv(e,t={}){if(t.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));Gn(m)&&(f=m)}catch{}return{kind:"error",summary:Wp(f),detail:fb(f)}}if(Gn(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Wp(e),detail:fb(e)}}const s=L4(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=hb(e,e);return f?{kind:"table",label:null,columns:f.columns,rows:f.rows,total:f.rows.length,stats:f.constants,notes:[],asides:[]}:e.every(Ia)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!Gn(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[f,m]of r){if(!Array.isArray(m))continue;const p=hb(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:f,candidate:p});continue}m.length>0&&m.every(Ia)&&(!a||m.length>a.items.length)&&(a={key:f,items:m})}const l=(i==null?void 0:i.key)??(a==null?void 0:a.key)??null,o=[],c=[],u=[];for(const[f,m]of r)if(f!==l){if(Y1(m)){c.push(m);continue}if(Ia(m)){if(m==="")continue;o.push(O4(f,m,e));continue}m!==void 0&&u.push({label:vn(f),value:m})}if(i)return{kind:"table",label:vn(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:vn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return h.length>0&&h.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${h.map(([m])=>vn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Ia(f)||Gn(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function fb(e){if(!Gn(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const jd=25,_4=3,Hp=8,q1=6;function Kp(e,t=0){if(t>q1||wl(e)||Y1(e))return 0;if(Ia(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=Kp(r,t+1),s>=Hp)return s;return s}if(Gn(e)){let s=0;for(const r of Object.values(e))if(s+=Kp(r,t+1),s>=Hp)return s;return s}return 0}function Vp(e,t=0){if(t>q1)return!1;if(Array.isArray(e))return e.some(a=>Vp(a,t+1));if(!Gn(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=>Vp(a,t+1))}function F4(e){if(Vp(e))return!0;const t=Iv(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=_4;case"record":case"tree":return Kp(e)>=Hp;default:return!1}}function Rf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Pv(e){const t=Rf(e);if(!t)return null;const s=Rf(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:Rf(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function z4({text:e,label:t}){const[s,r]=d.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function $f({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(z4,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function U4({value:e,children:t}){const{result:s,command:r,input:i}=e,a=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([h,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx($f,{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($f,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx($f,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((h,f)=>n.jsx("p",{className:"wb-fail",children:h},f))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:_n({...c,...i?{input:i}:{}})})]})]})}const nu=2,mb=64;function B4({props:e}){const[t,s]=d.useState(!1),r=Pv(e.value),i=W4((r==null?void 0:r.result)??e.value),a=d.useMemo(()=>Iv(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(pb,{files:i}),t?n.jsx("pre",{className:"ui-code",children:_n(e.value)}):r?n.jsx(U4,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(pb,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(gb,{shape:a})]}):n.jsx(gb,{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 W4(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 pb({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(H4,{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 H4({file:e}){const[t,s]=d.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function gb({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:Ko(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(If,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=Q4(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(If,{stats:e.stats}),n.jsx(Pf,{notes:e.notes}),t?n.jsx(X4,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(V4,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(Mf,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(If,{stats:e.stats}),n.jsx(Pf,{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:qt(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(Mf,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(Pf,{notes:e.notes}),n.jsx(K4,{pairs:e.pairs}),n.jsx(Mf,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:Ko(e.value,0)})}}function If({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:Mv(t.value,t.type,t.currency)})]},t.label))})}const xb=200;function Pf({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=xb),s=e.filter(r=>r.length>xb);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 K4({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:Mv(t.value,t.type,t.currency)})]},t.label))})}function Mf({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:Ko(t.value,1)})]},t.label))})}function V4({label:e,columns:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=jd+5?r:jd,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:X1(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(J4,{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 G4=/^(title|name|headline|subject|label|heading)$/i,Y4=/^(url|link|href|uri|permalink)$/i;function wd(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function q4(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Q1(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 su(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 Q4(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>Y4.test(h.key)&&t.some(f=>wd(f[h.key])))??s.find(h=>{const f=t.map(m=>m[h.key]).filter(m=>!wl(m));return f.length>0&&f.filter(wd).length/f.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>G4.test(h.key))??i.find(h=>su(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,f)=>su(t,f.key)-su(t,h.key)),c=o[0]&&su(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 X4({label:e,plan:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=jd+5?r:jd,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[t.url],f=wd(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:f?Q1(f):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=f?q4(f):null,v=t.meta.map(b=>c[b]).filter(b=>!wl(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return n.jsxs("li",{className:"wb-record",children:[f?n.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[g?n.jsx("span",{className:"wb-record-host",title:f??void 0,children:g}):null,v.map((b,j)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},j))]}),p?n.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}function J4({value:e,column:t}){if(wl(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(wd(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:Q1(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:_n(e),children:i})}const s=Mv(e,t.type,t.currency),r=s.length>mb?`${s.slice(0,mb-1)}…`:s;return n.jsx("td",{className:X1(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function X1(e){return e==="number"||e==="currency"}function Mv(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":qt(e,t==="text"?"text":t,s)}function Ko(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,". "]}),Ko(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=nu?n.jsx(vb,{summary:`${e.length} items`,open:t===nu,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:[vn(i),": "]}),Ko(a,t+1)]},i))});return t>=nu?n.jsx(vb,{summary:`${s.length} fields`,open:t===nu,children:r}):r}function vb({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function Z4({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:qt(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:J1(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(ez,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function ez({cell:e}){const t=qt(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:J1(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function J1(e){return e==="number"||e==="currency"||e==="percent"}const jb={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",check:"check",clock:"clock"};function yl(e){return(e&&Object.prototype.hasOwnProperty.call(jb,e)?jb[e]:void 0)??"dot"}function wb(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 yd="buddi:plugin-pages-changed";function tz(){window.dispatchEvent(new Event(yd))}function Z1(e=!1){const[t,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>A.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(yd,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(yd,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:wb(t,"rail"),settings:wb(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}let Mu=null;typeof window<"u"&&window.addEventListener(yd,()=>{Mu=null});function nz(){return Mu??(Mu=Promise.resolve().then(()=>A.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(Mu=null,[]))),Mu}function Dv(e,t,s){return s==="settings"?Ji(e,t):Pr(e,t)}function sz(e){const[t,s]=d.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return d.useEffect(()=>{if(!r||!i)return;let a=!1;return nz().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:Dv(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function eE({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(rz,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function rz({tile:e,picked:t,onPick:s}){const r=sz(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(me,{name:yl(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(vs,{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 ga=760,Df=400,Dt={top:18,right:18,bottom:36,left:66},iz=5;function az({props:e}){const{points:t,referenceLines:s,unit:r,currency:i}=e;if(t.length===0)return n.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const a=[...t.map(y=>y.y),...s.map(y=>y.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,f=ga-Dt.left-Dt.right,m=Df-Dt.top-Dt.bottom,p=y=>Dt.left+(t.length===1?f/2:y/(t.length-1)*f),g=y=>Dt.top+m-(y-u)/(h-u)*m,v=pd(l,o,4),b=oz(t.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:cz(t.map(y=>y.y),e.shadeBelow),x=t.map((y,k)=>`${k===0?"M":"L"}${p(k)},${g(y.y)}`).join(" "),w=y=>qt(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 ${ga} ${Df}`,role:"img","aria-label":lz(e,w),preserveAspectRatio:"xMidYMid meet",children:[j.map(y=>n.jsx("rect",{className:"wb-chart-breach",x:p(y.from),width:Math.max(2,p(y.to)-p(y.from)),y:Dt.top,height:m},`band-${y.from}`)),v.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Dt.left,x2:ga-Dt.right,y1:g(y),y2:g(y)}),n.jsx("text",{x:Dt.left-8,y:g(y)+4,textAnchor:"end",children:w(y)})]},`tick-${y}`)),s.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-floor",x1:Dt.left,x2:ga-Dt.right,y1:g(y.value),y2:g(y.value)}),n.jsxs("text",{x:ga-Dt.right,y:g(y.value)-6,textAnchor:"end",children:[y.label," ",w(y.value)]})]},`rule-${y.label}`)),n.jsx("line",{className:"wb-chart-axis",x1:Dt.left,x2:Dt.left,y1:Dt.top,y2:Dt.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:Dt.left,x2:ga-Dt.right,y1:Dt.top+m,y2:Dt.top+m}),n.jsx("path",{className:"wb-chart-series",d:x}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:g(t[b].y)+20,textAnchor:"middle",children:w(t[b].y)})]}):null,uz(t.length).map(y=>n.jsx("text",{x:p(y),y:Df-10,textAnchor:"middle",children:Mp(t[y].x)},`x-${y}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,k)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Mp(y.at)}),y.label]}),y.amount===null?null:n.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:qt(y.amount,r,i)})]},`${y.at}-${y.label}-${k}`))})]}):null]})]})}function lz(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 oz(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 cz(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 uz(e,t=iz){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 rs=e=>e,Gp={timeseries:rs(az),table:rs(Z4),bars:rs(KL),keyvalue:rs(j4),tiles:rs(eE),document:rs(EF),diff:rs(XL),terminal:rs(k4),image:rs(v4),preview:rs(C4),envelope:rs(f4),structured:rs(B4)},dz="structured";function hz(e){return(bd(e)?Gp[e]:void 0)??Gp[dz]}function bd(e){return Object.prototype.hasOwnProperty.call(Gp,e)}function fz({renderer:e,props:t,timezone:s,onDecided:r}){const i=hz(e),l=bd(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function mz({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:vn(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(Hl,{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(tE,{}),"Exact action"]})]})]})}),n.jsx(Hl,{title:"What it can do",note:pz(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(gz,{family:s},s.family))}),n.jsx(Hl,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(Kl,{label:"Provider",children:e.engine.provider}),n.jsx(Kl,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(Kl,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(Kl,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(Kl,{label:"Language",children:yz(e.engine.language)})]})}),e.skills.length>0?n.jsx(Hl,{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(Hl,{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 pz(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 gz({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:vn(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(xz,{tool:s},s.name))})]})}function xz({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:wz(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(tE,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:jz(e.tier),children:vz(e.tier)})]})}function vz(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function jz(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 wz(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function yz(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Hl({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 Kl({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 tE(){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 yb=16e3,bz=10*6e4,kz="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",nE="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function Nz(){const e=window;return e.AudioContext??e.webkitAudioContext}function Sz(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?kz:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":nE}async function Cz(e){var c;const t=Nz();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(nE),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let f=0;for(let m=0;m<h.length;m++)f+=h[m]*h[m];e(Math.min(1,Math.sqrt(f/h.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),Tz(Az(Ez(l),u,yb),yb)},cancel:o}}function Ez(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 Az(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 Tz(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 Yp="buddi.readAloud";function sE(){try{return window.localStorage.getItem(Yp)==="on"}catch{return!1}}function rE(e){try{e?window.localStorage.setItem(Yp,"on"):window.localStorage.removeItem(Yp)}catch{}}let Gs=null,uo=null,Vo=0,qp=null;const Qp=new Set;function kd(e){qp!==e&&(qp=e,Qp.forEach(t=>t()))}function Rz(){return qp}function $z(e){return Qp.add(e),()=>Qp.delete(e)}function iE(e){return bl(),kd(e),Vo}function bb(e){return e===Vo}function bl(){Vo++,Gs&&(Gs.pause(),Gs.removeAttribute("src")),uo&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(uo),uo=null,kd(null)}async function Iz(e,t,s=null){var i;const r=iE(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!==Vo)return;Gs||(Gs=new Audio,(i=Gs.addEventListener)==null||i.call(Gs,"ended",()=>kd(null))),uo=URL.createObjectURL(l),Gs.src=uo,await Gs.play()}catch(a){throw r===Vo&&kd(null),a}}const Pz=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function aE(e){return Pz.has(e.toLowerCase().split(";")[0].trim())}function kb(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 lE({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=d.useRef(null),a=d.useRef(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(0),[g,v]=d.useState(null);d.useEffect(()=>()=>{var x;(x=i.current)==null||x.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const x=i.current;if(x){if(l){x.pause();return}bl(),f(!1);try{if(!a.current){u(!0);const w=await fetch(fi(e),{credentials:"same-origin"});if(!w.ok)throw new Error(String(w.status));a.current=URL.createObjectURL(new Blob([await w.arrayBuffer()],{type:s})),x.src=a.current}await x.play()}catch{f(!0)}finally{u(!1)}}},j=h?"Could not play. Download it instead.":`${kb(m)} / ${kb(g)}`;return n.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":l?"true":void 0,children:[n.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":l?`Pause ${t}`:`Play ${t}`,disabled:c,onClick:()=>void b(),children:n.jsx(me,{name:l?"pause":"play",size:14})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:t,children:t}),n.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[c?"Loading…":j,!h&&zn(r)?` · ${zn(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:fi(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(me,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:x=>p(x.currentTarget.currentTime),onLoadedMetadata:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null),onDurationChange:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null)})]})}const Lf=1e5,_f=200,Ff=30;function oE({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=d.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:Dr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&aE(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(lE,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:Dr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(K,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(Mz,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(K,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(K,{children:"The file is no longer available; its record is kept."})}function Mz({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return a("loading"),fetch(Dr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||a({text:u.slice(0,Lf),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Lf})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(ge,{children:"Loading preview…"})});if(i==="failed")return n.jsx(K,{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(Oz,{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 ",Lf.toLocaleString()," characters. The download has the whole file."]}):null]})}function Dz(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const h=()=>{a.length<r?a.push(l):c=!0,l=""},f=()=>{h(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===t){h();continue}if(p!=="\r"){if(p===`
95
- `){f();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&f(),{rows:i,truncatedRows:u,truncatedCols:c}}function Oz({text:e,delimiter:t}){const s=d.useMemo(()=>Dz(e,t,_f+1,Ff),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(Ff,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,_f).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 ",_f," rows",s.truncatedCols?` and ${Ff} columns`:"",". The download has the whole file."]}):null]})}function Lz({attachment:e}){const t=$v(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(oE,{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:[Ui[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:zn(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:fi(e.artifactId),download:s,children:"Download"})})]})}const Nb=80,_z=["query","path","url","dir"],Fz=["message","task"];function Ov(e,t){const s=zz(t);if(!s)return null;const r=xa(s.command);if(r!==null){const l=xa(s.name);return ru(l===null?r:`${l}: ${r}`)}for(const l of _z){const o=xa(s[l]);if(o!==null)return ru(o)}const i=xa(s.action);if(i!==null){const l=Fz.map(o=>xa(s[o])).find(o=>o!==null)??null;return ru(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?ru(xa(a[0])):null}function xa(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function ru(e){return e===null?null:e.length>Nb?`${e.slice(0,Nb-1)}…`:e}function zz(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const cE="owner.notify",xr=e=>typeof e=="string"&&e.trim()!==""?e:null;function Uz(e){const t=e!==null&&typeof e=="object"?e:{};return{title:xr(t.title)??"(no title)",text:xr(t.text),urgency:xr(t.urgency)??"now",key:xr(t.key),link:xr(t.link)}}function uE(e){if(e===null||typeof e!="object")return xr(e);const t=e;return xr(t.delivered)??xr(t.message)??xr(t.error)}function Bz(e,t){if(!t||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const mi="agent.delegate";function Wz(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 Hz(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 Xp="canvas.show",Sb="canvas.clear",Cb=12;function Wa(e){return`${e.plugin}/${e.name}`}function Kz(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function Vz({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=T1(o,dE(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function Gz({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 f of h.blocks??[]){if(f.type==="tool_use"){if(l.set(f.id,{name:f.name,input:f.input,at:h.at??null}),f.name===Xp){const y=qz(f.id,f.input,h.at??null);y&&o.push(y)}if(f.name===Sb&&(o=[]),f.name===mi){const y=Wz(f.input);y&&o.push({id:f.id,tool:mi,title:"Delegation",renderer:"delegate",props:{...y,result:null},at:h.at??null,source:"delegate",substantial:!0})}continue}if(f.type!=="tool_result"||f.name===Xp||f.name===Sb)continue;const m=l.get(f.toolUseId),p=h.at??(m==null?void 0:m.at)??null,g=f.name||(m==null?void 0:m.name)||"tool",v=o.find(y=>y.source==="delegate"&&y.id===f.toolUseId);if(v&&((u=f.delegation)==null?void 0:u.state)==="waiting"){v.props={...v.props,result:null,waiting:{approvalId:f.delegation.approvalId}},f.delegation.approvalId&&(v.tone="warning");continue}if(v){v.props={...v.props,result:{ok:f.ok,text:Hz(f.ok?f.output:f.error??f.output),...f.ok&&vd(f.output).length>0?{files:vd(f.output)}:{}}},f.ok||(v.tone="critical");continue}const b=f.approval?Zp(f):(s==null?void 0:s.get(f.toolUseId))??Zp(f);if(b){o.push({id:f.toolUseId,tool:g,title:"Approval",renderer:"envelope",props:{approvalId:b},at:p,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(g))continue;if(g===cE){o.push({id:f.toolUseId,tool:g,title:"Message to you",renderer:"notify",props:{input:(m==null?void 0:m.input)??null,output:f.output??null,ok:f.ok!==!1},at:p,tone:f.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const j=dE(f.output);if(f.ok===!1){o.push({id:f.toolUseId,tool:g,title:er(g),renderer:"structured",props:{value:f.error??j??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}Kz(j)&&(c+=1);const x=a.get(g);if(x){const y=T1(x,j),{renderer:k}=y;let{props:N}=y;if(k==="preview"){const S=N,C=S.target??(S.awaiting&&(i!=null&&i.has(Wa(S.awaiting)))?S.awaiting:null);if(C===null)continue;N={...S,target:C,awaiting:null};const $=Wa(C);o=o.filter(R=>!(R.source==="descriptor"&&R.renderer==="preview"&&R.props.target!==null&&Wa(R.props.target)===$))}o.push({id:f.toolUseId,tool:g,title:x.title??er(g),renderer:k,props:N,at:p,source:"descriptor",substantial:Jp(k,N)});continue}const w={value:Pv(j)?{input:m==null?void 0:m.input,output:j}:j};Qz("structured",w)&&o.push({id:f.toolUseId,tool:g,title:er(g),renderer:"structured",props:w,at:p,source:"fallback",substantial:Jp("structured",w)})}for(const h of o)h.source==="descriptor"&&h.renderer==="preview"&&(h.props={...h.props,changes:c});return Yz(o)}const Eb="forAgent";function dE(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(Eb in e))return e;const{[Eb]:t,...s}=e;return s}function Yz(e){if(e.length<=Cb)return e;const t=e.length-Cb;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function qz(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&bd(r)?r:"structured";return{id:e,tool:Xp,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!bd(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function Qz(e,t){const s=t??{};return!!(s.failed===!0||Jp(e,t)||Iv(s.value).kind==="error")}function Jp(e,t){const s=t??{};switch(e){case"timeseries":return Vl(s.points)>0;case"bars":return Vl(s.bars)>0;case"keyvalue":return Vl(s.pairs)>0;case"tiles":return s.notice!==!0&&Vl(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=>Vl(i.rows)>0);default:return Pv(s.value)?!0:s.failed===!0?!1:F4(s.value)}}function Vl(e){return Array.isArray(e)?e.length:0}function Zp(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=fE(t,0);if(s)return s}return null}function Xz(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)?hE(i.input):i.input;return{id:t,tool:i.name,title:er(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 Jz=new Set(["value","text","password","secret","code"]);function hE(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=Jz.has(s)&&typeof r=="string"?"— withheld —":hE(r);return t}function fE(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=fE(a,t+1);if(l)return l}return null}function er(e){const t=e.split(".");return t.length===1?vn(e):t.map(s=>vn(s)).join(" · ")}function kh({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=$v(t,e),h=[Ui[u],zn(s)].filter(Boolean).join(" · "),f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-file-visual","data-family":u,children:r?n.jsx("img",{src:r,alt:""}):n.jsx(Lv,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":h})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:f}):n.jsx("span",{className:"wb-file-open",children:f}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Lv({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 Zz(e,t,s){const r=Tb(e),i=Tb(t==null?void 0:t.input),a=Ti(r==null?void 0:r.name)??r3(Ti(r==null?void 0:r.handle))??Ti(r==null?void 0:r.agent)??Ti(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:Ti(r==null?void 0:r.text)??Ti(r==null?void 0:r.note),o=Ab(r==null?void 0:r.durationMs)??Ab(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:Ti(i==null?void 0:i.task),answer:l,files:vd(e),durationMs:o??h}}function e3(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===mi&&((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 t3({block:e,messages:t,answeredAt:s}){const r=Zz(e.output,e3(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${n3(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:fi(a.artifactId),download:!0,children:n.jsx(kh,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:Rv(a.mime)?Dr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(Ct,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:s3(e.output)})})]})}function n3(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 s3(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function r3(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Ti(e){return typeof e=="string"&&e.trim()!==""?e:null}function Ab(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Tb(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const i3=1e3;function a3({messageId:e,text:t,onReadAloud:s}){const[r,i]=d.useState(!1),a=d.useRef(null),l=d.useSyncExternalStore($z,Rz)===e;d.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),i3)},()=>{})};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(me,{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?bl():s(e,t),children:n.jsx(me,{name:l?"stop":"play",size:14})}):null]})}function l3(e){const t=o3(e);if(!t)return null;const s=zf(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=zf(t.command),i=zf(t.plain),a=Uf(t.exitCode);return r!==null&&(i!==null||a!==null||Uf(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:Uf(t.elapsedMs)}:null}function zf(e){return typeof e=="string"&&e.trim()!==""?e:null}function Uf(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function o3(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const Rb="offer:",mE="owner:interjection";function c3(e){return e===mE}function u3(e){if(typeof e!="string"||!e.startsWith(Rb))return null;const t=e.slice(Rb.length).trim();return t===""?null:t}function _v({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:v,empty:b,plain:j=!1,workingLine:x,runs:w,onContinue:y}){var Z;const k=d.useRef(null);d.useEffect(()=>{var z;(z=k.current)==null||z.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const N=a&&!a.settled&&(a.text!==""||a.thinking!==""),S=e.filter(z=>(z.blocks??[]).some(y3)),C=j3(S,w??[]),$=c??l??[],R=z=>(o&&!c?$.find(q=>q.id===o):void 0)??$.find(q=>q.name===z)??null,I=o?$.find(z=>z.id===o)??null:null,F=i||t.length>0,_=F||!!N,E=!!N&&a.text!=="",M=F&&!E,P=S.at(-1),U=(P==null?void 0:P.role)!=="assistant"||!!h,L=h??g??"Assistant",W=S.filter((z,q)=>{var Q;return q===0||(c?(((Q=S[q-1])==null?void 0:Q.speaker)??null)!==(z.speaker??null):S[q-1].role!==z.role)}),O=_&&!U?((Z=W.at(-1))==null?void 0:Z.id)??null:null,V=(w??[]).reduce((z,q)=>z===null||(q.startedAt??"")>(z.startedAt??"")?q:z,null),X=(w??[]).some(z=>z.finishedAt===null),G=y&&!_&&!X&&P&&(V==null?void 0:V.stopped)==="max_turns"&&C.get(P.id)===V?P.id:null;return n.jsx(C1.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:v}):null,S.map((z,q)=>{const Q=z.speaker??null,ce=c?Q==="owner"||Q===null&&z.role==="user":z.role==="user",Pe=c&&Q==="room",Te=c&&Q&&Q!=="owner"&&Q!=="room"?c.find(he=>he.id===Q)??null:null,Le=S[q-1],J=q===0||(c?((Le==null?void 0:Le.speaker)??null)!==Q:Le.role!==z.role);if(Pe)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(z.blocks??[]).filter(he=>he.type==="text").map((he,ze)=>n.jsx("span",{children:he.text},ze))},z.id);const ke=(z.blocks??[]).filter(he=>he.type==="approval_result");if(ke.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:ke.map((he,ze)=>n.jsx(b3,{block:he,messages:e,at:z.at||null},ze))},z.id);const ne=z.role==="user"&&c3(Q),Ae=z.role==="user"?u3(Q):null;if(Ae){const he=(z.blocks??[]).filter(ze=>ze.type==="text").map(ze=>ze.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:he,children:Ae})},z.id)}const de=c&&Te&&z.role==="user"?g3(z):null;if(de){const he=S.slice(q+1).find(Ge=>Ge.role==="assistant"&&Ge.speaker&&Ge.speaker!==Te.id),ze=he!=null&&he.speaker?c.find(Ge=>Ge.id===he.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[Te.name," asked ",(ze==null?void 0:ze.name)??"a member",de.request?`: ${de.request.length>120?`${de.request.slice(0,119)}…`:de.request}`:""]}),de.request?n.jsx("p",{children:de.request}):null]},z.id)}const Re=C.get(z.id)??null,De=v3(z,e),Ve=!ce&&!ne&&!j?x3(z):"";return n.jsxs("div",{className:"wb-msg","data-role":ce||ne?"user":"assistant",children:[ne?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,J&&!ce&&!ne?n.jsx($b,{name:Te?Te.name:c&&Q&&Q!=="owner"&&Q!=="room"?Q:g??"Assistant",face:Te??I??R(g),moving:M&&O===z.id,children:Te&&u===Te.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,De.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:De.map(he=>n.jsx("span",{role:"listitem",children:aE(he.mime)?n.jsx(lE,{artifactId:he.artifactId,name:he.filename??"Untitled file",mime:he.mime,sizeBytes:he.sizeBytes}):n.jsx(kh,{name:he.filename??"Untitled file",mime:he.mime,sizeBytes:he.sizeBytes,thumbnail:Rv(he.mime)?Dr(he.artifactId):null,...f?{onOpen:()=>f(he)}:{}})},he.artifactId))}):null,(z.blocks??[]).map((he,ze)=>{const Ge=f3(z.blocks??[],ze,e);if(Ge==="inside")return null;if(Ge)return n.jsx(m3,{refusals:Ge.refusals},ze);if(he.type==="thinking")return j||he.text.trim()===""?null:n.jsx(eg,{text:he.text},ze);if(he.type==="text")return he.text.trim()===""?null:ce?n.jsx("div",{className:"wb-bubble",children:he.text},ze):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(Mr,{text:he.text})},ze);if(he.type==="attachment")return null;if(he.type==="tool_use"){if(j)return null;const Ye=Fv(e,he.id),nt=Ye?S3(Ye):null,Pt=!nt&&he.name===cE&&Ye?uE(Ye.output):null;return n.jsx(tg,{label:nt&&!(Ye!=null&&Ye.delegation)?`Approval · ${he.name}`:er(he.name),tool:he.name,ok:(Ye==null?void 0:Ye.ok)??null,running:Ye===null,...nt?{status:nt.status,waiting:nt.waiting,approval:!0}:Pt?{status:Pt}:{},gist:Ov(he.name,he.input),body:Ye?l3(Ye.output):null,opens:!0,onOpen:()=>r(he.id)},ze)}return null}),Re?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:w3(Re)}),G===z.id?n.jsx(T,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,z.feedback&&!ce&&!ne?n.jsx(A3,{feedback:z.feedback}):null,Ve!==""?n.jsx(a3,{messageId:z.id,text:Ve,onReadAloud:m}):null]},z.id)}),_?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[U?n.jsx($b,{name:L,face:R(L)??I,moving:M}):null,N&&a.thinking!==""&&!j?n.jsx(eg,{text:a.thinking,live:a.text==="",seconds:p3(a.thinkingStartedAt,a.textStartedAt??s)}):null,E?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(Mr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!N?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[x??`${h??g??"The agent"} is working`,n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):null,t.map(z=>n.jsx(tg,{label:er(z.name),tool:z.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-z.startedAt)/1e3)),opens:!1,onOpen:()=>r(z.toolUseId)},z.toolUseId))]}):null,p,n.jsx("div",{ref:k})]})})}function $b({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=k1(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(vh,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Os,{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 d3(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 h3="delegation refused:";function f3(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==mi)return null;const o=Fv(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(h3))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 m3({refusals:e}){const[t,s]=d.useState(!1),r=e.map(o=>d3(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(me,{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:[er(mi)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function p3(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function eg({text:e,live:t=!1,seconds:s=null}){const[r,i]=d.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(me,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(me,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(Mr,{text:e})}):null]})}function g3(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 x3(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
97
-
98
- `)}function v3(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===mi){const l=Fv(t,a.id);l!=null&&l.ok&&vd(l.output).forEach(i)}return s}function j3(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 w3(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 y3(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function b3({block:e,messages:t,at:s}){const[r,i]=d.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":er(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(me,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===mi?n.jsx(t3,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==mi?n.jsx("pre",{className:"wb-approval-output mono",children:k3(e.output)}):null]})}function k3(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const N3=40;function S3(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(Zp(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 tg({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:f=null}){const[m,p]=d.useState(!1),g=n.jsxs(n.Fragment,{children:[r?n.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):n.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e}),h?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,i===void 0?null:n.jsxs("span",{className:"wb-tool-elapsed",children:[i,"s"]}),o||s===!1?n.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),v={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return f?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...v,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(me,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(Do,{children:[n.jsx(Oo,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(me,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(Lo,{children:n.jsxs(_o,{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(C3,{body:f,onOpen:a?l:null}):null]}):a?n.jsxs(Do,{children:[n.jsx(Oo,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...v,onClick:l,children:[g,n.jsx(me,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(Lo,{children:n.jsxs(_o,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):n.jsx("span",{className:"wb-tool","data-static":"true",...v,children:g})}function C3({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(gd,{text:e.diff,limit:N3,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:E3(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 E3(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Fv(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 A3({feedback:e}){const t=e.source==="telegram"?"on Telegram":`on ${e.source}`;return n.jsxs("div",{className:"wb-msg-feedback","data-value":e.value,"data-testid":"message-feedback",title:`You reacted ${e.emoji} ${t}`,children:[n.jsx("span",{className:"wb-msg-feedback-emoji","aria-label":`You reacted ${e.emoji} ${t}`,children:e.emoji}),n.jsx("span",{children:t}),e.note?n.jsxs("span",{className:"wb-msg-feedback-note",children:["“",e.note,"”"]}):null]})}const pE="approval-dock";function T3(){var t;const e=document.getElementById(pE);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const R3=["workspace","cwd","workdir","root"];function $3({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=d.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(I3,{item:h,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function I3({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState("");d.useEffect(()=>{let $=!1;return A.approval(e.approvalId).then(R=>{$||(u(R),R.state!=="pending"&&a(R))}).catch(R=>{$||f(R instanceof pe?R.message:String(R))}),()=>{$=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;d.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:j,controls:x}=Av(c==null?void 0:c.choices),w=($,R)=>{const I=g.trim();p($),f(null),(j&&$==="approve"?A.decide(e.approvalId,$,R,j):A.decide(e.approvalId,$,R)).then(F=>{a(F.action),I&&l(I)}).catch(F=>{f(F instanceof pe?F.message:String(F)),p(null)})},y=m!==null||c===null||c.state!=="pending",k=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,N=c?Ov(c.tool,c.canonicalArgs)??M3(c.preview):null,S=c?P3(c):null;return n.jsxs("section",{id:pE,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?er(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),N||S?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[N?n.jsx("code",{className:"wb-dock-gist",children:N}):null,S?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:S})]}):null]}):null,x?n.jsx("div",{className:"wb-dock-section",children:x}):null,n.jsx(oe,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:$=>v($.target.value),onKeyDown:$=>{$.key==="Enter"&&$.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 ",Ze(c.expiresAt,s)," · "]}):null,n.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),n.jsx(T,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),k?n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),n.jsx(T,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,n.jsx(T,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":k?"Allow once":"Approve"})]})]})}function P3(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of R3){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function M3(e){const t=(e??"").split(`
99
- `).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const D3=2e3;function O3({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=d.useState(l),u=!o||i!==null,{data:h,error:f}=ue(()=>Be.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?D3:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(y=>y.runId===s)??null,g=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(y=>y.finishedAt!==null));d.useEffect(()=>{g&&c(!0)},[g]);const v=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":g?"done":"working",b=a.find(y=>y.id===t)??null,j=(b==null?void 0:b.name)??(h==null?void 0:h.agentId)??t,x=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??L3(x);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":v,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(xn,{agents:a,id:t}),n.jsxs("div",{className:"wb-delegate-who",children:[n.jsx("strong",{children:j}),n.jsx("span",{className:"wb-delegate-status","data-status":v,role:"status",children:v==="working"?n.jsxs(n.Fragment,{children:["Working",n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):v==="waiting"?"Waiting for your approval":v==="failed"?"Failed":"Done"})]})]}),f?n.jsx("p",{className:"muted",children:f}):null,n.jsx("div",{className:"wb-delegate-work",children:x.map((y,k)=>n.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((N,S)=>{if(N.type==="thinking")return N.text.trim()===""?null:n.jsx(eg,{text:N.text},S);if(N.type==="tool_use"){const C=F3(_3(x,N.id));return n.jsx(tg,{label:er(N.name),tool:N.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Ov(N.name,N.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??k))}),w?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(Mr,{text:w})}):v==="working"||v==="waiting"?n.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(y=>n.jsx("a",{role:"listitem",href:fi(y.artifactId),download:!0,children:n.jsx(kh,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Rv(y.mime)?Dr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[v==="waiting"?n.jsx(T,{variant:"accent",onClick:()=>T3(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:at(t||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function L3(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 _3(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 F3(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 Ib=1024*1024;function z3({files:e,agentId:t,root:s,revision:r}){const[i,a]=d.useState({kind:"dir",path:""});return d.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(U3,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(B3,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function gE({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 U3({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null);d.useEffect(()=>{let b=!1;return u(null),A.pageQuery(e.plugin,e.list,{agent:t,...r?{path:r}:{}}).then(j=>{b||o(j.data)}).catch(j=>{b||u(j instanceof Error?j.message:String(j))}),()=>{b=!0}},[e.plugin,e.list,t,r,i]),d.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const b=await fetch(A.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const y=await b.json().catch(()=>null);p((y==null?void 0:y.error)??"The archive could not be made.");return}const j=await b.blob(),x=URL.createObjectURL(j),w=document.createElement("a");w.href=x,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(x),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},v=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(re,{children:[n.jsx(gE,{root:s,path:r,go:a}),n.jsx(Bt,{}),n.jsx(T,{size:"sm",onClick:()=>void g(),disabled:h||v===null||v.length===0,children:h?"Packing…":"Download as archive"})]}),m?n.jsx(K,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(K,{tone:"critical",role:"alert",children:c}):null,v===null?c?null:n.jsx(ge,{children:"Reading the folder…"}):v.length===0?n.jsx(ge,{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:Xi,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(ft,{children:v.map(b=>n.jsx(ct,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(H3,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?zn(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 B3({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1);d.useEffect(()=>{let j=!1;return u(null),A.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(x=>{j||o(x.data)}).catch(x=>{j||u(x instanceof Error?x.message:String(x))}),()=>{j=!0}},[e.plugin,e.stat,t,r,i]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",v=A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=Ib;return n.jsxs(n.Fragment,{children:[n.jsxs(re,{children:[n.jsx(gE,{root:s,path:r,go:a}),n.jsx(Bt,{}),b?n.jsx(T,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,n.jsx(Tt,{size:"sm",href:v,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(K,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(ge,{children:"Reading the file…"}):m.type==="image"?n.jsx("figure",{className:"wb-files-picture",children:n.jsx("img",{src:g,alt:m.name})}):m.type==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:g,type:"application/pdf","aria-label":m.name,children:n.jsx(K,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(W3,{src:g,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(K,{children:m.type==="text"?`This file is over ${zn(Ib)}, 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(nn,{items:[{label:"Size",value:zn(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function W3({src:e,wrap:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1);return d.useEffect(()=>{let l=!1;return a(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(K,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(ge,{children:"Reading the file…"}):s===""?n.jsx(ge,{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 H3({kind:e}){return n.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",children:e==="dir"?n.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function K3({input:e,output:t,ok:s}){const r=Uz(e),i=uE(t)??(s?"sent":"not sent");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"To"}),n.jsx("dd",{className:"wb-envelope-action",children:"You"}),n.jsx("dt",{children:"Status"}),n.jsx("dd",{children:n.jsx(ve,{tone:Bz(i,s),dot:!0,children:i})})]}),n.jsxs("div",{className:"envelope-body",children:[n.jsx("strong",{children:r.title}),r.text?`
102
-
103
- ${r.text}`:null]})]}),n.jsx(Ct,{summary:"The call",children:n.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[n.jsx("dt",{children:"Urgency"}),n.jsx("dd",{children:r.urgency}),r.link?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Link"}),n.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Key"}),n.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const V3=3,G3=152,Y3=104,q3=100,Q3=2,Pb=5;function X3({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:f,agents:m,onClose:p,loading:g=!1}){const[v,b]=J3(h);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:v,"aria-hidden":"true",children:n.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),n.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:g?null:n.jsxs("div",{className:"wb-empty",children:[l?n.jsx("span",{className:"wb-empty-face",children:l}):null,n.jsx("p",{className:"ui-empty wb-empty-line",children:sU(u,rU(o??[],c??[]))})]})})]});const j=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:x,hidden:w}=Z3(e,j,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(FL,{value:j,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:v,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(zL,{className:"wb-tabstrip","aria-label":"Canvas",children:x.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(UL,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:k=>{k.key==="Delete"&&p&&Mb(y)&&(k.preventDefault(),p(y.id))},children:[y.tone==="warning"||y.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":y.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:y.title})]}),p&&Mb(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(eU,{items:w,onActivate:s,timezone:r})]}),e.map(y=>n.jsx(BL,{value:y.id,className:"wb-canvas-body","data-renderer":y.source==="descriptor"&&y.renderer==="preview"?"preview":void 0,"data-dense":aU.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?` · ${Ze(y.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,y.source==="browser"?f:y.source==="profile"?n.jsx(mz,{...y.props,...a?{onChange:a}:{}}):y.source==="artifact"?n.jsx(Lz,{...y.props}):y.source==="files"?n.jsx(z3,{...y.props}):y.source==="notify"?n.jsx(K3,{...y.props}):y.source==="delegate"?n.jsx(O3,{...y.props,agents:m??[]}):n.jsx(fz,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function Mb(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function J3(e){const[t,s]=d.useState(Pb),r=d.useRef(null);return[d.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-q3-Y3)/G3);s(Math.max(Q3,Math.min(Pb,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function Z3(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 eU({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(cc,{modal:!1,children:[n.jsx(uc,{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(me,{name:"chevron-down"})]})}),n.jsx(vl,{children:n.jsxs(dc,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(Qi,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(cs,{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:tU(i.at,s)??i.tool})]},i.id))]})})]})}function tU(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Ut(s,t)}const nU={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 sU(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>nU[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function rU(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=iU(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,V3)}function iU(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 aU=new Set(["table","diff","files"]),lU=3.5*6e4,oU=2e3;function cU(e,t,s={}){const[r,i]=d.useState({served:new Set,live:new Set,scope:t}),a=d.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??A.previewCheck,o=s.everyMs??oU,c=e.map(u=>`${Wa(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const g=Wa(p);if(a.current.has(g))continue;const v=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(v)?0:v+lU,j=u.get(g);(!j||b>j.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let h=!1,f;const m=async()=>{const p=Date.now();for(const[g,v]of[...u]){const b=await l(v.plugin,v.name).catch(()=>null);if(h)return;const j=p<=v.until;b!=null&&b.ok?(u.delete(g),i(x=>{const w={served:new Set(x.served).add(g),live:j?new Set(x.live).add(g):x.live,scope:x.scope};return a.current=w.served,w})):j||u.delete(g)}!h&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,t,l,o]),r}const ng="workspace-files";function uU(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 dU(e){const[t,s]=d.useState(null);return d.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await A.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await A.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function hU(e,t){return{id:ng,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 sg(e){return`agent-properties:${e}`}function fU(e){return{id:sg(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function mU(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 xE({progress:e}){return n.jsxs(se,{gap:"sm",children:[n.jsx("span",{role:"status",children:mU(e)}),n.jsx(_1,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function pU(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(h,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function Bf(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function Db(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const gU=4e3;function xU(e){return e.replace(/\r\n?/g,`
104
- `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,gU)}const vU=["left","middle","right"],jU=33;function wU(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function yU(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 bU(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function kU({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=d.useState("connecting"),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(!1),[g,v]=d.useState(0),b=d.useRef(null),j=d.useRef(null),x=d.useRef(null),w=d.useRef({at:0});d.useEffect(()=>{const E=r??(U=>new WebSocket(U));let M=!0,P;try{P=E(bU())}catch{a("lost");return}return P.binaryType="arraybuffer",b.current=P,P.onopen=()=>P.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),P.onmessage=U=>{if(!M)return;if(typeof U.data!="string"){const W=yU(U.data);if(!W||(f(O=>O&&wU(O,W.metadata)?O:W.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(W.jpeg).then(O=>{var X,G,Z;const V=j.current;if(!M||!V){(X=O.close)==null||X.call(O);return}(V.width!==O.width||V.height!==O.height)&&(V.width=O.width,V.height=O.height),(G=V.getContext("2d"))==null||G.drawImage(O,0,0),(Z=O.close)==null||Z.call(O)}).catch(()=>{});return}const L=JSON.parse(U.data);if(L.type==="driving"){a("driving"),o(null);return}(L.type==="refused"||L.type==="ended")&&(o(L.error??"The screen cannot be driven from here."),a("refused"))},P.onclose=()=>{M&&a(U=>U==="refused"?U:"lost")},P.onerror=()=>{M&&a(U=>U==="refused"?U:"lost")},()=>{M=!1,b.current=null;try{P.close()}catch{}}},[e,t,g,r]),d.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=d.useCallback(E=>{const M=b.current;if(M)try{M.send(JSON.stringify({type:"input",input:E}))}catch{}},[]),k=E=>{var U;const M=j.current;if(!M||!h)return null;const P=(U=M.getBoundingClientRect)==null?void 0:U.call(M);return P?pU(P,h,E.clientX,E.clientY):null},N=E=>{const M=w.current,P=Date.now();clearTimeout(M.timer),M.timer=void 0;const U=M.at+jU-P;if(U<=0){M.at=P,M.pending=void 0,y(E);return}M.pending=E,M.timer=setTimeout(()=>{const L=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),L&&y(L)},U)},S=()=>{const E=w.current;clearTimeout(E.timer),E.timer=void 0;const M=E.pending;E.pending=void 0,M&&(E.at=Date.now(),y(M))},C=E=>M=>{var L,W;const P=k(M);if(!P)return;E==="mousePressed"&&(M.preventDefault(),(W=(L=j.current)==null?void 0:L.focus)==null||W.call(L));const U={kind:"mouse",type:E,x:P.x,y:P.y,button:vU[M.button]??"left",clickCount:E==="mouseMoved"?0:Math.min(3,Math.max(1,M.detail||1)),modifiers:Bf(M)};if(E==="mouseMoved"){N(U);return}S(),y(U)},$=E=>{const M=k(E);M&&(S(),y({kind:"wheel",x:M.x,y:M.y,deltaX:Math.round(E.deltaX),deltaY:Math.round(E.deltaY)}))},R=E=>E.ctrlKey||E.metaKey||E.altKey,I=E=>{var P,U;if(E.key==="Escape"&&R(E)){p(!1),(U=(P=E.target).blur)==null||U.call(P);return}if(E.preventDefault(),(E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))return;const M=Bf(E);if(Db(E.key)&&!R(E)){y({kind:"key",type:"char",key:E.key,code:E.code,text:E.key,modifiers:M});return}y({kind:"key",type:"keyDown",key:E.key,code:E.code,modifiers:M})},F=E=>{E.key==="Escape"&&R(E)||(E.preventDefault(),!((E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))&&(Db(E.key)&&!R(E)||y({kind:"key",type:"keyUp",key:E.key,code:E.code,modifiers:Bf(E)})))},_=E=>{var P;E.preventDefault();const M=xU(((P=E.clipboardData)==null?void 0:P.getData("text/plain"))??"");M!==""&&y({kind:"text",text:M})};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(re,{align:"end",children:[n.jsx(T,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var M,P,U,L;const E=!m;p(E),E?(P=(M=x.current)==null?void 0:M.focus)==null||P.call(M):(L=(U=x.current)==null?void 0:U.blur)==null||L.call(U)},children:"Keyboard"}),n.jsx(T,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(K,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(re,{align:"end",children:n.jsx(T,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),v(E=>E+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(K,{tone:"warning",role:"status",children:l}):null,n.jsx("div",{className:"hand-screen",children:c?n.jsx("canvas",{ref:j,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:C("mousePressed"),onMouseUp:C("mouseReleased"),onMouseMove:C("mouseMoved"),onWheel:$,onKeyDown:I,onKeyUp:F,onPaste:_,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:x,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:I,onKeyUp:F,onPaste:_,onBlur:()=>p(!1)})]})}function NU(e){return e==="darwin"?"this Mac":"this computer"}let Wf=null;function zv(){const[e,t]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return Wf??(Wf=A.session().then(r=>r.platform,()=>{Wf=null})),Wf.then(r=>{s&&t(r)}),()=>{s=!1}},[]),NU(e)}function SU({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=ue(()=>A.browser(),[],3e3),a=ue(()=>A.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(An,{embedded:e,title:"Computer & browser",children:[n.jsx(oe,{message:r}),!s||!o?n.jsx(ge,{children:"Checking the host…"}):n.jsx(CU,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function CU({data:e,macOS:t,reload:s,timezone:r}){var S,C,$;const[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,f=(h==null?void 0:h.mode)??(!t&&e.mode==="computer"?"playwright":e.mode),m=f==="computer",p=(S=e.sessions)!=null&&S.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,v=async R=>{a(!0),o(null);try{await R()}catch(I){o(I instanceof Error?I.message:String(I))}finally{a(!1),s()}},b=R=>void v(()=>A.browserSettings(R)),j=e.permissions,x=f==="playwright"?e.browser:void 0,w=((C=x==null?void 0:x.install)==null?void 0:C.state)==="running",y=(x==null?void 0:x.engine)==="none",k=!!e.enabled&&!y&&!(x!=null&&x.problem)&&(!m||!(j!=null&&j.supported)||j.accessibility&&j.screenRecording),N=m?"Ready. Agents can use your computer within the apps you allow below.":f==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(x==null?void 0:x.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(se,{gap:"lg",children:[n.jsx(oe,{message:l}),n.jsx(le,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",disabled:i,onClick:()=>void v(()=>A.computerPermissions(!1)),children:"Check again"}),m&&!k&&(j!=null&&j.supported)?n.jsx(T,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void v(()=>A.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(T,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void v(()=>A.browserInstall()),children:w?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(se,{children:[e.enabled?y?n.jsxs(K,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):x!=null&&x.problem?n.jsx(K,{tone:"warning",children:x.message}):k?n.jsx(K,{tone:"good",children:N}):n.jsx(K,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(K,{tone:"warning",children:"The host is not available. Start buddi serve on a machine with a desktop session."}),m?j!=null&&j.supported?n.jsxs("ul",{className:"perm-list",children:[n.jsxs("li",{className:"perm-row",children:[n.jsx(ve,{tone:j.accessibility?"good":"warning",children:j.accessibility?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Accessibility"}),n.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),n.jsxs("li",{className:"perm-row",children:[n.jsx(ve,{tone:j.screenRecording?"good":"warning",children:j.screenRecording?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Screen Recording"}),n.jsx("span",{className:"muted",children:"Lets agents see the window they are working in."})]})]}):j?n.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null:null,(($=x==null?void 0:x.install)==null?void 0:$.state)==="running"?n.jsx(xE,{progress:x.install.progress}):x!=null&&x.install?n.jsx("p",{className:"muted",role:"status",children:x.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${x.install.line??"no reason given"}`}):null,x!=null&&x.headless&&!y?n.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&(j!=null&&j.message)?n.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!k?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(le,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(T,{variant:"danger",size:"sm",disabled:i,onClick:()=>void v(()=>A.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):n.jsx("div",{className:"ui-list",children:p.map(R=>n.jsxs("a",{className:"ui-list-row",href:at(R.session.agentId,R.session.conversationId),children:[n.jsx(Os,{id:R.session.agentId,name:R.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:R.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[R.session.agentId,", ",R.busy?"working":R.state,", ",R.session.steps," of ",R.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},R.session.id))})}),h?n.jsxs(n.Fragment,{children:[n.jsx(le,{title:"How agents get a screen",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(Hf,{current:h.mode,value:"computer",disabled:i||g||!e.enabled,title:"Use my apps",body:"Agents work in your own windows, signed in as you, in the browser profile you choose below. One agent at a time. Releasing control leaves everything open.",onPick:()=>b({...h,mode:"computer"})}):null,n.jsx(Hf,{current:h.mode,value:"playwright",disabled:i||g||!e.enabled,title:"Give agents their own browser",body:"A separate browser profile with its own tabs, one per conversation. Your apps are never touched.",onPick:()=>b({...h,mode:"playwright"})}),n.jsx(Hf,{current:h.mode,value:"extension",disabled:i||g||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...h,mode:"extension"})})]}),t?null:n.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),g?n.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,h.mode==="extension"?n.jsx(PU,{busy:i,timezone:r}):null]})}),t?n.jsx(le,{title:"Apps agents may use",panel:!0,children:n.jsxs(se,{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(MU,{settings:h,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(Ct,{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(FU,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:R=>{u(!1),h.allowedApps.includes(R)||b({...h,allowedApps:[...h.allowedApps,R]})}}):null]}):null]})}const EU="kmbckpnnjfggeffkkbmkggojnolkdokb",AU="",TU=[EU,AU].filter(Boolean);function RU(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 $U(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of TU)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 IU(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function PU({busy:e,timezone:t}){const{data:s,error:r,reload:i}=ue(()=>A.extension(),[],3e3),a=zv(),l=ue(()=>$U(),[],3e3).data??null,[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";d.useEffect(()=>{p&&c(p)},[p]);const g=async x=>{h(!0),m(null);try{await x()}catch(w){m(w instanceof Error?w.message:String(w))}finally{h(!1),i()}},v=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,j=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($t,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]});return n.jsxs(se,{divided:!0,children:[n.jsx(oe,{message:r??f}),n.jsxs(re,{children:[n.jsx(ve,{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 ${Ze(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(se,{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)&&RU(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&&!IU(l.gateway)?n.jsx(K,{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(re,{valign:"end",children:[n.jsx(ae,{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:x=>c(x.target.value)})}),n.jsx(Bt,{}),n.jsx(T,{variant:"accent",disabled:v||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await A.pairExtension(o),c("")}),children:"Pair"})]}):null,s!=null&&s.connected?n.jsx(Ct,{summary:"Pair a different browser",children:j}):j,n.jsx(re,{align:"end",children:n.jsx(T,{variant:"danger",disabled:v||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>A.forgetExtension()),children:"Forget this browser"})})]})}function Hf({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 MU({settings:e,disabled:t,onChange:s,onAdd:r}){const i=ue(()=>A.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(ge,{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(Os,{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(ve,{tone:"accent",className:"app-role",children:"browser"}):null]}),n.jsx("span",{className:"ui-list-sub mono",children:l})]}),n.jsxs(re,{children:[l!==e.browserApp&&_U(l)?n.jsx(T,{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(T,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),n.jsxs(re,{children:[n.jsx(T,{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"&&DU.includes(e.browserApp)?n.jsx(OU,{settings:e,disabled:t,onChange:s}):null]})}const DU=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function OU({settings:e,disabled:t,onChange:s}){var l;const i=((l=ue(()=>A.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(ae,{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 LU=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function _U(e){return LU.includes(e)}function FU({chosen:e,onClose:t,onPick:s}){const r=ue(()=>A.installedApps(),[]),[i,a]=d.useState(""),[l,o]=d.useState(""),c=d.useMemo(()=>{var f;const u=((f=r.data)==null?void 0:f.apps)??[],h=i.trim().toLowerCase();return u.filter(m=>!h||m.name.toLowerCase().includes(h)||m.id.toLowerCase().includes(h)).slice(0,60)},[r.data,i]);return n.jsxs(pt,{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(oe,{message:r.error}),r.data?c.length===0?n.jsx(ge,{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(Os,{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(T,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(ge,{children:"Reading your Applications folder…"}),n.jsx(Ct,{summary:"Add by bundle identifier instead",children:n.jsxs(re,{children:[n.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),n.jsx(T,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function zU({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var $,R,I;const[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),j=async F=>{h(!0),m(null),b(null);try{const _=F!=="stop"&&(e!=null&&e.session)?await A.browserControl(F,e.session.id):await A.browserControl(F);F==="takeover"?_.hand&&_.session?g(_.session.id):b(_.handMessage??null):g(null)}catch(_){m(_ instanceof Error?_.message:String(_))}finally{h(!1),s()}},x=p&&(($=e==null?void 0:e.session)==null?void 0:$.id)===p&&e.state==="paused"?p:null,w=!!(e!=null&&e.enabled)&&!u,y=(e==null?void 0:e.mode)==="computer",k=(e==null?void 0:e.mode)==="extension",N=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":k?"Your browser":"Browser"})]}),n.jsx(ve,{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.":k?"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(oe,{message:t??f}),c?n.jsxs(re,{children:[n.jsx(T,{variant:"danger",disabled:!w||(e==null?void 0:e.state)==="stopped",onClick:()=>void j("stop"),children:y?"Stop computer control":"Stop all browsers"}),n.jsx(T,{disabled:!w||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void j("takeover"),children:"Take over"}),n.jsx(T,{disabled:!w||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void j("resume"),children:"Resume access"}),n.jsx(T,{disabled:!w||!(e!=null&&e.session),onClick:()=>void j("release"),children:y?"Release control":"Close & release"})]}):null,c?r?n.jsx(Ct,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:N})}):n.jsx("p",{className:"muted",children:N}):null,v?n.jsx(K,{tone:"warning",role:"status",children:v}):null,e!=null&&e.message&&!x?n.jsx(K,{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 ",Ut(new Date(e.session.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone)]})]}):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."}),x?n.jsx(kU,{sessionId:x,csrf:na(),onGiveBack:()=>void j("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!x,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((R=e==null?void 0:e.page)==null?void 0:R.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 · ",Ut(new Date(e.page.capturedAt),Intl.DateTimeFormat().resolvedOptions().timeZone)," · ",e.page.title||"Untitled page"]})]}):n.jsxs("div",{className:"browser-empty",children:[n.jsx("strong",{children: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."})]})]}),(((I=e==null?void 0:e.page)==null?void 0:I.tabs.length)??0)>1?n.jsx(Ct,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(F=>n.jsxs("li",{children:[F.title||F.id," — ",F.url]},F.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."," ",x?"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 UU=2e3,BU=5;function WU(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 HU({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var w;const[l,o]=d.useState(0),[c,u]=d.useState(0),h=c>=BU;d.useEffect(()=>{if(!i||h)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(k=>k+1)},UU);return()=>window.clearInterval(y)},[i,h]);const f=d.useRef(null);i&&(e!=null&&e.session)&&(f.current=e);const[m,p]=d.useState(null),g=d.useRef(null),v=((w=e==null?void 0:e.page)==null?void 0:w.id)??null;d.useEffect(()=>{const y=i&&e?WU(e):null;if(!y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let k=!1;return(async()=>{try{const N=await fetch(y);if(!N.ok||k)return;const S=await N.blob();if(k)return;const C=URL.createObjectURL(S);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{k=!0}},[i,v]),d.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=f.current,j=i?e:b?m?b:{...b,hasScreenshot:!1}:e,x=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(zU,{data:j,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(y=>y+1),onScreenshotLoad:()=>u(0)}),i?h?n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"This session has ended. What is on this panel is the last thing it showed."}),n.jsx(KU,{steps:r,newestId:(x==null?void 0:x.id)??null,focusedId:a??null,live:i})]})}function KU({steps:e,newestId:t,focusedId:s,live:r}){const i=d.useRef(null);return d.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function VU({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=ue(()=>A.host(e,t),[e,t],2e3),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return n.jsx(Ct,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:n.jsxs(se,{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(oe,{message:a??r}),h.map(p=>n.jsxs(re,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(T,{size:"sm",disabled:o,onClick:()=>void u(()=>A.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),f.map(p=>n.jsxs(se,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx($t,{children:p.command}),n.jsx($t,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
105
- ${p.stderr}`:"Waiting for output…"}),n.jsx(re,{children:n.jsx(T,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>A.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const vE="browser.act",GU="browser.status",Du=new Set([vE,GU]);function YU(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 qU(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function QU(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===vE){const o={id:a.id,action:XU(a.input)??"act",target:JU(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:ZU(a)}}return t}function Ob(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=Du.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 XU(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function JU(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 ZU(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 e6({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(0);return d.useEffect(()=>{let m=!1;return o(null),u(null),(t?Be.groupConversations(t):Be.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,h]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>f(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Ii(t,m.id):at(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:[Ze(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 jE="buddi.dismissedTabs";function t6(){try{const e=JSON.parse(sessionStorage.getItem(jE)??"{}");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 Lb(e){try{sessionStorage.setItem(jE,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const n6=350,s6=60;function r6({conversationId:e,onText:t,onNotice:s}){const[r,i]=d.useState("idle"),a=d.useRef("idle"),l=x=>{a.current=x,i(x)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let x;try{x=await Cz(k=>{var N;return(N=f.current)==null?void 0:N.call(f,k)})}catch(k){h.current=null,l("idle"),m.current.onNotice(Sz(k));return}const w=c.current;c.current=null;const y=a.current;if(w==="discard"||y!=="starting"){x.cancel(),y==="starting"&&l("idle");return}o.current=x,l("recording"),u.current=window.setTimeout(()=>void v(!1),bz),w&&v(w.sendNow)},v=async x=>{h.current=null;const w=o.current;if(!w){a.current==="starting"&&(c.current={sendNow:x});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const k=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),N=await Be.attach(k),S=m.current.conversationId,C=await Be.transcribe({artifactId:N.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,x)}catch(y){m.current.onNotice(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l("idle")}},b=()=>{h.current=null;const x=o.current;if(!x){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),x.cancel(),l("idle")};d.useEffect(()=>{const x=w=>{if(h.current===null)return;const y=Date.now()-h.current;h.current=null,y>=n6&&v(w.shiftKey)};return window.addEventListener("pointerup",x),()=>window.removeEventListener("pointerup",x)},[]);const j=r==="starting"||r==="recording";return d.useEffect(()=>{if(!j)return;const x=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),b()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),v(w.shiftKey)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[j]),d.useEffect(()=>()=>{var x;(x=o.current)==null||x.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),g()},start:()=>{h.current=null,g()},finish:x=>void v(x),discard:b,levels:f}}function i6({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(me,{name:"mic"})})}function a6({voice:e}){const t=d.useRef(null),s=e.state==="transcribing";return d.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(l6,{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(me,{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(me,{name:"check"})})]})]})}function l6({sink:e,frozen:t}){const[s,r]=d.useState(()=>Array(s6).fill(0));return d.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const o6="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",iu="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",c6=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function u6(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(o6);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(c6(i))return null;throw new Error(iu)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((h,f)=>{a.onloadedmetadata=()=>h(),a.onerror=()=>f(new Error(iu))}),await a.play(),await new Promise(h=>{const f=a.requestVideoFrameCallback;typeof f=="function"?f.call(a,()=>h()):setTimeout(h,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(iu);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(iu);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 _b="Send files once the agent has answered.",rg="wb-composer-input",Uv=d.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:h,onOpenFile:f,mentions:m,history:p,threadKey:g,conversationId:v,readAloud:b,onReadAloud:j,placeholder:x,slim:w},y){var ur;const k=g?`buddi.draft.${g}`:null,N=Y=>{if(!Y)return"";try{return window.localStorage.getItem(Y)??""}catch{return""}},[S,C]=d.useState(()=>N(k)),[$,R]=d.useState([]),[I,F]=d.useState(!1),[_,E]=d.useState(null),[M,P]=d.useState(!1),U=d.useRef(null),L=d.useRef(null),[W,O]=d.useState(null),[V,X]=d.useState(0),G=W&&m?m.filter(Y=>Y.handle.toLowerCase().startsWith(W.query.toLowerCase())||Y.name.toLowerCase().startsWith(W.query.toLowerCase())).slice(0,6):[],Z=(Y,Ee)=>{if(!m||m.length===0){O(null);return}const it=Y.slice(0,Ee),et=/(^|\s)@([\w-]*)$/.exec(it);if(!et){O(null);return}O({start:Ee-et[2].length-1,query:et[2]}),X(0)},z=Y=>{if(!W)return;const Ee=L.current,it=Ee?Ee.selectionStart:S.length,et=`${S.slice(0,W.start)}@${Y} ${S.slice(it)}`;C(et),Q<0&&Le(et),O(null),window.requestAnimationFrame(()=>{if(!Ee)return;const Qt=W.start+Y.length+2;Ee.focus(),Ee.setSelectionRange(Qt,Qt),Pt()})},q=p??[],[Q,ce]=d.useState(-1),Pe=d.useRef(S),Te=d.useRef(k);if(Te.current!==k){Te.current=k;const Y=N(k);Pe.current=Y,Y!==S&&(C(Y),ce(-1),O(null))}const Le=Y=>{if(Pe.current=Y,!!k)try{Y===""?window.localStorage.removeItem(k):window.localStorage.setItem(k,Y)}catch{}},J=Y=>{C(Y),O(null);const Ee=L.current;Ee&&(Ee.value=Y,Ee.setSelectionRange(Y.length,Y.length)),window.requestAnimationFrame(Pt)},ke=Y=>!Y.value.slice(0,Y.selectionStart??Y.value.length).includes(`
106
- `),ne=()=>S===""||Q>=0&&S===q[Q],Ae=()=>{Q<0||(ce(-1),J(Pe.current))},de=$.some(Y=>Y.state==="uploading"),Re=$.length>0,De=s&&Re,Ve=!t&&!de&&!De&&S.trim()!=="",he=Y=>{for(const Ee of Array.from(Y??[])){const it=`${Ee.name}:${Ee.size}:${Math.random().toString(36).slice(2,8)}`,et=Ee.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Ee):null;R(Qt=>[...Qt,{key:it,filename:Ee.name||"Pasted image",mime:Ee.type||"application/octet-stream",sizeBytes:Ee.size,thumbnail:et,state:"uploading"}]),Be.attach(Ee).then(Qt=>R(je=>je.map(qe=>qe.key===it?{...qe,state:"ready",uploaded:Qt}:qe))).catch(Qt=>R(je=>je.map(qe=>qe.key===it?{...qe,state:"failed",error:Qt instanceof pe?Qt.message:String(Qt)}:qe)))}},ze=Y=>{Y.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Y.thumbnail)},Ge=Y=>{const Ee=$.find(it=>it.key===Y);Ee&&(ze(Ee),Ee.state==="ready"&&Ee.uploaded&&Be.discardAttachment(Ee.uploaded.artifactId).catch(()=>{})),R(it=>it.filter(et=>et.key!==Y))};d.useImperativeHandle(y,()=>({addFiles:Y=>{var Ee;he(Y),(Ee=L.current)==null||Ee.focus()},focus:()=>{var Y;return(Y=L.current)==null?void 0:Y.focus()}}));const Ye=d.useRef($);Ye.current=$,d.useEffect(()=>()=>Ye.current.forEach(ze),[]);const nt=d.useRef(0);d.useEffect(()=>{if(!l||l.at===nt.current)return;nt.current=l.at,C(Ee=>Ee.trim()===""?l.text:Ee),Q<0&&S.trim()===""&&Le(l.text);const Y=L.current;Y&&(Y.focus(),window.requestAnimationFrame(()=>{Y.style.height="auto",Y.style.height=`${Math.min(Y.scrollHeight,200)}px`,Y.setSelectionRange(Y.value.length,Y.value.length)}))},[l]);const Pt=()=>{const Y=L.current;Y&&(Y.style.height="auto",Y.style.height=`${Math.min(Y.scrollHeight,200)}px`)},un=Y=>{const Ee=(Y??S).trim();if(Y===void 0?!Ve:t||de||De||Ee==="")return;const it=$.filter(et=>et.state==="ready"&&et.uploaded).map(et=>et.uploaded);r(Ee,it),$.forEach(ze),ce(-1),Le(""),C(""),R([]),window.requestAnimationFrame(Pt)},ee=Y=>{if(W&&G.length>0){if(Y.key==="ArrowDown"){Y.preventDefault(),X(Ee=>(Ee+1)%G.length);return}if(Y.key==="ArrowUp"){Y.preventDefault(),X(Ee=>(Ee-1+G.length)%G.length);return}if(Y.key==="Enter"||Y.key==="Tab"){Y.preventDefault(),z(G[V].handle);return}if(Y.key==="Escape"){Y.preventDefault(),O(null);return}}if(Y.key==="ArrowUp"&&!Y.shiftKey&&!Y.altKey&&!Y.metaKey&&!Y.ctrlKey){const Ee=Y.currentTarget;if(q.length>0&&Q+1<q.length&&ke(Ee)&&ne()){Y.preventDefault(),Q<0&&(Pe.current=S),ce(Q+1),J(q[Q+1]);return}}if(Y.key==="ArrowDown"&&!Y.shiftKey&&!Y.altKey&&!Y.metaKey&&!Y.ctrlKey&&Q>=0&&S===q[Q]){if(Y.preventDefault(),Q===0){Ae();return}ce(Q-1),J(q[Q-1]);return}if(Y.key==="Escape"&&Q>=0){Y.preventDefault(),Ae();return}Y.key==="Enter"&&!Y.shiftKey&&(Y.preventDefault(),un())},ye=Y=>{var it;const Ee=Array.from(((it=Y.clipboardData)==null?void 0:it.files)??[]);Ee.length!==0&&(Y.preventDefault(),he(Ee))},H=$.filter(Y=>Y.state==="failed"),Fe=H.length,wt=r6({conversationId:v??null,onNotice:E,onText:(Y,Ee)=>{const it=S.trim()===""?Y:`${S.replace(/\s+$/,"")} ${Y}`;if(Ee){un(it);return}J(it),Q<0&&Le(it)}}),dt=wt.state!=="idle",Un=d.useRef(!1);return d.useEffect(()=>{var Y;Un.current&&!dt&&((Y=L.current)==null||Y.focus(),window.requestAnimationFrame(Pt)),Un.current=dt},[dt]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-slim":w||void 0,"data-busy":S.trim()!==""||Re||dt?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":M||dt,"data-disabled":t,"data-listening":dt||void 0,children:[$.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:$.map(Y=>n.jsx("span",{role:"listitem",children:n.jsx(kh,{name:Y.filename,mime:Y.mime,sizeBytes:Y.sizeBytes,thumbnail:Y.thumbnail,state:Y.state,error:Y.error,onRemove:()=>Ge(Y.key),...f&&Y.state==="ready"&&Y.uploaded?{onOpen:()=>f(d6(Y.uploaded))}:{},size:"sm"})},Y.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:rg,children:["Message ",a]}),n.jsx("textarea",{id:rg,ref:L,value:S,rows:w?1:2,placeholder:s?`${a} is working…`:x??`Message ${a}`,onChange:Y=>{C(Y.target.value),Q<0&&Le(Y.target.value),Z(Y.target.value,Y.target.selectionStart??Y.target.value.length),Pt()},onFocus:()=>P(!0),onBlur:()=>P(!1),onKeyDown:ee,onPaste:ye,disabled:t,hidden:dt}),dt?n.jsx(a6,{voice:wt}):null,!dt&&W&&G.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:G.map((Y,Ee)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ee===V,className:"wb-mention","data-active":Ee===V||void 0,onMouseDown:it=>{it.preventDefault(),z(Y.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",Y.handle]}),n.jsx("span",{className:"wb-mention-name",children:Y.name})]},Y.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:dt,children:[n.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:Y=>{he(Y.target.files),Y.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 Y;return(Y=U.current)==null?void 0:Y.click()},disabled:t,children:n.jsx(me,{name:"clip"})}),n.jsx(i6,{disabled:t,voice:wt}),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:()=>{E(null),F(!0),u6().then(Y=>{var Ee;Y&&(he([Y]),(Ee=L.current)==null||Ee.focus())}).catch(Y=>E(Y instanceof Error?Y.message:String(Y))).finally(()=>F(!1))},disabled:t||I,children:n.jsx(me,{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":au(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${au(u)?"on":"off"}`:au(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(au(u)?"off":"on"),children:[n.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,j?n.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!b,title:b?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>j(!b),children:n.jsx(me,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":S!==""&&!s||Fe>0||De||_!==null,"data-tone":Fe>0||_!==null?"critical":void 0,children:Fe>0?Fe===1&&((ur=H[0])!=null&&ur.error)?H[0].error:`${Fe} files failed to upload and will not be sent`:_!==null?_:De?_b:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:De?_b:de?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>un(),disabled:!Ve,children:n.jsx(me,{name:"send"})})]})]})})});function au(e){return(e??"on")==="on"}function d6(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function h6({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=d.useState("");return d.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(T,{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:f6(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 f6(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 m6(e,t){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null||e.idleTimeoutMs===null?!1:t-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function p6(e){const t=e/864e5;if(t>=1&&Number.isInteger(t))return t===7?"1 week":`${t} day${t===1?"":"s"}`;const s=e/36e5;if(s>=1&&Number.isInteger(s))return`${s} hour${s===1?"":"s"}`;const r=Math.round(e/6e4);return`${r} minute${r===1?"":"s"}`}function g6(e){const{lifetime:t,startedAt:s,now:r,timezone:i}=e;if(!t||t.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const a=`${Math.round(t.maxChars/1e3)}k characters`,l=(t.idleTimeoutMs===null?`A conversation ends once its transcript grows past ${a}. `:`A conversation ends after ${p6(t.idleTimeoutMs)} idle, or once its transcript grows past ${a}. `)+"What the agent remembers about you carries over.",o=`${t.messages} message${t.messages===1?"":"s"}`;if(m6(t,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?He(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${Ze(s,i)}. ${l}`:l,tone:"quiet"}}function x6({text:e,onDelete:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null);return n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:n.jsxs(Ct,{summary:"Carried over from the previous conversation",children:[n.jsx("p",{className:"wb-carryover-text",children:e}),n.jsxs(re,{align:"end",children:[i?n.jsx("span",{className:"critical",role:"alert",children:i}):null,n.jsx(T,{size:"sm",variant:"danger-ghost",disabled:s,onClick:()=>{r(!0),a(null),t().catch(l=>{a(l instanceof Error?l.message:String(l)),r(!1)})},children:"Delete note"})]})]})})}function wE(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function yE(e,t){return e.members.map(s=>t.find(r=>r.id===s)).filter(s=>s!==void 0)}function v6(e,t){var i;const s=yE(e,t),r=e.members.filter(a=>!t.some(l=>l.id===a));if(!t.some(a=>a.id===e.coordinator))return{kind:"coordinator",text:`${e.coordinator} coordinated this group and is no longer in buddi, so the group can't take requests.`,action:"Choose a coordinator"};if(s.length<2){const a=r.length>0?`: ${r.join(", ")} ${r.length===1?"was":"were"} removed from buddi`:"";return{kind:"alone",text:`Only ${((i=s[0])==null?void 0:i.name)??e.coordinator} is left here${a}.`,action:"Add a member"}}return null}function j6(){return n.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function w6({group:e,agents:t,onClose:s,onSaved:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,h=wv(t).filter(g=>!e.members.includes(g.id)),f=!t.some(g=>g.id===e.coordinator),m=async g=>{a(!0),o(null);try{r(await Be.updateGroup(e.id,g))}catch(v){o(v instanceof pe?v.message:String(v))}finally{a(!1)}},p=g=>void m({members:e.members.filter(v=>v!==g)});return n.jsxs(pt,{title:"Members",onClose:s,children:[n.jsxs("p",{className:"group-lede",children:[e.name," · ",e.members.length," agents. Each keeps its own account, tools and approvals; being here grants nothing."]}),f?n.jsxs(K,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?n.jsx(K,{tone:"critical",children:l}):null,n.jsx(ft,{children:c.map(g=>{const v=t.find(j=>j.id===g),b=g===e.coordinator;return v?n.jsx(ct,{lead:n.jsx(xn,{agents:t,id:g}),title:v.name,sub:v.description,side:n.jsxs(n.Fragment,{children:[b?n.jsx(ve,{tone:"accent",children:"Coordinator"}):null,f&&v.available?n.jsx(T,{size:"sm",disabled:i,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,n.jsx(bh,{label:`More for ${v.name}`,...b?{note:"Coordinates the group"}:{},items:[!b&&v.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:g})},{label:`Open ${v.name}'s page`,onSelect:()=>{window.location.hash=St(g)}},!b&&"separator",!b&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(g):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},g):n.jsx(ct,{lead:n.jsx(j6,{}),title:n.jsx("span",{className:"group-gone-id",children:g}),sub:n.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",b?" · was the coordinator":u?"":" · add a member to take it out"]}),side:u&&!b?n.jsx(T,{size:"sm",disabled:i,onClick:()=>p(g),children:"Remove"}):void 0},g)})}),n.jsxs("div",{className:"group-add",children:[n.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?n.jsx(ft,{children:h.map(g=>n.jsx(ct,{lead:n.jsx(xn,{agents:t,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:n.jsx(T,{size:"sm",disabled:i,onClick:()=>void m({members:[...e.members,g.id]}),children:"Add"})},g.id))}):n.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),n.jsx("p",{className:"group-quiet",children:"Members read what is said here and what they recall from shared and group memory; nothing an agent knows privately comes in on its own. Taking a member out leaves what it said in the history."})]})}function y6({group:e,onClose:t,onSaved:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!a,h=async()=>{if(u){l(!0),c(null);try{s(await Be.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof pe?f.message:String(f)),l(!1)}}};return n.jsx(xs,{title:"Rename group",onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!u,onClick:()=>void h(),children:a?"Renaming…":"Rename"})]}),children:n.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:n.jsxs(se,{children:[n.jsx(ae,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:f=>f.currentTarget.select(),onChange:f=>i(f.target.value)})}),o?n.jsx(K,{tone:"critical",children:o}):null]})})})}function bE(e){const[t,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return Be.group(e).then(i=>{var a;r&&s(((a=i.history)==null?void 0:a.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),t}function b6(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function k6({group:e,onClose:t,onCleared:s}){const r=bE(e.id),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{a(!0),o(null);try{await Be.clearGroup(e.id),s()}catch(h){o(h instanceof pe?h.message:String(h)),a(!1)}},u=r===0;return n.jsxs(xs,{title:`Clear the history of ${e.name}?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:i||u,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:i?"Clearing…":"Clear history"})]}),children:[n.jsx("p",{className:"group-dialog-text",children:u?"Nothing has been said in this group yet, so there is nothing to clear.":`${b6(r)} ${r===1?"is":"are"} deleted for good, and anything it is doing now stops. The group, its members and what it remembers stay; files it made stay in Files.`}),l?n.jsx(K,{tone:"critical",children:l}):null]})}function N6({group:e,agents:t,onClose:s,onDeleted:r}){const i=bE(e.id),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=yE(e,t).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await Be.deleteGroup(e.id);r(m)}catch(m){c(m instanceof pe?m.message:String(m)),l(!1)}},f=i===null?"its conversations":i===0?"nothing said yet":`its ${i} ${i===1?"conversation":"conversations"}`;return n.jsxs(xs,{title:`Delete ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:a,"data-testid":"group-delete-confirm",onClick:()=>void h(),children:a?"Deleting…":"Delete group"})]}),children:[n.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",f," and what it remembers."," ",u.length>0?`${wE(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?n.jsx(K,{tone:"critical",children:o}):null]})}const Ou=320,kE="buddi.chatWidth";function S6({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onGroupAction:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:v,requestedTab:b,onConversationOpened:j}){var Yj,qj,Qj,Xj,Jj,Zj;const x=zv(),[w,y]=d.useState([]),[k,N]=d.useState(null),[S,C]=d.useState(null),[$,R]=d.useState(null),[I,F]=d.useState([]),[_,E]=d.useState([]),[M,P]=d.useState(null),[U,L]=d.useState(!1),[W,O]=d.useState(new Map),[V,X]=d.useState(null),[G,Z]=d.useState(t6),[z,q]=d.useState([]),[Q,ce]=d.useState(!1),Pe=d.useRef(0),Te=d.useRef(null),[Le,J]=d.useState(!1),ke=d.useRef(g??0),ne=d.useRef(s),Ae=d.useRef({agentId:s,conversationId:k});Ae.current={agentId:s,conversationId:k};const de=G[k??""]??[],[Re,De]=d.useState(null),[Ve,he]=d.useState(null),[ze,Ge]=d.useState(null),[Ye,nt]=d.useState([]),[Pt,un]=d.useState(!1),[ee,ye]=d.useState(()=>Date.now()),[H,Fe]=d.useState(C6),wt=d.useRef(null),[dt,Un]=d.useState(null),[ur,Y]=d.useState(!1),[Ee,it]=d.useState(null),[et,Qt]=d.useState(sE),je=d.useRef(et);je.current=et;const qe=d.useRef(null),[Oe,Wt]=d.useState(null),js=d.useCallback(B=>{Qt(B),rE(B),B||bl()},[]),[wn,ws]=d.useState(null),[be,Ue]=d.useState(null);d.useEffect(()=>{if(!s)return;const B=R6(s);B&&it({text:B,at:Date.now()})},[s]);const Me=i?`group:${i.id}`:s??null,Xe=[...t.top,...t.middle,...t.bottom],we=Xe.find(B=>B.id===s)??null,Fs=ue(()=>A.providerAccounts(),[]),ys=i?i.members.map(B=>Xe.find(te=>te.id===B)).filter(B=>!!B):[],[Ni,Tl]=d.useState(null),Si=U?Ni??s??null:null;d.useEffect(()=>{o==null||o(Si)},[Si,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let B=!1;return Be.views().then(te=>{B||y(te.views??[])}).catch(()=>{}),()=>{B=!0}},[]),d.useEffect(()=>{if(!s)return;const B=ne.current===s;if(ne.current=s,B&&v&&v===Ae.current.conversationId)return;let te=!1;return N(null),C(null),R(null),F([]),De(null),L(!1),X(null),q([]),jc(null),J(!1),Un(null),v?(v!=="new"?N(v):R(Me),()=>{te=!0}):((i?Be.groupConversations(i.id):Be.conversations(s)).then(Ne=>{if(te)return;const $e=[...Ne.conversations??[]].sort(E6)[0];$e?(N($e.id),j==null||j(s,$e.id)):R(Me)}).catch(()=>{te||R(Me)}),()=>{te=!0})},[s,i==null?void 0:i.id,Me,v,j]);const Rn=d.useCallback(B=>Be.conversation(B).then(te=>{if(Ae.current.conversationId===B){if(te.agentId!==Ae.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(te),F(Ne=>Ne.filter($e=>!Kf(te,$e)))}}).catch(te=>{Ae.current.conversationId===B&&De(Ur(te))}),[]);d.useEffect(()=>{if(!k)return;let B=!1;return O(new Map),E([]),Be.conversation(k).then(te=>{if(!B){if(te.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(te),F(Ne=>Ne.filter($e=>!Kf(te,$e)))}}).catch(te=>{B||De(Ur(te))}),()=>{B=!0}},[k,s]),d.useEffect(()=>{if(!k)return;let B=!1;const te=window.setInterval(()=>{Be.conversation(k).then(Ne=>{B||Ne.agentId!==Ae.current.agentId||(C(Ne),F($e=>$e.filter(Je=>!Kf(Ne,Je))))}).catch(()=>{})},3e3);return()=>{B=!0,window.clearInterval(te)}},[k,s]),d.useEffect(()=>{if(!k)return;const B=ph({url:Be.streamUrl(k),onEvent:te=>{var Ne;switch(te.name){case"run.started":qe.current=null,L(!0),P(null),Tl(rn(te.data.agentId));break;case"live":{const $e=rn(te.data.runId)??"",Je=Number(te.data.turn??0),Ke=te.data.kind==="thinking"?"thinking":"text",yn=rn(te.data.text)??"",hr=Date.now();if(Ke==="text"){const Us=qe.current;qe.current=Us&&Us.runId===$e&&Us.turn===Je?{...Us,text:Us.text+yn}:{runId:$e,turn:Je,text:yn}}P(Us=>{const da=Us&&Us.runId===$e&&Us.turn===Je?Us:{runId:$e,turn:Je,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ke==="thinking"?{...da,thinking:da.thinking+yn,thinkingStartedAt:da.thinkingStartedAt??hr}:{...da,text:da.text+yn,textStartedAt:da.textStartedAt??hr}});break}case"live.snapshot":{const $e=rn(te.data.runId)??"",Je=Number(te.data.turn??0),Ke=rn(te.data.text)??"",yn=rn(te.data.thinking)??"",hr=Number(te.data.startedAt??Date.now());qe.current={runId:$e,turn:Je,text:Ke},P({runId:$e,turn:Je,text:Ke,thinking:yn,thinkingStartedAt:yn?hr:null,textStartedAt:Ke?hr:null,settled:!1});break}case"live.settle":{const $e=rn(te.data.runId)??"",Je=Number(te.data.turn??0);P(Ke=>Ke&&Ke.runId===$e&&Ke.turn===Je?{...Ke,settled:!0}:Ke);break}case"tool.called":{const $e=rn(te.data.toolUseId)??rn(te.data.id),Je=rn(te.data.name)??rn(te.data.tool)??"tool";$e&&E(Ke=>[...Ke.filter(yn=>yn.toolUseId!==$e),{toolUseId:$e,name:Je,startedAt:Date.now()}]);break}case"tool.result":{const $e=rn(te.data.toolUseId)??rn(te.data.id);$e&&E(Je=>Je.filter(Ke=>Ke.toolUseId!==$e)),Rn(k);break}case"reaction":Rn(k);break;case"message.appended":Rn(k).then(()=>{P($e=>$e!=null&&$e.settled?null:$e)});break;case"awaiting-approval":{const $e=rn(te.data.approvalId)??rn(te.data.actionId),Je=rn(te.data.toolUseId);$e&&Je&&O(Ke=>new Map(Ke).set(Je,$e)),E(Ke=>Ke.filter(yn=>yn.toolUseId!==Je)),Rn(k);break}case"run.finished":{L(!1),E([]),P(null),Tl(null);const $e=rn(te.data.message);De($e??null);const Je=((Ne=qe.current)==null?void 0:Ne.text.trim())??"";qe.current=null,!$e&&Je!==""&&je.current&&Nd(Je,k).then(Ke=>{Ke&&Wt(Ke)}),Rn(k);break}}}});return()=>B.close()},[k,Rn]),d.useEffect(()=>{const B=window.setInterval(()=>ye(Date.now()),_.length===0?6e4:1e3);return()=>window.clearInterval(B)},[_.length]);const Ci=ue(()=>s&&k?A.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),dr=Ci.error?void 0:Ci.data,Fr=dr!=null&&dr.session&&dr.session.agentId===s&&dr.session.conversationId===k?dr:void 0,Lt=YU(Fr,s,k),zs=(Lt==null?void 0:Lt.id)??null,[Rl,bR]=d.useState(null),Rj=Fr==null?void 0:Fr.mode;d.useEffect(()=>{Lt&&s&&k&&bR({agentId:s,conversationId:k,tab:qU(Lt,Rj)})},[zs,Rj,s,k]);const kR=Rl&&Rl.agentId===s&&Rl.conversationId===k&&!de.includes(Rl.tab.id)?Rl.tab:null,dn=Lt??kR,NR=d.useMemo(()=>QU((S==null?void 0:S.messages)??[]),[S]),[SR,jc]=d.useState(null),CR=d.useMemo(()=>Vz({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),ca=cU(CR,k??null),Ph=dU(i?null:s),$j=d.useMemo(()=>uU((S==null?void 0:S.messages)??[]),[S]),Bn=d.useMemo(()=>{const te=Gz({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:W,served:ca.served,...dn?{folded:Du}:{}}).filter(Ne=>Ne.source==="approval"||!de.includes(Ne.id));if(V&&!de.includes(V)&&!te.some(Ne=>Ne.id===V)){const Ne=Xz((S==null?void 0:S.messages)??[],V,{redactInputOf:Du});Ne&&!Du.has(Ne.tool)&&te.push(Ne)}dn&&te.push(dn);for(const Ne of z)te.push(x4(Ne));return Ph&&te.unshift(hU(Ph,$j)),dt?[...te,fU(dt)]:te},[S,w,W,dt,zs,dn==null?void 0:dn.title,V,G,k,z,ca.served,Ph,$j]),ER=d.useMemo(()=>{var te;const B=[];for(const Ne of(S==null?void 0:S.messages)??[]){if(Ne.role!=="user"||Ne.speaker&&Ne.speaker!=="owner")continue;const $e=(te=Ne.blocks.find(Je=>Je.type==="text"))==null?void 0:te.text.trim();$e&&B.unshift($e)}return B},[S]),Mh=d.useMemo(()=>Bn.filter(B=>B.source==="approval"),[Bn]),wc=Mh.at(-1)??null,yc=d.useMemo(()=>[...Mh.map(B=>({approvalId:B.props.approvalId,toolUseId:B.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(B=>({approvalId:B.approvalId,toolUseId:B.toolUseId??"",askedBy:P6(B.chain,Xe)}))],[Mh,S==null?void 0:S.delegatedApprovals]),$l=d.useMemo(()=>{for(let B=Bn.length-1;B>=0;B-=1){const te=Bn[B];if(te!=null&&te.substantial)return te.id}return null},[Bn]),bc=d.useRef(null),Dh=((Yj=Bn.filter(B=>(B.source!=="browser"||B.pinned===!0)&&B.id!==ng).at(-1))==null?void 0:Yj.id)??((qj=Bn.filter(B=>B.id!==ng).at(-1))==null?void 0:qj.id)??null;d.useEffect(()=>{if($l&&$l!==bc.current){bc.current=$l,X($l);return}V===null&&Dh&&X(Dh)},[$l,V,Dh]);const Ij=d.useRef(ca.live);d.useEffect(()=>{const B=Ij.current;Ij.current=ca.live;const te=[...ca.live].filter(Je=>!B.has(Je));if(te.length===0||wc||V!==null&&V!==bc.current)return;const $e=[...Bn].reverse().find(Je=>Je.source==="descriptor"&&Je.renderer==="preview"&&Je.props.target!==null&&te.includes(Wa(Je.props.target)));$e&&X($e.id)},[ca.live,Bn,wc,V]);const Pj=d.useRef(null);d.useEffect(()=>{zs!==Pj.current&&(Pj.current=zs,zs&&!wc&&X(zs))},[zs,wc]);const Mj=d.useRef(null),Il=b==="browser"?(dn==null?void 0:dn.id)??null:null;d.useEffect(()=>{!Il||Mj.current===Il||(Mj.current=Il,X(Il))},[Il]);const Oh=(dn==null?void 0:dn.id)??null;d.useEffect(()=>{!Oh||!V||Ob((S==null?void 0:S.messages)??[],V)!==null&&(jc(V),X(Oh))},[Oh,V,S]);const Dj=B=>{q(te=>te.some(Ne=>Ne.artifactId===B.artifactId)?te:[...te,B]),X(Pu(B.artifactId)),h&&(m==null||m())},kc=!i&&we&&!we.available?j1(we):null,Oj=i?n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:i.members.slice(0,2).map(B=>{const te=Xe.find(Ne=>Ne.id===B);return n.jsx(jh,{className:"wb-group-chip",id:B,name:(te==null?void 0:te.name)??"?",face:te,initials:1},B)})}):null,Ei=i&&Xe.length>0?v6(i,Xe):null,Lj=(Ei==null?void 0:Ei.kind)==="coordinator",_j=Lp(i?null:we),Fj=((S==null?void 0:S.offers)??[]).filter(B=>!Ye.includes(B.id)&&Date.parse(B.expiresAt)>ee),AR=we&&be===we.id?wn:(we==null?void 0:we.thinking)??null,TR=B=>{if(!we)return;const te=we.id;Ue(te),ws(B),A.setAgentEngine(te,{thinking:B}).catch(Ne=>{Ue(null),De(Ne instanceof pe?Ne.message:String(Ne))})},Lh=(B,te)=>{if(!s)return;const Ne=te.map(Ke=>Ke.artifactId),$e=U,Je={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:B},...te.map(Ke=>({type:"attachment",artifactId:Ke.artifactId,filename:Ke.filename,mime:Ke.mime,kind:Ke.kind,sizeBytes:Ke.sizeBytes}))],...$e?{speaker:mE}:{}};F(Ke=>$e?[...Ke,Je]:[Je]),De(null),he(null),L(!0),(i?Be.sendToGroup(i.id,{...k?{conversationId:k}:{},text:B,attachmentIds:Ne}):Be.send(s,{...k?{conversationId:k}:{},text:B,attachmentIds:Ne})).then(async Ke=>{Ae.current.agentId!==s||Ae.current.conversationId!==k||(he(Ke.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ke.conversationId!==k?(C(null),N(Ke.conversationId)):await Rn(Ke.conversationId),Ke.queued===!0&&F(yn=>yn.filter(hr=>hr.id!==Je.id)),j==null||j(s,Ke.conversationId))}).catch(Ke=>{F(yn=>yn.filter(hr=>hr.id!==Je.id)),De(Ur(Ke)),L(!1)})},RR=B=>{De(null),Ge(B),nt(te=>[...te,B]),A.takeOffer(B,k??void 0).then(te=>{te.runId&&(he(null),L(!0)),k&&Rn(k)}).catch(te=>{nt(Ne=>Ne.filter($e=>$e!==B)),De(Ur(te)),k&&Rn(k)}).finally(()=>Ge(null))},$R=(B,te)=>zj({answer:B,...te?{optionId:te}:{}}),IR=()=>zj({answer:"",skipped:!0}),zj=B=>{const te=S==null?void 0:S.question;te&&(De(null),un(!0),L(!0),Be.answerQuestion(te.id,B).then(()=>{if(k)return Rn(k)}).catch(Ne=>{De(Ur(Ne)),L(!1)}).finally(()=>un(!1)))},PR=()=>{if(s){if(dt){Un(null);return}Y(!0),A.agentProfile(s).then(B=>{Un(B),X(sg(B.id)),h&&(m==null||m())}).catch(B=>De(Ur(B))).finally(()=>Y(!1))}},MR=B=>{it({text:B.prompt,at:Date.now()}),l(B.agentId),h&&(p==null||p())},DR=()=>{k&&Be.cancel(k).catch(B=>De(Ur(B))).finally(()=>{L(!1),E([])})},Nc=d.useCallback(()=>{if(N(null),C(null),F([]),L(!1),De(null),he(null),E([]),O(new Map),X(null),q([]),jc(null),bc.current=null,i){Be.startGroupConversation(i.id).then(({conversationId:B})=>{N(B),s&&(j==null||j(s,B))}).catch(B=>De(Ur(B)));return}R(Me),s&&(j==null||j(s,"new"))},[s,i,Me,j]);d.useEffect(()=>{g&&g!==ke.current&&(ke.current=g,Nc())},[g,Nc]);const Uj=B=>{k&&Rn(k),A.overview().catch(()=>{}),B.state!=="pending"&&O(te=>new Map([...te].filter(([,Ne])=>Ne!==B.id)))},Sc=d.useRef(!1);d.useEffect(()=>{const B=Ne=>{if(!Sc.current)return;const $e=Math.max(Ou,Math.min(720,Ne.clientX-52));Fe($e)},te=()=>{if(Sc.current){Sc.current=!1;try{H!==null&&window.localStorage.setItem(kE,String(H))}catch{}}};return window.addEventListener("pointermove",B),window.addEventListener("pointerup",te),()=>{window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",te)}},[H]);const OR=((Qj=Xe.find(B=>B.id===r))==null?void 0:Qj.name)??null,Bj=i?[]:Z_(we,OR),Wj=!(S&&S.conversationId===k)&&!(!k&&$!==null&&$===Me),Hj=Wj?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&we?n.jsx(H1,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(xn,{agents:Xe,id:we.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${we.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:eF(we)}),Bj.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${we.name}`,children:Bj.map(B=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var te;it({text:B,at:Date.now()}),(te=Te.current)==null||te.focus()},children:B},B))}):null]})}):null,Kj=n.jsx(X3,{renderables:Bn,activeId:V,onActivate:X,onClose:B=>{dt&&B===sg(dt.id)?Un(null):z.some(te=>Pu(te.artifactId)===B)?q(te=>te.filter(Ne=>Pu(Ne.artifactId)!==B)):k&&Z(te=>{const Ne={...te,[k]:[...new Set([...te[k]??[],B])]};return Lb(Ne),Ne}),V===B&&X(null)},timezone:e,onDecided:Uj,onChangeAgent:MR,agents:Xe,browserPanel:dn?n.jsx(HU,{status:Fr,error:Ci.error,reload:Ci.reload,steps:NR,live:Lt!==null,focusedStepId:SR},dn.id):null,descriptors:w,grantedTools:i?ys.flatMap(B=>B.tools??[]):(we==null?void 0:we.tools)??[],...we?{agentName:we.name}:{},loading:Wj,...!i&&we?{face:n.jsx(xn,{agents:Xe,id:we.id,size:"xl"})}:{}}),Vj=(Jj=(Xj=[...(S==null?void 0:S.messages)??[],...I].find(B=>B.role==="user"))==null?void 0:Xj.blocks.find(B=>B.type==="text"))==null?void 0:Jj.text.trim(),Gj=Vj?Vj.split(`
107
- `)[0]:"New conversation",ua=g6({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:ee,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:wt,style:h||H===null?void 0:{width:H},"data-sized":!h&&H!==null?"true":void 0,"data-testid":"chat-column","data-dropping":Q||void 0,onDragEnter:B=>{lu(B)&&(B.preventDefault(),Pe.current+=1,ce(!0))},onDragOver:B=>{lu(B)&&(B.preventDefault(),B.dataTransfer.dropEffect="copy")},onDragLeave:B=>{lu(B)&&(Pe.current=Math.max(0,Pe.current-1),Pe.current===0&&ce(!1))},onDrop:B=>{var te;lu(B)&&(B.preventDefault(),Pe.current=0,ce(!1),s&&((te=Te.current)==null||te.addFiles(B.dataTransfer.files)))},children:[Q?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(A6,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:we?`It goes with your next message to ${we.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&we?fc(hc(we)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:Oj}):we?n.jsx("a",{className:"wb-head-face",href:St(we.id),"aria-label":`${we.name}'s page`,children:n.jsx(xn,{agents:Xe,id:we.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:Gj,children:Gj}),n.jsx("span",{className:"wb-head-meta","data-tone":ua.tone,title:i?`${ys.map(B=>B.name).join(", ")}. Coordinator: ${(we==null?void 0:we.name)??i.coordinator}.`:ua.title,children:i?`${ys.map(B=>B.name).join(", ")} · ${ua.text}`:we?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:St(we.id),title:`${we.name}'s page`,children:we.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",we.handle]}),` · ${ua.tone==="quiet"&&ua.text==="New conversation"?`on ${x}`:ua.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:()=>{J(!1),Nc()},children:n.jsx(me,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":Le,"data-open":Le?"true":void 0,disabled:!s,onClick:()=>J(B=>!B),children:n.jsx($6,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:Bn.length===0,children:["Canvas",Bn.length>0?` (${Bn.length})`:""]}):null,i?n.jsx(Fb,{disabled:!1,label:"More about this group",title:i.name,sub:wE(ys.map(B=>B.name)),face:Oj,items:[{label:"Members",hint:`${i.members.length} agents · ${we?`${we.name} coordinates`:"no coordinator"}`,testId:"group-members",onSelect:()=>a==null?void 0:a("members")},{label:"Rename…",hint:"What this team is for",testId:"group-rename",onSelect:()=>a==null?void 0:a("rename")},"separator",{label:"Clear history…",hint:"Keeps the group and its members",testId:"group-clear",onSelect:()=>a==null?void 0:a("clear")},{label:"Delete group…",hint:"With its history; the agents stay",tone:"critical",testId:"group-delete",onSelect:()=>a==null?void 0:a("delete")}]}):n.jsx(Fb,{disabled:!s,label:"More about this agent",title:(we==null?void 0:we.name)??"Agent",...we?{sub:`@${we.handle}`,face:n.jsx(xn,{agents:Xe,id:we.id,size:"sm"})}:{},items:[{label:dt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:ur,onSelect:PR},...we?[{label:"Set up",hint:"Identity, model and access",href:St(we.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:St(we.id)}]:[]]})]}),u?n.jsx(y1,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Si?{working:new Set([Si])}:{}}):null]}),Le&&s?n.jsx(e6,{agentId:s,...i?{groupId:i.id}:{},currentId:k,timezone:e,onNew:()=>{J(!1),Nc()},onSelect:B=>{if(B===k){J(!1);return}J(!1),C(null),F([]),L(!1),X(null),De(null),he(null),q([]),N(B),j==null||j(s,B,!1)}}):null,s&&k?n.jsx(VU,{agentId:s,conversationId:k},`${s}:${k}`):null,Re?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(oe,{message:Re})}):null,Ve?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Ve}):null,S!=null&&S.carriedOver?n.jsx(x6,{text:S.carriedOver,onDelete:async()=>{const B=S.conversationId;await Be.deleteCarryOver(B),C(te=>{if(!te||te.conversationId!==B)return te;const{carriedOver:Ne,...$e}=te;return $e})}},S.conversationId):null,n.jsx(_v,{messages:[...(S==null?void 0:S.messages)??[],...I],live:_,now:ee,working:U,partial:M,agents:Xe,...S!=null&&S.runs?{runs:S.runs}:{},...s&&k?{onContinue:()=>Lh("continue",[])}:{},...i?{speakers:Xe,coordinatorId:i.coordinator}:{},...Ni?{workingAs:((Zj=Xe.find(B=>B.id===Ni))==null?void 0:Zj.name)??Ni}:{},onOpenFile:Dj,onReadAloud:(B,te)=>{Wt(null),Nd(te,k??void 0,B).then(Ne=>{Ne&&Wt(Ne)})},onOpen:B=>{if(dn){const te=Ob([...(S==null?void 0:S.messages)??[],...I],B);if(te){jc(te),X(dn.id),h&&(m==null||m());return}}k&&Z(te=>{const Ne={...te,[k]:(te[k]??[]).filter($e=>$e!==B)};return Lb(Ne),Ne}),X(B),h&&(m==null||m())},...we?{agentName:we.name,agentId:we.id}:{},...Hj?{empty:Hj}:{},emptyHint:i?`Give the team a task once; ${we?we.name:"the coordinator"} brings members in. @ addresses one of them.`:we?`Nothing here yet. Ask ${we.name} for something.`:"Loading agents…"}),Fj.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Fj.map(B=>n.jsx("button",{className:"ui-btn",disabled:ze!==null,title:B.prompt,onClick:()=>RR(B.id),children:B.label},B.id))}):null,Ei?n.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Ei.kind,children:n.jsx(K,{tone:Lj?"warning":void 0,role:"status",children:n.jsxs("span",{children:[Ei.text," ",n.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>a==null?void 0:a("members"),children:Ei.action})]})})}):null,kc?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(K,{tone:"warning",role:"status",children:[kc," ",n.jsx("a",{href:_e(_j.section),children:_j.label})]})}):yc.length>0?n.jsx($3,{approvals:yc,timezone:e,now:ee,version:S,onDecided:Uj,onSay:B=>Lh(B,[]),onOpenFull:B=>{X(B),h&&(m==null||m())}}):null,kc||yc.length>0?null:S!=null&&S.question?n.jsx(h6,{question:S.question,disabled:Pt||U,onAnswer:$R,onSkip:IR},S.question.id):null,kc||Lj?null:n.jsxs("div",{hidden:yc.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(Uv,{ref:Te,disabled:!s,running:U,onSend:Lh,onStop:DR,agentName:i?i.name:(we==null?void 0:we.name)??"the agent",draft:Ee,history:ER,threadKey:k??(i?`group:${i.id}`:s),model:i?null:(we==null?void 0:we.model)??null,setupHref:i?null:we?St(we.id,"setup","brain"):null,thinking:AR,...!i&&we&&dC(hC(we,Fs.data))?{onThinking:TR}:{},...i?{mentions:ys.map(B=>({handle:B.handle,name:B.name}))}:{},onOpenFile:Dj,conversationId:k??null,readAloud:et,onReadAloud:js}),Oe?n.jsx("p",{className:"wb-voice-note",role:"status",children:Oe}):null]})]}),h?f?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),Kj]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:B=>{var te,Ne;Sc.current=!0,(Ne=(te=B.currentTarget).setPointerCapture)==null||Ne.call(te,B.pointerId)},onKeyDown:B=>{const te=Ne=>{var $e;return Ne??(($e=wt.current)==null?void 0:$e.offsetWidth)??Ou};B.key==="ArrowLeft"&&Fe(Ne=>Math.max(Ou,te(Ne)-16)),B.key==="ArrowRight"&&Fe(Ne=>Math.min(720,te(Ne)+16))}}),Kj]})]})}function C6(){try{const e=window.localStorage.getItem(kE),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=Ou?t:null}catch{return null}}function E6(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function rn(e){return typeof e=="string"&&e!==""?e:null}function Ur(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function Kf(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 lu(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function A6(){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 ig="buddi.chatDraft";function T6(e,t){try{window.sessionStorage.setItem(ig,JSON.stringify({agentId:e,text:t}))}catch{}}function R6(e){try{const t=window.sessionStorage.getItem(ig);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(ig),s.text)}catch{return null}}function $6(){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 I6(){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 Fb({items:e,disabled:t,label:s,title:r,sub:i,face:a}){const[l,o]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!l)return;const h=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",h),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",f)}},[l]);const u=h=>{const f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-menu-item-text",children:h.label}),h.hint?n.jsx("span",{className:"ui-menu-item-hint",children:h.hint}):null]});return h.href?n.jsx("a",{className:"ui-menu-item",role:"menuitem",href:h.href,"data-tone":h.tone,onClick:()=>o(!1),children:f},h.label):n.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":h.testId,"data-tone":h.tone,disabled:h.disabled,onClick:()=>{var m;o(!1),(m=h.onSelect)==null||m.call(h)},children:f},h.label)};return n.jsxs("div",{className:"wb-head-menu",ref:c,children:[n.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":l,"data-open":l?"true":void 0,disabled:t,onClick:()=>o(h=>!h),children:n.jsx(I6,{})}),l?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),n.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[n.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[a,n.jsxs("span",{className:"wb-head-menu-heading",children:[n.jsx("span",{className:"wb-head-menu-title",children:r}),i?n.jsx("span",{className:"wb-head-menu-sub",children:i}):null]})]}),e.map((h,f)=>h==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(h)),n.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}function P6(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 zb=!1;const M6=new Set(["missing","unconfigured","not-english"]);async function Nd(e,t,s=null){const r=iE(s);try{const i=await Be.say({text:e,...t?{conversationId:t}:{}});return bb(r)&&await Iz(i.audioUrl,i.mime,s),null}catch(i){bb(r)&&bl();const a=i instanceof pe&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&M6.has(a)&&(s!==null||!zb)?(zb=!0,i.message):null}}let is=null;function D6(e){if(Iu(e)!==null)return!1;const t=f1(e);return t!==tn&&t!==ii}function O6({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=d.useRef(null),l=d.useRef(s),o=`Ask ${e.name}`,[c,u]=d.useState(!1);return d.useEffect(()=>{if(s||!c||!is)return;const h=ph({url:Be.streamUrl(is.conversationId),lastEventId:is.lastEventId??null,onEvent:f=>{f.name==="run.finished"&&u(!1)}});return()=>h.close()},[s,c]),d.useEffect(()=>{const h=f=>{!f.altKey||f.ctrlKey||f.metaKey||f.code!=="Slash"||(f.preventDefault(),r(!s))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s,r]),d.useEffect(()=>{var h;l.current&&!s&&((h=a.current)==null||h.focus()),l.current=s},[s]),s?n.jsx(_6,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(Do,{children:[n.jsx(Oo,{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(L6,{busy:c})})}),n.jsx(Lo,{children:n.jsx(_o,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function L6({busy:e}){const[t,s]=d.useState(!1);return t?n.jsx(Ho,{size:"lg"}):n.jsx(vh,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function _6({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=d.useRef(null),[l,o]=d.useState(is&&is.agentId===e.id?is.conversationId:null),[c,u]=d.useState(null),[h,f]=d.useState([]),[m,p]=d.useState([]),[g,v]=d.useState(null),[b,j]=d.useState(!1),[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,$]=d.useState(Date.now()),[R,I]=d.useState(sE),F=d.useRef(R);F.current=R;const[_,E]=d.useState(null),M=d.useRef(null),P=d.useCallback(async G=>{try{const Z=await Be.conversation(G);u(Z),f(z=>z.filter(q=>!F6(Z,q)))}catch{}},[]);d.useEffect(()=>{l&&P(l)},[l,P]),d.useEffect(()=>{if(!l)return;const G=ph({url:Be.streamUrl(l),onEvent:Z=>{var z;switch(Z.name){case"run.started":M.current=null,j(!0),v(null);break;case"live":{const q=Wn(Z.data.runId)??"",Q=Number(Z.data.turn??0),ce=Z.data.kind==="thinking"?"thinking":"text",Pe=Wn(Z.data.text)??"",Te=Date.now();if(ce==="text"){const Le=M.current;M.current=Le&&Le.runId===q&&Le.turn===Q?{...Le,text:Le.text+Pe}:{runId:q,turn:Q,text:Pe}}v(Le=>{const J=Le&&Le.runId===q&&Le.turn===Q?Le:{runId:q,turn:Q,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return ce==="thinking"?{...J,thinking:J.thinking+Pe,thinkingStartedAt:J.thinkingStartedAt??Te}:{...J,text:J.text+Pe,textStartedAt:J.textStartedAt??Te}});break}case"live.snapshot":{const q=Wn(Z.data.runId)??"",Q=Number(Z.data.turn??0),ce=Wn(Z.data.text)??"",Pe=Wn(Z.data.thinking)??"",Te=Number(Z.data.startedAt??Date.now());M.current={runId:q,turn:Q,text:ce},j(!0),v({runId:q,turn:Q,text:ce,thinking:Pe,thinkingStartedAt:Pe?Te:null,textStartedAt:ce?Te:null,settled:!1});break}case"live.settle":{const q=Wn(Z.data.runId)??"",Q=Number(Z.data.turn??0);v(ce=>ce&&ce.runId===q&&ce.turn===Q?{...ce,settled:!0}:ce);break}case"tool.called":{const q=Wn(Z.data.toolUseId)??Wn(Z.data.id),Q=Wn(Z.data.name)??Wn(Z.data.tool)??"tool";q&&p(ce=>[...ce.filter(Pe=>Pe.toolUseId!==q),{toolUseId:q,name:Q,startedAt:Date.now()}]);break}case"tool.result":{const q=Wn(Z.data.toolUseId)??Wn(Z.data.id);q&&p(Q=>Q.filter(ce=>ce.toolUseId!==q)),P(l);break}case"message.appended":case"awaiting-approval":P(l).then(()=>v(q=>q!=null&&q.settled?null:q));break;case"run.finished":{j(!1),p([]),v(null);const q=Wn(Z.data.message);k(q??null);const Q=((z=M.current)==null?void 0:z.text.trim())??"";M.current=null,!q&&Q!==""&&F.current&&Nd(Q,l).then(ce=>{ce&&E(ce)}),P(l);break}}}});return()=>{is&&is.conversationId===l&&(is.lastEventId=G.lastEventId()),G.close()}},[l,P]),d.useEffect(()=>{i(b||x)},[b,x,i]),d.useEffect(()=>{if(m.length===0)return;const G=window.setInterval(()=>$(Date.now()),1e3);return()=>window.clearInterval(G)},[m.length]);const U=(G,Z)=>{w(!0),k(null);const z={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:G}]};f(q=>[...q,z]),(async()=>{try{const q=l??(await Be.startConversation(e.id)).conversationId;q!==l&&(is={agentId:e.id,conversationId:q},o(q));const Q=await Be.send(e.id,{conversationId:q,text:G,...Z.length>0?{attachmentIds:Z.map(ce=>ce.artifactId)}:{}});Q.conversationId!==q&&(is={agentId:e.id,conversationId:Q.conversationId},o(Q.conversationId)),j(!0),P(Q.conversationId)}catch(q){f(Q=>Q.filter(ce=>ce.id!==z.id)),k(q instanceof pe?q.message:String(q)),S({text:G,at:Date.now()})}finally{w(!1)}})()},L=()=>{l&&Be.cancel(l).catch(G=>k(String(G))).finally(()=>j(!1))},W=()=>{var G;is=null,o(null),u(null),f([]),p([]),v(null),j(!1),k(null),(G=a.current)==null||G.focus()},O=G=>{I(G),rE(G),G||bl()},V=l?at(e.id,l):at(e.id),X=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(l4,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:G=>{var Z;G.preventDefault(),(Z=a.current)==null||Z.focus()},onCloseAutoFocus:G=>G.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:W,disabled:l===null&&h.length===0,children:"New"}),n.jsx(Tt,{size:"sm",variant:"ghost",href:V,onClick:G=>{G.preventDefault(),s(V)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(_v,{messages:X,live:m,now:C,working:b||x,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(V),onReadAloud:(G,Z)=>{E(null),Nd(Z,l??void 0,G).then(z=>{z&&E(z)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(oe,{message:y}):null,n.jsx(Uv,{ref:a,disabled:x||!e.available,running:b,onSend:U,onStop:L,agentName:e.name,placeholder:`Message ${e.name}…`,draft:N,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:R,onReadAloud:O}),_?n.jsx("p",{className:"wb-voice-note",role:"status",children:_}):null]})]})}function Wn(e){return typeof e=="string"?e:null}function F6(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 NE=3;function z6(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function U6(e,t){return e?t?"above-dock":"above-button":"corner"}function B6({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function W6(e){return e.state==="shown"&&e.seenAt===null}function H6(e){const[t,s]=d.useState([]),r=d.useRef(new Set),i=d.useRef(new Set),a=d.useCallback(()=>{e&&A.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>W6(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of t.slice(0,NE))i.current.has(o.id)||(i.current.add(o.id),A.notificationSeen(o.id).catch(()=>{}))},[t]);const l=d.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function K6({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,NE),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":z6(l.kind),role:"status",children:[l.agentId?n.jsx(xn,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:zo(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:V6(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 ${zo(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function V6(e){var t;return((t=e.split(`
108
- `).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const G6=3e4,Y6=1e3;function q6(e,t,s){const r=d.useRef(t);r.current=t;const i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",f=j=>{var x;l=Date.now(),A.presence(j).catch(w=>{var y;w instanceof pe&&w.status===401&&(a=!0,(y=i.current)==null||y.call(i))}),j==="active"&&((x=r.current)==null||x.call(r))},m=j=>{if(a||(o=j,c!==null))return;const x=l+Y6-Date.now();if(x<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const w=o;o=null,f(w)},x)},p=()=>{u=!0,h()&&m("active")},g=()=>{u=!1,m("away")},v=()=>m(h()?"active":"away");h()&&m("active");const b=window.setInterval(()=>{h()&&u&&m("active")},G6);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",v),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",v)}},[e])}function Q6({agents:e,onClose:t,onCreated:s}){return v1(e)?n.jsx(X6,{agents:wv(e),onClose:t,...s?{onCreated:s}:{}}):n.jsx(pt,{title:"A new group",onClose:t,children:n.jsxs(K,{children:["A group needs two agents. Make another one with ",Q_(e)," first."]})})}function X6({agents:e,onClose:t,onCreated:s}){var j,x;const[r,i]=d.useState(""),[a,l]=d.useState([]),[o,c]=d.useState(((j=e.find(w=>w.roles.includes(pv)))==null?void 0:j.id)??((x=e[0])==null?void 0:x.id)??""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=[...new Set([o,...a])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,v=w=>l(y=>y.includes(w)?y.filter(k=>k!==w):[...y,w]),b=async()=>{h(!0),m(null);try{s==null||s(await Be.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof pe?w.message:String(w))}finally{h(!1)}};return n.jsx(pt,{title:"A new group",onClose:t,children:n.jsxs(se,{children:[n.jsx(ae,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:r,autoFocus:!0,maxLength:80,onChange:w=>i(w.target.value),placeholder:"Household finances"})}),n.jsx(ae,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:n.jsx("select",{value:o,onChange:w=>c(w.target.value),children:e.map(w=>n.jsx("option",{value:w.id,children:w.name},w.id))})}),n.jsx(ae,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(w=>w.id!==o).map(w=>n.jsxs("label",{className:"group-pick-row","data-on":a.includes(w.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:a.includes(w.id),onChange:()=>v(w.id)}),n.jsx(xn,{agents:e,id:w.id,size:"sm"}),n.jsxs("span",{className:"group-pick-text",children:[n.jsx("span",{className:"group-pick-name",children:w.name}),n.jsx("span",{className:"group-pick-desc",children:w.description})]})]},w.id))})}),n.jsx(K,{children:"Members read what is said in this group and what they recall from shared and group memory. Nothing an agent knows privately is brought in on its own: what enters the room is seen by the room."}),f?n.jsx(K,{tone:"critical",children:f}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:t,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!g||u,onClick:()=>void b(),children:u?"Creating…":"Create group"})]})]})})}const J6=1e4;function Ub({title:e,body:t,duration:s,onUndo:r,onGone:i}){return n.jsxs(g2,{className:"ui-toast wb-undo-toast",duration:s,onOpenChange:a=>{a||i()},"data-testid":"undo-toast",children:[n.jsx("span",{className:"ui-toast-mark","aria-hidden":"true"}),n.jsxs("div",{className:"ui-toast-main",children:[n.jsx(x2,{className:"ui-toast-title",children:e}),t?n.jsx(v2,{className:"ui-toast-body",children:t}):null]}),r?n.jsx(j2,{altText:"Undo",asChild:!0,children:n.jsx("button",{type:"button",className:"ui-btn wb-undo-toast-action","data-variant":"ghost","data-size":"sm",onClick:r,children:"Undo"})}):null]})}function Bv(e){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,h,f)=>{var p,g,v,b;s(c),l(null),i(null);let m;try{const j=f?await A.decide(c,u,h,f):await A.decide(c,u,h);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},i(u==="reject"?`Rejected ${j.action.tool}.`:((g=j.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((v=j.execution)==null?void 0:v.state)??"no execution"}${(b=j.execution)!=null&&b.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function Wv({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,f;const[a,l]=d.useState(!1),{values:o,controls:c}=Av(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(vs,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(ve,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx($t,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",Ze(e.expiresAt,t)," (",He(e.expiresAt),"). Policy v",e.policyVersion,", args ",Fo(e.argsHash,12),e.jobId?`, job ${Fo(e.jobId)}`:"","."]}),c,n.jsxs(re,{children:[n.jsx(T,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(f=e.permissionScopes)!=null&&f.length?n.jsxs(n.Fragment,{children:[n.jsx(T,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(T,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(T,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(T,{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(le,{title:"Envelope: everything that decides what the world will see",children:n.jsx($t,{children:_n(e.envelope)})}),n.jsx(le,{title:"Canonical arguments",children:n.jsx($t,{children:_n(e.canonicalArgs)})})]}):null]})}function Hv(e,t,s){const[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null);return{accept:()=>{e&&(i(!0),c(null),A.acceptPluginAgent(e,t).then(h=>{l(h.agent)}).catch(h=>c(h instanceof pe?h.message:String(h))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function SE({agent:e}){return n.jsxs(K,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:at(e.id),children:["Talk to @",e.handle]})]})}function CE(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 Z6(e,t){var i;const s=ue(()=>A.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>CE(a,e,t)))??null,reload:s.reload}}function eB({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Bv(a=>t(a));return n.jsxs(se,{gap:"sm",children:[n.jsx(Wv,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(oe,{message:r})]})}function Kv({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var f;const l=Hv(e,t),o=Z6(e,t),[c,u]=d.useState(null),h=l.created??c;if(h)return n.jsx(SE,{agent:h});if(o.action){const m=i??((f=/@(\S+)/.exec(r))==null?void 0:f[1])??t;return n.jsxs(se,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx(eB,{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(se,{gap:"sm",children:[n.jsxs(re,{children:[n.jsx("span",{children:s}),n.jsx(Bt,{}),a?n.jsx(T,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(T,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(oe,{message:l.failure})]})}function EE(){var t;const e=ue(()=>A.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function AE({offers:e,reload:t}){return e.length===0?null:n.jsx(le,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(se,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(Kv,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{A.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const tB=512*1024,nB=/^[A-Za-z0-9+/]*={0,2}$/;function TE(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===""||!nB.test(r)||Math.floor(r.length*3/4)>tB+2?null:{mime:s,data:r}}function RE(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let vr=null,ho=null,Go=null;const ag=new Set;function $E(){for(const e of ag)e()}function eo(){vr&&(vr.onended=null,vr.onerror=null,vr.pause()),ho&&URL.revokeObjectURL(ho),ho=null,Go!==null&&(Go=null,$E())}async function IE(e,t){eo();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);vr??(vr=new Audio),ho=URL.createObjectURL(new Blob([r],{type:e.mime})),Go=t,vr.onended=eo,vr.onerror=eo,vr.src=ho,$E();try{await vr.play()}catch{throw eo(),new Error("The browser would not play the sound.")}}function Bb(e){e!==void 0&&Go!==e||eo()}function sB(){return d.useSyncExternalStore(e=>(ag.add(e),()=>ag.delete(e)),()=>Go,()=>null)}const rB=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ks=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Wb=/^\d{4}-\d{2}-\d{2}$/;function Bi(e){return e.split("-").map(Number)}function la(e,t){const[s,r,i]=Bi(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function PE(e){const[t,s,r]=Bi(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function ME(e){return rB[PE(e)]}function DE(e){return Bi(e)[2]}function Hb(e){return la(e,-((PE(e)+6)%7))}function Sr(e){return lh(e,{weekday:!0,compact:!0})}function iB(e,t){return e===t?`Today · ${Sr(e)}`:e===la(t,1)?`Tomorrow · ${Sr(e)}`:Sr(e)}function Pi(e){return Qx(e)}const Kb=new Map;function lg(e,t){let s=Kb.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"}),Kb.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 aB(e,t=new Date){return lg(t,e).date}function lB(e,t){return e==="week"?{from:Hb(t),days:7}:e==="month"?{from:Hb(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function oB(e,t,s){if(e!=="month")return la(t,s*7);const[r,i]=Bi(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function cB(e,t,s,r){const[i,a]=Bi(t);if(e==="month")return lC(i,a);const l=la(s,r-1),[o,c,u]=Bi(s),[h,f,m]=Bi(l);return aC().date==="iso"?`${s} – ${l}`:tD()?c===f&&o===h?`${Ks[c-1]} ${u} – ${m}, ${h}`:o===h?`${Ks[c-1]} ${u} – ${Ks[f-1]} ${m}, ${h}`:`${Ks[c-1]} ${u}, ${o} – ${Ks[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${Ks[f-1]} ${h}`:o===h?`${u} ${Ks[c-1]} – ${m} ${Ks[f-1]} ${h}`:`${u} ${Ks[c-1]} ${o} – ${m} ${Ks[f-1]} ${h}`}function va(e){return e==null?"":String(e)}function uB(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=va(Se(l,t.id)),u=va(Se(l,t.title)),h=va(Se(l,t.start)),f=va(Se(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:Se(l,t.allDay),p=m===void 0?Wb.test(h):m===!0||m==="true",g=t.tone===void 0?0:Number(Se(l,t.tone)),v=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":va(Se(l,t.calendar)),tone:v,location:t.location===void 0?"":va(Se(l,t.location))};if(p){const k=h.slice(0,10),N=Wb.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):la(k,1);i.push({...b,allDay:!0,startDate:k,startMin:0,endDate:N,endMin:0});return}const j=new Date(h);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const x=new Date(f),w=lg(j,s),y=Number.isNaN(x.getTime())||x<j?w:lg(x,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function dB(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 Vv(e,t){return e.map(s=>({event:s,part:dB(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 Gv(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${Pi(t.to)}`:s&&t.to===1440?`from ${Pi(t.from)}`:t.from===t.to?Pi(t.from):`${Pi(t.from)}–${Pi(t.to)}`}function og(e,t,s){return[Gv(e,t),e.title,e.location,e.calendar,Sr(s)].filter(Boolean).join(", ")}const OE=30;function hB(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+OE);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 Yv="(max-width: 900px)";function tr(e){const[t,s]=d.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return d.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}const fB={week:"Week",month:"Month",list:"List"},mB=["week","month","list"],pB="(max-width: 720px)";function gB(e){try{return window.localStorage.getItem(e)}catch{return null}}function xB(e,t){try{window.localStorage.setItem(e,t)}catch{}}function vB(e){const t=e.views&&e.views.length>0?e.views:mB,s=tr(pB),[r,i]=d.useState(()=>{const p=gB(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=d.useState(e.today),[u,h]=d.useState(null),{from:f,days:m}=lB(l,o);return{views:t,view:l,setView:p=>{i(p),xB(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:oB(l,o,p)),h(null)},from:f,days:m,to:la(f,m),selected:u,select:h}}function jB({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,h=d.useMemo(()=>Array.from({length:u},(v,b)=>la(c,b)),[c,u]),f=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,g=v=>{if(!v.target.closest('input, textarea, select, [contenteditable="true"]')&&!(v.altKey||v.ctrlKey||v.metaKey)){if(v.key==="ArrowLeft")e.go(-1);else if(v.key==="ArrowRight")e.go(1);else if(v.key==="t"||v.key==="T")e.go(0);else return;v.preventDefault()}};return n.jsxs("div",{className:"cal",role:"region","aria-label":i,tabIndex:0,onKeyDown:g,children:[n.jsxs("div",{className:"cal-bar",children:[n.jsx(T,{size:"sm","aria-label":`Previous ${f}`,onClick:()=>e.go(-1),children:n.jsx(me,{name:"chevron-left",size:14})}),n.jsx(T,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(T,{size:"sm","aria-label":`Next ${f}`,onClick:()=>e.go(1),children:n.jsx(me,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:cB(a,l,c,u)}),e.views.length>1?n.jsx(sn,{label:"View",options:e.views.map(v=>({value:v,label:fB[v]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(wB,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(bB,{dates:h,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:h.map(v=>n.jsx(Vb,{date:v,today:o,events:t,empty:r},v))}):null,p?n.jsx(Vb,{date:p,today:o,events:t,empty:r}):null]})}function Vb({date:e,today:t,events:s,empty:r}){const i=Vv(s,e);return n.jsx(lt,{flush:!0,title:iB(e,t),children:n.jsx(ft,{children:i.length===0?n.jsx(ct,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(ct,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:Gv(a,l)},a.id))})})}function wB({dates:e,today:t,events:s,hours:r,onPick:i}){const a=d.useRef(null);d.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:Vv(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(lt,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Sr(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":Sr(c),children:[n.jsx("span",{className:"cal-wd",children:ME(c)}),n.jsx("span",{className:"cal-num",children:DE(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(h=>h.part.allDay).map(({event:h,part:f})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":h.tone,"aria-label":og(h,f,c),onClick:()=>i(c),children:h.title},h.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:Pi(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Sr(c),"data-today":o(c),children:hB(u.filter(h=>!h.part.allDay)).map(({event:h,part:f,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":h.tone,"data-short":f.to-f.from<60?"true":void 0,"data-lane":m,"aria-label":og(h,f,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${f.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(f.to-f.from,OE)/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:Gv(h,f)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const yB=3;function bB({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(h,f)=>e.slice(f*7,f*7+7)),[o,c]=t.split("-").map(Number),u=lC(o,c);return n.jsx(lt,{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:ME(h)},h))}),l.map(h=>n.jsx("div",{className:"cal-row",role:"row",children:h.map(f=>{const m=Vv(r,f),p=m.slice(0,yB),g=m.length-p.length,v=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":f===i,"data-date":f,"data-today":f===s?"true":void 0,"data-outside":f.slice(0,7)!==t?"true":void 0,"data-selected":f===i?"true":void 0,onClick:()=>a(f),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${Sr(f)}, ${v}`,"aria-pressed":f===i,children:DE(f)}),p.map(({event:b,part:j})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":b.tone,"data-timed":j.allDay?void 0:"true","aria-label":og(b,j,f),children:j.allDay?b.title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"cal-dot","data-tone":b.tone,"aria-hidden":"true"}),n.jsx("span",{className:"cal-chip-time",children:Pi(j.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${Sr(f)}`,children:["+",g]}):null]},f)})},h[0]))]})})}const LE={width:1200,height:200,top:28,right:12,bottom:24,left:36};function kB(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 ou(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function NB(e){const t=LE,s=e.values.length,r=t.width-t.left-t.right,i=t.height-t.top-t.bottom,a=t.height-t.bottom,l=s>0?r/s:r,o=j=>Mi(t.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=kB(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Mi(t.top+i-(j-h)/(f-h)*i),p=e.values.map((j,x)=>{const w=j!==null&&Number.isFinite(j);return{index:x,x:o(x),y:w?m(j):null,value:w?j:null}}),g=[],v=[];if(e.kind==="area"){let j=[];const x=()=>{if(j.length===0)return;const w=j.map((y,k)=>`${k===0?"M":"L"}${y.x},${y.y}`).join(" ");g.push(w),v.push(`${w} L${j[j.length-1].x},${a} L${j[0].x},${a} Z`),j=[]};for(const w of p)w.y===null?x():j.push(w);x()}const b=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Mi(j.x-l*.28),y:j.y,width:Mi(l*.56),height:Mi(a-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:v,bars:b,points:p,slot:l,floor:a}}function SB({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var k;const[l,o]=d.useState(((k=r[0])==null?void 0:k.id)??""),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=s.length,g=c??h,v=r.find(N=>N.id===l)??r[0],b=NB(v),j=LE,x=N=>N%a===0||N===g,w=v.values.filter(N=>N!==null&&Number.isFinite(N));d.useEffect(()=>{const N=m.current,S=g===null?null:N==null?void 0:N.children[g];!N||!S||typeof N.scrollTo!="function"||(S.offsetLeft<N.scrollLeft?N.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>N.scrollLeft+N.clientWidth&&N.scrollTo({left:S.offsetLeft+S.offsetWidth-N.clientWidth,behavior:"smooth"}))},[g]);const y=N=>{var $,R,I;const S=N.key==="ArrowRight"?1:N.key==="ArrowLeft"?-1:0,C=N.key==="Home"?0:N.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(h??-S)+S));C!==null&&(N.preventDefault(),f(C),(I=(R=($=m.current)==null?void 0:$.children[C])==null?void 0:R.querySelector("button"))==null||I.focus())};return n.jsxs(lt,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(N=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":N.id===v.id,onClick:()=>o(N.id),children:N.label},N.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":v.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(N=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:N.y,y2:N.y}),n.jsx("text",{className:"pg-series-tick",x:j.left-8,y:N.y,textAnchor:"end",dominantBaseline:"middle",children:ou(N.value,v.unit)})]},N.value)),b.areas.map((N,S)=>n.jsx("path",{className:"pg-series-area",d:N},`a${S}`)),b.lines.map((N,S)=>n.jsx("path",{className:"pg-series-line",d:N},`l${S}`)),b.bars.map(N=>n.jsx("rect",{className:"pg-series-bar","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y,width:N.width,height:N.height},N.index)),g!==null&&b.points[g]?n.jsx("line",{className:"pg-series-guide","data-index":g,x1:b.points[g].x,x2:b.points[g].x,y1:j.top-4,y2:b.floor}):null,v.kind==="area"?b.points.map(N=>N.y!==null&&x(N.index)?n.jsx("circle",{className:"pg-series-dot","data-index":N.index,"data-hover":N.index===g?"true":void 0,cx:N.x,cy:N.y,r:N.index===g?5:3},N.index):null):null,b.points.map(N=>N.y!==null&&N.value!==null&&x(N.index)?n.jsx("text",{className:"pg-series-value","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y-(v.kind==="area"?10:6),textAnchor:"middle",children:ou(N.value,v.unit)},N.index):null),b.points.map(N=>N.index%a===0?n.jsx("text",{className:"pg-series-x",x:N.x,y:j.height-6,textAnchor:"middle",children:s[N.index]},N.index):null),b.points.map(N=>n.jsx("rect",{className:"pg-series-hit","data-index":N.index,x:Mi(j.left+b.slot*N.index),y:0,width:Mi(b.slot),height:j.height,onMouseEnter:()=>u(N.index),onClick:()=>f(N.index)},N.index))]}),n.jsx("figcaption",{className:"sr-only",children:w.length===0?`${v.label}: no values.`:`${v.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${ou(Math.min(...w),v.unit)}, highest ${ou(Math.max(...w),v.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:i.map((N,S)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===h,"aria-label":[N.label,N.value,...N.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":N.icon??"dot",children:n.jsx(me,{name:yl(N.icon),size:22})}),N.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:N.value}):null,n.jsx("span",{className:"wb-tile-label",children:N.label}),N.lines.map((C,$)=>n.jsx("span",{className:"wb-tile-line",children:C},$))]})})},S))})]})]})}function Mi(e){return Math.round(e*10)/10}const qv=d.createContext(null),Sd=d.createContext(!1);function Et(){const e=d.useContext(qv);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function cg(e,t=new Set){if(Array.isArray(e))for(const s of e)cg(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))cg(r,t)}return t}function _E(e,t){if(t.size===0)return!1;for(const s of cg(e))if(t.has(s))return!0;return!1}function FE(){const[e,t]=d.useState(!1);return d.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function zE({revealed:e,onToggle:t}){return n.jsx(T,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function UE(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function BE({children:e}){const[t,s]=FE();return n.jsxs(se,{gap:"sm",children:[n.jsx(re,{align:"end",children:n.jsx(zE,{revealed:t,onToggle:s})}),t?n.jsx(Sd.Provider,{value:!0,children:e}):n.jsx(UE,{})]})}function Qv(e){return e===void 0||e==="neutral"?void 0:e}function ug(e){return Qv(e)}function CB(e){const t=Qv(e);return t==="accent"?void 0:t}function ms(e,t){if(!t)return!0;const s=Se(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function Xv(e,t,s){if("chat"in t){const a=We(s,t.chat);return a==null?"":at(String(a))}if("proposals"in t)return h_(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return Ji(e.plugin,t.page);const i=t.item===void 0?null:We(s,t.item);return Pr(e.plugin,t.page,i==null?null:String(i))}function Jv(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=Se(t.row,r);return i==null?"":String(i)})}function dg(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=We(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function WE(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=We(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function oa(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Se(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]=We(t.data,o);return s}function Tn(e,t,s,r){const i=Et(),a=e?{...WE(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=ue(()=>e?A.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function gc(){const e=Et(),t=d.useId(),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=(j,x)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=We(x,j.done);return w==null?null:String(w)},p=(j,x,w)=>{const y=j??"refresh";if(typeof y=="object"){const k=Xv(e,y.route,x);k===""?e.refresh():e.navigate(k);return}y==="close"&&(w==null||w()),e.refresh()},g=async(j,x,w)=>{r(j.tool),a(null),o(null);try{const y=await A.pageAct(e.plugin,{tool:j.tool,args:x});if(y.approvalId){u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}});return}u(null),f(null);const k=TE(y.result);o(m(j,y.result)??(k?RE(y.result):null)),k&&await IE(k,t),p(j.then,y.result,w)}catch(y){a(y instanceof Error?y.message:String(y)),e.refresh()}finally{r(null)}},v=j=>{if(!j){e.refresh();return}const x=h;if(u(null),f(null),x&&j.decision==="approve"&&j.state==="succeeded"){o(m(x.ref,j.result)),p(x.then,void 0,x.onDone);return}e.refresh()},b=()=>{a(null),o(null)};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:v,run:g,reset:b}}function kl({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=d.useState(!1),u=f=>Jv(f,{...i===void 0?{}:{count:i},row:a}),h=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(T,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(T,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(T,{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 Cd({id:e,onDecided:t}){const s=Et(),r=ue(()=>A.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Bv(c=>{t?t(c):s.refresh()});return r.error?n.jsx(oe,{message:r.error}):r.data?n.jsxs(se,{children:[n.jsx(Wv,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,h,f)=>{o(c,u,h,f)}}),a?n.jsx(K,{tone:"good",role:"status",children:a}):null,n.jsx(oe,{message:l})]}):n.jsx(ge,{children:"Loading the approval…"})}function Nl({act:e}){return e.error?n.jsx(oe,{message:e.error}):e.approvalId?e.waiting?n.jsxs(se,{children:[n.jsx(K,{role:"status",children:e.waiting}),n.jsx(Cd,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(Cd,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(K,{tone:"good",role:"status",children:e.done}):null}function Yo(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:Se(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 HE(e,t,s){const r=Et(),i=e.optionsFrom,a=i?{...WE(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=ue(()=>i?A.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:ar(o.data,i.rows).map(c=>({value:String(Se(c,i.value)??""),label:String(Se(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function EB({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=HE(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},h=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const m=Array.isArray(s)?s.map(String):[],g=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return n.jsx(ae,{label:e.label,hint:l?void 0:[h,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(c4,{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(AB,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:h,children:m}):n.jsx(ae,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return n.jsx(ae,{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(ae,{label:e.label,hint:h,inline:!0,wide:!l,children:n.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const f=e.type==="secret"?"password":e.type==="number"?"number":e.type;return n.jsx(ae,{label:e.label,hint:h,children:n.jsx("input",{...u,type:f,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?TB(m.target.value):m.target.value)})})}function AB({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=Et(),u=d.useId(),h=sB()===u,[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>()=>Bb(u),[u]);const w=Zv(s,r,i),y=t.args!==void 0?oa(t.args,{data:i,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),k=async()=>{if(h){Bb(u);return}m(!0),g(null),b(null),x(null);try{const S=await A.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){x(S.approvalId);return}g(RE(S.result));const C=TE(S.result);C&&await IE(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},N=h?"Stop":t.label;return n.jsx(ae,{label:e.label,hint:l,action:n.jsx(T,{"data-shape":"icon","aria-label":f?`${t.label}: working`:N,title:N,"aria-busy":f||void 0,"aria-pressed":t.icon==="play"?h:void 0,disabled:a===!0||f,onClick:()=>void k(),children:f?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(me,{name:h?"stop":t.icon??"arrow"})}),after:v?n.jsx(oe,{message:v}):j?n.jsx(Cd,{id:j,onDecided:()=>x(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function TB(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function KE(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function Zv(e,t,s){const r=KE(t,s);return new Set(e.filter(i=>i.when!==void 0&&!ms(r,i.when)||i.disabledWhen!==void 0&&ms(r,i.disabledWhen)).map(i=>i.name))}function Nh({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=KE(t,s);return n.jsx(Is,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||ms(o,c.when)).map(c=>n.jsx(EB,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&ms(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const qo=d.createContext(!1),VE=d.createContext(!1),GE=d.createContext(!1);function ns({title:e,note:t,actions:s,children:r}){const i=d.useContext(qo);return n.jsx(le,{title:e,aside:t,actions:s,panel:i,children:n.jsx(qo.Provider,{value:!1,children:n.jsx(VE.Provider,{value:i,children:r})})})}function ir({component:e,data:t,choose:s,chosen:r}){const i=Et(),a=d.useContext(Sd);if(!ms(t,e.when))return null;if(e.kind!=="section"&&!a&&_E(e,i.sensitive))return n.jsx(BE,{children:n.jsx(ir,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(RB,{component:e,data:t});case"notice":return n.jsx(K,{tone:Qv(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(We(t,e.text)??"")});case"link":return n.jsx($B,{component:e,data:t});case"progress":return n.jsx(PB,{component:e,data:t});case"chart":return n.jsx(MB,{component:e,data:t});case"stats":return n.jsx(DB,{component:e,data:t});case"list":return n.jsx(LB,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(FB,{component:e,data:t});case"detail":return n.jsx(BB,{component:e,data:t});case"form":return n.jsx(WB,{component:e,data:t});case"search":return n.jsx(VB,{component:e,data:t});case"list-detail":return n.jsx(GB,{component:e,data:t});case"repeat":return n.jsx(YB,{component:e,data:t});case"calendar":return n.jsx(qB,{component:e,data:t});case"tiles":return n.jsx(QB,{component:e,data:t});case"series-panel":return n.jsx(XB,{component:e,data:t});case"hero":return n.jsx(JB,{component:e,data:t});case"tabs":return n.jsx(ZB,{component:e,data:t});case"expand":return n.jsx(e5,{component:e,data:t});case"button":return n.jsx(t5,{component:e,data:t});case"approval":return n.jsx(s5,{component:e,data:t});case"artifact":return n.jsx(r5,{component:e,data:t});case"editor":return n.jsx(i5,{component:e,data:t});case"agent-offer":return n.jsx(n5,{component:e});default:return n.jsx(K,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function RB({component:e,data:t}){const s=Et(),r=d.useContext(Sd),[i,a]=FE(),l=!r&&_E(e.body,s.sensitive),o=l&&!i,c=d.useContext(qo);let u=e.body.length;const h=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&h(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(ns,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(ir,{component:p,data:t},g)),l?n.jsx(zE,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(se,{gap:"lg",divided:c,children:o?n.jsx(UE,{}):n.jsx(Sd.Provider,{value:r||l,children:f.map((p,g)=>n.jsx(ir,{component:p,data:t},g))})})})}function $B({component:e,data:t}){const s=Et(),r=Xv(s,e.to,t);return r===""?null:n.jsx(re,{children:n.jsx(Tt,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function Gb(e){return Math.round(e/1e6)}function IB(e,t){const s=qn(We(t,e.value))??0,r=e.total?qn(We(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?`${Gb(s)} of ${Math.max(1,Gb(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function PB({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(We(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=IB(e,t);return n.jsxs(se,{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(_1,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function MB({component:e,data:t}){const s=Tn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:ar(s.data,e.rows),i=r.map(h=>String(Se(h,e.x)??"")),a=h=>r.map(f=>qn(Se(f,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:a(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:a(h)})),u=e.target?qn(We(s.data,e.target))??null:null;return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(ge,{children:"Loading…"}):n.jsx(Sl,{text:e.empty??"Nothing recorded yet."}):n.jsx(r4,{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)?Mp(h):h,formatY:h=>qt(h,"number",null)})]})}function DB({component:e,data:t}){const s=Tn(e.query,t);return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:s.error}),s.data===void 0?n.jsx(ge,{children:e.empty??"Loading…"}):n.jsx(yh,{children:e.items.map((r,i)=>n.jsx(Xs,{label:r.label,value:qt(We(s.data,r.value),r.unit??"text",null),tone:CB(r.tone)},i))})]})}function YE(e,t,s,r){const i=(t.meta??[]).map(u=>String(We(s,u)??"")).filter(u=>u!==""),a=String(We(s,t.title)??""),l=t.to&&!r?Xv(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,h)=>{const f=We(s,u.value);if(f==null||f==="")return null;const m=OB(u,f,s);return n.jsx(ve,{tone:ug(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(We(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function OB(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]:dg(e.tone,s)}}function ar(e,t){const s=Se(e,t);return Array.isArray(s)?s:[]}function qE(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:Se(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 LB({component:e,data:t,onChoose:s,chosen:r}){var N;const i=Et(),a=d.useContext(GE),l=Tn(e.query,t),o=gc(),[c,u]=d.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=ar(l.data,e.rows),m=e.collapsed?ar(l.data,e.collapsed.rows):[],p=QE(e.actions,f,o),g={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},v=qE([...f,...m],e.key??((N=e.select)==null?void 0:N.key),g),b=new Map(v.map(S=>[S.row,S.key])),j=new Set(v.map(S=>S.row)),x=new Set(v.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!ms(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>x.has(S)),y=d.useMemo(()=>{const S=f.filter($=>j.has($));if(!e.groupBy)return[{label:null,rows:S}];const C=new Map;for(const $ of S){const R=String(Se($,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],$])}return[...C].map(([$,R])=>{var I,F;return{label:((F=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:F[$])??$,rows:R}})},[f,e.groupBy,v.length]),k=S=>S.map(C=>{var _;const $=YE(i,e.item,C,s),R=b.get(C);if(h&&(s||$.href))return n.jsx(F1,{href:$.href??"#",current:r===R,onClick:()=>s?s(R):i.navigate($.href),title:$.text,meta:$.meta,sub:$.sub,side:$.pills},R);const I=((_=e.select)==null?void 0:_.disabledWhen)!==void 0&&ms(C,e.select.disabledWhen),F=(e.actions??[]).filter(E=>ms(C,E.when));return n.jsx(ct,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${$.text}`,disabled:I,checked:c.includes(R),onClick:E=>E.stopPropagation(),onChange:E=>u(M=>E.target.checked?[...M,R]:M.filter(P=>P!==R))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===R?"true":void 0,onClick:E=>{E.preventDefault(),s(R)},children:$.text}):$.title,sub:$.sub,side:n.jsxs(n.Fragment,{children:[$.side,F.map((E,M)=>n.jsx(XE,{action:E,row:C,data:l.data,act:o,onForm:p.show},M))]})},R)});return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:l.error}),p.open?null:n.jsx(Nl,{act:o}),p.open?n.jsx(JE,{open:p.open,data:l.data,act:o,onClose:p.close,onDone:p.finish}):null,y.every(S=>S.rows.length===0)?l.loading?n.jsx(ge,{children:"Loading…"}):n.jsx(Sl,{text:e.empty??"Nothing here yet."}):n.jsxs(ft,{children:[e.select?n.jsx(ct,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&w.length===x.size,disabled:x.size===0,onChange:S=>u(S.target.checked?[...x]:[])}),title:n.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,y.map((S,C)=>n.jsxs("div",{children:[S.label?n.jsx("div",{className:"ui-list-group",children:S.label}):null,k(S.rows)]},C))]}),e.collapsed&&m.some(S=>j.has(S))?n.jsx(Ct,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:n.jsx(ft,{children:k(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(re,{align:"end",children:[n.jsxs("span",{className:"ui-toolbar-note",children:[w.length," selected"]}),e.bulk.map((S,C)=>{const $=w.length>0||S.all!==!0?w:[...x];return n.jsx(kl,{action:S,args:oa(S.args,{data:l.data,selected:$,scope:i}),count:$.length,disabled:o.busy||$.length===0,running:o.running===S.tool,onRun:(R,I)=>{u([]),o.run(R,I)}},C)})]}):null]})}function _B(e,t,s){return Object.entries(e).every(([r,i])=>{const a=typeof i=="string"?i:Se(s,i.row);return a!=null&&t[r]===String(a)})}function QE(e,t,s){const r=Et(),[i,a]=d.useState(null);return d.useEffect(()=>{var l;if(!(i!==null||t.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=t.find(h=>ms(h,o.when)&&_B(c,r.params,h));if(u!==void 0){a({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(h=>[h,null])));return}}},[t.length,JSON.stringify(r.params)]),{open:i,show:(l,o)=>{s.reset(),a({action:l,row:o})},close:()=>{s.reset(),a(null)},finish:()=>a(null)}}function XE({action:e,row:t,data:s,act:r,onForm:i}){const a=Et();return e.form?n.jsx(T,{disabled:r.busy,onClick:()=>i(e,t),children:Jv(e.label,{row:t})}):n.jsx(kl,{action:e,args:oa(e.args,{data:s,row:t,scope:a}),disabled:r.busy,running:r.running===e.tool,row:t,onRun:(l,o)=>void r.run(l,o)})}function JE({open:e,data:t,act:s,onClose:r,onDone:i}){const a=Et(),{action:l,row:o}=e,c=l.form,[u,h]=d.useState(()=>Yo(c.fields,o)),f=c.fields.some(v=>v.required&&(u[v.name]===""||u[v.name]===void 0)),{confirm:m,...p}=l,g={...p,label:c.submit};return n.jsx(pt,{title:Jv(c.title,{row:o}),onClose:r,foot:n.jsxs(re,{align:"end",children:[n.jsx(T,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(kl,{action:g,args:oa(l.args,{data:t,row:o,fields:u,shape:c.fields,scope:a}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(v,b)=>void s.run(v,b,i)})]}),children:n.jsxs(se,{children:[n.jsx(Nh,{fields:c.fields,values:u,data:o,onChange:(v,b)=>h(j=>({...j,[v]:b}))}),n.jsx(oe,{message:s.error})]})})}function FB({component:e,data:t}){const s=Tn(e.query,t),r=gc(),i=ar(s.data,e.rows),a=QE(e.actions,i,r);return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:s.error}),a.open?null:n.jsx(Nl,{act:r}),a.open?n.jsx(JE,{open:a.open,data:s.data,act:r,onClose:a.close,onDone:a.finish}):null,i.length===0?s.loading?n.jsx(ge,{children:"Loading…"}):n.jsx(Sl,{text:e.empty??"Nothing here yet."}):n.jsxs(Fn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[e.columns.map(l=>n.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?n.jsx("th",{"aria-label":"Actions"}):null]})}),n.jsx("tbody",{children:i.map((l,o)=>n.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:qt(Se(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:zB(c,l,u),children:c.pill?n.jsx(UB,{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(re,{align:"end",children:e.actions.filter(c=>ms(l,c.when)).map((c,u)=>n.jsx(XE,{action:c,row:l,data:s.data,act:r,onForm:a.show},u))})}):null]},o))})]})]})}function zB(e,t,s){if(e.hint){const r=Se(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function UB({column:e,row:t}){var l,o;const s=Se(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var v;const h=c,f=typeof h=="object"&&h!==null?h.value:c;if(f==null||f==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(v=e.pill)==null?void 0:v.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:qt(f,e.type??"text",null);return n.jsx(ve,{tone:ug(dg(typeof m=="string"?m:void 0,t)),children:g},u)})});const r=(l=e.pill)==null?void 0:l.labels,i=String(s),a=r&&Object.prototype.hasOwnProperty.call(r,i)?r[i]:qt(s,e.type??"text",null);return n.jsx(ve,{tone:ug(dg((o=e.pill)==null?void 0:o.tone,t)),children:a})}function BB({component:e,data:t}){const s=Tn(e.query,t);return s.error?n.jsx(oe,{message:s.error}):s.data===void 0?n.jsx(ge,{children:e.empty??"Loading…"}):n.jsx(ns,{title:e.title,note:e.note,children:n.jsxs(se,{gap:"lg",children:[e.fields.length>0?n.jsx(nn,{items:e.fields.map(r=>({key:r.label,label:r.label,value:qt(We(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(ir,{component:r,data:s.data},i))]})})}function WB({component:e,data:t}){const s=Et(),r=Tn(e.initial,t),i=gc(),[a,l]=d.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(HB,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(le,{title:e.title,aside:e.note,actions:n.jsx(T,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(Nl,{act:i}),a?n.jsx(pt,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:r.error}),c]})}function HB({component:e,data:t,initialData:s,act:r,onDone:i}){const a=d.useContext(VE),l=Et(),[o,c]=d.useState(()=>Yo(e.fields,s)),u=Zv(e.fields,o,s),h=e.fields.some(f=>f.required&&!u.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return n.jsxs(se,{children:[n.jsx(Nh,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:n.jsx(Nl,{act:r}),n.jsx(re,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(kl,{action:e.submit,args:oa(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,i)})})]})}function KB(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 Yb(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function VB({component:e,data:t}){const s=Et(),[r,i]=d.useState(()=>Yo(e.fields,t)),[a,l]=d.useState(e.auto===!0),[o,c]=d.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=Tn(a&&u?e.query:void 0,t),f=ar(h.data,e.rows),m=e.count===void 0?void 0:Se(h.data,e.count),p=e.note===void 0?void 0:Se(h.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,v=e.fields.filter(C=>C!==g),b=C=>{s.setParams(Object.fromEntries(e.fields.map($=>[$.name,String(C[$.name]??"")||null]))),l(!0)},j=(C,$)=>{const R={...r,[C]:$};i(R),e.auto&&b(R)},x=()=>{const C=Yo(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map($=>[$.name,null]))),l(!1))},w=a?v.filter(C=>Yb(s.params[C.name])):[],y=g?w.map(C=>n.jsx(xd,{label:C.label,onRemove:()=>{const $={...r,[C.name]:C.type==="checkbox"?!1:""};i($),b($)},children:KB(C,String(s.params[C.name]))},C.name)):[],k=v.filter(C=>Yb(r[C.name])).length,N=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(T,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:n.jsx(T,{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(ns,{title:e.title,children:n.jsxs(se,{children:[n.jsx(W1,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:g?n.jsx("input",{id:`f-${g.name}`,name:g.name,type:g.type==="email"?"email":"search","aria-label":g.label,placeholder:g.hint??g.label,title:g.hint,required:g.required,value:String(r[g.name]??""),onChange:C=>j(g.name,C.target.value)}):void 0,filters:v.length>0?n.jsx(Nh,{fields:v,values:r,data:t,compact:!0,onChange:j}):void 0,...g&&v.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:k}:{},chips:y.length>0?y:void 0,actions:N}),n.jsx(oe,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${qt(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?f.length===0?n.jsx(ge,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(ft,{children:f.map((C,$)=>{const R=YE(s,S,C);return n.jsx(ct,{title:R.title,sub:R.sub,side:R.side},$)})})}):null]})})}function GB({component:e,data:t}){const s=Et(),r=e.selection==="local",[i,a]=d.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(se,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>n.jsx(ir,{component:u,data:t},h))});return n.jsx(qo.Provider,{value:!1,children:n.jsx(z1,{list:n.jsx(GE.Provider,{value:!0,children:n.jsx(ir,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(qv.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function YB({component:e,data:t}){const s=Et(),[r,i]=d.useState(!1),a=Tn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&ms(a.data,e.poll.while);d.useEffect(()=>i(l),[l]);const o=ar(a.data,e.rows);return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:a.error}),o.length===0?a.loading?n.jsx(ge,{children:"Loading…"}):n.jsx(Sl,{text:e.empty??"Nothing here yet."}):n.jsx(se,{gap:"lg",divided:!0,children:qE(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(le,{children:n.jsx(se,{children:e.body.map((h,f)=>n.jsx(ir,{component:h,data:u},f))})},c))})]})}function qB({component:e,data:t}){const s=Et(),r=vB({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:aB(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=Tn(e.query,t,void 0,{from:r.from,to:r.to}),a=d.useMemo(()=>uB(ar(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(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:i.error}),n.jsx(jB,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function QB({component:e,data:t}){var f;const s=Et(),r=Tn(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=ar(r.data,e.items).flatMap(m=>{const p=yv([m],i).tiles[0];return p?[{tile:p,key:e.select?String(Se(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((f=a[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,h=a.some(m=>m.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:r.error}),r.data===void 0?n.jsx(ge,{children:"Loading…"}):a.length===0?n.jsx(Sl,{text:e.empty??"Nothing to show."}):n.jsx(eE,{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 XB({component:e,data:t}){const s=Tn(e.query,t),r=ar(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(ns,{title:e.title,note:e.note,children:[n.jsx(oe,{message:s.error}),s.data===void 0?n.jsx(ge,{children:"Loading…"}):n.jsx(Sl,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(Se(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)=>yv([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=>qn(Se(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(oe,{message:s.error}),n.jsx(SB,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function JB({component:e,data:t}){const s=Tn(e.query,t),r=o=>{const c=Se(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(oe,{message:s.error}),n.jsx(ge,{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(me,{name:yl(Up(We(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 ZB({component:e,data:t}){var u;const s=Et(),[r,i]=d.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=HE({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(sn,{label:a.label,options:l,value:o,onChange:h=>s.setParams({[a.param]:h})}):null,n.jsx(sn,{label:e.title??"View",options:e.tabs.map(h=>({value:h.id,label:h.label})),value:c.id,onChange:i})]}),c.body.map((h,f)=>n.jsx(ir,{component:h,data:t},`${c.id}-${f}`))]})}function e5({component:e,data:t}){const[s,r]=d.useState(!1),i=Tn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(We(t,e.label)??"");return n.jsxs(Ct,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(oe,{message:i.error}),i.data===void 0?n.jsx(ge,{children:"Loading…"}):n.jsx(se,{children:e.body.map((l,o)=>n.jsx(ir,{component:l,data:i.data},o))})]})}function t5({component:e,data:t}){const s=Et(),r=gc();return n.jsxs(n.Fragment,{children:[n.jsx(re,{align:"end",children:n.jsx(kl,{action:e.action,args:oa(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(Nl,{act:r})]})}function n5({component:e}){const t=Et();return n.jsx(Kv,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function s5({component:e,data:t}){const s=Se(t,e.path);return typeof s!="string"||s===""?null:n.jsx(Cd,{id:s})}function r5({component:e,data:t}){const s=Se(t,e.path);return typeof s!="string"||s===""?null:n.jsx(re,{children:n.jsx("a",{href:fi(s),children:e.label})})}function i5({component:e,data:t}){const s=Tn(e.query,t),r=gc();return s.error?n.jsx(oe,{message:s.error}):s.data===void 0?n.jsx(ge,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(Nl,{act:r}),n.jsx(a5,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function a5({component:e,data:t,loaded:s,act:r}){const i=Et(),[a,l]=d.useState(()=>Yo(e.fields,s)),o={...a,version:Se(s,e.version)},c=Zv(e.fields,a,s),u=e.readOnlyWhen!==void 0&&ms(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(kl,{action:p,args:oa(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(v,b)=>void r.run(v,b)},`${p.tool}-${g}`);return n.jsx(ns,{title:e.title,note:e.note,children:n.jsxs(se,{children:[n.jsx(Nh,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(v=>({...v,[p]:g}))}),u?null:n.jsxs(re,{align:"end",children:[h.map(m),h.length>0?n.jsx(Bt,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function ej({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a,params:l}){const[o,c]=d.useState(()=>({...l})),u=JSON.stringify(l??{});d.useEffect(()=>{l&&Object.keys(l).length>0&&c(b=>({...b,...l}))},[u]);const[h,f]=d.useState(0),m={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...o,...t?{item:t}:{},...o5(e,t)},setParams:b=>c(j=>{const x={...j};for(const[w,y]of Object.entries(b))y===null?delete x[w]:x[w]=y;return x}),navigate:s,timezone:r,version:h,refresh:()=>f(b=>b+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],g=!i&&(p==null?void 0:p.kind)==="notice"&&typeof p.text=="string"&&p.when===void 0&&p.title===void 0&&(p.tone===void 0||p.tone==="neutral")?p.text:void 0,v=g===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(qv.Provider,{value:m,children:n.jsx(An,{embedded:i,title:e.title,lede:g,children:n.jsx(l5,{page:v,boxed:i===!0})})})}function l5({page:e,boxed:t}){const s=Et();return e.data&&s.sensitive.has(e.data.query)?n.jsx(BE,{children:n.jsx(qb,{page:e,boxed:t})}):n.jsx(qb,{page:e,boxed:t})}function qb({page:e,boxed:t}){const s=Tn(e.data,null);return n.jsxs(se,{gap:"lg",divided:!t,children:[n.jsx(oe,{message:s.error}),n.jsx(qo.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(ir,{component:r,data:s.data??null},i))})]})}function o5(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 c5(e){return n.jsx(ej,{...e,embedded:!0})}function Sl({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(cn,{title:s,children:r||null})}const Qb=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],u5=["","image","pdf","table","text","code","audio","video","archive","file"];function d5({hash:e,timezone:t,navigate:s,agents:r}){var _;const i=ZL(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,h]=d.useState(c);d.useEffect(()=>{h(c)},[c]);const f=(E,M=!1)=>s(Xc(a,{q:c,origin:l,family:o,...E}),M);d.useEffect(()=>{if(u===c)return;const E=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout(E)},[u]);const[m,p]=d.useState(null),[g,v]=d.useState(null),[b,j]=d.useState(null),[x,w]=d.useState(!1),[y,k]=d.useState(!1),N=E=>{var M;return E?((M=r.find(P=>P.id===E))==null?void 0:M.name)??E:""},S=d.useRef(0);d.useEffect(()=>{const E=++S.current;p(null),v(null),w(!1),j(null),A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(M=>{S.current===E&&(p(M.entries),v(M.next))}).catch(M=>{S.current===E&&j(M instanceof pe?M.message:String(M))})},[c,l,o]);const C=()=>{if(!g||x)return;w(!0);const E=S.current;A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(M=>{S.current===E&&(p(P=>{const U=new Set((P??[]).map(L=>L.id));return[...P??[],...M.entries.filter(L=>!U.has(L.id))]}),v(M.next))}).catch(M=>{S.current===E&&j(M instanceof pe?M.message:String(M))}).finally(()=>{S.current===E&&w(!1)})},$=(l?1:0)+(o?1:0),R=((_=Qb.find(E=>E.id===l))==null?void 0:_.label)??l,I=n.jsxs(n.Fragment,{children:[m===null?n.jsx(ge,{children:"Loading…"}):m.length===0?n.jsx(ge,{children:"No file matches that."}):n.jsx(ft,{children:m.map(E=>n.jsx(F1,{href:Xc(E.id,{q:c,origin:l,family:o}),current:E.id===a,onClick:()=>s(Xc(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:Dr(E.id),alt:"",loading:"lazy"}):n.jsx(Lv,{family:E.family})}),title:E.filename??"Untitled file",meta:n.jsx("span",{title:Ze(E.createdAt,t),children:He(E.createdAt)}),sub:`${Ui[E.family]} · ${zn(E.sizeBytes)} · ${ZE(E,N)}${h5(E,N)}`},E.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(T,{size:"sm",onClick:C,disabled:x,children:x?"Loading…":"Show more"})}):null]}),F=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."})]}),F?n.jsx(cn,{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(W1,{label:"Files",onSubmit:()=>f({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(Is,{dense:!0,children:[n.jsx(ae,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:E=>f({origin:E.target.value}),children:Qb.map(E=>n.jsx("option",{value:E.id,children:E.label},E.id))})}),n.jsx(ae,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:E=>f({family:E.target.value}),children:u5.map(E=>n.jsx("option",{value:E,children:E===""?"Any kind":Ui[E]},E))})})]}),filtersOpen:y,onToggleFilters:()=>k(E=>!E),active:$,chips:$>0?n.jsxs(n.Fragment,{children:[l?n.jsx(xd,{label:"Origin",onRemove:()=>f({origin:""}),children:R}):null,o?n.jsx(xd,{label:"Kind",onRemove:()=>f({family:""}),children:Ui[o]}):null]}):void 0}),n.jsx(oe,{message:b}),n.jsx(z1,{className:"files-split",label:"Files",list:I,detail:a?n.jsx(f5,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(Xc(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function h5(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 ZE(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 f5({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let x=!1;return l(null),h(null),A.libraryEntry(e).then(w=>{x||l(w)}).catch(w=>{x||h(w instanceof pe&&w.status===404?"This file is no longer in the library.":w instanceof pe?w.message:String(w))}),()=>{x=!0}},[e]);const f=x=>{var w;return x?((w=s.find(y=>y.id===x))==null?void 0:w.name)??x:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(T,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(K,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(ge,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:v}=a,b=m.filename??"Untitled file",j=()=>{c(!0),A.libraryEntry(e,p.length).then(x=>l(w=>w&&{...w,contexts:[...w.contexts,...x.contexts],contextsTotal:x.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(T,{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(Lv,{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:[Ui[m.family]," · ",zn(m.sizeBytes)," · ",Ze(m.createdAt,t)]})]}),v?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:fi(m.id),download:b,children:"Download"}):null]}),v?null:n.jsx(K,{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(oE,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:v}),n.jsx(nn,{items:[{label:"Origin",value:ZE(m,f)},...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(xn,{agents:s,id:m.agentId,size:"sm"}),f(m.agentId)]})}]:[],{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:n.jsx("span",{className:"mono",children:m.id})}]}),n.jsxs("section",{className:"files-conversations",children:[n.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?n.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):n.jsx("ul",{className:"files-ctx",role:"list",children:p.map(x=>{const w=x.groupId?Ii(x.groupId,x.conversationId):at(x.conversationAgentId,x.conversationId),y=x.groupId?x.groupName??"a group":f(x.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:x.groupId?`Group: ${y}`:y}),n.jsxs("span",{className:"muted",children:[" · ",x.kind==="produced"?`made by ${f(x.agentId)||"an agent"}`:x.kind==="reused"?"sent again":"sent by you"," · ",He(x.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:k=>{k.preventDefault(),r(w)},children:"Open conversation"})]},`${x.conversationId}:${x.kind}`)})}),p.length<g?n.jsx(re,{align:"end",children:n.jsx(T,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const m5={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 eA(e){return e&&m5[e]||"plug"}const tA="buddi.keepClose";let nl=null;const hg=new Set;function fg(){for(const e of hg)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),nl=e,fg()}),window.addEventListener("appinstalled",()=>{nl=null,nj(),fg()}));function Sh(){const[e,t]=d.useState(nl);return d.useEffect(()=>{const s=()=>t(nl);return hg.add(s),s(),()=>{hg.delete(s)}},[]),nA()?null:e}async function tj(e){try{await e.prompt();const t=await e.userChoice;nl===e&&(nl=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&nj(),fg(),s}catch{return!1}}function p5(){try{return window.localStorage.getItem(tA)!==null}catch{return!1}}function nj(){try{window.localStorage.setItem(tA,"dismissed")}catch{}}function nA(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function g5(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function sA(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 x5(e){return/Mac|iPhone|iPad/.test(e)}function v5(){const e=Sh(),[t,s]=d.useState(p5);if(t||!e)return null;const r=()=>{nj(),s(!0)};return n.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[n.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),n.jsxs(re,{align:"end",children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(T,{size:"sm",variant:"accent",onClick:()=>{tj(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function j5(){const e=Sh(),[t,s]=d.useState(void 0),[r]=d.useState(nA);if(d.useEffect(()=>{if(r)return;let o=!0;return A.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=g5(),l=e?null:sA(i);return n.jsx(le,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(re,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>{tj(e)},children:"Install the app"})}):void 0,children:n.jsxs(se,{children:[n.jsxs("p",{children:[e?"This browser can install buddi as an app: its own window, the Blob as its icon. ":l?`${l} `:null,"Or bookmark it with ",x5(i)?"⌘D":"Ctrl+D",".",a?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),a&&t==="darwin"?n.jsxs("p",{children:["On this Mac, ",n.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications that signs you in each time it opens (docs/cli.md, under Everyday)."]}):null]})})}function rA(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const w5=3,iA=8e3,y5={hiddenHere:new Set,restoredHere:new Set};function b5(e,t){return t.hiddenHere.has(e.id)?!0:e.hidden&&!t.restoredHere.has(e.id)}function k5(e,t=y5){return(e??[]).filter(s=>!b5(s,t)).slice(0,w5)}function aA(e){const[t,s]=d.useState(new Set),[r,i]=d.useState(new Set),[a,l]=d.useState(null),o=d.useRef(e);o.current=e;const c=(m,p)=>new Set(m).add(p),u=(m,p)=>{const g=new Set(m);return g.delete(p),g};return d.useEffect(()=>{if(!a)return;const m=window.setTimeout(()=>l(null),iA);return()=>window.clearTimeout(m)},[a]),{hiddenHere:t,restoredHere:r,justHidden:a,hide:(m,p)=>{s(g=>c(g,m.id)),i(g=>u(g,m.id)),l({glance:m,spot:p}),A.setGlanceHidden(m.id,!0).then(()=>{var g;return(g=o.current)==null?void 0:g.call(o)},()=>{s(g=>u(g,m.id)),l(g=>(g==null?void 0:g.glance.id)===m.id?null:g)})},undo:()=>{if(!a)return;const{glance:m}=a;l(null),s(p=>u(p,m.id)),i(p=>c(p,m.id)),A.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{i(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function N5({hiding:e,spot:t}){const s=e.justHidden;return!s||s.spot!==t?null:n.jsxs("span",{className:"home-glance-undo",role:"status","aria-live":"polite","data-spot":t,children:[n.jsxs("span",{children:[s.glance.title," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function S5(e){return e.link?Dv(e.link.plugin,e.link.page,e.link.place):null}function C5({glances:e,navigate:t,onChanged:s,except:r,hiding:i}){var u,h;const a=aA(s),l=i??a,o=k5(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=n.jsx(N5,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:n.jsxs("span",{className:"home-glances",children:[((h=l.justHidden)==null?void 0:h.spot)==="line"?n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(f=>{const m=S5(f),p=n.jsxs(n.Fragment,{children:[n.jsx(me,{name:yl(f.icon),size:14}),n.jsx("span",{children:f.text})]});return n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),m?n.jsx("a",{className:"home-glance-text",href:m,onClick:g=>{g.preventDefault(),t(m)},children:p}):n.jsx("span",{className:"home-glance-text",children:p}),n.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${f.title} from Home`,title:"Hide from Home",onClick:()=>l.hide(f,"line"),children:n.jsx(me,{name:"close",size:10})})]},f.id)})]})}function E5(e){const i=Math.min(...e),l=Math.max(...e)-i||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-i)/l)*(24-2*2)])}function A5({points:e,className:t="wg-spark"}){const s=E5(e).map(([r,i])=>`${r.toFixed(1)},${i.toFixed(1)}`);return n.jsxs("svg",{className:t,viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[n.jsx("path",{d:`M0,24 L${s.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),n.jsx("polyline",{points:s.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}const T5={small:2,medium:4},Xb=new Map;function R5(e){let t=Xb.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),Xb.set(e,t)),t}function Jb(e,t){const s=Object.fromEntries(R5(t).formatToParts(e).map(l=>[l.type,l.value])),r=Number(s.hour)%24,i=Number(s.minute),a=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),r,i);return{date:`${s.year}-${s.month}-${s.day}`,h:r,m:i,s:Number(s.second),offset:Math.round((a-Math.floor(e.getTime()/6e4)*6e4)/6e4)}}function $5(e){if(e===0)return"Same time";const t=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${e>0?"+":"−"}${t===0?`${s} min`:s===0?`${t} h`:`${t} h ${s}`}`}function I5(e){if(e===0)return"same time";const t=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${[t?`${t} hour${t===1?"":"s"}`:"",s?`${s} minute${s===1?"":"s"}`:""].filter(Boolean).join(" ")} ${e>0?"ahead":"behind"}`}function P5(e,t,s,r,i){const a=Jb(e,t.zone),l=Jb(e,s),o=a.date===l.date?"Today":a.date>l.date?"Tomorrow":"Yesterday",c=a.offset-l.offset,u=ac(i?{timeFormat:i}:{},()=>Ut(e,t.zone)),h=r?"your time":I5(c);return{...a,day:o,daytime:a.h>=6&&a.h<18,offsetText:r?"Here":$5(c),time:u,label:`${t.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function M5(e,t){const s=t?e.s:0;return{hour:(e.h%12+e.m/60+s/3600)*30,minute:(e.m+s/60)*6,second:t?e.s*6:null}}function D5(e){const[t,s]=d.useState(()=>new Date);return d.useEffect(()=>{const r=e?1e3:6e4;let i;const a=()=>{i=setTimeout(()=>{s(new Date),a()},r-Date.now()%r+5)};return s(new Date),a(),()=>clearTimeout(i)},[e]),t}function Zb({angle:e,length:t,width:s}){return n.jsxs("g",{className:"wg-clock-hand",transform:`rotate(${e} 50 50)`,children:[n.jsx("line",{x1:"50",y1:"50",x2:"50",y2:"42",strokeWidth:Math.min(s,1.8)}),n.jsx("line",{x1:"50",y1:"42",x2:"50",y2:50-t,strokeWidth:s})]})}const O5=Array.from({length:12},(e,t)=>t);function L5({time:e,seconds:t}){const s=M5(e,t);return n.jsxs("svg",{className:"wg-clock-face",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:[n.jsx("circle",{className:"wg-clock-dial",cx:"50",cy:"50",r:"49.25"}),O5.map(r=>n.jsx("line",{className:"wg-clock-tick","data-major":r%3===0?"true":void 0,x1:"50",y1:r%3===0?6.5:7.5,x2:"50",y2:r%3===0?14:12,transform:`rotate(${r*30} 50 50)`},r)),n.jsx(Zb,{angle:s.hour,length:24,width:4.6}),n.jsx(Zb,{angle:s.minute,length:37,width:3.4}),s.second===null?null:n.jsx("g",{className:"wg-clock-second","data-testid":"second-hand",transform:`rotate(${s.second} 50 50)`,children:n.jsx("line",{x1:"50",y1:"59",x2:"50",y2:"9"})}),n.jsx("circle",{className:"wg-clock-pin",cx:"50",cy:"50",r:"2.8"}),s.second===null?null:n.jsx("circle",{className:"wg-clock-pin-second",cx:"50",cy:"50",r:"1.5"})]})}function _5({body:e,size:t}){const s=tr("(prefers-reduced-motion: reduce)"),r=D5(!s),i=e.clocks.slice(0,T5[t]);return n.jsx("div",{className:"wg-clocks","data-count":i.length,children:i.map((a,l)=>{let o;try{o=P5(r,a,e.home,l===0&&a.zone===e.home,e.time)}catch{return null}return n.jsxs("div",{className:"wg-clock","data-night":o.daytime?void 0:"true",role:"img","aria-label":o.label,title:`${a.label} · ${o.time}`,children:[n.jsx(L5,{time:o,seconds:!s}),n.jsxs("span",{className:"wg-clock-words","aria-hidden":"true",children:[n.jsx("span",{className:"wg-clock-city",children:a.label}),n.jsx("span",{className:"wg-clock-day","data-today":o.day==="Today"?"true":void 0,children:o.day}),n.jsx("span",{className:"wg-clock-off",children:o.offsetText})]})]},`${a.label}-${a.zone}`)})})}const F5=3,z5={small:4,medium:6};function Vf({icon:e,size:t}){return e?n.jsx("span",{className:"wg-icon",children:n.jsx(me,{name:yl(e),size:t})}):null}function sj({body:e,size:t}){switch(e.kind){case"stat":return n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"wg-stat-now",children:[n.jsx(Vf,{icon:e.icon,size:24}),n.jsx("span",{className:"wg-value",children:e.value})]}),e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null,n.jsx("span",{className:"wg-push"}),e.trend?n.jsxs("span",{className:"wg-trend",children:[n.jsx(A5,{points:e.trend.points,className:"wg-spark"}),e.trend.label?n.jsx("span",{children:e.trend.label}):null]}):null,e.foot?n.jsx("span",{className:"wg-foot",children:e.foot}):null]});case"list":return n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"wg-list",children:e.rows.slice(0,F5).map((s,r)=>n.jsxs("li",{className:"wg-row",children:[n.jsxs("span",{className:"wg-row-text",children:[n.jsx("span",{className:"wg-row-title",children:s.title}),s.sub&&t==="medium"?n.jsx("span",{className:"wg-row-sub",children:s.sub}):null]}),s.side?n.jsx("span",{className:"wg-row-side","data-tone":s.tone,children:s.side}):null]},`${s.title}-${r}`))}),n.jsx("span",{className:"wg-push"}),e.more?n.jsx("span",{className:"wg-foot",children:e.more}):null]});case"strip":return n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"wg-strip-head",children:[n.jsx(Vf,{icon:e.icon,size:20}),e.value?n.jsx("span",{className:"wg-strip-value",children:e.value}):null,e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null]}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-strip",children:e.items.slice(0,z5[t]).map((s,r)=>n.jsxs("span",{className:"wg-tile",children:[n.jsx("span",{className:"wg-tile-label",children:s.label}),n.jsx(Vf,{icon:s.icon,size:18}),n.jsx("span",{className:"wg-tile-value",children:s.value})]},`${s.label}-${r}`))})]});case"progress":{const s=Math.round(Math.max(0,Math.min(1,e.ratio))*100);return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wg-value",children:e.value}),e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null,n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"ui-meter",role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-label":e.caption??e.value,children:n.jsx("span",{className:"ui-meter-fill","data-tone":e.tone,style:{inlineSize:`${s}%`}})}),e.foot?n.jsx("span",{className:"wg-foot",children:e.foot}):null]})}case"clocks":return n.jsx(_5,{body:e,size:t});case"text":return n.jsxs("span",{className:"wg-text",children:[e.icon?n.jsx("span",{className:"wg-text-icon",children:n.jsx(me,{name:yl(e.icon),size:18})}):null,n.jsxs("span",{className:"wg-text-words",children:[n.jsx("span",{className:"wg-text-main",children:e.text}),e.sub?n.jsx("span",{className:"wg-row-sub",children:e.sub}):null]})]})}}function mg({label:e,options:t,multiple:s,value:r,onChange:i}){const a=Array.isArray(r)?r:[r],l=c=>a.includes(c),o=c=>{if(!s)return i(c);i(l(c)?a.filter(u=>u!==c):[...a,c])};return n.jsx("div",{className:"wg-options",role:s?"group":"radiogroup","aria-label":e,children:t.map(c=>n.jsxs("button",{type:"button",role:s?"checkbox":"radio","aria-checked":l(c.value),className:"wg-option","data-on":l(c.value)?"true":void 0,onClick:()=>o(c.value),children:[n.jsx("span",{className:"wg-option-mark","data-multiple":s?"true":void 0,"aria-hidden":"true",children:s&&l(c.value)?n.jsx(me,{name:"check",size:12}):null}),n.jsxs("span",{className:"wg-option-text",children:[n.jsx("span",{className:"wg-option-name",children:c.label}),c.sub?n.jsx("span",{className:"wg-option-sub",children:c.sub}):null]})]},c.value))})}function ek(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function U5(e){var t;return{label:((t=e.name.split(",")[0])==null?void 0:t.trim())||e.name,name:e.name,latitude:e.latitude,longitude:e.longitude,timezone:e.timezone??null}}function B5({field:e,value:t,places:s,onChange:r}){const i=Array.isArray(t)?t:t?[t]:[],[a,l]=d.useState(""),[o,c]=d.useState([]),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=new Map;for(const y of s)p.set(y.id,{value:{place:y.id},label:y.label,sub:y.name});for(const y of[...i,...o])"place"in y||p.set(ek(y),{value:y,label:y.label,sub:y.name});const g=[...p.entries()].map(([y,k])=>({value:y,label:k.label,sub:k.sub})),v=i.map(ek),b=s.find(y=>y.id==="home"||y.label.toLowerCase()==="home")??s[0],j=e.multiple?v:v[0]??(b==null?void 0:b.id)??"",x=y=>{const k=(Array.isArray(y)?y:[y]).map(N=>{var S;return(S=p.get(N))==null?void 0:S.value}).filter(N=>!!N);r(e.multiple?k.slice(-3):k[0]??null)},w=()=>{const y=a.trim();y.length<2||(h(!0),m(null),A.findPlace(y).then(({found:k})=>{const N=k.slice(0,3).map(U5);c(N),N.length===0?m(`Nothing found for “${y}”.`):e.multiple?r([...i,N[0]].slice(-3)):r(N[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return n.jsxs("div",{className:"wg-field-stack",children:[g.length>0?n.jsx(mg,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:x}):null,n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{value:a,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),w())}}),n.jsx(T,{size:"sm",disabled:u||a.trim().length<2,onClick:w,children:u?"Finding…":"Find"})]}),f?n.jsx("span",{className:"ui-field-hint",children:f}):null]})}function W5({field:e,value:t,sheet:s,onChange:r}){var a;let i;switch(e.kind){case"select":{const l=e.options??[],o=typeof t=="string"?t:e.default??((a=l[0])==null?void 0:a.value)??"",c=l.length>0&&l.length<=3&&l.every(u=>u.label.length<=14);i=l.length===0?n.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?n.jsx(sn,{label:e.label,options:l,value:o,onChange:r}):n.jsx(mg,{label:e.label,options:l,value:o,onChange:r});break}case"multiselect":{const l=e.options??[];i=l.length===0?n.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):n.jsx(mg,{label:e.label,options:l,multiple:!0,value:Array.isArray(t)?t:e.default??[],onChange:r});break}case"toggle":return n.jsxs("div",{className:"wg-field",children:[n.jsxs("label",{className:"wg-toggle",children:[n.jsx("input",{type:"checkbox",checked:typeof t=="boolean"?t:e.default??!1,onChange:l=>r(l.target.checked)}),n.jsx("span",{children:e.label})]}),e.hint?n.jsx("span",{className:"ui-field-hint",children:e.hint}):null]});case"text":i=n.jsx("input",{"aria-label":e.label,value:typeof t=="string"?t:e.default??"",maxLength:e.max??60,placeholder:e.placeholder,onChange:l=>r(l.target.value)});break;case"place":i=n.jsx(B5,{field:e,value:t,places:s.places,onChange:r});break;case"timeFormat":i=n.jsx(sn,{label:e.label,options:[{value:"profile",label:`Profile · ${Qx(14*60+32)}`},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:t==="12h"||t==="24h"?t:"profile",onChange:r});break}return n.jsxs("div",{className:"wg-field",role:"group","aria-label":e.label,children:[n.jsx("span",{className:"wg-field-label",children:e.label}),i,e.hint?n.jsx("span",{className:"ui-field-hint",children:e.hint}):null]})}function H5({info:e,placement:t,surface:s,view:r,label:i}){var u;const a=s==="lock",l=((u=r==null?void 0:r.body)==null?void 0:u.kind)==="text",o=a&&(l||t.size==="small")?"small":t.size,c=r?r.body?e.sensitive?n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),n.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."})]}):n.jsx(sj,{body:r.body,size:o}):n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:r.state==="error"?`Couldn't load this${r.error?`: ${r.error}`:""}.`:"Nothing to show right now."})}):n.jsxs("span",{className:"wg-skel-body","aria-hidden":"true",children:[n.jsx("span",{className:"wg-skel","data-w":"half"}),n.jsx("span",{className:"wg-skel","data-w":"third"}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-skel"})]});return n.jsx("div",{className:"wg-preview","data-surface":s,"aria-label":`Preview of ${i}`,role:"img",children:n.jsxs("div",{className:"wg-frame","data-size":o,"data-variant":a?"compact":void 0,"data-kind":r!=null&&r.body&&!e.sensitive?r.body.kind:void 0,"aria-hidden":"true",children:[a?null:n.jsx("div",{className:"wg-head",children:n.jsx("span",{className:"wg-title",children:i})}),n.jsx("div",{className:"wg-body",children:c}),a?n.jsx("span",{className:"wg-compact-title",children:i}):null]})})}function lA({info:e,placement:t,surface:s,onSave:r,onRemove:i,onClose:a}){const l=ue(()=>A.widgetSettings(e.id),[e.id]),[o,c]=d.useState(t.settings??{}),[u,h]=d.useState(null),[f,m]=d.useState(t.label??e.title),[p,g]=d.useState(!1),[v,b]=d.useState(null),j=d.useRef(0),x=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const k=++j.current,N=window.setTimeout(()=>{A.previewWidget({widget:e.id,size:t.size,settings:o}).then(S=>{k===j.current&&(h(S.view),m(S.label))}).catch(()=>{k===j.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(N)},[x,e.id,t.size]);const w=()=>{g(!0),b(null),r(o).then(k=>{g(!1),k||b("Couldn’t keep these settings. Try again.")})},y=s==="lock"?"the lock screen":"Home";return n.jsx(pt,{title:f,onClose:a,foot:n.jsxs(re,{children:[n.jsxs(T,{variant:"danger-ghost",onClick:i,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",onClick:a,children:"Cancel"}),n.jsx(T,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"wg-sheet",children:[n.jsx(H5,{info:e,placement:t,surface:s,view:u,label:f}),n.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",y,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),n.jsx(oe,{message:v??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>n.jsx(W5,{field:k,value:o[k.key],sheet:l.data,onChange:N=>c({...o,[k.key]:N})},k.key)):l.error?null:n.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const K5=6e4,oA="buddi.clock",cA="buddi.home.widgets";function V5(){try{const e=Number(window.localStorage.getItem(cA));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function G5(e){try{window.localStorage.setItem(cA,String(e))}catch{}}function uA(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}`}function dA(e,t){const s=d.useRef(t);s.current=t,d.useEffect(()=>{if(!e)return;let r;const i=()=>{r=setTimeout(()=>{s.current(),i()},6e4-Date.now()%6e4+1e3)};return i(),()=>clearTimeout(r)},[e])}function Y5(){const e=ue(()=>A.widgets("home"),[],K5),[t,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{t&&G5(t.home.length)},[t]),dA((t==null?void 0:t.home.some(r=>{var i,a;return r.widget===oA&&((a=(i=t.views[r.key])==null?void 0:i.body)==null?void 0:a.kind)!=="clocks"}))??!1,e.reload),{answer:t,error:e.error,apply:s,reload:e.reload}}function q5(e){return new Set(((e==null?void 0:e.home)??[]).map(t=>t.widget))}function Q5(e){const[t,s]=d.useState(!1);return d.useEffect(()=>{if(!e||!t)return;const r=()=>{(document.visibilityState==="hidden"||!document.hasFocus())&&s(!1)};return document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r)}},[e,t]),[t,s]}const hA=(e,t)=>e.label??(t==null?void 0:t.title)??e.widget;function X5({info:e,placement:t,view:s,index:r,count:i,editing:a,navigate:l,act:o,onRetry:c,retrying:u,drag:h}){var S;const[f,m]=Q5(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,v=e.link?Dv(e.link.plugin,e.link.page,e.link.place):null,b=v!==null&&!a&&p!=="error"&&!g,j=t.size==="small"?"medium":"small",x=hA(t,e),w=t.key,y=(((S=e.settings)==null?void 0:S.length)??0)>0;let k;!s&&a?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?n.jsxs("span",{className:"wg-state-sub",children:[J5(s.error),"."]}):null,a?null:n.jsx(T,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),n.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),a?null:n.jsx(T,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=n.jsx(sj,{body:s.body,size:t.size});const N=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),h.start(w)};return n.jsxs("div",{className:"wg-frame",role:"group","aria-label":x,"data-id":e.id,"data-key":w,"data-size":t.size,"data-kind":s!=null&&s.body&&!g&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":b?"true":void 0,"data-dragging":h.dragging===w?"true":void 0,"data-over":h.over===w&&h.dragging!==w?"true":void 0,draggable:a?!0:void 0,onDragStart:a?N:void 0,onDragOver:a?C=>{h.dragging&&(C.preventDefault(),h.enter(w))}:void 0,onDrop:a?C=>{C.preventDefault(),h.drop(w)}:void 0,onDragEnd:a?()=>h.end():void 0,children:[n.jsxs("div",{className:"wg-head",children:[a?n.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":w,"aria-label":`Move ${x}, position ${r+1} of ${i}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:n.jsx(me,{name:"grip",size:14})}):null,n.jsx("span",{className:"wg-title",children:x}),p==="stale"?n.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${Jx(s.updatedAt)} old`:"Not current"}):null,a&&y?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${x}`,title:"Settings",onClick:()=>o("settings"),children:n.jsx(me,{name:"settings",size:14})}):null,a?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${x} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:n.jsx(me,{name:"close",size:12})}):n.jsx("span",{className:"wg-more",children:n.jsx(bh,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${He(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[y?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<i-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(j)?{label:`Make it ${j}`,onSelect:()=>o("size",j)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),b?n.jsx("a",{className:"wg-body",href:v,onClick:C=>{C.preventDefault(),l(v)},children:k}):n.jsx("div",{className:"wg-body",children:k}),a?n.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?n.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${x}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>n.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":t.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):n.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),n.jsxs("span",{className:"wg-edit-move",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:earlier`,"aria-label":`Move ${x} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:n.jsx(me,{name:"chevron-left"})}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${x} later`,title:"Move later",disabled:r===i-1,onClick:()=>o("later"),children:n.jsx(me,{name:"chevron-right"})})]})]}):null]})}function J5(e){const t=e.replace(/\.$/,"");return t.charAt(0).toUpperCase()+t.slice(1)}function Z5({widgets:e,navigate:t}){const{answer:s,apply:r}=e,[i,a]=d.useState(!1),[l,o]=d.useState([]),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(null),[g,v]=d.useState(!1),[b,j]=d.useState(null),[x,w]=d.useState(null),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,$]=d.useState(new Set),[R]=d.useState(V5),I=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const J=window.setTimeout(()=>u(null),iA);return()=>window.clearTimeout(J)},[c]),d.useEffect(()=>{var ke;const J=I.current;J&&(I.current=null,(ke=document.querySelector(`[data-grip="${CSS.escape(J)}"], [data-move="${CSS.escape(J)}"]`))==null||ke.focus())}),!s)return R===0?null:n.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets","aria-busy":"true",children:[n.jsx("div",{className:"ui-section-head",children:n.jsx("h3",{className:"ui-section-title",children:"Widgets"})}),n.jsx("div",{className:"wg-grid",children:Array.from({length:R},(J,ke)=>n.jsxs("div",{className:"wg-frame","data-state":"loading","aria-hidden":"true",children:[n.jsx("div",{className:"wg-head"}),n.jsxs("span",{className:"wg-skel-body",children:[n.jsx("span",{className:"wg-skel","data-w":"half"}),n.jsx("span",{className:"wg-skel","data-w":"third"}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-skel"})]})]},ke))})]});if(s.available.every(J=>J.builtIn)&&s.home.length===0)return null;const F=new Map(s.available.map(J=>[J.id,J])),_=i?l:s.home,E=J=>hA(J,F.get(J.widget)),M=(J,ke)=>(p(null),r({...ke,home:J,arranged:{...ke.arranged,home:!0}}),A.saveWidgets("home",J).then(ne=>(r(ne),!0),ne=>(r(ke),p(`Couldn't save your widgets: ${ne instanceof Error?ne.message:String(ne)}`),!1))),P=(J,ke,ne)=>{if(ne<0||ne>=J.length||ke===ne)return null;const Ae=J.slice(),[de]=Ae.splice(ke,1);return Ae.splice(ne,0,de),f(`${E(de)}, position ${ne+1} of ${Ae.length}.`),Ae},U=()=>{o(s.home),$(new Set),u(null),p(null),a(!0)},L=J=>(ke,ne)=>{const Ae=_[J];if(ke==="edit"){U();return}if(ke==="settings"){S(Ae.key);return}if(i){if(ke==="earlier"||ke==="later"){const de=P(l,J,ke==="earlier"?J-1:J+1);if(de){const Re=document.activeElement;I.current=(Re==null?void 0:Re.dataset.grip)??(Re==null?void 0:Re.dataset.move)??null,o(de)}}ke==="size"&&ne&&(o(l.map((de,Re)=>Re===J?{...de,size:ne}:de)),$(new Set([...C,Ae.key]))),ke==="hide"&&(o(l.filter((de,Re)=>Re!==J)),f(`${E(Ae)} taken off.`));return}if(ke==="earlier"||ke==="later"){const de=P(s.home,J,ke==="earlier"?J-1:J+1);de&&M(de,s)}ke==="size"&&ne&&M(s.home.map((de,Re)=>Re===J?{...de,size:ne}:de),s),ke==="hide"&&M(s.home.filter((de,Re)=>Re!==J),s).then(de=>{de&&u({item:Ae,at:J})})},W=()=>{if(!c)return;const J=s.home.filter(ke=>ke.key!==c.item.key);J.splice(Math.min(c.at,J.length),0,c.item),u(null),M(J,s)},O=()=>{v(!0),M(l,s).then(J=>{v(!1),J&&(a(!1),f("Widgets saved."))})},V=J=>{j(J),A.refreshWidget(J).then(r,()=>{}).finally(()=>j(null))},X=J=>{var Ae;const ke={key:uA(),widget:J.id,size:J.sizes[0],settings:{}},ne=l.some(de=>de.widget===J.id);o([...l,ke]),f(`${J.title} added.`),ne&&(((Ae=J.settings)==null?void 0:Ae.length)??0)>0&&S(ke.key)},G=(J,ke)=>i?(o(l.map(ne=>{if(ne.key!==J)return ne;const{label:Ae,...de}=ne;return{...de,settings:ke}})),$(new Set([...C,J])),S(null),Promise.resolve(!0)):M(s.home.map(ne=>ne.key===J?{...ne,settings:ke}:ne),s).then(ne=>(ne&&(S(null),f("Settings saved.")),ne)),Z=J=>{S(null);const ke=_.findIndex(ne=>ne.key===J);ke>=0&&L(ke)("hide")},z={dragging:x,over:y,start:J=>w(J),enter:J=>{y!==J&&k(J)},end:()=>{w(null),k(null)},drop:J=>{const ke=l.findIndex(de=>de.key===x),ne=l.findIndex(de=>de.key===J),Ae=ke>=0&&ne>=0?P(l,ke,ne):null;Ae&&o(Ae),w(null),k(null)}},q=c?n.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[n.jsxs("span",{children:[E(c.item)," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:W,children:"Undo"})]},"undo"):null,Q=[];_.forEach((J,ke)=>{const ne=F.get(J.widget);if(!ne)return;c&&!i&&c.at===ke&&Q.push(q);const Ae=i&&(C.has(J.key)||!s.home.some(de=>de.key===J.key));Q.push(n.jsx(X5,{info:ne,placement:J,view:Ae?void 0:s.views[J.key],index:ke,count:_.length,editing:i,navigate:t,act:L(ke),onRetry:()=>V(J.key),retrying:b===J.key,drag:z},J.key))}),c&&!i&&c.at>=_.length&&Q.push(q);const ce=s.available.filter(J=>!J.builtIn),Pe=ce.length-2,Te=N?_.find(J=>J.key===N):void 0,Le=Te?F.get(Te.widget):void 0;return n.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets",children:[n.jsxs("div",{className:"ui-section-head",children:[n.jsx("h3",{className:"ui-section-title",children:"Widgets"}),i?n.jsxs("div",{className:"ui-toolbar","data-align":"end",children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>{a(!1),o([])},disabled:g,children:"Cancel"}),n.jsx(T,{size:"sm",variant:"accent",onClick:O,disabled:g,children:g?"Saving…":"Done"})]}):_.length>0?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(T,{size:"sm",variant:"ghost",onClick:U,children:"Edit"})}):null]}),n.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),m?n.jsx(K,{tone:"critical",role:"alert",children:m}):null,_.length===0&&!i&&!c?n.jsxs("div",{className:"wg-empty",children:[n.jsxs("div",{className:"wg-empty-text",children:[n.jsx("p",{className:"wg-empty-title",children:"Add widgets to Home"}),n.jsxs("p",{className:"wg-empty-sub",children:["Small live panels from your plugins:"," ",(ce.length>0?ce:s.available).slice(0,2).map(J=>J.title).join(", "),Pe>0?` and ${Pe} more`:"","."]})]}),n.jsx(T,{size:"sm",variant:"accent",onClick:U,children:"Add widgets"})]}):Q.length>0?n.jsx("div",{className:"wg-grid","data-editing":i?"true":void 0,children:Q}):null,i?n.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[n.jsxs("div",{className:"wg-gallery-head",children:[n.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),n.jsx("a",{className:"wg-gallery-aside",href:_e("lock"),onClick:J=>{J.preventDefault(),t(_e("lock"))},children:"The lock screen has its own pick"})]}),n.jsx("ul",{className:"wg-gallery-list",children:s.available.map(J=>{var De;const ke=l.filter(Ve=>Ve.widget===J.id).length,ne=(((De=J.settings)==null?void 0:De.length)??0)>0,Ae=J.builtIn?"Built in":`${J.plugin} plugin`,de=J.sizes.length>1?"small or medium":`${J.sizes[0]} only`,Re=ke>1?` · ${ke} on Home`:ke===1&&ne?" · on Home":"";return n.jsxs("li",{className:"wg-add",children:[n.jsxs("span",{className:"wg-add-text",children:[n.jsx("span",{className:"wg-add-title",children:J.title}),n.jsxs("span",{className:"wg-add-sub",children:[Ae," · ",de,J.sensitive?" · hidden until you show it":"",Re]})]}),ke>0&&!ne?n.jsx("span",{className:"wg-add-note",children:"On Home"}):n.jsxs(T,{size:"sm","aria-label":`${ke>0?"Add another":"Add"} ${J.title}`,onClick:()=>X(J),children:[n.jsx(me,{name:"plus",size:12})," ",ke>0?"Add another":"Add"]})]},J.id)})})]}):null,Te&&Le?n.jsx(lA,{info:Le,placement:Te,surface:"home",onClose:()=>S(null),onSave:J=>G(Te.key,J),onRemove:()=>Z(Te.key)}):null]})}const e8="(max-width: 720px)",t8=3e4,n8={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Gf(e,t){return{time:Ut(e,t),day:or(e,t,{weekday:!0})}}function s8(e,t,s=new Date){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),a=Gf(r,t).day===Gf(s,t).day?Gf(r,t).time:oC(r,t);return e.reason==="idle"?`Locked after ${e.delayMinutes?n8[e.delayMinutes]??`${e.delayMinutes} minutes`:"a while"} away, at ${a}`:e.reason==="start"?`Locked since this session began, at ${a}`:`Locked by you at ${a}`}function r8(e){const t=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=d.useState(t);return d.useEffect(()=>{if(r(t()),!e)return;const i=window.setInterval(()=>r(t()),500);return()=>window.clearInterval(i)},[e]),s}const i8=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function tk({size:e=16}){return n.jsx(me,{name:"lock",size:e})}function fA({size:e=16}){return n.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:n.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})})}function a8(){return n.jsxs("svg",{width:18,height:18,viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[n.jsx("path",{d:"M7.6 5h8a1.4 1.4 0 0 1 1.4 1.4v7.2A1.4 1.4 0 0 1 15.6 15h-8L3 10z"}),n.jsx("path",{d:"M9.6 8l4 4M13.6 8l-4 4"})]})}function nk({text:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("div",{className:"so-cmd",children:[n.jsx("code",{className:"so-cmd-text",children:e}),n.jsx(T,{size:"sm",onClick:r,children:t?"Copied":"Copy"})]})}function l8({onClose:e}){return n.jsx(xs,{title:"Forgot your PIN?",onClose:e,foot:n.jsx(T,{variant:"accent",onClick:e,children:"Done"}),children:n.jsxs("div",{className:"lk-forgot",children:[n.jsx("p",{className:"lk-forgot-text",children:"The PIN covers this dashboard; it doesn’t sign you in. On the computer buddi runs on, run one of these:"}),n.jsxs("div",{className:"lk-forgot-way",children:[n.jsx(nk,{text:"buddi dashboard --unlock"}),n.jsx("p",{className:"lk-forgot-hint",children:"Opens buddi without the PIN, once. It prints a link for your other devices too, good for five minutes."})]}),n.jsxs("div",{className:"lk-forgot-way",children:[n.jsx(nk,{text:"buddi dashboard --remove-pin"}),n.jsx("p",{className:"lk-forgot-hint",children:"Removes the PIN on every device. Set a new one in Settings → Lock screen."})]})]})})}function o8({approvals:e,unread:t,after:s,onPick:r}){const i=[];return e>0&&i.push({key:"approvals",n:e,text:e===1?"approval waiting":"approvals waiting"}),t>0&&i.push({key:"unread",n:t,text:t===1?"notification":"notifications"}),i.length===0?null:n.jsx("ul",{className:"lk-badges","aria-label":"Waiting for you",children:i.map(a=>n.jsx("li",{children:n.jsxs("button",{type:"button",className:"lk-chip","data-kind":a.key,"aria-pressed":s===a.key,disabled:!r,title:r?a.key==="unread"?"Open your notifications once unlocked":"Open your approvals once unlocked":void 0,onClick:()=>r==null?void 0:r(s===a.key?null:a.key),children:[n.jsx("span",{className:"ui-badge","aria-hidden":"true",children:a.n>99?"99+":a.n}),n.jsxs("span",{children:[n.jsxs("span",{className:"lk-sr",children:[a.n," "]}),a.text]})]})},a.key))})}function c8({widgets:e,phone:t}){if(e.length===0)return null;const s=e.map(i=>({w:i,size:t||i.view.body.kind==="text"?"small":i.size})),r=Math.min(t?2:4,s.reduce((i,{size:a})=>i+(a==="medium"?2:1),0));return n.jsx("div",{className:"lk-widgets",children:n.jsx("div",{className:"lk-grid","data-phone":t?"true":void 0,"data-cols":r,children:s.map(({w:i,size:a})=>n.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":a,"data-kind":i.view.body.kind,role:"group","aria-label":i.title,children:[n.jsx("div",{className:"wg-body",children:n.jsx(sj,{body:i.view.body,size:a})}),n.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function u8({text:e}){const t=/^(.*?)[\s\u202f]?([AaPp]\.?[Mm]\.?)$/.exec(e);return n.jsx("p",{className:"lk-time","aria-label":e,children:t?n.jsxs(n.Fragment,{children:[t[1],n.jsx("span",{className:"lk-ampm","aria-hidden":"true",children:t[2]})]}):e})}function sk(e,t){const s=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e).map(i=>[i.type,i.value])),r=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),Number(s.hour)%24,Number(s.minute));return Math.round((r-Math.floor(e.getTime()/6e4)*6e4)/6e4)}function d8(e,t,s){try{const r=sk(e,t)-sk(e,s);if(r===0)return"Same time";const i=u=>new Intl.DateTimeFormat("en-CA",{timeZone:u,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),a=i(t)!==i(s)?r>0?", tomorrow":", yesterday":"",l=Math.floor(Math.abs(r)/60),o=Math.abs(r)%60;return`${o===0?`${l} h`:l===0?`${o} min`:`${l} h ${o}`} ${r>0?"ahead":"behind"}${a}`}catch{return""}}function h8(e,t,s){const r=s??{time:null,date:null,zone:null};return ac({timeFormat:r.time,dateFormat:r.date==="off"?null:r.date},()=>({time:Ut(e,t),day:r.date==="off"?null:or(e,t,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Ut(e,r.zone.timezone),offset:d8(e,r.zone.timezone,t)}:null}))}function mA({data:e,now:t,phone:s,pad:r=!1,after:i,onPick:a}){const l=(e==null?void 0:e.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,o=h8(t,l,e==null?void 0:e.clockView),c=(e==null?void 0:e.background)==="image"&&!e.image?"field":(e==null?void 0:e.background)??"field",u=(e==null?void 0:e.focus)??null;return n.jsxs(n.Fragment,{children:[c==="image"&&(e!=null&&e.image)?n.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[n.jsx("img",{className:"lk-photo",src:e.image,alt:""}),n.jsx("div",{className:"lk-scrim"})]}):n.jsx("div",{className:"ui-fieldbg lk-ground","aria-hidden":"true"}),n.jsxs("header",{className:"lk-top",children:[n.jsxs("span",{className:"lk-brand",children:[n.jsx(Ho,{size:"sm"}),n.jsx("span",{children:"buddi"})]}),n.jsx("span",{className:"lk-top-spacer"}),u?n.jsxs("span",{className:"lk-chip","data-kind":"focus",children:[n.jsx(me,{name:"moon",size:13}),n.jsx("span",{children:s?p8(Qo(u,l,t)):`${_i[u.mode]} ${Qo(u,l,t)}`})]}):null]}),n.jsxs("div",{className:"lk-main",children:[o.day?n.jsx("p",{className:"lk-date",children:o.day}):null,n.jsx(u8,{text:o.time}),o.zone?n.jsxs("p",{className:"lk-zone",children:[n.jsx("span",{className:"lk-zone-name",children:o.zone.label}),n.jsx("span",{className:"lk-zone-time",children:o.zone.time}),o.zone.offset?n.jsx("span",{className:"lk-zone-off",children:o.zone.offset}):null]}):null,r||!e?null:n.jsx(o8,{approvals:e.approvals,unread:e.unread,after:i??null,...a?{onPick:a}:{}}),r||!e?null:n.jsx(c8,{widgets:e.widgets,phone:s})]})]})}function f8({value:e,disabled:t,onDigit:s,onBack:r,onSubmit:i}){return n.jsxs("div",{className:"lk-pad",role:"group","aria-label":"PIN pad",children:[["1","2","3","4","5","6","7","8","9"].map(a=>n.jsx("button",{type:"button",className:"lk-key",disabled:t,onClick:()=>s(a),children:a},a)),n.jsx("button",{type:"button",className:"lk-key","data-kind":"quiet","aria-label":"Delete",disabled:t||e.length===0,onClick:r,children:n.jsx(a8,{})}),n.jsx("button",{type:"button",className:"lk-key",disabled:t,onClick:()=>s("0"),children:"0"}),n.jsx("button",{type:"button",className:"lk-key","data-kind":"go","aria-label":"Unlock",disabled:t||e.length<4,onClick:i,children:n.jsx(fA,{size:18})})]})}function m8({initial:e,onUnlocked:t}){const s=tr(e8),r=rA(),[i,a]=d.useState(null),l=i??e,[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState((e==null?void 0:e.waitUntil)??null),[p,g]=d.useState(!1),[v,b]=d.useState(!1),[j,x]=d.useState(!1),[w,y]=d.useState(!1),[k,N]=d.useState(!1),[S,C]=d.useState(null),$=d.useRef(null),R=r8(f),I=R>0,F=d.useRef(t),_=d.useRef(S);_.current=S,F.current=G=>{_.current&&(window.location.hash=_.current==="unread"?h1:fv),t(G)};const E=G=>{var Z;C(G),s&&G?y(!0):(Z=$.current)==null||Z.focus()},M=d.useCallback(()=>{A.lockScreen().then(G=>{b(!1),a(G),m(G.waitUntil),G.locked||F.current(G)}).catch(G=>{G instanceof pe&&G.status===401?window.location.reload():Np(G)&&b(!0)})},[]);d.useEffect(()=>{M();const G=window.setInterval(M,t8),Z=()=>{document.visibilityState==="visible"&&M()};return document.addEventListener("visibilitychange",Z),()=>{window.clearInterval(G),document.removeEventListener("visibilitychange",Z)}},[M]),dA((i==null?void 0:i.widgets.some(G=>G.id===oA&&G.view.body.kind!=="clocks"))??!1,M),d.useEffect(()=>{var G;!s&&!j&&!I&&((G=$.current)==null||G.focus())},[s,j,I,p]),d.useEffect(()=>{!I&&f&&h(null)},[I,f]);const P=G=>{G==null||G.preventDefault(),!(p||I||o.length<4)&&(g(!0),A.unlock(o).then(Z=>{var q;if(c(""),Z.locked){g(!1);return}if((q=window.matchMedia)==null?void 0:q.call(window,"(prefers-reduced-motion: reduce)").matches){F.current(Z);return}N(!0),window.setTimeout(()=>F.current(Z),240)}).catch(Z=>{if(g(!1),c(""),!(Z instanceof pe))return h("Something went wrong. Try again.");const z=Z.detail??{};if(Z.status===403||Z.status===429){z.waitUntil&&m(z.waitUntil);const q=z.triesLeft??0;h(z.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${q} ${q===1?"try":"tries"} left.`)}else Np(Z)?h("buddi isn’t answering. Try again in a moment."):h(Z.message)}))},U=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,L=(l==null?void 0:l.background)==="image"&&!l.image?"field":(l==null?void 0:l.background)??"field",W=(i==null?void 0:i.owner)??null,O=v?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:I?{tone:"critical",text:`Too many tries. Try again in ${i8(R)}.`}:u?{tone:"critical",text:u}:S?{tone:void 0,text:S==="unread"?"Unlock to open your notifications.":"Unlock to open your approvals."}:{tone:void 0,text:l?s8(l,U,r):"Locked"},V=G=>G.replace(/\D/g,"").slice(0,8),X=n.jsxs("div",{className:"lk-who",children:[n.jsx("span",{className:"lk-face","aria-hidden":"true",children:(W??"You").slice(0,1).toUpperCase()}),W?n.jsx("span",{className:"lk-owner",children:W}):null]});return n.jsxs("div",{className:"lk","data-bg":L,"data-phone":s?"true":void 0,"data-view":w?"pad":"glance","data-opening":k?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[n.jsx(mA,{data:i??(l?{...g8(l)}:null),now:r,phone:s,pad:w,after:S,onPick:E}),n.jsx("footer",{className:"lk-unlock",children:s&&!w?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>y(!0),children:[n.jsx(tk,{size:14}),n.jsx("span",{children:"Enter PIN"})]}),n.jsx("p",{className:"lk-note","data-tone":O.tone,role:"status","aria-live":"polite",children:O.text})]}):s?n.jsxs(n.Fragment,{children:[X,n.jsx("div",{className:"lk-dots","aria-hidden":"true","data-state":u?"wrong":void 0,children:o.length===0?n.jsx("span",{className:"lk-dots-empty",children:"Enter your PIN"}):Array.from(o).map((G,Z)=>n.jsx("span",{className:"lk-dot"},Z))}),n.jsx("span",{className:"lk-sr","aria-live":"polite",children:o.length===1?"1 digit entered":`${o.length} digits entered`}),n.jsx("p",{className:"lk-note","data-tone":O.tone,role:"status","aria-live":"polite",children:O.text}),n.jsx(f8,{value:o,disabled:I||p,onDigit:G=>{h(null),c(V(o+G))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>P()}),n.jsxs("div",{className:"lk-pad-foot",children:[n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),c(""),h(null)},children:"Cancel"})]})]}):n.jsxs(n.Fragment,{children:[X,n.jsxs("form",{className:"lk-pin","data-state":u&&!I?"wrong":I?"wait":void 0,onSubmit:P,children:[n.jsx(tk,{size:15}),n.jsx("input",{ref:$,type:"password",inputMode:"numeric",autoComplete:"off",maxLength:8,"aria-label":"PIN","aria-describedby":"lk-note",placeholder:I?"Wait a moment":"Enter your PIN",disabled:I,value:o,onChange:G=>{h(null),c(V(G.target.value))}}),n.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:n.jsx(fA,{})})]}),n.jsx("p",{className:"lk-note",id:"lk-note","data-tone":O.tone,role:"status","aria-live":"polite",children:O.text}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"})]})}),j?n.jsx(l8,{onClose:()=>x(!1)}):null]})}function p8(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function g8(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,unread:0,widgets:[]}}const x8=3e4,v8=5e3,j8="buddi-lock",pg="buddi-locked",w8=_e("lock");function pA(){var t;const e=navigator;return/mac|iphone|ipad|ipod/i.test(((t=e.userAgentData)==null?void 0:t.platform)||navigator.platform||navigator.userAgent)}function y8(e=pA()){return e?"⌃⌘L":"Ctrl+Alt+L"}function b8(e,t=pA()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:t?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const gA=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function Ch(){return d.useContext(gA)}function cu(e){try{e?localStorage.setItem(pg,"1"):localStorage.removeItem(pg)}catch{}}function k8(){try{return localStorage.getItem(pg)==="1"}catch{return!1}}function N8(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(j8)}catch{return null}}function S8({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(null),a=d.useRef(null),l=d.useRef(Date.now()),o=d.useRef(0),c=d.useRef(0),u=d.useRef(0),h=d.useCallback((v,b)=>{v&&i(v),s(b?"locked":"open"),cu(b),b||(l.current=Date.now())},[]),f=d.useCallback(()=>{A.lockState().then(v=>h(v,v.locked)).catch(v=>{if(v instanceof pe&&v.status===401)return s("open");h(null,k8())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((v="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=w8;return}s("locked"),cu(!0),(b=a.current)==null||b.postMessage({type:"locked"}),A.lockNow(v).then(j=>h(j,j.locked)).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const v=()=>{s("locked"),cu(!0),f()};return window.addEventListener(wp,v),()=>window.removeEventListener(wp,v)},[f]),d.useEffect(()=>{const v=N8();if(a.current=v,!!v)return v.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),cu(!0)):(j==null?void 0:j.type)==="unlocked"?f():(j==null?void 0:j.type)==="activity"&&typeof j.at=="number"&&(l.current=Math.max(l.current,j.at))},()=>{v.close(),a.current=null}},[f]),d.useEffect(()=>{const v=b=>{b8(b)&&(b.preventDefault(),t==="open"&&m("owner"))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[t,m]);const p=r!=null&&r.pin?r.delayMinutes:null;d.useEffect(()=>{if(t!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const v=()=>{var N;const k=Date.now();l.current=k,k-u.current>1e4&&(u.current=k,(N=a.current)==null||N.postMessage({type:"activity",at:k}))},b=()=>{const k=Date.now();l.current<=c.current||k-o.current<x8||(o.current=k,c.current=l.current,A.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}b()},x=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const k of x)window.addEventListener(k,v,{passive:!0,capture:!0});const w=window.setInterval(j,v8),y=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",y),()=>{for(const k of x)window.removeEventListener(k,v,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",y)}},[t,r==null?void 0:r.pin,p,m]);const g=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:v=>h(v,v.locked),shortcut:y8()}),[r,m,h]);return t==="checking"?null:t==="locked"?n.jsx(m8,{initial:r,onUnlocked:v=>{var b;(b=a.current)==null||b.postMessage({type:"unlocked"}),h(v,!1)}}):n.jsx(gA.Provider,{value:g,children:e})}const xA="a connection needs you";function C8({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:f,status:m}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:tn,onClick:p=>{p.preventDefault(),s(tn)},"aria-label":"buddi home",children:n.jsx(Ho,{})}),p_.filter(p=>p.route!==gn).map(p=>n.jsx(Yf,{label:p.label,href:p.route,active:t===p.route,badge:p.route===tn?e:0,onClick:()=>s(p.route),children:rk[p.route]},p.route)),a.map(p=>{const g=Pr(p.plugin,p.id);return n.jsx(Yf,{label:p.title,href:g,active:t===g,badge:0,onClick:()=>s(g),children:n.jsx(me,{name:eA(p.icon)})},g)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(Yf,{label:"Settings",href:gn,active:t===gn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(gn),children:rk[gn]}),m,n.jsx(A8,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const E8=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function A8({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var y,k,N;const o=ue(()=>A.owner(),[]),c=Ch(),u=ue(()=>A.focus(),[],6e4),h=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{A.setFocus(S,C).finally(()=>u.reload())},m=((N=(k=o.data)==null?void 0:k.preferredName)==null?void 0:N.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[g]=d.useState(I_),[v]=d.useState($8),b=Sh(),j=m?`You: ${m}`:"You",x=h?`${_i[h.mode]} ${Qo(h,l)}`:null,w=[j,x,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(cc,{modal:!1,children:[n.jsx(uc,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":w,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,h?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(me,{name:"moon",size:10})}):null]})}),n.jsx(vl,{children:n.jsxs(dc,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[n.jsxs("div",{className:"rail-owner-head",children:[n.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:p}),n.jsxs("span",{className:"rail-owner-who",children:[n.jsx("span",{className:"rail-owner-name",children:m??"You"}),n.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),n.jsx(yr,{className:"ui-menu-sep"}),n.jsx(R8,{focus:h,timezone:l,onSwitch:f}),n.jsx(yr,{className:"ui-menu-sep"}),n.jsx(Qi,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(sn,{label:"Theme",options:E8,value:e,onChange:t})}),n.jsx(yr,{className:"ui-menu-sep"}),c.pin?n.jsxs(cs,{className:"ui-menu-item rail-owner-reload",onSelect:()=>c.lockNow(),children:[n.jsx("span",{children:"Lock now"}),n.jsx("kbd",{className:"rail-owner-kbd",children:c.shortcut})]}):n.jsx(cs,{className:"ui-menu-item",onSelect:()=>s(_e("lock")),children:"Set up a lock screen…"}),n.jsx(cs,{className:"ui-menu-item",onSelect:()=>s(_e("appearance")),children:"Change appearance"}),b?n.jsx(cs,{className:"ui-menu-item",onSelect:()=>{tj(b)},children:"Install the app"}):null,g||i?n.jsxs(cs,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),v?n.jsx("kbd",{className:"rail-owner-kbd",children:v}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(yr,{className:"ui-menu-sep"}),n.jsxs(cs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(_e("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 _i={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},T8=[{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 Qo(e,t,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),i=t??Intl.DateTimeFormat().resolvedOptions().timeZone,a=c=>new Intl.DateTimeFormat("en-CA",{timeZone:i,dateStyle:"short"}).format(c),l=Ut(r,i);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:i,weekday:"short"}).format(r)} ${l}`}function R8({focus:e,timezone:t,onSwitch:s}){return n.jsxs(CL,{children:[n.jsxs(EL,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?_i[e.mode]:"Off"})]}),n.jsx(vl,{children:n.jsxs(AL,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${_i[e.mode]} ${Qo(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(i1,{children:[n.jsx(yr,{className:"ui-menu-sep"}),n.jsx(Qi,{className:"ui-menu-label",children:_i[r]}),T8.map(i=>n.jsx(cs,{className:"ui-menu-item","aria-label":`${_i[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(yr,{className:"ui-menu-sep"}),n.jsx(cs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function $8(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function Yf({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 rk={[Xi]:n.jsx(me,{name:"files"}),[tn]:n.jsx(me,{name:"home"}),[ii]:n.jsx(me,{name:"chat"}),[Nt]:n.jsx(me,{name:"agents"}),[xt]:n.jsx(me,{name:"activity"}),[gn]:n.jsx(me,{name:"settings"})},Xo=e=>`${e.plugin}:${e.id}`,I8=new Set;let rj=I8,ik=!1;const gg=new Set;function xg(e){rj=e;for(const t of gg)t()}function P8(e){return gg.add(e),()=>gg.delete(e)}const ak=()=>rj;function M8(){ik||(ik=!0,Promise.resolve().then(()=>A.rail()).then(e=>xg(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function D8(e,t){const s=rj,r=new Set(s);t?r.add(Xo(e)):r.delete(Xo(e)),xg(r);try{await A.setRailHidden(e.plugin,e.id,t)}catch(i){throw xg(s),i}}function vA(){return d.useEffect(M8,[]),d.useSyncExternalStore(P8,ak,ak)}function O8(e,t){return e.filter(s=>!t.has(Xo(s)))}function L8(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function _8(e,t=!0,s){d.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||L8(i.target))return;i.preventDefault();const a=document.getElementById(rg);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(tn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const jA="buddi.theme";function F8(e=wA()){try{const t=e==null?void 0:e.getItem(jA);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function z8(e,t=wA()){try{t==null||t.setItem(jA,e)}catch{}}function U8(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function wA(){try{return window.localStorage}catch{return}}const yA="buddi.ground",bA="buddi.pageWidth";function B8(e=SA()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(yA),r=t(bA);return{theme:F8(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function kA(e,t=document.documentElement){t&&(U8(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 W8(e,t=SA()){z8(e.theme,t);try{t==null||t.setItem(yA,e.ground),t==null||t.setItem(bA,e.width)}catch{}}let Ha=null;const vg=new Set;function jg(){return Ha||(Ha=B8()),Ha}function H8(e){return vg.add(e),()=>vg.delete(e)}function K8(e){Ha={...jg(),...e},kA(Ha),W8(Ha);for(const t of vg)t()}function NA(){return[d.useSyncExternalStore(H8,jg,jg),K8]}function SA(){try{return window.localStorage}catch{return}}function V8({timezone:e,embedded:t}){var m,p;const{data:s,error:r,reload:i}=ue(()=>A.sentinels(),[],3e4),a=ue(()=>A.missions(),[]),[l,o]=d.useState(null),c=((p=(m=a.data)==null?void 0:m.missions.find(g=>g.id==="sentinel-wake"))==null?void 0:p.agentId)??null,u=async(g,v)=>{o(null);try{await A.snoozeAlert(g,v),i()}catch(b){o(b instanceof Error?b.message:String(b))}},h=((s==null?void 0:s.open)??[]).filter(g=>!g.snoozedAt),f=((s==null?void 0:s.open)??[]).filter(g=>g.snoozedAt);return n.jsxs(An,{embedded:t,title:"Alerts",lede:"What the watchers found.",children:[n.jsx(oe,{message:r??l}),n.jsx(K,{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(qf,{title:"Open",findings:h,timezone:e,askAgentId:c,onSnooze:g=>u(g,!0),empty:"Nothing open. Your watchers are quiet."}),f.length>0?n.jsx(qf,{title:"Snoozed",findings:f,timezone:e,askAgentId:c,onSnooze:g=>u(g,!1),empty:""}):null,n.jsx(qf,{title:"Resolved",findings:(s==null?void 0:s.resolved)??[],timezone:e,empty:"Nothing has resolved yet."}),n.jsx(lt,{title:"Waiting for the weekly recap",flush:!0,children:!s||s.digest.length===0?n.jsx(cn,{icon:"bell",title:"Nothing waiting for the recap"}):n.jsxs(Fn,{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(g=>n.jsxs("tr",{children:[n.jsxs("td",{children:[Ja(g.title),n.jsx(EA,{text:Ja(g.detail)})]}),n.jsx("td",{children:n.jsx(CA,{severity:g.severity})}),n.jsx("td",{className:"nowrap",children:Ze(g.createdAt,e)})]},g.id))})]})})]})}function CA({severity:e}){return n.jsx(ve,{tone:e==="urgent"?"critical":void 0,children:e})}function EA({text:e}){const[t,s]=d.useState(!1),r=e.length>240||e.split(`
109
- `).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 G8(e){return`About this alert: "${Ja(e.title)}". ${Ja(e.detail)}
110
-
111
- What should I do about it, and what do you need from me to clear it?`}function qf({title:e,findings:t,timezone:s,askAgentId:r,onSnooze:i,empty:a}){const l=e==="Snoozed";return n.jsx(lt,{title:e,flush:!0,children:t.length===0?n.jsx(ge,{children:a}):n.jsxs(Fn,{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:Ja(o.title)}),n.jsx(EA,{text:Ja(o.detail)}),o.data?n.jsx(Ct,{summary:"evidence",children:n.jsx($t,{children:_n(o.data)})}):null]}),n.jsx("td",{children:n.jsx(CA,{severity:o.severity})}),n.jsxs("td",{className:"nowrap",children:[Ze(o.firstSeenAt,s),n.jsxs("div",{className:"sub",title:Ze(o.lastSeenAt,s),children:["last seen ",He(o.lastSeenAt)]})]}),i?n.jsx("td",{children:n.jsxs(re,{align:"end",children:[r?n.jsx(Tt,{size:"sm",href:at(r,"new"),onClick:()=>T6(r,G8(o)),children:"Ask about it"}):null,n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>i(o.key),children:l?"Wake":"Snooze"})]})}):null]},o.key))})]})})}const lk=5e3,ok=50;function Y8({timezone:e,embedded:t}){var j;const[s,r]=d.useState(""),[i,a]=d.useState(""),[l,o]=d.useState(null),c=ue(()=>A.eventKinds(),[]),{data:u,error:h}=ue(()=>A.events({kind:s||void 0,q:i||void 0,limit:ok}),[s,i],lk),[f,m]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);const p=f.events.length>0?f.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(x=>({...x,busy:!0,error:null}));try{const x=await A.events({kind:s||void 0,q:i||void 0,before:p,limit:ok});m(w=>({events:[...w.events,...x.events],cursor:x.nextCursor,busy:!1,error:null}))}catch(x){m(w=>({...w,busy:!1,error:x instanceof Error?x.message:String(x)}))}}},v=new Set(((u==null?void 0:u.events)??[]).map(x=>x.id)),b=[...(u==null?void 0:u.events)??[],...f.events.filter(x=>!v.has(x.id))];return n.jsxs(An,{embedded:t,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[n.jsxs(re,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:x=>r(x.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(x=>n.jsxs("option",{value:x.kind,children:[x.kind," (",x.count,")"]},x.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:x=>a(x.target.value),size:28}),s||i?n.jsx(T,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",lk/1e3,"s"]})]}),n.jsx(oe,{message:h}),n.jsx(lt,{flush:!0,children:!u||b.length===0?n.jsx(ge,{children:"No events match."}):n.jsxs(Fn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(x=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(x),children:[n.jsx("td",{className:"mono muted",children:x.id}),n.jsxs("td",{className:"nowrap",children:[Ze(x.createdAt,e),n.jsx("div",{className:"sub",children:He(x.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:x.kind}),n.jsx("td",{className:"mono muted",children:rr(_n(x.payload).replace(/\s+/g," "),120)})]},x.id))})]})}),p||f.error?n.jsxs(re,{children:[n.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),f.error?n.jsx("span",{className:"critical",children:f.error}):null,p?n.jsx(T,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(pt,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",Ze(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx($t,{children:_n(l.payload)})]}):null]})}const q8=["pending","leased","suspended","failed","succeeded","cancelled"],Gl=50;function Q8({timezone:e,embedded:t,initialState:s}){const[r,i]=d.useState(s??""),[a,l]=d.useState(null),[o,c]=d.useState(null),{data:u,error:h,reload:f}=ue(()=>A.jobs({...r?{state:r}:{},limit:String(Gl)}),[r],1e4),[m,p]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{p({jobs:[],done:!1,busy:!1})},[r]);const g=async()=>{p(S=>({...S,busy:!0}));try{const S=await A.jobs({...r?{state:r}:{},limit:String(Gl),offset:String(Gl+m.jobs.length)});p(C=>({jobs:[...C.jobs,...S.jobs],done:S.jobs.length<Gl,busy:!1}))}catch(S){c(S instanceof Error?S.message:String(S)),p(C=>({...C,busy:!1}))}},v=new Set(((u==null?void 0:u.jobs)??[]).map(S=>S.id)),b=[...(u==null?void 0:u.jobs)??[],...m.jobs.filter(S=>!v.has(S.id))],j=r?(u==null?void 0:u.counts[r])??0:Object.values((u==null?void 0:u.counts)??{}).reduce((S,C)=>S+C,0),x=!m.done&&b.length<j&&((u==null?void 0:u.jobs.length)??0)>=Gl,[w,y]=d.useState(null),k=async S=>{c(null),y(S);try{const C=(await A.jobs({state:"failed",limit:"500"})).jobs;for(const $ of C)await(S==="retry"?A.retryJob($.id):A.cancelJob($.id));f()}catch(C){c(C instanceof Error?C.message:String(C))}finally{y(null)}},N=async S=>{c(null);try{await S,l(null),f()}catch(C){c(C instanceof Error?C.message:String(C))}};return n.jsxs(An,{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(T,{size:"sm",variant:u!=null&&u.paused?"accent":void 0,onClick:()=>N(A.setPaused(!((u==null?void 0:u.paused)??!1))),children:u!=null&&u.paused?"Resume the queue":"Pause the queue"}),children:[n.jsxs(re,{children:[n.jsxs("select",{"aria-label":"Job state",value:r,onChange:S=>i(S.target.value),children:[n.jsx("option",{value:"",children:"every state"}),q8.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(T,{size:"sm",disabled:w!==null,onClick:()=>void k("retry"),children:w==="retry"?"Retrying…":"Retry all failed"}),n.jsx(T,{size:"sm",variant:"danger",disabled:w!==null,onClick:()=>void k("cancel"),children:w==="cancel"?"Cancelling…":"Cancel all failed"})]}):null]}),n.jsx(oe,{message:h??o}),n.jsx(lt,{flush:!0,children:!u||b.length===0?n.jsx(ge,{children:"No jobs match."}):n.jsxs(Fn,{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:Fo(S.id)})]}),n.jsxs("td",{children:[n.jsx(mc,{state:S.state}),S.suspendedReason?n.jsx("div",{className:"sub",children:rr(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?rr(S.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[Ze(S.updatedAt,e),n.jsx("div",{className:"sub",children:He(S.updatedAt)})]}),n.jsx("td",{children:n.jsxs(re,{align:"end",children:[["failed","cancelled","suspended"].includes(S.state)?n.jsx(T,{size:"sm",onClick:()=>N(A.retryJob(S.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(S.state)?n.jsx(T,{size:"sm",variant:"danger",onClick:()=>N(A.cancelJob(S.id)),children:"Cancel"}):null]})})]},S.id))})]})}),x?n.jsxs(re,{children:[n.jsxs("span",{className:"muted",children:[b.length," of ",j," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(T,{disabled:m.busy,onClick:()=>void g(),children:m.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(pt,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),n.jsx(le,{title:"Payload",children:n.jsx($t,{children:_n(a.payload)})}),n.jsx(le,{title:"Result",children:n.jsx($t,{children:_n(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null]})}const X8=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function J8({hash:e,timezone:t,navigate:s,agents:r}){var u,h;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(i){let f=i[1];try{f=decodeURIComponent(f)}catch{}return n.jsx(tW,{id:f,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=f=>m=>{m.preventDefault(),s(f)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(wh,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(rW,{})}),n.jsx(iW,{}),n.jsx(pc,{children:X8.map(f=>{const m=f.id==="conversations"?xt:`${xt}/${f.id}`;return n.jsx(tl,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?n.jsx(Z8,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(Q8,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(eW,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(V8,{timezone:t,embedded:!0}):null,l==="events"?n.jsx(Y8,{timezone:t,embedded:!0}):null]})}function Z8({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=ue(()=>A.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(oe,{message:a}),n.jsx(lt,{flush:!0,children:i?i.conversations.length===0?n.jsx(cn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(ft,{children:i.conversations.map(l=>n.jsx(ct,{href:el(l.id),onClick:()=>t(el(l.id)),lead:n.jsx(xn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?rr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${iD(l.usage)}`,side:n.jsx("span",{title:Ze(l.lastMessageAt??l.createdAt,e),children:He(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(ge,{children:"Loading…"})})]})}function eW({timezone:e,nameOf:t}){const{data:s,error:r}=ue(()=>A.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(oe,{message:r}),n.jsx(lt,{flush:!0,children:s?i.length===0?n.jsx(cn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(Fn,{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:Fo(a.id)})]}),n.jsx("td",{children:n.jsx(mc,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[Ze(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[Ze(a.createdAt,e),n.jsx("div",{className:"sub",children:He(a.createdAt)})]})]},a.id))})]}):n.jsx(ge,{children:"Loading…"})})]})}function tW({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null);d.useEffect(()=>{let u=!1;return A.conversation(e).then(h=>{u||a(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:xt,onClick:c(xt),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(T,{size:"sm",onClick:()=>s(xt),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Tt,{size:"sm",href:at(i.agentId,e),onClick:c(at(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(oe,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(yh,{children:[n.jsx(Xs,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(Xs,{label:"Runs",value:i.runs.length}),n.jsx(Xs,{label:"Tokens",value:`${Vt(i.usage.input)} / ${Vt(i.usage.output)}`,note:jp(i.usage)?`input / output, ${jp(i.usage)}`:"input / output"}),n.jsx(Xs,{label:"Started",value:Ze(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(lt,{title:"Runs",flush:!0,children:n.jsxs(Fn,{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:[Ze(u.startedAt,t)," ",u.resumed?n.jsx(ve,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:Ze(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 ",Fo(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[Vt(u.usage.input)," / ",Vt(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?Vt((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,n.jsx(le,{title:"Messages",children:n.jsx(se,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===ck?"approved action, result":u.role,", ",Ze(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===ck?u.blocks.map((h,f)=>n.jsx(nW,{block:h},f)):u.blocks.map((h,f)=>n.jsx(sW,{block:h},f))]})]},u.id))})})]}):n.jsx(ge,{children:"Loading…"})]})}const ck="approval:resume";function nW({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx($t,{children:e.type==="text"?e.text??"":_n(e)})]})}function sW({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($t,{children:_n(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($t,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx($t,{children:_n(e.ref)})]})}function rW(){const{data:e,reload:t}=ue(()=>A.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const i=()=>{r(!0),A.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(T,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function iW(){const{data:e}=ue(()=>A.overview(),[],1e4);if(!e)return null;const t=r=>e.jobs[r]??0,s=t("leased");return n.jsxs(yh,{children:[n.jsx(Xs,{label:"Jobs done",value:Vt(t("succeeded"))}),n.jsx(Xs,{label:"Failed",value:Vt(t("failed")),...t("failed")>0?{tone:"critical"}:{}}),n.jsx(Xs,{label:"Queued",value:Vt(t("pending")),note:`${s} running`}),n.jsx(Xs,{label:"Approvals",value:Vt(e.approvals.pending),note:"waiting for you"})]})}const aW=["replay-all","coalesce","latest-only","skip-after-deadline"];function AA({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ue(()=>A.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await h,a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(An,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(oe,{message:i??o}),!r||l.length===0?n.jsxs(cn,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(se,{children:l.map(h=>n.jsx(lW,{mission:h,timezone:e,onRun:u},h.id))})]})}function lW({mission:e,timezone:t,onRun:s}){const[r,i]=d.useState(!1);return n.jsxs(vs,{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(ve,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(ve,{children:"always delivers"}):null,e.enabled?null:n.jsx(ve,{tone:"warning",children:"disabled"}),e.pausedReason?n.jsx(ve,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",onClick:()=>s(A.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(T,{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?`${Ze(e.nextRun,t)} (${He(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"} ${He(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(re,{children:[n.jsx(ae,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(A.setMisfirePolicy(e.id,a.target.value)),children:aW.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(le,{title:"Prompt",children:n.jsx($t,{children:e.prompt})}),n.jsx(le,{title:"Recent occurrences",children:n.jsx(lt,{flush:!0,children:e.occurrences.length===0?n.jsx(ge,{children:"Never run."}):n.jsxs(Fn,{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:Ze(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(mc,{state:a.state})}),n.jsx("td",{className:"nowrap",children:Ze(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?rr(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function oW(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 TA({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=d.useState(!1),[l,o]=d.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:oW(r,t)}),n.jsx(T,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),A.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(T,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function RA({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=ue(()=>A.offers(),[],2e4),l=j=>!t||j.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),v=async(j,x)=>{h(null),m(j);try{const w=await A.takeOffer(j);g(w.jobId?`On it — ${x}. Started as job ${w.jobId}.`:`Taken — ${x}. No worker is running here, so nothing has started yet.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},b=async(j,x)=>{h(null),m(j);try{await A.dismissOffer(j),g(`Dismissed — ${x}. It will not come back.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return n.jsxs(An,{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(oe,{message:i??u}),p?n.jsx(K,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(re,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(TA,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx(cn,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):n.jsx(se,{children:o.map(j=>n.jsx(vs,{tone:"accent",title:j.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{mono:!0,children:j.agentId}),n.jsxs("span",{className:"muted",children:["expires ",He(j.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void b(j.id,j.label),children:"Not now"}),n.jsx(T,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void v(j.id,j.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?n.jsxs(Ct,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(lt,{flush:!0,children:n.jsx(ft,{children:c.map(j=>n.jsx(ct,{title:j.label,sub:`${j.agentId} — ${cD(j)}`,side:He(j.dismissedAt??j.lapsedAt??j.createdAt)},j.id))})}),n.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const cW="Add a teammate",uW="Each one keeps its own memory and tools, and can work on a schedule. Add the ones you want; Agent Father can make others.",dW="front-desk";function $A(e,t){return e.length>0&&e.every(s=>s.id===t||s.roles.includes(dW)||s.roles.includes(xh))}const hW={plugins:{label:"Plugins",route:_e("plugins")},mailbox:{label:"Add a mailbox",route:Ji("email","settings")},accounts:{label:"Accounts",route:_e("accounts")}},fW="Your starter team is complete. Agent Father can make others.";function wg({navigate:e,standing:t=!1}){var h;const s=ue(()=>A.teammates(),[]),[r,i]=d.useState(new Set),a=(((h=s.data)==null?void 0:h.teammates)??[]).filter(f=>!r.has(`${f.plugin}/${f.agent}`));if(a.length===0)return null;const l=f=>{i(m=>new Set(m).add(`${f.plugin}/${f.agent}`)),A.dismissAgentOffer(f.plugin,f.agent).then(s.reload,s.reload)},o=f=>m=>{m.preventDefault(),e(f)},c=t?a.filter(f=>f.state!=="added"):a,u=t?a.filter(f=>f.state==="added"):[];return n.jsx(le,{title:cW,children:c.length===0?n.jsx("p",{className:"teammates-lede","data-testid":"teammates-complete",children:fW}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"teammates-lede",children:uW}),n.jsx("div",{className:"teammates-grid","data-testid":"teammates",children:c.map(f=>n.jsx(mW,{row:f,navigate:e,onDismiss:()=>l(f)},`${f.plugin}/${f.agent}`))}),u.length>0?n.jsx("ul",{className:"teammates-added","data-testid":"teammates-added",children:u.map(f=>n.jsx("li",{children:n.jsxs("a",{className:"teammates-added-chip",href:St(f.agent),onClick:o(St(f.agent)),children:["Added · open @",f.handle]})},`${f.plugin}/${f.agent}`))}):null]})})}function mW({row:e,navigate:t,onDismiss:s}){const r=Hv(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?hW[e.fix]:null;return n.jsx("div",{className:"teammate","data-state":l,"data-testid":`teammate-${e.agent}`,children:n.jsxs(vs,{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(me,{name:"close"})}),foot:n.jsxs(n.Fragment,{children:[n.jsxs(re,{children:[l==="unavailable"?n.jsx("span",{className:"teammate-reason",children:e.reason}):null,n.jsx(Bt,{}),a?n.jsxs("a",{href:St(a.id),onClick:i(St(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(T,{variant:"accent",size:"sm",disabled:r.busy,onClick:r.accept,"aria-label":`Add ${e.name}`,children:"Add"})]}),n.jsx(oe,{message:r.failure})]}),children:[n.jsx("p",{className:"ui-card-meta",children:e.text}),n.jsx("p",{className:"teammate-needs",children:e.needs})]})})}const pW=["fact","observation","todo"];function IA({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=ue(()=>A.memory(r),[r],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),p=y=>{var k;return y==="shared"?"Everyone":((k=t.find(N=>N.id===y))==null?void 0:k.name)??y},g=async y=>{m(null);try{await y,l()}catch(k){m(k instanceof pe?k.message:String(k))}},v={nameOf:p,timezone:s,onChangePreference:y=>c({key:y.key,scope:y.scope}),onForgetPreference:y=>void g(A.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>h(y),onForgetNote:y=>void g(A.forgetNote(y.id))},b=r?p(r):"",j=r&&i?{preferences:i.preferences.filter(y=>y.scope===r),notes:i.notes.filter(y=>y.scope===r)}:null,x=r&&i?{preferences:i.preferences.filter(y=>y.scope==="shared"),notes:i.notes.filter(y=>y.scope==="shared")}:null,w=n.jsx(T,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(An,{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(oe,{message:a??f}),j&&x?n.jsxs(se,{gap:"lg",children:[n.jsx(le,{title:"Preferences",aside:`what you told ${b} alone`,actions:w,panel:!0,flush:!0,children:n.jsx(Qf,{preferences:j.preferences,empty:`Nothing stated to ${b} alone yet.`,...v})}),n.jsx(le,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(Xf,{notes:j.notes,empty:`${b} has kept no private notes yet.`,...v})}),n.jsx(Ct,{summary:`Shared with every agent, which ${b} also reads · ${x.preferences.length} preferences, ${x.notes.length} notes`,children:n.jsxs(se,{gap:"lg",children:[n.jsx(le,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(Qf,{preferences:x.preferences,empty:"No shared preferences.",...v})}),n.jsx(le,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(Xf,{notes:x.notes,empty:"No shared notes.",...v})})]})})]}):n.jsxs(se,{gap:"lg",children:[n.jsx(le,{title:"Preferences",aside:"what you said you want, one current value each",actions:w,panel:!0,flush:!0,children:i?n.jsx(Qf,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...v}):n.jsx(ge,{children:"Loading…"})}),n.jsx(le,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(Xf,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...v}):n.jsx(ge,{children:"Loading…"})})]}),o?n.jsx(gW,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await g((async()=>{await A.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await A.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(xW,{note:u,agents:t,onClose:()=>h(null),onSave:y=>g(A.updateNote(u.id,y)).then(()=>h(null))}):null]})}function Qf({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(ge,{children:t}):n.jsxs(Fn,{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(PA,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?He(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(re,{align:"end",children:[n.jsx(T,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function Xf({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(ge,{children:t}):n.jsxs(Fn,{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(ve,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(PA,{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?He(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",or(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(re,{align:"end",children:[n.jsx(T,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function PA({scope:e,name:t}){return n.jsx(ve,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function MA({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 gW({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(x=>x.key===s.key&&x.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((a==null?void 0:a.value)??""),[h,f]=d.useState(s.scope),[m,p]=d.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=t.find(x=>x.key===g&&x.scope===h),b=!a||g!==a.key||c.trim()!==a.value||h!==a.scope,j=g!==""&&c.trim()!==""&&b;return n.jsx(pt,{title:"A preference",onClose:r,children:n.jsxs(se,{children:[n.jsx(K,{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(ae,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:x=>o(x.target.value),placeholder:"reporting_currency"})}),n.jsx(ae,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:x=>u(x.target.value),placeholder:"EUR"})}),n.jsx(ae,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(MA,{value:h,agents:e,onChange:f})}),v&&v!==a?n.jsxs(K,{tone:"warning",children:['This replaces the value already stored for this key here, "',v.value,'" (revision ',v.revision,")."]}):null,a&&h!==a.scope?n.jsxs(K,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:r,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),i({key:g,value:c.trim(),scope:h}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function xW({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=d.useState(e.content),[l,o]=d.useState(e.scope),[c,u]=d.useState(e.kind),[h,f]=d.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(pt,{title:"A note",onClose:s,children:n.jsxs(se,{children:[n.jsx(ae,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:n.jsx("textarea",{rows:4,value:i,maxLength:2e3,autoFocus:!0,onChange:g=>a(g.target.value)})}),n.jsxs(Is,{children:[n.jsx(ae,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:pW.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(ae,{label:"Who sees it",children:n.jsx(MA,{value:l,agents:t,onChange:o})})]}),e.createdByAgent?n.jsxs("p",{className:"muted",children:["Written by ",((p=t.find(g=>g.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${He(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:s,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!m||i.trim()===""||h,onClick:()=>{f(!0);const g={};i.trim()!==e.content&&(g.content=i.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>f(!1))},children:"Save"})]})]})})}function vW({agentId:e,agentName:t}){const{data:s,error:r,reload:i}=ue(()=>A.agentSkills(e),[e],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),f=async g=>{l(null),c(null),h(g.name);try{const v=await A.removeSkill(e,g.name);c(`Removed ${v.name}. Its versions are kept, and ${t} will not propose it again for 90 days.`),i()}catch(v){l(v instanceof pe?v.message:String(v))}finally{h(null)}};if(!s)return r?n.jsx(oe,{message:r}):n.jsx(ge,{children:"Loading…"});const m=s.skills.filter(g=>g.learned!==null),p=s.skills.filter(g=>g.learned===null);return n.jsxs(se,{divided:!0,children:[n.jsx(oe,{message:r??a}),o?n.jsx(K,{tone:"good",role:"status",children:o}):null,n.jsx(le,{title:"Learned",aside:n.jsxs("span",{className:"muted",children:["what ",t," proposed and you kept"]}),children:m.length===0?n.jsx(cn,{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(lt,{flush:!0,children:n.jsxs(Fn,{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(g=>n.jsx(wW,{skill:g,busy:u===g.name,onRemove:()=>void f(g)},g.name))})]})})}),n.jsx(le,{title:"From files and plugins",aside:n.jsx("span",{className:"muted",children:"read-only here"}),children:p.length===0?n.jsx(ge,{children:"No other skills."}):n.jsx(lt,{flush:!0,children:n.jsxs(Fn,{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(g=>n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Ct,{summary:n.jsx("span",{className:"mono",children:g.name}),children:[n.jsx($t,{children:g.body}),n.jsx("p",{className:"muted mono skill-file",children:g.file})]})}),n.jsx("td",{children:g.description}),n.jsx("td",{children:n.jsxs(se,{gap:"sm",children:[n.jsx(ve,{children:g.scope==="shared"?"shared":`${t} only`}),n.jsx("span",{className:"muted",children:jW(g)})]})})]},`${g.scope}:${g.name}`))})]})})})]})}function jW(e){return e.provenance==="imported"?e.source?`from ${e.source}`:"imported":e.provenance==="agent"?"written by an agent":"yours"}function wW({skill:e,busy:t,onRemove:s}){const r=e.learned;return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Ct,{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($t,{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(se,{gap:"sm",children:[n.jsxs("span",{children:["v",r.version,r.edited?" · your correction":""]}),r.untrusted?n.jsx(ve,{tone:"warning",children:"untrusted text in view"}):null]})}),n.jsx("td",{children:n.jsxs(se,{gap:"sm",children:[r.conversation?n.jsx("a",{href:el(r.conversation),children:r.turn?`conversation, turn ${r.turn}`:"conversation"}):n.jsx("span",{className:"muted",children:"no conversation"}),n.jsx("a",{href:_e("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?He(r.keptAt,Date.now()):""}),n.jsx("td",{className:"num",children:n.jsx(re,{align:"end",children:n.jsx(T,{size:"sm",variant:"ghost",disabled:t,onClick:s,children:"Remove"})})})]})}function DA({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ue(()=>A.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await A.cancelReminder(h),a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(An,{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(oe,{message:i??o}),n.jsx(lt,{flush:!0,children:r?l.length===0?n.jsx(cn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(Fn,{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:[Ze(h.dueAt,e),n.jsx("div",{className:"sub",children:He(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx(Ct,{summary:"context",children:n.jsx($t,{children:_n(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(mc,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(T,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(ge,{children:"Loading…"})})]})}const yW=/(flux|klein|schnell|qwen[-_]?image|image)/i;function OA(e){return e.kind==="image"||e.kind===void 0&&yW.test(e.id)}function bW(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!OA(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function yg(e){return bW(e)[0]}function ij(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function kW(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 LA(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 _A="an image model; pick it in the Image plugin, not here";function aj({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),p=d.useRef(0),g=async x=>{if(!e)return;const w=++p.current;c(!0),h("");try{const y=await A.accountModels(e,x);w===p.current&&l(y)}catch(y){w===p.current&&h(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(d.useEffect(()=>(l(null),m(!1),h(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(ae,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const v=(a==null?void 0:a.models)??[],b=!!s&&!v.some(x=>x.id===s),j=[a&&!v.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(ae,{label:t,children:n.jsxs("select",{value:f?"__buddi_custom__":s,disabled:i,onChange:x=>{x.target.value==="__buddi_custom__"?m(!0):(m(!1),r(x.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),v.map(x=>n.jsxs("option",{value:x.id,children:[x.name===x.id?x.id:`${x.name} — ${x.id}`,x.isDefault?" (provider default)":"",x.image?` — ${_A}`:""]},x.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(T,{disabled:i||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),f&&n.jsx(ae,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function NW(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 SW(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const CW="This agent will not remember anything between conversations.";function EW({view:e,chosen:t,onChange:s,disabled:r}){var k;const[i,a]=d.useState(""),[l,o]=d.useState(null),[c,u]=d.useState(()=>new Set),h=N=>u(S=>{const C=new Set(S);return C.has(N)?C.delete(N):C.add(N),C}),f=N=>{a(N),u(new Set)},m=d.useId(),p=new Set(t),g=new Set(e.groups.flatMap(N=>N.tools.filter(S=>S.core).map(S=>S.name))),v=(N,S)=>{const C=S.filter($=>p.has($));if(C.length!==0){if(C.some($=>g.has($))){o({plugin:N,names:C});return}s(t.filter($=>!C.includes($)))}},b=N=>{s([...t,...N.filter(S=>!p.has(S))])},j=i.trim().toLowerCase(),x=(N,S)=>j===""||N.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(N=>({group:N,tools:N.tools.filter(S=>x(S.name,S.description))})).filter(N=>N.tools.length>0),y=(((k=e.suggested)==null?void 0:k.tools)??[]).filter(N=>!p.has(N.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(N=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:N.name}),n.jsx("span",{className:"ui-list-sub",children:N.description})]}),n.jsx(T,{size:"sm",disabled:r,"aria-label":`Add ${N.name}`,onClick:()=>b([N.name]),children:"Add"})]},N.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:N=>f(N.target.value)})]}),w.length===0?n.jsxs(ge,{children:["No installed tool matches “",i.trim(),"”."]}):null,w.map(({group:N,tools:S})=>{const C=N.tools.filter(E=>E.grantable).map(E=>E.name),$=N.tools.filter(E=>p.has(E.name)).length,R=!!N.glob&&$===N.tools.length,I=`${m}-${N.plugin}`,F=`${m}-${N.plugin}-list`,_=j!==""?!c.has(N.plugin):c.has(N.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":_?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":_,"aria-controls":F,onClick:()=>h(N.plugin),children:[n.jsx(AW,{}),n.jsx("span",{id:I,className:"tool-picker-plugin",children:N.plugin}),n.jsx("span",{className:"muted",children:R?`all ${N.tools.length}`:`${$} of ${N.tools.length} granted`})]}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":`All ${N.plugin} tools`,disabled:r||C.every(E=>p.has(E)),onClick:()=>b(C),children:"all"}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":`No ${N.plugin} tools`,disabled:r||!C.some(E=>p.has(E)),onClick:()=>v(N.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===N.plugin?n.jsx(K,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:CW}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(T,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(T,{size:"sm",variant:"danger",onClick:()=>{s(t.filter(E=>!l.names.includes(E))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:F,className:"ui-list tool-picker-list",hidden:!_,children:S.map(E=>{const M=`${m}-${E.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:M,checked:p.has(E.name),disabled:r||!E.grantable,onChange:P=>P.target.checked?b([E.name]):v(N.plugin,[E.name])}),n.jsxs("label",{htmlFor:M,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(ve,{tone:"accent",children:"core"}):null,E.gated?n.jsx(ve,{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)})})]},N.plugin)})]})}function AW(){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 as={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."},Yr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function FA(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(as.json)}if(!Yr(t))throw new Error(as.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!Yr(u))throw new Error(as.empty);const h=Object.keys(u);if(h.length===0)throw new Error(as.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const f=u[s];if(!Yr(f))throw new Error(as.url);r=f}if("command"in r)throw new Error(as.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(as.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(as.url);const a=Yr(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,h]=l,f=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?h.trim().slice(f[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const fo={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 zA(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const UA=/^[A-Za-z_][A-Za-z0-9_]*$/;function TW(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function BA(e,t){const s=TW(t);return{name:e,value:s?"":t,secret:zA(e),placeholder:s}}function WA(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!==`
112
- `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
113
- `||o==="\r"&&e[a+1]===`
114
- `){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(fo.quote);return r&&t.push(s),t}function RW(e){const t=WA(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=h=>{const f=h.indexOf("="),m=f>0?h.slice(0,f).trim():"";if(!UA.test(m))throw new Error(fo.env);r.push(BA(m,h.slice(f+1)))},u=[];for(;s<t.length;s+=1){const h=t[s];if(h==="--"){o=t.slice(s+1);break}const[f,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(fo.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(as.url);const f={};for(const m of i){const p=m.indexOf(":");p>0&&(f[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:FA(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(fo.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function $W(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return RW(t);let s;try{s=JSON.parse(t)}catch{throw new Error(as.json)}if(!Yr(s))throw new Error(as.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!Yr(c))throw new Error(as.empty);const u=Object.keys(c);u.length===1&&Yr(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:FA(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(fo.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=Yr(i.env)?Object.entries(i.env).filter(([c])=>UA.test(c)).map(([c,u])=>BA(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function lj({code:e,label:t="Your code",large:s=!1}){const[r,i]=d.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(re,{valign:"end",children:[n.jsx(ae,{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(T,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function HA(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 IW="It can delete or destroy something, so it asks you every time and is never remembered.";function PW(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 KA="buddi-connections",MW="/connections/callback",DW="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.",VA="Services and programs your team can use, and the tools each one brings.",oj=(e,t,s)=>`${e} ${e===1?t:s}`;function uk(e,t){return e.transport==="stdio"?void 0:t.find(s=>uj(s.url,e.url))}function cj({connection:e,card:t,size:s}){return t?n.jsx(hi,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(hi,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function GA({connection:e}){const t=HA(e);return n.jsx(ve,{tone:t.tone,dot:t.dot,children:t.label})}const Jf=e=>t=>{t.stopPropagation(),e()},Lu=[{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"}],YA="buddi.connections.add-way";function OW(){try{const e=window.localStorage.getItem(YA);return Lu.some(t=>t.value===e)?e:"address"}catch{return"address"}}function LW({embedded:e,timezone:t,connection:s}={}){const r=ue(()=>A.connections(),[],3e4),[i,a]=d.useState(null),[l,o]=d.useState(s??null);d.useEffect(()=>{s&&o(s)},[s]);const[c,u]=d.useState(null),[h,f]=d.useState(null),m=r.data,p=N=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===N))==null?void 0:S.name)??N},g=t??Intl.DateTimeFormat().resolvedOptions().timeZone,v=(m==null?void 0:m.connections)??[],b=(m==null?void 0:m.catalog)??[],j=b.filter(N=>!v.some(S=>S.transport!=="stdio"&&uj(N.url,S.url))),x=l?v.find(N=>N.id===l):void 0,w=c?v.find(N=>N.id===c):void 0,y=h?v.find(N=>N.id===h):void 0,k=N=>{o(null),a(N)};return n.jsxs(An,{embedded:e,title:"Connections",lede:VA,children:[n.jsxs(se,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(me,{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:_e("plugins"),children:"Plugins"})]})]}),!m&&!r.error?n.jsx(ge,{children:"Reading your connections…"}):null,n.jsx(oe,{message:r.error}),m&&!m.vault?n.jsx(K,{tone:"warning",children:"This installation has no vault, so a service that asks for a sign-in cannot be connected. Turn the vault on first."}):null,m?n.jsx(lt,{flush:!0,title:"Your connections",tool:v.length>0?oj(v.length,"connection","connections"):void 0,children:v.length===0?n.jsx(ge,{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(ft,{children:v.map(N=>n.jsx(_W,{connection:N,card:uk(N,b),twin:N.slug!==null&&v.some(S=>S.id!==N.id&&S.name===N.name),onOpen:()=>o(N.id),onFlow:k},N.id))})})}):null,m&&j.length>0?n.jsx(lt,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:j.map(N=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(cj,{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(T,{size:"sm",onClick:()=>k({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,m?n.jsx(WW,{onFlow:N=>k({step:N})}):null]}),x?n.jsx(zW,{connection:x,card:uk(x,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:k,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,y&&m?n.jsx(UW,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?n.jsx(BW,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,i&&m?n.jsx(HW,{start:i,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{a(null),r.reload()}}):null]})}function _W({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":oj(e.toolCount,"tool","tools");return n.jsx(ct,{onClick:r,label:`${l}: details`,lead:n.jsx(cj,{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(T,{size:"sm",variant:"accent",onClick:Jf(()=>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(T,{size:"sm",onClick:Jf(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(T,{size:"sm",onClick:Jf(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(GA,{connection:e}),n.jsx(me,{name:"chevron-right",size:14})]})})}const FW={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 zW({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>a({step:"consent",connection:e,keepGrants:!0}),f=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(pt,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(cj,{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(GA,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(re,{children:[n.jsx(T,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(Bt,{}),u?n.jsx(T,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(T,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(T,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(T,{variant:e.state==="needs-review"?"accent":void 0,onClick:f,children:"Review again"})]}),children:[c?n.jsx(K,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(K,{tone:"warning",action:e.authKind!=="none"?n.jsx(T,{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(K,{tone:"warning",action:n.jsx(T,{size:"sm",variant:"accent",onClick:f,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?n.jsx(K,{tone:"critical",children:u?`It stopped answering at ${Ze(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${Ze(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(K,{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(K,{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(nn,{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:FW[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${oj(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${He(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(T,{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(le,{title:"What the program last said",children:n.jsx($t,{label:"Its last lines on stderr",children:e.stderr.join(`
115
- `)})}):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(T,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function UW({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=d.useState(()=>new Set(e.agents)),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=(p,g)=>a(v=>{const b=new Set(v);return g?b.add(p):b.delete(p),b}),f=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await A.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Ps(p))}finally{o(!1)}};return n.jsxs(xs,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:g=>h(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(oe,{message:c})]})}function BW({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await A.disconnect(e.id),r()}catch(h){o(Ps(h))}finally{a(!1)}};return n.jsxs(xs,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(T,{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(oe,{message:l})]})}function WW({onFlow:e}){const[t,s]=d.useState(OW),r=Lu.find(a=>a.value===t)??Lu[0],i=a=>{s(a);try{window.localStorage.setItem(YA,a)}catch{}};return n.jsx(lt,{title:"Add your own",actions:n.jsx(sn,{label:"How to add it",options:Lu.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(T,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function HW({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=d.useState(e.step),[c,u]=d.useState(e.connection),[h,f]=d.useState("unknown"),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(y=>b!==void 0&&uj(y.url,b)),x=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${x}`:l==="review"?`What ${x} brings`:"Who gets these tools";return n.jsxs(pt,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(KW,{onRead:y=>{y.kind==="program"?(v(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(VW,{card:j,pasted:m,onDone:(y,k)=>{u(y),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?n.jsx(eH,{connection:c,pasted:g,tokens:r,onDone:y=>{var k;v(null),u(y),e.keepGrants&&!((k=y.program)!=null&&k.changedSinceReview)&&y.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(qW,{connection:c,signIn:h,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:y=>{p(null),u(y),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(tH,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(nH,{connection:c,agents:t,onDone:i}):null]})}function uj(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Ps(e){return e instanceof Error?e.message:String(e)}function KW({onRead:e}){const[t,s]=d.useState(""),[r,i]=d.useState(null),a=()=>{try{const l=$W(t);s(""),i(null),e(l)}catch(l){i(Ps(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(ae,{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(oe,{message:r}),n.jsx(re,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function VW({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=d.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{l(!0),c(null);try{const g=await A.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Ps(g))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",f=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return n.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?n.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):n.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),n.jsx(ae,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>i(g.target.value)})}),e&&!e.verified?n.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?n.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(oe,{message:o}),n.jsx(re,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const GW={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function YW(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 qW({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var W,O;const[c,u]=d.useState(t),h=(W=s==null?void 0:s.auth)!=null&&W.device?s.auth.recommended==="device"?"first":"offered":"none",f=YW(c,a,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((O=s==null?void 0:s.auth)==null?void 0:O.recommended)==="token"),[p,g]=d.useState(()=>m&&f.includes("token")?"token":f[0]),v=f.includes(p)?p:f[0],[b,j]=d.useState(DW),[x,w]=d.useState(""),[y,k]=d.useState(null),[N,S]=d.useState(!1),[C,$]=d.useState(null),[R,I]=d.useState(!1),[F,_]=d.useState(null),E=`${location.origin}${MW}`,M=d.useRef(o);M.current=o,d.useEffect(()=>{if(!R)return;let V=!1;const X=async()=>{if(!V){V=!0;try{M.current(await A.connection(e.id))}catch(Q){$(Ps(Q))}}},G=typeof BroadcastChannel=="function"?new BroadcastChannel(KA):null;G&&(G.onmessage=Q=>{var ce;((ce=Q.data)==null?void 0:ce.id)===e.id&&X()});let Z;const z=Date.now(),q=async()=>{if(!V){try{const Q=await A.connection(e.id);if((!e.signedIn||e.authKind==="token")&&Q.signedIn&&Q.authKind==="oauth"){X();return}}catch{}if(Date.now()-z>10*6e4){I(!1),$("The sign-in did not come back within ten minutes. Start it again.");return}Z=window.setTimeout(()=>void q(),l)}};return Z=window.setTimeout(()=>void q(),l),()=>{V=!0,G==null||G.close(),window.clearTimeout(Z)}},[R,e,l]);const P=async V=>{var X;S(!0),$(null);try{const{authorizeUrl:G}=await A.connectionConsent(e.id,V);k(G)}catch(G){G instanceof pe&&((X=G.detail)==null?void 0:X.code)==="client-id"?(j(G.message),u("manual"),g("client")):$(Ps(G))}finally{S(!1)}};d.useEffect(()=>{v!=="oauth"||y!==null||P()},[v]);const U=V=>{const X=window.open(V,"_blank");X?(X.opener=null,_(null)):_(V),I(!0)},L=V=>{g(V),k(null),$(null),I(!1),_(null)};return n.jsxs("div",{className:"ui-stack",children:[f.length>1?n.jsx(sn,{label:"How to sign in",options:f.map(V=>({value:V,label:GW[V]})),value:v,onChange:L}):null,v==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),N?n.jsxs(ge,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,v==="client"?n.jsxs(n.Fragment,{children:[n.jsx(K,{tone:"warning",children:b}),n.jsx(ae,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:x,onChange:V=>{w(V.target.value),k(null),I(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:E})]})]}):null,v==="token"?n.jsx(JW,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,v==="device"?n.jsx(XW,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(v==="oauth"||v==="client")&&R?n.jsxs(K,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(v==="oauth"||v==="client")&&F?n.jsx("p",{children:n.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,v==="oauth"||v==="client"?n.jsx(oe,{message:C}):null,v==="oauth"?n.jsx(re,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>{y&&U(y)},disabled:y===null,children:R?"Open it again":`Sign in to ${e.name}`})}):null,v==="client"?n.jsx(re,{align:"end",children:y===null?n.jsx(T,{variant:"accent",onClick:()=>void P(x.trim()),disabled:N||x.trim()==="",children:N?"Checking…":"Continue"}):n.jsx(T,{variant:"accent",onClick:()=>U(y),children:R?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function QW(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function XW({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(0),[h,f]=d.useState(null),m=d.useRef(r);m.current=r,d.useEffect(()=>{let v=!1,b;a(null),o(null),f(null);const j=async()=>{var x,w;if(!v){try{const y=await A.connection(e.id);if(v)return;if(((x=y.device)==null?void 0:x.state)==="done"){m.current(y);return}if(((w=y.device)==null?void 0:w.state)==="failed"){o(y.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void j(),s)}};return(async()=>{try{const x=await A.connectionDevice(e.id);if(v)return;a({userCode:x.userCode,verificationUri:x.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(x){v||o(Ps(x))}})(),()=>{v=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=v=>{const b=window.open(v,"_blank");b?(b.opener=null,f(null)):f(v)},g=i?QW(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(ge,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(lj,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(K,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),h?n.jsx("p",{children:n.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(re,{align:"end",children:n.jsxs(T,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(oe,{message:l}),n.jsx(re,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function JW({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var j,x;const[a,l]=d.useState((s==null?void 0:s.value)??""),[o,c]=d.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=d.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=async()=>{m(!0),g(null);try{const w=await A.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){g(Ps(w))}finally{m(!1)}},b=(j=t==null?void 0:t.auth)==null?void 0:j.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),v()},children:[n.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(K,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(ae,{label:"Token",hint:(x=t==null?void 0:t.auth)==null?void 0:x.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:w=>l(w.target.value)})}),n.jsxs(Is,{columns:2,dense:!0,children:[n.jsx(ae,{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(ae,{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(oe,{message:p}),n.jsx(re,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:f||a.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function ZW(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function eH({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=d.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=d.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,h]=d.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[f,m]=d.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(E=>({key:l(),value:E}))),[p,g]=d.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}))),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=/\s/.test(u.trim())?WA(u.trim()):[u.trim()],y=w[0]??"",k=[...w.slice(1),...f.map(E=>E.value)],N=[y,...k].filter((E,M)=>M>0||E!==""),S=()=>{w.length<2||(h(y),m(E=>[...w.slice(1).map(M=>({key:l(),value:M})),...E]))},C=N.map(ZW).join(" "),$=p.filter(E=>E.secret&&E.value===""&&!E.kept).map(E=>E.name||"a variable"),R=((t==null?void 0:t.env)??[]).filter(E=>E.placeholder).map(E=>E.name),I=(E,M)=>m(P=>P.map(U=>U.key===E?{...U,value:M}:U)),F=(E,M)=>g(P=>P.map(U=>U.key===E?{...U,...M}:U)),_=async()=>{b(!0),x(null);const E={name:o.trim(),command:y,args:k,env:p.filter(M=>M.name.trim()!=="").map(M=>({name:M.name.trim(),value:M.value,secret:M.secret}))};try{r(e?await A.updateProgram(e.id,E):(await A.addProgram(E)).connection),g(M=>M.map(P=>P.secret?{...P,value:""}:P))}catch(M){x(Ps(M))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:E=>{E.preventDefault(),_()},children:[n.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),n.jsxs(Is,{columns:2,children:[n.jsx(ae,{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(ae,{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(ae,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map((E,M)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${M+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:E.value,onChange:P=>I(E.key,P.target.value)}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>m(P=>P.filter(U=>U.key!==E.key)),"aria-label":`Remove argument ${M+1}`,children:"Remove"})]},E.key)),n.jsx(re,{children:n.jsx(T,{size:"sm",onClick:()=>m(E=>[...E,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(ae,{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,M)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${M+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:E.name,onChange:P=>{const U=P.target.value;F(E.key,E.value===""&&!E.kept?{name:U,secret:zA(U)}:{name:U})}}),n.jsx("input",{"aria-label":`Variable ${M+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:P=>F(E.key,{value:P.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:E.secret,onChange:P=>F(E.key,{secret:P.target.checked,kept:P.target.checked&&E.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>g(P=>P.filter(U=>U.key!==E.key)),"aria-label":`Remove variable ${M+1}`,children:"Remove"})]},E.key)),n.jsx(re,{children:n.jsx(T,{size:"sm",onClick:()=>g(E=>[...E,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),R.length>0?n.jsxs(K,{tone:"accent",children:["Your config had a placeholder for ",R.join(", "),". Type the value itself."]}):null,!s&&p.some(E=>E.secret)?n.jsx(K,{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($t,{label:"The command line",children:C||"…"})]}),n.jsx(oe,{message:j}),n.jsx(re,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:v||o.trim()===""||u.trim()===""||$.length>0,title:$.length>0?`Give ${$.join(", ")} a value.`:void 0,children:v?"Saving…":e?"Save":"Continue"})})]})}function tH({connection:e,onKept:t}){const s=ue(()=>A.connectionReview(e.id),[e.id]),[r,i]=d.useState(null),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{t(await A.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(g){g instanceof pe&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Ps(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(oe,{message:s.error}):e.transport==="stdio"?n.jsxs(ge,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(ge,{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(K,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(se,{gap:"sm",children:[n.jsx($t,{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(K,{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(K,{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(ae,{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(ge,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=PW(p),v=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return n.jsx("div",{className:"ui-list-row connections-tool",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("span",{className:"mono",children:v}),p.problem?n.jsx(ve,{tone:"muted",children:"Cannot be used"}):n.jsx(ve,{tone:g.tone,children:g.label}),p.change==="added"?n.jsx(Ba,{children:"New"}):p.change==="changed"?n.jsx(Ba,{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?IW:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Tools tab."}):null,p.problem?n.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),n.jsx(oe,{message:o}),n.jsx(re,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>void f(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function nH({connection:e,agents:t,onDone:s}){var b;const r=t.find(j=>j.frontDesk)??t[0],[i,a]=d.useState(()=>new Set(r?[r.id]:[])),o=(((b=ue(()=>A.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=(j,x)=>{a(w=>{const y=new Set(w);return x?y.add(j):y.delete(j),y})},v=async()=>{f(!0),p(null);try{const j=await A.grantConnection(e.id,[...i]);if(j.failed.length>0){p(j.failed.map(x=>`${x.agent}: ${x.message}`).join(" "));return}for(const x of j.granted)for(const w of c)await A.setRememberedApproval(x,w,!0);s()}catch(j){p(Ps(j))}finally{f(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(j=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(j.id),onChange:x=>g(j.id,x.target.checked)}),n.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),n.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?n.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[n.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(j=>n.jsxs(se,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:x=>u(w=>{const y=new Set(w);return x.target.checked?y.add(j.tool):y.delete(j.tool),y})}),n.jsx("span",{className:"mono",children:j.tool})]}),j.why?n.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,n.jsx(oe,{message:m}),n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:s,disabled:h,children:"Not now"}),n.jsx(T,{variant:"accent",onClick:()=>void v(),disabled:h||i.size===0,children:"Give them"})]})]})}const sH=(e,t,s)=>`${e} ${e===1?t:s}`;function rH(e){return e.state==="pending-review"||!e.slug?"Not finished: its tools are not reviewed yet.":e.state==="needs-review"?"Its tools changed and need your review.":e.state==="needs-reconnect"?"Its sign-in ended; sign in again first.":null}function iH({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=d.useState({}),o=ue(()=>A.connections().then(w=>(l({}),w)),[r]),[c,u]=d.useState(null),[h,f]=d.useState(null),m=_e("connections"),p=async(w,y)=>{u(w.id),f(null);try{const k=await A.setConnectionHolder(w.id,e,y);l(N=>({...N,[w.id]:k.held})),i==null||i()}catch(k){f(k instanceof Error?k.message:String(k))}finally{u(null)}},g=o.data,v=(g==null?void 0:g.connections)??[],b=w=>a[w.id]??w.agents.includes(e),j=g?g.agents.some(w=>w.id===e):!0,x=v.filter(b).length;return n.jsxs(le,{title:"Connections",aside:g&&v.length>0?`holds ${x} of ${v.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(oe,{message:o.error??h}),g?v.length===0?n.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",n.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?n.jsxs(n.Fragment,{children:[s?n.jsx(K,{tone:"warning",children:"This agent ships with buddi, so its connections are read-only here. Ask Agent Father to make it yours, then it can change."}):null,n.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${t} holds`,children:v.map(w=>{const y=b(w),k=rH(w),N=w.transport==="stdio"?"on this computer":w.host,S=w.slug?sH(w.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${w.id}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",role:"switch",id:C,checked:y,"aria-checked":y,disabled:s||c!==null||k!==null&&!y,onChange:$=>void p(w,$.target.checked)}),n.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[w.name,k?n.jsxs(n.Fragment,{children:[" ",n.jsx(ve,{tone:"warning",children:HA(w).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${N} · ${S}`}),k?n.jsxs("span",{className:"ui-list-sub",children:[k," ",n.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},w.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[t," makes and changes agents, so it holds no connections."]}):o.error?null:n.jsx(ge,{children:"Loading the connections…"})]})}const aH=(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 qA(e){const t=await fetch(aa(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 lH({face:e,onPick:t,label:s=D.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,mF.map(o=>{const c={kind:"mascot",role:o},u=aH(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":D.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:aa(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:gF.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 oH=["mirror","en","fr"],cH=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],Zf=10,em=500,QA=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],dk=e=>{var t;return e==="access"?"tools":((t=QA.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function uH({agentId:e,section:t,navigate:s}){var v,b,j;const{data:r,error:i,reload:a}=ue(()=>A.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(dk(t));d.useEffect(()=>f(dk(t)),[t]);const m=x=>{f(x),s==null||s(St(e,"setup",x))},p=async x=>{o(null),u(null);try{const w=await x;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),a()}catch(w){o(w instanceof Error?w.message:String(w))}},g=r==null?void 0:r.agents.find(x=>x.id===e);return n.jsxs(se,{gap:"lg",children:[n.jsx(pc,{level:"secondary",label:"Setup",children:QA.map(x=>n.jsx(tl,{href:St(e,"setup",x.id),active:h===x.id,onClick:w=>{w.preventDefault(),m(x.id)},children:x.label},x.id))}),n.jsx(oe,{message:i??l}),c?n.jsx(K,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(dH,{agent:g,all:r.agents,engine:r.engines.find(x=>x.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:a},`${g.id}:${(v=r.engines.find(x=>x.id===g.id))==null?void 0:v.model}:${(j=(b=r.providerAccounts)==null?void 0:b.bindings.find(x=>x.agentId===g.id))==null?void 0:j.accountId}`):n.jsx(ge,{children:"This agent is not installed as a file."}):n.jsx(ge,{children:"Loading…"})]})}function dH({agent:e,all:t,engine:s,providers:r,accounts:i,shown:a,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(N=>N.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,v]=d.useState(null),b=N=>{o(A.setAgentEngine(e.id,N))},j=N=>{const S=r.find(C=>C.kind===N);b({provider:N,model:(S==null?void 0:S.defaultModel)??f})},x=(h==null?void 0:h.models.map(N=>N.id))??[],w=x.includes(f)?x:[f,...x],y=s?s.available:!0,k=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(se,{gap:"lg",children:[y?null:n.jsxs(K,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:St(e.id,"setup","brain"),onClick:N=>{N.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(hH,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(se,{gap:"lg",children:[y?null:n.jsxs(K,{tone:"warning",children:["This agent cannot run right now: ",k,"."]}),n.jsx(le,{panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsxs(le,{title:"Runs on",children:[i?n.jsx(jH,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(Is,{children:[n.jsx(ae,{label:"Provider",children:n.jsx("select",{value:u,onChange:N=>j(N.target.value),children:r.map(N=>n.jsxs("option",{value:N.kind,children:[N.kind,N.usable?"":" (no credential)"]},N.kind))})}),n.jsxs(ae,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:N=>{N.target.value.trim()!==""&&N.target.value.trim()!==f&&b({model:N.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:w.map(N=>n.jsx("option",{value:N},N))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(le,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(Is,{children:[n.jsx(ae,{label:"Steps per reply",hint:`${s!=null&&s.maxTurnsIsDefault?`Default ${s.defaultMaxTurns??40}. `:""}Each tool call is a step; a reply that uses them all stops and offers Continue.`,after:g?n.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:n.jsx("input",{type:"number",min:Zf,max:em,value:m,onChange:N=>{p(N.target.value),v(null)},onBlur:()=>{const N=Number(m);if(!Number.isInteger(N)||N<Zf||N>em){v(`Between ${Zf} and ${em}.`);return}N!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:N})}})}),n.jsx(ae,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:N=>b({language:N.target.value}),children:oH.map(N=>n.jsx("option",{value:N,children:N},N))})}),s?n.jsx(ae,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:n.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:N=>b({idleRollover:N.target.value==="3h"?null:N.target.value}),children:cH.map(N=>n.jsx("option",{value:N.value,children:N.label},N.value))})}):null,dC(hC(s??{id:e.id,provider:u},i))?n.jsx(ae,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:N=>b({thinking:N.target.value==="default"?null:N.target.value}),children:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(ae,{label:"Thinking",hint:dD,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(Ct,{summary:"Built-in context",boxed:!0,children:n.jsx("p",{className:"ui-card-meta",children:"Every agent receives current time, owner timezone and server-host information. system.time and system.info are always available, without grants or approval. Host and browser access still require their own permissions."})})]})}),n.jsx("div",{hidden:a!=="tools",children:n.jsxs(se,{gap:"lg",children:[n.jsx(fH,{agent:e,all:t,onSaved:c}),n.jsx(iH,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),n.jsx("div",{hidden:a!=="team",children:n.jsx(se,{gap:"lg",children:n.jsx(kH,{agent:e,all:t,onSaved:c})})})]})}function XA({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(T,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const JA=n.jsx(K,{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 hH({agent:e,onSaved:t}){var _;const[s,r]=d.useState(e.name),[i,a]=d.useState(e.handle),[l,o]=d.useState(e.description),[c,u]=d.useState(e.avatar??""),[h,f]=d.useState(!1),m=ue(()=>A.agentFile(e.id),[e.id]),[p,g]=d.useState(null),v=((_=m.data)==null?void 0:_.persona.trim())??"",b=p??v,j=m.data!==void 0&&p!==null&&p.trim()!==v,[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,$=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),R=bg($?{...e,avatar:c.trim()}:e),I={...R?{avatar:R}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!$&&e.picture?{picture:e.picture}:{}},F=async()=>{w(!0),k(null),S(null);try{const E=await A.updateAgentFile(e.id,{name:s.trim(),handle:i.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...j&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await A.removeAgentPicture(e.id),window.dispatchEvent(new Event(Uo))),g(null),m.reload(),S(E.message),t()}catch(E){k(E instanceof Error?E.message:String(E))}finally{w(!1)}};return n.jsx(le,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(XA,{dirty:C,busy:x,failure:y,label:"Save who it is",onSave:()=>void F()}),children:n.jsxs(se,{children:[e.isExample?JA:null,N?n.jsx(K,{tone:"good",role:"status",children:N}):null,n.jsxs(Is,{children:[n.jsx(ae,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:x||e.isExample,onChange:E=>r(E.target.value)})}),n.jsx(ae,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:x||e.isExample,onChange:E=>a(E.target.value)})})]}),n.jsxs(re,{children:[n.jsx(Os,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),n.jsx(T,{"aria-expanded":h,onClick:()=>f(E=>!E),children:h?"Hide faces":"Change face"})]}),h?n.jsx(xH,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:x}):null,n.jsx(ae,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:x||e.isExample,onChange:E=>o(E.target.value)})}),n.jsx(ae,{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(oe,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
116
- `).length+1),disabled:x||e.isExample,onChange:E=>g(E.target.value)}):n.jsx(ge,{children:"Reading its file…"})})]})})}function fH({agent:e,all:t,onSaved:s}){var $;const r=ue(()=>A.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(Gy))),[c,u]=d.useState((e.roles??[]).filter(R=>!Gy(R)).join(", ")),[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(R,I)=>R.split(I).map(F=>F.trim()).filter(F=>F!==""),j=(($=r.data)==null?void 0:$.granted)??e.tools,x=i??j,w=r.data!==void 0&&!SW(x,j),y=Yy(l,b(c,/[\n,]/)),k=R=>o(I=>{const F=new Set(I);return F.has(R)?F.delete(R):F.add(R),F}),S=w||!((R,I)=>R.join(",")===I.join(","))(y,Yy(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),v(null);try{const R=await A.updateAgentFile(e.id,{...w&&r.data?{tools:NW(r.data.groups,x)}:{},roles:y});v(R.message),a(null),r.reload(),s()}catch(R){p(R instanceof Error?R.message:String(R))}finally{f(!1)}};return n.jsx(le,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(XA,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(se,{children:[e.isExample?JA:null,g?n.jsx(K,{tone:"good",role:"status",children:g}):null,n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),n.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:gv.map(R=>{const I=k_(t,R.id),F=I&&I.id!==e.id?I:void 0;return n.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(R.id),"data-on":l.has(R.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>k(R.id),children:[n.jsx("span",{className:"role-chip-label",children:R.label}),n.jsx("span",{className:"role-chip-meaning",children:R.meaning}),F?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",F.name,". If both claim it, the one listed first keeps it."]}):null]},R.id)})}),n.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),n.jsx(ae,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:h||e.isExample,onChange:R=>u(R.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?n.jsx(oe,{message:r.error}):r.data?n.jsx(EW,{view:r.data,chosen:x,onChange:a,disabled:h||e.isExample}):n.jsx(ge,{children:"Loading the installed tools…"})]}),n.jsx(mH,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),pH(j)?n.jsx(gH,{agentId:e.id}):null]})})}function mH({agentId:e,version:t,disabled:s}){var g;const r=ue(()=>Promise.resolve().then(()=>A.rememberedApprovals(e)),[e,t]),i=ue(()=>Promise.resolve().then(()=>A.connections()).catch(()=>null),[]),[a,l]=d.useState(null),[o,c]=d.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const h=async(v,b)=>{l(v),c(null);try{await A.setRememberedApproval(e,v,b),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const v of u)f.set(v.connection,[...f.get(v.connection)??[],v]);const m=v=>{var b,j;return((j=(b=i.data)==null?void 0:b.connections.find(x=>x.slug===v))==null?void 0:j.name)??v},p=v=>v.tool.split(".").slice(2).join(".")||v.tool;return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...f].map(([v,b])=>{const j=b.filter(k=>k.rememberable),x=b.filter(k=>!k.rememberable),w=j.filter(k=>k.remembered),y=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(v)}),n.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return n.jsxs(Ct,{summary:y,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(v)}: remember my approval`,children:j.map(k=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:k.remembered,disabled:s||a!==null,onChange:N=>void h(k.tool,N.target.checked),"aria-label":`Remember my approval for ${k.tool}`}),n.jsx("span",{className:"mono",children:p(k)})]},k.tool))}),x.length>0?n.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",n.jsx("span",{className:"mono",children:x.map(p).join(", ")})]}):null]},v)})}),n.jsx(oe,{message:o}),n.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function pH(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function gH({agentId:e}){var h,f;const t=ue(()=>A.notificationSettings(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=s??((f=(h=t.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),A.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>a(!1))};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Messages to you"}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:c,disabled:i||!t.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),n.jsx("span",{children:"Mute its messages"})]}),n.jsx(oe,{message:t.error??l}),n.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function bg(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 xH({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(f?{kind:"emoji",value:t.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(h(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await A.uploadAgentPicture(e.id,await qA(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(Uo))}catch(v){h(v instanceof Error?v.message:String(v))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(lH,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(vH,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function vH({agent:e,onChanged:t}){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(0);d.useEffect(()=>{if(!s)return a(null);const S=URL.createObjectURL(s);return a(S),()=>URL.revokeObjectURL(S)},[s]);const g=S=>{r(null),p(C=>C+1),f(S),t(),window.dispatchEvent(new Event(Uo))},v=async S=>{o(!0),u(null),f(null);try{g(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>v(async()=>(await A.uploadAgentPicture(e.id,s)).note??null),j=()=>v(async()=>(await A.removeAgentPicture(e.id),null)),x={avatar:bg(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[w,y]=d.useState(!1),k=d.useRef(null),N=S=>{u(null),f(null),r(S??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||y(!0)},onDragLeave:()=>y(!1),onDrop:S=>{var C;S.preventDefault(),y(!1),l||N((C=S.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(re,{children:[n.jsx(Os,{id:e.id,name:e.name,size:"xl",face:x}),n.jsx("input",{ref:k,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return N((C=S.target.files)==null?void 0:C[0])}},m),n.jsx(T,{disabled:l,onClick:()=>{var S;return(S=k.current)==null?void 0:S.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(T,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,n.jsx(T,{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 jH({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=d.useState((r==null?void 0:r.accountId)??""),[l,o]=d.useState((r==null?void 0:r.model)??""),[c,u]=d.useState(!1),h=t.accounts.find(p=>p.id===i),f=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(re,{valign:"end",children:[n.jsx(ae,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(v=>v.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[n.jsx("option",{value:"",children:"Choose an account"}),t.accounts.map(p=>n.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),n.jsx(aj,{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(re,{children:[f&&i&&l.trim()?n.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):n.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(T,{variant:"accent",disabled:c||!i||!l.trim()||!f,onClick:()=>{u(!0),s(A.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const wH=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],tm=e=>e.tools.some(t=>wH.includes(t)),yH=["front-desk","maker"],bH={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function kH({agent:e,all:t,onSaved:s}){const[r,i]=d.useState(e.delegates),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(e.delegates),[p,g]=d.useState(e.asksEveryone),[v,b]=d.useState(!1),j=t.filter(R=>R.id!==e.id),x=yH.find(R=>{var I;return(I=e.roles)==null?void 0:I.includes(R)}),w=p===void 0||v,y=v||[...r].sort().join(",")!==[...f].sort().join(","),k=t.filter(R=>R.id!==e.id&&(R.delegates.includes(e.id)||R.asksEveryone!==void 0&&!tm(e))),N=R=>i(I=>I.includes(R)?I.filter(F=>F!==R):[...I,R]),S=async R=>{l(!0),c(null),h(!1);try{const I=await A.setDelegates(e.id,R);m(I.delegates),i(I.delegates),g(I.asksEveryone),b(!1),h(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{i(j.filter(R=>!tm(R)).map(R=>R.id)),b(!0),h(!1)},$=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(le,{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:$}),n.jsx("span",{className:"ui-toolbar-spacer"}),w&&x!==void 0?n.jsx(T,{disabled:a,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?n.jsx(T,{variant:"accent",disabled:!y||a,onClick:()=>void S(r),children:"Save who it can ask"}):n.jsx(T,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(se,{divided:!0,children:[n.jsxs(le,{title:"Can ask",children:[e.isExample?n.jsx(K,{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(oe,{message:o}),w?j.length===0?n.jsx(ge,{children:"Nobody else is installed."}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),n.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:j.map(R=>{const I=tm(R);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${R.id}`,checked:r.includes(R.id),disabled:I||e.isExample||a,onChange:()=>N(R.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${R.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[R.name," ",n.jsxs("span",{className:"mono muted",children:["@",R.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":R.description})]})]},R.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[bH[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(le,{title:"Asked by",children:k.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(a4,{children:k.map(R=>n.jsx(ve,{children:R.name},R.id))})})]})})}const NH=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"}],SH=[{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 CH({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var j,x,w,y,k;const l=t_(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=N=>S=>{S.preventDefault(),s(N)},u=ue(()=>A.agents(),[]),h=zv(),f=ue(()=>A.offers(),[],2e4),m=EE(),p=(((x=f.data)==null?void 0:x.offers.length)??0)+m.offers.length,g=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??a??null,v=r.find(N=>N.roles.includes(xh)),b=$A(r,g);return n.jsxs("div",{className:"ui-page",children:[n.jsx(wh,{title:"Agents",lede:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:v?n.jsx(Tt,{variant:"accent",href:at(v.id),onClick:c(at(v.id)),children:"Add an agent"}):null}),n.jsx(pc,{children:NH.map(N=>n.jsx(tl,{href:N.id==="team"?Nt:`${Nt}?tab=${N.id}`,active:o===N.id,count:N.id==="offers"?p:void 0,onClick:c(N.id==="team"?Nt:`${Nt}?tab=${N.id}`),children:N.label},N.id))}),o==="missions"?n.jsx(AA,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(AE,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(RA,{embedded:!0}):null,o==="reminders"?n.jsx(DA,{timezone:t,embedded:!0}):null,o==="team"&&b?n.jsx(wg,{navigate:s,standing:!0}):null,o==="team"?n.jsx(EH,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(cn,{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:x1(r,g).map(N=>{const S=gh(i.get(N.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...fc(hc(N)),"data-unavailable":N.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Os,{id:N.id,name:N.name,size:"xl",unavailable:!N.available,face:N})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:St(N.id,"conversations"),onClick:c(St(N.id,"conversations")),children:N.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",N.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:N.description})]}),n.jsxs("div",{className:"ui-row",children:[N.id===g?n.jsx(Ba,{children:"front desk"}):null,S?n.jsx(ve,{tone:"critical",dot:!0,children:"waiting for you"}):N.available?n.jsx(ve,{tone:"good",dot:!0,children:"ready"}):n.jsx(ve,{tone:"warning",children:rr(N.unavailableReason??"cannot run",60)}),n.jsx(ve,{mono:!0,children:N.model}),n.jsx(Tt,{className:"agent-card-talk",size:"sm",href:at(N.id),onClick:c(at(N.id)),"aria-label":`Talk to ${N.name}`,children:"Talk"})]})]},N.id)})}):null,o==="team"&&!b?n.jsx(wg,{navigate:s,standing:!0}):null,l?n.jsx(pt,{title:((k=r.find(N=>N.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(Nt),children:n.jsx(AH,{agentId:l.agentId,agent:r.find(N=>N.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function EH({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null);if(t)return n.jsx(oe,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,v=r.problem,b=x=>x.map(w=>{var y;return((y=r.choices.find(k=>k.id===w))==null?void 0:y.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const x=await A.setDefaultAgent(p);f(x.note),a(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return n.jsx(lt,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(oe,{message:c}),(v==null?void 0:v.code)==="multiple-defaults"?n.jsx(K,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(v.agents)}. The one chosen here wins.`}):(v==null?void 0:v.code)==="no-default-agent"?n.jsx(K,{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(K,{tone:"good",role:"status",children:h}):null,n.jsxs(re,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:x=>a(x.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(x=>n.jsxs("option",{value:x.id,disabled:!x.available,children:[x.name," @",x.handle,x.available?"":" (cannot run)"]},x.id))]}),n.jsx(T,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function AH({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=f=>m=>{m.preventDefault(),l(f)},u=gh(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(Os,{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(ve,{tone:"critical",children:u}):t&&!t.available?n.jsx(ve,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(Tt,{variant:"accent",href:at(e),onClick:c(at(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(K,{tone:"warning",role:"status",children:[j1(t)," ",n.jsx("a",{href:_e(Lp(t).section),children:Lp(t).label})]}):null,n.jsx(pc,{children:SH.map(f=>n.jsx(tl,{href:St(e,f.id),active:r===f.id,onClick:c(St(e,f.id)),children:f.label},f.id))}),r==="conversations"?n.jsx(TH,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(AA,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(RA,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(DA,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(IA,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(vW,{agentId:e,agentName:h}):null,r==="setup"?n.jsx(uH,{agentId:e,section:i,navigate:l}):null]})}function TH({agentId:e,navigate:t}){const{data:s,error:r}=ue(()=>Be.conversations(e,50),[e]);if(r)return n.jsx(ge,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(lt,{flush:!0,children:s?i.length===0?n.jsx(cn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(ft,{children:i.map(a=>n.jsx(ct,{href:at(e,a.id),onClick:()=>t(at(e,a.id)),title:rr(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:He(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(ge,{children:"Loading…"})})}const hk=3,RH=40;function $H({agent:e,navigate:t}){var g;const s=d.useRef(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null),u=ue(()=>Be.conversations(e.id,hk),[e.id],3e4),h=tr(Yv),f=tr("(pointer: coarse)");d.useEffect(()=>{var v;!h&&!f&&((v=s.current)==null||v.focus())},[]);const m=(v,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:j}=await Be.startConversation(e.id),x=await Be.send(e.id,{conversationId:j,text:v,...b.length>0?{attachmentIds:b.map(w=>w.artifactId)}:{}});t(at(e.id,x.conversationId))}catch(j){l(j instanceof pe?j.message:String(j)),c({text:v,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,hk);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(oe,{message:a}):null,n.jsx(Uv,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(v=>{const b=at(e.id,v.id),j=v.opening??v.preview??"Untitled conversation",x=Jx(v.lastMessageAt??v.createdAt??v.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:j,onClick:w=>{w.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:rr(j,RH)}),x?n.jsx("span",{className:"home-continue-when",children:x}):null]})},v.id)})})]}):null]})}function IH(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 PH({navigate:e,preview:t,hidden:s}){var c;const r=ue(()=>A.currentTip(t),[t]),[i,a]=d.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?A.dismissTip(l.id):A.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(K,{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(me,{name:"close"})})]}),n.jsxs(re,{children:[n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(T,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const kg="buddi.tipsOpen";function MH(e){return lh(e,{compact:!0})}function DH(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 ${MH(e.shownAt)}`:"Shown"}}function OH(){try{return window.localStorage.getItem(kg)==="1"}catch{return!1}}function LH(){const e=ue(()=>A.tips(),[]),[t,s]=d.useState(OH),r=d.useCallback(i=>{s(i);try{i?window.localStorage.setItem(kg,"1"):window.localStorage.removeItem(kg)}catch{}},[]);return{open:t,setOpen:r,list:e}}function _H({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(me,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function FH({tips:e,navigate:t}){var b,j;const{open:s,setOpen:r,list:i}=e,[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null);if(!s)return null;const f=((b=i.data)==null?void 0:b.tips)??null,m=u??((j=i.data)==null?void 0:j.enabled)??!0,p=x=>l(x instanceof pe?x.message:String(x)),g=x=>{c(x),l(null),A.restoreTip(x).then(()=>i.reload(),p).finally(()=>c(null))},v=x=>{c("switch"),l(null),h(x),A.saveTipsSettings(x).then(w=>{h(w.enabled),i.reload()}).catch(w=>{h(!x),p(w)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(le,{title:"Tips",children:[n.jsx(oe,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(f??[]).map(x=>n.jsx("div",{className:"tips-card","data-tip":x.id,"data-status":x.status,children:n.jsxs(vs,{tone:x.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(ve,{tone:x.status==="today"?"accent":"muted",children:DH(x)})}),n.jsx("p",{className:"tips-card-text",children:x.text}),n.jsxs(re,{children:[n.jsx(Bt,{}),x.status==="dismissed"?n.jsx(T,{size:"sm",disabled:o===x.id,onClick:()=>g(x.id),children:"Bring back"}):n.jsx(T,{size:"sm",variant:x.status==="today"?"accent":void 0,onClick:()=>t(x.action.route),children:x.action.label})]})]})},x.id))}),n.jsxs(re,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||f===null,onChange:x=>v(x.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const ZA="buddi.needsYouView";function zH(){try{return window.localStorage.getItem(ZA)==="list"?"list":"deck"}catch{return"deck"}}function UH(e){try{window.localStorage.setItem(ZA,e)}catch{}}function BH(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function WH({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=d.useState(0);if(e.length===0)return n.jsx(ge,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,h=v=>l((o+v+e.length)%e.length),f=()=>r(c),m=()=>i(c),p=v=>{const b=v.target;b.closest('input, textarea, select, [contenteditable="true"]')||(v.key==="ArrowRight"&&u?(v.preventDefault(),h(1)):v.key==="ArrowLeft"&&u?(v.preventDefault(),h(-1)):v.key==="Enter"&&!b.closest("button, a")?(v.preventDefault(),c.link&&f()):(v.key==="d"||v.key==="Delete")&&!v.metaKey&&!v.ctrlKey&&!v.altKey&&(v.preventDefault(),m()))},g=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(xn,{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(vs,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":He(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(T,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(me,{name:"chevron-left"})}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:n.jsx(me,{name:"chevron-right"})})]}),foot:n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:m,children:"Done"}),c.link?n.jsx(T,{variant:"accent",onClick:f,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:zo(c)}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null]})})})}function HH({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o=""}){var de,Re,De,Ve,he,ze,Ge,Ye,nt,Pt,un,ee,ye;const c=ue(()=>A.overview(),[],15e3),u=ue(()=>A.approvals(),[],1e4),h=ue(()=>A.missions(),[],6e4),f=ue(()=>A.reminders(),[],6e4),m=ue(()=>A.conversations(),[],3e4),p=ue(()=>A.offers(),[],3e4),g=ue(()=>A.proposals(),[],6e4),v=ue(()=>A.agentOffers(),[],6e4),b=ue(()=>A.owner(),[]),j=ue(()=>A.notifications(20),[],3e4),x=d.useMemo(()=>x1(s,r??null),[s,r]),{busy:w,note:y,failure:k,decide:N}=Bv(()=>{u.reload(),c.reload()}),S=c.data,C=s.find(H=>H.id===r)??null,$=H=>{var Fe;return((Fe=s.find(wt=>wt.id===H))==null?void 0:Fe.name)??H},R=H=>Fe=>{Fe.preventDefault(),t(H)},I=((de=u.data)==null?void 0:de.pending)??[],F=((Re=S==null?void 0:S.jobs)==null?void 0:Re.failed)??0,_=((De=S==null?void 0:S.sentinels)==null?void 0:De.openUrgent)??0,E=((Ve=g.data)==null?void 0:Ve.open.length)??0,M=(((he=v.data)==null?void 0:he.offers)??[]).filter(H=>!I.some(Fe=>CE(Fe,H.plugin,H.agent))),P=GH(((ze=j.data)==null?void 0:ze.notifications)??[],I),[U,L]=d.useState(new Set),[W,O]=d.useState(zH),V=P.filter(H=>!U.has(H.id)),X=H=>{L(Fe=>new Set(Fe).add(H.id)),A.notificationSeen(H.id).catch(()=>{})},G=H=>{X(H),H.link&&t(H.link)},Z=H=>BH(H.agentId?$(H.agentId):H.pluginId??VH[H.kind],H,$),z=I.length+(F>0?1:0)+(_>0?1:0)+(E>0?1:0)+M.length+P.length;d.useEffect(()=>{var H,Fe;o===fv&&((Fe=(H=document.getElementById(Ng))==null?void 0:H.scrollIntoView)==null||Fe.call(H,{behavior:"smooth",block:"start"}))},[o]);const q=d.useMemo(()=>{var H,Fe;return XH(((H=h.data)==null?void 0:H.missions)??[],((Fe=f.data)==null?void 0:Fe.reminders)??[])},[h.data,f.data]),Q=(((Ge=m.data)==null?void 0:Ge.conversations)??[]).slice(0,5),ce=((Ye=p.data)==null?void 0:Ye.offers)??[],Pe=ce.slice(0,YH),Te=LH(),Le=ce.length-Pe.length,J=aA(()=>c.reload()),ke=Y5(),ne=d.useMemo(()=>q5(ke.answer),[ke.answer]),Ae=nK({approvals:I.length,failed:F,urgent:_,paused:(S==null?void 0:S.paused)??!1,proposals:E,agentsToSetUp:M.length,messages:P.length});return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"home-band",children:n.jsxs("header",{className:"home-top",children:[n.jsxs("div",{className:"home-top-text",children:[n.jsxs("p",{className:"home-date",children:[n.jsx("span",{children:eK(S==null?void 0:S.now,e)}),n.jsx(C5,{glances:S==null?void 0:S.glances,navigate:t,except:ne,hiding:J}),n.jsx(_H,{tips:Te})]}),n.jsx("h1",{className:"home-greeting",children:ZH(S==null?void 0:S.now,e,((nt=b.data)==null?void 0:nt.preferredName)||((Pt=b.data)==null?void 0:Pt.displayName))}),n.jsx(sK,{items:Ae,navigate:t})]}),n.jsx("div",{className:"home-side",children:n.jsx(S1,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[C?n.jsx($H,{agent:C,navigate:t},C.id):null,n.jsx(FH,{tips:Te,navigate:t}),n.jsx(PH,{navigate:t,preview:IH(o),hidden:Te.open}),a&&a.updateAvailable&&!a.checkout&&a.latest?n.jsx(K,{tone:"accent",children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:_e("system"),onClick:R(_e("system")),children:"Upgrade from Settings → Version."})]})}):null,l.map(H=>n.jsx(K,{tone:"accent",children:n.jsxs("p",{children:[H.sentence," ",n.jsx("a",{href:_e("connections"),onClick:R(_e("connections")),children:"Settings → Connections."})]})},H.id)),n.jsx(oe,{message:c.error??u.error??k}),y?n.jsx(K,{tone:"good",role:"status",children:y}):null,z>0?n.jsx("div",{id:Ng,className:"home-needs",children:n.jsx(le,{title:"Needs you",actions:P.length>0?n.jsx(sn,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:W,onChange:H=>{O(H),UH(H)}}):void 0,children:n.jsxs(se,{children:[I.map(H=>n.jsx(Wv,{action:H,timezone:e,busy:w===H.id,onDecide:N,agentName:$(H.agentId)},H.id)),P.length>0&&W==="deck"?n.jsx(WH,{rows:V,agents:s,label:Z,onOpen:G,onDone:X}):null,P.length>0&&W==="list"?n.jsx(lt,{flush:!0,children:n.jsx(ft,{children:V.map(H=>n.jsx(ct,{href:H.link??void 0,onClick:()=>G(H),lead:H.agentId?n.jsx(xn,{agents:s,id:H.agentId,size:"sm"}):void 0,title:zo(H),sub:Z(H),side:H.state==="held"?"today":He(H.createdAt)},H.id))})}):null,F>0?n.jsx(K,{tone:"critical",children:n.jsxs("a",{href:`${xt}/jobs?state=failed`,onClick:R(`${xt}/jobs?state=failed`),children:[F," failed job",F===1?"":"s",". See why, then retry or cancel them, one by one or all at once."]})}):null,_>0?n.jsx(K,{tone:"critical",children:n.jsxs("a",{href:`${xt}/alerts`,onClick:R(`${xt}/alerts`),children:[_," urgent alert",_===1?"":"s"," from your watchers."]})}):null,M.map(H=>n.jsx(lt,{children:n.jsx(Kv,{plugin:H.plugin,agent:H.agent,text:H.text,label:`Create @${H.handle}`,handle:H.handle,onDismiss:()=>{A.dismissAgentOffer(H.plugin,H.agent).then(()=>v.reload())}})},`${H.plugin}/${H.agent}`)),E>0?n.jsx(K,{tone:"accent",children:n.jsxs("a",{href:_e("proposals"),onClick:R(_e("proposals")),children:[E," proposal",E===1?"":"s"," from your agents to keep or discard."]})}):null,(((un=S==null?void 0:S.sentinels)==null?void 0:un.errors)??[]).map(H=>n.jsxs(K,{tone:"warning",children:["Watcher ",H.sentinelId," failed: ",H.error]},H.sentinelId)),((S==null?void 0:S.mail)??[]).filter(H=>H.lastError).map(H=>n.jsxs(K,{tone:"warning",children:["Source ",H.sourceId,": ",H.lastError]},H.sourceId))]})})}):null,n.jsx(Z5,{widgets:ke,navigate:t}),n.jsx(le,{title:"Your team",aside:n.jsx("a",{href:Nt,onClick:R(Nt),children:"All agents"}),children:s.length===0?n.jsx(ge,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsx("div",{className:"home-team",children:x.map(H=>{const Fe=gh(i.get(H.id));return n.jsxs("a",{className:"home-face",...fc(hc(H)),href:at(H.id),onClick:R(at(H.id)),"data-waiting":Fe?"true":void 0,"data-unavailable":H.available?void 0:"true",children:[n.jsx(Os,{id:H.id,name:H.name,size:"lg",unavailable:!H.available,face:H}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:H.name}),n.jsx("span",{className:"home-face-status",children:Fe?rK(Fe):H.available?rr(H.description,60):H.unavailableReason??"Cannot run right now."})]})]},H.id)})})}),$A(s,r)?n.jsx(wg,{navigate:t}):null,Pe.length>0?n.jsx(le,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[Le>0?n.jsxs("a",{href:`${Nt}?tab=offers`,onClick:R(`${Nt}?tab=offers`),children:[Le," more"]}):null,n.jsx(TA,{ids:ce.map(H=>H.id),onDone:()=>p.reload()})]}),children:n.jsx("div",{className:"home-offers",children:Pe.map(H=>n.jsx(QH,{offer:H,agents:s,open:R(St(H.agentId,"offers")),onDismissed:()=>p.reload()},H.id))})}):null,n.jsx(v5,{}),(ye=(ee=g.data)==null?void 0:ee.digest)!=null&&ye.latest?n.jsx(tK,{digest:g.data.digest.latest,go:R}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(le,{title:"Coming up",aside:n.jsx("a",{href:`${Nt}?tab=missions`,onClick:R(`${Nt}?tab=missions`),children:"All missions"}),children:n.jsx(lt,{flush:!0,children:q.length===0?n.jsx(ge,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(ft,{children:q.map(H=>n.jsx(ct,{href:H.route,onClick:()=>t(H.route),lead:n.jsx(xn,{agents:s,id:H.agentId,size:"sm"}),title:H.title,sub:`${H.kind} for ${$(H.agentId)}`,side:He(H.at)},H.key))})})}),n.jsx(le,{title:"Lately",aside:n.jsx("a",{href:xt,onClick:R(xt),children:"All activity"}),children:n.jsx(lt,{flush:!0,children:Q.length===0?n.jsx(ge,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(ft,{children:Q.map(H=>n.jsx(ct,{href:at(H.agentId,H.id),onClick:()=>t(at(H.agentId,H.id)),lead:n.jsx(xn,{agents:s,id:H.agentId,size:"sm"}),title:H.opening?rr(H.opening,80):"Untitled conversation",sub:`${$(H.agentId)}, ${H.messageCount} message${H.messageCount===1?"":"s"}`,side:He(H.lastMessageAt??H.createdAt)},H.id))})})})]}),((S==null?void 0:S.home)??[]).map(H=>n.jsx(iK,{block:H},H.id)),S!=null&&S.jobs&&S.missions?n.jsxs("p",{className:"home-foot muted",children:[Vt(S.jobs.pending??0)," queued, ",Vt(S.jobs.leased??0)," running, ",Vt(S.missions.enabled)," of ",Vt(S.missions.total)," missions on."," ",S.paused?n.jsx(ve,{tone:"warning",children:"paused"}):n.jsx(ve,{tone:"good",children:"running"})," ",n.jsx("a",{href:el("").replace(/\/conversations\/$/,""),onClick:R(xt),children:"Activity"})," · ",n.jsx("a",{href:_e("system"),onClick:R(_e("system")),children:"System"})]}):null]})]})}const KH=new Set(["watcher","reminder","failure","recap","plugin","agent"]),VH={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function GH(e,t){const s=new Set(t.map(r=>r.id));return e.filter(r=>KH.has(r.kind)&&r.actedAt===null&&r.state!=="stored"&&(r.seenAt===null||r.state==="held")&&!(r.actionId&&s.has(r.actionId)))}const YH=6,qH=500;function QH({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=d.useState(!1),l=d.useRef(null),o=d.useRef(!1),c=()=>{i||(a(!0),A.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:St(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},qH)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(xn,{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 XH(e,t){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:St(r.agentId,"missions")});for(const r of t)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:St(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function JH(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 ZH(e,t,s){const r=JH(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 eK(e,t){try{return or(e?new Date(e):new Date,t,{weekday:!0})}catch{return Ze(e??null,t)}}function uu(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 tK({digest:e,go:t}){var a,l;const s=[uu(e.memory,"memory note","memory notes"),uu(e.skills,"skill kept","skills kept"),uu(e.rules,"rule kept","rules kept"),uu(e.changes,"change to an agent kept","changes to agents kept")].filter(o=>o!==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(([,o])=>o>0).map(([o,c])=>`${o} ${c}`).join(", ")}).`:"No rule you kept acted this week.",i=Object.entries(((a=e.feedback)==null?void 0:a.byAgent)??{}).map(([o,c])=>[o,[c.up>0?`${c.up} 👍`:"",c.down>0?`${c.down} 👎`:"",c.neutral>0?`${c.neutral} other`:""].filter(Boolean).join(" ")]).filter(([,o])=>o!=="").map(([o,c])=>{var u;return`${((u=e.agentNames)==null?void 0:u[o])??o}: ${c}`});return n.jsx(le,{title:"What buddi learned this week",aside:n.jsx("span",{className:"muted",children:He(e.at)}),children:n.jsx(lt,{children:n.jsxs(se,{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(o=>n.jsx("li",{children:o},o))})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Proposes"}),n.jsx("p",{children:e.open>0?n.jsxs("a",{href:_e("proposals"),onClick:t(_e("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})]}),i.length>0?n.jsxs("div",{"data-testid":"digest-reactions",children:[n.jsx("p",{className:"ui-card-meta",children:"Your reactions"}),n.jsxs("ul",{className:"home-digest-list",children:[i.map(o=>n.jsx("li",{children:o},o)),(((l=e.feedback)==null?void 0:l.notes)??[]).map((o,c)=>{var u;return n.jsxs("li",{children:["What was off (",((u=e.agentNames)==null?void 0:u[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}const Ng="home-needs";function nK(e){const t=(r,i,a=`${i}s`)=>r===1?i:a,s=[];return e.approvals>0&&s.push({key:"approvals",count:e.approvals,label:t(e.approvals,"approval")}),e.failed>0&&s.push({key:"failed",count:e.failed,label:t(e.failed,"failed job"),tone:"critical",route:`${xt}/jobs?state=failed`}),e.urgent>0&&s.push({key:"urgent",count:e.urgent,label:t(e.urgent,"urgent alert"),tone:"critical",route:`${xt}/alerts`}),e.paused&&s.push({key:"paused",count:null,label:"Paused",route:`${xt}/jobs`}),e.proposals>0&&s.push({key:"proposals",count:e.proposals,label:t(e.proposals,"proposal"),route:_e("proposals")}),e.agentsToSetUp>0&&s.push({key:"agents",count:e.agentsToSetUp,label:t(e.agentsToSetUp,"agent to set up","agents to set up")}),e.messages>0&&s.push({key:"messages",count:e.messages,label:t(e.messages,"message")}),s}function sK({items:e,navigate:t}){if(e.length===0)return n.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,i;(i=(r=document.getElementById(Ng))==null?void 0:r.scrollIntoView)==null||i.call(r,{behavior:"smooth",block:"start"})};return n.jsx("p",{className:"home-counts",children:e.map((r,i)=>{const a=n.jsxs(n.Fragment,{children:[r.count!==null?n.jsxs(n.Fragment,{children:[n.jsx("strong",{children:r.count})," "]}):null,r.label]});return n.jsxs(d.Fragment,{children:[i>0?n.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?n.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),t(r.route)},children:a}):n.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:a})]},r.key)})})}function rK(e){return e.charAt(0).toUpperCase()+e.slice(1)}function iK({block:e}){const[t,s]=d.useState(!1),r=e.sensitive===!0&&!t;d.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(T,{size:"sm",variant:"ghost","aria-pressed":!r,onClick:()=>s(a=>!a),children:r?"Show":"Hide"}):null]});return n.jsxs(le,{title:e.title,aside:i,children:[e.note?n.jsx(K,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(yh,{children:e.stats.map(a=>n.jsx(Xs,{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(lt,{flush:!0,children:n.jsx(ft,{children:e.rows.map((a,l)=>n.jsx(ct,{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 aK=3e4;function eT(){const{data:e,reload:t}=ue(()=>A.recovery(),[],aK),s=d.useRef(t);return s.current=t,d.useEffect(()=>{const r=()=>s.current(),i=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",i)}},[]),{data:e,reload:t}}function fk(e){return e.kind==="account"?e.accountId?i_(e.accountId):_e("accounts"):e.kind==="telegram"?_e("telegram"):e.kind==="connection"?e.connectionId?l_(e.connectionId):_e("connections"):e.kind==="email"?e.settingsRoute:_e("secrets")}function lK(e){return e.install?u_(e.install):d_}const oK=_e("system");function cK(e){return e.loadsAtRestart?`installed — loads at the next restart${e.waiting?`; ${e.waiting.note}`:""}`:e.waiting?`${e.name} — ${e.waiting.note}`:e.source}const uK="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function dK({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,l=e.checklist.keptTables??[],[o,c]=d.useState(!0),[u,h]=d.useState([]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(!1),j=r.filter(k=>!k.installed||k.waiting!==void 0||k.loadsAtRestart===!0),x=i.jobs+i.missions+i.approvals+i.telegramChats,w=k=>{h(N=>N.includes(k)?N.filter(S=>S!==k):[...N,k])},y=()=>{m(!0),g(null),A.leaveRecovery({dropPending:o,keepGrants:u}).then(()=>{b(!0),t==null||t()}).catch(k=>g(k instanceof pe?k.message:String(k))).finally(()=>m(!1))};return n.jsx(lt,{title:"Back from a backup",children:n.jsxs(se,{divided:!0,children:[n.jsxs(le,{children:[n.jsx(nn,{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(le,{title:"Keys to paste again",children:s.length===0?n.jsx(ge,{children:"Nothing is missing."}):n.jsx(ft,{children:s.map(k=>n.jsx(ct,{title:k.label??k.name,sub:k.name?n.jsx("span",{className:"mono",children:k.name}):void 0,side:k.signIn?n.jsx(Tt,{size:"sm",href:fk(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):n.jsx(Tt,{size:"sm",href:fk(k),"aria-label":`Fix ${k.label??k.name}`,children:"Fix"})},`${k.kind}:${k.accountId??k.name}`))})}),n.jsx(le,{title:"Add-ons to install again",children:j.length===0&&l.length===0?n.jsx(ge,{children:"Everything the backup named is installed."}):n.jsxs(ft,{children:[j.map(k=>n.jsx(ct,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:k.name})," ",k.version]}),sub:cK(k),side:k.loadsAtRestart?n.jsx(Tt,{size:"sm",href:oK,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:n.jsx(Tt,{size:"sm",href:lK(k),"aria-label":`Install ${k.name} again`,children:k.install?"Install":"Find it"})},k.name)),l.map(k=>n.jsx(ct,{title:n.jsx("span",{className:"mono",children:k.table}),sub:k.sentence},`kept:${k.table}`))]})}),n.jsx(le,{title:"Work that was waiting",children:x===0?n.jsx(ge,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(se,{gap:"sm",children:[n.jsx(nn,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(le,{title:"Standing permissions",children:a.length===0?n.jsx(ge,{children:"No agent had a standing permission."}):n.jsxs(se,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),n.jsx("ul",{className:"recovery-list",children:a.map(k=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:u.includes(k.id),onChange:()=>w(k.id),"aria-label":`Keep ${k.tool} for ${k.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:k.tool})," for ",k.agent," ",n.jsx("span",{className:"ui-card-meta",children:k.scope}),k.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",k.description]}):null]})]})},k.id))})]})}),n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:p}),v?n.jsx(K,{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(re,{align:"end",children:n.jsx(T,{variant:"accent",disabled:f||v,onClick:y,children:"Leave recovery mode"})})]})})]})})}const hK=2e3,fK={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 mk(e){return fK[e.phase]??e.detail??e.phase}const mK=new Set(["done","failed","rolled-back"]);function tT(e){return e!==void 0&&(mK.has(e.phase)||!!e.finishedAt)}function pK(e){const[t,s]=d.useState(void 0),[r,i]=d.useState(!1),[a,l]=d.useState(null),o=d.useRef(!1);return d.useEffect(()=>{if(!e){s(void 0),i(!1),o.current=!1;return}let c=!1;const u=()=>{A.backupJob(e).then(f=>{if(!c){if(o.current){window.location.reload();return}s(f),l(null),tT(f)&&(c=!0)}}).catch(f=>{if(!c){if(f instanceof pe&&f.status!==0&&f.status<500){l(f.message);return}o.current=!0,i(!0)}})};u();const h=window.setInterval(u,hK);return()=>{c=!0,window.clearInterval(h)}},[e]),{job:t,away:r,error:a}}function gK({job:e,away:t,error:s}){return s?n.jsx(oe,{message:s}):t?n.jsx(K,{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(K,{tone:"critical",role:"alert",children:[mk(e)," ",e.error??""]}):n.jsxs(K,{tone:e.phase==="done"?"good":void 0,role:"status",children:[mk(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function xK(){var b,j,x,w,y,k,N;const e=ue(()=>A.backups(),[],3e4),t=eT(),s=ue(()=>A.service(),[]),[r,i]=d.useState(null),a=pK(r),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(null),m=((b=e.data)==null?void 0:b.supervised)??((j=s.data)==null?void 0:j.supervised),p=h!==null||m===!1,g=((x=e.data)==null?void 0:x.archives)??[],v=S=>{u(!0),o(null),S.then(C=>{var $;return i((($=C.job)==null?void 0:$.id)??null)}).catch(C=>{C instanceof pe&&C.status===409?f(C.message):o(C instanceof pe?C.message:String(C))}).finally(()=>{u(!1),e.reload()})};return d.useEffect(()=>{tT(a.job)&&e.reload()},[(w=a.job)==null?void 0:w.phase]),n.jsxs(se,{gap:"lg",children:[(y=t.data)!=null&&y.active?n.jsx(dK,{view:t.data,onLeft:t.reload}):null,n.jsx(oe,{message:e.error??l}),n.jsx(gK,{...a}),n.jsx(jK,{onSaved:()=>e.reload()}),n.jsx(le,{title:"Backups",panel:!0,actions:n.jsx(T,{variant:"accent",size:"sm",disabled:c,onClick:()=>v(A.startBackup(!0)),children:"Back up now"}),children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsxs("p",{className:"ui-card-meta",children:["Kept in ",n.jsx("span",{className:"mono",children:((k=e.data)==null?void 0:k.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),n.jsx(le,{children:e.data&&g.length===0?n.jsx(cn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(Fn,{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:g.map(S=>{var C;return n.jsx(wK,{archive:S,busy:c,database:(C=e.data)==null?void 0:C.database,checkout:p,onVerify:()=>v(A.verifyArchive(S.name)),onRestore:($,R)=>v(A.restoreArchive({name:S.name,...$?{passphrase:$}:{},...R?{confirm:R}:{}}))},S.name)})})]}):n.jsx(ge,{children:"Loading…"})})]})}),n.jsx(yK,{}),n.jsx(bK,{busy:c,checkout:p,checkoutSaid:h,database:(N=e.data)==null?void 0:N.database,onRestore:(S,C,$)=>v(A.restoreUpload(S,{passphrase:C,confirm:$}))})]})}const vK={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function jK({onSaved:e}){var p;const t=ue(()=>A.backupSchedule(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1);d.useEffect(()=>{t.data&&r(t.data)},[t.data]);const h={...vK,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(le,{title:"Every night",panel:!0,children:n.jsx(le,{children:n.jsx(K,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...h,...g})},m=()=>{a(!0),o(null),A.setBackupSchedule(h).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof pe?g.message:String(g))).finally(()=>a(!1))};return n.jsx(le,{title:"Every night",panel:!0,foot:n.jsx(T,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.enabled,onChange:g=>f({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(Is,{children:[n.jsx(ae,{label:"At",children:n.jsx("input",{type:"time",value:h.time,onChange:g=>f({time:g.target.value})})}),n.jsx(ae,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(ae,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(K,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${He(h.lastRunAt)}.`:""]}):null]})})]})})}function wK({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,f]=d.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:He(e.createdAt)}),n.jsx("td",{children:zn(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(ve,{tone:"good",children:"locked"}):n.jsx(ve,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(ve,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(re,{align:"end",children:[n.jsx(T,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?n.jsx("tr",{children:n.jsx("td",{colSpan:5,children:r?n.jsx(K,{tone:"warning",children:nT}):n.jsx(sT,{what:`${e.name}, taken ${He(e.createdAt)}, ${zn(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:f,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,h)})})}):null]})}const nT="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function sT({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=t??"",f=h===""?a.trim()!=="":a.trim()===h;return n.jsxs(se,{gap:"sm",children:[n.jsxs(K,{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(ae,{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(ae,{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(re,{align:"end",children:[n.jsx(T,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function yK(){const[e,t]=d.useState(null),[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=()=>{a(!0),o(null),A.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))},f=()=>{a(!0),o(null),A.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))};return n.jsx(le,{title:"The passphrase",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{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(re,{align:"end",children:n.jsx(T,{disabled:i,onClick:h,children:"Show it"})}),c?n.jsx(K,{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(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(ae,{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(re,{align:"end",children:n.jsx(T,{variant:"accent",disabled:i||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function bK({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(!1);return t?n.jsx(le,{title:"Restore from a file",panel:!0,children:n.jsx(le,{children:n.jsx(K,{tone:"warning",children:s??nT})})}):n.jsx(le,{title:"Restore from a file",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(Is,{children:[n.jsx(ae,{label:"The backup file",children:n.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),n.jsx(ae,{label:"Its passphrase",hint:"Only if it was locked with one.",children:n.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),f?null:n.jsx(re,{align:"end",children:n.jsx(T,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),f&&a?n.jsx(le,{children:n.jsx(sT,{what:`${a.name}, ${zn(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 rT="gemini-2.5-pro";function Eh(e){return e.replace(/^models\//,"")}const dj=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function iT(e){const t=e.map(Eh);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||dj.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||Ed(a,s.version)>0||Ed(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 aT(e){let t;for(const s of e.map(Eh)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||dj.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||Ed(i,t.version)>0||Ed(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function lT(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Eh(e))}function kK(e){return[...new Set(e.map(Eh).filter(t=>t.startsWith("gemini-")&&!dj.test(t)))]}function oT(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function Ed(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 cT(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function NK({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=ue(()=>A.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState(!1),[b,j]=d.useState(t??null);d.useEffect(()=>{t&&j(t)},[t]);const x=s==null?void 0:s.accounts.some(S=>{var C;return((C=S.login)==null?void 0:C.state)==="pending"&&S.login.expiresAt&&Date.parse(S.login.expiresAt)>Date.now()});d.useEffect(()=>{if(!x)return;const S=setInterval(i,2e3);return()=>clearInterval(S)},[x,i]);const w=async(S,C)=>{o(!0),u(null),f(""),v(!1);try{const $=await S();return f(($==null?void 0:$.warning)??C),i(),!0}catch($){return u($ instanceof Error?$.message:"Could not apply change."),i(),!1}finally{o(!1)}},y=(s==null?void 0:s.accounts)??[],k=y.find(S=>S.id===b)??y[0],N=S=>{var C;return cT(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":uT(S)};return n.jsxs(An,{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(oe,{message:r??c}),h&&n.jsx(K,{tone:"good",role:"status",children:h}),g&&n.jsx(K,{role:"status",children:a?"Refreshing account status…":r?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!s&&!r&&n.jsx(ge,{children:"Loading accounts…"}),r&&n.jsx(re,{children:n.jsx(T,{onClick:i,children:"Retry"})}),s&&n.jsxs(n.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&n.jsx(K,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&n.jsx(pt,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(MK,{accounts:y,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),n.jsx(le,{title:"Accounts",aside:`Secrets live in the ${SK(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),f(""),v(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.jsx(T,{variant:"accent",size:"sm",disabled:l,"aria-expanded":m,"aria-controls":"new-provider-account",onClick:()=>p(!m),children:"Add account"})]}),panel:!0,flush:!0,children:y.length===0?n.jsx(cn,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:y.map(S=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(k==null?void 0:k.id)===S.id,onClick:()=>j(S.id),children:[n.jsx(CK,{kind:S.kind,auth:S.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:S.label}),Ad(S)?n.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[N(S)," · back at ",hj(Ad(S).until)]}):n.jsxs("span",{className:"accounts-row-sub",children:[N(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(hT,{account:S})]},S.id))}),k?n.jsx($K,{account:k,provider:N(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${k.id}:${k.revision}`):null]})})]})]})}function SK(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function uT(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":ij(e)?"mlxh":"OpenAI-compatible"}function dT(e){return e.detectedContextWindowSource==="mlxh"?kW(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function CK({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 EK(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function Ad(e,t=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>t?s:null}const AK=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function hj(e,t=new Date,s=AK()){const r=new Date(e),i=a=>a.toLocaleDateString("en-CA",{timeZone:s});return i(r)===i(t)?Ut(r,s):i(r)===i(new Date(t.getTime()+864e5))?`tomorrow at ${Ut(r,s)}`:oC(r,s)}function hT({account:e,long:t}){const s=Ad(e);if(s){const a=`Rate-limited until ${hj(s.until)}`;return n.jsx("span",{title:a,children:n.jsx(ve,{tone:"warning",children:t?a:"Rate-limited"})})}const r=e.enabled?e.configured?"good":"warning":void 0,i=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return n.jsx(ve,{tone:r,children:i})}function TK({id:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("span",{className:"accounts-id",children:[n.jsx("code",{className:"accounts-id-text",children:e}),n.jsx(T,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:t?"Copied":"Copy"})]})}function RK({account:e,provider:t}){const s=Ad(e);if(!s)return null;const r=s.provider??t,i=hj(s.until);if(s.scope==="day"){const a=e.assignedAgents,l=a.length===1?a[0]:"its agents",o=s.provider==="ChatGPT",c=o?"This ChatGPT plan has reached its usage limit":s.limit!==null?`${s.freeTier?`${r}'s free tier allows`:`${r} allows this account`} ${s.limit.toLocaleString()} ${s.unit??"requests"} a day`:`${r} says this account has used today's allowance`,u=s.freeTier&&s.provider==="Gemini"?", or turn on billing for the key at aistudio.google.com":"";return n.jsx(K,{tone:"warning",title:c,action:a.length>0?n.jsx(Tt,{size:"sm",href:a.length===1?St(a[0],"setup","brain"):Nt,children:a.length===1?`Change ${a[0]}'s account`:"Change their accounts"}):void 0,children:n.jsxs("p",{children:["It resets ",/^tomorrow/.test(i)?i:`at ${i}`,". Until then buddi doesn't send this account's requests to ",r,", so ",a.length?`${l}'s runs stop with this note`:"a run on it stops with this note"," instead of failing again and again. To keep going ",o?"before then":"today",", ",a.length?`give ${l} another account`:"use another account",u,"."]})})}return n.jsx(K,{tone:"warning",title:`${r} asked buddi to slow down`,children:n.jsxs("p",{children:["It said to wait until ",i,". A run that meets this waits and tries again — up to a minute during a conversation, longer for work in the background."]})})}function fj(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 $K({account:e,provider:t,busy:s,run:r,anthropicOAuthEnabled:i}){const[a,l]=d.useState(!1),[o,c]=d.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(hT,{account:e,long:!0})]}),n.jsx(nn,{items:[{label:"Provider",value:t},{label:"Default model",value:n.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:n.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${dT(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>n.jsx("a",{href:St(u,"setup","brain"),children:u},u))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:Nt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${Ze(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:n.jsx(TK,{id:e.id})}]}),n.jsx(RK,{account:e,provider:t}),e.removalPending&&n.jsx(K,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(K,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(pT,{account:e,enabled:!!i,busy:s,run:r}),e.kind==="codex"&&n.jsx(fT,{account:e,busy:s,run:r}),e.auth==="device-key"&&n.jsx(mT,{account:e,busy:s,run:r}),n.jsxs(re,{children:[n.jsx(T,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),n.jsx(T,{disabled:s||e.removalPending,onClick:()=>void r(()=>A.saveProviderAccount({...fj(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(T,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>A.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(T,{variant:"danger",disabled:s||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>c(!0),children:"Remove account"})]}),e.test&&n.jsxs(n.Fragment,{children:[n.jsxs(K,{role:"status",tone:EK(e.test.state),children:[n.jsx("p",{children:e.test.message}),e.test.retryAt?n.jsxs("p",{children:["Provider suggested retry time: ",new Date(e.test.retryAt).toLocaleString(),". This is retry advice, not a guaranteed quota reset."]}):["rate-limited","quota-exhausted"].includes(e.test.state)&&n.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),n.jsxs("p",{className:"muted",children:["Tested at ",new Date(e.test.checkedAt).toLocaleString(),e.test.httpStatus?` · HTTP ${e.test.httpStatus}`:"",". This is not a quota reset or subscription renewal date."]})]}),a&&n.jsx(pt,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:n.jsx(IK,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&n.jsxs(K,{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(re,{children:[n.jsx(T,{variant:"danger",disabled:s,onClick:()=>void r(()=>A.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(T,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),n.jsx(Ct,{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 fT({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(re,{children:[n.jsx(T,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>A.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(T,{disabled:t,onClick:()=>void s(()=>A.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(T,{disabled:t||!e.configured,onClick:()=>void s(()=>A.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(K,{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(lj,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(re,{children:n.jsx(Tt,{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 ",Ut(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&n.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function IK({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=d.useState((e==null?void 0:e.label)??""),[c,u]=d.useState((e==null?void 0:e.kind)??"anthropic"),[h,f]=d.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=d.useState((e==null?void 0:e.baseUrl)??""),[g,v]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,j]=d.useState(""),[x,w]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=N=>{u(N),f(N==="codex"?"chatgpt":"api-key"),j(""),p(N==="openai-compatible"?"http://localhost:11434/v1":""),v(N==="anthropic"?"claude-sonnet-5":N==="openai"?"gpt-5":"")},k=!l.trim()||!g.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:N=>{N.preventDefault();const S=b;j(""),s(()=>A.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:x.trim()?Number(x):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ae,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:N=>o(N.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(ae,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:N=>{N.target.value==="anthropic-oauth"?(y("anthropic"),f("anthropic-oauth")):y(N.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(ae,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:N=>p(N.target.value)})}),n.jsx(ae,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:h,onChange:N=>{f(N.target.value),j("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(re,{valign:"end",children:n.jsx(aj,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:v,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(ae,{label:"Context window",hint:ij(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:x,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${dT(e)})`:"assumed from the model",onChange:N=>w(N.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&n.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),h==="api-key"&&n.jsx(ae,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:N=>j(N.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:r,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",disabled:k,children:"Save account"})]})]}),k&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function mT({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,A.ollamaPoll(e.id,r.attemptId).then(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?i.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):i.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await A.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return n.jsxs(n.Fragment,{children:[l&&n.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),n.jsxs(re,{children:[n.jsx(T,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(T,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await A.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(K,{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&&Ut(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function pT({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,h;const[i,a]=d.useState("");return d.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(K,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(re,{children:[n.jsx(T,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>A.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&n.jsx(T,{disabled:s,onClick:()=>{a(""),r(()=>A.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(T,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>A.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((h=e.login)==null?void 0:h.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=i;a(""),r(()=>A.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&Ut(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),n.jsx(ae,{label:"Claude authorization code",children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:i,onChange:f=>a(f.target.value),disabled:s})}),n.jsx(re,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const nm={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function sm(e,t,s){return Sg(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 Sg(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 PK="That key was refused. Check it and paste it again.";function MK({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(ne=>ne.label),[c,u]=d.useState(null),[h,f]=d.useState("anthropic"),[m,p]=d.useState("api-key"),[g,v]=d.useState(()=>sm("anthropic","api-key",o)),[b,j]=d.useState(!1),[x,w]=d.useState(""),[y,k]=d.useState(""),[N,S]=d.useState(null),[C,$]=d.useState(!1),[R,I]=d.useState(""),[F,_]=d.useState(""),[E,M]=d.useState(!1),[P,U]=d.useState(!1),[L,W]=d.useState(!1),[O,V]=d.useState(void 0),X=(ne,Ae,de=!1)=>{f(ne),p(Ae),k(""),S(null),I(""),_(""),M(!1),U(de),W(!1),V(void 0),w(de?"":ne==="openai-compatible"?"http://localhost:11434/v1":""),b||v(de?sm(ne,"device-key",o):sm(ne,Ae,o))},G=ne=>{X("openai-compatible",ne?"api-key":"device-key",!0),ne&&A.ollama().then(Ae=>w(Ae.cloudBaseUrl)).catch(()=>{})},Z=()=>{l&&(X("openai-compatible","api-key"),W(!0),w(l.baseUrl),b||v(Sg("Gemini",o)))},z=()=>{X("openai-compatible","none"),V(null),b||v(Sg("mlxh",o)),A.mlxh().then(ne=>{V(ne),w(ne.baseUrl)}).catch(()=>V(void 0))},q=O!==void 0,Q=c?e.find(ne=>ne.id===c):void 0;if(c)return Q?n.jsx(DK,{account:Q,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(Q.id)}):n.jsx(ge,{children:"Saving…"});const ce=h==="openai-compatible"&&m!=="device-key",Pe=h==="codex"||m==="anthropic-oauth"||m==="device-key",Te=!Pe&&(m==="none"||y.trim()!=="")&&(!ce||x.trim()!==""),Le=async()=>{var ne,Ae;$(!0),I("");try{const de=await A.probeModels({kind:h,auth:m,...ce?{baseUrl:x}:{},...y.trim()?{secret:y}:{}});S(de),F||_(((ne=de.models.find(Re=>Re.isDefault))==null?void 0:ne.id)??((Ae=de.models[0])==null?void 0:Ae.id)??"")}catch(de){I(de instanceof Error?de.message:"Could not load models. You can still enter a custom model.")}finally{$(!1)}},J=F.trim(),ke=!g.trim()||ce&&!x.trim()||ce&&!L&&!q&&!J||L&&!y.trim()||q&&!(O!=null&&O.running);return n.jsxs("form",{className:"ui-stack",onSubmit:ne=>{var De;ne.preventDefault();const Ae=y;k("");let de=J||(q?yg(O)??((De=O==null?void 0:O.models[0])==null?void 0:De.id):void 0)||(m==="device-key"?Tu:nm[h])||"claude-sonnet-5",Re;(async()=>{if(L){de=rT;try{const Ye=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:Ae})).models.map(nt=>nt.id);de=iT(Ye)??de,Re=lT(de)?aT(Ye):void 0}catch{}}let Ve,he=!1;!await s(async()=>{if(Ve=await A.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:x,defaultModel:de,enabled:!0,...Ae.trim()?{secret:Ae}:{}}),m!=="api-key")return Ve;const Ge=await A.testProviderAccount(Ve.id);if(Ge.state==="connected")return Ve;if(Zx(Ge)){const Ye=Ve.id;Ve=void 0;try{const nt=(await A.providerAccounts()).accounts.find(Pt=>Pt.id===Ye);nt&&await A.removeProviderAccount(Ye,nt.revision)}catch{}throw new Error(PK)}if(L&&Re&&oT(Ge)){const Ye=(await A.providerAccounts()).accounts.find(nt=>nt.id===Ve.id);if(Ye&&(await A.saveProviderAccount({...fj(Ye),defaultModel:Re}),(await A.testProviderAccount(Ve.id)).state==="connected"))return{...Ve,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${Re}; turn on billing at Google to use Pro.`}}return he=!0,{...Ve,warning:`Account saved. ${Ge.message}`}},"Account saved.")||!Ve||(L||q||he?u(Ve.id):J||!Pe?r(Ve.id):u(Ve.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ae,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":P?"ollama-cloud":L?"gemini":q?"mlxh":h,onChange:ne=>{if(ne.target.value==="anthropic-oauth")X("anthropic","anthropic-oauth");else if(ne.target.value==="gemini")Z();else if(ne.target.value==="mlxh")z();else if(ne.target.value==="ollama-cloud")X("openai-compatible","device-key",!0);else{const Ae=ne.target.value;X(Ae,Ae==="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(ae,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:ne=>{v(ne.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),P&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:ne=>G(ne.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),ce&&n.jsxs(n.Fragment,{children:[n.jsx(ae,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:x,onChange:ne=>{w(ne.target.value),S(null)}})}),!L&&!q&&n.jsx(ae,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:ne=>{p(ne.target.value),k(""),S(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(ae,{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:ne=>{k(ne.target.value),S(null)}})}),q?O===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):O!=null&&O.running?n.jsxs(se,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",O.models.length===1?"one model":`${O.models.length} models`,". No key: mlxh takes any. buddi starts on ",yg(O)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),O.models.some(ne=>ne.kind==="image")?n.jsxs("p",{className:"muted",children:[O.models.filter(ne=>ne.kind==="image").map(ne=>ne.id).join(", "),": ",_A,"."]}):null]}):n.jsx(K,{tone:"warning",children:LA((O==null?void 0:O.baseUrl)??x)}):L&&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"}),N?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:E?"__custom__":F,onChange:ne=>{ne.target.value==="__custom__"?(M(!0),_("")):(M(!1),_(ne.target.value))},children:[N.models.map(ne=>n.jsxs("option",{value:ne.id,children:[ne.name===ne.id?ne.id:`${ne.name} — ${ne.id}`,ne.isDefault?" (provider default)":"",ne.thinks?" · thinks":""]},ne.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(T,{size:"sm",disabled:C||!Te,onClick:()=>void Le(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(T,{disabled:C||!Te,onClick:()=>void Le(),children:C?"Loading models…":"Load models"}),ce?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",nm[h]," is used until you pick one."]})]}),E||ce&&!N?n.jsx("input",{"aria-label":"Custom model",required:ce,maxLength:150,value:F,onChange:ne=>_(ne.target.value),placeholder:ce?"qwen3:8b":nm[h]}):null,R?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:R}):null,N!=null&&N.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:()=>r(),children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",disabled:ke,children:"Save account"})]})]}),ke&&!q&&n.jsxs("p",{className:"muted",children:["Enter an account name",L?" and a key":ce?", an endpoint and a model":""," to enable Save account."]})]})}function DK({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=d.useState(e.defaultModel),o=e.configured;return n.jsxs(se,{gap:"lg",children:[n.jsxs(K,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(pT,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(fT,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(mT,{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(re,{valign:"end",children:n.jsx(aj,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:i,children:"Skip for now"}),n.jsx(T,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>A.saveProviderAccount({...fj(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(re,{children:n.jsx(T,{onClick:i,children:"Finish later"})})]})}const pk=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 OK(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||pk.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return pk.has(`*.${s}`)}function LK(e){return typeof e=="string"&&e.includes("*")}function _K(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"}:OK(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const gk=["every-time","first-time","pre-approved"],gT={"every-time":"every time","first-time":"first time only","pre-approved":"pre-approved"};function FK(e){const t=gk.indexOf(e);return gk.slice(0,t<0?1:t+1)}function xT(e){return e.endsWith(".account")}const zK="This account’s process holds the value for as long as its connection lives.",mj="Stored, not usable until it has a binding.";function UK(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":xT(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const vT={"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})}},BK="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",WK=e=>`That is a public suffix; ${e} would match every site.`,xk="Give the site as an origin, like https://en.wikipedia.org.";function vk(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(LK(e)){const s=_K(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:BK};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:WK(r)}}return{ok:!1,error:xk}}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:xk}}}function HK(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 jT(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 vk(s);if(e==="browser.native.type"||xT(e))return{ok:!0,target:s};const r=vT[e];if(r===void 0)return{ok:!0,target:s};const i=HK(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=vk(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 KK(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function VK(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=vT[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 wT="accounts.provider";function GK(e,t){for(const s of e)if(s.kind===wT&&typeof s.target=="string"){const r=t.get(s.target);if(r)return r}}function Cg(e,t,s){if(e===wT&&typeof t=="string"){const r=s.get(t);if(r)return r.label}return VK(e,t)}function yT(e){if(e==="delivered")return"good";if(e==="held"||e==="pending")return"warning";if(e==="refused"||e==="failed")return"critical"}function bT(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 kT(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 YK(e){const t=bT(e,"found");return t.length?`The value already sits in ${kT(t)}.`:""}function qK(e){const t=bT(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${kT(t)}.`:""}async function Zi(e,t,s,r){s(!0),r(null);try{return(await A.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}function QK({embedded:e,timezone:t,secret:s}={}){const r=ue(()=>A.secrets(),[]),i=ue(()=>A.providerAccounts(),[]),a=d.useMemo(()=>{var u;return new Map((((u=i.data)==null?void 0:u.accounts)??[]).map(h=>[h.id,{label:h.label,provider:uT(h)}]))},[i.data]),[l,o]=d.useState(!1),c=r.data;return n.jsxs(An,{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(se,{gap:"lg",children:[!c&&!r.error?n.jsx(ge,{children:"Opening the vault…"}):null,r.error?n.jsx(re,{children:n.jsx(T,{onClick:r.reload,children:"Retry"})}):null,c?n.jsx(le,{title:"Secrets",aside:"A value the agents use and never see: bound to where it may go, never shown again.",actions:n.jsx(T,{variant:"accent",size:"sm",onClick:()=>o(!0),children:"Add a secret"}),panel:!0,children:n.jsx(se,{divided:!0,children:c.secrets.length===0?n.jsx(cn,{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."}):c.secrets.map(u=>n.jsx(XK,{secret:u,accounts:a,destinations:c.destinations,timezone:t,onChanged:r.reload,replacing:s===u.name},u.name))})}):null,c?n.jsx(le,{title:"buddi’s own keys",aside:"Read-only.",children:n.jsxs(se,{gap:"sm",children:[c.ownKeys.length===0?n.jsx(ge,{children:"No keys of buddi’s own right now."}):n.jsx("div",{className:"ui-list",children:c.ownKeys.map(u=>n.jsx("div",{className:"ui-list-row",children:n.jsx("span",{className:"ui-list-main",children:n.jsx("span",{className:"mono",children:u})})},u))}),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]}),l&&c?n.jsx(ZK,{destinations:c.destinations,onClose:()=>o(!1),onChanged:r.reload}):null]})}function XK({secret:e,accounts:t,destinations:s,timezone:r,onChanged:i,replacing:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(a?"replace":null);d.useEffect(()=>{a&&f("replace")},[a]);const[m,p]=d.useState(!1),[g,v]=d.useState(!1),b=async()=>{await Zi("secrets.delete",{name:e.name},o,u)!==null&&(p(!1),i())},j=e.lastUse,x=GK(e.bindings,t);return n.jsxs(se,{gap:"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:x?x.label:e.name}),x?n.jsx(Ba,{children:x.provider}):null,e.totp?n.jsx(Ba,{children:"TOTP"}):null,j?n.jsx(ve,{tone:yT(j.outcome),children:j.outcome}):null]}),x?n.jsx("p",{className:"ui-card-meta mono",children:e.name}):null,e.bindings.length===0?n.jsx("p",{className:"ui-card-meta",children:mj}):n.jsx("div",{className:"ui-stack","data-gap":"sm",children:e.bindings.map((w,y)=>n.jsxs("div",{className:"ui-row",children:[n.jsx(Ba,{children:w.kind}),n.jsx("span",{className:"mono",children:Cg(w.kind,w.target,t)}),n.jsx(ve,{tone:"muted",children:gT[w.rule]??w.rule})]},y))}),e.bindings.some(w=>w.heldByPlugin)?n.jsx("p",{className:"ui-card-meta",children:zK}):null,n.jsx("p",{className:"ui-card-meta",children:j?`Last used ${He(j.at)}${j.agentId?` by ${j.agentId}`:""} — ${j.kind}, ${Cg(j.kind,j.target,t)}.`:"Never used."}),n.jsx(oe,{message:c}),m?n.jsxs(K,{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(re,{children:[n.jsx(T,{variant:"danger",disabled:l,onClick:()=>void b(),children:"Delete it"}),n.jsx(T,{disabled:l,onClick:()=>p(!1),children:"Cancel"})]})]}):null,n.jsxs(re,{children:[n.jsx(T,{size:"sm",disabled:l,onClick:()=>f("replace"),children:"Replace value"}),n.jsx(T,{size:"sm",disabled:l,onClick:()=>f("rename"),children:"Rename"}),n.jsx(T,{size:"sm",disabled:l,onClick:()=>f("rebind"),children:e.bindings.length===0?"Add a binding":"Rebind"}),n.jsx(T,{size:"sm",variant:"danger",disabled:l,onClick:()=>p(!0),children:"Delete"}),n.jsx(T,{size:"sm",variant:"ghost","aria-expanded":g,onClick:()=>v(!g),children:"Use log"})]}),g?n.jsx(JK,{name:e.name,accounts:t,timezone:r}):null,h==="replace"?n.jsx(eV,{secret:e,onClose:()=>f(null),onChanged:i}):null,h==="rename"?n.jsx(tV,{secret:e,onClose:()=>f(null),onChanged:i}):null,h==="rebind"?n.jsx(nV,{secret:e,destinations:s,onClose:()=>f(null),onChanged:i}):null]})}function JK({name:e,accounts:t,timezone:s}){const r=ue(()=>A.secretUses(e,50),[e]);if(r.error)return n.jsx(oe,{message:r.error});if(!r.data)return n.jsx(ge,{children:"Reading the log…"});const i=r.data.uses;return i.length===0?n.jsx(ge,{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:[Ze(a.at,s??"UTC")," — ",a.kind,", ",Cg(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(ve,{tone:yT(a.outcome),children:a.outcome})})]},l))})}function NT({name:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a,onDone:l}){const o=YK(t);return n.jsxs(se,{gap:"sm",children:[n.jsxs(K,{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(oe,{message:i}),o?n.jsx(re,{children:n.jsx(T,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":qK(s)||"Nothing of it was left to replace."})}):null,n.jsx(re,{align:"end",children:n.jsx(T,{onClick:l,children:"Done"})})]})}function ST({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(se,{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(re,{valign:"end",children:[n.jsx(ae,{label:"Kind",inline:!0,children:n.jsx("select",{value:a.kind,disabled:s,onChange:u=>{var f;const h=u.target.value;i(l,{kind:h,rule:((f=e.find(m=>m.kind===h))==null?void 0:f.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(ae,{label:"Target",inline:!0,grow:!0,children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:UK(a.kind),onChange:u=>i(l,{target:u.target.value})})}),n.jsx(ae,{label:"Rule",inline:!0,children:n.jsx("select",{value:a.rule,disabled:s,onChange:u=>i(l,{rule:u.target.value}),children:FK(c).map(u=>n.jsx("option",{value:u,children:gT[u]},u))})}),n.jsx(T,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((u,h)=>h!==l)),children:"Remove"})]},l)})})}function ZK({destinations:e,onClose:t,onChanged:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:e[0].maxRule}]:[]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null),w=async()=>{const k=u.map($=>jT($.kind,$.target)),N=k.findIndex($=>!$.ok);if(N!==-1){g(`Binding ${N+1}: ${k[N].error}`);return}const S=a;l("");const C=await Zi("secrets.put",{name:r.trim(),value:S,totp:o,bindings:u.map(($,R)=>({kind:$.kind,target:k[R].target,rule:$.rule}))},m,g);C!==null&&(b({name:r.trim(),result:C}),s())},y=async()=>{const k=await Zi("secrets.scrub_history",{name:(v==null?void 0:v.name)??""},m,g);k!==null&&(x(k),s())};return n.jsx(pt,{title:"Add a secret",onClose:t,children:v?n.jsx(NT,{name:v.name,result:v.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:k=>{k.preventDefault(),w()},children:n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx(ae,{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:k=>i(k.target.value),placeholder:"PNC password"})}),n.jsx(ae,{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:k=>l(k.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"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(ST,{destinations:e,bindings:u,disabled:f,onChange:h}),u.length===0?n.jsx("p",{className:"ui-field-hint",children:mj}):null,e.length?n.jsx(re,{children:n.jsx(T,{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(K,{tone:"critical",role:"alert",children:p}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:t,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",children:"Save secret"})]})]})})})}function eV({secret:e,onClose:t,onChanged:s}){const[r,i]=d.useState(""),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),p=async()=>{const v=r;i("");const b=await Zi("secrets.put",{name:e.name,value:v,totp:e.totp,bindings:e.bindings.map(({kind:j,target:x,rule:w})=>({kind:j,target:x,rule:w}))},l,c);b!==null&&(h(b),s())},g=async()=>{const v=await Zi("secrets.scrub_history",{name:e.name},l,c);v!==null&&(m(v),s())};return n.jsx(pt,{title:`Replace the value of “${e.name}”`,onClose:t,children:u?n.jsx(NT,{name:e.name,result:u,scrubbed:f,busy:a,failure:o,onScrub:()=>void g(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:v=>{v.preventDefault(),p()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(ae,{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:v=>i(v.target.value)})}),o?n.jsx(K,{tone:"critical",role:"alert",children:o}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:t,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",children:"Save value"})]})]})})})}function tV({secret:e,onClose:t,onChanged:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{await Zi("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(pt,{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(ae,{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(K,{tone:"critical",role:"alert",children:o}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:t,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",disabled:!r.trim()||r.trim()===e.name,children:"Save name"})]})]})})})}function nV({secret:e,destinations:t,onClose:s,onChanged:r}){const[i,a]=d.useState(()=>e.bindings.map(f=>({kind:f.kind,target:KK(f.target),rule:f.rule}))),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=async()=>{const f=i.map(g=>jT(g.kind,g.target)),m=f.findIndex(g=>!g.ok);if(m!==-1){u(`Binding ${m+1}: ${f[m].error}`);return}await Zi("secrets.rebind",{name:e.name,bindings:i.map((g,v)=>({kind:g.kind,target:f[v].target,rule:g.rule}))},o,u)!==null&&(r(),s())};return n.jsx(pt,{title:`Rebind “${e.name}”`,onClose:s,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),h()},children:n.jsxs("fieldset",{disabled:l,className:"ui-stack","data-gap":"sm",children:[n.jsx(ST,{destinations:t,bindings:i,disabled:l,onChange:a}),i.length===0?n.jsx("p",{className:"ui-field-hint",children:mj}):null,t.length?n.jsx(re,{children:n.jsx(T,{size:"sm",onClick:()=>a([...i,{kind:t[0].kind,target:"",rule:t[0].maxRule}]),children:"Add a binding"})}):null,c?n.jsx(K,{tone:"critical",role:"alert",children:c}):null,n.jsxs(re,{align:"end",children:[n.jsx(T,{onClick:s,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",children:"Save bindings"})]})]})})})}function sV({timezone:e,embedded:t}){const{data:s,error:r,reload:i}=ue(()=>A.sentinels(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(p=>p.lastError),f=u.filter(p=>!p.enabled),m=(p,g)=>{l(p),c(null),A.setSentinelEnabled(p,g).catch(v=>c(v instanceof pe?v.message:String(v))).finally(()=>{l(null),i()})};return n.jsxs(An,{embedded:t,title:"Watchers",children:[n.jsx(oe,{message:r??o}),n.jsx(K,{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(K,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,f.length>0?n.jsxs(K,{tone:"warning",children:[f.length===1?"One watcher is off.":`${f.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,n.jsx(le,{title:"Installed",aside:n.jsx("a",{href:`${xt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx(cn,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(ft,{children:u.map(p=>{const g=s.runs.find(v=>v.sentinelId===p.id);return n.jsx(ct,{lead:n.jsx(ve,{tone:p.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:p.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:p.description,sub:`${p.id}, every ${rV(p.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:g?Ze(g.lastRunAt,e):void 0,children:g?He(g.lastRunAt):"never ran"}),n.jsx(T,{size:"sm",disabled:a===p.id,onClick:()=>m(p.id,!p.enabled),children:p.enabled?"Turn off":"Turn on"})]})},p.id)})}):n.jsx(ge,{children:"Loading…"})})]})}function rV(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const t=Math.max(1,Math.round(e/60));return t===1?"minute":`${t} minutes`}const jk=4,iV={time:"profile",date:"profile",zone:null};function aV({data:e,phone:t}){const s=d.useRef(null),r=rA(),[i,a]=d.useState(.4),l=t?390:1280,o=t?780:800;d.useEffect(()=>{const u=s.current;if(!u)return;const h=()=>a(u.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(h);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return n.jsx("div",{ref:s,className:"lke-preview","data-phone":t?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:n.jsxs("div",{className:"lk","data-preview":"true","data-bg":(e==null?void 0:e.background)==="image"&&!e.image?"field":(e==null?void 0:e.background)??"field","data-phone":t?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${i})`},"aria-hidden":"true",children:[n.jsx(mA,{data:e??null,now:r,phone:t}),n.jsx("footer",{className:"lk-unlock",children:t?n.jsxs("span",{className:"lk-chip lk-enter",children:[n.jsx(me,{name:"lock",size:14}),n.jsx("span",{children:"Enter PIN"})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"lk-who",children:[n.jsx("span",{className:"lk-face",children:(c??"You").slice(0,1).toUpperCase()}),c?n.jsx("span",{className:"lk-owner",children:c}):null]}),n.jsxs("span",{className:"lk-pin",children:[n.jsx(me,{name:"lock",size:15}),n.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function lV({info:e,placement:t,index:s,count:r,onSize:i,onSettings:a,onMove:l,onRemove:o}){var u;const c=t.label??e.title;return n.jsxs("li",{className:"lke-row","data-key":t.key,children:[n.jsxs("span",{className:"lke-row-text",children:[n.jsx("span",{className:"lke-row-title",children:c}),n.jsx("span",{className:"lke-row-sub",children:e.builtIn?"Built in":`${e.plugin} plugin`})]}),n.jsxs("span",{className:"lke-row-tools",children:[e.sizes.length>1?n.jsx(sn,{label:`Size of ${c}`,options:["small","medium"].filter(h=>e.sizes.includes(h)).map(h=>({value:h,label:h==="small"?"Small":"Medium"})),value:t.size,onChange:i}):null,n.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:a,children:n.jsx(me,{name:"settings",size:14})}):null,n.jsxs("span",{className:"lke-move",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} earlier`,title:"Move earlier",disabled:s===0,onClick:()=>l(-1),children:n.jsx(me,{name:"chevron-left"})}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} later`,title:"Move later",disabled:s===r-1,onClick:()=>l(1),children:n.jsx(me,{name:"chevron-right"})})]}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${c} off the lock screen`,title:"Take off the lock screen",onClick:o,children:n.jsx(me,{name:"close",size:12})})]})]})]})}function wk(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function oV({clock:e,onClock:t,version:s}){var X,G,Z;const r=e??iV,i=ue(()=>A.lockScreen(),[s]),a=ue(()=>A.widgets("lock"),[]),l=ue(()=>A.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>{a.data&&c(a.data)},[a.data]);const w=((X=i.data)==null?void 0:X.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(z=>[z.id,z])),N=y.length>=jk,S=z=>{if(!o)return Promise.resolve(!1);const q=o;return m(null),c({...o,lock:z,arranged:{...o.arranged,lock:!0}}),A.saveWidgets("lock",z).then(Q=>(c(Q),i.reload(),!0),Q=>(c(q),m(`Couldn't save the lock screen's widgets: ${Q instanceof Error?Q.message:String(Q)}`),!1))},C=(z,q)=>{const Q=y.slice(),[ce]=Q.splice(z,1);Q.splice(z+q,0,ce),S(Q)},$=(z,q)=>{const Q=k.get(z);!Q||N||S([...y,{key:uA(),widget:z,size:Q.sizes.includes("small")?"small":Q.sizes[0],settings:q}])},R=z=>{if(z==="find"){b({query:"",found:[],busy:!1});return}if(b(null),z==="")return t({...r,zone:null});if(z.startsWith("place:"))return t({...r,zone:{place:z.slice(6)}});const q=r.zone&&!("place"in r.zone)?r.zone:j;q&&t({...r,zone:q})},I=()=>{if(!v||v.query.trim().length<2)return;const z=v.query.trim();b({query:v.query,found:[],busy:!0}),A.findPlace(z).then(({found:q})=>{var Te;const Q=q.filter(Le=>Le.timezone);if(Q.length===0){b({query:z,found:[],busy:!1,missed:`Nothing with a timezone found for “${z}”.`});return}const ce=Q[0],Pe={label:((Te=ce.name.split(",")[0])==null?void 0:Te.trim())||ce.name,timezone:ce.timezone};x(Pe),b(null),t({...r,zone:Pe})}).catch(()=>b({query:z,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},F=new Date,_=Qx(14*60+32),E=z=>ac({dateFormat:z},()=>or(F,w,{weekday:!0})),M=(((G=l.data)==null?void 0:G.places)??[]).filter(z=>z.timezone&&z.timezone!==w),P=r.zone&&!("place"in r.zone)?r.zone:j,U=((o==null?void 0:o.home)??[]).filter(z=>k.has(z.widget)&&!k.get(z.widget).sensitive),L=((o==null?void 0:o.available)??[]).filter(z=>!z.sensitive),W=((o==null?void 0:o.available)??[]).filter(z=>z.sensitive).map(z=>z.title),O=p?y.find(z=>z.key===p):void 0,V=O?k.get(O.widget):void 0;return n.jsxs(le,{title:"What it shows",aside:"Every change is kept at once.",panel:!0,children:[n.jsxs("div",{className:"lke",children:[n.jsxs("div",{className:"lke-look",children:[n.jsx(aV,{data:i.data,phone:u}),n.jsxs("div",{className:"lke-look-foot",children:[n.jsx(sn,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:z=>h(z==="phone")}),n.jsxs("span",{className:"lke-look-note",children:["As it shows now",(Z=i.data)!=null&&Z.focus?", with your focus on":"","."]})]})]}),n.jsxs("div",{className:"lke-controls",children:[n.jsx(oe,{message:f}),n.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[n.jsx("p",{className:"lke-group-title",children:"Clock"}),n.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[n.jsx("span",{className:"wg-field-label",children:"Time"}),n.jsx(sn,{label:"Time",options:[{value:"profile",label:`Profile · ${_}`},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:z=>t({...r,time:z})})]}),n.jsx(ae,{label:"Date",children:n.jsxs("select",{value:r.date,onChange:z=>t({...r,date:z.target.value}),children:[n.jsxs("option",{value:"profile",children:["Profile · ",E(null)]}),n.jsx("option",{value:"short",children:E("short")}),n.jsx("option",{value:"long",children:E("long")}),n.jsx("option",{value:"iso",children:E("iso")}),n.jsx("option",{value:"off",children:"No date"})]})}),n.jsx(ae,{label:"A second clock",hint:"A place in another zone, under the time.",children:n.jsxs("select",{value:v?"find":wk(r.zone),onChange:z=>R(z.target.value),children:[n.jsx("option",{value:"",children:"None"}),M.map(z=>n.jsxs("option",{value:`place:${z.id}`,children:[z.label," — ",z.name.split(",")[0]]},z.id)),r.zone&&"place"in r.zone&&!M.some(z=>z.id===r.zone.place)?n.jsx("option",{value:wk(r.zone),children:"A place no longer in another zone"}):null,P?n.jsx("option",{value:`town:${P.timezone}:${P.label}`,children:P.label}):null,n.jsx("option",{value:"find",children:"Another town…"})]})}),v?n.jsxs("div",{className:"wg-field-stack",children:[n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{autoFocus:!0,value:v.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:z=>b({...v,query:z.target.value}),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),I()),z.key==="Escape"&&b(null)}}),n.jsx(T,{size:"sm",disabled:v.busy||v.query.trim().length<2,onClick:I,children:v.busy?"Finding…":"Find"})]}),v.missed?n.jsx("span",{className:"ui-field-hint",children:v.missed}):null]}):null]}),n.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[n.jsxs("div",{className:"lke-group-head",children:[n.jsxs("p",{className:"lke-group-title",children:["Widgets ",n.jsxs("span",{className:"lke-count",children:[y.length," of ",jk]})]}),N||!o?n.jsxs(T,{size:"sm",disabled:!0,children:[n.jsx(me,{name:"plus",size:12})," Add a widget"]}):n.jsx(bh,{label:"Add a widget",trigger:n.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[n.jsx(me,{name:"plus",size:12})," Add a widget"]}),items:[U.length>0?{heading:"As on Home"}:null,...U.map(z=>({label:z.label??k.get(z.widget).title,hint:"same settings",onSelect:()=>$(z.widget,z.settings)})),U.length>0?"separator":null,{heading:"Every widget"},...L.map(z=>({label:z.title,onSelect:()=>$(z.id,{})}))]})]}),o?y.length===0?n.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):n.jsx("ul",{className:"lke-list",children:y.map((z,q)=>{const Q=k.get(z.widget);return Q?n.jsx(lV,{info:Q,placement:z,index:q,count:y.length,onSize:ce=>void S(y.map(Pe=>Pe.key===z.key?{...Pe,size:ce}:Pe)),onSettings:()=>g(z.key),onMove:ce=>C(q,ce),onRemove:()=>void S(y.filter(ce=>ce.key!==z.key))},z.key):null})}):n.jsx("p",{className:"lke-empty","aria-busy":"true",children:"Reading the lock screen’s widgets…"}),n.jsxs("p",{className:"ui-field-hint",children:[N?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",W.length>0?` A sensitive widget — ${W.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),n.jsxs("p",{className:"lke-note",children:[n.jsx(me,{name:"moon",size:13}),n.jsx("span",{children:"Your focus shows at the top only while one is on. Approvals and notifications show as counts when there are some, never what they say."})]})]})]}),O&&V?n.jsx(lA,{info:V,placement:O,surface:"lock",onClose:()=>g(null),onSave:z=>S(y.map(q=>q.key===O.key?{...q,settings:z}:q)).then(q=>(q&&g(null),q)),onRemove:()=>{g(null),S(y.filter(z=>z.key!==O.key))}}):null]})}const cV=[{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],uV=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],dV=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Eg(e){if(e instanceof pe){const t=e.detail??{};return e.status===429||t.waitUntil?"Too many wrong tries. Wait a moment, then try again.":e.status===403&&typeof t.triesLeft=="number"?`${e.message} ${t.triesLeft} ${t.triesLeft===1?"try":"tries"} left.`:e.message}return"Something went wrong. Try again."}function hV({kind:e,onClose:t,onDone:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=e==="remove",g=e!=="set",v=!f&&(!g||r.length>=4)&&(p||a.length>=4&&o.length>=4),b=y=>y.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",x=y=>{if(y==null||y.preventDefault(),!v)return;if(!p&&a!==o){h("The two PINs aren’t the same.");return}m(!0),h(null),(p?A.removePin(r):A.setPin(a,g?r:void 0)).then(s).catch(N=>{m(!1),h(Eg(N))})},w=(y,k,N,S)=>n.jsx(ae,{label:y,children:n.jsx("input",{type:"password",inputMode:"numeric",autoComplete:y==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:k,onChange:C=>{h(null),N(b(C.target.value))}})});return n.jsx(xs,{title:j,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{variant:p?"danger":"accent",disabled:!v,onClick:()=>x(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:n.jsxs("form",{className:"lk-form",onSubmit:x,children:[n.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),g?w("Current PIN",r,i,!0):null,p?null:w(e==="set"?"PIN":"New PIN",a,l,!g),p?null:w("The same again",o,c,!1),u?n.jsx(K,{tone:"critical",children:u}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function fV(e){const t=Ch(),s=ue(()=>A.lockState(),[]),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=d.useRef(null),h=s.data??t.state,f=b=>{t.update(b),s.reload()},m=b=>{l(null),b.then(f).catch(j=>l(Eg(j)))},p=b=>{b&&(c(!0),l(null),A.uploadLockBackground(b).then(f).catch(j=>l(Eg(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!h)return n.jsx(le,{title:"Lock screen",panel:!0,children:n.jsx(oe,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=h.pin,v=(b,j)=>n.jsxs("button",{type:"button",className:"lk-swatch","data-bg":b,"aria-pressed":h.background===b,"aria-label":j,title:j,onClick:()=>m(A.setLockSettings({background:b})),children:[b==="image"&&h.image?n.jsx("img",{src:h.image,alt:""}):n.jsx("span",{className:"lk-swatch-field"}),n.jsx("span",{className:"lk-swatch-label",children:j})]},b);return n.jsxs(n.Fragment,{children:[n.jsxs(le,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:g?n.jsxs(T,{size:"sm",onClick:()=>t.lockNow(),children:[n.jsx(me,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[n.jsxs(se,{divided:!0,gap:"lg",children:[n.jsx("p",{className:"lk-honest ui-section",children:"A privacy screen over this dashboard, on every device signed in to it: it locks when nobody has used it for a while, or when you lock it, and opens with your PIN. A new browser opens locked too. It isn’t a second sign-in — anyone who can run buddi on this computer can open it without the PIN. Telegram and buddi in your coding tools carry on as before."}),n.jsx(oe,{message:a}),n.jsxs("div",{className:"lk-pref ui-section",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"PIN"}),n.jsx("div",{className:"ui-field-hint",children:g?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),g?n.jsxs(re,{children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>i("remove"),children:"Remove…"}),n.jsx(T,{size:"sm",onClick:()=>i("change"),children:"Change…"})]}):n.jsx(T,{size:"sm",variant:"accent",onClick:()=>i("set"),children:"Set a PIN"})]}),n.jsxs("div",{className:"lk-pref ui-section","data-off":g?void 0:"true","aria-disabled":g?void 0:"true",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"Lock after"}),n.jsx("div",{className:"ui-field-hint",children:g?n.jsxs(n.Fragment,{children:["Nobody using it for this long. Lock it yourself from your menu",n.jsxs("span",{className:"lk-shortcut",children:[", or with ",n.jsx("kbd",{className:"lk-kbd",children:t.shortcut})]}),"."]}):"Set a PIN first."})]}),n.jsx(sn,{label:"Lock after",options:uV,value:g?dV(h):"",onChange:b=>{g&&m(A.setLockSettings({delayMinutes:b==="never"?null:Number(b)}))}})]}),n.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"Background"}),n.jsx("div",{className:"ui-field-hint",children:"Behind the time and your widgets, on every device. A picture is kept as a JPEG of at most 2560 pixels, without its location or other details."})]}),n.jsxs("div",{className:"lk-swatches",role:"group","aria-label":"Background",children:[cV.map(b=>v(b.id,b.label)),h.image?v("image","Your picture"):null,n.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o?"true":void 0,children:[n.jsx("input",{ref:u,type:"file",accept:"image/jpeg,image/png",className:"lk-sr",disabled:o,onChange:b=>{var j;return p((j=b.target.files)==null?void 0:j[0])}}),n.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:n.jsx(me,{name:"plus",size:16})}),n.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":h.image?"Replace":"Your picture"})]})]}),h.image?n.jsx(re,{align:"end",children:n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>m(A.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?n.jsx(hV,{kind:r,onClose:()=>i(null),onDone:b=>{i(null),f(b)}}):null]}),n.jsx(oV,{clock:h.clock,onClock:b=>m(A.setLockSettings({clock:b})),version:`${h.background}:${h.image??""}:${JSON.stringify(h.clock??null)}`})]})}const rm=60;function CT(e){return e instanceof pe?e.message:"Something went wrong. Try again."}function mV(e,t,s=Date.now()){const r=`made ${or(new Date(e.createdAt),t,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${He(e.lastUsedAt,s)}`:"never used"}`}function pV({onClose:e,onMade:t}){const[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),m=!i&&s.trim()!==""&&s.trim().length<=rm,p=g=>{g==null||g.preventDefault(),m&&(a(!0),o(null),A.createApiToken(s.trim()).then(v=>{u({token:v.token,name:v.apiToken.name}),t()}).catch(v=>o(CT(v))).finally(()=>a(!1)))};if(c){const g=()=>{var v;(v=navigator.clipboard)==null||v.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return n.jsx(xs,{title:`Token for ${c.name}`,onClose:e,foot:n.jsx(T,{variant:"accent",onClick:e,children:"Done"}),children:n.jsxs("div",{className:"at-form",children:[n.jsxs("div",{className:"at-secret",children:[n.jsx("code",{className:"at-secret-text","aria-label":"The token",children:c.token}),n.jsx(T,{size:"sm",onClick:g,children:h?"Copied":"Copy"})]}),n.jsx(K,{tone:"warning",title:"Copy it now",children:"buddi keeps only a fingerprint of it, so it can’t show it again. Lost it? Revoke it and make another."}),n.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),n.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return n.jsx(xs,{title:"Make a token",onClose:e,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:e,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!m,onClick:()=>p(),children:"Make token"})]}),children:n.jsxs("form",{className:"at-form",onSubmit:p,children:[n.jsx("p",{className:"at-text",children:"It acts as you on buddi’s HTTP API. Anything a gated tool does still waits for your approval here or on Telegram."}),n.jsx(ae,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${rm} characters.`,children:n.jsx("input",{autoFocus:!0,value:s,maxLength:rm,placeholder:"Home Assistant",onChange:g=>{o(null),r(g.target.value)}})}),l?n.jsx(K,{tone:"critical",children:l}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function gV({token:e,onClose:t,onRevoked:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.revokeApiToken(e.id).then(()=>{s(),t()}).catch(c=>{i(!1),l(CT(c))})};return n.jsxs(xs,{title:`Revoke “${e.name}”?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:r,onClick:o,children:"Revoke"})]}),children:[n.jsx("p",{className:"at-text",children:"A request carrying it is refused from now on. Whatever uses it stops working until you give it a new token."}),a?n.jsx(K,{tone:"critical",children:a}):null]})}function xV({timezone:e}){var o;const t=ue(()=>A.apiTokens(),[]),[s,r]=d.useState(!1),[i,a]=d.useState(null),l=((o=t.data)==null?void 0:o.tokens)??[];return n.jsxs(se,{gap:"lg",children:[n.jsx("p",{className:"ui-page-lede",children:"Let a script or another program use buddi without the dashboard. A token acts as you, minus the decisions only you make here."}),n.jsx(oe,{message:t.error?"Couldn’t read the API tokens.":null}),n.jsx(le,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:n.jsx(T,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:t.data&&l.length===0?n.jsxs(ge,{title:"No tokens yet.",children:["Make one here, or in a terminal with ",n.jsx("code",{className:"mono",children:"buddi api-token create <name>"}),"."]}):n.jsx(ft,{children:l.map(c=>n.jsx(ct,{lead:n.jsx(hi,{icon:"key"}),title:c.name,sub:mV(c,e),side:n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>a(c),children:"Revoke…"})},c.id))})}),n.jsxs(le,{title:"What a token can’t do",panel:!0,children:[n.jsxs("ul",{className:"at-cant",children:[n.jsx("li",{children:"Approve anything, or make a change where your click is the approval. It can reject."}),n.jsx("li",{children:"Change what an agent may do without asking: its tools, who it hands work to, a connection given out, an “Always”."}),n.jsx("li",{children:"Install or run code buddi hasn’t run before: plugins, upgrades, program connections."}),n.jsx("li",{children:"Change how buddi is reached or unlocked — PIN, Tailscale, Telegram pairing, other tokens — or restore a backup."}),n.jsx("li",{children:"Read or store a secret: owner secrets, model account keys, the backup passphrase."})]}),n.jsxs("p",{className:"at-foot",children:["In a terminal: ",n.jsx("code",{className:"mono",children:"buddi api-token create"}),", ",n.jsx("code",{className:"mono",children:"list"}),", ",n.jsx("code",{className:"mono",children:"revoke"}),". Every route, and which a token may call: docs/api.md."]})]}),s?n.jsx(pV,{onClose:()=>r(!1),onMade:()=>t.reload()}):null,i?n.jsx(gV,{token:i,onClose:()=>a(null),onRevoked:()=>t.reload()}):null]})}function vV({embedded:e}){const{data:t,error:s,reload:r}=ue(()=>A.owner(),[]);return n.jsxs(An,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(oe,{message:s}),t?n.jsxs(se,{gap:"lg",children:[n.jsx(yV,{initial:t,onSaved:r}),n.jsx(SV,{initial:t})]}):null]})}const ET=new Date(Date.UTC(2026,9,1,14,5));function jV(){return[["",`Auto (${ac({timeFormat:null},()=>Ut(ET,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function wV(){return[["",`Auto (${ac({dateFormat:null},()=>or(ET,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function yV({initial:e,onSaved:t}){const[s,r]=d.useState(e.preferredName??""),[i,a]=d.useState(e.timezone??""),[l,o]=d.useState(e.timeFormat??""),[c,u]=d.useState(e.dateFormat??""),[h,f]=d.useState(e.language??""),[m,p]=d.useState(e.about??""),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(null);d.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??"")},[e]);const y=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??""),k=async()=>{v(!0),w(null);try{const C=await A.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:h.trim()===""?null:h.trim(),about:m.trim()===""?null:m.trim()});qx({timeFormat:C.timeFormat??null,dateFormat:C.dateFormat??null}),window.dispatchEvent(new Event(vp)),j(!0),t()}catch(C){w(C instanceof pe?C.message:String(C))}finally{v(!1)}},N=e.zones.length>0?e.zones:[e.detectedTimezone],S=C=>$=>{j(!1),C($)};return n.jsx(le,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:n.jsxs(n.Fragment,{children:[b&&!y?n.jsx("span",{className:"muted",children:"Saved"}):null,n.jsx(T,{variant:"accent",disabled:!y||g,onClick:()=>void k(),children:g?"Saving…":"Save"})]}),children:n.jsxs(se,{divided:!0,gap:"lg",children:[n.jsx(le,{title:"Name, time and language",children:n.jsxs(Is,{children:[n.jsx(ae,{label:"What the agents call you",children:n.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:C=>S(r)(C.target.value)})}),n.jsx(ae,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:C=>S(a)(C.target.value),children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),N.map(C=>n.jsx("option",{value:C,children:C},C))]})}),n.jsx(ae,{label:"Time",children:n.jsx("select",{value:l,onChange:C=>S(o)(C.target.value),children:jV().map(([C,$])=>n.jsx("option",{value:C,children:$},C))})}),n.jsx(ae,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:n.jsx("select",{value:c,onChange:C=>S(u)(C.target.value),children:wV().map(([C,$])=>n.jsx("option",{value:C,children:$},C))})}),n.jsx(ae,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:h,maxLength:40,placeholder:"English, français…",onChange:C=>S(f)(C.target.value)})})]})}),n.jsxs(le,{title:"About you",children:[n.jsx(ae,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:n.jsx("textarea",{rows:4,maxLength:1e3,value:m,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:C=>S(p)(C.target.value)})}),x?n.jsx(K,{tone:"critical",children:x}):null]})]})})}const bV=["Home","Work"];function kV(e){const t=e.trim().toLowerCase();return t==="home"?"home":t==="work"?"briefcase":"pin"}function yk({label:e,empty:t}){return n.jsx("span",{className:"place-glyph","data-empty":t?"true":void 0,"aria-hidden":"true",children:n.jsx(me,{name:kV(e),size:18})})}function NV(e){var s;const t=((s=e.name.split(",").pop())==null?void 0:s.trim())??"";return e.address?t&&!e.address.toLowerCase().includes(t.toLowerCase())?`${e.address} · ${t}`:e.address:e.name}function SV({initial:e}){var c;const[t,s]=d.useState(e.places??[]);d.useEffect(()=>s(e.places??[]),[e]);const[r,i]=d.useState(null),a=e.timezone??e.detectedTimezone,l=bV.filter(u=>!t.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[t]);return n.jsxs(le,{title:"Places",aside:"the front desk, and plugins you allow",actions:n.jsx(T,{size:"sm",onClick:()=>i({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[n.jsxs(ft,{children:[t.map(u=>n.jsx(ct,{label:`${u.label}: edit`,onClick:()=>i({place:u,label:u.label}),lead:n.jsx(yk,{label:u.label}),title:u.label,sub:NV(u),side:u.timezone&&u.timezone!==a?n.jsxs(ve,{children:[Ut(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>n.jsx(ct,{label:`${u}: add`,onClick:()=>i({label:u}),lead:n.jsx(yk,{label:u,empty:!0}),title:n.jsx("span",{className:"muted",children:u}),sub:"Not set",side:n.jsx(T,{size:"sm",onClick:h=>{h.stopPropagation(),i({label:u})},children:"Add"})},u))]}),n.jsx("p",{className:"place-note",children:"Only the town is looked up, on Open-Meteo, to find where it is and its timezone. The address stays on this computer."}),r?n.jsx(CV,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>i(null),onSaved:u=>{s(u),i(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function CV({editing:e,zones:t,onClose:s,onSaved:r}){const i=e.place,[a,l]=d.useState(e.label),[o,c]=d.useState((i==null?void 0:i.address)??""),[u,h]=d.useState(i?[{name:i.name,latitude:i.latitude,longitude:i.longitude,...i.timezone?{timezone:i.timezone}:{}}]:null),[f,m]=d.useState(0),[p,g]=d.useState((i==null?void 0:i.timezone)??""),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState((i==null?void 0:i.address)??""),k=u==null?void 0:u[f],N=()=>{o.trim().length<2||(b("find"),x(null),A.findPlace(o.trim()).then(I=>{var F;h(I.found),y(o.trim()),m(0),g(((F=I.found[0])==null?void 0:F.timezone)??""),I.found.length===0&&x("Nothing found by that name. Try the town, with its country.")}).catch(I=>x(I instanceof pe?I.message:String(I))).finally(()=>b(null)))},S=()=>{k&&(b("save"),x(null),A.savePlace({...i?{id:i.id}:{},label:a.trim(),address:o.trim()===""?null:o.trim(),name:k.name,latitude:k.latitude,longitude:k.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>x(I instanceof pe?I.message:String(I))).finally(()=>b(null)))},C=()=>{i&&(b("remove"),x(null),A.removePlace(i.id).then(I=>r(I.places)).catch(I=>x(I instanceof pe?I.message:String(I))).finally(()=>b(null)))},$=i?i.label:e.label?`Add ${e.label}`:"Add a place",R=p!==""&&!t.includes(p)?[p,...t]:t;return n.jsx(pt,{title:$,onClose:s,foot:n.jsxs(re,{children:[i?n.jsx(T,{variant:"danger-ghost",disabled:v!==null,onClick:C,children:v==="remove"?"Removing…":"Remove"}):null,n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!k||a.trim()===""||v!==null,onClick:S,children:v==="save"?"Saving…":"Save"})]}),children:n.jsxs(se,{gap:"lg",children:[n.jsx(ae,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:n.jsx("input",{value:a,maxLength:40,autoFocus:!e.label,onChange:I=>l(I.target.value)})}),n.jsx(ae,{label:"Address",hint:"A street address, or just the town.",action:n.jsx(T,{disabled:o.trim().length<2||v!==null,onClick:N,children:v==="find"?"Finding…":"Find"}),children:n.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!i,placeholder:"12 Elm Street, Portland, Maine",onChange:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),N())}})}),u&&u.length>0?n.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,F)=>n.jsxs("button",{type:"button",role:"radio","aria-checked":F===f,className:"place-option","data-on":F===f?"true":void 0,onClick:()=>{m(F),g(I.timezone??"")},children:[n.jsx("span",{className:"place-radio","aria-hidden":"true"}),n.jsxs("span",{className:"place-option-text",children:[n.jsx("span",{className:"place-option-name",children:I.name}),n.jsxs("span",{className:"place-option-sub",children:[I.latitude.toFixed(2),", ",I.longitude.toFixed(2),I.timezone?` · ${I.timezone}`:""]})]})]},`${I.latitude},${I.longitude}`))}):n.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),i&&u&&o.trim()!==w?n.jsx("p",{className:"place-note-inline",children:"The address changed. Find it again to move the pin, or save to keep it where it is."}):null,n.jsx(ae,{label:"Its timezone",hint:k?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:n.jsxs("select",{value:p,disabled:!k,onChange:I=>g(I.target.value),children:[n.jsx("option",{value:"",children:"Not known"}),R.map(I=>n.jsx("option",{value:I,children:I},I))]})}),n.jsx(oe,{message:j})]})})}const EV=2e6;function bk(e,t){const s=e.replace(/\r\n/g,`
117
- `).replace(/\n+$/,"").split(`
118
- `),r=t.replace(/\r\n/g,`
119
- `).replace(/\n+$/,"").split(`
120
- `);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>EV)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
121
- `);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(`
122
- `)}const AT={skill:"skill",policy:"rule",change:"change to itself"};function AV(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 Ag(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function TV(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Ag(s.current??""));return Ag(t).filter(i=>!r.has(i))}function RV(e){const t=a=>a.kind==="policy"&&a.ruleKind?`${String(a.payload.plugin??"")}\0${a.ruleKind}`:null,s=new Map;for(const a of e){const l=t(a);l&&s.set(l,(s.get(l)??0)+1)}const r=new Map,i=[];for(const a of e){const l=t(a);if(!l||(s.get(l)??0)<2){i.push(a);continue}let o=r.get(l);o||(o={key:l,label:a.ruleKindLabel||a.ruleKind||"Rules",plugin:String(a.payload.plugin??""),cards:[]},r.set(l,o),i.push(o)),o.cards.push(a)}return i}function $V(e){return"cards"in e}function kk(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function IV({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=ue(()=>A.proposals(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState({}),p=async(x,w,y=!1)=>{l(null),c(null),h(x),m(({[x]:k,...N})=>N);try{c(await w()),i()}catch(k){const N=k instanceof Error?k.message:String(k);y?m(S=>({...S,[x]:N})):l(N)}finally{h(null)}},g=EE(),v=((s==null?void 0:s.open)??[]).filter(x=>kk(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>kk(x,t)),j=x=>n.jsx(LV,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:w=>void p(x.id,async()=>{const y=await A.keepProposal(x.id,w);return`${x.title}: ${y.note}`},!0),onDiscard:w=>void p(x.id,async()=>(await A.discardProposal(x.id,w),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id);return n.jsxs(An,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Keep what is right, correct what is nearly right, discard the rest. A few rules apply themselves, where their plugin allows it (one you always keep, one that only quiets mail sent to many); its own page lists them, with Undo.",children:[n.jsx(oe,{message:r??a}),t?n.jsxs(K,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:_e("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(K,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(AE,{offers:g.offers,reload:g.reload}),!s||v.length===0?n.jsx(le,{title:"Waiting",panel:!0,children:s?t?n.jsx(cn,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(cn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(ge,{children:"Loading…"})}):n.jsx(le,{title:"Waiting",aside:`${v.length} to decide`,children:RV(v).map(x=>$V(x)?n.jsx(PV,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const w=await A.keepAllProposals(x.cards.map(y=>y.id));return`${x.label}: ${w.note}`}),card:w=>j(w)},x.key):j(x))}),b.length>0?n.jsx(le,{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(ft,{children:b.map(x=>{var w;return n.jsx(ct,{title:x.title,sub:`${x.agent}: ${MV(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((w=x.skill)!=null&&w.live)?n.jsxs(re,{align:"end",children:[n.jsx("span",{className:"muted",children:He(x.decidedAt??x.createdAt)}),n.jsx(T,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const y=x.skill;return await A.removeSkill(x.agent,y.name),`Removed ${y.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):He(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(OV,{schedule:s.digest.schedule,onSaved:i}):null]})}function PV({group:e,busy:t,onKeepAll:s,card:r}){const i=e.cards.length,a=e.cards.some(l=>l.untrusted);return n.jsx(vs,{tone:a?"warning":"accent",title:`${e.label} (${i})`,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{children:AT.policy}),n.jsx(ve,{mono:!0,children:e.plugin})]}),foot:n.jsx(re,{align:"end",children:n.jsxs(T,{variant:"accent",size:"sm",disabled:t,onClick:s,children:["Keep all (",i,")"]})}),children:n.jsxs(se,{gap:"sm",children:[n.jsxs("p",{children:[i," rules of the same kind from ",e.plugin,", each learned from your own decisions. Keep all keeps every one of them as if you had kept each, in one go."]}),n.jsx(Ct,{summary:`Show each of the ${i}`,children:n.jsx(se,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function MV(e){switch(e.state){case"kept":return e.decidedBy==="auto"?e.note??"Kept by itself.":e.kind==="skill"&&e.skill?e.skill.live?`Kept as ${e.skill.name}, version ${e.skill.version}; it loads on the agent's next run.`:`Kept; ${e.skill.name} has a newer version now (${e.skill.version}).`:e.note??"Kept.";case"discarded":return e.reason?`Discarded: ${e.reason}`:"Discarded.";case"expired":return`Expired: ${e.reason??"not decided in 30 days"}.`;default:return"Waiting."}}const DV=Array.from({length:24},(e,t)=>t),Nk=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function OV({schedule:e,onSaved:t}){const[s,r]=d.useState(e.day),[i,a]=d.useState(e.hour),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=s!==e.day||i!==e.hour,f=async()=>{o(!0),u(null);try{await A.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${Nk[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(le,{title:"Weekly digest",panel:!0,foot:n.jsx(T,{variant:"accent",disabled:l||!h,onClick:()=>void f(),children:"Save"}),children:n.jsxs(se,{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: ${He(e.next)}.`:""]}),n.jsxs(re,{children:[n.jsx(ae,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:Nk.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(ae,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:DV.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(K,{tone:c.tone,role:"status",children:c.text}):null]})})}function Sk(e,t){return e==="tools"?Ag(t).join(`
123
- `):t}function LV({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=d.useState(e.editable??""),[o,c]=d.useState(""),u=e.editable!==null&&a!==e.editable,h=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=TV(e,a);return n.jsx(vs,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{children:AT[e.kind]}),n.jsx(ve,{mono:!0,children:e.agent}),e.untrusted?n.jsx(ve,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(ve,{tone:"warning",children:"widens its tools"}):null]}),foot:n.jsxs(re,{align:"end",children:[s?n.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,n.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:t,onChange:g=>c(g.target.value)}),n.jsx(T,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(T,{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(se,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",He(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:el(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(K,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",n.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>n.jsx("li",{className:"mono",children:g},g))}),f.length>0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),n.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:f.map(g=>n.jsx("li",{children:n.jsx("mark",{className:"wb-diff-mark",children:g})},g))})]}):null]}):null,e.kind==="skill"?n.jsxs(n.Fragment,{children:[typeof h.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?n.jsxs(se,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.jsxs("a",{href:St(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),n.jsx(gd,{text:bk(e.skill.steps,a),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(ae,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?n.jsxs(n.Fragment,{children:[p.length>0?n.jsxs(K,{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(K,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(gd,{text:bk(Sk(m.part,m.current),Sk(m.part,a)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?n.jsx(Ct,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx($t,{children:h.before})}):null,n.jsx(ae,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?n.jsx(nn,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:AV(h.matcher??{})})},{label:"Does",value:String(h.action??"")},{label:"Learned from",value:(()=>{const g=Array.isArray(h.verdicts)?h.verdicts.length:0;return`${g} ${g===1?"decision":"decisions"}`})()}]}):null]})})}function _V(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 FV({start:e,onPick:t,onClose:s}){const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(""),u=(p,g=!1)=>{l(null),A.pluginFolders(p).then(v=>{i(v),c("")}).catch(v=>{g&&p!==void 0?u(void 0):l(v instanceof pe?v.message:String(v))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?_V(r):[];return n.jsxs(pt,{title:"Choose the folder",onClose:s,foot:n.jsxs(re,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{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(B1,{label:"Folder",items:m.map((p,g)=>g===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,n.jsx(U1,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(oe,{message:a}),r?f.length===0?n.jsx(ge,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(lt,{flush:!0,children:n.jsx(ft,{children:f.map(p=>n.jsx(ct,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(hi,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(ve,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(ge,{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 zV="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 Ck(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(me,{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:_e("connections"),children:"Connections"})]})]})}const UV=1500,BV={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."},WV="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",TT=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],RT="buddi.plugins.install-mode";function HV(){try{const e=window.localStorage.getItem(RT);if(TT.some(t=>t.value===e))return e}catch{}return"npm"}function KV(e){try{window.localStorage.setItem(RT,e)}catch{}}const du=".tgz",Cr=(e,t,s)=>`${e} ${e===1?t:s}`;function $T(e){const t=[];return e.tools>0&&t.push(Cr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Cr(e.views,"view","views")),e.agents>0&&t.push(`${Cr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function Tg(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 IT(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function pj(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function PT(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Ah({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 Rg({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 MT(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function gj(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 pi=e=>e instanceof pe?e.message:String(e);function VV(e){const[t,s]=d.useState(void 0),[r,i]=d.useState(null);return d.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{A.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(pi(c)),a=!0)})};l();const o=window.setInterval(l,UV);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function GV({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=Pr(a.plugin,a.id);return n.jsx(Tt,{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 DT({plugin:e}){var s;if(e.enabled===!1)return n.jsx(ve,{children:"disabled"});const t=(s=e.needs)==null?void 0:s[0];return t?n.jsxs(ve,{tone:"warning",children:["needs ",t.plugin]}):e.loaded&&e.setup?n.jsx(ve,{tone:"warning",children:"needs setup"}):e.loaded?n.jsx(ve,{tone:"good",dot:!0,children:"loaded"}):n.jsx(ve,{tone:"critical",children:"did not load"})}function xj({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(ve,{tone:"accent",children:"by buddi"}):n.jsxs(ve,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const $g=_e("plugins"),im={installed:$g,browse:`${$g}?tab=browse`};function YV({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=ue(()=>A.plugins(),[],2e4),[a,l]=d.useState(null),{job:o,error:c}=VV(a),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(()=>Vy(r));d.useEffect(()=>g(Vy(r)),[r]);const[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),[k,N]=d.useState(null),[S,C]=d.useState(!1),$=ee=>{C(!0),A.market(ee).then(N).catch(ye=>N({plugins:[],unavailable:pi(ye)})).finally(()=>C(!1))};d.useEffect(()=>{p==="browse"&&k===null&&!S&&$(!1)},[p]);const R=ee=>{h(null),m(null),l(ee)},I=ee=>h(pi(ee)),[F,_]=d.useState(!1),E=ee=>{_(!0),b(null),ee.then(ye=>{R(ye.job.id),g("installed")}).catch(I).finally(()=>_(!1))},M=d.useRef(null);d.useEffect(()=>{const ee=m_(r);if(!(ee===null||M.current===ee)){M.current=ee,g("installed"),E(A.stagePlugin(ee));try{window.history.replaceState(window.history.state,"",$g)}catch{}}},[r]);const P=ee=>ye=>{ye.preventDefault(),g(ee),b(null),s==null||s(im[ee])};d.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const U=i.data,L=(U==null?void 0:U.checkout)??!0,W=(U==null?void 0:U.installed)??[],O=ee=>k==null?void 0:k.plugins.find(ye=>ye.installed!==void 0&&(ye.installed.name??ye.name)===ee.name),V=ee=>e.some(ye=>ye.plugin===ee),X=(ee,ye)=>V(ee)?n.jsx(GV,{plugin:ee,pages:e,navigate:s,variant:ye}):void 0,G=ee=>{const ye=e.find(H=>H.plugin===ee);ye&&s&&s(Pr(ye.plugin,ye.id))},Z=ee=>{const ye=t.find(H=>H.plugin===ee);if(!(!ye||!s))return()=>s(Ji(ye.plugin,ye.id))},z=((k==null?void 0:k.plugins)??[]).filter(ee=>ee.update).length,q=(ee,ye)=>A.setPluginEnabled(ee,ye).then(H=>{tz(),y({name:ee,notes:H.notes??[]}),i.reload()}),Q=(ee,ye,H)=>A.uninstallPlugin(ee,ye?{purge:!0,confirm:H}:{}).then(Fe=>{b(null),y({name:ee,notes:Fe.notes??[]}),i.reload()}),ce=ee=>{h(null),q(ee,!0).catch(I)},Pe=(ee,ye)=>{const H=k==null?void 0:k.plugins.find(wt=>{var dt;return(((dt=wt.installed)==null?void 0:dt.name)??wt.name)===ee&&wt.installed!==void 0}),Fe=H&&ye?`${H.npm}@${ye}`:void 0;E(Fe?A.updatePlugin(ee,ye,Fe):A.updatePlugin(ee,ye))},Te=ee=>{h(null);const ye=H=>{const Fe=H.plugins.find(wt=>{var dt;return wt.name===ee||((dt=wt.installed)==null?void 0:dt.name)===ee});if(!Fe){h(`${ee} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}E(A.stagePlugin(`${Fe.npm}@${Fe.version}`))};if(k&&k.plugins.length>0)return ye(k);_(!0),A.market(!1).then(H=>{N(H),ye(H)}).catch(I).finally(()=>_(!1))},Le=(ee,ye)=>ye===void 0?void 0:ye.place==="settings"?Ji(ee,ye.id):Pr(ee,ye.id),J=ee=>{var H;if(ee.enabled===!1)return;const ye=(H=ee.needs)==null?void 0:H[0];if(ye)switch(ye.state){case"missing":return{label:`Install ${ye.plugin}`,run:()=>Te(ye.plugin)};case"disabled":return{label:`Enable ${ye.plugin}`,run:()=>ce(ye.plugin)};case"range":return{label:`Update ${ye.plugin}`,run:()=>Pe(ye.plugin)};case"setup":{const Fe=Le(ye.plugin,ye.page),wt=Fe&&s?()=>s(Fe):Z(ye.plugin);return wt?{label:`Set up ${ye.plugin}`,run:wt}:void 0}default:return{label:`See ${ye.plugin}`,run:()=>b({kind:"installed",name:ye.plugin})}}if(ee.loaded&&ee.setup){const Fe=Le(ee.name,ee.setup.page),wt=Fe&&s?()=>s(Fe):Z(ee.name);return wt?{label:"Set it up",run:wt}:void 0}},ke=n.jsxs(pc,{label:"Plugins",children:[n.jsx(tl,{href:im.installed,active:p==="installed",count:z,onClick:P("installed"),children:"Installed"}),n.jsx(tl,{href:im.browse,active:p==="browse",onClick:P("browse"),children:"Browse"})]}),ne=(U==null?void 0:U.staged)??[],Ae=n7(ne,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),de=ne.find(ee=>ee.id===Ae),Re=ne.filter(ee=>ee.id!==Ae),De=ee=>{b(null),m(ee),r7(ee),l(null),i.reload()},Ve=(v==null?void 0:v.kind)==="staged"?Re.find(ee=>ee.id===v.name):void 0,he=(v==null?void 0:v.kind)==="installed"?W.find(ee=>ee.name===v.name):void 0,ze=(v==null?void 0:v.kind)==="market"?k==null?void 0:k.plugins.find(ee=>ee.name===v.name):void 0,Ge=w&&!(he&&he.name===w.name)&&w.notes.length>0?w.notes:null,Ye=Ve?n.jsx(e7,{staged:Ve,onClose:()=>b(null),onInstalled:De,onInstallFirst:Te,onGone:()=>{b(null),i.reload()}},Ve.id):he?n.jsx(d7,{plugin:he,listing:O(he),notes:(w==null?void 0:w.name)===he.name?w.notes:null,canOpen:V(he.name)&&he.enabled!==!1,onOpen:()=>G(he.name),onClose:()=>b(null),onDisable:()=>x({kind:"disable",name:he.name}),onEnable:()=>ce(he.name),onRemove:()=>x({kind:"remove",name:he.name}),onUpdate:ee=>Pe(he.name,ee),onSettings:he.enabled===!1?void 0:Z(he.name),firstStep:J(he),busy:F}):ze?n.jsx(j7,{entry:ze,canOpen:ze.installed!==void 0&&V(ze.installed.name??ze.name),onOpen:()=>{var ee;return G(((ee=ze.installed)==null?void 0:ee.name)??ze.name)},onClose:()=>b(null),onInstall:()=>E(A.stagePlugin(`${ze.npm}@${ze.version}`)),onUpdate:ee=>{var ye;return Pe(((ye=ze.installed)==null?void 0:ye.name)??ze.name,ee)},busy:F}):null,nt=j?W.find(ee=>ee.name===j.name):void 0,Pt=j?n.jsx(h7,{kind:j.kind,name:j.name,canDisable:(nt==null?void 0:nt.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>q(j.name,!1).then(()=>x(null)),onRemove:(ee,ye)=>Q(j.name,ee,ye).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(p==="browse")return n.jsxs(se,{gap:"lg",children:[n.jsx(Ck,{}),ke,n.jsx(oe,{message:u}),n.jsx(w7,{market:k,loading:S,busy:F,onRetry:()=>$(!0),onOpen:ee=>b({kind:"market",name:ee.name}),onInstall:ee=>E(A.stagePlugin(`${ee.npm}@${ee.version}`)),onUpdate:(ee,ye)=>{var H;return Pe(((H=ee.installed)==null?void 0:H.name)??ee.name,ye)}}),Ye]});const un=(U==null?void 0:U.builtIn)??[];return n.jsxs(se,{gap:"lg",children:[n.jsx(Ck,{}),ke,n.jsx(oe,{message:i.error??u??c}),U!=null&&U.unavailable?n.jsx(K,{tone:"warning",children:U.unavailable}):null,Ge?n.jsx(K,{role:"status",children:Ge.join(" ")}):null,n.jsx(qV,{trust:(U==null?void 0:U.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:R,onFailed:h}),de?n.jsx(JV,{staged:de,onInstalled:De,onGone:()=>i.reload(),onInstallFirst:Te},de.id):null,Re.length>0?n.jsx(lt,{flush:!0,title:"Waiting for you",tool:Cr(Re.length,"package","packages"),children:n.jsx("div",{className:"plugins-rows",children:n.jsx(ft,{children:Re.map(ee=>n.jsx(ZV,{staged:ee,onReview:()=>{LT(ee),b({kind:"staged",name:ee.id})},onReject:()=>{h(null),A.rejectStaged(ee.id).then(()=>i.reload()).catch(I)}},ee.id))})})}):null,f||U!=null&&U.restartNeeded?n.jsx(s7,{checkout:L,name:f}):null,n.jsx(a7,{list:W,firstStepFor:J}),n.jsx(lt,{flush:!0,title:"Installed",tool:U?Cr(W.length,"plugin","plugins"):void 0,children:U?W.length===0?n.jsx(ge,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(ft,{children:W.map(ee=>n.jsx(o7,{plugin:ee,listing:O(ee),open:ee.enabled===!1?void 0:X(ee.name,"ghost"),canOpen:V(ee.name)&&ee.enabled!==!1,busy:F,onDetails:()=>b({kind:"installed",name:ee.name}),onOpen:()=>G(ee.name),onSettings:ee.enabled===!1?void 0:Z(ee.name),onDisable:()=>x({kind:"disable",name:ee.name}),onEnable:()=>ce(ee.name),onRemove:()=>x({kind:"remove",name:ee.name}),onUpdate:ye=>Pe(ee.name,ye),firstStep:J(ee)},ee.name))})}):n.jsx(ge,{children:"Loading…"})}),un.length>0?n.jsx(f7,{plugins:un,openFor:X}):null,Ye,Pt]})}function qV({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=d.useState(HV),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(!1),w=d.useRef(null),y=C=>i(pi(C)),k=C=>{l(C),KV(C),g(null)},N=()=>{h(!0),A.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(du)){m(null),g(`${C.name} is not a ${du}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),A.uploadPlugin(C).then($=>r($.job.id)).catch(y).finally(()=>h(!1))}};return n.jsxs(lt,{title:"Add a plugin",actions:n.jsx(sn,{label:"Where it comes from",options:TT,value:a,onChange:k}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":v?"over":p?"refused":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var $,R;C.preventDefault(),b(!1),S((R=($=C.dataTransfer)==null?void 0:$.files)==null?void 0:R[0])},children:[n.jsx(me,{name:"drop",size:20}),n.jsx("span",{className:"plugins-drop-text",children:p??(f?`${f} — reading it.`:n.jsxs(n.Fragment,{children:["Drop a ",n.jsx("span",{className:"mono",children:du})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(T,{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:du,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var $;S(($=C.target.files)==null?void 0:$[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(re,{valign:"end",children:[n.jsx(ae,{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(T,{onClick:()=>x(!0),children:"Browse…"}):null,n.jsx(T,{variant:"accent",disabled:s||u||o.trim()==="",onClick:N,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[BV[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(K,{tone:"warning",children:e})})]}),j?n.jsx(FV,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function QV({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?gj([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(ve,{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 OT(e,t,s){const[r,i]=d.useState(e.plan??null),[a,l]=d.useState(!1),[o,c]=d.useState(null);return{plan:r,busy:a,failed:o,approve:f=>{l(!0),c(null),A.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?t(e.name):m.plan&&i(m.plan)}).catch(m=>c(pi(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),A.rejectStaged(e.id).then(()=>s()).catch(f=>c(pi(f))).finally(()=>l(!1))}}}function LT(e){e.openedAt||A.openedStaged(e.id).catch(()=>{})}function XV({staged:e,onInstallFirst:t}){return n.jsxs("span",{className:"plugins-requires",children:[(e.requires??[]).map(s=>n.jsxs("span",{className:"plugins-require",children:[n.jsxs("span",{title:s.range,children:[n.jsx("span",{className:"mono",children:s.plugin})," ",s.rangeWords??s.range]}),s.state==="ok"?n.jsx("span",{className:"plugins-require-ok",children:s.installed?`${s.installed} is here`:"here"}):s.state==="missing"?n.jsxs(n.Fragment,{children:[n.jsx(ve,{tone:"warning",children:"not installed"}),t?n.jsxs(T,{size:"sm",onClick:()=>t(s.plugin),children:["Install ",s.plugin," first"]}):null]}):n.jsx(ve,{tone:"warning",children:s.state==="disabled"?"disabled here":s.state==="range"?`${s.installed??"another version"} is here`:s.state==="failed"?"did not load here":"waiting here"})]},s.plugin)),(e.requires??[]).some(s=>s.state!=="ok")?n.jsx("span",{className:"muted",children:"It installs either way, and waits — tools and widgets off, nothing lost — until each is here and set up."}):null]})}function _T({staged:e,inSheet:t,onInstallFirst:s}){var i;const r=e.dependencies;return n.jsxs("div",{className:"plugins-staged","data-in":t?"sheet":void 0,children:[n.jsx("div",{className:"plugins-facts",children:n.jsx(nn,{items:[...e.author?[{label:"By",value:n.jsx(Ah,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Tg(e.source)},{label:"Published by",value:pj(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Tg(e.previousSource)}`}]:e.source.kind==="directory"&&((i=e.previous)==null?void 0:i.version)===e.version?[{label:"Reinstalls",value:`${e.version}, the same version, its files read again from the folder`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?n.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:r.count===0?"none":`${r.count}${r.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${r.withScripts.join(", ")}`}`},{label:"What it reaches",value:n.jsx(QV,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:n.jsx(XV,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:n.jsx(Rg,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(Rg,{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(nn,{items:[{label:"Schema it owns",value:e.claims.schema?n.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":n.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function FT({plan:e,busy:t,onReject:s,onInstallAnyway:r}){return n.jsxs(vs,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(ve,{tone:"warning",children:"read this first"}),foot:n.jsxs(re,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",disabled:t,onClick:s,children:"Not this one"}),n.jsx(T,{variant:"danger",disabled:t,onClick:r,children:"Install anyway"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),n.jsx("ul",{className:"plugins-drift",children:e.drift.map(i=>n.jsx("li",{children:i},i))}),n.jsx(zT,{unlocks:e.agents??[]})]})}function JV({staged:e,onInstalled:t,onGone:s,onInstallFirst:r}){const{plan:i,busy:a,failed:l,approve:o,reject:c}=OT(e,t,s);d.useEffect(()=>LT(e),[e.id]);const u=(i==null?void 0:i.drift)??[];return n.jsxs(se,{gap:"sm",children:[n.jsxs(vs,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(ve,{children:"read, not installed"}),foot:n.jsxs(re,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",disabled:a,onClick:c,children:"Not this one"}),n.jsx(T,{variant:"accent",disabled:a||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[n.jsx(oe,{message:l}),n.jsx(_T,{staged:e,onInstallFirst:r})]}),i&&u.length>0?n.jsx(FT,{plan:i,busy:a,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function ZV({staged:e,onReview:t,onReject:s}){const r=He(e.createdAt);return n.jsx(ct,{onClick:t,label:`${e.name}: review`,lead:n.jsx(hi,{svg:void 0}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${IT(e.source)}${r?` · read ${r}`:""}`,side:n.jsxs("span",{className:"plugins-side",children:[n.jsxs("span",{className:"plugins-wait-extra",children:[n.jsx(ve,{children:"read, not installed"}),n.jsx(T,{size:"sm",variant:"ghost",onClick:sl(s),children:"Not this one"})]}),n.jsx(T,{size:"sm",onClick:sl(t),children:"Review"})]})})}function e7({staged:e,onClose:t,onInstalled:s,onGone:r,onInstallFirst:i}){const{plan:a,busy:l,failed:o,approve:c,reject:u}=OT(e,s,r),h=(a==null?void 0:a.drift)??[];return n.jsxs(pt,{title:n.jsx(wj,{svg:void 0,name:e.name,version:e.version,by:e.author?n.jsx(Ah,{author:e.author}):pj(e.source,e.publisher),pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(ve,{children:"read, not installed"})]})}),onClose:t,foot:n.jsxs(re,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),n.jsx(T,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[n.jsx(oe,{message:o}),n.jsx(_T,{staged:e,inSheet:!0,onInstallFirst:i}),a&&h.length>0?n.jsx(FT,{plan:a,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const t7=10*60*1e3;function n7(e,t,s=Date.now()){if(t&&e.some(a=>a.id===t))return t;const r=[...e].sort((a,l)=>(l.createdAt??"").localeCompare(a.createdAt??""))[0];if(!(r!=null&&r.createdAt))return null;const i=s-Date.parse(r.createdAt);return Number.isFinite(i)&&i<t7?r.id:null}function s7({checkout:e,name:t}){const[s,r]=d.useState(!1),[i,a]=d.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(se,{gap:"sm",children:[n.jsx(oe,{message:i}),n.jsxs(K,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(T,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),A.serviceAction("restart").catch(o=>a(pi(o))).finally(()=>r(!1))},children:"Restart to load it"}),children:[l," ",e?WV:`${t?"Its tools appear":"It takes effect"} once buddi restarts. That closes this dashboard for a few seconds.`]})]})}const vj="buddi.plugins.justInstalled";function r7(e){try{window.sessionStorage.setItem(vj,e)}catch{}}function i7(){try{return window.sessionStorage.getItem(vj)}catch{return null}}function a7({list:e,firstStepFor:t}){var u;const[s,r]=d.useState(()=>i7()),i=s?e.find(h=>h.name===s):void 0,a=i!==void 0&&(i.loaded||i.needs!==void 0),l=a&&(i.needs!==void 0||i.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(vj)}catch{}r(null)};if(d.useEffect(()=>{a&&!l&&o()},[a,l]),!i||!l)return null;const c=t(i);return n.jsx(K,{tone:"accent",role:"status",action:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?n.jsx(T,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:i.needs?`${i.name} is installed and waits. ${jj(i)}.`:`${i.name} is loaded. First: ${((u=i.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const sl=e=>t=>{t.stopPropagation(),e()},l7=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function jj(e){var t;return e.needs&&e.needs.length>0?e.needs.map(s=>s.state==="setup"&&s.note?`${s.words}: ${s.note}`:s.words).join(" · "):((t=e.setup)==null?void 0:t.note)??"Not set up yet. Its settings say what it needs."}function o7({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=l7(e),v=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return n.jsx(ct,{onClick:a,label:`${e.name}: details`,dimmed:p,lead:n.jsx(hi,{svg:t==null?void 0:t.iconSvg}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version}),g>0?n.jsxs("span",{className:"plugins-ask",children:[Cr(g,"agent","agents")," to accept"]}):null]}),sub:v?n.jsx("span",{className:"plugins-sub","data-tone":"warning",children:jj(e)}):`by ${PT(e)} · from ${IT(e.source)} · ${$T(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[v&&m?n.jsx(T,{size:"sm",onClick:sl(m.run),children:m.label}):null,t!=null&&t.update?n.jsxs(T,{size:"sm",disabled:i,onClick:sl(()=>f(t.update)),children:["Update to ",t.update]}):null,v?null:s,!v&&!r&&o?n.jsx(T,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,n.jsx(DT,{plugin:e}),n.jsx(bh,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!i?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>f()}:null,p?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const c7={"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 zT({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(le,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(ft,{children:t.map(s=>n.jsx(u7,{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:Nt,children:"on the Agents page"}),"."]})]})}function u7({plugin:e,unlock:t}){const s=Hv(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=c7[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(ct,{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(ve,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(T,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(oe,{message:s.failure}),s.created?n.jsx(SE,{agent:s.created}):null]})}function wj({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(hi,{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 d7({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){var x,w;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",v=(t==null?void 0:t.summary)??e.description,b=(e.network??((w=(x=t==null?void 0:t.claims)==null?void 0:x.manifest)==null?void 0:w.network)??[]).map(y=>y.host),j=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(pt,{title:n.jsx(wj,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(Ah,{author:e.author}):PT(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(xj,{entry:t})]}):null," · ",n.jsx(DT,{plugin:e})]})}),onClose:o,foot:n.jsxs(re,{children:[n.jsx(T,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(Bt,{}),l?n.jsx(T,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(T,{onClick:a,children:"Open"}):null,p?n.jsx(T,{onClick:u,children:"Enable"}):n.jsx(T,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(T,{variant:"accent",disabled:i,onClick:()=>f(t.update),children:["Update to ",t.update]}):n.jsx(T,{disabled:i,onClick:()=>f(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error?n.jsx(K,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(K,{role:"status",children:s.join(" ")}):null,p?n.jsx(K,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,!p&&e.needs&&e.needs.length>0?n.jsxs(K,{tone:"warning",action:m?n.jsx(T,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",jj(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?n.jsxs(K,{tone:"warning",action:m?n.jsx(T,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,v?n.jsx("p",{className:"plugins-summary-full",children:v}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(nn,{items:[{label:"From",value:Tg(e.source)},...g?[]:[{label:"Published by",value:pj(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(Rg,{value:e.integrity})},{label:"Installed",value:He(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:$T(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:MT(b)}]:[],...j?[{label:"Reaches in buddi",value:gj(j)}]:[]]})}),n.jsx(zT,{plugin:e.name,unlocks:e.unlocks})]})}function h7({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=j=>{m(!0),g(null),j().catch(x=>g(pi(x))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(xs,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:f,onClick:()=>v(a),children:"Disable"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),n.jsx(oe,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(xs,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(T,{variant:"ghost",size:"sm",disabled:f,onClick:i,children:"Disable instead"}):null,n.jsx(Bt,{}),n.jsx(T,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:f||!b,onClick:()=>v(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",t," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),n.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:j=>{c(j.target.checked),h("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(ae,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:j=>h(j.target.value)})}):null]}),n.jsx(oe,{message:p})]})}function f7({plugins:e,openFor:t}){return n.jsxs(Ct,{boxed:!0,summary:`Ships with buddi · ${Cr(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"),Cr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const m7=[{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 p7(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function g7({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 x7({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(vs,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(hi,{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(xj,{entry:e}),e.installed?n.jsxs(ve,{children:["installed ",e.installed.version]}):null,n.jsx(Bt,{}),e.update?n.jsxs(T,{size:"sm",disabled:t,onClick:sl(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(T,{size:"sm",variant:"accent",disabled:t,onClick:sl(r),children:"Install"})]})]})}function v7(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 j7({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,v,b,j,x,w;const o=(m=e.screenshots)==null?void 0:m[0],c=(((g=(p=e.claims)==null?void 0:p.manifest)==null?void 0:g.network)??[]).map(y=>y.host),u=v7(e),h=((j=(b=(v=e.claims)==null?void 0:v.manifest)==null?void 0:b.agents)==null?void 0:j.length)??0,f=(w=(x=e.claims)==null?void 0:x.package)==null?void 0:w.dependencies;return n.jsxs(pt,{title:n.jsx(wj,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(Ah,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(xj,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(ve,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(re,{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(Bt,{}),t?n.jsx(T,{onClick:r,children:"Open"}):null,e.update?n.jsxs(T,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(T,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:A.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(nn,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Cr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:MT(c)},{label:"Reaches in buddi",value:gj(e.usesWords??[])},...f?[{label:"Dependencies",value:f.count===0?"none":`${f.count}${f.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${f.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:n.jsxs(n.Fragment,{children:[e.license??"not stated"," · ",n.jsx(g7,{pricing:e.pricing})]})}]})})]})}function w7({market:e,loading:t,busy:s,onRetry:r,onOpen:i,onInstall:a,onUpdate:l}){const[o,c]=d.useState(""),[u,h]=d.useState("all"),f=(e==null?void 0:e.plugins)??[],m=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...m7.filter(v=>f.some(b=>b.category===v.value))],p=f.filter(v=>u==="recommended"&&(v.trust!=="by-buddi"||v.installed)||u!=="all"&&u!=="recommended"&&v.category!==u?!1:p7(v,o)),g=o.trim();return n.jsxs(se,{gap:"lg",children:[n.jsxs(re,{children:[n.jsx(U1,{grow:!0,label:"Search plugins",value:o,placeholder:"Search plugins: weather, money, calendar…",onChange:c}),n.jsx(u4,{label:"Show",options:m,value:u,onChange:h})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(me,{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(ge,{children:"Asking withbuddi.com…"}):e.unavailable?n.jsx(K,{tone:"warning",action:n.jsx(T,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:e.unavailable}):n.jsxs(n.Fragment,{children:[e.stale?n.jsxs(K,{tone:"warning",action:n.jsx(T,{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?` ${He(e.fetchedAt)}`:" last time","."]}):null,p.length>0?n.jsx("div",{className:"plugins-grid",children:p.map(v=>n.jsx(x7,{entry:v,busy:s,onOpen:()=>i(v),onInstall:()=>a(v),onUpdate:b=>l(v,b)},v.npm))}):n.jsx(ge,{warm:!0,title:"Nothing listed matches",children:g!==""?`No plugin on withbuddi.com mentions “${g}”.`:f.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]})]})}var xc={},y7=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},UT={},ss={};let yj;const b7=[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];ss.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};ss.getSymbolTotalCodewords=function(t){return b7[t]};ss.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};ss.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');yj=t};ss.isKanjiModeEnabled=function(){return typeof yj<"u"};ss.toSJIS=function(t){return yj(t)};var Th={};(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}}})(Th);function BT(){this.buffer=[],this.length=0}BT.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 k7=BT;function vc(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)}vc.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};vc.prototype.get=function(e,t){return this.data[e*this.size+t]};vc.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};vc.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var N7=vc,WT={};(function(e){const t=ss.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}})(WT);var HT={};const S7=ss.getSymbolSize,Ek=7;HT.getPositions=function(t){const s=S7(t);return[[0,0],[s-Ek,0],[0,s-Ek]]};var KT={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,h=null;for(let f=0;f<a;f++){o=c=0,u=h=null;for(let m=0;m<a;m++){let p=i.get(f,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,f),p===h?c++:(c>=5&&(l+=t.N1+(c-5)),h=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let h=0;h<a;h++)o=o<<1&2047|i.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const h=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),h<c&&(c=h,o=u)}return o}})(KT);var Rh={};const qr=Th,hu=[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],fu=[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];Rh.getBlocksCount=function(t,s){switch(s){case qr.L:return hu[(t-1)*4+0];case qr.M:return hu[(t-1)*4+1];case qr.Q:return hu[(t-1)*4+2];case qr.H:return hu[(t-1)*4+3];default:return}};Rh.getTotalCodewordsCount=function(t,s){switch(s){case qr.L:return fu[(t-1)*4+0];case qr.M:return fu[(t-1)*4+1];case qr.Q:return fu[(t-1)*4+2];case qr.H:return fu[(t-1)*4+3];default:return}};var VT={},$h={};const mo=new Uint8Array(512),Td=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)mo[s]=t,Td[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)mo[s]=mo[s-255]})();$h.log=function(t){if(t<1)throw new Error("log("+t+")");return Td[t]};$h.exp=function(t){return mo[t]};$h.mul=function(t,s){return t===0||s===0?0:mo[Td[t]+Td[s]]};(function(e){const t=$h;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}})(VT);const GT=VT;function bj(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}bj.prototype.initialize=function(t){this.degree=t,this.genPoly=GT.generateECPolynomial(this.degree)};bj.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=GT.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 C7=bj,YT={},ki={},kj={};kj.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var cr={};const qT="[0-9]+",E7="[A-Z $%*+\\-./:]+";let Jo="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Jo=Jo.replace(/u/g,"\\u");const A7="(?:(?![A-Z0-9 $%*+\\-./:]|"+Jo+`)(?:.|[\r
124
- ]))+`;cr.KANJI=new RegExp(Jo,"g");cr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");cr.BYTE=new RegExp(A7,"g");cr.NUMERIC=new RegExp(qT,"g");cr.ALPHANUMERIC=new RegExp(E7,"g");const T7=new RegExp("^"+Jo+"$"),R7=new RegExp("^"+qT+"$"),$7=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");cr.testKanji=function(t){return T7.test(t)};cr.testNumeric=function(t){return R7.test(t)};cr.testAlphanumeric=function(t){return $7.test(t)};(function(e){const t=kj,s=cr;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}}})(ki);(function(e){const t=ss,s=Rh,r=Th,i=ki,a=kj,l=7973,o=t.getBCHDigit(l);function c(m,p,g){for(let v=1;v<=40;v++)if(p<=e.getCapacity(v,g,m))return v}function u(m,p){return i.getCharCountIndicator(m,p)+4}function h(m,p){let g=0;return m.forEach(function(v){const b=u(v.mode,p);g+=b+v.getBitsLength()}),g}function f(m,p){for(let g=1;g<=40;g++)if(h(m,g)<=e.getCapacity(g,p,i.MIXED))return g}e.from=function(p,g){return a.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,v){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof v>"u"&&(v=i.BYTE);const b=t.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),x=(b-j)*8;if(v===i.MIXED)return x;const w=x-u(v,p);switch(v){case i.NUMERIC:return Math.floor(w/10*3);case i.ALPHANUMERIC:return Math.floor(w/11*2);case i.KANJI:return Math.floor(w/13);case i.BYTE:default:return Math.floor(w/8)}},e.getBestVersionForData=function(p,g){let v;const b=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,b);if(p.length===0)return 1;v=p[0]}else v=p;return c(v.mode,v.getLength(),b)},e.getEncodedBits=function(p){if(!a.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;t.getBCHDigit(g)-o>=0;)g^=l<<t.getBCHDigit(g)-o;return p<<12|g}})(YT);var QT={};const Ig=ss,XT=1335,I7=21522,Ak=Ig.getBCHDigit(XT);QT.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Ig.getBCHDigit(i)-Ak>=0;)i^=XT<<Ig.getBCHDigit(i)-Ak;return(r<<10|i)^I7};var JT={};const P7=ki;function rl(e){this.mode=P7.NUMERIC,this.data=e.toString()}rl.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};rl.prototype.getLength=function(){return this.data.length};rl.prototype.getBitsLength=function(){return rl.getBitsLength(this.data.length)};rl.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 M7=rl;const D7=ki,am=["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 il(e){this.mode=D7.ALPHANUMERIC,this.data=e}il.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};il.prototype.getLength=function(){return this.data.length};il.prototype.getBitsLength=function(){return il.getBitsLength(this.data.length)};il.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=am.indexOf(this.data[s])*45;r+=am.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(am.indexOf(this.data[s]),6)};var O7=il;const L7=ki;function al(e){this.mode=L7.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}al.getBitsLength=function(t){return t*8};al.prototype.getLength=function(){return this.data.length};al.prototype.getBitsLength=function(){return al.getBitsLength(this.data.length)};al.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var _7=al;const F7=ki,z7=ss;function ll(e){this.mode=F7.KANJI,this.data=e}ll.getBitsLength=function(t){return t*13};ll.prototype.getLength=function(){return this.data.length};ll.prototype.getBitsLength=function(){return ll.getBitsLength(this.data.length)};ll.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=z7.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]+`
125
- Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var U7=ll,ZT={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,h,f,m,p,g,v,b;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],g=f+p,v=l[h],b=typeof l[h]>"u",(b||v>g)&&(l[h]=g,o.push(h,g),a[h]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var j=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(j)}return a},extract_shortest_path_from_predecessor_list:function(s,r){for(var i=[],a=r;a;)i.push(a),s[a],a=s[a];return i.reverse(),i},find_path:function(s,r,i){var a=t.single_source_shortest_paths(s,r,i);return t.extract_shortest_path_from_predecessor_list(a,i)},PriorityQueue:{make:function(s){var r=t.PriorityQueue,i={},a;s=s||{};for(a in r)r.hasOwnProperty(a)&&(i[a]=r[a]);return i.queue=[],i.sorter=s.sorter||r.default_sorter,i},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var i={value:s,cost:r};this.queue.push(i),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(ZT);var B7=ZT.exports;(function(e){const t=ki,s=M7,r=O7,i=_7,a=U7,l=cr,o=ss,c=B7;function u(j){return unescape(encodeURIComponent(j)).length}function h(j,x,w){const y=[];let k;for(;(k=j.exec(w))!==null;)y.push({data:k[0],index:k.index,mode:x,length:k[0].length});return y}function f(j){const x=h(l.NUMERIC,t.NUMERIC,j),w=h(l.ALPHANUMERIC,t.ALPHANUMERIC,j);let y,k;return o.isKanjiModeEnabled()?(y=h(l.BYTE,t.BYTE,j),k=h(l.KANJI,t.KANJI,j)):(y=h(l.BYTE_KANJI,t.BYTE,j),k=[]),x.concat(w,y,k).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,x){switch(x){case t.NUMERIC:return s.getBitsLength(j);case t.ALPHANUMERIC:return r.getBitsLength(j);case t.KANJI:return a.getBitsLength(j);case t.BYTE:return i.getBitsLength(j)}}function p(j){return j.reduce(function(x,w){const y=x.length-1>=0?x[x.length-1]:null;return y&&y.mode===w.mode?(x[x.length-1].data+=w.data,x):(x.push(w),x)},[])}function g(j){const x=[];for(let w=0;w<j.length;w++){const y=j[w];switch(y.mode){case t.NUMERIC:x.push([y,{data:y.data,mode:t.ALPHANUMERIC,length:y.length},{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.ALPHANUMERIC:x.push([y,{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.KANJI:x.push([y,{data:y.data,mode:t.BYTE,length:u(y.data)}]);break;case t.BYTE:x.push([{data:y.data,mode:t.BYTE,length:u(y.data)}])}}return x}function v(j,x){const w={},y={start:{}};let k=["start"];for(let N=0;N<j.length;N++){const S=j[N],C=[];for(let $=0;$<S.length;$++){const R=S[$],I=""+N+$;C.push(I),w[I]={node:R,lastCount:0},y[I]={};for(let F=0;F<k.length;F++){const _=k[F];w[_]&&w[_].node.mode===R.mode?(y[_][I]=m(w[_].lastCount+R.length,R.mode)-m(w[_].lastCount,R.mode),w[_].lastCount+=R.length):(w[_]&&(w[_].lastCount=R.length),y[_][I]=m(R.length,R.mode)+4+t.getCharCountIndicator(R.mode,x))}}k=C}for(let N=0;N<k.length;N++)y[k[N]].end=0;return{map:y,table:w}}function b(j,x){let w;const y=t.getBestModeForData(j);if(w=t.from(x,y),w!==t.BYTE&&w.bit<y.bit)throw new Error('"'+j+'" cannot be encoded with mode '+t.toString(w)+`.
126
- Suggested mode is: `+t.toString(y));switch(w===t.KANJI&&!o.isKanjiModeEnabled()&&(w=t.BYTE),w){case t.NUMERIC:return new s(j);case t.ALPHANUMERIC:return new r(j);case t.KANJI:return new a(j);case t.BYTE:return new i(j)}}e.fromArray=function(x){return x.reduce(function(w,y){return typeof y=="string"?w.push(b(y,null)):y.data&&w.push(b(y.data,y.mode)),w},[])},e.fromString=function(x,w){const y=f(x,o.isKanjiModeEnabled()),k=g(y),N=v(k,w),S=c.find_path(N.map,"start","end"),C=[];for(let $=1;$<S.length-1;$++)C.push(N.table[S[$]].node);return e.fromArray(p(C))},e.rawSplit=function(x){return e.fromArray(f(x,o.isKanjiModeEnabled()))}})(JT);const Ih=ss,lm=Th,W7=k7,H7=N7,K7=WT,V7=HT,Pg=KT,Mg=Rh,G7=C7,Rd=YT,Y7=QT,q7=ki,om=JT;function Q7(e,t){const s=e.size,r=V7.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 X7(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 J7(e,t){const s=K7.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 Z7(e,t){const s=e.size,r=Rd.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 cm(e,t,s){const r=e.size,i=Y7.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 e9(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 t9(e,t,s){const r=new W7;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),q7.getCharCountIndicator(c.mode,e)),c.write(r)});const i=Ih.getSymbolTotalCodewords(e),a=Mg.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 n9(r,e,t)}function n9(e,t,s){const r=Ih.getSymbolTotalCodewords(t),i=Mg.getTotalCodewordsCount(t,s),a=r-i,l=Mg.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(a/l),f=h+1,m=u-h,p=new G7(m);let g=0;const v=new Array(l),b=new Array(l);let j=0;const x=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:f;v[S]=x.slice(g,g+C),b[S]=p.encode(v[S]),g+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let y=0,k,N;for(k=0;k<j;k++)for(N=0;N<l;N++)k<v[N].length&&(w[y++]=v[N][k]);for(k=0;k<m;k++)for(N=0;N<l;N++)w[y++]=b[N][k];return w}function s9(e,t,s,r){let i;if(Array.isArray(e))i=om.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=om.rawSplit(e);u=Rd.getBestVersionForData(h,s)}i=om.fromString(e,u||40)}else throw new Error("Invalid data");const a=Rd.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(`
127
- The chosen QR Code version cannot contain this amount of data.
128
- Minimum version required to store current data is: `+a+`.
129
- `);const l=t9(t,s,i),o=Ih.getSymbolSize(t),c=new H7(o);return Q7(c,t),X7(c),J7(c,t),cm(c,s,0),t>=7&&Z7(c,t),e9(c,l),isNaN(r)&&(r=Pg.getBestMask(c,cm.bind(null,c,s))),Pg.applyMask(r,c),cm(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}UT.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=lm.M,i,a;return typeof s<"u"&&(r=lm.from(s.errorCorrectionLevel,lm.M),i=Rd.from(s.version),a=Pg.from(s.maskPattern),s.toSJISFunc&&Ih.setToSJISFunction(s.toSJISFunc)),s9(t,i,r,a)};var eR={},Nj={};(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),h=a.margin*c,f=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,v=a.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const b=Math.floor((m-h)/c),j=Math.floor((p-h)/c);v=f[o[b*l+j]?1:0]}r[g++]=v.r,r[g++]=v.g,r[g++]=v.b,r[g]=v.a}}})(Nj);(function(e){const t=Nj;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const h=t.getImageWidth(a.modules.size,c),f=u.getContext("2d"),m=f.createImageData(h,h);return t.qrToImageData(m.data,a,c),s(f,u,h),f.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(h,f.quality)}})(eR);var tR={};const r9=Nj;function Tk(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function um(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function i9(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?um("M",c+s,.5+u+s):um("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=um("h",l),l=0)):i++}return r}tR.render=function(t,s,r){const i=r9.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+Tk(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+Tk(i.color.dark,"stroke")+' d="'+i9(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>
130
- `;return typeof r=="function"&&r(null,m),m};const a9=y7,Dg=UT,nR=eR,l9=tR;function Sj(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!a9())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=Dg.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=Dg.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}xc.create=Dg.create;xc.toCanvas=Sj.bind(null,nR.render);xc.toDataURL=Sj.bind(null,nR.renderToDataURL);xc.toString=Sj.bind(null,function(e,t,s){return l9.render(e,s)});async function o9(e){const t=await xc.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const Rk=10*6e4,c9=2e3;function Cj(e,t){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),h=d.useRef(e);h.current=e;const f=d.useRef(t);f.current=t;const m=d.useCallback(async()=>{const p=await A.telegramPairing();r(p),u(!1),o(!1),a(await o9(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+Rk,Date.now()+Rk),v=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}h.current().then(b=>{var j;p||!b||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},c9);return()=>{p=!0,window.clearInterval(v)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function Ej({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 sR=new Set(["approval","question"]),_u={approval:{label:"Approvals",hint:"A run nobody is watching wants to do something gated."},question:{label:"Questions",hint:"A run asked you something and waits."},watcher:{label:"Watchers",hint:"A watcher or a source found something."},reminder:{label:"Reminders",hint:"A reminder an agent promised you came due."},failure:{label:"Failures",hint:"Background jobs died and will not be retried."},recap:{label:"Reports",hint:"Mission reports, the weekly recap, answers to actions you tapped."},plugin:{label:"Plugins",hint:"A plugin that may send you messages has something to say."},agent:{label:"Messages from your agents",hint:"An agent told you something itself."}},u9=new Set(["agent"]),d9={maxUrgency:"now",muted:[]};function h9(e,t){var i;const s=_u[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((i=t.find(a=>a.id===e.agentId))==null?void 0:i.name)??e.agentId}`}function f9({timezone:e}){var j,x,w;const t=ue(()=>A.notificationSettings(),[]),s=ue(()=>A.agents(),[]),r=ue(()=>A.notifications(20),[],3e4),i=d.useRef(!1);d.useEffect(()=>{var y,k;i.current||!r.data||window.location.hash!==h1||(i.current=!0,(k=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||k.call(y,{block:"start"}))},[r.data]);const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=((j=t.data)==null?void 0:j.channels)??[],g=a??((x=t.data)==null?void 0:x.settings),v=y=>{g&&(h(!1),l({...g,...y}))},b=()=>{g&&(c(!0),h(!1),m(null),A.saveNotificationSettings(g).then(()=>{h(!0),l(null),t.reload()}).catch(y=>m(y instanceof pe?y.message:String(y))).finally(()=>c(!1)))};return n.jsxs(se,{gap:"lg",children:[n.jsx(le,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(T,{variant:"accent",disabled:o||!g,onClick:b,children:"Save"}),children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{message:t.error??f}),n.jsx(le,{title:"Where buddi reaches you",children:g?p.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",n.jsx("a",{href:_e("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(se,{gap:"sm",children:[p.map(y=>{var k;return n.jsx(w9,{channel:y,checked:(g.defaultChannel??((k=p[0])==null?void 0:k.kind))===y.kind,onPick:()=>v({defaultChannel:y.kind})},y.kind)}),p.some(y=>y.kind==="telegram")?null:n.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",n.jsx("a",{href:_e("telegram"),children:"Set up Telegram"})]})]}):n.jsx(ge,{children:"Loading…"})}),n.jsx(le,{title:"By kind",children:g?n.jsxs(se,{gap:"sm",children:[uD.filter(y=>!u9.has(y)).map(y=>n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:_u[y].label}),n.jsx("span",{className:"ui-field-hint",children:_u[y].hint})]}),n.jsxs("select",{"aria-label":_u[y].label,value:y9(g,y,p),onChange:k=>{const N={...g.perKind};k.target.value==="default"?delete N[y]:N[y]=k.target.value,v({perKind:N})},children:[n.jsx("option",{value:"default",children:"Default"}),p.map(k=>n.jsx("option",{value:k.kind,children:k.label},k.kind)),sR.has(y)?null:n.jsx("option",{value:"off",children:"Off"})]})]},y)),n.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),n.jsx(le,{title:"Messages from your agents",children:g?n.jsx(m9,{settings:g,agents:((w=s.data)==null?void 0:w.agents)??[],onChange:v}):null}),n.jsx(le,{title:"Focus schedules",children:g?n.jsxs(se,{gap:"sm",children:[n.jsx(N9,{schedules:g.schedules,onChange:y=>v({schedules:y})}),n.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(ae,{label:"End of the day",children:n.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>v({endOfDay:y.target.value})})})}),n.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),u?n.jsx(K,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(p9,{}),n.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:n.jsxs(le,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(oe,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(ge,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(ft,{children:r.data.notifications.map(y=>{var k;return n.jsx(ct,{title:zo(y),sub:`${Ze(y.createdAt,e)} · ${h9(y,((k=s.data)==null?void 0:k.agents)??[])} · ${b9(y,p)}`,side:n.jsx(k9,{row:y})},y.id)})}):n.jsx(ge,{children:"Loading…"})]})})]})}function m9({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??d9,a=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...i,muted:c?[...new Set([...i.muted,o])]:i.muted.filter(u=>u!==o)}});return n.jsxs(se,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:o=>a(o.target.checked)}),n.jsx("span",{children:"Agents may message you"})]}),n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Highest urgency"}),n.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),n.jsxs("select",{"aria-label":"Highest urgency for agents",value:i.maxUrgency,disabled:!r,onChange:o=>s({agents:{...i,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[n.jsx("option",{value:"now",children:"Now"}),n.jsx("option",{value:"today",children:"End of the day"})]})]}),t.length>0?n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:t.map(o=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),n.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,n.jsx("p",{className:"ui-field-hint",children:'An agent given the owner.notify tool can message you itself, signed "@agent: title" on Telegram; here the agent is named beside it. Each agent may send 6 urgent messages an hour and 20 a day. Off keeps them in the list below and never sends them.'})]})}function p9(){var u;const e=ue(()=>A.tipsSettings(),[]),[t,s]=d.useState(!1),[r,i]=d.useState(null),[a,l]=d.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),i(null),l(h),A.saveTipsSettings(h).then(f=>l(f.enabled)).catch(f=>{l(!h),i(f instanceof pe?f.message:String(f))}).finally(()=>s(!1))};return n.jsx(le,{title:"Tips",panel:!0,children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{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 g9({timezone:e}){return n.jsx(x9,{timezone:e,onChange:()=>{}})}function x9({timezone:e,onChange:t}){var C,$;const s=ue(()=>A.telegramBot(),[]),r=ue(()=>A.telegramDevices(),[]),[i,a]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(null),g=d.useRef(new Set),v=Cj(()=>A.telegramDevices().then(R=>R.devices.some(I=>!g.current.has(I.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,j=!b||i,x=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const R=i&&(((I=s.data)==null?void 0:I.running)??!1);A.saveTelegramToken(l.trim()).then(F=>{o(""),a(!1),f(F.restartNeeded?{ok:!1,text:F.note??"Saved. It will be ready the next time buddi starts."}:R?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),t()}).catch(F=>f({ok:!1,text:F instanceof pe?F.message:String(F)})).finally(()=>u(!1))},w=()=>{var R;p(null),g.current=new Set((((R=r.data)==null?void 0:R.devices)??[]).map(I=>I.id)),v.ask().catch(I=>p(I instanceof pe?I.message:String(I)))},{offer:y,square:k,paired:N,stale:S}=v;return n.jsx(le,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{title:"The bot",foot:j?n.jsxs(n.Fragment,{children:[i?n.jsx(T,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(T,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:s.error}),!s.data&&!s.error?n.jsx(ge,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:($=s.data)!=null&&$.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>{a(!0),f(null)},children:"Replace token"})]}):null,j?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),n.jsx(ae,{label:"Bot token",grow:!0,children:n.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:R=>o(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),x())}})})]}):null,h?n.jsx(K,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),n.jsxs(le,{title:"Your devices",children:[n.jsx(oe,{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(ft,{children:r.data.devices.map(R=>n.jsx(ct,{title:R.name??`Telegram user ${R.userId}`,sub:`Paired ${Ze(R.pairedAt,e)} · ${R.lastSeenAt?`last spoke ${He(R.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(v9,{id:R.id,onGone:()=>{r.reload(),t()}})},R.id))}):r.error?null:n.jsx(ge,{children:"Loading…"})]}),n.jsx(le,{title:"Pair a device",foot:b&&(!y||N)?n.jsx(T,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):b&&S?n.jsx(T,{variant:"accent",onClick:w,children:"New code"}):void 0,children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:m}),b?N?n.jsx(K,{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(Ej,{offer:y,square:k,children:n.jsx(j9,{text:y.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",Ze(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 v9({id:e,onGone:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(!1),[l,o]=d.useState(null);if(!s)return n.jsx(T,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),A.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(T,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(T,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function j9({text:e}){const[t,s]=d.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(T,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function w9({channel:e,checked:t,onPick:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof 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(T,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function y9(e,t,s){const r=e.perKind[t];return r==="off"?sR.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function b9(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 k9({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 $k={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},Ik={mode:"do-not-disturb",days:[...Cp],from:"22:00",to:"07:00"};function N9({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(se,{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:Cp.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${$k[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Cp.filter(c=>c===l||r.days.includes(c))}),children:$k[l]},l)})}),n.jsx(ae,{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(ae,{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(T,{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(T,{size:"sm",onClick:()=>t([...e,{...Ik,days:[...Ik.days]}]),children:"Add a schedule"})})]})}const S9={you:"person",appearance:"sun",notifications:"bell",telegram:"send",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",lock:"lock",api:"terminal",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function C9(e){const t=x_.map(r=>({id:r.id,route:_e(r.id),label:r.label,icon:S9[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:c1(r.plugin,r.id),route:Ji(r.plugin,r.id),label:r.title,icon:eA(r.icon),group:"plugins"}));return[...t,...s]}function rR(e){return g_.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function iR(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function E9({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=d.useRef(null),l=rR(e),o=e.some(h=>h.id===t)?t:(u=e[0])==null?void 0:u.id,c=h=>{var g;const f=[...((g=a.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=v=>{var b;h.preventDefault(),(b=f[Math.max(0,Math.min(f.length-1,v))])==null||b.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(f.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const v=f[m].getAttribute("href");v&&i(v)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(h=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(f=>{const m=f.id===t,p=s[f.id],g=r[f.id];return n.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":iR(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:v=>{v.preventDefault(),i(f.route)},children:[n.jsx(me,{name:f.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:f.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},h.id))})}function A9({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=rR(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(cc,{modal:!1,children:[n.jsx(uc,{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(me,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(me,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(vl,{children:n.jsx(dc,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(NL,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(i1,{children:[c>0?n.jsx(yr,{className:"ui-menu-sep"}):null,n.jsx(Qi,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],f=r[u.id];return n.jsxs(SL,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":iR(u.label,h,f),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(me,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):f?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function T9({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var x,w,y;const a=v_(e),l=Z1(i!==void 0),o=i??l,c=r_(e),u=c?o.find(c.plugin,c.page):void 0,h=tr(Yv),f=C9(o.settings),p={proposals:((w=(x=ue(()=>Promise.resolve().then(()=>A.proposals()),[],3e4).data)==null?void 0:x.open)==null?void 0:w.length)??0},g=ue(()=>A.version(),[]),v=ue(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((y=v.data)==null?void 0:y.signals)??[]).length>0&&(b.connections=xA);const j={entries:f,active:a,counts:p,dots:b,navigate:k=>s(k)};return n.jsxs("div",{className:"settings",children:[h?null:n.jsx(E9,{...j}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="plugins"||a==="connections"?n.jsx(wh,{before:n.jsx(B1,{inline:!0,items:[{label:"Settings",href:gn,onClick:()=>s(gn)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?zV:VA}):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(A9,{...j}):null,u?n.jsx(c5,{page:u,params:o1(e),navigate:s,timezone:t,siblings:o.all.filter(k=>k.plugin===u.plugin)}):null,a==="you"?n.jsx(vV,{embedded:!0}):null,a==="appearance"?n.jsx(R9,{railPages:o.rail}):null,a==="notifications"?n.jsx(f9,{timezone:t}):null,a==="telegram"?n.jsx(g9,{timezone:t}):null,a==="memory"?n.jsx(IA,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(IV,{embedded:!0,plugin:f_(e)}):null,a==="accounts"?n.jsx(NK,{embedded:!0,account:a_(e)}):null,a==="computer"?n.jsx(SU,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(QK,{embedded:!0,timezone:t,secret:c_(e)}):null,a==="connections"?n.jsx(LW,{embedded:!0,timezone:t,connection:o_(e)}):null,a==="lock"?n.jsx(fV,{navigate:s}):null,a==="api"?n.jsx(xV,{timezone:t}):null,a==="watchers"?n.jsx(sV,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(xK,{}):null,a==="plugins"?n.jsx(YV,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(P9,{timezone:t}):null]})})]})}function R9({railPages:e}){const[t,s]=NA();return n.jsx(le,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(se,{divided:!0,gap:"lg",children:[n.jsx(dm,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(sn,{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(dm,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(sn,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(dm,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(sn,{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(I9,{pages:e}),n.jsx($9,{})]})})}function $9(){var a;const e=ue(()=>A.overview(),[]),[t,s]=d.useState(null),r=((a=e.data)==null?void 0:a.glances)??[];if(r.length===0)return null;const i=(l,o)=>{s(l),A.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(se,{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 I9({pages:e}){const t=vA(),[s,r]=d.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),D8(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(se,{gap:"sm",children:[n.jsx(oe,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Xo(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Xo(a)))]})]})}function dm({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 P9({timezone:e}){const t=ue(()=>A.overview(),[],15e3),s=ue(()=>A.session(),[]),r=ue(()=>A.providerAccounts(),[]),i=t.data;return n.jsxs(se,{gap:"lg",children:[n.jsx(oe,{message:t.error}),n.jsx(G9,{}),i?n.jsx(le,{title:"The queue",panel:!0,actions:n.jsx(T,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{A.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(ve,{tone:"warning",children:"paused"}):n.jsx(ve,{tone:"good",children:"running"})]})}):null,n.jsxs(le,{title:"This host",panel:!0,children:[n.jsx(nn,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?Ze(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?L9(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(K,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(O9,{}),n.jsx(j5,{}),n.jsx(M9,{}),n.jsx(le,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(ge,{children:"No sources are installed."}):n.jsx(nn,{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 ",He(a.lastRunAt)]})}))}):n.jsx(ge,{children:"Loading…"})})]})}function M9(){var p;const e=ue(()=>A.tailscale(),[]),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=e.data,h=t??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),f=(u==null?void 0:u.proxied)===!0,m=g=>{i(!0),l(null),c(!1),A.setTailscale({enabled:g,login:h.trim()}).then(()=>{c(!0)}).catch(v=>l(v instanceof pe?v.message:String(v))).finally(()=>{i(!1),e.reload()})};return n.jsx(le,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(T,{variant:"accent",disabled:r||!u||f,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(se,{divided:!0,children:n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:e.error??a}),n.jsx("p",{className:"ui-card-meta",children:u?u.available&&u.self?`Tailscale is running on this machine as ${u.self.login}.`:u.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),f?n.jsxs(n.Fragment,{children:[n.jsx(K,{tone:"warning",children:"Change this from the computer buddi runs on."}),n.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${h}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||f,onChange:g=>m(g.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(ae,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:h,placeholder:"you@example.com",disabled:r||!u||f,onChange:g=>s(g.target.value)})}),n.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),n.jsxs("div",{className:"tailscale-command",children:[n.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),n.jsx(T,{size:"sm",disabled:r||!u,onClick:()=>{D9((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(K,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function D9(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function O9(){var u;const e=ue(()=>A.service(),[],1e4),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{i(!0),l(null),A.serviceAction(h).then(()=>{s(null)}).catch(f=>{l(f.message)}).finally(()=>{i(!1),e.reload()})};return n.jsx(le,{title:"Service",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsx(nn,{items:[{label:"Database",value:n.jsx(Pk,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(Pk,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:a}),t?n.jsx(K,{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(re,{align:"end",children:t?n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(T,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(T,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function Pk({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(ve,{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 L9(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const _9=2e3,Mk={starting:"Getting started.",backup:"Taking a backup first, so there is a way back.",stopping:"Stopping the gateway. The database stays up.",installing:"Installing the new version.",verifying:"Checking that the new version can start its database.","rolling-back":"The new version could not start its database. Putting the previous one back.",restarting:"Restarting buddi on the new version.",migrating:"Bringing the database up to date.",done:"Done.",failed:"That did not work."},F9=new Set(["done","failed","rolled-back"]),z9="The check asks the npm registry for the newest version and sends nothing else.",U9="This takes a backup, installs the new version and restarts buddi. This page closes and comes back on its own.",B9="A checkout upgrades with git pull, then buddi upgrade in a terminal.",W9=10*6e4,H9="buddi did not come back. Run buddi doctor in a terminal.";function K9(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 V9(e,t,s,r){const[i,a]=d.useState(void 0),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=d.useRef(!1),f=d.useRef(s),m=d.useRef(r);return f.current=s,m.current=r,d.useEffect(()=>{if(!e){a(void 0),o(!1),h.current=!1;return}let p=!1,g=0;const v=()=>{h.current=!0,g=Date.now()+W9,o(!0)},b=()=>{if(Date.now()<g){A.session().then(w=>{p||w.version!==void 0&&w.version===t||(p=!0,f.current())}).catch(()=>{}),A.version().then(w=>{const y=w.history[w.history.length-1];p||(y==null?void 0:y.outcome)!=="failed"||(p=!0,o(!1),u(K9(y)))}).catch(()=>{});return}p=!0,o(!1),u(H9)},j=()=>{if(!p){if(h.current)return b();A.upgradeJob(e).then(w=>{var y;p||(a(w),u(null),(F9.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):v())})}};j();const x=window.setInterval(j,_9);return()=>{p=!0,window.clearInterval(x)}},[e,t]),{job:i,away:l,error:c}}function G9({reload:e}){var y;const t=ue(()=>A.version(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),m=(y=t.data)==null?void 0:y.current,p=e??(()=>window.location.reload()),g=d.useCallback(k=>{r(null),f(k)},[]),v=V9(s,m,p,g),b=t.data,j=()=>{o(!0),u(null),A.checkVersion().catch(k=>u(k instanceof pe?k.message:String(k))).finally(()=>{o(!1),t.reload()})},x=k=>{o(!0),u(null),A.setVersionCheck(k).catch(N=>u(N instanceof pe?N.message:String(N))).finally(()=>{o(!1),t.reload()})},w=()=>{o(!0),u(null),f(null),A.startUpgrade(b==null?void 0:b.latest).then(k=>{var N;a(!1),r(((N=k.job)==null?void 0:N.id)??null)}).catch(k=>u(k instanceof pe?k.message:String(k))).finally(()=>o(!1))};return b!=null&&b.checkout?n.jsx(le,{title:"Version",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsx(nn,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:b.current})}]})}),n.jsx(le,{children:n.jsx("p",{className:"ui-card-meta",children:B9})})]})}):n.jsx(le,{title:"Version",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(oe,{message:t.error??c}),n.jsx(nn,{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 ",He(b.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),b!=null&&b.error?n.jsxs(K,{tone:"warning",children:["The last check did not get an answer: ",b.error]}):null,n.jsx(re,{align:"end",children:n.jsx(T,{disabled:l,onClick:j,children:"Check now"})})]})}),n.jsx(le,{children:n.jsxs(se,{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:k=>x(k.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:z9})]})}),b!=null&&b.updateAvailable&&b.latest&&b.latestNotes?n.jsx(le,{title:`What changes in ${b.latest}`,children:n.jsx(Mr,{text:b.latestNotes})}):null,n.jsx(le,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(Y9,{...v,job:v.job??h??void 0}),i?n.jsx(K,{tone:"warning",role:"alert",children:U9}):null,n.jsx(re,{align:"end",children:i?n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Cancel"}),n.jsxs(T,{variant:"accent",disabled:l,onClick:w,children:["Upgrade to ",b==null?void 0:b.latest]})]}):n.jsx(T,{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(le,{title:"Upgrades so far",children:n.jsx(nn,{items:b.history.slice().reverse().map(k=>({key:k.startedAt,label:n.jsxs("span",{className:"mono",children:[k.from," → ",k.to]}),value:n.jsx(q9,{attempt:k})}))})}):null]})})}function Y9({job:e,away:t,error:s}){return s?n.jsx(oe,{message:s}):t?n.jsx(K,{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(K,{tone:"critical",role:"alert",children:[Mk.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(K,{tone:e.phase==="done"?"good":void 0,role:"status",children:Mk[e.phase]??e.detail??e.phase}):null}function q9({attempt:e}){return n.jsxs("span",{children:[n.jsx(ve,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",He(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 $d=["hello","brain","takeOn","reach","assistant","handover"],aR={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function lR(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function Q9(e){var a,l,o;const t=lR(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 oR(e){var a,l,o,c,u;const t=Q9(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 cR(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 Fu(e){return $d.find(t=>!cR(e,t))??"handover"}function X9(e){const t=$d.indexOf(e);return t>0?$d[t-1]:null}function Dk(e,t,s){return s===t?"now":cR(e,s)?"done":"todo"}function J9(e,t){return{...e}}const Og="buddi.firstRun.restore";function Lg(e){try{e===null?window.sessionStorage.removeItem(Og):window.sessionStorage.setItem(Og,e)}catch{}}function uR(){try{return window.sessionStorage.getItem(Og)}catch{return null}}function Z9(e){const t=oR(e),s=Fu(t);return{answers:t,open:s,stay:s!=="handover"}}function eG(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function tG(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 nG=6e4,sG=5*6e4,dR=1500,rG=2e3,iG="(max-width: 720px)";function Cl(){const e=d.useRef(null);return d.useEffect(()=>{let t=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const Aj=d.createContext({busy:0,report:()=>{}});function aG({children:e}){const[t,s]=d.useState(0),r=d.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=d.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(Aj.Provider,{value:i,children:e})}function ot({children:e}){const{busy:t}=d.useContext(Aj);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(vh,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function tt({children:e}){return n.jsx(n.Fragment,{children:e})}function _s({line:e}){const{report:t}=d.useContext(Aj);return d.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const Tj=d.createContext(null);function Yt({children:e,actions:t}){const s=d.useContext(Tj),r=t==null?null:s?hl.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 Xn({onClick:e,disabled:t}){return n.jsxs(T,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(me,{name:"chevron-left"}),D.back]})}function El({children:e,onClick:t,disabled:s}){return n.jsxs(T,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(me,{name:"arrow"})]})}function lG({navigate:e,timezone:t}){var Un,ur,Y,Ee,it,et,Qt;const s=tr(iG),[r,i]=d.useState(void 0);d.useEffect(()=>{A.session().then(je=>i(je.platform)).catch(()=>{})},[]);const[a,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[f,m]=d.useState(void 0),[p,g]=d.useState([]),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[$,R]=d.useState(null),[I,F]=d.useState(null),[_,E]=d.useState(()=>uR()?"running":"idle"),[M,P]=d.useState({}),[U,L]=d.useState([]),[W,O]=d.useState(0),V=d.useRef(void 0),[X,G]=d.useState(null),Z=d.useCallback(()=>{Promise.resolve().then(()=>A.takeOnProgress()).then(je=>{je&&Array.isArray(je.plugins)&&G(je)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(X!=null&&X.running))return;const je=window.setInterval(Z,rG);return()=>window.clearInterval(je)},[X==null?void 0:X.running,Z]);const z=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),q=d.useRef(e);q.current=e;const Q=d.useCallback(async(je=!0,qe=!1)=>{var Fs,ys,Ni,Tl,Si,Rn,Ci,dr,Fr;const[Oe,Wt,js,wn,ws,be]=await Promise.all([A.onboarding().catch(()=>{}),A.owner().catch(()=>{}),A.providerAccounts().catch(()=>{}),Be.agents().catch(()=>{}),A.browser().catch(()=>{}),A.providers().catch(()=>{})]);h(js);const Ue=(ys=(Fs=be==null?void 0:be.providers.find(Lt=>Lt.kind==="anthropic"))==null?void 0:Fs.defaultModel)==null?void 0:ys.trim();m(Ue||void 0),g((Wt==null?void 0:Wt.zones)??[]),N(((Ni=Oe==null?void 0:Oe.details)==null?void 0:Ni.conversationId)??null);const Me=(wn==null?void 0:wn.agents.find(Lt=>Lt.id===wn.defaultAgentId))??(wn==null?void 0:wn.agents[0]);Me&&b(Me),C(Oe&&!Oe.needs.agent&&Me?{id:Me.id,name:Me.name,avatar:((Tl=Me.avatar)==null?void 0:Tl.kind)==="emoji"?Me.avatar.value:"",description:Me.description,...Me.picture?{picture:Me.picture}:{}}:null),Array.isArray((Si=Oe==null?void 0:Oe.details)==null?void 0:Si.takeOn)&&Z();const Xe={onboarding:Oe,owner:Wt,accounts:js,browser:(Rn=ws==null?void 0:ws.browser)==null?void 0:Rn.engine,...Me?{assistant:{id:Me.id,name:Me.name,avatar:((Ci=Me.avatar)==null?void 0:Ci.kind)==="emoji"?Me.avatar.value:""}}:{}};if(qe){const Lt=Z9(Xe);if(l(Lt.answers),c(Lt.open),!Lt.stay){const zs=(dr=Oe==null?void 0:Oe.details)==null?void 0:dr.conversationId;q.current(zs&&Me?at(Me.id,zs):tn,!0)}return}if(je&&(Oe==null?void 0:Oe.state)==="done"){const Lt=(Fr=Oe.details)==null?void 0:Fr.conversationId;q.current(Lt&&Me?at(Me.id,Lt):tn,!0);return}if(!je)return;const we=oR(Xe);l(we),c(Lt=>Lt??Fu(we))},[]);d.useEffect(()=>{Q()},[Q]);const ce=(je,qe={})=>{Promise.resolve().then(()=>A.onboardingStep(aR[je],qe)).catch(()=>{})},Pe=je=>Fu(je)==="brain"&&M.brain?{...je,brain:M.brain}:je,Te=(je,qe)=>{const Oe=Pe(qe);Oe.brain&&(V.current=Oe.brain),x(null),L([]),l(Oe),je==="brain"&&Oe.brain?ce(je,{accountId:Oe.brain.accountId}):je==="reach"?ce(je,Oe.reach?{reach:Oe.reach}:{}):je!=="takeOn"&&ce(je),c(Fu(Oe))},Le=(je,qe)=>{x(null),l(qe),qe.brain&&(V.current=qe.brain),je==="brain"&&qe.brain&&ce(je,{accountId:qe.brain.accountId})},J=je=>{x(null),l(qe=>J9(qe)),c(je)},ke=()=>{if(!o)return;const je=X9(o==="handover"?"handover":o);je&&J(je)},ne=()=>{const je=a.brain??V.current,qe=((X==null?void 0:X.plugins)??[]).filter(Oe=>Oe.state==="ready").map(Oe=>Oe.title);x(null),P({}),L([]),l({}),c("hello"),O(Oe=>Oe+1),(async()=>{var Ue;const[Oe,Wt,js]=await Promise.all([Promise.resolve().then(()=>A.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>A.telegram()).catch(()=>{}),Promise.resolve().then(()=>A.browser()).catch(()=>{})]),wn=lR(Oe),ws=je&&wn.some(Me=>Me.id===je.accountId)?je:void 0;Oe&&h(Oe),P(ws?{brain:ws}:{});const be=[...new Set(wn.map(Me=>Me.label)),...Wt!=null&&Wt.paired?[D.startOver.telegram]:[],...((Ue=js==null?void 0:js.browser)==null?void 0:Ue.engine)==="chromium"?[D.startOver.browser]:[],...qe];L(be.length>0?[D.startOver.said(be.join(", "))]:[])})()},Ae=()=>{y(!0),A.skipOnboarding().then(()=>e(tn)).catch(je=>x(je instanceof pe?je.message:String(je))).finally(()=>y(!1))},de=ue(()=>A.version().catch(()=>({current:""})),[]),Re=d.useRef(null);d.useEffect(()=>{Re.current&&(Re.current.scrollTop=0)},[o]);const De=_==="running",Ve=Object.keys(a).length===0,he={answers:a,accounts:u,claudeModel:f,zones:p,browserZone:z,assistantAgent:v,met:k,onMet:N,existing:S,progress:X,onProgress:Z,navigate:e,onSettled:je=>o&&Te(o,je),onKept:je=>o&&Le(o,je),onBack:ke,onTrouble:x,onReload:()=>void Q(!1),onPickAnotherBrain:()=>J("brain"),onSpoken:F},ze=(a.takeOn??[]).map(je=>{var qe;return((qe=Ua.find(Oe=>Oe.id===je))==null?void 0:qe.title)??je}),Ge=(X==null?void 0:X.plugins)??[],Ye=Ge.filter(je=>je.state==="ready").length,nt=Ge.length===0?null:X!=null&&X.running?D.takeOn.installing(Ye,Ge.length):Ye===Ge.length?D.takeOn.installed:null,Pt=[(Un=a.reach)!=null&&Un.phone?D.reach.done.phone:null,(ur=a.reach)!=null&&ur.mailbox?D.reach.done.mailbox:null,(Y=a.reach)!=null&&Y.app||(Ee=a.reach)!=null&&Ee.browser?D.reach.done.app:null].filter(je=>je!==null),un={hello:{answer:D.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:D.brain.answer(((it=a.brain)==null?void 0:it.label)??"")},takeOn:{answer:D.takeOn.answer(ze),sub:nt},reach:{answer:D.reach.answer(Pt)},assistant:{answer:((et=a.assistant)==null?void 0:et.name)??""}},ee=$d.filter(je=>je!=="handover"),ye=o===null||o==="handover"?ee.length:ee.indexOf(o),H=Math.min(ye,ee.length-1),Fe=I?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:Ae,children:D.later}),o==="hello"&&Ve&&_==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>E("form"),children:D.restore.offer}):!De&&o!==null&&!(o==="hello"&&Ve)?n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:ne,children:D.startOver.link}):null]}),wt=r===void 0||r==="darwin"?D.tagline:D.taglineElsewhere,dt=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:D.count(ye+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(Tj.Provider,{value:$,children:n.jsx(aG,{children:n.jsxs(H1,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:Re,"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(Ho,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?D.count(ye+1):void 0,children:ee.map(je=>n.jsx("i",{"data-state":Dk(a,o,je)},je))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?D.strip(ye+1,D.chapters[ye]??""):D.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(Ho,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:wt}),(Qt=de.data)!=null&&Qt.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",de.data.current]}):null]})]}),ee.map((je,qe)=>{const Oe=De?je==="hello"?"now":"todo":Dk(a,o,je),Wt=un[je];return n.jsxs("div",{className:"wiz-ch","data-state":Oe,"aria-current":Oe==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":Oe,children:Oe==="done"?n.jsx(me,{name:"check",size:12}):qe+1}),n.jsxs("span",{className:"wiz-ch-label",children:[Oe==="done"?Wt.answer:D.chapters[qe],Oe==="done"&&Wt.sub?n.jsx("span",{className:"wiz-ch-sub",children:Wt.sub}):null]}),Oe==="done"&&!De?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>J(je),children:D.change}):null]},je)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:D.mapNotes[H]}),Fe]}),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(d4,{dock:n.jsxs(n.Fragment,{children:[dt,n.jsx("div",{className:"wiz-dock-actions",ref:R})]}),children:[De?n.jsx(OG,{onDone:je=>{E("idle"),L([...je?[D.restore.welcome(je)]:[],D.restore.keys]),Q(!0,!0)},onFailed:je=>{E("idle"),x(je)}}):o==="hello"?n.jsx(oG,{...he}):o==="brain"?n.jsx(uG,{...he}):o==="takeOn"?n.jsx(CG,{...he}):o==="reach"?n.jsx(EG,{...he}):o==="assistant"?n.jsx(IG,{...he}):o==="handover"?n.jsx(PG,{...he}):n.jsx(_s,{}),U.length>0||j?n.jsxs(tt,{children:[U.map(je=>n.jsx(ot,{children:je},je)),j?n.jsx(ot,{children:j}):null]}):null]},`${W}-${o??""}-${De?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:Fe}):null]})})]})}),_==="form"?n.jsx(DG,{onCancel:()=>E("idle"),onStarted:()=>E("running"),onTrouble:x}):null]})})})}function Al({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function Ok(e){try{return Ut(new Date,e)}catch{return""}}function oG({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=Cl(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,f]=d.useState(!1),[m,p]=d.useState(!1),g=()=>{const v=l.trim();v===""||m||(p(!0),A.setOwner({preferredName:v,timezone:c}).then(()=>r({...e,name:v,clock:c})).catch(b=>i(b instanceof pe?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.hello.title}),n.jsx(tt,{children:D.hello.opening.map(v=>n.jsx(ot,{children:v},v))}),n.jsxs(Yt,{actions:n.jsx(El,{onClick:g,disabled:m||l.trim()==="",children:D.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(ae,{label:D.name.label,children:n.jsx("input",{ref:a,placeholder:D.name.placeholder,maxLength:80,value:l,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}})}),h?n.jsx(ae,{label:D.clock.label,hint:D.clock.hint(Ok(c)),children:n.jsx("select",{value:c,onChange:v=>u(v.target.value),children:(t.includes(c)?t:[c,...t]).map(v=>n.jsx("option",{value:v,children:v},v))})}):n.jsx(ae,{label:D.clock.label,hint:D.clock.hint(Ok(c)),action:n.jsx(T,{size:"lg",onClick:()=>f(!0),children:D.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:D.hello.foot})]})]})}const cG={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 uG(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=d.useState(null),[u,h]=d.useState("key"),[f,m]=d.useState(null),[p,g]=d.useState(!1),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),k=(t==null?void 0:t.anthropicOAuthEnabled)===!0,N=(t==null?void 0:t.codexEnabled)===!0,S=t==null?void 0:t.gemini,[C,$]=d.useState(null);d.useEffect(()=>{let W=!1;const O=()=>{Promise.resolve().then(()=>A.ollama()).then(X=>{!W&&X&&b(X)}).catch(()=>{}),Promise.resolve().then(()=>A.mlxh()).then(X=>{!W&&X&&x(X)}).catch(()=>{W||x({running:!1,baseUrl:"",manager:!1,models:[]})})};O();const V=window.setInterval(O,4e3);return()=>{W=!0,window.clearInterval(V)}},[]);const R=async W=>{if(s.assistant??e.existing)try{await A.bindBrain({accountId:W.accountId,model:W.model})}catch(O){return O instanceof pe?O.message:String(O)}return a(),i({...s,brain:W}),C==null||C.close(),$(null),c(null),y(null),null},I=async(W,O,V)=>{g(!0),m(null);try{const X=await A.saveProviderAccount(W);let G=await A.testProviderAccount(X.id),Z=W.defaultModel,z=!1;if(G.state!=="connected"&&V&&V!==Z&&oT(G)){const Q=(await A.providerAccounts()).accounts.find(ce=>ce.id===X.id);Q&&(await A.saveProviderAccount({id:Q.id,revision:Q.revision,label:Q.label,kind:Q.kind,auth:Q.auth,baseUrl:Q.baseUrl,defaultModel:V,enabled:Q.enabled}),G=await A.testProviderAccount(X.id),G.state==="connected"&&(Z=V,z=!0))}if(G.state!=="connected"){try{const Q=(await A.providerAccounts()).accounts.find(ce=>ce.id===X.id);Q&&await A.removeProviderAccount(X.id,Q.revision)}catch{}return m(G.message),G}const q=await R({accountId:X.id,label:O,model:Z,...z?{freeTier:z}:{}});return q&&m(q),G}catch(X){return m(X instanceof pe?X.message:String(X)),null}finally{g(!1)}},F=async W=>{g(!0),m(null);try{const O=await A.saveProviderAccount(W);let V;try{V=await A.testProviderAccount(O.id)}finally{try{const X=(await A.providerAccounts()).accounts.find(G=>G.id===O.id);X&&await A.removeProviderAccount(O.id,X.revision)}catch{}}return V.state!=="connected"&&m(V.message),V}catch(O){return m(O instanceof pe?O.message:String(O)),null}finally{g(!1)}},_=(W,O,V)=>{if(W.length<=1){I(O(W[0]??""),V);return}y({models:W,make:O,label:V})},E=W=>{if(W===o)return;C==null||C.close(),$((W==="free"||W==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(W)},M=()=>{C==null||C.close(),$(null),y(null),m(null),c(null)},P=fR(v,j),U=["free",...k?["claude"]:[],...N?["chatgpt"]:[],"key","local"];let L=null;return w?L=n.jsxs(n.Fragment,{children:[n.jsx(tt,{children:n.jsx(ot,{children:D.brain.model.ask})}),p?n.jsx(_s,{line:D.brain.checking.service}):f?n.jsx(tt,{children:n.jsx(ot,{children:f})}):null,n.jsx(dG,{busy:p,models:w.models,onBack:M,onUse:W=>void I(w.make(W),w.label)})]}):o==="key"?L=n.jsxs(n.Fragment,{children:[n.jsx(sn,{label:D.brain.keyKinds.label,value:u,onChange:W=>{m(null),h(W)},options:[{value:"key",label:D.brain.keyKinds.key},...S?[{value:"gemini",label:D.brain.keyKinds.gemini}]:[],{value:"service",label:D.brain.keyKinds.service}]}),u==="gemini"&&S?n.jsx(fG,{busy:p,problem:f,preset:S,onBack:M,onUse:I},"gemini"):u==="service"?n.jsx(pG,{busy:p,problem:f,address:(v==null?void 0:v.cloudBaseUrl)??"",onBack:M,onOffer:_,onTrial:F,onUse:I},"service"):n.jsx(hG,{busy:p,problem:f,onBack:M,onUse:I},"key")]}):o==="local"?L=n.jsx(mG,{busy:p,problem:f,probe:v,mlxh:j,onBack:M,onOffer:_,onUse:I}):o==="free"?L=n.jsx(xG,{...e,busy:p,consent:C,onBack:M,onConnected:R}):o==="chatgpt"?L=n.jsx(wG,{...e,busy:p,consent:C,onBack:M,onConnected:R}):o==="claude"&&(L=n.jsx(bG,{...e,busy:p,problem:f,onBack:M,onConnected:R})),n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.brain.title}),n.jsx(tt,{children:n.jsx(ot,{children:D.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":D.brain.ask,children:U.map(W=>{const O=cG[W],V=D.brain.cards[W];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===W,"data-wide":O.wide?"true":void 0,onClick:()=>E(W),children:[n.jsx("span",{className:"wiz-glyph","data-tone":O.tone,"aria-hidden":"true",children:n.jsx(me,{name:O.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:V.title}),n.jsx("span",{className:"wiz-opt-line",children:W==="local"?P:V.line}),"pill"in V?n.jsx(ve,{tone:"good",children:V.pill}):null]})]},W)})}),L,L===null&&s.brain?n.jsxs(tt,{children:[n.jsx(ot,{children:s.brain.freeTier?D.brain.worksOnFlash(s.brain.model):D.brain.works(s.brain.model)}),n.jsx(vG,{...e})]}):null,L===null?n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:l}),n.jsx(El,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:D.brain.submit})]})}):null]})}function dG({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=d.useState(t[0]??"");return n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:s,disabled:e}),n.jsx(T,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:D.brain.model.submit})]}),children:n.jsx(ae,{label:D.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 hR({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(ae,{label:D.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 hG({busy:e,problem:t,onBack:s,onUse:r}){const i=Cl(),[a,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(""),[v,b]=d.useState(!1),j=e||u,x=!v&&t!==null&&f.length>0,w=o??eG(a),y=()=>{const k=a.trim();k===""||j||(h(!0),b(!1),(async()=>{var $;let N=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")N=p;else try{const R=await A.probeModels({kind:w,auth:"api-key",secret:k});N=(($=R.models.find(I=>I.isDefault))==null?void 0:$.id)??N,S=R.models.map(I=>I.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:N,enabled:!0,secret:k},w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai);if(!(!C||C.state==="connected")){if(Zx(C)){b(!0),m([]);return}m(S.includes(N)||S.length===0?S:[N,...S]),g(N)}})())};return n.jsxs(n.Fragment,{children:[j?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.key})}):v?n.jsx(tt,{children:n.jsx(ot,{children:D.brain.key.refused})}):t?n.jsx(tt,{children:n.jsx(ot,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:s,disabled:j}),n.jsx(T,{variant:"accent",size:"lg",disabled:j||a.trim()==="",onClick:y,children:x?D.brain.model.retry:D.brain.key.submit})]}),children:[n.jsx(ae,{label:D.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:D.brain.key.placeholder,value:a,onChange:k=>{l(k.target.value),m([])},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),y())}})}),x?n.jsx(hR,{models:f,picked:p,disabled:j,onPick:g}):null,n.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai," · ",D.brain.key.which]})]})]})}function fG({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=Cl(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState([]),[m,p]=d.useState(""),g=e||c,v=t!==null&&h.length>0,b=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let x=rT,w;if(v&&m!=="")x=m;else try{const k=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(N=>N.id);x=iT(k)??x,w=lT(x)?aT(k):void 0,f(kK(k)),p(w??x)}catch{}u(!1),await i({label:D.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:x,enabled:!0,secret:j},D.brain.gemini.label,w)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.gemini})}):t?n.jsx(tt,{children:n.jsx(ot,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:r,disabled:g}),n.jsx(T,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:D.brain.gemini.submit})]}),children:[n.jsx(ae,{label:D.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:D.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),b())}})}),v?n.jsx(ae,{label:D.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:h.map(j=>n.jsx("option",{value:j,children:j},j))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:D.brain.gemini.get})]})]})}function fR(e,t){return e===null||t===null?D.brain.local.looking:!e.running&&!t.running?D.brain.local.missing:D.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function mG({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=yg(r),u=()=>{!(r!=null&&r.running)||!c||l({label:D.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},D.brain.mlxh.label)},h=s!==null&&r!==null&&!s.running&&!r.running,f=()=>{s&&a(o,m=>({label:D.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),D.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.ollama})}):t?n.jsx(tt,{children:n.jsx(ot,{children:t})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(T,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e||o.length===0,onClick:f,children:D.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(T,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:D.brain.mlxh.connect}):null,h&&s?n.jsx(Tt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:D.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[fR(s,r),r!=null&&r.running&&!c?` ${D.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${LA(r.baseUrl)}`:""]})})]})}function pG({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=Cl(),[c,u]=d.useState(s),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState([]),[b,j]=d.useState(""),[x,w]=d.useState(!1),y=e||m,k=!x&&t!==null&&g.length>0,N=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var M;const S=h.trim()?"api-key":"none",C=P=>({label:D.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:P,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),$=(P,U,L)=>{if(!(!P||P.state==="connected")){if(Zx(P)){w(!0),v([]);return}v(U),j(L)}};if(S==="api-key"&&k&&b!==""){p(!1),$(await l(C(b),D.brain.service.label),g,b);return}let R=[],I;try{const P=await A.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});R=P.models.map(U=>U.id),I=(M=P.models.find(U=>U.isDefault))==null?void 0:M.id}catch{}p(!1);const F=I?[I]:R;if(S==="none"){i(F,C,D.brain.service.label);return}const _=F[0]??"";if(F.length<=1){$(await l(C(_),D.brain.service.label),R,_);return}const E=await a(C(_));(E==null?void 0:E.state)==="connected"?i(F,C,D.brain.service.label):$(E,R,_)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.service})}):x?n.jsx(tt,{children:n.jsx(ot,{children:D.brain.key.refused})}):t?n.jsx(tt,{children:n.jsx(ot,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:r,disabled:y}),n.jsx(T,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:N,children:k?D.brain.model.retry:D.brain.service.submit})]}),children:[n.jsx(ae,{label:D.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:D.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),v([])}})}),n.jsx(ae,{label:D.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{f(S.target.value),v([])}})}),k?n.jsx(hR,{models:g,picked:b,disabled:y,onPick:j}):null]})]})}const gG=2e3;function xG({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=D.brain.cloud.label;d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?t:g.current;(async()=>{try{const x=((i==null?void 0:i.accounts)??[]).find(N=>N.auth==="device-key"),w=x?{id:x.id}:await A.saveProviderAccount({label:v,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:Tu,enabled:!0}),y=(await A.providerAccounts()).accounts.find(N=>N.id===w.id),k=await A.ollamaConnect(y.id,y.revision);h({id:y.id,attemptId:k.attemptId,url:k.verificationUrl}),j&&(j.location.href=k.verificationUrl)}catch(x){j==null||j.close(),c(x instanceof pe?x.message:String(x))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let j=!1,x=!1;const w=async()=>{if(!(j||x)){x=!0;try{const k=await A.ollamaPoll(u.id,u.attemptId);if(j||k.state==="waiting")return;if(j=!0,h(null),k.state==="failed"){c(k.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{x=!1}}},y=window.setInterval(()=>void w(),gG);return()=>{j=!0,window.clearInterval(y)}},[u]);const b=async j=>{try{const x=(await A.accountModels(j).catch(()=>({models:[]}))).models.map(N=>N.id),w=x.length===0||x.includes(Tu)?Tu:x[0],y=(await A.providerAccounts()).accounts.find(N=>N.id===j);y&&y.defaultModel!==w&&await A.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const k=await A.testProviderAccount(j);return k.state!=="connected"?k.message:await r({accountId:j,label:v,model:w})}catch(x){return x instanceof pe?x.message:String(x)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.cloud})}):o?n.jsx(tt,{children:n.jsx(ot,{children:o})}):u?n.jsx(tt,{children:n.jsx(ot,{children:D.brain.cloud.waiting})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:s,disabled:a||e}),u?n.jsx(Tt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:D.brain.cloud.open}):o?n.jsx(T,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:D.brain.cloud.again}):null]})})]})}function vG({answers:e,accounts:t,onKept:s,onTrouble:r}){var p;const i=e.brain,a=i?((t==null?void 0:t.accounts)??[]).find(g=>g.id===i.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=ij(a),f=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&cT(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!a)return;let g=!1;return A.accountModels(a.id).then(v=>{const b=h?v.models.filter(j=>!OA({id:j.id,...j.image?{kind:"image"}:{}})):v.models;g||o(b.map(j=>j.id))}).catch(()=>{}),()=>{g=!0}},[f,a==null?void 0:a.id]),!f||!a||!i||l.length<2)return null;const m=g=>{g===i.model||c||(u(!0),r(null),(async()=>{try{await A.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:g,enabled:a.enabled}),e.assistant&&await A.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(v){r(v instanceof pe?v.message:String(v))}finally{u(!1)}})())};return n.jsx(ot,{children:n.jsx(ae,{label:D.brain.model.change,children:n.jsx("select",{value:i.model,disabled:c,onChange:g=>m(g.target.value),children:(l.includes(i.model)?l:[i.model,...l]).map(g=>n.jsx("option",{value:g,children:g},g))})})})}const Lk="gpt-5.5",jG=2e3;function wG({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=d.useRef(null),b=D.brain.chatgpt.label;d.useEffect(()=>()=>{const w=v.current;v.current=null,w&&A.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]),d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const w=f===0?t:g.current;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),k=y?{id:y.id}:await A.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:Lk,enabled:!0}),N=(await A.providerAccounts()).accounts.find(C=>C.id===k.id),S=await A.codexAccountAction(N.id,"login",N.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??D.brain.chatgpt.failed);v.current={id:N.id,revision:N.revision},h({id:N.id,revision:N.revision,url:S.verificationUrl,code:S.userCode}),w&&(w.location.href=S.verificationUrl)}catch(y){w==null||w.close(),c(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let w=!1,y=!1;const k=async()=>{if(!(w||y)){y=!0;try{const S=(await A.providerAccounts()).accounts.find($=>$.id===u.id);if(w)return;const C=S==null?void 0:S.login;if(!C||C.state==="pending")return;if(w=!0,v.current=null,h(null),C.state!=="connected"){c(C.message??D.brain.chatgpt.failed);return}l(!0),c(await j(u.id)),l(!1)}catch{}finally{y=!1}}},N=window.setInterval(()=>void k(),jG);return()=>{w=!0,window.clearInterval(N)}},[u]);const j=async w=>{var y,k;try{const N=(await A.accountModels(w).catch(()=>({models:[]}))).models,S=((y=N.find($=>$.isDefault))==null?void 0:y.id)??((k=N[0])==null?void 0:k.id)??Lk,C=(await A.providerAccounts()).accounts.find($=>$.id===w);return C&&C.defaultModel!==S&&await A.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:S,enabled:C.enabled}),await r({accountId:w,label:b,model:S})}catch(N){return N instanceof pe?N.message:String(N)}},x=()=>{const w=v.current;v.current=null,w&&A.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(tt,{children:n.jsx(_s,{line:D.brain.checking.chatgpt})}):o?n.jsx(tt,{children:n.jsx(ot,{children:o})}):u?n.jsx(tt,{children:n.jsxs(ot,{children:[D.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),D.brain.chatgpt.codeAfter]})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:x,disabled:a||e}),u?n.jsx(Tt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:D.brain.chatgpt.open}):o?n.jsx(T,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(w=>w+1)},children:D.brain.chatgpt.again}):null]}),children:u?n.jsx(lj,{code:u.code,label:D.brain.chatgpt.code}):null})]})}const yG="claude-sonnet-5";function bG({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(""),g=d.useRef(null);d.useEffect(()=>()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const v=()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??yG,j=()=>{o(!0),u(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find($=>$.auth==="anthropic-oauth"),k=y?{id:y.id}:await A.saveProviderAccount({label:D.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await A.providerAccounts()).accounts.find($=>$.id===k.id),C=await A.anthropicAccountAction(S.id,"login",S.revision);g.current={id:S.id,revision:S.revision+1},f({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(y){w==null||w.close(),u(y instanceof pe?y.message:String(y))}finally{o(!1)}})()},x=()=>{!h||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await A.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await A.testProviderAccount(h.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:h.id,label:D.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(tt,{children:n.jsx(_s,{line:D.brain.checking.claude})}):t??c?n.jsx(tt,{children:n.jsx(ot,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(tt,{children:n.jsx(ot,{children:D.brain.claude.waiting})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:v,disabled:l}),n.jsx(Tt,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:D.brain.claude.open}),n.jsx(T,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:x,children:D.brain.claude.finish})]}),children:n.jsx(ae,{label:D.brain.claude.paste,grow:!0,children:n.jsx(kG,{value:m,onChange:p})})})]}):n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:v,disabled:e||l}),n.jsx(T,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:D.brain.claude.start})]})})]})}function kG({value:e,onChange:t}){const s=Cl();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const NG={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function SG(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:D.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>D.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:D.takeOn.ready(s),done:!0}}function CG({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=d.useState(()=>e.takeOn??[...wF]),[c,u]=d.useState(!1),h=Ua.filter(g=>l.includes(g.id)),f=g=>o(v=>v.includes(g)?v.filter(b=>b!==g):[...v,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>A.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(v=>a(v instanceof pe?v.message:String(v))).finally(()=>u(!1)))},p=SG(t);return n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.takeOn.title}),n.jsx(tt,{children:n.jsx(ot,{children:D.takeOn.ask})}),n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:i,disabled:c}),n.jsx(T,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:D.takeOn.none}),n.jsx(El,{onClick:()=>m(Ua.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:D.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":D.takeOn.title,children:Ua.map(g=>{const v=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":v,onClick:()=>f(g.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(me,{name:NG[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:v?n.jsx(me,{name:"check",size:12}):null})]}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:g.title}),n.jsx("span",{className:"wiz-opt-plugins",children:g.plugins})]}),n.jsx("span",{className:"wiz-opt-line",children:g.line})]},g.id)})}),h.length>0?n.jsxs("div",{className:"wiz-stack",children:[p?n.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[n.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),n.jsx("span",{children:p.line}),l.includes("mail")?n.jsx("span",{className:"wiz-busy-side",children:D.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:h.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:D.takeOn.nothing})]})]})}function EG({answers:e,navigate:t,onSettled:s,onBack:r}){var g,v,b;const[i,a]=d.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=d.useState(((v=e.reach)==null?void 0:v.mailbox)===!0),[c,u]=d.useState(((b=e.reach)==null?void 0:b.app)===!0),[h,f]=d.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const j={phone:i,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>A.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.reach.title}),n.jsx(tt,{children:n.jsx(ot,{children:D.reach.ask})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:r}),n.jsx(El,{onClick:p,children:D.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(AG,{paired:i,onPaired:()=>a(!0)}),n.jsx(RG,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx($G,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),i?n.jsx(K,{tone:"good",role:"status",children:D.reach.phone.hello}):null]})})]})}function AG({paired:e,onPaired:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1),l=d.useRef(t);l.current=t,d.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>A.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(me,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:D.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:D.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ve,{tone:"good",dot:!0,children:D.reach.phone.paired})}):o?n.jsx(TG,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(T,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:D.reach.phone.setUp})}),i?n.jsx(pt,{title:D.telegram.sheet,onClose:()=>a(!1),children:n.jsx(LG,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function TG({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=Cj(()=>A.telegram().then(o=>o.paired),e),l=d.useRef(!1);return d.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ve,{tone:"good",dot:!0,children:D.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(T,{size:"lg",onClick:()=>void a().catch(()=>{}),children:D.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(Ej,{offer:t,square:s})})}function RG({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=d.useState(void 0),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=d.useCallback(()=>{Promise.resolve().then(()=>A.pageQuery("email","accounts")).then(m=>{var g,v,b;const p=((b=(v=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:v[0])==null?void 0:b.address)??null;h(p),s(p!==null)}).catch(()=>{})},[]);return d.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>A.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),v=g.find(b=>b.id==="settings")??null;l(v?{page:v,siblings:g}:null)}).catch(()=>{m||l(null)}),f(),()=>{m=!0}},[f]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(me,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?D.reach.mailbox.forTriage:D.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?D.reach.mailbox.unavailable:D.reach.mailbox.line})]}),n.jsx("span",{className:"wiz-row-side",children:t||u?n.jsx(ve,{tone:"good",dot:!0,mono:u!==null,children:u??D.reach.mailbox.added}):a?n.jsx(T,{size:"lg",onClick:()=>c(!0),children:D.reach.mailbox.add}):null}),o&&a?n.jsx(pt,{title:D.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:n.jsx(ej,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function $G({app:e,onApp:t,browser:s,onBrowser:r}){const i=Sh(),a=typeof navigator>"u"?null:sA(navigator.userAgent),[l,o]=d.useState(null),[c,u]=d.useState("idle"),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState(void 0),b=d.useRef(!1),j=d.useRef(!0);d.useEffect(()=>(j.current=!0,Promise.resolve().then(()=>A.browser()).then(C=>{var R;if(!j.current)return;const $=C==null?void 0:C.browser;$?((R=$.install)==null?void 0:R.state)==="running"?(o("none"),b.current=!0,u("installing"),y()):o($.engine):o("other")}).catch(()=>{j.current&&o("other")}),()=>{j.current=!1}),[]);const x=(C,$)=>{j.current&&(b.current=!1,u("failed"),f(C),p($??null))},w=async C=>{u("launching");let $;try{$=await A.browserCheck()}catch(R){return x(R instanceof pe?R.message:String(R))}if(j.current){if($.ok){u("idle"),o(C),r(b.current?"installed":C);return}x($.message,$.command)}},y=async()=>{var R,I;let C;try{C=await A.browser()}catch(F){return x(F instanceof pe?F.message:String(F))}if(!j.current)return;const $=C.browser;if(!$)return x(D.browser.failed(""));if(((R=$.install)==null?void 0:R.state)==="running"){u("installing"),v($.install.progress),window.setTimeout(()=>void y(),1e3);return}return $.engine!=="none"?w($.engine):x(((I=$.install)==null?void 0:I.line)??"")},k=()=>{if(p(null),l==="chrome"||l==="chromium"){w(l);return}b.current=!0,u("installing"),v(void 0),Promise.resolve().then(()=>A.browserInstall()).then(()=>{j.current&&window.setTimeout(()=>void y(),1e3)}).catch(C=>x(C instanceof pe?C.message:String(C)))},N=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(me,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:D.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:D.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(ve,{tone:"good",dot:!0,children:D.reach.app.installed}):i?n.jsx(T,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:D.reach.app.install}):null,N?n.jsx(ve,{tone:"good",dot:!0,children:D.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(T,{size:"lg",disabled:S,onClick:k,children:S?D.browser.installing:c==="failed"?D.browser.retry:l==="chrome"?D.reach.app.chrome:l==="chromium"?D.reach.app.chromium:D.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:D.browser.needs}),n.jsx(xE,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(_s,{line:D.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:D.browser.failed(h??"")}),m?n.jsx(MG,{command:m}):null]}):null]})}function IG({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=d.useState(()=>(t==null?void 0:t.name)??fF),[c,u]=d.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[h,f]=d.useState(t?null:D.assistant.purposeValue),[m,p]=d.useState(t?"":D.assistant.purposeValue);d.useEffect(()=>{if(!t)return;let w=!1;return A.firstAgentPersona().then(y=>{w||(f(y.persona),p(y.persona))},y=>{w||r(y instanceof pe?y.message:String(y))}),()=>{w=!0}},[t==null?void 0:t.id]);const[g,v]=d.useState(!1),b=Ua.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),j=Zy.find(w=>w.id===c),x=()=>{if(l.trim()===""||g)return;v(!0);const w=!t||h!==null&&m.trim()!==""&&m.trim()!==h.trim()?{instructions:m.trim()}:{},y=t?A.updateFirstAgent({name:l.trim(),...w}):A.createFirstAgent({name:l.trim(),handle:tG(l),description:"",...w,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let k;try{k=await y}catch(S){r(S instanceof pe?S.message:String(S)),v(!1);return}let N=null;try{j&&await A.uploadAgentPicture(k.id,await qA(j.role))}catch(S){N=S instanceof pe?S.message:String(S)}v(!1),i(),s({...e,assistant:{id:k.id,name:l.trim(),avatar:j?"":(t==null?void 0:t.avatar)??""}}),N&&r(N)})()};return n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.assistant.title}),n.jsx(tt,{children:n.jsxs(ot,{children:[D.assistant.ask,b.length>0?D.assistant.team(b):""]})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Xn,{onClick:a,disabled:g}),n.jsx(El,{onClick:x,disabled:g||l.trim()===""||h===null,children:D.assistant.submit})]}),children:n.jsxs("div",{className:"wiz-meet",children:[n.jsxs("div",{className:"wiz-face",children:[n.jsx("span",{className:"wiz-face-tile","data-agent":(j==null?void 0:j.id)??"buddi","aria-hidden":"true",children:j?n.jsx("img",{src:aa(j.role),alt:""}):t!=null&&t.picture?n.jsx("img",{src:t.picture,alt:""}):n.jsx("span",{className:"wiz-face-emoji",children:(t==null?void 0:t.avatar)??""})}),n.jsx("div",{className:"wiz-swatches",role:"group","aria-label":D.assistant.colour,children:Zy.map(w=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":w.id,"aria-label":D.assistant.swatch(w.label),"aria-pressed":c===w.id,onClick:()=>u(w.id)},w.id))}),n.jsx("span",{className:"wiz-face-cap",children:D.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(ae,{label:D.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:w=>o(w.target.value)})}),n.jsx(ae,{label:D.assistant.purpose,hint:D.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:w=>p(w.target.value)})})]})]})})]})}function PG({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var M;const u=e.assistant,[h,f]=d.useState(s),[m,p]=d.useState([]),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(!0),[y,k]=d.useState(!1),N=d.useRef(!1),S=d.useMemo(()=>t?[t]:[],[t]);d.useEffect(()=>{c()},[]),d.useEffect(()=>{if(!u||N.current)return;if(N.current=!0,s){f(s);return}let P=!1;return(async()=>{try{const U=await Be.startConversation(u.id);if(P)return;f(U.conversationId),r(U.conversationId),await A.onboardingStep(aR.handover,{conversationId:U.conversationId}).catch(()=>{}),await Be.send(u.id,{conversationId:U.conversationId,text:xF,opening:!0})}catch{P||(w(!1),v(!0))}})(),()=>{P=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let P=!1;const U=Date.now(),L=()=>{Be.conversation(h).then(O=>{if(P)return;p(O.messages);const V=Date.now()-U;if(O.messages.some(_k)){w(!1),v(!1),j(!1);return}const X=O.runs??[],G=X.some(z=>z.finishedAt===null),Z=X.length>0&&!G;j(G&&V>=nG),(Z||V>=sG)&&(w(!1),v(!0))}).catch(()=>{})};L();const W=window.setInterval(L,dR);return()=>{P=!0,window.clearInterval(W)}},[h]);const C=u&&h?at(u.id,h):null,$=m.some(_k);d.useEffect(()=>{$&&C&&l(C)},[$,C,l]);const R=e.takeOn??[],I=Ua.filter(P=>R.includes(P.id)&&"mate"in P).map(P=>P.mate),F=D.handover.starters({days:R.includes("days"),mail:R.includes("mail"),mailbox:((M=e.reach)==null?void 0:M.mailbox)===!0},I),_=(o==null?void 0:o.waiting)??[],E=P=>{!u||!h||y||(k(!0),Promise.resolve().then(()=>Be.send(u.id,{conversationId:h,text:P})).then(()=>i(at(u.id,h),!0)).catch(()=>k(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(_v,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:x,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:D.handover.waiting,plain:!0,workingLine:D.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?n.jsx(tt,{children:n.jsx(ot,{children:D.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(tt,{children:n.jsx(ot,{children:D.handover.silent})}),n.jsx(Yt,{actions:n.jsx(El,{onClick:a,children:D.handover.again})})]}):null,$?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":D.handover.starterLabel,children:F.map(P=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>E(P),children:P},P))}):null,$&&_.length>0?n.jsx(K,{tone:"warm",title:D.handover.waitingTitle(_.length),action:n.jsx(T,{variant:"accent",onClick:()=>i(tn,!0),children:D.handover.home}),children:D.handover.waitingBody(_)}):null,$&&C?n.jsx(Yt,{actions:n.jsx(Tt,{variant:"accent",size:"lg",href:C,onClick:P=>{P.preventDefault(),i(C,!0)},children:D.done.open})}):null]})}function MG({command:e}){const[t,s]=d.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(se,{gap:"sm",children:[n.jsx($t,{label:"The command to run",children:e}),n.jsxs(re,{align:"end",children:[t==="failed"?n.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,n.jsx(T,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function _k(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function DG({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=d.useState(null),[a,l]=d.useState(""),[o,c]=d.useState(!1),u=()=>{!r||o||(c(!0),s(null),A.firstRunRestore(r,a.trim()).then(h=>{Lg(h.job.id),t()}).catch(h=>s(h instanceof pe?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(pt,{title:D.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:D.restore.lede}),n.jsx(ae,{label:D.restore.file,children:n.jsx("input",{type:"file",onChange:h=>{var f;return i(((f=h.target.files)==null?void 0:f[0])??null)}})}),n.jsx(ae,{label:D.restore.passphrase,hint:D.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:h=>l(h.target.value)})}),n.jsxs(re,{align:"end",children:[n.jsx(T,{variant:"ghost",onClick:e,children:D.restore.cancel}),n.jsx(T,{variant:"accent",disabled:o||!r,onClick:u,children:D.restore.submit})]})]})})}function OG({onDone:e,onFailed:t}){const[s,r]=d.useState([]),i=d.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},d.useEffect(()=>{const l=uR();if(!l)return;let o=!1;const c=()=>{A.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,Lg(null),A.owner().then(f=>i.current.onDone(f.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Lg(null),i.current.onFailed(h.error??D.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,dR);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in D.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(Al,{children:D.restore.title}),n.jsxs(tt,{children:[n.jsx(ot,{children:D.restore.started}),a.map(l=>n.jsx(ot,{children:D.restore.phases[l]},l))]}),n.jsx(_s,{})]})}function LG(e){return n.jsx(Tj.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(_G,{...e})})})}function _G({onPaired:e,onDismiss:t}){const s=Cl(),[r,i]=d.useState(""),[a,l]=d.useState(!1),[o,c]=d.useState(null),{offer:u,square:h,paired:f,stale:m,ask:p}=Cj(()=>A.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await A.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??D.telegram.restart);return}await p()}catch(b){c(b instanceof pe?b.message:String(b))}finally{l(!1)}})())},v=()=>{c(null),p().catch(b=>c(b instanceof pe?b.message:String(b)))};return f?n.jsxs(n.Fragment,{children:[n.jsx(tt,{children:n.jsx(ot,{children:D.telegram.paired})}),n.jsx(Yt,{actions:n.jsx(T,{variant:"accent",onClick:t,children:D.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(tt,{children:n.jsx(ot,{children:m?D.telegram.expired:D.telegram.scan})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:D.telegram.notNow}),m?n.jsx(T,{variant:"accent",onClick:v,children:D.telegram.newCode}):null]}),children:m?null:n.jsx(Ej,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(tt,{children:[n.jsx(ot,{children:D.telegram.how}),o?n.jsx(ot,{children:o}):null]}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:D.telegram.notNow}),n.jsx(T,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:D.telegram.submit})]}),children:n.jsx(ae,{label:D.telegram.field,grow:!0,children:n.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g())}})})})]})}const hm={recovery:0,lost:1,paused:2},FG="Lost buddi. Retrying…",zG="The queue is paused. Nothing is being claimed until you resume it.";function UG(e){const t=[];return e.recovery&&t.push({id:"recovery",priority:hm.recovery,tone:"warning",text:uK,action:{label:"Finish the checklist",href:j_}}),e.lost&&t.push({id:"lost",priority:hm.lost,tone:"critical",text:FG}),e.paused&&t.push({id:"paused",priority:hm.paused,tone:"warning",text:zG,action:{label:"Resume",onClick:()=>{A.setPaused(!1).catch(()=>{})}}}),t}function BG({banners:e,onNavigate:t}){if(e.length===0)return null;const s=[...e].sort((l,o)=>l.priority-o.priority),r=s[0],i=s.slice(1),a=r.action;return n.jsxs("div",{className:"shell-banner",role:"status","data-tone":r.tone,"data-banner":r.id,children:[n.jsx("span",{className:"shell-banner-dot","aria-hidden":"true"}),n.jsx("span",{className:"shell-banner-text",children:r.text}),i.length>0?n.jsxs("span",{className:"shell-banner-more",title:i.map(l=>l.text).join(`
131
- `),children:["+",i.length," more"]}):null,a!=null&&a.href?n.jsx(Tt,{size:"sm",href:a.href,onClick:l=>{l.preventDefault(),t(a.href)},children:a.label}):a?n.jsx(T,{size:"sm",onClick:a.onClick,children:a.label}):null]})}const mR=1e4,WG=3e4,pR=6e3,gR=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function HG(e){return gR.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 xR(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new pe(0,md)),e)});try{return{up:!0,version:await Promise.race([A.version(),s])}}catch(r){return Np(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function vR(e){var t;return e.up&&vv((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function KG({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:aa("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:HG(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(T,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function VG({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(!1),a=d.useRef(!1),l=d.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await xR(pR);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":vR(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),mR);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(KG,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsx(n.Fragment,{children:e})}function GG(e=WG){const[t,s]=d.useState(!1);return d.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=kp();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=cC(i);return()=>{a(),clearTimeout(r)}},[e]),t}function YG(){const e=GG();return d.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{xR(pR).then(vR)},mR);return()=>window.clearInterval(t)},[e]),e}const qG={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},Fk=(e,t,s=`${t}s`)=>e===1?t:s;function QG(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function XG(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function JG(e,t){return t?"reconnecting":gR.test(e)?"local":"tailnet"}function jR(e,t,s=QG()){const r=[],i=qG[e.link];if(r.push({key:"link",route:_e("system"),dot:e.link==="reconnecting"?"warning":"good",text:i,label:`Connection: ${i}`}),e.focus){const u=`${_i[e.focus.mode]} ${Qo(e.focus,e.timezone,t)}`;r.push({key:"focus",route:_e("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const a=[];if(e.working>0&&a.push({key:"working",dot:"working",text:`${e.working} ${Fk(e.working,"agent")} working`}),a.push(e.paused?{key:"queue",tone:"warning",text:"Queue paused"}:{key:"queue",text:"Queue running"}),e.failed>0&&a.push({key:"failed",tone:"critical",text:`${e.failed} failed`}),r.push({key:"work",route:e.failed>0?`${xt}/jobs?state=failed`:`${xt}/jobs`,parts:a,label:`Work: ${a.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${Fk(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:fv,count:e.approvals,text:u,label:`${e.approvals} ${u}`})}if(e.version){const u=e.version.updateAvailable&&e.version.latest?e.version.latest:null;r.push({key:"version",route:_e("system"),end:!0,mono:`buddi ${e.version.current}`,update:u!==null,label:`buddi ${e.version.current}${u?`, a newer buddi is ready: ${u}`:""}`})}const l=e.timezone||s,o=Ut(t,l),c=l!==s;return r.push({key:"time",route:_e("you"),end:!0,time:o,...c?{zone:XG(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function ZG(e){var t;return e.link==="reconnecting"||e.failed>0?"critical":e.paused?"warning":e.approvals>0||(((t=e.version)==null?void 0:t.updateAvailable)??!1)?"attention":"good"}function wR(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function eY(){const[e,t]=d.useState(()=>kp()!==null);return d.useEffect(()=>cC(()=>t(kp()!==null)),[]),e}function yR({item:e}){var t;return n.jsxs(n.Fragment,{children:[e.dot?n.jsx("span",{className:"shell-status-dot","data-tone":e.dot,"aria-hidden":"true"}):null,e.icon?n.jsx(me,{name:e.icon,size:12}):null,e.count?n.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(t=e.parts)==null?void 0:t.map((s,r)=>n.jsxs(d.Fragment,{children:[r>0?n.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?n.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,n.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?n.jsx("span",{children:e.text}):null,e.mono?n.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?n.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?n.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?n.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function tY({status:e,onNavigate:t}){const s=wR(),r=Ch(),i=jR(e,s),a=l=>n.jsx("a",{className:"shell-status-item","data-item":l.key,href:l.route,"aria-label":l.label,title:l.label,onClick:o=>{o.preventDefault(),t(l.route)},children:n.jsx(yR,{item:l})},l.key);return n.jsxs("footer",{className:"shell-status","aria-label":"Status",children:[i.filter(l=>!l.end).map(a),n.jsx("span",{className:"shell-status-spacer"}),i.filter(l=>l.end).map(a),r.pin?n.jsx("button",{type:"button",className:"shell-status-item shell-status-lock","data-item":"lock","aria-label":`Lock now (${r.shortcut})`,title:`Lock now (${r.shortcut})`,onClick:()=>r.lockNow(),children:n.jsx(me,{name:"lock",size:13})}):null]})}function nY({status:e,onNavigate:t}){const s=wR(),r=Ch(),i=ZG(e);return n.jsx("div",{className:"rail-status",children:n.jsxs(cc,{modal:!1,children:[n.jsx(uc,{asChild:!0,children:n.jsx("button",{type:"button",className:"rail-status-btn","aria-label":"Status",children:n.jsx("span",{className:"rail-status-dot","data-tone":i,"data-testid":"rail-status-dot","aria-hidden":"true"})})}),n.jsx(vl,{children:n.jsxs(dc,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[n.jsx(Qi,{className:"ui-menu-label",children:"Status"}),jR(e,s).map(a=>n.jsx(cs,{asChild:!0,onSelect:()=>t(a.route),children:n.jsx("a",{className:"ui-menu-item rail-status-item","data-item":a.key,href:a.route,"aria-label":a.label,children:n.jsx("span",{className:"rail-status-line",children:n.jsx(yR,{item:a})})})},a.key)),r.pin?n.jsxs(n.Fragment,{children:[n.jsx(yr,{className:"ui-menu-sep"}),n.jsx(cs,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:n.jsxs("span",{className:"rail-status-line",children:[n.jsx(me,{name:"lock",size:12}),n.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const sY="(max-width: 1080px)",rY="(max-width: 720px)";function iY(){const[e,t]=d.useState(()=>window.location.hash||tn);d.useEffect(()=>{const r=()=>t(window.location.hash||tn);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=d.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function aY(){const[e,t]=NA();d.useEffect(()=>{kA(e)},[e]);const s=d.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const zk=new Map;function lY(){var Wt,js,wn,ws;const[e,t]=iY(),[s,r]=d.useState("UTC"),[i,a]=d.useState({approvals:0,failed:0,paused:!1,running:0}),[l,o]=aY(),c=tr(Yv),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState([]),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[$,R]=d.useState(0),[I,F]=d.useState(null),_=q_(),E=f.find(be=>be.id===p)??null,M=E!==null&&D6(e),[P,U]=d.useState(!1),L=d.useCallback(()=>U(!0),[]);d.useEffect(()=>{M||U(!1)},[M]),_8(t,Iu(e)===null,M?L:void 0);const W=tr(sY),O=eT(),V=Z1(),X=vA(),G=ue(()=>Promise.resolve().then(()=>A.version()),[],P_),Z=G.data;W_(G.reload);const z=Z&&!Z.checkout&&Z.updateAvailable?Z:null,q=vv(Z==null?void 0:Z.web);H_(Z==null?void 0:Z.web);const Q=((Wt=ue(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4).data)==null?void 0:Wt.signals)??[],[ce,Pe]=d.useState(null),Te=d.useMemo(()=>new Set(ce?[ce]:[]),[ce]),[Le,J]=d.useState(new Map);d.useEffect(()=>{const be=()=>{A.conversations().then(Me=>{const Xe=new Map;for(const we of Me.conversations){const Fs=we.lastMessageAt??we.createdAt,ys=Xe.get(we.agentId);(!ys||Fs>ys)&&Xe.set(we.agentId,Fs)}J(Xe)}).catch(()=>{})};be();const Ue=window.setInterval(be,3e4);return()=>window.clearInterval(Ue)},[e]);const[ke,ne]=d.useState(!1);d.useEffect(()=>{if(ke)return;let be=!1;return A.onboarding().then(Ue=>{be||(ne(!0),Ue.state==="pending"&&Ue.needs.model&&!Iu(window.location.hash)&&t(JL,!0))}).catch(()=>{be||ne(!0)}),()=>{be=!0}},[ke,t]),d.useEffect(()=>{const be=w_(e);be&&t(be,!0)},[e,t]),d.useEffect(()=>{let be=!1;const Ue=()=>{Be.agents().then(Xe=>{be||(m(Xe.agents),E_(Xe.defaultAgentId??null),g(Xe.defaultAgentId??null),b(we=>{var Fs;return we??Xe.defaultAgentId??((Fs=Xe.agents[0])==null?void 0:Fs.id)??null}))}).catch(()=>{})};Ue();const Me=window.setInterval(Ue,15e3);return window.addEventListener("focus",Ue),window.addEventListener(Uo,Ue),()=>{be=!0,window.clearInterval(Me),window.removeEventListener("focus",Ue),window.removeEventListener(Uo,Ue)}},[e]),d.useEffect(()=>{let be=!1;const Ue=()=>{Be.groups().then(Xe=>{be||x(Xe.groups)}).catch(()=>{})};Ue();const Me=window.setInterval(Ue,3e4);return()=>{be=!0,window.clearInterval(Me)}},[e]);const Ae=g1(f,p),de=e_(e),Re=l1(e),De=Re?j.find(be=>be.id===Re.groupId)??null:null,Ve=Re?null:(de==null?void 0:de.agentId)??v;d.useEffect(()=>{de&&b(de.agentId)},[de==null?void 0:de.agentId]);const he=d.useRef(null);de&&(he.current=e);const ze=be=>{b(be),t(at(be))},Ge=be=>t(Ii(be)),Ye=d.useCallback((be,Ue,Me=!0)=>t(Re?Ii(Re.groupId,Ue):at(be,Ue),Me),[t,Re==null?void 0:Re.groupId]),[nt,Pt]=d.useState(!1),[,un]=d.useState(0);d.useEffect(()=>{const be=()=>{un(Ue=>Ue+1),A.session().then(Ue=>r(Ue.timezone)).catch(()=>{})};return window.addEventListener(vp,be),()=>window.removeEventListener(vp,be)},[]),d.useEffect(()=>{A.session().then(be=>{qx({timeFormat:be.timeFormat??null,dateFormat:be.dateFormat??null}),r(be.timezone),Pt(!0)}).catch(()=>{})},[]);const ee=H6(nt);q6(nt,ee.refresh,()=>Pt(!1)),d.useEffect(()=>{const be=()=>{A.overview().then(Me=>a({approvals:Me.approvals.pending,failed:Me.jobs.failed??0,paused:Me.paused,running:Me.running??0})).catch(()=>{})};be();const Ue=window.setInterval(be,2e4);return window.addEventListener(Zl,be),()=>{window.clearInterval(Ue),window.removeEventListener(Zl,be)}},[]);const ye=ue(()=>Promise.resolve().then(()=>A.focus()),[],6e4),H=d.useRef(ye.reload);H.current=ye.reload,d.useEffect(()=>{const be=()=>H.current();return window.addEventListener(Zl,be),()=>window.removeEventListener(Zl,be)},[]);const Fe=eY(),wt=YG(),dt=tr(rY);d.useEffect(()=>{if(!nt)return;if(e===y_){y(!0),t(ii,!0);return}const be=b_(e),Ue=new Date().toDateString();!be||zk.get(be)===Ue||(zk.set(be,Ue),A.tipsSeenPage(be).catch(()=>{}))},[e,nt,t]);const Un={link:JG(window.location.hostname,Fe),focus:((js=ye.data)==null?void 0:js.focus)??null,working:i.running,paused:i.paused,failed:i.failed,approvals:i.approvals,version:Z?{current:Z.current,latest:Z.latest,updateAvailable:!Z.checkout&&Z.updateAvailable}:void 0,timezone:s},ur=UG({recovery:((wn=O.data)==null?void 0:wn.active)===!0,lost:wt,paused:i.paused}),Y=Iu(e),Ee=f1(e),it=Ee===ii,et=k?j.find(be=>be.id===k.groupId)??null:null,Qt=be=>x(Ue=>Ue.map(Me=>Me.id===be.id?be:Me)),je=()=>N(null),qe=w?n.jsx(Q6,{agents:f,onClose:()=>y(!1),onCreated:be=>{x(Ue=>[...Ue,be]),y(!1),t(Ii(be.id))}}):et&&(k==null?void 0:k.kind)==="members"?n.jsx(w6,{group:et,agents:f,onClose:je,onSaved:Qt}):et&&(k==null?void 0:k.kind)==="rename"?n.jsx(y6,{group:et,onClose:je,onSaved:be=>{Qt(be),je()}}):et&&(k==null?void 0:k.kind)==="clear"?n.jsx(k6,{group:et,onClose:je,onCleared:()=>{je(),R(be=>be+1),t(Ii(et.id),!0)}}):et&&(k==null?void 0:k.kind)==="delete"?n.jsx(N6,{group:et,agents:f,onClose:je,onDeleted:be=>{const Ue=j.findIndex(Me=>Me.id===et.id);je(),x(Me=>Me.filter(Xe=>Xe.id!==et.id)),C({group:et,index:Ue,until:be}),t(he.current??ii)}}):null,Oe=()=>{const be=S;be&&(C(null),Be.restoreGroup(be.group.id).then(Ue=>{x(Me=>{if(Me.some(we=>we.id===Ue.id))return Me;const Xe=[...Me];return Xe.splice(Math.min(Math.max(be.index,0),Xe.length),0,Ue),Xe}),t(Ii(Ue.id))}).catch(()=>F(be.group.name)))};return Y?n.jsx(Iy,{delayDuration:400,children:n.jsxs(jy,{swipeDirection:"right",children:[n.jsx(lG,{navigate:t,timezone:s}),n.jsx(wy,{className:"ui-toasts"})]})}):n.jsx(NF,{picture:(ws=f.find(be=>be.id===p))==null?void 0:ws.picture,children:n.jsx(Iy,{delayDuration:400,children:n.jsxs(jy,{swipeDirection:"right",children:[qe,n.jsxs("div",{className:"wb-shell",children:[n.jsx(BG,{banners:ur,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(C8,{attention:i.approvals+i.failed,place:Ee,onNavigate:t,theme:l,onTheme:o,plugins:O8(V.rail,X),updateAvailable:z!==null,settingsDot:Q.length>0?xA:void 0,stale:q,timezone:s,version:Z&&!Z.checkout?{current:Z.current,latest:Z.latest,updateAvailable:Z.updateAvailable}:Z?{current:Z.current,updateAvailable:!1}:void 0,status:dt?n.jsx(nY,{status:Un,onNavigate:t}):void 0}),it&&!W?n.jsx(y1,{agents:Ae,currentId:Ve,attention:_,onSelect:ze,lastActivity:Le,working:Te,groups:j,currentGroupId:(De==null?void 0:De.id)??null,onSelectGroup:Ge,onNewGroup:()=>y(!0)}):null,it?n.jsx(S6,{timezone:s,agents:Ae,agentId:De?De.coordinator:Ve,defaultAgentId:p,group:De,...De?{onGroupAction:be=>N({kind:be,groupId:De.id})}:{},requestedConversationId:(Re==null?void 0:Re.conversationId)??(de==null?void 0:de.conversationId),requestedTab:de==null?void 0:de.tab,onConversationOpened:Ye,onSelectAgent:ze,onWorking:Pe,attention:_,agentsInHeader:W,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${$}`):n.jsx("main",{"data-ground":oY(Ee,e)?"plain":void 0,"data-layout":Ee===gn?"split":void 0,children:n.jsx(cY,{hash:e,place:Ee,timezone:s,navigate:t,agents:f,defaultAgentId:p,attention:_,pluginPages:V,update:z,connectionSignals:Q})})]}),dt?null:n.jsx(tY,{status:Un,onNavigate:t})]}),M&&E?n.jsx(O6,{agent:E,agents:f,open:P,onOpenChange:U,navigate:t}):null,n.jsxs(B6,{placement:U6(M,P),children:[n.jsx(K6,{queue:ee.queue,agents:f,navigate:t,onDismiss:ee.dismiss}),S?n.jsx(Ub,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:J6,onUndo:Oe,onGone:()=>C(null)},S.group.id):null,I?n.jsx(Ub,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>F(null)},`late-${I}`):null,n.jsx(wy,{className:"ui-toasts"})]})]})})})}function oY(e,t){return mv(t)!==null}function cY({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=mv(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(ej,{page:a,item:i.item??null,params:o1(s.hash),navigate:s.navigate,timezone:s.timezone,siblings:t.all.filter(l=>l.plugin===i.plugin)});if(t.all.length===0)return n.jsx(n.Fragment,{})}switch(e){case Nt:return n.jsx(CH,{...s});case xt:return n.jsx(J8,{...s});case gn:return n.jsx(T9,{...r});case Xi:return n.jsx(d5,{...s});default:return n.jsx(HH,{...s})}}function uY(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(xv)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function dY({search:e=location.search}){const[t,s]=d.useState(null),r=d.useRef(!1);return d.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;A.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(KA);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(se,{gap:"lg",children:[n.jsx("h2",{className:"ui-page-title",children:"Connections"}),t===null?n.jsx(K,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(K,{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(K,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(Tt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const Uk=document.getElementById("root");Uk&&eS(Uk).render(n.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(dY,{}):n.jsx(VG,{children:n.jsx(S8,{children:n.jsx(lY,{})})})}));uY();export{fY as c,_R as g};