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

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 (336) hide show
  1. package/README.md +58 -368
  2. package/extension/manifest.json +2 -2
  3. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  4. package/node_modules/@buddi/cli/dist/commands.js +1 -1
  5. package/node_modules/@buddi/cli/dist/commands.js.map +1 -1
  6. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  7. package/node_modules/@buddi/cli/dist/doctor-probes.js +4 -11
  8. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  9. package/node_modules/@buddi/cli/dist/doctor.d.ts +16 -0
  10. package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
  11. package/node_modules/@buddi/cli/dist/doctor.js +30 -0
  12. package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
  13. package/node_modules/@buddi/cli/dist/main.d.ts.map +1 -1
  14. package/node_modules/@buddi/cli/dist/main.js +22 -8
  15. package/node_modules/@buddi/cli/dist/main.js.map +1 -1
  16. package/node_modules/@buddi/cli/dist/mcp/tools.d.ts.map +1 -1
  17. package/node_modules/@buddi/cli/dist/mcp/tools.js +3 -1
  18. package/node_modules/@buddi/cli/dist/mcp/tools.js.map +1 -1
  19. package/node_modules/@buddi/cli/dist/status.d.ts +15 -9
  20. package/node_modules/@buddi/cli/dist/status.d.ts.map +1 -1
  21. package/node_modules/@buddi/cli/dist/status.js +6 -11
  22. package/node_modules/@buddi/cli/dist/status.js.map +1 -1
  23. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  24. package/node_modules/@buddi/core/dist/actions/store.d.ts +8 -0
  25. package/node_modules/@buddi/core/dist/actions/store.d.ts.map +1 -1
  26. package/node_modules/@buddi/core/dist/actions/store.js +13 -0
  27. package/node_modules/@buddi/core/dist/actions/store.js.map +1 -1
  28. package/node_modules/@buddi/core/dist/clock-widget.d.ts.map +1 -1
  29. package/node_modules/@buddi/core/dist/clock-widget.js +5 -3
  30. package/node_modules/@buddi/core/dist/clock-widget.js.map +1 -1
  31. package/node_modules/@buddi/core/dist/host/build.d.ts.map +1 -1
  32. package/node_modules/@buddi/core/dist/host/build.js +11 -0
  33. package/node_modules/@buddi/core/dist/host/build.js.map +1 -1
  34. package/node_modules/@buddi/core/dist/host/types.d.ts +7 -0
  35. package/node_modules/@buddi/core/dist/host/types.d.ts.map +1 -1
  36. package/node_modules/@buddi/core/dist/learning/store.d.ts +7 -0
  37. package/node_modules/@buddi/core/dist/learning/store.d.ts.map +1 -1
  38. package/node_modules/@buddi/core/dist/learning/store.js +6 -0
  39. package/node_modules/@buddi/core/dist/learning/store.js.map +1 -1
  40. package/node_modules/@buddi/core/dist/notifications/agent.d.ts +7 -0
  41. package/node_modules/@buddi/core/dist/notifications/agent.d.ts.map +1 -1
  42. package/node_modules/@buddi/core/dist/notifications/agent.js +2 -0
  43. package/node_modules/@buddi/core/dist/notifications/agent.js.map +1 -1
  44. package/node_modules/@buddi/core/dist/notifications/index.d.ts +1 -0
  45. package/node_modules/@buddi/core/dist/notifications/index.d.ts.map +1 -1
  46. package/node_modules/@buddi/core/dist/notifications/index.js +1 -0
  47. package/node_modules/@buddi/core/dist/notifications/index.js.map +1 -1
  48. package/node_modules/@buddi/core/dist/notifications/needs.d.ts +49 -0
  49. package/node_modules/@buddi/core/dist/notifications/needs.d.ts.map +1 -0
  50. package/node_modules/@buddi/core/dist/notifications/needs.js +41 -0
  51. package/node_modules/@buddi/core/dist/notifications/needs.js.map +1 -0
  52. package/node_modules/@buddi/core/dist/notifications/notify.d.ts.map +1 -1
  53. package/node_modules/@buddi/core/dist/notifications/notify.js +16 -7
  54. package/node_modules/@buddi/core/dist/notifications/notify.js.map +1 -1
  55. package/node_modules/@buddi/core/dist/notifications/store.d.ts.map +1 -1
  56. package/node_modules/@buddi/core/dist/notifications/store.js +2 -1
  57. package/node_modules/@buddi/core/dist/notifications/store.js.map +1 -1
  58. package/node_modules/@buddi/core/dist/notifications/types.d.ts +10 -0
  59. package/node_modules/@buddi/core/dist/notifications/types.d.ts.map +1 -1
  60. package/node_modules/@buddi/core/dist/notifications/types.js.map +1 -1
  61. package/node_modules/@buddi/core/dist/owner-timezone.d.ts +20 -22
  62. package/node_modules/@buddi/core/dist/owner-timezone.d.ts.map +1 -1
  63. package/node_modules/@buddi/core/dist/owner-timezone.js +17 -25
  64. package/node_modules/@buddi/core/dist/owner-timezone.js.map +1 -1
  65. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  66. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  67. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +39 -10
  68. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
  69. package/node_modules/@buddi/core/dist/scheduler/missions.js +44 -17
  70. package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
  71. package/node_modules/@buddi/core/dist/scheduler/types.d.ts +7 -0
  72. package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
  73. package/node_modules/@buddi/core/dist/scheduler/types.js +1 -0
  74. package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
  75. package/node_modules/@buddi/core/dist/web-settings.d.ts +13 -0
  76. package/node_modules/@buddi/core/dist/web-settings.d.ts.map +1 -1
  77. package/node_modules/@buddi/core/dist/web-settings.js +26 -0
  78. package/node_modules/@buddi/core/dist/web-settings.js.map +1 -1
  79. package/node_modules/@buddi/core/dist/widgets.d.ts +13 -5
  80. package/node_modules/@buddi/core/dist/widgets.d.ts.map +1 -1
  81. package/node_modules/@buddi/core/dist/widgets.js +10 -1
  82. package/node_modules/@buddi/core/dist/widgets.js.map +1 -1
  83. package/node_modules/@buddi/core/migrations/068_notification_action.sql +12 -0
  84. package/node_modules/@buddi/core/migrations/069_schedule_zone_explicit.sql +18 -0
  85. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  86. package/node_modules/@buddi/gateway/dist/agents/learning-digest.d.ts +29 -7
  87. package/node_modules/@buddi/gateway/dist/agents/learning-digest.d.ts.map +1 -1
  88. package/node_modules/@buddi/gateway/dist/agents/learning-digest.js +87 -38
  89. package/node_modules/@buddi/gateway/dist/agents/learning-digest.js.map +1 -1
  90. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  91. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js +11 -1
  92. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js.map +1 -1
  93. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
  94. package/node_modules/@buddi/gateway/dist/agents/platform.js +2 -0
  95. package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/index.d.ts +1 -0
  97. package/node_modules/@buddi/gateway/dist/index.d.ts.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/index.js +1 -0
  99. package/node_modules/@buddi/gateway/dist/index.js.map +1 -1
  100. package/node_modules/@buddi/gateway/dist/missions/defaults.d.ts +0 -6
  101. package/node_modules/@buddi/gateway/dist/missions/defaults.d.ts.map +1 -1
  102. package/node_modules/@buddi/gateway/dist/missions/defaults.js +4 -8
  103. package/node_modules/@buddi/gateway/dist/missions/defaults.js.map +1 -1
  104. package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts.map +1 -1
  105. package/node_modules/@buddi/gateway/dist/missions/reminders.js +4 -1
  106. package/node_modules/@buddi/gateway/dist/missions/reminders.js.map +1 -1
  107. package/node_modules/@buddi/gateway/dist/missions/zone-provenance.d.ts +13 -0
  108. package/node_modules/@buddi/gateway/dist/missions/zone-provenance.d.ts.map +1 -0
  109. package/node_modules/@buddi/gateway/dist/missions/zone-provenance.js +36 -0
  110. package/node_modules/@buddi/gateway/dist/missions/zone-provenance.js.map +1 -0
  111. package/node_modules/@buddi/gateway/dist/missions-cli.js +2 -2
  112. package/node_modules/@buddi/gateway/dist/missions-cli.js.map +1 -1
  113. package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
  114. package/node_modules/@buddi/gateway/dist/serve.js +10 -10
  115. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  116. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts +11 -1
  117. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
  118. package/node_modules/@buddi/gateway/dist/telegram/channel.js +13 -2
  119. package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
  120. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  121. package/node_modules/@buddi/gateway/dist/web/api-routes.js +8 -3
  122. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  123. package/node_modules/@buddi/gateway/dist/web/lock.d.ts +5 -1
  124. package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
  125. package/node_modules/@buddi/gateway/dist/web/lock.js +4 -15
  126. package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
  127. package/node_modules/@buddi/gateway/dist/web/needs-you.d.ts +36 -0
  128. package/node_modules/@buddi/gateway/dist/web/needs-you.d.ts.map +1 -0
  129. package/node_modules/@buddi/gateway/dist/web/needs-you.js +65 -0
  130. package/node_modules/@buddi/gateway/dist/web/needs-you.js.map +1 -0
  131. package/node_modules/@buddi/gateway/dist/web/notifications.d.ts +9 -1
  132. package/node_modules/@buddi/gateway/dist/web/notifications.d.ts.map +1 -1
  133. package/node_modules/@buddi/gateway/dist/web/notifications.js +14 -3
  134. package/node_modules/@buddi/gateway/dist/web/notifications.js.map +1 -1
  135. package/node_modules/@buddi/gateway/dist/web/read.d.ts +17 -1
  136. package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
  137. package/node_modules/@buddi/gateway/dist/web/read.js +52 -8
  138. package/node_modules/@buddi/gateway/dist/web/read.js.map +1 -1
  139. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  140. package/node_modules/@buddi/gateway/dist/web/server.js +28 -3
  141. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  142. package/node_modules/@buddi/gateway/dist/web/write.d.ts.map +1 -1
  143. package/node_modules/@buddi/gateway/dist/web/write.js +4 -0
  144. package/node_modules/@buddi/gateway/dist/web/write.js.map +1 -1
  145. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  146. package/node_modules/@buddi/install/dist/doctor-timezone.d.ts +17 -0
  147. package/node_modules/@buddi/install/dist/doctor-timezone.d.ts.map +1 -0
  148. package/node_modules/@buddi/install/dist/doctor-timezone.js +34 -0
  149. package/node_modules/@buddi/install/dist/doctor-timezone.js.map +1 -0
  150. package/node_modules/@buddi/install/dist/launcher.d.ts.map +1 -1
  151. package/node_modules/@buddi/install/dist/launcher.js +3 -0
  152. package/node_modules/@buddi/install/dist/launcher.js.map +1 -1
  153. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  154. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  155. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  156. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  157. package/node_modules/@buddi/tool-email/dist/needs-you.d.ts +4 -1
  158. package/node_modules/@buddi/tool-email/dist/needs-you.d.ts.map +1 -1
  159. package/node_modules/@buddi/tool-email/dist/needs-you.js +2 -0
  160. package/node_modules/@buddi/tool-email/dist/needs-you.js.map +1 -1
  161. package/node_modules/@buddi/tool-email/migrations/026_attention_filed.sql +89 -0
  162. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  163. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  164. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  165. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  166. package/package.json +2 -2
  167. package/packages/cli/dist/.tsbuildinfo +1 -1
  168. package/packages/cli/dist/commands.js +1 -1
  169. package/packages/cli/dist/commands.js.map +1 -1
  170. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  171. package/packages/cli/dist/doctor-probes.js +4 -11
  172. package/packages/cli/dist/doctor-probes.js.map +1 -1
  173. package/packages/cli/dist/doctor.d.ts +16 -0
  174. package/packages/cli/dist/doctor.d.ts.map +1 -1
  175. package/packages/cli/dist/doctor.js +30 -0
  176. package/packages/cli/dist/doctor.js.map +1 -1
  177. package/packages/cli/dist/main.d.ts.map +1 -1
  178. package/packages/cli/dist/main.js +22 -8
  179. package/packages/cli/dist/main.js.map +1 -1
  180. package/packages/cli/dist/mcp/tools.d.ts.map +1 -1
  181. package/packages/cli/dist/mcp/tools.js +3 -1
  182. package/packages/cli/dist/mcp/tools.js.map +1 -1
  183. package/packages/cli/dist/status.d.ts +15 -9
  184. package/packages/cli/dist/status.d.ts.map +1 -1
  185. package/packages/cli/dist/status.js +6 -11
  186. package/packages/cli/dist/status.js.map +1 -1
  187. package/packages/core/dist/.tsbuildinfo +1 -1
  188. package/packages/core/dist/actions/store.d.ts +8 -0
  189. package/packages/core/dist/actions/store.d.ts.map +1 -1
  190. package/packages/core/dist/actions/store.js +13 -0
  191. package/packages/core/dist/actions/store.js.map +1 -1
  192. package/packages/core/dist/clock-widget.d.ts.map +1 -1
  193. package/packages/core/dist/clock-widget.js +5 -3
  194. package/packages/core/dist/clock-widget.js.map +1 -1
  195. package/packages/core/dist/host/build.d.ts.map +1 -1
  196. package/packages/core/dist/host/build.js +11 -0
  197. package/packages/core/dist/host/build.js.map +1 -1
  198. package/packages/core/dist/host/types.d.ts +7 -0
  199. package/packages/core/dist/host/types.d.ts.map +1 -1
  200. package/packages/core/dist/learning/store.d.ts +7 -0
  201. package/packages/core/dist/learning/store.d.ts.map +1 -1
  202. package/packages/core/dist/learning/store.js +6 -0
  203. package/packages/core/dist/learning/store.js.map +1 -1
  204. package/packages/core/dist/notifications/agent.d.ts +7 -0
  205. package/packages/core/dist/notifications/agent.d.ts.map +1 -1
  206. package/packages/core/dist/notifications/agent.js +2 -0
  207. package/packages/core/dist/notifications/agent.js.map +1 -1
  208. package/packages/core/dist/notifications/index.d.ts +1 -0
  209. package/packages/core/dist/notifications/index.d.ts.map +1 -1
  210. package/packages/core/dist/notifications/index.js +1 -0
  211. package/packages/core/dist/notifications/index.js.map +1 -1
  212. package/packages/core/dist/notifications/needs.d.ts +49 -0
  213. package/packages/core/dist/notifications/needs.d.ts.map +1 -0
  214. package/packages/core/dist/notifications/needs.js +41 -0
  215. package/packages/core/dist/notifications/needs.js.map +1 -0
  216. package/packages/core/dist/notifications/notify.d.ts.map +1 -1
  217. package/packages/core/dist/notifications/notify.js +16 -7
  218. package/packages/core/dist/notifications/notify.js.map +1 -1
  219. package/packages/core/dist/notifications/store.d.ts.map +1 -1
  220. package/packages/core/dist/notifications/store.js +2 -1
  221. package/packages/core/dist/notifications/store.js.map +1 -1
  222. package/packages/core/dist/notifications/types.d.ts +10 -0
  223. package/packages/core/dist/notifications/types.d.ts.map +1 -1
  224. package/packages/core/dist/notifications/types.js.map +1 -1
  225. package/packages/core/dist/owner-timezone.d.ts +20 -22
  226. package/packages/core/dist/owner-timezone.d.ts.map +1 -1
  227. package/packages/core/dist/owner-timezone.js +17 -25
  228. package/packages/core/dist/owner-timezone.js.map +1 -1
  229. package/packages/core/dist/plugin/version.d.ts +1 -1
  230. package/packages/core/dist/plugin/version.js +1 -1
  231. package/packages/core/dist/scheduler/missions.d.ts +39 -10
  232. package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
  233. package/packages/core/dist/scheduler/missions.js +44 -17
  234. package/packages/core/dist/scheduler/missions.js.map +1 -1
  235. package/packages/core/dist/scheduler/types.d.ts +7 -0
  236. package/packages/core/dist/scheduler/types.d.ts.map +1 -1
  237. package/packages/core/dist/scheduler/types.js +1 -0
  238. package/packages/core/dist/scheduler/types.js.map +1 -1
  239. package/packages/core/dist/web-settings.d.ts +13 -0
  240. package/packages/core/dist/web-settings.d.ts.map +1 -1
  241. package/packages/core/dist/web-settings.js +26 -0
  242. package/packages/core/dist/web-settings.js.map +1 -1
  243. package/packages/core/dist/widgets.d.ts +13 -5
  244. package/packages/core/dist/widgets.d.ts.map +1 -1
  245. package/packages/core/dist/widgets.js +10 -1
  246. package/packages/core/dist/widgets.js.map +1 -1
  247. package/packages/core/migrations/068_notification_action.sql +12 -0
  248. package/packages/core/migrations/069_schedule_zone_explicit.sql +18 -0
  249. package/packages/gateway/dist/.tsbuildinfo +1 -1
  250. package/packages/gateway/dist/agents/learning-digest.d.ts +29 -7
  251. package/packages/gateway/dist/agents/learning-digest.d.ts.map +1 -1
  252. package/packages/gateway/dist/agents/learning-digest.js +87 -38
  253. package/packages/gateway/dist/agents/learning-digest.js.map +1 -1
  254. package/packages/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  255. package/packages/gateway/dist/agents/owner-tools.js +11 -1
  256. package/packages/gateway/dist/agents/owner-tools.js.map +1 -1
  257. package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
  258. package/packages/gateway/dist/agents/platform.js +2 -0
  259. package/packages/gateway/dist/agents/platform.js.map +1 -1
  260. package/packages/gateway/dist/index.d.ts +1 -0
  261. package/packages/gateway/dist/index.d.ts.map +1 -1
  262. package/packages/gateway/dist/index.js +1 -0
  263. package/packages/gateway/dist/index.js.map +1 -1
  264. package/packages/gateway/dist/missions/defaults.d.ts +0 -6
  265. package/packages/gateway/dist/missions/defaults.d.ts.map +1 -1
  266. package/packages/gateway/dist/missions/defaults.js +4 -8
  267. package/packages/gateway/dist/missions/defaults.js.map +1 -1
  268. package/packages/gateway/dist/missions/reminders.d.ts.map +1 -1
  269. package/packages/gateway/dist/missions/reminders.js +4 -1
  270. package/packages/gateway/dist/missions/reminders.js.map +1 -1
  271. package/packages/gateway/dist/missions/zone-provenance.d.ts +13 -0
  272. package/packages/gateway/dist/missions/zone-provenance.d.ts.map +1 -0
  273. package/packages/gateway/dist/missions/zone-provenance.js +36 -0
  274. package/packages/gateway/dist/missions/zone-provenance.js.map +1 -0
  275. package/packages/gateway/dist/missions-cli.js +2 -2
  276. package/packages/gateway/dist/missions-cli.js.map +1 -1
  277. package/packages/gateway/dist/serve.d.ts.map +1 -1
  278. package/packages/gateway/dist/serve.js +10 -10
  279. package/packages/gateway/dist/serve.js.map +1 -1
  280. package/packages/gateway/dist/telegram/channel.d.ts +11 -1
  281. package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
  282. package/packages/gateway/dist/telegram/channel.js +13 -2
  283. package/packages/gateway/dist/telegram/channel.js.map +1 -1
  284. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  285. package/packages/gateway/dist/web/api-routes.js +8 -3
  286. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  287. package/packages/gateway/dist/web/lock.d.ts +5 -1
  288. package/packages/gateway/dist/web/lock.d.ts.map +1 -1
  289. package/packages/gateway/dist/web/lock.js +4 -15
  290. package/packages/gateway/dist/web/lock.js.map +1 -1
  291. package/packages/gateway/dist/web/needs-you.d.ts +36 -0
  292. package/packages/gateway/dist/web/needs-you.d.ts.map +1 -0
  293. package/packages/gateway/dist/web/needs-you.js +65 -0
  294. package/packages/gateway/dist/web/needs-you.js.map +1 -0
  295. package/packages/gateway/dist/web/notifications.d.ts +9 -1
  296. package/packages/gateway/dist/web/notifications.d.ts.map +1 -1
  297. package/packages/gateway/dist/web/notifications.js +14 -3
  298. package/packages/gateway/dist/web/notifications.js.map +1 -1
  299. package/packages/gateway/dist/web/read.d.ts +17 -1
  300. package/packages/gateway/dist/web/read.d.ts.map +1 -1
  301. package/packages/gateway/dist/web/read.js +52 -8
  302. package/packages/gateway/dist/web/read.js.map +1 -1
  303. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  304. package/packages/gateway/dist/web/server.js +28 -3
  305. package/packages/gateway/dist/web/server.js.map +1 -1
  306. package/packages/gateway/dist/web/write.d.ts.map +1 -1
  307. package/packages/gateway/dist/web/write.js +4 -0
  308. package/packages/gateway/dist/web/write.js.map +1 -1
  309. package/packages/install/dist/.tsbuildinfo +1 -1
  310. package/packages/install/dist/doctor-timezone.d.ts +17 -0
  311. package/packages/install/dist/doctor-timezone.d.ts.map +1 -0
  312. package/packages/install/dist/doctor-timezone.js +34 -0
  313. package/packages/install/dist/doctor-timezone.js.map +1 -0
  314. package/packages/install/dist/launcher.d.ts.map +1 -1
  315. package/packages/install/dist/launcher.js +3 -0
  316. package/packages/install/dist/launcher.js.map +1 -1
  317. package/packages/runtime/dist/.tsbuildinfo +1 -1
  318. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  319. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  320. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  321. package/packages/tools/email/dist/needs-you.d.ts +4 -1
  322. package/packages/tools/email/dist/needs-you.d.ts.map +1 -1
  323. package/packages/tools/email/dist/needs-you.js +2 -0
  324. package/packages/tools/email/dist/needs-you.js.map +1 -1
  325. package/packages/tools/email/migrations/026_attention_filed.sql +89 -0
  326. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  327. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  328. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  329. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  330. package/packages/web/dist/assets/{index-Zrt_o2UG.css → index-BYRgwiZp.css} +1 -1
  331. package/packages/web/dist/assets/index-Qb1N-6kN.js +129 -0
  332. package/packages/web/dist/assets/{lottie_light-Ls7i1ATS.js → lottie_light-DU37j1-6.js} +1 -1
  333. package/packages/web/dist/build.json +1 -1
  334. package/packages/web/dist/index.html +2 -2
  335. package/packages/web/dist/precache.json +4 -4
  336. package/packages/web/dist/assets/index-WS4UjGsy.js +0 -129
@@ -0,0 +1,129 @@
1
+ var _w=e=>{throw TypeError(e)};var Fw=(e,t,s)=>t.has(e)||_w("Cannot "+s);var fn=(e,t,s)=>(Fw(e,t,"read from private field"),s?s.call(e):t.get(e)),zw=(e,t,s)=>t.has(e)?_w("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),pf=(e,t,s,r)=>(Fw(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function _$(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 pQ=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function F$(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O0={exports:{}},th={},L0={exports:{}},Je={};/**
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 mc=Symbol.for("react.element"),z$=Symbol.for("react.portal"),U$=Symbol.for("react.fragment"),B$=Symbol.for("react.strict_mode"),W$=Symbol.for("react.profiler"),H$=Symbol.for("react.provider"),K$=Symbol.for("react.context"),V$=Symbol.for("react.forward_ref"),G$=Symbol.for("react.suspense"),Y$=Symbol.for("react.memo"),q$=Symbol.for("react.lazy"),Uw=Symbol.iterator;function Q$(e){return e===null||typeof e!="object"?null:(e=Uw&&e[Uw]||e["@@iterator"],typeof e=="function"?e:null)}var _0={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},F0=Object.assign,z0={};function gl(e,t,s){this.props=e,this.context=t,this.refs=z0,this.updater=s||_0}gl.prototype.isReactComponent={};gl.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")};gl.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function U0(){}U0.prototype=gl.prototype;function vx(e,t,s){this.props=e,this.context=t,this.refs=z0,this.updater=s||_0}var jx=vx.prototype=new U0;jx.constructor=vx;F0(jx,gl.prototype);jx.isPureReactComponent=!0;var Bw=Array.isArray,B0=Object.prototype.hasOwnProperty,wx={current:null},W0={key:!0,ref:!0,__self:!0,__source:!0};function H0(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)B0.call(t,r)&&!W0.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:mc,type:e,key:a,ref:l,props:i,_owner:wx.current}}function X$(e,t){return{$$typeof:mc,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function yx(e){return typeof e=="object"&&e!==null&&e.$$typeof===mc}function J$(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var Ww=/\/+/g;function gf(e,t){return typeof e=="object"&&e!==null&&e.key!=null?J$(""+e.key):t.toString(36)}function Ru(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 mc:case z$:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+gf(l,0):r,Bw(i)?(s="",e!=null&&(s=e.replace(Ww,"$&/")+"/"),Ru(i,t,s,"",function(u){return u})):i!=null&&(yx(i)&&(i=X$(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(Ww,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",Bw(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+gf(a,o);l+=Ru(a,t,s,c,i)}else if(c=Q$(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+gf(a,o++),l+=Ru(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 Bc(e,t,s){if(e==null)return e;var r=[],i=0;return Ru(e,r,"","",function(a){return t.call(s,a,i++)}),r}function Z$(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},$u={transition:null},eI={ReactCurrentDispatcher:Cn,ReactCurrentBatchConfig:$u,ReactCurrentOwner:wx};function K0(){throw Error("act(...) is not supported in production builds of React.")}Je.Children={map:Bc,forEach:function(e,t,s){Bc(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return Bc(e,function(){t++}),t},toArray:function(e){return Bc(e,function(t){return t})||[]},only:function(e){if(!yx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};Je.Component=gl;Je.Fragment=U$;Je.Profiler=W$;Je.PureComponent=vx;Je.StrictMode=B$;Je.Suspense=G$;Je.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=eI;Je.act=K0;Je.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=F0({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=wx.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)B0.call(t,c)&&!W0.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:mc,type:e.type,key:i,ref:a,props:r,_owner:l}};Je.createContext=function(e){return e={$$typeof:K$,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:H$,_context:e},e.Consumer=e};Je.createElement=H0;Je.createFactory=function(e){var t=H0.bind(null,e);return t.type=e,t};Je.createRef=function(){return{current:null}};Je.forwardRef=function(e){return{$$typeof:V$,render:e}};Je.isValidElement=yx;Je.lazy=function(e){return{$$typeof:q$,_payload:{_status:-1,_result:e},_init:Z$}};Je.memo=function(e,t){return{$$typeof:Y$,type:e,compare:t===void 0?null:t}};Je.startTransition=function(e){var t=$u.transition;$u.transition={};try{e()}finally{$u.transition=t}};Je.unstable_act=K0;Je.useCallback=function(e,t){return Cn.current.useCallback(e,t)};Je.useContext=function(e){return Cn.current.useContext(e)};Je.useDebugValue=function(){};Je.useDeferredValue=function(e){return Cn.current.useDeferredValue(e)};Je.useEffect=function(e,t){return Cn.current.useEffect(e,t)};Je.useId=function(){return Cn.current.useId()};Je.useImperativeHandle=function(e,t,s){return Cn.current.useImperativeHandle(e,t,s)};Je.useInsertionEffect=function(e,t){return Cn.current.useInsertionEffect(e,t)};Je.useLayoutEffect=function(e,t){return Cn.current.useLayoutEffect(e,t)};Je.useMemo=function(e,t){return Cn.current.useMemo(e,t)};Je.useReducer=function(e,t,s){return Cn.current.useReducer(e,t,s)};Je.useRef=function(e){return Cn.current.useRef(e)};Je.useState=function(e){return Cn.current.useState(e)};Je.useSyncExternalStore=function(e,t,s){return Cn.current.useSyncExternalStore(e,t,s)};Je.useTransition=function(){return Cn.current.useTransition()};Je.version="18.3.1";L0.exports=Je;var h=L0.exports;const tI=F$(h),xl=_$({__proto__:null,default:tI},[h]);/**
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 nI=h,sI=Symbol.for("react.element"),rI=Symbol.for("react.fragment"),iI=Object.prototype.hasOwnProperty,aI=nI.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,lI={key:!0,ref:!0,__self:!0,__source:!0};function V0(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)iI.call(t,r)&&!lI.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:sI,type:e,key:a,ref:l,props:i,_owner:aI.current}}th.Fragment=rI;th.jsx=V0;th.jsxs=V0;O0.exports=th;var n=O0.exports,G0={exports:{}},es={},Y0={exports:{}},q0={};/**
18
+ * @license React
19
+ * scheduler.production.min.js
20
+ *
21
+ * Copyright (c) Facebook, Inc. and its affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */(function(e){function t(M,W){var L=M.length;M.push(W);e:for(;0<L;){var q=L-1>>>1,B=M[q];if(0<i(B,W))M[q]=W,M[L]=B,L=q;else break e}}function s(M){return M.length===0?null:M[0]}function r(M){if(M.length===0)return null;var W=M[0],L=M.pop();if(L!==W){M[0]=L;e:for(var q=0,B=M.length,V=B>>>1;q<V;){var F=2*(q+1)-1,X=M[F],Y=F+1,Z=M[Y];if(0>i(X,L))Y<B&&0>i(Z,X)?(M[q]=Z,M[Y]=L,q=Y):(M[q]=X,M[F]=L,q=F);else if(Y<B&&0>i(Z,L))M[q]=Z,M[Y]=L,q=Y;else break e}}return W}function i(M,W){var L=M.sortIndex-W.sortIndex;return L!==0?L:M.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],d=1,f=null,m=3,p=!1,g=!1,x=!1,b=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(M){for(var W=s(u);W!==null;){if(W.callback===null)r(u);else if(W.startTime<=M)r(u),W.sortIndex=W.expirationTime,t(c,W);else break;W=s(u)}}function y(M){if(x=!1,w(M),!g)if(s(c)!==null)g=!0,D(N);else{var W=s(u);W!==null&&O(y,W.startTime-M)}}function N(M,W){g=!1,x&&(x=!1,j(C),C=-1),p=!0;var L=m;try{for(w(W),f=s(c);f!==null&&(!(f.expirationTime>W)||M&&!I());){var q=f.callback;if(typeof q=="function"){f.callback=null,m=f.priorityLevel;var B=q(f.expirationTime<=W);W=e.unstable_now(),typeof B=="function"?f.callback=B:f===s(c)&&r(c),w(W)}else r(c);f=s(c)}if(f!==null)var V=!0;else{var F=s(u);F!==null&&O(y,F.startTime-W),V=!1}return V}finally{f=null,m=L,p=!1}}var k=!1,S=null,C=-1,$=5,R=-1;function I(){return!(e.unstable_now()-R<$)}function U(){if(S!==null){var M=e.unstable_now();R=M;var W=!0;try{W=S(!0,M)}finally{W?z():(k=!1,S=null)}}else k=!1}var z;if(typeof v=="function")z=function(){v(U)};else if(typeof MessageChannel<"u"){var A=new MessageChannel,P=A.port2;A.port1.onmessage=U,z=function(){P.postMessage(null)}}else z=function(){b(U,0)};function D(M){S=M,k||(k=!0,z())}function O(M,W){C=b(function(){M(e.unstable_now())},W)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(M){M.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,D(N))},e.unstable_forceFrameRate=function(M){0>M||125<M?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<M?Math.floor(1e3/M):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(M){switch(m){case 1:case 2:case 3:var W=3;break;default:W=m}var L=m;m=W;try{return M()}finally{m=L}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(M,W){switch(M){case 1:case 2:case 3:case 4:case 5:break;default:M=3}var L=m;m=M;try{return W()}finally{m=L}},e.unstable_scheduleCallback=function(M,W,L){var q=e.unstable_now();switch(typeof L=="object"&&L!==null?(L=L.delay,L=typeof L=="number"&&0<L?q+L:q):L=q,M){case 1:var B=-1;break;case 2:B=250;break;case 5:B=1073741823;break;case 4:B=1e4;break;default:B=5e3}return B=L+B,M={id:d++,callback:W,priorityLevel:M,startTime:L,expirationTime:B,sortIndex:-1},L>q?(M.sortIndex=L,t(u,M),s(c)===null&&M===s(u)&&(x?(j(C),C=-1):x=!0,O(y,L-q))):(M.sortIndex=B,t(c,M),g||p||(g=!0,D(N))),M},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(M){var W=m;return function(){var L=m;m=W;try{return M.apply(this,arguments)}finally{m=L}}}})(q0);Y0.exports=q0;var oI=Y0.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 cI=h,Xn=oI;function de(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 Q0=new Set,Eo={};function sa(e,t){Za(e,t),Za(e+"Capture",t)}function Za(e,t){for(Eo[e]=t,e=0;e<t.length;e++)Q0.add(t[e])}var Rr=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Wm=Object.prototype.hasOwnProperty,uI=/^[: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]*$/,Hw={},Kw={};function dI(e){return Wm.call(Kw,e)?!0:Wm.call(Hw,e)?!1:uI.test(e)?Kw[e]=!0:(Hw[e]=!0,!1)}function hI(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 fI(e,t,s,r){if(t===null||typeof t>"u"||hI(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 cn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){cn[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];cn[t]=new En(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){cn[e]=new En(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){cn[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){cn[e]=new En(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){cn[e]=new En(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){cn[e]=new En(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){cn[e]=new En(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){cn[e]=new En(e,5,!1,e.toLowerCase(),null,!1,!1)});var bx=/[\-:]([a-z])/g;function kx(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(bx,kx);cn[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(bx,kx);cn[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(bx,kx);cn[t]=new En(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){cn[e]=new En(e,1,!1,e.toLowerCase(),null,!1,!1)});cn.xlinkHref=new En("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){cn[e]=new En(e,1,!1,e.toLowerCase(),null,!0,!0)});function Nx(e,t,s,r){var i=cn.hasOwnProperty(t)?cn[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(fI(t,s,i,r)&&(s=null),r||i===null?dI(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 zr=cI.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Wc=Symbol.for("react.element"),Sa=Symbol.for("react.portal"),Ca=Symbol.for("react.fragment"),Sx=Symbol.for("react.strict_mode"),Hm=Symbol.for("react.profiler"),X0=Symbol.for("react.provider"),J0=Symbol.for("react.context"),Cx=Symbol.for("react.forward_ref"),Km=Symbol.for("react.suspense"),Vm=Symbol.for("react.suspense_list"),Ex=Symbol.for("react.memo"),Vr=Symbol.for("react.lazy"),Z0=Symbol.for("react.offscreen"),Vw=Symbol.iterator;function Wl(e){return e===null||typeof e!="object"?null:(e=Vw&&e[Vw]||e["@@iterator"],typeof e=="function"?e:null)}var Pt=Object.assign,xf;function io(e){if(xf===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);xf=t&&t[1]||""}return`
34
+ `+xf+e}var vf=!1;function jf(e,t){if(!e||vf)return"";vf=!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{vf=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?io(e):""}function mI(e){switch(e.tag){case 5:return io(e.type);case 16:return io("Lazy");case 13:return io("Suspense");case 19:return io("SuspenseList");case 0:case 2:case 15:return e=jf(e.type,!1),e;case 11:return e=jf(e.type.render,!1),e;case 1:return e=jf(e.type,!0),e;default:return""}}function Gm(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Ca:return"Fragment";case Sa:return"Portal";case Hm:return"Profiler";case Sx:return"StrictMode";case Km:return"Suspense";case Vm:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case J0:return(e.displayName||"Context")+".Consumer";case X0:return(e._context.displayName||"Context")+".Provider";case Cx:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Ex:return t=e.displayName||null,t!==null?t:Gm(e.type)||"Memo";case Vr:t=e._payload,e=e._init;try{return Gm(e(t))}catch{}}return null}function pI(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 Gm(t);case 8:return t===Sx?"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 di(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function eN(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function gI(e){var t=eN(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 Hc(e){e._valueTracker||(e._valueTracker=gI(e))}function tN(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=eN(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function nd(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 Ym(e,t){var s=t.checked;return Pt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Gw(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=di(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 nN(e,t){t=t.checked,t!=null&&Nx(e,"checked",t,!1)}function qm(e,t){nN(e,t);var s=di(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")?Qm(e,t.type,s):t.hasOwnProperty("defaultValue")&&Qm(e,t.type,di(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Yw(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 Qm(e,t,s){(t!=="number"||nd(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var ao=Array.isArray;function Ua(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=""+di(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 Xm(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(de(91));return Pt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function qw(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(de(92));if(ao(s)){if(1<s.length)throw Error(de(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:di(s)}}function sN(e,t){var s=di(t.value),r=di(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 Qw(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function rN(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 Jm(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?rN(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Kc,iN=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(Kc=Kc||document.createElement("div"),Kc.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=Kc.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Ao(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var fo={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},xI=["Webkit","ms","Moz","O"];Object.keys(fo).forEach(function(e){xI.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),fo[t]=fo[e]})});function aN(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||fo.hasOwnProperty(e)&&fo[e]?(""+t).trim():t+"px"}function lN(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=aN(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var vI=Pt({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 Zm(e,t){if(t){if(vI[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(de(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(de(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(de(61))}if(t.style!=null&&typeof t.style!="object")throw Error(de(62))}}function ep(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 tp=null;function Ax(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var np=null,Ba=null,Wa=null;function Xw(e){if(e=xc(e)){if(typeof np!="function")throw Error(de(280));var t=e.stateNode;t&&(t=ah(t),np(e.stateNode,e.type,t))}}function oN(e){Ba?Wa?Wa.push(e):Wa=[e]:Ba=e}function cN(){if(Ba){var e=Ba,t=Wa;if(Wa=Ba=null,Xw(e),t)for(e=0;e<t.length;e++)Xw(t[e])}}function uN(e,t){return e(t)}function dN(){}var wf=!1;function hN(e,t,s){if(wf)return e(t,s);wf=!0;try{return uN(e,t,s)}finally{wf=!1,(Ba!==null||Wa!==null)&&(dN(),cN())}}function To(e,t){var s=e.stateNode;if(s===null)return null;var r=ah(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(de(231,t,typeof s));return s}var sp=!1;if(Rr)try{var Hl={};Object.defineProperty(Hl,"passive",{get:function(){sp=!0}}),window.addEventListener("test",Hl,Hl),window.removeEventListener("test",Hl,Hl)}catch{sp=!1}function jI(e,t,s,r,i,a,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{t.apply(s,u)}catch(d){this.onError(d)}}var mo=!1,sd=null,rd=!1,rp=null,wI={onError:function(e){mo=!0,sd=e}};function yI(e,t,s,r,i,a,l,o,c){mo=!1,sd=null,jI.apply(wI,arguments)}function bI(e,t,s,r,i,a,l,o,c){if(yI.apply(this,arguments),mo){if(mo){var u=sd;mo=!1,sd=null}else throw Error(de(198));rd||(rd=!0,rp=u)}}function ra(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 fN(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 Jw(e){if(ra(e)!==e)throw Error(de(188))}function kI(e){var t=e.alternate;if(!t){if(t=ra(e),t===null)throw Error(de(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 Jw(i),e;if(a===r)return Jw(i),t;a=a.sibling}throw Error(de(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(de(189))}}if(s.alternate!==r)throw Error(de(190))}if(s.tag!==3)throw Error(de(188));return s.stateNode.current===s?e:t}function mN(e){return e=kI(e),e!==null?pN(e):null}function pN(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=pN(e);if(t!==null)return t;e=e.sibling}return null}var gN=Xn.unstable_scheduleCallback,Zw=Xn.unstable_cancelCallback,NI=Xn.unstable_shouldYield,SI=Xn.unstable_requestPaint,Lt=Xn.unstable_now,CI=Xn.unstable_getCurrentPriorityLevel,Tx=Xn.unstable_ImmediatePriority,xN=Xn.unstable_UserBlockingPriority,id=Xn.unstable_NormalPriority,EI=Xn.unstable_LowPriority,vN=Xn.unstable_IdlePriority,nh=null,nr=null;function AI(e){if(nr&&typeof nr.onCommitFiberRoot=="function")try{nr.onCommitFiberRoot(nh,e,void 0,(e.current.flags&128)===128)}catch{}}var Rs=Math.clz32?Math.clz32:$I,TI=Math.log,RI=Math.LN2;function $I(e){return e>>>=0,e===0?32:31-(TI(e)/RI|0)|0}var Vc=64,Gc=4194304;function lo(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 ad(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=lo(o):(a&=l,a!==0&&(r=lo(a)))}else l=s&~i,l!==0?r=lo(l):a!==0&&(r=lo(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-Rs(t),i=1<<s,r|=e[s],t&=~i;return r}function II(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 PI(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-Rs(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=II(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function ip(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function jN(){var e=Vc;return Vc<<=1,!(Vc&4194240)&&(Vc=64),e}function yf(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function pc(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Rs(t),e[t]=s}function MI(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-Rs(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function Rx(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-Rs(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var mt=0;function wN(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var yN,$x,bN,kN,NN,ap=!1,Yc=[],ei=null,ti=null,ni=null,Ro=new Map,$o=new Map,Yr=[],DI="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 ey(e,t){switch(e){case"focusin":case"focusout":ei=null;break;case"dragenter":case"dragleave":ti=null;break;case"mouseover":case"mouseout":ni=null;break;case"pointerover":case"pointerout":Ro.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":$o.delete(t.pointerId)}}function Kl(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=xc(t),t!==null&&$x(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function OI(e,t,s,r,i){switch(t){case"focusin":return ei=Kl(ei,e,t,s,r,i),!0;case"dragenter":return ti=Kl(ti,e,t,s,r,i),!0;case"mouseover":return ni=Kl(ni,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return Ro.set(a,Kl(Ro.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,$o.set(a,Kl($o.get(a)||null,e,t,s,r,i)),!0}return!1}function SN(e){var t=Fi(e.target);if(t!==null){var s=ra(t);if(s!==null){if(t=s.tag,t===13){if(t=fN(s),t!==null){e.blockedOn=t,NN(e.priority,function(){bN(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 Iu(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=lp(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);tp=r,s.target.dispatchEvent(r),tp=null}else return t=xc(s),t!==null&&$x(t),e.blockedOn=s,!1;t.shift()}return!0}function ty(e,t,s){Iu(e)&&s.delete(t)}function LI(){ap=!1,ei!==null&&Iu(ei)&&(ei=null),ti!==null&&Iu(ti)&&(ti=null),ni!==null&&Iu(ni)&&(ni=null),Ro.forEach(ty),$o.forEach(ty)}function Vl(e,t){e.blockedOn===t&&(e.blockedOn=null,ap||(ap=!0,Xn.unstable_scheduleCallback(Xn.unstable_NormalPriority,LI)))}function Io(e){function t(i){return Vl(i,e)}if(0<Yc.length){Vl(Yc[0],e);for(var s=1;s<Yc.length;s++){var r=Yc[s];r.blockedOn===e&&(r.blockedOn=null)}}for(ei!==null&&Vl(ei,e),ti!==null&&Vl(ti,e),ni!==null&&Vl(ni,e),Ro.forEach(t),$o.forEach(t),s=0;s<Yr.length;s++)r=Yr[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Yr.length&&(s=Yr[0],s.blockedOn===null);)SN(s),s.blockedOn===null&&Yr.shift()}var Ha=zr.ReactCurrentBatchConfig,ld=!0;function _I(e,t,s,r){var i=mt,a=Ha.transition;Ha.transition=null;try{mt=1,Ix(e,t,s,r)}finally{mt=i,Ha.transition=a}}function FI(e,t,s,r){var i=mt,a=Ha.transition;Ha.transition=null;try{mt=4,Ix(e,t,s,r)}finally{mt=i,Ha.transition=a}}function Ix(e,t,s,r){if(ld){var i=lp(e,t,s,r);if(i===null)$f(e,t,r,od,s),ey(e,r);else if(OI(i,e,t,s,r))r.stopPropagation();else if(ey(e,r),t&4&&-1<DI.indexOf(e)){for(;i!==null;){var a=xc(i);if(a!==null&&yN(a),a=lp(e,t,s,r),a===null&&$f(e,t,r,od,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else $f(e,t,r,null,s)}}var od=null;function lp(e,t,s,r){if(od=null,e=Ax(r),e=Fi(e),e!==null)if(t=ra(e),t===null)e=null;else if(s=t.tag,s===13){if(e=fN(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 od=e,null}function CN(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(CI()){case Tx:return 1;case xN:return 4;case id:case EI:return 16;case vN:return 536870912;default:return 16}default:return 16}}var Qr=null,Px=null,Pu=null;function EN(){if(Pu)return Pu;var e,t=Px,s=t.length,r,i="value"in Qr?Qr.value:Qr.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 Pu=i.slice(e,1<r?1-r:void 0)}function Mu(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 qc(){return!0}function ny(){return!1}function ts(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)?qc:ny,this.isPropagationStopped=ny,this}return Pt(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=qc)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=qc)},persist:function(){},isPersistent:qc}),t}var vl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Mx=ts(vl),gc=Pt({},vl,{view:0,detail:0}),zI=ts(gc),bf,kf,Gl,sh=Pt({},gc,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Dx,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!==Gl&&(Gl&&e.type==="mousemove"?(bf=e.screenX-Gl.screenX,kf=e.screenY-Gl.screenY):kf=bf=0,Gl=e),bf)},movementY:function(e){return"movementY"in e?e.movementY:kf}}),sy=ts(sh),UI=Pt({},sh,{dataTransfer:0}),BI=ts(UI),WI=Pt({},gc,{relatedTarget:0}),Nf=ts(WI),HI=Pt({},vl,{animationName:0,elapsedTime:0,pseudoElement:0}),KI=ts(HI),VI=Pt({},vl,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),GI=ts(VI),YI=Pt({},vl,{data:0}),ry=ts(YI),qI={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},QI={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"},XI={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function JI(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=XI[e])?!!t[e]:!1}function Dx(){return JI}var ZI=Pt({},gc,{key:function(e){if(e.key){var t=qI[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Mu(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?QI[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Dx,charCode:function(e){return e.type==="keypress"?Mu(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Mu(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),eP=ts(ZI),tP=Pt({},sh,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),iy=ts(tP),nP=Pt({},gc,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Dx}),sP=ts(nP),rP=Pt({},vl,{propertyName:0,elapsedTime:0,pseudoElement:0}),iP=ts(rP),aP=Pt({},sh,{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}),lP=ts(aP),oP=[9,13,27,32],Ox=Rr&&"CompositionEvent"in window,po=null;Rr&&"documentMode"in document&&(po=document.documentMode);var cP=Rr&&"TextEvent"in window&&!po,AN=Rr&&(!Ox||po&&8<po&&11>=po),ay=" ",ly=!1;function TN(e,t){switch(e){case"keyup":return oP.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function RN(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ea=!1;function uP(e,t){switch(e){case"compositionend":return RN(t);case"keypress":return t.which!==32?null:(ly=!0,ay);case"textInput":return e=t.data,e===ay&&ly?null:e;default:return null}}function dP(e,t){if(Ea)return e==="compositionend"||!Ox&&TN(e,t)?(e=EN(),Pu=Px=Qr=null,Ea=!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 AN&&t.locale!=="ko"?null:t.data;default:return null}}var hP={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 oy(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!hP[e.type]:t==="textarea"}function $N(e,t,s,r){oN(r),t=cd(t,"onChange"),0<t.length&&(s=new Mx("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var go=null,Po=null;function fP(e){BN(e,0)}function rh(e){var t=Ra(e);if(tN(t))return e}function mP(e,t){if(e==="change")return t}var IN=!1;if(Rr){var Sf;if(Rr){var Cf="oninput"in document;if(!Cf){var cy=document.createElement("div");cy.setAttribute("oninput","return;"),Cf=typeof cy.oninput=="function"}Sf=Cf}else Sf=!1;IN=Sf&&(!document.documentMode||9<document.documentMode)}function uy(){go&&(go.detachEvent("onpropertychange",PN),Po=go=null)}function PN(e){if(e.propertyName==="value"&&rh(Po)){var t=[];$N(t,Po,e,Ax(e)),hN(fP,t)}}function pP(e,t,s){e==="focusin"?(uy(),go=t,Po=s,go.attachEvent("onpropertychange",PN)):e==="focusout"&&uy()}function gP(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return rh(Po)}function xP(e,t){if(e==="click")return rh(t)}function vP(e,t){if(e==="input"||e==="change")return rh(t)}function jP(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Ds=typeof Object.is=="function"?Object.is:jP;function Mo(e,t){if(Ds(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(!Wm.call(t,i)||!Ds(e[i],t[i]))return!1}return!0}function dy(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function hy(e,t){var s=dy(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=dy(s)}}function MN(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?MN(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function DN(){for(var e=window,t=nd();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=nd(e.document)}return t}function Lx(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 wP(e){var t=DN(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&MN(s.ownerDocument.documentElement,s)){if(r!==null&&Lx(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=hy(s,a);var l=hy(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 yP=Rr&&"documentMode"in document&&11>=document.documentMode,Aa=null,op=null,xo=null,cp=!1;function fy(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;cp||Aa==null||Aa!==nd(r)||(r=Aa,"selectionStart"in r&&Lx(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}),xo&&Mo(xo,r)||(xo=r,r=cd(op,"onSelect"),0<r.length&&(t=new Mx("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=Aa)))}function Qc(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var Ta={animationend:Qc("Animation","AnimationEnd"),animationiteration:Qc("Animation","AnimationIteration"),animationstart:Qc("Animation","AnimationStart"),transitionend:Qc("Transition","TransitionEnd")},Ef={},ON={};Rr&&(ON=document.createElement("div").style,"AnimationEvent"in window||(delete Ta.animationend.animation,delete Ta.animationiteration.animation,delete Ta.animationstart.animation),"TransitionEvent"in window||delete Ta.transitionend.transition);function ih(e){if(Ef[e])return Ef[e];if(!Ta[e])return e;var t=Ta[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in ON)return Ef[e]=t[s];return e}var LN=ih("animationend"),_N=ih("animationiteration"),FN=ih("animationstart"),zN=ih("transitionend"),UN=new Map,my="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 yi(e,t){UN.set(e,t),sa(t,[e])}for(var Af=0;Af<my.length;Af++){var Tf=my[Af],bP=Tf.toLowerCase(),kP=Tf[0].toUpperCase()+Tf.slice(1);yi(bP,"on"+kP)}yi(LN,"onAnimationEnd");yi(_N,"onAnimationIteration");yi(FN,"onAnimationStart");yi("dblclick","onDoubleClick");yi("focusin","onFocus");yi("focusout","onBlur");yi(zN,"onTransitionEnd");Za("onMouseEnter",["mouseout","mouseover"]);Za("onMouseLeave",["mouseout","mouseover"]);Za("onPointerEnter",["pointerout","pointerover"]);Za("onPointerLeave",["pointerout","pointerover"]);sa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));sa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));sa("onBeforeInput",["compositionend","keypress","textInput","paste"]);sa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var oo="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(" "),NP=new Set("cancel close invalid load scroll toggle".split(" ").concat(oo));function py(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,bI(r,t,void 0,e),e.currentTarget=null}function BN(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;py(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;py(i,o,u),a=c}}}if(rd)throw e=rp,rd=!1,rp=null,e}function bt(e,t){var s=t[mp];s===void 0&&(s=t[mp]=new Set);var r=e+"__bubble";s.has(r)||(WN(t,e,2,!1),s.add(r))}function Rf(e,t,s){var r=0;t&&(r|=4),WN(s,e,r,t)}var Xc="_reactListening"+Math.random().toString(36).slice(2);function Do(e){if(!e[Xc]){e[Xc]=!0,Q0.forEach(function(s){s!=="selectionchange"&&(NP.has(s)||Rf(s,!1,e),Rf(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[Xc]||(t[Xc]=!0,Rf("selectionchange",!1,t))}}function WN(e,t,s,r){switch(CN(t)){case 1:var i=_I;break;case 4:i=FI;break;default:i=Ix}s=i.bind(null,t,s,e),i=void 0,!sp||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 $f(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=Fi(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}hN(function(){var u=a,d=Ax(s),f=[];e:{var m=UN.get(e);if(m!==void 0){var p=Mx,g=e;switch(e){case"keypress":if(Mu(s)===0)break e;case"keydown":case"keyup":p=eP;break;case"focusin":g="focus",p=Nf;break;case"focusout":g="blur",p=Nf;break;case"beforeblur":case"afterblur":p=Nf;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=sy;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=BI;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=sP;break;case LN:case _N:case FN:p=KI;break;case zN:p=iP;break;case"scroll":p=zI;break;case"wheel":p=lP;break;case"copy":case"cut":case"paste":p=GI;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=iy}var x=(t&4)!==0,b=!x&&e==="scroll",j=x?m!==null?m+"Capture":null:m;x=[];for(var v=u,w;v!==null;){w=v;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,j!==null&&(y=To(v,j),y!=null&&x.push(Oo(v,y,w)))),b)break;v=v.return}0<x.length&&(m=new p(m,g,null,s,d),f.push({event:m,listeners:x}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==tp&&(g=s.relatedTarget||s.fromElement)&&(Fi(g)||g[$r]))break e;if((p||m)&&(m=d.window===d?d:(m=d.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Fi(g):null,g!==null&&(b=ra(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(x=sy,y="onMouseLeave",j="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(x=iy,y="onPointerLeave",j="onPointerEnter",v="pointer"),b=p==null?m:Ra(p),w=g==null?m:Ra(g),m=new x(y,v+"leave",p,s,d),m.target=b,m.relatedTarget=w,y=null,Fi(d)===u&&(x=new x(j,v+"enter",g,s,d),x.target=w,x.relatedTarget=b,y=x),b=y,p&&g)t:{for(x=p,j=g,v=0,w=x;w;w=ga(w))v++;for(w=0,y=j;y;y=ga(y))w++;for(;0<v-w;)x=ga(x),v--;for(;0<w-v;)j=ga(j),w--;for(;v--;){if(x===j||j!==null&&x===j.alternate)break t;x=ga(x),j=ga(j)}x=null}else x=null;p!==null&&gy(f,m,p,x,!1),g!==null&&b!==null&&gy(f,b,g,x,!0)}}e:{if(m=u?Ra(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var N=mP;else if(oy(m))if(IN)N=vP;else{N=gP;var k=pP}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(N=xP);if(N&&(N=N(e,u))){$N(f,N,s,d);break e}k&&k(e,m,u),e==="focusout"&&(k=m._wrapperState)&&k.controlled&&m.type==="number"&&Qm(m,"number",m.value)}switch(k=u?Ra(u):window,e){case"focusin":(oy(k)||k.contentEditable==="true")&&(Aa=k,op=u,xo=null);break;case"focusout":xo=op=Aa=null;break;case"mousedown":cp=!0;break;case"contextmenu":case"mouseup":case"dragend":cp=!1,fy(f,s,d);break;case"selectionchange":if(yP)break;case"keydown":case"keyup":fy(f,s,d)}var S;if(Ox)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 Ea?TN(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(AN&&s.locale!=="ko"&&(Ea||C!=="onCompositionStart"?C==="onCompositionEnd"&&Ea&&(S=EN()):(Qr=d,Px="value"in Qr?Qr.value:Qr.textContent,Ea=!0)),k=cd(u,C),0<k.length&&(C=new ry(C,e,null,s,d),f.push({event:C,listeners:k}),S?C.data=S:(S=RN(s),S!==null&&(C.data=S)))),(S=cP?uP(e,s):dP(e,s))&&(u=cd(u,"onBeforeInput"),0<u.length&&(d=new ry("onBeforeInput","beforeinput",null,s,d),f.push({event:d,listeners:u}),d.data=S))}BN(f,t)})}function Oo(e,t,s){return{instance:e,listener:t,currentTarget:s}}function cd(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=To(e,s),a!=null&&r.unshift(Oo(e,a,i)),a=To(e,t),a!=null&&r.push(Oo(e,a,i))),e=e.return}return r}function ga(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function gy(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=To(s,a),c!=null&&l.unshift(Oo(s,c,o))):i||(c=To(s,a),c!=null&&l.push(Oo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var SP=/\r\n?/g,CP=/\u0000|\uFFFD/g;function xy(e){return(typeof e=="string"?e:""+e).replace(SP,`
38
+ `).replace(CP,"")}function Jc(e,t,s){if(t=xy(t),xy(e)!==t&&s)throw Error(de(425))}function ud(){}var up=null,dp=null;function hp(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 fp=typeof setTimeout=="function"?setTimeout:void 0,EP=typeof clearTimeout=="function"?clearTimeout:void 0,vy=typeof Promise=="function"?Promise:void 0,AP=typeof queueMicrotask=="function"?queueMicrotask:typeof vy<"u"?function(e){return vy.resolve(null).then(e).catch(TP)}:fp;function TP(e){setTimeout(function(){throw e})}function If(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),Io(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);Io(t)}function si(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 jy(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 jl=Math.random().toString(36).slice(2),Js="__reactFiber$"+jl,Lo="__reactProps$"+jl,$r="__reactContainer$"+jl,mp="__reactEvents$"+jl,RP="__reactListeners$"+jl,$P="__reactHandles$"+jl;function Fi(e){var t=e[Js];if(t)return t;for(var s=e.parentNode;s;){if(t=s[$r]||s[Js]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=jy(e);e!==null;){if(s=e[Js])return s;e=jy(e)}return t}e=s,s=e.parentNode}return null}function xc(e){return e=e[Js]||e[$r],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ra(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(de(33))}function ah(e){return e[Lo]||null}var pp=[],$a=-1;function bi(e){return{current:e}}function kt(e){0>$a||(e.current=pp[$a],pp[$a]=null,$a--)}function wt(e,t){$a++,pp[$a]=e.current,e.current=t}var hi={},vn=bi(hi),Mn=bi(!1),Yi=hi;function el(e,t){var s=e.type.contextTypes;if(!s)return hi;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 Dn(e){return e=e.childContextTypes,e!=null}function dd(){kt(Mn),kt(vn)}function wy(e,t,s){if(vn.current!==hi)throw Error(de(168));wt(vn,t),wt(Mn,s)}function HN(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(de(108,pI(e)||"Unknown",i));return Pt({},s,r)}function hd(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||hi,Yi=vn.current,wt(vn,e),wt(Mn,Mn.current),!0}function yy(e,t,s){var r=e.stateNode;if(!r)throw Error(de(169));s?(e=HN(e,t,Yi),r.__reactInternalMemoizedMergedChildContext=e,kt(Mn),kt(vn),wt(vn,e)):kt(Mn),wt(Mn,s)}var vr=null,lh=!1,Pf=!1;function KN(e){vr===null?vr=[e]:vr.push(e)}function IP(e){lh=!0,KN(e)}function ki(){if(!Pf&&vr!==null){Pf=!0;var e=0,t=mt;try{var s=vr;for(mt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}vr=null,lh=!1}catch(i){throw vr!==null&&(vr=vr.slice(e+1)),gN(Tx,ki),i}finally{mt=t,Pf=!1}}return null}var Ia=[],Pa=0,fd=null,md=0,cs=[],us=0,qi=null,br=1,kr="";function Mi(e,t){Ia[Pa++]=md,Ia[Pa++]=fd,fd=e,md=t}function VN(e,t,s){cs[us++]=br,cs[us++]=kr,cs[us++]=qi,qi=e;var r=br;e=kr;var i=32-Rs(r)-1;r&=~(1<<i),s+=1;var a=32-Rs(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,br=1<<32-Rs(t)+i|s<<i|r,kr=a+e}else br=1<<a|s<<i|r,kr=e}function _x(e){e.return!==null&&(Mi(e,1),VN(e,1,0))}function Fx(e){for(;e===fd;)fd=Ia[--Pa],Ia[Pa]=null,md=Ia[--Pa],Ia[Pa]=null;for(;e===qi;)qi=cs[--us],cs[us]=null,kr=cs[--us],cs[us]=null,br=cs[--us],cs[us]=null}var qn=null,Gn=null,St=!1,As=null;function GN(e,t){var s=ms(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 by(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,qn=e,Gn=si(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,qn=e,Gn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=qi!==null?{id:br,overflow:kr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=ms(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,qn=e,Gn=null,!0):!1;default:return!1}}function gp(e){return(e.mode&1)!==0&&(e.flags&128)===0}function xp(e){if(St){var t=Gn;if(t){var s=t;if(!by(e,t)){if(gp(e))throw Error(de(418));t=si(s.nextSibling);var r=qn;t&&by(e,t)?GN(r,s):(e.flags=e.flags&-4097|2,St=!1,qn=e)}}else{if(gp(e))throw Error(de(418));e.flags=e.flags&-4097|2,St=!1,qn=e}}}function ky(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;qn=e}function Zc(e){if(e!==qn)return!1;if(!St)return ky(e),St=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!hp(e.type,e.memoizedProps)),t&&(t=Gn)){if(gp(e))throw YN(),Error(de(418));for(;t;)GN(e,t),t=si(t.nextSibling)}if(ky(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(de(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Gn=si(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Gn=null}}else Gn=qn?si(e.stateNode.nextSibling):null;return!0}function YN(){for(var e=Gn;e;)e=si(e.nextSibling)}function tl(){Gn=qn=null,St=!1}function zx(e){As===null?As=[e]:As.push(e)}var PP=zr.ReactCurrentBatchConfig;function Yl(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(de(309));var r=s.stateNode}if(!r)throw Error(de(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(de(284));if(!s._owner)throw Error(de(290,e))}return e}function eu(e,t){throw e=Object.prototype.toString.call(t),Error(de(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function Ny(e){var t=e._init;return t(e._payload)}function qN(e){function t(j,v){if(e){var w=j.deletions;w===null?(j.deletions=[v],j.flags|=16):w.push(v)}}function s(j,v){if(!e)return null;for(;v!==null;)t(j,v),v=v.sibling;return null}function r(j,v){for(j=new Map;v!==null;)v.key!==null?j.set(v.key,v):j.set(v.index,v),v=v.sibling;return j}function i(j,v){return j=li(j,v),j.index=0,j.sibling=null,j}function a(j,v,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<v?(j.flags|=2,v):w):(j.flags|=2,v)):(j.flags|=1048576,v)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,v,w,y){return v===null||v.tag!==6?(v=zf(w,j.mode,y),v.return=j,v):(v=i(v,w),v.return=j,v)}function c(j,v,w,y){var N=w.type;return N===Ca?d(j,v,w.props.children,y,w.key):v!==null&&(v.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Vr&&Ny(N)===v.type)?(y=i(v,w.props),y.ref=Yl(j,v,w),y.return=j,y):(y=Uu(w.type,w.key,w.props,null,j.mode,y),y.ref=Yl(j,v,w),y.return=j,y)}function u(j,v,w,y){return v===null||v.tag!==4||v.stateNode.containerInfo!==w.containerInfo||v.stateNode.implementation!==w.implementation?(v=Uf(w,j.mode,y),v.return=j,v):(v=i(v,w.children||[]),v.return=j,v)}function d(j,v,w,y,N){return v===null||v.tag!==7?(v=Ki(w,j.mode,y,N),v.return=j,v):(v=i(v,w),v.return=j,v)}function f(j,v,w){if(typeof v=="string"&&v!==""||typeof v=="number")return v=zf(""+v,j.mode,w),v.return=j,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case Wc:return w=Uu(v.type,v.key,v.props,null,j.mode,w),w.ref=Yl(j,null,v),w.return=j,w;case Sa:return v=Uf(v,j.mode,w),v.return=j,v;case Vr:var y=v._init;return f(j,y(v._payload),w)}if(ao(v)||Wl(v))return v=Ki(v,j.mode,w,null),v.return=j,v;eu(j,v)}return null}function m(j,v,w,y){var N=v!==null?v.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return N!==null?null:o(j,v,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case Wc:return w.key===N?c(j,v,w,y):null;case Sa:return w.key===N?u(j,v,w,y):null;case Vr:return N=w._init,m(j,v,N(w._payload),y)}if(ao(w)||Wl(w))return N!==null?null:d(j,v,w,y,null);eu(j,w)}return null}function p(j,v,w,y,N){if(typeof y=="string"&&y!==""||typeof y=="number")return j=j.get(w)||null,o(v,j,""+y,N);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Wc:return j=j.get(y.key===null?w:y.key)||null,c(v,j,y,N);case Sa:return j=j.get(y.key===null?w:y.key)||null,u(v,j,y,N);case Vr:var k=y._init;return p(j,v,w,k(y._payload),N)}if(ao(y)||Wl(y))return j=j.get(w)||null,d(v,j,y,N,null);eu(v,y)}return null}function g(j,v,w,y){for(var N=null,k=null,S=v,C=v=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),v=a(R,v,C),k===null?N=R:k.sibling=R,k=R,S=$}if(C===w.length)return s(j,S),St&&Mi(j,C),N;if(S===null){for(;C<w.length;C++)S=f(j,w[C],y),S!==null&&(v=a(S,v,C),k===null?N=S:k.sibling=S,k=S);return St&&Mi(j,C),N}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),v=a($,v,C),k===null?N=$:k.sibling=$,k=$);return e&&S.forEach(function(I){return t(j,I)}),St&&Mi(j,C),N}function x(j,v,w,y){var N=Wl(w);if(typeof N!="function")throw Error(de(150));if(w=N.call(w),w==null)throw Error(de(151));for(var k=N=null,S=v,C=v=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),v=a(I,v,C),k===null?N=I:k.sibling=I,k=I,S=$}if(R.done)return s(j,S),St&&Mi(j,C),N;if(S===null){for(;!R.done;C++,R=w.next())R=f(j,R.value,y),R!==null&&(v=a(R,v,C),k===null?N=R:k.sibling=R,k=R);return St&&Mi(j,C),N}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),v=a(R,v,C),k===null?N=R:k.sibling=R,k=R);return e&&S.forEach(function(U){return t(j,U)}),St&&Mi(j,C),N}function b(j,v,w,y){if(typeof w=="object"&&w!==null&&w.type===Ca&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case Wc:e:{for(var N=w.key,k=v;k!==null;){if(k.key===N){if(N=w.type,N===Ca){if(k.tag===7){s(j,k.sibling),v=i(k,w.props.children),v.return=j,j=v;break e}}else if(k.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Vr&&Ny(N)===k.type){s(j,k.sibling),v=i(k,w.props),v.ref=Yl(j,k,w),v.return=j,j=v;break e}s(j,k);break}else t(j,k);k=k.sibling}w.type===Ca?(v=Ki(w.props.children,j.mode,y,w.key),v.return=j,j=v):(y=Uu(w.type,w.key,w.props,null,j.mode,y),y.ref=Yl(j,v,w),y.return=j,j=y)}return l(j);case Sa:e:{for(k=w.key;v!==null;){if(v.key===k)if(v.tag===4&&v.stateNode.containerInfo===w.containerInfo&&v.stateNode.implementation===w.implementation){s(j,v.sibling),v=i(v,w.children||[]),v.return=j,j=v;break e}else{s(j,v);break}else t(j,v);v=v.sibling}v=Uf(w,j.mode,y),v.return=j,j=v}return l(j);case Vr:return k=w._init,b(j,v,k(w._payload),y)}if(ao(w))return g(j,v,w,y);if(Wl(w))return x(j,v,w,y);eu(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,v!==null&&v.tag===6?(s(j,v.sibling),v=i(v,w),v.return=j,j=v):(s(j,v),v=zf(w,j.mode,y),v.return=j,j=v),l(j)):s(j,v)}return b}var nl=qN(!0),QN=qN(!1),pd=bi(null),gd=null,Ma=null,Ux=null;function Bx(){Ux=Ma=gd=null}function Wx(e){var t=pd.current;kt(pd),e._currentValue=t}function vp(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 Ka(e,t){gd=e,Ux=Ma=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Pn=!0),e.firstContext=null)}function xs(e){var t=e._currentValue;if(Ux!==e)if(e={context:e,memoizedValue:t,next:null},Ma===null){if(gd===null)throw Error(de(308));Ma=e,gd.dependencies={lanes:0,firstContext:e}}else Ma=Ma.next=e;return t}var zi=null;function Hx(e){zi===null?zi=[e]:zi.push(e)}function XN(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,Hx(t)):(s.next=i.next,i.next=s),t.interleaved=s,Ir(e,r)}function Ir(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 Gr=!1;function Kx(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function JN(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 Sr(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function ri(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,at&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,Ir(e,s)}return i=r.interleaved,i===null?(t.next=t,Hx(r)):(t.next=i.next,i.next=t),r.interleaved=t,Ir(e,s)}function Du(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,Rx(e,s)}}function Sy(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 xd(e,t,s,r){var i=e.updateQueue;Gr=!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 d=e.alternate;d!==null&&(d=d.updateQueue,o=d.lastBaseUpdate,o!==l&&(o===null?d.firstBaseUpdate=u:o.next=u,d.lastBaseUpdate=c))}if(a!==null){var f=i.baseState;l=0,d=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){d!==null&&(d=d.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,x=o;switch(m=t,p=s,x.tag){case 1:if(g=x.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=x.payload,m=typeof g=="function"?g.call(p,f,m):g,m==null)break e;f=Pt({},f,m);break e;case 2:Gr=!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},d===null?(u=d=p,c=f):d=d.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(d===null&&(c=f),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=d,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);Xi|=l,e.lanes=l,e.memoizedState=f}}function Cy(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(de(191,i));i.call(r)}}}var vc={},sr=bi(vc),_o=bi(vc),Fo=bi(vc);function Ui(e){if(e===vc)throw Error(de(174));return e}function Vx(e,t){switch(wt(Fo,t),wt(_o,e),wt(sr,vc),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Jm(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Jm(t,e)}kt(sr),wt(sr,t)}function sl(){kt(sr),kt(_o),kt(Fo)}function ZN(e){Ui(Fo.current);var t=Ui(sr.current),s=Jm(t,e.type);t!==s&&(wt(_o,e),wt(sr,s))}function Gx(e){_o.current===e&&(kt(sr),kt(_o))}var Rt=bi(0);function vd(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 Mf=[];function Yx(){for(var e=0;e<Mf.length;e++)Mf[e]._workInProgressVersionPrimary=null;Mf.length=0}var Ou=zr.ReactCurrentDispatcher,Df=zr.ReactCurrentBatchConfig,Qi=0,$t=null,Ht=null,Xt=null,jd=!1,vo=!1,zo=0,MP=0;function mn(){throw Error(de(321))}function qx(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!Ds(e[s],t[s]))return!1;return!0}function Qx(e,t,s,r,i,a){if(Qi=a,$t=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,Ou.current=e===null||e.memoizedState===null?_P:FP,e=s(r,i),vo){a=0;do{if(vo=!1,zo=0,25<=a)throw Error(de(301));a+=1,Xt=Ht=null,t.updateQueue=null,Ou.current=zP,e=s(r,i)}while(vo)}if(Ou.current=wd,t=Ht!==null&&Ht.next!==null,Qi=0,Xt=Ht=$t=null,jd=!1,t)throw Error(de(300));return e}function Xx(){var e=zo!==0;return zo=0,e}function Qs(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Xt===null?$t.memoizedState=Xt=e:Xt=Xt.next=e,Xt}function vs(){if(Ht===null){var e=$t.alternate;e=e!==null?e.memoizedState:null}else e=Ht.next;var t=Xt===null?$t.memoizedState:Xt.next;if(t!==null)Xt=t,Ht=e;else{if(e===null)throw Error(de(310));Ht=e,e={memoizedState:Ht.memoizedState,baseState:Ht.baseState,baseQueue:Ht.baseQueue,queue:Ht.queue,next:null},Xt===null?$t.memoizedState=Xt=e:Xt=Xt.next=e}return Xt}function Uo(e,t){return typeof t=="function"?t(e):t}function Of(e){var t=vs(),s=t.queue;if(s===null)throw Error(de(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 d=u.lane;if((Qi&d)===d)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:d,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,$t.lanes|=d,Xi|=d}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,Ds(r,t.memoizedState)||(Pn=!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,$t.lanes|=a,Xi|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function Lf(e){var t=vs(),s=t.queue;if(s===null)throw Error(de(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);Ds(a,t.memoizedState)||(Pn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function eS(){}function tS(e,t){var s=$t,r=vs(),i=t(),a=!Ds(r.memoizedState,i);if(a&&(r.memoizedState=i,Pn=!0),r=r.queue,Jx(rS.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||Xt!==null&&Xt.memoizedState.tag&1){if(s.flags|=2048,Bo(9,sS.bind(null,s,r,i,t),void 0,null),tn===null)throw Error(de(349));Qi&30||nS(s,t,i)}return i}function nS(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=$t.updateQueue,t===null?(t={lastEffect:null,stores:null},$t.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function sS(e,t,s,r){t.value=s,t.getSnapshot=r,iS(t)&&aS(e)}function rS(e,t,s){return s(function(){iS(t)&&aS(e)})}function iS(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!Ds(e,s)}catch{return!0}}function aS(e){var t=Ir(e,1);t!==null&&$s(t,e,1,-1)}function Ey(e){var t=Qs();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Uo,lastRenderedState:e},t.queue=e,e=e.dispatch=LP.bind(null,$t,e),[t.memoizedState,e]}function Bo(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=$t.updateQueue,t===null?(t={lastEffect:null,stores:null},$t.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 lS(){return vs().memoizedState}function Lu(e,t,s,r){var i=Qs();$t.flags|=e,i.memoizedState=Bo(1|t,s,void 0,r===void 0?null:r)}function oh(e,t,s,r){var i=vs();r=r===void 0?null:r;var a=void 0;if(Ht!==null){var l=Ht.memoizedState;if(a=l.destroy,r!==null&&qx(r,l.deps)){i.memoizedState=Bo(t,s,a,r);return}}$t.flags|=e,i.memoizedState=Bo(1|t,s,a,r)}function Ay(e,t){return Lu(8390656,8,e,t)}function Jx(e,t){return oh(2048,8,e,t)}function oS(e,t){return oh(4,2,e,t)}function cS(e,t){return oh(4,4,e,t)}function uS(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 dS(e,t,s){return s=s!=null?s.concat([e]):null,oh(4,4,uS.bind(null,t,e),s)}function Zx(){}function hS(e,t){var s=vs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&qx(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function fS(e,t){var s=vs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&qx(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function mS(e,t,s){return Qi&21?(Ds(s,t)||(s=jN(),$t.lanes|=s,Xi|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Pn=!0),e.memoizedState=s)}function DP(e,t){var s=mt;mt=s!==0&&4>s?s:4,e(!0);var r=Df.transition;Df.transition={};try{e(!1),t()}finally{mt=s,Df.transition=r}}function pS(){return vs().memoizedState}function OP(e,t,s){var r=ai(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},gS(e))xS(t,s);else if(s=XN(e,t,s,r),s!==null){var i=Nn();$s(s,e,r,i),vS(s,t,r)}}function LP(e,t,s){var r=ai(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(gS(e))xS(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,Ds(o,l)){var c=t.interleaved;c===null?(i.next=i,Hx(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=XN(e,t,i,r),s!==null&&(i=Nn(),$s(s,e,r,i),vS(s,t,r))}}function gS(e){var t=e.alternate;return e===$t||t!==null&&t===$t}function xS(e,t){vo=jd=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function vS(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,Rx(e,s)}}var wd={readContext:xs,useCallback:mn,useContext:mn,useEffect:mn,useImperativeHandle:mn,useInsertionEffect:mn,useLayoutEffect:mn,useMemo:mn,useReducer:mn,useRef:mn,useState:mn,useDebugValue:mn,useDeferredValue:mn,useTransition:mn,useMutableSource:mn,useSyncExternalStore:mn,useId:mn,unstable_isNewReconciler:!1},_P={readContext:xs,useCallback:function(e,t){return Qs().memoizedState=[e,t===void 0?null:t],e},useContext:xs,useEffect:Ay,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,Lu(4194308,4,uS.bind(null,t,e),s)},useLayoutEffect:function(e,t){return Lu(4194308,4,e,t)},useInsertionEffect:function(e,t){return Lu(4,2,e,t)},useMemo:function(e,t){var s=Qs();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Qs();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=OP.bind(null,$t,e),[r.memoizedState,e]},useRef:function(e){var t=Qs();return e={current:e},t.memoizedState=e},useState:Ey,useDebugValue:Zx,useDeferredValue:function(e){return Qs().memoizedState=e},useTransition:function(){var e=Ey(!1),t=e[0];return e=DP.bind(null,e[1]),Qs().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=$t,i=Qs();if(St){if(s===void 0)throw Error(de(407));s=s()}else{if(s=t(),tn===null)throw Error(de(349));Qi&30||nS(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,Ay(rS.bind(null,r,a,e),[e]),r.flags|=2048,Bo(9,sS.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Qs(),t=tn.identifierPrefix;if(St){var s=kr,r=br;s=(r&~(1<<32-Rs(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=zo++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=MP++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},FP={readContext:xs,useCallback:hS,useContext:xs,useEffect:Jx,useImperativeHandle:dS,useInsertionEffect:oS,useLayoutEffect:cS,useMemo:fS,useReducer:Of,useRef:lS,useState:function(){return Of(Uo)},useDebugValue:Zx,useDeferredValue:function(e){var t=vs();return mS(t,Ht.memoizedState,e)},useTransition:function(){var e=Of(Uo)[0],t=vs().memoizedState;return[e,t]},useMutableSource:eS,useSyncExternalStore:tS,useId:pS,unstable_isNewReconciler:!1},zP={readContext:xs,useCallback:hS,useContext:xs,useEffect:Jx,useImperativeHandle:dS,useInsertionEffect:oS,useLayoutEffect:cS,useMemo:fS,useReducer:Lf,useRef:lS,useState:function(){return Lf(Uo)},useDebugValue:Zx,useDeferredValue:function(e){var t=vs();return Ht===null?t.memoizedState=e:mS(t,Ht.memoizedState,e)},useTransition:function(){var e=Lf(Uo)[0],t=vs().memoizedState;return[e,t]},useMutableSource:eS,useSyncExternalStore:tS,useId:pS,unstable_isNewReconciler:!1};function Cs(e,t){if(e&&e.defaultProps){t=Pt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function jp(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:Pt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var ch={isMounted:function(e){return(e=e._reactInternals)?ra(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=Nn(),i=ai(e),a=Sr(r,i);a.payload=t,s!=null&&(a.callback=s),t=ri(e,a,i),t!==null&&($s(t,e,i,r),Du(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=Nn(),i=ai(e),a=Sr(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=ri(e,a,i),t!==null&&($s(t,e,i,r),Du(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=Nn(),r=ai(e),i=Sr(s,r);i.tag=2,t!=null&&(i.callback=t),t=ri(e,i,r),t!==null&&($s(t,e,r,s),Du(t,e,r))}};function Ty(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?!Mo(s,r)||!Mo(i,a):!0}function jS(e,t,s){var r=!1,i=hi,a=t.contextType;return typeof a=="object"&&a!==null?a=xs(a):(i=Dn(t)?Yi:vn.current,r=t.contextTypes,a=(r=r!=null)?el(e,i):hi),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=ch,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Ry(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&&ch.enqueueReplaceState(t,t.state,null)}function wp(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},Kx(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=xs(a):(a=Dn(t)?Yi:vn.current,i.context=el(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(jp(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&&ch.enqueueReplaceState(i,i.state,null),xd(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function rl(e,t){try{var s="",r=t;do s+=mI(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 _f(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function yp(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var UP=typeof WeakMap=="function"?WeakMap:Map;function wS(e,t,s){s=Sr(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){bd||(bd=!0,$p=r),yp(e,t)},s}function yS(e,t,s){s=Sr(-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(){yp(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){yp(e,t),typeof r!="function"&&(ii===null?ii=new Set([this]):ii.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function $y(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new UP;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=t2.bind(null,e,t,s),t.then(e,e))}function Iy(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 Py(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=Sr(-1,1),t.tag=2,ri(s,t,1))),s.lanes|=1),e)}var BP=zr.ReactCurrentOwner,Pn=!1;function bn(e,t,s,r){t.child=e===null?QN(t,null,s,r):nl(t,e.child,s,r)}function My(e,t,s,r,i){s=s.render;var a=t.ref;return Ka(t,i),r=Qx(e,t,s,r,a,i),s=Xx(),e!==null&&!Pn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Pr(e,t,i)):(St&&s&&_x(t),t.flags|=1,bn(e,t,r,i),t.child)}function Dy(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!lv(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,bS(e,t,a,r,i)):(e=Uu(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:Mo,s(l,r)&&e.ref===t.ref)return Pr(e,t,i)}return t.flags|=1,e=li(a,r),e.ref=t.ref,e.return=t,t.child=e}function bS(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(Mo(a,r)&&e.ref===t.ref)if(Pn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Pn=!0);else return t.lanes=e.lanes,Pr(e,t,i)}return bp(e,t,s,r,i)}function kS(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},wt(Oa,Kn),Kn|=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,wt(Oa,Kn),Kn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,wt(Oa,Kn),Kn|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,wt(Oa,Kn),Kn|=r;return bn(e,t,i,s),t.child}function NS(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function bp(e,t,s,r,i){var a=Dn(s)?Yi:vn.current;return a=el(t,a),Ka(t,i),s=Qx(e,t,s,r,a,i),r=Xx(),e!==null&&!Pn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Pr(e,t,i)):(St&&r&&_x(t),t.flags|=1,bn(e,t,s,i),t.child)}function Oy(e,t,s,r,i){if(Dn(s)){var a=!0;hd(t)}else a=!1;if(Ka(t,i),t.stateNode===null)_u(e,t),jS(t,s,r),wp(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=xs(u):(u=Dn(s)?Yi:vn.current,u=el(t,u));var d=s.getDerivedStateFromProps,f=typeof d=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Ry(t,l,r,u),Gr=!1;var m=t.memoizedState;l.state=m,xd(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Mn.current||Gr?(typeof d=="function"&&(jp(t,s,d,r),c=t.memoizedState),(o=Gr||Ty(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,JN(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:Cs(t.type,o),l.props=u,f=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=xs(c):(c=Dn(s)?Yi:vn.current,c=el(t,c));var p=s.getDerivedStateFromProps;(d=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&Ry(t,l,r,c),Gr=!1,m=t.memoizedState,l.state=m,xd(t,r,l,i);var g=t.memoizedState;o!==f||m!==g||Mn.current||Gr?(typeof p=="function"&&(jp(t,s,p,r),g=t.memoizedState),(u=Gr||Ty(t,s,u,r,m,g,c)||!1)?(d||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 kp(e,t,s,r,a,i)}function kp(e,t,s,r,i,a){NS(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&yy(t,s,!1),Pr(e,t,a);r=t.stateNode,BP.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=nl(t,e.child,null,a),t.child=nl(t,null,o,a)):bn(e,t,o,a),t.memoizedState=r.state,i&&yy(t,s,!0),t.child}function SS(e){var t=e.stateNode;t.pendingContext?wy(e,t.pendingContext,t.pendingContext!==t.context):t.context&&wy(e,t.context,!1),Vx(e,t.containerInfo)}function Ly(e,t,s,r,i){return tl(),zx(i),t.flags|=256,bn(e,t,s,r),t.child}var Np={dehydrated:null,treeContext:null,retryLane:0};function Sp(e){return{baseLanes:e,cachePool:null,transitions:null}}function CS(e,t,s){var r=t.pendingProps,i=Rt.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),wt(Rt,i&1),e===null)return xp(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=hh(l,r,0,null),e=Ki(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=Sp(s),t.memoizedState=Np,e):ev(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return WP(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=li(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=li(o,a):(a=Ki(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?Sp(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=Np,r}return a=e.child,e=a.sibling,r=li(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 ev(e,t){return t=hh({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function tu(e,t,s,r){return r!==null&&zx(r),nl(t,e.child,null,s),e=ev(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function WP(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=_f(Error(de(422))),tu(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=hh({mode:"visible",children:r.children},i,0,null),a=Ki(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&nl(t,e.child,null,l),t.child.memoizedState=Sp(l),t.memoizedState=Np,a);if(!(t.mode&1))return tu(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(de(419)),r=_f(a,r,void 0),tu(e,t,l,r)}if(o=(l&e.childLanes)!==0,Pn||o){if(r=tn,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,Ir(e,i),$s(r,e,i,-1))}return av(),r=_f(Error(de(421))),tu(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=n2.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Gn=si(i.nextSibling),qn=t,St=!0,As=null,e!==null&&(cs[us++]=br,cs[us++]=kr,cs[us++]=qi,br=e.id,kr=e.overflow,qi=t),t=ev(t,r.children),t.flags|=4096,t)}function _y(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),vp(e.return,t,s)}function Ff(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 ES(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(bn(e,t,r.children,s),r=Rt.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&&_y(e,s,t);else if(e.tag===19)_y(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(wt(Rt,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&&vd(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),Ff(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&&vd(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}Ff(t,!0,s,null,a);break;case"together":Ff(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function _u(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Pr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),Xi|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(de(153));if(t.child!==null){for(e=t.child,s=li(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=li(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function HP(e,t,s){switch(t.tag){case 3:SS(t),tl();break;case 5:ZN(t);break;case 1:Dn(t.type)&&hd(t);break;case 4:Vx(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;wt(pd,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(wt(Rt,Rt.current&1),t.flags|=128,null):s&t.child.childLanes?CS(e,t,s):(wt(Rt,Rt.current&1),e=Pr(e,t,s),e!==null?e.sibling:null);wt(Rt,Rt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return ES(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),wt(Rt,Rt.current),r)break;return null;case 22:case 23:return t.lanes=0,kS(e,t,s)}return Pr(e,t,s)}var AS,Cp,TS,RS;AS=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}};Cp=function(){};TS=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Ui(sr.current);var a=null;switch(s){case"input":i=Ym(e,i),r=Ym(e,r),a=[];break;case"select":i=Pt({},i,{value:void 0}),r=Pt({},r,{value:void 0}),a=[];break;case"textarea":i=Xm(e,i),r=Xm(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=ud)}Zm(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"&&(Eo.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"&&(Eo.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&bt("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)}};RS=function(e,t,s,r){s!==r&&(t.flags|=4)};function ql(e,t){if(!St)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 pn(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 KP(e,t,s){var r=t.pendingProps;switch(Fx(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return pn(t),null;case 1:return Dn(t.type)&&dd(),pn(t),null;case 3:return r=t.stateNode,sl(),kt(Mn),kt(vn),Yx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Zc(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,As!==null&&(Mp(As),As=null))),Cp(e,t),pn(t),null;case 5:Gx(t);var i=Ui(Fo.current);if(s=t.type,e!==null&&t.stateNode!=null)TS(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(de(166));return pn(t),null}if(e=Ui(sr.current),Zc(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[Js]=t,r[Lo]=a,e=(t.mode&1)!==0,s){case"dialog":bt("cancel",r),bt("close",r);break;case"iframe":case"object":case"embed":bt("load",r);break;case"video":case"audio":for(i=0;i<oo.length;i++)bt(oo[i],r);break;case"source":bt("error",r);break;case"img":case"image":case"link":bt("error",r),bt("load",r);break;case"details":bt("toggle",r);break;case"input":Gw(r,a),bt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},bt("invalid",r);break;case"textarea":qw(r,a),bt("invalid",r)}Zm(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&&Jc(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&Jc(r.textContent,o,e),i=["children",""+o]):Eo.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&bt("scroll",r)}switch(s){case"input":Hc(r),Yw(r,a,!0);break;case"textarea":Hc(r),Qw(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=ud)}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=rN(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[Js]=t,e[Lo]=r,AS(e,t,!1,!1),t.stateNode=e;e:{switch(l=ep(s,r),s){case"dialog":bt("cancel",e),bt("close",e),i=r;break;case"iframe":case"object":case"embed":bt("load",e),i=r;break;case"video":case"audio":for(i=0;i<oo.length;i++)bt(oo[i],e);i=r;break;case"source":bt("error",e),i=r;break;case"img":case"image":case"link":bt("error",e),bt("load",e),i=r;break;case"details":bt("toggle",e),i=r;break;case"input":Gw(e,r),i=Ym(e,r),bt("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=Pt({},r,{value:void 0}),bt("invalid",e);break;case"textarea":qw(e,r),i=Xm(e,r),bt("invalid",e);break;default:i=r}Zm(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?lN(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&iN(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Ao(e,c):typeof c=="number"&&Ao(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Eo.hasOwnProperty(a)?c!=null&&a==="onScroll"&&bt("scroll",e):c!=null&&Nx(e,a,c,l))}switch(s){case"input":Hc(e),Yw(e,r,!1);break;case"textarea":Hc(e),Qw(e);break;case"option":r.value!=null&&e.setAttribute("value",""+di(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?Ua(e,!!r.multiple,a,!1):r.defaultValue!=null&&Ua(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=ud)}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 pn(t),null;case 6:if(e&&t.stateNode!=null)RS(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(de(166));if(s=Ui(Fo.current),Ui(sr.current),Zc(t)){if(r=t.stateNode,s=t.memoizedProps,r[Js]=t,(a=r.nodeValue!==s)&&(e=qn,e!==null))switch(e.tag){case 3:Jc(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Jc(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Js]=t,t.stateNode=r}return pn(t),null;case 13:if(kt(Rt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(St&&Gn!==null&&t.mode&1&&!(t.flags&128))YN(),tl(),t.flags|=98560,a=!1;else if(a=Zc(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(de(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(de(317));a[Js]=t}else tl(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;pn(t),a=!1}else As!==null&&(Mp(As),As=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||Rt.current&1?Gt===0&&(Gt=3):av())),t.updateQueue!==null&&(t.flags|=4),pn(t),null);case 4:return sl(),Cp(e,t),e===null&&Do(t.stateNode.containerInfo),pn(t),null;case 10:return Wx(t.type._context),pn(t),null;case 17:return Dn(t.type)&&dd(),pn(t),null;case 19:if(kt(Rt),a=t.memoizedState,a===null)return pn(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)ql(a,!1);else{if(Gt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=vd(e),l!==null){for(t.flags|=128,ql(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 wt(Rt,Rt.current&1|2),t.child}e=e.sibling}a.tail!==null&&Lt()>il&&(t.flags|=128,r=!0,ql(a,!1),t.lanes=4194304)}else{if(!r)if(e=vd(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),ql(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!St)return pn(t),null}else 2*Lt()-a.renderingStartTime>il&&s!==1073741824&&(t.flags|=128,r=!0,ql(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=Lt(),t.sibling=null,s=Rt.current,wt(Rt,r?s&1|2:s&1),t):(pn(t),null);case 22:case 23:return iv(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Kn&1073741824&&(pn(t),t.subtreeFlags&6&&(t.flags|=8192)):pn(t),null;case 24:return null;case 25:return null}throw Error(de(156,t.tag))}function VP(e,t){switch(Fx(t),t.tag){case 1:return Dn(t.type)&&dd(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return sl(),kt(Mn),kt(vn),Yx(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Gx(t),null;case 13:if(kt(Rt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(de(340));tl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return kt(Rt),null;case 4:return sl(),null;case 10:return Wx(t.type._context),null;case 22:case 23:return iv(),null;case 24:return null;default:return null}}var nu=!1,gn=!1,GP=typeof WeakSet=="function"?WeakSet:Set,Te=null;function Da(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 Ep(e,t,s){try{s()}catch(r){Mt(e,t,r)}}var Fy=!1;function YP(e,t){if(up=ld,e=DN(),Lx(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,d=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&&++d===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(dp={focusedElem:e,selectionRange:s},ld=!1,Te=t;Te!==null;)if(t=Te,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Te=e;else for(;Te!==null;){t=Te;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 x=g.memoizedProps,b=g.memoizedState,j=t.stateNode,v=j.getSnapshotBeforeUpdate(t.elementType===t.type?x:Cs(t.type,x),b);j.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(de(163))}}catch(y){Mt(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,Te=e;break}Te=t.return}return g=Fy,Fy=!1,g}function jo(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&&Ep(t,s,a)}i=i.next}while(i!==r)}}function uh(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 Ap(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 $S(e){var t=e.alternate;t!==null&&(e.alternate=null,$S(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Js],delete t[Lo],delete t[mp],delete t[RP],delete t[$P])),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 IS(e){return e.tag===5||e.tag===3||e.tag===4}function zy(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||IS(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 Tp(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=ud));else if(r!==4&&(e=e.child,e!==null))for(Tp(e,t,s),e=e.sibling;e!==null;)Tp(e,t,s),e=e.sibling}function Rp(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(Rp(e,t,s),e=e.sibling;e!==null;)Rp(e,t,s),e=e.sibling}var an=null,Es=!1;function Hr(e,t,s){for(s=s.child;s!==null;)PS(e,t,s),s=s.sibling}function PS(e,t,s){if(nr&&typeof nr.onCommitFiberUnmount=="function")try{nr.onCommitFiberUnmount(nh,s)}catch{}switch(s.tag){case 5:gn||Da(s,t);case 6:var r=an,i=Es;an=null,Hr(e,t,s),an=r,Es=i,an!==null&&(Es?(e=an,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):an.removeChild(s.stateNode));break;case 18:an!==null&&(Es?(e=an,s=s.stateNode,e.nodeType===8?If(e.parentNode,s):e.nodeType===1&&If(e,s),Io(e)):If(an,s.stateNode));break;case 4:r=an,i=Es,an=s.stateNode.containerInfo,Es=!0,Hr(e,t,s),an=r,Es=i;break;case 0:case 11:case 14:case 15:if(!gn&&(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)&&Ep(s,t,l),i=i.next}while(i!==r)}Hr(e,t,s);break;case 1:if(!gn&&(Da(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)}Hr(e,t,s);break;case 21:Hr(e,t,s);break;case 22:s.mode&1?(gn=(r=gn)||s.memoizedState!==null,Hr(e,t,s),gn=r):Hr(e,t,s);break;default:Hr(e,t,s)}}function Uy(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new GP),t.forEach(function(r){var i=s2.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function Ss(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,Es=!1;break e;case 3:an=o.stateNode.containerInfo,Es=!0;break e;case 4:an=o.stateNode.containerInfo,Es=!0;break e}o=o.return}if(an===null)throw Error(de(160));PS(a,l,i),an=null,Es=!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;)MS(t,e),t=t.sibling}function MS(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Ss(t,e),Vs(e),r&4){try{jo(3,e,e.return),uh(3,e)}catch(x){Mt(e,e.return,x)}try{jo(5,e,e.return)}catch(x){Mt(e,e.return,x)}}break;case 1:Ss(t,e),Vs(e),r&512&&s!==null&&Da(s,s.return);break;case 5:if(Ss(t,e),Vs(e),r&512&&s!==null&&Da(s,s.return),e.flags&32){var i=e.stateNode;try{Ao(i,"")}catch(x){Mt(e,e.return,x)}}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&&nN(i,a),ep(o,l);var u=ep(o,a);for(l=0;l<c.length;l+=2){var d=c[l],f=c[l+1];d==="style"?lN(i,f):d==="dangerouslySetInnerHTML"?iN(i,f):d==="children"?Ao(i,f):Nx(i,d,f,u)}switch(o){case"input":qm(i,a);break;case"textarea":sN(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?Ua(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?Ua(i,!!a.multiple,a.defaultValue,!0):Ua(i,!!a.multiple,a.multiple?[]:"",!1))}i[Lo]=a}catch(x){Mt(e,e.return,x)}}break;case 6:if(Ss(t,e),Vs(e),r&4){if(e.stateNode===null)throw Error(de(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(x){Mt(e,e.return,x)}}break;case 3:if(Ss(t,e),Vs(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Io(t.containerInfo)}catch(x){Mt(e,e.return,x)}break;case 4:Ss(t,e),Vs(e);break;case 13:Ss(t,e),Vs(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(sv=Lt())),r&4&&Uy(e);break;case 22:if(d=s!==null&&s.memoizedState!==null,e.mode&1?(gn=(u=gn)||d,Ss(t,e),gn=u):Ss(t,e),Vs(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(Te=e,d=e.child;d!==null;){for(f=Te=d;Te!==null;){switch(m=Te,p=m.child,m.tag){case 0:case 11:case 14:case 15:jo(4,m,m.return);break;case 1:Da(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(x){Mt(r,s,x)}}break;case 5:Da(m,m.return);break;case 22:if(m.memoizedState!==null){Wy(f);continue}}p!==null?(p.return=m,Te=p):Wy(f)}d=d.sibling}e:for(d=null,f=e;;){if(f.tag===5){if(d===null){d=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=aN("display",l))}catch(x){Mt(e,e.return,x)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(x){Mt(e,e.return,x)}}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;d===f&&(d=null),f=f.return}d===f&&(d=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Ss(t,e),Vs(e),r&4&&Uy(e);break;case 21:break;default:Ss(t,e),Vs(e)}}function Vs(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(IS(s)){var r=s;break e}s=s.return}throw Error(de(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(Ao(i,""),r.flags&=-33);var a=zy(e);Rp(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=zy(e);Tp(e,o,l);break;default:throw Error(de(161))}}catch(c){Mt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function qP(e,t,s){Te=e,DS(e)}function DS(e,t,s){for(var r=(e.mode&1)!==0;Te!==null;){var i=Te,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||nu;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||gn;o=nu;var u=gn;if(nu=l,(gn=c)&&!u)for(Te=i;Te!==null;)l=Te,c=l.child,l.tag===22&&l.memoizedState!==null?Hy(i):c!==null?(c.return=l,Te=c):Hy(i);for(;a!==null;)Te=a,DS(a),a=a.sibling;Te=i,nu=o,gn=u}By(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,Te=a):By(e)}}function By(e){for(;Te!==null;){var t=Te;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:gn||uh(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!gn)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:Cs(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&Cy(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}Cy(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 d=u.memoizedState;if(d!==null){var f=d.dehydrated;f!==null&&Io(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(de(163))}gn||t.flags&512&&Ap(t)}catch(m){Mt(t,t.return,m)}}if(t===e){Te=null;break}if(s=t.sibling,s!==null){s.return=t.return,Te=s;break}Te=t.return}}function Wy(e){for(;Te!==null;){var t=Te;if(t===e){Te=null;break}var s=t.sibling;if(s!==null){s.return=t.return,Te=s;break}Te=t.return}}function Hy(e){for(;Te!==null;){var t=Te;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{uh(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{Ap(t)}catch(c){Mt(t,a,c)}break;case 5:var l=t.return;try{Ap(t)}catch(c){Mt(t,l,c)}}}catch(c){Mt(t,t.return,c)}if(t===e){Te=null;break}var o=t.sibling;if(o!==null){o.return=t.return,Te=o;break}Te=t.return}}var QP=Math.ceil,yd=zr.ReactCurrentDispatcher,tv=zr.ReactCurrentOwner,ps=zr.ReactCurrentBatchConfig,at=0,tn=null,zt=null,on=0,Kn=0,Oa=bi(0),Gt=0,Wo=null,Xi=0,dh=0,nv=0,wo=null,In=null,sv=0,il=1/0,gr=null,bd=!1,$p=null,ii=null,su=!1,Xr=null,kd=0,yo=0,Ip=null,Fu=-1,zu=0;function Nn(){return at&6?Lt():Fu!==-1?Fu:Fu=Lt()}function ai(e){return e.mode&1?at&2&&on!==0?on&-on:PP.transition!==null?(zu===0&&(zu=jN()),zu):(e=mt,e!==0||(e=window.event,e=e===void 0?16:CN(e.type)),e):1}function $s(e,t,s,r){if(50<yo)throw yo=0,Ip=null,Error(de(185));pc(e,s,r),(!(at&2)||e!==tn)&&(e===tn&&(!(at&2)&&(dh|=s),Gt===4&&qr(e,on)),On(e,r),s===1&&at===0&&!(t.mode&1)&&(il=Lt()+500,lh&&ki()))}function On(e,t){var s=e.callbackNode;PI(e,t);var r=ad(e,e===tn?on:0);if(r===0)s!==null&&Zw(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&Zw(s),t===1)e.tag===0?IP(Ky.bind(null,e)):KN(Ky.bind(null,e)),AP(function(){!(at&6)&&ki()}),s=null;else{switch(wN(r)){case 1:s=Tx;break;case 4:s=xN;break;case 16:s=id;break;case 536870912:s=vN;break;default:s=id}s=WS(s,OS.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function OS(e,t){if(Fu=-1,zu=0,at&6)throw Error(de(327));var s=e.callbackNode;if(Va()&&e.callbackNode!==s)return null;var r=ad(e,e===tn?on:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Nd(e,r);else{t=r;var i=at;at|=2;var a=_S();(tn!==e||on!==t)&&(gr=null,il=Lt()+500,Hi(e,t));do try{ZP();break}catch(o){LS(e,o)}while(!0);Bx(),yd.current=a,at=i,zt!==null?t=0:(tn=null,on=0,t=Gt)}if(t!==0){if(t===2&&(i=ip(e),i!==0&&(r=i,t=Pp(e,i))),t===1)throw s=Wo,Hi(e,0),qr(e,r),On(e,Lt()),s;if(t===6)qr(e,r);else{if(i=e.current.alternate,!(r&30)&&!XP(i)&&(t=Nd(e,r),t===2&&(a=ip(e),a!==0&&(r=a,t=Pp(e,a))),t===1))throw s=Wo,Hi(e,0),qr(e,r),On(e,Lt()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(de(345));case 2:Di(e,In,gr);break;case 3:if(qr(e,r),(r&130023424)===r&&(t=sv+500-Lt(),10<t)){if(ad(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){Nn(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=fp(Di.bind(null,e,In,gr),t);break}Di(e,In,gr);break;case 4:if(qr(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-Rs(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=Lt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*QP(r/1960))-r,10<r){e.timeoutHandle=fp(Di.bind(null,e,In,gr),r);break}Di(e,In,gr);break;case 5:Di(e,In,gr);break;default:throw Error(de(329))}}}return On(e,Lt()),e.callbackNode===s?OS.bind(null,e):null}function Pp(e,t){var s=wo;return e.current.memoizedState.isDehydrated&&(Hi(e,t).flags|=256),e=Nd(e,t),e!==2&&(t=In,In=s,t!==null&&Mp(t)),e}function Mp(e){In===null?In=e:In.push.apply(In,e)}function XP(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(!Ds(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 qr(e,t){for(t&=~nv,t&=~dh,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-Rs(t),r=1<<s;e[s]=-1,t&=~r}}function Ky(e){if(at&6)throw Error(de(327));Va();var t=ad(e,0);if(!(t&1))return On(e,Lt()),null;var s=Nd(e,t);if(e.tag!==0&&s===2){var r=ip(e);r!==0&&(t=r,s=Pp(e,r))}if(s===1)throw s=Wo,Hi(e,0),qr(e,t),On(e,Lt()),s;if(s===6)throw Error(de(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Di(e,In,gr),On(e,Lt()),null}function rv(e,t){var s=at;at|=1;try{return e(t)}finally{at=s,at===0&&(il=Lt()+500,lh&&ki())}}function Ji(e){Xr!==null&&Xr.tag===0&&!(at&6)&&Va();var t=at;at|=1;var s=ps.transition,r=mt;try{if(ps.transition=null,mt=1,e)return e()}finally{mt=r,ps.transition=s,at=t,!(at&6)&&ki()}}function iv(){Kn=Oa.current,kt(Oa)}function Hi(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,EP(s)),zt!==null)for(s=zt.return;s!==null;){var r=s;switch(Fx(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&dd();break;case 3:sl(),kt(Mn),kt(vn),Yx();break;case 5:Gx(r);break;case 4:sl();break;case 13:kt(Rt);break;case 19:kt(Rt);break;case 10:Wx(r.type._context);break;case 22:case 23:iv()}s=s.return}if(tn=e,zt=e=li(e.current,null),on=Kn=t,Gt=0,Wo=null,nv=dh=Xi=0,In=wo=null,zi!==null){for(t=0;t<zi.length;t++)if(s=zi[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}zi=null}return e}function LS(e,t){do{var s=zt;try{if(Bx(),Ou.current=wd,jd){for(var r=$t.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}jd=!1}if(Qi=0,Xt=Ht=$t=null,vo=!1,zo=0,tv.current=null,s===null||s.return===null){Gt=1,Wo=t,zt=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=on,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,d=o,f=d.tag;if(!(d.mode&1)&&(f===0||f===11||f===15)){var m=d.alternate;m?(d.updateQueue=m.updateQueue,d.memoizedState=m.memoizedState,d.lanes=m.lanes):(d.updateQueue=null,d.memoizedState=null)}var p=Iy(l);if(p!==null){p.flags&=-257,Py(p,l,o,a,t),p.mode&1&&$y(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var x=new Set;x.add(c),t.updateQueue=x}else g.add(c);break e}else{if(!(t&1)){$y(a,u,t),av();break e}c=Error(de(426))}}else if(St&&o.mode&1){var b=Iy(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),Py(b,l,o,a,t),zx(rl(c,o));break e}}a=c=rl(c,o),Gt!==4&&(Gt=2),wo===null?wo=[a]:wo.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var j=wS(a,c,t);Sy(a,j);break e;case 1:o=c;var v=a.type,w=a.stateNode;if(!(a.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(ii===null||!ii.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=yS(a,o,t);Sy(a,y);break e}}a=a.return}while(a!==null)}zS(s)}catch(N){t=N,zt===s&&s!==null&&(zt=s=s.return);continue}break}while(!0)}function _S(){var e=yd.current;return yd.current=wd,e===null?wd:e}function av(){(Gt===0||Gt===3||Gt===2)&&(Gt=4),tn===null||!(Xi&268435455)&&!(dh&268435455)||qr(tn,on)}function Nd(e,t){var s=at;at|=2;var r=_S();(tn!==e||on!==t)&&(gr=null,Hi(e,t));do try{JP();break}catch(i){LS(e,i)}while(!0);if(Bx(),at=s,yd.current=r,zt!==null)throw Error(de(261));return tn=null,on=0,Gt}function JP(){for(;zt!==null;)FS(zt)}function ZP(){for(;zt!==null&&!NI();)FS(zt)}function FS(e){var t=BS(e.alternate,e,Kn);e.memoizedProps=e.pendingProps,t===null?zS(e):zt=t,tv.current=null}function zS(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=VP(s,t),s!==null){s.flags&=32767,zt=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Gt=6,zt=null;return}}else if(s=KP(s,t,Kn),s!==null){zt=s;return}if(t=t.sibling,t!==null){zt=t;return}zt=t=e}while(t!==null);Gt===0&&(Gt=5)}function Di(e,t,s){var r=mt,i=ps.transition;try{ps.transition=null,mt=1,e2(e,t,s,r)}finally{ps.transition=i,mt=r}return null}function e2(e,t,s,r){do Va();while(Xr!==null);if(at&6)throw Error(de(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(de(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(MI(e,a),e===tn&&(zt=tn=null,on=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||su||(su=!0,WS(id,function(){return Va(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=ps.transition,ps.transition=null;var l=mt;mt=1;var o=at;at|=4,tv.current=null,YP(e,s),MS(s,e),wP(dp),ld=!!up,dp=up=null,e.current=s,qP(s),SI(),at=o,mt=l,ps.transition=a}else e.current=s;if(su&&(su=!1,Xr=e,kd=i),a=e.pendingLanes,a===0&&(ii=null),AI(s.stateNode),On(e,Lt()),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(bd)throw bd=!1,e=$p,$p=null,e;return kd&1&&e.tag!==0&&Va(),a=e.pendingLanes,a&1?e===Ip?yo++:(yo=0,Ip=e):yo=0,ki(),null}function Va(){if(Xr!==null){var e=wN(kd),t=ps.transition,s=mt;try{if(ps.transition=null,mt=16>e?16:e,Xr===null)var r=!1;else{if(e=Xr,Xr=null,kd=0,at&6)throw Error(de(331));var i=at;for(at|=4,Te=e.current;Te!==null;){var a=Te,l=a.child;if(Te.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(Te=u;Te!==null;){var d=Te;switch(d.tag){case 0:case 11:case 15:jo(8,d,a)}var f=d.child;if(f!==null)f.return=d,Te=f;else for(;Te!==null;){d=Te;var m=d.sibling,p=d.return;if($S(d),d===u){Te=null;break}if(m!==null){m.return=p,Te=m;break}Te=p}}}var g=a.alternate;if(g!==null){var x=g.child;if(x!==null){g.child=null;do{var b=x.sibling;x.sibling=null,x=b}while(x!==null)}}Te=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,Te=l;else e:for(;Te!==null;){if(a=Te,a.flags&2048)switch(a.tag){case 0:case 11:case 15:jo(9,a,a.return)}var j=a.sibling;if(j!==null){j.return=a.return,Te=j;break e}Te=a.return}}var v=e.current;for(Te=v;Te!==null;){l=Te;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Te=w;else e:for(l=v;Te!==null;){if(o=Te,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:uh(9,o)}}catch(N){Mt(o,o.return,N)}if(o===l){Te=null;break e}var y=o.sibling;if(y!==null){y.return=o.return,Te=y;break e}Te=o.return}}if(at=i,ki(),nr&&typeof nr.onPostCommitFiberRoot=="function")try{nr.onPostCommitFiberRoot(nh,e)}catch{}r=!0}return r}finally{mt=s,ps.transition=t}}return!1}function Vy(e,t,s){t=rl(s,t),t=wS(e,t,1),e=ri(e,t,1),t=Nn(),e!==null&&(pc(e,1,t),On(e,t))}function Mt(e,t,s){if(e.tag===3)Vy(e,e,s);else for(;t!==null;){if(t.tag===3){Vy(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ii===null||!ii.has(r))){e=rl(s,e),e=yS(t,e,1),t=ri(t,e,1),e=Nn(),t!==null&&(pc(t,1,e),On(t,e));break}}t=t.return}}function t2(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=Nn(),e.pingedLanes|=e.suspendedLanes&s,tn===e&&(on&s)===s&&(Gt===4||Gt===3&&(on&130023424)===on&&500>Lt()-sv?Hi(e,0):nv|=s),On(e,t)}function US(e,t){t===0&&(e.mode&1?(t=Gc,Gc<<=1,!(Gc&130023424)&&(Gc=4194304)):t=1);var s=Nn();e=Ir(e,t),e!==null&&(pc(e,t,s),On(e,s))}function n2(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),US(e,s)}function s2(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(de(314))}r!==null&&r.delete(t),US(e,s)}var BS;BS=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Mn.current)Pn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Pn=!1,HP(e,t,s);Pn=!!(e.flags&131072)}else Pn=!1,St&&t.flags&1048576&&VN(t,md,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;_u(e,t),e=t.pendingProps;var i=el(t,vn.current);Ka(t,s),i=Qx(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,Dn(r)?(a=!0,hd(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Kx(t),i.updater=ch,t.stateNode=i,i._reactInternals=t,wp(t,r,e,s),t=kp(null,t,r,!0,a,s)):(t.tag=0,St&&a&&_x(t),bn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(_u(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=i2(r),e=Cs(r,e),i){case 0:t=bp(null,t,r,e,s);break e;case 1:t=Oy(null,t,r,e,s);break e;case 11:t=My(null,t,r,e,s);break e;case 14:t=Dy(null,t,r,Cs(r.type,e),s);break e}throw Error(de(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Cs(r,i),bp(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Cs(r,i),Oy(e,t,r,i,s);case 3:e:{if(SS(t),e===null)throw Error(de(387));r=t.pendingProps,a=t.memoizedState,i=a.element,JN(e,t),xd(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=rl(Error(de(423)),t),t=Ly(e,t,r,s,i);break e}else if(r!==i){i=rl(Error(de(424)),t),t=Ly(e,t,r,s,i);break e}else for(Gn=si(t.stateNode.containerInfo.firstChild),qn=t,St=!0,As=null,s=QN(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(tl(),r===i){t=Pr(e,t,s);break e}bn(e,t,r,s)}t=t.child}return t;case 5:return ZN(t),e===null&&xp(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,hp(r,i)?l=null:a!==null&&hp(r,a)&&(t.flags|=32),NS(e,t),bn(e,t,l,s),t.child;case 6:return e===null&&xp(t),null;case 13:return CS(e,t,s);case 4:return Vx(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=nl(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:Cs(r,i),My(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,wt(pd,r._currentValue),r._currentValue=l,a!==null)if(Ds(a.value,l)){if(a.children===i.children&&!Mn.current){t=Pr(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=Sr(-1,s&-s),c.tag=2;var u=a.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?c.next=c:(c.next=d.next,d.next=c),u.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),vp(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(de(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),vp(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,Ka(t,s),i=xs(i),r=r(i),t.flags|=1,bn(e,t,r,s),t.child;case 14:return r=t.type,i=Cs(r,t.pendingProps),i=Cs(r.type,i),Dy(e,t,r,i,s);case 15:return bS(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Cs(r,i),_u(e,t),t.tag=1,Dn(r)?(e=!0,hd(t)):e=!1,Ka(t,s),jS(t,r,i),wp(t,r,i,s),kp(null,t,r,!0,e,s);case 19:return ES(e,t,s);case 22:return kS(e,t,s)}throw Error(de(156,t.tag))};function WS(e,t){return gN(e,t)}function r2(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 ms(e,t,s,r){return new r2(e,t,s,r)}function lv(e){return e=e.prototype,!(!e||!e.isReactComponent)}function i2(e){if(typeof e=="function")return lv(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Cx)return 11;if(e===Ex)return 14}return 2}function li(e,t){var s=e.alternate;return s===null?(s=ms(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 Uu(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")lv(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Ca:return Ki(s.children,i,a,t);case Sx:l=8,i|=8;break;case Hm:return e=ms(12,s,t,i|2),e.elementType=Hm,e.lanes=a,e;case Km:return e=ms(13,s,t,i),e.elementType=Km,e.lanes=a,e;case Vm:return e=ms(19,s,t,i),e.elementType=Vm,e.lanes=a,e;case Z0:return hh(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case X0:l=10;break e;case J0:l=9;break e;case Cx:l=11;break e;case Ex:l=14;break e;case Vr:l=16,r=null;break e}throw Error(de(130,e==null?e:typeof e,""))}return t=ms(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function Ki(e,t,s,r){return e=ms(7,e,r,t),e.lanes=s,e}function hh(e,t,s,r){return e=ms(22,e,r,t),e.elementType=Z0,e.lanes=s,e.stateNode={isHidden:!1},e}function zf(e,t,s){return e=ms(6,e,null,t),e.lanes=s,e}function Uf(e,t,s){return t=ms(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function a2(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=yf(0),this.expirationTimes=yf(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=yf(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function ov(e,t,s,r,i,a,l,o,c){return e=new a2(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=ms(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Kx(a),e}function l2(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Sa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function HS(e){if(!e)return hi;e=e._reactInternals;e:{if(ra(e)!==e||e.tag!==1)throw Error(de(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Dn(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(de(171))}if(e.tag===1){var s=e.type;if(Dn(s))return HN(e,s,t)}return t}function KS(e,t,s,r,i,a,l,o,c){return e=ov(s,r,!0,e,i,a,l,o,c),e.context=HS(null),s=e.current,r=Nn(),i=ai(s),a=Sr(r,i),a.callback=t??null,ri(s,a,i),e.current.lanes=i,pc(e,i,r),On(e,r),e}function fh(e,t,s,r){var i=t.current,a=Nn(),l=ai(i);return s=HS(s),t.context===null?t.context=s:t.pendingContext=s,t=Sr(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=ri(i,t,l),e!==null&&($s(e,i,l,a),Du(e,i,l)),l}function Sd(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 Gy(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function cv(e,t){Gy(e,t),(e=e.alternate)&&Gy(e,t)}function o2(){return null}var VS=typeof reportError=="function"?reportError:function(e){console.error(e)};function uv(e){this._internalRoot=e}mh.prototype.render=uv.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(de(409));fh(e,t,null,null)};mh.prototype.unmount=uv.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Ji(function(){fh(null,e,null,null)}),t[$r]=null}};function mh(e){this._internalRoot=e}mh.prototype.unstable_scheduleHydration=function(e){if(e){var t=kN();e={blockedOn:null,target:e,priority:t};for(var s=0;s<Yr.length&&t!==0&&t<Yr[s].priority;s++);Yr.splice(s,0,e),s===0&&SN(e)}};function dv(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function ph(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Yy(){}function c2(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Sd(l);a.call(u)}}var l=KS(t,r,e,0,null,!1,!1,"",Yy);return e._reactRootContainer=l,e[$r]=l.current,Do(e.nodeType===8?e.parentNode:e),Ji(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Sd(c);o.call(u)}}var c=ov(e,0,!1,null,null,!1,!1,"",Yy);return e._reactRootContainer=c,e[$r]=c.current,Do(e.nodeType===8?e.parentNode:e),Ji(function(){fh(t,c,s,r)}),c}function gh(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=Sd(l);o.call(c)}}fh(t,l,e,i)}else l=c2(s,t,e,i,r);return Sd(l)}yN=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=lo(t.pendingLanes);s!==0&&(Rx(t,s|1),On(t,Lt()),!(at&6)&&(il=Lt()+500,ki()))}break;case 13:Ji(function(){var r=Ir(e,1);if(r!==null){var i=Nn();$s(r,e,1,i)}}),cv(e,1)}};$x=function(e){if(e.tag===13){var t=Ir(e,134217728);if(t!==null){var s=Nn();$s(t,e,134217728,s)}cv(e,134217728)}};bN=function(e){if(e.tag===13){var t=ai(e),s=Ir(e,t);if(s!==null){var r=Nn();$s(s,e,t,r)}cv(e,t)}};kN=function(){return mt};NN=function(e,t){var s=mt;try{return mt=e,t()}finally{mt=s}};np=function(e,t,s){switch(t){case"input":if(qm(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=ah(r);if(!i)throw Error(de(90));tN(r),qm(r,i)}}}break;case"textarea":sN(e,s);break;case"select":t=s.value,t!=null&&Ua(e,!!s.multiple,t,!1)}};uN=rv;dN=Ji;var u2={usingClientEntryPoint:!1,Events:[xc,Ra,ah,oN,cN,rv]},Ql={findFiberByHostInstance:Fi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},d2={bundleType:Ql.bundleType,version:Ql.version,rendererPackageName:Ql.rendererPackageName,rendererConfig:Ql.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:zr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=mN(e),e===null?null:e.stateNode},findFiberByHostInstance:Ql.findFiberByHostInstance||o2,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 ru=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!ru.isDisabled&&ru.supportsFiber)try{nh=ru.inject(d2),nr=ru}catch{}}es.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=u2;es.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!dv(t))throw Error(de(200));return l2(e,t,null,s)};es.createRoot=function(e,t){if(!dv(e))throw Error(de(299));var s=!1,r="",i=VS;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=ov(e,1,!1,null,null,s,!1,r,i),e[$r]=t.current,Do(e.nodeType===8?e.parentNode:e),new uv(t)};es.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(de(188)):(e=Object.keys(e).join(","),Error(de(268,e)));return e=mN(t),e=e===null?null:e.stateNode,e};es.flushSync=function(e){return Ji(e)};es.hydrate=function(e,t,s){if(!ph(t))throw Error(de(200));return gh(null,e,t,!0,s)};es.hydrateRoot=function(e,t,s){if(!dv(e))throw Error(de(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=VS;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=KS(t,null,e,1,s??null,i,!1,a,l),e[$r]=t.current,Do(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 mh(t)};es.render=function(e,t,s){if(!ph(t))throw Error(de(200));return gh(null,e,t,!1,s)};es.unmountComponentAtNode=function(e){if(!ph(e))throw Error(de(40));return e._reactRootContainer?(Ji(function(){gh(null,null,e,!1,function(){e._reactRootContainer=null,e[$r]=null})}),!0):!1};es.unstable_batchedUpdates=rv;es.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!ph(s))throw Error(de(200));if(e==null||e._reactInternals===void 0)throw Error(de(38));return gh(e,t,s,!1,r)};es.version="18.3.1-next-f1338f8080-20240426";function GS(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(GS)}catch(e){console.error(e)}}GS(),G0.exports=es;var wl=G0.exports,YS,qy=wl;YS=qy.createRoot,qy.hydrateRoot;var h2=Object.defineProperty,yl=(e,t)=>h2(e,"name",{value:t,configurable:!0}),qS=!!(typeof window<"u"&&window.document&&window.document.createElement);function Pe(e,t,{checkForDefaultPrevented:s=!0}={}){return yl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}yl(Pe,"composeEventHandlers");function f2(e){var t;if(!qS)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}yl(f2,"getOwnerWindow");function Dp(e){if(!qS)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}yl(Dp,"getOwnerDocument");function QS(e,t=!1){const{activeElement:s}=Dp(e);if(!(s!=null&&s.nodeName))return null;if(XS(s)&&s.contentDocument)return QS(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=Dp(s).getElementById(r);if(i)return i}}return s}yl(QS,"getActiveElement");function XS(e){return e.tagName==="IFRAME"}yl(XS,"isFrame");var m2=Object.defineProperty,hv=(e,t)=>m2(e,"name",{value:t,configurable:!0});function Op(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}hv(Op,"setRef");function JS(...e){return t=>{let s=!1;const r=e.map(i=>{const a=Op(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():Op(e[i],null)}}}}hv(JS,"composeRefs");function vt(...e){return h.useCallback(JS(...e),e)}hv(vt,"useComposedRefs");var p2=Object.defineProperty,fs=(e,t)=>p2(e,"name",{value:t,configurable:!0});function g2(e,t){const s=h.createContext(t);s.displayName=e+"Context";const r=fs(a=>{const{children:l,...o}=a,c=h.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=h.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return fs(i,"useContext"),[r,i]}fs(g2,"createContext");function Fs(e,t=[]){let s=[];function r(a,l){const o=h.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=fs(f=>{var j;const{scope:m,children:p,...g}=f,x=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=h.useMemo(()=>g,Object.values(g));return n.jsx(x.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function d(f,m,p={}){var j;const{optional:g=!1}=p,x=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=h.useContext(x);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${a}\``)}return fs(d,"useContext"),[u,d]}fs(r,"createContext");const i=fs(()=>{const a=s.map(l=>h.createContext(l));return fs(function(o){const c=(o==null?void 0:o[e])||a;return h.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,ZS(i,...t)]}fs(Fs,"createContextScope");function ZS(...e){const t=e[0];if(e.length===1)return t;const s=fs(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return fs(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...o,...f}},{});return h.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}fs(ZS,"composeContextScopes");var x2=Object.defineProperty,zs=(e,t)=>x2(e,"name",{value:t,configurable:!0});function fi(e){const t=h.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];Lp(i)&&typeof iu=="function"&&(i=iu(i._payload)),h.Children.forEach(i,m=>{var p;if(rC(m)){o=!0;const g=m;let x="child"in g.props?g.props.child:g.props.children;Lp(x)&&typeof iu=="function"&&(x=iu(x._payload)),l=v2(g,x),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=h.cloneElement(l,void 0,c):!o&&h.Children.count(i)===1&&h.isValidElement(i)&&(l=i);const u=l?sC(l):void 0,d=vt(r,u);if(!l){if(i||i===0)throw new Error(o?y2(e):w2(e));return i}const f=nC(a,l.props??{});return l.type!==h.Fragment&&(f.ref=r?d:u),h.cloneElement(l,f)});return t.displayName=`${e}.Slot`,t}zs(fi,"createSlot");var eC=Symbol.for("radix.slottable");function tC(e){const t=zs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=eC,t}zs(tC,"createSlottable");var v2=zs((e,t)=>{if("child"in e.props){const s=e.props.child;return h.isValidElement(s)?h.cloneElement(s,void 0,e.props.children(s.props.children)):null}return h.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function nC(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}}zs(nC,"mergeProps");function sC(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)}zs(sC,"getElementRef");function rC(e){return h.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===eC}zs(rC,"isSlottable");var j2=Symbol.for("react.lazy");function Lp(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===j2&&"_payload"in e&&iC(e._payload)}zs(Lp,"isLazyComponent");function iC(e){return typeof e=="object"&&e!==null&&"then"in e}zs(iC,"isPromiseLike");var w2=zs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),y2=zs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),iu=xl[" use ".trim().toString()],b2=Object.defineProperty,Jt=(e,t)=>b2(e,"name",{value:t,configurable:!0});function xh(e){const t=e+"CollectionProvider",[s,r]=Fs(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=Jt(x=>{const{scope:b,children:j}=x,v=h.useRef(null),w=h.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:w,collectionRef:v,children:j})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=fi(o),u=h.forwardRef((x,b)=>{const{scope:j,children:v}=x,w=a(o,j),y=vt(b,w.collectionRef);return n.jsx(c,{ref:y,children:v})});u.displayName=o;const d=e+"CollectionItemSlot",f="data-radix-collection-item",m=fi(d),p=h.forwardRef((x,b)=>{const{scope:j,children:v,...w}=x,y=h.useRef(null),N=vt(b,y),k=a(d,j);return h.useEffect(()=>(k.itemMap.set(y,{ref:y,...w}),()=>void k.itemMap.delete(y))),n.jsx(m,{[f]:"",ref:N,children:v})});p.displayName=d;function g(x){const b=a(e+"CollectionConsumer",x);return h.useCallback(()=>{const v=b.collectionRef.current;if(!v)return[];const w=Array.from(v.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((k,S)=>w.indexOf(k.ref.current)-w.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return Jt(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}Jt(xh,"createCollection");var Qy=new WeakMap,Ft,Vn,Bf=(Vn=class extends Map{constructor(s){super(s);zw(this,Ft);pf(this,Ft,[...super.keys()]),Qy.set(this,!0)}set(s,r){return Qy.get(this)&&(this.has(s)?fn(this,Ft)[fn(this,Ft).indexOf(s)]=s:fn(this,Ft).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=fn(this,Ft).length,o=fv(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 d=this.size+(a?0:1);o<0&&c++;const f=[...fn(this,Ft)];let m,p=!1;for(let g=c;g<d;g++)if(c===g){let x=f[g];f[g]===r&&(x=f[g+1]),a&&this.delete(r),m=this.get(x),this.set(r,i)}else{!p&&f[g-1]===r&&(p=!0);const x=f[p?g:g-1],b=m;m=this.get(x),this.delete(x),this.set(x,b)}return this}with(s,r,i){const a=new Vn(this);return a.insert(s,r,i),a}before(s){const r=fn(this,Ft).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=fn(this,Ft).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=fn(this,Ft).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=fn(this,Ft).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return pf(this,Ft,[]),super.clear()}delete(s){const r=super.delete(s);return r&&fn(this,Ft).splice(fn(this,Ft).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=Bu(fn(this,Ft),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=Bu(fn(this,Ft),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return fn(this,Ft).indexOf(s)}keyAt(s){return Bu(fn(this,Ft),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 Vn(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 Vn(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 Vn(r)}toReversed(){const s=new Vn;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 Vn(r)}slice(s,r){const i=new Vn;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}},Ft=new WeakMap,Jt(Vn,"OrderedDict"),Vn);function Bu(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=aC(e,t);return s===-1?void 0:e[s]}Jt(Bu,"at");function aC(e,t){const s=e.length,r=fv(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}Jt(aC,"toSafeIndex");function fv(e){return e!==e||e===0?0:Math.trunc(e)}Jt(fv,"toSafeInteger");function k2(e){const t=e+"CollectionProvider",[s,r]=Fs(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Bf,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:N,state:k}=w,S=h.useRef(null),[C,$]=h.useState(null),R=vt(S,$),[I,U]=k;return h.useEffect(()=>{if(!C)return;const z=cC(()=>{});return z.observe(C,{childList:!0,subtree:!0}),()=>{z.disconnect()}},[C]),n.jsx(i,{scope:y,itemMap:I,setItemMap:U,collectionRef:R,collectionRefObject:S,collectionElement:C,children:N})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",d=fi(u),f=h.forwardRef((w,y)=>{const{scope:N,children:k}=w,S=a(u,N),C=vt(y,S.collectionRef);return n.jsx(d,{ref:C,children:k})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=fi(m),x=h.forwardRef((w,y)=>{const{scope:N,children:k,...S}=w,C=h.useRef(null),[$,R]=h.useState(null),I=vt(y,C,R),U=a(m,N),{setItemMap:z}=U,A=h.useRef(S);lC(A.current,S)||(A.current=S);const P=A.current;return h.useEffect(()=>{const D=P;return z(O=>$?O.has($)?O.set($,{...D,element:$}).toSorted(_p):(O.set($,{...D,element:$}),O.toSorted(_p)):O),()=>{z(O=>!$||!O.has($)?O:(O.delete($),new Bf(O)))}},[$,P,z]),n.jsx(g,{[p]:"",ref:I,children:k})});x.displayName=m;function b(){return h.useState(new Bf)}Jt(b,"useInitCollection");function j(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return Jt(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:x},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}Jt(k2,"createCollection");function lC(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(lC,"shallowEqual");function oC(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Jt(oC,"isElementPreceding");function _p(e,t){return!e[1].element||!t[1].element?0:oC(e[1].element,t[1].element)?-1:1}Jt(_p,"sortByDocumentPosition");function cC(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Jt(cC,"getChildListObserver");var N2=Object.defineProperty,S2=(e,t)=>N2(e,"name",{value:t,configurable:!0}),C2=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],pt=C2.reduce((e,t)=>{const s=fi(`Primitive.${t}`),r=h.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 vh(e,t){e&&wl.flushSync(()=>e.dispatchEvent(t))}S2(vh,"dispatchDiscreteCustomEvent");var E2=Object.defineProperty,A2=(e,t)=>E2(e,"name",{value:t,configurable:!0});function Sn(e){const t=h.useRef(e);return h.useEffect(()=>{t.current=e}),h.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}A2(Sn,"useCallbackRef");var T2=Object.defineProperty,Kt=(e,t)=>T2(e,"name",{value:t,configurable:!0}),Fp="dismissableLayer.update",R2="dismissableLayer.pointerDownOutside",$2="dismissableLayer.focusOutside",Xy,mv=h.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),jh=h.forwardRef(Kt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...d}=t,f=h.useContext(mv),[m,p]=h.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=h.useState({}),b=vt(s,p),j=Array.from(f.layers),[v]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=v?j.indexOf(v):-1,y=m?j.indexOf(m):-1,N=f.layersWithOutsidePointerEventsDisabled.size>0,k=y>=w,S=h.useRef(!1),C=dC(U=>{l==null||l(U),c==null||c(U),U.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:h.useCallback(U=>{if(!(U instanceof Node))return!1;const z=[...f.branches].some(A=>A.contains(U));return k&&!z},[f.branches,k])}),$=hC(U=>{if(i&&S.current)return;const z=U.target;[...f.branches].some(P=>P.contains(z))||(o==null||o(U),c==null||c(U),U.defaultPrevented||u==null||u())},g),R=m?y===j.length-1:!1,I=Sn(U=>{U.key==="Escape"&&(a==null||a(U),!U.defaultPrevented&&u&&(U.preventDefault(),u()))});return h.useEffect(()=>{if(R)return g.addEventListener("keydown",I,{capture:!0}),()=>g.removeEventListener("keydown",I,{capture:!0})},[g,R,I]),h.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Xy=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),zp(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Xy))}},[m,g,r,f]),h.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),zp())},[m,f]),h.useEffect(()=>{const U=Kt(()=>x({}),"handleUpdate");return document.addEventListener(Fp,U),()=>document.removeEventListener(Fp,U)},[]),n.jsx(pt.div,{...d,ref:b,style:{pointerEvents:N?k?"auto":"none":void 0,...t.style},onFocusCapture:Pe(t.onFocusCapture,$.onFocusCapture),onBlurCapture:Pe(t.onBlurCapture,$.onBlurCapture),onPointerDownCapture:Pe(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),I2=h.forwardRef(Kt(function(t,s){const r=h.useContext(mv),i=h.useRef(null),a=vt(s,i);return h.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(pt.div,{...t,ref:a})},"DismissableLayerBranch"));function uC(){const e=h.useContext(mv),[t,s]=h.useState(null);return h.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Kt(uC,"useDismissableLayerSurface");var P2=Kt(()=>!0,"IS_TRUE");function dC(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=P2}=t,o=Sn(e),c=h.useRef(!1),u=h.useRef(!1),d=h.useRef(new Map),f=h.useRef(()=>{});return h.useEffect(()=>{function m(){u.current=!1,i.current=!1,d.current.clear()}Kt(m,"resetOutsideInteraction");function p(){return Array.from(d.current.values()).some(Boolean)}Kt(p,"isOutsideInteractionIntercepted");function g(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...a].some(k=>k.contains(y))||d.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}Kt(g,"handleInteractionCapture");function x(w){u.current&&d.current.set(w.type,!1)}Kt(x,"handleInteractionBubble");const b=Kt(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",f.current);const k=p();m(),k||pv(R2,o,N,{discrete:!0})};if(Kt(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const N={originalEvent:w};u.current=!0,i.current=r&&w.button===0,d.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,x);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",b),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,g,!0),s.removeEventListener(w,x)}},[s,o,r,i,a,l]),{onPointerDownCapture:Kt(()=>c.current=!0,"onPointerDownCapture")}}Kt(dC,"usePointerDownOutside");function hC(e,t=globalThis==null?void 0:globalThis.document){const s=Sn(e),r=h.useRef(!1);return h.useEffect(()=>{const i=Kt(a=>{a.target&&!r.current&&pv($2,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(hC,"useFocusOutside");function zp(){const e=new CustomEvent(Fp);document.dispatchEvent(e)}Kt(zp,"dispatchUpdate");function pv(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?vh(i,a):i.dispatchEvent(a)}Kt(pv,"handleAndDispatchCustomEvent");var M2=jh,D2=I2,Ln=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},O2=Object.defineProperty,L2=(e,t)=>O2(e,"name",{value:t,configurable:!0}),wh=h.forwardRef(L2(function(t,s){var c;const{container:r,...i}=t,[a,l]=h.useState(!1);Ln(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?wl.createPortal(n.jsx(pt.div,{...i,ref:s}),o):null},"Portal")),_2=Object.defineProperty,Mr=(e,t)=>_2(e,"name",{value:t,configurable:!0});function fC(e,t){return h.useReducer((s,r)=>t[s][r]??s,e)}Mr(fC,"useStateMachine");var ur=Mr(e=>{const{present:t,children:s}=e,r=mC(t),i=typeof s=="function"?s({present:r.isPresent}):h.Children.only(s),a=pC(r.ref,gC(i));return typeof s=="function"||r.isPresent?h.cloneElement(i,{ref:a}):null},"Presence");function mC(e){const[t,s]=h.useState(),r=h.useRef(null),i=h.useRef(e),a=h.useRef("none"),l=h.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=fC(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{c==="mounted"?(a.current=l.current??Na(r.current),l.current=void 0):a.current="none"},[c]),Ln(()=>{const d=r.current,f=i.current;if(f!==e){const p=a.current,g=Na(d);e?(l.current=g,u("MOUNT")):g==="none"||(d==null?void 0:d.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Ln(()=>{if(t){let d;const f=t.ownerDocument.defaultView??window,m=Mr(g=>{const b=Na(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",d=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},"handleAnimationEnd"),p=Mr(g=>{g.target===t&&(a.current=Na(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(d),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:h.useCallback(d=>{if(d){const f=getComputedStyle(d);r.current=f,l.current=Na(f)}else r.current=null;s(d)},[])}}Mr(mC,"usePresence");function Up(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Mr(Up,"setRef");function pC(...e){const t=h.useRef(e);return t.current=e,h.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=Up(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():Up(r[l],null)}}},[])}Mr(pC,"useStableComposedRefs");function Na(e){return(e==null?void 0:e.animationName)||"none"}Mr(Na,"getAnimationName");function gC(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)}Mr(gC,"getElementRef");var F2=Object.defineProperty,z2=(e,t)=>F2(e,"name",{value:t,configurable:!0}),Jy=xl[" useEffectEvent ".trim().toString()],Zy=xl[" useInsertionEffect ".trim().toString()];function xC(e){if(typeof Jy=="function")return Jy(e);const t=h.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof Zy=="function"?Zy(()=>{t.current=e}):Ln(()=>{t.current=e}),h.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}z2(xC,"useEffectEvent");var U2=Object.defineProperty,jc=(e,t)=>U2(e,"name",{value:t,configurable:!0}),B2=xl[" useInsertionEffect ".trim().toString()]||Ln;function Ni({prop:e,defaultProp:t,onChange:s=jc(()=>{},"onChange"),caller:r}){const[i,a,l]=vC({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=h.useCallback(d=>{var f;if(o){const m=jC(d)?d(e):d;m!==e&&((f=l.current)==null||f.call(l,m))}else a(d)},[o,e,a,l]);return[c,u]}jc(Ni,"useControllableState");function vC({defaultProp:e,onChange:t}){const[s,r]=h.useState(e),i=h.useRef(s),a=h.useRef(t);return B2(()=>{a.current=t},[t]),h.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}jc(vC,"useUncontrolledState");function jC(e){return typeof e=="function"}jc(jC,"isFunction");var eb=Symbol("RADIX:SYNC_STATE");function W2(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=xC(l),d=[{...s,state:a}];r&&d.push(r);const[f,m]=h.useReducer((b,j)=>{if(j.type===eb)return{...b,state:j.state};const v=e(b,j);return c&&!Object.is(v.state,b.state)&&u(v.state),v},...d),p=f.state,g=h.useRef(p);h.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const x=h.useMemo(()=>i!==void 0?{...f,state:i}:f,[f,i]);return h.useEffect(()=>{c&&!Object.is(i,f.state)&&m({type:eb,state:i})},[i,f.state,c]),[x,m]}jc(W2,"useControllableStateReducer");var H2=Object.defineProperty,K2=(e,t)=>H2(e,"name",{value:t,configurable:!0}),V2=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"}),gv=h.forwardRef(K2(function(t,s){return n.jsx(pt.span,{...t,ref:s,style:{...V2,...t.style}})},"VisuallyHidden")),G2=gv,Y2=Object.defineProperty,gt=(e,t)=>Y2(e,"name",{value:t,configurable:!0}),wC="ToastProvider",[xv,yC,q2]=xh("Toast"),[bC,gQ]=Fs("Toast",[q2]),[Q2,yh]=bC(wC),X2=gt(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=h.useState(null),[d,f]=h.useState(0),m=h.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${wC}\`. Expected non-empty \`string\`.`),n.jsx(xv.Provider,{scope:t,children:n.jsx(Q2,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:d,viewport:c,onViewportChange:u,onToastAdd:h.useCallback(()=>f(p=>p+1),[]),onToastRemove:h.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),J2="ToastViewport",Z2=["F8"],Bp="toast.viewportPause",Wp="toast.viewportResume",eM=h.forwardRef(gt(function(t,s){const{__scopeToast:r,hotkey:i=Z2,label:a="Notifications ({hotkey})",...l}=t,o=yh(J2,r),c=yC(r),u=h.useRef(null),d=h.useRef(null),f=h.useRef(null),m=h.useRef(null),p=vt(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),x=o.toastCount>0;h.useEffect(()=>{const j=gt(v=>{var y;i.length!==0&&i.every(N=>v[N]||v.code===N)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[i]),h.useEffect(()=>{const j=u.current,v=m.current;if(x&&j&&v){const w=gt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(Bp);v.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=gt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(Wp);v.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),N=gt(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),k=gt(()=>{j.contains(document.activeElement)||y()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",N),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",k),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",N),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",k),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[x,o.isClosePausedRef]);const b=h.useCallback(({tabbingDirection:j})=>{const w=c().map(y=>{const N=y.ref.current,k=[N,...CC(N)];return j==="forwards"?k:k.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return h.useEffect(()=>{const j=m.current;if(j){const v=gt(w=>{var k,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){(k=d.current)==null||k.focus();return}const z=b({tabbingDirection:R?"backwards":"forwards"}),A=z.findIndex(P=>P===$);Wu(z.slice(A+1))?w.preventDefault():R?(S=d.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",v),()=>j.removeEventListener("keydown",v)}},[c,b]),n.jsxs(D2,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:x?void 0:"none"},children:[x&&n.jsx(tb,{ref:d,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});Wu(j)}}),n.jsx(xv.Slot,{scope:r,children:n.jsx(pt.ol,{tabIndex:-1,...l,ref:p})}),x&&n.jsx(tb,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});Wu(j)}})]})},"ToastViewport")),tM="ToastFocusProxy",tb=h.forwardRef(gt(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=yh(tM,r);return n.jsx(gv,{tabIndex:0,...a,ref:s,style:{position:"fixed"},onFocus:o=>{var d;const c=o.relatedTarget;!((d=l.viewport)!=null&&d.contains(c))&&i()}})},"ToastFocusProxy")),bh="Toast",nM="toast.swipeStart",sM="toast.swipeMove",rM="toast.swipeCancel",iM="toast.swipeEnd",aM=h.forwardRef(gt(function(t,s){const{forceMount:r,open:i,defaultOpen:a,onOpenChange:l,...o}=t,[c,u]=Ni({prop:i,defaultProp:a??!0,onChange:l,caller:bh});return n.jsx(ur,{present:r||c,children:n.jsx(cM,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Sn(t.onPause),onResume:Sn(t.onResume),onSwipeStart:Pe(t.onSwipeStart,d=>{d.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Pe(t.onSwipeMove,d=>{const{x:f,y:m}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","move"),d.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:Pe(t.onSwipeCancel,d=>{d.currentTarget.setAttribute("data-swipe","cancel"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Pe(t.onSwipeEnd,d=>{const{x:f,y:m}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","end"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[lM,oM]=bC(bh,{onClose(){}}),cM=h.forwardRef(gt(function(t,s){const{__scopeToast:r,type:i="foreground",duration:a,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:d,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...x}=t,b=yh(bh,r),j=yC(r),[v,w]=h.useState(null),y=vt(s,w),N=h.useRef(null),k=h.useRef(null),S=a||b.duration,C=h.useRef(0),$=h.useRef(S),R=h.useRef(0),{onToastAdd:I,onToastRemove:U}=b,z=Sn(()=>{var O;(v==null?void 0:v.contains(document.activeElement))&&((O=b.viewport)==null||O.focus()),o()}),A=h.useCallback(D=>{!D||D===1/0||(window.clearTimeout(R.current),C.current=new Date().getTime(),R.current=window.setTimeout(z,D))},[z]);h.useEffect(()=>{const D=b.viewport;if(D){const O=gt(()=>{A($.current),d==null||d()},"handleResume"),M=gt(()=>{const W=new Date().getTime()-C.current;$.current=$.current-W,window.clearTimeout(R.current),u==null||u()},"handlePause");return D.addEventListener(Bp,M),D.addEventListener(Wp,O),()=>{D.removeEventListener(Bp,M),D.removeEventListener(Wp,O)}}},[b.viewport,S,u,d,A]),h.useEffect(()=>{l&&!b.isClosePausedRef.current&&A(S)},[l,S,b.isClosePausedRef,A]),h.useEffect(()=>()=>{window.clearTimeout(R.current)},[]),h.useEffect(()=>(I(),()=>U()),[I,U]);const P=h.useMemo(()=>v?vv(v):null,[v]);return b.viewport?n.jsxs(n.Fragment,{children:[P&&n.jsx(uM,{__scopeToast:r,role:"status","aria-live":i==="foreground"?"assertive":"polite",children:P}),n.jsx(lM,{scope:r,onClose:z,children:wl.createPortal(n.jsx(xv.ItemSlot,{scope:r,children:n.jsx(M2,{asChild:!0,onEscapeKeyDown:Pe(c,D=>{j().some(M=>{var W;return(W=M.ref.current)==null?void 0:W.contains(D.target)})||z()}),children:n.jsx(pt.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":b.swipeDirection,...x,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:Pe(t.onKeyDown,D=>{D.key==="Escape"&&(c==null||c(D.nativeEvent),D.nativeEvent.defaultPrevented||z())}),onPointerDown:Pe(t.onPointerDown,D=>{D.button===0&&(N.current={x:D.clientX,y:D.clientY})}),onPointerMove:Pe(t.onPointerMove,D=>{if(!N.current)return;const O=D.clientX-N.current.x,M=D.clientY-N.current.y,W=!!k.current,L=["left","right"].includes(b.swipeDirection),q=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,B=L?q(0,O):0,V=L?0:q(0,M),F=D.pointerType==="touch"?10:2,X={x:B,y:V},Y={originalEvent:D,delta:X};W?(k.current=X,co(sM,m,Y,{discrete:!1})):nb(X,b.swipeDirection,F)?(k.current=X,co(nM,f,Y,{discrete:!1}),D.target.setPointerCapture(D.pointerId)):(Math.abs(O)>F||Math.abs(M)>F)&&(N.current=null)}),onPointerUp:Pe(t.onPointerUp,D=>{const O=k.current,M=D.target;if(M.hasPointerCapture(D.pointerId)&&M.releasePointerCapture(D.pointerId),k.current=null,N.current=null,O){const W=D.currentTarget,L={originalEvent:D,delta:O};nb(O,b.swipeDirection,b.swipeThreshold)?co(iM,g,L,{discrete:!0}):co(rM,p,L,{discrete:!0}),W.addEventListener("click",q=>q.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),uM=gt(e=>{const{__scopeToast:t,children:s,...r}=e,i=yh(bh,t),[a,l]=h.useState(!1),[o,c]=h.useState(!1);return NC(()=>l(!0)),h.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:n.jsx(wh,{asChild:!0,container:i.announcerContainer||void 0,children:n.jsx(gv,{...r,children:a&&n.jsxs(n.Fragment,{children:[i.label," ",s]})})})},"ToastAnnounce"),dM=h.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(pt.div,{...i,ref:s})},"ToastTitle")),hM=h.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(pt.div,{...i,ref:s})},"ToastDescription")),fM="ToastAction",mM=h.forwardRef(gt(function(t,s){const{altText:r,...i}=t;return r.trim()?n.jsx(kC,{altText:r,asChild:!0,children:n.jsx(gM,{...i,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${fM}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),pM="ToastClose",gM=h.forwardRef(gt(function(t,s){const{__scopeToast:r,...i}=t,a=oM(pM,r);return n.jsx(kC,{asChild:!0,children:n.jsx(pt.button,{type:"button",...i,ref:s,onClick:Pe(t.onClick,a.onClose)})})},"ToastClose")),kC=h.forwardRef(gt(function(t,s){const{__scopeToast:r,altText:i,...a}=t;return n.jsx(pt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":i||void 0,...a,ref:s})},"ToastAnnounceExclude"));function vv(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),SC(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(...vv(r))}}),t}gt(vv,"getAnnounceTextContent");function co(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?vh(i,a):i.dispatchEvent(a)}gt(co,"handleAndDispatchCustomEvent");var nb=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 NC(e=()=>{}){const t=Sn(e);Ln(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}gt(NC,"useNextFrame");function SC(e){return e.nodeType===e.ELEMENT_NODE}gt(SC,"isHTMLElement");function CC(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(CC,"getTabbableCandidates");function Wu(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}gt(Wu,"focusFirst");var sb=X2,rb=eM,xM=aM,vM=dM,jM=hM,wM=mM,yM=Object.defineProperty,bM=(e,t)=>yM(e,"name",{value:t,configurable:!0}),kM=xl[" useId ".trim().toString()]||(()=>{}),NM=0;function Is(e){const[t,s]=h.useState(kM());return Ln(()=>{e||s(r=>r??String(NM++))},[e]),e||(t?`radix-${t}`:"")}bM(Is,"useId");const SM=["top","right","bottom","left"],mi=Math.min,Cr=Math.max,Cd=Math.round,au=Math.floor,Er=e=>({x:e,y:e}),CM={left:"right",right:"left",bottom:"top",top:"bottom"};function EC(e,t,s){return Cr(e,mi(t,s))}function Dr(e,t){return typeof e=="function"?e(t):e}function pi(e){return e.split("-")[0]}function bl(e){return e.split("-")[1]}function jv(e){return e==="x"?"y":"x"}function wv(e){return e==="y"?"height":"width"}function er(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function yv(e){return jv(er(e))}function EM(e,t,s){s===void 0&&(s=!1);const r=bl(e),i=yv(e),a=wv(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Ed(l)),[l,Ed(l)]}function AM(e){const t=Ed(e);return[Hp(e),t,Hp(t)]}function Hp(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const ib=["left","right"],ab=["right","left"],TM=["top","bottom"],RM=["bottom","top"];function $M(e,t,s){switch(e){case"top":case"bottom":return s?t?ab:ib:t?ib:ab;case"left":case"right":return t?TM:RM;default:return[]}}function IM(e,t,s,r){const i=bl(e);let a=$M(pi(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(Hp)))),a}function Ed(e){const t=pi(e);return CM[t]+e.slice(t.length)}function PM(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 AC(e){return typeof e!="number"?PM(e):{top:e,right:e,bottom:e,left:e}}function Ad(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 lb(e,t,s){let{reference:r,floating:i}=e;const a=er(t),l=yv(t),o=wv(l),c=pi(t),u=a==="y",d=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:d,y:r.y-i.height};break;case"bottom":p={x:d,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=bl(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function MM(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:d="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=Dr(t,e),g=AC(p),b=o[m?f==="floating"?"reference":"floating":f],j=Ad(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:d,strategy:c})),v=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},N=Ad(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:w,strategy:c}):v);return{top:(j.top-N.top+g.top)/y.y,bottom:(N.bottom-j.bottom+g.bottom)/y.y,left:(j.left-N.left+g.left)/y.x,right:(N.right-j.right+g.right)/y.x}}const DM=50,OM=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:MM},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:d,y:f}=lb(u,r,c),m=r,p=0;const g={};for(let x=0;x<a.length;x++){const b=a[x];if(!b)continue;const{name:j,fn:v}=b,{x:w,y,data:N,reset:k}=await v({x:d,y:f,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});d=w??d,f=y??f,g[j]={...g[j],...N},k&&p<DM&&(p++,typeof k=="object"&&(k.placement&&(m=k.placement),k.rects&&(u=k.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):k.rects),{x:d,y:f}=lb(u,m,c)),x=-1)}return{x:d,y:f,placement:m,strategy:i,middlewareData:g}},LM=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:d=0}=Dr(e,t)||{};if(u==null)return{};const f=AC(d),m={x:s,y:r},p=yv(i),g=wv(p),x=await l.getDimensions(u),b=p==="y",j=b?"top":"left",v=b?"bottom":"right",w=b?"clientHeight":"clientWidth",y=a.reference[g]+a.reference[p]-m[p]-a.floating[g],N=m[p]-a.reference[p],k=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=k?k[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(k)))&&(S=o.floating[w]||a.floating[g]);const C=y/2-N/2,$=S/2-x[g]/2-1,R=mi(f[j],$),I=mi(f[v],$),U=S-x[g]-I,z=S/2-x[g]/2+C,A=EC(R,z,U),P=!c.arrow&&bl(i)!=null&&z!==A&&a.reference[g]/2-(z<R?R:I)-x[g]/2<0,D=P?z<R?z-R:z-U:0;return{[p]:m[p]+D,data:{[p]:A,centerOffset:z-A-D,...P&&{alignmentOffset:D}},reset:P}}}),_M=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:d=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:x=!0,...b}=Dr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const j=pi(i),v=er(o),w=pi(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),N=m||(w||!x?[Ed(o)]:AM(o)),k=g!=="none";!m&&k&&N.push(...IM(o,x,g,y));const S=[o,...N],C=await c.detectOverflow(t,b),$=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(d&&$.push(C[j]),f){const A=EM(i,l,y);$.push(C[A[0]],C[A[1]])}if(R=[...R,{placement:i,overflows:$}],!$.every(A=>A<=0)){var I,U;const A=(((I=a.flip)==null?void 0:I.index)||0)+1,P=S[A];if(P&&(!(f==="alignment"?v!==er(P):!1)||R.every(M=>er(M.placement)===v?M.overflows[0]>0:!0)))return{data:{index:A,overflows:R},reset:{placement:P}};let D=(U=R.filter(O=>O.overflows[0]<=0).sort((O,M)=>O.overflows[1]-M.overflows[1])[0])==null?void 0:U.placement;if(!D)switch(p){case"bestFit":{var z;const O=(z=R.filter(M=>{if(k){const W=er(M.placement);return W===v||W==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(W=>W>0).reduce((W,L)=>W+L,0)]).sort((M,W)=>M[1]-W[1])[0])==null?void 0:z[0];O&&(D=O);break}case"initialPlacement":D=o;break}if(i!==D)return{reset:{placement:D}}}return{}}}};function ob(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function cb(e){return SM.some(t=>e[t]>=0)}const FM=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=Dr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=ob(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:cb(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=ob(l,s.floating);return{data:{escapedOffsets:o,escaped:cb(o)}}}default:return{}}}}},TC=new Set(["left","top"]);async function zM(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=pi(s),o=bl(s),c=er(s)==="y",u=TC.has(l)?-1:1,d=a&&c?-1:1,f=Dr(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*d,y:m*u}:{x:m*u,y:p*d}}const UM=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 zM(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}}}}},BM=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:v=>{let{x:w,y}=v;return{x:w,y}}},...u}=Dr(e,t),d={x:s,y:r},f=await a.detectOverflow(t,u),m=er(i),p=jv(m);let g=d[p],x=d[m];const b=(v,w)=>EC(w+f[v==="y"?"top":"left"],w,w-f[v==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(x=b(m,x));const j=c.fn({...t,[p]:g,[m]:x});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},WM=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:d=!0,crossAxis:f=!0}=Dr(e,t),m={x:i,y:a},p=er(l),g=jv(p);let x=m[g],b=m[p];const j=Dr(u,t),v=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(d){const N=g==="y"?"height":"width",k=o.reference[g]-o.floating[N]+v.mainAxis,S=o.reference[g]+o.reference[N]-v.mainAxis;x<k?x=k:x>S&&(x=S)}if(f){var w,y;const N=g==="y"?"width":"height",k=TC.has(pi(l)),S=o.reference[p]-o.floating[N]+(k&&((w=c.offset)==null?void 0:w[p])||0)+(k?0:v.crossAxis),C=o.reference[p]+o.reference[N]+(k?0:((y=c.offset)==null?void 0:y[p])||0)-(k?v.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[g]:x,[p]:b}}}},HM=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}=Dr(e,t),c=await i.detectOverflow(t,o),u=pi(s),d=bl(s),f=er(s)==="y",{width:m,height:p}=r.floating;let g,x;u==="top"||u==="bottom"?(g=u,x=d===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=u,g=d==="end"?"top":"bottom");const b=p-c.top-c.bottom,j=m-c.left-c.right,v=mi(p-c[g],b),w=mi(m-c[x],j),y=t.middlewareData.shift,N=!y;let k=v,S=w;y!=null&&y.enabled.x&&(S=j),y!=null&&y.enabled.y&&(k=b),N&&!d&&(f?S=m-2*Cr(c.left,c.right):k=p-2*Cr(c.top,c.bottom)),await l({...t,availableWidth:S,availableHeight:k});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function kh(){return typeof window<"u"}function kl(e){return RC(e)?(e.nodeName||"").toLowerCase():"#document"}function _n(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Ur(e){var t;return(t=(RC(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function RC(e){return kh()?e instanceof Node||e instanceof _n(e).Node:!1}function ir(e){return kh()?e instanceof Element||e instanceof _n(e).Element:!1}function Si(e){return kh()?e instanceof HTMLElement||e instanceof _n(e).HTMLElement:!1}function ub(e){return!kh()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof _n(e).ShadowRoot}function Nh(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=ar(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function KM(e){return/^(table|td|th)$/.test(kl(e))}function Sh(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const VM=/transform|translate|scale|rotate|perspective|filter/,GM=/paint|layout|strict|content/,Ii=e=>!!e&&e!=="none";let Wf;function bv(e){const t=ir(e)?ar(e):e;return Ii(t.transform)||Ii(t.translate)||Ii(t.scale)||Ii(t.rotate)||Ii(t.perspective)||!kv()&&(Ii(t.backdropFilter)||Ii(t.filter))||VM.test(t.willChange||"")||GM.test(t.contain||"")}function YM(e){let t=Zi(e);for(;Si(t)&&!Ho(t);){if(bv(t))return t;if(Sh(t))return null;t=Zi(t)}return null}function kv(){return Wf==null&&(Wf=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wf}function Ho(e){return/^(html|body|#document)$/.test(kl(e))}function ar(e){return _n(e).getComputedStyle(e)}function Ch(e){return ir(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Zi(e){if(kl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||ub(e)&&e.host||Ur(e);return ub(t)?t.host:t}function $C(e){const t=Zi(e);return Ho(t)?(e.ownerDocument||e).body:Si(t)&&Nh(t)?t:$C(t)}function Ko(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=$C(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=_n(i);if(a){const o=Kp(l);return t.concat(l,l.visualViewport||[],Nh(i)?i:[],o&&s?Ko(o):[])}else return t.concat(i,Ko(i,[],s))}function Kp(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function IC(e){const t=ar(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Si(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Cd(s)!==a||Cd(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function Nv(e){return ir(e)?e:e.contextElement}function Ga(e){const t=Nv(e);if(!Si(t))return Er(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=IC(t);let l=(a?Cd(s.width):s.width)/r,o=(a?Cd(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const qM=Er(0);function PC(e){const t=_n(e);return!kv()||!t.visualViewport?qM:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function QM(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===_n(e)}function ea(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=Nv(e);let l=Er(1);t&&(r?ir(r)&&(l=Ga(r)):l=Ga(e));const o=QM(a,s,r)?PC(a):Er(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,d=i.width/l.x,f=i.height/l.y;if(a&&r){const m=_n(a),p=ir(r)?_n(r):r;let g=m,x=Kp(g);for(;x&&p!==g;){const b=Ga(x),j=x.getBoundingClientRect(),v=ar(x),w=j.left+(x.clientLeft+parseFloat(v.paddingLeft))*b.x,y=j.top+(x.clientTop+parseFloat(v.paddingTop))*b.y;c*=b.x,u*=b.y,d*=b.x,f*=b.y,c+=w,u+=y,g=_n(x),x=Kp(g)}}return Ad({width:d,height:f,x:c,y:u})}function Eh(e,t){const s=Ch(e).scrollLeft;return t?t.left+s:ea(Ur(e)).left+s}function MC(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-Eh(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function XM(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=Ur(r),o=t?Sh(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=Er(1);const d=Er(0),f=Si(r);if((f||!a)&&((kl(r)!=="body"||Nh(l))&&(c=Ch(r)),f)){const p=ea(r);u=Ga(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const m=l&&!f&&!a?MC(l,c):Er(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+d.x+m.x,y:s.y*u.y-c.scrollTop*u.y+d.y+m.y}}function JM(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function ZM(e){const t=Ch(e),s=e.ownerDocument.body,r=Cr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=Cr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+Eh(e);const l=-t.scrollTop;return ar(s).direction==="rtl"&&(a+=Cr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const eD=25;function tD(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=_n(e),a=Ur(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,d=0;if(l){const m=!kv()||t==="fixed";r?m||(u=-l.offsetLeft,d=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,d=l.offsetTop))}if(Eh(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),x=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-x),j=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;j<=eD&&(o-=j)}return{width:o,height:c,x:u,y:d}}function nD(e,t){const s=ea(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=Ga(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 db(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=tD(e,s,t);else if(t==="document")r=ZM(Ur(e));else if(ir(t))r=nD(t,s);else{const i=PC(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ad(r)}function sD(e,t){const s=t.get(e);if(s)return s;let r=Ko(e,[],!1).filter(o=>ir(o)&&kl(o)!=="body"),i=null;const a=ar(e).position==="fixed";let l=a?Zi(e):e;for(;ir(l)&&!Ho(l);){const o=ar(l),c=bv(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):i=o,l=Zi(l)}return t.set(e,r),r}function rD(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?Sh(t)?[]:sD(t,this._c):[].concat(s),r],o=db(t,l[0],i);let c=o.top,u=o.right,d=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=db(t,l[m],i);c=Cr(p.top,c),u=mi(p.right,u),d=mi(p.bottom,d),f=Cr(p.left,f)}return{width:u-f,height:d-c,x:f,y:c}}function iD(e){const{width:t,height:s}=IC(e);return{width:t,height:s}}function aD(e,t,s){const r=Si(t),i=Ur(t),a=s==="fixed",l=ea(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=Er(0);if((r||!a)&&((kl(t)!=="body"||Nh(i))&&(o=Ch(t)),r)){const m=ea(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=Eh(i));const u=i&&!r&&!a?MC(i,o):Er(0),d=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:d,y:f,width:l.width,height:l.height}}function Hf(e){return ar(e).position==="static"}function hb(e,t){if(!Si(e)||ar(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return Ur(e)===s&&(s=s.ownerDocument.body),s}function DC(e,t){const s=_n(e);if(Sh(e))return s;if(!Si(e)){let i=Zi(e);for(;i&&!Ho(i);){if(ir(i)&&!Hf(i))return i;i=Zi(i)}return s}let r=hb(e,t);for(;r&&KM(r)&&Hf(r);)r=hb(r,t);return r&&Ho(r)&&Hf(r)&&!bv(r)?s:r||YM(e)||s}const lD=async function(e){const t=this.getOffsetParent||DC,s=this.getDimensions,r=await s(e.floating);return{reference:aD(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oD(e){return ar(e).direction==="rtl"}const cD={convertOffsetParentRelativeRectToViewportRelativeRect:XM,getDocumentElement:Ur,getClippingRect:rD,getOffsetParent:DC,getElementRects:lD,getClientRects:JM,getDimensions:iD,getScale:Ga,isElement:ir,isRTL:oD};function OC(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function uD(e,t,s){let r=null,i;const a=Ur(e);function l(){var d;clearTimeout(i),(d=r)==null||d.disconnect(),r=null}function o(d,f){d===void 0&&(d=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:x,height:b}=m;if(d||t(),!x||!b)return;const j=au(g),v=au(a.clientWidth-(p+x)),w=au(a.clientHeight-(g+b)),y=au(p),k={rootMargin:-j+"px "+-v+"px "+-w+"px "+-y+"px",threshold:Cr(0,mi(1,f))||1};let S=!0;function C($){const R=$[0].intersectionRatio;if(!OC(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,{...k,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,k)}r.observe(e)}const c=_n(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function dD(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=Nv(e),d=i||a?[...u?Ko(u):[],...t?Ko(t):[]]:[];d.forEach(j=>{i&&j.addEventListener("scroll",s),a&&j.addEventListener("resize",s)});const f=u&&o?uD(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[v]=j;v&&v.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,x=c?ea(e):null;c&&b();function b(){const j=ea(e);x&&!OC(x,j)&&s(),x=j,g=requestAnimationFrame(b)}return s(),()=>{var j;d.forEach(v=>{i&&v.removeEventListener("scroll",s),a&&v.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const hD=UM,fD=BM,mD=_M,pD=HM,gD=FM,fb=LM,xD=WM,vD=(e,t,s)=>{const r=new Map,i=s??{},a={...cD,...i.platform,_c:r};return OM(e,t,{...i,platform:a})};var jD=typeof document<"u",wD=function(){},Hu=jD?h.useLayoutEffect:wD;function Td(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(!Td(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)&&!Td(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function LC(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function mb(e,t){const s=LC(e);return Math.round(t*s)/s}function Kf(e){const t=h.useRef(e);return Hu(()=>{t.current=e}),t}function yD(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,[d,f]=h.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=h.useState(r);Td(m,r)||p(r);const[g,x]=h.useState(null),[b,j]=h.useState(null),v=h.useCallback(M=>{M!==k.current&&(k.current=M,x(M))},[]),w=h.useCallback(M=>{M!==S.current&&(S.current=M,j(M))},[]),y=a||g,N=l||b,k=h.useRef(null),S=h.useRef(null),C=h.useRef(d),$=c!=null,R=Kf(c),I=Kf(i),U=Kf(u),z=h.useCallback(()=>{if(!k.current||!S.current)return;const M={placement:t,strategy:s,middleware:m};I.current&&(M.platform=I.current),vD(k.current,S.current,M).then(W=>{const L={...W,isPositioned:U.current!==!1};A.current&&!Td(C.current,L)&&(C.current=L,wl.flushSync(()=>{f(L)}))})},[m,t,s,I,U]);Hu(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(M=>({...M,isPositioned:!1})))},[u]);const A=h.useRef(!1);Hu(()=>(A.current=!0,()=>{A.current=!1}),[]),Hu(()=>{if(y&&(k.current=y),N&&(S.current=N),y&&N){if(R.current)return R.current(y,N,z);z()}},[y,N,z,R,$]);const P=h.useMemo(()=>({reference:k,floating:S,setReference:v,setFloating:w}),[v,w]),D=h.useMemo(()=>({reference:y,floating:N}),[y,N]),O=h.useMemo(()=>{const M={position:s,left:0,top:0};if(!D.floating)return M;const W=mb(D.floating,d.x),L=mb(D.floating,d.y);return o?{...M,transform:"translate("+W+"px, "+L+"px)",...LC(D.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:W,top:L}},[s,o,D.floating,d.x,d.y]);return h.useMemo(()=>({...d,update:z,refs:P,elements:D,floatingStyles:O}),[d,z,P,D,O])}const bD=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?fb({element:r.current,padding:i}).fn(s):{}:r?fb({element:r,padding:i}).fn(s):{}}}},kD=(e,t)=>{const s=hD(e);return{name:s.name,fn:s.fn,options:[e,t]}},ND=(e,t)=>{const s=fD(e);return{name:s.name,fn:s.fn,options:[e,t]}},SD=(e,t)=>({fn:xD(e).fn,options:[e,t]}),CD=(e,t)=>{const s=mD(e);return{name:s.name,fn:s.fn,options:[e,t]}},ED=(e,t)=>{const s=pD(e);return{name:s.name,fn:s.fn,options:[e,t]}},AD=(e,t)=>{const s=gD(e);return{name:s.name,fn:s.fn,options:[e,t]}},TD=(e,t)=>{const s=bD(e);return{name:s.name,fn:s.fn,options:[e,t]}};var RD=Object.defineProperty,$D=(e,t)=>RD(e,"name",{value:t,configurable:!0});function _C(e){const[t,s]=h.useState(void 0);return Ln(()=>{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}$D(_C,"useSize");var ID=Object.defineProperty,oi=(e,t)=>ID(e,"name",{value:t,configurable:!0}),FC="Popper",[zC,Ah]=Fs(FC),[PD,UC]=zC(FC),MD=oi(e=>{const{__scopePopper:t,children:s}=e,[r,i]=h.useState(null),[a,l]=h.useState(void 0);return n.jsx(PD,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),DD="PopperAnchor",OD=h.forwardRef(oi(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=UC(DD,r),o=h.useRef(null),c=l.onAnchorChange,u=h.useCallback(x=>{o.current=x,x&&c(x)},[c]),d=vt(s,u),f=h.useRef(null);h.useEffect(()=>{if(!i)return;const x=f.current;f.current=i.current,x!==f.current&&c(f.current)});const m=l.placementState&&Th(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(pt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:d})},"PopperAnchor")),BC="PopperContent",[LD,xQ]=zC(BC),_D=h.forwardRef(oi(function(t,s){var Le,Ie,ze,ee,be,re,Ee;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:x,...b}=t,j=UC(BC,r),[v,w]=h.useState(null),y=vt(s,w),[N,k]=h.useState(null),S=_C(N),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},U=Array.isArray(d)?d:[d],z=U.length>0,A={padding:I,boundary:U.filter(WC),altBoundary:z},{refs:P,floatingStyles:D,placement:O,isPositioned:M,middlewareData:W}=yD({strategy:"fixed",placement:R,whileElementsMounted:oi((...me)=>dD(...me,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[kD({mainAxis:a+$,alignmentAxis:o}),u&&ND({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?SD():void 0,...A}),u&&CD({...A}),ED({...A,apply:oi(({elements:me,rects:Re,availableWidth:Se,availableHeight:Ue})=>{const{width:et,height:Ae}=Re.reference,Be=me.floating.style;Be.setProperty("--radix-popper-available-width",`${Se}px`),Be.setProperty("--radix-popper-available-height",`${Ue}px`),Be.setProperty("--radix-popper-anchor-width",`${et}px`),Be.setProperty("--radix-popper-anchor-height",`${Ae}px`)},"apply")}),N&&TD({element:N,padding:c}),FD({arrowWidth:C,arrowHeight:$}),p&&AD({strategy:"referenceHidden",...A,boundary:z?A.boundary:void 0})]}),L=j.setPlacementState;Ln(()=>(L(O),()=>{L(void 0)}),[O,L]);const[q,B]=Th(O),V=Sn(x);Ln(()=>{M&&(V==null||V())},[M,V]);const F=(Le=W.arrow)==null?void 0:Le.x,X=(Ie=W.arrow)==null?void 0:Ie.y,Y=((ze=W.arrow)==null?void 0:ze.centerOffset)!==0,[Z,he]=h.useState();return Ln(()=>{v&&he(window.getComputedStyle(v).zIndex)},[v]),n.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:M?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Z,"--radix-popper-transform-origin":[(ee=W.transformOrigin)==null?void 0:ee.x,(be=W.transformOrigin)==null?void 0:be.y].join(" "),...((re=W.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(LD,{scope:r,placedSide:q,placedAlign:B,onArrowChange:k,arrowX:F,arrowY:X,shouldHideArrow:Y,children:n.jsx(pt.div,{"data-side":q,"data-align":B,...b,ref:y,style:{...b.style,animation:M?(Ee=b.style)==null?void 0:Ee.animation:"none"}})})})},"PopperContent"));function WC(e){return e!==null}oi(WC,"isNotNull");var FD=oi(e=>({name:"transformOrigin",options:e,fn(t){var b,j,v;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,d]=Th(s),f={start:"0%",center:"50%",end:"100%"}[d],m=(((j=i.arrow)==null?void 0:j.x)??0)+o/2,p=(((v=i.arrow)==null?void 0:v.y)??0)+c/2;let g="",x="";return u==="bottom"?(g=l?f:`${m}px`,x=`${-c}px`):u==="top"?(g=l?f:`${m}px`,x=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,x=l?f:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,x=l?f:`${p}px`),{data:{x:g,y:x}}}}),"transformOrigin");function Th(e){const[t,s="center"]=e.split("-");return[t,s]}oi(Th,"getSideAndAlignFromPlacement");var Sv=MD,HC=OD,KC=_D,zD=Object.defineProperty,en=(e,t)=>zD(e,"name",{value:t,configurable:!0}),[Cv,vQ]=Fs("Tooltip",[Ah]),Ev=Ah(),UD="TooltipProvider",BD=700,Vp="tooltip.open",[WD,Av]=Cv(UD),HD=en(e=>{const{__scopeTooltip:t,delayDuration:s=BD,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=h.useRef(!0),o=h.useRef(!1),c=h.useRef(0);return h.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(WD,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:h.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:h.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:h.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),Gp="Tooltip",[KD,wc]=Cv(Gp),VD=en(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=Av(Gp,e.__scopeTooltip),u=Ev(t),[d,f]=h.useState(null),[m,p]=h.useState(void 0),g=Is(),x=h.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,v=h.useRef(!1),[w,y]=Ni({prop:r,defaultProp:i??!1,onChange:en(R=>{R?(c.onOpen(),document.dispatchEvent(new CustomEvent(Vp))):c.onClose(),a==null||a(R)},"onChange"),caller:Gp}),N=h.useMemo(()=>w?v.current?"delayed-open":"instant-open":"closed",[w]),k=h.useCallback(()=>{window.clearTimeout(x.current),x.current=0,v.current=!1,y(!0)},[y]),S=h.useCallback(()=>{window.clearTimeout(x.current),x.current=0,y(!1)},[y]),C=h.useCallback(()=>{window.clearTimeout(x.current),x.current=window.setTimeout(()=>{v.current=!0,y(!0),x.current=0},j)},[j,y]);h.useEffect(()=>()=>{x.current&&(window.clearTimeout(x.current),x.current=0)},[]);const $=m??g;return n.jsx(Sv,{...u,children:n.jsx(KD,{scope:t,contentId:$,setContentId:p,open:w,stateAttribute:N,trigger:d,onTriggerChange:f,onTriggerEnter:h.useCallback(()=>{c.isOpenDelayedRef.current?C():k()},[c.isOpenDelayedRef,C,k]),onTriggerLeave:h.useCallback(()=>{b?S():(window.clearTimeout(x.current),x.current=0)},[S,b]),onOpen:k,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),pb="TooltipTrigger",GD=h.forwardRef(en(function(t,s){const{__scopeTooltip:r,...i}=t,a=wc(pb,r),l=Av(pb,r),o=Ev(r),c=h.useRef(null),u=vt(s,c,a.onTriggerChange),d=h.useRef(!1),f=h.useRef(!1),m=h.useCallback(()=>d.current=!1,[]);return h.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx(HC,{asChild:!0,...o,children:n.jsx(pt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Pe(t.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),f.current=!0)}),onPointerLeave:Pe(t.onPointerLeave,()=>{a.onTriggerLeave(),f.current=!1}),onPointerDown:Pe(t.onPointerDown,()=>{a.open&&a.onClose(),d.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Pe(t.onFocus,()=>{d.current||a.onOpen()}),onBlur:Pe(t.onBlur,a.onClose),onClick:Pe(t.onClick,a.onClose)})})},"TooltipTrigger")),VC="TooltipPortal",[YD,qD]=Cv(VC,{forceMount:void 0}),QD=en(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=wc(VC,t);return n.jsx(YD,{scope:t,forceMount:s,children:n.jsx(ur,{present:s||a.open,children:n.jsx(wh,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),Vo="TooltipContent",XD=h.forwardRef(en(function(t,s){const r=qD(Vo,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=wc(Vo,t.__scopeTooltip);return n.jsx(ur,{present:i||o.open,children:o.disableHoverableContent?n.jsx(GC,{side:a,...l,ref:s}):n.jsx(JD,{side:a,...l,ref:s})})},"TooltipContent")),JD=h.forwardRef(en(function(t,s){const r=wc(Vo,t.__scopeTooltip),i=Av(Vo,t.__scopeTooltip),a=h.useRef(null),l=vt(s,a),[o,c]=h.useState(null),{trigger:u,onClose:d}=r,f=a.current,{onPointerInTransitChange:m}=i,p=h.useCallback(()=>{c(null),m(!1)},[m]),g=h.useCallback((x,b)=>{const j=x.currentTarget,v={x:x.clientX,y:x.clientY},w=YC(v,j.getBoundingClientRect()),y=qC(v,w),N=QC(b.getBoundingClientRect()),k=JC([...y,...N]);c(k),m(!0)},[m]);return h.useEffect(()=>()=>p(),[p]),h.useEffect(()=>{if(u&&f){const x=en(j=>g(j,f),"handleTriggerLeave"),b=en(j=>g(j,u),"handleContentLeave");return u.addEventListener("pointerleave",x),f.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",x),f.removeEventListener("pointerleave",b)}}},[u,f,g,p]),h.useEffect(()=>{if(o){const x=en(b=>{const j=b.target,v={x:b.clientX,y:b.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),y=!XC(v,o);w?p():y&&(p(),d())},"handleTrackPointerGrace");return document.addEventListener("pointermove",x),()=>document.removeEventListener("pointermove",x)}},[u,f,o,d,p]),n.jsx(GC,{...t,ref:l})},"TooltipContentHoverable")),ZD=tC("TooltipContent"),GC=h.forwardRef(en(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,d=wc(Vo,r),f=Ev(r),{onClose:m}=d;h.useEffect(()=>(document.addEventListener(Vp,m),()=>document.removeEventListener(Vp,m)),[m]),h.useEffect(()=>{if(d.trigger){const g=en(x=>{x.target instanceof Node&&x.target.contains(d.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[d.trigger,m]);const{setContentId:p}=d;return Ln(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(jh,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(KC,{"data-state":d.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:d.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(ZD,{children:i}),a?n.jsx(G2,{id:d.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function YC(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")}}en(YC,"getExitSideFromRect");function qC(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}en(qC,"getPaddedExitPoints");function QC(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}]}en(QC,"getPointsFromRect");function XC(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,d=o.y,f=c.x,m=c.y;d>r!=m>r&&s<(f-u)*(r-d)/(m-d)+u&&(i=!i)}return i}en(XC,"isPointInPolygon");function JC(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),ZC(t)}en(JC,"getHull");function ZC(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)}en(ZC,"getHullPresorted");var gb=HD,Go=VD,Yo=GD,qo=QD,Qo=XD;let Ut={time:"auto",date:"auto",locale:void 0};function Tv(e){const t=e.timeFormat===void 0?Ut.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?Ut.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";Ut={time:t,date:s,locale:e.locale??Ut.locale}}function e1(){return{time:Ut.time,date:Ut.date}}function yc(e,t){const s=Ut;Tv(e);try{return t()}finally{Ut=s}}const Yp="buddi:formats";function bc(){if(Ut.locale)return Ut.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const xb=new Map;function Nl(e,t){const s=`${e}|${JSON.stringify(t)}`;let r=xb.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,t)}catch{r=new Intl.DateTimeFormat(e,{...t,timeZone:"UTC"})}xb.set(s,r)}return r}function Vf(e,t,s,r){return Object.fromEntries(Nl(s,{timeZone:t,...r}).formatToParts(e).map(i=>[i.type,i.value]))}function eO(){return Ut.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:Ut.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Rh()?"numeric":"2-digit",minute:"2-digit"}}function tO(){return Ut.time==="auto"?bc():"en-US"}function Wt(e,t){return Number.isNaN(e.getTime())?"—":Nl(tO(),{timeZone:t,...eO()}).format(e)}function nO(e){return e>=1440&&!Rh()?"24:00":Wt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Rh(){var e;return Ut.time!=="auto"?Ut.time==="12h":((e=Nl(bc(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function t1(){return`Profile (${Rh()?"12-hour":"24-hour"})`}function sO(){if(Ut.date!=="auto")return Ut.date==="short";const e=Nl(bc(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(t=>t.type);return e.indexOf("month")<e.indexOf("day")}function dr(e,t,s={}){return rO(e,t,s).replace(/\bSept\b/g,"Sep")}function rO(e,t,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:i=!1,compact:a=!1}=s;switch(Ut.date){case"iso":{const l=Vf(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=Vf(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=Vf(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 Nl(bc(),{timeZone:t,month:a?"short":"long",day:"numeric",...i?{year:"numeric"}:{},...r?{weekday:a?"short":"long"}:{}}).format(e)}}function n1(e,t){if(Ut.date==="iso")return`${e}-${String(t).padStart(2,"0")}`;const s=new Date(Date.UTC(e,t-1,15)),r=Ut.date==="auto"?bc():"en-GB";return Nl(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function $h(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:dr(r,"UTC",t)}function nt(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${dr(s,t,{year:!0,compact:!0})}, ${Wt(s,t)}`}function Rv(e,t){return`${dr(e,t,{weekday:!0,compact:!0})}, ${Wt(e,t)}`}function De(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 $v(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 iO(e,t=Date.now()){const s=$v(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function aO(e,t){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function Vt(e){return new Intl.NumberFormat("en-US").format(e)}function qp(e){return[...e.cacheRead?[`cached ${Vt(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Vt(e.cacheWrite)}`]:[]].join(", ")}function lO(e){const t=qp(e);return`${Vt(e.input)} in${t?` (${t})`:""} / ${Vt(e.output)} out`}function Jn(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Xo(e,t=8){return e.length<=t?e:e.slice(0,t)}function Os(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function Jo(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}const vb="buddi_csrf",Sl="x-buddi-csrf",Zo="buddi:agents-changed",Bi="buddi:status-changed",Xl=e=>(window.dispatchEvent(new Event(Bi)),e),Qp="buddi:locked",oO="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 ia(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${vb}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${vb}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Rd="buddi isn't answering.";let Xp=null;const Jp=new Set;function Jl(e){if(e!==(Xp===null)){Xp=e?null:Date.now();for(const t of Jp)t()}}function ec(){return Xp}function Iv(e){return Jp.add(e),()=>Jp.delete(e)}function $d(e){return e instanceof pe&&(e.status===0||e.status===502||e.status===503)&&e.message===Rd}async function aa(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:(Jl(!1),new pe(0,Rd,o))}if(s.status===401)throw Jl(!0),new pe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Jl(!0),window.dispatchEvent(new Event(Qp)),new pe(423,"This dashboard is locked.");const r=await s.text(),i=r===""?null:cO(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 Jl(!1),new pe(s.status,Rd,i);if(Jl(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?oO:`request failed (${s.status})`);throw new pe(s.status,c,i)}return i}function cO(e){try{return JSON.parse(e)}catch{return null}}function Gf(){return e1().time==="auto"?{hour:Rh()?"12":"24"}:{}}function ge(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 aa(`/api${e}${r?`?${r}`:""}`)}function Zp(e,t){return aa(`/api${e}`,{method:"POST",headers:{[Sl]:ia()},body:t})}function jr(e){return aa(`/api${e}`,{method:"DELETE",headers:{[Sl]:ia()}})}function ne(e,t={}){return aa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[Sl]:ia()},body:JSON.stringify(t??{})})}function s1(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return aa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[Sl]:ia(),"X-Filename":i,...r},body:t})}function jb(e,t,s){return s1(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function uO(e,t={}){return aa(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[Sl]:ia()},body:JSON.stringify(t??{})})}function Gs(e,t={}){return aa(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[Sl]:ia()},body:JSON.stringify(t??{})})}function dO(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 Ku="gpt-oss:120b",hO=["approval","question","watcher","reminder","failure","recap","plugin","agent"],eg=["mon","tue","wed","thu","fri","sat","sun"],He={agents:()=>ge("/chat/agents"),views:()=>ge("/chat/views"),conversations:(e,t)=>ge(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>ne(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>ge(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>jr(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,t)=>ne(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>ne(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>ne(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),Zp("/chat/attachments",t)},transcribe:e=>ne("/speech/transcribe",e),say:e=>ne("/speech/say",e),discardAttachment:e=>jr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>ge("/groups"),group:e=>ge(`/groups/${encodeURIComponent(e)}`),createGroup:e=>ne("/groups",e),updateGroup:(e,t)=>uO(`/groups/${encodeURIComponent(e)}`,t),deleteGroup:e=>jr(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>ne(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>ne(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>ge(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>ne(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>ne(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function Pv(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const E={providers:()=>ge("/providers"),providerAccounts:()=>ge("/provider-accounts"),probeModels:e=>ne("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>ne(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>ne("/provider-accounts/save",e),testProviderAccount:e=>ne(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>ne(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>ne(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>ne(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>ne(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>ne(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>ne(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>ne(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>ge("/host/browser-profiles",{app:e}),installedApps:()=>ge("/host/apps"),browser:e=>ge(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>ne(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>ne("/browser/settings",e),computerPermissions:(e=!1)=>ne("/browser/permissions",{prompt:e}),browserInstall:()=>ne("/browser/install",{}),browserCheck:()=>ne("/browser/check",{}),previewLink:(e,t)=>ge(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>ge(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>ge("/extension"),pairExtension:e=>ne("/extension/pair",{code:e}),forgetExtension:()=>jr("/extension/pair"),session:()=>ge("/session"),overview:()=>ge("/overview"),events:e=>ge("/events",e),eventKinds:()=>ge("/events/kinds"),conversations:()=>ge("/conversations"),conversation:e=>ge(`/conversations/${encodeURIComponent(e)}`),missions:()=>ge("/missions"),jobs:(e={})=>ge("/jobs",e),approvals:()=>ge("/approvals"),approval:e=>ge(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>ge("/offers"),dismissOffer:e=>ne(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>ne("/offers/dismiss-all",{ids:e}),agentOffers:()=>ge("/agent-offers"),teammates:()=>ge("/teammates"),dismissAgentOffer:(e,t)=>ne(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>ge("/proposals"),setDigestSchedule:(e,t)=>ne("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),keepAllProposals:e=>ne("/proposals/keep-all",{ids:e}),discardProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>ge("/reminders"),sentinels:()=>ge("/sentinels"),setSentinelEnabled:(e,t)=>ne(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),widgets:(e="home")=>ge("/widgets",{...e==="lock"?{surface:e}:{},...Gf()}),saveWidgets:(e,t)=>Gs(`/widgets/${e}`,{placements:t.map(({key:s,widget:r,size:i,settings:a})=>({...s?{key:s}:{},widget:r,size:i,settings:a}))}),widgetSettings:e=>ge(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>ne("/widgets/preview",{...e,...Gf()}),refreshWidget:(e,t="home")=>ne(`/widgets/${encodeURIComponent(e)}/refresh${t==="lock"?"?surface=lock":""}`),homeDismiss:(e,t)=>ne("/home/dismiss",{slot:e,token:t}),setGlanceHidden:(e,t)=>ne(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>ge("/rail"),setRailHidden:(e,t,s)=>ne(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlerts:(e,t,s)=>ne("/alerts/snooze",{keys:e,snoozed:t,...s!==void 0?{days:s}:{}}),muteAlert:(e,t)=>ne("/alerts/mute",{key:e,scope:t}),unmuteAlert:e=>ne(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>ne("/alerts/act",{entries:e}),askAboutAlerts:e=>ne("/alerts/ask",{keys:e}),agents:()=>ge("/agents"),library:e=>ge("/artifacts",e),libraryEntry:(e,t=0)=>ge(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>ge("/onboarding"),onboardingStep:(e,t={})=>ne("/onboarding/step",{step:e,...t}),takeOn:e=>ne("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>ge("/onboarding/take-on"),completeOnboarding:()=>ne("/onboarding/complete"),skipOnboarding:()=>ne("/onboarding/skip"),createFirstAgent:e=>ne("/onboarding/agent",e),ollama:()=>ge("/onboarding/ollama"),mlxh:()=>ge("/onboarding/mlxh"),firstAgentPersona:()=>ge("/onboarding/agent"),updateFirstAgent:e=>ne("/onboarding/agent/update",e),bindBrain:e=>ne("/onboarding/brain",e),pages:()=>ge("/pages"),pageQuery:(e,t,s={})=>ge(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,s),pageFileUrl:(e,t,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,i])=>i!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r?`?${r}`:""}`},pageAct:(e,t)=>ne(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>ge("/telegram"),saveTelegramToken:e=>ne("/telegram/token",{token:e}),telegramPairing:()=>ne("/telegram/pairing"),telegramBot:()=>ge("/telegram/bot"),telegramDevices:()=>ge("/telegram/devices"),unpairTelegramDevice:e=>jr(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>ge("/notifications",{limit:e}),notificationsNeedingYou:()=>ge("/notifications",{needs:1}),notificationSeen:e=>ne(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>ge("/notifications/settings"),saveNotificationSettings:e=>Gs("/notifications/settings",e),focus:()=>ge("/notifications/focus"),lockState:()=>ge("/lock"),lockScreen:()=>ge("/lock/screen",Gf()),lockNow:(e="owner")=>ne("/lock",{reason:e}),unlock:e=>ne("/lock/unlock",{pin:e}),lockActivity:()=>ne("/lock/activity"),setPin:(e,t)=>Gs("/lock/pin",t===void 0?{pin:e}:{pin:e,current:t}),removePin:e=>ne("/lock/pin/remove",{current:e}),setLockSettings:e=>Gs("/lock/settings",e),uploadLockBackground:e=>{const t=new FormData;return t.append("file",e),Zp("/lock/background",t)},removeLockBackground:()=>jr("/lock/background"),setFocus:(e,t)=>Gs("/notifications/focus",t?{mode:e,duration:t}:{mode:e}).then(Xl),testChannel:e=>ne("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>ne("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>ge(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>ge("/tips"),restoreTip:e=>ne(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>ne(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>ne(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>ne("/tips/seen-page",{page:e}),tipsSettings:()=>ge("/tips/settings"),saveTipsSettings:e=>Gs("/tips/settings",{enabled:e}),presence:e=>ne("/presence",{state:e}),owner:()=>ge("/owner"),setOwner:e=>ne("/owner",e),findPlace:e=>ne("/owner/places/find",{address:e}),savePlace:e=>ne("/owner/places",e),removePlace:e=>ne("/owner/places/remove",{id:e}),memory:e=>ge(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>ne("/memory/preferences",e),forgetPreference:e=>ne("/memory/preferences/forget",e),updateNote:(e,t)=>ne(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>ne(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>ge(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>ge(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>ge("/host",{agentId:e,conversationId:t}),connections:()=>ge("/connections"),connection:e=>ge(`/connections/${e}`),addConnection:(e,t)=>ne("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>ne("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>ne(`/connections/${e}/program`,t),connectionConsent:(e,t)=>ne(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>ne(`/connections/${e}/token`,t),connectionDevice:e=>ne(`/connections/${e}/device`,{}),connectionCallback:e=>ne("/connections/callback",e),connectionReview:e=>ge(`/connections/${e}/review`),saveConnectionReview:(e,t)=>ne(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>ne(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>ne(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>jr(`/connections/${e}`),connectionSignals:()=>ge("/connections/signals"),connectionTools:e=>ge(`/connections/${e}/tools`),rememberedApprovals:e=>ge(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>ne("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>ge("/secrets"),secretUses:(e,t)=>ge("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>ne("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>ne("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>ne("/host/revoke",{id:e}),decide:(e,t,s,r)=>ne(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>ne("/pause",{paused:e}).then(Xl),service:()=>ge("/service"),serviceAction:e=>ne(`/service/${e}`),version:()=>ge("/version"),checkVersion:()=>ne("/version/check"),setVersionCheck:e=>Gs("/version/check",{enabled:e}),tailscale:()=>ge("/tailscale"),setTailscale:e=>Gs("/tailscale",e),apiTokens:()=>ge("/api-tokens"),createApiToken:e=>ne("/api-tokens",{name:e}),revokeApiToken:e=>jr(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>ne("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>ge(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>ge("/backups"),startBackup:e=>ne("/backups",{encrypt:e}),verifyArchive:e=>ne("/backups/verify",{name:e}),restoreArchive:e=>ne("/backups/restore",e),restoreUpload:(e,t)=>jb("/backups/restore",e,t),backupJob:e=>ge(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>ge("/backups/schedule"),setBackupSchedule:e=>Gs("/backups/schedule",e),backupPassphrase:()=>ge("/backups/passphrase"),setBackupPassphrase:e=>Gs("/backups/passphrase",{passphrase:e}),plugins:()=>ge("/plugins"),market:(e=!1)=>ge(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>ge("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>ne("/plugins/stage",{spec:e}),uploadPlugin:e=>s1("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>ge(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>ne(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>ne(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>ne(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,t,s)=>ne(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>ge("/recovery"),leaveRecovery:e=>ne("/recovery/leave",e),firstRunRestore:(e,t)=>jb("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>ne(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),setMisfirePolicy:(e,t,s)=>ne(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>ne(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>ne(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>ge("/jobs/failures"),dismissJobs:e=>ne("/jobs/dismiss",e).then(Xl),undismissJobs:e=>ne("/jobs/undismiss",{ids:e}).then(Xl),retryJobs:e=>ne("/jobs/retry",e).then(Xl),setDefaultAgent:e=>ne("/agents/default",{agentId:e}),agentTools:e=>ge(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>ge(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),Zp(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>jr(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>ne(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>ne(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})};function r1(e){return e==="anthropic"||e==="openai"}function i1(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 fO="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var mO=Object.defineProperty,pO=(e,t)=>mO(e,"name",{value:t,configurable:!0}),gO=h.createContext(void 0);function Ih(e){const t=h.useContext(gO);return e||t||"ltr"}pO(Ih,"useDirection");var xO=Object.defineProperty,Mv=(e,t)=>xO(e,"name",{value:t,configurable:!0}),lu=0,Ys=null;function vO(e){return Ph(),e.children}Mv(vO,"FocusGuards");function Ph(){h.useEffect(()=>{Ys||(Ys={start:tg(),end:tg()});const{start:e,end:t}=Ys;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),lu++,()=>{lu===1&&(Ys==null||Ys.start.remove(),Ys==null||Ys.end.remove(),Ys=null),lu=Math.max(0,lu-1)}},[])}Mv(Ph,"useFocusGuards");function tg(){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}Mv(tg,"createFocusGuard");var jO=Object.defineProperty,kn=(e,t)=>jO(e,"name",{value:t,configurable:!0}),Yf="focusScope.autoFocusOnMount",qf="focusScope.autoFocusOnUnmount",wb={bubbles:!1,cancelable:!0},a1=h.forwardRef(kn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=h.useState(null),d=Sn(a),f=Sn(l),m=h.useRef(null),p=vt(s,u),g=h.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;h.useEffect(()=>{if(i){let b=function(y){if(g.paused||!c)return;const N=y.target;c.contains(N)?m.current=N:xr(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const N=y.relatedTarget;N!==null&&(c.contains(N)||xr(m.current,{select:!0}))},v=function(y){if(document.activeElement===document.body)for(const k of y)k.removedNodes.length>0&&xr(c)};kn(b,"handleFocusIn"),kn(j,"handleFocusOut"),kn(v,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",j);const w=new MutationObserver(v);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",j),w.disconnect()}}},[i,c,g.paused]),h.useEffect(()=>{if(c){yb.add(g);const b=document.activeElement;if(!c.contains(b)){const v=new CustomEvent(Yf,wb);c.addEventListener(Yf,d),c.dispatchEvent(v),v.defaultPrevented||(l1(h1(Dv(c)),{select:!0}),document.activeElement===b&&xr(c))}return()=>{c.removeEventListener(Yf,d),setTimeout(()=>{const v=new CustomEvent(qf,wb);c.addEventListener(qf,f),c.dispatchEvent(v),v.defaultPrevented||xr(b??document.body,{select:!0}),c.removeEventListener(qf,f),yb.remove(g)},0)}}},[c,d,f,g]);const x=h.useCallback(b=>{if(!r&&!i||g.paused)return;const j=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,v=document.activeElement;if(j&&v){const w=b.currentTarget,[y,N]=o1(w);y&&N?!b.shiftKey&&v===N?(b.preventDefault(),r&&xr(y,{select:!0})):b.shiftKey&&v===y&&(b.preventDefault(),r&&xr(N,{select:!0})):v===w&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(pt.div,{tabIndex:-1,...o,ref:p,onKeyDown:x})},"FocusScope"));function l1(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(xr(r,{select:t}),document.activeElement!==s)return}kn(l1,"focusFirst");function o1(e){const t=Dv(e),s=ng(t,e),r=ng(t.reverse(),e);return[s,r]}kn(o1,"getTabbableEdges");function Dv(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(Dv,"getTabbableCandidates");function ng(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):c1(r,{upTo:t})))return r}kn(ng,"findVisible");function c1(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(c1,"isHidden");function u1(e){return e instanceof HTMLInputElement&&"select"in e}kn(u1,"isSelectableInput");function xr(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&u1(e)&&t&&e.select()}}kn(xr,"focus");var yb=d1();function d1(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=sg(e,t),e.unshift(t)},remove(t){var s;e=sg(e,t),(s=e[0])==null||s.resume()}}}kn(d1,"createFocusScopesStack");function sg(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}kn(sg,"arrayRemove");function h1(e){return e.filter(t=>t.tagName!=="A")}kn(h1,"removeLinks");var wO=Object.defineProperty,Ov=(e,t)=>wO(e,"name",{value:t,configurable:!0}),Qf=!1;function f1(){const[e,t]=h.useState(Qf);return h.useEffect(()=>{Qf||(Qf=!0,t(!0))},[]),e}Ov(f1,"useIsHydrated");var m1=xl[" useSyncExternalStore ".trim().toString()];function p1(){return()=>{}}Ov(p1,"subscribe");function g1(){return m1(p1,()=>!0,()=>!1)}Ov(g1,"useIsHydratedModern");var yO=typeof m1=="function"?g1:f1,bO=Object.defineProperty,la=(e,t)=>bO(e,"name",{value:t,configurable:!0}),Xf="rovingFocusGroup.onEntryFocus",kO={bubbles:!1,cancelable:!0},Mh="RovingFocusGroup",[rg,x1,NO]=xh(Mh),[SO,Dh]=Fs(Mh,[NO]),[CO,EO]=SO(Mh),AO=h.forwardRef(la(function(t,s){return n.jsx(rg.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(rg.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(TO,{...t,ref:s})})})},"RovingFocusGroup")),TO=h.forwardRef(la(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...m}=t,p=h.useRef(null),g=vt(s,p),x=Ih(l),[b,j]=Ni({prop:o,defaultProp:c??null,onChange:u,caller:Mh}),[v,w]=h.useState(!1),y=Sn(d),N=x1(r),k=h.useRef(!1),[S,C]=h.useState(0);return h.useEffect(()=>{const $=p.current;if($)return $.addEventListener(Xf,y),()=>$.removeEventListener(Xf,y)},[y]),n.jsx(CO,{scope:r,orientation:i,dir:x,loop:a,currentTabStopId:b,onItemFocus:h.useCallback($=>j($),[j]),onItemShiftTab:h.useCallback(()=>w(!0),[]),onFocusableItemAdd:h.useCallback(()=>C($=>$+1),[]),onFocusableItemRemove:h.useCallback(()=>C($=>$-1),[]),children:n.jsx(pt.div,{tabIndex:v||S===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Pe(t.onMouseDown,()=>{k.current=!0}),onFocus:Pe(t.onFocus,$=>{const R=!k.current;if($.target===$.currentTarget&&R&&!v){const I=new CustomEvent(Xf,kO);if($.currentTarget.dispatchEvent(I),!I.defaultPrevented){const U=N().filter(O=>O.focusable),z=U.find(O=>O.active),A=U.find(O=>O.id===b),D=[z,A,...U].filter(Boolean).map(O=>O.ref.current);Lv(D,f)}}k.current=!1}),onBlur:Pe(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),RO="RovingFocusGroupItem",$O=h.forwardRef(la(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=Is(),d=l||u,f=EO(RO,r),m=f.currentTabStopId===d,p=x1(r),{onFocusableItemAdd:g,onFocusableItemRemove:x,currentTabStopId:b}=f,j=yO();return Ln(()=>{if(!(!j||!i))return g(),()=>x()},[j,i,g,x]),h.useEffect(()=>{if(!(j||!i))return g(),()=>x()},[j,i,g,x]),n.jsx(rg.ItemSlot,{scope:r,id:d,focusable:i,active:a,children:n.jsx(pt.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:Pe(t.onMouseDown,v=>{i?f.onItemFocus(d):v.preventDefault()}),onFocus:Pe(t.onFocus,()=>f.onItemFocus(d)),onKeyDown:Pe(t.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){f.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const w=j1(v,f.orientation,f.dir);if(w!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let N=p().filter(k=>k.focusable).map(k=>k.ref.current);if(w==="last")N.reverse();else if(w==="prev"||w==="next"){w==="prev"&&N.reverse();const k=N.indexOf(v.currentTarget);N=f.loop?w1(N,k+1):N.slice(k+1)}setTimeout(()=>Lv(N))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),IO={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function v1(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}la(v1,"getDirectionAwareKey");function j1(e,t,s){const r=v1(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return IO[r]}la(j1,"getFocusIntent");function Lv(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}la(Lv,"focusFirst");function w1(e,t){return e.map((s,r)=>e[(t+r)%e.length])}la(w1,"wrapArray");var y1=AO,b1=$O,PO=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xa=new WeakMap,ou=new WeakMap,cu={},Jf=0,k1=function(e){return e&&(e.host||k1(e.parentNode))},MO=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=k1(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})},DO=function(e,t,s,r){var i=MO(t,Array.isArray(e)?e:[e]);cu[s]||(cu[s]=new WeakMap);var a=cu[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 d=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))d(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",x=(xa.get(m)||0)+1,b=(a.get(m)||0)+1;xa.set(m,x),a.set(m,b),l.push(m),x===1&&g&&ou.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 d(t),o.clear(),Jf++,function(){l.forEach(function(f){var m=xa.get(f)-1,p=a.get(f)-1;xa.set(f,m),a.set(f,p),m||(ou.has(f)||f.removeAttribute(r),ou.delete(f)),p||f.removeAttribute(s)}),Jf--,Jf||(xa=new WeakMap,xa=new WeakMap,ou=new WeakMap,cu={})}},N1=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=PO(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),DO(r,i,s,"aria-hidden")):function(){return null}},Zs=function(){return Zs=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},Zs.apply(this,arguments)};function S1(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 OO(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 Vu="right-scroll-bar-position",Gu="width-before-scroll-bar",LO="with-scroll-bars-hidden",_O="--removed-body-scroll-bar-size";function Zf(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function FO(e,t){var s=h.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 zO=typeof window<"u"?h.useLayoutEffect:h.useEffect,bb=new WeakMap;function UO(e,t){var s=FO(null,function(r){return e.forEach(function(i){return Zf(i,r)})});return zO(function(){var r=bb.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||Zf(o,null)}),a.forEach(function(o){i.has(o)||Zf(o,l)})}bb.set(s,e)},[e]),s}function BO(e){return e}function WO(e,t){t===void 0&&(t=BO);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 d=l;l=[],d.forEach(a)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(d){l.push(d),u()},filter:function(d){return l=l.filter(d),s}}}};return i}function HO(e){e===void 0&&(e={});var t=WO(null);return t.options=Zs({async:!0,ssr:!1},e),t}var C1=function(e){var t=e.sideCar,s=S1(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 h.createElement(r,Zs({},s))};C1.isSideCarExport=!0;function KO(e,t){return e.useMedium(t),C1}var E1=HO(),em=function(){},Oh=h.forwardRef(function(e,t){var s=h.useRef(null),r=h.useState({onScrollCapture:em,onWheelCapture:em,onTouchMoveCapture:em}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,x=e.inert,b=e.allowPinchZoom,j=e.as,v=j===void 0?"div":j,w=e.gapMode,y=S1(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),N=m,k=UO([s,t]),S=Zs(Zs({},y),i);return h.createElement(h.Fragment,null,d&&h.createElement(N,{sideCar:E1,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:x,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:w}),l?h.cloneElement(h.Children.only(o),Zs(Zs({},S),{ref:k})):h.createElement(v,Zs({},S,{className:c,ref:k}),o))});Oh.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Oh.classNames={fullWidth:Gu,zeroRight:Vu};var VO=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function GO(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=VO();return t&&e.setAttribute("nonce",t),e}function YO(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qO(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var QO=function(){var e=0,t=null;return{add:function(s){e==0&&(t=GO())&&(YO(t,s),qO(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},XO=function(){var e=QO();return function(t,s){h.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},A1=function(){var e=XO(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},JO={left:0,top:0,right:0,gap:0},tm=function(e){return parseInt(e||"",10)||0},ZO=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[tm(s),tm(r),tm(i)]},eL=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return JO;var t=ZO(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])}},tL=A1(),Ya="data-scroll-locked",nL=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(LO,` {
42
+ overflow: hidden `).concat(r,`;
43
+ padding-right: `).concat(o,"px ").concat(r,`;
44
+ }
45
+ body[`).concat(Ya,`] {
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(Vu,` {
59
+ right: `).concat(o,"px ").concat(r,`;
60
+ }
61
+
62
+ .`).concat(Gu,` {
63
+ margin-right: `).concat(o,"px ").concat(r,`;
64
+ }
65
+
66
+ .`).concat(Vu," .").concat(Vu,` {
67
+ right: 0 `).concat(r,`;
68
+ }
69
+
70
+ .`).concat(Gu," .").concat(Gu,` {
71
+ margin-right: 0 `).concat(r,`;
72
+ }
73
+
74
+ body[`).concat(Ya,`] {
75
+ `).concat(_O,": ").concat(o,`px;
76
+ }
77
+ `)},kb=function(){var e=parseInt(document.body.getAttribute(Ya)||"0",10);return isFinite(e)?e:0},sL=function(){h.useEffect(function(){return document.body.setAttribute(Ya,(kb()+1).toString()),function(){var e=kb()-1;e<=0?document.body.removeAttribute(Ya):document.body.setAttribute(Ya,e.toString())}},[])},rL=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;sL();var a=h.useMemo(function(){return eL(i)},[i]);return h.createElement(tL,{styles:nL(a,!t,i,s?"":"!important")})},ig=!1;if(typeof window<"u")try{var uu=Object.defineProperty({},"passive",{get:function(){return ig=!0,!0}});window.addEventListener("test",uu,uu),window.removeEventListener("test",uu,uu)}catch{ig=!1}var va=ig?{passive:!1}:!1,iL=function(e){return e.tagName==="TEXTAREA"},T1=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!iL(e)&&s[t]==="visible")},aL=function(e){return T1(e,"overflowY")},lL=function(e){return T1(e,"overflowX")},Nb=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=R1(e,r);if(i){var a=$1(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},oL=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},cL=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},R1=function(e,t){return e==="v"?aL(t):lL(t)},$1=function(e,t){return e==="v"?oL(t):cL(t)},uL=function(e,t){return e==="h"&&t==="rtl"?-1:1},dL=function(e,t,s,r,i){var a=uL(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,d=l>0,f=0,m=0;do{if(!o)break;var p=$1(e,o),g=p[0],x=p[1],b=p[2],j=x-b-a*g;(g||j)&&R1(e,o)&&(f+=j,m+=g);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(d&&Math.abs(f)<1||!d&&Math.abs(m)<1)&&(u=!0),u},du=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Sb=function(e){return[e.deltaX,e.deltaY]},Cb=function(e){return e&&"current"in e?e.current:e},hL=function(e,t){return e[0]===t[0]&&e[1]===t[1]},fL=function(e){return`
78
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
79
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
80
+ `)},mL=0,ja=[];function pL(e){var t=h.useRef([]),s=h.useRef([0,0]),r=h.useRef(),i=h.useState(mL++)[0],a=h.useState(A1)[0],l=h.useRef(e);h.useEffect(function(){l.current=e},[e]),h.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=OO([e.lockRef.current],(e.shards||[]).map(Cb),!0).filter(Boolean);return x.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=h.useCallback(function(x,b){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!l.current.allowPinchZoom;var j=du(x),v=s.current,w="deltaX"in x?x.deltaX:v[0]-j[0],y="deltaY"in x?x.deltaY:v[1]-j[1],N,k=x.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in x&&S==="h"&&k.type==="range")return!1;var C=window.getSelection(),$=C&&C.anchorNode,R=$?$===k||$.contains(k):!1;if(R)return!1;var I=Nb(S,k);if(!I)return!0;if(I?N=S:(N=S==="v"?"h":"v",I=Nb(S,k)),!I)return!1;if(!r.current&&"changedTouches"in x&&(w||y)&&(r.current=N),!N)return!0;var U=r.current||N;return dL(U,b,x,U==="h"?w:y)},[]),c=h.useCallback(function(x){var b=x;if(!(!ja.length||ja[ja.length-1]!==a)){var j="deltaY"in b?Sb(b):du(b),v=t.current.filter(function(N){return N.name===b.type&&(N.target===b.target||b.target===N.shadowParent)&&hL(N.delta,j)})[0];if(v&&v.should){b.cancelable&&b.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(Cb).filter(Boolean).filter(function(N){return N.contains(b.target)}),y=w.length>0?o(b,w[0]):!l.current.noIsolation;y&&b.cancelable&&b.preventDefault()}}},[]),u=h.useCallback(function(x,b,j,v){var w={name:x,delta:b,target:j,should:v,shadowParent:gL(j)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(y){return y!==w})},1)},[]),d=h.useCallback(function(x){s.current=du(x),r.current=void 0},[]),f=h.useCallback(function(x){u(x.type,Sb(x),x.target,o(x,e.lockRef.current))},[]),m=h.useCallback(function(x){u(x.type,du(x),x.target,o(x,e.lockRef.current))},[]);h.useEffect(function(){return ja.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,va),document.addEventListener("touchmove",c,va),document.addEventListener("touchstart",d,va),function(){ja=ja.filter(function(x){return x!==a}),document.removeEventListener("wheel",c,va),document.removeEventListener("touchmove",c,va),document.removeEventListener("touchstart",d,va)}},[]);var p=e.removeScrollBar,g=e.inert;return h.createElement(h.Fragment,null,g?h.createElement(a,{styles:fL(i)}):null,p?h.createElement(rL,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function gL(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const xL=KO(E1,pL);var _v=h.forwardRef(function(e,t){return h.createElement(Oh,Zs({},e,{ref:t,sideCar:xL}))});_v.classNames=Oh.classNames;var vL=Object.defineProperty,lt=(e,t)=>vL(e,"name",{value:t,configurable:!0}),ag=["Enter"," "],jL=["ArrowDown","PageUp","Home"],I1=["ArrowUp","PageDown","End"],wL=[...jL,...I1],yL={ltr:[...ag,"ArrowRight"],rtl:[...ag,"ArrowLeft"]},bL={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Lh="Menu",[tc,kL,NL]=xh(Lh),[oa,P1]=Fs(Lh,[NL,Ah,Dh]),_h=Ah(),M1=Dh(),[D1,Ci]=oa(Lh),[SL,kc]=oa(Lh),CL=lt(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=_h(t),[c,u]=h.useState(null),d=h.useRef(!1),f=Sn(a),m=Ih(i);return h.useEffect(()=>{const p=lt(()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=lt(()=>d.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})}},[]),h.useEffect(()=>{if(!s)return;const p=lt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),n.jsx(Sv,{...o,children:n.jsx(D1,{scope:t,open:s,onOpenChange:f,content:c,onContentChange:u,children:n.jsx(SL,{scope:t,onClose:h.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:m,modal:l,children:r})})})},"Menu"),O1=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,...i}=t,a=_h(r);return n.jsx(HC,{...a,...i,ref:s})},"MenuAnchor")),L1="MenuPortal",[EL,_1]=oa(L1,{forceMount:void 0}),AL=lt(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=Ci(L1,t);return n.jsx(EL,{scope:t,forceMount:s,children:n.jsx(ur,{present:s||a.open,children:n.jsx(wh,{asChild:!0,container:i,children:r})})})},"MenuPortal"),Ps="MenuContent",[TL,Fv]=oa(Ps),RL=h.forwardRef(lt(function(t,s){const r=_1(Ps,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=Ci(Ps,t.__scopeMenu),o=kc(Ps,t.__scopeMenu);return n.jsx(tc.Provider,{scope:t.__scopeMenu,children:n.jsx(ur,{present:i||l.open,children:n.jsx(tc.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx($L,{...a,ref:s}):n.jsx(IL,{...a,ref:s})})})})},"MenuContent")),$L=h.forwardRef(lt(function(t,s){const r=Ci(Ps,t.__scopeMenu),i=h.useRef(null),a=vt(s,i);return h.useEffect(()=>{const l=i.current;if(l)return N1(l)},[]),n.jsx(zv,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Pe(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),IL=h.forwardRef(lt(function(t,s){const r=Ci(Ps,t.__scopeMenu);return n.jsx(zv,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),PL=fi("MenuContent.ScrollLock"),zv=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:x,...b}=t,j=Ci(Ps,r),v=kc(Ps,r),w=_h(r),y=M1(r),N=kL(r),[k,S]=h.useState(null),C=h.useRef(null),$=vt(s,C,j.onContentChange),R=h.useRef(0),I=h.useRef(""),U=h.useRef(0),z=h.useRef(null),A=h.useRef("right"),P=h.useRef(0),D=x?_v:h.Fragment,O=x?{as:PL,allowPinchZoom:!0}:void 0,M=lt(L=>{var he,Le;const q=I.current+L,B=N().filter(Ie=>!Ie.disabled),V=document.activeElement,F=(he=B.find(Ie=>Ie.ref.current===V))==null?void 0:he.textValue,X=B.map(Ie=>Ie.textValue),Y=Y1(X,q,F),Z=(Le=B.find(Ie=>Ie.textValue===Y))==null?void 0:Le.ref.current;lt(function Ie(ze){I.current=ze,window.clearTimeout(R.current),ze!==""&&(R.current=window.setTimeout(()=>Ie(""),1e3))},"updateSearch")(q),Z&&setTimeout(()=>Z.focus())},"handleTypeaheadSearch");h.useEffect(()=>()=>window.clearTimeout(R.current),[]),Ph();const W=h.useCallback(L=>{var B,V;return A.current===((B=z.current)==null?void 0:B.side)&&Q1(L,(V=z.current)==null?void 0:V.area)},[]);return n.jsx(TL,{scope:r,searchRef:I,onItemEnter:h.useCallback(L=>{W(L)&&L.preventDefault()},[W]),onItemLeave:h.useCallback(L=>{var q;W(L)||((q=C.current)==null||q.focus(),S(null))},[W]),onTriggerLeave:h.useCallback(L=>{W(L)&&L.preventDefault()},[W]),pointerGraceTimerRef:U,onPointerGraceIntentChange:h.useCallback(L=>{z.current=L},[]),children:n.jsx(D,{...O,children:n.jsx(a1,{asChild:!0,trapped:a,onMountAutoFocus:Pe(l,L=>{var q;L.preventDefault(),(q=C.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(jh,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(y1,{asChild:!0,...y,dir:v.dir,orientation:"vertical",loop:i,currentTabStopId:k,onCurrentTabStopIdChange:S,onEntryFocus:Pe(u,L=>{v.isUsingKeyboardRef.current||L.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(KC,{role:"menu","aria-orientation":"vertical","data-state":Uv(j.open),"data-radix-menu-content":"",dir:v.dir,...w,...b,ref:$,style:{outline:"none",...b.style},onKeyDown:Pe(b.onKeyDown,L=>{const B=L.target.closest("[data-radix-menu-content]")===L.currentTarget,V=L.ctrlKey||L.altKey||L.metaKey,F=L.key.length===1;B&&(L.key==="Tab"&&L.preventDefault(),!V&&F&&M(L.key));const X=C.current;if(L.target!==X||!wL.includes(L.key))return;L.preventDefault();const Z=N().filter(he=>!he.disabled).map(he=>he.ref.current);I1.includes(L.key)&&Z.reverse(),V1(Z)}),onBlur:Pe(t.onBlur,L=>{L.currentTarget.contains(L.target)||(window.clearTimeout(R.current),I.current="")}),onPointerMove:Pe(t.onPointerMove,al(L=>{const q=L.target,B=P.current!==L.clientX;if(L.currentTarget.contains(q)&&B){const V=L.clientX>P.current?"right":"left";A.current=V,P.current=L.clientX}}))})})})})})})},"MenuContentImpl")),F1=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(pt.div,{role:"group",...i,ref:s})},"MenuGroup")),ML=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(pt.div,{...i,ref:s})},"MenuLabel")),lg="MenuItem",Eb="menu.itemSelect",z1=h.forwardRef(lt(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=h.useRef(null),o=kc(lg,t.__scopeMenu),c=Fv(lg,t.__scopeMenu),u=vt(s,l),d=h.useRef(!1),f=lt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(Eb,{bubbles:!0,cancelable:!0});m.addEventListener(Eb,g=>i==null?void 0:i(g),{once:!0}),vh(m,p),p.defaultPrevented?d.current=!1:o.onClose()}},"handleSelect");return n.jsx(U1,{...a,ref:u,disabled:r,onClick:Pe(t.onClick,f),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),d.current=!0},onPointerUp:Pe(t.onPointerUp,m=>{var p;d.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Pe(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||ag.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),U1=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=Fv(lg,r),c=M1(r),u=h.useRef(null),d=vt(s,u),[f,m]=h.useState(!1),[p,g]=h.useState("");return h.useEffect(()=>{const x=u.current;x&&g((x.textContent??"").trim())},[l.children]),n.jsx(tc.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(b1,{asChild:!0,...c,focusable:!i,children:n.jsx(pt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:d,onPointerMove:Pe(t.onPointerMove,al(x=>{i?o.onItemLeave(x):(o.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Pe(t.onPointerLeave,al(x=>o.onItemLeave(x))),onFocus:Pe(t.onFocus,()=>m(!0)),onBlur:Pe(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),DL="MenuRadioGroup",[OL,LL]=oa(DL,{value:void 0,onValueChange:lt(()=>{},"onValueChange")}),_L=h.forwardRef(lt(function(t,s){const{value:r,onValueChange:i,...a}=t,l=Sn(i);return n.jsx(OL,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(F1,{...a,ref:s})})},"MenuRadioGroup")),FL="MenuRadioItem",zL=h.forwardRef(lt(function(t,s){const{value:r,...i}=t,a=LL(FL,t.__scopeMenu),l=r===a.value;return n.jsx(BL,{scope:t.__scopeMenu,checked:l,children:n.jsx(z1,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":K1(l),onSelect:Pe(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),UL="MenuItemIndicator",[BL,jQ]=oa(UL,{checked:!1}),WL=h.forwardRef(lt(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(pt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),B1="MenuSub",[HL,W1]=oa(B1),KL=lt(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=Ci(B1,t),l=_h(t),[o,c]=h.useState(null),[u,d]=h.useState(null),f=Sn(i);return h.useEffect(()=>(a.open===!1&&f(!1),()=>f(!1)),[a.open,f]),n.jsx(Sv,{...l,children:n.jsx(D1,{scope:t,open:r,onOpenChange:f,content:u,onContentChange:d,children:n.jsx(HL,{scope:t,contentId:Is(),triggerId:Is(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),hu="MenuSubTrigger",VL=h.forwardRef(lt(function(t,s){const r=Ci(hu,t.__scopeMenu),i=kc(hu,t.__scopeMenu),a=W1(hu,t.__scopeMenu),l=Fv(hu,t.__scopeMenu),o=h.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,d={__scopeMenu:t.__scopeMenu},f=h.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);h.useEffect(()=>f,[f]),h.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=vt(s,a.onTriggerChange);return n.jsx(O1,{asChild:!0,...d,children:n.jsx(U1,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":Uv(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:Pe(t.onPointerMove,al(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:Pe(t.onPointerLeave,al(p=>{var x,b;f();const g=(x=r.content)==null?void 0:x.getBoundingClientRect();if(g){const j=(b=r.content)==null?void 0:b.dataset.side,v=j==="right",w=v?-5:5,y=g[v?"left":"right"],N=g[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:g.top},{x:N,y:g.top},{x:N,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:Pe(t.onKeyDown,p=>{var x;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||yL[i.dir].includes(p.key)&&(r.onOpenChange(!0),(x=r.content)==null||x.focus(),p.preventDefault())})})})},"MenuSubTrigger")),GL="MenuSubContent",YL=h.forwardRef(lt(function(t,s){const r=_1(Ps,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=Ci(Ps,t.__scopeMenu),c=kc(Ps,t.__scopeMenu),u=W1(GL,t.__scopeMenu),d=h.useRef(null),f=vt(s,d);return n.jsx(tc.Provider,{scope:t.__scopeMenu,children:n.jsx(ur,{present:i||o.open,children:n.jsx(tc.Slot,{scope:t.__scopeMenu,children:n.jsx(zv,{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=d.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Pe(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Pe(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Pe(t.onKeyDown,m=>{var x;const p=m.currentTarget.contains(m.target),g=bL[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(x=u.trigger)==null||x.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function Uv(e){return e?"open":"closed"}lt(Uv,"getOpenState");function H1(e){return e==="indeterminate"}lt(H1,"isIndeterminate");function K1(e){return H1(e)?"indeterminate":e?"checked":"unchecked"}lt(K1,"getCheckedState");function V1(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}lt(V1,"focusFirst");function G1(e,t){return e.map((s,r)=>e[(t+r)%e.length])}lt(G1,"wrapArray");function Y1(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=G1(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}lt(Y1,"getNextMatch");function q1(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,d=o.y,f=c.x,m=c.y;d>r!=m>r&&s<(f-u)*(r-d)/(m-d)+u&&(i=!i)}return i}lt(q1,"isPointInPolygon");function Q1(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return q1(s,t)}lt(Q1,"isPointerInGraceArea");function al(e){return t=>t.pointerType==="mouse"?e(t):void 0}lt(al,"whenMouse");var qL=CL,QL=O1,XL=AL,JL=RL,ZL=F1,e_=ML,t_=z1,n_=_L,s_=zL,r_=WL,i_=KL,a_=VL,l_=YL,o_=Object.defineProperty,ns=(e,t)=>o_(e,"name",{value:t,configurable:!0}),Bv="DropdownMenu",[c_,wQ]=Fs(Bv,[P1]),ss=P1(),[u_,X1]=c_(Bv),d_=ns(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=ss(t),u=h.useRef(null),[d,f]=Ni({prop:i,defaultProp:a??!1,onChange:l,caller:Bv});return n.jsx(u_,{scope:t,triggerId:Is(),triggerRef:u,contentId:Is(),open:d,onOpenChange:f,onOpenToggle:h.useCallback(()=>f(m=>!m),[f]),modal:o,children:n.jsx(qL,{...c,open:d,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),h_="DropdownMenuTrigger",f_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=X1(h_,r),o=ss(r),c=vt(s,l.triggerRef);return n.jsx(QL,{asChild:!0,...o,children:n.jsx(pt.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:Pe(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Pe(t.onKeyDown,u=>{i||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),m_=ns(e=>{const{__scopeDropdownMenu:t,...s}=e,r=ss(t);return n.jsx(XL,{...r,...s})},"DropdownMenuPortal"),p_="DropdownMenuContent",g_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=X1(p_,r),l=ss(r),o=h.useRef(!1);return n.jsx(JL,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Pe(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Pe(t.onInteractOutside,c=>{const u=c.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!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")),x_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(ZL,{...a,...i,ref:s})},"DropdownMenuGroup")),v_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(e_,{...a,...i,ref:s})},"DropdownMenuLabel")),j_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(t_,{...a,...i,ref:s})},"DropdownMenuItem")),w_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(n_,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),y_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(s_,{...a,...i,ref:s})},"DropdownMenuRadioItem")),b_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(r_,{...a,...i,ref:s})},"DropdownMenuSeparator")),k_=ns(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=ss(t),[o,c]=Ni({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(i_,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),N_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(a_,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),S_=h.forwardRef(ns(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=ss(r);return n.jsx(l_,{...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")),Nc=d_,Sc=f_,Cl=m_,Cc=g_,J1=x_,ta=v_,ds=j_,C_=w_,E_=y_,Nr=b_,A_=k_,T_=N_,R_=S_,$_=Object.defineProperty,El=(e,t)=>$_(e,"name",{value:t,configurable:!0}),Wv="Tabs",[I_,yQ]=Fs(Wv,[Dh]),Z1=Dh(),[P_,Hv]=I_(Wv),M_=h.forwardRef(El(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...d}=t,f=Ih(c),[m,p]=Ni({prop:i,onChange:a,defaultProp:l??"",caller:Wv});return n.jsx(P_,{scope:r,baseId:Is(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:n.jsx(pt.div,{dir:f,"data-orientation":o,...d,ref:s})})},"Tabs")),D_="TabsList",O_=h.forwardRef(El(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=Hv(D_,r),o=Z1(r);return n.jsx(y1,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(pt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),L_="TabsTrigger",__=h.forwardRef(El(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=Hv(L_,r),c=Z1(r),u=Kv(o.baseId,i),d=Vv(o.baseId,i),f=i===o.value;return n.jsx(b1,{asChild:!0,...c,focusable:!a,active:f,children:n.jsx(pt.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":d,"data-state":f?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Pe(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Pe(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Pe(t.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),F_="TabsContent",z_=h.forwardRef(El(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=Hv(F_,r),u=Kv(c.baseId,i),d=Vv(c.baseId,i),f=i===c.value,m=h.useRef(f);return h.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(ur,{present:a||f,children:({present:p})=>n.jsx(pt.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:d,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function Kv(e,t){return`${e}-trigger-${t}`}El(Kv,"makeTriggerId");function Vv(e,t){return`${e}-content-${t}`}El(Vv,"makeContentId");var U_=M_,B_=O_,W_=__,H_=z_;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)?K_(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${Ab(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Vt(r):Ab(r):String(e)}case"date":return V_(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 K_(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return aO(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function V_(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?$h(t[0],{year:!0,compact:!0}):e}function og(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?$h(t[0],{compact:!0}):e}function Ab(e){return String(Math.round(e*100)/100)}function Id(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 G_({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 Y_=/^(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 )/,q_=/^(… |\.\.\. |\(no change\)$|\)/;function Q_(e){return e.replace(/\n$/,"").split(`
81
+ `).map(s=>({kind:X_(s),text:s}))}function X_(e){return e.startsWith("@@")?"hunk":Y_.test(e)||q_.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function J_({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 Pd({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=Q_(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(J_,{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 Z_({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(Pd,{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 nn="#/",Fh="#/needs",ci="#/chat",Ct="#/agents",xt="#/activity",Zt="#/settings",Or="#/files",eF="#/welcome";function Yu(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function fu(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`${Or}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function tF(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 tt(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function nF(e){if(eE(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 Oi(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function eE(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 Et(e,t,s){return`${Ct}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function sF(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 ll(e){return`${xt}/conversations/${encodeURIComponent(e)}`}const rF="#/p";function lr(e,t,s){const r=`${rF}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Gv(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 iF="p.";function gi(e,t,s){const r=s?new URLSearchParams(s).toString():"";return`${Zt}/${encodeURIComponent(nE(e,t))}${r?`?${r}`:""}`}function tE(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 aF(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 nE(e,t){return`${iF}${e}${t===e?"":`.${t}`}`}function Oe(e){return e?`${Zt}/${e}`:Zt}function sE(e){return`${Oe("accounts")}?account=${encodeURIComponent(e)}`}function lF(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function Yv(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 rE(e){return`${Oe("connections")}?connection=${encodeURIComponent(e)}`}function oF(e){return Yv(e,"connections","connection")}function cF(e){return Yv(e,"secrets","secret")}const Tb=`${Oe("secrets")}?add=1`;function uF(e){return Yv(e,"secrets","add")==="1"}function dF(e){return`${Oe("plugins")}?install=${encodeURIComponent(e)}`}const hF=`${Oe("plugins")}?tab=browse`;function fF(e){return`${Oe("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function mF(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function iE(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function pF(e){var s,r;const t=(r=(s=iE(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Rb(e){const t=iE(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const gF=[{route:nn,label:"Home"},{route:ci,label:"Chat"},{route:Ct,label:"Agents"},{route:xt,label:"Activity"},{route:Or,label:"Files"},{route:Zt,label:"Settings"}],xF=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],vF=[{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 jF(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const cg="#/settings/notifications/recent",ug=Oe("backup");function wF(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return ll(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return lr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return lr("email","mail")}return e==="#/settings/email"?gi("email","settings"):{"#/overview":nn,"#/approvals":nn,"#/events":`${xt}/events`,"#/jobs":`${xt}/jobs`,"#/conversations":xt,"#/missions":`${Ct}?tab=missions`,"#/offers":`${Ct}?tab=offers`,"#/reminders":`${Ct}?tab=reminders`,"#/providers":Oe("accounts"),"#/browser":Oe("computer"),"#/sentinels":Oe("watchers"),"#/settings/sentinels":Oe("watchers")}[e]??null}function aE(e){if(e===""||e==="#"||e===nn)return nn;if(e.startsWith(ci))return ci;if(e.startsWith(Ct))return Ct;if(e.startsWith(xt))return xt;if(e.startsWith(Or))return Or;if(e.startsWith(Zt))return Zt;const t=Gv(e);return t?lr(t.plugin,t.page):nn}const yF="#/chat?group=new";function bF(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 qv="front-desk",Qv=[{id:qv,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."}],lE=new Set(Qv.map(e=>e.id)),$b=e=>lE.has(e);function Ib(e,t){const s=t.filter(r=>!lE.has(r));return[...Qv.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function kF(e,t){return e.find(s=>(s.roles??[]).includes(t))}const Pb=["coding","finance","mail","research","calendar","files","memory"],NF={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[qv]:"buddi"},SF=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function CF(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of SF)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let dg=null;function EF(e){dg=e}function Ec(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=NF[s];if(r)return{key:r}}const t=CF(e.tools??[]);return t?{key:t}:dg!==null&&e.id===dg?{key:"buddi"}:{key:Pb[AF(e.id)%Pb.length]??"coding"}}function Ac(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function AF(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const TF=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function RF(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 d=u.indexOf(":"),f=d===-1?u:u.slice(0,d),m=d===-1?"":u.slice(d+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:TF.includes(o)?o:"ping",data:$F(c.join(`
86
+ `))})}return{events:i,rest:r}}function $F(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function zh(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(d=>setTimeout(d,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,d,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}`);(d=e.onStatus)==null||d.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const x=g.body.getReader(),b=new TextDecoder;let j="";for(;;){const{done:v,value:w}=await x.read();if(v)break;j+=b.decode(w,{stream:!0});const{events:y,rest:N}=RF(j);j=N;for(const k of y)e.onEvent(k),k.id!==null&&(i=k.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const Xv="0.1.0+d05a46e";function Jv(e,t=Xv){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function IF(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const PF=5*6e4,MF=6e4,DF=5e3,nc="buddi:stream-reconnected",oE="buddi.autoReloadedFor";function OF(){window.dispatchEvent(new Event(nc))}const Mb=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let Zv=Date.now(),mu=0;const Db=()=>{Zv=Date.now()};function LF(){if(mu===0){Zv=Date.now();for(const e of Mb)window.addEventListener(e,Db,{capture:!0,passive:!0})}return mu+=1,()=>{if(mu-=1,mu===0)for(const e of Mb)window.removeEventListener(e,Db,{capture:!0})}}function _F(e=Date.now()){return e-Zv}function cE(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 FF(e){return e.hidden?!0:e.idleMs>=MF&&!e.busy}function zF(e){try{return window.sessionStorage.getItem(oE)===e}catch{return!1}}function UF(e){try{window.sessionStorage.setItem(oE,e)}catch{}}function BF(e){const t=h.useRef(e);t.current=e,h.useEffect(()=>{const s=()=>t.current();return window.addEventListener(nc,s),()=>window.removeEventListener(nc,s)},[])}function WF(e,t=()=>window.location.reload(),s=Xv){const r=Jv(e,s),i=h.useRef(t);i.current=t,h.useEffect(()=>LF(),[]),h.useEffect(()=>{if(!r||e===void 0||zF(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";FF({hidden:c,idleMs:_F(),busy:cE()})&&(a=!0,UF(e),i.current())};l();const o=window.setInterval(l,DF);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const HF=9e4,uE=5*6e4,KF=500,VF=2e3,GF=3e3,YF="/_buddi/ready",qa={reload:()=>window.location.reload(),now:()=>Date.now()};let xi=null,La=null,uo=null;const hg=new Set;function Md(e){xi=e;for(const t of hg)t()}function Ob(){return xi}function qF(e){return hg.add(e),()=>hg.delete(e)}function QF(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(t=>t.toString(16).padStart(2,"0")).join("")}async function ej(e=GF){const t=new AbortController,s=setTimeout(()=>t.abort(),e);try{const r=await fetch(`${YF}?challenge=${QF()}`,{cache:"no-store",credentials:"omit",redirect:"error",signal:t.signal,headers:{Accept:"application/json"}});if(r.status!==200)return null;const i=await r.json().catch(()=>null);return typeof(i==null?void 0:i.boot)=="string"?i.boot:""}catch{return null}finally{clearTimeout(s)}}async function XF(){const e=await ej();e&&(La=e)}function JF(){let e=La,t=!1,s=!1,r=KF,i;const a=async()=>{if(t)return;const l=await ej();if(!t){if(l===null)s=!0;else if(e!==null?l!==e:s){t=!0,qa.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),VF),i=setTimeout(()=>void a(),r)}};return i=setTimeout(()=>void a(),r),()=>{t=!0,clearTimeout(i)}}function Uh(e){if(xi){if(e.kind==="detected")return;Md({...xi,...e});return}Md({...e,startedAt:qa.now()}),uo=JF()}function dE(e){xi&&Md({...xi,...e})}function ol(){uo==null||uo(),uo=null,Md(null)}async function Bh(e,t){Uh(e);try{return await t()}catch(s){if($d(s))return;throw ol(),s}}function ZF(e){Uh({kind:e.for==="stop"?"stop":"detected"})}async function Lb(){if(xi)return;const e=await ej();if(La===null){e&&(La=e);return}if(!(!e||e===La||xi)){if(cE()){La=e;return}Uh({kind:"detected"})}}function e4(e){const[t,s]=e;if(!t)return null;const r=`${t.name} ${t.version}`;return s?e.length===2?`${r} and ${s.name} ${s.version}`:`${r} and ${e.length-1} more`:r}const t4="/api/chat/attention/stream";function hE(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 fE(e,t){const s=hE(e,t);return[...s.top,...s.middle,...s.bottom]}function Wh(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 n4(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 s4(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function r4(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function i4(){const[e,t]=h.useState(null);return h.useEffect(()=>{let s=!1;const r=()=>{ge("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=zh({url:t4,onEvent:a=>a.name==="closing"?ZF(a.data):r(),onReconnect:OF});return()=>{s=!0,i.close()}},[]),r4(e)}const Hh="maker";function tj(e){return e.filter(t=>t.available&&!t.roles.includes(Hh))}function mE(e){return tj(e).length>=2}function a4(e){var t;return((t=e.find(s=>s.roles.includes(Hh)))==null?void 0:t.name)??"the agent maker"}const l4="{{default}}";function o4(e,t){return e.split(l4).join(t??"your assistant")}function c4(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>o4(s,t))}function u4(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 d4(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 pE(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 h4="Settings → Model accounts",f4="Install it in Settings → Plugins";function fg(e){return e!=null&&e.heldBack?{section:"plugins",label:f4}:{section:"accounts",label:h4}}const m4={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"})],"moon-cloud":[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M9.4 6.8A3.6 3.6 0 0 1 4.6 2a3.6 3.6 0 1 0 4.8 4.8Z"}),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"})]})],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 ue({name:e,size:t,className:s,...r}){const[i,a,l,o]=m4[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 gE="buddi.rosterCollapsed";function p4(){try{return window.localStorage.getItem(gE)==="1"}catch{return!1}}function g4(e){try{window.localStorage.setItem(gE,e?"1":"0")}catch{}}function xE({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:d}){const f=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=h.useState(p4),x=b=>n.jsx(x4,{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(x),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(x),u&&mE(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"}),d?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:d,children:n.jsx(ue,{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 v=f.find(w=>w.id===j);return n.jsx(Kh,{className:"wb-group-chip",id:j,name:(v==null?void 0:v.name)??"?",face:v,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 v;return((v=f.find(w=>w.id===j))==null?void 0:v.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:Ct,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(x),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=>(g4(!b),!b)),children:n.jsx(ue,{name:p?"chevron-right":"chevron-left"})}):null]})}function x4({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=Wh(s),c=n4(s)??(e.available?a?iO(a):e.description:e.unavailableReason??"Cannot run right now"),u=s4(s,l&&e.available),d=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(Go,{children:[n.jsx(Yo,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Ac(Ec(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(Kh,{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(ue,{name:"out"})})]})}),n.jsx(qo,{children:n.jsxs(Qo,{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}`:d}),o?n.jsx("span",{className:"ui-tip-alert",children:v4(o)}):null]})})]})}function v4(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function j4(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const w4="modulepreload",y4=function(e,t){return new URL(e,t).href},_b={},b4=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=y4(u,r),u in _b)return;_b[u]=!0;const d=u.endsWith(".css"),f=d?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const x=l[g];if(x.href===u&&(!d||x.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=d?"stylesheet":w4,d||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),d)return new Promise((g,x)=>{p.addEventListener("load",g),p.addEventListener("error",()=>x(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)})},k4="buddi",N4=["core","coding","finance","garage","mail","maker","playground","research"],ca=e=>`./mascot/${e}.png`,S4=["core"],mg=(e,t)=>S4.includes(e)?`./mascot/anim/${e}-${t}.json`:null,C4=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],E4="Introduce yourself by name and say one thing you can do today.",A4=["Hello","A brain","What I take on","Reach me","Your assistant"],Zl=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,nm=e=>e.charAt(0).toUpperCase()+e.slice(1),T4=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Qa=[{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."}],R4=["days","mail"],Fb=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],_={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:A4,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 ${Zl(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${Zl(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":nm(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":nm(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: ${Zl(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 ${Zl(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=>`${T4[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${nm(Zl(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 pu=null;const zb=new Map;function $4(){return pu??(pu=b4(()=>import("./lottie_light-DU37j1-6.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),pu.catch(()=>{pu=null}),pu}function I4(e){let t=zb.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),zb.set(e,t)),t}const Ub="(prefers-reduced-motion: reduce)";function vE(){const[e,t]=h.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(Ub).matches);return h.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(Ub),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 Tc({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=h.useRef(null),o=vE(),[c,u]=h.useState(!1),d=s==="xs"?null:mg(e,t);return h.useEffect(()=>{if(u(!1),!o||!d)return;let f=!1,m=null;return Promise.all([$4(),I4(d)]).then(([p,g])=>{if(f||!g||!l.current)return;const x=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?x.pause():x.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),x.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[o,d]),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??ca(e),alt:"",onError:a})})}async function Bb(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 jE(e,t="core"){const s=vE(),r=e!==null&&P4(e,t),[i,a]=h.useState(!1);return h.useEffect(()=>{if(a(!1),!e||r||!s||!mg(t,"idle"))return;let l=!1;return Promise.all([Bb(e),Bb(ca(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((d,f,m)=>d+Math.abs(f-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&mg(t,"idle")!==null&&(r||i)}function P4(e,t){const s=ca(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 Kh({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=h.useState(null),d=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=d?"image":f==null?void 0:f.kind,p=t?Ac(Ec({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:d?n.jsx("img",{src:d,alt:"",onError:()=>u(d)}):(f==null?void 0:f.kind)==="image"?n.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:d4(s).slice(0,o)})}function Us({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(Kh,{className:"ui-avatar",id:e,tint:j4(e),name:t,size:s,unavailable:r,face:i})}function ln({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Us,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const wE=h.createContext(null);function M4({picture:e,children:t}){return n.jsx(wE.Provider,{value:e??null,children:t})}function yE({size:e,anim:t}){const s=h.useContext(wE),[r,i]=h.useState(null),a=jE(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(Tc,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const bE=h.createContext([]);function Lr({text:e,className:t}){const s=pg(e.replace(/\r\n/g,`
88
+ `).split(`
89
+ `));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(gg,{block:r},i))})}const Wb=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Hb=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Kb=/^\s*([-*_])(\s*\1){2,}\s*$/,gu=/^(\s*)([-*+])\s+(.*)$/,eo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,xu=/^\s*>\s?(.*)$/,sm=/^\s*\|.*\|\s*$/,Vb=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function pg(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Wb.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=Hb.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Kb.test(r)){t.push({type:"hr"}),s+=1;continue}if(xu.test(r)){const o=[];for(;s<e.length&&xu.test(e[s]);)o.push(xu.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:pg(o),raw:o.join(`
91
+ `)});continue}if(sm.test(r)&&s+1<e.length&&Vb.test(e[s+1])){const o=im(r),c=im(e[s+1]).map(d=>{const f=d.startsWith(":"),m=d.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&sm.test(e[s]);)u.push(im(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(gu.test(r)||eo.test(r)){const o=eo.exec(r)??gu.exec(r),c=eo.test(r),u=o[1].length,d=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?eo.exec(e[s]):gu.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],x=g.trim()!==""&&rm(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&rm(e[s+1])>u;if(!x&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(rm(g),u+2))),s+=1}f.push(pg(p))}t.push({type:"list",ordered:c,start:d,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||Wb.test(o)||Hb.test(o)||Kb.test(o)||xu.test(o)||gu.test(o)||eo.test(o)||sm.test(o)&&s+1<e.length&&Vb.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 rm(e){return e.length-e.trimStart().length}function im(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 gg({block:e}){switch(e.type){case"p":return n.jsx("p",{children:Ts(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:Ts(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(Gb,{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(gg,{block:t},s))}),n.jsx(Gb,{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(h.Fragment,{children:Ts(i.text)},a):n.jsx(gg,{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:Ts(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:Ts(r)},i))},s))})]})})}}function Gb({text:e,what:t,always:s=!1}){const[r,i]=h.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 D4({handle:e}){const s=h.useContext(bE).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(Go,{children:[n.jsx(Yo,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:tt(s.id),children:["@",s.handle]})}),n.jsx(qo,{children:n.jsxs(Qo,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Us,{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 O4=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 Ts(e){const t=[];let s=e,r=0;for(;s!=="";){const i=O4.exec(s);if(!i){t.push(...Yb(s,r));break}i.index>0&&t.push(...Yb(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:Ts(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:Ts(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:Ts(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:Ts(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:Ts(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:Ts(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(D4,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function Yb(e,t){return e.split(`
93
+ `).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function L4({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(Lr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const _4=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear","check","clock","moon-cloud"];function Ne(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 Ve(e,t){if(t)return"const"in t?t.const:Ne(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 dt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function ui(e){return Array.isArray(e)?e:[]}function F4(e,t){const s=ui(Ne(e,t.points)).map(i=>{const a=Qn(Ne(i,t.y)),l=dt(Ne(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(Ve(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:dt(Ve(e,t.currency)),label:dt(Ve(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:Qn(Ve(e,t.shadeBelow)),events:z4(e,t)}}function z4(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=dt(Ne(a,s.label));if(o===null)return;const c=dt(Ne(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Qn(Ne(a,s.amount)):null})};if(s.parent){for(const a of ui(Ne(e,t.points))){const l=dt(Ne(a,t.x));for(const o of ui(Ne(a,s.parent)))i(o,l)}return r}for(const a of ui(Ne(e,s.path??t.points)))i(a,null);return r}function U4(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=Ne(o,c.key);let d=null;if(c.bar){const f=Qn(Ve(o,c.bar.max))??Qn(Ve(e,c.bar.max)),m=Qn(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));d={fraction:p,tone:W4(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:dt(Ve(o,c.currency))??dt(Ve(e,c.currency)),bar:d}}),i=ui(Ne(e,t.rows)),a=t.groupBy?B4(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:Ve(e,o.value),unit:o.unit??"text",currency:dt(Ve(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function B4(e,t,s){const r=new Map;for(const i of e){const a=String(Ne(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 W4(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 H4(e,t){return{bars:ui(Ne(e,t.bars)).map(r=>{const i=Qn(Ne(r,t.value)),a=dt(Ne(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:dt(Ve(e,t.currency))}}function K4(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text",currency:dt(Ve(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ne(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:xn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const V4=new Set(["good","warning","critical","neutral","accent"]),G4=new Set(_4);function xg(e){return typeof e=="string"&&G4.has(e)?e:null}function nj(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=dt(Ne(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:xg(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:ui(Ne(e,t.items)).map(l=>{const o=dt(Ne(l,t.value))??"",c=dt(Ne(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?dt(Ne(l,t.tone)):null;return{icon:xg(Ve(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(d=>dt(Ne(l,d))).filter(d=>d!==null&&d.trim()!==""),tone:u!==null&&V4.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function Y4(e,t){const s=dt(Ve(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?dt(Ne(e,t.src)):null;return{kind:r,text:t.text?dt(Ne(e,t.text)):null,src:i&&NE(i)?i:null,title:dt(Ve(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Ve(e,a.value),unit:a.unit??"text"}))}}function q4(e,t){const s=t.diff?Ne(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:dt(Ve(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text"}))}}function Q4(e,t){const s=t.output?Ne(e,t.output):void 0,r=l=>{const o=l?Ne(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?Ne(e,t.elapsedMs):void 0;return{command:dt(Ve(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:Ve(e,l.value),unit:l.unit??"text"}))}}const X4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function kE(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&X4.test(t)?t.toLowerCase():null}function J4(e,t){return{artifactId:t.src?kE(Ne(e,t.src)):null,title:dt(Ve(e,t.title)),caption:dt(Ve(e,t.caption)),...t.captionLabel?{captionLabel:dt(Ve(e,t.captionLabel))}:{}}}function qb(e){if(!NE(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 Z4(e,t){const s=t.src?dt(Ne(e,t.src)):null,r=t.port?Ne(e,t.port):null,i=t.awaiting?dt(Ne(e,t.awaiting)):null;return{target:s?qb(s):null,title:dt(Ve(e,t.title)),output:t.output?dt(Ne(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?qb(i):null,reloadsItself:t.reloadsItself?Ne(e,t.reloadsItself)===!0:!1,ports:t.ports?ez(Ne(e,t.ports)):[]}}function ez(e){const t=ui(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function NE(e){return e.startsWith("/")&&!e.startsWith("//")}function xn(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 SE(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:F4(t,s)};case"table":return{renderer:"table",props:U4(t,s)};case"bars":return{renderer:"bars",props:H4(t,s)};case"keyvalue":return{renderer:"keyvalue",props:K4(t,s)};case"tiles":return{renderer:"tiles",props:nj(t,s,e.tool)};case"document":return{renderer:"document",props:Y4(t,s)};case"diff":return{renderer:"diff",props:q4(t,s)};case"terminal":return{renderer:"terminal",props:Q4(t,s)};case"image":return{renderer:"image",props:J4(t,s)};case"preview":return{renderer:"preview",props:Z4(t,s)};default:return{renderer:"structured",props:{value:t}}}}var tz=Object.defineProperty,ws=(e,t)=>tz(e,"name",{value:t,configurable:!0}),sj="Dialog",[CE,bQ]=Fs(sj),[nz,hr]=CE(sj),Vh=ws(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=h.useRef(null),c=h.useRef(null),[u,d]=Ni({prop:r,defaultProp:i??!1,onChange:a,caller:sj}),[f,m]=h.useState(0),[p,g]=h.useState(0);return n.jsx(nz,{scope:t,triggerRef:o,contentRef:c,contentId:Is(),titleId:Is(),descriptionId:Is(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:d,onOpenToggle:h.useCallback(()=>d(x=>!x),[d]),modal:l,children:s})},"Dialog"),sz="DialogTrigger",rz=h.forwardRef(ws(function(t,s){const{__scopeDialog:r,...i}=t,a=hr(sz,r),l=vt(s,a.triggerRef);return n.jsx(pt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Qh(a.open),...i,ref:l,onClick:Pe(t.onClick,a.onOpenToggle)})},"DialogTrigger")),EE="DialogPortal",[iz,AE]=CE(EE,{forceMount:void 0}),Gh=ws(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=hr(EE,t);return n.jsx(iz,{scope:t,forceMount:s,children:h.Children.map(r,l=>n.jsx(ur,{present:s||a.open,children:n.jsx(wh,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),vg="DialogOverlay",rj=h.forwardRef(ws(function(t,s){const r=AE(vg,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=hr(vg,t.__scopeDialog);return l.modal?n.jsx(ur,{present:i||l.open,children:n.jsx(lz,{...a,ref:s})}):null},"DialogOverlay")),az=fi("DialogOverlay.RemoveScroll"),lz=h.forwardRef(ws(function(t,s){const{__scopeDialog:r,...i}=t,a=hr(vg,r),l=uC(),o=vt(s,l);return n.jsx(_v,{as:az,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(pt.div,{"data-state":Qh(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),sc="DialogContent",Yh=h.forwardRef(ws(function(t,s){const r=AE(sc,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=hr(sc,t.__scopeDialog);return n.jsx(ur,{present:i||l.open,children:l.modal?n.jsx(oz,{...a,ref:s}):n.jsx(cz,{...a,ref:s})})},"DialogContent")),oz=h.forwardRef(ws(function(t,s){const r=hr(sc,t.__scopeDialog),i=h.useRef(null),a=vt(s,r.contentRef,i);return h.useEffect(()=>{const l=i.current;if(l)return N1(l)},[]),n.jsx(TE,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Pe(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Pe(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Pe(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),cz=h.forwardRef(ws(function(t,s){const r=hr(sc,t.__scopeDialog),i=h.useRef(!1),a=h.useRef(!1);return n.jsx(TE,{...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,d;(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;((d=r.triggerRef.current)==null?void 0:d.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),TE=h.forwardRef(ws(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=hr(sc,r);return Ph(),n.jsx(n.Fragment,{children:n.jsx(a1,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(jh,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Qh(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),uz="DialogTitle",qh=h.forwardRef(ws(function(t,s){const{__scopeDialog:r,...i}=t,a=hr(uz,r),{setTitleCount:l}=a;return Ln(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(pt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),dz="DialogClose",ij=h.forwardRef(ws(function(t,s){const{__scopeDialog:r,...i}=t,a=hr(dz,r);return n.jsx(pt.button,{type:"button",...i,ref:s,onClick:Pe(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function Qh(e){return e?"open":"closed"}ws(Qh,"getState");const hz=5;function ce(e,t,s){const[r,i]=h.useState(void 0),[a,l]=h.useState(null),[o,c]=h.useState(!0),[u,d]=h.useState(0),[f,m]=h.useState(0),p=h.useRef(e);return p.current=e,h.useEffect(()=>{let g=!1;return c(!0),p.current().then(x=>{g||(i(x),l(null),m(0))}).catch(x=>{g||(l(x instanceof pe?x.message:String(x)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),h.useEffect(()=>{if(!s||f>=hz)return;const g=window.setTimeout(()=>d(x=>x+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:a,loading:o,reload:()=>{m(0),d(g=>g+1)}}}const RE={width:480,height:160,top:10,right:10,bottom:22,left:40},$E={width:1200,height:180,top:10,right:40,bottom:22,left:40};function fz({xs:e,series:t}){const s=$E,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=z=>z.filter(A=>A!==null&&Number.isFinite(A)),l=t.filter(z=>z.type!=="bar"),o=t.filter(z=>z.type==="bar"),c=l.flatMap(z=>a(z.values)),u=c.length>0?Math.min(...c):0,d=c.length>0?Math.max(...c):1;let f=u,m=d;if(f===m)f-=1,m+=1;else{const z=(m-f)*.08;f-=z,m+=z}const p=z=>hs(s.top+i-(z-f)/(m-f)*i),g=o.length>0&&o.every(z=>z.unit==="percent"),x=g?100:Math.max(1,...o.flatMap(z=>a(z.values))),b=z=>hs(s.top+i-Math.max(0,z)/x*i),j=e.length,v=j>0?r/j:r,w=z=>hs(s.left+v*(z+.5)),y=t.map(z=>{if(z.type==="bar")return"";let A="M";const P=[];return z.values.forEach((D,O)=>{if(D===null||!Number.isFinite(D)){A="M";return}P.push(`${A}${w(O)},${p(D)}`),A="L"}),P.join(" ")}),N=[],k=v*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((z,A)=>{if(z.type!=="bar")return;const P=C++;z.values.forEach((D,O)=>{if(D===null||!Number.isFinite(D)||D<=0)return;const M=b(D);N.push({series:A,index:O,x:hs(w(O)-v*.3+k*P),y:M,width:hs(k),height:hs(S-M)})})});const $=c.length>0?Id(u,d,2).map(z=>({value:z,y:p(z)})):[],R=o.length===0?[]:(g?[0,50,100]:Id(0,x,2)).map(z=>({value:z,y:b(z),percent:g})),I=Math.max(1,Math.ceil(j/8)),U=e.flatMap((z,A)=>A%I===0?[{index:A,x:w(A)}]:[]);return{lines:y,bars:N,targetY:null,ticks:$,xLabels:U,rightTicks:R}}function mz({xs:e,series:t,type:s="line",target:r=null}){const i=RE,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 d=w=>hs(i.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?a/f:a,p=w=>hs(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 N=[];return w.values.forEach((k,S)=>{if(k===null||!Number.isFinite(k)){y="M";return}N.push(`${y}${p(S)},${d(k)}`),y="L"}),N.join(" ")}):[],x=[];if(s==="bar"&&f>0){const w=m*.7,y=w/Math.max(1,t.length),N=d(0);t.forEach((k,S)=>{k.values.forEach((C,$)=>{if(C===null||!Number.isFinite(C))return;const R=d(C);x.push({series:S,index:$,x:hs(i.left+m*$+(m-w)/2+y*S),y:Math.min(R,N),width:hs(y),height:hs(Math.abs(N-R))})})})}const j=(o.length>0?Id(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:d(w)})),v=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:g,bars:x,targetY:r!==null&&Number.isFinite(r)?d(r):null,ticks:j,xLabels:v.map(w=>({index:w,x:p(w)}))}}function pz(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(d=>d!==null&&Number.isFinite(d));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 gz({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?$E:RE,u=o?fz({xs:e,series:t}):mz({xs:e,series:t,type:s,target:r}),d=pz({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:d}),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 hs(e){return Math.round(e*10)/10}const aj="(max-width: 900px)";function Ms(e){const[t,s]=h.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return h.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}function Ei(...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:Ei("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Nt({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:Ei("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function ae({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:Ei("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function Dt(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function ie({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=h.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 Ls({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:Ei("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 jg({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Rc({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 G({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 le({message:e}){return e?n.jsx(G,{tone:"critical",role:"alert",children:e}):null}function xe({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(yE,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function jn({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(ue,{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 xz({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function rc({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(xz,{children:[n.jsx(rc,{title:t,lede:s,actions:r}),i]})}function oe({title:e,aside:t,actions:s,panel:r,flush:i,foot:a,children:l}){const o=e||t||s?n.jsxs("div",{className:"ui-section-head",children:[e?n.jsx("h3",{className:"ui-section-title",children:e}):n.jsx("span",{}),t||s?n.jsxs("div",{className:"ui-section-side",children:[t?n.jsx("span",{className:"ui-section-aside",children:t}):null,s?n.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return n.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?n.jsxs("div",{className:"ui-panel","data-flush":i?"true":void 0,children:[l,a?n.jsx("div",{className:"ui-panel-foot",children:a}):null]}):n.jsxs(n.Fragment,{children:[l,a?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:a}):null]})]})}function Qe({title:e,tool:t,actions:s,flush:r,children:i}){return n.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||t||s?n.jsxs("header",{className:"ui-panel-head",children:[e?n.jsx("h3",{className:"ui-panel-title",children:e}):n.jsx("span",{}),t?n.jsx("span",{className:"ui-panel-tool",children:t}):null,s?n.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,i]})}function ys({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:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.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 vz({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function Xh({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function tr({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 Bt({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 js({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function IE({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 It({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function yt({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:Ei("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 ft({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(Vh,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(Gh,{children:[n.jsx(rj,{className:"ui-sheet-overlay"}),n.jsxs(Yh,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(qh,{className:"ui-sheet-title",children:e}),n.jsx(ij,{asChild:!0,children:n.jsx(T,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function un({title:e,onClose:t,foot:s,children:r}){return n.jsx(Vh,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(Gh,{children:[n.jsx(rj,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(Yh,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(qh,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Al({label:e,items:t,note:s,trigger:r,sheet:i}){const a=Ms(jz);return i&&a&&!r?n.jsx(wz,{label:e,items:t,title:i.title,sub:i.sub}):n.jsx(yz,{label:e,items:t,note:s,trigger:r})}const jz="(max-width: 720px)";function wz({label:e,items:t,title:s,sub:r}){const[i,a]=h.useState(!1);return n.jsxs(Vh,{open:i,onOpenChange:a,children:[n.jsx(rz,{asChild:!0,children:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:l=>l.stopPropagation(),children:n.jsx(ue,{name:"more"})})}),n.jsxs(Gh,{children:[n.jsx(rj,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),n.jsxs(Yh,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[n.jsxs("div",{className:"ui-action-sheet-head",children:[n.jsx(qh,{className:"ui-action-sheet-title",children:s}),r?n.jsx("span",{className:"ui-action-sheet-sub",children:r}):null]}),n.jsx("div",{className:"ui-menu ui-action-sheet-list",role:"menu",children:t.map((l,o)=>l?l==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${o}`):"heading"in l?n.jsx("div",{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs("button",{type:"button",role:"menuitem",className:"ui-menu-item","data-tone":l.tone,onClick:()=>{a(!1),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)}),n.jsx(ij,{asChild:!0,children:n.jsx(T,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function yz({label:e,items:t,note:s,trigger:r}){const i=l=>l.stopPropagation(),a=h.useRef(!1);return n.jsxs(Nc,{modal:!1,onOpenChange:l=>{l&&(a.current=!1)},children:[n.jsx(Sc,{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(ue,{name:"more"})})}),n.jsx(Cl,{children:n.jsxs(Cc,{className:"ui-menu",align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:l=>{a.current&&l.preventDefault()},children:[s?n.jsx(ta,{className:"ui-menu-label",children:s}):null,t.map((l,o)=>l?l==="separator"?n.jsx(Nr,{className:"ui-menu-sep"},`sep-${o}`):"heading"in l?n.jsx(ta,{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs(ds,{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 bz({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(Vh,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(Gh,{children:n.jsxs(Yh,{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(qh,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(ij,{asChild:!0,children:n.jsx(T,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function $c({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function cl({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 ht({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function st({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?d=>{d.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:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),t())},children:c}):n.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function PE({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 ME({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:Ei("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 Dd({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 kz=8;function Nz({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(0),p=h.useRef(null),g=h.useRef(null),x=h.useRef(null),b=h.useRef(null),j=h.useId(),v=A=>{var P;return((P=t.find(D=>D.value===A))==null?void 0:P.label)??A},w=i!==void 0&&s.length>=i,y=t.filter(A=>!s.includes(A.value)),N=t.length>kz,k=u.trim().toLowerCase(),S=k===""?y:y.filter(A=>A.label.toLowerCase().includes(k)),C=Math.min(f,Math.max(0,S.length-1)),$=A=>{var P;c(!1),d(""),m(0),A&&((P=g.current)==null||P.focus())};h.useEffect(()=>{var P;if(!o)return;(P=N?x.current:b.current)==null||P.focus();const A=D=>{p.current&&!p.current.contains(D.target)&&$(!1)};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[o,N]);const R=A=>{const P=[...s,A];r(P),d(""),m(0);const D=i!==void 0&&P.length>=i;(D||P.length>=t.length)&&$(!D)},I=A=>{if(A.key==="Escape")A.preventDefault(),$(!0);else if(A.key==="ArrowDown")A.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if(A.key==="ArrowUp")A.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if(A.key==="Enter"){A.preventDefault();const P=S[C];P&&R(P.value)}else A.key==="Backspace"&&u===""&&s.length>0&&(A.preventDefault(),r(s.slice(0,-1)))},U=A=>`${j}-${A}`,z=o&&S.length>0?U(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(A=>n.jsx(Dd,{label:v(A),disabled:a,onRemove:()=>r(s.filter(P=>P!==A)),children:v(A)},A)),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:[N?n.jsx("input",{ref:x,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":z,value:u,onChange:A=>{d(A.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":N?void 0:z,tabIndex:N?-1:0,className:"ui-chippicker-list",children:[S.map((A,P)=>n.jsx("div",{id:U(P),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":P===C?"":void 0,onMouseEnter:()=>m(P),onMouseDown:D=>D.preventDefault(),onClick:()=>R(A.value),children:A.label},A.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function Sz({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 DE({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 _r({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(ue,{name:t})})}function wg({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(ue,{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 OE({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 ic({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function LE({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:Ei("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function Cz({dock:e,className:t,children:s}){return n.jsxs("div",{className:Ei("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 Ez(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function lj(e){const[t,s]=h.useState({}),r=e??[],i={...Ez(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(ie,{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 Az({props:e,timezone:t="UTC",onDecided:s}){var w;const[r,i]=h.useState(null),[a,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(null);h.useEffect(()=>{let y=!1;return i(null),l(null),E.approval(e.approvalId).then(N=>{y||i(N)}).catch(N=>{y||l(N instanceof pe?N.message:String(N))}),()=>{y=!0}},[e.approvalId]);const{values:f,controls:m}=lj(r==null?void 0:r.choices),p=(y,N)=>{d(y),l(null),(f&&y==="approve"?E.decide(e.approvalId,y,N,f):E.decide(e.approvalId,y,N)).then(k=>{i(k.action),s==null||s(k.action)}).catch(k=>l(k instanceof pe?k.message:String(k))).finally(()=>d(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",x=(w=r.permissionScopes)==null?void 0:w.includes("always"),b=Tz(r),j=(r.preview??"").split(`
94
+ `).length>12||(r.preview??"").length>900,v=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>xn(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(Rc,{state:r.state}),!g&&v?n.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children:nt(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(le,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:x?"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"}),x?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…":x?"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 Tz(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(Qb(xn(i),a));else s!=null&&t.push({label:"Envelope",value:oj(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 · ${xn(i)}`;t.some(o=>o.label===l)||t.push(Qb(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 Qb(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:oj(t)}}function oj(e){return e==null?"—":Array.isArray(e)?e.map(t=>oj(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):qt(e,"text",null)}const Rz=new Set(["image/png","image/jpeg","image/gif","image/webp"]),$z=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Od(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"||!$z.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 cj(e){return Rz.has(e.toLowerCase())}function Fr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function vi(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function Fn(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 uj(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 Vi={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function qu(e){return`artifact:${e}`}function Iz(e){const t=uj(e.mime,e.filename);return{id:qu(e.artifactId),tool:Vi[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function Pz({props:e}){const t=kE(e.artifactId),[s,r]=h.useState(null),[i,a]=h.useState(null),[l,o]=h.useState(!1);if(h.useEffect(()=>{if(t===null)return;let d=!0;return r(null),a(null),o(!1),E.libraryEntry(t).then(f=>{d&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{d=!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?Fn(s.sizeBytes):null].filter(d=>d!==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:Fr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:Fr(t),alt:e.caption??c,onLoad:d=>{const f=d.currentTarget;f.naturalWidth>0&&a({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(ae,{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(Nt,{size:"sm",href:vi(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(yt,{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 Mz({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 Dz=8;function _E({text:e,label:t="Output",className:s}){const r=h.useRef(null),i=h.useRef(!0);return h.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<=Dz},children:e})}function Oz(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 Lz({text:e}){const[t,s]=h.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 _z({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(ae,{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:Oz(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(Lz,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",Fn(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(_E,{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 Fz(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function Xb(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function zz(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function Uz({props:e}){var N;const[t,s]=h.useState(null),[r,i]=h.useState(null),[a,l]=h.useState(null),[o,c]=h.useState(!1),u=((N=e.target)==null?void 0:N.plugin)??null,d=zz(e),[f,m]=h.useState(null),p=f!==null&&d.includes(f)?f:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,x=e.changes??0,b=h.useRef(x),[j,v]=h.useState(0);h.useEffect(()=>{x<=b.current||(b.current=x,e.reloadsItself||v(k=>k+1))},[x,e.reloadsItself]),h.useEffect(()=>{if(u===null||g===null)return;let k=!0;return s(null),i(null),l(null),v(0),E.previewLink(u,g).then(S=>{k&&(s(S.url),i(Xb(S.url)))}).catch(S=>{k&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{k=!1}},[u,g]);const w=()=>{u===null||g===null||E.previewLink(u,g).then(k=>i(k.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,d.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:k=>m(Number(k.target.value)),children:d.map(k=>n.jsxs("option",{value:k,children:[":",k]},k))}):null,y?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(k=>!k),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&Fz()?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:Xb(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(_E,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const Bz=50,Wz=9,Hz=24,Kz=.6,Vz=48,Gz=/(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,Yz=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,qz=/^id$|(^|[a-z0-9])Id$|_id$/;function _a(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Yn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function FE(...e){for(const t of e)if(Yn(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 zE(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&&Gz.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&Yz.test(i))?"date":"text"}function Qz(e,t){if(!qz.test(e))return!1;const s=t.filter(r=>!Tl(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Tl(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:Yn(e)?Object.keys(e).length===0:!1}function Jb(e,t){const s=e.filter(Yn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,Bz),i=new Map,a=[];for(const d of r)for(const f of Object.keys(d))i.has(f)||a.push(f),i.set(f,(i.get(f)??0)+1);if(i.size===0||i.size>Hz||[...i.values()].reduce((d,f)=>d+f,0)/(i.size*r.length)<Kz)return null;const o=[...i.keys()].sort((d,f)=>{const m=(i.get(f)??0)-(i.get(d)??0);return m!==0?m:a.indexOf(d)-a.indexOf(f)}),c=[],u=[];for(const d of o){const f=r.map(x=>x[d]),m=f.filter(x=>!Tl(x));if(m.length===0||Qz(d,f))continue;const p=FE(r[0],t),g=zE(d,f,p);if(r.length>=4&&m.length===f.length&&f.every(x=>_a(x)&&x===f[0])){u.push({label:xn(d),value:f[0],type:g,currency:p});continue}if(c.push({key:d,label:xn(d),type:g,currency:g==="currency"?p:null}),c.length===Wz)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function Xz(e,t,s){const r=FE(s);return{label:xn(e),value:t,type:zE(e,[t],r),currency:r}}function UE(e){return typeof e=="string"&&e.length>Vz}function Jz(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.":Yn(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function yg(e){if(typeof e=="string"&&e.trim()!=="")return e;if(Yn(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(Yn(s)){const r=yg(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function dj(e,t={}){if(t.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));Yn(m)&&(f=m)}catch{}return{kind:"error",summary:yg(f),detail:Zb(f)}}if(Yn(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:yg(e),detail:Zb(e)}}const s=Jz(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=Jb(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(_a)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!Yn(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=Jb(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:f,candidate:p});continue}m.length>0&&m.every(_a)&&(!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(UE(m)){c.push(m);continue}if(_a(m)){if(m==="")continue;o.push(Xz(f,m,e));continue}m!==void 0&&u.push({label:xn(f),value:m})}if(i)return{kind:"table",label:xn(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:xn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const d=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return d.length>0&&d.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${d.map(([m])=>xn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>_a(f)||Yn(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function Zb(e){if(!Yn(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const Ld=25,Zz=3,bg=8,BE=6;function kg(e,t=0){if(t>BE||Tl(e)||UE(e))return 0;if(_a(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=kg(r,t+1),s>=bg)return s;return s}if(Yn(e)){let s=0;for(const r of Object.values(e))if(s+=kg(r,t+1),s>=bg)return s;return s}return 0}function Ng(e,t=0){if(t>BE)return!1;if(Array.isArray(e))return e.some(a=>Ng(a,t+1));if(!Yn(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=>Ng(a,t+1))}function e3(e){if(Ng(e))return!0;const t=dj(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=Zz;case"record":case"tree":return kg(e)>=bg;default:return!1}}function am(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function hj(e){const t=am(e);if(!t)return null;const s=am(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:am(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function t3({text:e,label:t}){const[s,r]=h.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 lm({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(t3,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function n3({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(([d,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(d)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(d=>typeof d=="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(lm,{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(lm,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(lm,{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((d,f)=>n.jsx("p",{className:"wb-fail",children:d},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:Jn({...c,...i?{input:i}:{}})})]})]})}const vu=2,ek=64;function s3({props:e}){const[t,s]=h.useState(!1),r=hj(e.value),i=r3((r==null?void 0:r.result)??e.value),a=h.useMemo(()=>dj(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(tk,{files:i}),t?n.jsx("pre",{className:"ui-code",children:Jn(e.value)}):r?n.jsx(n3,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(tk,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(nk,{shape:a})]}):n.jsx(nk,{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 r3(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 tk({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(i3,{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 i3({file:e}){const[t,s]=h.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 nk({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:ac(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(om,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=d3(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(om,{stats:e.stats}),n.jsx(cm,{notes:e.notes}),t?n.jsx(h3,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(l3,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(um,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(om,{stats:e.stats}),n.jsx(cm,{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(um,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(cm,{notes:e.notes}),n.jsx(a3,{pairs:e.pairs}),n.jsx(um,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:ac(e.value,0)})}}function om({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:fj(t.value,t.type,t.currency)})]},t.label))})}const sk=200;function cm({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=sk),s=e.filter(r=>r.length>sk);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 a3({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:fj(t.value,t.type,t.currency)})]},t.label))})}function um({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:ac(t.value,1)})]},t.label))})}function l3({label:e,columns:t,rows:s,total:r}){const[i,a]=h.useState(!1),l=r<=Ld+5?r:Ld,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:HE(c.type)?"num":void 0,children:c.label},c.key))})}),n.jsx("tbody",{children:o.map((c,u)=>n.jsx("tr",{children:t.map(d=>n.jsx(f3,{value:c[d.key],column:d},d.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 o3=/^(title|name|headline|subject|label|heading)$/i,c3=/^(url|link|href|uri|permalink)$/i;function _d(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function u3(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function WE(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 ju(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 d3(e,t){if(t.length===0)return null;const s=e.filter(d=>d.type==="text"),r=s.find(d=>c3.test(d.key)&&t.some(f=>_d(f[d.key])))??s.find(d=>{const f=t.map(m=>m[d.key]).filter(m=>!Tl(m));return f.length>0&&f.filter(_d).length/f.length>=.6});if(!r)return null;const i=s.filter(d=>d.key!==r.key),a=i.find(d=>o3.test(d.key))??i.find(d=>ju(t,d.key)>0);if(!a)return null;const o=[...i.filter(d=>d.key!==a.key)].sort((d,f)=>ju(t,f.key)-ju(t,d.key)),c=o[0]&&ju(t,o[0].key)>40?o[0]:null,u=e.filter(d=>d.key!==r.key&&d.key!==a.key&&d.key!==(c==null?void 0:c.key)).map(d=>d.key);return{url:r.key,title:a.key,description:(c==null?void 0:c.key)??null,meta:u}}function h3({label:e,plan:t,rows:s,total:r}){const[i,a]=h.useState(!1),l=r<=Ld+5?r:Ld,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 d=c[t.url],f=_d(d)?d.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:f?WE(f):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=f?u3(f):null,x=t.meta.map(b=>c[b]).filter(b=>!Tl(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,x.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 f3({value:e,column:t}){if(Tl(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(_d(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:WE(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:Jn(e),children:i})}const s=fj(e,t.type,t.currency),r=s.length>ek?`${s.slice(0,ek-1)}…`:s;return n.jsx("td",{className:HE(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function HE(e){return e==="number"||e==="currency"}function fj(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":qt(e,t==="text"?"text":t,s)}function ac(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,". "]}),ac(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=vu?n.jsx(rk,{summary:`${e.length} items`,open:t===vu,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:[xn(i),": "]}),ac(a,t+1)]},i))});return t>=vu?n.jsx(rk,{summary:`${s.length} fields`,open:t===vu,children:r}):r}function rk({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function m3({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:KE(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(p3,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function p3({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:KE(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function KE(e){return e==="number"||e==="currency"||e==="percent"}const ik={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun","partly-cloudy":"partly-cloudy",cloud:"cloud",rain:"rain",drizzle:"drizzle",snow:"snow",storm:"storm",fog:"fog",wind:"wind","moon-clear":"moon-clear","moon-cloud":"moon-cloud",check:"check",clock:"clock"};function Rl(e){return(e&&Object.prototype.hasOwnProperty.call(ik,e)?ik[e]:void 0)??"dot"}function Fd(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 zd="buddi:plugin-pages-changed";function g3(){window.dispatchEvent(new Event(zd))}function VE(e=!1){const[t,s]=h.useState([]);return h.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>E.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(zd,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(zd,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:Fd(t,"rail"),settings:Fd(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}function x3(e,t){const s=(t??[]).filter(a=>a.plugin===e),r=Fd(s,"rail")[0]??Fd(s,"settings")[0];if(r!=null&&r.title.trim())return r.title.trim();const i=e.replace(/[-_]+/g," ").trim();return i?i.charAt(0).toUpperCase()+i.slice(1):e}let Qu=null;typeof window<"u"&&window.addEventListener(zd,()=>{Qu=null});function v3(){return Qu??(Qu=Promise.resolve().then(()=>E.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(Qu=null,[]))),Qu}function mj(e,t,s){return s==="settings"?gi(e,t):lr(e,t)}function j3(e){const[t,s]=h.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return h.useEffect(()=>{if(!r||!i)return;let a=!1;return v3().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:mj(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function GE({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(w3,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function w3({tile:e,picked:t,onPick:s}){const r=j3(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(ue,{name:Rl(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(ys,{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 wa=760,dm=400,Ot={top:18,right:18,bottom:36,left:66},y3=5;function b3({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,d=o+c*.08,f=wa-Ot.left-Ot.right,m=dm-Ot.top-Ot.bottom,p=y=>Ot.left+(t.length===1?f/2:y/(t.length-1)*f),g=y=>Ot.top+m-(y-u)/(d-u)*m,x=Id(l,o,4),b=N3(t.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:S3(t.map(y=>y.y),e.shadeBelow),v=t.map((y,N)=>`${N===0?"M":"L"}${p(N)},${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 ${wa} ${dm}`,role:"img","aria-label":k3(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:Ot.top,height:m},`band-${y.from}`)),x.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Ot.left,x2:wa-Ot.right,y1:g(y),y2:g(y)}),n.jsx("text",{x:Ot.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:Ot.left,x2:wa-Ot.right,y1:g(y.value),y2:g(y.value)}),n.jsxs("text",{x:wa-Ot.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:Ot.left,x2:Ot.left,y1:Ot.top,y2:Ot.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:Ot.left,x2:wa-Ot.right,y1:Ot.top+m,y2:Ot.top+m}),n.jsx("path",{className:"wb-chart-series",d:v}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy: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,C3(t.length).map(y=>n.jsx("text",{x:p(y),y:dm-10,textAnchor:"middle",children:og(t[y].x)},`x-${y}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,N)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:og(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}-${N}`))})]}):null]})]})}function k3(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 N3(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 S3(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 C3(e,t=y3){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 as=e=>e,Sg={timeseries:as(b3),table:as(m3),bars:as(G_),keyvalue:as(Mz),tiles:as(GE),document:as(L4),diff:as(Z_),terminal:as(_z),image:as(Pz),preview:as(Uz),envelope:as(Az),structured:as(s3)},E3="structured";function A3(e){return(Ud(e)?Sg[e]:void 0)??Sg[E3]}function Ud(e){return Object.prototype.hasOwnProperty.call(Sg,e)}function T3({renderer:e,props:t,timezone:s,onDecided:r}){const i=A3(e),l=Ud(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function R3({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(hm,{children:"Opens by default"}):null,n.jsx(hm,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(hm,{title:`A surface command that asks for "${s}" lands on this agent.`,children:xn(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(to,{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(YE,{}),"Exact action"]})]})]})}),n.jsx(to,{title:"What it can do",note:$3(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(I3,{family:s},s.family))}),n.jsx(to,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(no,{label:"Provider",children:e.engine.provider}),n.jsx(no,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(no,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(no,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(no,{label:"Language",children:L3(e.engine.language)})]})}),e.skills.length>0?n.jsx(to,{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(to,{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 $3(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 I3({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:xn(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(P3,{tool:s},s.name))})]})}function P3({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:O3(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(YE,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:D3(e.tier),children:M3(e.tier)})]})}function M3(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function D3(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 O3(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function L3(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function to({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 no({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 hm({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function YE(){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 ak=16e3,_3=10*6e4,F3="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",qE="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function z3(){const e=window;return e.AudioContext??e.webkitAudioContext}function U3(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?F3:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":qE}async function B3(e){var c;const t=z3();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(qE),{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 d=u.inputBuffer.getChannelData(0);l.push(new Float32Array(d));let f=0;for(let m=0;m<d.length;m++)f+=d[m]*d[m];e(Math.min(1,Math.sqrt(f/d.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(),K3(H3(W3(l),u,ak),ak)},cancel:o}}function W3(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 H3(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 K3(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 Cg="buddi.readAloud";function QE(){try{return window.localStorage.getItem(Cg)==="on"}catch{return!1}}function XE(e){try{e?window.localStorage.setItem(Cg,"on"):window.localStorage.removeItem(Cg)}catch{}}let Xs=null,bo=null,lc=0,Eg=null;const Ag=new Set;function Bd(e){Eg!==e&&(Eg=e,Ag.forEach(t=>t()))}function V3(){return Eg}function G3(e){return Ag.add(e),()=>Ag.delete(e)}function JE(e){return $l(),Bd(e),lc}function lk(e){return e===lc}function $l(){lc++,Xs&&(Xs.pause(),Xs.removeAttribute("src")),bo&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(bo),bo=null,Bd(null)}async function Y3(e,t,s=null){var i;const r=JE(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!==lc)return;Xs||(Xs=new Audio,(i=Xs.addEventListener)==null||i.call(Xs,"ended",()=>Bd(null))),bo=URL.createObjectURL(l),Xs.src=bo,await Xs.play()}catch(a){throw r===lc&&Bd(null),a}}const q3=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function ZE(e){return q3.has(e.toLowerCase().split(";")[0].trim())}function ok(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 eA({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=h.useRef(null),a=h.useRef(null),[l,o]=h.useState(!1),[c,u]=h.useState(!1),[d,f]=h.useState(!1),[m,p]=h.useState(0),[g,x]=h.useState(null);h.useEffect(()=>()=>{var v;(v=i.current)==null||v.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const v=i.current;if(v){if(l){v.pause();return}$l(),f(!1);try{if(!a.current){u(!0);const w=await fetch(vi(e),{credentials:"same-origin"});if(!w.ok)throw new Error(String(w.status));a.current=URL.createObjectURL(new Blob([await w.arrayBuffer()],{type:s})),v.src=a.current}await v.play()}catch{f(!0)}finally{u(!1)}}},j=d?"Could not play. Download it instead.":`${ok(m)} / ${ok(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(ue,{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,!d&&Fn(r)?` · ${Fn(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:vi(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(ue,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:v=>p(v.currentTarget.currentTime),onLoadedMetadata:v=>x(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null),onDurationChange:v=>x(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null)})]})}const fm=1e5,mm=200,pm=30;function tA({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=h.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:Fr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&ZE(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(eA,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:Fr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(Q3,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(G,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(G,{children:"The file is no longer available; its record is kept."})}function Q3({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=h.useState("loading");if(h.useEffect(()=>{let o=!1;return a("loading"),fetch(Fr(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,fm),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>fm})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(xe,{children:"Loading preview…"})});if(i==="failed")return n.jsx(G,{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(J3,{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 ",fm.toLocaleString()," characters. The download has the whole file."]}):null]})}function X3(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const d=()=>{a.length<r?a.push(l):c=!0,l=""},f=()=>{d(),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){d();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 J3({text:e,delimiter:t}){const s=h.useMemo(()=>X3(e,t,mm+1,pm),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(pm,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,mm).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 ",mm," rows",s.truncatedCols?` and ${pm} columns`:"",". The download has the whole file."]}):null]})}function Z3({attachment:e}){const t=uj(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(tA,{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:[Vi[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:Fn(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:vi(e.artifactId),download:s,children:"Download"})})]})}const ck=80,eU=["query","path","url","dir"],tU=["message","task"];function pj(e,t){const s=nU(t);if(!s)return null;const r=ya(s.command);if(r!==null){const l=ya(s.name);return wu(l===null?r:`${l}: ${r}`)}for(const l of eU){const o=ya(s[l]);if(o!==null)return wu(o)}const i=ya(s.action);if(i!==null){const l=tU.map(o=>ya(s[o])).find(o=>o!==null)??null;return wu(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?wu(ya(a[0])):null}function ya(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function wu(e){return e===null?null:e.length>ck?`${e.slice(0,ck-1)}…`:e}function nU(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const nA="owner.notify",wr=e=>typeof e=="string"&&e.trim()!==""?e:null;function sU(e){const t=e!==null&&typeof e=="object"?e:{};return{title:wr(t.title)??"(no title)",text:wr(t.text),urgency:wr(t.urgency)??"now",key:wr(t.key),link:wr(t.link)}}function sA(e){if(e===null||typeof e!="object")return wr(e);const t=e;return wr(t.delivered)??wr(t.message)??wr(t.error)}function rU(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 ji="agent.delegate";function iU(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 aU(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 Tg="canvas.show",uk="canvas.clear",dk=12;function Xa(e){return`${e.plugin}/${e.name}`}function lU(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function oU({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=SE(o,rA(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function cU({messages:e,descriptors:t,awaiting:s,folded:r,served:i}){var u;const a=new Map(t.map(d=>[d.tool,d])),l=new Map;let o=[],c=0;for(const d of e)for(const f of d.blocks??[]){if(f.type==="tool_use"){if(l.set(f.id,{name:f.name,input:f.input,at:d.at??null}),f.name===Tg){const y=dU(f.id,f.input,d.at??null);y&&o.push(y)}if(f.name===uk&&(o=[]),f.name===ji){const y=iU(f.input);y&&o.push({id:f.id,tool:ji,title:"Delegation",renderer:"delegate",props:{...y,result:null},at:d.at??null,source:"delegate",substantial:!0})}continue}if(f.type!=="tool_result"||f.name===Tg||f.name===uk)continue;const m=l.get(f.toolUseId),p=d.at??(m==null?void 0:m.at)??null,g=f.name||(m==null?void 0:m.name)||"tool",x=o.find(y=>y.source==="delegate"&&y.id===f.toolUseId);if(x&&((u=f.delegation)==null?void 0:u.state)==="waiting"){x.props={...x.props,result:null,waiting:{approvalId:f.delegation.approvalId}},f.delegation.approvalId&&(x.tone="warning");continue}if(x){x.props={...x.props,result:{ok:f.ok,text:aU(f.ok?f.output:f.error??f.output),...f.ok&&Od(f.output).length>0?{files:Od(f.output)}:{}}},f.ok||(x.tone="critical");continue}const b=f.approval?$g(f):(s==null?void 0:s.get(f.toolUseId))??$g(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===nA){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=rA(f.output);if(f.ok===!1){o.push({id:f.toolUseId,tool:g,title:rr(g),renderer:"structured",props:{value:f.error??j??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}lU(j)&&(c+=1);const v=a.get(g);if(v){const y=SE(v,j),{renderer:N}=y;let{props:k}=y;if(N==="preview"){const S=k,C=S.target??(S.awaiting&&(i!=null&&i.has(Xa(S.awaiting)))?S.awaiting:null);if(C===null)continue;k={...S,target:C,awaiting:null};const $=Xa(C);o=o.filter(R=>!(R.source==="descriptor"&&R.renderer==="preview"&&R.props.target!==null&&Xa(R.props.target)===$))}o.push({id:f.toolUseId,tool:g,title:v.title??rr(g),renderer:N,props:k,at:p,source:"descriptor",substantial:Rg(N,k)});continue}const w={value:hj(j)?{input:m==null?void 0:m.input,output:j}:j};hU("structured",w)&&o.push({id:f.toolUseId,tool:g,title:rr(g),renderer:"structured",props:w,at:p,source:"fallback",substantial:Rg("structured",w)})}for(const d of o)d.source==="descriptor"&&d.renderer==="preview"&&(d.props={...d.props,changes:c});return uU(o)}const hk="forAgent";function rA(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(hk in e))return e;const{[hk]:t,...s}=e;return s}function uU(e){if(e.length<=dk)return e;const t=e.length-dk;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function dU(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&Ud(r)?r:"structured";return{id:e,tool:Tg,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!Ud(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function hU(e,t){const s=t??{};return!!(s.failed===!0||Rg(e,t)||dj(s.value).kind==="error")}function Rg(e,t){const s=t??{};switch(e){case"timeseries":return so(s.points)>0;case"bars":return so(s.bars)>0;case"keyvalue":return so(s.pairs)>0;case"tiles":return s.notice!==!0&&so(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=>so(i.rows)>0);default:return hj(s.value)?!0:s.failed===!0?!1:e3(s.value)}}function so(e){return Array.isArray(e)?e.length:0}function $g(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=aA(t,0);if(s)return s}return null}function fU(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)?iA(i.input):i.input;return{id:t,tool:i.name,title:rr(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 mU=new Set(["value","text","password","secret","code"]);function iA(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=mU.has(s)&&typeof r=="string"?"— withheld —":iA(r);return t}function aA(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=aA(a,t+1);if(l)return l}return null}function rr(e){const t=e.split(".");return t.length===1?xn(e):t.map(s=>xn(s)).join(" · ")}function Jh({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=uj(t,e),d=[Vi[u],Fn(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(gj,{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":d})]})]});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 gj({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 pU(e,t,s){const r=mk(e),i=mk(t==null?void 0:t.input),a=Pi(r==null?void 0:r.name)??wU(Pi(r==null?void 0:r.handle))??Pi(r==null?void 0:r.agent)??Pi(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:Pi(r==null?void 0:r.text)??Pi(r==null?void 0:r.note),o=fk(r==null?void 0:r.durationMs)??fk(r==null?void 0:r.elapsedMs),c=t!=null&&t.at?Date.parse(t.at):NaN,u=s?Date.parse(s):NaN,d=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:a,question:Pi(i==null?void 0:i.task),answer:l,files:Od(e),durationMs:o??d}}function gU(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===ji&&((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 xU({block:e,messages:t,answeredAt:s}){const r=pU(e.output,gU(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${vU(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(Lr,{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:vi(a.artifactId),download:!0,children:n.jsx(Jh,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:cj(a.mime)?Fr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(yt,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:jU(e.output)})})]})}function vU(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 jU(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function wU(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Pi(e){return typeof e=="string"&&e.trim()!==""?e:null}function fk(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function mk(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const yU=1e3;function bU({messageId:e,text:t,onReadAloud:s}){const[r,i]=h.useState(!1),a=h.useRef(null),l=h.useSyncExternalStore(G3,V3)===e;h.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),yU)},()=>{})};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(ue,{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?$l():s(e,t),children:n.jsx(ue,{name:l?"stop":"play",size:14})}):null]})}function kU(e){const t=NU(e);if(!t)return null;const s=gm(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=gm(t.command),i=gm(t.plain),a=xm(t.exitCode);return r!==null&&(i!==null||a!==null||xm(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:xm(t.elapsedMs)}:null}function gm(e){return typeof e=="string"&&e.trim()!==""?e:null}function xm(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function NU(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const pk="offer:",lA="owner:interjection";function SU(e){return e===lA}function CU(e){if(typeof e!="string"||!e.startsWith(pk))return null;const t=e.slice(pk.length).trim();return t===""?null:t}const gk="brief:";function EU(e){if(typeof e!="string"||!e.startsWith(gk))return null;const t=e.slice(gk.length).trim();return t===""?null:t}function xj({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:d,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:x,empty:b,plain:j=!1,workingLine:v,runs:w,onContinue:y}){var F;const N=h.useRef(null);h.useEffect(()=>{var X;(X=N.current)==null||X.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const k=a&&!a.settled&&(a.text!==""||a.thinking!==""),S=e.filter(X=>(X.blocks??[]).some(_U)),C=OU(S,w??[]),$=c??l??[],R=X=>(o&&!c?$.find(Y=>Y.id===o):void 0)??$.find(Y=>Y.name===X)??null,I=o?$.find(X=>X.id===o)??null:null,U=i||t.length>0,z=U||!!k,A=!!k&&a.text!=="",P=U&&!A,D=S.at(-1),O=(D==null?void 0:D.role)!=="assistant"||!!d,M=d??g??"Assistant",W=S.filter((X,Y)=>{var Z;return Y===0||(c?(((Z=S[Y-1])==null?void 0:Z.speaker)??null)!==(X.speaker??null):S[Y-1].role!==X.role)}),L=z&&!O?((F=W.at(-1))==null?void 0:F.id)??null:null,q=(w??[]).reduce((X,Y)=>X===null||(Y.startedAt??"")>(X.startedAt??"")?Y:X,null),B=(w??[]).some(X=>X.finishedAt===null),V=y&&!z&&!B&&D&&(q==null?void 0:q.stopped)==="max_turns"&&C.get(D.id)===q?D.id:null;return n.jsx(bE.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:x}):null,S.map((X,Y)=>{const Z=X.speaker??null,he=c?Z==="owner"||Z===null&&X.role==="user":X.role==="user",Le=c&&Z==="room",Ie=c&&Z&&Z!=="owner"&&Z!=="room"?c.find(Ae=>Ae.id===Z)??null:null,ze=S[Y-1],ee=Y===0||(c?((ze==null?void 0:ze.speaker)??null)!==Z:ze.role!==X.role);if(Le)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(X.blocks??[]).filter(Ae=>Ae.type==="text").map((Ae,Be)=>n.jsx("span",{children:Ae.text},Be))},X.id);const be=(X.blocks??[]).filter(Ae=>Ae.type==="approval_result");if(be.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:be.map((Ae,Be)=>n.jsx(FU,{block:Ae,messages:e,at:X.at||null},Be))},X.id);const re=X.role==="user"&&SU(Z),Ee=X.role==="user"?EU(Z):null;if(Ee)return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",children:Ee})},X.id);const me=X.role==="user"?CU(Z):null;if(me){const Ae=(X.blocks??[]).filter(Be=>Be.type==="text").map(Be=>Be.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:Ae,children:me})},X.id)}const Re=c&&Ie&&X.role==="user"?PU(X):null;if(Re){const Ae=S.slice(Y+1).find(it=>it.role==="assistant"&&it.speaker&&it.speaker!==Ie.id),Be=Ae!=null&&Ae.speaker?c.find(it=>it.id===Ae.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[Ie.name," asked ",(Be==null?void 0:Be.name)??"a member",Re.request?`: ${Re.request.length>120?`${Re.request.slice(0,119)}…`:Re.request}`:""]}),Re.request?n.jsx("p",{children:Re.request}):null]},X.id)}const Se=C.get(X.id)??null,Ue=DU(X,e),et=!he&&!re&&!j?MU(X):"";return n.jsxs("div",{className:"wb-msg","data-role":he||re?"user":"assistant",children:[re?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,ee&&!he&&!re?n.jsx(xk,{name:Ie?Ie.name:c&&Z&&Z!=="owner"&&Z!=="room"?Z:g??"Assistant",face:Ie??I??R(g),moving:P&&L===X.id,children:Ie&&u===Ie.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Ue.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Ue.map(Ae=>n.jsx("span",{role:"listitem",children:ZE(Ae.mime)?n.jsx(eA,{artifactId:Ae.artifactId,name:Ae.filename??"Untitled file",mime:Ae.mime,sizeBytes:Ae.sizeBytes}):n.jsx(Jh,{name:Ae.filename??"Untitled file",mime:Ae.mime,sizeBytes:Ae.sizeBytes,thumbnail:cj(Ae.mime)?Fr(Ae.artifactId):null,...f?{onOpen:()=>f(Ae)}:{}})},Ae.artifactId))}):null,(X.blocks??[]).map((Ae,Be)=>{const it=RU(X.blocks??[],Be,e);if(it==="inside")return null;if(it)return n.jsx($U,{refusals:it.refusals},Be);if(Ae.type==="thinking")return j||Ae.text.trim()===""?null:n.jsx(Ig,{text:Ae.text},Be);if(Ae.type==="text")return Ae.text.trim()===""?null:he?n.jsx("div",{className:"wb-bubble",children:Ae.text},Be):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(Lr,{text:Ae.text})},Be);if(Ae.type==="attachment")return null;if(Ae.type==="tool_use"){if(j)return null;const qe=vj(e,Ae.id),J=qe?BU(qe):null,we=!J&&Ae.name===nA&&qe?sA(qe.output):null;return n.jsx(Pg,{label:J&&!(qe!=null&&qe.delegation)?`Approval · ${Ae.name}`:rr(Ae.name),tool:Ae.name,ok:(qe==null?void 0:qe.ok)??null,running:qe===null,...J?{status:J.status,waiting:J.waiting,approval:!0}:we?{status:we}:{},gist:pj(Ae.name,Ae.input),body:qe?kU(qe.output):null,opens:!0,onOpen:()=>r(Ae.id)},Be)}return null}),Se?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:LU(Se)}),V===X.id?n.jsx(T,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,X.feedback&&!he&&!re?n.jsx(KU,{feedback:X.feedback}):null,et!==""?n.jsx(bU,{messageId:X.id,text:et,onReadAloud:m}):null]},X.id)}),z?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[O?n.jsx(xk,{name:M,face:R(M)??I,moving:P}):null,k&&a.thinking!==""&&!j?n.jsx(Ig,{text:a.thinking,live:a.text==="",seconds:IU(a.thinkingStartedAt,a.textStartedAt??s)}):null,A?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(Lr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!k?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${d??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(X=>n.jsx(Pg,{label:rr(X.name),tool:X.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-X.startedAt)/1e3)),opens:!1,onOpen:()=>r(X.toolUseId)},X.toolUseId))]}):null,p,n.jsx("div",{ref:N})]})})}function xk({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=jE(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(Tc,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Us,{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 AU(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 TU="delegation refused:";function RU(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==ji)return null;const o=vj(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(TU))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 $U({refusals:e}){const[t,s]=h.useState(!1),r=e.map(o=>AU(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(ue,{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:[rr(ji)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function IU(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function Ig({text:e,live:t=!1,seconds:s=null}){const[r,i]=h.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(ue,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(ue,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(Lr,{text:e})}):null]})}function PU(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 MU(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
97
+
98
+ `)}function DU(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===ji){const l=vj(t,a.id);l!=null&&l.ok&&Od(l.output).forEach(i)}return s}function OU(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 LU(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 _U(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function FU({block:e,messages:t,at:s}){const[r,i]=h.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":rr(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ue,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===ji?n.jsx(xU,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==ji?n.jsx("pre",{className:"wb-approval-output mono",children:zU(e.output)}):null]})}function zU(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const UU=40;function BU(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($g(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 Pg({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:d=null,body:f=null}){const[m,p]=h.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}),d?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:d}):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]}),x={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":d?!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",...x,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(ue,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(Go,{children:[n.jsx(Yo,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(ue,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(qo,{children:n.jsxs(Qo,{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(WU,{body:f,onOpen:a?l:null}):null]}):a?n.jsxs(Go,{children:[n.jsx(Yo,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...x,onClick:l,children:[g,n.jsx(ue,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(qo,{children:n.jsxs(Qo,{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",...x,children:g})}function WU({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(Pd,{text:e.diff,limit:UU,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:HU(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 HU(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function vj(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 KU({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 oA="approval-dock";function VU(){var t;const e=document.getElementById(oA);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const GU=["workspace","cwd","workdir","root"];function YU({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=h.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),d=u[0];if(!d)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(qU,{item:d,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{f(d.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(d.toolUseId)},d.approvalId)}function qU({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,x]=h.useState("");h.useEffect(()=>{let $=!1;return E.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;h.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:j,controls:v}=lj(c==null?void 0:c.choices),w=($,R)=>{const I=g.trim();p($),f(null),(j&&$==="approve"?E.decide(e.approvalId,$,R,j):E.decide(e.approvalId,$,R)).then(U=>{a(U.action),I&&l(I)}).catch(U=>{f(U instanceof pe?U.message:String(U)),p(null)})},y=m!==null||c===null||c.state!=="pending",N=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,k=c?pj(c.tool,c.canonicalArgs)??XU(c.preview):null,S=c?QU(c):null;return n.jsxs("section",{id:oA,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?rr(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),k||S?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[k?n.jsx("code",{className:"wb-dock-gist",children:k}):null,S?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:S})]}):null]}):null,v?n.jsx("div",{className:"wb-dock-section",children:v}):null,n.jsx(le,{message:d}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:$=>x($.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 ",nt(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"}),N?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…":N?"Allow once":"Approve"})]})]})}function QU(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of GU){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function XU(e){const t=(e??"").split(`
99
+ `).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const JU=2e3;function ZU({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=h.useState(l),u=!o||i!==null,{data:d,error:f}=ce(()=>He.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?JU:void 0),m=(d==null?void 0:d.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));h.useEffect(()=>{g&&c(!0)},[g]);const x=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)??(d==null?void 0:d.agentId)??t,v=(d==null?void 0:d.messages)??[],w=(r==null?void 0:r.text)??e6(v);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":x,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(ln,{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":x,role:"status",children:x==="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",{})]})]}):x==="waiting"?"Waiting for your approval":x==="failed"?"Failed":"Done"})]})]}),f?n.jsx("p",{className:"muted",children:f}):null,n.jsx("div",{className:"wb-delegate-work",children:v.map((y,N)=>n.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((k,S)=>{if(k.type==="thinking")return k.text.trim()===""?null:n.jsx(Ig,{text:k.text},S);if(k.type==="tool_use"){const C=n6(t6(v,k.id));return n.jsx(Pg,{label:rr(k.name),tool:k.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:pj(k.name,k.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??N))}),w?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(Lr,{text:w})}):x==="working"||x==="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:vi(y.artifactId),download:!0,children:n.jsx(Jh,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:cj(y.mime)?Fr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[x==="waiting"?n.jsx(T,{variant:"accent",onClick:()=>VU(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:tt(t||(d==null?void 0:d.agentId)||"",e),children:"Open this conversation"})]})]})}function e6(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 t6(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 n6(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 vk=1024*1024;function s6({files:e,agentId:t,root:s,revision:r}){const[i,a]=h.useState({kind:"dir",path:""});return h.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(r6,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(i6,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function cA({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 r6({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1),[m,p]=h.useState(null);h.useEffect(()=>{let b=!1;return u(null),E.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]),h.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const b=await fetch(E.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(),v=URL.createObjectURL(j),w=document.createElement("a");w.href=v,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(v),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},x=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(cA,{root:s,path:r,go:a}),n.jsx(Dt,{}),n.jsx(T,{size:"sm",onClick:()=>void g(),disabled:d||x===null||x.length===0,children:d?"Packing…":"Download as archive"})]}),m?n.jsx(G,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(G,{tone:"critical",role:"alert",children:c}):null,x===null?c?null:n.jsx(xe,{children:"Reading the folder…"}):x.length===0?n.jsx(xe,{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:Or,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(ht,{children:x.map(b=>n.jsx(st,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(l6,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?Fn(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 i6({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1);h.useEffect(()=>{let j=!1;return u(null),E.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(v=>{j||o(v.data)}).catch(v=>{j||u(v instanceof Error?v.message:String(v))}),()=>{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?E.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",x=E.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=vk;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(cA,{root:s,path:r,go:a}),n.jsx(Dt,{}),b?n.jsx(T,{size:"sm","aria-pressed":d,onClick:()=>f(j=>!j),children:"Wrap"}):null,n.jsx(Nt,{size:"sm",href:x,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(G,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(xe,{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(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(a6,{src:g,wrap:d}):n.jsxs(n.Fragment,{children:[n.jsx(G,{children:m.type==="text"?`This file is over ${Fn(vk)}, 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(Bt,{items:[{label:"Size",value:Fn(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function a6({src:e,wrap:t}){const[s,r]=h.useState(null),[i,a]=h.useState(!1);return h.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(G,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(xe,{children:"Reading the file…"}):s===""?n.jsx(xe,{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 l6({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 o6({input:e,output:t,ok:s}){const r=sU(e),i=sA(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:rU(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(yt,{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 c6=3,u6=152,d6=104,h6=100,f6=2,jk=5;function m6({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:d,browserPanel:f,agents:m,onClose:p,loading:g=!1}){const[x,b]=p6(d);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:x,"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:w6(u,y6(o??[],c??[]))})]})})]});const j=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:v,hidden:w}=g6(e,j,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(U_,{value:j,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:x,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(B_,{className:"wb-tabstrip","aria-label":"Canvas",children:v.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(W_,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:N=>{N.key==="Delete"&&p&&wk(y)&&(N.preventDefault(),p(y.id))},children:[y.tone==="warning"||y.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":y.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:y.title})]}),p&&wk(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(x6,{items:w,onActivate:s,timezone:r})]}),e.map(y=>n.jsx(H_,{value:y.id,className:"wb-canvas-body","data-renderer":y.source==="descriptor"&&y.renderer==="preview"?"preview":void 0,"data-dense":k6.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?` · ${nt(y.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,y.source==="browser"?f:y.source==="profile"?n.jsx(R3,{...y.props,...a?{onChange:a}:{}}):y.source==="artifact"?n.jsx(Z3,{...y.props}):y.source==="files"?n.jsx(s6,{...y.props}):y.source==="notify"?n.jsx(o6,{...y.props}):y.source==="delegate"?n.jsx(ZU,{...y.props,agents:m??[]}):n.jsx(T3,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function wk(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function p6(e){const[t,s]=h.useState(jk),r=h.useRef(null);return[h.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-h6-d6)/u6);s(Math.max(f6,Math.min(jk,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function g6(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 x6({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(Nc,{modal:!1,children:[n.jsx(Sc,{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(ue,{name:"chevron-down"})]})}),n.jsx(Cl,{children:n.jsxs(Cc,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(ta,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(ds,{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:v6(i.at,s)??i.tool})]},i.id))]})})]})}function v6(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Wt(s,t)}const j6={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 w6(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>j6[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function y6(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=b6(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,c6)}function b6(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 k6=new Set(["table","diff","files"]),N6=3.5*6e4,S6=2e3;function C6(e,t,s={}){const[r,i]=h.useState({served:new Set,live:new Set,scope:t}),a=h.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??E.previewCheck,o=s.everyMs??S6,c=e.map(u=>`${Xa(u)}@${u.at??""}`).join("|");return h.useEffect(()=>{const u=new Map;for(const p of e){const g=Xa(p);if(a.current.has(g))continue;const x=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(x)?0:x+N6,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 d=!1,f;const m=async()=>{const p=Date.now();for(const[g,x]of[...u]){const b=await l(x.plugin,x.name).catch(()=>null);if(d)return;const j=p<=x.until;b!=null&&b.ok?(u.delete(g),i(v=>{const w={served:new Set(v.served).add(g),live:j?new Set(v.live).add(g):v.live,scope:v.scope};return a.current=w.served,w})):j||u.delete(g)}!d&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{d=!0,f!==void 0&&clearTimeout(f)}},[c,t,l,o]),r}const Mg="workspace-files";function E6(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 A6(e){const[t,s]=h.useState(null);return h.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await E.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await E.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 T6(e,t){return{id:Mg,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 Dg(e){return`agent-properties:${e}`}function R6(e){return{id:Dg(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function $6(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 uA({progress:e}){return n.jsxs(se,{gap:"sm",children:[n.jsx("span",{role:"status",children:$6(e)}),n.jsx(IE,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function I6(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=(d,f)=>Math.max(0,Math.min(Math.round(d),Math.round(f)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function vm(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function yk(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const P6=4e3;function M6(e){return e.replace(/\r\n?/g,`
104
+ `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,P6)}const D6=["left","middle","right"],O6=33;function L6(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function _6(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 F6(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function z6({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=h.useState("connecting"),[l,o]=h.useState(null),[c,u]=h.useState(!1),[d,f]=h.useState(null),[m,p]=h.useState(!1),[g,x]=h.useState(0),b=h.useRef(null),j=h.useRef(null),v=h.useRef(null),w=h.useRef({at:0});h.useEffect(()=>{const A=r??(O=>new WebSocket(O));let P=!0,D;try{D=A(F6())}catch{a("lost");return}return D.binaryType="arraybuffer",b.current=D,D.onopen=()=>D.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),D.onmessage=O=>{if(!P)return;if(typeof O.data!="string"){const W=_6(O.data);if(!W||(f(L=>L&&L6(L,W.metadata)?L:W.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(W.jpeg).then(L=>{var B,V,F;const q=j.current;if(!P||!q){(B=L.close)==null||B.call(L);return}(q.width!==L.width||q.height!==L.height)&&(q.width=L.width,q.height=L.height),(V=q.getContext("2d"))==null||V.drawImage(L,0,0),(F=L.close)==null||F.call(L)}).catch(()=>{});return}const M=JSON.parse(O.data);if(M.type==="driving"){a("driving"),o(null);return}(M.type==="refused"||M.type==="ended")&&(o(M.error??"The screen cannot be driven from here."),a("refused"))},D.onclose=()=>{P&&a(O=>O==="refused"?O:"lost")},D.onerror=()=>{P&&a(O=>O==="refused"?O:"lost")},()=>{P=!1,b.current=null;try{D.close()}catch{}}},[e,t,g,r]),h.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=h.useCallback(A=>{const P=b.current;if(P)try{P.send(JSON.stringify({type:"input",input:A}))}catch{}},[]),N=A=>{var O;const P=j.current;if(!P||!d)return null;const D=(O=P.getBoundingClientRect)==null?void 0:O.call(P);return D?I6(D,d,A.clientX,A.clientY):null},k=A=>{const P=w.current,D=Date.now();clearTimeout(P.timer),P.timer=void 0;const O=P.at+O6-D;if(O<=0){P.at=D,P.pending=void 0,y(A);return}P.pending=A,P.timer=setTimeout(()=>{const M=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),M&&y(M)},O)},S=()=>{const A=w.current;clearTimeout(A.timer),A.timer=void 0;const P=A.pending;A.pending=void 0,P&&(A.at=Date.now(),y(P))},C=A=>P=>{var M,W;const D=N(P);if(!D)return;A==="mousePressed"&&(P.preventDefault(),(W=(M=j.current)==null?void 0:M.focus)==null||W.call(M));const O={kind:"mouse",type:A,x:D.x,y:D.y,button:D6[P.button]??"left",clickCount:A==="mouseMoved"?0:Math.min(3,Math.max(1,P.detail||1)),modifiers:vm(P)};if(A==="mouseMoved"){k(O);return}S(),y(O)},$=A=>{const P=N(A);P&&(S(),y({kind:"wheel",x:P.x,y:P.y,deltaX:Math.round(A.deltaX),deltaY:Math.round(A.deltaY)}))},R=A=>A.ctrlKey||A.metaKey||A.altKey,I=A=>{var D,O;if(A.key==="Escape"&&R(A)){p(!1),(O=(D=A.target).blur)==null||O.call(D);return}if(A.preventDefault(),(A.metaKey||A.ctrlKey)&&(A.key==="v"||A.key==="V"))return;const P=vm(A);if(yk(A.key)&&!R(A)){y({kind:"key",type:"char",key:A.key,code:A.code,text:A.key,modifiers:P});return}y({kind:"key",type:"keyDown",key:A.key,code:A.code,modifiers:P})},U=A=>{A.key==="Escape"&&R(A)||(A.preventDefault(),!((A.metaKey||A.ctrlKey)&&(A.key==="v"||A.key==="V"))&&(yk(A.key)&&!R(A)||y({kind:"key",type:"keyUp",key:A.key,code:A.code,modifiers:vm(A)})))},z=A=>{var D;A.preventDefault();const P=M6(((D=A.clipboardData)==null?void 0:D.getData("text/plain"))??"");P!==""&&y({kind:"text",text:P})};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(ae,{align:"end",children:[n.jsx(T,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var P,D,O,M;const A=!m;p(A),A?(D=(P=v.current)==null?void 0:P.focus)==null||D.call(P):(M=(O=v.current)==null?void 0:O.blur)==null||M.call(O)},children:"Keyboard"}),n.jsx(T,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(G,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(ae,{align:"end",children:n.jsx(T,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),x(A=>A+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(G,{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:U,onPaste:z,onContextMenu:A=>A.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.jsx("input",{ref:v,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:I,onKeyUp:U,onPaste:z,onBlur:()=>p(!1)})]})}function U6(e){return e==="darwin"?"this Mac":"this computer"}let jm=null;function jj(){const[e,t]=h.useState(void 0);return h.useEffect(()=>{let s=!0;return jm??(jm=E.session().then(r=>r.platform,()=>{jm=null})),jm.then(r=>{s&&t(r)}),()=>{s=!1}},[]),U6(e)}function B6({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=ce(()=>E.browser(),[],3e3),a=ce(()=>E.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(le,{message:r}),!s||!o?n.jsx(xe,{children:"Checking the host…"}):n.jsx(W6,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function W6({data:e,macOS:t,reload:s,timezone:r}){var S,C,$;const[i,a]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1),d=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,f=(d==null?void 0:d.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,x=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 x(()=>E.browserSettings(R)),j=e.permissions,v=f==="playwright"?e.browser:void 0,w=((C=v==null?void 0:v.install)==null?void 0:C.state)==="running",y=(v==null?void 0:v.engine)==="none",N=!!e.enabled&&!y&&!(v!=null&&v.problem)&&(!m||!(j!=null&&j.supported)||j.accessibility&&j.screenRecording),k=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.":(v==null?void 0:v.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(se,{gap:"lg",children:[n.jsx(le,{message:l}),n.jsx(oe,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",disabled:i,onClick:()=>void x(()=>E.computerPermissions(!1)),children:"Check again"}),m&&!N&&(j!=null&&j.supported)?n.jsx(T,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void x(()=>E.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(T,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void x(()=>E.browserInstall()),children:w?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(se,{children:[e.enabled?y?n.jsxs(G,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):v!=null&&v.problem?n.jsx(G,{tone:"warning",children:v.message}):N?n.jsx(G,{tone:"good",children:k}):n.jsx(G,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(G,{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,(($=v==null?void 0:v.install)==null?void 0:$.state)==="running"?n.jsx(uA,{progress:v.install.progress}):v!=null&&v.install?n.jsx("p",{className:"muted",role:"status",children:v.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${v.install.line??"no reason given"}`}):null,v!=null&&v.headless&&!y?n.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&(j!=null&&j.message)?n.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!N?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(oe,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(T,{variant:"danger",size:"sm",disabled:i,onClick:()=>void x(()=>E.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:tt(R.session.agentId,R.session.conversationId),children:[n.jsx(Us,{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))})}),d?n.jsxs(n.Fragment,{children:[n.jsx(oe,{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(wm,{current:d.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({...d,mode:"computer"})}):null,n.jsx(wm,{current:d.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({...d,mode:"playwright"})}),n.jsx(wm,{current:d.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({...d,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,d.mode==="extension"?n.jsx(J6,{busy:i,timezone:r}):null]})}),t?n.jsx(oe,{title:"Apps agents may use",panel:!0,children:n.jsxs(se,{children:[d.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(Z6,{settings:d,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(yt,{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(rB,{chosen:d.allowedApps,onClose:()=>u(!1),onPick:R=>{u(!1),d.allowedApps.includes(R)||b({...d,allowedApps:[...d.allowedApps,R]})}}):null]}):null]})}const H6="kmbckpnnjfggeffkkbmkggojnolkdokb",K6="pbfpjefkiijjgefblpnlnlpmeaddfbah",V6="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",G6=[H6,K6].filter(Boolean);function Y6(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 q6(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of G6)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 Q6(e=navigator){var s,r,i;const t=e.userAgent??"";return(s=e.userAgentData)!=null&&s.mobile||/Android|iPhone|iPad|iPod|Mobile/i.test(t)?"phone":(i=(r=e.userAgentData)==null?void 0:r.brands)!=null&&i.some(a=>/Chromium/i.test(a.brand))||/Chrome\/|Chromium\/|Edg\//.test(t)&&!/Firefox\/|OPR\//.test(t)?"chromium":"other"}function X6(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function J6({busy:e,timezone:t}){const{data:s,error:r,reload:i}=ce(()=>E.extension(),[],3e3),a=jj(),l=ce(()=>q6(),[],3e3).data??null,[o,c]=h.useState(""),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";h.useEffect(()=>{p&&c(p)},[p]);const g=async w=>{d(!0),m(null);try{await w()}catch(y){m(y instanceof Error?y.message:String(y))}finally{d(!1),i()}},x=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,j=Q6(),v=j==="phone"?null:j==="other"?n.jsx("p",{className:"muted",children:"The buddi extension needs Chrome, Edge, Brave or Arc on a computer. Open this page in one of them to install it."}):n.jsxs(se,{children:[n.jsxs(ae,{children:[n.jsx("span",{className:"muted",children:"Install the buddi extension from the Chrome Web Store, then pair it here."}),n.jsx(Dt,{}),n.jsx(Nt,{variant:"accent",href:V6,target:"_blank",rel:"noopener noreferrer",children:"Add to Chrome"})]}),n.jsx(yt,{summary:"Developer install",children: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(It,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]})})]});return n.jsxs(se,{divided:!0,children:[n.jsx(le,{message:r??f}),n.jsxs(ae,{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 ${nt(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}.`:j==="phone"?"The extension runs in Chrome, Edge, Brave or Arc on a computer: install and pair it from there.":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)&&Y6(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&&!X6(l.gateway)?n.jsx(G,{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(ae,{valign:"end",children:[n.jsx(ie,{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:w=>c(w.target.value)})}),n.jsx(Dt,{}),n.jsx(T,{variant:"accent",disabled:x||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await E.pairExtension(o),c("")}),children:"Pair"})]}):null,v?s!=null&&s.connected?n.jsx(yt,{summary:"Pair a different browser",children:v}):v:null,n.jsx(ae,{align:"end",children:n.jsx(T,{variant:"danger",disabled:x||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>E.forgetExtension()),children:"Forget this browser"})})]})}function wm({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 Z6({settings:e,disabled:t,onChange:s,onAdd:r}){const i=ce(()=>E.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(xe,{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(Us,{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(ae,{children:[l!==e.browserApp&&sB(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(ae,{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"&&eB.includes(e.browserApp)?n.jsx(tB,{settings:e,disabled:t,onChange:s}):null]})}const eB=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function tB({settings:e,disabled:t,onChange:s}){var l;const i=((l=ce(()=>E.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(ie,{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 nB=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function sB(e){return nB.includes(e)}function rB({chosen:e,onClose:t,onPick:s}){const r=ce(()=>E.installedApps(),[]),[i,a]=h.useState(""),[l,o]=h.useState(""),c=h.useMemo(()=>{var f;const u=((f=r.data)==null?void 0:f.apps)??[],d=i.trim().toLowerCase();return u.filter(m=>!d||m.name.toLowerCase().includes(d)||m.id.toLowerCase().includes(d)).slice(0,60)},[r.data,i]);return n.jsxs(ft,{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(le,{message:r.error}),r.data?c.length===0?n.jsx(xe,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const d=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Us,{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:d,onClick:()=>s(u.id),children:d?"Allowed":"Allow"})]},u.id)})}):n.jsx(xe,{children:"Reading your Applications folder…"}),n.jsx(yt,{summary:"Add by bundle identifier instead",children:n.jsxs(ae,{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 iB({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,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[x,b]=h.useState(null),j=async U=>{d(!0),m(null),b(null);try{const z=U!=="stop"&&(e!=null&&e.session)?await E.browserControl(U,e.session.id):await E.browserControl(U);U==="takeover"?z.hand&&z.session?g(z.session.id):b(z.handMessage??null):g(null)}catch(z){m(z instanceof Error?z.message:String(z))}finally{d(!1),s()}},v=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",N=(e==null?void 0:e.mode)==="extension",k=y?"Stop computer control interrupts native input and revokes access. Take over pauses agent input. Release ends this conversation’s control without closing your apps. Already dispatched actions cannot be undone. Avoid using the same mouse and keyboard while the agent is working.":"Stop all browsers closes every session and revokes access until you resume. Take over, Resume and Close & release affect only the selected conversation. An in-flight action is interrupted by closing its tabs. Actions already submitted cannot be undone.",S=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",C=e!=null&&e.busy||(e==null?void 0:e.state)==="running"?"good":(e==null?void 0:e.state)==="stopped"||(e==null?void 0:e.state)==="error"?"critical":void 0;return n.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[n.jsxs("div",{className:"browser-heading",children:[n.jsxs("div",{children:[r?null:n.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),n.jsx("h2",{className:"browser-title",children:y?"Computer":N?"Your browser":"Browser"})]}),n.jsx(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.":N?"Your own Chrome, signed in as you, working in background tabs grouped as “buddi”. You keep browsing.":"A real browser window, driven by your assistant. You stay in control."}),n.jsx(le,{message:t??f}),c?n.jsxs(ae,{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(yt,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:k})}):n.jsx("p",{className:"muted",children:k}):null,x?n.jsx(G,{tone:"warning",role:"status",children:x}):null,e!=null&&e.message&&!v?n.jsx(G,{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 ",Wt(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."}),v?n.jsx(z6,{sessionId:v,csrf:ia(),onGiveBack:()=>void j("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!v,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((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 · ",Wt(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(yt,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(U=>n.jsxs("li",{children:[U.title||U.id," — ",U.url]},U.id))})}):null,n.jsxs("p",{className:"muted",children:[y?"Sign in directly in the host app during takeover. Don’t send passwords or MFA codes in chat. Native apps retain your existing logins and documents. Secure accessibility fields are masked; other sensitive window content can still appear in screenshots.":"Sign in directly in this conversation’s host tab during takeover. Don’t send passwords or MFA codes in chat. Agent tabs share saved logins and cookies."," ",v?"While you are driving this is a live view of the page; nothing you type is kept.":"Screenshots update after agent actions; this is not a live video feed."]})]})}const aB=2e3,lB=5;function oB(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 cB({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var w;const[l,o]=h.useState(0),[c,u]=h.useState(0),d=c>=lB;h.useEffect(()=>{if(!i||d)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(N=>N+1)},aB);return()=>window.clearInterval(y)},[i,d]);const f=h.useRef(null);i&&(e!=null&&e.session)&&(f.current=e);const[m,p]=h.useState(null),g=h.useRef(null),x=((w=e==null?void 0:e.page)==null?void 0:w.id)??null;h.useEffect(()=>{const y=i&&e?oB(e):null;if(!y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let N=!1;return(async()=>{try{const k=await fetch(y);if(!k.ok||N)return;const S=await k.blob();if(N)return;const C=URL.createObjectURL(S);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{N=!0}},[i,x]),h.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,v=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(iB,{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?d?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(uB,{steps:r,newestId:(v==null?void 0:v.id)??null,focusedId:a??null,live:i})]})}function uB({steps:e,newestId:t,focusedId:s,live:r}){const i=h.useRef(null);return h.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 dB({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=ce(()=>E.host(e,t),[e,t],2e3),[a,l]=h.useState(null),[o,c]=h.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)}},d=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=d.some(p=>!p.conversationId)?"Always allowed":d.length?"Conversation auto-mode":"Ask each time";return n.jsx(yt,{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(le,{message:a??r}),d.map(p=>n.jsxs(ae,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(T,{size:"sm",disabled:o,onClick:()=>void u(()=>E.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),d.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(It,{children:p.command}),n.jsx(It,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
105
+ ${p.stderr}`:"Waiting for output…"}),n.jsx(ae,{children:n.jsx(T,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>E.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const dA="browser.act",hB="browser.status",Xu=new Set([dA,hB]);function fB(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 mB(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function pB(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===dA){const o={id:a.id,action:gB(a.input)??"act",target:xB(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:vB(a)}}return t}function bk(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=Xu.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 gB(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function xB(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 vB(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 jB({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(0);return h.useEffect(()=>{let m=!1;return o(null),u(null),(t?He.groupConversations(t):He.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,d]),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?Oi(t,m.id):tt(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:[nt(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 hA="buddi.dismissedTabs";function wB(){try{const e=JSON.parse(sessionStorage.getItem(hA)??"{}");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 kk(e){try{sessionStorage.setItem(hA,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const yB=350,bB=60;function kB({conversationId:e,onText:t,onNotice:s}){const[r,i]=h.useState("idle"),a=h.useRef("idle"),l=v=>{a.current=v,i(v)},o=h.useRef(null),c=h.useRef(null),u=h.useRef(null),d=h.useRef(null),f=h.useRef(null),m=h.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 v;try{v=await B3(N=>{var k;return(k=f.current)==null?void 0:k.call(f,N)})}catch(N){d.current=null,l("idle"),m.current.onNotice(U3(N));return}const w=c.current;c.current=null;const y=a.current;if(w==="discard"||y!=="starting"){v.cancel(),y==="starting"&&l("idle");return}o.current=v,l("recording"),u.current=window.setTimeout(()=>void x(!1),_3),w&&x(w.sendNow)},x=async v=>{d.current=null;const w=o.current;if(!w){a.current==="starting"&&(c.current={sendNow:v});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const N=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),k=await He.attach(N),S=m.current.conversationId,C=await He.transcribe({artifactId:k.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,v)}catch(y){m.current.onNotice(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l("idle")}},b=()=>{d.current=null;const v=o.current;if(!v){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};h.useEffect(()=>{const v=w=>{if(d.current===null)return;const y=Date.now()-d.current;d.current=null,y>=yB&&x(w.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const j=r==="starting"||r==="recording";return h.useEffect(()=>{if(!j)return;const v=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),b()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),x(w.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[j]),h.useEffect(()=>()=>{var v;(v=o.current)==null||v.cancel(),p()},[]),{state:r,hold:()=>{d.current=Date.now(),g()},start:()=>{d.current=null,g()},finish:v=>void x(v),discard:b,levels:f}}function NB({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(ue,{name:"mic"})})}function SB({voice:e}){const t=h.useRef(null),s=e.state==="transcribing";return h.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(CB,{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(ue,{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(ue,{name:"check"})})]})]})}function CB({sink:e,frozen:t}){const[s,r]=h.useState(()=>Array(bB).fill(0));return h.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 EB="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",yu="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",AB=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function TB(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(EB);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(AB(i))return null;throw new Error(yu)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((d,f)=>{a.onloadedmetadata=()=>d(),a.onerror=()=>f(new Error(yu))}),await a.play(),await new Promise(d=>{const f=a.requestVideoFrameCallback;typeof f=="function"?f.call(a,()=>d()):setTimeout(d,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(yu);o.drawImage(a,0,0);const c=await new Promise(d=>l.toBlob(d,"image/png"));if(!c)throw new Error(yu);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 Nk="Send files once the agent has answered.",Og="wb-composer-input",wj=h.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:d,onOpenFile:f,mentions:m,history:p,threadKey:g,conversationId:x,readAloud:b,onReadAloud:j,placeholder:v,slim:w},y){var Un;const N=g?`buddi.draft.${g}`:null,k=Q=>{if(!Q)return"";try{return window.localStorage.getItem(Q)??""}catch{return""}},[S,C]=h.useState(()=>k(N)),[$,R]=h.useState([]),[I,U]=h.useState(!1),[z,A]=h.useState(null),[P,D]=h.useState(!1),O=h.useRef(null),M=h.useRef(null),[W,L]=h.useState(null),[q,B]=h.useState(0),V=W&&m?m.filter(Q=>Q.handle.toLowerCase().startsWith(W.query.toLowerCase())||Q.name.toLowerCase().startsWith(W.query.toLowerCase())).slice(0,6):[],F=(Q,$e)=>{if(!m||m.length===0){L(null);return}const Xe=Q.slice(0,$e),K=/(^|\s)@([\w-]*)$/.exec(Xe);if(!K){L(null);return}L({start:$e-K[2].length-1,query:K[2]}),B(0)},X=Q=>{if(!W)return;const $e=M.current,Xe=$e?$e.selectionStart:S.length,K=`${S.slice(0,W.start)}@${Q} ${S.slice(Xe)}`;C(K),Z<0&&ze(K),L(null),window.requestAnimationFrame(()=>{if(!$e)return;const _e=W.start+Q.length+2;$e.focus(),$e.setSelectionRange(_e,_e),J()})},Y=p??[],[Z,he]=h.useState(-1),Le=h.useRef(S),Ie=h.useRef(N);if(Ie.current!==N){Ie.current=N;const Q=k(N);Le.current=Q,Q!==S&&(C(Q),he(-1),L(null))}const ze=Q=>{if(Le.current=Q,!!N)try{Q===""?window.localStorage.removeItem(N):window.localStorage.setItem(N,Q)}catch{}},ee=Q=>{C(Q),L(null);const $e=M.current;$e&&($e.value=Q,$e.setSelectionRange(Q.length,Q.length)),window.requestAnimationFrame(J)},be=Q=>!Q.value.slice(0,Q.selectionStart??Q.value.length).includes(`
106
+ `),re=()=>S===""||Z>=0&&S===Y[Z],Ee=()=>{Z<0||(he(-1),ee(Le.current))},me=$.some(Q=>Q.state==="uploading"),Re=$.length>0,Se=s&&Re,Ue=!t&&!me&&!Se&&S.trim()!=="",et=Q=>{for(const $e of Array.from(Q??[])){const Xe=`${$e.name}:${$e.size}:${Math.random().toString(36).slice(2,8)}`,K=$e.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL($e):null;R(_e=>[..._e,{key:Xe,filename:$e.name||"Pasted image",mime:$e.type||"application/octet-stream",sizeBytes:$e.size,thumbnail:K,state:"uploading"}]),He.attach($e).then(_e=>R(je=>je.map(Ke=>Ke.key===Xe?{...Ke,state:"ready",uploaded:_e}:Ke))).catch(_e=>R(je=>je.map(Ke=>Ke.key===Xe?{...Ke,state:"failed",error:_e instanceof pe?_e.message:String(_e)}:Ke)))}},Ae=Q=>{Q.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Q.thumbnail)},Be=Q=>{const $e=$.find(Xe=>Xe.key===Q);$e&&(Ae($e),$e.state==="ready"&&$e.uploaded&&He.discardAttachment($e.uploaded.artifactId).catch(()=>{})),R(Xe=>Xe.filter(K=>K.key!==Q))};h.useImperativeHandle(y,()=>({addFiles:Q=>{var $e;et(Q),($e=M.current)==null||$e.focus()},focus:()=>{var Q;return(Q=M.current)==null?void 0:Q.focus()}}));const it=h.useRef($);it.current=$,h.useEffect(()=>()=>it.current.forEach(Ae),[]);const qe=h.useRef(0);h.useEffect(()=>{if(!l||l.at===qe.current)return;qe.current=l.at,C($e=>$e.trim()===""?l.text:$e),Z<0&&S.trim()===""&&ze(l.text);const Q=M.current;Q&&(Q.focus(),window.requestAnimationFrame(()=>{Q.style.height="auto",Q.style.height=`${Math.min(Q.scrollHeight,200)}px`,Q.setSelectionRange(Q.value.length,Q.value.length)}))},[l]);const J=()=>{const Q=M.current;Q&&(Q.style.height="auto",Q.style.height=`${Math.min(Q.scrollHeight,200)}px`)},we=Q=>{const $e=(Q??S).trim();if(Q===void 0?!Ue:t||me||Se||$e==="")return;const Xe=$.filter(K=>K.state==="ready"&&K.uploaded).map(K=>K.uploaded);r($e,Xe),$.forEach(Ae),he(-1),ze(""),C(""),R([]),window.requestAnimationFrame(J)},Ye=Q=>{if(W&&V.length>0){if(Q.key==="ArrowDown"){Q.preventDefault(),B($e=>($e+1)%V.length);return}if(Q.key==="ArrowUp"){Q.preventDefault(),B($e=>($e-1+V.length)%V.length);return}if(Q.key==="Enter"||Q.key==="Tab"){Q.preventDefault(),X(V[q].handle);return}if(Q.key==="Escape"){Q.preventDefault(),L(null);return}}if(Q.key==="ArrowUp"&&!Q.shiftKey&&!Q.altKey&&!Q.metaKey&&!Q.ctrlKey){const $e=Q.currentTarget;if(Y.length>0&&Z+1<Y.length&&be($e)&&re()){Q.preventDefault(),Z<0&&(Le.current=S),he(Z+1),ee(Y[Z+1]);return}}if(Q.key==="ArrowDown"&&!Q.shiftKey&&!Q.altKey&&!Q.metaKey&&!Q.ctrlKey&&Z>=0&&S===Y[Z]){if(Q.preventDefault(),Z===0){Ee();return}he(Z-1),ee(Y[Z-1]);return}if(Q.key==="Escape"&&Z>=0){Q.preventDefault(),Ee();return}Q.key==="Enter"&&!Q.shiftKey&&(Q.preventDefault(),we())},ot=Q=>{var Xe;const $e=Array.from(((Xe=Q.clipboardData)==null?void 0:Xe.files)??[]);$e.length!==0&&(Q.preventDefault(),et($e))},ct=$.filter(Q=>Q.state==="failed"),Tt=ct.length,zn=kB({conversationId:x??null,onNotice:A,onText:(Q,$e)=>{const Xe=S.trim()===""?Q:`${S.replace(/\s+$/,"")} ${Q}`;if($e){we(Xe);return}ee(Xe),Z<0&&ze(Xe)}}),jt=zn.state!=="idle",dn=h.useRef(!1);return h.useEffect(()=>{var Q;dn.current&&!jt&&((Q=M.current)==null||Q.focus(),window.requestAnimationFrame(J)),dn.current=jt},[jt]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-slim":w||void 0,"data-busy":S.trim()!==""||Re||jt?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":P||jt,"data-disabled":t,"data-listening":jt||void 0,children:[$.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:$.map(Q=>n.jsx("span",{role:"listitem",children:n.jsx(Jh,{name:Q.filename,mime:Q.mime,sizeBytes:Q.sizeBytes,thumbnail:Q.thumbnail,state:Q.state,error:Q.error,onRemove:()=>Be(Q.key),...f&&Q.state==="ready"&&Q.uploaded?{onOpen:()=>f(RB(Q.uploaded))}:{},size:"sm"})},Q.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:Og,children:["Message ",a]}),n.jsx("textarea",{id:Og,ref:M,value:S,rows:w?1:2,placeholder:s?`${a} is working…`:v??`Message ${a}`,onChange:Q=>{C(Q.target.value),Z<0&&ze(Q.target.value),F(Q.target.value,Q.target.selectionStart??Q.target.value.length),J()},onFocus:()=>D(!0),onBlur:()=>D(!1),onKeyDown:Ye,onPaste:ot,disabled:t,hidden:jt}),jt?n.jsx(SB,{voice:zn}):null,!jt&&W&&V.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:V.map((Q,$e)=>n.jsxs("button",{type:"button",role:"option","aria-selected":$e===q,className:"wb-mention","data-active":$e===q||void 0,onMouseDown:Xe=>{Xe.preventDefault(),X(Q.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",Q.handle]}),n.jsx("span",{className:"wb-mention-name",children:Q.name})]},Q.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:jt,children:[n.jsx("input",{ref:O,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:Q=>{et(Q.target.files),Q.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 Q;return(Q=O.current)==null?void 0:Q.click()},disabled:t,children:n.jsx(ue,{name:"clip"})}),n.jsx(NB,{disabled:t,voice:zn}),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:()=>{A(null),U(!0),TB().then(Q=>{var $e;Q&&(et([Q]),($e=M.current)==null||$e.focus())}).catch(Q=>A(Q instanceof Error?Q.message:String(Q))).finally(()=>U(!1))},disabled:t||I,children:n.jsx(ue,{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,d?n.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":bu(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${bu(u)?"on":"off"}`:bu(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:()=>d(bu(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(ue,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":S!==""&&!s||Tt>0||Se||z!==null,"data-tone":Tt>0||z!==null?"critical":void 0,children:Tt>0?Tt===1&&((Un=ct[0])!=null&&Un.error)?ct[0].error:`${Tt} files failed to upload and will not be sent`:z!==null?z:Se?Nk:"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:Se?Nk:me?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>we(),disabled:!Ue,children:n.jsx(ue,{name:"send"})})]})]})})});function bu(e){return(e??"on")==="on"}function RB(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function $B({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=h.useState("");return h.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:IB(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 IB(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 PB(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 MB(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 DB(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 ${MB(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(PB(t,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?De(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${nt(s,i)}. ${l}`:l,tone:"quiet"}}function OB({text:e,onDelete:t}){const[s,r]=h.useState(!1),[i,a]=h.useState(null);return n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:n.jsxs(yt,{summary:"Carried over from the previous conversation",children:[n.jsx("p",{className:"wb-carryover-text",children:e}),n.jsxs(ae,{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 fA(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function mA(e,t){return e.members.map(s=>t.find(r=>r.id===s)).filter(s=>s!==void 0)}function LB(e,t){var i;const s=mA(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 _B(){return n.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function FB({group:e,agents:t,onClose:s,onSaved:r}){const[i,a]=h.useState(!1),[l,o]=h.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,d=tj(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 He.updateGroup(e.id,g))}catch(x){o(x instanceof pe?x.message:String(x))}finally{a(!1)}},p=g=>void m({members:e.members.filter(x=>x!==g)});return n.jsxs(ft,{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(G,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?n.jsx(G,{tone:"critical",children:l}):null,n.jsx(ht,{children:c.map(g=>{const x=t.find(j=>j.id===g),b=g===e.coordinator;return x?n.jsx(st,{lead:n.jsx(ln,{agents:t,id:g}),title:x.name,sub:x.description,side:n.jsxs(n.Fragment,{children:[b?n.jsx(ve,{tone:"accent",children:"Coordinator"}):null,f&&x.available?n.jsx(T,{size:"sm",disabled:i,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,n.jsx(Al,{label:`More for ${x.name}`,...b?{note:"Coordinates the group"}:{},items:[!b&&x.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:g})},{label:`Open ${x.name}'s page`,onSelect:()=>{window.location.hash=Et(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(st,{lead:n.jsx(_B,{}),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"}),d.length>0?n.jsx(ht,{children:d.map(g=>n.jsx(st,{lead:n.jsx(ln,{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 zB({group:e,onClose:t,onSaved:s}){const[r,i]=h.useState(e.name),[a,l]=h.useState(!1),[o,c]=h.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!a,d=async()=>{if(u){l(!0),c(null);try{s(await He.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof pe?f.message:String(f)),l(!1)}}};return n.jsx(un,{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 d(),children:a?"Renaming…":"Rename"})]}),children:n.jsx("form",{onSubmit:f=>{f.preventDefault(),d()},children:n.jsxs(se,{children:[n.jsx(ie,{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(G,{tone:"critical",children:o}):null]})})})}function pA(e){const[t,s]=h.useState(null);return h.useEffect(()=>{let r=!0;return He.group(e).then(i=>{var a;r&&s(((a=i.history)==null?void 0:a.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),t}function UB(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function BB({group:e,onClose:t,onCleared:s}){const r=pA(e.id),[i,a]=h.useState(!1),[l,o]=h.useState(null),c=async()=>{a(!0),o(null);try{await He.clearGroup(e.id),s()}catch(d){o(d instanceof pe?d.message:String(d)),a(!1)}},u=r===0;return n.jsxs(un,{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.":`${UB(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(G,{tone:"critical",children:l}):null]})}function WB({group:e,agents:t,onClose:s,onDeleted:r}){const i=pA(e.id),[a,l]=h.useState(!1),[o,c]=h.useState(null),u=mA(e,t).map(m=>m.name),d=async()=>{l(!0),c(null);try{const{undoUntil:m}=await He.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(un,{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 d(),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?`${fA(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?n.jsx(G,{tone:"critical",children:o}):null]})}const Ju=320,gA="buddi.chatWidth";function HB({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onGroupAction:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:d,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:x,requestedTab:b,onConversationOpened:j}){var Iw,Pw,Mw,Dw,Ow,Lw;const v=jj(),[w,y]=h.useState([]),[N,k]=h.useState(null),[S,C]=h.useState(null),[$,R]=h.useState(null),[I,U]=h.useState([]),[z,A]=h.useState([]),[P,D]=h.useState(null),[O,M]=h.useState(!1),[W,L]=h.useState(new Map),[q,B]=h.useState(null),[V,F]=h.useState(wB),[X,Y]=h.useState([]),[Z,he]=h.useState(!1),Le=h.useRef(0),Ie=h.useRef(null),[ze,ee]=h.useState(!1),be=h.useRef(g??0),re=h.useRef(s),Ee=h.useRef({agentId:s,conversationId:N});Ee.current={agentId:s,conversationId:N};const me=V[N??""]??[],[Re,Se]=h.useState(null),[Ue,et]=h.useState(null),[Ae,Be]=h.useState(null),[it,qe]=h.useState([]),[J,we]=h.useState(!1),[Ye,ot]=h.useState(()=>Date.now()),[ct,Tt]=h.useState(KB),zn=h.useRef(null),[jt,dn]=h.useState(null),[Un,Q]=h.useState(!1),[$e,Xe]=h.useState(null),[K,_e]=h.useState(QE),je=h.useRef(K);je.current=K;const Ke=h.useRef(null),[Fe,Qt]=h.useState(null),bs=h.useCallback(H=>{_e(H),XE(H),H||$l()},[]),[wn,ks]=h.useState(null),[Ns,ye]=h.useState(null);h.useEffect(()=>{if(!s)return;const H=YB(s);H&&Xe({text:H,at:Date.now()})},[s]);const Ce=i?`group:${i.id}`:s??null,We=[...t.top,...t.middle,...t.bottom],fe=We.find(H=>H.id===s)??null,Bn=ce(()=>E.providerAccounts(),[]),Rn=i?i.members.map(H=>We.find(te=>te.id===H)).filter(H=>!!H):[],[Ws,Fl]=h.useState(null),Ti=O?Ws??s??null:null;h.useEffect(()=>{o==null||o(Ti)},[Ti,o]),h.useEffect(()=>()=>o==null?void 0:o(null),[o]),h.useEffect(()=>{let H=!1;return He.views().then(te=>{H||y(te.views??[])}).catch(()=>{}),()=>{H=!0}},[]),h.useEffect(()=>{if(!s)return;const H=re.current===s;if(re.current=s,H&&x&&x===Ee.current.conversationId)return;let te=!1;return k(null),C(null),R(null),U([]),Se(null),M(!1),B(null),Y([]),Dc(null),ee(!1),dn(null),x?(x!=="new"?k(x):R(Ce),()=>{te=!0}):((i?He.groupConversations(i.id):He.conversations(s)).then(ke=>{if(te)return;const Me=[...ke.conversations??[]].sort(VB)[0];Me?(k(Me.id),j==null||j(s,Me.id)):R(Ce)}).catch(()=>{te||R(Ce)}),()=>{te=!0})},[s,i==null?void 0:i.id,Ce,x,j]);const $n=h.useCallback(H=>He.conversation(H).then(te=>{if(Ee.current.conversationId===H){if(te.agentId!==Ee.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(te),U(ke=>ke.filter(Me=>!ym(te,Me)))}}).catch(te=>{Ee.current.conversationId===H&&Se(Kr(te))}),[]);h.useEffect(()=>{if(!N)return;let H=!1;return L(new Map),A([]),He.conversation(N).then(te=>{if(!H){if(te.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(te),U(ke=>ke.filter(Me=>!ym(te,Me)))}}).catch(te=>{H||Se(Kr(te))}),()=>{H=!0}},[N,s]),h.useEffect(()=>{if(!N)return;let H=!1;const te=window.setInterval(()=>{He.conversation(N).then(ke=>{H||ke.agentId!==Ee.current.agentId||(C(ke),U(Me=>Me.filter(Ze=>!ym(ke,Ze))))}).catch(()=>{})},3e3);return()=>{H=!0,window.clearInterval(te)}},[N,s]),h.useEffect(()=>{if(!N)return;const H=zh({url:He.streamUrl(N),onEvent:te=>{var ke;switch(te.name){case"run.started":Ke.current=null,M(!0),D(null),Fl(rn(te.data.agentId));break;case"live":{const Me=rn(te.data.runId)??"",Ze=Number(te.data.turn??0),Ge=te.data.kind==="thinking"?"thinking":"text",yn=rn(te.data.text)??"",pr=Date.now();if(Ge==="text"){const Ks=Ke.current;Ke.current=Ks&&Ks.runId===Me&&Ks.turn===Ze?{...Ks,text:Ks.text+yn}:{runId:Me,turn:Ze,text:yn}}D(Ks=>{const pa=Ks&&Ks.runId===Me&&Ks.turn===Ze?Ks:{runId:Me,turn:Ze,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ge==="thinking"?{...pa,thinking:pa.thinking+yn,thinkingStartedAt:pa.thinkingStartedAt??pr}:{...pa,text:pa.text+yn,textStartedAt:pa.textStartedAt??pr}});break}case"live.snapshot":{const Me=rn(te.data.runId)??"",Ze=Number(te.data.turn??0),Ge=rn(te.data.text)??"",yn=rn(te.data.thinking)??"",pr=Number(te.data.startedAt??Date.now());Ke.current={runId:Me,turn:Ze,text:Ge},D({runId:Me,turn:Ze,text:Ge,thinking:yn,thinkingStartedAt:yn?pr:null,textStartedAt:Ge?pr:null,settled:!1});break}case"live.settle":{const Me=rn(te.data.runId)??"",Ze=Number(te.data.turn??0);D(Ge=>Ge&&Ge.runId===Me&&Ge.turn===Ze?{...Ge,settled:!0}:Ge);break}case"tool.called":{const Me=rn(te.data.toolUseId)??rn(te.data.id),Ze=rn(te.data.name)??rn(te.data.tool)??"tool";Me&&A(Ge=>[...Ge.filter(yn=>yn.toolUseId!==Me),{toolUseId:Me,name:Ze,startedAt:Date.now()}]);break}case"tool.result":{const Me=rn(te.data.toolUseId)??rn(te.data.id);Me&&A(Ze=>Ze.filter(Ge=>Ge.toolUseId!==Me)),$n(N);break}case"reaction":$n(N);break;case"message.appended":$n(N).then(()=>{D(Me=>Me!=null&&Me.settled?null:Me)});break;case"awaiting-approval":{const Me=rn(te.data.approvalId)??rn(te.data.actionId),Ze=rn(te.data.toolUseId);Me&&Ze&&L(Ge=>new Map(Ge).set(Ze,Me)),A(Ge=>Ge.filter(yn=>yn.toolUseId!==Ze)),$n(N);break}case"run.finished":{M(!1),A([]),D(null),Fl(null);const Me=rn(te.data.message);Se(Me??null);const Ze=((ke=Ke.current)==null?void 0:ke.text.trim())??"";Ke.current=null,!Me&&Ze!==""&&je.current&&Wd(Ze,N).then(Ge=>{Ge&&Qt(Ge)}),$n(N);break}}}});return()=>H.close()},[N,$n]),h.useEffect(()=>{const H=window.setInterval(()=>ot(Date.now()),z.length===0?6e4:1e3);return()=>window.clearInterval(H)},[z.length]);const Ri=ce(()=>s&&N?E.browser({agentId:s,conversationId:N}):Promise.resolve(void 0),[s,N],1500),mr=Ri.error?void 0:Ri.data,Wr=mr!=null&&mr.session&&mr.session.agentId===s&&mr.session.conversationId===N?mr:void 0,_t=fB(Wr,s,N),Hs=(_t==null?void 0:_t.id)??null,[zl,k$]=h.useState(null),mw=Wr==null?void 0:Wr.mode;h.useEffect(()=>{_t&&s&&N&&k$({agentId:s,conversationId:N,tab:mB(_t,mw)})},[Hs,mw,s,N]);const N$=zl&&zl.agentId===s&&zl.conversationId===N&&!me.includes(zl.tab.id)?zl.tab:null,hn=_t??N$,S$=h.useMemo(()=>pB((S==null?void 0:S.messages)??[]),[S]),[C$,Dc]=h.useState(null),E$=h.useMemo(()=>oU({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),fa=C6(E$,N??null),uf=A6(i?null:s),pw=h.useMemo(()=>E6((S==null?void 0:S.messages)??[]),[S]),Wn=h.useMemo(()=>{const te=cU({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:W,served:fa.served,...hn?{folded:Xu}:{}}).filter(ke=>ke.source==="approval"||!me.includes(ke.id));if(q&&!me.includes(q)&&!te.some(ke=>ke.id===q)){const ke=fU((S==null?void 0:S.messages)??[],q,{redactInputOf:Xu});ke&&!Xu.has(ke.tool)&&te.push(ke)}hn&&te.push(hn);for(const ke of X)te.push(Iz(ke));return uf&&te.unshift(T6(uf,pw)),jt?[...te,R6(jt)]:te},[S,w,W,jt,Hs,hn==null?void 0:hn.title,q,V,N,X,fa.served,uf,pw]),A$=h.useMemo(()=>{var te;const H=[];for(const ke of(S==null?void 0:S.messages)??[]){if(ke.role!=="user"||ke.speaker&&ke.speaker!=="owner")continue;const Me=(te=ke.blocks.find(Ze=>Ze.type==="text"))==null?void 0:te.text.trim();Me&&H.unshift(Me)}return H},[S]),df=h.useMemo(()=>Wn.filter(H=>H.source==="approval"),[Wn]),Oc=df.at(-1)??null,Lc=h.useMemo(()=>[...df.map(H=>({approvalId:H.props.approvalId,toolUseId:H.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(H=>({approvalId:H.approvalId,toolUseId:H.toolUseId??"",askedBy:XB(H.chain,We)}))],[df,S==null?void 0:S.delegatedApprovals]),Ul=h.useMemo(()=>{for(let H=Wn.length-1;H>=0;H-=1){const te=Wn[H];if(te!=null&&te.substantial)return te.id}return null},[Wn]),_c=h.useRef(null),hf=((Iw=Wn.filter(H=>(H.source!=="browser"||H.pinned===!0)&&H.id!==Mg).at(-1))==null?void 0:Iw.id)??((Pw=Wn.filter(H=>H.id!==Mg).at(-1))==null?void 0:Pw.id)??null;h.useEffect(()=>{if(Ul&&Ul!==_c.current){_c.current=Ul,B(Ul);return}q===null&&hf&&B(hf)},[Ul,q,hf]);const gw=h.useRef(fa.live);h.useEffect(()=>{const H=gw.current;gw.current=fa.live;const te=[...fa.live].filter(Ze=>!H.has(Ze));if(te.length===0||Oc||q!==null&&q!==_c.current)return;const Me=[...Wn].reverse().find(Ze=>Ze.source==="descriptor"&&Ze.renderer==="preview"&&Ze.props.target!==null&&te.includes(Xa(Ze.props.target)));Me&&B(Me.id)},[fa.live,Wn,Oc,q]);const xw=h.useRef(null);h.useEffect(()=>{Hs!==xw.current&&(xw.current=Hs,Hs&&!Oc&&B(Hs))},[Hs,Oc]);const vw=h.useRef(null),Bl=b==="browser"?(hn==null?void 0:hn.id)??null:null;h.useEffect(()=>{!Bl||vw.current===Bl||(vw.current=Bl,B(Bl))},[Bl]);const ff=(hn==null?void 0:hn.id)??null;h.useEffect(()=>{!ff||!q||bk((S==null?void 0:S.messages)??[],q)!==null&&(Dc(q),B(ff))},[ff,q,S]);const jw=H=>{Y(te=>te.some(ke=>ke.artifactId===H.artifactId)?te:[...te,H]),B(qu(H.artifactId)),d&&(m==null||m())},Fc=!i&&fe&&!fe.available?pE(fe):null,ww=i?n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:i.members.slice(0,2).map(H=>{const te=We.find(ke=>ke.id===H);return n.jsx(Kh,{className:"wb-group-chip",id:H,name:(te==null?void 0:te.name)??"?",face:te,initials:1},H)})}):null,$i=i&&We.length>0?LB(i,We):null,yw=($i==null?void 0:$i.kind)==="coordinator",bw=fg(i?null:fe),kw=((S==null?void 0:S.offers)??[]).filter(H=>!it.includes(H.id)&&Date.parse(H.expiresAt)>Ye),T$=fe&&Ns===fe.id?wn:(fe==null?void 0:fe.thinking)??null,R$=H=>{if(!fe)return;const te=fe.id;ye(te),ks(H),E.setAgentEngine(te,{thinking:H}).catch(ke=>{ye(null),Se(ke instanceof pe?ke.message:String(ke))})},mf=(H,te)=>{if(!s)return;const ke=te.map(Ge=>Ge.artifactId),Me=O,Ze={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:H},...te.map(Ge=>({type:"attachment",artifactId:Ge.artifactId,filename:Ge.filename,mime:Ge.mime,kind:Ge.kind,sizeBytes:Ge.sizeBytes}))],...Me?{speaker:lA}:{}};U(Ge=>Me?[...Ge,Ze]:[Ze]),Se(null),et(null),M(!0),(i?He.sendToGroup(i.id,{...N?{conversationId:N}:{},text:H,attachmentIds:ke}):He.send(s,{...N?{conversationId:N}:{},text:H,attachmentIds:ke})).then(async Ge=>{Ee.current.agentId!==s||Ee.current.conversationId!==N||(et(Ge.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ge.conversationId!==N?(C(null),k(Ge.conversationId)):await $n(Ge.conversationId),Ge.queued===!0&&U(yn=>yn.filter(pr=>pr.id!==Ze.id)),j==null||j(s,Ge.conversationId))}).catch(Ge=>{U(yn=>yn.filter(pr=>pr.id!==Ze.id)),Se(Kr(Ge)),M(!1)})},$$=H=>{Se(null),Be(H),qe(te=>[...te,H]),E.takeOffer(H,N??void 0).then(te=>{te.runId&&(et(null),M(!0)),N&&$n(N)}).catch(te=>{qe(ke=>ke.filter(Me=>Me!==H)),Se(Kr(te)),N&&$n(N)}).finally(()=>Be(null))},I$=(H,te)=>Nw({answer:H,...te?{optionId:te}:{}}),P$=()=>Nw({answer:"",skipped:!0}),Nw=H=>{const te=S==null?void 0:S.question;te&&(Se(null),we(!0),M(!0),He.answerQuestion(te.id,H).then(()=>{if(N)return $n(N)}).catch(ke=>{Se(Kr(ke)),M(!1)}).finally(()=>we(!1)))},M$=()=>{if(s){if(jt){dn(null);return}Q(!0),E.agentProfile(s).then(H=>{dn(H),B(Dg(H.id)),d&&(m==null||m())}).catch(H=>Se(Kr(H))).finally(()=>Q(!1))}},D$=H=>{Xe({text:H.prompt,at:Date.now()}),l(H.agentId),d&&(p==null||p())},O$=()=>{N&&He.cancel(N).catch(H=>Se(Kr(H))).finally(()=>{M(!1),A([])})},zc=h.useCallback(()=>{if(k(null),C(null),U([]),M(!1),Se(null),et(null),A([]),L(new Map),B(null),Y([]),Dc(null),_c.current=null,i){He.startGroupConversation(i.id).then(({conversationId:H})=>{k(H),s&&(j==null||j(s,H))}).catch(H=>Se(Kr(H)));return}R(Ce),s&&(j==null||j(s,"new"))},[s,i,Ce,j]);h.useEffect(()=>{g&&g!==be.current&&(be.current=g,zc())},[g,zc]);const Sw=H=>{N&&$n(N),E.overview().catch(()=>{}),H.state!=="pending"&&L(te=>new Map([...te].filter(([,ke])=>ke!==H.id)))},Uc=h.useRef(!1);h.useEffect(()=>{const H=ke=>{if(!Uc.current)return;const Me=Math.max(Ju,Math.min(720,ke.clientX-52));Tt(Me)},te=()=>{if(Uc.current){Uc.current=!1;try{ct!==null&&window.localStorage.setItem(gA,String(ct))}catch{}}};return window.addEventListener("pointermove",H),window.addEventListener("pointerup",te),()=>{window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",te)}},[ct]);const L$=((Mw=We.find(H=>H.id===r))==null?void 0:Mw.name)??null,Cw=i?[]:c4(fe,L$),Ew=!(S&&S.conversationId===N)&&!(!N&&$!==null&&$===Ce),Aw=Ew?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&fe?n.jsx(LE,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(ln,{agents:We,id:fe.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${fe.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:u4(fe)}),Cw.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${fe.name}`,children:Cw.map(H=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var te;Xe({text:H,at:Date.now()}),(te=Ie.current)==null||te.focus()},children:H},H))}):null]})}):null,Tw=n.jsx(m6,{renderables:Wn,activeId:q,onActivate:B,onClose:H=>{jt&&H===Dg(jt.id)?dn(null):X.some(te=>qu(te.artifactId)===H)?Y(te=>te.filter(ke=>qu(ke.artifactId)!==H)):N&&F(te=>{const ke={...te,[N]:[...new Set([...te[N]??[],H])]};return kk(ke),ke}),q===H&&B(null)},timezone:e,onDecided:Sw,onChangeAgent:D$,agents:We,browserPanel:hn?n.jsx(cB,{status:Wr,error:Ri.error,reload:Ri.reload,steps:S$,live:_t!==null,focusedStepId:C$},hn.id):null,descriptors:w,grantedTools:i?Rn.flatMap(H=>H.tools??[]):(fe==null?void 0:fe.tools)??[],...fe?{agentName:fe.name}:{},loading:Ew,...!i&&fe?{face:n.jsx(ln,{agents:We,id:fe.id,size:"xl"})}:{}}),Rw=(Ow=(Dw=[...(S==null?void 0:S.messages)??[],...I].find(H=>H.role==="user"))==null?void 0:Dw.blocks.find(H=>H.type==="text"))==null?void 0:Ow.text.trim(),$w=Rw?Rw.split(`
107
+ `)[0]:"New conversation",ma=DB({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:Ye,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:zn,style:d||ct===null?void 0:{width:ct},"data-sized":!d&&ct!==null?"true":void 0,"data-testid":"chat-column","data-dropping":Z||void 0,onDragEnter:H=>{ku(H)&&(H.preventDefault(),Le.current+=1,he(!0))},onDragOver:H=>{ku(H)&&(H.preventDefault(),H.dataTransfer.dropEffect="copy")},onDragLeave:H=>{ku(H)&&(Le.current=Math.max(0,Le.current-1),Le.current===0&&he(!1))},onDrop:H=>{var te;ku(H)&&(H.preventDefault(),Le.current=0,he(!1),s&&((te=Ie.current)==null||te.addFiles(H.dataTransfer.files)))},children:[Z?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(GB,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:fe?`It goes with your next message to ${fe.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&fe?Ac(Ec(fe)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:ww}):fe?n.jsx("a",{className:"wb-head-face",href:Et(fe.id),"aria-label":`${fe.name}'s page`,children:n.jsx(ln,{agents:We,id:fe.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:$w,children:$w}),n.jsx("span",{className:"wb-head-meta","data-tone":ma.tone,title:i?`${Rn.map(H=>H.name).join(", ")}. Coordinator: ${(fe==null?void 0:fe.name)??i.coordinator}.`:ma.title,children:i?`${Rn.map(H=>H.name).join(", ")} · ${ma.text}`:fe?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:Et(fe.id),title:`${fe.name}'s page`,children:fe.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",fe.handle]}),` · ${ma.tone==="quiet"&&ma.text==="New conversation"?`on ${v}`:ma.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:()=>{ee(!1),zc()},children:n.jsx(ue,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":ze,"data-open":ze?"true":void 0,disabled:!s,onClick:()=>ee(H=>!H),children:n.jsx(qB,{})}),d?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:Wn.length===0,children:["Canvas",Wn.length>0?` (${Wn.length})`:""]}):null,i?n.jsx(Ck,{disabled:!1,label:"More about this group",title:i.name,sub:fA(Rn.map(H=>H.name)),face:ww,items:[{label:"Members",hint:`${i.members.length} agents · ${fe?`${fe.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(Ck,{disabled:!s,label:"More about this agent",title:(fe==null?void 0:fe.name)??"Agent",...fe?{sub:`@${fe.handle}`,face:n.jsx(ln,{agents:We,id:fe.id,size:"sm"})}:{},items:[{label:jt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Un,onSelect:M$},...fe?[{label:"Set up",hint:"Identity, model and access",href:Et(fe.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Et(fe.id)}]:[]]})]}),u?n.jsx(xE,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Ti?{working:new Set([Ti])}:{}}):null]}),ze&&s?n.jsx(jB,{agentId:s,...i?{groupId:i.id}:{},currentId:N,timezone:e,onNew:()=>{ee(!1),zc()},onSelect:H=>{if(H===N){ee(!1);return}ee(!1),C(null),U([]),M(!1),B(null),Se(null),et(null),Y([]),k(H),j==null||j(s,H,!1)}}):null,s&&N?n.jsx(dB,{agentId:s,conversationId:N},`${s}:${N}`):null,Re?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(le,{message:Re})}):null,Ue?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Ue}):null,S!=null&&S.carriedOver?n.jsx(OB,{text:S.carriedOver,onDelete:async()=>{const H=S.conversationId;await He.deleteCarryOver(H),C(te=>{if(!te||te.conversationId!==H)return te;const{carriedOver:ke,...Me}=te;return Me})}},S.conversationId):null,n.jsx(xj,{messages:[...(S==null?void 0:S.messages)??[],...I],live:z,now:Ye,working:O,partial:P,agents:We,...S!=null&&S.runs?{runs:S.runs}:{},...s&&N?{onContinue:()=>mf("continue",[])}:{},...i?{speakers:We,coordinatorId:i.coordinator}:{},...Ws?{workingAs:((Lw=We.find(H=>H.id===Ws))==null?void 0:Lw.name)??Ws}:{},onOpenFile:jw,onReadAloud:(H,te)=>{Qt(null),Wd(te,N??void 0,H).then(ke=>{ke&&Qt(ke)})},onOpen:H=>{if(hn){const te=bk([...(S==null?void 0:S.messages)??[],...I],H);if(te){Dc(te),B(hn.id),d&&(m==null||m());return}}N&&F(te=>{const ke={...te,[N]:(te[N]??[]).filter(Me=>Me!==H)};return kk(ke),ke}),B(H),d&&(m==null||m())},...fe?{agentName:fe.name,agentId:fe.id}:{},...Aw?{empty:Aw}:{},emptyHint:i?`Give the team a task once; ${fe?fe.name:"the coordinator"} brings members in. @ addresses one of them.`:fe?`Nothing here yet. Ask ${fe.name} for something.`:"Loading agents…"}),kw.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:kw.map(H=>n.jsx("button",{className:"ui-btn",disabled:Ae!==null,title:H.prompt,onClick:()=>$$(H.id),children:H.label},H.id))}):null,$i?n.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":$i.kind,children:n.jsx(G,{tone:yw?"warning":void 0,role:"status",children:n.jsxs("span",{children:[$i.text," ",n.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>a==null?void 0:a("members"),children:$i.action})]})})}):null,Fc?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(G,{tone:"warning",role:"status",children:[Fc," ",n.jsx("a",{href:Oe(bw.section),children:bw.label})]})}):Lc.length>0?n.jsx(YU,{approvals:Lc,timezone:e,now:Ye,version:S,onDecided:Sw,onSay:H=>mf(H,[]),onOpenFull:H=>{B(H),d&&(m==null||m())}}):null,Fc||Lc.length>0?null:S!=null&&S.question?n.jsx($B,{question:S.question,disabled:J||O,onAnswer:I$,onSkip:P$},S.question.id):null,Fc||yw?null:n.jsxs("div",{hidden:Lc.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(wj,{ref:Ie,disabled:!s,running:O,onSend:mf,onStop:O$,agentName:i?i.name:(fe==null?void 0:fe.name)??"the agent",draft:$e,history:A$,threadKey:N??(i?`group:${i.id}`:s),model:i?null:(fe==null?void 0:fe.model)??null,setupHref:i?null:fe?Et(fe.id,"setup","brain"):null,thinking:T$,...!i&&fe&&r1(i1(fe,Bn.data))?{onThinking:R$}:{},...i?{mentions:Rn.map(H=>({handle:H.handle,name:H.name}))}:{},onOpenFile:jw,conversationId:N??null,readAloud:K,onReadAloud:bs}),Fe?n.jsx("p",{className:"wb-voice-note",role:"status",children:Fe}):null]})]}),d?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"})]}),Tw]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:H=>{var te,ke;Uc.current=!0,(ke=(te=H.currentTarget).setPointerCapture)==null||ke.call(te,H.pointerId)},onKeyDown:H=>{const te=ke=>{var Me;return ke??((Me=zn.current)==null?void 0:Me.offsetWidth)??Ju};H.key==="ArrowLeft"&&Tt(ke=>Math.max(Ju,te(ke)-16)),H.key==="ArrowRight"&&Tt(ke=>Math.min(720,te(ke)+16))}}),Tw]})]})}function KB(){try{const e=window.localStorage.getItem(gA),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=Ju?t:null}catch{return null}}function VB(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 Kr(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function ym(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 ku(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function GB(){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 Sk="buddi.chatDraft";function YB(e){try{const t=window.sessionStorage.getItem(Sk);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Sk),s.text)}catch{return null}}function qB(){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 QB(){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 Ck({items:e,disabled:t,label:s,title:r,sub:i,face:a}){const[l,o]=h.useState(!1),c=h.useRef(null);h.useEffect(()=>{if(!l)return;const d=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",d),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",f)}},[l]);const u=d=>{const f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-menu-item-text",children:d.label}),d.hint?n.jsx("span",{className:"ui-menu-item-hint",children:d.hint}):null]});return d.href?n.jsx("a",{className:"ui-menu-item",role:"menuitem",href:d.href,"data-tone":d.tone,onClick:()=>o(!1),children:f},d.label):n.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":d.testId,"data-tone":d.tone,disabled:d.disabled,onClick:()=>{var m;o(!1),(m=d.onSelect)==null||m.call(d)},children:f},d.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(d=>!d),children:n.jsx(QB,{})}),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((d,f)=>d==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(d)),n.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}function XB(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 Ek=!1;const JB=new Set(["missing","unconfigured","not-english"]);async function Wd(e,t,s=null){const r=JE(s);try{const i=await He.say({text:e,...t?{conversationId:t}:{}});return lk(r)&&await Y3(i.audioUrl,i.mime,s),null}catch(i){lk(r)&&$l();const a=i instanceof pe&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&JB.has(a)&&(s!==null||!Ek)?(Ek=!0,i.message):null}}let ls=null;function ZB(e){if(Yu(e)!==null)return!1;const t=aE(e);return t!==nn&&t!==ci}function e5({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=h.useRef(null),l=h.useRef(s),o=`Ask ${e.name}`,[c,u]=h.useState(!1);return h.useEffect(()=>{if(s||!c||!ls)return;const d=zh({url:He.streamUrl(ls.conversationId),lastEventId:ls.lastEventId??null,onEvent:f=>{f.name==="run.finished"&&u(!1)}});return()=>d.close()},[s,c]),h.useEffect(()=>{const d=f=>{!f.altKey||f.ctrlKey||f.metaKey||f.code!=="Slash"||(f.preventDefault(),r(!s))};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s,r]),h.useEffect(()=>{var d;l.current&&!s&&((d=a.current)==null||d.focus()),l.current=s},[s]),s?n.jsx(n5,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(Go,{children:[n.jsx(Yo,{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(t5,{busy:c})})}),n.jsx(qo,{children:n.jsx(Qo,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function t5({busy:e}){const[t,s]=h.useState(!1);return t?n.jsx(ic,{size:"lg"}):n.jsx(Tc,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function n5({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=h.useRef(null),[l,o]=h.useState(ls&&ls.agentId===e.id?ls.conversationId:null),[c,u]=h.useState(null),[d,f]=h.useState([]),[m,p]=h.useState([]),[g,x]=h.useState(null),[b,j]=h.useState(!1),[v,w]=h.useState(!1),[y,N]=h.useState(null),[k,S]=h.useState(null),[C,$]=h.useState(Date.now()),[R,I]=h.useState(QE),U=h.useRef(R);U.current=R;const[z,A]=h.useState(null),P=h.useRef(null),D=h.useCallback(async V=>{try{const F=await He.conversation(V);u(F),f(X=>X.filter(Y=>!s5(F,Y)))}catch{}},[]);h.useEffect(()=>{l&&D(l)},[l,D]),h.useEffect(()=>{if(!l)return;const V=zh({url:He.streamUrl(l),onEvent:F=>{var X;switch(F.name){case"run.started":P.current=null,j(!0),x(null);break;case"live":{const Y=Hn(F.data.runId)??"",Z=Number(F.data.turn??0),he=F.data.kind==="thinking"?"thinking":"text",Le=Hn(F.data.text)??"",Ie=Date.now();if(he==="text"){const ze=P.current;P.current=ze&&ze.runId===Y&&ze.turn===Z?{...ze,text:ze.text+Le}:{runId:Y,turn:Z,text:Le}}x(ze=>{const ee=ze&&ze.runId===Y&&ze.turn===Z?ze:{runId:Y,turn:Z,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return he==="thinking"?{...ee,thinking:ee.thinking+Le,thinkingStartedAt:ee.thinkingStartedAt??Ie}:{...ee,text:ee.text+Le,textStartedAt:ee.textStartedAt??Ie}});break}case"live.snapshot":{const Y=Hn(F.data.runId)??"",Z=Number(F.data.turn??0),he=Hn(F.data.text)??"",Le=Hn(F.data.thinking)??"",Ie=Number(F.data.startedAt??Date.now());P.current={runId:Y,turn:Z,text:he},j(!0),x({runId:Y,turn:Z,text:he,thinking:Le,thinkingStartedAt:Le?Ie:null,textStartedAt:he?Ie:null,settled:!1});break}case"live.settle":{const Y=Hn(F.data.runId)??"",Z=Number(F.data.turn??0);x(he=>he&&he.runId===Y&&he.turn===Z?{...he,settled:!0}:he);break}case"tool.called":{const Y=Hn(F.data.toolUseId)??Hn(F.data.id),Z=Hn(F.data.name)??Hn(F.data.tool)??"tool";Y&&p(he=>[...he.filter(Le=>Le.toolUseId!==Y),{toolUseId:Y,name:Z,startedAt:Date.now()}]);break}case"tool.result":{const Y=Hn(F.data.toolUseId)??Hn(F.data.id);Y&&p(Z=>Z.filter(he=>he.toolUseId!==Y)),D(l);break}case"message.appended":case"awaiting-approval":D(l).then(()=>x(Y=>Y!=null&&Y.settled?null:Y));break;case"run.finished":{j(!1),p([]),x(null);const Y=Hn(F.data.message);N(Y??null);const Z=((X=P.current)==null?void 0:X.text.trim())??"";P.current=null,!Y&&Z!==""&&U.current&&Wd(Z,l).then(he=>{he&&A(he)}),D(l);break}}}});return()=>{ls&&ls.conversationId===l&&(ls.lastEventId=V.lastEventId()),V.close()}},[l,D]),h.useEffect(()=>{i(b||v)},[b,v,i]),h.useEffect(()=>{if(m.length===0)return;const V=window.setInterval(()=>$(Date.now()),1e3);return()=>window.clearInterval(V)},[m.length]);const O=(V,F)=>{w(!0),N(null);const X={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:V}]};f(Y=>[...Y,X]),(async()=>{try{const Y=l??(await He.startConversation(e.id)).conversationId;Y!==l&&(ls={agentId:e.id,conversationId:Y},o(Y));const Z=await He.send(e.id,{conversationId:Y,text:V,...F.length>0?{attachmentIds:F.map(he=>he.artifactId)}:{}});Z.conversationId!==Y&&(ls={agentId:e.id,conversationId:Z.conversationId},o(Z.conversationId)),j(!0),D(Z.conversationId)}catch(Y){f(Z=>Z.filter(he=>he.id!==X.id)),N(Y instanceof pe?Y.message:String(Y)),S({text:V,at:Date.now()})}finally{w(!1)}})()},M=()=>{l&&He.cancel(l).catch(V=>N(String(V))).finally(()=>j(!1))},W=()=>{var V;ls=null,o(null),u(null),f([]),p([]),x(null),j(!1),N(null),(V=a.current)==null||V.focus()},L=V=>{I(V),XE(V),V||$l()},q=l?tt(e.id,l):tt(e.id),B=[...(c==null?void 0:c.messages)??[],...d];return n.jsxs(bz,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:V=>{var F;V.preventDefault(),(F=a.current)==null||F.focus()},onCloseAutoFocus:V=>V.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:W,disabled:l===null&&d.length===0,children:"New"}),n.jsx(Nt,{size:"sm",variant:"ghost",href:q,onClick:V=>{V.preventDefault(),s(q)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(xj,{messages:B,live:m,now:C,working:b||v,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(q),onReadAloud:(V,F)=>{A(null),Wd(F,l??void 0,V).then(X=>{X&&A(X)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(le,{message:y}):null,n.jsx(wj,{ref:a,disabled:v||!e.available,running:b,onSend:O,onStop:M,agentName:e.name,placeholder:`Message ${e.name}…`,draft:k,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:R,onReadAloud:L}),z?n.jsx("p",{className:"wb-voice-note",role:"status",children:z}):null]})]})}function Hn(e){return typeof e=="string"?e:null}function s5(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 xA=3;function r5(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function i5(e,t){return e?t?"above-dock":"above-button":"corner"}function a5({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function l5(e){return e.state==="shown"&&e.seenAt===null}function o5(e){const[t,s]=h.useState([]),r=h.useRef(new Set),i=h.useRef(new Set),a=h.useCallback(()=>{e&&E.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>l5(u)&&!r.current.has(u.id));s(u=>{const d=new Set(u.map(m=>m.id)),f=c.filter(m=>!d.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);h.useEffect(()=>{for(const o of t.slice(0,xA))i.current.has(o.id)||(i.current.add(o.id),E.notificationSeen(o.id).catch(()=>{}))},[t]);const l=h.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function c5({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,xA),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":r5(l.kind),role:"status",children:[l.agentId?n.jsx(ln,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:Jo(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:u5(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 ${Jo(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function u5(e){var t;return((t=e.split(`
108
+ `).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const d5=3e4,h5=1e3;function f5(e,t,s){const r=h.useRef(t);r.current=t;const i=h.useRef(s);i.current=s,h.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const d=()=>document.visibilityState!=="hidden",f=j=>{var v;l=Date.now(),E.presence(j).catch(w=>{var y;w instanceof pe&&w.status===401&&(a=!0,(y=i.current)==null||y.call(i))}),j==="active"&&((v=r.current)==null||v.call(r))},m=j=>{if(a||(o=j,c!==null))return;const v=l+h5-Date.now();if(v<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const w=o;o=null,f(w)},v)},p=()=>{u=!0,d()&&m("active")},g=()=>{u=!1,m("away")},x=()=>m(d()?"active":"away");d()&&m("active");const b=window.setInterval(()=>{d()&&u&&m("active")},d5);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",x),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",x)}},[e])}function m5({agents:e,onClose:t,onCreated:s}){return mE(e)?n.jsx(p5,{agents:tj(e),onClose:t,...s?{onCreated:s}:{}}):n.jsx(ft,{title:"A new group",onClose:t,children:n.jsxs(G,{children:["A group needs two agents. Make another one with ",a4(e)," first."]})})}function p5({agents:e,onClose:t,onCreated:s}){var j,v;const[r,i]=h.useState(""),[a,l]=h.useState([]),[o,c]=h.useState(((j=e.find(w=>w.roles.includes(qv)))==null?void 0:j.id)??((v=e[0])==null?void 0:v.id)??""),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=[...new Set([o,...a])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,x=w=>l(y=>y.includes(w)?y.filter(N=>N!==w):[...y,w]),b=async()=>{d(!0),m(null);try{s==null||s(await He.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof pe?w.message:String(w))}finally{d(!1)}};return n.jsx(ft,{title:"A new group",onClose:t,children:n.jsxs(se,{children:[n.jsx(ie,{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(ie,{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(ie,{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:()=>x(w.id)}),n.jsx(ln,{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(G,{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(G,{tone:"critical",children:f}):null,n.jsxs(ae,{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 g5=1e4;function Hd({title:e,body:t,duration:s,onUndo:r,onGone:i}){return n.jsxs(xM,{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(vM,{className:"ui-toast-title",children:e}),t?n.jsx(jM,{className:"ui-toast-body",children:t}):null]}),r?n.jsx(wM,{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 yj(e){const[t,s]=h.useState(null),[r,i]=h.useState(null),[a,l]=h.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,d,f)=>{var p,g,x,b;s(c),l(null),i(null);let m;try{const j=f?await E.decide(c,u,d,f):await E.decide(c,u,d);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}: ${((x=j.execution)==null?void 0:x.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 bj({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var d,f;const[a,l]=h.useState(!1),{values:o,controls:c}=lj(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(ys,{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(It,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",nt(e.expiresAt,t)," (",De(e.expiresAt),"). Policy v",e.policyVersion,", args ",Xo(e.argsHash,12),e.jobId?`, job ${Xo(e.jobId)}`:"","."]}),c,n.jsxs(ae,{children:[n.jsx(T,{variant:"good",disabled:s,onClick:()=>u(),children:(d=e.permissionScopes)!=null&&d.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(oe,{title:"Envelope: everything that decides what the world will see",children:n.jsx(It,{children:Jn(e.envelope)})}),n.jsx(oe,{title:"Canonical arguments",children:n.jsx(It,{children:Jn(e.canonicalArgs)})})]}):null]})}function kj(e,t,s){const[r,i]=h.useState(!1),[a,l]=h.useState(null),[o,c]=h.useState(null);return{accept:()=>{e&&(i(!0),c(null),E.acceptPluginAgent(e,t).then(d=>{l(d.agent)}).catch(d=>c(d instanceof pe?d.message:String(d))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function vA({agent:e}){return n.jsxs(G,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:tt(e.id),children:["Talk to @",e.handle]})]})}function jA(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 x5(e,t){var i;const s=ce(()=>E.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>jA(a,e,t)))??null,reload:s.reload}}function v5({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=yj(a=>t(a));return n.jsxs(se,{gap:"sm",children:[n.jsx(bj,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(le,{message:r})]})}function Nj({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var f;const l=kj(e,t),o=x5(e,t),[c,u]=h.useState(null),d=l.created??c;if(d)return n.jsx(vA,{agent:d});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(v5,{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(ae,{children:[n.jsx("span",{children:s}),n.jsx(Dt,{}),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(le,{message:l.failure})]})}function wA(){var t;const e=ce(()=>E.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function yA({offers:e,reload:t}){return e.length===0?null:n.jsx(oe,{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(Nj,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{E.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const j5=512*1024,w5=/^[A-Za-z0-9+/]*={0,2}$/;function bA(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===""||!w5.test(r)||Math.floor(r.length*3/4)>j5+2?null:{mime:s,data:r}}function kA(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let yr=null,ko=null,oc=null;const Lg=new Set;function NA(){for(const e of Lg)e()}function ho(){yr&&(yr.onended=null,yr.onerror=null,yr.pause()),ko&&URL.revokeObjectURL(ko),ko=null,oc!==null&&(oc=null,NA())}async function SA(e,t){ho();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);yr??(yr=new Audio),ko=URL.createObjectURL(new Blob([r],{type:e.mime})),oc=t,yr.onended=ho,yr.onerror=ho,yr.src=ko,NA();try{await yr.play()}catch{throw ho(),new Error("The browser would not play the sound.")}}function Ak(e){e!==void 0&&oc!==e||ho()}function y5(){return h.useSyncExternalStore(e=>(Lg.add(e),()=>Lg.delete(e)),()=>oc,()=>null)}const b5=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],qs=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Tk=/^\d{4}-\d{2}-\d{2}$/;function Gi(e){return e.split("-").map(Number)}function ua(e,t){const[s,r,i]=Gi(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function CA(e){const[t,s,r]=Gi(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function EA(e){return b5[CA(e)]}function AA(e){return Gi(e)[2]}function Rk(e){return ua(e,-((CA(e)+6)%7))}function Ar(e){return $h(e,{weekday:!0,compact:!0})}function k5(e,t){return e===t?`Today · ${Ar(e)}`:e===ua(t,1)?`Tomorrow · ${Ar(e)}`:Ar(e)}function Li(e){return nO(e)}const $k=new Map;function _g(e,t){let s=$k.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"}),$k.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 N5(e,t=new Date){return _g(t,e).date}function S5(e,t){return e==="week"?{from:Rk(t),days:7}:e==="month"?{from:Rk(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function C5(e,t,s){if(e!=="month")return ua(t,s*7);const[r,i]=Gi(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function E5(e,t,s,r){const[i,a]=Gi(t);if(e==="month")return n1(i,a);const l=ua(s,r-1),[o,c,u]=Gi(s),[d,f,m]=Gi(l);return e1().date==="iso"?`${s} – ${l}`:sO()?c===f&&o===d?`${qs[c-1]} ${u} – ${m}, ${d}`:o===d?`${qs[c-1]} ${u} – ${qs[f-1]} ${m}, ${d}`:`${qs[c-1]} ${u}, ${o} – ${qs[f-1]} ${m}, ${d}`:c===f&&o===d?`${u} – ${m} ${qs[f-1]} ${d}`:o===d?`${u} ${qs[c-1]} – ${m} ${qs[f-1]} ${d}`:`${u} ${qs[c-1]} ${o} – ${m} ${qs[f-1]} ${d}`}function ba(e){return e==null?"":String(e)}function A5(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=ba(Ne(l,t.id)),u=ba(Ne(l,t.title)),d=ba(Ne(l,t.start)),f=ba(Ne(l,t.end));if(c===""||a.has(c)||d===""){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:Ne(l,t.allDay),p=m===void 0?Tk.test(d):m===!0||m==="true",g=t.tone===void 0?0:Number(Ne(l,t.tone)),x=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":ba(Ne(l,t.calendar)),tone:x,location:t.location===void 0?"":ba(Ne(l,t.location))};if(p){const N=d.slice(0,10),k=Tk.test(f.slice(0,10))&&f.slice(0,10)>N?f.slice(0,10):ua(N,1);i.push({...b,allDay:!0,startDate:N,startMin:0,endDate:k,endMin:0});return}const j=new Date(d);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${d}", which is not a time — not drawn`);return}const v=new Date(f),w=_g(j,s),y=Number.isNaN(v.getTime())||v<j?w:_g(v,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function T5(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 Sj(e,t){return e.map(s=>({event:s,part:T5(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 Cj(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${Li(t.to)}`:s&&t.to===1440?`from ${Li(t.from)}`:t.from===t.to?Li(t.from):`${Li(t.from)}–${Li(t.to)}`}function Fg(e,t,s){return[Cj(e,t),e.title,e.location,e.calendar,Ar(s)].filter(Boolean).join(", ")}const TA=30;function R5(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+TA);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 $5={week:"Week",month:"Month",list:"List"},I5=["week","month","list"],P5="(max-width: 720px)";function M5(e){try{return window.localStorage.getItem(e)}catch{return null}}function D5(e,t){try{window.localStorage.setItem(e,t)}catch{}}function O5(e){const t=e.views&&e.views.length>0?e.views:I5,s=Ms(P5),[r,i]=h.useState(()=>{const p=M5(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]=h.useState(e.today),[u,d]=h.useState(null),{from:f,days:m}=S5(l,o);return{views:t,view:l,setView:p=>{i(p),D5(e.storageKey,p),d(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:C5(l,o,p)),d(null)},from:f,days:m,to:ua(f,m),selected:u,select:d}}function L5({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,d=h.useMemo(()=>Array.from({length:u},(x,b)=>ua(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=x=>{if(!x.target.closest('input, textarea, select, [contenteditable="true"]')&&!(x.altKey||x.ctrlKey||x.metaKey)){if(x.key==="ArrowLeft")e.go(-1);else if(x.key==="ArrowRight")e.go(1);else if(x.key==="t"||x.key==="T")e.go(0);else return;x.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(ue,{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(ue,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:E5(a,l,c,u)}),e.views.length>1?n.jsx(sn,{label:"View",options:e.views.map(x=>({value:x,label:$5[x]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(_5,{dates:d,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(z5,{dates:d,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:d.map(x=>n.jsx(Ik,{date:x,today:o,events:t,empty:r},x))}):null,p?n.jsx(Ik,{date:p,today:o,events:t,empty:r}):null]})}function Ik({date:e,today:t,events:s,empty:r}){const i=Sj(s,e);return n.jsx(Qe,{flush:!0,title:k5(e,t),children:n.jsx(ht,{children:i.length===0?n.jsx(st,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(st,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:Cj(a,l)},a.id))})})}function _5({dates:e,today:t,events:s,hours:r,onPick:i}){const a=h.useRef(null);h.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:Sj(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(Qe,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Ar(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":Ar(c),children:[n.jsx("span",{className:"cal-wd",children:EA(c)}),n.jsx("span",{className:"cal-num",children:AA(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(d=>d.part.allDay).map(({event:d,part:f})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":d.tone,"aria-label":Fg(d,f,c),onClick:()=>i(c),children:d.title},d.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:Li(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Ar(c),"data-today":o(c),children:R5(u.filter(d=>!d.part.allDay)).map(({event:d,part:f,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":d.tone,"data-short":f.to-f.from<60?"true":void 0,"data-lane":m,"aria-label":Fg(d,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,TA)/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:Cj(d,f)}),n.jsx("span",{className:"cal-event-title",children:d.title})]},d.id))},c))]})})]})})}const F5=3;function z5({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(d,f)=>e.slice(f*7,f*7+7)),[o,c]=t.split("-").map(Number),u=n1(o,c);return n.jsx(Qe,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(d=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:EA(d)},d))}),l.map(d=>n.jsx("div",{className:"cal-row",role:"row",children:d.map(f=>{const m=Sj(r,f),p=m.slice(0,F5),g=m.length-p.length,x=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":`${Ar(f)}, ${x}`,"aria-pressed":f===i,children:AA(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":Fg(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:Li(j.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${Ar(f)}`,children:["+",g]}):null]},f)})},d[0]))]})})}const RA={width:1200,height:200,top:28,right:12,bottom:24,left:36};function U5(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 Nu(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function B5(e){const t=RA,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=>_i(t.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=U5(c,e.unit),d=u[0],f=u[u.length-1],m=j=>_i(t.top+i-(j-d)/(f-d)*i),p=e.values.map((j,v)=>{const w=j!==null&&Number.isFinite(j);return{index:v,x:o(v),y:w?m(j):null,value:w?j:null}}),g=[],x=[];if(e.kind==="area"){let j=[];const v=()=>{if(j.length===0)return;const w=j.map((y,N)=>`${N===0?"M":"L"}${y.x},${y.y}`).join(" ");g.push(w),x.push(`${w} L${j[j.length-1].x},${a} L${j[0].x},${a} Z`),j=[]};for(const w of p)w.y===null?v():j.push(w);v()}const b=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:_i(j.x-l*.28),y:j.y,width:_i(l*.56),height:_i(a-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:x,bars:b,points:p,slot:l,floor:a}}function W5({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var N;const[l,o]=h.useState(((N=r[0])==null?void 0:N.id)??""),[c,u]=h.useState(null),[d,f]=h.useState(null),m=h.useRef(null),p=s.length,g=c??d,x=r.find(k=>k.id===l)??r[0],b=B5(x),j=RA,v=k=>k%a===0||k===g,w=x.values.filter(k=>k!==null&&Number.isFinite(k));h.useEffect(()=>{const k=m.current,S=g===null?null:k==null?void 0:k.children[g];!k||!S||typeof k.scrollTo!="function"||(S.offsetLeft<k.scrollLeft?k.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>k.scrollLeft+k.clientWidth&&k.scrollTo({left:S.offsetLeft+S.offsetWidth-k.clientWidth,behavior:"smooth"}))},[g]);const y=k=>{var $,R,I;const S=k.key==="ArrowRight"?1:k.key==="ArrowLeft"?-1:0,C=k.key==="Home"?0:k.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(d??-S)+S));C!==null&&(k.preventDefault(),f(C),(I=(R=($=m.current)==null?void 0:$.children[C])==null?void 0:R.querySelector("button"))==null||I.focus())};return n.jsxs(Qe,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(k=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":k.id===x.id,onClick:()=>o(k.id),children:k.label},k.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":x.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(k=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:k.y,y2:k.y}),n.jsx("text",{className:"pg-series-tick",x:j.left-8,y:k.y,textAnchor:"end",dominantBaseline:"middle",children:Nu(k.value,x.unit)})]},k.value)),b.areas.map((k,S)=>n.jsx("path",{className:"pg-series-area",d:k},`a${S}`)),b.lines.map((k,S)=>n.jsx("path",{className:"pg-series-line",d:k},`l${S}`)),b.bars.map(k=>n.jsx("rect",{className:"pg-series-bar","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y,width:k.width,height:k.height},k.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,x.kind==="area"?b.points.map(k=>k.y!==null&&v(k.index)?n.jsx("circle",{className:"pg-series-dot","data-index":k.index,"data-hover":k.index===g?"true":void 0,cx:k.x,cy:k.y,r:k.index===g?5:3},k.index):null):null,b.points.map(k=>k.y!==null&&k.value!==null&&v(k.index)?n.jsx("text",{className:"pg-series-value","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y-(x.kind==="area"?10:6),textAnchor:"middle",children:Nu(k.value,x.unit)},k.index):null),b.points.map(k=>k.index%a===0?n.jsx("text",{className:"pg-series-x",x:k.x,y:j.height-6,textAnchor:"middle",children:s[k.index]},k.index):null),b.points.map(k=>n.jsx("rect",{className:"pg-series-hit","data-index":k.index,x:_i(j.left+b.slot*k.index),y:0,width:_i(b.slot),height:j.height,onMouseEnter:()=>u(k.index),onClick:()=>f(k.index)},k.index))]}),n.jsx("figcaption",{className:"sr-only",children:w.length===0?`${x.label}: no values.`:`${x.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Nu(Math.min(...w),x.unit)}, highest ${Nu(Math.max(...w),x.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:i.map((k,S)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===d,"aria-label":[k.label,k.value,...k.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":k.icon??"dot",children:n.jsx(ue,{name:Rl(k.icon),size:22})}),k.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:k.value}):null,n.jsx("span",{className:"wb-tile-label",children:k.label}),k.lines.map((C,$)=>n.jsx("span",{className:"wb-tile-line",children:C},$))]})})},S))})]})]})}function _i(e){return Math.round(e*10)/10}const Ej=h.createContext(null),Kd=h.createContext(!1);function At(){const e=h.useContext(Ej);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function zg(e,t=new Set){if(Array.isArray(e))for(const s of e)zg(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))zg(r,t)}return t}function $A(e,t){if(t.size===0)return!1;for(const s of zg(e))if(t.has(s))return!0;return!1}function IA(){const[e,t]=h.useState(!1);return h.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 PA({revealed:e,onToggle:t}){return n.jsx(T,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function MA(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function DA({children:e}){const[t,s]=IA();return n.jsxs(se,{gap:"sm",children:[n.jsx(ae,{align:"end",children:n.jsx(PA,{revealed:t,onToggle:s})}),t?n.jsx(Kd.Provider,{value:!0,children:e}):n.jsx(MA,{})]})}function Aj(e){return e===void 0||e==="neutral"?void 0:e}function Ug(e){return Aj(e)}function H5(e){const t=Aj(e);return t==="accent"?void 0:t}function gs(e,t){if(!t)return!0;const s=Ne(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function Tj(e,t,s){if("chat"in t){const a=Ve(s,t.chat);return a==null?"":tt(String(a))}if("proposals"in t)return fF(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return gi(e.plugin,t.page);const i=t.item===void 0?null:Ve(s,t.item);return lr(e.plugin,t.page,i==null?null:String(i))}function Rj(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=Ne(t.row,r);return i==null?"":String(i)})}function Bg(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=Ve(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function OA(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=Ve(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function da(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ne(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(d=>d.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]=Ve(t.data,o);return s}function Tn(e,t,s,r){const i=At(),a=e?{...OA(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=ce(()=>e?E.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 Ic(){const e=At(),t=h.useId(),[s,r]=h.useState(null),[i,a]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(null),m=(j,v)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=Ve(v,j.done);return w==null?null:String(w)},p=(j,v,w)=>{const y=j??"refresh";if(typeof y=="object"){const N=Tj(e,y.route,v);N===""?e.refresh():e.navigate(N);return}y==="close"&&(w==null||w()),e.refresh()},g=async(j,v,w)=>{r(j.tool),a(null),o(null);try{const y=await E.pageAct(e.plugin,{tool:j.tool,args:v});if(y.approvalId){u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}});return}u(null),f(null);const N=bA(y.result);o(m(j,y.result)??(N?kA(y.result):null)),N&&await SA(N,t),p(j.then,y.result,w)}catch(y){a(y instanceof Error?y.message:String(y)),e.refresh()}finally{r(null)}},x=j=>{if(!j){e.refresh();return}const v=d;if(u(null),f(null),v&&j.decision==="approve"&&j.state==="succeeded"){o(m(v.ref,j.result)),p(v.then,void 0,v.onDone);return}e.refresh()},b=()=>{a(null),o(null)};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(d==null?void 0:d.ref.pending)??null,settle:x,run:g,reset:b}}function Il({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=h.useState(!1),u=f=>Rj(f,{...i===void 0?{}:{count:i},row:a}),d=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, ",d.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:d})}function Vd({id:e,onDecided:t}){const s=At(),r=ce(()=>E.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=yj(c=>{t?t(c):s.refresh()});return r.error?n.jsx(le,{message:r.error}):r.data?n.jsxs(se,{children:[n.jsx(bj,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,d,f)=>{o(c,u,d,f)}}),a?n.jsx(G,{tone:"good",role:"status",children:a}):null,n.jsx(le,{message:l})]}):n.jsx(xe,{children:"Loading the approval…"})}function Pl({act:e}){return e.error?n.jsx(le,{message:e.error}):e.approvalId?e.waiting?n.jsxs(se,{children:[n.jsx(G,{role:"status",children:e.waiting}),n.jsx(Vd,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(Vd,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(G,{tone:"good",role:"status",children:e.done}):null}function cc(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:Ne(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 LA(e,t,s){const r=At(),i=e.optionsFrom,a=i?{...OA(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=ce(()=>i?E.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:cr(o.data,i.rows).map(c=>({value:String(Ne(c,i.value)??""),label:String(Ne(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function K5({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=LA(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},d=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(ie,{label:e.label,hint:l?void 0:[d,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(Nz,{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(V5,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:d,children:m}):n.jsx(ie,{label:e.label,hint:d,children:m})}if(e.type==="textarea")return n.jsx(ie,{label:e.label,hint:d,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(ie,{label:e.label,hint:d,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(ie,{label:e.label,hint:d,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"?G5(m.target.value):m.target.value)})})}function V5({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=At(),u=h.useId(),d=y5()===u,[f,m]=h.useState(!1),[p,g]=h.useState(null),[x,b]=h.useState(null),[j,v]=h.useState(null);h.useEffect(()=>()=>Ak(u),[u]);const w=$j(s,r,i),y=t.args!==void 0?da(t.args,{data:i,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),N=async()=>{if(d){Ak(u);return}m(!0),g(null),b(null),v(null);try{const S=await E.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){v(S.approvalId);return}g(kA(S.result));const C=bA(S.result);C&&await SA(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},k=d?"Stop":t.label;return n.jsx(ie,{label:e.label,hint:l,action:n.jsx(T,{"data-shape":"icon","aria-label":f?`${t.label}: working`:k,title:k,"aria-busy":f||void 0,"aria-pressed":t.icon==="play"?d:void 0,disabled:a===!0||f,onClick:()=>void N(),children:f?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(ue,{name:d?"stop":t.icon??"arrow"})}),after:x?n.jsx(le,{message:x}):j?n.jsx(Vd,{id:j,onDecided:()=>v(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function G5(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function _A(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function $j(e,t,s){const r=_A(t,s);return new Set(e.filter(i=>i.when!==void 0&&!gs(r,i.when)||i.disabledWhen!==void 0&&gs(r,i.disabledWhen)).map(i=>i.name))}function Zh({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=_A(t,s);return n.jsx(Ls,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||gs(o,c.when)).map(c=>n.jsx(K5,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&gs(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const uc=h.createContext(!1),FA=h.createContext(!1),zA=h.createContext(!1);function rs({title:e,note:t,actions:s,children:r}){const i=h.useContext(uc);return n.jsx(oe,{title:e,aside:t,actions:s,panel:i,children:n.jsx(uc.Provider,{value:!1,children:n.jsx(FA.Provider,{value:i,children:r})})})}function or({component:e,data:t,choose:s,chosen:r}){const i=At(),a=h.useContext(Kd);if(!gs(t,e.when))return null;if(e.kind!=="section"&&!a&&$A(e,i.sensitive))return n.jsx(DA,{children:n.jsx(or,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(Y5,{component:e,data:t});case"notice":return n.jsx(G,{tone:Aj(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(Ve(t,e.text)??"")});case"link":return n.jsx(q5,{component:e,data:t});case"progress":return n.jsx(X5,{component:e,data:t});case"chart":return n.jsx(J5,{component:e,data:t});case"stats":return n.jsx(Z5,{component:e,data:t});case"list":return n.jsx(t8,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(s8,{component:e,data:t});case"detail":return n.jsx(a8,{component:e,data:t});case"form":return n.jsx(l8,{component:e,data:t});case"search":return n.jsx(u8,{component:e,data:t});case"list-detail":return n.jsx(d8,{component:e,data:t});case"repeat":return n.jsx(h8,{component:e,data:t});case"calendar":return n.jsx(f8,{component:e,data:t});case"tiles":return n.jsx(m8,{component:e,data:t});case"series-panel":return n.jsx(p8,{component:e,data:t});case"hero":return n.jsx(g8,{component:e,data:t});case"tabs":return n.jsx(x8,{component:e,data:t});case"expand":return n.jsx(v8,{component:e,data:t});case"button":return n.jsx(j8,{component:e,data:t});case"approval":return n.jsx(y8,{component:e,data:t});case"artifact":return n.jsx(b8,{component:e,data:t});case"editor":return n.jsx(k8,{component:e,data:t});case"agent-offer":return n.jsx(w8,{component:e});default:return n.jsx(G,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function Y5({component:e,data:t}){const s=At(),r=h.useContext(Kd),[i,a]=IA(),l=!r&&$A(e.body,s.sensitive),o=l&&!i,c=h.useContext(uc);let u=e.body.length;const d=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&d(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(rs,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(or,{component:p,data:t},g)),l?n.jsx(PA,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(se,{gap:"lg",divided:c,children:o?n.jsx(MA,{}):n.jsx(Kd.Provider,{value:r||l,children:f.map((p,g)=>n.jsx(or,{component:p,data:t},g))})})})}function q5({component:e,data:t}){const s=At(),r=Tj(s,e.to,t);return r===""?null:n.jsx(ae,{children:n.jsx(Nt,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function Pk(e){return Math.round(e/1e6)}function Q5(e,t){const s=Qn(Ve(t,e.value))??0,r=e.total?Qn(Ve(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?`${Pk(s)} of ${Math.max(1,Pk(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function X5({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ve(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=Q5(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(IE,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function J5({component:e,data:t}){const s=Tn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:cr(s.data,e.rows),i=r.map(d=>String(Ne(d,e.x)??"")),a=d=>r.map(f=>Qn(Ne(f,d))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(d=>({label:d.label,values:a(d.y),type:d.type,...d.unit?{unit:d.unit}:{}})):o.map(d=>({label:o.length===1?e.label??d:d,values:a(d)})),u=e.target?Qn(Ve(s.data,e.target))??null:null;return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(xe,{children:"Loading…"}):n.jsx(Ml,{text:e.empty??"Nothing recorded yet."}):n.jsx(gz,{xs:i,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:d=>/^\d{4}-\d{2}-\d{2}/.test(d)?og(d):d,formatY:d=>qt(d,"number",null)})]})}function Z5({component:e,data:t}){const s=Tn(e.query,t);return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:s.error}),s.data===void 0?n.jsx(xe,{children:e.empty??"Loading…"}):n.jsx(Xh,{children:e.items.map((r,i)=>n.jsx(tr,{label:r.label,value:qt(Ve(s.data,r.value),r.unit??"text",null),tone:H5(r.tone)},i))})]})}function UA(e,t,s,r){const i=(t.meta??[]).map(u=>String(Ve(s,u)??"")).filter(u=>u!==""),a=String(Ve(s,t.title)??""),l=t.to&&!r?Tj(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,d)=>{const f=Ve(s,u.value);if(f==null||f==="")return null;const m=e8(u,f,s);return n.jsx(ve,{tone:Ug(m.tone),children:m.text},d)});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(Ve(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function e8(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]:Bg(e.tone,s)}}function cr(e,t){const s=Ne(e,t);return Array.isArray(s)?s:[]}function BA(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:Ne(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 t8({component:e,data:t,onChoose:s,chosen:r}){var k;const i=At(),a=h.useContext(zA),l=Tn(e.query,t),o=Ic(),[c,u]=h.useState([]),d=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=cr(l.data,e.rows),m=e.collapsed?cr(l.data,e.collapsed.rows):[],p=WA(e.actions,f,o),g={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},x=BA([...f,...m],e.key??((k=e.select)==null?void 0:k.key),g),b=new Map(x.map(S=>[S.row,S.key])),j=new Set(x.map(S=>S.row)),v=new Set(x.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!gs(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>v.has(S)),y=h.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(Ne($,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],$])}return[...C].map(([$,R])=>{var I,U;return{label:((U=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:U[$])??$,rows:R}})},[f,e.groupBy,x.length]),N=S=>S.map(C=>{var z;const $=UA(i,e.item,C,s),R=b.get(C);if(d&&(s||$.href))return n.jsx(PE,{href:$.href??"#",current:r===R,onClick:()=>s?s(R):i.navigate($.href),title:$.text,meta:$.meta,sub:$.sub,side:$.pills},R);const I=((z=e.select)==null?void 0:z.disabledWhen)!==void 0&&gs(C,e.select.disabledWhen),U=(e.actions??[]).filter(A=>gs(C,A.when));return n.jsx(st,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${$.text}`,disabled:I,checked:c.includes(R),onClick:A=>A.stopPropagation(),onChange:A=>u(P=>A.target.checked?[...P,R]:P.filter(D=>D!==R))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===R?"true":void 0,onClick:A=>{A.preventDefault(),s(R)},children:$.text}):$.title,sub:$.sub,side:n.jsxs(n.Fragment,{children:[$.side,U.map((A,P)=>n.jsx(HA,{action:A,row:C,data:l.data,act:o,onForm:p.show},P))]})},R)});return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:l.error}),p.open?null:n.jsx(Pl,{act:o}),p.open?n.jsx(KA,{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(xe,{children:"Loading…"}):n.jsx(Ml,{text:e.empty??"Nothing here yet."}):n.jsxs(ht,{children:[e.select?n.jsx(st,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:v.size>0&&w.length===v.size,disabled:v.size===0,onChange:S=>u(S.target.checked?[...v]:[])}),title:n.jsxs("span",{className:"muted",children:[v.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,N(S.rows)]},C))]}),e.collapsed&&m.some(S=>j.has(S))?n.jsx(yt,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:n.jsx(ht,{children:N(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(ae,{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:[...v];return n.jsx(Il,{action:S,args:da(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 n8(e,t,s){return Object.entries(e).every(([r,i])=>{const a=typeof i=="string"?i:Ne(s,i.row);return a!=null&&t[r]===String(a)})}function WA(e,t,s){const r=At(),[i,a]=h.useState(null);return h.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(d=>gs(d,o.when)&&n8(c,r.params,d));if(u!==void 0){a({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(d=>[d,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 HA({action:e,row:t,data:s,act:r,onForm:i}){const a=At();return e.form?n.jsx(T,{disabled:r.busy,onClick:()=>i(e,t),children:Rj(e.label,{row:t})}):n.jsx(Il,{action:e,args:da(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 KA({open:e,data:t,act:s,onClose:r,onDone:i}){const a=At(),{action:l,row:o}=e,c=l.form,[u,d]=h.useState(()=>cc(c.fields,o)),f=c.fields.some(x=>x.required&&(u[x.name]===""||u[x.name]===void 0)),{confirm:m,...p}=l,g={...p,label:c.submit};return n.jsx(ft,{title:Rj(c.title,{row:o}),onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(T,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(Il,{action:g,args:da(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:(x,b)=>void s.run(x,b,i)})]}),children:n.jsxs(se,{children:[n.jsx(Zh,{fields:c.fields,values:u,data:o,onChange:(x,b)=>d(j=>({...j,[x]:b}))}),n.jsx(le,{message:s.error})]})})}function s8({component:e,data:t}){const s=Tn(e.query,t),r=Ic(),i=cr(s.data,e.rows),a=WA(e.actions,i,r);return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:s.error}),a.open?null:n.jsx(Pl,{act:r}),a.open?n.jsx(KA,{open:a.open,data:s.data,act:r,onClose:a.close,onDone:a.finish}):null,i.length===0?s.loading?n.jsx(xe,{children:"Loading…"}):n.jsx(Ml,{text:e.empty??"Nothing here yet."}):n.jsxs(js,{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(Ne(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:r8(c,l,u),children:c.pill?n.jsx(i8,{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(ae,{align:"end",children:e.actions.filter(c=>gs(l,c.when)).map((c,u)=>n.jsx(HA,{action:c,row:l,data:s.data,act:r,onForm:a.show},u))})}):null]},o))})]})]})}function r8(e,t,s){if(e.hint){const r=Ne(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function i8({column:e,row:t}){var l,o;const s=Ne(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var x;const d=c,f=typeof d=="object"&&d!==null?d.value:c;if(f==null||f==="")return null;const m=typeof d=="object"&&d!==null?d.tone:void 0,p=(x=e.pill)==null?void 0:x.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(Bg(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(Bg((o=e.pill)==null?void 0:o.tone,t)),children:a})}function a8({component:e,data:t}){const s=Tn(e.query,t);return s.error?n.jsx(le,{message:s.error}):s.data===void 0?n.jsx(xe,{children:e.empty??"Loading…"}):n.jsx(rs,{title:e.title,note:e.note,children:n.jsxs(se,{gap:"lg",children:[e.fields.length>0?n.jsx(Bt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:qt(Ve(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(or,{component:r,data:s.data},i))]})})}function l8({component:e,data:t}){const s=At(),r=Tn(e.initial,t),i=Ic(),[a,l]=h.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(o8,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(oe,{title:e.title,aside:e.note,actions:n.jsx(T,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(Pl,{act:i}),a?n.jsx(ft,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:r.error}),c]})}function o8({component:e,data:t,initialData:s,act:r,onDone:i}){const a=h.useContext(FA),l=At(),[o,c]=h.useState(()=>cc(e.fields,s)),u=$j(e.fields,o,s),d=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(Zh,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:n.jsx(Pl,{act:r}),n.jsx(ae,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Il,{action:e.submit,args:da(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||d,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,i)})})]})}function c8(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 Mk(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function u8({component:e,data:t}){const s=At(),[r,i]=h.useState(()=>cc(e.fields,t)),[a,l]=h.useState(e.auto===!0),[o,c]=h.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),d=Tn(a&&u?e.query:void 0,t),f=cr(d.data,e.rows),m=e.count===void 0?void 0:Ne(d.data,e.count),p=e.note===void 0?void 0:Ne(d.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,x=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)},v=()=>{const C=cc(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map($=>[$.name,null]))),l(!1))},w=a?x.filter(C=>Mk(s.params[C.name])):[],y=g?w.map(C=>n.jsx(Dd,{label:C.label,onRemove:()=>{const $={...r,[C.name]:C.type==="checkbox"?!1:""};i($),b($)},children:c8(C,String(s.params[C.name]))},C.name)):[],N=x.filter(C=>Mk(r[C.name])).length,k=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(T,{variant:"ghost",onClick:v,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(rs,{title:e.title,children:n.jsxs(se,{children:[n.jsx(OE,{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:x.length>0?n.jsx(Zh,{fields:x,values:r,data:t,compact:!0,onChange:j}):void 0,...g&&x.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:N}:{},chips:y.length>0?y:void 0,actions:k}),n.jsx(le,{message:d.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(xe,{children:d.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(ht,{children:f.map((C,$)=>{const R=UA(s,S,C);return n.jsx(st,{title:R.title,sub:R.sub,side:R.side},$)})})}):null]})})}function d8({component:e,data:t}){const s=At(),r=e.selection==="local",[i,a]=h.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,d)=>n.jsx(or,{component:u,data:t},d))});return n.jsx(uc.Provider,{value:!1,children:n.jsx(ME,{list:n.jsx(zA.Provider,{value:!0,children:n.jsx(or,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(Ej.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function h8({component:e,data:t}){const s=At(),[r,i]=h.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&&gs(a.data,e.poll.while);h.useEffect(()=>i(l),[l]);const o=cr(a.data,e.rows);return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:a.error}),o.length===0?a.loading?n.jsx(xe,{children:"Loading…"}):n.jsx(Ml,{text:e.empty??"Nothing here yet."}):n.jsx(se,{gap:"lg",divided:!0,children:BA(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(oe,{children:n.jsx(se,{children:e.body.map((d,f)=>n.jsx(or,{component:d,data:u},f))})},c))})]})}function f8({component:e,data:t}){const s=At(),r=O5({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:N5(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=Tn(e.query,t,void 0,{from:r.from,to:r.to}),a=h.useMemo(()=>A5(cr(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(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:i.error}),n.jsx(L5,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function m8({component:e,data:t}){var f;const s=At(),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=cr(r.data,e.items).flatMap(m=>{const p=nj([m],i).tiles[0];return p?[{tile:p,key:e.select?String(Ne(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,d=a.some(m=>m.key===u);return h.useEffect(()=>{l&&c!==""&&!d&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,d]),n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:r.error}),r.data===void 0?n.jsx(xe,{children:"Loading…"}):a.length===0?n.jsx(Ml,{text:e.empty??"Nothing to show."}):n.jsx(GE,{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 p8({component:e,data:t}){const s=Tn(e.query,t),r=cr(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(rs,{title:e.title,note:e.note,children:[n.jsx(le,{message:s.error}),s.data===void 0?n.jsx(xe,{children:"Loading…"}):n.jsx(Ml,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(Ne(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)=>nj([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(Ne(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(le,{message:s.error}),n.jsx(W5,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function g8({component:e,data:t}){const s=Tn(e.query,t),r=o=>{const c=Ne(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(le,{message:s.error}),n.jsx(xe,{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(ue,{name:Rl(xg(Ve(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 x8({component:e,data:t}){var u;const s=At(),[r,i]=h.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=LA({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(d=>d.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(d=>d.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,children:[a&&l.length>1?n.jsx(sn,{label:a.label,options:l,value:o,onChange:d=>s.setParams({[a.param]:d})}):null,e.tabs.length>1?n.jsx(sn,{label:e.title??"View",options:e.tabs.map(d=>({value:d.id,label:d.label})),value:c.id,onChange:i}):null]}),c.body.map((d,f)=>n.jsx(or,{component:d,data:t},`${c.id}-${f}`))]})}function v8({component:e,data:t}){const[s,r]=h.useState(!1),i=Tn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Ve(t,e.label)??"");return n.jsxs(yt,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(le,{message:i.error}),i.data===void 0?n.jsx(xe,{children:"Loading…"}):n.jsx(se,{children:e.body.map((l,o)=>n.jsx(or,{component:l,data:i.data},o))})]})}function j8({component:e,data:t}){const s=At(),r=Ic();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{align:"end",children:n.jsx(Il,{action:e.action,args:da(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(Pl,{act:r})]})}function w8({component:e}){const t=At();return n.jsx(Nj,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function y8({component:e,data:t}){const s=Ne(t,e.path);return typeof s!="string"||s===""?null:n.jsx(Vd,{id:s})}function b8({component:e,data:t}){const s=Ne(t,e.path);return typeof s!="string"||s===""?null:n.jsx(ae,{children:n.jsx("a",{href:vi(s),children:e.label})})}function k8({component:e,data:t}){const s=Tn(e.query,t),r=Ic();return s.error?n.jsx(le,{message:s.error}):s.data===void 0?n.jsx(xe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(Pl,{act:r}),n.jsx(N8,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function N8({component:e,data:t,loaded:s,act:r}){const i=At(),[a,l]=h.useState(()=>cc(e.fields,s)),o={...a,version:Ne(s,e.version)},c=$j(e.fields,a,s),u=e.readOnlyWhen!==void 0&&gs(s,e.readOnlyWhen),d=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Il,{action:p,args:da(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(x,b)=>void r.run(x,b)},`${p.tool}-${g}`);return n.jsx(rs,{title:e.title,note:e.note,children:n.jsxs(se,{children:[n.jsx(Zh,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(x=>({...x,[p]:g}))}),u?null:n.jsxs(ae,{align:"end",children:[d.map(m),d.length>0?n.jsx(Dt,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function Ij({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a,params:l}){const[o,c]=h.useState(()=>({...l})),u=JSON.stringify(l??{});h.useEffect(()=>{l&&Object.keys(l).length>0&&c(b=>({...b,...l}))},[u]);const[d,f]=h.useState(0),m={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...o,...t?{item:t}:{},...C8(e,t)},setParams:b=>c(j=>{const v={...j};for(const[w,y]of Object.entries(b))y===null?delete v[w]:v[w]=y;return v}),navigate:s,timezone:r,version:d,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,x=g===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(Ej.Provider,{value:m,children:n.jsx(An,{embedded:i,title:e.title,lede:g,children:n.jsx(S8,{page:x,boxed:i===!0})})})}function S8({page:e,boxed:t}){const s=At();return e.data&&s.sensitive.has(e.data.query)?n.jsx(DA,{children:n.jsx(Dk,{page:e,boxed:t})}):n.jsx(Dk,{page:e,boxed:t})}function Dk({page:e,boxed:t}){const s=Tn(e.data,null);return n.jsxs(se,{gap:"lg",divided:!t,children:[n.jsx(le,{message:s.error}),n.jsx(uc.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(or,{component:r,data:s.data??null},i))})]})}function C8(e,t){if(!t)return{};const s=[],r=i=>{for(const a of i)if(a.kind==="list-detail")s.push(a.param),r(a.detail);else if(a.kind==="section"||a.kind==="detail"||a.kind==="expand")r(a.body);else if(a.kind==="tabs")for(const l of a.tabs)r(l.body)};return r(e.body),Object.fromEntries(s.map(i=>[i,t]))}function E8(e){return n.jsx(Ij,{...e,embedded:!0})}function Ml({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(jn,{title:s,children:r||null})}const Ok=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],A8=["","image","pdf","table","text","code","audio","video","archive","file"];function T8({hash:e,timezone:t,navigate:s,agents:r}){var z;const i=tF(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,d]=h.useState(c);h.useEffect(()=>{d(c)},[c]);const f=(A,P=!1)=>s(fu(a,{q:c,origin:l,family:o,...A}),P);h.useEffect(()=>{if(u===c)return;const A=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout(A)},[u]);const[m,p]=h.useState(null),[g,x]=h.useState(null),[b,j]=h.useState(null),[v,w]=h.useState(!1),[y,N]=h.useState(!1),k=A=>{var P;return A?((P=r.find(D=>D.id===A))==null?void 0:P.name)??A:""},S=h.useRef(0);h.useEffect(()=>{const A=++S.current;p(null),x(null),w(!1),j(null),E.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(P=>{S.current===A&&(p(P.entries),x(P.next))}).catch(P=>{S.current===A&&j(P instanceof pe?P.message:String(P))})},[c,l,o]);const C=()=>{if(!g||v)return;w(!0);const A=S.current;E.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(P=>{S.current===A&&(p(D=>{const O=new Set((D??[]).map(M=>M.id));return[...D??[],...P.entries.filter(M=>!O.has(M.id))]}),x(P.next))}).catch(P=>{S.current===A&&j(P instanceof pe?P.message:String(P))}).finally(()=>{S.current===A&&w(!1)})},$=(l?1:0)+(o?1:0),R=((z=Ok.find(A=>A.id===l))==null?void 0:z.label)??l,I=n.jsxs(n.Fragment,{children:[m===null?n.jsx(xe,{children:"Loading…"}):m.length===0?n.jsx(xe,{children:"No file matches that."}):n.jsx(ht,{children:m.map(A=>n.jsx(PE,{href:fu(A.id,{q:c,origin:l,family:o}),current:A.id===a,onClick:()=>s(fu(A.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":A.family,children:A.family==="image"&&!A.deleted?n.jsx("img",{src:Fr(A.id),alt:"",loading:"lazy"}):n.jsx(gj,{family:A.family})}),title:A.filename??"Untitled file",meta:n.jsx("span",{title:nt(A.createdAt,t),children:De(A.createdAt)}),sub:`${Vi[A.family]} · ${Fn(A.sizeBytes)} · ${VA(A,k)}${R8(A,k)}`},A.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(T,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),U=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."})]}),U?n.jsx(jn,{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(OE,{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:A=>d(A.target.value)}),filters:n.jsxs(Ls,{dense:!0,children:[n.jsx(ie,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:A=>f({origin:A.target.value}),children:Ok.map(A=>n.jsx("option",{value:A.id,children:A.label},A.id))})}),n.jsx(ie,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:A=>f({family:A.target.value}),children:A8.map(A=>n.jsx("option",{value:A,children:A===""?"Any kind":Vi[A]},A))})})]}),filtersOpen:y,onToggleFilters:()=>N(A=>!A),active:$,chips:$>0?n.jsxs(n.Fragment,{children:[l?n.jsx(Dd,{label:"Origin",onRemove:()=>f({origin:""}),children:R}):null,o?n.jsx(Dd,{label:"Kind",onRemove:()=>f({family:""}),children:Vi[o]}):null]}):void 0}),n.jsx(le,{message:b}),n.jsx(ME,{className:"files-split",label:"Files",list:I,detail:a?n.jsx($8,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(fu(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function R8(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 VA(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 $8({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(null);h.useEffect(()=>{let v=!1;return l(null),d(null),E.libraryEntry(e).then(w=>{v||l(w)}).catch(w=>{v||d(w instanceof pe&&w.status===404?"This file is no longer in the library.":w instanceof pe?w.message:String(w))}),()=>{v=!0}},[e]);const f=v=>{var w;return v?((w=s.find(y=>y.id===v))==null?void 0:w.name)??v:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(T,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(G,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(xe,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:x}=a,b=m.filename??"Untitled file",j=()=>{c(!0),E.libraryEntry(e,p.length).then(v=>l(w=>w&&{...w,contexts:[...w.contexts,...v.contexts],contextsTotal:v.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(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(gj,{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:[Vi[m.family]," · ",Fn(m.sizeBytes)," · ",nt(m.createdAt,t)]})]}),x?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:vi(m.id),download:b,children:"Download"}):null]}),x?null:n.jsx(G,{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(tA,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:x}),n.jsx(Bt,{items:[{label:"Origin",value:VA(m,f)},...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(ln,{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(v=>{const w=v.groupId?Oi(v.groupId,v.conversationId):tt(v.conversationAgentId,v.conversationId),y=v.groupId?v.groupName??"a group":f(v.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:v.groupId?`Group: ${y}`:y}),n.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${f(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",De(v.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:N=>{N.preventDefault(),r(w)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<g?n.jsx(ae,{align:"end",children:n.jsx(T,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const I8={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 GA(e){return e&&I8[e]||"plug"}const YA="buddi.keepClose";let ul=null;const Wg=new Set;function Hg(){for(const e of Wg)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),ul=e,Hg()}),window.addEventListener("appinstalled",()=>{ul=null,Mj(),Hg()}));function ef(){const[e,t]=h.useState(ul);return h.useEffect(()=>{const s=()=>t(ul);return Wg.add(s),s(),()=>{Wg.delete(s)}},[]),qA()?null:e}async function Pj(e){try{await e.prompt();const t=await e.userChoice;ul===e&&(ul=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&Mj(),Hg(),s}catch{return!1}}function P8(){try{return window.localStorage.getItem(YA)!==null}catch{return!1}}function Mj(){try{window.localStorage.setItem(YA,"dismissed")}catch{}}function qA(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function M8(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function QA(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 D8(e){return/Mac|iPhone|iPad/.test(e)}function O8(){const e=ef(),[t,s]=h.useState(P8);if(t||!e)return null;const r=()=>{Mj(),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(ae,{align:"end",children:[n.jsx(T,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(T,{size:"sm",variant:"accent",onClick:()=>{Pj(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function L8(){const e=ef(),[t,s]=h.useState(void 0),[r]=h.useState(qA);if(h.useEffect(()=>{if(r)return;let o=!0;return E.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=M8(),l=e?null:QA(i);return n.jsx(oe,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(ae,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>{Pj(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 ",D8(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]})})}const _8=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,F8=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,z8="data:image/webp;base64,UklGRloGAABXRUJQVlA4IE4GAADQKgCdASrAAJAAPpVInUolpKmtqTe6EbASiUdvknkVpMHex+cfn6FpYp/9uZP+p3tPRfzQ/Vd/Sej/8/++pP8bkmkrujVcbfosAWVvo98GPJDgcpdpkar6crJ+OUcccXvyduwiVqZIt11sMX//3JP2wugWcHYMSjhNfw/YXfPBz7/+f4KsYSTyT6uayU6+fROo0TO6X4IyHrF+l6toP//txS0FMPUdRtJ6p+KCT2dP3gpLomT/wObriNY+VMOA0Zv+Tv48yM6/mEHjtXwfON8gBTL8RqQm7vROt+4EPvqHCsf6f1vUb+PxZm8Y0/H4GI68rdhftV4yy/CoatiRgTrzW8ekWPCSt9eJvusnrXMcJruQHwSz5/vX9vG8C1y5aeF5l34kChCD3TSgQUw9kBS9sQ1NbMi1pMKuJqUEgiZd/2y+wAjF/DOKI3FZHBa5Q2qCooTfUj9A0XCixL3kuiAA/vqtztWnhuK0AAUKVrOx4/8K6IntNvzYOatrdU3xfr4QYYAHyIAAE90qDuxwvNSaslOgj1XzeQ7o4CiG+WFb4zwdPY6lyVxnN49hB6ipRsqQgAGt1TM/WHRmZXsFqcgHgXvLRO/p+gY76bpHJq4QeDFM3Q6tVUsq12eA8xdt9XMl/j2W0PHmipASSSIaS5KLMTjz4jtZfUwqTOj0emDBJw60TFqwI7jSvw3mbEwxxbojRIHLx6DfSdsFdhjJvJMS7fn0N+lA61ZOdS0OwUdd69Dt/YuIccchkuSR0QX9woaHISeHgXHlRAF2XLwciGQqbLIy9BogJ/4g+AKroStuCVhcYugjGC2gxUtl2UrwpIDcHI1ccHnGLv68wJ5AAfOSAKcV1RtS2UUbfSRLCnU6xoa6KmV/rAxptF6OJf8GfEOtKNwm6VddtwyPoa9muhJGhR/j6ruJ/kFnMRNLH7WcXtQIhNlVo8xRvRaoH9RGwIfvhwAigF4zejYm1wAynQhgR7ecE/15lbKTsTBb8Y9fEc9zNmZZgMzlto8cNZj+0+k1TTQ0wmrRktZ299Sqko1Ov4yDQRP0iKSe/g8XpiHowGqR5N0lsvJeEojijafpSRp0k3G59maRyl+1LsIb5YW8WfgFHbtRtYszt39yl7EPwLfsYwXOWqPwg0IVemW8v5CMln54J4c9m95OIxJHYL7cQTzWyrY8qgaxhR5vtr+NJyiQTlKN31r1xeJhCmJZKtY9OIGzesGUOdmetfh1jmfh5YtwdxOG900hLMD4vv1jYXAng8YZpjDTRUcuUrlYiO+BtcbnuIUA9SVRzFAdwReo1Rry/Sm7lNWjORAVT0B4dXzkfjv/+SykUdSAYx2evoGEJeUFqXPQt16XiwAduftyvFBUlNVwP8bZv+Hg3wueDwbUZYgaHM2qC7CJdIdf4uB9elmZViV9gssG5C8+Vk1BCJoqMasH9cFJcYjqlpDSWtZ5XcTreCV+dBwxHKh/IfqUOmZWnvYIE6xQ0YlVMc2CZuriPdRDQEoKjgMZ67X1f7XsanRDwL3attVpj5zWBRiXYdoGzt/O4w9zk/qCWUbZyy7ik+prantqxCiKAbRE7jZhTXFGprni/fldU5v5vRozeswfGCVXQzQpmjEMJA5uV4eB1w0ooNYM+ZV9yo/rqYIfhQHnzn3N7N44UBzZl6EI7806lpMMDZMk2Vd7aTc7dapectSczJ1D9mZ0MKvd0Skg1Euq1uGwQNEu1ANTFFUYIOmREj8d3vYHkWlhmuiTLKbQxl4CgDYk4vH6kA9iGe43Mo5BF4WoiQ6OqRJTxel29R6Yc/FWmw/enfMaPdyWgKnVSn6TSLoPcgJ6lu1pd39McpTo92Aw0czVjUXTcdSL3c38q4YyOdJkv6sw+FeXr/DOXP3S3xXjo7SMXD2UED68pQEVkjf4SaSqWUarBkeacGOlssJDsoVFm46XleiI+Ug9j+hAVyLDPKsLDo+8qrFgcEexTGjmonZnow0nKD80SpF+KbZD78vfc4MJN2F5ZhWC+mDVgv6Bj8kTD6MGV+6YllFA/AdnvTw+idzBKLNTYe7PEcq2AWNOAog/43qtjJQbAdxGkS8KewzmlpTP4KIuDoynjBuqv9Y6PR+nv2IZpWyNvqTUkqiFJnCQI/XKogTppN/pcEAOJ+XFqAA=",Kg={desk:_8,phone:F8,thumb:z8},bm={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function U8(e){return e?Kg.phone:Kg.desk}function XA(){const[e,t]=h.useState(()=>new Date);return h.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const B8=3,JA=8e3,W8={hiddenHere:new Set,restoredHere:new Set};function H8(e,t){return t.hiddenHere.has(e.id)?!0:e.hidden&&!t.restoredHere.has(e.id)}function K8(e,t=W8){return(e??[]).filter(s=>!H8(s,t)).slice(0,B8)}function ZA(e){const[t,s]=h.useState(new Set),[r,i]=h.useState(new Set),[a,l]=h.useState(null),o=h.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 h.useEffect(()=>{if(!a)return;const m=window.setTimeout(()=>l(null),JA);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}),E.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)),E.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 V8({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 G8(e){return e.link?mj(e.link.plugin,e.link.page,e.link.place):null}function Y8({glances:e,navigate:t,onChanged:s,except:r,hiding:i}){var u,d;const a=ZA(s),l=i??a,o=K8(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=n.jsx(V8,{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:[((d=l.justHidden)==null?void 0:d.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=G8(f),p=n.jsxs(n.Fragment,{children:[n.jsx(ue,{name:Rl(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(ue,{name:"close",size:10})})]},f.id)})]})}function q8(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 Q8({points:e,className:t="wg-spark"}){const s=q8(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 ka=Math.PI/180;function X8(e,t,s){const r=e.getTime()/864e5+24405875e-1-2451545,i=(357.529+.98560028*r)*ka,l=(280.459+.98564736*r+1.915*Math.sin(i)+.02*Math.sin(2*i))*ka,o=(23.439-36e-8*r)*ka,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),u=Math.asin(Math.sin(o)*Math.sin(l)),f=((18.697374558+24.06570982441908*r)*15+s)*ka-c,m=t*ka,p=Math.sin(m)*Math.sin(u)+Math.cos(m)*Math.cos(u)*Math.cos(f);return Math.asin(Math.max(-1,Math.min(1,p)))/ka}function J8(e,t,s){return X8(e,t,s)>-.833}const Z8={small:2,medium:4},Lk=new Map;function eW(e){let t=Lk.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"}),Lk.set(e,t)),t}function _k(e,t){const s=Object.fromEntries(eW(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 tW(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 nW(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 sW(e,t,s,r,i){const a=_k(e,t.zone),l=_k(e,s),o=a.date===l.date?"Today":a.date>l.date?"Tomorrow":"Yesterday",c=a.offset-l.offset,u=yc(i?{timeFormat:i}:{},()=>Wt(e,t.zone)),d=r?"your time":nW(c);return{...a,day:o,daytime:typeof t.latitude=="number"&&typeof t.longitude=="number"?J8(e,t.latitude,t.longitude):a.h>=6&&a.h<18,offsetText:r?"Here":tW(c),time:u,label:`${t.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${d}`}}function rW(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 iW(e){const[t,s]=h.useState(()=>new Date);return h.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 Fk({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 aW=Array.from({length:12},(e,t)=>t);function lW({time:e,seconds:t}){const s=rW(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"}),aW.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(Fk,{angle:s.hour,length:24,width:4.6}),n.jsx(Fk,{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 oW({body:e,size:t}){const s=Ms("(prefers-reduced-motion: reduce)"),r=iW(!s),i=e.clocks.slice(0,Z8[t]);return n.jsx("div",{className:"wg-clocks","data-count":i.length,children:i.map((a,l)=>{let o;try{o=sW(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(lW,{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 cW=3,uW={small:4,medium:6};function km({icon:e,size:t}){return e?n.jsx("span",{className:"wg-icon",children:n.jsx(ue,{name:Rl(e),size:t})}):null}function Dj({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(km,{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(Q8,{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,cW).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(km,{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,uW[t]).map((s,r)=>n.jsxs("span",{className:"wg-tile",children:[n.jsx("span",{className:"wg-tile-label",children:s.label}),n.jsx(km,{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(oW,{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(ue,{name:Rl(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 Vg({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(ue,{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 zk(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function dW(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 hW({field:e,value:t,places:s,onChange:r}){const i=Array.isArray(t)?t:t?[t]:[],[a,l]=h.useState(""),[o,c]=h.useState([]),[u,d]=h.useState(!1),[f,m]=h.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(zk(y),{value:y,label:y.label,sub:y.name});const g=[...p.entries()].map(([y,N])=>({value:y,label:N.label,sub:N.sub})),x=i.map(zk),b=s.find(y=>y.id==="home"||y.label.toLowerCase()==="home")??s[0],j=e.multiple?x:x[0]??(b==null?void 0:b.id)??"",v=y=>{const N=(Array.isArray(y)?y:[y]).map(k=>{var S;return(S=p.get(k))==null?void 0:S.value}).filter(k=>!!k);r(e.multiple?N.slice(-3):N[0]??null)},w=()=>{const y=a.trim();y.length<2||(d(!0),m(null),E.findPlace(y).then(({found:N})=>{const k=N.slice(0,3).map(dW);c(k),k.length===0?m(`Nothing found for “${y}”.`):e.multiple?r([...i,k[0]].slice(-3)):r(k[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>d(!1)))};return n.jsxs("div",{className:"wg-field-stack",children:[g.length>0?n.jsx(Vg,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:v}):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 fW({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(Vg,{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(Vg,{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(hW,{field:e,value:t,places:s.places,onChange:r});break;case"timeFormat":i=n.jsx(sn,{label:e.label,options:[{value:"profile",label:t1()},{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 mW({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(Dj,{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 eT({info:e,placement:t,surface:s,onSave:r,onRemove:i,onClose:a}){const l=ce(()=>E.widgetSettings(e.id),[e.id]),[o,c]=h.useState(t.settings??{}),[u,d]=h.useState(null),[f,m]=h.useState(t.label??e.title),[p,g]=h.useState(!1),[x,b]=h.useState(null),j=h.useRef(0),v=h.useMemo(()=>JSON.stringify(o),[o]);h.useEffect(()=>{const N=++j.current,k=window.setTimeout(()=>{E.previewWidget({widget:e.id,size:t.size,settings:o}).then(S=>{N===j.current&&(d(S.view),m(S.label))}).catch(()=>{N===j.current&&d({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(k)},[v,e.id,t.size]);const w=()=>{g(!0),b(null),r(o).then(N=>{g(!1),N||b("Couldn’t keep these settings. Try again.")})},y=s==="lock"?"the lock screen":"Home";return n.jsx(ft,{title:f,onClose:a,foot:n.jsxs(ae,{children:[n.jsxs(T,{variant:"danger-ghost",onClick:i,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),n.jsx(Dt,{}),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(mW,{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(le,{message:x??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(N=>n.jsx(fW,{field:N,value:o[N.key],sheet:l.data,onChange:k=>c({...o,[N.key]:k})},N.key)):l.error?null:n.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const pW=6e4,tT="buddi.clock",nT="buddi.home.widgets";function gW(){try{const e=Number(window.localStorage.getItem(nT));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function xW(e){try{window.localStorage.setItem(nT,String(e))}catch{}}function sT(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}`}function rT(e,t){const s=h.useRef(t);s.current=t,h.useEffect(()=>{if(!e)return;let r;const i=()=>{r=setTimeout(()=>{s.current(),i()},6e4-Date.now()%6e4+1e3)};return i(),()=>clearTimeout(r)},[e])}function vW(){const e=ce(()=>E.widgets("home"),[],pW),[t,s]=h.useState(void 0);return h.useEffect(()=>{e.data&&s(e.data)},[e.data]),h.useEffect(()=>{t&&xW(t.home.length)},[t]),rT((t==null?void 0:t.home.some(r=>{var i,a;return r.widget===tT&&((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 jW(e){return new Set(((e==null?void 0:e.home)??[]).map(t=>t.widget))}function wW(e){const[t,s]=h.useState(!1);return h.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 iT=(e,t)=>e.label??(t==null?void 0:t.title)??e.widget;function yW({info:e,placement:t,view:s,index:r,count:i,editing:a,navigate:l,act:o,onRetry:c,retrying:u,drag:d}){var S;const[f,m]=wW(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,x=e.link?mj(e.link.plugin,e.link.page,e.link.place):null,b=x!==null&&!a&&p!=="error"&&!g,j=t.size==="small"?"medium":"small",v=iT(t,e),w=t.key,y=(((S=e.settings)==null?void 0:S.length)??0)>0;let N;!s&&a?N=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?N=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:[bW(s.error),"."]}):null,a?null:n.jsx(T,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?N=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?N=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"})]}):N=n.jsx(Dj,{body:s.body,size:t.size});const k=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),d.start(w)};return n.jsxs("div",{className:"wg-frame",role:"group","aria-label":v,"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":d.dragging===w?"true":void 0,"data-over":d.over===w&&d.dragging!==w?"true":void 0,draggable:a?!0:void 0,onDragStart:a?k:void 0,onDragOver:a?C=>{d.dragging&&(C.preventDefault(),d.enter(w))}:void 0,onDrop:a?C=>{C.preventDefault(),d.drop(w)}:void 0,onDragEnd:a?()=>d.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 ${v}, 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(ue,{name:"grip",size:14})}):null,n.jsx("span",{className:"wg-title",children:v}),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?`${$v(s.updatedAt)} old`:"Not current"}):null,a&&y?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${v}`,title:"Settings",onClick:()=>o("settings"),children:n.jsx(ue,{name:"settings",size:14})}):null,a?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${v} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:n.jsx(ue,{name:"close",size:12})}):n.jsx("span",{className:"wg-more",children:n.jsx(Al,{label:`More for ${v}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${De(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:x,onClick:C=>{C.preventDefault(),l(x)},children:N}):n.jsx("div",{className:"wg-body",children:N}),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 ${v}`,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 ${v} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:n.jsx(ue,{name:"chevron-left"})}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${v} later`,title:"Move later",disabled:r===i-1,onClick:()=>o("later"),children:n.jsx(ue,{name:"chevron-right"})})]})]}):null]})}function bW(e){const t=e.replace(/\.$/,"");return t.charAt(0).toUpperCase()+t.slice(1)}function kW({widgets:e,navigate:t}){const{answer:s,apply:r}=e,[i,a]=h.useState(!1),[l,o]=h.useState([]),[c,u]=h.useState(null),[d,f]=h.useState(""),[m,p]=h.useState(null),[g,x]=h.useState(!1),[b,j]=h.useState(null),[v,w]=h.useState(null),[y,N]=h.useState(null),[k,S]=h.useState(null),[C,$]=h.useState(new Set),[R]=h.useState(gW),I=h.useRef(null);if(h.useEffect(()=>{if(!c)return;const ee=window.setTimeout(()=>u(null),JA);return()=>window.clearTimeout(ee)},[c]),h.useEffect(()=>{var be;const ee=I.current;ee&&(I.current=null,(be=document.querySelector(`[data-grip="${CSS.escape(ee)}"], [data-move="${CSS.escape(ee)}"]`))==null||be.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},(ee,be)=>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"})]})]},be))})]});if(s.available.every(ee=>ee.builtIn)&&s.home.length===0)return null;const U=new Map(s.available.map(ee=>[ee.id,ee])),z=i?l:s.home,A=ee=>iT(ee,U.get(ee.widget)),P=(ee,be)=>(p(null),r({...be,home:ee,arranged:{...be.arranged,home:!0}}),E.saveWidgets("home",ee).then(re=>(r(re),!0),re=>(r(be),p(`Couldn't save your widgets: ${re instanceof Error?re.message:String(re)}`),!1))),D=(ee,be,re)=>{if(re<0||re>=ee.length||be===re)return null;const Ee=ee.slice(),[me]=Ee.splice(be,1);return Ee.splice(re,0,me),f(`${A(me)}, position ${re+1} of ${Ee.length}.`),Ee},O=()=>{o(s.home),$(new Set),u(null),p(null),a(!0)},M=ee=>(be,re)=>{const Ee=z[ee];if(be==="edit"){O();return}if(be==="settings"){S(Ee.key);return}if(i){if(be==="earlier"||be==="later"){const me=D(l,ee,be==="earlier"?ee-1:ee+1);if(me){const Re=document.activeElement;I.current=(Re==null?void 0:Re.dataset.grip)??(Re==null?void 0:Re.dataset.move)??null,o(me)}}be==="size"&&re&&(o(l.map((me,Re)=>Re===ee?{...me,size:re}:me)),$(new Set([...C,Ee.key]))),be==="hide"&&(o(l.filter((me,Re)=>Re!==ee)),f(`${A(Ee)} taken off.`));return}if(be==="earlier"||be==="later"){const me=D(s.home,ee,be==="earlier"?ee-1:ee+1);me&&P(me,s)}be==="size"&&re&&P(s.home.map((me,Re)=>Re===ee?{...me,size:re}:me),s),be==="hide"&&P(s.home.filter((me,Re)=>Re!==ee),s).then(me=>{me&&u({item:Ee,at:ee})})},W=()=>{if(!c)return;const ee=s.home.filter(be=>be.key!==c.item.key);ee.splice(Math.min(c.at,ee.length),0,c.item),u(null),P(ee,s)},L=()=>{x(!0),P(l,s).then(ee=>{x(!1),ee&&(a(!1),f("Widgets saved."))})},q=ee=>{j(ee),E.refreshWidget(ee).then(r,()=>{}).finally(()=>j(null))},B=ee=>{var Ee;const be={key:sT(),widget:ee.id,size:ee.sizes[0],settings:{}},re=l.some(me=>me.widget===ee.id);o([...l,be]),f(`${ee.title} added.`),re&&(((Ee=ee.settings)==null?void 0:Ee.length)??0)>0&&S(be.key)},V=(ee,be)=>i?(o(l.map(re=>{if(re.key!==ee)return re;const{label:Ee,...me}=re;return{...me,settings:be}})),$(new Set([...C,ee])),S(null),Promise.resolve(!0)):P(s.home.map(re=>re.key===ee?{...re,settings:be}:re),s).then(re=>(re&&(S(null),f("Settings saved.")),re)),F=ee=>{S(null);const be=z.findIndex(re=>re.key===ee);be>=0&&M(be)("hide")},X={dragging:v,over:y,start:ee=>w(ee),enter:ee=>{y!==ee&&N(ee)},end:()=>{w(null),N(null)},drop:ee=>{const be=l.findIndex(me=>me.key===v),re=l.findIndex(me=>me.key===ee),Ee=be>=0&&re>=0?D(l,be,re):null;Ee&&o(Ee),w(null),N(null)}},Y=c?n.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[n.jsxs("span",{children:[A(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,Z=[];z.forEach((ee,be)=>{const re=U.get(ee.widget);if(!re)return;c&&!i&&c.at===be&&Z.push(Y);const Ee=i&&(C.has(ee.key)||!s.home.some(me=>me.key===ee.key));Z.push(n.jsx(yW,{info:re,placement:ee,view:Ee?void 0:s.views[ee.key],index:be,count:z.length,editing:i,navigate:t,act:M(be),onRetry:()=>q(ee.key),retrying:b===ee.key,drag:X},ee.key))}),c&&!i&&c.at>=z.length&&Z.push(Y);const he=s.available.filter(ee=>!ee.builtIn),Le=he.length-2,Ie=k?z.find(ee=>ee.key===k):void 0,ze=Ie?U.get(Ie.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:L,disabled:g,children:g?"Saving…":"Done"})]}):z.length>0?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(T,{size:"sm",variant:"ghost",onClick:O,children:"Edit"})}):null]}),n.jsx("p",{className:"sr-only","aria-live":"polite",children:d}),m?n.jsx(G,{tone:"critical",role:"alert",children:m}):null,z.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:"," ",(he.length>0?he:s.available).slice(0,2).map(ee=>ee.title).join(", "),Le>0?` and ${Le} more`:"","."]})]}),n.jsx(T,{size:"sm",variant:"accent",onClick:O,children:"Add widgets"})]}):Z.length>0?n.jsx("div",{className:"wg-grid","data-editing":i?"true":void 0,children:Z}):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:Oe("lock"),onClick:ee=>{ee.preventDefault(),t(Oe("lock"))},children:"The lock screen has its own pick"})]}),n.jsx("ul",{className:"wg-gallery-list",children:s.available.map(ee=>{var Se;const be=l.filter(Ue=>Ue.widget===ee.id).length,re=(((Se=ee.settings)==null?void 0:Se.length)??0)>0,Ee=ee.builtIn?"Built in":`${ee.plugin} plugin`,me=ee.sizes.length>1?"small or medium":`${ee.sizes[0]} only`,Re=be>1?` · ${be} on Home`:be===1&&re?" · 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:ee.title}),n.jsxs("span",{className:"wg-add-sub",children:[Ee," · ",me,ee.sensitive?" · hidden until you show it":"",Re]})]}),be>0&&!re?n.jsx("span",{className:"wg-add-note",children:"On Home"}):n.jsxs(T,{size:"sm","aria-label":`${be>0?"Add another":"Add"} ${ee.title}`,onClick:()=>B(ee),children:[n.jsx(ue,{name:"plus",size:12})," ",be>0?"Add another":"Add"]})]},ee.id)})})]}):null,Ie&&ze?n.jsx(eT,{info:ze,placement:Ie,surface:"home",onClose:()=>S(null),onSave:ee=>V(Ie.key,ee),onRemove:()=>F(Ie.key)}):null]})}function Oj(e,t){return!e||e==="image"&&!t?"earth":e}const NW="(max-width: 720px)",SW=3e4,CW={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Nm(e,t){return{time:Wt(e,t),day:dr(e,t,{weekday:!0})}}function Lj(e,t){return e?yc({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},t):t()}function EW(e,t,s=new Date,r){return Lj(r,()=>AW(e,t,s))}function AW(e,t,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),a=Nm(r,t).day===Nm(s,t).day?Nm(r,t).time:Rv(r,t);return e.reason==="idle"?`Locked after ${e.delayMinutes?CW[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 TW(e){const t=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=h.useState(t);return h.useEffect(()=>{if(r(t()),!e)return;const i=window.setInterval(()=>r(t()),500);return()=>window.clearInterval(i)},[e]),s}const RW=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function Uk({size:e=16}){return n.jsx(ue,{name:"lock",size:e})}function aT({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 $W(){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 Bk({text:e}){const[t,s]=h.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 IW({onClose:e}){return n.jsx(un,{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(Bk,{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(Bk,{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 PW({approvals:e,needs: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:"needs",n:t,text:e>0?t===1?"more needs you":"more need you":t===1?"thing needs you":"things need you"}),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==="needs"?"Open Needs you 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 MW(e,t){const s=t?2:4;let r=0,i=0;for(const a of e){const l=Math.min(a==="medium"?2:1,s);i+l>s&&(i=0),i+=l,r=Math.max(r,i)}return r}function DW({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=MW(s.map(({size:i})=>i),t);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(Dj,{body:i.view.body,size:a})}),n.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function OW({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 Wk(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 LW(e,t,s){try{const r=Wk(e,t)-Wk(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 _W(e,t,s){const r=s??{date:null,zone:null};return Lj(s,()=>({time:Wt(e,t),day:r.date==="off"?null:dr(e,t,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Wt(e,r.zone.timezone),offset:LW(e,r.zone.timezone,t)}:null}))}function lT({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=_W(t,l,e==null?void 0:e.clockView),c=Oj(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,d=u?Lj(e==null?void 0:e.clockView,()=>s?UW(dc(u,l,t)):`${Wi[u.mode]} ${dc(u,l,t)}`):"";return n.jsxs(n.Fragment,{children:[c==="earth"?n.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[n.jsx("img",{className:"lk-photo","data-earth":"true",src:U8(s),alt:"",decoding:"async"}),n.jsx("div",{className:"lk-scrim"})]}):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(ic,{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(ue,{name:"moon",size:13}),n.jsx("span",{children:d})]}):null]}),n.jsxs("div",{className:"lk-main",children:[o.day?n.jsx("p",{className:"lk-date",children:o.day}):null,n.jsx(OW,{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(PW,{approvals:e.approvals,needs:e.needs??0,after:i??null,...a?{onPick:a}:{}}),r||!e?null:n.jsx(DW,{widgets:e.widgets,phone:s})]})]})}function FW({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($W,{})}),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(aT,{size:18})})]})}function zW({initial:e,onUnlocked:t}){const s=Ms(NW),r=XA(),[i,a]=h.useState(null),l=i??e,[o,c]=h.useState(""),[u,d]=h.useState(null),[f,m]=h.useState((e==null?void 0:e.waitUntil)??null),[p,g]=h.useState(!1),[x,b]=h.useState(!1),[j,v]=h.useState(!1),[w,y]=h.useState(!1),[N,k]=h.useState(!1),[S,C]=h.useState(null),$=h.useRef(null),R=TW(f),I=R>0,U=h.useRef(t),z=h.useRef(S);z.current=S,U.current=V=>{z.current&&(window.location.hash=Fh),t(V)};const A=V=>{var F;C(V),s&&V?y(!0):(F=$.current)==null||F.focus()},P=h.useCallback(()=>{E.lockScreen().then(V=>{b(!1),a(V),m(V.waitUntil),V.locked||U.current(V)}).catch(V=>{V instanceof pe&&V.status===401?window.location.reload():$d(V)&&b(!0)})},[]);h.useEffect(()=>{P();const V=window.setInterval(P,SW),F=()=>{document.visibilityState==="visible"&&P()};return document.addEventListener("visibilitychange",F),()=>{window.clearInterval(V),document.removeEventListener("visibilitychange",F)}},[P]),rT((i==null?void 0:i.widgets.some(V=>V.id===tT&&V.view.body.kind!=="clocks"))??!1,P),h.useEffect(()=>{var V;!s&&!j&&!I&&((V=$.current)==null||V.focus())},[s,j,I,p]),h.useEffect(()=>{!I&&f&&d(null)},[I,f]);const D=V=>{V==null||V.preventDefault(),!(p||I||o.length<4)&&(g(!0),E.unlock(o).then(F=>{var Y;if(c(""),F.locked){g(!1);return}if((Y=window.matchMedia)==null?void 0:Y.call(window,"(prefers-reduced-motion: reduce)").matches){U.current(F);return}k(!0),window.setTimeout(()=>U.current(F),240)}).catch(F=>{if(g(!1),c(""),!(F instanceof pe))return d("Something went wrong. Try again.");const X=F.detail??{};if(F.status===403||F.status===429){X.waitUntil&&m(X.waitUntil);const Y=X.triesLeft??0;d(X.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${Y} ${Y===1?"try":"tries"} left.`)}else $d(F)?d("buddi isn’t answering. Try again in a moment."):d(F.message)}))},O=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,M=Oj(l==null?void 0:l.background,l==null?void 0:l.image),W=(i==null?void 0:i.owner)??null,L=x?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:I?{tone:"critical",text:`Too many tries. Try again in ${RW(R)}.`}:u?{tone:"critical",text:u}:S?{tone:void 0,text:S==="needs"?"Unlock to open what needs you.":"Unlock to open your approvals."}:{tone:void 0,text:l?EW(l,O,r,i==null?void 0:i.clockView):"Locked"},q=V=>V.replace(/\D/g,"").slice(0,8),B=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":M,"data-phone":s?"true":void 0,"data-view":w?"pad":"glance","data-opening":N?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[n.jsx(lT,{data:i??(l?{...BW(l)}:null),now:r,phone:s,pad:w,after:S,onPick:A}),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(Uk,{size:14}),n.jsx("span",{children:"Enter PIN"})]}),n.jsx("p",{className:"lk-note","data-tone":L.tone,role:"status","aria-live":"polite",children:L.text})]}):s?n.jsxs(n.Fragment,{children:[B,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((V,F)=>n.jsx("span",{className:"lk-dot"},F))}),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":L.tone,role:"status","aria-live":"polite",children:L.text}),n.jsx(FW,{value:o,disabled:I||p,onDigit:V=>{d(null),c(q(o+V))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>D()}),n.jsxs("div",{className:"lk-pad-foot",children:[n.jsx("button",{type:"button",className:"lk-link",onClick:()=>v(!0),children:"Forgot PIN?"}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),c(""),d(null)},children:"Cancel"})]})]}):n.jsxs(n.Fragment,{children:[B,n.jsxs("form",{className:"lk-pin","data-state":u&&!I?"wrong":I?"wait":void 0,onSubmit:D,children:[n.jsx(Uk,{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:V=>{d(null),c(q(V.target.value))}}),n.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:n.jsx(aT,{})})]}),n.jsx("p",{className:"lk-note",id:"lk-note","data-tone":L.tone,role:"status","aria-live":"polite",children:L.text}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>v(!0),children:"Forgot PIN?"})]})}),j?n.jsx(IW,{onClose:()=>v(!1)}):null]})}function UW(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function BW(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const WW=3e4,HW=5e3,KW="buddi-lock",Gg="buddi-locked",VW=Oe("lock");function oT(){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 GW(e=oT()){return e?"⌃⌘L":"Ctrl+Alt+L"}function YW(e,t=oT()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:t?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const cT=h.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function tf(){return h.useContext(cT)}function Su(e){try{e?localStorage.setItem(Gg,"1"):localStorage.removeItem(Gg)}catch{}}function qW(){try{return localStorage.getItem(Gg)==="1"}catch{return!1}}function QW(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(KW)}catch{return null}}function XW({children:e}){const[t,s]=h.useState("checking"),[r,i]=h.useState(null),a=h.useRef(null),l=h.useRef(Date.now()),o=h.useRef(0),c=h.useRef(0),u=h.useRef(0),d=h.useCallback((x,b)=>{x&&i(x),s(b?"locked":"open"),Su(b),b||(l.current=Date.now())},[]),f=h.useCallback(()=>{E.lockState().then(x=>d(x,x.locked)).catch(x=>{if(x instanceof pe&&x.status===401)return s("open");d(null,qW())})},[d]);h.useEffect(()=>{f()},[f]);const m=h.useCallback((x="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=VW;return}s("locked"),Su(!0),(b=a.current)==null||b.postMessage({type:"locked"}),E.lockNow(x).then(j=>d(j,j.locked)).catch(()=>f())},[r==null?void 0:r.pin,d,f]);h.useEffect(()=>{const x=()=>{s("locked"),Su(!0),f()};return window.addEventListener(Qp,x),()=>window.removeEventListener(Qp,x)},[f]),h.useEffect(()=>{const x=QW();if(a.current=x,!!x)return x.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Su(!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))},()=>{x.close(),a.current=null}},[f]),h.useEffect(()=>{const x=b=>{YW(b)&&(b.preventDefault(),t==="open"&&m("owner"))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[t,m]);const p=r!=null&&r.pin?r.delayMinutes:null;h.useEffect(()=>{if(t!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const x=()=>{var k;const N=Date.now();l.current=N,N-u.current>1e4&&(u.current=N,(k=a.current)==null||k.postMessage({type:"activity",at:N}))},b=()=>{const N=Date.now();l.current<=c.current||N-o.current<WW||(o.current=N,c.current=l.current,E.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}b()},v=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const N of v)window.addEventListener(N,x,{passive:!0,capture:!0});const w=window.setInterval(j,HW),y=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",y),()=>{for(const N of v)window.removeEventListener(N,x,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",y)}},[t,r==null?void 0:r.pin,p,m]);const g=h.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:x=>d(x,x.locked),shortcut:GW()}),[r,m,d]);return t==="checking"?null:t==="locked"?n.jsx(zW,{initial:r,onUnlocked:x=>{var b;(b=a.current)==null||b.postMessage({type:"unlocked"}),d(x,!1)}}):n.jsx(cT.Provider,{value:g,children:e})}const uT="a connection needs you";function JW({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:d,timezone:f,status:m}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:nn,onClick:p=>{p.preventDefault(),s(nn)},"aria-label":"buddi home",children:n.jsx(ic,{})}),gF.filter(p=>p.route!==Zt).map(p=>n.jsx(Sm,{label:p.label,href:p.route,active:t===p.route,badge:p.route===nn?e:0,onClick:()=>s(p.route),children:Hk[p.route]},p.route)),a.map(p=>{const g=lr(p.plugin,p.id);return n.jsx(Sm,{label:p.title,href:g,active:t===g,badge:0,onClick:()=>s(g),children:n.jsx(ue,{name:GA(p.icon)})},g)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(Sm,{label:"Settings",href:Zt,active:t===Zt,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(Zt),children:Hk[Zt]}),m,n.jsx(eH,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:d,timezone:f})]})}const ZW=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function eH({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var y,N,k;const o=ce(()=>E.owner(),[]),c=tf(),u=ce(()=>E.focus(),[],6e4),d=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{E.setFocus(S,C).finally(()=>u.reload())},m=((k=(N=o.data)==null?void 0:N.preferredName)==null?void 0:k.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[g]=h.useState(IF),[x]=h.useState(sH),b=ef(),j=m?`You: ${m}`:"You",v=d?`${Wi[d.mode]} ${dc(d,l)}`:null,w=[j,v,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Nc,{modal:!1,children:[n.jsx(Sc,{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,d?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(ue,{name:"moon",size:10})}):null]})}),n.jsx(Cl,{children:n.jsxs(Cc,{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(Nr,{className:"ui-menu-sep"}),n.jsx(nH,{focus:d,timezone:l,onSwitch:f}),n.jsx(Nr,{className:"ui-menu-sep"}),n.jsx(ta,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(sn,{label:"Theme",options:ZW,value:e,onChange:t})}),n.jsx(Nr,{className:"ui-menu-sep"}),c.pin?n.jsxs(ds,{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(ds,{className:"ui-menu-item",onSelect:()=>s(Oe("lock")),children:"Set up a lock screen…"}),n.jsx(ds,{className:"ui-menu-item",onSelect:()=>s(Oe("appearance")),children:"Change appearance"}),b?n.jsx(ds,{className:"ui-menu-item",onSelect:()=>{Pj(b)},children:"Install the app"}):null,g||i?n.jsxs(ds,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),x?n.jsx("kbd",{className:"rail-owner-kbd",children:x}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Nr,{className:"ui-menu-sep"}),n.jsxs(ds,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Oe("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 Wi={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},tH=[{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 dc(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=Wt(r,i);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:i,weekday:"short"}).format(r)} ${l}`}function nH({focus:e,timezone:t,onSwitch:s}){return n.jsxs(A_,{children:[n.jsxs(T_,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?Wi[e.mode]:"Off"})]}),n.jsx(Cl,{children:n.jsxs(R_,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Wi[e.mode]} ${dc(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(J1,{children:[n.jsx(Nr,{className:"ui-menu-sep"}),n.jsx(ta,{className:"ui-menu-label",children:Wi[r]}),tH.map(i=>n.jsx(ds,{className:"ui-menu-item","aria-label":`${Wi[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Nr,{className:"ui-menu-sep"}),n.jsx(ds,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function sH(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function Sm({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 Hk={[Or]:n.jsx(ue,{name:"files"}),[nn]:n.jsx(ue,{name:"home"}),[ci]:n.jsx(ue,{name:"chat"}),[Ct]:n.jsx(ue,{name:"agents"}),[xt]:n.jsx(ue,{name:"activity"}),[Zt]:n.jsx(ue,{name:"settings"})},hc=e=>`${e.plugin}:${e.id}`,rH=new Set;let _j=rH,Kk=!1;const Yg=new Set;function qg(e){_j=e;for(const t of Yg)t()}function iH(e){return Yg.add(e),()=>Yg.delete(e)}const Vk=()=>_j;function aH(){Kk||(Kk=!0,Promise.resolve().then(()=>E.rail()).then(e=>qg(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function lH(e,t){const s=_j,r=new Set(s);t?r.add(hc(e)):r.delete(hc(e)),qg(r);try{await E.setRailHidden(e.plugin,e.id,t)}catch(i){throw qg(s),i}}function dT(){return h.useEffect(aH,[]),h.useSyncExternalStore(iH,Vk,Vk)}function oH(e,t){return e.filter(s=>!t.has(hc(s)))}function cH(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function uH(e,t=!0,s){h.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||cH(i.target))return;i.preventDefault();const a=document.getElementById(Og);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(nn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const hT="buddi.theme";function dH(e=fT()){try{const t=e==null?void 0:e.getItem(hT);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function hH(e,t=fT()){try{t==null||t.setItem(hT,e)}catch{}}function fH(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function fT(){try{return window.localStorage}catch{return}}const mT="buddi.ground",pT="buddi.pageWidth";function mH(e=vT()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(mT),r=t(pT);return{theme:dH(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function gT(e,t=document.documentElement){t&&(fH(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 pH(e,t=vT()){hH(e.theme,t);try{t==null||t.setItem(mT,e.ground),t==null||t.setItem(pT,e.width)}catch{}}let Ja=null;const Qg=new Set;function Xg(){return Ja||(Ja=mH()),Ja}function gH(e){return Qg.add(e),()=>Qg.delete(e)}function xH(e){Ja={...Xg(),...e},gT(Ja),pH(Ja);for(const t of Qg)t()}function xT(){return[h.useSyncExternalStore(gH,Xg,Xg),xH]}function vT(){try{return window.localStorage}catch{return}}const Gk=7,vH=1e4;function jH({timezone:e,embedded:t,agents:s=[],navigate:r}){const{data:i,error:a,reload:l}=ce(()=>E.sentinels(),[],3e4),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(null),[p,g]=h.useState(null),[x,b]=h.useState(!1),[j,v]=h.useState(null),w=i==null?void 0:i.alerts,y=(w==null?void 0:w.open)??[],N=O=>{r?r(O):window.location.hash=O},k=O=>{var M;return O?((M=s.find(W=>W.id===O))==null?void 0:M.name)??null:null},S=async O=>{c(null);try{await O()}catch(M){c(M instanceof pe||M instanceof Error?M.message:String(M))}finally{l()}},C=O=>d({...O,id:Date.now()}),$=(O,M,W)=>S(async()=>{const{keys:L}=await E.snoozeAlerts(O,!0,W);C({title:M,undo:()=>E.snoozeAlerts(L,!1)})}),R=O=>S(async()=>{const{id:M}=await E.muteAlert(O.keys[0],O.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>E.unmuteAlert(M)})}),I=O=>S(async()=>{const{agentId:M,conversationId:W}=await E.askAboutAlerts(O.keys);N(tt(M,W))}),U=O=>S(async()=>{const[M]=(await E.actOnAlerts([{key:O.key,action:O.index}])).results;if(M!=null&&M.error)throw new Error(M.error);M!=null&&M.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${O.label}: done`})}),z=(O,M)=>{M.kind==="open"?N(M.place==="files"?Or:M.plugin&&M.page?lr(M.plugin,M.page,M.item):Or):M.kind==="ask"?I(O):M.kind==="dismiss"?$(O.keys,"Set aside until it changes"):M.kind==="fill"?m(M):M.confirm?g(M):U(M)},A=()=>{const O=y.flatMap(M=>M.keys);$(O,`Cleared ${y.length} for a week`,Gk)},P=w==null?void 0:w.recap,D=wH((P==null?void 0:P.nextAt)??null,e);return n.jsxs(An,{embedded:t,title:"Alerts",lede:"What needs a decision from you.",children:[n.jsx(le,{message:a??o}),n.jsxs(Qe,{flush:!0,title:"Needs a decision",tool:y.length>0?String(y.length):void 0,actions:y.length>1?n.jsx(T,{size:"sm",variant:"ghost",onClick:A,children:"Clear all"}):void 0,children:[i?y.length===0?n.jsxs("div",{className:"al-empty",children:[n.jsx(ue,{name:"check"}),n.jsxs("div",{children:[n.jsx("p",{className:"al-empty-title",children:"Nothing needs a decision."}),n.jsxs("p",{className:"al-empty-line",children:["Your watchers are quiet. What they notice in passing waits for ",D,"."]})]})]}):n.jsx("ul",{className:"al-list",children:y.map(O=>n.jsx(Yk,{group:O,agentName:k(O.agentId),onAct:z,onStop:R,onNotNow:M=>void $(M.keys,"Snoozed for a week",Gk)},O.id))}):null,P&&P.count>0?n.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[n.jsxs("span",{children:[P.count," ",P.count===1?"note":"notes"," saved for ",D]}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("button",{type:"button",className:"wb-link",onClick:()=>b(!0),children:"Preview"})]}):null]}),w&&(w.snoozed.length>0||w.resolved.length>0)?n.jsxs("p",{className:"al-quiet",children:[w.snoozed.length>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="snoozed",onClick:()=>v(j==="snoozed"?null:"snoozed"),children:[w.snoozed.length," snoozed"]}):null,w.snoozed.length>0&&w.resolved.length>0?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,w.resolved.length>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="resolved",onClick:()=>v(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?n.jsx(Qe,{flush:!0,title:"Snoozed",children:n.jsx("ul",{className:"al-list",children:w.snoozed.map(O=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:O.title}),n.jsx("p",{className:"al-sub",children:O.snoozedUntil?`Back ${De(O.snoozedUntil)}`:"Until it changes"})]}),n.jsx("div",{className:"al-actions",children:n.jsx(T,{size:"sm",onClick:()=>void S(async()=>{await E.snoozeAlerts(O.keys,!1)}),children:"Bring back"})})]},O.id))})}):null,j==="resolved"&&w?n.jsx(Qe,{flush:!0,title:"Resolved this week",children:n.jsx("ul",{className:"al-list",children:w.resolved.map(O=>n.jsx("li",{className:"al-row",children:n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:O.title}),n.jsx("p",{className:"al-sub",children:O.resolvedAt?`Resolved ${De(O.resolvedAt)}`:null})]})},O.id))})}):null,x&&P?n.jsxs(ft,{title:yH(D),onClose:()=>b(!1),children:[n.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",D,"; nothing here needs you now, but you can act on one early."]}),n.jsx("ul",{className:"al-list al-list-sheet",children:P.groups.map(O=>n.jsx(Yk,{group:O,agentName:k(O.agentId),recap:!0,onAct:(M,W)=>{W.kind!=="fill"&&b(!1),z(M,W)},onStop:M=>{R(M)}},O.id))})]}):null,f?n.jsx(bH,{action:f,onClose:()=>m(null),onSaved:O=>{m(null),b(!1),C({title:`Saved ${O}`}),l()}}):null,p?n.jsx(un,{title:p.label,onClose:()=>g(null),foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),n.jsx(T,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const O=p;g(null),U(O)},children:p.label})]}),children:n.jsx("p",{children:p.confirm})}):null,u?n.jsx(Hd,{title:u.title,...u.body?{body:u.body}:{},duration:vH,...u.undo?{onUndo:()=>{const O=u.undo;S(async()=>{await O()})}}:{},onGone:()=>d(null)},u.id):null]})}function wH(e,t,s=Date.now()){if(!e)return"the weekly recap";const r=new Date(e);return Number.isNaN(r.getTime())||r.getTime()-s>7*864e5?"the weekly recap":`${new Intl.DateTimeFormat("en",{weekday:"long",timeZone:t}).format(r)}’s recap`}function yH(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Cu(e,t){return e.kind==="ask"?e.label??(t?`Ask ${t}`:"Ask about it"):e.label}function Yk({group:e,agentName:t,recap:s,onAct:r,onNotNow:i,onStop:a}){const[l,o]=h.useState(!1),[c,u,...d]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return n.jsxs("li",{className:"al-row","data-urgent":e.urgent&&!s?"true":void 0,children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:e.title}),e.line?n.jsx("p",{className:"al-line",children:e.line}):null,n.jsxs("p",{className:"al-sub",children:[t?n.jsx("span",{children:t}):null,t&&!s?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,s?null:n.jsxs("span",{children:["noticed ",De(e.since)]}),m?n.jsxs(n.Fragment,{children:[t||!s?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,n.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(p=>!p),children:l?"Hide":`Show the ${e.items.length}`})]}):null]}),l&&m?n.jsx("ul",{className:"al-items",children:e.items.map(p=>n.jsxs("li",{className:"al-item",children:[p.subject?n.jsx("span",{className:"al-item-who",children:p.subject.label}):null,n.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?n.jsx("span",{className:"al-item-actions",children:p.actions.map((g,x)=>n.jsx(T,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:Cu(g,t)},x))}):null]},p.key))}):null]}),n.jsxs("div",{className:"al-actions",children:[c?n.jsx(T,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Cu(c,t)}):null,u?n.jsx(T,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Cu(u,t)}):null,i?n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>i(e),children:"Not now"}):null,n.jsx("span",{className:"al-more",children:n.jsx(Al,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...d.map(p=>({label:Cu(p,t),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!f&&{label:t?`Ask ${t}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>a(e)}]})})]})]})}function bH({action:e,onClose:t,onSaved:s}){const r=e.fields.length===1,[i,a]=h.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=h.useState({}),[c,u]=h.useState(!1),[d,f]=h.useState(null),m=async()=>{const p=e.fields.filter(g=>(i[g.key]??"").trim()!=="").map(g=>({key:g.key,action:g.index,value:(i[g.key]??"").trim()}));if(p.length===0){t();return}u(!0),f(null);try{const{results:g}=await E.actOnAlerts(p),x=Object.fromEntries(g.filter(b=>b.error).map(b=>[b.key,b.error]));o(x),Object.keys(x).length===0&&s(p.length)}catch(g){f(g instanceof Error?g.message:String(g))}finally{u(!1)}};return n.jsx(ft,{title:e.title,onClose:t,foot:n.jsxs("div",{className:"al-form-foot",children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"al-form",children:[n.jsx(le,{message:d}),n.jsx("p",{className:"al-form-note",children:r?"Check it and save.":"Type what each is today. Leave the ones you don’t know; they stay as they are."}),n.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>n.jsxs("label",{className:"al-form-row",children:[n.jsxs("span",{className:"al-form-label",children:[n.jsx("span",{children:p.label}),p.hint?n.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),n.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:i[p.key]??"",placeholder:"—","aria-label":p.label,onChange:g=>a(x=>({...x,[p.key]:g.target.value}))}),l[p.key]?n.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function kH({mutes:e,onChanged:t}){const[s,r]=h.useState(null);return e.length===0?null:n.jsxs(Qe,{flush:!0,title:"Silenced",tool:String(e.length),children:[n.jsx(le,{message:s}),n.jsx("ul",{className:"al-list",children:e.map(i=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title al-silenced-label",children:i.label}),n.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",De(i.createdAt)]})]}),n.jsx("div",{className:"al-actions",children:n.jsx(T,{size:"sm",onClick:()=>{r(null),E.unmuteAlert(i.id).then(t,a=>r(a instanceof Error?a.message:String(a)))},children:"Tell me again"})})]},i.id))})]})}const qk=5e3,Qk=50;function NH({timezone:e,embedded:t}){var j;const[s,r]=h.useState(""),[i,a]=h.useState(""),[l,o]=h.useState(null),c=ce(()=>E.eventKinds(),[]),{data:u,error:d}=ce(()=>E.events({kind:s||void 0,q:i||void 0,limit:Qk}),[s,i],qk),[f,m]=h.useState({events:[],cursor:null,busy:!1,error:null});h.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(v=>({...v,busy:!0,error:null}));try{const v=await E.events({kind:s||void 0,q:i||void 0,before:p,limit:Qk});m(w=>({events:[...w.events,...v.events],cursor:v.nextCursor,busy:!1,error:null}))}catch(v){m(w=>({...w,busy:!1,error:v instanceof Error?v.message:String(v)}))}}},x=new Set(((u==null?void 0:u.events)??[]).map(v=>v.id)),b=[...(u==null?void 0:u.events)??[],...f.events.filter(v=>!x.has(v.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(ae,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(v=>n.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:v=>a(v.target.value),size:28}),s||i?n.jsx(T,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",qk/1e3,"s"]})]}),n.jsx(le,{message:d}),n.jsx(Qe,{flush:!0,children:!u||b.length===0?n.jsx(xe,{children:"No events match."}):n.jsxs(js,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(v=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[n.jsx("td",{className:"mono muted",children:v.id}),n.jsxs("td",{className:"nowrap",children:[nt(v.createdAt,e),n.jsx("div",{className:"sub",children:De(v.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:v.kind}),n.jsx("td",{className:"mono muted",children:Os(Jn(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||f.error?n.jsxs(ae,{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(ft,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",nt(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx(It,{children:Jn(l.payload)})]}):null]})}const Xk=["pending","leased","suspended","failed","succeeded","cancelled"],ro=50,SH=1e4,CH=(e,t,s=`${t}s`)=>e===1?t:s;function EH({timezone:e,embedded:t,initialState:s}){var L,q;const[r,i]=h.useState(s??""),[a,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(!1),p=r==="failed",{data:g,error:x,reload:b}=ce(()=>E.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(ro)}),[r],1e4),j=ce(()=>E.jobFailures(),[],1e4),[v,w]=h.useState({jobs:[],done:!1,busy:!1});h.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const y=async()=>{w(B=>({...B,busy:!0}));try{const B=await E.jobs({...r?{state:r}:{dismissed:"0"},limit:String(ro),offset:String(ro+v.jobs.length)});w(V=>({jobs:[...V.jobs,...B.jobs],done:B.jobs.length<ro,busy:!1}))}catch(B){c(B instanceof Error?B.message:String(B)),w(V=>({...V,busy:!1}))}},N=new Set(((g==null?void 0:g.jobs)??[]).map(B=>B.id)),k=[...(g==null?void 0:g.jobs)??[],...v.jobs.filter(B=>!N.has(B.id))],S=(g==null?void 0:g.counts)??{},C=r?S[r]??0:Xk.reduce((B,V)=>B+(S[V]??0),0),$=!v.done&&k.length<C&&((g==null?void 0:g.jobs.length)??0)>=ro,R=((L=j.data)==null?void 0:L.open)??[],I=((q=j.data)==null?void 0:q.dismissed)??[],U=R.reduce((B,V)=>B+V.count,0),z=I.reduce((B,V)=>B+V.count,0),A=()=>{b(),j.reload()},P=B=>d({...B,id:Date.now()}),D=async B=>{c(null);try{await B()}catch(V){c(V instanceof Error?V.message:String(V))}finally{A()}},O=async B=>{await D(async()=>{await B,l(null)})},M=B=>D(async()=>{const{ids:V}=await E.dismissJobs(B==="all"?{all:!0}:{ids:B});V.length!==0&&P({title:`Dismissed ${V.length===1?"it":V.length}`,body:"Kept under Dismissed, below.",undo:()=>E.undismissJobs(V)})}),W=(B,V)=>D(async()=>{const{jobs:F}=await E.retryJobs({ids:B});if(F.length===0)return;const X=F.length===1;P({title:`Retrying ${X?"it":F.length}`,body:V?`${X?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${X?"it":"them"} hasn’t changed, ${X?"it":"they"} will fail the same way.`})});return n.jsxs(An,{embedded:t,title:"Jobs",lede:`${g!=null&&g.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:g!=null&&g.paused?"accent":void 0,onClick:()=>O(E.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[n.jsx(le,{message:x??j.error??o}),R.length>0?n.jsxs(Qe,{flush:!0,title:"Gave up",tool:String(U),actions:U>1?n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>void M("all"),children:"Dismiss all"}):void 0,children:[n.jsx("ul",{className:"al-list",children:R.map(B=>n.jsx(Zk,{group:B,timezone:e,onOpen:l,onRetry:V=>void W(V,B.likelyFixed),onDismiss:V=>void M(V)},B.key))}),n.jsx("p",{className:"al-recap",children:n.jsx("span",{children:"These will not run again on their own. Dismissed jobs stay on record; any failed job older than 14 days is dismissed for you."})})]}):p&&j.data?n.jsx(Qe,{flush:!0,children:n.jsxs("div",{className:"al-empty",children:[n.jsx(ue,{name:"check"}),n.jsxs("div",{children:[n.jsx("p",{className:"al-empty-title",children:"No failed job needs you."}),n.jsx("p",{className:"al-empty-line",children:z>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,z>0||p?n.jsxs("p",{className:"al-quiet jb-quiet",children:[z>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(B=>!B),children:[z," dismissed"]}):null,z>0&&p?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,p?n.jsx("button",{type:"button",className:"wb-link",onClick:()=>i(""),children:"Show the whole queue"}):null]}):null,f&&I.length>0?n.jsx(Qe,{flush:!0,title:"Dismissed",children:n.jsx("ul",{className:"al-list",children:I.map(B=>n.jsx(Zk,{group:B,timezone:e,dismissed:!0,onOpen:l,onRetry:V=>void W(V,B.likelyFixed)},B.key))})}):null,p?null:n.jsx(Qe,{flush:!0,title:"Queue",actions:n.jsxs("select",{"aria-label":"Job state",value:r,onChange:B=>i(B.target.value),children:[n.jsx("option",{value:"",children:"every state"}),Xk.map(B=>n.jsxs("option",{value:B,children:[B," (",S[B]??0,")"]},B))]}),children:!g||k.length===0?n.jsx(xe,{children:"No jobs match."}):n.jsxs(js,{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:k.map(B=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(B),children:[B.kind,n.jsx("div",{className:"sub mono",children:Xo(B.id)})]}),n.jsxs("td",{children:[n.jsx(Rc,{state:B.state}),B.suspendedReason?n.jsx("div",{className:"sub",children:Os(B.suspendedReason,40)}):null,B.acknowledgedAt?n.jsx("div",{className:"sub",children:"dismissed"}):null]}),n.jsxs("td",{className:"num",children:[B.attempts,"/",B.maxAttempts]}),n.jsx("td",{className:B.lastError?"critical":"muted",children:B.lastError?Os(B.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[nt(B.updatedAt,e),n.jsx("div",{className:"sub",children:De(B.updatedAt)})]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[["failed","cancelled","suspended"].includes(B.state)?n.jsx(T,{size:"sm",onClick:()=>O(E.retryJob(B.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(B.state)?n.jsx(T,{size:"sm",variant:"danger",onClick:()=>O(E.cancelJob(B.id)),children:"Cancel"}):null]})})]},B.id))})]})}),$&&!p?n.jsxs(ae,{children:[n.jsxs("span",{className:"muted",children:[k.length," of ",C," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(T,{disabled:v.busy,onClick:()=>void y(),children:v.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(ft,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),a.lastError?n.jsx(oe,{title:"Last error",children:n.jsx(It,{children:a.lastError})}):null,n.jsx(oe,{title:"Payload",children:n.jsx(It,{children:Jn(a.payload)})}),n.jsx(oe,{title:"Result",children:n.jsx(It,{children:Jn(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null,u?n.jsx(Hd,{title:u.title,...u.body?{body:u.body}:{},duration:SH,...u.undo?{onUndo:()=>{const B=u.undo;D(async()=>{await B()})}}:{},onGone:()=>d(null)},u.id):null]})}function Jk(e){var s;if(e.missionName)return e.missionName;const t=(s=e.job.payload)==null?void 0:s.prompt;return typeof t=="string"&&t.trim()!==""?Os(t.trim().split(`
109
+ `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function Zk({group:e,timezone:t,dismissed:s,onOpen:r,onRetry:i,onDismiss:a}){var g;const[l,o]=h.useState(!1),c=e.jobs.length>1,u=e.jobs.map(x=>x.job.id),d=e.agents.map(x=>x.name??x.id),f=e.jobs[0],m=e.jobs.every(x=>x.job.acknowledgedBy==="auto"),p=s?m?"dismissed on its own after 14 days":`dismissed ${De(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${De(e.lastAt)}`;return n.jsxs("li",{className:"al-row","data-urgent":s?void 0:"true",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:c?`${e.label} · ${e.count}`:e.label}),s?null:n.jsx("p",{className:"al-line",children:e.reason}),n.jsxs("p",{className:"al-sub",children:[d.length>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:d.join(", ")}),n.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,!c&&f?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(f.job),children:Jk(f)}),n.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,n.jsx("span",{title:nt(e.lastAt,t),children:p}),c?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(x=>!x),children:l?"Hide":`Show the ${e.count}`})]}):null]}),l&&c?n.jsx("ul",{className:"al-items",children:e.jobs.map(x=>n.jsxs("li",{className:"al-item jb-item",children:[x.agentName||x.agentId?n.jsx("span",{className:"al-item-who",children:x.agentName??x.agentId}):null,n.jsxs("span",{className:"al-item-note",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(x.job),children:Jk(x)})," · ",Rv(new Date(x.job.updatedAt),t)," · tried ",x.job.attempts," ",CH(x.job.attempts,"time")]}),n.jsxs("span",{className:"jb-item-acts",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([x.job.id]),children:"Retry"}),a?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("button",{type:"button",className:"wb-link",onClick:()=>a([x.job.id]),children:"Dismiss"})]}):null]})]},x.job.id))}):null]}),n.jsxs("div",{className:"al-actions",children:[n.jsx(T,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>i(u),children:c?"Retry all":"Retry"}),a?n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>a(u),children:"Dismiss"}):null]})]})}const AH=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function TH({hash:e,timezone:t,navigate:s,agents:r}){var u,d;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(IH,{id:f,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(d=/[?&]state=([a-z]+)/.exec(e))==null?void 0:d[1],c=f=>m=>{m.preventDefault(),s(f)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(rc,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(DH,{})}),n.jsx(OH,{}),n.jsx($c,{children:AH.map(f=>{const m=f.id==="conversations"?xt:`${xt}/${f.id}`;return n.jsx(cl,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?n.jsx(RH,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(EH,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx($H,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(jH,{timezone:t,embedded:!0,agents:r,navigate:s}):null,l==="events"?n.jsx(NH,{timezone:t,embedded:!0}):null]})}function RH({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=ce(()=>E.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(le,{message:a}),n.jsx(Qe,{flush:!0,children:i?i.conversations.length===0?n.jsx(jn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(ht,{children:i.conversations.map(l=>n.jsx(st,{href:ll(l.id),onClick:()=>t(ll(l.id)),lead:n.jsx(ln,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Os(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${lO(l.usage)}`,side:n.jsx("span",{title:nt(l.lastMessageAt??l.createdAt,e),children:De(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(xe,{children:"Loading…"})})]})}function $H({timezone:e,nameOf:t}){const{data:s,error:r}=ce(()=>E.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(le,{message:r}),n.jsx(Qe,{flush:!0,children:s?i.length===0?n.jsx(jn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(js,{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:Xo(a.id)})]}),n.jsx("td",{children:n.jsx(Rc,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[nt(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[nt(a.createdAt,e),n.jsx("div",{className:"sub",children:De(a.createdAt)})]})]},a.id))})]}):n.jsx(xe,{children:"Loading…"})})]})}function IH({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=h.useState(null),[l,o]=h.useState(null);h.useEffect(()=>{let u=!1;return E.conversation(e).then(d=>{u||a(d)}).catch(d=>{u||o(d instanceof Error?d.message:String(d))}),()=>{u=!0}},[e]);const c=u=>d=>{d.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(Nt,{size:"sm",href:tt(i.agentId,e),onClick:c(tt(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(le,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(Xh,{children:[n.jsx(tr,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(tr,{label:"Runs",value:i.runs.length}),n.jsx(tr,{label:"Tokens",value:`${Vt(i.usage.input)} / ${Vt(i.usage.output)}`,note:qp(i.usage)?`input / output, ${qp(i.usage)}`:"input / output"}),n.jsx(tr,{label:"Started",value:nt(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(Qe,{title:"Runs",flush:!0,children:n.jsxs(js,{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,d)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(u.startedAt,t)," ",u.resumed?n.jsx(ve,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:nt(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 ",Xo(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)):"—"})]},d))})]})}):null,n.jsx(oe,{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===e0?"approved action, result":u.role,", ",nt(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===e0?u.blocks.map((d,f)=>n.jsx(PH,{block:d},f)):u.blocks.map((d,f)=>n.jsx(MH,{block:d},f))]})]},u.id))})})]}):n.jsx(xe,{children:"Loading…"})]})}const e0="approval:resume";function PH({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(It,{children:e.type==="text"?e.text??"":Jn(e)})]})}function MH({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(Lr,{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(Lr,{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(It,{children:Jn(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(It,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(It,{children:Jn(e.ref)})]})}function DH(){const{data:e,reload:t}=ce(()=>E.overview(),[],1e4),[s,r]=h.useState(!1);if(!e)return null;const i=()=>{r(!0),E.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 OH(){const{data:e,reload:t}=ce(()=>E.overview(),[],1e4);if(h.useEffect(()=>(window.addEventListener(Bi,t),()=>window.removeEventListener(Bi,t)),[t]),!e)return null;const s=i=>e.jobs[i]??0,r=s("leased");return n.jsxs(Xh,{children:[n.jsx(tr,{label:"Jobs done",value:Vt(s("succeeded"))}),n.jsx(tr,{label:"Failed",value:Vt(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),n.jsx(tr,{label:"Queued",value:Vt(s("pending")),note:`${r} running`}),n.jsx(tr,{label:"Approvals",value:Vt(e.approvals.pending),note:"waiting for you"})]})}const LH=["replay-all","coalesce","latest-only","skip-after-deadline"];function jT({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ce(()=>E.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(d=>!s||d.agentId===s),[o,c]=h.useState(null),u=async d=>{c(null);try{await d,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(le,{message:i??o}),!r||l.length===0?n.jsxs(jn,{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(d=>n.jsx(_H,{mission:d,timezone:e,onRun:u},d.id))})]})}function _H({mission:e,timezone:t,onRun:s}){const[r,i]=h.useState(!1);return n.jsxs(ys,{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(E.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.timezoneExplicit===!1?n.jsx("span",{title:e.schedule.timezone,children:"follows your timezone"}):e.schedule.timezone," ","· rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${nt(e.nextRun,t)} (${De(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"} ${De(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(ae,{children:[n.jsx(ie,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(E.setMisfirePolicy(e.id,a.target.value)),children:LH.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(oe,{title:"Prompt",children:n.jsx(It,{children:e.prompt})}),n.jsx(oe,{title:"Recent occurrences",children:n.jsx(Qe,{flush:!0,children:e.occurrences.length===0?n.jsx(xe,{children:"Never run."}):n.jsxs(js,{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:nt(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(Rc,{state:a.state})}),n.jsx("td",{className:"nowrap",children:nt(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Os(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function FH(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 wT({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=h.useState(!1),[l,o]=h.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:FH(r,t)}),n.jsx(T,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),E.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 yT({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=ce(()=>E.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,d]=h.useState(null),[f,m]=h.useState(null),[p,g]=h.useState(null),x=async(j,v)=>{d(null),m(j);try{const w=await E.takeOffer(j);g(w.jobId?`On it — ${v}. Started as job ${w.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),a()}catch(w){d(w instanceof Error?w.message:String(w))}finally{m(null)}},b=async(j,v)=>{d(null),m(j);try{await E.dismissOffer(j),g(`Dismissed — ${v}. It will not come back.`),a()}catch(w){d(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(le,{message:i??u}),p?n.jsx(G,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(ae,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(wT,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx(jn,{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(ys,{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 ",De(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 x(j.id,j.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?n.jsxs(yt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(Qe,{flush:!0,children:n.jsx(ht,{children:c.map(j=>n.jsx(st,{title:j.label,sub:`${j.agentId} — ${dO(j)}`,side:De(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 zH="Add a teammate",UH="Each one keeps its own memory and tools, and can work on a schedule. Add the ones you want; Agent Father can make others.",BH="front-desk";function bT(e,t){return e.length>0&&e.every(s=>s.id===t||s.roles.includes(BH)||s.roles.includes(Hh))}const WH={plugins:{label:"Plugins",route:Oe("plugins")},mailbox:{label:"Add a mailbox",route:gi("email","settings")},accounts:{label:"Accounts",route:Oe("accounts")}},HH="Your starter team is complete. Agent Father can make others.";function Jg({navigate:e,standing:t=!1}){var d;const s=ce(()=>E.teammates(),[]),[r,i]=h.useState(new Set),a=(((d=s.data)==null?void 0:d.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}`)),E.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(oe,{title:zH,children:c.length===0?n.jsx("p",{className:"teammates-lede","data-testid":"teammates-complete",children:HH}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"teammates-lede",children:UH}),n.jsx("div",{className:"teammates-grid","data-testid":"teammates",children:c.map(f=>n.jsx(KH,{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:Et(f.agent),onClick:o(Et(f.agent)),children:["Added · open @",f.handle]})},`${f.plugin}/${f.agent}`))}):null]})})}function KH({row:e,navigate:t,onDismiss:s}){const r=kj(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?WH[e.fix]:null;return n.jsx("div",{className:"teammate","data-state":l,"data-testid":`teammate-${e.agent}`,children:n.jsxs(ys,{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(ue,{name:"close"})}),foot:n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[l==="unavailable"?n.jsx("span",{className:"teammate-reason",children:e.reason}):null,n.jsx(Dt,{}),a?n.jsxs("a",{href:Et(a.id),onClick:i(Et(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(le,{message:r.failure})]}),children:[n.jsx("p",{className:"ui-card-meta",children:e.text}),n.jsx("p",{className:"teammate-needs",children:e.needs})]})})}const VH=["fact","observation","todo"];function kT({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=ce(()=>E.memory(r),[r],3e4),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(null),p=y=>{var N;return y==="shared"?"Everyone":((N=t.find(k=>k.id===y))==null?void 0:N.name)??y},g=async y=>{m(null);try{await y,l()}catch(N){m(N instanceof pe?N.message:String(N))}},x={nameOf:p,timezone:s,onChangePreference:y=>c({key:y.key,scope:y.scope}),onForgetPreference:y=>void g(E.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>d(y),onForgetNote:y=>void g(E.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,v=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(le,{message:a??f}),j&&v?n.jsxs(se,{gap:"lg",children:[n.jsx(oe,{title:"Preferences",aside:`what you told ${b} alone`,actions:w,panel:!0,flush:!0,children:n.jsx(Cm,{preferences:j.preferences,empty:`Nothing stated to ${b} alone yet.`,...x})}),n.jsx(oe,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(Em,{notes:j.notes,empty:`${b} has kept no private notes yet.`,...x})}),n.jsx(yt,{summary:`Shared with every agent, which ${b} also reads · ${v.preferences.length} preferences, ${v.notes.length} notes`,children:n.jsxs(se,{gap:"lg",children:[n.jsx(oe,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(Cm,{preferences:v.preferences,empty:"No shared preferences.",...x})}),n.jsx(oe,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(Em,{notes:v.notes,empty:"No shared notes.",...x})})]})})]}):n.jsxs(se,{gap:"lg",children:[n.jsx(oe,{title:"Preferences",aside:"what you said you want, one current value each",actions:w,panel:!0,flush:!0,children:i?n.jsx(Cm,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...x}):n.jsx(xe,{children:"Loading…"})}),n.jsx(oe,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(Em,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...x}):n.jsx(xe,{children:"Loading…"})})]}),o?n.jsx(GH,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await g((async()=>{await E.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await E.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(YH,{note:u,agents:t,onClose:()=>d(null),onSave:y=>g(E.updateNote(u.id,y)).then(()=>d(null))}):null]})}function Cm({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(xe,{children:t}):n.jsxs(js,{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(NT,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?De(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{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 Em({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(xe,{children:t}):n.jsxs(js,{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(NT,{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?De(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",dr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{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 NT({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 ST({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 GH({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=h.useState(s.key),[c,u]=h.useState((a==null?void 0:a.value)??""),[d,f]=h.useState(s.scope),[m,p]=h.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),x=t.find(v=>v.key===g&&v.scope===d),b=!a||g!==a.key||c.trim()!==a.value||d!==a.scope,j=g!==""&&c.trim()!==""&&b;return n.jsx(ft,{title:"A preference",onClose:r,children:n.jsxs(se,{children:[n.jsx(G,{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(ie,{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:v=>o(v.target.value),placeholder:"reporting_currency"})}),n.jsx(ie,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>u(v.target.value),placeholder:"EUR"})}),n.jsx(ie,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(ST,{value:d,agents:e,onChange:f})}),x&&x!==a?n.jsxs(G,{tone:"warning",children:['This replaces the value already stored for this key here, "',x.value,'" (revision ',x.revision,")."]}):null,a&&d!==a.scope?n.jsxs(G,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(ae,{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:d}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function YH({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=h.useState(e.content),[l,o]=h.useState(e.scope),[c,u]=h.useState(e.kind),[d,f]=h.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(ft,{title:"A note",onClose:s,children:n.jsxs(se,{children:[n.jsx(ie,{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(Ls,{children:[n.jsx(ie,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:VH.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(ie,{label:"Who sees it",children:n.jsx(ST,{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?`, ${De(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:s,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!m||i.trim()===""||d,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 qH({agentId:e,agentName:t}){const{data:s,error:r,reload:i}=ce(()=>E.agentSkills(e),[e],3e4),[a,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null),f=async g=>{l(null),c(null),d(g.name);try{const x=await E.removeSkill(e,g.name);c(`Removed ${x.name}. Its versions are kept, and ${t} will not propose it again for 90 days.`),i()}catch(x){l(x instanceof pe?x.message:String(x))}finally{d(null)}};if(!s)return r?n.jsx(le,{message:r}):n.jsx(xe,{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(le,{message:r??a}),o?n.jsx(G,{tone:"good",role:"status",children:o}):null,n.jsx(oe,{title:"Learned",aside:n.jsxs("span",{className:"muted",children:["what ",t," proposed and you kept"]}),children:m.length===0?n.jsx(jn,{icon:"bulb",title:"Nothing learned yet",children:s.writable?`When ${t} proposes a procedure and you keep it on Settings → Proposals, it appears here.`:`${t} ships with buddi, so it keeps no learned skills of its own until it is yours.`}):n.jsx(Qe,{flush:!0,children:n.jsxs(js,{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(XH,{skill:g,busy:u===g.name,onRemove:()=>void f(g)},g.name))})]})})}),n.jsx(oe,{title:"From files and plugins",aside:n.jsx("span",{className:"muted",children:"read-only here"}),children:p.length===0?n.jsx(xe,{children:"No other skills."}):n.jsx(Qe,{flush:!0,children:n.jsxs(js,{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(yt,{summary:n.jsx("span",{className:"mono",children:g.name}),children:[n.jsx(It,{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:QH(g)})]})})]},`${g.scope}:${g.name}`))})]})})})]})}function QH(e){return e.provenance==="imported"?e.source?`from ${e.source}`:"imported":e.provenance==="agent"?"written by an agent":"yours"}function XH({skill:e,busy:t,onRemove:s}){const r=e.learned;return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(yt,{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(It,{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:ll(r.conversation),children:r.turn?`conversation, turn ${r.turn}`:"conversation"}):n.jsx("span",{className:"muted",children:"no conversation"}),n.jsx("a",{href:Oe("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?De(r.keptAt,Date.now()):""}),n.jsx("td",{className:"num",children:n.jsx(ae,{align:"end",children:n.jsx(T,{size:"sm",variant:"ghost",disabled:t,onClick:s,children:"Remove"})})})]})}function CT({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ce(()=>E.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(d=>!s||d.agentId===s),[o,c]=h.useState(null),u=async d=>{c(null);try{await E.cancelReminder(d),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(le,{message:i??o}),n.jsx(Qe,{flush:!0,children:r?l.length===0?n.jsx(jn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(js,{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(d=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(d.dueAt,e),n.jsx("div",{className:"sub",children:De(d.dueAt)})]}),n.jsx("td",{className:"mono",children:d.agentId}),n.jsxs("td",{children:[d.text,d.context?n.jsx(yt,{summary:"context",children:n.jsx(It,{children:Jn(d.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Rc,{state:d.state}),d.cancelReason?n.jsx("div",{className:"sub",children:d.cancelReason}):null]}),n.jsx("td",{children:d.state==="pending"?n.jsx(T,{size:"sm",variant:"danger",onClick:()=>u(d.id),children:"Cancel"}):null})]},d.id))})]}):n.jsx(xe,{children:"Loading…"})})]})}const JH=/(flux|klein|schnell|qwen[-_]?image|image)/i;function ET(e){return e.kind==="image"||e.kind===void 0&&JH.test(e.id)}function ZH(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!ET(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Zg(e){return ZH(e)[0]}function Fj(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function eK(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 AT(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 TT="an image model; pick it in the Image plugin, not here";function zj({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(!1),p=h.useRef(0),g=async v=>{if(!e)return;const w=++p.current;c(!0),d("");try{const y=await E.accountModels(e,v);w===p.current&&l(y)}catch(y){w===p.current&&d(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(h.useEffect(()=>(l(null),m(!1),d(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(ie,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const x=(a==null?void 0:a.models)??[],b=!!s&&!x.some(v=>v.id===s),j=[a&&!x.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(ie,{label:t,children:n.jsxs("select",{value:f?"__buddi_custom__":s,disabled:i,onChange:v=>{v.target.value==="__buddi_custom__"?m(!0):(m(!1),r(v.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),x.map(v=>n.jsxs("option",{value:v.id,children:[v.name===v.id?v.id:`${v.name} — ${v.id}`,v.isDefault?" (provider default)":"",v.image?` — ${TT}`:""]},v.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(ie,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function tK(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 nK(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const sK="This agent will not remember anything between conversations.";function rK({view:e,chosen:t,onChange:s,disabled:r}){var N;const[i,a]=h.useState(""),[l,o]=h.useState(null),[c,u]=h.useState(()=>new Set),d=k=>u(S=>{const C=new Set(S);return C.has(k)?C.delete(k):C.add(k),C}),f=k=>{a(k),u(new Set)},m=h.useId(),p=new Set(t),g=new Set(e.groups.flatMap(k=>k.tools.filter(S=>S.core).map(S=>S.name))),x=(k,S)=>{const C=S.filter($=>p.has($));if(C.length!==0){if(C.some($=>g.has($))){o({plugin:k,names:C});return}s(t.filter($=>!C.includes($)))}},b=k=>{s([...t,...k.filter(S=>!p.has(S))])},j=i.trim().toLowerCase(),v=(k,S)=>j===""||k.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(k=>({group:k,tools:k.tools.filter(S=>v(S.name,S.description))})).filter(k=>k.tools.length>0),y=(((N=e.suggested)==null?void 0:N.tools)??[]).filter(k=>!p.has(k.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(k=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:k.name}),n.jsx("span",{className:"ui-list-sub",children:k.description})]}),n.jsx(T,{size:"sm",disabled:r,"aria-label":`Add ${k.name}`,onClick:()=>b([k.name]),children:"Add"})]},k.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:k=>f(k.target.value)})]}),w.length===0?n.jsxs(xe,{children:["No installed tool matches “",i.trim(),"”."]}):null,w.map(({group:k,tools:S})=>{const C=k.tools.filter(A=>A.grantable).map(A=>A.name),$=k.tools.filter(A=>p.has(A.name)).length,R=!!k.glob&&$===k.tools.length,I=`${m}-${k.plugin}`,U=`${m}-${k.plugin}-list`,z=j!==""?!c.has(k.plugin):c.has(k.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":z?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":z,"aria-controls":U,onClick:()=>d(k.plugin),children:[n.jsx(iK,{}),n.jsx("span",{id:I,className:"tool-picker-plugin",children:k.plugin}),n.jsx("span",{className:"muted",children:R?`all ${k.tools.length}`:`${$} of ${k.tools.length} granted`})]}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":`All ${k.plugin} tools`,disabled:r||C.every(A=>p.has(A)),onClick:()=>b(C),children:"all"}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":`No ${k.plugin} tools`,disabled:r||!C.some(A=>p.has(A)),onClick:()=>x(k.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===k.plugin?n.jsx(G,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:sK}),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(A=>!l.names.includes(A))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:U,className:"ui-list tool-picker-list",hidden:!z,children:S.map(A=>{const P=`${m}-${A.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:P,checked:p.has(A.name),disabled:r||!A.grantable,onChange:D=>D.target.checked?b([A.name]):x(k.plugin,[A.name])}),n.jsxs("label",{htmlFor:P,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:A.name}),A.core?n.jsx(ve,{tone:"accent",children:"core"}):null,A.gated?n.jsx(ve,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:A.grantable?A.description:`${A.description} Granted only by editing the file by hand.`})]})]},A.name)})})]},k.plugin)})]})}function iK(){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 os={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."},Jr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function RT(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(os.json)}if(!Jr(t))throw new Error(os.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!Jr(u))throw new Error(os.empty);const d=Object.keys(u);if(d.length===0)throw new Error(os.empty);if(d.length>1)throw new Error(`It names ${d.length} servers (${d.join(", ")}). Paste one at a time.`);s=d[0];const f=u[s];if(!Jr(f))throw new Error(os.url);r=f}if("command"in r)throw new Error(os.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(os.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(os.url);const a=Jr(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,d]=l,f=/^(Bearer|Basic)\s+/i.exec(d.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?d.trim().slice(f[0].length).trim():d.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 No={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 $T(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const IT=/^[A-Za-z_][A-Za-z0-9_]*$/;function aK(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function PT(e,t){const s=aK(t);return{name:e,value:s?"":t,secret:$T(e),placeholder:s}}function MT(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!==`
110
+ `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
111
+ `||o==="\r"&&e[a+1]===`
112
+ `){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(No.quote);return r&&t.push(s),t}function lK(e){const t=MT(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=d=>{const f=d.indexOf("="),m=f>0?d.slice(0,f).trim():"";if(!IT.test(m))throw new Error(No.env);r.push(PT(m,d.slice(f+1)))},u=[];for(;s<t.length;s+=1){const d=t[s];if(d==="--"){o=t.slice(s+1);break}const[f,m]=d.startsWith("--")&&d.includes("=")?[d.slice(0,d.indexOf("=")),d.slice(d.indexOf("=")+1)]:[d,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(No.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=d;continue}u.push(d)}}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 d=o[0];if(!d)throw new Error(os.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:RT(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:d,headers:f}}}))}}if(!l||o.length===0)throw new Error(No.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function oK(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return lK(t);let s;try{s=JSON.parse(t)}catch{throw new Error(os.json)}if(!Jr(s))throw new Error(os.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!Jr(c))throw new Error(os.empty);const u=Object.keys(c);u.length===1&&Jr(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:RT(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(No.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=Jr(i.env)?Object.entries(i.env).filter(([c])=>IT.test(c)).map(([c,u])=>PT(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function Uj({code:e,label:t="Your code",large:s=!1}){const[r,i]=h.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(ae,{valign:"end",children:[n.jsx(ie,{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 DT(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 cK="It can delete or destroy something, so it asks you every time and is never remembered.";function uK(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 OT="buddi-connections",dK="/connections/callback",hK="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.",LT="Services and programs your team can use, and the tools each one brings.",Bj=(e,t,s)=>`${e} ${e===1?t:s}`;function t0(e,t){return e.transport==="stdio"?void 0:t.find(s=>Hj(s.url,e.url))}function Wj({connection:e,card:t,size:s}){return t?n.jsx(_r,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(_r,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function _T({connection:e}){const t=DT(e);return n.jsx(ve,{tone:t.tone,dot:t.dot,children:t.label})}const Am=e=>t=>{t.stopPropagation(),e()},Zu=[{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"}],FT="buddi.connections.add-way";function fK(){try{const e=window.localStorage.getItem(FT);return Zu.some(t=>t.value===e)?e:"address"}catch{return"address"}}function mK({embedded:e,timezone:t,connection:s}={}){const r=ce(()=>E.connections(),[],3e4),[i,a]=h.useState(null),[l,o]=h.useState(s??null);h.useEffect(()=>{s&&o(s)},[s]);const[c,u]=h.useState(null),[d,f]=h.useState(null),m=r.data,p=k=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===k))==null?void 0:S.name)??k},g=t??Intl.DateTimeFormat().resolvedOptions().timeZone,x=(m==null?void 0:m.connections)??[],b=(m==null?void 0:m.catalog)??[],j=b.filter(k=>!x.some(S=>S.transport!=="stdio"&&Hj(k.url,S.url))),v=l?x.find(k=>k.id===l):void 0,w=c?x.find(k=>k.id===c):void 0,y=d?x.find(k=>k.id===d):void 0,N=k=>{o(null),a(k)};return n.jsxs(An,{embedded:e,title:"Connections",lede:LT,children:[n.jsxs(se,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ue,{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:Oe("plugins"),children:"Plugins"})]})]}),!m&&!r.error?n.jsx(xe,{children:"Reading your connections…"}):null,n.jsx(le,{message:r.error}),m&&!m.vault?n.jsx(G,{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(Qe,{flush:!0,title:"Your connections",tool:x.length>0?Bj(x.length,"connection","connections"):void 0,children:x.length===0?n.jsx(xe,{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(ht,{children:x.map(k=>n.jsx(pK,{connection:k,card:t0(k,b),twin:k.slug!==null&&x.some(S=>S.id!==k.id&&S.name===k.name),onOpen:()=>o(k.id),onFlow:N},k.id))})})}):null,m&&j.length>0?n.jsx(Qe,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:j.map(k=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(Wj,{card:k}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:k.name}),n.jsx("span",{className:"connections-tile-blurb",children:k.blurb})]}),n.jsx(T,{size:"sm",onClick:()=>N({step:"address",card:k}),"aria-label":`Connect ${k.name}`,children:"Connect"})]},k.id))})}):null,m?n.jsx(wK,{onFlow:k=>N({step:k})}):null]}),v?n.jsx(xK,{connection:v,card:t0(v,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:N,onDisconnect:()=>u(v.id),onHolders:()=>f(v.id)}):null,y&&m?n.jsx(vK,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?n.jsx(jK,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,i&&m?n.jsx(yK,{start:i,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{a(null),r.reload()}}):null]})}function pK({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":Bj(e.toolCount,"tool","tools");return n.jsx(st,{onClick:r,label:`${l}: details`,lead:n.jsx(Wj,{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:Am(()=>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:Am(()=>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:Am(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(_T,{connection:e}),n.jsx(ue,{name:"chevron-right",size:14})]})})}const gK={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 xK({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,d=()=>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(ft,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Wj,{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(_T,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(ae,{children:[n.jsx(T,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(Dt,{}),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:d,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(G,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(G,{tone:"warning",action:e.authKind!=="none"?n.jsx(T,{size:"sm",variant:"accent",onClick:d,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(G,{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(G,{tone:"critical",children:u?`It stopped answering at ${nt(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${nt(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(G,{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(G,{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(Bt,{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:gK[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${Bj(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${De(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(oe,{title:"What the program last said",children:n.jsx(It,{label:"Its last lines on stderr",children:e.stderr.join(`
113
+ `)})}):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 vK({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=h.useState(()=>new Set(e.agents)),[l,o]=h.useState(!1),[c,u]=h.useState(null),d=(p,g)=>a(x=>{const b=new Set(x);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 E.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(_s(p))}finally{o(!1)}};return n.jsxs(un,{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=>d(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(le,{message:c})]})}function jK({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=h.useState(!1),[l,o]=h.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await E.disconnect(e.id),r()}catch(d){o(_s(d))}finally{a(!1)}};return n.jsxs(un,{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(le,{message:l})]})}function wK({onFlow:e}){const[t,s]=h.useState(fK),r=Zu.find(a=>a.value===t)??Zu[0],i=a=>{s(a);try{window.localStorage.setItem(FT,a)}catch{}};return n.jsx(Qe,{title:"Add your own",actions:n.jsx(sn,{label:"How to add it",options:Zu.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 yK({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=h.useState(e.step),[c,u]=h.useState(e.connection),[d,f]=h.useState("unknown"),[m,p]=h.useState(null),[g,x]=h.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(y=>b!==void 0&&Hj(y.url,b)),v=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${v}`:l==="review"?`What ${v} brings`:"Who gets these tools";return n.jsxs(ft,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(bK,{onRead:y=>{y.kind==="program"?(x(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(kK,{card:j,pasted:m,onDone:(y,N)=>{u(y),N==="none"?o("review"):(f(N),o("consent"))}}):null,l==="program"?n.jsx($K,{connection:c,pasted:g,tokens:r,onDone:y=>{var N;x(null),u(y),e.keepGrants&&!((N=y.program)!=null&&N.changedSinceReview)&&y.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(CK,{connection:c,signIn:d,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(IK,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(PK,{connection:c,agents:t,onDone:i}):null]})}function Hj(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function _s(e){return e instanceof Error?e.message:String(e)}function bK({onRead:e}){const[t,s]=h.useState(""),[r,i]=h.useState(null),a=()=>{try{const l=oK(t);s(""),i(null),e(l)}catch(l){i(_s(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(ie,{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(le,{message:r}),n.jsx(ae,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function kK({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=h.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=h.useState(!1),[o,c]=h.useState(null),u=async()=>{l(!0),c(null);try{const g=await E.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(_s(g))}finally{l(!1)}},d=((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(ie,{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."]}):d?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(le,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const NK={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function SK(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 CK({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var W,L;const[c,u]=h.useState(t),d=(W=s==null?void 0:s.auth)!=null&&W.device?s.auth.recommended==="device"?"first":"offered":"none",f=SK(c,a,d),m=r!==void 0||d!=="first"&&(e.authKind==="token"||((L=s==null?void 0:s.auth)==null?void 0:L.recommended)==="token"),[p,g]=h.useState(()=>m&&f.includes("token")?"token":f[0]),x=f.includes(p)?p:f[0],[b,j]=h.useState(hK),[v,w]=h.useState(""),[y,N]=h.useState(null),[k,S]=h.useState(!1),[C,$]=h.useState(null),[R,I]=h.useState(!1),[U,z]=h.useState(null),A=`${location.origin}${dK}`,P=h.useRef(o);P.current=o,h.useEffect(()=>{if(!R)return;let q=!1;const B=async()=>{if(!q){q=!0;try{P.current(await E.connection(e.id))}catch(Z){$(_s(Z))}}},V=typeof BroadcastChannel=="function"?new BroadcastChannel(OT):null;V&&(V.onmessage=Z=>{var he;((he=Z.data)==null?void 0:he.id)===e.id&&B()});let F;const X=Date.now(),Y=async()=>{if(!q){try{const Z=await E.connection(e.id);if((!e.signedIn||e.authKind==="token")&&Z.signedIn&&Z.authKind==="oauth"){B();return}}catch{}if(Date.now()-X>10*6e4){I(!1),$("The sign-in did not come back within ten minutes. Start it again.");return}F=window.setTimeout(()=>void Y(),l)}};return F=window.setTimeout(()=>void Y(),l),()=>{q=!0,V==null||V.close(),window.clearTimeout(F)}},[R,e,l]);const D=async q=>{var B;S(!0),$(null);try{const{authorizeUrl:V}=await E.connectionConsent(e.id,q);N(V)}catch(V){V instanceof pe&&((B=V.detail)==null?void 0:B.code)==="client-id"?(j(V.message),u("manual"),g("client")):$(_s(V))}finally{S(!1)}};h.useEffect(()=>{x!=="oauth"||y!==null||D()},[x]);const O=q=>{const B=window.open(q,"_blank");B?(B.opener=null,z(null)):z(q),I(!0)},M=q=>{g(q),N(null),$(null),I(!1),z(null)};return n.jsxs("div",{className:"ui-stack",children:[f.length>1?n.jsx(sn,{label:"How to sign in",options:f.map(q=>({value:q,label:NK[q]})),value:x,onChange:M}):null,x==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),k?n.jsxs(xe,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,x==="client"?n.jsxs(n.Fragment,{children:[n.jsx(G,{tone:"warning",children:b}),n.jsx(ie,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:q=>{w(q.target.value),N(null),I(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:A})]})]}):null,x==="token"?n.jsx(TK,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,x==="device"?n.jsx(AK,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(x==="oauth"||x==="client")&&R?n.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(x==="oauth"||x==="client")&&U?n.jsx("p",{children:n.jsxs("a",{href:U,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,x==="oauth"||x==="client"?n.jsx(le,{message:C}):null,x==="oauth"?n.jsx(ae,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>{y&&O(y)},disabled:y===null,children:R?"Open it again":`Sign in to ${e.name}`})}):null,x==="client"?n.jsx(ae,{align:"end",children:y===null?n.jsx(T,{variant:"accent",onClick:()=>void D(v.trim()),disabled:k||v.trim()==="",children:k?"Checking…":"Continue"}):n.jsx(T,{variant:"accent",onClick:()=>O(y),children:R?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function EK(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function AK({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(0),[d,f]=h.useState(null),m=h.useRef(r);m.current=r,h.useEffect(()=>{let x=!1,b;a(null),o(null),f(null);const j=async()=>{var v,w;if(!x){try{const y=await E.connection(e.id);if(x)return;if(((v=y.device)==null?void 0:v.state)==="done"){m.current(y);return}if(((w=y.device)==null?void 0:w.state)==="failed"){o(y.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void j(),s)}};return(async()=>{try{const v=await E.connectionDevice(e.id);if(x)return;a({userCode:v.userCode,verificationUri:v.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(v){x||o(_s(v))}})(),()=>{x=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=x=>{const b=window.open(x,"_blank");b?(b.opener=null,f(null)):f(x)},g=i?EK(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(xe,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(Uj,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),d?n.jsx("p",{children:n.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(ae,{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(le,{message:l}),n.jsx(ae,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>u(x=>x+1),children:"Start again"})})]}):null]})}function TK({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var j,v;const[a,l]=h.useState((s==null?void 0:s.value)??""),[o,c]=h.useState((s==null?void 0:s.name)??"Authorization"),[u,d]=h.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=h.useState(!1),[p,g]=h.useState(null),x=async()=>{m(!0),g(null);try{const w=await E.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){g(_s(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(),x()},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(G,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(ie,{label:"Token",hint:(v=t==null?void 0:t.auth)==null?void 0:v.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:w=>l(w.target.value)})}),n.jsxs(Ls,{columns:2,dense:!0,children:[n.jsx(ie,{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(ie,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:w=>d(w.target.value)})})]}),n.jsx(le,{message:p}),n.jsx(ae,{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 RK(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function $K({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=h.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=h.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,d]=h.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[f,m]=h.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(A=>({key:l(),value:A}))),[p,g]=h.useState(()=>i?i.env.map(A=>({key:l(),name:A.name,value:A.value??"",secret:A.secret,kept:A.secret})):((t==null?void 0:t.env)??[]).map(A=>({key:l(),name:A.name,value:A.value,secret:A.secret,kept:!1}))),[x,b]=h.useState(!1),[j,v]=h.useState(null),w=/\s/.test(u.trim())?MT(u.trim()):[u.trim()],y=w[0]??"",N=[...w.slice(1),...f.map(A=>A.value)],k=[y,...N].filter((A,P)=>P>0||A!==""),S=()=>{w.length<2||(d(y),m(A=>[...w.slice(1).map(P=>({key:l(),value:P})),...A]))},C=k.map(RK).join(" "),$=p.filter(A=>A.secret&&A.value===""&&!A.kept).map(A=>A.name||"a variable"),R=((t==null?void 0:t.env)??[]).filter(A=>A.placeholder).map(A=>A.name),I=(A,P)=>m(D=>D.map(O=>O.key===A?{...O,value:P}:O)),U=(A,P)=>g(D=>D.map(O=>O.key===A?{...O,...P}:O)),z=async()=>{b(!0),v(null);const A={name:o.trim(),command:y,args:N,env:p.filter(P=>P.name.trim()!=="").map(P=>({name:P.name.trim(),value:P.value,secret:P.secret}))};try{r(e?await E.updateProgram(e.id,A):(await E.addProgram(A)).connection),g(P=>P.map(D=>D.secret?{...D,value:""}:D))}catch(P){v(_s(P))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:A=>{A.preventDefault(),z()},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(Ls,{columns:2,children:[n.jsx(ie,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:A=>c(A.target.value)})}),n.jsx(ie,{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:A=>d(A.target.value),onBlur:S})})]}),n.jsx(ie,{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((A,P)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${P+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:A.value,onChange:D=>I(A.key,D.target.value)}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>m(D=>D.filter(O=>O.key!==A.key)),"aria-label":`Remove argument ${P+1}`,children:"Remove"})]},A.key)),n.jsx(ae,{children:n.jsx(T,{size:"sm",onClick:()=>m(A=>[...A,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(ie,{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((A,P)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${P+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:A.name,onChange:D=>{const O=D.target.value;U(A.key,A.value===""&&!A.kept?{name:O,secret:$T(O)}:{name:O})}}),n.jsx("input",{"aria-label":`Variable ${P+1} value`,type:A.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:A.kept&&A.value===""?"Kept. Type to replace it.":"value",value:A.value,onChange:D=>U(A.key,{value:D.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:A.secret,onChange:D=>U(A.key,{secret:D.target.checked,kept:D.target.checked&&A.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>g(D=>D.filter(O=>O.key!==A.key)),"aria-label":`Remove variable ${P+1}`,children:"Remove"})]},A.key)),n.jsx(ae,{children:n.jsx(T,{size:"sm",onClick:()=>g(A=>[...A,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),R.length>0?n.jsxs(G,{tone:"accent",children:["Your config had a placeholder for ",R.join(", "),". Type the value itself."]}):null,!s&&p.some(A=>A.secret)?n.jsx(G,{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(It,{label:"The command line",children:C||"…"})]}),n.jsx(le,{message:j}),n.jsx(ae,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:x||o.trim()===""||u.trim()===""||$.length>0,title:$.length>0?`Give ${$.join(", ")} a value.`:void 0,children:x?"Saving…":e?"Save":"Continue"})})]})}function IK({connection:e,onKept:t}){const s=ce(()=>E.connectionReview(e.id),[e.id]),[r,i]=h.useState(null),[a,l]=h.useState(!1),[o,c]=h.useState(null),u=s.data,d=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{t(await E.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:d}:{}}))}catch(g){g instanceof pe&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(_s(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(le,{message:s.error}):e.transport==="stdio"?n.jsxs(xe,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(xe,{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(G,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(se,{gap:"sm",children:[n.jsx(It,{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(G,{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(G,{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(ie,{label:"Its name in buddi",hint:`Tools are called mcp.${d||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:d,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(xe,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=uK(p),x=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${d||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:x}),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(jg,{children:"New"}):p.change==="changed"?n.jsx(jg,{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?cK:"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(le,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(T,{variant:"accent",onClick:()=>void f(),disabled:a||u.slugEditable&&d.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function PK({connection:e,agents:t,onDone:s}){var b;const r=t.find(j=>j.frontDesk)??t[0],[i,a]=h.useState(()=>new Set(r?[r.id]:[])),o=(((b=ce(()=>E.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=h.useState(()=>new Set),[d,f]=h.useState(!1),[m,p]=h.useState(null),g=(j,v)=>{a(w=>{const y=new Set(w);return v?y.add(j):y.delete(j),y})},x=async()=>{f(!0),p(null);try{const j=await E.grantConnection(e.id,[...i]);if(j.failed.length>0){p(j.failed.map(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of j.granted)for(const w of c)await E.setRememberedApproval(v,w,!0);s()}catch(j){p(_s(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:v=>g(j.id,v.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:v=>u(w=>{const y=new Set(w);return v.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(le,{message:m}),n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:s,disabled:d,children:"Not now"}),n.jsx(T,{variant:"accent",onClick:()=>void x(),disabled:d||i.size===0,children:"Give them"})]})]})}const MK=(e,t,s)=>`${e} ${e===1?t:s}`;function DK(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 OK({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=h.useState({}),o=ce(()=>E.connections().then(w=>(l({}),w)),[r]),[c,u]=h.useState(null),[d,f]=h.useState(null),m=Oe("connections"),p=async(w,y)=>{u(w.id),f(null);try{const N=await E.setConnectionHolder(w.id,e,y);l(k=>({...k,[w.id]:N.held})),i==null||i()}catch(N){f(N instanceof Error?N.message:String(N))}finally{u(null)}},g=o.data,x=(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,v=x.filter(b).length;return n.jsxs(oe,{title:"Connections",aside:g&&x.length>0?`holds ${v} of ${x.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(le,{message:o.error??d}),g?x.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(G,{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:x.map(w=>{const y=b(w),N=DK(w),k=w.transport==="stdio"?"on this computer":w.host,S=w.slug?MK(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||N!==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,N?n.jsxs(n.Fragment,{children:[" ",n.jsx(ve,{tone:"warning",children:DT(w).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${k} · ${S}`}),N?n.jsxs("span",{className:"ui-list-sub",children:[N," ",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(xe,{children:"Loading the connections…"})]})}const LK=(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 zT(e){const t=await fetch(ca(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 _K({face:e,onPick:t,label:s=_.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,N4.map(o=>{const c={kind:"mascot",role:o},u=LK(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":_.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:ca(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:C4.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 FK=["mirror","en","fr"],zK=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],Tm=10,Rm=500,UT=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],n0=e=>{var t;return e==="access"?"tools":((t=UT.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function UK({agentId:e,section:t,navigate:s}){var x,b,j;const{data:r,error:i,reload:a}=ce(()=>E.agents(),[]),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(n0(t));h.useEffect(()=>f(n0(t)),[t]);const m=v=>{f(v),s==null||s(Et(e,"setup",v))},p=async v=>{o(null),u(null);try{const w=await v;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),a()}catch(w){o(w instanceof Error?w.message:String(w))}},g=r==null?void 0:r.agents.find(v=>v.id===e);return n.jsxs(se,{gap:"lg",children:[n.jsx($c,{level:"secondary",label:"Setup",children:UT.map(v=>n.jsx(cl,{href:Et(e,"setup",v.id),active:d===v.id,onClick:w=>{w.preventDefault(),m(v.id)},children:v.label},v.id))}),n.jsx(le,{message:i??l}),c?n.jsx(G,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(BK,{agent:g,all:r.agents,engine:r.engines.find(v=>v.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:d,onShow:m,onRun:p,onSaved:a},`${g.id}:${(x=r.engines.find(v=>v.id===g.id))==null?void 0:x.model}:${(j=(b=r.providerAccounts)==null?void 0:b.bindings.find(v=>v.agentId===g.id))==null?void 0:j.accountId}`):n.jsx(xe,{children:"This agent is not installed as a file."}):n.jsx(xe,{children:"Loading…"})]})}function BK({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,d=r.find(k=>k.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=h.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,x]=h.useState(null),b=k=>{o(E.setAgentEngine(e.id,k))},j=k=>{const S=r.find(C=>C.kind===k);b({provider:k,model:(S==null?void 0:S.defaultModel)??f})},v=(d==null?void 0:d.models.map(k=>k.id))??[],w=v.includes(f)?v:[f,...v],y=s?s.available:!0,N=(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(G,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:Et(e.id,"setup","brain"),onClick:k=>{k.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(WK,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(se,{gap:"lg",children:[y?null:n.jsxs(G,{tone:"warning",children:["This agent cannot run right now: ",N,"."]}),n.jsx(oe,{panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsxs(oe,{title:"Runs on",children:[i?n.jsx(QK,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(Ls,{children:[n.jsx(ie,{label:"Provider",children:n.jsx("select",{value:u,onChange:k=>j(k.target.value),children:r.map(k=>n.jsxs("option",{value:k.kind,children:[k.kind,k.usable?"":" (no credential)"]},k.kind))})}),n.jsxs(ie,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:k=>{k.target.value.trim()!==""&&k.target.value.trim()!==f&&b({model:k.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:w.map(k=>n.jsx("option",{value:k},k))})]})]}),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}),d&&!d.usable?` · default model ${d.defaultModel} (${d.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(oe,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(Ls,{children:[n.jsx(ie,{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:Tm,max:Rm,value:m,onChange:k=>{p(k.target.value),x(null)},onBlur:()=>{const k=Number(m);if(!Number.isInteger(k)||k<Tm||k>Rm){x(`Between ${Tm} and ${Rm}.`);return}k!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:k})}})}),n.jsx(ie,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:k=>b({language:k.target.value}),children:FK.map(k=>n.jsx("option",{value:k,children:k},k))})}),s?n.jsx(ie,{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:k=>b({idleRollover:k.target.value==="3h"?null:k.target.value}),children:zK.map(k=>n.jsx("option",{value:k.value,children:k.label},k.value))})}):null,r1(i1(s??{id:e.id,provider:u},i))?n.jsx(ie,{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:k=>b({thinking:k.target.value==="default"?null:k.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(ie,{label:"Thinking",hint:fO,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(yt,{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(HK,{agent:e,all:t,onSaved:c}),n.jsx(OK,{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(eV,{agent:e,all:t,onSaved:c})})})]})}function BT({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 WT=n.jsx(G,{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 WK({agent:e,onSaved:t}){var z;const[s,r]=h.useState(e.name),[i,a]=h.useState(e.handle),[l,o]=h.useState(e.description),[c,u]=h.useState(e.avatar??""),[d,f]=h.useState(!1),m=ce(()=>E.agentFile(e.id),[e.id]),[p,g]=h.useState(null),x=((z=m.data)==null?void 0:z.persona.trim())??"",b=p??x,j=m.data!==void 0&&p!==null&&p.trim()!==x,[v,w]=h.useState(!1),[y,N]=h.useState(null),[k,S]=h.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=ex($?{...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}:{}},U=async()=>{w(!0),N(null),S(null);try{const A=await E.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 E.removeAgentPicture(e.id),window.dispatchEvent(new Event(Zo))),g(null),m.reload(),S(A.message),t()}catch(A){N(A instanceof Error?A.message:String(A))}finally{w(!1)}};return n.jsx(oe,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(BT,{dirty:C,busy:v,failure:y,label:"Save who it is",onSave:()=>void U()}),children:n.jsxs(se,{children:[e.isExample?WT:null,k?n.jsx(G,{tone:"good",role:"status",children:k}):null,n.jsxs(Ls,{children:[n.jsx(ie,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:v||e.isExample,onChange:A=>r(A.target.value)})}),n.jsx(ie,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:v||e.isExample,onChange:A=>a(A.target.value)})})]}),n.jsxs(ae,{children:[n.jsx(Us,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),n.jsx(T,{"aria-expanded":d,onClick:()=>f(A=>!A),children:d?"Hide faces":"Change face"})]}),d?n.jsx(YK,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:v}):null,n.jsx(ie,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:v||e.isExample,onChange:A=>o(A.target.value)})}),n.jsx(ie,{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(le,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
114
+ `).length+1),disabled:v||e.isExample,onChange:A=>g(A.target.value)}):n.jsx(xe,{children:"Reading its file…"})})]})})}function HK({agent:e,all:t,onSaved:s}){var $;const r=ce(()=>E.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=h.useState(null),[l,o]=h.useState(()=>new Set((e.roles??[]).filter($b))),[c,u]=h.useState((e.roles??[]).filter(R=>!$b(R)).join(", ")),[d,f]=h.useState(!1),[m,p]=h.useState(null),[g,x]=h.useState(null),b=(R,I)=>R.split(I).map(U=>U.trim()).filter(U=>U!==""),j=(($=r.data)==null?void 0:$.granted)??e.tools,v=i??j,w=r.data!==void 0&&!nK(v,j),y=Ib(l,b(c,/[\n,]/)),N=R=>o(I=>{const U=new Set(I);return U.has(R)?U.delete(R):U.add(R),U}),S=w||!((R,I)=>R.join(",")===I.join(","))(y,Ib(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),x(null);try{const R=await E.updateAgentFile(e.id,{...w&&r.data?{tools:tK(r.data.groups,v)}:{},roles:y});x(R.message),a(null),r.reload(),s()}catch(R){p(R instanceof Error?R.message:String(R))}finally{f(!1)}};return n.jsx(oe,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(BT,{dirty:S,busy:d,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(se,{children:[e.isExample?WT:null,g?n.jsx(G,{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:Qv.map(R=>{const I=kF(t,R.id),U=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:d||e.isExample,onClick:()=>N(R.id),children:[n.jsx("span",{className:"role-chip-label",children:R.label}),n.jsx("span",{className:"role-chip-meaning",children:R.meaning}),U?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",U.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(ie,{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:d||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(le,{message:r.error}):r.data?n.jsx(rK,{view:r.data,chosen:v,onChange:a,disabled:d||e.isExample}):n.jsx(xe,{children:"Loading the installed tools…"})]}),n.jsx(KK,{agentId:e.id,version:j.join(","),disabled:d||e.isExample}),VK(j)?n.jsx(GK,{agentId:e.id}):null]})})}function KK({agentId:e,version:t,disabled:s}){var g;const r=ce(()=>Promise.resolve().then(()=>E.rememberedApprovals(e)),[e,t]),i=ce(()=>Promise.resolve().then(()=>E.connections()).catch(()=>null),[]),[a,l]=h.useState(null),[o,c]=h.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const d=async(x,b)=>{l(x),c(null);try{await E.setRememberedApproval(e,x,b),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const x of u)f.set(x.connection,[...f.get(x.connection)??[],x]);const m=x=>{var b,j;return((j=(b=i.data)==null?void 0:b.connections.find(v=>v.slug===x))==null?void 0:j.name)??x},p=x=>x.tool.split(".").slice(2).join(".")||x.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(([x,b])=>{const j=b.filter(N=>N.rememberable),v=b.filter(N=>!N.rememberable),w=j.filter(N=>N.remembered),y=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(x)}),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(yt,{summary:y,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(x)}: remember my approval`,children:j.map(N=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:N.remembered,disabled:s||a!==null,onChange:k=>void d(N.tool,k.target.checked),"aria-label":`Remember my approval for ${N.tool}`}),n.jsx("span",{className:"mono",children:p(N)})]},N.tool))}),v.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:v.map(p).join(", ")})]}):null]},x)})}),n.jsx(le,{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 VK(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function GK({agentId:e}){var d,f;const t=ce(()=>E.notificationSettings(),[]),[s,r]=h.useState(null),[i,a]=h.useState(!1),[l,o]=h.useState(null),c=s??((f=(d=t.data)==null?void 0:d.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),E.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(le,{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 ex(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 YK({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.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(d(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await E.uploadAgentPicture(e.id,await zT(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(Zo))}catch(x){d(x instanceof Error?x.message:String(x))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(_K,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(qK,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function qK({agent:e,onChanged:t}){const[s,r]=h.useState(null),[i,a]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(0);h.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(Zo))},x=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=()=>x(async()=>(await E.uploadAgentPicture(e.id,s)).note??null),j=()=>x(async()=>(await E.removeAgentPicture(e.id),null)),v={avatar:ex(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[w,y]=h.useState(!1),N=h.useRef(null),k=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||k((C=S.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(ae,{children:[n.jsx(Us,{id:e.id,name:e.name,size:"xl",face:v}),n.jsx("input",{ref:N,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return k((C=S.target.files)==null?void 0:C[0])}},m),n.jsx(T,{disabled:l,onClick:()=>{var S;return(S=N.current)==null?void 0:S.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(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:d??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function QK({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=h.useState((r==null?void 0:r.accountId)??""),[l,o]=h.useState((r==null?void 0:r.model)??""),[c,u]=h.useState(!1),d=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(ae,{valign:"end",children:[n.jsx(ie,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(x=>x.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(zj,{accountId:d!=null&&d.configured?i:void 0,label:"Model",value:l,onChange:o,disabled:c},`${i}:${d==null?void 0:d.revision}`)]}),n.jsxs(ae,{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(E.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const XK=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],$m=e=>e.tools.some(t=>XK.includes(t)),JK=["front-desk","maker"],ZK={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function eV({agent:e,all:t,onSaved:s}){const[r,i]=h.useState(e.delegates),[a,l]=h.useState(!1),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState(e.delegates),[p,g]=h.useState(e.asksEveryone),[x,b]=h.useState(!1),j=t.filter(R=>R.id!==e.id),v=JK.find(R=>{var I;return(I=e.roles)==null?void 0:I.includes(R)}),w=p===void 0||x,y=x||[...r].sort().join(",")!==[...f].sort().join(","),N=t.filter(R=>R.id!==e.id&&(R.delegates.includes(e.id)||R.asksEveryone!==void 0&&!$m(e))),k=R=>i(I=>I.includes(R)?I.filter(U=>U!==R):[...I,R]),S=async R=>{l(!0),c(null),d(!1);try{const I=await E.setDelegates(e.id,R);m(I.delegates),i(I.delegates),g(I.asksEveryone),b(!1),d(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{i(j.filter(R=>!$m(R)).map(R=>R.id)),b(!0),d(!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(oe,{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&&v!==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(oe,{title:"Can ask",children:[e.isExample?n.jsx(G,{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(le,{message:o}),w?j.length===0?n.jsx(xe,{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=$m(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:()=>k(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:[ZK[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(oe,{title:"Asked by",children:N.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(vz,{children:N.map(R=>n.jsx(ve,{children:R.name},R.id))})})]})})}const tV=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"}],nV=[{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 sV({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var j,v,w,y,N;const l=sF(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=k=>S=>{S.preventDefault(),s(k)},u=ce(()=>E.agents(),[]),d=jj(),f=ce(()=>E.offers(),[],2e4),m=wA(),p=(((v=f.data)==null?void 0:v.offers.length)??0)+m.offers.length,g=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??a??null,x=r.find(k=>k.roles.includes(Hh)),b=bT(r,g);return n.jsxs("div",{className:"ui-page",children:[n.jsx(rc,{title:"Agents",lede:`Your team. Each one is a file on ${d} — what it can reach is listed on its page.`,actions:x?n.jsx(Nt,{variant:"accent",href:tt(x.id),onClick:c(tt(x.id)),children:"Add an agent"}):null}),n.jsx($c,{children:tV.map(k=>n.jsx(cl,{href:k.id==="team"?Ct:`${Ct}?tab=${k.id}`,active:o===k.id,count:k.id==="offers"?p:void 0,onClick:c(k.id==="team"?Ct:`${Ct}?tab=${k.id}`),children:k.label},k.id))}),o==="missions"?n.jsx(jT,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(yA,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(yT,{embedded:!0}):null,o==="reminders"?n.jsx(CT,{timezone:t,embedded:!0}):null,o==="team"&&b?n.jsx(Jg,{navigate:s,standing:!0}):null,o==="team"?n.jsx(rV,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(jn,{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:fE(r,g).map(k=>{const S=Wh(i.get(k.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Ac(Ec(k)),"data-unavailable":k.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Us,{id:k.id,name:k.name,size:"xl",unavailable:!k.available,face:k})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:Et(k.id,"conversations"),onClick:c(Et(k.id,"conversations")),children:k.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",k.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:k.description})]}),n.jsxs("div",{className:"ui-row",children:[k.id===g?n.jsx(jg,{children:"front desk"}):null,S?n.jsx(ve,{tone:"critical",dot:!0,children:"waiting for you"}):k.available?n.jsx(ve,{tone:"good",dot:!0,children:"ready"}):n.jsx(ve,{tone:"warning",children:Os(k.unavailableReason??"cannot run",60)}),n.jsx(ve,{mono:!0,children:k.model}),n.jsx(Nt,{className:"agent-card-talk",size:"sm",href:tt(k.id),onClick:c(tt(k.id)),"aria-label":`Talk to ${k.name}`,children:"Talk"})]})]},k.id)})}):null,o==="team"&&!b?n.jsx(Jg,{navigate:s,standing:!0}):null,l?n.jsx(ft,{title:((N=r.find(k=>k.id===l.agentId))==null?void 0:N.name)??l.agentId,size:"wide",onClose:()=>s(Ct),children:n.jsx(iV,{agentId:l.agentId,agent:r.find(k=>k.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function rV({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null);if(t)return n.jsx(le,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,x=r.problem,b=v=>v.map(w=>{var y;return((y=r.choices.find(N=>N.id===w))==null?void 0:y.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const v=await E.setDefaultAgent(p);f(v.note),a(null),s()}catch(v){u(v instanceof Error?v.message:String(v))}finally{o(!1)}};return n.jsx(Qe,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(le,{message:c}),(x==null?void 0:x.code)==="multiple-defaults"?n.jsx(G,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(x.agents)}. The one chosen here wins.`}):(x==null?void 0:x.code)==="no-default-agent"?n.jsx(G,{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,d?n.jsx(G,{tone:"good",role:"status",children:d}):null,n.jsxs(ae,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:v=>a(v.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>n.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),n.jsx(T,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function iV({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=Wh(o.get(e)),d=(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(Us,{id:e,name:d,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(Nt,{variant:"accent",href:tt(e),onClick:c(tt(e)),children:["Talk to ",d]})})]}),t&&!t.available?n.jsxs(G,{tone:"warning",role:"status",children:[pE(t)," ",n.jsx("a",{href:Oe(fg(t).section),children:fg(t).label})]}):null,n.jsx($c,{children:nV.map(f=>n.jsx(cl,{href:Et(e,f.id),active:r===f.id,onClick:c(Et(e,f.id)),children:f.label},f.id))}),r==="conversations"?n.jsx(aV,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(jT,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(yT,{embedded:!0,agentId:e,agentName:d}):null,r==="reminders"?n.jsx(CT,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(kT,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(qH,{agentId:e,agentName:d}):null,r==="setup"?n.jsx(UK,{agentId:e,section:i,navigate:l}):null]})}function aV({agentId:e,navigate:t}){const{data:s,error:r}=ce(()=>He.conversations(e,50),[e]);if(r)return n.jsx(xe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(Qe,{flush:!0,children:s?i.length===0?n.jsx(jn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(ht,{children:i.map(a=>n.jsx(st,{href:tt(e,a.id),onClick:()=>t(tt(e,a.id)),title:Os(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:De(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(xe,{children:"Loading…"})})}const lV=3e4;function HT(){const{data:e,reload:t}=ce(()=>E.recovery(),[],lV),s=h.useRef(t);return s.current=t,h.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 s0(e){return e.kind==="account"?e.accountId?sE(e.accountId):Oe("accounts"):e.kind==="telegram"?Oe("telegram"):e.kind==="connection"?e.connectionId?rE(e.connectionId):Oe("connections"):e.kind==="email"?e.settingsRoute:Oe("secrets")}function oV(e){return e.install?dF(e.install):hF}const cV=Oe("system");function uV(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 KT="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function dV({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,l=e.checklist.keptTables??[],[o,c]=h.useState(!0),[u,d]=h.useState([]),[f,m]=h.useState(!1),[p,g]=h.useState(null),[x,b]=h.useState(!1),j=r.filter(N=>!N.installed||N.waiting!==void 0||N.loadsAtRestart===!0),v=i.jobs+i.missions+i.approvals+i.telegramChats,w=N=>{d(k=>k.includes(N)?k.filter(S=>S!==N):[...k,N])},y=()=>{m(!0),g(null),Bh({kind:"recovery"},()=>E.leaveRecovery({dropPending:o,keepGrants:u})).then(N=>{N&&N.restarting===!1&&ol(),b(!0),t==null||t()}).catch(N=>g(N instanceof pe?N.message:String(N))).finally(()=>m(!1))};return n.jsx(Qe,{title:"Back from a backup",children:n.jsxs(se,{divided:!0,children:[n.jsxs(oe,{children:[n.jsx(Bt,{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(oe,{title:"Keys to paste again",children:s.length===0?n.jsx(xe,{children:"Nothing is missing."}):n.jsx(ht,{children:s.map(N=>n.jsx(st,{title:N.label??N.name,sub:N.name?n.jsx("span",{className:"mono",children:N.name}):void 0,side:N.signIn?n.jsx(Nt,{size:"sm",href:s0(N),"aria-label":`Sign in again: ${N.label??N.name}`,children:"Sign in again"}):n.jsx(Nt,{size:"sm",href:s0(N),"aria-label":`Fix ${N.label??N.name}`,children:"Fix"})},`${N.kind}:${N.accountId??N.name}`))})}),n.jsx(oe,{title:"Add-ons to install again",children:j.length===0&&l.length===0?n.jsx(xe,{children:"Everything the backup named is installed."}):n.jsxs(ht,{children:[j.map(N=>n.jsx(st,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:N.name})," ",N.version]}),sub:uV(N),side:N.loadsAtRestart?n.jsx(Nt,{size:"sm",href:cV,"aria-label":`Restart to load ${N.name}`,children:"Restart"}):N.installed?void 0:n.jsx(Nt,{size:"sm",href:oV(N),"aria-label":`Install ${N.name} again`,children:N.install?"Install":"Find it"})},N.name)),l.map(N=>n.jsx(st,{title:n.jsx("span",{className:"mono",children:N.table}),sub:N.sentence},`kept:${N.table}`))]})}),n.jsx(oe,{title:"Work that was waiting",children:v===0?n.jsx(xe,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(se,{gap:"sm",children:[n.jsx(Bt,{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:N=>c(N.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(oe,{title:"Standing permissions",children:a.length===0?n.jsx(xe,{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(N=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:u.includes(N.id),onChange:()=>w(N.id),"aria-label":`Keep ${N.tool} for ${N.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:N.tool})," for ",N.agent," ",n.jsx("span",{className:"ui-card-meta",children:N.scope}),N.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",N.description]}):null]})]})},N.id))})]})}),n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:p}),x?n.jsx(G,{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(ae,{align:"end",children:n.jsx(T,{variant:"accent",disabled:f||x,onClick:y,children:"Leave recovery mode"})})]})})]})})}const r0=3,hV=40;function fV({agent:e,navigate:t}){var g;const s=h.useRef(null),[r,i]=h.useState(!1),[a,l]=h.useState(null),[o,c]=h.useState(null),u=ce(()=>He.conversations(e.id,r0),[e.id],3e4),d=Ms(aj),f=Ms("(pointer: coarse)");h.useEffect(()=>{var x;!d&&!f&&((x=s.current)==null||x.focus())},[]);const m=(x,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:j}=await He.startConversation(e.id),v=await He.send(e.id,{conversationId:j,text:x,...b.length>0?{attachmentIds:b.map(w=>w.artifactId)}:{}});t(tt(e.id,v.conversationId))}catch(j){l(j instanceof pe?j.message:String(j)),c({text:x,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,r0);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(le,{message:a}):null,n.jsx(wj,{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(x=>{const b=tt(e.id,x.id),j=x.opening??x.preview??"Untitled conversation",v=$v(x.lastMessageAt??x.createdAt??x.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:Os(j,hV)}),v?n.jsx("span",{className:"home-continue-when",children:v}):null]})},x.id)})})]}):null]})}function mV(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 pV({navigate:e,preview:t,hidden:s}){var c;const r=ce(()=>E.currentTip(t),[t]),[i,a]=h.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"?E.dismissTip(l.id):E.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(G,{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(ue,{name:"close"})})]}),n.jsxs(ae,{children:[n.jsx(Dt,{}),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 tx="buddi.tipsOpen";function gV(e){return $h(e,{compact:!0})}function xV(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 ${gV(e.shownAt)}`:"Shown"}}function vV(){try{return window.localStorage.getItem(tx)==="1"}catch{return!1}}function jV(){const e=ce(()=>E.tips(),[]),[t,s]=h.useState(vV),r=h.useCallback(i=>{s(i);try{i?window.localStorage.setItem(tx,"1"):window.localStorage.removeItem(tx)}catch{}},[]);return{open:t,setOpen:r,list:e}}function wV({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(ue,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function yV({tips:e,navigate:t}){var b,j;const{open:s,setOpen:r,list:i}=e,[a,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.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=v=>l(v instanceof pe?v.message:String(v)),g=v=>{c(v),l(null),E.restoreTip(v).then(()=>i.reload(),p).finally(()=>c(null))},x=v=>{c("switch"),l(null),d(v),E.saveTipsSettings(v).then(w=>{d(w.enabled),i.reload()}).catch(w=>{d(!v),p(w)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(oe,{title:"Tips",children:[n.jsx(le,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(f??[]).map(v=>n.jsx("div",{className:"tips-card","data-tip":v.id,"data-status":v.status,children:n.jsxs(ys,{tone:v.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(ve,{tone:v.status==="today"?"accent":"muted",children:xV(v)})}),n.jsx("p",{className:"tips-card-text",children:v.text}),n.jsxs(ae,{children:[n.jsx(Dt,{}),v.status==="dismissed"?n.jsx(T,{size:"sm",disabled:o===v.id,onClick:()=>g(v.id),children:"Bring back"}):n.jsx(T,{size:"sm",variant:v.status==="today"?"accent":void 0,onClick:()=>t(v.action.route),children:v.action.label})]})]})},v.id))}),n.jsxs(ae,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||f===null,onChange:v=>x(v.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(Dt,{}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const VT="buddi.needsYouView";function bV(){try{return window.localStorage.getItem(VT)==="list"?"list":"deck"}catch{return"deck"}}function kV(e){try{window.localStorage.setItem(VT,e)}catch{}}function NV(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function SV({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=h.useState(0);if(e.length===0)return n.jsx(xe,{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,d=x=>l((o+x+e.length)%e.length),f=()=>r(c),m=()=>i(c),p=x=>{const b=x.target;b.closest('input, textarea, select, [contenteditable="true"]')||(x.key==="ArrowRight"&&u?(x.preventDefault(),d(1)):x.key==="ArrowLeft"&&u?(x.preventDefault(),d(-1)):x.key==="Enter"&&!b.closest("button, a")?(x.preventDefault(),(c.link||c.agentId)&&f()):(x.key==="d"||x.key==="Delete")&&!x.metaKey&&!x.ctrlKey&&!x.altKey&&(x.preventDefault(),m()))},g=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(ln,{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(ys,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":De(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:()=>d(-1),children:n.jsx(ue,{name:"chevron-left"})}),n.jsx(T,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>d(1),children:n.jsx(ue,{name:"chevron-right"})})]}),foot:n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:m,children:"Done"}),c.link||c.agentId?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:Jo(c)}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null,c.action?n.jsx("p",{className:"home-deck-text",children:n.jsx("strong",{children:c.action})}):null]})})})}function CV({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o="",pluginPages:c}){var it,qe,J,we,Ye,ot,ct,Tt,zn,jt,dn,Un,Q,$e,Xe;const u=ce(()=>E.overview(),[],15e3),d=ce(()=>E.approvals(),[],1e4),f=ce(()=>E.missions(),[],6e4),m=ce(()=>E.reminders(),[],6e4),p=ce(()=>E.conversations(),[],3e4),g=ce(()=>E.offers(),[],3e4),x=ce(()=>E.proposals(),[],6e4),b=ce(()=>E.agentOffers(),[],6e4),j=ce(()=>E.owner(),[]),v=ce(()=>E.notificationsNeedingYou(),[],3e4),w=h.useMemo(()=>fE(s,r??null),[s,r]),{busy:y,note:N,failure:k,decide:S}=yj(()=>{d.reload(),u.reload()}),C=u.data,$=s.find(K=>K.id===r)??null,R=K=>{var _e;return((_e=s.find(je=>je.id===K))==null?void 0:_e.name)??K},I=K=>_e=>{_e.preventDefault(),t(K)},U=((it=d.data)==null?void 0:it.pending)??[],z=((qe=C==null?void 0:C.jobs)==null?void 0:qe.failed)??0,A=((J=C==null?void 0:C.sentinels)==null?void 0:J.openUrgent)??0,P=((we=x.data)==null?void 0:we.open.length)??0,D=(((Ye=b.data)==null?void 0:Ye.offers)??[]).filter(K=>!U.some(_e=>jA(_e,K.plugin,K.agent))),O=AV(((ot=v.data)==null?void 0:ot.notifications)??[],U),[M,W]=h.useState(new Set),[L,q]=h.useState(bV),B=O.filter(K=>!M.has(K.id)),V=K=>{W(_e=>new Set(_e).add(K.id)),E.notificationSeen(K.id).catch(()=>{})},F=K=>{V(K);const _e=K.link??(K.agentId?tt(K.agentId):null);_e&&t(_e)},X=K=>NV(K.agentId?R(K.agentId):K.pluginId?x3(K.pluginId,c==null?void 0:c.all):EV[K.kind],K,R),Y=IV(C==null?void 0:C.dismissed,()=>u.reload()),Z=(((ct=C==null?void 0:C.sentinels)==null?void 0:ct.errors)??[]).filter(K=>!Y.is(`watcher-error:${K.sentinelId}`,K.error)),he=((C==null?void 0:C.mail)??[]).filter(K=>K.lastError&&!Y.is(`source-error:${K.sourceId}`,K.lastError)),Le=TV(i),Ie=l.filter(K=>!Y.is(`connection:${K.id}`,K.sentence)),ze=(((Tt=C==null?void 0:C.needsYou)==null?void 0:Tt.recovery)??0)>0,ee=U.length+Le.length+(z>0?1:0)+(A>0?1:0)+(P>0?1:0)+D.length+O.length+Ie.length+(ze?1:0);h.useEffect(()=>{var K,_e;o===Fh&&((_e=(K=document.getElementById(nx))==null?void 0:K.scrollIntoView)==null||_e.call(K,{behavior:"smooth",block:"start"}))},[o]);const be=h.useMemo(()=>{var K,_e;return OV(((K=f.data)==null?void 0:K.missions)??[],((_e=m.data)==null?void 0:_e.reminders)??[])},[f.data,m.data]),re=(((zn=p.data)==null?void 0:zn.conversations)??[]).slice(0,5),Ee=((jt=g.data)==null?void 0:jt.offers)??[],me=Ee.slice(0,PV),Re=jV(),Se=Ee.length-me.length,Ue=ZA(()=>u.reload()),et=vW(),Ae=h.useMemo(()=>jW(et.answer),[et.answer]),Be=BV((C==null?void 0:C.needsYou)??{approvals:U.length,questions:Le.length,failed:z,urgent:A,proposals:P,agentsToSetUp:D.length,asks:O.length,signIns:Ie.length,recovery:ze?1:0},(C==null?void 0:C.paused)??!1);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:FV(C==null?void 0:C.now,e)}),n.jsx(Y8,{glances:C==null?void 0:C.glances,navigate:t,except:Ae,hiding:Ue}),n.jsx(wV,{tips:Re})]}),n.jsx("h1",{className:"home-greeting",children:_V(C==null?void 0:C.now,e,((dn=j.data)==null?void 0:dn.preferredName)||((Un=j.data)==null?void 0:Un.displayName))}),n.jsx(WV,{items:Be,navigate:t})]}),n.jsx("div",{className:"home-side",children:n.jsx(yE,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[$?n.jsx(fV,{agent:$,navigate:t},$.id):null,n.jsx(yV,{tips:Re,navigate:t}),n.jsx(pV,{navigate:t,preview:mV(o),hidden:Re.open}),a&&a.updateAvailable&&!a.checkout&&a.latest&&!Y.is("update",a.latest)?n.jsx(G,{tone:"accent",action:n.jsx(Fa,{label:"Not now — tell me at the next version",onClick:()=>Y.close("update",a.latest)}),children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:Oe("system"),onClick:I(Oe("system")),children:"Upgrade from Settings → Version."})]})}):null,Z.map(K=>n.jsxs(G,{tone:"warning",action:n.jsx(Fa,{label:"Hide until the error changes",onClick:()=>Y.close(`watcher-error:${K.sentinelId}`,K.error)}),children:["Watcher ",K.sentinelId," failed: ",K.error]},K.sentinelId)),he.map(K=>n.jsxs(G,{tone:"warning",action:n.jsx(Fa,{label:"Hide until the error changes",onClick:()=>Y.close(`source-error:${K.sourceId}`,K.lastError)}),children:["Source ",K.sourceId,": ",K.lastError]},K.sourceId)),n.jsx(le,{message:u.error??d.error??k}),N?n.jsx(G,{tone:"good",role:"status",children:N}):null,ee>0?n.jsx("div",{id:nx,className:"home-needs",children:n.jsx(oe,{title:"Needs you",aside:n.jsx("a",{href:cg,onClick:I(cg),children:"All notifications"}),actions:O.length>0?n.jsx(sn,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:L,onChange:K=>{q(K),kV(K)}}):void 0,children:n.jsxs(se,{children:[U.map(K=>n.jsx(bj,{action:K,timezone:e,busy:y===K.id,onDecide:S,agentName:R(K.agentId)},K.id)),A>0?n.jsx(G,{tone:"warning",children:n.jsx("a",{href:`${xt}/alerts`,onClick:I(`${xt}/alerts`),children:UV(A,((Q=C==null?void 0:C.sentinels)==null?void 0:Q.decisions)??[])})}):null,Le.length>0||O.length>0&&L==="list"?n.jsx(Qe,{flush:!0,children:n.jsxs(ht,{children:[Le.map(K=>n.jsx(st,{href:K.route,onClick:()=>t(K.route),lead:n.jsx(ln,{agents:s,id:K.agentId,size:"sm"}),title:"Asked you a question",sub:`${R(K.agentId)} · waiting for your answer`,side:De(K.at)},K.agentId)),L==="list"?B.map(K=>n.jsx(st,{href:K.link??void 0,onClick:()=>F(K),lead:K.agentId?n.jsx(ln,{agents:s,id:K.agentId,size:"sm"}):void 0,title:Jo(K),sub:K.action?`${X(K)} · ${K.action}`:X(K),side:K.state==="held"?"today":De(K.createdAt)},K.id)):null]})}):null,O.length>0&&L==="deck"?n.jsx(SV,{rows:B,agents:s,label:X,onOpen:F,onDone:V}):null,z>0?n.jsx(G,{tone:"critical",children:n.jsxs("a",{href:`${xt}/jobs?state=failed`,onClick:I(`${xt}/jobs?state=failed`),children:[z," failed job",z===1?"":"s",". See why, then retry or dismiss ",z===1?"it":"them","."]})}):null,P>0?n.jsx(G,{tone:"accent",children:n.jsxs("a",{href:Oe("proposals"),onClick:I(Oe("proposals")),children:[P," proposal",P===1?"":"s"," from your agents to keep or discard."]})}):null,Ie.map(K=>n.jsx(G,{tone:"accent",action:n.jsx(Fa,{label:"Not now — tell me if it changes",onClick:()=>Y.close(`connection:${K.id}`,K.sentence)}),children:n.jsxs("p",{children:[K.sentence," ",n.jsx("a",{href:Oe("connections"),onClick:I(Oe("connections")),children:"Settings → Connections."})]})},K.id)),D.map(K=>n.jsx(Qe,{children:n.jsx(Nj,{plugin:K.plugin,agent:K.agent,text:K.text,label:`Create @${K.handle}`,handle:K.handle,onDismiss:()=>{E.dismissAgentOffer(K.plugin,K.agent).then(()=>b.reload())}})},`${K.plugin}/${K.agent}`)),ze?n.jsx(G,{tone:"warning",children:n.jsxs("p",{children:[KT," ",n.jsx("a",{href:ug,onClick:I(ug),children:"Open the checklist."})]})}):null]})})}):null,n.jsx(kW,{widgets:et,navigate:t}),n.jsx(oe,{title:"Your team",aside:n.jsx("a",{href:Ct,onClick:I(Ct),children:"All agents"}),children:s.length===0?n.jsx(xe,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsx("div",{className:"home-team",children:w.map(K=>{const _e=Wh(i.get(K.id));return n.jsxs("a",{className:"home-face",...Ac(Ec(K)),href:tt(K.id),onClick:I(tt(K.id)),"data-waiting":_e?"true":void 0,"data-unavailable":K.available?void 0:"true",children:[n.jsx(Us,{id:K.id,name:K.name,size:"lg",unavailable:!K.available,face:K}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:K.name}),n.jsx("span",{className:"home-face-status",children:_e?HV(_e):K.available?Os(K.description,60):K.unavailableReason??"Cannot run right now."})]})]},K.id)})})}),bT(s,r)?n.jsx(Jg,{navigate:t}):null,me.length>0?n.jsx(oe,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[Se>0?n.jsxs("a",{href:`${Ct}?tab=offers`,onClick:I(`${Ct}?tab=offers`),children:[Se," more"]}):null,n.jsx(wT,{ids:Ee.map(K=>K.id),onDone:()=>g.reload()})]}),children:n.jsx("div",{className:"home-offers",children:me.map(K=>n.jsx(DV,{offer:K,agents:s,open:I(Et(K.agentId,"offers")),onDismissed:()=>g.reload()},K.id))})}):null,n.jsx(O8,{}),(Xe=($e=x.data)==null?void 0:$e.digest)!=null&&Xe.latest&&$V(x.data.digest.latest,C==null?void 0:C.now,Y.is)?n.jsx(zV,{digest:x.data.digest.latest,go:I,onClose:()=>Y.close(GT,x.data.digest.latest.at)}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(oe,{title:"Coming up",aside:n.jsx("a",{href:`${Ct}?tab=missions`,onClick:I(`${Ct}?tab=missions`),children:"All missions"}),children:n.jsx(Qe,{flush:!0,children:be.length===0?n.jsx(xe,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(ht,{children:be.map(K=>n.jsx(st,{href:K.route,onClick:()=>t(K.route),lead:n.jsx(ln,{agents:s,id:K.agentId,size:"sm"}),title:K.title,sub:`${K.kind} for ${R(K.agentId)}`,side:De(K.at)},K.key))})})}),n.jsx(oe,{title:"Lately",aside:n.jsx("a",{href:xt,onClick:I(xt),children:"All activity"}),children:n.jsx(Qe,{flush:!0,children:re.length===0?n.jsx(xe,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(ht,{children:re.map(K=>n.jsx(st,{href:tt(K.agentId,K.id),onClick:()=>t(tt(K.agentId,K.id)),lead:n.jsx(ln,{agents:s,id:K.agentId,size:"sm"}),title:K.opening?Os(K.opening,80):"Untitled conversation",sub:`${R(K.agentId)}, ${K.messageCount} message${K.messageCount===1?"":"s"}`,side:De(K.lastMessageAt??K.createdAt)},K.id))})})})]}),((C==null?void 0:C.home)??[]).filter(K=>!Y.is(i0(K.id),a0)).map(K=>n.jsx(KV,{block:K,onHide:()=>Y.close(i0(K.id),a0)},K.id)),C!=null&&C.jobs&&C.missions?n.jsxs("p",{className:"home-foot muted",children:[Vt(C.jobs.pending??0)," queued, ",Vt(C.jobs.leased??0)," running, ",Vt(C.missions.enabled)," of ",Vt(C.missions.total)," missions on."," ",C.paused?n.jsx(ve,{tone:"warning",children:"paused"}):n.jsx(ve,{tone:"good",children:"running"})," ",n.jsx("a",{href:ll("").replace(/\/conversations\/$/,""),onClick:I(xt),children:"Activity"})," · ",n.jsx("a",{href:Oe("system"),onClick:I(Oe("system")),children:"System"})]}):null]})]})}const EV={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function AV(e,t){const s=new Set(t.map(r=>r.id));return e.filter(r=>r.needsOwner===!0&&r.kind!=="approval"&&r.kind!=="question"&&r.actedAt===null&&r.state!=="stored"&&r.seenAt===null&&!(r.actionId&&s.has(r.actionId)))}function TV(e){const t=[];for(const s of e.values())s.question&&t.push({agentId:s.agentId,at:s.question.at,route:tt(s.agentId,s.question.conversationId)});return t.sort((s,r)=>s.at.localeCompare(r.at))}const GT="digest",RV=3*864e5;function i0(e){return`block:${e}`}const a0="hidden";function $V(e,t,s){if(s(GT,e.at))return!1;const r=Date.parse(e.at),i=t?Date.parse(t):Date.now();return Number.isFinite(r)&&i-r<RV}function IV(e,t){const[s,r]=h.useState({});return{is:(l,o)=>(s[l]??(e==null?void 0:e[l]))===o,close:(l,o)=>{r(c=>({...c,[l]:o})),E.homeDismiss(l,o).then(t,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function Fa({label:e,onClick:t}){return n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:t,children:n.jsx(ue,{name:"close"})})}const PV=6,MV=500;function DV({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=h.useState(!1),l=h.useRef(null),o=h.useRef(!1),c=()=>{i||(a(!0),E.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:Et(e.agentId,"offers"),onClick:d=>{if(o.current){o.current=!1,d.preventDefault();return}s(d)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},MV)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(ln,{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 OV(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:Et(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:Et(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function LV(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 _V(e,t,s){const r=LV(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 FV(e,t){try{return dr(e?new Date(e):new Date,t,{weekday:!0})}catch{return nt(e??null,t)}}function zV({digest:e,go:t,onClose:s}){var a,l;const r=e.summary??[],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 r.length===0&&i.length===0?null:n.jsx(oe,{title:"What buddi learned this week",aside:n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:De(e.at)}),s?n.jsx(Fa,{label:"Hide until next week",onClick:s}):null]}),children:n.jsx(Qe,{children:n.jsxs(se,{divided:!0,children:[r.length>0?n.jsx("ul",{className:"home-digest-list","data-plain":"",children:r.map(o=>n.jsxs("li",{children:[o.text,o.link?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:o.link.route,onClick:t(o.link.route),children:o.link.label})]}):null]},o.key))}):null,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]})})})}function UV(e,t){const s=t[0];return s?e>1?`${s.title} And ${e-1} more to decide on.`:s.title:`${e} alert${e===1?"":"s"} from your watchers need${e===1?"s":""} a decision.`}const nx="home-needs";function BV(e,t=!1){const s=(i,a,l=`${a}s`)=>i===1?a:l,r=[];return e.approvals>0&&r.push({key:"approvals",count:e.approvals,label:s(e.approvals,"approval")}),e.questions>0&&r.push({key:"questions",count:e.questions,label:s(e.questions,"question")}),e.urgent>0&&r.push({key:"urgent",count:e.urgent,label:s(e.urgent,"urgent alert"),tone:"critical",route:`${xt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${xt}/jobs?state=failed`}),t&&r.push({key:"paused",count:null,label:"Paused",route:`${xt}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:Oe("proposals")}),e.asks>0&&r.push({key:"asks",count:e.asks,label:s(e.asks,"request")}),e.signIns>0&&r.push({key:"signins",count:e.signIns,label:s(e.signIns,"connection to check","connections to check")}),e.agentsToSetUp>0&&r.push({key:"agents",count:e.agentsToSetUp,label:s(e.agentsToSetUp,"agent to set up","agents to set up")}),e.recovery>0&&r.push({key:"recovery",count:null,label:"Restore to finish"}),r}function WV({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(nx))==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(h.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 HV(e){return e.charAt(0).toUpperCase()+e.slice(1)}function KV({block:e,onHide:t}){const[s,r]=h.useState(!1),i=e.sensitive===!0&&!s;h.useEffect(()=>{if(!e.sensitive||!s)return;const l=()=>{document.visibilityState==="hidden"&&r(!1)};return document.addEventListener("visibilitychange",l),window.addEventListener("blur",l),()=>{document.removeEventListener("visibilitychange",l),window.removeEventListener("blur",l)}},[e.sensitive,s]);const a=n.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!i?n.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?n.jsx(T,{size:"sm",variant:"ghost","aria-pressed":!i,onClick:()=>r(l=>!l),children:i?"Show":"Hide"}):null,n.jsx(Fa,{label:`Hide ${e.title} from Home`,onClick:t})]});return n.jsxs(oe,{title:e.title,aside:a,children:[e.note?n.jsx(G,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(Xh,{children:e.stats.map(l=>n.jsx(tr,{label:l.label,value:i?"••••":l.value,note:i?void 0:l.note,tone:i?void 0:l.tone},l.label))}):null,e.rows.length>0?i?n.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):n.jsx(Qe,{flush:!0,children:n.jsx(ht,{children:e.rows.map((l,o)=>n.jsx(st,{title:l.title,sub:l.sub,side:l.side?n.jsx("span",{className:l.tone==="critical"?"critical":l.tone==="good"?"good":void 0,children:l.side}):void 0},`${l.title}-${o}`))})}):null]})}const VV=2e3,GV={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 sx(e){return GV[e.phase]??e.detail??e.phase}const YV=new Set(["done","failed","rolled-back"]);function YT(e){return e!==void 0&&(YV.has(e.phase)||!!e.finishedAt)}function qV(e,t=!1){const[s,r]=h.useState(void 0),[i,a]=h.useState(!1),[l,o]=h.useState(null),c=h.useRef(!1);return h.useEffect(()=>{if(!e){r(void 0),a(!1),c.current=!1;return}let u=!1;const d=()=>{t&&c.current||E.backupJob(e).then(m=>{if(!u){if(t&&(dE({step:sx(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&ol()),c.current){window.location.reload();return}r(m),o(null),YT(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof pe&&m.status!==0&&m.status<500){t&&ol(),o(m.message);return}c.current=!0,t||a(!0)}})};d();const f=window.setInterval(d,VV);return()=>{u=!0,window.clearInterval(f)}},[e,t]),{job:s,away:i,error:l}}function QV({job:e,away:t,error:s}){return s?n.jsx(le,{message:s}):t?n.jsx(G,{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(G,{tone:"critical",role:"alert",children:[sx(e)," ",e.error??""]}):n.jsxs(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:[sx(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function XV(){var v,w,y,N,k,S,C;const e=ce(()=>E.backups(),[],3e4),t=HT(),s=ce(()=>E.service(),[]),[r,i]=h.useState(null),[a,l]=h.useState(!1),o=qV(r,a),[c,u]=h.useState(null),[d,f]=h.useState(!1),[m,p]=h.useState(null),g=((v=e.data)==null?void 0:v.supervised)??((w=s.data)==null?void 0:w.supervised),x=m!==null||g===!1,b=((y=e.data)==null?void 0:y.archives)??[],j=($,R=!1)=>{f(!0),u(null),l(R),$().then(I=>{var U;R&&I.job&&Uh({kind:"restore",patienceMs:uE}),i(((U=I.job)==null?void 0:U.id)??null)}).catch(I=>{I instanceof pe&&I.status===409?p(I.message):u(I instanceof pe?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return h.useEffect(()=>{YT(o.job)&&e.reload()},[(N=o.job)==null?void 0:N.phase]),n.jsxs(se,{gap:"lg",children:[(k=t.data)!=null&&k.active?n.jsx(dV,{view:t.data,onLeft:t.reload}):null,n.jsx(le,{message:e.error??c}),n.jsx(QV,{...o}),n.jsx(ZV,{onSaved:()=>e.reload()}),n.jsx(oe,{title:"Backups",panel:!0,actions:n.jsx(T,{variant:"accent",size:"sm",disabled:d,onClick:()=>j(()=>E.startBackup(!0)),children:"Back up now"}),children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{children:n.jsxs("p",{className:"ui-card-meta",children:["Kept in ",n.jsx("span",{className:"mono",children:((S=e.data)==null?void 0:S.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),n.jsx(oe,{children:e.data&&b.length===0?n.jsx(jn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(js,{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:b.map($=>{var R;return n.jsx(e9,{archive:$,busy:d,database:(R=e.data)==null?void 0:R.database,checkout:x,onVerify:()=>j(()=>E.verifyArchive($.name)),onRestore:(I,U)=>j(()=>E.restoreArchive({name:$.name,...I?{passphrase:I}:{},...U?{confirm:U}:{}}),!0)},$.name)})})]}):n.jsx(xe,{children:"Loading…"})})]})}),n.jsx(t9,{}),n.jsx(n9,{busy:d,checkout:x,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:($,R,I)=>j(()=>E.restoreUpload($,{passphrase:R,confirm:I}),!0)})]})}const JV={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function ZV({onSaved:e}){var p;const t=ce(()=>E.backupSchedule(),[]),[s,r]=h.useState(null),[i,a]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1);h.useEffect(()=>{t.data&&r(t.data)},[t.data]);const d={...JV,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(oe,{title:"Every night",panel:!0,children:n.jsx(oe,{children:n.jsx(G,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...d,...g})},m=()=>{a(!0),o(null),E.setBackupSchedule(d).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof pe?g.message:String(g))).finally(()=>a(!1))};return n.jsx(oe,{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(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:d.enabled,onChange:g=>f({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(Ls,{children:[n.jsx(ie,{label:"At",children:n.jsx("input",{type:"time",value:d.time,onChange:g=>f({time:g.target.value})})}),n.jsx(ie,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:d.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:d.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(ie,{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:d.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(G,{tone:"good",role:"status",children:["Saved.",d.lastRunAt?` Last run ${De(d.lastRunAt)}.`:""]}):null]})})]})})}function e9({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=h.useState(!1),[c,u]=h.useState(""),[d,f]=h.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:De(e.createdAt)}),n.jsx("td",{children:Fn(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(ae,{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(G,{tone:"warning",children:qT}):n.jsx(QT,{what:`${e.name}, taken ${De(e.createdAt)}, ${Fn(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:d,onConfirm:f,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,d)})})}):null]})}const qT="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function QT({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const d=t??"",f=d===""?a.trim()!=="":a.trim()===d;return n.jsxs(se,{gap:"sm",children:[n.jsxs(G,{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(ie,{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(ie,{label:d?`Type ${d} to confirm`:"Type the name of this database to confirm",hint:d?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(ae,{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 t9(){const[e,t]=h.useState(null),[s,r]=h.useState(""),[i,a]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1),d=()=>{a(!0),o(null),E.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))},f=()=>{a(!0),o(null),E.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(oe,{title:"The passphrase",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{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(ae,{align:"end",children:n.jsx(T,{disabled:i,onClick:d,children:"Show it"})}),c?n.jsx(G,{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(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(ie,{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(ae,{align:"end",children:n.jsx(T,{variant:"accent",disabled:i||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function n9({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=h.useState(null),[o,c]=h.useState(""),[u,d]=h.useState(""),[f,m]=h.useState(!1);return t?n.jsx(oe,{title:"Restore from a file",panel:!0,children:n.jsx(oe,{children:n.jsx(G,{tone:"warning",children:s??qT})})}):n.jsx(oe,{title:"Restore from a file",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{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(Ls,{children:[n.jsx(ie,{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(ie,{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(ae,{align:"end",children:n.jsx(T,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),f&&a?n.jsx(oe,{children:n.jsx(QT,{what:`${a.name}, ${Fn(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:d,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const XT="gemini-2.5-pro";function nf(e){return e.replace(/^models\//,"")}const Kj=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function JT(e){const t=e.map(nf);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||Kj.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||Gd(a,s.version)>0||Gd(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 ZT(e){let t;for(const s of e.map(nf)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Kj.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||Gd(i,t.version)>0||Gd(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function eR(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(nf(e))}function s9(e){return[...new Set(e.map(nf).filter(t=>t.startsWith("gemini-")&&!Kj.test(t)))]}function tR(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function Gd(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 nR(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function r9({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=ce(()=>E.providerAccounts(),[]),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(""),[m,p]=h.useState(!1),[g,x]=h.useState(!1),[b,j]=h.useState(t??null);h.useEffect(()=>{t&&j(t)},[t]);const v=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()});h.useEffect(()=>{if(!v)return;const S=setInterval(i,2e3);return()=>clearInterval(S)},[v,i]);const w=async(S,C)=>{o(!0),u(null),f(""),x(!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)??[],N=y.find(S=>S.id===b)??y[0],k=S=>{var C;return nR(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":sR(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(le,{message:r??c}),d&&n.jsx(G,{tone:"good",role:"status",children:d}),g&&n.jsx(G,{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(xe,{children:"Loading accounts…"}),r&&n.jsx(ae,{children:n.jsx(T,{onClick:i,children:"Retry"})}),s&&n.jsxs(n.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&n.jsx(G,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&n.jsx(ft,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(m9,{accounts:y,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),n.jsx(oe,{title:"Accounts",aside:`Secrets live in the ${i9(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(""),x(!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(jn,{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":(N==null?void 0:N.id)===S.id,onClick:()=>j(S.id),children:[n.jsx(a9,{kind:S.kind,auth:S.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:S.label}),Yd(S)?n.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[k(S)," · back at ",Vj(Yd(S).until)]}):n.jsxs("span",{className:"accounts-row-sub",children:[k(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(iR,{account:S})]},S.id))}),N?n.jsx(d9,{account:N,provider:k(N),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${N.id}:${N.revision}`):null]})})]})]})}function i9(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function sR(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":Fj(e)?"mlxh":"OpenAI-compatible"}function rR(e){return e.detectedContextWindowSource==="mlxh"?eK(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function a9({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 l9(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function Yd(e,t=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>t?s:null}const o9=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Vj(e,t=new Date,s=o9()){const r=new Date(e),i=a=>a.toLocaleDateString("en-CA",{timeZone:s});return i(r)===i(t)?Wt(r,s):i(r)===i(new Date(t.getTime()+864e5))?`tomorrow at ${Wt(r,s)}`:Rv(r,s)}function iR({account:e,long:t}){const s=Yd(e);if(s){const a=`Rate-limited until ${Vj(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 c9({id:e}){const[t,s]=h.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 u9({account:e,provider:t}){const s=Yd(e);if(!s)return null;const r=s.provider??t,i=Vj(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(G,{tone:"warning",title:c,action:a.length>0?n.jsx(Nt,{size:"sm",href:a.length===1?Et(a[0],"setup","brain"):Ct,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(G,{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 Gj(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 d9({account:e,provider:t,busy:s,run:r,anthropicOAuthEnabled:i}){const[a,l]=h.useState(!1),[o,c]=h.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(iR,{account:e,long:!0})]}),n.jsx(Bt,{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?"":` (${rR(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:Et(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:Ct,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${nt(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:n.jsx(c9,{id:e.id})}]}),n.jsx(u9,{account:e,provider:t}),e.removalPending&&n.jsx(G,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(G,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(oR,{account:e,enabled:!!i,busy:s,run:r}),e.kind==="codex"&&n.jsx(aR,{account:e,busy:s,run:r}),e.auth==="device-key"&&n.jsx(lR,{account:e,busy:s,run:r}),n.jsxs(ae,{children:[n.jsx(T,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),n.jsx(T,{disabled:s||e.removalPending,onClick:()=>void r(()=>E.saveProviderAccount({...Gj(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(()=>E.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(G,{role:"status",tone:l9(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(ft,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:n.jsx(h9,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&n.jsxs(G,{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(ae,{children:[n.jsx(T,{variant:"danger",disabled:s,onClick:()=>void r(()=>E.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(T,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),n.jsx(yt,{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 aR({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(T,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>E.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(()=>E.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(T,{disabled:t||!e.configured,onClick:()=>void s(()=>E.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(G,{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(Uj,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(ae,{children:n.jsx(Nt,{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 ",Wt(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 h9({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=h.useState((e==null?void 0:e.label)??""),[c,u]=h.useState((e==null?void 0:e.kind)??"anthropic"),[d,f]=h.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=h.useState((e==null?void 0:e.baseUrl)??""),[g,x]=h.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,j]=h.useState(""),[v,w]=h.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=k=>{u(k),f(k==="codex"?"chatgpt":"api-key"),j(""),p(k==="openai-compatible"?"http://localhost:11434/v1":""),x(k==="anthropic"?"claude-sonnet-5":k==="openai"?"gpt-5":"")},N=!l.trim()||!g.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:k=>{k.preventDefault();const S=b;j(""),s(()=>E.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:d,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:v.trim()?Number(v):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ie,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:k=>o(k.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(ie,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:d==="anthropic-oauth"?"anthropic-oauth":d==="device-key"?"ollama-cloud":c,onChange:k=>{k.target.value==="anthropic-oauth"?(y("anthropic"),f("anthropic-oauth")):y(k.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&d!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(ie,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:k=>p(k.target.value)})}),n.jsx(ie,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:d,onChange:k=>{f(k.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(ae,{valign:"end",children:n.jsx(zj,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:x,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(ie,{label:"Context window",hint:Fj(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${rR(e)})`:"assumed from the model",onChange:k=>w(k.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),d==="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."}),d==="api-key"&&n.jsx(ie,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:k=>j(k.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:r,children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",disabled:N,children:"Save account"})]})]}),N&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function lR({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=h.useRef(s);i.current=s,h.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const d=setInterval(()=>{c||u||(u=!0,E.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(d)}},[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 E.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(ae,{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 E.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(G,{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&&Wt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function oR({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,d;const[i,a]=h.useState("");return h.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(G,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(ae,{children:[n.jsx(T,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>E.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(()=>E.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(()=>E.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((d=e.login)==null?void 0:d.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=i;a(""),r(()=>E.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&&Wt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),n.jsx(ie,{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(ae,{align:"end",children:n.jsx(T,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const Im={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function Pm(e,t,s){return rx(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 rx(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 f9="That key was refused. Check it and paste it again.";function m9({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(re=>re.label),[c,u]=h.useState(null),[d,f]=h.useState("anthropic"),[m,p]=h.useState("api-key"),[g,x]=h.useState(()=>Pm("anthropic","api-key",o)),[b,j]=h.useState(!1),[v,w]=h.useState(""),[y,N]=h.useState(""),[k,S]=h.useState(null),[C,$]=h.useState(!1),[R,I]=h.useState(""),[U,z]=h.useState(""),[A,P]=h.useState(!1),[D,O]=h.useState(!1),[M,W]=h.useState(!1),[L,q]=h.useState(void 0),B=(re,Ee,me=!1)=>{f(re),p(Ee),N(""),S(null),I(""),z(""),P(!1),O(me),W(!1),q(void 0),w(me?"":re==="openai-compatible"?"http://localhost:11434/v1":""),b||x(me?Pm(re,"device-key",o):Pm(re,Ee,o))},V=re=>{B("openai-compatible",re?"api-key":"device-key",!0),re&&E.ollama().then(Ee=>w(Ee.cloudBaseUrl)).catch(()=>{})},F=()=>{l&&(B("openai-compatible","api-key"),W(!0),w(l.baseUrl),b||x(rx("Gemini",o)))},X=()=>{B("openai-compatible","none"),q(null),b||x(rx("mlxh",o)),E.mlxh().then(re=>{q(re),w(re.baseUrl)}).catch(()=>q(void 0))},Y=L!==void 0,Z=c?e.find(re=>re.id===c):void 0;if(c)return Z?n.jsx(p9,{account:Z,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(Z.id)}):n.jsx(xe,{children:"Saving…"});const he=d==="openai-compatible"&&m!=="device-key",Le=d==="codex"||m==="anthropic-oauth"||m==="device-key",Ie=!Le&&(m==="none"||y.trim()!=="")&&(!he||v.trim()!==""),ze=async()=>{var re,Ee;$(!0),I("");try{const me=await E.probeModels({kind:d,auth:m,...he?{baseUrl:v}:{},...y.trim()?{secret:y}:{}});S(me),U||z(((re=me.models.find(Re=>Re.isDefault))==null?void 0:re.id)??((Ee=me.models[0])==null?void 0:Ee.id)??"")}catch(me){I(me instanceof Error?me.message:"Could not load models. You can still enter a custom model.")}finally{$(!1)}},ee=U.trim(),be=!g.trim()||he&&!v.trim()||he&&!M&&!Y&&!ee||M&&!y.trim()||Y&&!(L!=null&&L.running);return n.jsxs("form",{className:"ui-stack",onSubmit:re=>{var Se;re.preventDefault();const Ee=y;N("");let me=ee||(Y?Zg(L)??((Se=L==null?void 0:L.models[0])==null?void 0:Se.id):void 0)||(m==="device-key"?Ku:Im[d])||"claude-sonnet-5",Re;(async()=>{if(M){me=XT;try{const it=(await E.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:Ee})).models.map(qe=>qe.id);me=JT(it)??me,Re=eR(me)?ZT(it):void 0}catch{}}let Ue,et=!1;!await s(async()=>{if(Ue=await E.saveProviderAccount({label:g,kind:d,auth:m,baseUrl:v,defaultModel:me,enabled:!0,...Ee.trim()?{secret:Ee}:{}}),m!=="api-key")return Ue;const Be=await E.testProviderAccount(Ue.id);if(Be.state==="connected")return Ue;if(Pv(Be)){const it=Ue.id;Ue=void 0;try{const qe=(await E.providerAccounts()).accounts.find(J=>J.id===it);qe&&await E.removeProviderAccount(it,qe.revision)}catch{}throw new Error(f9)}if(M&&Re&&tR(Be)){const it=(await E.providerAccounts()).accounts.find(qe=>qe.id===Ue.id);if(it&&(await E.saveProviderAccount({...Gj(it),defaultModel:Re}),(await E.testProviderAccount(Ue.id)).state==="connected"))return{...Ue,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 et=!0,{...Ue,warning:`Account saved. ${Be.message}`}},"Account saved.")||!Ue||(M||Y||et?u(Ue.id):ee||!Le?r(Ue.id):u(Ue.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ie,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":D?"ollama-cloud":M?"gemini":Y?"mlxh":d,onChange:re=>{if(re.target.value==="anthropic-oauth")B("anthropic","anthropic-oauth");else if(re.target.value==="gemini")F();else if(re.target.value==="mlxh")X();else if(re.target.value==="ollama-cloud")B("openai-compatible","device-key",!0);else{const Ee=re.target.value;B(Ee,Ee==="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(ie,{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:re=>{x(re.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),D&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:re=>V(re.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),he&&n.jsxs(n.Fragment,{children:[n.jsx(ie,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:v,onChange:re=>{w(re.target.value),S(null)}})}),!M&&!Y&&n.jsx(ie,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:re=>{p(re.target.value),N(""),S(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(ie,{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:re=>{N(re.target.value),S(null)}})}),Y?L===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):L!=null&&L.running?n.jsxs(se,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",L.models.length===1?"one model":`${L.models.length} models`,". No key: mlxh takes any. buddi starts on ",Zg(L)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),L.models.some(re=>re.kind==="image")?n.jsxs("p",{className:"muted",children:[L.models.filter(re=>re.kind==="image").map(re=>re.id).join(", "),": ",TT,"."]}):null]}):n.jsx(G,{tone:"warning",children:AT((L==null?void 0:L.baseUrl)??v)}):M&&l?n.jsxs("p",{className:"muted",children:[n.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):Le?n.jsx("p",{className:"muted",children:d==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),k?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:A?"__custom__":U,onChange:re=>{re.target.value==="__custom__"?(P(!0),z("")):(P(!1),z(re.target.value))},children:[k.models.map(re=>n.jsxs("option",{value:re.id,children:[re.name===re.id?re.id:`${re.name} — ${re.id}`,re.isDefault?" (provider default)":"",re.thinks?" · thinks":""]},re.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(T,{size:"sm",disabled:C||!Ie,onClick:()=>void ze(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(T,{disabled:C||!Ie,onClick:()=>void ze(),children:C?"Loading models…":"Load models"}),he?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",Im[d]," is used until you pick one."]})]}),A||he&&!k?n.jsx("input",{"aria-label":"Custom model",required:he,maxLength:150,value:U,onChange:re=>z(re.target.value),placeholder:he?"qwen3:8b":Im[d]}):null,R?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:R}):null,k!=null&&k.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:()=>r(),children:"Cancel"}),n.jsx(T,{type:"submit",variant:"accent",disabled:be,children:"Save account"})]})]}),be&&!Y&&n.jsxs("p",{className:"muted",children:["Enter an account name",M?" and a key":he?", an endpoint and a model":""," to enable Save account."]})]})}function p9({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=h.useState(e.defaultModel),o=e.configured;return n.jsxs(se,{gap:"lg",children:[n.jsxs(G,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(oR,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(aR,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(lR,{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(ae,{valign:"end",children:n.jsx(zj,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(ae,{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(()=>E.saveProviderAccount({...Gj(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(ae,{children:n.jsx(T,{onClick:i,children:"Finish later"})})]})}const l0=new Set(["co.uk","org.uk","me.uk","ltd.uk","plc.uk","net.uk","sch.uk","ac.uk","gov.uk","nhs.uk","police.uk","mod.uk","gov.ie","co.at","or.at","ac.at","gv.at","com.pl","net.pl","org.pl","info.pl","biz.pl","edu.pl","gov.pl","waw.pl","com.es","org.es","nom.es","gob.es","edu.es","com.pt","org.pt","gov.pt","edu.pt","com.gr","org.gr","net.gr","edu.gr","gov.gr","com.cy","org.cy","net.cy","gov.cy","ac.cy","com.mt","org.mt","net.mt","edu.mt","gov.mt","co.hu","org.hu","info.hu","com.ro","org.ro","info.ro","nom.ro","co.rs","org.rs","edu.rs","gov.rs","in.rs","com.ua","org.ua","net.ua","gov.ua","edu.ua","in.ua","kiev.ua","com.ru","org.ru","net.ru","msk.ru","spb.ru","co.no","priv.no","com.hr","from.hr","iz.hr","name.hr","co.it","gov.it","edu.it","asso.fr","com.fr","gouv.fr","nom.fr","prd.fr","tm.fr","co.je","net.je","org.je","co.gg","net.gg","org.gg","co.im","net.im","org.im","gc.ca","on.ca","qc.ca","bc.ca","ab.ca","com.mx","org.mx","net.mx","edu.mx","gob.mx","ny.us","ca.us","tx.us","fl.us","wa.us","k12.ca.us","lib.ca.us","com.br","net.br","org.br","gov.br","edu.br","art.br","blog.br","eco.br","emp.br","ind.br","inf.br","tv.br","app.br","dev.br","com.ar","org.ar","net.ar","gob.ar","edu.ar","int.ar","tur.ar","com.co","org.co","net.co","edu.co","gov.co","nom.co","com.pe","org.pe","net.pe","gob.pe","edu.pe","nom.pe","com.ve","org.ve","net.ve","gob.ve","co.ve","com.uy","org.uy","net.uy","gub.uy","edu.uy","com.ec","org.ec","net.ec","gob.ec","edu.ec","fin.ec","com.bo","org.bo","net.bo","gob.bo","edu.bo","com.py","org.py","net.py","gov.py","edu.py","gob.cl","gov.cl","co.cl","com.do","org.do","net.do","gob.do","edu.do","com.gt","org.gt","net.gt","gob.gt","edu.gt","co.cr","or.cr","fi.cr","go.cr","ac.cr","com.pa","org.pa","net.pa","gob.pa","com.sv","org.sv","gob.sv","edu.sv","com.ni","org.ni","gob.ni","com.hn","org.hn","net.hn","gob.hn","com.cu","org.cu","net.cu","gob.cu","com.jm","org.jm","net.jm","gov.jm","com.tt","org.tt","net.tt","gov.tt","co.tt","com.pr","org.pr","net.pr","gov.pr","com.au","net.au","org.au","edu.au","gov.au","asn.au","id.au","co.nz","net.nz","org.nz","ac.nz","govt.nz","school.nz","geek.nz","gen.nz","kiwi.nz","maori.nz","co.jp","ne.jp","or.jp","ac.jp","ad.jp","ed.jp","go.jp","gr.jp","lg.jp","com.cn","net.cn","org.cn","gov.cn","edu.cn","ac.cn","com.hk","net.hk","org.hk","edu.hk","gov.hk","idv.hk","com.tw","net.tw","org.tw","edu.tw","gov.tw","idv.tw","co.kr","or.kr","ne.kr","go.kr","ac.kr","re.kr","pe.kr","co.in","net.in","org.in","firm.in","gen.in","ind.in","ac.in","edu.in","gov.in","res.in","nic.in","com.sg","net.sg","org.sg","edu.sg","gov.sg","per.sg","com.my","net.my","org.my","edu.my","gov.my","name.my","co.id","or.id","ac.id","go.id","web.id","my.id","biz.id","net.id","sch.id","co.th","in.th","ac.th","go.th","or.th","net.th","com.vn","net.vn","org.vn","edu.vn","gov.vn","com.ph","net.ph","org.ph","edu.ph","gov.ph","com.pk","net.pk","org.pk","edu.pk","gov.pk","com.bd","org.bd","net.bd","gov.bd","edu.bd","com.lk","org.lk","gov.lk","edu.lk","com.np","org.np","gov.np","edu.np","com.kh","org.kh","gov.kh","com.mm","org.mm","gov.mm","com.fj","org.fj","gov.fj","ac.fj","com.pg","org.pg","gov.pg","ac.pg","com.kz","org.kz","gov.kz","edu.kz","com.tr","net.tr","org.tr","gov.tr","edu.tr","gen.tr","biz.tr","info.tr","av.tr","bel.tr","k12.tr","co.il","org.il","net.il","ac.il","gov.il","muni.il","com.sa","net.sa","org.sa","gov.sa","edu.sa","med.sa","co.ae","net.ae","org.ae","gov.ae","ac.ae","com.qa","org.qa","net.qa","gov.qa","edu.qa","com.kw","org.kw","net.kw","gov.kw","edu.kw","com.bh","org.bh","net.bh","gov.bh","edu.bh","com.om","org.om","net.om","gov.om","co.om","com.jo","org.jo","net.jo","gov.jo","edu.jo","com.lb","org.lb","net.lb","gov.lb","edu.lb","com.eg","org.eg","net.eg","gov.eg","edu.eg","eun.eg","co.ir","ac.ir","gov.ir","org.ir","net.ir","co.za","org.za","net.za","gov.za","ac.za","web.za","edu.za","nom.za","com.ng","org.ng","net.ng","gov.ng","edu.ng","name.ng","co.ke","or.ke","ne.ke","go.ke","ac.ke","sc.ke","co.tz","or.tz","ne.tz","go.tz","ac.tz","co.ug","or.ug","ne.ug","go.ug","ac.ug","com.gh","org.gh","gov.gh","edu.gh","co.ma","net.ma","org.ma","gov.ma","ac.ma","press.ma","com.tn","org.tn","gov.tn","ens.tn","fin.tn","com.dz","org.dz","net.dz","gov.dz","edu.dz","com.et","org.et","gov.et","edu.et","co.zw","org.zw","gov.zw","ac.zw","co.zm","org.zm","gov.zm","ac.zm","co.bw","org.bw","ac.bw","com.na","org.na","co.na","co.mz","org.mz","gov.mz","com.cm","co.cm","net.cm","gov.cm","com.sn","org.sn","edu.sn","gouv.sn","com.ci","co.ci","or.ci","go.ci","ac.ci","com.tg","gouv.tg","co.rw","gov.rw","ac.rw","*.ck","*.er","*.fk","*.jm","*.kh","*.mm","*.np","*.pg","*.bd","github.io","githubusercontent.com","gitlab.io","bitbucket.io","pages.dev","workers.dev","trycloudflare.com","vercel.app","vercel.dev","now.sh","netlify.app","netlify.com","herokuapp.com","herokussl.com","cloudfront.net","amazonaws.com","s3.amazonaws.com","elasticbeanstalk.com","awsapprunner.com","amplifyapp.com","azurewebsites.net","azurestaticapps.net","cloudapp.net","azureedge.net","azurefd.net","blob.core.windows.net","trafficmanager.net","appspot.com","firebaseapp.com","web.app","run.app","cloudfunctions.net","blogspot.com","fly.dev","onrender.com","up.railway.app","deno.dev","deno.net","glitch.me","repl.co","replit.dev","replit.app","ngrok.io","ngrok.app","ngrok-free.app","ngrok.dev","ngrok-free.dev","surge.sh","readthedocs.io","myshopify.com","wixsite.com","webflow.io","framer.app","framer.website","ondigitalocean.app","digitaloceanspaces.com","supabase.co","fastly.net","global.ssl.fastly.net","edgecompute.app","duckdns.org","dyndns.org","ddns.net","no-ip.org","hopto.org","zapto.org","eu.org","us.org","neocities.org","codeberg.page","sourceforge.io","pythonanywhere.com","streamlit.app","hf.space"]);function g9(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||l0.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return l0.has(`*.${s}`)}function x9(e){return typeof e=="string"&&e.includes("*")}function v9(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"}:g9(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const o0=["every-time","first-time","pre-approved"];function cR(e){const t=o0.indexOf(e);return o0.slice(0,t<0?1:t+1)}function ha(e){return e.endsWith(".account")}const j9="Stored, not usable until it has a binding.";function w9(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":ha(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const uR={"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})}},y9="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",b9=e=>`That is a public suffix; ${e} would match every site.`,c0="Give the site as an origin, like https://en.wikipedia.org.";function u0(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(x9(e)){const s=v9(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:y9};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:b9(r)}}return{ok:!1,error:c0}}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:c0}}}function k9(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 N9(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 u0(s);if(e==="browser.native.type"||ha(e))return{ok:!0,target:s};const r=uR[e];if(r===void 0)return{ok:!0,target:s};const i=k9(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=u0(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 S9(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function dR(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=uR[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 Dl="accounts.provider";function hR(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 fR(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 C9(e){const t=hR(e,"found");return t.length?`The value already sits in ${fR(t)}.`:""}function E9(e){const t=hR(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${fR(t)}.`:""}const A9=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,T9=/^MCP_(TOKEN|ENV|CONNECTION)_/,mR="GMAIL_APP_PASSWORD";function Br(e){const t=e.usedBy??[],s=e.bindings.map(r=>r.kind);if(t.some(r=>r.kind==="mailbox")||s.includes("email.account")||e.name===mR)return"mail";if(t.some(r=>r.kind==="model-account")||s.includes(Dl)||A9.test(e.name))return"models";if(t.some(r=>r.kind==="connection")||s.includes("mcp.env")||T9.test(e.name))return"connections";for(const r of e.bindings){if(r.kind==="http.url"&&Yj(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(ha(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function R9(e){if(e==="mine")return{title:"Your secrets",aside:"Agents fill these where you allow, without seeing them."};if(e==="mail")return{title:"Mail",aside:"Mailbox passwords. A new one is set on the Email page, which tests it first."};if(e==="models")return{title:"Model accounts",aside:"Managed in Model accounts."};if(e==="connections")return{title:"Connections",aside:"Managed in Connections."};const t=e.slice(7);return t==="calendar"?{title:"Calendar links",aside:"Private links, fetched only by the calendar plugin."}:{title:t.charAt(0).toUpperCase()+t.slice(1),aside:`Kept for the ${t} plugin.`}}function $9(e,t){const s=r=>r==="mine"?0:r==="mail"?1:r==="models"?3:r==="connections"?4:2;return s(e)-s(t)||e.localeCompare(t)}function pR(e){return e==="models"||e==="connections"}function Yj(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function d0(e){const t=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return t.startsWith("*.")?`any ${t.slice(2)} site`:t}const qj=e=>(e.usedBy??[]).flatMap(t=>t.kind==="mailbox"?[t]:[]),sf=e=>(e.usedBy??[]).find(t=>t.kind==="model-account"),Qj=e=>(e.usedBy??[]).find(t=>t.kind==="connection");function So(e,t=new Map){var r,i;const s=Br(e);if(s==="mail"){const a=qj(e)[0];return a?`${a.provider==="Email"?"Mailbox":a.provider} ${a.auth==="xoauth2"?"sign-in":"app password"}`:"Old mailbox password"}if(s==="models"){const a=sf(e),l=(a==null?void 0:a.id)??((r=e.bindings.find(c=>c.kind===Dl&&typeof c.target=="string"))==null?void 0:r.target),o=typeof l=="string"?t.get(l):void 0;return(o==null?void 0:o.label)??(a==null?void 0:a.label)??"Old model account key"}if(s==="connections")return((i=Qj(e))==null?void 0:i.name)??"Old connection sign-in";if(s.startsWith("plugin:")){const a=/^[^:]{1,40}:\s+(.+)$/.exec(e.name);return a?a[1]:e.name}return e.name}function I9(e,t){var r,i,a;if(Br(e)!=="models")return null;const s=((r=sf(e))==null?void 0:r.id)??((i=e.bindings.find(l=>l.kind===Dl&&typeof l.target=="string"))==null?void 0:i.target);return typeof s=="string"?((a=t.get(s))==null?void 0:a.provider)??null:null}function gR(e,t){const s=Yj(t)?t:{},r=i=>typeof s[i]=="string"?s[i]:"";return e==="browser.field"&&typeof t=="string"?`Filled on ${d0(t)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${d0(r("origin"))}`:e==="browser.native.type"&&typeof t=="string"?`Typed into the app ${t}`:(e==="http.header"||e==="http.url")&&r("host")?`Sent only to ${r("host")}`:e==="developer.env"&&r("variable")?`Given to ${r("workspace")} as ${r("variable")}`:e==="mcp.env"&&r("variable")?`Given to a program as ${r("variable")}`:e==="email.account"?"Used by a mailbox":e===Dl?"Used by a model account":ha(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${dR(e,t)}`}function P9(e,t){return ha(e)||e===Dl?"Signed in":gR(e,t).replace(/^Sent only to/,"Sent to")}const M9={"api-key":"API key for this model account",chatgpt:"ChatGPT sign-in for this model account","anthropic-oauth":"Claude sign-in for this model account","device-key":"Ollama device key for this model account"};function D9(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Xj(e){const t=Br(e);if(t==="mail"){const a=qj(e).map(l=>l.address);return a.length?`Used by the ${a.length===1?"mailbox":"mailboxes"} ${D9(a)}`:e.name===mR?"From the old .env setup":"No mailbox uses it"}if(t==="models"){const a=sf(e);return a?M9[a.auth]??"Key for this model account":"No model account uses it"}if(t==="connections"){const a=Qj(e);if(a!=null&&a.variable)return`Given to the program as ${a.variable}`;const l=e.bindings.find(c=>c.kind==="http.header"),o=l&&Yj(l.target)&&typeof l.target.host=="string"?l.target.host:null;return o?`Sign-in token · sent only to ${o}`:a?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=e.bindings.map(a=>gR(a.kind,a.target));let r=s.length<=2?s.join(" · "):`${s[0]} and ${s.length-1} more places`;const i=new Set(e.bindings.map(a=>a.rule==="first-time"&&a.firstApprovedAt!==null?"pre-approved":a.rule));return i.size===1&&i.has("every-time")&&(r+=" · asks you every time"),i.size===1&&i.has("first-time")&&(r+=" · asks you the first time"),e.totp&&(r+=" · a fresh code each time"),r}function O9(e,t=Date.now()){return e.lastUse?`Last used ${De(e.lastUse.at,t)}`:"Never used"}function ix(e){return gi("email","settings",{account:e,set:"password"})}function xR(e){var s,r;const t=Br(e);if(t==="models"){const i=(s=sf(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:i?sE(i):Oe("accounts")}}if(t==="connections"){const i=(r=Qj(e))==null?void 0:r.id;return{label:"Managed in Connections",href:i?rE(i):Oe("connections")}}return null}function vR(e){const t=/is not bound to (.+?)\.?$/.exec(e);if(!t)return null;const s=t[1];return/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(s)?null:s}function jR(e,t=Date.now()){if(e.unused)return null;const s=Br(e),r=qj(e)[0],i=xR(e),a=()=>r?{label:"Set password",href:ix(r.id)}:i?{label:s==="models"?"Fix in Model accounts":"Fix in Connections",href:i.href}:{label:"Set a value",action:"replace"},l=e.lastUse,o=l?De(l.at,t):"",c=(l==null?void 0:l.detail)??"";if(e.hasValue===!1||(l==null?void 0:l.outcome)==="refused"&&/has no value stored/.test(c))return{text:"No value stored.",fix:a()};if(r!=null&&r.loginFailedAt)return{text:`${r.provider==="Email"?"The mail server":r.provider} turned it down at sign-in ${De(r.loginFailedAt,t)}.`,fix:{label:"Set password",href:ix(r.id)}};if((l==null?void 0:l.outcome)==="refused"){if(/vault is locked/.test(c))return{text:`Held back ${o}: the vault was locked.`,fix:null};if(/TOTP secret/.test(c))return{text:`Held back ${o}: a one-time code goes only into a field on a website.`,fix:null};if(/is not bound to/.test(c)){const u=s==="mine"?vR(c):null;return{text:u?`Held back ${o}: it was asked for at ${u}, where it may not go.`:`Held back ${o}: it was asked for somewhere it may not go.`,fix:s==="mine"?{label:"Change where it may go",action:"places"}:null}}return{text:`Held back ${o}: ${yR(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const u=r?a():i?null:{label:"Replace value",action:"replace"};return{text:`Didn’t go through ${o}${c?`: ${c.replace(/\.$/,"")}`:""}.`,fix:u}}return(l==null?void 0:l.outcome)==="pending"?{text:`Waiting for your approval since ${o}.`,fix:{label:"Review",href:Fh}}:s==="mine"&&e.bindings.length===0?{text:"Can’t be used anywhere until you choose where it may go.",fix:{label:"Choose where it may go",action:"places"}}:null}function wR(e){if(!e.unused)return"";const t=Br(e);return t==="mail"?"Not used by anything — no mailbox uses it any more.":t==="models"?"Not used by anything — no model account uses it any more.":t==="connections"?"Not used by anything — no connection uses it any more.":"Not used by anything — what it was for is gone."}function ax(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function za(e){return!!e.unused&&!pR(Br(e))}function L9(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const t=Xj(e).split(" · ")[0]??"";return t.startsWith("Filled on ")?`Agents can no longer fill it on ${t.slice(10)}.`:t.startsWith("Sent only to ")?`Agents can no longer send it to ${t.slice(13)}.`:`Whatever uses it stops working: ${t.charAt(0).toLowerCase()}${t.slice(1)}.`}const _9={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function F9(e){const t={"browser.field":"A field on a website","browser.form.data":"A form field, by its name","browser.native.type":"An app on this computer","http.header":"A request to a host","http.url":"A plugin’s web address","developer.env":"A workspace variable","mcp.env":"A program’s variable",[Dl]:"A model account"};return t[e]?t[e]:ha(e)?`A ${e.slice(0,-8)} account`:e}const z9={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function yR(e){if(!e)return"buddi didn’t hand it over";if(/has no value stored/.test(e))return"no value was stored";if(/vault is locked/.test(e))return"the vault was locked";if(/TOTP secret/.test(e))return"a one-time code goes only into a field on a website";const t=/is not bound to/.test(e)?vR(e):void 0;return t!==void 0?t?`asked for at ${t}, where it may not go`:"asked for somewhere it may not go":e.replace(/\.$/,"")}function U9(e){return e==="browser.field"?"www.pnc.com":e==="browser.form.data"?"www.pnc.com card-number":e==="browser.native.type"?"com.bank.app":e==="http.header"?"api.github.com Authorization":e==="http.url"?"calendar calendar.google.com":e==="developer.env"?"my-app ADMIN_PASSWORD":ha(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function qd(e){return cR(e).includes("first-time")?"first-time":e}function B9(e){const t=P9(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${yR(e.detail)}`,tone:"warning"}:e.outcome==="failed"?{text:`Didn’t go through — ${(e.detail??t).replace(/\.$/,"")}`,tone:"warning"}:e.outcome==="pending"?{text:`Asked for your approval · ${t}`}:{text:t}}async function na(e,t,s,r){s(!0),r(null);try{return(await E.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}const bR="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function W9(e,t){if(t==="mail")return"mail";if(t==="models")return"chip";if(t==="connections")return"plug";if(t==="plugin:calendar")return"calendar";const s=e.bindings.map(r=>r.kind);return s.some(r=>r.startsWith("browser."))?"globe":s.includes("developer.env")?"terminal":"key"}function H9({embedded:e,timezone:t,secret:s,adding:r,navigate:i}={}){const a=ce(()=>E.secrets(),[]),l=ce(()=>E.providerAccounts(),[]),o=h.useMemo(()=>{var g;return new Map((((g=l.data)==null?void 0:g.accounts)??[]).map(x=>[x.id,{label:x.label,provider:sR(x)}]))},[l.data]),[c,u]=h.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);h.useEffect(()=>{s&&u({what:"replace",name:s})},[s]),h.useEffect(()=>{r&&u({what:"add"})},[r]);const d=()=>{u(null),(s||r)&&i&&i(Oe("secrets"))},f=a.data,m=h.useMemo(()=>{const g=new Map;for(const x of(f==null?void 0:f.secrets)??[]){const b=Br(x);g.set(b,[...g.get(b)??[],x])}return[...g.entries()].sort(([x],[b])=>$9(x,b))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(g=>g.name===c.name))??null:null;return n.jsxs(An,{embedded:e,title:"Keys and secrets",lede:bR,actions:e?void 0:n.jsx(T,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[n.jsxs(se,{gap:"lg",children:[!f&&!a.error?n.jsx(xe,{children:"Opening the vault…"}):null,a.error?n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:a.error}),n.jsx(ae,{children:n.jsx(T,{onClick:a.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?n.jsx(Qe,{children:n.jsx(jn,{icon:"lock",title:"Nothing stored yet.",children:"Add a site password or an API token, and say where an agent may use it. Mailbox passwords and calendar links show up here as you add them."})}):null,f&&f.secrets.length>0?n.jsx(Qe,{flush:!0,children:m.map(([g,x])=>{const b=R9(g);return n.jsxs("section",{className:"secrets-group","aria-label":b.title,children:[n.jsxs("header",{className:"secrets-group-head",children:[n.jsx("h3",{className:"secrets-group-title",children:b.title}),n.jsx("span",{className:"secrets-group-aside",children:b.aside})]}),n.jsx(ht,{children:x.map(j=>n.jsx(V9,{secret:j,group:g,accounts:o,onOpen:v=>u({what:v,name:j.name})},j.name))})]},g)})}):null,f&&f.ownKeys.length>0?n.jsx(yt,{summary:`buddi’s own keys · ${f.ownKeys.length}`,children:n.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",f.ownKeys.map((g,x)=>n.jsxs("span",{children:[x>0?", ":"",n.jsx("code",{className:"mono",children:g})]},g)),". They aren’t changed here, and buddi hides them in whatever it sends out, like your own."]})}):null]}),(c==null?void 0:c.what)==="add"&&f?n.jsx(q9,{destinations:f.destinations,onClose:d,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?n.jsx(G9,{secret:p,accounts:o,timezone:t,onClose:d,onOpen:g=>u({what:g,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?n.jsx(Q9,{secret:p,title:So(p,o),onClose:d,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="rename"?n.jsx(X9,{secret:p,onClose:d,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?n.jsx(J9,{secret:p,title:So(p,o),destinations:f.destinations,onClose:d,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="delete"?n.jsx(Z9,{secret:p,title:So(p,o),onClose:d,onChanged:a.reload}):null]})}const Qd=e=>t=>{t.stopPropagation(),e==null||e()};function kR({fix:e,onOpen:t}){return"href"in e?n.jsx(Nt,{size:"sm",href:e.href,onClick:Qd(),children:e.label}):n.jsx(T,{size:"sm",onClick:Qd(()=>t(e.action)),children:e.label})}function K9(e,t,s){if(t==="mine")return[{label:"Replace value…",onSelect:()=>s("replace")},{label:"Rename…",onSelect:()=>s("rename")},{label:"Change where it may go…",hint:"Places, and when it asks",onSelect:()=>s("places")},{label:"Usage history",onSelect:()=>s("sheet")},"separator",{label:"Delete…",tone:"critical",onSelect:()=>s("delete")}];if(t==="mail"){const r=(e.usedBy??[]).find(i=>i.kind==="mailbox");return[r&&!e.unused?{label:"Set a new password",hint:"On the Email page, which tests it first",onSelect:()=>{window.location.hash=ix(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},za(e)?"separator":null,za(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}return[{label:t==="plugin:calendar"?"Replace link…":"Replace value…",onSelect:()=>s("replace")},{label:"Usage history",onSelect:()=>s("sheet")},za(e)?"separator":null,za(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function V9({secret:e,group:t,accounts:s,onOpen:r}){const i=So(e,s),a=I9(e,s),l=[Xj(e),O9(e)].filter(Boolean).join(" · "),o=jR(e),c=wR(e),u=ax(e),d=pR(t)?xR(e):null;return n.jsx(st,{onClick:()=>r("sheet"),label:`${i}: details`,lead:n.jsx(_r,{icon:W9(e,t)}),title:n.jsxs(n.Fragment,{children:[i,a?n.jsx("span",{className:"secrets-tag",children:a}):null]}),sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"secrets-line",children:l}),o?n.jsx("span",{className:"secrets-status","data-tone":"warning",children:o.text}):null,c?n.jsx("span",{className:"secrets-status",children:c}):null,u?n.jsx("span",{className:"secrets-status",children:u}):null]}),side:n.jsxs("span",{className:"secrets-side",children:[o!=null&&o.fix?n.jsx(kR,{fix:o.fix,onOpen:r}):null,c&&za(e)?n.jsx(T,{size:"sm",variant:"ghost",onClick:Qd(()=>r("delete")),children:"Remove…"}):null,d?n.jsxs("a",{className:"secrets-managed",href:d.href,onClick:Qd(),children:[d.label,n.jsx(ue,{name:"chevron-right",size:12})]}):n.jsx(Al,{label:`More for ${i}`,items:K9(e,t,r),sheet:{title:i,sub:l}})]})})}function G9({secret:e,accounts:t,timezone:s,onClose:r,onOpen:i}){const a=Br(e),l=So(e,t),o=jR(e),c=wR(e),u=[...new Set(e.bindings.map(m=>m.rule))],d=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:n.jsx("code",{className:"mono secrets-mono",children:m.id})}));return n.jsx(ft,{title:l,onClose:r,foot:a==="mine"?n.jsxs(ae,{children:[n.jsx(T,{variant:"danger-ghost",onClick:()=>i("delete"),children:"Delete…"}),n.jsx(Dt,{}),n.jsx(T,{onClick:()=>i("rename"),children:"Rename…"}),n.jsx(T,{variant:"accent",onClick:()=>i("replace"),children:"Replace value…"})]}):void 0,children:n.jsxs(se,{gap:"lg",children:[n.jsx(Bt,{items:[{label:"Where it may go",value:Xj(e)||"Nowhere yet"},...u.length===1&&a==="mine"?[{label:"Asks you",value:_9[u[0]]}]:[],{label:"Last used",value:d?`${De(d.at)}${d.agentId?` by ${d.agentId}`:""}`:"Never"}]}),o?n.jsx(G,{tone:"warning",action:o.fix?n.jsx(kR,{fix:o.fix,onOpen:i}):void 0,children:o.text}):null,c?za(e)?n.jsxs(G,{action:n.jsx(T,{size:"sm",onClick:()=>i("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):n.jsx(G,{children:c}):null,ax(e)?n.jsx(G,{children:ax(e)}):null,n.jsxs(se,{gap:"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),n.jsx(Y9,{name:e.name,timezone:s})]}),n.jsx(yt,{summary:"Details",children:n.jsxs(se,{gap:"sm",children:[n.jsx(Bt,{items:[{label:"Stored as",value:n.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:n.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",dR(m.kind,m.target)," · ",m.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...f]}),n.jsx("p",{className:"secrets-note",children:"What buddi keeps for it, never the value. “Held back” means buddi declined to hand the value over — not bound to that place, no value stored, or the vault locked — so it never left."})]})})]})})}function Y9({name:e,timezone:t}){const s=ce(()=>E.secretUses(e,50),[e]);if(s.error)return n.jsx(le,{message:s.error});if(!s.data)return n.jsx(xe,{children:"Reading the history…"});const r=s.data.uses;return r.length===0?n.jsx("p",{className:"secrets-note",children:"Nothing has used it yet."}):n.jsx(ht,{children:r.map((i,a)=>{const l=B9(i);return n.jsx(st,{title:n.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${nt(i.at,t??"UTC")} · ${i.agent??(i.plugin?`the ${i.plugin} plugin`:"you")}`},a)})})}function NR({title:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a}){const l=C9(t);return n.jsxs(se,{gap:"sm",children:[n.jsxs(G,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),n.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),n.jsx(le,{message:i}),l?n.jsx(ae,{children:n.jsx(T,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":E9(s)||"Nothing of it was left to replace."})}):null]})}function SR({destinations:e,bindings:t,disabled:s,onChange:r}){const i=(a,l)=>{r(t.map((o,c)=>c===a?{...o,...l}:o))};return n.jsxs(se,{gap:"sm",children:[t.map((a,l)=>{const o=e.find(d=>d.kind===a.kind),c=(o==null?void 0:o.maxRule)??a.rule,u=o?e:[...e,{kind:a.kind,plugin:"",maxRule:a.rule}];return n.jsxs("div",{className:"secrets-place",children:[n.jsx(ie,{label:"Kind of place",children:n.jsx("select",{value:a.kind,disabled:s,onChange:d=>{var p;const f=d.target.value,m=(p=e.find(g=>g.kind===f))==null?void 0:p.maxRule;i(l,{kind:f,rule:m?qd(m):a.rule})},children:u.map(d=>n.jsx("option",{value:d.kind,children:F9(d.kind)},d.kind))})}),n.jsx(ie,{label:"The place",children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:U9(a.kind),onChange:d=>i(l,{target:d.target.value})})}),n.jsx(ie,{label:"Asks you",children:n.jsx("select",{value:a.rule,disabled:s,onChange:d=>i(l,{rule:d.target.value}),children:cR(c).map(d=>n.jsx("option",{value:d,children:z9[d]},d))})}),n.jsx(T,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((d,f)=>f!==l)),children:"Remove"}),n.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",w9(a.kind),"."]})]},l)}),t.length===0?n.jsx("p",{className:"ui-field-hint",children:j9}):null,e.length?n.jsx(ae,{children:n.jsx(T,{size:"sm",disabled:s,onClick:()=>r([...t,{kind:e[0].kind,target:"",rule:qd(e[0].maxRule)}]),children:"Add a place"})}):n.jsx("p",{className:"ui-field-hint",children:"Nothing installed here takes a secret yet, so there is nowhere to send one."})]})}function CR(e){const t=e.map(r=>N9(r.kind,r.target)),s=t.findIndex(r=>!r.ok);return s!==-1?{ok:!1,error:`Place ${s+1}: ${t[s].error}`}:{ok:!0,bindings:e.map((r,i)=>({kind:r.kind,target:t[i].target,rule:r.rule}))}}function q9({destinations:e,onClose:t,onChanged:s}){const[r,i]=h.useState(""),[a,l]=h.useState(""),[o,c]=h.useState(!1),[u,d]=h.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:qd(e[0].maxRule)}]:[]),[f,m]=h.useState(!1),[p,g]=h.useState(null),[x,b]=h.useState(null),[j,v]=h.useState(null),w=async()=>{const N=CR(u);if(!N.ok){g(N.error);return}const k=a;l("");const S=await na("secrets.put",{name:r.trim(),value:k,totp:o,bindings:N.bindings},m,g);S!==null&&(b({name:r.trim(),result:S}),s())},y=async()=>{const N=await na("secrets.scrub_history",{name:(x==null?void 0:x.name)??""},m,g);N!==null&&(v(N),s())};return x?n.jsx(ft,{title:"Add a secret",onClose:t,foot:n.jsx(ae,{align:"end",children:n.jsx(T,{onClick:t,children:"Done"})}),children:n.jsx(NR,{title:x.name,result:x.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y()})}):n.jsx(ft,{title:"Add a secret",size:"wide",onClose:t,foot:n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:t,children:"Cancel"}),n.jsx(T,{type:"submit",form:"secrets-add",variant:"accent",disabled:f,children:"Save secret"})]}),children:n.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:N=>{N.preventDefault(),w()},children:[n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx(ie,{label:"Name",hint:"What agents ask for it by. Saving a name that exists replaces that secret’s value.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:N=>i(N.target.value),placeholder:"PNC password"})}),n.jsx(ie,{label:"Value",hint:"Kept in the vault and never shown again, not even here.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:a,onChange:N=>l(N.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),n.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),n.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),n.jsx(SR,{destinations:e,bindings:u,disabled:f,onChange:d})]}),p?n.jsx(G,{tone:"critical",role:"alert",children:p}):null]})})}function Q9({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=h.useState(""),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),g=async()=>{const b=i;a("");const j=await na("secrets.put",{name:e.name,value:b,totp:e.totp,bindings:e.bindings.map(({kind:v,target:w,rule:y})=>({kind:v,target:w,rule:y}))},o,u);j!==null&&(f(j),r())},x=async()=>{const b=await na("secrets.scrub_history",{name:e.name},o,u);b!==null&&(p(b),r())};return d?n.jsx(un,{title:`Replaced the value of “${t}”`,onClose:s,foot:n.jsx(T,{variant:"accent",onClick:s,children:"Done"}),children:n.jsx(NR,{title:t,result:d,scrubbed:m,busy:l,failure:c,onScrub:()=>void x()})}):n.jsx(un,{title:`Replace the value of “${t}”`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{type:"submit",form:"secrets-replace",variant:"accent",disabled:l||i==="",children:"Save value"})]}),children:n.jsxs("form",{id:"secrets-replace",className:"ui-stack","data-gap":"sm",onSubmit:b=>{b.preventDefault(),i!==""&&g()},children:[n.jsx(ie,{label:"New value",hint:"Kept in the vault and never shown again. Where it may go stays the same.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,disabled:l,value:i,onChange:b=>a(b.target.value)})}),n.jsx(le,{message:c})]})})}function X9({secret:e,onClose:t,onChanged:s}){const[r,i]=h.useState(e.name),[a,l]=h.useState(!1),[o,c]=h.useState(null),u=r.trim()!==""&&r.trim()!==e.name,d=async()=>{await na("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(un,{title:`Rename “${e.name}”`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(T,{type:"submit",form:"secrets-rename",variant:"accent",disabled:a||!u,children:"Rename"})]}),children:n.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),u&&d()},children:[n.jsx(ie,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:a,value:r,onChange:f=>i(f.target.value)})}),n.jsx(le,{message:o})]})})}function J9({secret:e,title:t,destinations:s,onClose:r,onChanged:i}){const[a,l]=h.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:S9(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:qd(s[0].maxRule)}]:[]),[o,c]=h.useState(!1),[u,d]=h.useState(null),f=async()=>{const m=CR(a);if(!m.ok){d(m.error);return}await na("secrets.rebind",{name:e.name,bindings:m.bindings},c,d)!==null&&(i(),r())};return n.jsx(ft,{title:`Where “${t}” may go`,size:"wide",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(T,{onClick:r,children:"Cancel"}),n.jsx(T,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:n.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),f()},children:[n.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),n.jsx(SR,{destinations:s,bindings:a,disabled:o,onChange:l}),u?n.jsx(G,{tone:"critical",role:"alert",children:u}):null]})})}function Z9({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=h.useState(!1),[l,o]=h.useState(null),c=!!e.unused,u=async()=>{await na("secrets.delete",{name:e.name},a,o)!==null&&(r(),s())};return n.jsxs(un,{title:`${c?"Remove":"Delete"} “${t}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:i,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[n.jsxs("p",{className:"secrets-dialog-text",children:[L9(e)," The value is gone for good; its usage history stays, under its name."]}),n.jsx(le,{message:l})]})}function e7({timezone:e,embedded:t}){var p;const{data:s,error:r,reload:i}=ce(()=>E.sentinels(),[],3e4),[a,l]=h.useState(null),[o,c]=h.useState(null),u=(s==null?void 0:s.installed)??[],d=((s==null?void 0:s.runs)??[]).filter(g=>g.lastError),f=u.filter(g=>!g.enabled),m=(g,x)=>{l(g),c(null),E.setSentinelEnabled(g,x).catch(b=>c(b instanceof pe?b.message:String(b))).finally(()=>{l(null),i()})};return n.jsxs(An,{embedded:t,title:"Watchers",children:[n.jsx(le,{message:r??o}),n.jsx(G,{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."}),d.length>0?n.jsx(G,{tone:"warning",children:d.length===1?"One watcher failed on its last run.":`${d.length} watchers failed on their last run.`}):null,f.length>0?n.jsxs(G,{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(oe,{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(jn,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(ht,{children:u.map(g=>{const x=s.runs.find(b=>b.sentinelId===g.id);return n.jsx(st,{lead:n.jsx(ve,{tone:g.enabled?x!=null&&x.lastError?"critical":x?"good":void 0:"muted",children:g.enabled?x!=null&&x.lastError?"failed":x?"ok":"never ran":"off"}),title:g.description,sub:`${g.id}, every ${t7(g.every)}${x!=null&&x.lastError?`. ${x.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:x?nt(x.lastRunAt,e):void 0,children:x?De(x.lastRunAt):"never ran"}),n.jsx(T,{size:"sm",disabled:a===g.id,onClick:()=>m(g.id,!g.enabled),children:g.enabled?"Turn off":"Turn on"})]})},g.id)})}):n.jsx(xe,{children:"Loading…"})}),n.jsx(kH,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:i})]})}function t7(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 h0=4,n7={time:"profile",date:"profile",zone:null};function s7({data:e,phone:t}){const s=h.useRef(null),r=XA(),[i,a]=h.useState(.4),l=t?390:1280,o=t?780:800;h.useEffect(()=>{const u=s.current;if(!u)return;const d=()=>a(u.clientWidth/l||.4);if(d(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(d);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":Oj(e==null?void 0:e.background,e==null?void 0:e.image),"data-phone":t?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${i})`},"aria-hidden":"true",children:[n.jsx(lT,{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(ue,{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(ue,{name:"lock",size:15}),n.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function r7({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(d=>e.sizes.includes(d)).map(d=>({value:d,label:d==="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(ue,{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(ue,{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(ue,{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(ue,{name:"close",size:12})})]})]})]})}function f0(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function i7({clock:e,onClock:t,version:s}){var q,B,V;const r=e??n7,i=ce(()=>E.lockScreen(),[s]),a=ce(()=>E.widgets("lock"),[]),l=ce(()=>E.owner(),[]),[o,c]=h.useState(void 0),[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[x,b]=h.useState(null),[j,v]=h.useState(null);h.useEffect(()=>{a.data&&c(a.data)},[a.data]);const w=((q=i.data)==null?void 0:q.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],N=new Map(((o==null?void 0:o.available)??[]).map(F=>[F.id,F])),k=y.length>=h0,S=F=>{if(!o)return Promise.resolve(!1);const X=o;return m(null),c({...o,lock:F,arranged:{...o.arranged,lock:!0}}),E.saveWidgets("lock",F).then(Y=>(c(Y),i.reload(),!0),Y=>(c(X),m(`Couldn't save the lock screen's widgets: ${Y instanceof Error?Y.message:String(Y)}`),!1))},C=(F,X)=>{const Y=y.slice(),[Z]=Y.splice(F,1);Y.splice(F+X,0,Z),S(Y)},$=(F,X)=>{const Y=N.get(F);!Y||k||S([...y,{key:sT(),widget:F,size:Y.sizes.includes("small")?"small":Y.sizes[0],settings:X}])},R=F=>{if(F==="find"){b({query:"",found:[],busy:!1});return}if(b(null),F==="")return t({...r,zone:null});if(F.startsWith("place:"))return t({...r,zone:{place:F.slice(6)}});const X=r.zone&&!("place"in r.zone)?r.zone:j;X&&t({...r,zone:X})},I=()=>{if(!x||x.query.trim().length<2)return;const F=x.query.trim();b({query:x.query,found:[],busy:!0}),E.findPlace(F).then(({found:X})=>{var Le;const Y=X.filter(Ie=>Ie.timezone);if(Y.length===0){b({query:F,found:[],busy:!1,missed:`Nothing with a timezone found for “${F}”.`});return}const Z=Y[0],he={label:((Le=Z.name.split(",")[0])==null?void 0:Le.trim())||Z.name,timezone:Z.timezone};v(he),b(null),t({...r,zone:he})}).catch(()=>b({query:F,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},U=new Date,z=F=>yc({dateFormat:F},()=>dr(U,w,{weekday:!0})),A=(((B=l.data)==null?void 0:B.places)??[]).filter(F=>F.timezone&&F.timezone!==w),P=r.zone&&!("place"in r.zone)?r.zone:j,D=((o==null?void 0:o.home)??[]).filter(F=>N.has(F.widget)&&!N.get(F.widget).sensitive),O=((o==null?void 0:o.available)??[]).filter(F=>!F.sensitive),M=((o==null?void 0:o.available)??[]).filter(F=>F.sensitive).map(F=>F.title),W=p?y.find(F=>F.key===p):void 0,L=W?N.get(W.widget):void 0;return n.jsxs(oe,{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(s7,{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:F=>d(F==="phone")}),n.jsxs("span",{className:"lke-look-note",children:["As it shows now",(V=i.data)!=null&&V.focus?", with your focus on":"","."]})]})]}),n.jsxs("div",{className:"lke-controls",children:[n.jsx(le,{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:t1()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:F=>t({...r,time:F})})]}),n.jsx(ie,{label:"Date",children:n.jsxs("select",{value:r.date,onChange:F=>t({...r,date:F.target.value}),children:[n.jsxs("option",{value:"profile",children:["Profile · ",z(null)]}),n.jsx("option",{value:"short",children:z("short")}),n.jsx("option",{value:"long",children:z("long")}),n.jsx("option",{value:"iso",children:z("iso")}),n.jsx("option",{value:"off",children:"No date"})]})}),n.jsx(ie,{label:"A second clock",hint:"A place in another zone, under the time.",children:n.jsxs("select",{value:x?"find":f0(r.zone),onChange:F=>R(F.target.value),children:[n.jsx("option",{value:"",children:"None"}),A.map(F=>n.jsxs("option",{value:`place:${F.id}`,children:[F.label," — ",F.name.split(",")[0]]},F.id)),r.zone&&"place"in r.zone&&!A.some(F=>F.id===r.zone.place)?n.jsx("option",{value:f0(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…"})]})}),x?n.jsxs("div",{className:"wg-field-stack",children:[n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{autoFocus:!0,value:x.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:F=>b({...x,query:F.target.value}),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),I()),F.key==="Escape"&&b(null)}}),n.jsx(T,{size:"sm",disabled:x.busy||x.query.trim().length<2,onClick:I,children:x.busy?"Finding…":"Find"})]}),x.missed?n.jsx("span",{className:"ui-field-hint",children:x.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 ",h0]})]}),k||!o?n.jsxs(T,{size:"sm",disabled:!0,children:[n.jsx(ue,{name:"plus",size:12})," Add a widget"]}):n.jsx(Al,{label:"Add a widget",trigger:n.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[n.jsx(ue,{name:"plus",size:12})," Add a widget"]}),items:[D.length>0?{heading:"As on Home"}:null,...D.map(F=>({label:F.label??N.get(F.widget).title,hint:"same settings",onSelect:()=>$(F.widget,F.settings)})),D.length>0?"separator":null,{heading:"Every widget"},...O.map(F=>({label:F.title,onSelect:()=>$(F.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((F,X)=>{const Y=N.get(F.widget);return Y?n.jsx(r7,{info:Y,placement:F,index:X,count:y.length,onSize:Z=>void S(y.map(he=>he.key===F.key?{...he,size:Z}:he)),onSettings:()=>g(F.key),onMove:Z=>C(X,Z),onRemove:()=>void S(y.filter(Z=>Z.key!==F.key))},F.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:[k?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",M.length>0?` A sensitive widget — ${M.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),n.jsxs("p",{className:"lke-note",children:[n.jsx(ue,{name:"moon",size:13}),n.jsx("span",{children:"Your focus shows at the top only while one is on. Approvals and what else needs you show as counts when there are some, never what they say."})]})]})]}),W&&L?n.jsx(eT,{info:L,placement:W,surface:"lock",onClose:()=>g(null),onSave:F=>S(y.map(X=>X.key===W.key?{...X,settings:F}:X)).then(X=>(X&&g(null),X)),onRemove:()=>{g(null),S(y.filter(F=>F.key!==W.key))}}):null]})}const a7=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],l7=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],o7=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function lx(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 c7({kind:e,onClose:t,onDone:s}){const[r,i]=h.useState(""),[a,l]=h.useState(""),[o,c]=h.useState(""),[u,d]=h.useState(null),[f,m]=h.useState(!1),p=e==="remove",g=e!=="set",x=!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?",v=y=>{if(y==null||y.preventDefault(),!x)return;if(!p&&a!==o){d("The two PINs aren’t the same.");return}m(!0),d(null),(p?E.removePin(r):E.setPin(a,g?r:void 0)).then(s).catch(k=>{m(!1),d(lx(k))})},w=(y,N,k,S)=>n.jsx(ie,{label:y,children:n.jsx("input",{type:"password",inputMode:"numeric",autoComplete:y==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:N,onChange:C=>{d(null),k(b(C.target.value))}})});return n.jsx(un,{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:!x,onClick:()=>v(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:n.jsxs("form",{className:"lk-form",onSubmit:v,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(G,{tone:"critical",children:u}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function u7(e){const t=tf(),s=ce(()=>E.lockState(),[]),[r,i]=h.useState(null),[a,l]=h.useState(null),[o,c]=h.useState(!1),u=h.useRef(null),d=s.data??t.state,f=b=>{t.update(b),s.reload()},m=b=>{l(null),b.then(f).catch(j=>l(lx(j)))},p=b=>{b&&(c(!0),l(null),E.uploadLockBackground(b).then(f).catch(j=>l(lx(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!d)return n.jsx(oe,{title:"Lock screen",panel:!0,children:n.jsx(le,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=d.pin,x=(b,j)=>n.jsxs("button",{type:"button",className:"lk-swatch","data-bg":b,"aria-pressed":d.background===b,"aria-label":j,title:j,onClick:()=>m(E.setLockSettings({background:b})),children:[b==="image"&&d.image?n.jsx("img",{src:d.image,alt:""}):b==="earth"?n.jsx("img",{src:Kg.thumb,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(oe,{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(ue,{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(le,{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(ae,{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:l7,value:g?o7(d):"",onChange:b=>{g&&m(E.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:[a7.map(b=>x(b.id,b.label)),d.image?x("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(ue,{name:"plus",size:16})}),n.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":d.image?"Replace":"Your picture"})]})]}),n.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",n.jsx("a",{href:bm.authorUrl,target:"_blank",rel:"noreferrer",children:bm.author})," on ",n.jsx("a",{href:bm.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),d.image?n.jsx(ae,{align:"end",children:n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>m(E.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?n.jsx(c7,{kind:r,onClose:()=>i(null),onDone:b=>{i(null),f(b)}}):null]}),n.jsx(i7,{clock:d.clock,onClock:b=>m(E.setLockSettings({clock:b})),version:`${d.background}:${d.image??""}:${JSON.stringify(d.clock??null)}`})]})}const Mm=60;function ER(e){return e instanceof pe?e.message:"Something went wrong. Try again."}function d7(e,t,s=Date.now()){const r=`made ${dr(new Date(e.createdAt),t,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${De(e.lastUsedAt,s)}`:"never used"}`}function h7({onClose:e,onMade:t}){const[s,r]=h.useState(""),[i,a]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1),m=!i&&s.trim()!==""&&s.trim().length<=Mm,p=g=>{g==null||g.preventDefault(),m&&(a(!0),o(null),E.createApiToken(s.trim()).then(x=>{u({token:x.token,name:x.apiToken.name}),t()}).catch(x=>o(ER(x))).finally(()=>a(!1)))};if(c){const g=()=>{var x;(x=navigator.clipboard)==null||x.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return n.jsx(un,{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:d?"Copied":"Copy"})]}),n.jsx(G,{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(un,{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(ie,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${Mm} characters.`,children:n.jsx("input",{autoFocus:!0,value:s,maxLength:Mm,placeholder:"Home Assistant",onChange:g=>{o(null),r(g.target.value)}})}),l?n.jsx(G,{tone:"critical",children:l}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function f7({token:e,onClose:t,onRevoked:s}){const[r,i]=h.useState(!1),[a,l]=h.useState(null),o=()=>{i(!0),l(null),E.revokeApiToken(e.id).then(()=>{s(),t()}).catch(c=>{i(!1),l(ER(c))})};return n.jsxs(un,{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(G,{tone:"critical",children:a}):null]})}function m7({timezone:e}){var o;const t=ce(()=>E.apiTokens(),[]),[s,r]=h.useState(!1),[i,a]=h.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(le,{message:t.error?"Couldn’t read the API tokens.":null}),n.jsx(oe,{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(xe,{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(ht,{children:l.map(c=>n.jsx(st,{lead:n.jsx(_r,{icon:"key"}),title:c.name,sub:d7(c,e),side:n.jsx(T,{size:"sm",variant:"ghost",onClick:()=>a(c),children:"Revoke…"})},c.id))})}),n.jsxs(oe,{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(h7,{onClose:()=>r(!1),onMade:()=>t.reload()}):null,i?n.jsx(f7,{token:i,onClose:()=>a(null),onRevoked:()=>t.reload()}):null]})}function p7({embedded:e}){const{data:t,error:s,reload:r}=ce(()=>E.owner(),[]);return n.jsxs(An,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(le,{message:s}),t?n.jsxs(se,{gap:"lg",children:[n.jsx(v7,{initial:t,onSaved:r}),n.jsx(b7,{initial:t})]}):null]})}const AR=new Date(Date.UTC(2026,9,1,14,5));function g7(){return[["",`Auto (${yc({timeFormat:null},()=>Wt(AR,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function x7(){return[["",`Auto (${yc({dateFormat:null},()=>dr(AR,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function v7({initial:e,onSaved:t}){const[s,r]=h.useState(e.preferredName??""),[i,a]=h.useState(e.timezone??""),[l,o]=h.useState(e.timeFormat??""),[c,u]=h.useState(e.dateFormat??""),[d,f]=h.useState(e.language??""),[m,p]=h.useState(e.about??""),[g,x]=h.useState(!1),[b,j]=h.useState(!1),[v,w]=h.useState(null);h.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??"")},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about]);const y=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||d.trim()!==(e.language??"")||m.trim()!==(e.about??""),N=async()=>{x(!0),w(null);try{const C=await E.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:d.trim()===""?null:d.trim(),about:m.trim()===""?null:m.trim()});Tv({timeFormat:C.timeFormat??null,dateFormat:C.dateFormat??null}),window.dispatchEvent(new Event(Yp)),j(!0),t()}catch(C){w(C instanceof pe?C.message:String(C))}finally{x(!1)}},k=e.zones.length>0?e.zones:[e.detectedTimezone],S=C=>$=>{j(!1),C($)};return n.jsx(oe,{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 N(),children:g?"Saving…":"Save"})]}),children:n.jsxs(se,{divided:!0,gap:"lg",children:[n.jsx(oe,{title:"Name, time and language",children:n.jsxs(Ls,{children:[n.jsx(ie,{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(ie,{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)"}),k.map(C=>n.jsx("option",{value:C,children:C},C))]})}),n.jsx(ie,{label:"Time",children:n.jsx("select",{value:l,onChange:C=>S(o)(C.target.value),children:g7().map(([C,$])=>n.jsx("option",{value:C,children:$},C))})}),n.jsx(ie,{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:x7().map(([C,$])=>n.jsx("option",{value:C,children:$},C))})}),n.jsx(ie,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:d,maxLength:40,placeholder:"English, français…",onChange:C=>S(f)(C.target.value)})})]})}),n.jsxs(oe,{title:"About you",children:[n.jsx(ie,{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)})}),v?n.jsx(G,{tone:"critical",children:v}):null]})]})})}const j7=["Home","Work"];function w7(e){const t=e.trim().toLowerCase();return t==="home"?"home":t==="work"?"briefcase":"pin"}function m0({label:e,empty:t}){return n.jsx("span",{className:"place-glyph","data-empty":t?"true":void 0,"aria-hidden":"true",children:n.jsx(ue,{name:w7(e),size:18})})}function y7(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 b7({initial:e}){var c;const[t,s]=h.useState(e.places??[]);h.useEffect(()=>s(e.places??[]),[e]);const[r,i]=h.useState(null),a=e.timezone??e.detectedTimezone,l=j7.filter(u=>!t.some(d=>d.label.toLowerCase()===u.toLowerCase())),o=h.useMemo(()=>new Date,[t]);return n.jsxs(oe,{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(ht,{children:[t.map(u=>n.jsx(st,{label:`${u.label}: edit`,onClick:()=>i({place:u,label:u.label}),lead:n.jsx(m0,{label:u.label}),title:u.label,sub:y7(u),side:u.timezone&&u.timezone!==a?n.jsxs(ve,{children:[Wt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>n.jsx(st,{label:`${u}: add`,onClick:()=>i({label:u}),lead:n.jsx(m0,{label:u,empty:!0}),title:n.jsx("span",{className:"muted",children:u}),sub:"Not set",side:n.jsx(T,{size:"sm",onClick:d=>{d.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(k7,{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 k7({editing:e,zones:t,onClose:s,onSaved:r}){const i=e.place,[a,l]=h.useState(e.label),[o,c]=h.useState((i==null?void 0:i.address)??""),[u,d]=h.useState(i?[{name:i.name,latitude:i.latitude,longitude:i.longitude,...i.timezone?{timezone:i.timezone}:{}}]:null),[f,m]=h.useState(0),[p,g]=h.useState((i==null?void 0:i.timezone)??""),[x,b]=h.useState(null),[j,v]=h.useState(null),[w,y]=h.useState((i==null?void 0:i.address)??""),N=u==null?void 0:u[f],k=()=>{o.trim().length<2||(b("find"),v(null),E.findPlace(o.trim()).then(I=>{var U;d(I.found),y(o.trim()),m(0),g(((U=I.found[0])==null?void 0:U.timezone)??""),I.found.length===0&&v("Nothing found by that name. Try the town, with its country.")}).catch(I=>v(I instanceof pe?I.message:String(I))).finally(()=>b(null)))},S=()=>{N&&(b("save"),v(null),E.savePlace({...i?{id:i.id}:{},label:a.trim(),address:o.trim()===""?null:o.trim(),name:N.name,latitude:N.latitude,longitude:N.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>v(I instanceof pe?I.message:String(I))).finally(()=>b(null)))},C=()=>{i&&(b("remove"),v(null),E.removePlace(i.id).then(I=>r(I.places)).catch(I=>v(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(ft,{title:$,onClose:s,foot:n.jsxs(ae,{children:[i?n.jsx(T,{variant:"danger-ghost",disabled:x!==null,onClick:C,children:x==="remove"?"Removing…":"Remove"}):null,n.jsx(Dt,{}),n.jsx(T,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(T,{variant:"accent",disabled:!N||a.trim()===""||x!==null,onClick:S,children:x==="save"?"Saving…":"Save"})]}),children:n.jsxs(se,{gap:"lg",children:[n.jsx(ie,{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(ie,{label:"Address",hint:"A street address, or just the town.",action:n.jsx(T,{disabled:o.trim().length<2||x!==null,onClick:k,children:x==="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(),k())}})}),u&&u.length>0?n.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,U)=>n.jsxs("button",{type:"button",role:"radio","aria-checked":U===f,className:"place-option","data-on":U===f?"true":void 0,onClick:()=>{m(U),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(ie,{label:"Its timezone",hint:N?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:n.jsxs("select",{value:p,disabled:!N,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(le,{message:j})]})})}const N7=2e6;function p0(e,t){const s=e.replace(/\r\n/g,`
115
+ `).replace(/\n+$/,"").split(`
116
+ `),r=t.replace(/\r\n/g,`
117
+ `).replace(/\n+$/,"").split(`
118
+ `);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>N7)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
119
+ `);const i=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)i[c][u]=s[c]===r[u]?i[c+1][u+1]+1:Math.max(i[c+1][u],i[c][u+1]);const a=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(a.push(` ${s[l]}`),l++,o++):i[l+1][o]>=i[l][o+1]?a.push(`-${s[l++]}`):a.push(`+${r[o++]}`);for(;l<s.length;)a.push(`-${s[l++]}`);for(;o<r.length;)a.push(`+${r[o++]}`);return a.join(`
120
+ `)}const TR={skill:"skill",policy:"rule",change:"change to itself"};function S7(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 ox(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function C7(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(ox(s.current??""));return ox(t).filter(i=>!r.has(i))}function E7(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 A7(e){return"cards"in e}function g0(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function T7({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=ce(()=>E.proposals(),[],3e4),[a,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState({}),p=async(v,w,y=!1)=>{l(null),c(null),d(v),m(({[v]:N,...k})=>k);try{c(await w()),i()}catch(N){const k=N instanceof Error?N.message:String(N);y?m(S=>({...S,[v]:k})):l(k)}finally{d(null)}},g=wA(),x=((s==null?void 0:s.open)??[]).filter(v=>g0(v,t)),b=((s==null?void 0:s.closed)??[]).filter(v=>g0(v,t)),j=v=>n.jsx(M7,{proposal:v,busy:u===v.id,refusal:f[v.id]??null,onKeep:w=>void p(v.id,async()=>{const y=await E.keepProposal(v.id,w);return`${v.title}: ${y.note}`},!0),onDiscard:w=>void p(v.id,async()=>(await E.discardProposal(v.id,w),`Discarded: ${v.title}. ${v.agent} will be told once and will not propose it again for 90 days.`))},v.id);return 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(le,{message:r??a}),t?n.jsxs(G,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:Oe("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(G,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(yA,{offers:g.offers,reload:g.reload}),!s||x.length===0?n.jsx(oe,{title:"Waiting",panel:!0,children:s?t?n.jsx(jn,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(jn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(xe,{children:"Loading…"})}):n.jsx(oe,{title:"Waiting",aside:`${x.length} to decide`,children:E7(x).map(v=>A7(v)?n.jsx(R7,{group:v,busy:u===v.key,onKeepAll:()=>void p(v.key,async()=>{const w=await E.keepAllProposals(v.cards.map(y=>y.id));return`${v.label}: ${w.note}`}),card:w=>j(w)},v.key):j(v))}),b.length>0?n.jsx(oe,{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(ht,{children:b.map(v=>{var w;return n.jsx(st,{title:v.title,sub:`${v.agent}: ${$7(v)}`,side:v.kind==="skill"&&v.state==="kept"&&((w=v.skill)!=null&&w.live)?n.jsxs(ae,{align:"end",children:[n.jsx("span",{className:"muted",children:De(v.decidedAt??v.createdAt)}),n.jsx(T,{size:"sm",variant:"ghost",disabled:u===v.id,onClick:()=>void p(v.id,async()=>{const y=v.skill;return await E.removeSkill(v.agent,y.name),`Removed ${y.name} from ${v.agent}. Its versions are kept, and ${v.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):De(v.decidedAt??v.createdAt)},v.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(P7,{schedule:s.digest.schedule,onSaved:i}):null]})}function R7({group:e,busy:t,onKeepAll:s,card:r}){const i=e.cards.length,a=e.cards.some(l=>l.untrusted);return n.jsx(ys,{tone:a?"warning":"accent",title:`${e.label} (${i})`,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{children:TR.policy}),n.jsx(ve,{mono:!0,children:e.plugin})]}),foot:n.jsx(ae,{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(yt,{summary:`Show each of the ${i}`,children:n.jsx(se,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function $7(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 I7=Array.from({length:24},(e,t)=>t),x0=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function P7({schedule:e,onSaved:t}){const[s,r]=h.useState(e.day),[i,a]=h.useState(e.hour),[l,o]=h.useState(!1),[c,u]=h.useState(null),d=s!==e.day||i!==e.hour,f=async()=>{o(!0),u(null);try{await E.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${x0[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(oe,{title:"Weekly digest",panel:!0,foot:n.jsx(T,{variant:"accent",disabled:l||!d,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: ${De(e.next)}.`:""]}),n.jsxs(ae,{children:[n.jsx(ie,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:x0.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(ie,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:I7.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(G,{tone:c.tone,role:"status",children:c.text}):null]})})}function v0(e,t){return e==="tools"?ox(t).join(`
121
+ `):t}function M7({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=h.useState(e.editable??""),[o,c]=h.useState(""),u=e.editable!==null&&a!==e.editable,d=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=C7(e,a);return n.jsx(ys,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{children:TR[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(ae,{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," ",De(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:ll(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(G,{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 d.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",d.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:Et(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(Pd,{text:p0(e.skill.steps,a),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(ie,{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(G,{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(G,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(Pd,{text:p0(v0(m.part,m.current),v0(m.part,a)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof d.before=="string"?n.jsx(yt,{summary:`What its ${d.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(It,{children:d.before})}):null,n.jsx(ie,{label:d.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(Bt,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(d.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:S7(d.matcher??{})})},{label:"Does",value:String(d.action??"")},{label:"Learned from",value:(()=>{const g=Array.isArray(d.verdicts)?d.verdicts.length:0;return`${g} ${g===1?"decision":"decisions"}`})()}]}):null]})})}function D7(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 O7({start:e,onPick:t,onClose:s}){const[r,i]=h.useState(null),[a,l]=h.useState(null),[o,c]=h.useState(""),u=(p,g=!1)=>{l(null),E.pluginFolders(p).then(x=>{i(x),c("")}).catch(x=>{g&&p!==void 0?u(void 0):l(x instanceof pe?x.message:String(x))})};h.useEffect(()=>{u(e,!0)},[]);const d=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>d===""||p.name.toLowerCase().includes(d)),m=r?D7(r):[];return n.jsxs(ft,{title:"Choose the folder",onClose:s,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(Dt,{}),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(wg,{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(DE,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(le,{message:a}),r?f.length===0?n.jsx(xe,{children:d===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(Qe,{flush:!0,children:n.jsx(ht,{children:f.map(p=>n.jsx(st,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(_r,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(ve,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(xe,{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 L7="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 j0(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ue,{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:Oe("connections"),children:"Connections"})]})]})}const _7=1500,F7={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."},z7="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",RR=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],$R="buddi.plugins.install-mode";function U7(){try{const e=window.localStorage.getItem($R);if(RR.some(t=>t.value===e))return e}catch{}return"npm"}function B7(e){try{window.localStorage.setItem($R,e)}catch{}}const Eu=".tgz",Tr=(e,t,s)=>`${e} ${e===1?t:s}`;function IR(e){const t=[];return e.tools>0&&t.push(Tr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Tr(e.views,"view","views")),e.agents>0&&t.push(`${Tr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function cx(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 PR(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Jj(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function MR(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function rf({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 ux({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 DR(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function Zj(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 wi=e=>e instanceof pe?e.message:String(e);function W7(e){const[t,s]=h.useState(void 0),[r,i]=h.useState(null);return h.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{E.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(wi(c)),a=!0)})};l();const o=window.setInterval(l,_7);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function H7({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=lr(a.plugin,a.id);return n.jsx(Nt,{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 OR({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.loadsAtRestart?n.jsx(ve,{tone:"accent",children:"loads at restart"}):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 ew({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 dx=Oe("plugins"),Dm={installed:dx,browse:`${dx}?tab=browse`};function K7({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=ce(()=>E.plugins(),[],2e4),[a,l]=h.useState(null),{job:o,error:c}=W7(a),[u,d]=h.useState(null),[f,m]=h.useState(()=>Rb(r));h.useEffect(()=>m(Rb(r)),[r]);const[p,g]=h.useState(null),[x,b]=h.useState(null),[j,v]=h.useState(null),[w,y]=h.useState(null),[N,k]=h.useState(!1),S=J=>{k(!0),E.market(J).then(y).catch(we=>y({plugins:[],unavailable:wi(we)})).finally(()=>k(!1))};h.useEffect(()=>{f==="browse"&&w===null&&!N&&S(!1)},[f]);const C=J=>{d(null),l(J)},$=J=>d(wi(J)),[R,I]=h.useState(!1),U=J=>{I(!0),g(null),J.then(we=>{C(we.job.id),m("installed")}).catch($).finally(()=>I(!1))},z=h.useRef(null);h.useEffect(()=>{const J=pF(r);if(!(J===null||z.current===J)){z.current=J,m("installed"),U(E.stagePlugin(J));try{window.history.replaceState(window.history.state,"",dx)}catch{}}},[r]);const A=J=>we=>{we.preventDefault(),m(J),g(null),s==null||s(Dm[J])};h.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const P=i.data,D=(P==null?void 0:P.checkout)??!0,O=(P==null?void 0:P.installed)??[],M=J=>w==null?void 0:w.plugins.find(we=>we.installed!==void 0&&(we.installed.name??we.name)===J.name),W=J=>e.some(we=>we.plugin===J),L=(J,we)=>W(J)?n.jsx(H7,{plugin:J,pages:e,navigate:s,variant:we}):void 0,q=J=>{const we=e.find(Ye=>Ye.plugin===J);we&&s&&s(lr(we.plugin,we.id))},B=J=>{const we=t.find(Ye=>Ye.plugin===J);if(!(!we||!s))return()=>s(gi(we.plugin,we.id))},V=((w==null?void 0:w.plugins)??[]).filter(J=>J.update).length,F=(J,we)=>E.setPluginEnabled(J,we).then(Ye=>{g3(),v({name:J,notes:Ye.notes??[]}),i.reload()}),X=(J,we,Ye)=>E.uninstallPlugin(J,we?{purge:!0,confirm:Ye}:{}).then(ot=>{g(null),v({name:J,notes:ot.notes??[]}),i.reload()}),Y=J=>{d(null),F(J,!0).catch($)},Z=(J,we)=>{const Ye=w==null?void 0:w.plugins.find(ct=>{var Tt;return(((Tt=ct.installed)==null?void 0:Tt.name)??ct.name)===J&&ct.installed!==void 0}),ot=Ye&&we?`${Ye.npm}@${we}`:void 0;U(ot?E.updatePlugin(J,we,ot):E.updatePlugin(J,we))},he=J=>{d(null);const we=Ye=>{const ot=Ye.plugins.find(ct=>{var Tt;return ct.name===J||((Tt=ct.installed)==null?void 0:Tt.name)===J});if(!ot){d(`${J} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}U(E.stagePlugin(`${ot.npm}@${ot.version}`))};if(w&&w.plugins.length>0)return we(w);I(!0),E.market(!1).then(Ye=>{y(Ye),we(Ye)}).catch($).finally(()=>I(!1))},Le=(J,we)=>we===void 0?void 0:we.place==="settings"?gi(J,we.id):lr(J,we.id),Ie=J=>{var Ye;if(J.enabled===!1)return;const we=(Ye=J.needs)==null?void 0:Ye[0];if(we)switch(we.state){case"missing":return{label:`Install ${we.plugin}`,run:()=>he(we.plugin)};case"disabled":return{label:`Enable ${we.plugin}`,run:()=>Y(we.plugin)};case"range":return{label:`Update ${we.plugin}`,run:()=>Z(we.plugin)};case"setup":{const ot=Le(we.plugin,we.page),ct=ot&&s?()=>s(ot):B(we.plugin);return ct?{label:`Set up ${we.plugin}`,run:ct}:void 0}default:return{label:`See ${we.plugin}`,run:()=>g({kind:"installed",name:we.plugin})}}if(J.loaded&&J.setup){const ot=Le(J.name,J.setup.page),ct=ot&&s?()=>s(ot):B(J.name);return ct?{label:"Set it up",run:ct}:void 0}},ze=n.jsxs($c,{label:"Plugins",children:[n.jsx(cl,{href:Dm.installed,active:f==="installed",count:V,onClick:A("installed"),children:"Installed"}),n.jsx(cl,{href:Dm.browse,active:f==="browse",onClick:A("browse"),children:"Browse"})]}),ee=(P==null?void 0:P.staged)??[],be=Z7(ee,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),re=ee.find(J=>J.id===be),Ee=ee.filter(J=>J.id!==be),me=J=>{g(null),tG(J),l(null),i.reload()},Re=(p==null?void 0:p.kind)==="staged"?Ee.find(J=>J.id===p.name):void 0,Se=(p==null?void 0:p.kind)==="installed"?O.find(J=>J.name===p.name):void 0,Ue=(p==null?void 0:p.kind)==="market"?w==null?void 0:w.plugins.find(J=>J.name===p.name):void 0,et=j&&!(Se&&Se.name===j.name)&&j.notes.length>0?j.notes:null,Ae=Re?n.jsx(X7,{staged:Re,onClose:()=>g(null),onInstalled:me,onInstallFirst:he,onGone:()=>{g(null),i.reload()}},Re.id):Se?n.jsx(oG,{plugin:Se,listing:M(Se),notes:(j==null?void 0:j.name)===Se.name?j.notes:null,canOpen:W(Se.name)&&Se.enabled!==!1,onOpen:()=>q(Se.name),onClose:()=>g(null),onDisable:()=>b({kind:"disable",name:Se.name}),onEnable:()=>Y(Se.name),onRemove:()=>b({kind:"remove",name:Se.name}),onUpdate:J=>Z(Se.name,J),onSettings:Se.enabled===!1?void 0:B(Se.name),firstStep:Ie(Se),busy:R}):Ue?n.jsx(gG,{entry:Ue,canOpen:Ue.installed!==void 0&&W(Ue.installed.name??Ue.name),onOpen:()=>{var J;return q(((J=Ue.installed)==null?void 0:J.name)??Ue.name)},onClose:()=>g(null),onInstall:()=>U(E.stagePlugin(`${Ue.npm}@${Ue.version}`)),onUpdate:J=>{var we;return Z(((we=Ue.installed)==null?void 0:we.name)??Ue.name,J)},busy:R}):null,Be=x?O.find(J=>J.name===x.name):void 0,it=x?n.jsx(cG,{kind:x.kind,name:x.name,canDisable:(Be==null?void 0:Be.enabled)!==!1,onCancel:()=>b(null),onDisableInstead:()=>b({kind:"disable",name:x.name}),onDisable:()=>F(x.name,!1).then(()=>b(null)),onRemove:(J,we)=>X(x.name,J,we).then(()=>b(null))},`${x.kind}:${x.name}`):null;if(f==="browse")return n.jsxs(se,{gap:"lg",children:[n.jsx(j0,{}),ze,n.jsx(le,{message:u}),n.jsx(xG,{market:w,loading:N,busy:R,onRetry:()=>S(!0),onOpen:J=>g({kind:"market",name:J.name}),onInstall:J=>U(E.stagePlugin(`${J.npm}@${J.version}`)),onUpdate:(J,we)=>{var Ye;return Z(((Ye=J.installed)==null?void 0:Ye.name)??J.name,we)}}),Ae]});const qe=(P==null?void 0:P.builtIn)??[];return n.jsxs(se,{gap:"lg",children:[n.jsx(j0,{}),ze,n.jsx(le,{message:i.error??u??c}),P!=null&&P.unavailable?n.jsx(G,{tone:"warning",children:P.unavailable}):null,et?n.jsx(G,{role:"status",children:et.join(" ")}):null,n.jsx(V7,{trust:(P==null?void 0:P.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:C,onFailed:d}),re?n.jsx(q7,{staged:re,onInstalled:me,onGone:()=>i.reload(),onInstallFirst:he},re.id):null,Ee.length>0?n.jsx(Qe,{flush:!0,title:"Waiting for you",tool:Tr(Ee.length,"package","packages"),children:n.jsx("div",{className:"plugins-rows",children:n.jsx(ht,{children:Ee.map(J=>n.jsx(Q7,{staged:J,onReview:()=>{_R(J),g({kind:"staged",name:J.id})},onReject:()=>{d(null),E.rejectStaged(J.id).then(()=>i.reload()).catch($)}},J.id))})})}):null,P!=null&&P.restartNeeded?n.jsx(eG,{checkout:D,waiting:O.filter(J=>J.loadsAtRestart)}):null,n.jsx(sG,{list:O,firstStepFor:Ie}),n.jsx(Qe,{flush:!0,title:"Installed",tool:P?Tr(O.length,"plugin","plugins"):void 0,children:P?O.length===0?n.jsx(xe,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(ht,{children:O.map(J=>n.jsx(iG,{plugin:J,listing:M(J),open:J.enabled===!1?void 0:L(J.name,"ghost"),canOpen:W(J.name)&&J.enabled!==!1,busy:R,onDetails:()=>g({kind:"installed",name:J.name}),onOpen:()=>q(J.name),onSettings:J.enabled===!1?void 0:B(J.name),onDisable:()=>b({kind:"disable",name:J.name}),onEnable:()=>Y(J.name),onRemove:()=>b({kind:"remove",name:J.name}),onUpdate:we=>Z(J.name,we),firstStep:Ie(J)},J.name))})}):n.jsx(xe,{children:"Loading…"})}),qe.length>0?n.jsx(uG,{plugins:qe,openFor:L}):null,Ae,it]})}function V7({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=h.useState(U7),[o,c]=h.useState(""),[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[x,b]=h.useState(!1),[j,v]=h.useState(!1),w=h.useRef(null),y=C=>i(wi(C)),N=C=>{l(C),B7(C),g(null)},k=()=>{d(!0),E.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>d(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Eu)){m(null),g(`${C.name} is not a ${Eu}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),d(!0),E.uploadPlugin(C).then($=>r($.job.id)).catch(y).finally(()=>d(!1))}};return n.jsxs(Qe,{title:"Add a plugin",actions:n.jsx(sn,{label:"Where it comes from",options:RR,value:a,onChange:N}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":x?"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(ue,{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:Eu})," 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:Eu,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(ae,{valign:"end",children:[n.jsx(ie,{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:()=>v(!0),children:"Browse…"}):null,n.jsx(T,{variant:"accent",disabled:s||u||o.trim()==="",onClick:k,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[F7[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(G,{tone:"warning",children:e})})]}),j?n.jsx(O7,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function G7({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?Zj([]):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 LR(e,t,s){const[r,i]=h.useState(e.plan??null),[a,l]=h.useState(!1),[o,c]=h.useState(null);return{plan:r,busy:a,failed:o,approve:f=>{l(!0),c(null),E.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?t(e.name):m.plan&&i(m.plan)}).catch(m=>c(wi(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),E.rejectStaged(e.id).then(()=>s()).catch(f=>c(wi(f))).finally(()=>l(!1))}}}function _R(e){e.openedAt||E.openedStaged(e.id).catch(()=>{})}function Y7({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 FR({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(Bt,{items:[...e.author?[{label:"By",value:n.jsx(rf,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:cx(e.source)},{label:"Published by",value:Jj(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${cx(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(G7,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:n.jsx(Y7,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:n.jsx(ux,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(ux,{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(Bt,{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 zR({plan:e,busy:t,onReject:s,onInstallAnyway:r}){return n.jsxs(ys,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(ve,{tone:"warning",children:"read this first"}),foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(Dt,{}),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(UR,{unlocks:e.agents??[]})]})}function q7({staged:e,onInstalled:t,onGone:s,onInstallFirst:r}){const{plan:i,busy:a,failed:l,approve:o,reject:c}=LR(e,t,s);h.useEffect(()=>_R(e),[e.id]);const u=(i==null?void 0:i.drift)??[];return n.jsxs(se,{gap:"sm",children:[n.jsxs(ys,{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(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(Dt,{}),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(le,{message:l}),n.jsx(FR,{staged:e,onInstallFirst:r})]}),i&&u.length>0?n.jsx(zR,{plan:i,busy:a,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function Q7({staged:e,onReview:t,onReject:s}){const r=De(e.createdAt);return n.jsx(st,{onClick:t,label:`${e.name}: review`,lead:n.jsx(_r,{svg:void 0}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${PR(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:dl(s),children:"Not this one"})]}),n.jsx(T,{size:"sm",onClick:dl(t),children:"Review"})]})})}function X7({staged:e,onClose:t,onInstalled:s,onGone:r,onInstallFirst:i}){const{plan:a,busy:l,failed:o,approve:c,reject:u}=LR(e,s,r),d=(a==null?void 0:a.drift)??[];return n.jsxs(ft,{title:n.jsx(sw,{svg:void 0,name:e.name,version:e.version,by:e.author?n.jsx(rf,{author:e.author}):Jj(e.source,e.publisher),pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(ve,{children:"read, not installed"})]})}),onClose:t,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(Dt,{}),n.jsx(T,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),n.jsx(T,{variant:"accent",disabled:l||d.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[n.jsx(le,{message:o}),n.jsx(FR,{staged:e,inSheet:!0,onInstallFirst:i}),a&&d.length>0?n.jsx(zR,{plan:a,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const J7=10*60*1e3;function Z7(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<J7?r.id:null}function eG({checkout:e,waiting:t}){const[s,r]=h.useState(!1),[i,a]=h.useState(null),l=e4(t),o=l?`${l} ${t.length===1?"is":"are"} 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(le,{message:i}),n.jsxs(G,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(T,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),Bh({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>E.serviceAction("restart")).catch(c=>a(wi(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?z7:`${l?t.length===1?"Its tools appear":"Their tools appear":"It takes effect"} once buddi restarts, which takes a few seconds. This page waits and comes back by itself.`]})]})}const tw="buddi.plugins.justInstalled";function tG(e){try{window.sessionStorage.setItem(tw,e)}catch{}}function nG(){try{return window.sessionStorage.getItem(tw)}catch{return null}}function sG({list:e,firstStepFor:t}){var u;const[s,r]=h.useState(()=>nG()),i=s?e.find(d=>d.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(tw)}catch{}r(null)};if(h.useEffect(()=>{a&&!l&&o()},[a,l]),!i||!l)return null;const c=t(i);return n.jsx(G,{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. ${nw(i)}.`:`${i.name} is loaded. First: ${((u=i.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const dl=e=>t=>{t.stopPropagation(),e()},rG=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function nw(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 iG({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=rG(e),x=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return n.jsx(st,{onClick:a,label:`${e.name}: details`,dimmed:p,lead:n.jsx(_r,{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:[Tr(g,"agent","agents")," to accept"]}):null]}),sub:x?n.jsx("span",{className:"plugins-sub","data-tone":"warning",children:nw(e)}):`by ${MR(e)} · from ${PR(e.source)} · ${IR(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[x&&m?n.jsx(T,{size:"sm",onClick:dl(m.run),children:m.label}):null,t!=null&&t.update?n.jsxs(T,{size:"sm",disabled:i,onClick:dl(()=>f(t.update)),children:["Update to ",t.update]}):null,x?null:s,!x&&!r&&o?n.jsx(T,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,n.jsx(OR,{plugin:e}),n.jsx(Al,{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:d}]})]})})}const aG={"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 UR({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(oe,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(ht,{children:t.map(s=>n.jsx(lG,{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:Ct,children:"on the Agents page"}),"."]})]})}function lG({plugin:e,unlock:t}){const s=kj(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=aG[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(st,{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(le,{message:s.failure}),s.created?n.jsx(vA,{agent:s.created}):null]})}function sw({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(_r,{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 oG({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:f,firstStep:m}){var v,w;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",x=(t==null?void 0:t.summary)??e.description,b=(e.network??((w=(v=t==null?void 0:t.claims)==null?void 0:v.manifest)==null?void 0:w.network)??[]).map(y=>y.host),j=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(ft,{title:n.jsx(sw,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(rf,{author:e.author}):MR(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(ew,{entry:t})]}):null," · ",n.jsx(OR,{plugin:e})]})}),onClose:o,foot:n.jsxs(ae,{children:[n.jsx(T,{variant:"danger-ghost",onClick:d,children:"Remove…"}),n.jsx(Dt,{}),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(G,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(G,{role:"status",children:s.join(" ")}):null,p?n.jsx(G,{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(G,{tone:"warning",action:m?n.jsx(T,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",nw(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?n.jsxs(G,{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,x?n.jsx("p",{className:"plugins-summary-full",children:x}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Bt,{items:[{label:"From",value:cx(e.source)},...g?[]:[{label:"Published by",value:Jj(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(ux,{value:e.integrity})},{label:"Installed",value:De(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:IR(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:DR(b)}]:[],...j?[{label:"Reaches in buddi",value:Zj(j)}]:[]]})}),n.jsx(UR,{plugin:e.name,unlocks:e.unlocks})]})}function cG({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(!1),[p,g]=h.useState(null),x=j=>{m(!0),g(null),j().catch(v=>g(wi(v))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(un,{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:()=>x(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(le,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(un,{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(Dt,{}),n.jsx(T,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(T,{variant:"danger",disabled:f||!b,onClick:()=>x(()=>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),d("")}}),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(ie,{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=>d(j.target.value)})}):null]}),n.jsx(le,{message:p})]})}function uG({plugins:e,openFor:t}){return n.jsxs(yt,{boxed:!0,summary:`Ships with buddi · ${Tr(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"),Tr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const dG=[{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 hG(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function fG({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 mG({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(ys,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(_r,{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(ew,{entry:e}),e.installed?n.jsxs(ve,{children:["installed ",e.installed.version]}):null,n.jsx(Dt,{}),e.update?n.jsxs(T,{size:"sm",disabled:t,onClick:dl(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(T,{size:"sm",variant:"accent",disabled:t,onClick:dl(r),children:"Install"})]})]})}function pG(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 gG({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,x,b,j,v,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=pG(e),d=((j=(b=(x=e.claims)==null?void 0:x.manifest)==null?void 0:b.agents)==null?void 0:j.length)??0,f=(w=(v=e.claims)==null?void 0:v.package)==null?void 0:w.dependencies;return n.jsxs(ft,{title:n.jsx(sw,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(rf,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(ew,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(ve,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(ae,{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(Dt,{}),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:E.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(Bt,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...d>0?[{label:"Proposes",value:`${Tr(d,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:DR(c)},{label:"Reaches in buddi",value:Zj(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(fG,{pricing:e.pricing})]})}]})})]})}function xG({market:e,loading:t,busy:s,onRetry:r,onOpen:i,onInstall:a,onUpdate:l}){const[o,c]=h.useState(""),[u,d]=h.useState("all"),f=(e==null?void 0:e.plugins)??[],m=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...dG.filter(x=>f.some(b=>b.category===x.value))],p=f.filter(x=>u==="recommended"&&(x.trust!=="by-buddi"||x.installed)||u!=="all"&&u!=="recommended"&&x.category!==u?!1:hG(x,o)),g=o.trim();return n.jsxs(se,{gap:"lg",children:[n.jsxs(ae,{children:[n.jsx(DE,{grow:!0,label:"Search plugins",value:o,placeholder:"Search plugins: weather, money, calendar…",onChange:c}),n.jsx(Sz,{label:"Show",options:m,value:u,onChange:d})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ue,{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(xe,{children:"Asking withbuddi.com…"}):e.unavailable?n.jsx(G,{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(G,{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?` ${De(e.fetchedAt)}`:" last time","."]}):null,p.length>0?n.jsx("div",{className:"plugins-grid",children:p.map(x=>n.jsx(mG,{entry:x,busy:s,onOpen:()=>i(x),onInstall:()=>a(x),onUpdate:b=>l(x,b)},x.npm))}):n.jsx(xe,{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 Pc={},vG=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},BR={},is={};let rw;const jG=[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];is.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};is.getSymbolTotalCodewords=function(t){return jG[t]};is.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};is.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');rw=t};is.isKanjiModeEnabled=function(){return typeof rw<"u"};is.toSJIS=function(t){return rw(t)};var af={};(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}}})(af);function WR(){this.buffer=[],this.length=0}WR.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 wG=WR;function Mc(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)}Mc.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};Mc.prototype.get=function(e,t){return this.data[e*this.size+t]};Mc.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};Mc.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var yG=Mc,HR={};(function(e){const t=is.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}})(HR);var KR={};const bG=is.getSymbolSize,w0=7;KR.getPositions=function(t){const s=bG(t);return[[0,0],[s-w0,0],[0,s-w0]]};var VR={};(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,d=null;for(let f=0;f<a;f++){o=c=0,u=d=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===d?c++:(c>=5&&(l+=t.N1+(c-5)),d=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 d=0;d<a;d++)o=o<<1&2047|i.get(u,d),d>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(d,u),d>=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 d=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),d<c&&(c=d,o=u)}return o}})(VR);var lf={};const Zr=af,Au=[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],Tu=[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];lf.getBlocksCount=function(t,s){switch(s){case Zr.L:return Au[(t-1)*4+0];case Zr.M:return Au[(t-1)*4+1];case Zr.Q:return Au[(t-1)*4+2];case Zr.H:return Au[(t-1)*4+3];default:return}};lf.getTotalCodewordsCount=function(t,s){switch(s){case Zr.L:return Tu[(t-1)*4+0];case Zr.M:return Tu[(t-1)*4+1];case Zr.Q:return Tu[(t-1)*4+2];case Zr.H:return Tu[(t-1)*4+3];default:return}};var GR={},of={};const Co=new Uint8Array(512),Xd=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Co[s]=t,Xd[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Co[s]=Co[s-255]})();of.log=function(t){if(t<1)throw new Error("log("+t+")");return Xd[t]};of.exp=function(t){return Co[t]};of.mul=function(t,s){return t===0||s===0?0:Co[Xd[t]+Xd[s]]};(function(e){const t=of;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}})(GR);const YR=GR;function iw(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}iw.prototype.initialize=function(t){this.degree=t,this.genPoly=YR.generateECPolynomial(this.degree)};iw.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=YR.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 kG=iw,qR={},Ai={},aw={};aw.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var fr={};const QR="[0-9]+",NG="[A-Z $%*+\\-./:]+";let fc="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";fc=fc.replace(/u/g,"\\u");const SG="(?:(?![A-Z0-9 $%*+\\-./:]|"+fc+`)(?:.|[\r
122
+ ]))+`;fr.KANJI=new RegExp(fc,"g");fr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");fr.BYTE=new RegExp(SG,"g");fr.NUMERIC=new RegExp(QR,"g");fr.ALPHANUMERIC=new RegExp(NG,"g");const CG=new RegExp("^"+fc+"$"),EG=new RegExp("^"+QR+"$"),AG=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");fr.testKanji=function(t){return CG.test(t)};fr.testNumeric=function(t){return EG.test(t)};fr.testAlphanumeric=function(t){return AG.test(t)};(function(e){const t=aw,s=fr;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}}})(Ai);(function(e){const t=is,s=lf,r=af,i=Ai,a=aw,l=7973,o=t.getBCHDigit(l);function c(m,p,g){for(let x=1;x<=40;x++)if(p<=e.getCapacity(x,g,m))return x}function u(m,p){return i.getCharCountIndicator(m,p)+4}function d(m,p){let g=0;return m.forEach(function(x){const b=u(x.mode,p);g+=b+x.getBitsLength()}),g}function f(m,p){for(let g=1;g<=40;g++)if(d(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,x){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof x>"u"&&(x=i.BYTE);const b=t.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),v=(b-j)*8;if(x===i.MIXED)return v;const w=v-u(x,p);switch(x){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 x;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;x=p[0]}else x=p;return c(x.mode,x.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}})(qR);var XR={};const hx=is,JR=1335,TG=21522,y0=hx.getBCHDigit(JR);XR.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;hx.getBCHDigit(i)-y0>=0;)i^=JR<<hx.getBCHDigit(i)-y0;return(r<<10|i)^TG};var ZR={};const RG=Ai;function hl(e){this.mode=RG.NUMERIC,this.data=e.toString()}hl.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};hl.prototype.getLength=function(){return this.data.length};hl.prototype.getBitsLength=function(){return hl.getBitsLength(this.data.length)};hl.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 $G=hl;const IG=Ai,Om=["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 fl(e){this.mode=IG.ALPHANUMERIC,this.data=e}fl.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};fl.prototype.getLength=function(){return this.data.length};fl.prototype.getBitsLength=function(){return fl.getBitsLength(this.data.length)};fl.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Om.indexOf(this.data[s])*45;r+=Om.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(Om.indexOf(this.data[s]),6)};var PG=fl;const MG=Ai;function ml(e){this.mode=MG.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}ml.getBitsLength=function(t){return t*8};ml.prototype.getLength=function(){return this.data.length};ml.prototype.getBitsLength=function(){return ml.getBitsLength(this.data.length)};ml.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var DG=ml;const OG=Ai,LG=is;function pl(e){this.mode=OG.KANJI,this.data=e}pl.getBitsLength=function(t){return t*13};pl.prototype.getLength=function(){return this.data.length};pl.prototype.getBitsLength=function(){return pl.getBitsLength(this.data.length)};pl.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=LG.toSJIS(this.data[t]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
123
+ Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var _G=pl,e$={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,d,f,m,p,g,x,b;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(d in m)m.hasOwnProperty(d)&&(p=m[d],g=f+p,x=l[d],b=typeof l[d]>"u",(b||x>g)&&(l[d]=g,o.push(d,g),a[d]=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})(e$);var FG=e$.exports;(function(e){const t=Ai,s=$G,r=PG,i=DG,a=_G,l=fr,o=is,c=FG;function u(j){return unescape(encodeURIComponent(j)).length}function d(j,v,w){const y=[];let N;for(;(N=j.exec(w))!==null;)y.push({data:N[0],index:N.index,mode:v,length:N[0].length});return y}function f(j){const v=d(l.NUMERIC,t.NUMERIC,j),w=d(l.ALPHANUMERIC,t.ALPHANUMERIC,j);let y,N;return o.isKanjiModeEnabled()?(y=d(l.BYTE,t.BYTE,j),N=d(l.KANJI,t.KANJI,j)):(y=d(l.BYTE_KANJI,t.BYTE,j),N=[]),v.concat(w,y,N).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,v){switch(v){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(v,w){const y=v.length-1>=0?v[v.length-1]:null;return y&&y.mode===w.mode?(v[v.length-1].data+=w.data,v):(v.push(w),v)},[])}function g(j){const v=[];for(let w=0;w<j.length;w++){const y=j[w];switch(y.mode){case t.NUMERIC:v.push([y,{data:y.data,mode:t.ALPHANUMERIC,length:y.length},{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.ALPHANUMERIC:v.push([y,{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.KANJI:v.push([y,{data:y.data,mode:t.BYTE,length:u(y.data)}]);break;case t.BYTE:v.push([{data:y.data,mode:t.BYTE,length:u(y.data)}])}}return v}function x(j,v){const w={},y={start:{}};let N=["start"];for(let k=0;k<j.length;k++){const S=j[k],C=[];for(let $=0;$<S.length;$++){const R=S[$],I=""+k+$;C.push(I),w[I]={node:R,lastCount:0},y[I]={};for(let U=0;U<N.length;U++){const z=N[U];w[z]&&w[z].node.mode===R.mode?(y[z][I]=m(w[z].lastCount+R.length,R.mode)-m(w[z].lastCount,R.mode),w[z].lastCount+=R.length):(w[z]&&(w[z].lastCount=R.length),y[z][I]=m(R.length,R.mode)+4+t.getCharCountIndicator(R.mode,v))}}N=C}for(let k=0;k<N.length;k++)y[N[k]].end=0;return{map:y,table:w}}function b(j,v){let w;const y=t.getBestModeForData(j);if(w=t.from(v,y),w!==t.BYTE&&w.bit<y.bit)throw new Error('"'+j+'" cannot be encoded with mode '+t.toString(w)+`.
124
+ Suggested mode is: `+t.toString(y));switch(w===t.KANJI&&!o.isKanjiModeEnabled()&&(w=t.BYTE),w){case t.NUMERIC:return new s(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(v){return v.reduce(function(w,y){return typeof y=="string"?w.push(b(y,null)):y.data&&w.push(b(y.data,y.mode)),w},[])},e.fromString=function(v,w){const y=f(v,o.isKanjiModeEnabled()),N=g(y),k=x(N,w),S=c.find_path(k.map,"start","end"),C=[];for(let $=1;$<S.length-1;$++)C.push(k.table[S[$]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(f(v,o.isKanjiModeEnabled()))}})(ZR);const cf=is,Lm=af,zG=wG,UG=yG,BG=HR,WG=KR,fx=VR,mx=lf,HG=kG,Jd=qR,KG=XR,VG=Ai,_m=ZR;function GG(e,t){const s=e.size,r=WG.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 YG(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 qG(e,t){const s=BG.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 QG(e,t){const s=e.size,r=Jd.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 Fm(e,t,s){const r=e.size,i=KG.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 XG(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 JG(e,t,s){const r=new zG;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),VG.getCharCountIndicator(c.mode,e)),c.write(r)});const i=cf.getSymbolTotalCodewords(e),a=mx.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 ZG(r,e,t)}function ZG(e,t,s){const r=cf.getSymbolTotalCodewords(t),i=mx.getTotalCodewordsCount(t,s),a=r-i,l=mx.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),d=Math.floor(a/l),f=d+1,m=u-d,p=new HG(m);let g=0;const x=new Array(l),b=new Array(l);let j=0;const v=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?d:f;x[S]=v.slice(g,g+C),b[S]=p.encode(x[S]),g+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let y=0,N,k;for(N=0;N<j;N++)for(k=0;k<l;k++)N<x[k].length&&(w[y++]=x[k][N]);for(N=0;N<m;N++)for(k=0;k<l;k++)w[y++]=b[k][N];return w}function eY(e,t,s,r){let i;if(Array.isArray(e))i=_m.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const d=_m.rawSplit(e);u=Jd.getBestVersionForData(d,s)}i=_m.fromString(e,u||40)}else throw new Error("Invalid data");const a=Jd.getBestVersionForData(i,s);if(!a)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=a;else if(t<a)throw new Error(`
125
+ The chosen QR Code version cannot contain this amount of data.
126
+ Minimum version required to store current data is: `+a+`.
127
+ `);const l=JG(t,s,i),o=cf.getSymbolSize(t),c=new UG(o);return GG(c,t),YG(c),qG(c,t),Fm(c,s,0),t>=7&&QG(c,t),XG(c,l),isNaN(r)&&(r=fx.getBestMask(c,Fm.bind(null,c,s))),fx.applyMask(r,c),Fm(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}BR.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=Jd.from(s.version),a=fx.from(s.maskPattern),s.toSJISFunc&&cf.setToSJISFunction(s.toSJISFunc)),eY(t,i,r,a)};var t$={},lw={};(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),d=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,x=a.color.light;if(m>=d&&p>=d&&m<u-d&&p<u-d){const b=Math.floor((m-d)/c),j=Math.floor((p-d)/c);x=f[o[b*l+j]?1:0]}r[g++]=x.r,r[g++]=x.g,r[g++]=x.b,r[g]=x.a}}})(lw);(function(e){const t=lw;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 d=t.getImageWidth(a.modules.size,c),f=u.getContext("2d"),m=f.createImageData(d,d);return t.qrToImageData(m.data,a,c),s(f,u,d),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),d=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(d,f.quality)}})(t$);var n$={};const tY=lw;function b0(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function zm(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function nY(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?zm("M",c+s,.5+u+s):zm("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=zm("h",l),l=0)):i++}return r}n$.render=function(t,s,r){const i=tY.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+b0(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+b0(i.color.dark,"stroke")+' d="'+nY(l,a,i.margin)+'"/>',d='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+u+`</svg>
128
+ `;return typeof r=="function"&&r(null,m),m};const sY=vG,px=BR,s$=t$,rY=n$;function ow(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!sY())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 d=px.create(s,r);c(e(d,t,r))}catch(d){u(d)}})}try{const c=px.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}Pc.create=px.create;Pc.toCanvas=ow.bind(null,s$.render);Pc.toDataURL=ow.bind(null,s$.renderToDataURL);Pc.toString=ow.bind(null,function(e,t,s){return rY.render(e,s)});async function iY(e){const t=await Pc.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const k0=10*6e4,aY=2e3;function cw(e,t){const[s,r]=h.useState(null),[i,a]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(!1),d=h.useRef(e);d.current=e;const f=h.useRef(t);f.current=t;const m=h.useCallback(async()=>{const p=await E.telegramPairing();r(p),u(!1),o(!1),a(await iY(p.link).catch(()=>""))},[]);return h.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+k0,Date.now()+k0),x=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}d.current().then(b=>{var j;p||!b||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},aY);return()=>{p=!0,window.clearInterval(x)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function uw({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 r$=new Set(["approval","question"]),ed={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."}},lY=new Set(["agent"]),oY={maxUrgency:"now",muted:[]};function cY(e,t){var i;const s=ed[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 uY({timezone:e}){var j,v,w;const t=ce(()=>E.notificationSettings(),[]),s=ce(()=>E.agents(),[]),r=ce(()=>E.notifications(20),[],3e4),i=h.useRef(!1);h.useEffect(()=>{var y,N;i.current||!r.data||window.location.hash!==cg||(i.current=!0,(N=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||N.call(y,{block:"start"}))},[r.data]);const[a,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=((j=t.data)==null?void 0:j.channels)??[],g=a??((v=t.data)==null?void 0:v.settings),x=y=>{g&&(d(!1),l({...g,...y}))},b=()=>{g&&(c(!0),d(!1),m(null),E.saveNotificationSettings(g).then(()=>{d(!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(oe,{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(le,{message:t.error??f}),n.jsx(oe,{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:Oe("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(se,{gap:"sm",children:[p.map(y=>{var N;return n.jsx(xY,{channel:y,checked:(g.defaultChannel??((N=p[0])==null?void 0:N.kind))===y.kind,onPick:()=>x({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:Oe("telegram"),children:"Set up Telegram"})]})]}):n.jsx(xe,{children:"Loading…"})}),n.jsx(oe,{title:"By kind",children:g?n.jsxs(se,{gap:"sm",children:[hO.filter(y=>!lY.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:ed[y].label}),n.jsx("span",{className:"ui-field-hint",children:ed[y].hint})]}),n.jsxs("select",{"aria-label":ed[y].label,value:vY(g,y,p),onChange:N=>{const k={...g.perKind};N.target.value==="default"?delete k[y]:k[y]=N.target.value,x({perKind:k})},children:[n.jsx("option",{value:"default",children:"Default"}),p.map(N=>n.jsx("option",{value:N.kind,children:N.label},N.kind)),r$.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(oe,{title:"Messages from your agents",children:g?n.jsx(dY,{settings:g,agents:((w=s.data)==null?void 0:w.agents)??[],onChange:x}):null}),n.jsx(oe,{title:"Focus schedules",children:g?n.jsxs(se,{gap:"sm",children:[n.jsx(yY,{schedules:g.schedules,onChange:y=>x({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(ie,{label:"End of the day",children:n.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>x({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(G,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(hY,{}),n.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:n.jsxs(oe,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(le,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(xe,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(ht,{children:r.data.notifications.map(y=>{var N;return n.jsx(st,{title:Jo(y),sub:`${nt(y.createdAt,e)} · ${cY(y,((N=s.data)==null?void 0:N.agents)??[])} · ${jY(y,p)}`,side:n.jsx(wY,{row:y})},y.id)})}):n.jsx(xe,{children:"Loading…"})]})})]})}function dY({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??oY,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 hY(){var u;const e=ce(()=>E.tipsSettings(),[]),[t,s]=h.useState(!1),[r,i]=h.useState(null),[a,l]=h.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=d=>{s(!0),i(null),l(d),E.saveTipsSettings(d).then(f=>l(f.enabled)).catch(f=>{l(!d),i(f instanceof pe?f.message:String(f))}).finally(()=>s(!1))};return n.jsx(oe,{title:"Tips",panel:!0,children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:d=>c(d.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 fY({timezone:e}){return n.jsx(mY,{timezone:e,onChange:()=>{}})}function mY({timezone:e,onChange:t}){var C,$;const s=ce(()=>E.telegramBot(),[]),r=ce(()=>E.telegramDevices(),[]),[i,a]=h.useState(!1),[l,o]=h.useState(""),[c,u]=h.useState(!1),[d,f]=h.useState(null),[m,p]=h.useState(null),g=h.useRef(new Set),x=cw(()=>E.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,v=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const R=i&&(((I=s.data)==null?void 0:I.running)??!1);E.saveTelegramToken(l.trim()).then(U=>{o(""),a(!1),f(U.restartNeeded?{ok:!1,text:U.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(U=>f({ok:!1,text:U instanceof pe?U.message:String(U)})).finally(()=>u(!1))},w=()=>{var R;p(null),g.current=new Set((((R=r.data)==null?void 0:R.devices)??[]).map(I=>I.id)),x.ask().catch(I=>p(I instanceof pe?I.message:String(I)))},{offer:y,square:N,paired:k,stale:S}=x;return n.jsx(oe,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{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:v,children:"Save token"})]}):void 0,children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:s.error}),!s.data&&!s.error?n.jsx(xe,{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(ie,{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(),v())}})})]}):null,d?n.jsx(G,{tone:d.ok?"good":"warning",role:"status",children:d.text}):null]})}),n.jsxs(oe,{title:"Your devices",children:[n.jsx(le,{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(ht,{children:r.data.devices.map(R=>n.jsx(st,{title:R.name??`Telegram user ${R.userId}`,sub:`Paired ${nt(R.pairedAt,e)} · ${R.lastSeenAt?`last spoke ${De(R.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(pY,{id:R.id,onGone:()=>{r.reload(),t()}})},R.id))}):r.error?null:n.jsx(xe,{children:"Loading…"})]}),n.jsx(oe,{title:"Pair a device",foot:b&&(!y||k)?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(le,{message:m}),b?k?n.jsx(G,{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(uw,{offer:y,square:N,children:n.jsx(gY,{text:y.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",nt(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 pY({id:e,onGone:t}){const[s,r]=h.useState(!1),[i,a]=h.useState(!1),[l,o]=h.useState(null);if(!s)return n.jsx(T,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),E.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 gY({text:e}){const[t,s]=h.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 xY({channel:e,checked:t,onPick:s}){const[r,i]=h.useState(!1),[a,l]=h.useState(null),o=()=>{i(!0),l(null),E.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 vY(e,t,s){const r=e.perKind[t];return r==="off"?r$.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function jY(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 wY({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 N0={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},S0={mode:"do-not-disturb",days:[...eg],from:"22:00",to:"07:00"};function yY({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:eg.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${N0[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):eg.filter(c=>c===l||r.days.includes(c))}),children:N0[l]},l)})}),n.jsx(ie,{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(ie,{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,{...S0,days:[...S0.days]}]),children:"Add a schedule"})})]})}const bY={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 kY(e){const t=vF.map(r=>({id:r.id,route:Oe(r.id),label:r.label,icon:bY[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:nE(r.plugin,r.id),route:gi(r.plugin,r.id),label:r.title,icon:GA(r.icon),group:"plugins"}));return[...t,...s]}function i$(e){return xF.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function a$(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function NY({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=h.useRef(null),l=i$(e),o=e.some(d=>d.id===t)?t:(u=e[0])==null?void 0:u.id,c=d=>{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=x=>{var b;d.preventDefault(),(b=f[Math.max(0,Math.min(f.length-1,x))])==null||b.focus()};if(d.key==="ArrowDown")p(m+1);else if(d.key==="ArrowUp")p(m-1);else if(d.key==="Home")p(0);else if(d.key==="End")p(f.length-1);else if(d.key==="Enter"||d.key===" "){d.preventDefault();const x=f[m].getAttribute("href");x&&i(x)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(d=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${d.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${d.id}`,children:d.label}),d.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":a$(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:x=>{x.preventDefault(),i(f.route)},children:[n.jsx(ue,{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)})]},d.id))})}function SY({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=i$(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Nc,{modal:!1,children:[n.jsx(Sc,{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(ue,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(ue,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(Cl,{children:n.jsx(Cc,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(C_,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(J1,{children:[c>0?n.jsx(Nr,{className:"ui-menu-sep"}):null,n.jsx(ta,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const d=s[u.id],f=r[u.id];return n.jsxs(E_,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":a$(u.label,d,f),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(ue,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),d?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:d>99?"99+":d}):f?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function CY({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var v,w,y;const a=jF(e),l=VE(i!==void 0),o=i??l,c=aF(e),u=c?o.find(c.plugin,c.page):void 0,d=Ms(aj),f=kY(o.settings),p={proposals:((w=(v=ce(()=>Promise.resolve().then(()=>E.proposals()),[],3e4).data)==null?void 0:v.open)==null?void 0:w.length)??0},g=ce(()=>E.version(),[]),x=ce(()=>Promise.resolve().then(()=>E.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((y=x.data)==null?void 0:y.signals)??[]).length>0&&(b.connections=uT);const j={entries:f,active:a,counts:p,dots:b,navigate:N=>s(N)};return n.jsxs("div",{className:"settings",children:[d?null:n.jsx(NY,{...j}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="secrets"?n.jsx(rc,{before:n.jsx(wg,{inline:!0,items:[{label:"Settings",href:Zt,onClick:()=>s(Zt)}]}),title:"Keys and secrets",lede:bR,actions:n.jsx(Nt,{variant:"accent",size:"sm",href:Tb,onClick:N=>{N.preventDefault(),s(Tb)},children:"Add a secret"})}):a==="plugins"||a==="connections"?n.jsx(rc,{before:n.jsx(wg,{inline:!0,items:[{label:"Settings",href:Zt,onClick:()=>s(Zt)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?L7:LT}):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."})]}),d?n.jsx(SY,{...j}):null,u?n.jsx(E8,{page:u,params:tE(e),navigate:s,timezone:t,siblings:o.all.filter(N=>N.plugin===u.plugin)}):null,a==="you"?n.jsx(p7,{embedded:!0}):null,a==="appearance"?n.jsx(EY,{railPages:o.rail}):null,a==="notifications"?n.jsx(uY,{timezone:t}):null,a==="telegram"?n.jsx(fY,{timezone:t}):null,a==="memory"?n.jsx(kT,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(T7,{embedded:!0,plugin:mF(e)}):null,a==="accounts"?n.jsx(r9,{embedded:!0,account:lF(e)}):null,a==="computer"?n.jsx(B6,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(H9,{embedded:!0,timezone:t,secret:cF(e),adding:uF(e),navigate:s}):null,a==="connections"?n.jsx(mK,{embedded:!0,timezone:t,connection:oF(e)}):null,a==="lock"?n.jsx(u7,{navigate:s}):null,a==="api"?n.jsx(m7,{timezone:t}):null,a==="watchers"?n.jsx(e7,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(XV,{}):null,a==="plugins"?n.jsx(K7,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(RY,{timezone:t}):null]})})]})}function EY({railPages:e}){const[t,s]=xT();return n.jsx(oe,{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(Um,{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(Um,{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(Um,{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(TY,{pages:e}),n.jsx(AY,{})]})})}function AY(){var c,u,d;const e=ce(()=>E.overview(),[]),[t,s]=h.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],i=((u=e.data)==null?void 0:u.home)??[],a=((d=e.data)==null?void 0:d.dismissed)??{};if(r.length===0&&i.length===0)return null;const l=(f,m)=>{s(f),E.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),E.homeDismiss(`block:${f}`,m?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return n.jsxs(n.Fragment,{children:[r.length>0?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(f=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!f.hidden,disabled:t===f.id,onChange:m=>l(f.id,m.target.checked)}),n.jsx("span",{children:f.title})]},f.id))})]}):null,i.length>0?n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home sections"}),n.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),n.jsx(se,{gap:"sm",children:i.map(f=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:a[`block:${f.id}`]!=="hidden",disabled:t===`block:${f.id}`,onChange:m=>o(f.id,m.target.checked)}),n.jsx("span",{children:f.title})]},f.id))})]}):null]})}function TY({pages:e}){const t=dT(),[s,r]=h.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),lH(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(le,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(hc(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},hc(a)))]})]})}function Um({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 RY({timezone:e}){const t=ce(()=>E.overview(),[],15e3),s=ce(()=>E.session(),[]),r=ce(()=>E.providerAccounts(),[]),i=t.data;return n.jsxs(se,{gap:"lg",children:[n.jsx(le,{message:t.error}),n.jsx(WY,{}),i?n.jsx(oe,{title:"The queue",panel:!0,actions:n.jsx(T,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{E.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(oe,{title:"This host",panel:!0,children:[n.jsx(Bt,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?nt(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?MY(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(G,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(PY,{}),n.jsx(L8,{}),n.jsx($Y,{}),n.jsx(oe,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(xe,{children:"No sources are installed."}):n.jsx(Bt,{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 ",De(a.lastRunAt)]})}))}):n.jsx(xe,{children:"Loading…"})})]})}function $Y(){var p;const e=ce(()=>E.tailscale(),[]),[t,s]=h.useState(null),[r,i]=h.useState(!1),[a,l]=h.useState(null),[o,c]=h.useState(!1),u=e.data,d=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),E.setTailscale({enabled:g,login:d.trim()}).then(()=>{c(!0)}).catch(x=>l(x instanceof pe?x.message:String(x))).finally(()=>{i(!1),e.reload()})};return n.jsx(oe,{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(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{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(G,{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 ${d}`:"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(ie,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:d,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:()=>{IY((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(G,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function IY(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function PY(){var u;const e=ce(()=>E.service(),[],1e4),[t,s]=h.useState(null),[r,i]=h.useState(!1),[a,l]=h.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=d=>{i(!0),l(null),Bh({kind:d},()=>E.serviceAction(d)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{i(!1)})};return n.jsx(oe,{title:"Service",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{children:n.jsx(Bt,{items:[{label:"Database",value:n.jsx(C0,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(C0,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:a}),t?n.jsx(G,{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 takes a few seconds. This page waits for it and comes back by itself."}):n.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),n.jsx(ae,{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 C0({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 MY(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const DY=2e3,Zd={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."},OY=new Set(["done","failed","rolled-back"]),LY="The check asks the npm registry for the newest version and sends nothing else.",_Y="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",FY="A checkout upgrades with git pull, then buddi upgrade in a terminal.",zY=15*6e4;function UY(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 E0(e,t=Date.now()){const s=e[e.length-1];if((s==null?void 0:s.outcome)!=="failed")return null;const r=Date.parse(s.finishedAt??s.startedAt);return Number.isFinite(r)&&t-r<zY?s:null}function BY(e,t){const[s,r]=h.useState(void 0),[i,a]=h.useState(null),l=h.useRef(t);return l.current=t,h.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||E.upgradeJob(e).then(f=>{var m;o||(r(f),a(null),dE({step:Zd[f.phase]??f.detail??f.phase}),(OY.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(ol(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof pe&&f.status!==0&&f.status<500?(o=!0,ol(),a(f.message)):c=!0)})};u();const d=window.setInterval(u,DY);return()=>{o=!0,window.clearInterval(d)}},[e]),{job:s,error:i}}function WY(){const e=ce(()=>E.version(),[]),[t,s]=h.useState(null),[r,i]=h.useState(!1),[a,l]=h.useState(!1),[o,c]=h.useState(null),[u,d]=h.useState(null),f=h.useCallback(j=>{s(null),d(j)},[]),m=BY(t,f),p=e.data,g=()=>{l(!0),c(null),E.checkVersion().catch(j=>c(j instanceof pe?j.message:String(j))).finally(()=>{l(!1),e.reload()})},x=j=>{l(!0),c(null),E.setVersionCheck(j).catch(v=>c(v instanceof pe?v.message:String(v))).finally(()=>{l(!1),e.reload()})},b=()=>{l(!0),c(null),d(null),Bh({kind:"upgrade",line:p!=null&&p.latest?`Upgrading to ${p.latest}…`:"Upgrading…",step:Zd.starting,patienceMs:uE},()=>E.startUpgrade(p==null?void 0:p.latest)).then(j=>{var v;i(!1),s(((v=j==null?void 0:j.job)==null?void 0:v.id)??null)}).catch(j=>c(j instanceof pe?j.message:String(j))).finally(()=>l(!1))};return p!=null&&p.checkout?n.jsx(oe,{title:"Version",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{children:n.jsx(Bt,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:p.current})}]})}),n.jsx(oe,{children:n.jsx("p",{className:"ui-card-meta",children:FY})})]})}):n.jsx(oe,{title:"Version",panel:!0,children:n.jsxs(se,{divided:!0,children:[n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(le,{message:e.error??o}),n.jsx(Bt,{items:[{label:"Running",value:p?n.jsx("span",{className:"mono",children:p.current}):"…"},{label:"Newest",value:p?p.updateAvailable&&p.latest?n.jsxs("span",{children:["A newer buddi is available: ",n.jsx("span",{className:"mono",children:p.latest})]}):p.checkedAt?n.jsxs("span",{children:["This is the latest, as of ",De(p.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),p!=null&&p.error?n.jsxs(G,{tone:"warning",children:["The last check did not get an answer: ",p.error]}):null,n.jsx(ae,{align:"end",children:n.jsx(T,{disabled:a,onClick:g,children:"Check now"})})]})}),n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(p==null?void 0:p.checkEnabled)??!1,disabled:a||!p,onChange:j=>x(j.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:LY})]})}),p!=null&&p.updateAvailable&&p.latest&&p.latestNotes?n.jsx(oe,{title:`What changes in ${p.latest}`,children:n.jsx(Lr,{text:p.latestNotes})}):null,n.jsx(oe,{children:n.jsxs(se,{gap:"sm",children:[n.jsx(HY,{...m,job:m.job??u??void 0}),!m.job&&!u&&!m.error&&p&&E0(p.history)?n.jsx(G,{tone:"critical",role:"alert",children:UY(E0(p.history))}):null,r?n.jsx(G,{tone:"warning",role:"alert",children:_Y}):null,n.jsx(ae,{align:"end",children:r?n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",disabled:a,onClick:()=>i(!1),children:"Cancel"}),n.jsxs(T,{variant:"accent",disabled:a,onClick:b,children:["Upgrade to ",p==null?void 0:p.latest]})]}):n.jsx(T,{variant:"accent",disabled:a||t!==null||!(p!=null&&p.updateAvailable),onClick:()=>i(!0),children:p!=null&&p.updateAvailable&&p.latest?`Upgrade to ${p.latest}`:"Upgrade"})})]})}),p&&p.history.length>0?n.jsx(oe,{title:"Upgrades so far",children:n.jsx(Bt,{items:p.history.slice().reverse().map(j=>({key:j.startedAt,label:n.jsxs("span",{className:"mono",children:[j.from," → ",j.to]}),value:n.jsx(KY,{attempt:j})}))})}):null]})})}function HY({job:e,error:t}){return t?n.jsx(le,{message:t}):e?e.phase==="failed"?n.jsxs(G,{tone:"critical",role:"alert",children:[Zd.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:Zd[e.phase]??e.detail??e.phase}):null}function KY({attempt:e}){return n.jsxs("span",{children:[n.jsx(ve,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",De(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 eh=["hello","brain","takeOn","reach","assistant","handover"],l$={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function o$(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function VY(e){var a,l,o;const t=o$(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 c$(e){var a,l,o,c,u;const t=VY(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 u$(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 td(e){return eh.find(t=>!u$(e,t))??"handover"}function GY(e){const t=eh.indexOf(e);return t>0?eh[t-1]:null}function A0(e,t,s){return s===t?"now":u$(e,s)?"done":"todo"}function YY(e,t){return{...e}}const gx="buddi.firstRun.restore";function xx(e){try{e===null?window.sessionStorage.removeItem(gx):window.sessionStorage.setItem(gx,e)}catch{}}function d$(){try{return window.sessionStorage.getItem(gx)}catch{return null}}function qY(e){const t=c$(e),s=td(t);return{answers:t,open:s,stay:s!=="handover"}}function QY(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function XY(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 JY=6e4,ZY=5*6e4,h$=1500,eq=2e3,tq="(max-width: 720px)";function Ol(){const e=h.useRef(null);return h.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 dw=h.createContext({busy:0,report:()=>{}});function nq({children:e}){const[t,s]=h.useState(0),r=h.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=h.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(dw.Provider,{value:i,children:e})}function ut({children:e}){const{busy:t}=h.useContext(dw);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Tc,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function rt({children:e}){return n.jsx(n.Fragment,{children:e})}function Bs({line:e}){const{report:t}=h.useContext(dw);return h.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 hw=h.createContext(null);function Yt({children:e,actions:t}){const s=h.useContext(hw),r=t==null?null:s?wl.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 Zn({onClick:e,disabled:t}){return n.jsxs(T,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ue,{name:"chevron-left"}),_.back]})}function Ll({children:e,onClick:t,disabled:s}){return n.jsxs(T,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ue,{name:"arrow"})]})}function sq({navigate:e,timezone:t}){var dn,Un,Q,$e,Xe,K,_e;const s=Ms(tq),[r,i]=h.useState(void 0);h.useEffect(()=>{E.session().then(je=>i(je.platform)).catch(()=>{})},[]);const[a,l]=h.useState({}),[o,c]=h.useState(null),[u,d]=h.useState(void 0),[f,m]=h.useState(void 0),[p,g]=h.useState([]),[x,b]=h.useState(null),[j,v]=h.useState(null),[w,y]=h.useState(!1),[N,k]=h.useState(null),[S,C]=h.useState(null),[$,R]=h.useState(null),[I,U]=h.useState(null),[z,A]=h.useState(()=>d$()?"running":"idle"),[P,D]=h.useState({}),[O,M]=h.useState([]),[W,L]=h.useState(0),q=h.useRef(void 0),[B,V]=h.useState(null),F=h.useCallback(()=>{Promise.resolve().then(()=>E.takeOnProgress()).then(je=>{je&&Array.isArray(je.plugins)&&V(je)}).catch(()=>{})},[]);h.useEffect(()=>{if(!(B!=null&&B.running))return;const je=window.setInterval(F,eq);return()=>window.clearInterval(je)},[B==null?void 0:B.running,F]);const X=h.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),Y=h.useRef(e);Y.current=e;const Z=h.useCallback(async(je=!0,Ke=!1)=>{var Bn,Rn,Ws,Fl,Ti,$n,Ri,mr,Wr;const[Fe,Qt,bs,wn,ks,Ns]=await Promise.all([E.onboarding().catch(()=>{}),E.owner().catch(()=>{}),E.providerAccounts().catch(()=>{}),He.agents().catch(()=>{}),E.browser().catch(()=>{}),E.providers().catch(()=>{})]);d(bs);const ye=(Rn=(Bn=Ns==null?void 0:Ns.providers.find(_t=>_t.kind==="anthropic"))==null?void 0:Bn.defaultModel)==null?void 0:Rn.trim();m(ye||void 0),g((Qt==null?void 0:Qt.zones)??[]),k(((Ws=Fe==null?void 0:Fe.details)==null?void 0:Ws.conversationId)??null);const Ce=(wn==null?void 0:wn.agents.find(_t=>_t.id===wn.defaultAgentId))??(wn==null?void 0:wn.agents[0]);Ce&&b(Ce),C(Fe&&!Fe.needs.agent&&Ce?{id:Ce.id,name:Ce.name,avatar:((Fl=Ce.avatar)==null?void 0:Fl.kind)==="emoji"?Ce.avatar.value:"",description:Ce.description,...Ce.picture?{picture:Ce.picture}:{}}:null),Array.isArray((Ti=Fe==null?void 0:Fe.details)==null?void 0:Ti.takeOn)&&F();const We={onboarding:Fe,owner:Qt,accounts:bs,browser:($n=ks==null?void 0:ks.browser)==null?void 0:$n.engine,...Ce?{assistant:{id:Ce.id,name:Ce.name,avatar:((Ri=Ce.avatar)==null?void 0:Ri.kind)==="emoji"?Ce.avatar.value:""}}:{}};if(Ke){const _t=qY(We);if(l(_t.answers),c(_t.open),!_t.stay){const Hs=(mr=Fe==null?void 0:Fe.details)==null?void 0:mr.conversationId;Y.current(Hs&&Ce?tt(Ce.id,Hs):nn,!0)}return}if(je&&(Fe==null?void 0:Fe.state)==="done"){const _t=(Wr=Fe.details)==null?void 0:Wr.conversationId;Y.current(_t&&Ce?tt(Ce.id,_t):nn,!0);return}if(!je)return;const fe=c$(We);l(fe),c(_t=>_t??td(fe))},[]);h.useEffect(()=>{Z()},[Z]);const he=(je,Ke={})=>{Promise.resolve().then(()=>E.onboardingStep(l$[je],Ke)).catch(()=>{})},Le=je=>td(je)==="brain"&&P.brain?{...je,brain:P.brain}:je,Ie=(je,Ke)=>{const Fe=Le(Ke);Fe.brain&&(q.current=Fe.brain),v(null),M([]),l(Fe),je==="brain"&&Fe.brain?he(je,{accountId:Fe.brain.accountId}):je==="reach"?he(je,Fe.reach?{reach:Fe.reach}:{}):je!=="takeOn"&&he(je),c(td(Fe))},ze=(je,Ke)=>{v(null),l(Ke),Ke.brain&&(q.current=Ke.brain),je==="brain"&&Ke.brain&&he(je,{accountId:Ke.brain.accountId})},ee=je=>{v(null),l(Ke=>YY(Ke)),c(je)},be=()=>{if(!o)return;const je=GY(o==="handover"?"handover":o);je&&ee(je)},re=()=>{const je=a.brain??q.current,Ke=((B==null?void 0:B.plugins)??[]).filter(Fe=>Fe.state==="ready").map(Fe=>Fe.title);v(null),D({}),M([]),l({}),c("hello"),L(Fe=>Fe+1),(async()=>{var ye;const[Fe,Qt,bs]=await Promise.all([Promise.resolve().then(()=>E.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>E.telegram()).catch(()=>{}),Promise.resolve().then(()=>E.browser()).catch(()=>{})]),wn=o$(Fe),ks=je&&wn.some(Ce=>Ce.id===je.accountId)?je:void 0;Fe&&d(Fe),D(ks?{brain:ks}:{});const Ns=[...new Set(wn.map(Ce=>Ce.label)),...Qt!=null&&Qt.paired?[_.startOver.telegram]:[],...((ye=bs==null?void 0:bs.browser)==null?void 0:ye.engine)==="chromium"?[_.startOver.browser]:[],...Ke];M(Ns.length>0?[_.startOver.said(Ns.join(", "))]:[])})()},Ee=()=>{y(!0),E.skipOnboarding().then(()=>e(nn)).catch(je=>v(je instanceof pe?je.message:String(je))).finally(()=>y(!1))},me=ce(()=>E.version().catch(()=>({current:""})),[]),Re=h.useRef(null);h.useEffect(()=>{Re.current&&(Re.current.scrollTop=0)},[o]);const Se=z==="running",Ue=Object.keys(a).length===0,et={answers:a,accounts:u,claudeModel:f,zones:p,browserZone:X,assistantAgent:x,met:N,onMet:k,existing:S,progress:B,onProgress:F,navigate:e,onSettled:je=>o&&Ie(o,je),onKept:je=>o&&ze(o,je),onBack:be,onTrouble:v,onReload:()=>void Z(!1),onPickAnotherBrain:()=>ee("brain"),onSpoken:U},Ae=(a.takeOn??[]).map(je=>{var Ke;return((Ke=Qa.find(Fe=>Fe.id===je))==null?void 0:Ke.title)??je}),Be=(B==null?void 0:B.plugins)??[],it=Be.filter(je=>je.state==="ready").length,qe=Be.length===0?null:B!=null&&B.running?_.takeOn.installing(it,Be.length):it===Be.length?_.takeOn.installed:null,J=[(dn=a.reach)!=null&&dn.phone?_.reach.done.phone:null,(Un=a.reach)!=null&&Un.mailbox?_.reach.done.mailbox:null,(Q=a.reach)!=null&&Q.app||($e=a.reach)!=null&&$e.browser?_.reach.done.app:null].filter(je=>je!==null),we={hello:{answer:_.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:_.brain.answer(((Xe=a.brain)==null?void 0:Xe.label)??"")},takeOn:{answer:_.takeOn.answer(Ae),sub:qe},reach:{answer:_.reach.answer(J)},assistant:{answer:((K=a.assistant)==null?void 0:K.name)??""}},Ye=eh.filter(je=>je!=="handover"),ot=o===null||o==="handover"?Ye.length:Ye.indexOf(o),ct=Math.min(ot,Ye.length-1),Tt=I?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:Ee,children:_.later}),o==="hello"&&Ue&&z==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>A("form"),children:_.restore.offer}):!Se&&o!==null&&!(o==="hello"&&Ue)?n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:re,children:_.startOver.link}):null]}),zn=r===void 0||r==="darwin"?_.tagline:_.taglineElsewhere,jt=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:_.count(ot+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(hw.Provider,{value:$,children:n.jsx(nq,{children:n.jsxs(LE,{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(ic,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?_.count(ot+1):void 0,children:Ye.map(je=>n.jsx("i",{"data-state":A0(a,o,je)},je))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?_.strip(ot+1,_.chapters[ot]??""):_.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(ic,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:zn}),(_e=me.data)!=null&&_e.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",me.data.current]}):null]})]}),Ye.map((je,Ke)=>{const Fe=Se?je==="hello"?"now":"todo":A0(a,o,je),Qt=we[je];return n.jsxs("div",{className:"wiz-ch","data-state":Fe,"aria-current":Fe==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":Fe,children:Fe==="done"?n.jsx(ue,{name:"check",size:12}):Ke+1}),n.jsxs("span",{className:"wiz-ch-label",children:[Fe==="done"?Qt.answer:_.chapters[Ke],Fe==="done"&&Qt.sub?n.jsx("span",{className:"wiz-ch-sub",children:Qt.sub}):null]}),Fe==="done"&&!Se?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>ee(je),children:_.change}):null]},je)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:_.mapNotes[ct]}),Tt]}),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(Cz,{dock:n.jsxs(n.Fragment,{children:[jt,n.jsx("div",{className:"wiz-dock-actions",ref:R})]}),children:[Se?n.jsx(Iq,{onDone:je=>{A("idle"),M([...je?[_.restore.welcome(je)]:[],_.restore.keys]),Z(!0,!0)},onFailed:je=>{A("idle"),v(je)}}):o==="hello"?n.jsx(rq,{...et}):o==="brain"?n.jsx(aq,{...et}):o==="takeOn"?n.jsx(bq,{...et}):o==="reach"?n.jsx(kq,{...et}):o==="assistant"?n.jsx(Aq,{...et}):o==="handover"?n.jsx(Tq,{...et}):n.jsx(Bs,{}),O.length>0||j?n.jsxs(rt,{children:[O.map(je=>n.jsx(ut,{children:je},je)),j?n.jsx(ut,{children:j}):null]}):null]},`${W}-${o??""}-${Se?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:Tt}):null]})})]})}),z==="form"?n.jsx($q,{onCancel:()=>A("idle"),onStarted:()=>A("running"),onTrouble:v}):null]})})})}function _l({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function T0(e){try{return Wt(new Date,e)}catch{return""}}function rq({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=Ol(),[l,o]=h.useState(e.name??""),[c,u]=h.useState(e.clock??s),[d,f]=h.useState(!1),[m,p]=h.useState(!1),g=()=>{const x=l.trim();x===""||m||(p(!0),E.setOwner({preferredName:x,timezone:c}).then(()=>r({...e,name:x,clock:c})).catch(b=>i(b instanceof pe?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.hello.title}),n.jsx(rt,{children:_.hello.opening.map(x=>n.jsx(ut,{children:x},x))}),n.jsxs(Yt,{actions:n.jsx(Ll,{onClick:g,disabled:m||l.trim()==="",children:_.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(ie,{label:_.name.label,children:n.jsx("input",{ref:a,placeholder:_.name.placeholder,maxLength:80,value:l,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())}})}),d?n.jsx(ie,{label:_.clock.label,hint:_.clock.hint(T0(c)),children:n.jsx("select",{value:c,onChange:x=>u(x.target.value),children:(t.includes(c)?t:[c,...t]).map(x=>n.jsx("option",{value:x,children:x},x))})}):n.jsx(ie,{label:_.clock.label,hint:_.clock.hint(T0(c)),action:n.jsx(T,{size:"lg",onClick:()=>f(!0),children:_.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:_.hello.foot})]})]})}const iq={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 aq(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=h.useState(null),[u,d]=h.useState("key"),[f,m]=h.useState(null),[p,g]=h.useState(!1),[x,b]=h.useState(null),[j,v]=h.useState(null),[w,y]=h.useState(null),N=(t==null?void 0:t.anthropicOAuthEnabled)===!0,k=(t==null?void 0:t.codexEnabled)===!0,S=t==null?void 0:t.gemini,[C,$]=h.useState(null);h.useEffect(()=>{let W=!1;const L=()=>{Promise.resolve().then(()=>E.ollama()).then(B=>{!W&&B&&b(B)}).catch(()=>{}),Promise.resolve().then(()=>E.mlxh()).then(B=>{!W&&B&&v(B)}).catch(()=>{W||v({running:!1,baseUrl:"",manager:!1,models:[]})})};L();const q=window.setInterval(L,4e3);return()=>{W=!0,window.clearInterval(q)}},[]);const R=async W=>{if(s.assistant??e.existing)try{await E.bindBrain({accountId:W.accountId,model:W.model})}catch(L){return L instanceof pe?L.message:String(L)}return a(),i({...s,brain:W}),C==null||C.close(),$(null),c(null),y(null),null},I=async(W,L,q)=>{g(!0),m(null);try{const B=await E.saveProviderAccount(W);let V=await E.testProviderAccount(B.id),F=W.defaultModel,X=!1;if(V.state!=="connected"&&q&&q!==F&&tR(V)){const Z=(await E.providerAccounts()).accounts.find(he=>he.id===B.id);Z&&(await E.saveProviderAccount({id:Z.id,revision:Z.revision,label:Z.label,kind:Z.kind,auth:Z.auth,baseUrl:Z.baseUrl,defaultModel:q,enabled:Z.enabled}),V=await E.testProviderAccount(B.id),V.state==="connected"&&(F=q,X=!0))}if(V.state!=="connected"){try{const Z=(await E.providerAccounts()).accounts.find(he=>he.id===B.id);Z&&await E.removeProviderAccount(B.id,Z.revision)}catch{}return m(V.message),V}const Y=await R({accountId:B.id,label:L,model:F,...X?{freeTier:X}:{}});return Y&&m(Y),V}catch(B){return m(B instanceof pe?B.message:String(B)),null}finally{g(!1)}},U=async W=>{g(!0),m(null);try{const L=await E.saveProviderAccount(W);let q;try{q=await E.testProviderAccount(L.id)}finally{try{const B=(await E.providerAccounts()).accounts.find(V=>V.id===L.id);B&&await E.removeProviderAccount(L.id,B.revision)}catch{}}return q.state!=="connected"&&m(q.message),q}catch(L){return m(L instanceof pe?L.message:String(L)),null}finally{g(!1)}},z=(W,L,q)=>{if(W.length<=1){I(L(W[0]??""),q);return}y({models:W,make:L,label:q})},A=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),d("key"),c(W)},P=()=>{C==null||C.close(),$(null),y(null),m(null),c(null)},D=m$(x,j),O=["free",...N?["claude"]:[],...k?["chatgpt"]:[],"key","local"];let M=null;return w?M=n.jsxs(n.Fragment,{children:[n.jsx(rt,{children:n.jsx(ut,{children:_.brain.model.ask})}),p?n.jsx(Bs,{line:_.brain.checking.service}):f?n.jsx(rt,{children:n.jsx(ut,{children:f})}):null,n.jsx(lq,{busy:p,models:w.models,onBack:P,onUse:W=>void I(w.make(W),w.label)})]}):o==="key"?M=n.jsxs(n.Fragment,{children:[n.jsx(sn,{label:_.brain.keyKinds.label,value:u,onChange:W=>{m(null),d(W)},options:[{value:"key",label:_.brain.keyKinds.key},...S?[{value:"gemini",label:_.brain.keyKinds.gemini}]:[],{value:"service",label:_.brain.keyKinds.service}]}),u==="gemini"&&S?n.jsx(cq,{busy:p,problem:f,preset:S,onBack:P,onUse:I},"gemini"):u==="service"?n.jsx(dq,{busy:p,problem:f,address:(x==null?void 0:x.cloudBaseUrl)??"",onBack:P,onOffer:z,onTrial:U,onUse:I},"service"):n.jsx(oq,{busy:p,problem:f,onBack:P,onUse:I},"key")]}):o==="local"?M=n.jsx(uq,{busy:p,problem:f,probe:x,mlxh:j,onBack:P,onOffer:z,onUse:I}):o==="free"?M=n.jsx(fq,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="chatgpt"?M=n.jsx(gq,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="claude"&&(M=n.jsx(vq,{...e,busy:p,problem:f,onBack:P,onConnected:R})),n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.brain.title}),n.jsx(rt,{children:n.jsx(ut,{children:_.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":_.brain.ask,children:O.map(W=>{const L=iq[W],q=_.brain.cards[W];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===W,"data-wide":L.wide?"true":void 0,onClick:()=>A(W),children:[n.jsx("span",{className:"wiz-glyph","data-tone":L.tone,"aria-hidden":"true",children:n.jsx(ue,{name:L.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:q.title}),n.jsx("span",{className:"wiz-opt-line",children:W==="local"?D:q.line}),"pill"in q?n.jsx(ve,{tone:"good",children:q.pill}):null]})]},W)})}),M,M===null&&s.brain?n.jsxs(rt,{children:[n.jsx(ut,{children:s.brain.freeTier?_.brain.worksOnFlash(s.brain.model):_.brain.works(s.brain.model)}),n.jsx(mq,{...e})]}):null,M===null?n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:l}),n.jsx(Ll,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:_.brain.submit})]})}):null]})}function lq({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=h.useState(t[0]??"");return n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:s,disabled:e}),n.jsx(T,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:_.brain.model.submit})]}),children:n.jsx(ie,{label:_.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 f$({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(ie,{label:_.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 oq({busy:e,problem:t,onBack:s,onUse:r}){const i=Ol(),[a,l]=h.useState(""),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState([]),[p,g]=h.useState(""),[x,b]=h.useState(!1),j=e||u,v=!x&&t!==null&&f.length>0,w=o??QY(a),y=()=>{const N=a.trim();N===""||j||(d(!0),b(!1),(async()=>{var $;let k=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(v&&p!=="")k=p;else try{const R=await E.probeModels({kind:w,auth:"api-key",secret:N});k=(($=R.models.find(I=>I.isDefault))==null?void 0:$.id)??k,S=R.models.map(I=>I.id)}catch{S=[]}d(!1);const C=await r({label:w==="anthropic"?_.brain.key.anthropic:_.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:k,enabled:!0,secret:N},w==="anthropic"?_.brain.key.anthropic:_.brain.key.openai);if(!(!C||C.state==="connected")){if(Pv(C)){b(!0),m([]);return}m(S.includes(k)||S.length===0?S:[k,...S]),g(k)}})())};return n.jsxs(n.Fragment,{children:[j?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.key})}):x?n.jsx(rt,{children:n.jsx(ut,{children:_.brain.key.refused})}):t?n.jsx(rt,{children:n.jsx(ut,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:s,disabled:j}),n.jsx(T,{variant:"accent",size:"lg",disabled:j||a.trim()==="",onClick:y,children:v?_.brain.model.retry:_.brain.key.submit})]}),children:[n.jsx(ie,{label:_.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.key.placeholder,value:a,onChange:N=>{l(N.target.value),m([])},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),y())}})}),v?n.jsx(f$,{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"?_.brain.key.anthropic:_.brain.key.openai," · ",_.brain.key.which]})]})]})}function cq({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=Ol(),[l,o]=h.useState(""),[c,u]=h.useState(!1),[d,f]=h.useState([]),[m,p]=h.useState(""),g=e||c,x=t!==null&&d.length>0,b=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let v=XT,w;if(x&&m!=="")v=m;else try{const N=(await E.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(k=>k.id);v=JT(N)??v,w=eR(v)?ZT(N):void 0,f(s9(N)),p(w??v)}catch{}u(!1),await i({label:_.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:j},_.brain.gemini.label,w)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.gemini})}):t?n.jsx(rt,{children:n.jsx(ut,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:r,disabled:g}),n.jsx(T,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:_.brain.gemini.submit})]}),children:[n.jsx(ie,{label:_.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),b())}})}),x?n.jsx(ie,{label:_.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:d.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:_.brain.gemini.get})]})]})}function m$(e,t){return e===null||t===null?_.brain.local.looking:!e.running&&!t.running?_.brain.local.missing:_.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function uq({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Zg(r),u=()=>{!(r!=null&&r.running)||!c||l({label:_.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},_.brain.mlxh.label)},d=s!==null&&r!==null&&!s.running&&!r.running,f=()=>{s&&a(o,m=>({label:_.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),_.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.ollama})}):t?n.jsx(rt,{children:n.jsx(ut,{children:t})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{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:_.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(T,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:_.brain.mlxh.connect}):null,d&&s?n.jsx(Nt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[m$(s,r),r!=null&&r.running&&!c?` ${_.brain.mlxh.noBrain}`:"",d&&(r!=null&&r.baseUrl)?` ${AT(r.baseUrl)}`:""]})})]})}function dq({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=Ol(),[c,u]=h.useState(s),[d,f]=h.useState(""),[m,p]=h.useState(!1),[g,x]=h.useState([]),[b,j]=h.useState(""),[v,w]=h.useState(!1),y=e||m,N=!v&&t!==null&&g.length>0,k=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var P;const S=d.trim()?"api-key":"none",C=D=>({label:_.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:D,enabled:!0,...d.trim()?{secret:d.trim()}:{}}),$=(D,O,M)=>{if(!(!D||D.state==="connected")){if(Pv(D)){w(!0),x([]);return}x(O),j(M)}};if(S==="api-key"&&N&&b!==""){p(!1),$(await l(C(b),_.brain.service.label),g,b);return}let R=[],I;try{const D=await E.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...d.trim()?{secret:d.trim()}:{}});R=D.models.map(O=>O.id),I=(P=D.models.find(O=>O.isDefault))==null?void 0:P.id}catch{}p(!1);const U=I?[I]:R;if(S==="none"){i(U,C,_.brain.service.label);return}const z=U[0]??"";if(U.length<=1){$(await l(C(z),_.brain.service.label),R,z);return}const A=await a(C(z));(A==null?void 0:A.state)==="connected"?i(U,C,_.brain.service.label):$(A,R,z)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.service})}):v?n.jsx(rt,{children:n.jsx(ut,{children:_.brain.key.refused})}):t?n.jsx(rt,{children:n.jsx(ut,{children:t})}):null,n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:r,disabled:y}),n.jsx(T,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:k,children:N?_.brain.model.retry:_.brain.service.submit})]}),children:[n.jsx(ie,{label:_.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:_.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),x([])}})}),n.jsx(ie,{label:_.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:d,onChange:S=>{f(S.target.value),x([])}})}),N?n.jsx(f$,{models:g,picked:b,disabled:y,onPick:j}):null]})]})}const hq=2e3;function fq({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=h.useState(!0),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(0),p=h.useRef(-1),g=h.useRef(null),x=_.brain.cloud.label;h.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?t:g.current;(async()=>{try{const v=((i==null?void 0:i.accounts)??[]).find(k=>k.auth==="device-key"),w=v?{id:v.id}:await E.saveProviderAccount({label:x,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:Ku,enabled:!0}),y=(await E.providerAccounts()).accounts.find(k=>k.id===w.id),N=await E.ollamaConnect(y.id,y.revision);d({id:y.id,attemptId:N.attemptId,url:N.verificationUrl}),j&&(j.location.href=N.verificationUrl)}catch(v){j==null||j.close(),c(v instanceof pe?v.message:String(v))}finally{l(!1)}})()},[f]),h.useEffect(()=>{if(!u)return;let j=!1,v=!1;const w=async()=>{if(!(j||v)){v=!0;try{const N=await E.ollamaPoll(u.id,u.attemptId);if(j||N.state==="waiting")return;if(j=!0,d(null),N.state==="failed"){c(N.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{v=!1}}},y=window.setInterval(()=>void w(),hq);return()=>{j=!0,window.clearInterval(y)}},[u]);const b=async j=>{try{const v=(await E.accountModels(j).catch(()=>({models:[]}))).models.map(k=>k.id),w=v.length===0||v.includes(Ku)?Ku:v[0],y=(await E.providerAccounts()).accounts.find(k=>k.id===j);y&&y.defaultModel!==w&&await E.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const N=await E.testProviderAccount(j);return N.state!=="connected"?N.message:await r({accountId:j,label:x,model:w})}catch(v){return v instanceof pe?v.message:String(v)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.cloud})}):o?n.jsx(rt,{children:n.jsx(ut,{children:o})}):u?n.jsx(rt,{children:n.jsx(ut,{children:_.brain.cloud.waiting})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:s,disabled:a||e}),u?n.jsx(Nt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.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:_.brain.cloud.again}):null]})})]})}function mq({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]=h.useState([]),[c,u]=h.useState(!1),d=Fj(a),f=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||d||!!a&&nR(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(h.useEffect(()=>{if(!f||!a)return;let g=!1;return E.accountModels(a.id).then(x=>{const b=d?x.models.filter(j=>!ET({id:j.id,...j.image?{kind:"image"}:{}})):x.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 E.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 E.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(x){r(x instanceof pe?x.message:String(x))}finally{u(!1)}})())};return n.jsx(ut,{children:n.jsx(ie,{label:_.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 R0="gpt-5.5",pq=2e3;function gq({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=h.useState(!0),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(0),p=h.useRef(-1),g=h.useRef(null),x=h.useRef(null),b=_.brain.chatgpt.label;h.useEffect(()=>()=>{const w=x.current;x.current=null,w&&E.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]),h.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"),N=y?{id:y.id}:await E.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:R0,enabled:!0}),k=(await E.providerAccounts()).accounts.find(C=>C.id===N.id),S=await E.codexAccountAction(k.id,"login",k.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??_.brain.chatgpt.failed);x.current={id:k.id,revision:k.revision},d({id:k.id,revision:k.revision,url:S.verificationUrl,code:S.userCode}),w&&(w.location.href=S.verificationUrl)}catch(y){w==null||w.close(),c(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l(!1)}})()},[f]),h.useEffect(()=>{if(!u)return;let w=!1,y=!1;const N=async()=>{if(!(w||y)){y=!0;try{const S=(await E.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,x.current=null,d(null),C.state!=="connected"){c(C.message??_.brain.chatgpt.failed);return}l(!0),c(await j(u.id)),l(!1)}catch{}finally{y=!1}}},k=window.setInterval(()=>void N(),pq);return()=>{w=!0,window.clearInterval(k)}},[u]);const j=async w=>{var y,N;try{const k=(await E.accountModels(w).catch(()=>({models:[]}))).models,S=((y=k.find($=>$.isDefault))==null?void 0:y.id)??((N=k[0])==null?void 0:N.id)??R0,C=(await E.providerAccounts()).accounts.find($=>$.id===w);return C&&C.defaultModel!==S&&await E.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:S,enabled:C.enabled}),await r({accountId:w,label:b,model:S})}catch(k){return k instanceof pe?k.message:String(k)}},v=()=>{const w=x.current;x.current=null,w&&E.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(rt,{children:n.jsx(Bs,{line:_.brain.checking.chatgpt})}):o?n.jsx(rt,{children:n.jsx(ut,{children:o})}):u?n.jsx(rt,{children:n.jsxs(ut,{children:[_.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),_.brain.chatgpt.codeAfter]})}):null,n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:v,disabled:a||e}),u?n.jsx(Nt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.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:_.brain.chatgpt.again}):null]}),children:u?n.jsx(Uj,{code:u.code,label:_.brain.chatgpt.code}):null})]})}const xq="claude-sonnet-5";function vq({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(""),g=h.useRef(null);h.useEffect(()=>()=>{const w=g.current;g.current=null,w&&E.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const x=()=>{const w=g.current;g.current=null,w&&E.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??xq,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"),N=y?{id:y.id}:await E.saveProviderAccount({label:_.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await E.providerAccounts()).accounts.find($=>$.id===N.id),C=await E.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)}})()},v=()=>{!d||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await E.anthropicAccountAction(d.id,"complete-login",d.revision,{attemptId:d.attemptId,code:m.trim()});const w=await E.testProviderAccount(d.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:d.id,label:_.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(rt,{children:n.jsx(Bs,{line:_.brain.checking.claude})}):t??c?n.jsx(rt,{children:n.jsx(ut,{children:t??c})}):null,d?n.jsxs(n.Fragment,{children:[n.jsx(rt,{children:n.jsx(ut,{children:_.brain.claude.waiting})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:x,disabled:l}),n.jsx(Nt,{size:"lg",href:d.url,target:"_blank",rel:"noreferrer",children:_.brain.claude.open}),n.jsx(T,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:_.brain.claude.finish})]}),children:n.jsx(ie,{label:_.brain.claude.paste,grow:!0,children:n.jsx(jq,{value:m,onChange:p})})})]}):n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:x,disabled:e||l}),n.jsx(T,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:_.brain.claude.start})]})})]})}function jq({value:e,onChange:t}){const s=Ol();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const wq={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function yq(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:_.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>_.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:_.takeOn.ready(s),done:!0}}function bq({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=h.useState(()=>e.takeOn??[...R4]),[c,u]=h.useState(!1),d=Qa.filter(g=>l.includes(g.id)),f=g=>o(x=>x.includes(g)?x.filter(b=>b!==g):[...x,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>E.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(x=>a(x instanceof pe?x.message:String(x))).finally(()=>u(!1)))},p=yq(t);return n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.takeOn.title}),n.jsx(rt,{children:n.jsx(ut,{children:_.takeOn.ask})}),n.jsxs(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:i,disabled:c}),n.jsx(T,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:_.takeOn.none}),n.jsx(Ll,{onClick:()=>m(Qa.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:_.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":_.takeOn.title,children:Qa.map(g=>{const x=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":x,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(ue,{name:wq[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:x?n.jsx(ue,{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)})}),d.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:_.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:d.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:_.takeOn.nothing})]})]})}function kq({answers:e,navigate:t,onSettled:s,onBack:r}){var g,x,b;const[i,a]=h.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=h.useState(((x=e.reach)==null?void 0:x.mailbox)===!0),[c,u]=h.useState(((b=e.reach)==null?void 0:b.app)===!0),[d,f]=h.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const j={phone:i,mailbox:l,app:c,browser:d==="chrome"||d==="chromium"||d==="installed"};d!==void 0&&Promise.resolve().then(()=>E.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...d!==void 0?{browser:d}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.reach.title}),n.jsx(rt,{children:n.jsx(ut,{children:_.reach.ask})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:r}),n.jsx(Ll,{onClick:p,children:_.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(Nq,{paired:i,onPaired:()=>a(!0)}),n.jsx(Cq,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(Eq,{app:c,onApp:()=>u(!0),browser:d,onBrowser:f}),i?n.jsx(G,{tone:"good",role:"status",children:_.reach.phone.hello}):null]})})]})}function Nq({paired:e,onPaired:t}){const[s,r]=h.useState(null),[i,a]=h.useState(!1),l=h.useRef(t);l.current=t,h.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>E.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(ue,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:_.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:_.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ve,{tone:"good",dot:!0,children:_.reach.phone.paired})}):o?n.jsx(Sq,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(T,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:_.reach.phone.setUp})}),i?n.jsx(ft,{title:_.telegram.sheet,onClose:()=>a(!1),children:n.jsx(Pq,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function Sq({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=cw(()=>E.telegram().then(o=>o.paired),e),l=h.useRef(!1);return h.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:_.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(T,{size:"lg",onClick:()=>void a().catch(()=>{}),children:_.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(uw,{offer:t,square:s})})}function Cq({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=h.useState(void 0),[o,c]=h.useState(!1),[u,d]=h.useState(null),f=h.useCallback(()=>{Promise.resolve().then(()=>E.pageQuery("email","accounts")).then(m=>{var g,x,b;const p=((b=(x=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:x[0])==null?void 0:b.address)??null;d(p),s(p!==null)}).catch(()=>{})},[]);return h.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>E.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),x=g.find(b=>b.id==="settings")??null;l(x?{page:x,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(ue,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?_.reach.mailbox.forTriage:_.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?_.reach.mailbox.unavailable:_.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??_.reach.mailbox.added}):a?n.jsx(T,{size:"lg",onClick:()=>c(!0),children:_.reach.mailbox.add}):null}),o&&a?n.jsx(ft,{title:_.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:n.jsx(Ij,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function Eq({app:e,onApp:t,browser:s,onBrowser:r}){const i=ef(),a=typeof navigator>"u"?null:QA(navigator.userAgent),[l,o]=h.useState(null),[c,u]=h.useState("idle"),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,x]=h.useState(void 0),b=h.useRef(!1),j=h.useRef(!0);h.useEffect(()=>(j.current=!0,Promise.resolve().then(()=>E.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 v=(C,$)=>{j.current&&(b.current=!1,u("failed"),f(C),p($??null))},w=async C=>{u("launching");let $;try{$=await E.browserCheck()}catch(R){return v(R instanceof pe?R.message:String(R))}if(j.current){if($.ok){u("idle"),o(C),r(b.current?"installed":C);return}v($.message,$.command)}},y=async()=>{var R,I;let C;try{C=await E.browser()}catch(U){return v(U instanceof pe?U.message:String(U))}if(!j.current)return;const $=C.browser;if(!$)return v(_.browser.failed(""));if(((R=$.install)==null?void 0:R.state)==="running"){u("installing"),x($.install.progress),window.setTimeout(()=>void y(),1e3);return}return $.engine!=="none"?w($.engine):v(((I=$.install)==null?void 0:I.line)??"")},N=()=>{if(p(null),l==="chrome"||l==="chromium"){w(l);return}b.current=!0,u("installing"),x(void 0),Promise.resolve().then(()=>E.browserInstall()).then(()=>{j.current&&window.setTimeout(()=>void y(),1e3)}).catch(C=>v(C instanceof pe?C.message:String(C)))},k=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(ue,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:_.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:_.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(ve,{tone:"good",dot:!0,children:_.reach.app.installed}):i?n.jsx(T,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:_.reach.app.install}):null,k?n.jsx(ve,{tone:"good",dot:!0,children:_.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(T,{size:"lg",disabled:S,onClick:N,children:S?_.browser.installing:c==="failed"?_.browser.retry:l==="chrome"?_.reach.app.chrome:l==="chromium"?_.reach.app.chromium:_.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:_.browser.needs}),n.jsx(uA,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Bs,{line:_.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:_.browser.failed(d??"")}),m?n.jsx(Rq,{command:m}):null]}):null]})}function Aq({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=h.useState(()=>(t==null?void 0:t.name)??k4),[c,u]=h.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[d,f]=h.useState(t?null:_.assistant.purposeValue),[m,p]=h.useState(t?"":_.assistant.purposeValue);h.useEffect(()=>{if(!t)return;let w=!1;return E.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,x]=h.useState(!1),b=Qa.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),j=Fb.find(w=>w.id===c),v=()=>{if(l.trim()===""||g)return;x(!0);const w=!t||d!==null&&m.trim()!==""&&m.trim()!==d.trim()?{instructions:m.trim()}:{},y=t?E.updateFirstAgent({name:l.trim(),...w}):E.createFirstAgent({name:l.trim(),handle:XY(l),description:"",...w,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let N;try{N=await y}catch(S){r(S instanceof pe?S.message:String(S)),x(!1);return}let k=null;try{j&&await E.uploadAgentPicture(N.id,await zT(j.role))}catch(S){k=S instanceof pe?S.message:String(S)}x(!1),i(),s({...e,assistant:{id:N.id,name:l.trim(),avatar:j?"":(t==null?void 0:t.avatar)??""}}),k&&r(k)})()};return n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.assistant.title}),n.jsx(rt,{children:n.jsxs(ut,{children:[_.assistant.ask,b.length>0?_.assistant.team(b):""]})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Zn,{onClick:a,disabled:g}),n.jsx(Ll,{onClick:v,disabled:g||l.trim()===""||d===null,children:_.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:ca(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":_.assistant.colour,children:Fb.map(w=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":w.id,"aria-label":_.assistant.swatch(w.label),"aria-pressed":c===w.id,onClick:()=>u(w.id)},w.id))}),n.jsx("span",{className:"wiz-face-cap",children:_.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(ie,{label:_.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:w=>o(w.target.value)})}),n.jsx(ie,{label:_.assistant.purpose,hint:_.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:w=>p(w.target.value)})})]})]})})]})}function Tq({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var P;const u=e.assistant,[d,f]=h.useState(s),[m,p]=h.useState([]),[g,x]=h.useState(!1),[b,j]=h.useState(!1),[v,w]=h.useState(!0),[y,N]=h.useState(!1),k=h.useRef(!1),S=h.useMemo(()=>t?[t]:[],[t]);h.useEffect(()=>{c()},[]),h.useEffect(()=>{if(!u||k.current)return;if(k.current=!0,s){f(s);return}let D=!1;return(async()=>{try{const O=await He.startConversation(u.id);if(D)return;f(O.conversationId),r(O.conversationId),await E.onboardingStep(l$.handover,{conversationId:O.conversationId}).catch(()=>{}),await He.send(u.id,{conversationId:O.conversationId,text:E4,opening:!0})}catch{D||(w(!1),x(!0))}})(),()=>{D=!0}},[u==null?void 0:u.id,s]),h.useEffect(()=>{if(!d)return;let D=!1;const O=Date.now(),M=()=>{He.conversation(d).then(L=>{if(D)return;p(L.messages);const q=Date.now()-O;if(L.messages.some($0)){w(!1),x(!1),j(!1);return}const B=L.runs??[],V=B.some(X=>X.finishedAt===null),F=B.length>0&&!V;j(V&&q>=JY),(F||q>=ZY)&&(w(!1),x(!0))}).catch(()=>{})};M();const W=window.setInterval(M,h$);return()=>{D=!0,window.clearInterval(W)}},[d]);const C=u&&d?tt(u.id,d):null,$=m.some($0);h.useEffect(()=>{$&&C&&l(C)},[$,C,l]);const R=e.takeOn??[],I=Qa.filter(D=>R.includes(D.id)&&"mate"in D).map(D=>D.mate),U=_.handover.starters({days:R.includes("days"),mail:R.includes("mail"),mailbox:((P=e.reach)==null?void 0:P.mailbox)===!0},I),z=(o==null?void 0:o.waiting)??[],A=D=>{!u||!d||y||(N(!0),Promise.resolve().then(()=>He.send(u.id,{conversationId:d,text:D})).then(()=>i(tt(u.id,d),!0)).catch(()=>N(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(xj,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:_.handover.waiting,plain:!0,workingLine:_.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?n.jsx(rt,{children:n.jsx(ut,{children:_.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(rt,{children:n.jsx(ut,{children:_.handover.silent})}),n.jsx(Yt,{actions:n.jsx(Ll,{onClick:a,children:_.handover.again})})]}):null,$?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":_.handover.starterLabel,children:U.map(D=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>A(D),children:D},D))}):null,$&&z.length>0?n.jsx(G,{tone:"warm",title:_.handover.waitingTitle(z.length),action:n.jsx(T,{variant:"accent",onClick:()=>i(nn,!0),children:_.handover.home}),children:_.handover.waitingBody(z)}):null,$&&C?n.jsx(Yt,{actions:n.jsx(Nt,{variant:"accent",size:"lg",href:C,onClick:D=>{D.preventDefault(),i(C,!0)},children:_.done.open})}):null]})}function Rq({command:e}){const[t,s]=h.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(It,{label:"The command to run",children:e}),n.jsxs(ae,{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 $0(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function $q({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=h.useState(null),[a,l]=h.useState(""),[o,c]=h.useState(!1),u=()=>{!r||o||(c(!0),s(null),E.firstRunRestore(r,a.trim()).then(d=>{xx(d.job.id),t()}).catch(d=>s(d instanceof pe?d.message:String(d))).finally(()=>c(!1)))};return n.jsx(ft,{title:_.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:_.restore.lede}),n.jsx(ie,{label:_.restore.file,children:n.jsx("input",{type:"file",onChange:d=>{var f;return i(((f=d.target.files)==null?void 0:f[0])??null)}})}),n.jsx(ie,{label:_.restore.passphrase,hint:_.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:d=>l(d.target.value)})}),n.jsxs(ae,{align:"end",children:[n.jsx(T,{variant:"ghost",onClick:e,children:_.restore.cancel}),n.jsx(T,{variant:"accent",disabled:o||!r,onClick:u,children:_.restore.submit})]})]})})}function Iq({onDone:e,onFailed:t}){const[s,r]=h.useState([]),i=h.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},h.useEffect(()=>{const l=d$();if(!l)return;let o=!1;const c=()=>{E.backupJob(l).then(d=>{o||(r(f=>f.includes(d.phase)?f:[...f,d.phase]),d.phase==="done"?(o=!0,xx(null),E.owner().then(f=>i.current.onDone(f.preferredName??void 0),()=>i.current.onDone(void 0))):(d.phase==="rolled-back"||d.phase==="failed")&&(o=!0,xx(null),i.current.onFailed(d.error??_.restore.phases[d.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,h$);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in _.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(_l,{children:_.restore.title}),n.jsxs(rt,{children:[n.jsx(ut,{children:_.restore.started}),a.map(l=>n.jsx(ut,{children:_.restore.phases[l]},l))]}),n.jsx(Bs,{})]})}function Pq(e){return n.jsx(hw.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(Mq,{...e})})})}function Mq({onPaired:e,onDismiss:t}){const s=Ol(),[r,i]=h.useState(""),[a,l]=h.useState(!1),[o,c]=h.useState(null),{offer:u,square:d,paired:f,stale:m,ask:p}=cw(()=>E.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await E.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??_.telegram.restart);return}await p()}catch(b){c(b instanceof pe?b.message:String(b))}finally{l(!1)}})())},x=()=>{c(null),p().catch(b=>c(b instanceof pe?b.message:String(b)))};return f?n.jsxs(n.Fragment,{children:[n.jsx(rt,{children:n.jsx(ut,{children:_.telegram.paired})}),n.jsx(Yt,{actions:n.jsx(T,{variant:"accent",onClick:t,children:_.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(rt,{children:n.jsx(ut,{children:m?_.telegram.expired:_.telegram.scan})}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:_.telegram.notNow}),m?n.jsx(T,{variant:"accent",onClick:x,children:_.telegram.newCode}):null]}),children:m?null:n.jsx(uw,{offer:u,square:d})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(rt,{children:[n.jsx(ut,{children:_.telegram.how}),o?n.jsx(ut,{children:o}):null]}),n.jsx(Yt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(T,{variant:"ghost",onClick:t,children:_.telegram.notNow}),n.jsx(T,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:_.telegram.submit})]}),children:n.jsx(ie,{label:_.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 Bm={recovery:0,lost:1,paused:2},Dq="Lost buddi. Retrying…",Oq="The queue is paused. Nothing is being claimed until you resume it.";function Lq(e){const t=[];return e.recovery&&t.push({id:"recovery",priority:Bm.recovery,tone:"warning",text:KT,action:{label:"Finish the checklist",href:ug}}),e.lost&&t.push({id:"lost",priority:Bm.lost,tone:"critical",text:Dq}),e.paused&&t.push({id:"paused",priority:Bm.paused,tone:"warning",text:Oq,action:{label:"Resume",onClick:()=>{E.setPaused(!1).catch(()=>{})}}}),t}function _q({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(`
129
+ `),children:["+",i.length," more"]}):null,a!=null&&a.href?n.jsx(Nt,{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 p$=1e4,Fq=3e4,g$=6e3,fw=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function zq(e){return fw.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 x$(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new pe(0,Rd)),e)});try{return{up:!0,version:await Promise.race([E.version(),s])}}catch(r){return $d(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function v$(e){var t;return e.up&&Jv((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function Uq({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:ca("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:zq(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(T,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function Bq({children:e}){const[t,s]=h.useState("checking"),[r,i]=h.useState(!1),a=h.useRef(!1),l=h.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await x$(g$);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":v$(o)?"up":"down")},[]);return h.useEffect(()=>{l()},[l]),h.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),p$);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(Uq,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsx(n.Fragment,{children:e})}function Wq(e=Fq){const[t,s]=h.useState(!1);return h.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=ec();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=Iv(i);return()=>{a(),clearTimeout(r)}},[e]),t}function Hq(){const e=Wq();return h.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{x$(g$).then(v$)},p$);return()=>window.clearInterval(t)},[e]),e}const Kq={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},I0=(e,t,s=`${t}s`)=>e===1?t:s;function Vq(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Gq(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function Yq(e,t){return t?"reconnecting":fw.test(e)?"local":"tailnet"}function j$(e,t,s=Vq()){const r=[],i=Kq[e.link];if(r.push({key:"link",route:Oe("system"),dot:e.link==="reconnecting"?"warning":"good",text:i,label:`Connection: ${i}`}),e.focus){const u=`${Wi[e.focus.mode]} ${dc(e.focus,e.timezone,t)}`;r.push({key:"focus",route:Oe("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const a=[];if(e.working>0&&a.push({key:"working",dot:"working",text:`${e.working} ${I0(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=`${I0(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:Fh,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:Oe("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=Wt(t,l),c=l!==s;return r.push({key:"time",route:Oe("you"),end:!0,time:o,...c?{zone:Gq(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function qq(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 w$(){const[e,t]=h.useState(()=>new Date);return h.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function Qq(){const[e,t]=h.useState(()=>ec()!==null);return h.useEffect(()=>Iv(()=>t(ec()!==null)),[]),e}function y$({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(ue,{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(h.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 Xq({status:e,onNavigate:t}){const s=w$(),r=tf(),i=j$(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(y$,{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(ue,{name:"lock",size:13})}):null]})}function Jq({status:e,onNavigate:t}){const s=w$(),r=tf(),i=qq(e);return n.jsx("div",{className:"rail-status",children:n.jsxs(Nc,{modal:!1,children:[n.jsx(Sc,{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(Cl,{children:n.jsxs(Cc,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[n.jsx(ta,{className:"ui-menu-label",children:"Status"}),j$(e,s).map(a=>n.jsx(ds,{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(y$,{item:a})})})},a.key)),r.pin?n.jsxs(n.Fragment,{children:[n.jsx(Nr,{className:"ui-menu-sep"}),n.jsx(ds,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:n.jsxs("span",{className:"rail-status-line",children:[n.jsx(ue,{name:"lock",size:12}),n.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const Zq=1e4;function b$(){return h.useSyncExternalStore(qF,Ob,Ob)}function eQ(e){switch(e.kind){case"plugins":return{title:"Restarting buddi",line:e.line??"Loading your plugins…"};case"upgrade":return{title:"Upgrading buddi",line:e.line??"Upgrading…"};case"restore":return{title:"Restoring buddi",line:e.line??"Putting your backup in place…"};case"recovery":return{title:"Restarting buddi",line:e.line??"Turning schedules, watchers and the phone back on…"};case"stop":return{title:"buddi is stopped",line:"This page comes back by itself once buddi is started again."};default:return{title:"Restarting buddi",line:e.line??"Back in a few seconds…"}}}function P0(e){const t=Math.max(0,Math.floor(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function tQ({command:e}){const[t,s]=h.useState(!1);return h.useEffect(()=>{if(!t)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[t]),n.jsxs("div",{className:"rs-cmd",children:[n.jsx("code",{className:"rs-cmd-text",children:e}),n.jsx(T,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:t?"Copied":"Copy"})]})}function nQ({state:e,elapsedMs:t,hostname:s=window.location.hostname,onReload:r=()=>qa.reload()}){const i=eQ(e),a=e.kind==="stop",l=!a&&t>=(e.patienceMs??HF),o=fw.test(s),c=h.useRef(null);h.useEffect(()=>{var d;return(d=c.current)==null?void 0:d.focus()},[]);const u=a?o?"This starts it again, in Terminal on this computer:":"On the computer buddi runs on, this starts it again:":o?"This says what it’s doing, in Terminal on this computer:":"On the computer buddi runs on, this says what it’s doing. Is that computer awake, and Tailscale on?";return n.jsx("div",{className:"ui-fieldbg rs-field","data-quiet":"true",children:n.jsx("div",{ref:c,className:"rs",role:"dialog","aria-modal":"true","aria-labelledby":"rs-title",tabIndex:-1,"data-state":a?"stopped":l?"long":"waiting",children:n.jsxs("div",{className:"rs-body",children:[n.jsx("span",{className:"ui-mascot rs-blob","data-size":"lg","aria-hidden":"true",children:n.jsx(Tc,{role:"core",state:a||l?"idle":"working",className:"ui-mascot-blob"})}),n.jsx("h1",{id:"rs-title",className:"rs-title",children:i.title}),n.jsx("p",{className:"rs-line",role:"status",children:l?"Still waiting — buddi may need a hand.":i.line}),!l&&e.step?n.jsx("p",{className:"rs-step",children:e.step}):null,a||l?null:n.jsx("div",{className:"rs-track","aria-hidden":"true",children:n.jsx("span",{})}),a||l?n.jsxs("div",{className:"rs-help",children:[n.jsx("p",{className:"rs-help-line",children:u}),n.jsx(tQ,{command:a?"buddi service start":"buddi status"})]}):null,n.jsxs("div",{className:"rs-foot",children:[n.jsx("span",{className:"rs-meta",children:a?"Checking every few seconds.":l?`${P0(t)} · still checking every few seconds`:t>=Zq?`${P0(t)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),a||l?n.jsx(T,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function sQ(e){const[t,s]=h.useState(()=>qa.now());return h.useEffect(()=>{if(!e)return;s(qa.now());const r=window.setInterval(()=>s(qa.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,t-e.startedAt):0}function rQ({children:e}){const t=b$(),s=sQ(t),r=h.useRef(null);return h.useEffect(()=>{XF();let i=ec()!==null;const a=Iv(()=>{const o=ec()!==null;i&&!o&&Lb(),i=o}),l=()=>void Lb();return window.addEventListener(nc,l),()=>{a(),window.removeEventListener(nc,l)}},[]),h.useEffect(()=>{const i=r.current;i&&(i.toggleAttribute("inert",t!==null),t?i.setAttribute("aria-hidden","true"):i.removeAttribute("aria-hidden"))},[t]),n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:r,className:"rs-host",children:e}),t?n.jsx(nQ,{state:t,elapsedMs:s}):null]})}const iQ="(max-width: 1080px)",aQ="(max-width: 720px)";function lQ(){const[e,t]=h.useState(()=>window.location.hash||nn);h.useEffect(()=>{const r=()=>t(window.location.hash||nn);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=h.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function oQ(){const[e,t]=xT();h.useEffect(()=>{gT(e)},[e]);const s=h.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const M0=new Map;function cQ(){var bs,wn,ks,Ns;const[e,t]=lQ(),[s,r]=h.useState("UTC"),[i,a]=h.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=oQ(),c=Ms(aj),[u,d]=h.useState(!1),[f,m]=h.useState([]),[p,g]=h.useState(null),[x,b]=h.useState(null),[j,v]=h.useState([]),[w,y]=h.useState(!1),[N,k]=h.useState(null),[S,C]=h.useState(null),[$,R]=h.useState(0),[I,U]=h.useState(null),z=i4(),A=f.find(ye=>ye.id===p)??null,P=A!==null&&ZB(e),[D,O]=h.useState(!1),M=h.useCallback(()=>O(!0),[]);h.useEffect(()=>{P||O(!1)},[P]),uH(t,Yu(e)===null,P?M:void 0);const W=Ms(iQ),L=HT(),q=VE(),B=dT(),V=ce(()=>Promise.resolve().then(()=>E.version()),[],PF),F=V.data;BF(V.reload);const X=F&&!F.checkout&&F.updateAvailable?F:null,Y=Jv(F==null?void 0:F.web);WF(F==null?void 0:F.web);const Z=((bs=ce(()=>Promise.resolve().then(()=>E.connectionSignals()),[],6e4).data)==null?void 0:bs.signals)??[],[he,Le]=h.useState(null),Ie=h.useMemo(()=>new Set(he?[he]:[]),[he]),[ze,ee]=h.useState(new Map);h.useEffect(()=>{const ye=()=>{E.conversations().then(We=>{const fe=new Map;for(const Bn of We.conversations){const Rn=Bn.lastMessageAt??Bn.createdAt,Ws=fe.get(Bn.agentId);(!Ws||Rn>Ws)&&fe.set(Bn.agentId,Rn)}ee(fe)}).catch(()=>{})};ye();const Ce=window.setInterval(ye,3e4);return()=>window.clearInterval(Ce)},[e]);const[be,re]=h.useState(!1);h.useEffect(()=>{if(be)return;let ye=!1;return E.onboarding().then(Ce=>{ye||(re(!0),Ce.state==="pending"&&Ce.needs.model&&!Yu(window.location.hash)&&t(eF,!0))}).catch(()=>{ye||re(!0)}),()=>{ye=!0}},[be,t]),h.useEffect(()=>{const ye=wF(e);ye&&t(ye,!0)},[e,t]),h.useEffect(()=>{let ye=!1;const Ce=()=>{He.agents().then(fe=>{ye||(m(fe.agents),EF(fe.defaultAgentId??null),g(fe.defaultAgentId??null),b(Bn=>{var Rn;return Bn??fe.defaultAgentId??((Rn=fe.agents[0])==null?void 0:Rn.id)??null}))}).catch(()=>{})};Ce();const We=window.setInterval(Ce,15e3);return window.addEventListener("focus",Ce),window.addEventListener(Zo,Ce),()=>{ye=!0,window.clearInterval(We),window.removeEventListener("focus",Ce),window.removeEventListener(Zo,Ce)}},[e]),h.useEffect(()=>{let ye=!1;const Ce=()=>{He.groups().then(fe=>{ye||v(fe.groups)}).catch(()=>{})};Ce();const We=window.setInterval(Ce,3e4);return()=>{ye=!0,window.clearInterval(We)}},[e]);const Ee=hE(f,p),me=nF(e),Re=eE(e),Se=Re?j.find(ye=>ye.id===Re.groupId)??null:null,Ue=Re?null:(me==null?void 0:me.agentId)??x;h.useEffect(()=>{me&&b(me.agentId)},[me==null?void 0:me.agentId]);const et=h.useRef(null);me&&(et.current=e);const Ae=ye=>{b(ye),t(tt(ye))},Be=ye=>t(Oi(ye)),it=h.useCallback((ye,Ce,We=!0)=>t(Re?Oi(Re.groupId,Ce):tt(ye,Ce),We),[t,Re==null?void 0:Re.groupId]),[qe,J]=h.useState(!1),[,we]=h.useState(0);h.useEffect(()=>{const ye=()=>{we(Ce=>Ce+1),E.session().then(Ce=>r(Ce.timezone)).catch(()=>{})};return window.addEventListener(Yp,ye),()=>window.removeEventListener(Yp,ye)},[]),h.useEffect(()=>{E.session().then(ye=>{Tv({timeFormat:ye.timeFormat??null,dateFormat:ye.dateFormat??null}),r(ye.timezone),J(!0)}).catch(()=>{})},[]);const Ye=o5(qe);f5(qe,Ye.refresh,()=>J(!1)),h.useEffect(()=>{const ye=()=>{E.overview().then(We=>{var fe;return a({approvals:We.approvals.pending,failed:We.jobs.failed??0,paused:We.paused,running:We.running??0,needs:((fe=We.needsYou)==null?void 0:fe.total)??We.approvals.pending+(We.jobs.failed??0)})}).catch(()=>{})};ye();const Ce=window.setInterval(ye,2e4);return window.addEventListener(Bi,ye),()=>{window.clearInterval(Ce),window.removeEventListener(Bi,ye)}},[]);const ot=ce(()=>Promise.resolve().then(()=>E.focus()),[],6e4),ct=h.useRef(ot.reload);ct.current=ot.reload,h.useEffect(()=>{const ye=()=>ct.current();return window.addEventListener(Bi,ye),()=>window.removeEventListener(Bi,ye)},[]);const Tt=Qq(),zn=Hq(),jt=b$()!==null,dn=Ms(aQ);h.useEffect(()=>{if(!qe)return;if(e===yF){y(!0),t(ci,!0);return}const ye=bF(e),Ce=new Date().toDateString();!ye||M0.get(ye)===Ce||(M0.set(ye,Ce),E.tipsSeenPage(ye).catch(()=>{}))},[e,qe,t]);const Un={link:Yq(window.location.hostname,Tt&&!jt),focus:((wn=ot.data)==null?void 0:wn.focus)??null,working:i.running,paused:i.paused,failed:i.failed,approvals:i.approvals,version:F?{current:F.current,latest:F.latest,updateAvailable:!F.checkout&&F.updateAvailable}:void 0,timezone:s},Q=Lq({recovery:((ks=L.data)==null?void 0:ks.active)===!0,lost:zn&&!jt,paused:i.paused}),$e=Yu(e),Xe=aE(e),K=Xe===ci,_e=N?j.find(ye=>ye.id===N.groupId)??null:null,je=ye=>v(Ce=>Ce.map(We=>We.id===ye.id?ye:We)),Ke=()=>k(null),Fe=w?n.jsx(m5,{agents:f,onClose:()=>y(!1),onCreated:ye=>{v(Ce=>[...Ce,ye]),y(!1),t(Oi(ye.id))}}):_e&&(N==null?void 0:N.kind)==="members"?n.jsx(FB,{group:_e,agents:f,onClose:Ke,onSaved:je}):_e&&(N==null?void 0:N.kind)==="rename"?n.jsx(zB,{group:_e,onClose:Ke,onSaved:ye=>{je(ye),Ke()}}):_e&&(N==null?void 0:N.kind)==="clear"?n.jsx(BB,{group:_e,onClose:Ke,onCleared:()=>{Ke(),R(ye=>ye+1),t(Oi(_e.id),!0)}}):_e&&(N==null?void 0:N.kind)==="delete"?n.jsx(WB,{group:_e,agents:f,onClose:Ke,onDeleted:ye=>{const Ce=j.findIndex(We=>We.id===_e.id);Ke(),v(We=>We.filter(fe=>fe.id!==_e.id)),C({group:_e,index:Ce,until:ye}),t(et.current??ci)}}):null,Qt=()=>{const ye=S;ye&&(C(null),He.restoreGroup(ye.group.id).then(Ce=>{v(We=>{if(We.some(Bn=>Bn.id===Ce.id))return We;const fe=[...We];return fe.splice(Math.min(Math.max(ye.index,0),fe.length),0,Ce),fe}),t(Oi(Ce.id))}).catch(()=>U(ye.group.name)))};return $e?n.jsx(gb,{delayDuration:400,children:n.jsxs(sb,{swipeDirection:"right",children:[n.jsx(sq,{navigate:t,timezone:s}),n.jsx(rb,{className:"ui-toasts"})]})}):n.jsx(M4,{picture:(Ns=f.find(ye=>ye.id===p))==null?void 0:Ns.picture,children:n.jsx(gb,{delayDuration:400,children:n.jsxs(sb,{swipeDirection:"right",children:[Fe,n.jsxs("div",{className:"wb-shell",children:[n.jsx(_q,{banners:Q,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(JW,{attention:i.needs,place:Xe,onNavigate:t,theme:l,onTheme:o,plugins:oH(q.rail,B),updateAvailable:X!==null,settingsDot:Z.length>0?uT:void 0,stale:Y,timezone:s,version:F&&!F.checkout?{current:F.current,latest:F.latest,updateAvailable:F.updateAvailable}:F?{current:F.current,updateAvailable:!1}:void 0,status:dn?n.jsx(Jq,{status:Un,onNavigate:t}):void 0}),K&&!W?n.jsx(xE,{agents:Ee,currentId:Ue,attention:z,onSelect:Ae,lastActivity:ze,working:Ie,groups:j,currentGroupId:(Se==null?void 0:Se.id)??null,onSelectGroup:Be,onNewGroup:()=>y(!0)}):null,K?n.jsx(HB,{timezone:s,agents:Ee,agentId:Se?Se.coordinator:Ue,defaultAgentId:p,group:Se,...Se?{onGroupAction:ye=>k({kind:ye,groupId:Se.id})}:{},requestedConversationId:(Re==null?void 0:Re.conversationId)??(me==null?void 0:me.conversationId),requestedTab:me==null?void 0:me.tab,onConversationOpened:it,onSelectAgent:Ae,onWorking:Le,attention:z,agentsInHeader:W,narrow:c,canvasOpen:u,onOpenCanvas:()=>d(!0),onCloseCanvas:()=>d(!1)},`room-${$}`):n.jsx("main",{"data-ground":uQ(Xe,e)?"plain":void 0,"data-layout":Xe===Zt?"split":void 0,children:n.jsx(dQ,{hash:e,place:Xe,timezone:s,navigate:t,agents:f,defaultAgentId:p,attention:z,pluginPages:q,update:X,connectionSignals:Z})})]}),dn?null:n.jsx(Xq,{status:Un,onNavigate:t})]}),P&&A?n.jsx(e5,{agent:A,agents:f,open:D,onOpenChange:O,navigate:t}):null,n.jsxs(a5,{placement:i5(P,D),children:[n.jsx(c5,{queue:Ye.queue,agents:f,navigate:t,onDismiss:Ye.dismiss}),S?n.jsx(Hd,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:g5,onUndo:Qt,onGone:()=>C(null)},S.group.id):null,I?n.jsx(Hd,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>U(null)},`late-${I}`):null,n.jsx(rb,{className:"ui-toasts"})]})]})})})}function uQ(e,t){return Gv(t)!==null}function dQ({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=Gv(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(Ij,{page:a,item:i.item??null,params:tE(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 Ct:return n.jsx(sV,{...s});case xt:return n.jsx(TH,{...s});case Zt:return n.jsx(CY,{...r});case Or:return n.jsx(T8,{...s});default:return n.jsx(CV,{...r})}}function hQ(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Xv)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function fQ({search:e=location.search}){const[t,s]=h.useState(null),r=h.useRef(!1);return h.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;E.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(OT);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(G,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(G,{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(G,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(Nt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const D0=document.getElementById("root");D0&&YS(D0).render(n.jsx(h.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(fQ,{}):n.jsx(rQ,{children:n.jsx(Bq,{children:n.jsx(XW,{children:n.jsx(cQ,{})})})})}));hQ();export{pQ as c,F$ as g};