@withbuddi/buddi 0.1.0-pre.31 → 0.1.0-pre.32
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.
- package/examples/agents/concierge/agent.md +10 -2
- package/extension/manifest.json +2 -2
- package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/cli/dist/agents-catalogue-cmd.d.ts +50 -0
- package/node_modules/@buddi/cli/dist/agents-catalogue-cmd.d.ts.map +1 -0
- package/node_modules/@buddi/cli/dist/agents-catalogue-cmd.js +328 -0
- package/node_modules/@buddi/cli/dist/agents-catalogue-cmd.js.map +1 -0
- package/node_modules/@buddi/cli/dist/args.d.ts +5 -0
- package/node_modules/@buddi/cli/dist/args.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/args.js +8 -0
- package/node_modules/@buddi/cli/dist/args.js.map +1 -1
- package/node_modules/@buddi/cli/dist/commands.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/commands.js +62 -0
- package/node_modules/@buddi/cli/dist/commands.js.map +1 -1
- package/node_modules/@buddi/cli/dist/main.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/main.js +22 -1
- package/node_modules/@buddi/cli/dist/main.js.map +1 -1
- package/node_modules/@buddi/cli/dist/skills-cmd.d.ts +15 -0
- package/node_modules/@buddi/cli/dist/skills-cmd.d.ts.map +1 -0
- package/node_modules/@buddi/cli/dist/skills-cmd.js +54 -0
- package/node_modules/@buddi/cli/dist/skills-cmd.js.map +1 -0
- package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/core/dist/agents/catalog.d.ts +11 -3
- package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/agents/catalog.js +58 -10
- package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
- package/node_modules/@buddi/core/dist/agents/frontmatter.d.ts +1 -1
- package/node_modules/@buddi/core/dist/agents/frontmatter.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/agents/frontmatter.js +1 -1
- package/node_modules/@buddi/core/dist/agents/frontmatter.js.map +1 -1
- package/node_modules/@buddi/core/dist/agents/skills.d.ts +29 -3
- package/node_modules/@buddi/core/dist/agents/skills.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/agents/skills.js +49 -2
- package/node_modules/@buddi/core/dist/agents/skills.js.map +1 -1
- package/node_modules/@buddi/core/dist/offers/store.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/offers/store.js +9 -4
- package/node_modules/@buddi/core/dist/offers/store.js.map +1 -1
- package/node_modules/@buddi/core/dist/offers/types.d.ts +24 -1
- package/node_modules/@buddi/core/dist/offers/types.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/offers/types.js +23 -1
- package/node_modules/@buddi/core/dist/offers/types.js.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +46 -0
- package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/missions.js +119 -22
- package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/runner.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/runner.js +6 -1
- package/node_modules/@buddi/core/dist/scheduler/runner.js.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/types.d.ts +15 -0
- package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/scheduler/types.js +5 -0
- package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
- package/node_modules/@buddi/core/migrations/070_offer_handoff.sql +15 -0
- package/node_modules/@buddi/core/migrations/071_mission_lifespan.sql +19 -0
- package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/gateway/dist/agents/canvas.d.ts +6 -6
- package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +313 -0
- package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +356 -0
- package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +361 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +1021 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-names.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents/platform-names.js +3 -0
- package/node_modules/@buddi/gateway/dist/agents/platform-names.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents/platform.d.ts +62 -25
- package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents/platform.js +121 -29
- package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents-cli.d.ts +1 -1
- package/node_modules/@buddi/gateway/dist/agents-cli.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents-cli.js +6 -0
- package/node_modules/@buddi/gateway/dist/agents-cli.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/bootstrap.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/bootstrap.js +13 -1
- package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +6 -0
- package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/execute.js +74 -2
- package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts +10 -0
- package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/reminders.js +84 -18
- package/node_modules/@buddi/gateway/dist/missions/reminders.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/zone-provenance.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/missions/zone-provenance.js +5 -10
- package/node_modules/@buddi/gateway/dist/missions/zone-provenance.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/load.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/load.js +12 -5
- package/node_modules/@buddi/gateway/dist/plugins/load.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/provenance.d.ts +35 -1
- package/node_modules/@buddi/gateway/dist/plugins/provenance.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/provenance.js +39 -1
- package/node_modules/@buddi/gateway/dist/plugins/provenance.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/surfaces/handoff.d.ts +62 -0
- package/node_modules/@buddi/gateway/dist/surfaces/handoff.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/surfaces/handoff.js +121 -0
- package/node_modules/@buddi/gateway/dist/surfaces/handoff.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.d.ts +2 -0
- package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.js +1 -1
- package/node_modules/@buddi/gateway/dist/surfaces/offered-actions.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/main.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/main.js +7 -1
- package/node_modules/@buddi/gateway/dist/telegram/main.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts +9 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.js +58 -6
- package/node_modules/@buddi/gateway/dist/telegram/surface.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts +0 -30
- package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agent-offers.js +1 -64
- package/node_modules/@buddi/gateway/dist/web/agent-offers.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts +1 -0
- package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/api-routes.js +118 -4
- package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/catalogue-source.d.ts +33 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue-source.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue-source.js +124 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue-source.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue.d.ts +155 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue.js +734 -0
- package/node_modules/@buddi/gateway/dist/web/catalogue.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/chat.d.ts +3 -1
- package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/chat.js +8 -1
- package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/client-key.d.ts +24 -0
- package/node_modules/@buddi/gateway/dist/web/client-key.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/client-key.js +17 -0
- package/node_modules/@buddi/gateway/dist/web/client-key.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/market.d.ts +1 -0
- package/node_modules/@buddi/gateway/dist/web/market.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/market.js +6 -0
- package/node_modules/@buddi/gateway/dist/web/market.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/read.d.ts +10 -0
- package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/read.js +5 -0
- package/node_modules/@buddi/gateway/dist/web/read.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/server.js +137 -10
- package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/skills.d.ts +120 -0
- package/node_modules/@buddi/gateway/dist/web/skills.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/skills.js +672 -0
- package/node_modules/@buddi/gateway/dist/web/skills.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/web/take-on.d.ts +35 -1
- package/node_modules/@buddi/gateway/dist/web/take-on.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/take-on.js +76 -51
- package/node_modules/@buddi/gateway/dist/web/take-on.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/write.d.ts +9 -1
- package/node_modules/@buddi/gateway/dist/web/write.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/write.js +35 -2
- package/node_modules/@buddi/gateway/dist/web/write.js.map +1 -1
- package/node_modules/@buddi/gateway/package.json +0 -1
- package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/packages/cli/dist/.tsbuildinfo +1 -1
- package/packages/cli/dist/agents-catalogue-cmd.d.ts +50 -0
- package/packages/cli/dist/agents-catalogue-cmd.d.ts.map +1 -0
- package/packages/cli/dist/agents-catalogue-cmd.js +328 -0
- package/packages/cli/dist/agents-catalogue-cmd.js.map +1 -0
- package/packages/cli/dist/args.d.ts +5 -0
- package/packages/cli/dist/args.d.ts.map +1 -1
- package/packages/cli/dist/args.js +8 -0
- package/packages/cli/dist/args.js.map +1 -1
- package/packages/cli/dist/commands.d.ts.map +1 -1
- package/packages/cli/dist/commands.js +62 -0
- package/packages/cli/dist/commands.js.map +1 -1
- package/packages/cli/dist/main.d.ts.map +1 -1
- package/packages/cli/dist/main.js +22 -1
- package/packages/cli/dist/main.js.map +1 -1
- package/packages/cli/dist/skills-cmd.d.ts +15 -0
- package/packages/cli/dist/skills-cmd.d.ts.map +1 -0
- package/packages/cli/dist/skills-cmd.js +54 -0
- package/packages/cli/dist/skills-cmd.js.map +1 -0
- package/packages/core/dist/.tsbuildinfo +1 -1
- package/packages/core/dist/agents/catalog.d.ts +11 -3
- package/packages/core/dist/agents/catalog.d.ts.map +1 -1
- package/packages/core/dist/agents/catalog.js +58 -10
- package/packages/core/dist/agents/catalog.js.map +1 -1
- package/packages/core/dist/agents/frontmatter.d.ts +1 -1
- package/packages/core/dist/agents/frontmatter.d.ts.map +1 -1
- package/packages/core/dist/agents/frontmatter.js +1 -1
- package/packages/core/dist/agents/frontmatter.js.map +1 -1
- package/packages/core/dist/agents/skills.d.ts +29 -3
- package/packages/core/dist/agents/skills.d.ts.map +1 -1
- package/packages/core/dist/agents/skills.js +49 -2
- package/packages/core/dist/agents/skills.js.map +1 -1
- package/packages/core/dist/offers/store.d.ts.map +1 -1
- package/packages/core/dist/offers/store.js +9 -4
- package/packages/core/dist/offers/store.js.map +1 -1
- package/packages/core/dist/offers/types.d.ts +24 -1
- package/packages/core/dist/offers/types.d.ts.map +1 -1
- package/packages/core/dist/offers/types.js +23 -1
- package/packages/core/dist/offers/types.js.map +1 -1
- package/packages/core/dist/scheduler/missions.d.ts +46 -0
- package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
- package/packages/core/dist/scheduler/missions.js +119 -22
- package/packages/core/dist/scheduler/missions.js.map +1 -1
- package/packages/core/dist/scheduler/runner.d.ts.map +1 -1
- package/packages/core/dist/scheduler/runner.js +6 -1
- package/packages/core/dist/scheduler/runner.js.map +1 -1
- package/packages/core/dist/scheduler/types.d.ts +15 -0
- package/packages/core/dist/scheduler/types.d.ts.map +1 -1
- package/packages/core/dist/scheduler/types.js +5 -0
- package/packages/core/dist/scheduler/types.js.map +1 -1
- package/packages/core/migrations/070_offer_handoff.sql +15 -0
- package/packages/core/migrations/071_mission_lifespan.sql +19 -0
- package/packages/gateway/dist/.tsbuildinfo +1 -1
- package/packages/gateway/dist/agents/canvas.d.ts +6 -6
- package/packages/gateway/dist/agents/catalogue-package.d.ts +313 -0
- package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -0
- package/packages/gateway/dist/agents/catalogue-package.js +356 -0
- package/packages/gateway/dist/agents/catalogue-package.js.map +1 -0
- package/packages/gateway/dist/agents/platform-catalogue.d.ts +361 -0
- package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -0
- package/packages/gateway/dist/agents/platform-catalogue.js +1021 -0
- package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -0
- package/packages/gateway/dist/agents/platform-names.d.ts.map +1 -1
- package/packages/gateway/dist/agents/platform-names.js +3 -0
- package/packages/gateway/dist/agents/platform-names.js.map +1 -1
- package/packages/gateway/dist/agents/platform.d.ts +62 -25
- package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
- package/packages/gateway/dist/agents/platform.js +121 -29
- package/packages/gateway/dist/agents/platform.js.map +1 -1
- package/packages/gateway/dist/agents-cli.d.ts +1 -1
- package/packages/gateway/dist/agents-cli.d.ts.map +1 -1
- package/packages/gateway/dist/agents-cli.js +6 -0
- package/packages/gateway/dist/agents-cli.js.map +1 -1
- package/packages/gateway/dist/bootstrap.d.ts.map +1 -1
- package/packages/gateway/dist/bootstrap.js +13 -1
- package/packages/gateway/dist/bootstrap.js.map +1 -1
- package/packages/gateway/dist/missions/execute.d.ts +6 -0
- package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
- package/packages/gateway/dist/missions/execute.js +74 -2
- package/packages/gateway/dist/missions/execute.js.map +1 -1
- package/packages/gateway/dist/missions/reminders.d.ts +10 -0
- package/packages/gateway/dist/missions/reminders.d.ts.map +1 -1
- package/packages/gateway/dist/missions/reminders.js +84 -18
- package/packages/gateway/dist/missions/reminders.js.map +1 -1
- package/packages/gateway/dist/missions/zone-provenance.d.ts.map +1 -1
- package/packages/gateway/dist/missions/zone-provenance.js +5 -10
- package/packages/gateway/dist/missions/zone-provenance.js.map +1 -1
- package/packages/gateway/dist/plugins/load.d.ts.map +1 -1
- package/packages/gateway/dist/plugins/load.js +12 -5
- package/packages/gateway/dist/plugins/load.js.map +1 -1
- package/packages/gateway/dist/plugins/provenance.d.ts +35 -1
- package/packages/gateway/dist/plugins/provenance.d.ts.map +1 -1
- package/packages/gateway/dist/plugins/provenance.js +39 -1
- package/packages/gateway/dist/plugins/provenance.js.map +1 -1
- package/packages/gateway/dist/surfaces/handoff.d.ts +62 -0
- package/packages/gateway/dist/surfaces/handoff.d.ts.map +1 -0
- package/packages/gateway/dist/surfaces/handoff.js +121 -0
- package/packages/gateway/dist/surfaces/handoff.js.map +1 -0
- package/packages/gateway/dist/surfaces/offered-actions.d.ts +2 -0
- package/packages/gateway/dist/surfaces/offered-actions.d.ts.map +1 -1
- package/packages/gateway/dist/surfaces/offered-actions.js +1 -1
- package/packages/gateway/dist/surfaces/offered-actions.js.map +1 -1
- package/packages/gateway/dist/telegram/main.d.ts.map +1 -1
- package/packages/gateway/dist/telegram/main.js +7 -1
- package/packages/gateway/dist/telegram/main.js.map +1 -1
- package/packages/gateway/dist/telegram/surface.d.ts +9 -1
- package/packages/gateway/dist/telegram/surface.d.ts.map +1 -1
- package/packages/gateway/dist/telegram/surface.js +58 -6
- package/packages/gateway/dist/telegram/surface.js.map +1 -1
- package/packages/gateway/dist/web/agent-offers.d.ts +0 -30
- package/packages/gateway/dist/web/agent-offers.d.ts.map +1 -1
- package/packages/gateway/dist/web/agent-offers.js +1 -64
- package/packages/gateway/dist/web/agent-offers.js.map +1 -1
- package/packages/gateway/dist/web/api-routes.d.ts +1 -0
- package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
- package/packages/gateway/dist/web/api-routes.js +118 -4
- package/packages/gateway/dist/web/api-routes.js.map +1 -1
- package/packages/gateway/dist/web/catalogue-source.d.ts +33 -0
- package/packages/gateway/dist/web/catalogue-source.d.ts.map +1 -0
- package/packages/gateway/dist/web/catalogue-source.js +124 -0
- package/packages/gateway/dist/web/catalogue-source.js.map +1 -0
- package/packages/gateway/dist/web/catalogue.d.ts +155 -0
- package/packages/gateway/dist/web/catalogue.d.ts.map +1 -0
- package/packages/gateway/dist/web/catalogue.js +734 -0
- package/packages/gateway/dist/web/catalogue.js.map +1 -0
- package/packages/gateway/dist/web/chat.d.ts +3 -1
- package/packages/gateway/dist/web/chat.d.ts.map +1 -1
- package/packages/gateway/dist/web/chat.js +8 -1
- package/packages/gateway/dist/web/chat.js.map +1 -1
- package/packages/gateway/dist/web/client-key.d.ts +24 -0
- package/packages/gateway/dist/web/client-key.d.ts.map +1 -0
- package/packages/gateway/dist/web/client-key.js +17 -0
- package/packages/gateway/dist/web/client-key.js.map +1 -0
- package/packages/gateway/dist/web/market.d.ts +1 -0
- package/packages/gateway/dist/web/market.d.ts.map +1 -1
- package/packages/gateway/dist/web/market.js +6 -0
- package/packages/gateway/dist/web/market.js.map +1 -1
- package/packages/gateway/dist/web/read.d.ts +10 -0
- package/packages/gateway/dist/web/read.d.ts.map +1 -1
- package/packages/gateway/dist/web/read.js +5 -0
- package/packages/gateway/dist/web/read.js.map +1 -1
- package/packages/gateway/dist/web/server.d.ts.map +1 -1
- package/packages/gateway/dist/web/server.js +137 -10
- package/packages/gateway/dist/web/server.js.map +1 -1
- package/packages/gateway/dist/web/skills.d.ts +120 -0
- package/packages/gateway/dist/web/skills.d.ts.map +1 -0
- package/packages/gateway/dist/web/skills.js +672 -0
- package/packages/gateway/dist/web/skills.js.map +1 -0
- package/packages/gateway/dist/web/take-on.d.ts +35 -1
- package/packages/gateway/dist/web/take-on.d.ts.map +1 -1
- package/packages/gateway/dist/web/take-on.js +76 -51
- package/packages/gateway/dist/web/take-on.js.map +1 -1
- package/packages/gateway/dist/web/write.d.ts +9 -1
- package/packages/gateway/dist/web/write.d.ts.map +1 -1
- package/packages/gateway/dist/web/write.js +35 -2
- package/packages/gateway/dist/web/write.js.map +1 -1
- package/packages/gateway/package.json +0 -1
- package/packages/install/dist/.tsbuildinfo +1 -1
- package/packages/runtime/dist/.tsbuildinfo +1 -1
- package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
- package/packages/tools/browser/dist/.tsbuildinfo +1 -1
- package/packages/tools/email/dist/.tsbuildinfo +1 -1
- package/packages/tools/host/dist/.tsbuildinfo +1 -1
- package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
- package/packages/tools/memory/dist/.tsbuildinfo +1 -1
- package/packages/tools/web/dist/.tsbuildinfo +1 -1
- package/packages/web/dist/assets/index-BldmgplG.css +1 -0
- package/packages/web/dist/assets/index-C8GaSH__.js +132 -0
- package/packages/web/dist/assets/{lottie_light-DU37j1-6.js → lottie_light-DdwKPR04.js} +1 -1
- package/packages/web/dist/build.json +1 -1
- package/packages/web/dist/index.html +2 -2
- package/packages/web/dist/precache.json +4 -4
- package/node_modules/@buddi/gateway/dist/agents/starter-team.d.ts +0 -59
- package/node_modules/@buddi/gateway/dist/agents/starter-team.d.ts.map +0 -1
- package/node_modules/@buddi/gateway/dist/agents/starter-team.js +0 -156
- package/node_modules/@buddi/gateway/dist/agents/starter-team.js.map +0 -1
- package/node_modules/@buddi/gateway/src/agents/starter/keeper/agent.md +0 -31
- package/node_modules/@buddi/gateway/src/agents/starter/keeper/skills/keeping-a-history.md +0 -22
- package/node_modules/@buddi/gateway/src/agents/starter/planner/agent.md +0 -30
- package/node_modules/@buddi/gateway/src/agents/starter/planner/skills/holding-a-follow-up.md +0 -17
- package/node_modules/@buddi/gateway/src/agents/starter/planner/skills/writing-the-morning-brief.md +0 -32
- package/node_modules/@buddi/gateway/src/agents/starter/scout/agent.md +0 -33
- package/node_modules/@buddi/gateway/src/agents/starter/scout/skills/answering-with-sources.md +0 -23
- package/node_modules/@buddi/gateway/src/agents/starter/scout/skills/the-web-is-evidence.md +0 -25
- package/packages/gateway/dist/agents/starter-team.d.ts +0 -59
- package/packages/gateway/dist/agents/starter-team.d.ts.map +0 -1
- package/packages/gateway/dist/agents/starter-team.js +0 -156
- package/packages/gateway/dist/agents/starter-team.js.map +0 -1
- package/packages/gateway/src/agents/starter/keeper/agent.md +0 -31
- package/packages/gateway/src/agents/starter/keeper/skills/keeping-a-history.md +0 -22
- package/packages/gateway/src/agents/starter/planner/agent.md +0 -30
- package/packages/gateway/src/agents/starter/planner/skills/holding-a-follow-up.md +0 -17
- package/packages/gateway/src/agents/starter/planner/skills/writing-the-morning-brief.md +0 -32
- package/packages/gateway/src/agents/starter/scout/agent.md +0 -33
- package/packages/gateway/src/agents/starter/scout/skills/answering-with-sources.md +0 -23
- package/packages/gateway/src/agents/starter/scout/skills/the-web-is-evidence.md +0 -25
- package/packages/web/dist/assets/index-BYRgwiZp.css +0 -1
- package/packages/web/dist/assets/index-Qb1N-6kN.js +0 -129
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var vy=e=>{throw TypeError(e)};var jy=(e,t,s)=>t.has(e)||vy("Cannot "+s);var gn=(e,t,s)=>(jy(e,t,"read from private field"),s?s.call(e):t.get(e)),wy=(e,t,s)=>t.has(e)?vy("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),Ff=(e,t,s,r)=>(jy(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function LI(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 cX=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function FI(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var bN={exports:{}},bh={},kN={exports:{}},tt={};/**
|
|
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 Cc=Symbol.for("react.element"),_I=Symbol.for("react.portal"),zI=Symbol.for("react.fragment"),UI=Symbol.for("react.strict_mode"),BI=Symbol.for("react.profiler"),WI=Symbol.for("react.provider"),HI=Symbol.for("react.context"),KI=Symbol.for("react.forward_ref"),VI=Symbol.for("react.suspense"),GI=Symbol.for("react.memo"),YI=Symbol.for("react.lazy"),yy=Symbol.iterator;function qI(e){return e===null||typeof e!="object"?null:(e=yy&&e[yy]||e["@@iterator"],typeof e=="function"?e:null)}var NN={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},SN=Object.assign,CN={};function Tl(e,t,s){this.props=e,this.context=t,this.refs=CN,this.updater=s||NN}Tl.prototype.isReactComponent={};Tl.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")};Tl.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function EN(){}EN.prototype=Tl.prototype;function Wx(e,t,s){this.props=e,this.context=t,this.refs=CN,this.updater=s||NN}var Hx=Wx.prototype=new EN;Hx.constructor=Wx;SN(Hx,Tl.prototype);Hx.isPureReactComponent=!0;var by=Array.isArray,AN=Object.prototype.hasOwnProperty,Kx={current:null},TN={key:!0,ref:!0,__self:!0,__source:!0};function $N(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)AN.call(t,r)&&!TN.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:Cc,type:e,key:a,ref:l,props:i,_owner:Kx.current}}function JI(e,t){return{$$typeof:Cc,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Vx(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cc}function QI(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var ky=/\/+/g;function _f(e,t){return typeof e=="object"&&e!==null&&e.key!=null?QI(""+e.key):t.toString(36)}function Vu(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 Cc:case _I:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+_f(l,0):r,by(i)?(s="",e!=null&&(s=e.replace(ky,"$&/")+"/"),Vu(i,t,s,"",function(u){return u})):i!=null&&(Vx(i)&&(i=JI(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(ky,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",by(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+_f(a,o);l+=Vu(a,t,s,c,i)}else if(c=qI(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+_f(a,o++),l+=Vu(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 su(e,t,s){if(e==null)return e;var r=[],i=0;return Vu(e,r,"","",function(a){return t.call(s,a,i++)}),r}function XI(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 Rn={current:null},Gu={transition:null},ZI={ReactCurrentDispatcher:Rn,ReactCurrentBatchConfig:Gu,ReactCurrentOwner:Kx};function RN(){throw Error("act(...) is not supported in production builds of React.")}tt.Children={map:su,forEach:function(e,t,s){su(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return su(e,function(){t++}),t},toArray:function(e){return su(e,function(t){return t})||[]},only:function(e){if(!Vx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};tt.Component=Tl;tt.Fragment=zI;tt.Profiler=BI;tt.PureComponent=Wx;tt.StrictMode=UI;tt.Suspense=VI;tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=ZI;tt.act=RN;tt.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=SN({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=Kx.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)AN.call(t,c)&&!TN.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:Cc,type:e.type,key:i,ref:a,props:r,_owner:l}};tt.createContext=function(e){return e={$$typeof:HI,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:WI,_context:e},e.Consumer=e};tt.createElement=$N;tt.createFactory=function(e){var t=$N.bind(null,e);return t.type=e,t};tt.createRef=function(){return{current:null}};tt.forwardRef=function(e){return{$$typeof:KI,render:e}};tt.isValidElement=Vx;tt.lazy=function(e){return{$$typeof:YI,_payload:{_status:-1,_result:e},_init:XI}};tt.memo=function(e,t){return{$$typeof:GI,type:e,compare:t===void 0?null:t}};tt.startTransition=function(e){var t=Gu.transition;Gu.transition={};try{e()}finally{Gu.transition=t}};tt.unstable_act=RN;tt.useCallback=function(e,t){return Rn.current.useCallback(e,t)};tt.useContext=function(e){return Rn.current.useContext(e)};tt.useDebugValue=function(){};tt.useDeferredValue=function(e){return Rn.current.useDeferredValue(e)};tt.useEffect=function(e,t){return Rn.current.useEffect(e,t)};tt.useId=function(){return Rn.current.useId()};tt.useImperativeHandle=function(e,t,s){return Rn.current.useImperativeHandle(e,t,s)};tt.useInsertionEffect=function(e,t){return Rn.current.useInsertionEffect(e,t)};tt.useLayoutEffect=function(e,t){return Rn.current.useLayoutEffect(e,t)};tt.useMemo=function(e,t){return Rn.current.useMemo(e,t)};tt.useReducer=function(e,t,s){return Rn.current.useReducer(e,t,s)};tt.useRef=function(e){return Rn.current.useRef(e)};tt.useState=function(e){return Rn.current.useState(e)};tt.useSyncExternalStore=function(e,t,s){return Rn.current.useSyncExternalStore(e,t,s)};tt.useTransition=function(){return Rn.current.useTransition()};tt.version="18.3.1";kN.exports=tt;var d=kN.exports;const eP=FI(d),$l=LI({__proto__:null,default:eP},[d]);/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.production.min.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var tP=d,nP=Symbol.for("react.element"),sP=Symbol.for("react.fragment"),rP=Object.prototype.hasOwnProperty,iP=tP.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,aP={key:!0,ref:!0,__self:!0,__source:!0};function IN(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)rP.call(t,r)&&!aP.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:nP,type:e,key:a,ref:l,props:i,_owner:iP.current}}bh.Fragment=sP;bh.jsx=IN;bh.jsxs=IN;bN.exports=bh;var n=bN.exports,PN={exports:{}},is={},MN={exports:{}},DN={};/**
|
|
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(D,H){var U=D.length;D.push(H);e:for(;0<U;){var q=U-1>>>1,B=D[q];if(0<i(B,H))D[q]=H,D[U]=B,U=q;else break e}}function s(D){return D.length===0?null:D[0]}function r(D){if(D.length===0)return null;var H=D[0],U=D.pop();if(U!==H){D[0]=U;e:for(var q=0,B=D.length,Y=B>>>1;q<Y;){var F=2*(q+1)-1,X=D[F],Q=F+1,ee=D[Q];if(0>i(X,U))Q<B&&0>i(ee,X)?(D[q]=ee,D[Q]=U,q=Q):(D[q]=X,D[F]=U,q=F);else if(Q<B&&0>i(ee,U))D[q]=ee,D[Q]=U,q=Q;else break e}}return H}function i(D,H){var U=D.sortIndex-H.sortIndex;return U!==0?U:D.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=1,f=null,m=3,p=!1,g=!1,v=!1,b=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,x=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(D){for(var H=s(u);H!==null;){if(H.callback===null)r(u);else if(H.startTime<=D)r(u),H.sortIndex=H.expirationTime,t(c,H);else break;H=s(u)}}function y(D){if(v=!1,w(D),!g)if(s(c)!==null)g=!0,O(k);else{var H=s(u);H!==null&&M(y,H.startTime-D)}}function k(D,H){g=!1,v&&(v=!1,j(C),C=-1),p=!0;var U=m;try{for(w(H),f=s(c);f!==null&&(!(f.expirationTime>H)||D&&!I());){var q=f.callback;if(typeof q=="function"){f.callback=null,m=f.priorityLevel;var B=q(f.expirationTime<=H);H=e.unstable_now(),typeof B=="function"?f.callback=B:f===s(c)&&r(c),w(H)}else r(c);f=s(c)}if(f!==null)var Y=!0;else{var F=s(u);F!==null&&M(y,F.startTime-H),Y=!1}return Y}finally{f=null,m=U,p=!1}}var N=!1,S=null,C=-1,T=5,R=-1;function I(){return!(e.unstable_now()-R<T)}function L(){if(S!==null){var D=e.unstable_now();R=D;var H=!0;try{H=S(!0,D)}finally{H?W():(N=!1,S=null)}}else N=!1}var W;if(typeof x=="function")W=function(){x(L)};else if(typeof MessageChannel<"u"){var $=new MessageChannel,P=$.port2;$.port1.onmessage=L,W=function(){P.postMessage(null)}}else W=function(){b(L,0)};function O(D){S=D,N||(N=!0,W())}function M(D,H){C=b(function(){D(e.unstable_now())},H)}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(D){D.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,O(k))},e.unstable_forceFrameRate=function(D){0>D||125<D?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):T=0<D?Math.floor(1e3/D):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(D){switch(m){case 1:case 2:case 3:var H=3;break;default:H=m}var U=m;m=H;try{return D()}finally{m=U}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(D,H){switch(D){case 1:case 2:case 3:case 4:case 5:break;default:D=3}var U=m;m=D;try{return H()}finally{m=U}},e.unstable_scheduleCallback=function(D,H,U){var q=e.unstable_now();switch(typeof U=="object"&&U!==null?(U=U.delay,U=typeof U=="number"&&0<U?q+U:q):U=q,D){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=U+B,D={id:h++,callback:H,priorityLevel:D,startTime:U,expirationTime:B,sortIndex:-1},U>q?(D.sortIndex=U,t(u,D),s(c)===null&&D===s(u)&&(v?(j(C),C=-1):v=!0,M(y,U-q))):(D.sortIndex=B,t(c,D),g||p||(g=!0,O(k))),D},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(D){var H=m;return function(){var U=m;m=H;try{return D.apply(this,arguments)}finally{m=U}}}})(DN);MN.exports=DN;var lP=MN.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 oP=d,ns=lP;function xe(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 ON=new Set,zo={};function ha(e,t){ul(e,t),ul(e+"Capture",t)}function ul(e,t){for(zo[e]=t,e=0;e<t.length;e++)ON.add(t[e])}var Fr=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),pp=Object.prototype.hasOwnProperty,cP=/^[: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]*$/,Ny={},Sy={};function uP(e){return pp.call(Sy,e)?!0:pp.call(Ny,e)?!1:cP.test(e)?Sy[e]=!0:(Ny[e]=!0,!1)}function dP(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 hP(e,t,s,r){if(t===null||typeof t>"u"||dP(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 In(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 fn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){fn[e]=new In(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];fn[t]=new In(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){fn[e]=new In(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){fn[e]=new In(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){fn[e]=new In(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){fn[e]=new In(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){fn[e]=new In(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){fn[e]=new In(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){fn[e]=new In(e,5,!1,e.toLowerCase(),null,!1,!1)});var Gx=/[\-:]([a-z])/g;function Yx(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(Gx,Yx);fn[t]=new In(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(Gx,Yx);fn[t]=new In(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(Gx,Yx);fn[t]=new In(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){fn[e]=new In(e,1,!1,e.toLowerCase(),null,!1,!1)});fn.xlinkHref=new In("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){fn[e]=new In(e,1,!1,e.toLowerCase(),null,!0,!0)});function qx(e,t,s,r){var i=fn.hasOwnProperty(t)?fn[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(hP(t,s,i,r)&&(s=null),r||i===null?uP(t)&&(s===null?e.removeAttribute(t):e.setAttribute(t,""+s)):i.mustUseProperty?e[i.propertyName]=s===null?i.type===3?!1:"":s:(t=i.attributeName,r=i.attributeNamespace,s===null?e.removeAttribute(t):(i=i.type,s=i===3||i===4&&s===!0?"":""+s,r?e.setAttributeNS(r,t,s):e.setAttribute(t,s))))}var Gr=oP.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ru=Symbol.for("react.element"),Oa=Symbol.for("react.portal"),La=Symbol.for("react.fragment"),Jx=Symbol.for("react.strict_mode"),gp=Symbol.for("react.profiler"),LN=Symbol.for("react.provider"),FN=Symbol.for("react.context"),Qx=Symbol.for("react.forward_ref"),xp=Symbol.for("react.suspense"),vp=Symbol.for("react.suspense_list"),Xx=Symbol.for("react.memo"),Zr=Symbol.for("react.lazy"),_N=Symbol.for("react.offscreen"),Cy=Symbol.iterator;function no(e){return e===null||typeof e!="object"?null:(e=Cy&&e[Cy]||e["@@iterator"],typeof e=="function"?e:null)}var Mt=Object.assign,zf;function vo(e){if(zf===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);zf=t&&t[1]||""}return`
|
|
34
|
+
`+zf+e}var Uf=!1;function Bf(e,t){if(!e||Uf)return"";Uf=!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{Uf=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?vo(e):""}function fP(e){switch(e.tag){case 5:return vo(e.type);case 16:return vo("Lazy");case 13:return vo("Suspense");case 19:return vo("SuspenseList");case 0:case 2:case 15:return e=Bf(e.type,!1),e;case 11:return e=Bf(e.type.render,!1),e;case 1:return e=Bf(e.type,!0),e;default:return""}}function jp(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 La:return"Fragment";case Oa:return"Portal";case gp:return"Profiler";case Jx:return"StrictMode";case xp:return"Suspense";case vp:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case FN:return(e.displayName||"Context")+".Consumer";case LN:return(e._context.displayName||"Context")+".Provider";case Qx:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Xx:return t=e.displayName||null,t!==null?t:jp(e.type)||"Memo";case Zr:t=e._payload,e=e._init;try{return jp(e(t))}catch{}}return null}function mP(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 jp(t);case 8:return t===Jx?"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 vi(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function zN(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function pP(e){var t=zN(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 iu(e){e._valueTracker||(e._valueTracker=pP(e))}function UN(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=zN(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function jd(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 wp(e,t){var s=t.checked;return Mt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Ey(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=vi(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 BN(e,t){t=t.checked,t!=null&&qx(e,"checked",t,!1)}function yp(e,t){BN(e,t);var s=vi(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")?bp(e,t.type,s):t.hasOwnProperty("defaultValue")&&bp(e,t.type,vi(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Ay(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 bp(e,t,s){(t!=="number"||jd(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var jo=Array.isArray;function Xa(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=""+vi(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 kp(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(xe(91));return Mt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Ty(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(xe(92));if(jo(s)){if(1<s.length)throw Error(xe(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:vi(s)}}function WN(e,t){var s=vi(t.value),r=vi(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 $y(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function HN(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 Np(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?HN(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var au,KN=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(au=au||document.createElement("div"),au.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=au.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Uo(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var So={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},gP=["Webkit","ms","Moz","O"];Object.keys(So).forEach(function(e){gP.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),So[t]=So[e]})});function VN(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||So.hasOwnProperty(e)&&So[e]?(""+t).trim():t+"px"}function GN(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=VN(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var xP=Mt({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 Sp(e,t){if(t){if(xP[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(xe(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(xe(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(xe(61))}if(t.style!=null&&typeof t.style!="object")throw Error(xe(62))}}function Cp(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 Ep=null;function Zx(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Ap=null,Za=null,el=null;function Ry(e){if(e=Tc(e)){if(typeof Ap!="function")throw Error(xe(280));var t=e.stateNode;t&&(t=Eh(t),Ap(e.stateNode,e.type,t))}}function YN(e){Za?el?el.push(e):el=[e]:Za=e}function qN(){if(Za){var e=Za,t=el;if(el=Za=null,Ry(e),t)for(e=0;e<t.length;e++)Ry(t[e])}}function JN(e,t){return e(t)}function QN(){}var Wf=!1;function XN(e,t,s){if(Wf)return e(t,s);Wf=!0;try{return JN(e,t,s)}finally{Wf=!1,(Za!==null||el!==null)&&(QN(),qN())}}function Bo(e,t){var s=e.stateNode;if(s===null)return null;var r=Eh(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(xe(231,t,typeof s));return s}var Tp=!1;if(Fr)try{var so={};Object.defineProperty(so,"passive",{get:function(){Tp=!0}}),window.addEventListener("test",so,so),window.removeEventListener("test",so,so)}catch{Tp=!1}function vP(e,t,s,r,i,a,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{t.apply(s,u)}catch(h){this.onError(h)}}var Co=!1,wd=null,yd=!1,$p=null,jP={onError:function(e){Co=!0,wd=e}};function wP(e,t,s,r,i,a,l,o,c){Co=!1,wd=null,vP.apply(jP,arguments)}function yP(e,t,s,r,i,a,l,o,c){if(wP.apply(this,arguments),Co){if(Co){var u=wd;Co=!1,wd=null}else throw Error(xe(198));yd||(yd=!0,$p=u)}}function fa(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 ZN(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 Iy(e){if(fa(e)!==e)throw Error(xe(188))}function bP(e){var t=e.alternate;if(!t){if(t=fa(e),t===null)throw Error(xe(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 Iy(i),e;if(a===r)return Iy(i),t;a=a.sibling}throw Error(xe(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(xe(189))}}if(s.alternate!==r)throw Error(xe(190))}if(s.tag!==3)throw Error(xe(188));return s.stateNode.current===s?e:t}function eS(e){return e=bP(e),e!==null?tS(e):null}function tS(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=tS(e);if(t!==null)return t;e=e.sibling}return null}var nS=ns.unstable_scheduleCallback,Py=ns.unstable_cancelCallback,kP=ns.unstable_shouldYield,NP=ns.unstable_requestPaint,Lt=ns.unstable_now,SP=ns.unstable_getCurrentPriorityLevel,ev=ns.unstable_ImmediatePriority,sS=ns.unstable_UserBlockingPriority,bd=ns.unstable_NormalPriority,CP=ns.unstable_LowPriority,rS=ns.unstable_IdlePriority,kh=null,ar=null;function EP(e){if(ar&&typeof ar.onCommitFiberRoot=="function")try{ar.onCommitFiberRoot(kh,e,void 0,(e.current.flags&128)===128)}catch{}}var Ds=Math.clz32?Math.clz32:$P,AP=Math.log,TP=Math.LN2;function $P(e){return e>>>=0,e===0?32:31-(AP(e)/TP|0)|0}var lu=64,ou=4194304;function wo(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 kd(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=wo(o):(a&=l,a!==0&&(r=wo(a)))}else l=s&~i,l!==0?r=wo(l):a!==0&&(r=wo(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-Ds(t),i=1<<s,r|=e[s],t&=~i;return r}function RP(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 IP(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-Ds(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=RP(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function Rp(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function iS(){var e=lu;return lu<<=1,!(lu&4194240)&&(lu=64),e}function Hf(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Ec(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Ds(t),e[t]=s}function PP(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-Ds(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function tv(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-Ds(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var pt=0;function aS(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var lS,nv,oS,cS,uS,Ip=!1,cu=[],li=null,oi=null,ci=null,Wo=new Map,Ho=new Map,ti=[],MP="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 My(e,t){switch(e){case"focusin":case"focusout":li=null;break;case"dragenter":case"dragleave":oi=null;break;case"mouseover":case"mouseout":ci=null;break;case"pointerover":case"pointerout":Wo.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":Ho.delete(t.pointerId)}}function ro(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=Tc(t),t!==null&&nv(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function DP(e,t,s,r,i){switch(t){case"focusin":return li=ro(li,e,t,s,r,i),!0;case"dragenter":return oi=ro(oi,e,t,s,r,i),!0;case"mouseover":return ci=ro(ci,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return Wo.set(a,ro(Wo.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,Ho.set(a,ro(Ho.get(a)||null,e,t,s,r,i)),!0}return!1}function dS(e){var t=Gi(e.target);if(t!==null){var s=fa(t);if(s!==null){if(t=s.tag,t===13){if(t=ZN(s),t!==null){e.blockedOn=t,uS(e.priority,function(){oS(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 Yu(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=Pp(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Ep=r,s.target.dispatchEvent(r),Ep=null}else return t=Tc(s),t!==null&&nv(t),e.blockedOn=s,!1;t.shift()}return!0}function Dy(e,t,s){Yu(e)&&s.delete(t)}function OP(){Ip=!1,li!==null&&Yu(li)&&(li=null),oi!==null&&Yu(oi)&&(oi=null),ci!==null&&Yu(ci)&&(ci=null),Wo.forEach(Dy),Ho.forEach(Dy)}function io(e,t){e.blockedOn===t&&(e.blockedOn=null,Ip||(Ip=!0,ns.unstable_scheduleCallback(ns.unstable_NormalPriority,OP)))}function Ko(e){function t(i){return io(i,e)}if(0<cu.length){io(cu[0],e);for(var s=1;s<cu.length;s++){var r=cu[s];r.blockedOn===e&&(r.blockedOn=null)}}for(li!==null&&io(li,e),oi!==null&&io(oi,e),ci!==null&&io(ci,e),Wo.forEach(t),Ho.forEach(t),s=0;s<ti.length;s++)r=ti[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<ti.length&&(s=ti[0],s.blockedOn===null);)dS(s),s.blockedOn===null&&ti.shift()}var tl=Gr.ReactCurrentBatchConfig,Nd=!0;function LP(e,t,s,r){var i=pt,a=tl.transition;tl.transition=null;try{pt=1,sv(e,t,s,r)}finally{pt=i,tl.transition=a}}function FP(e,t,s,r){var i=pt,a=tl.transition;tl.transition=null;try{pt=4,sv(e,t,s,r)}finally{pt=i,tl.transition=a}}function sv(e,t,s,r){if(Nd){var i=Pp(e,t,s,r);if(i===null)em(e,t,r,Sd,s),My(e,r);else if(DP(i,e,t,s,r))r.stopPropagation();else if(My(e,r),t&4&&-1<MP.indexOf(e)){for(;i!==null;){var a=Tc(i);if(a!==null&&lS(a),a=Pp(e,t,s,r),a===null&&em(e,t,r,Sd,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else em(e,t,r,null,s)}}var Sd=null;function Pp(e,t,s,r){if(Sd=null,e=Zx(r),e=Gi(e),e!==null)if(t=fa(e),t===null)e=null;else if(s=t.tag,s===13){if(e=ZN(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 Sd=e,null}function hS(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(SP()){case ev:return 1;case sS:return 4;case bd:case CP:return 16;case rS:return 536870912;default:return 16}default:return 16}}var si=null,rv=null,qu=null;function fS(){if(qu)return qu;var e,t=rv,s=t.length,r,i="value"in si?si.value:si.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 qu=i.slice(e,1<r?1-r:void 0)}function Ju(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 uu(){return!0}function Oy(){return!1}function as(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)?uu:Oy,this.isPropagationStopped=Oy,this}return Mt(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=uu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=uu)},persist:function(){},isPersistent:uu}),t}var Rl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},iv=as(Rl),Ac=Mt({},Rl,{view:0,detail:0}),_P=as(Ac),Kf,Vf,ao,Nh=Mt({},Ac,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:av,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!==ao&&(ao&&e.type==="mousemove"?(Kf=e.screenX-ao.screenX,Vf=e.screenY-ao.screenY):Vf=Kf=0,ao=e),Kf)},movementY:function(e){return"movementY"in e?e.movementY:Vf}}),Ly=as(Nh),zP=Mt({},Nh,{dataTransfer:0}),UP=as(zP),BP=Mt({},Ac,{relatedTarget:0}),Gf=as(BP),WP=Mt({},Rl,{animationName:0,elapsedTime:0,pseudoElement:0}),HP=as(WP),KP=Mt({},Rl,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),VP=as(KP),GP=Mt({},Rl,{data:0}),Fy=as(GP),YP={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},qP={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"},JP={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function QP(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=JP[e])?!!t[e]:!1}function av(){return QP}var XP=Mt({},Ac,{key:function(e){if(e.key){var t=YP[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Ju(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?qP[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:av,charCode:function(e){return e.type==="keypress"?Ju(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Ju(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),ZP=as(XP),e2=Mt({},Nh,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),_y=as(e2),t2=Mt({},Ac,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:av}),n2=as(t2),s2=Mt({},Rl,{propertyName:0,elapsedTime:0,pseudoElement:0}),r2=as(s2),i2=Mt({},Nh,{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}),a2=as(i2),l2=[9,13,27,32],lv=Fr&&"CompositionEvent"in window,Eo=null;Fr&&"documentMode"in document&&(Eo=document.documentMode);var o2=Fr&&"TextEvent"in window&&!Eo,mS=Fr&&(!lv||Eo&&8<Eo&&11>=Eo),zy=" ",Uy=!1;function pS(e,t){switch(e){case"keyup":return l2.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function gS(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Fa=!1;function c2(e,t){switch(e){case"compositionend":return gS(t);case"keypress":return t.which!==32?null:(Uy=!0,zy);case"textInput":return e=t.data,e===zy&&Uy?null:e;default:return null}}function u2(e,t){if(Fa)return e==="compositionend"||!lv&&pS(e,t)?(e=fS(),qu=rv=si=null,Fa=!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 mS&&t.locale!=="ko"?null:t.data;default:return null}}var d2={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 By(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!d2[e.type]:t==="textarea"}function xS(e,t,s,r){YN(r),t=Cd(t,"onChange"),0<t.length&&(s=new iv("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var Ao=null,Vo=null;function h2(e){AS(e,0)}function Sh(e){var t=Ua(e);if(UN(t))return e}function f2(e,t){if(e==="change")return t}var vS=!1;if(Fr){var Yf;if(Fr){var qf="oninput"in document;if(!qf){var Wy=document.createElement("div");Wy.setAttribute("oninput","return;"),qf=typeof Wy.oninput=="function"}Yf=qf}else Yf=!1;vS=Yf&&(!document.documentMode||9<document.documentMode)}function Hy(){Ao&&(Ao.detachEvent("onpropertychange",jS),Vo=Ao=null)}function jS(e){if(e.propertyName==="value"&&Sh(Vo)){var t=[];xS(t,Vo,e,Zx(e)),XN(h2,t)}}function m2(e,t,s){e==="focusin"?(Hy(),Ao=t,Vo=s,Ao.attachEvent("onpropertychange",jS)):e==="focusout"&&Hy()}function p2(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Sh(Vo)}function g2(e,t){if(e==="click")return Sh(t)}function x2(e,t){if(e==="input"||e==="change")return Sh(t)}function v2(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var _s=typeof Object.is=="function"?Object.is:v2;function Go(e,t){if(_s(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var i=s[r];if(!pp.call(t,i)||!_s(e[i],t[i]))return!1}return!0}function Ky(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Vy(e,t){var s=Ky(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=Ky(s)}}function wS(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?wS(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function yS(){for(var e=window,t=jd();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=jd(e.document)}return t}function ov(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 j2(e){var t=yS(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&wS(s.ownerDocument.documentElement,s)){if(r!==null&&ov(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=Vy(s,a);var l=Vy(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 w2=Fr&&"documentMode"in document&&11>=document.documentMode,_a=null,Mp=null,To=null,Dp=!1;function Gy(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Dp||_a==null||_a!==jd(r)||(r=_a,"selectionStart"in r&&ov(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}),To&&Go(To,r)||(To=r,r=Cd(Mp,"onSelect"),0<r.length&&(t=new iv("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=_a)))}function du(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var za={animationend:du("Animation","AnimationEnd"),animationiteration:du("Animation","AnimationIteration"),animationstart:du("Animation","AnimationStart"),transitionend:du("Transition","TransitionEnd")},Jf={},bS={};Fr&&(bS=document.createElement("div").style,"AnimationEvent"in window||(delete za.animationend.animation,delete za.animationiteration.animation,delete za.animationstart.animation),"TransitionEvent"in window||delete za.transitionend.transition);function Ch(e){if(Jf[e])return Jf[e];if(!za[e])return e;var t=za[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in bS)return Jf[e]=t[s];return e}var kS=Ch("animationend"),NS=Ch("animationiteration"),SS=Ch("animationstart"),CS=Ch("transitionend"),ES=new Map,Yy="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 Ei(e,t){ES.set(e,t),ha(t,[e])}for(var Qf=0;Qf<Yy.length;Qf++){var Xf=Yy[Qf],y2=Xf.toLowerCase(),b2=Xf[0].toUpperCase()+Xf.slice(1);Ei(y2,"on"+b2)}Ei(kS,"onAnimationEnd");Ei(NS,"onAnimationIteration");Ei(SS,"onAnimationStart");Ei("dblclick","onDoubleClick");Ei("focusin","onFocus");Ei("focusout","onBlur");Ei(CS,"onTransitionEnd");ul("onMouseEnter",["mouseout","mouseover"]);ul("onMouseLeave",["mouseout","mouseover"]);ul("onPointerEnter",["pointerout","pointerover"]);ul("onPointerLeave",["pointerout","pointerover"]);ha("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ha("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ha("onBeforeInput",["compositionend","keypress","textInput","paste"]);ha("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ha("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ha("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var yo="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(" "),k2=new Set("cancel close invalid load scroll toggle".split(" ").concat(yo));function qy(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,yP(r,t,void 0,e),e.currentTarget=null}function AS(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;qy(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;qy(i,o,u),a=c}}}if(yd)throw e=$p,yd=!1,$p=null,e}function Nt(e,t){var s=t[zp];s===void 0&&(s=t[zp]=new Set);var r=e+"__bubble";s.has(r)||(TS(t,e,2,!1),s.add(r))}function Zf(e,t,s){var r=0;t&&(r|=4),TS(s,e,r,t)}var hu="_reactListening"+Math.random().toString(36).slice(2);function Yo(e){if(!e[hu]){e[hu]=!0,ON.forEach(function(s){s!=="selectionchange"&&(k2.has(s)||Zf(s,!1,e),Zf(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[hu]||(t[hu]=!0,Zf("selectionchange",!1,t))}}function TS(e,t,s,r){switch(hS(t)){case 1:var i=LP;break;case 4:i=FP;break;default:i=sv}s=i.bind(null,t,s,e),i=void 0,!Tp||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 em(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=Gi(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}XN(function(){var u=a,h=Zx(s),f=[];e:{var m=ES.get(e);if(m!==void 0){var p=iv,g=e;switch(e){case"keypress":if(Ju(s)===0)break e;case"keydown":case"keyup":p=ZP;break;case"focusin":g="focus",p=Gf;break;case"focusout":g="blur",p=Gf;break;case"beforeblur":case"afterblur":p=Gf;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=Ly;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=UP;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=n2;break;case kS:case NS:case SS:p=HP;break;case CS:p=r2;break;case"scroll":p=_P;break;case"wheel":p=a2;break;case"copy":case"cut":case"paste":p=VP;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=_y}var v=(t&4)!==0,b=!v&&e==="scroll",j=v?m!==null?m+"Capture":null:m;v=[];for(var x=u,w;x!==null;){w=x;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,j!==null&&(y=Bo(x,j),y!=null&&v.push(qo(x,y,w)))),b)break;x=x.return}0<v.length&&(m=new p(m,g,null,s,h),f.push({event:m,listeners:v}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Ep&&(g=s.relatedTarget||s.fromElement)&&(Gi(g)||g[_r]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Gi(g):null,g!==null&&(b=fa(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(v=Ly,y="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(v=_y,y="onPointerLeave",j="onPointerEnter",x="pointer"),b=p==null?m:Ua(p),w=g==null?m:Ua(g),m=new v(y,x+"leave",p,s,h),m.target=b,m.relatedTarget=w,y=null,Gi(h)===u&&(v=new v(j,x+"enter",g,s,h),v.target=w,v.relatedTarget=b,y=v),b=y,p&&g)t:{for(v=p,j=g,x=0,w=v;w;w=Ca(w))x++;for(w=0,y=j;y;y=Ca(y))w++;for(;0<x-w;)v=Ca(v),x--;for(;0<w-x;)j=Ca(j),w--;for(;x--;){if(v===j||j!==null&&v===j.alternate)break t;v=Ca(v),j=Ca(j)}v=null}else v=null;p!==null&&Jy(f,m,p,v,!1),g!==null&&b!==null&&Jy(f,b,g,v,!0)}}e:{if(m=u?Ua(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=f2;else if(By(m))if(vS)k=x2;else{k=p2;var N=m2}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=g2);if(k&&(k=k(e,u))){xS(f,k,s,h);break e}N&&N(e,m,u),e==="focusout"&&(N=m._wrapperState)&&N.controlled&&m.type==="number"&&bp(m,"number",m.value)}switch(N=u?Ua(u):window,e){case"focusin":(By(N)||N.contentEditable==="true")&&(_a=N,Mp=u,To=null);break;case"focusout":To=Mp=_a=null;break;case"mousedown":Dp=!0;break;case"contextmenu":case"mouseup":case"dragend":Dp=!1,Gy(f,s,h);break;case"selectionchange":if(w2)break;case"keydown":case"keyup":Gy(f,s,h)}var S;if(lv)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 Fa?pS(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(mS&&s.locale!=="ko"&&(Fa||C!=="onCompositionStart"?C==="onCompositionEnd"&&Fa&&(S=fS()):(si=h,rv="value"in si?si.value:si.textContent,Fa=!0)),N=Cd(u,C),0<N.length&&(C=new Fy(C,e,null,s,h),f.push({event:C,listeners:N}),S?C.data=S:(S=gS(s),S!==null&&(C.data=S)))),(S=o2?c2(e,s):u2(e,s))&&(u=Cd(u,"onBeforeInput"),0<u.length&&(h=new Fy("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}AS(f,t)})}function qo(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=Bo(e,s),a!=null&&r.unshift(qo(e,a,i)),a=Bo(e,t),a!=null&&r.push(qo(e,a,i))),e=e.return}return r}function Ca(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Jy(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=Bo(s,a),c!=null&&l.unshift(qo(s,c,o))):i||(c=Bo(s,a),c!=null&&l.push(qo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var N2=/\r\n?/g,S2=/\u0000|\uFFFD/g;function Qy(e){return(typeof e=="string"?e:""+e).replace(N2,`
|
|
38
|
+
`).replace(S2,"")}function fu(e,t,s){if(t=Qy(t),Qy(e)!==t&&s)throw Error(xe(425))}function Ed(){}var Op=null,Lp=null;function Fp(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 _p=typeof setTimeout=="function"?setTimeout:void 0,C2=typeof clearTimeout=="function"?clearTimeout:void 0,Xy=typeof Promise=="function"?Promise:void 0,E2=typeof queueMicrotask=="function"?queueMicrotask:typeof Xy<"u"?function(e){return Xy.resolve(null).then(e).catch(A2)}:_p;function A2(e){setTimeout(function(){throw e})}function tm(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),Ko(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);Ko(t)}function ui(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 Zy(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 Il=Math.random().toString(36).slice(2),nr="__reactFiber$"+Il,Jo="__reactProps$"+Il,_r="__reactContainer$"+Il,zp="__reactEvents$"+Il,T2="__reactListeners$"+Il,$2="__reactHandles$"+Il;function Gi(e){var t=e[nr];if(t)return t;for(var s=e.parentNode;s;){if(t=s[_r]||s[nr]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=Zy(e);e!==null;){if(s=e[nr])return s;e=Zy(e)}return t}e=s,s=e.parentNode}return null}function Tc(e){return e=e[nr]||e[_r],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ua(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(xe(33))}function Eh(e){return e[Jo]||null}var Up=[],Ba=-1;function Ai(e){return{current:e}}function Ct(e){0>Ba||(e.current=Up[Ba],Up[Ba]=null,Ba--)}function bt(e,t){Ba++,Up[Ba]=e.current,e.current=t}var ji={},yn=Ai(ji),zn=Ai(!1),na=ji;function dl(e,t){var s=e.type.contextTypes;if(!s)return ji;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 Un(e){return e=e.childContextTypes,e!=null}function Ad(){Ct(zn),Ct(yn)}function eb(e,t,s){if(yn.current!==ji)throw Error(xe(168));bt(yn,t),bt(zn,s)}function $S(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(xe(108,mP(e)||"Unknown",i));return Mt({},s,r)}function Td(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||ji,na=yn.current,bt(yn,e),bt(zn,zn.current),!0}function tb(e,t,s){var r=e.stateNode;if(!r)throw Error(xe(169));s?(e=$S(e,t,na),r.__reactInternalMemoizedMergedChildContext=e,Ct(zn),Ct(yn),bt(yn,e)):Ct(zn),bt(zn,s)}var Sr=null,Ah=!1,nm=!1;function RS(e){Sr===null?Sr=[e]:Sr.push(e)}function R2(e){Ah=!0,RS(e)}function Ti(){if(!nm&&Sr!==null){nm=!0;var e=0,t=pt;try{var s=Sr;for(pt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}Sr=null,Ah=!1}catch(i){throw Sr!==null&&(Sr=Sr.slice(e+1)),nS(ev,Ti),i}finally{pt=t,nm=!1}}return null}var Wa=[],Ha=0,$d=null,Rd=0,ps=[],gs=0,sa=null,Tr=1,$r="";function Bi(e,t){Wa[Ha++]=Rd,Wa[Ha++]=$d,$d=e,Rd=t}function IS(e,t,s){ps[gs++]=Tr,ps[gs++]=$r,ps[gs++]=sa,sa=e;var r=Tr;e=$r;var i=32-Ds(r)-1;r&=~(1<<i),s+=1;var a=32-Ds(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,Tr=1<<32-Ds(t)+i|s<<i|r,$r=a+e}else Tr=1<<a|s<<i|r,$r=e}function cv(e){e.return!==null&&(Bi(e,1),IS(e,1,0))}function uv(e){for(;e===$d;)$d=Wa[--Ha],Wa[Ha]=null,Rd=Wa[--Ha],Wa[Ha]=null;for(;e===sa;)sa=ps[--gs],ps[gs]=null,$r=ps[--gs],ps[gs]=null,Tr=ps[--gs],ps[gs]=null}var es=null,Xn=null,Tt=!1,Ps=null;function PS(e,t){var s=ws(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 nb(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,es=e,Xn=ui(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,es=e,Xn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=sa!==null?{id:Tr,overflow:$r}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=ws(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,es=e,Xn=null,!0):!1;default:return!1}}function Bp(e){return(e.mode&1)!==0&&(e.flags&128)===0}function Wp(e){if(Tt){var t=Xn;if(t){var s=t;if(!nb(e,t)){if(Bp(e))throw Error(xe(418));t=ui(s.nextSibling);var r=es;t&&nb(e,t)?PS(r,s):(e.flags=e.flags&-4097|2,Tt=!1,es=e)}}else{if(Bp(e))throw Error(xe(418));e.flags=e.flags&-4097|2,Tt=!1,es=e}}}function sb(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;es=e}function mu(e){if(e!==es)return!1;if(!Tt)return sb(e),Tt=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!Fp(e.type,e.memoizedProps)),t&&(t=Xn)){if(Bp(e))throw MS(),Error(xe(418));for(;t;)PS(e,t),t=ui(t.nextSibling)}if(sb(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(xe(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Xn=ui(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Xn=null}}else Xn=es?ui(e.stateNode.nextSibling):null;return!0}function MS(){for(var e=Xn;e;)e=ui(e.nextSibling)}function hl(){Xn=es=null,Tt=!1}function dv(e){Ps===null?Ps=[e]:Ps.push(e)}var I2=Gr.ReactCurrentBatchConfig;function lo(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(xe(309));var r=s.stateNode}if(!r)throw Error(xe(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(xe(284));if(!s._owner)throw Error(xe(290,e))}return e}function pu(e,t){throw e=Object.prototype.toString.call(t),Error(xe(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function rb(e){var t=e._init;return t(e._payload)}function DS(e){function t(j,x){if(e){var w=j.deletions;w===null?(j.deletions=[x],j.flags|=16):w.push(x)}}function s(j,x){if(!e)return null;for(;x!==null;)t(j,x),x=x.sibling;return null}function r(j,x){for(j=new Map;x!==null;)x.key!==null?j.set(x.key,x):j.set(x.index,x),x=x.sibling;return j}function i(j,x){return j=mi(j,x),j.index=0,j.sibling=null,j}function a(j,x,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<x?(j.flags|=2,x):w):(j.flags|=2,x)):(j.flags|=1048576,x)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,x,w,y){return x===null||x.tag!==6?(x=cm(w,j.mode,y),x.return=j,x):(x=i(x,w),x.return=j,x)}function c(j,x,w,y){var k=w.type;return k===La?h(j,x,w.props.children,y,w.key):x!==null&&(x.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Zr&&rb(k)===x.type)?(y=i(x,w.props),y.ref=lo(j,x,w),y.return=j,y):(y=sd(w.type,w.key,w.props,null,j.mode,y),y.ref=lo(j,x,w),y.return=j,y)}function u(j,x,w,y){return x===null||x.tag!==4||x.stateNode.containerInfo!==w.containerInfo||x.stateNode.implementation!==w.implementation?(x=um(w,j.mode,y),x.return=j,x):(x=i(x,w.children||[]),x.return=j,x)}function h(j,x,w,y,k){return x===null||x.tag!==7?(x=Zi(w,j.mode,y,k),x.return=j,x):(x=i(x,w),x.return=j,x)}function f(j,x,w){if(typeof x=="string"&&x!==""||typeof x=="number")return x=cm(""+x,j.mode,w),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case ru:return w=sd(x.type,x.key,x.props,null,j.mode,w),w.ref=lo(j,null,x),w.return=j,w;case Oa:return x=um(x,j.mode,w),x.return=j,x;case Zr:var y=x._init;return f(j,y(x._payload),w)}if(jo(x)||no(x))return x=Zi(x,j.mode,w,null),x.return=j,x;pu(j,x)}return null}function m(j,x,w,y){var k=x!==null?x.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return k!==null?null:o(j,x,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case ru:return w.key===k?c(j,x,w,y):null;case Oa:return w.key===k?u(j,x,w,y):null;case Zr:return k=w._init,m(j,x,k(w._payload),y)}if(jo(w)||no(w))return k!==null?null:h(j,x,w,y,null);pu(j,w)}return null}function p(j,x,w,y,k){if(typeof y=="string"&&y!==""||typeof y=="number")return j=j.get(w)||null,o(x,j,""+y,k);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case ru:return j=j.get(y.key===null?w:y.key)||null,c(x,j,y,k);case Oa:return j=j.get(y.key===null?w:y.key)||null,u(x,j,y,k);case Zr:var N=y._init;return p(j,x,w,N(y._payload),k)}if(jo(y)||no(y))return j=j.get(w)||null,h(x,j,y,k,null);pu(x,y)}return null}function g(j,x,w,y){for(var k=null,N=null,S=x,C=x=0,T=null;S!==null&&C<w.length;C++){S.index>C?(T=S,S=null):T=S.sibling;var R=m(j,S,w[C],y);if(R===null){S===null&&(S=T);break}e&&S&&R.alternate===null&&t(j,S),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R,S=T}if(C===w.length)return s(j,S),Tt&&Bi(j,C),k;if(S===null){for(;C<w.length;C++)S=f(j,w[C],y),S!==null&&(x=a(S,x,C),N===null?k=S:N.sibling=S,N=S);return Tt&&Bi(j,C),k}for(S=r(j,S);C<w.length;C++)T=p(S,j,C,w[C],y),T!==null&&(e&&T.alternate!==null&&S.delete(T.key===null?C:T.key),x=a(T,x,C),N===null?k=T:N.sibling=T,N=T);return e&&S.forEach(function(I){return t(j,I)}),Tt&&Bi(j,C),k}function v(j,x,w,y){var k=no(w);if(typeof k!="function")throw Error(xe(150));if(w=k.call(w),w==null)throw Error(xe(151));for(var N=k=null,S=x,C=x=0,T=null,R=w.next();S!==null&&!R.done;C++,R=w.next()){S.index>C?(T=S,S=null):T=S.sibling;var I=m(j,S,R.value,y);if(I===null){S===null&&(S=T);break}e&&S&&I.alternate===null&&t(j,S),x=a(I,x,C),N===null?k=I:N.sibling=I,N=I,S=T}if(R.done)return s(j,S),Tt&&Bi(j,C),k;if(S===null){for(;!R.done;C++,R=w.next())R=f(j,R.value,y),R!==null&&(x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return Tt&&Bi(j,C),k}for(S=r(j,S);!R.done;C++,R=w.next())R=p(S,j,C,R.value,y),R!==null&&(e&&R.alternate!==null&&S.delete(R.key===null?C:R.key),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return e&&S.forEach(function(L){return t(j,L)}),Tt&&Bi(j,C),k}function b(j,x,w,y){if(typeof w=="object"&&w!==null&&w.type===La&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case ru:e:{for(var k=w.key,N=x;N!==null;){if(N.key===k){if(k=w.type,k===La){if(N.tag===7){s(j,N.sibling),x=i(N,w.props.children),x.return=j,j=x;break e}}else if(N.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Zr&&rb(k)===N.type){s(j,N.sibling),x=i(N,w.props),x.ref=lo(j,N,w),x.return=j,j=x;break e}s(j,N);break}else t(j,N);N=N.sibling}w.type===La?(x=Zi(w.props.children,j.mode,y,w.key),x.return=j,j=x):(y=sd(w.type,w.key,w.props,null,j.mode,y),y.ref=lo(j,x,w),y.return=j,j=y)}return l(j);case Oa:e:{for(N=w.key;x!==null;){if(x.key===N)if(x.tag===4&&x.stateNode.containerInfo===w.containerInfo&&x.stateNode.implementation===w.implementation){s(j,x.sibling),x=i(x,w.children||[]),x.return=j,j=x;break e}else{s(j,x);break}else t(j,x);x=x.sibling}x=um(w,j.mode,y),x.return=j,j=x}return l(j);case Zr:return N=w._init,b(j,x,N(w._payload),y)}if(jo(w))return g(j,x,w,y);if(no(w))return v(j,x,w,y);pu(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,x!==null&&x.tag===6?(s(j,x.sibling),x=i(x,w),x.return=j,j=x):(s(j,x),x=cm(w,j.mode,y),x.return=j,j=x),l(j)):s(j,x)}return b}var fl=DS(!0),OS=DS(!1),Id=Ai(null),Pd=null,Ka=null,hv=null;function fv(){hv=Ka=Pd=null}function mv(e){var t=Id.current;Ct(Id),e._currentValue=t}function Hp(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 nl(e,t){Pd=e,hv=Ka=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Fn=!0),e.firstContext=null)}function Ns(e){var t=e._currentValue;if(hv!==e)if(e={context:e,memoizedValue:t,next:null},Ka===null){if(Pd===null)throw Error(xe(308));Ka=e,Pd.dependencies={lanes:0,firstContext:e}}else Ka=Ka.next=e;return t}var Yi=null;function pv(e){Yi===null?Yi=[e]:Yi.push(e)}function LS(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,pv(t)):(s.next=i.next,i.next=s),t.interleaved=s,zr(e,r)}function zr(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 ei=!1;function gv(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function FS(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 Ir(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function di(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,lt&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,zr(e,s)}return i=r.interleaved,i===null?(t.next=t,pv(r)):(t.next=i.next,i.next=t),r.interleaved=t,zr(e,s)}function Qu(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,tv(e,s)}}function ib(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 Md(e,t,s,r){var i=e.updateQueue;ei=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(a!==null){var f=i.baseState;l=0,h=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,v=o;switch(m=t,p=s,v.tag){case 1:if(g=v.payload,typeof g=="function"){f=g.call(p,f,m);break e}f=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=v.payload,m=typeof g=="function"?g.call(p,f,m):g,m==null)break e;f=Mt({},f,m);break e;case 2:ei=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=f):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(h===null&&(c=f),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=h,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);ia|=l,e.lanes=l,e.memoizedState=f}}function ab(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(xe(191,i));i.call(r)}}}var $c={},lr=Ai($c),Qo=Ai($c),Xo=Ai($c);function qi(e){if(e===$c)throw Error(xe(174));return e}function xv(e,t){switch(bt(Xo,t),bt(Qo,e),bt(lr,$c),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Np(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Np(t,e)}Ct(lr),bt(lr,t)}function ml(){Ct(lr),Ct(Qo),Ct(Xo)}function _S(e){qi(Xo.current);var t=qi(lr.current),s=Np(t,e.type);t!==s&&(bt(Qo,e),bt(lr,s))}function vv(e){Qo.current===e&&(Ct(lr),Ct(Qo))}var Rt=Ai(0);function Dd(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 sm=[];function jv(){for(var e=0;e<sm.length;e++)sm[e]._workInProgressVersionPrimary=null;sm.length=0}var Xu=Gr.ReactCurrentDispatcher,rm=Gr.ReactCurrentBatchConfig,ra=0,It=null,Yt=null,tn=null,Od=!1,$o=!1,Zo=0,P2=0;function xn(){throw Error(xe(321))}function wv(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!_s(e[s],t[s]))return!1;return!0}function yv(e,t,s,r,i,a){if(ra=a,It=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,Xu.current=e===null||e.memoizedState===null?L2:F2,e=s(r,i),$o){a=0;do{if($o=!1,Zo=0,25<=a)throw Error(xe(301));a+=1,tn=Yt=null,t.updateQueue=null,Xu.current=_2,e=s(r,i)}while($o)}if(Xu.current=Ld,t=Yt!==null&&Yt.next!==null,ra=0,tn=Yt=It=null,Od=!1,t)throw Error(xe(300));return e}function bv(){var e=Zo!==0;return Zo=0,e}function Zs(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return tn===null?It.memoizedState=tn=e:tn=tn.next=e,tn}function Ss(){if(Yt===null){var e=It.alternate;e=e!==null?e.memoizedState:null}else e=Yt.next;var t=tn===null?It.memoizedState:tn.next;if(t!==null)tn=t,Yt=e;else{if(e===null)throw Error(xe(310));Yt=e,e={memoizedState:Yt.memoizedState,baseState:Yt.baseState,baseQueue:Yt.baseQueue,queue:Yt.queue,next:null},tn===null?It.memoizedState=tn=e:tn=tn.next=e}return tn}function ec(e,t){return typeof t=="function"?t(e):t}function im(e){var t=Ss(),s=t.queue;if(s===null)throw Error(xe(311));s.lastRenderedReducer=e;var r=Yt,i=r.baseQueue,a=s.pending;if(a!==null){if(i!==null){var l=i.next;i.next=a.next,a.next=l}r.baseQueue=i=a,s.pending=null}if(i!==null){a=i.next,r=r.baseState;var o=l=null,c=null,u=a;do{var h=u.lane;if((ra&h)===h)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var f={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,It.lanes|=h,ia|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,_s(r,t.memoizedState)||(Fn=!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,It.lanes|=a,ia|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function am(e){var t=Ss(),s=t.queue;if(s===null)throw Error(xe(311));s.lastRenderedReducer=e;var r=s.dispatch,i=s.pending,a=t.memoizedState;if(i!==null){s.pending=null;var l=i=i.next;do a=e(a,l.action),l=l.next;while(l!==i);_s(a,t.memoizedState)||(Fn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function zS(){}function US(e,t){var s=It,r=Ss(),i=t(),a=!_s(r.memoizedState,i);if(a&&(r.memoizedState=i,Fn=!0),r=r.queue,kv(HS.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||tn!==null&&tn.memoizedState.tag&1){if(s.flags|=2048,tc(9,WS.bind(null,s,r,i,t),void 0,null),on===null)throw Error(xe(349));ra&30||BS(s,t,i)}return i}function BS(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=It.updateQueue,t===null?(t={lastEffect:null,stores:null},It.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function WS(e,t,s,r){t.value=s,t.getSnapshot=r,KS(t)&&VS(e)}function HS(e,t,s){return s(function(){KS(t)&&VS(e)})}function KS(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!_s(e,s)}catch{return!0}}function VS(e){var t=zr(e,1);t!==null&&Os(t,e,1,-1)}function lb(e){var t=Zs();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:ec,lastRenderedState:e},t.queue=e,e=e.dispatch=O2.bind(null,It,e),[t.memoizedState,e]}function tc(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=It.updateQueue,t===null?(t={lastEffect:null,stores:null},It.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 GS(){return Ss().memoizedState}function Zu(e,t,s,r){var i=Zs();It.flags|=e,i.memoizedState=tc(1|t,s,void 0,r===void 0?null:r)}function Th(e,t,s,r){var i=Ss();r=r===void 0?null:r;var a=void 0;if(Yt!==null){var l=Yt.memoizedState;if(a=l.destroy,r!==null&&wv(r,l.deps)){i.memoizedState=tc(t,s,a,r);return}}It.flags|=e,i.memoizedState=tc(1|t,s,a,r)}function ob(e,t){return Zu(8390656,8,e,t)}function kv(e,t){return Th(2048,8,e,t)}function YS(e,t){return Th(4,2,e,t)}function qS(e,t){return Th(4,4,e,t)}function JS(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 QS(e,t,s){return s=s!=null?s.concat([e]):null,Th(4,4,JS.bind(null,t,e),s)}function Nv(){}function XS(e,t){var s=Ss();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&wv(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function ZS(e,t){var s=Ss();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&wv(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function eC(e,t,s){return ra&21?(_s(s,t)||(s=iS(),It.lanes|=s,ia|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Fn=!0),e.memoizedState=s)}function M2(e,t){var s=pt;pt=s!==0&&4>s?s:4,e(!0);var r=rm.transition;rm.transition={};try{e(!1),t()}finally{pt=s,rm.transition=r}}function tC(){return Ss().memoizedState}function D2(e,t,s){var r=fi(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},nC(e))sC(t,s);else if(s=LS(e,t,s,r),s!==null){var i=En();Os(s,e,r,i),rC(s,t,r)}}function O2(e,t,s){var r=fi(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(nC(e))sC(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var l=t.lastRenderedState,o=a(l,s);if(i.hasEagerState=!0,i.eagerState=o,_s(o,l)){var c=t.interleaved;c===null?(i.next=i,pv(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=LS(e,t,i,r),s!==null&&(i=En(),Os(s,e,r,i),rC(s,t,r))}}function nC(e){var t=e.alternate;return e===It||t!==null&&t===It}function sC(e,t){$o=Od=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function rC(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,tv(e,s)}}var Ld={readContext:Ns,useCallback:xn,useContext:xn,useEffect:xn,useImperativeHandle:xn,useInsertionEffect:xn,useLayoutEffect:xn,useMemo:xn,useReducer:xn,useRef:xn,useState:xn,useDebugValue:xn,useDeferredValue:xn,useTransition:xn,useMutableSource:xn,useSyncExternalStore:xn,useId:xn,unstable_isNewReconciler:!1},L2={readContext:Ns,useCallback:function(e,t){return Zs().memoizedState=[e,t===void 0?null:t],e},useContext:Ns,useEffect:ob,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,Zu(4194308,4,JS.bind(null,t,e),s)},useLayoutEffect:function(e,t){return Zu(4194308,4,e,t)},useInsertionEffect:function(e,t){return Zu(4,2,e,t)},useMemo:function(e,t){var s=Zs();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Zs();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=D2.bind(null,It,e),[r.memoizedState,e]},useRef:function(e){var t=Zs();return e={current:e},t.memoizedState=e},useState:lb,useDebugValue:Nv,useDeferredValue:function(e){return Zs().memoizedState=e},useTransition:function(){var e=lb(!1),t=e[0];return e=M2.bind(null,e[1]),Zs().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=It,i=Zs();if(Tt){if(s===void 0)throw Error(xe(407));s=s()}else{if(s=t(),on===null)throw Error(xe(349));ra&30||BS(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,ob(HS.bind(null,r,a,e),[e]),r.flags|=2048,tc(9,WS.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Zs(),t=on.identifierPrefix;if(Tt){var s=$r,r=Tr;s=(r&~(1<<32-Ds(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=Zo++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=P2++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},F2={readContext:Ns,useCallback:XS,useContext:Ns,useEffect:kv,useImperativeHandle:QS,useInsertionEffect:YS,useLayoutEffect:qS,useMemo:ZS,useReducer:im,useRef:GS,useState:function(){return im(ec)},useDebugValue:Nv,useDeferredValue:function(e){var t=Ss();return eC(t,Yt.memoizedState,e)},useTransition:function(){var e=im(ec)[0],t=Ss().memoizedState;return[e,t]},useMutableSource:zS,useSyncExternalStore:US,useId:tC,unstable_isNewReconciler:!1},_2={readContext:Ns,useCallback:XS,useContext:Ns,useEffect:kv,useImperativeHandle:QS,useInsertionEffect:YS,useLayoutEffect:qS,useMemo:ZS,useReducer:am,useRef:GS,useState:function(){return am(ec)},useDebugValue:Nv,useDeferredValue:function(e){var t=Ss();return Yt===null?t.memoizedState=e:eC(t,Yt.memoizedState,e)},useTransition:function(){var e=am(ec)[0],t=Ss().memoizedState;return[e,t]},useMutableSource:zS,useSyncExternalStore:US,useId:tC,unstable_isNewReconciler:!1};function Rs(e,t){if(e&&e.defaultProps){t=Mt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function Kp(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:Mt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var $h={isMounted:function(e){return(e=e._reactInternals)?fa(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=En(),i=fi(e),a=Ir(r,i);a.payload=t,s!=null&&(a.callback=s),t=di(e,a,i),t!==null&&(Os(t,e,i,r),Qu(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=En(),i=fi(e),a=Ir(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=di(e,a,i),t!==null&&(Os(t,e,i,r),Qu(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=En(),r=fi(e),i=Ir(s,r);i.tag=2,t!=null&&(i.callback=t),t=di(e,i,r),t!==null&&(Os(t,e,r,s),Qu(t,e,r))}};function cb(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?!Go(s,r)||!Go(i,a):!0}function iC(e,t,s){var r=!1,i=ji,a=t.contextType;return typeof a=="object"&&a!==null?a=Ns(a):(i=Un(t)?na:yn.current,r=t.contextTypes,a=(r=r!=null)?dl(e,i):ji),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=$h,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function ub(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&&$h.enqueueReplaceState(t,t.state,null)}function Vp(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},gv(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=Ns(a):(a=Un(t)?na:yn.current,i.context=dl(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(Kp(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&&$h.enqueueReplaceState(i,i.state,null),Md(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function pl(e,t){try{var s="",r=t;do s+=fP(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 lm(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function Gp(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var z2=typeof WeakMap=="function"?WeakMap:Map;function aC(e,t,s){s=Ir(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){_d||(_d=!0,sg=r),Gp(e,t)},s}function lC(e,t,s){s=Ir(-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(){Gp(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){Gp(e,t),typeof r!="function"&&(hi===null?hi=new Set([this]):hi.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function db(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new z2;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=eM.bind(null,e,t,s),t.then(e,e))}function hb(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 fb(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=Ir(-1,1),t.tag=2,di(s,t,1))),s.lanes|=1),e)}var U2=Gr.ReactCurrentOwner,Fn=!1;function Sn(e,t,s,r){t.child=e===null?OS(t,null,s,r):fl(t,e.child,s,r)}function mb(e,t,s,r,i){s=s.render;var a=t.ref;return nl(t,i),r=yv(e,t,s,r,a,i),s=bv(),e!==null&&!Fn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Ur(e,t,i)):(Tt&&s&&cv(t),t.flags|=1,Sn(e,t,r,i),t.child)}function pb(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Iv(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,oC(e,t,a,r,i)):(e=sd(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:Go,s(l,r)&&e.ref===t.ref)return Ur(e,t,i)}return t.flags|=1,e=mi(a,r),e.ref=t.ref,e.return=t,t.child=e}function oC(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(Go(a,r)&&e.ref===t.ref)if(Fn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Fn=!0);else return t.lanes=e.lanes,Ur(e,t,i)}return Yp(e,t,s,r,i)}function cC(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},bt(Ga,Jn),Jn|=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,bt(Ga,Jn),Jn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,bt(Ga,Jn),Jn|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,bt(Ga,Jn),Jn|=r;return Sn(e,t,i,s),t.child}function uC(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function Yp(e,t,s,r,i){var a=Un(s)?na:yn.current;return a=dl(t,a),nl(t,i),s=yv(e,t,s,r,a,i),r=bv(),e!==null&&!Fn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Ur(e,t,i)):(Tt&&r&&cv(t),t.flags|=1,Sn(e,t,s,i),t.child)}function gb(e,t,s,r,i){if(Un(s)){var a=!0;Td(t)}else a=!1;if(nl(t,i),t.stateNode===null)ed(e,t),iC(t,s,r),Vp(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=Ns(u):(u=Un(s)?na:yn.current,u=dl(t,u));var h=s.getDerivedStateFromProps,f=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&ub(t,l,r,u),ei=!1;var m=t.memoizedState;l.state=m,Md(t,r,l,i),c=t.memoizedState,o!==r||m!==c||zn.current||ei?(typeof h=="function"&&(Kp(t,s,h,r),c=t.memoizedState),(o=ei||cb(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,FS(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:Rs(t.type,o),l.props=u,f=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=Ns(c):(c=Un(s)?na:yn.current,c=dl(t,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&ub(t,l,r,c),ei=!1,m=t.memoizedState,l.state=m,Md(t,r,l,i);var g=t.memoizedState;o!==f||m!==g||zn.current||ei?(typeof p=="function"&&(Kp(t,s,p,r),g=t.memoizedState),(u=ei||cb(t,s,u,r,m,g,c)||!1)?(h||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,g,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,g,c)),typeof l.componentDidUpdate=="function"&&(t.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),r=!1)}return qp(e,t,s,r,a,i)}function qp(e,t,s,r,i,a){uC(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&tb(t,s,!1),Ur(e,t,a);r=t.stateNode,U2.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=fl(t,e.child,null,a),t.child=fl(t,null,o,a)):Sn(e,t,o,a),t.memoizedState=r.state,i&&tb(t,s,!0),t.child}function dC(e){var t=e.stateNode;t.pendingContext?eb(e,t.pendingContext,t.pendingContext!==t.context):t.context&&eb(e,t.context,!1),xv(e,t.containerInfo)}function xb(e,t,s,r,i){return hl(),dv(i),t.flags|=256,Sn(e,t,s,r),t.child}var Jp={dehydrated:null,treeContext:null,retryLane:0};function Qp(e){return{baseLanes:e,cachePool:null,transitions:null}}function hC(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),bt(Rt,i&1),e===null)return Wp(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=Ph(l,r,0,null),e=Zi(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=Qp(s),t.memoizedState=Jp,e):Sv(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return B2(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=mi(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=mi(o,a):(a=Zi(a,l,s,null),a.flags|=2),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,l=e.child.memoizedState,l=l===null?Qp(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=Jp,r}return a=e.child,e=a.sibling,r=mi(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 Sv(e,t){return t=Ph({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function gu(e,t,s,r){return r!==null&&dv(r),fl(t,e.child,null,s),e=Sv(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function B2(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=lm(Error(xe(422))),gu(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Ph({mode:"visible",children:r.children},i,0,null),a=Zi(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&fl(t,e.child,null,l),t.child.memoizedState=Qp(l),t.memoizedState=Jp,a);if(!(t.mode&1))return gu(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(xe(419)),r=lm(a,r,void 0),gu(e,t,l,r)}if(o=(l&e.childLanes)!==0,Fn||o){if(r=on,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,zr(e,i),Os(r,e,i,-1))}return Rv(),r=lm(Error(xe(421))),gu(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=tM.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Xn=ui(i.nextSibling),es=t,Tt=!0,Ps=null,e!==null&&(ps[gs++]=Tr,ps[gs++]=$r,ps[gs++]=sa,Tr=e.id,$r=e.overflow,sa=t),t=Sv(t,r.children),t.flags|=4096,t)}function vb(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Hp(e.return,t,s)}function om(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 fC(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Sn(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&&vb(e,s,t);else if(e.tag===19)vb(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(bt(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&&Dd(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),om(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&&Dd(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}om(t,!0,s,null,a);break;case"together":om(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function ed(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Ur(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),ia|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(xe(153));if(t.child!==null){for(e=t.child,s=mi(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=mi(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function W2(e,t,s){switch(t.tag){case 3:dC(t),hl();break;case 5:_S(t);break;case 1:Un(t.type)&&Td(t);break;case 4:xv(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;bt(Id,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(bt(Rt,Rt.current&1),t.flags|=128,null):s&t.child.childLanes?hC(e,t,s):(bt(Rt,Rt.current&1),e=Ur(e,t,s),e!==null?e.sibling:null);bt(Rt,Rt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return fC(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),bt(Rt,Rt.current),r)break;return null;case 22:case 23:return t.lanes=0,cC(e,t,s)}return Ur(e,t,s)}var mC,Xp,pC,gC;mC=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}};Xp=function(){};pC=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,qi(lr.current);var a=null;switch(s){case"input":i=wp(e,i),r=wp(e,r),a=[];break;case"select":i=Mt({},i,{value:void 0}),r=Mt({},r,{value:void 0}),a=[];break;case"textarea":i=kp(e,i),r=kp(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Ed)}Sp(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"&&(zo.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"&&(zo.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&Nt("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)}};gC=function(e,t,s,r){s!==r&&(t.flags|=4)};function oo(e,t){if(!Tt)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 vn(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 H2(e,t,s){var r=t.pendingProps;switch(uv(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return vn(t),null;case 1:return Un(t.type)&&Ad(),vn(t),null;case 3:return r=t.stateNode,ml(),Ct(zn),Ct(yn),jv(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(mu(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ps!==null&&(ag(Ps),Ps=null))),Xp(e,t),vn(t),null;case 5:vv(t);var i=qi(Xo.current);if(s=t.type,e!==null&&t.stateNode!=null)pC(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(xe(166));return vn(t),null}if(e=qi(lr.current),mu(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[nr]=t,r[Jo]=a,e=(t.mode&1)!==0,s){case"dialog":Nt("cancel",r),Nt("close",r);break;case"iframe":case"object":case"embed":Nt("load",r);break;case"video":case"audio":for(i=0;i<yo.length;i++)Nt(yo[i],r);break;case"source":Nt("error",r);break;case"img":case"image":case"link":Nt("error",r),Nt("load",r);break;case"details":Nt("toggle",r);break;case"input":Ey(r,a),Nt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},Nt("invalid",r);break;case"textarea":Ty(r,a),Nt("invalid",r)}Sp(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&&fu(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&fu(r.textContent,o,e),i=["children",""+o]):zo.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Nt("scroll",r)}switch(s){case"input":iu(r),Ay(r,a,!0);break;case"textarea":iu(r),$y(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Ed)}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=HN(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[nr]=t,e[Jo]=r,mC(e,t,!1,!1),t.stateNode=e;e:{switch(l=Cp(s,r),s){case"dialog":Nt("cancel",e),Nt("close",e),i=r;break;case"iframe":case"object":case"embed":Nt("load",e),i=r;break;case"video":case"audio":for(i=0;i<yo.length;i++)Nt(yo[i],e);i=r;break;case"source":Nt("error",e),i=r;break;case"img":case"image":case"link":Nt("error",e),Nt("load",e),i=r;break;case"details":Nt("toggle",e),i=r;break;case"input":Ey(e,r),i=wp(e,r),Nt("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=Mt({},r,{value:void 0}),Nt("invalid",e);break;case"textarea":Ty(e,r),i=kp(e,r),Nt("invalid",e);break;default:i=r}Sp(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?GN(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&KN(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Uo(e,c):typeof c=="number"&&Uo(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(zo.hasOwnProperty(a)?c!=null&&a==="onScroll"&&Nt("scroll",e):c!=null&&qx(e,a,c,l))}switch(s){case"input":iu(e),Ay(e,r,!1);break;case"textarea":iu(e),$y(e);break;case"option":r.value!=null&&e.setAttribute("value",""+vi(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?Xa(e,!!r.multiple,a,!1):r.defaultValue!=null&&Xa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Ed)}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 vn(t),null;case 6:if(e&&t.stateNode!=null)gC(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(xe(166));if(s=qi(Xo.current),qi(lr.current),mu(t)){if(r=t.stateNode,s=t.memoizedProps,r[nr]=t,(a=r.nodeValue!==s)&&(e=es,e!==null))switch(e.tag){case 3:fu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&fu(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[nr]=t,t.stateNode=r}return vn(t),null;case 13:if(Ct(Rt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Tt&&Xn!==null&&t.mode&1&&!(t.flags&128))MS(),hl(),t.flags|=98560,a=!1;else if(a=mu(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(xe(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(xe(317));a[nr]=t}else hl(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;vn(t),a=!1}else Ps!==null&&(ag(Ps),Ps=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?Qt===0&&(Qt=3):Rv())),t.updateQueue!==null&&(t.flags|=4),vn(t),null);case 4:return ml(),Xp(e,t),e===null&&Yo(t.stateNode.containerInfo),vn(t),null;case 10:return mv(t.type._context),vn(t),null;case 17:return Un(t.type)&&Ad(),vn(t),null;case 19:if(Ct(Rt),a=t.memoizedState,a===null)return vn(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)oo(a,!1);else{if(Qt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=Dd(e),l!==null){for(t.flags|=128,oo(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 bt(Rt,Rt.current&1|2),t.child}e=e.sibling}a.tail!==null&&Lt()>gl&&(t.flags|=128,r=!0,oo(a,!1),t.lanes=4194304)}else{if(!r)if(e=Dd(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),oo(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!Tt)return vn(t),null}else 2*Lt()-a.renderingStartTime>gl&&s!==1073741824&&(t.flags|=128,r=!0,oo(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,bt(Rt,r?s&1|2:s&1),t):(vn(t),null);case 22:case 23:return $v(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Jn&1073741824&&(vn(t),t.subtreeFlags&6&&(t.flags|=8192)):vn(t),null;case 24:return null;case 25:return null}throw Error(xe(156,t.tag))}function K2(e,t){switch(uv(t),t.tag){case 1:return Un(t.type)&&Ad(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return ml(),Ct(zn),Ct(yn),jv(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return vv(t),null;case 13:if(Ct(Rt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(xe(340));hl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Ct(Rt),null;case 4:return ml(),null;case 10:return mv(t.type._context),null;case 22:case 23:return $v(),null;case 24:return null;default:return null}}var xu=!1,jn=!1,V2=typeof WeakSet=="function"?WeakSet:Set,Te=null;function Va(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Dt(e,t,r)}else s.current=null}function Zp(e,t,s){try{s()}catch(r){Dt(e,t,r)}}var jb=!1;function G2(e,t){if(Op=Nd,e=yS(),ov(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,f=e,m=null;t:for(;;){for(var p;f!==s||i!==0&&f.nodeType!==3||(o=l+i),f!==a||r!==0&&f.nodeType!==3||(c=l+r),f.nodeType===3&&(l+=f.nodeValue.length),(p=f.firstChild)!==null;)m=f,f=p;for(;;){if(f===e)break t;if(m===s&&++u===i&&(o=l),m===a&&++h===r&&(c=l),(p=f.nextSibling)!==null)break;f=m,m=f.parentNode}f=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(Lp={focusedElem:e,selectionRange:s},Nd=!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 v=g.memoizedProps,b=g.memoizedState,j=t.stateNode,x=j.getSnapshotBeforeUpdate(t.elementType===t.type?v:Rs(t.type,v),b);j.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(xe(163))}}catch(y){Dt(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,Te=e;break}Te=t.return}return g=jb,jb=!1,g}function Ro(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&&Zp(t,s,a)}i=i.next}while(i!==r)}}function Rh(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 eg(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 xC(e){var t=e.alternate;t!==null&&(e.alternate=null,xC(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[nr],delete t[Jo],delete t[zp],delete t[T2],delete t[$2])),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 vC(e){return e.tag===5||e.tag===3||e.tag===4}function wb(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||vC(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 tg(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=Ed));else if(r!==4&&(e=e.child,e!==null))for(tg(e,t,s),e=e.sibling;e!==null;)tg(e,t,s),e=e.sibling}function ng(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(ng(e,t,s),e=e.sibling;e!==null;)ng(e,t,s),e=e.sibling}var dn=null,Is=!1;function Qr(e,t,s){for(s=s.child;s!==null;)jC(e,t,s),s=s.sibling}function jC(e,t,s){if(ar&&typeof ar.onCommitFiberUnmount=="function")try{ar.onCommitFiberUnmount(kh,s)}catch{}switch(s.tag){case 5:jn||Va(s,t);case 6:var r=dn,i=Is;dn=null,Qr(e,t,s),dn=r,Is=i,dn!==null&&(Is?(e=dn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):dn.removeChild(s.stateNode));break;case 18:dn!==null&&(Is?(e=dn,s=s.stateNode,e.nodeType===8?tm(e.parentNode,s):e.nodeType===1&&tm(e,s),Ko(e)):tm(dn,s.stateNode));break;case 4:r=dn,i=Is,dn=s.stateNode.containerInfo,Is=!0,Qr(e,t,s),dn=r,Is=i;break;case 0:case 11:case 14:case 15:if(!jn&&(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)&&Zp(s,t,l),i=i.next}while(i!==r)}Qr(e,t,s);break;case 1:if(!jn&&(Va(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Dt(s,t,o)}Qr(e,t,s);break;case 21:Qr(e,t,s);break;case 22:s.mode&1?(jn=(r=jn)||s.memoizedState!==null,Qr(e,t,s),jn=r):Qr(e,t,s);break;default:Qr(e,t,s)}}function yb(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new V2),t.forEach(function(r){var i=nM.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function $s(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:dn=o.stateNode,Is=!1;break e;case 3:dn=o.stateNode.containerInfo,Is=!0;break e;case 4:dn=o.stateNode.containerInfo,Is=!0;break e}o=o.return}if(dn===null)throw Error(xe(160));jC(a,l,i),dn=null,Is=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Dt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)wC(t,e),t=t.sibling}function wC(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if($s(t,e),qs(e),r&4){try{Ro(3,e,e.return),Rh(3,e)}catch(v){Dt(e,e.return,v)}try{Ro(5,e,e.return)}catch(v){Dt(e,e.return,v)}}break;case 1:$s(t,e),qs(e),r&512&&s!==null&&Va(s,s.return);break;case 5:if($s(t,e),qs(e),r&512&&s!==null&&Va(s,s.return),e.flags&32){var i=e.stateNode;try{Uo(i,"")}catch(v){Dt(e,e.return,v)}}if(r&4&&(i=e.stateNode,i!=null)){var a=e.memoizedProps,l=s!==null?s.memoizedProps:a,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&a.type==="radio"&&a.name!=null&&BN(i,a),Cp(o,l);var u=Cp(o,a);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?GN(i,f):h==="dangerouslySetInnerHTML"?KN(i,f):h==="children"?Uo(i,f):qx(i,h,f,u)}switch(o){case"input":yp(i,a);break;case"textarea":WN(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?Xa(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?Xa(i,!!a.multiple,a.defaultValue,!0):Xa(i,!!a.multiple,a.multiple?[]:"",!1))}i[Jo]=a}catch(v){Dt(e,e.return,v)}}break;case 6:if($s(t,e),qs(e),r&4){if(e.stateNode===null)throw Error(xe(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(v){Dt(e,e.return,v)}}break;case 3:if($s(t,e),qs(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Ko(t.containerInfo)}catch(v){Dt(e,e.return,v)}break;case 4:$s(t,e),qs(e);break;case 13:$s(t,e),qs(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Av=Lt())),r&4&&yb(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(jn=(u=jn)||h,$s(t,e),jn=u):$s(t,e),qs(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(Te=e,h=e.child;h!==null;){for(f=Te=h;Te!==null;){switch(m=Te,p=m.child,m.tag){case 0:case 11:case 14:case 15:Ro(4,m,m.return);break;case 1:Va(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{t=r,g.props=t.memoizedProps,g.state=t.memoizedState,g.componentWillUnmount()}catch(v){Dt(r,s,v)}}break;case 5:Va(m,m.return);break;case 22:if(m.memoizedState!==null){kb(f);continue}}p!==null?(p.return=m,Te=p):kb(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{i=f.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=VN("display",l))}catch(v){Dt(e,e.return,v)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(v){Dt(e,e.return,v)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;h===f&&(h=null),f=f.return}h===f&&(h=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:$s(t,e),qs(e),r&4&&yb(e);break;case 21:break;default:$s(t,e),qs(e)}}function qs(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(vC(s)){var r=s;break e}s=s.return}throw Error(xe(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(Uo(i,""),r.flags&=-33);var a=wb(e);ng(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=wb(e);tg(e,o,l);break;default:throw Error(xe(161))}}catch(c){Dt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function Y2(e,t,s){Te=e,yC(e)}function yC(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||xu;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||jn;o=xu;var u=jn;if(xu=l,(jn=c)&&!u)for(Te=i;Te!==null;)l=Te,c=l.child,l.tag===22&&l.memoizedState!==null?Nb(i):c!==null?(c.return=l,Te=c):Nb(i);for(;a!==null;)Te=a,yC(a),a=a.sibling;Te=i,xu=o,jn=u}bb(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,Te=a):bb(e)}}function bb(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:jn||Rh(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!jn)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:Rs(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&ab(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}ab(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var f=h.dehydrated;f!==null&&Ko(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(xe(163))}jn||t.flags&512&&eg(t)}catch(m){Dt(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 kb(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 Nb(e){for(;Te!==null;){var t=Te;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{Rh(4,t)}catch(c){Dt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Dt(t,i,c)}}var a=t.return;try{eg(t)}catch(c){Dt(t,a,c)}break;case 5:var l=t.return;try{eg(t)}catch(c){Dt(t,l,c)}}}catch(c){Dt(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 q2=Math.ceil,Fd=Gr.ReactCurrentDispatcher,Cv=Gr.ReactCurrentOwner,ys=Gr.ReactCurrentBatchConfig,lt=0,on=null,Ut=null,hn=0,Jn=0,Ga=Ai(0),Qt=0,nc=null,ia=0,Ih=0,Ev=0,Io=null,Ln=null,Av=0,gl=1/0,kr=null,_d=!1,sg=null,hi=null,vu=!1,ri=null,zd=0,Po=0,rg=null,td=-1,nd=0;function En(){return lt&6?Lt():td!==-1?td:td=Lt()}function fi(e){return e.mode&1?lt&2&&hn!==0?hn&-hn:I2.transition!==null?(nd===0&&(nd=iS()),nd):(e=pt,e!==0||(e=window.event,e=e===void 0?16:hS(e.type)),e):1}function Os(e,t,s,r){if(50<Po)throw Po=0,rg=null,Error(xe(185));Ec(e,s,r),(!(lt&2)||e!==on)&&(e===on&&(!(lt&2)&&(Ih|=s),Qt===4&&ni(e,hn)),Bn(e,r),s===1&<===0&&!(t.mode&1)&&(gl=Lt()+500,Ah&&Ti()))}function Bn(e,t){var s=e.callbackNode;IP(e,t);var r=kd(e,e===on?hn:0);if(r===0)s!==null&&Py(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&Py(s),t===1)e.tag===0?R2(Sb.bind(null,e)):RS(Sb.bind(null,e)),E2(function(){!(lt&6)&&Ti()}),s=null;else{switch(aS(r)){case 1:s=ev;break;case 4:s=sS;break;case 16:s=bd;break;case 536870912:s=rS;break;default:s=bd}s=TC(s,bC.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function bC(e,t){if(td=-1,nd=0,lt&6)throw Error(xe(327));var s=e.callbackNode;if(sl()&&e.callbackNode!==s)return null;var r=kd(e,e===on?hn:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Ud(e,r);else{t=r;var i=lt;lt|=2;var a=NC();(on!==e||hn!==t)&&(kr=null,gl=Lt()+500,Xi(e,t));do try{X2();break}catch(o){kC(e,o)}while(!0);fv(),Fd.current=a,lt=i,Ut!==null?t=0:(on=null,hn=0,t=Qt)}if(t!==0){if(t===2&&(i=Rp(e),i!==0&&(r=i,t=ig(e,i))),t===1)throw s=nc,Xi(e,0),ni(e,r),Bn(e,Lt()),s;if(t===6)ni(e,r);else{if(i=e.current.alternate,!(r&30)&&!J2(i)&&(t=Ud(e,r),t===2&&(a=Rp(e),a!==0&&(r=a,t=ig(e,a))),t===1))throw s=nc,Xi(e,0),ni(e,r),Bn(e,Lt()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(xe(345));case 2:Wi(e,Ln,kr);break;case 3:if(ni(e,r),(r&130023424)===r&&(t=Av+500-Lt(),10<t)){if(kd(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){En(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=_p(Wi.bind(null,e,Ln,kr),t);break}Wi(e,Ln,kr);break;case 4:if(ni(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-Ds(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*q2(r/1960))-r,10<r){e.timeoutHandle=_p(Wi.bind(null,e,Ln,kr),r);break}Wi(e,Ln,kr);break;case 5:Wi(e,Ln,kr);break;default:throw Error(xe(329))}}}return Bn(e,Lt()),e.callbackNode===s?bC.bind(null,e):null}function ig(e,t){var s=Io;return e.current.memoizedState.isDehydrated&&(Xi(e,t).flags|=256),e=Ud(e,t),e!==2&&(t=Ln,Ln=s,t!==null&&ag(t)),e}function ag(e){Ln===null?Ln=e:Ln.push.apply(Ln,e)}function J2(e){for(var t=e;;){if(t.flags&16384){var s=t.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var i=s[r],a=i.getSnapshot;i=i.value;try{if(!_s(a(),i))return!1}catch{return!1}}}if(s=t.child,t.subtreeFlags&16384&&s!==null)s.return=t,t=s;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function ni(e,t){for(t&=~Ev,t&=~Ih,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-Ds(t),r=1<<s;e[s]=-1,t&=~r}}function Sb(e){if(lt&6)throw Error(xe(327));sl();var t=kd(e,0);if(!(t&1))return Bn(e,Lt()),null;var s=Ud(e,t);if(e.tag!==0&&s===2){var r=Rp(e);r!==0&&(t=r,s=ig(e,r))}if(s===1)throw s=nc,Xi(e,0),ni(e,t),Bn(e,Lt()),s;if(s===6)throw Error(xe(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Wi(e,Ln,kr),Bn(e,Lt()),null}function Tv(e,t){var s=lt;lt|=1;try{return e(t)}finally{lt=s,lt===0&&(gl=Lt()+500,Ah&&Ti())}}function aa(e){ri!==null&&ri.tag===0&&!(lt&6)&&sl();var t=lt;lt|=1;var s=ys.transition,r=pt;try{if(ys.transition=null,pt=1,e)return e()}finally{pt=r,ys.transition=s,lt=t,!(lt&6)&&Ti()}}function $v(){Jn=Ga.current,Ct(Ga)}function Xi(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,C2(s)),Ut!==null)for(s=Ut.return;s!==null;){var r=s;switch(uv(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Ad();break;case 3:ml(),Ct(zn),Ct(yn),jv();break;case 5:vv(r);break;case 4:ml();break;case 13:Ct(Rt);break;case 19:Ct(Rt);break;case 10:mv(r.type._context);break;case 22:case 23:$v()}s=s.return}if(on=e,Ut=e=mi(e.current,null),hn=Jn=t,Qt=0,nc=null,Ev=Ih=ia=0,Ln=Io=null,Yi!==null){for(t=0;t<Yi.length;t++)if(s=Yi[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}Yi=null}return e}function kC(e,t){do{var s=Ut;try{if(fv(),Xu.current=Ld,Od){for(var r=It.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}Od=!1}if(ra=0,tn=Yt=It=null,$o=!1,Zo=0,Cv.current=null,s===null||s.return===null){Qt=1,nc=t,Ut=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=hn,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,f=h.tag;if(!(h.mode&1)&&(f===0||f===11||f===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=hb(l);if(p!==null){p.flags&=-257,fb(p,l,o,a,t),p.mode&1&&db(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var v=new Set;v.add(c),t.updateQueue=v}else g.add(c);break e}else{if(!(t&1)){db(a,u,t),Rv();break e}c=Error(xe(426))}}else if(Tt&&o.mode&1){var b=hb(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),fb(b,l,o,a,t),dv(pl(c,o));break e}}a=c=pl(c,o),Qt!==4&&(Qt=2),Io===null?Io=[a]:Io.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var j=aC(a,c,t);ib(a,j);break e;case 1:o=c;var x=a.type,w=a.stateNode;if(!(a.flags&128)&&(typeof x.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(hi===null||!hi.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=lC(a,o,t);ib(a,y);break e}}a=a.return}while(a!==null)}CC(s)}catch(k){t=k,Ut===s&&s!==null&&(Ut=s=s.return);continue}break}while(!0)}function NC(){var e=Fd.current;return Fd.current=Ld,e===null?Ld:e}function Rv(){(Qt===0||Qt===3||Qt===2)&&(Qt=4),on===null||!(ia&268435455)&&!(Ih&268435455)||ni(on,hn)}function Ud(e,t){var s=lt;lt|=2;var r=NC();(on!==e||hn!==t)&&(kr=null,Xi(e,t));do try{Q2();break}catch(i){kC(e,i)}while(!0);if(fv(),lt=s,Fd.current=r,Ut!==null)throw Error(xe(261));return on=null,hn=0,Qt}function Q2(){for(;Ut!==null;)SC(Ut)}function X2(){for(;Ut!==null&&!kP();)SC(Ut)}function SC(e){var t=AC(e.alternate,e,Jn);e.memoizedProps=e.pendingProps,t===null?CC(e):Ut=t,Cv.current=null}function CC(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=K2(s,t),s!==null){s.flags&=32767,Ut=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Qt=6,Ut=null;return}}else if(s=H2(s,t,Jn),s!==null){Ut=s;return}if(t=t.sibling,t!==null){Ut=t;return}Ut=t=e}while(t!==null);Qt===0&&(Qt=5)}function Wi(e,t,s){var r=pt,i=ys.transition;try{ys.transition=null,pt=1,Z2(e,t,s,r)}finally{ys.transition=i,pt=r}return null}function Z2(e,t,s,r){do sl();while(ri!==null);if(lt&6)throw Error(xe(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(xe(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(PP(e,a),e===on&&(Ut=on=null,hn=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||vu||(vu=!0,TC(bd,function(){return sl(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=ys.transition,ys.transition=null;var l=pt;pt=1;var o=lt;lt|=4,Cv.current=null,G2(e,s),wC(s,e),j2(Lp),Nd=!!Op,Lp=Op=null,e.current=s,Y2(s),NP(),lt=o,pt=l,ys.transition=a}else e.current=s;if(vu&&(vu=!1,ri=e,zd=i),a=e.pendingLanes,a===0&&(hi=null),EP(s.stateNode),Bn(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(_d)throw _d=!1,e=sg,sg=null,e;return zd&1&&e.tag!==0&&sl(),a=e.pendingLanes,a&1?e===rg?Po++:(Po=0,rg=e):Po=0,Ti(),null}function sl(){if(ri!==null){var e=aS(zd),t=ys.transition,s=pt;try{if(ys.transition=null,pt=16>e?16:e,ri===null)var r=!1;else{if(e=ri,ri=null,zd=0,lt&6)throw Error(xe(331));var i=lt;for(lt|=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 h=Te;switch(h.tag){case 0:case 11:case 15:Ro(8,h,a)}var f=h.child;if(f!==null)f.return=h,Te=f;else for(;Te!==null;){h=Te;var m=h.sibling,p=h.return;if(xC(h),h===u){Te=null;break}if(m!==null){m.return=p,Te=m;break}Te=p}}}var g=a.alternate;if(g!==null){var v=g.child;if(v!==null){g.child=null;do{var b=v.sibling;v.sibling=null,v=b}while(v!==null)}}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:Ro(9,a,a.return)}var j=a.sibling;if(j!==null){j.return=a.return,Te=j;break e}Te=a.return}}var x=e.current;for(Te=x;Te!==null;){l=Te;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Te=w;else e:for(l=x;Te!==null;){if(o=Te,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Rh(9,o)}}catch(k){Dt(o,o.return,k)}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(lt=i,Ti(),ar&&typeof ar.onPostCommitFiberRoot=="function")try{ar.onPostCommitFiberRoot(kh,e)}catch{}r=!0}return r}finally{pt=s,ys.transition=t}}return!1}function Cb(e,t,s){t=pl(s,t),t=aC(e,t,1),e=di(e,t,1),t=En(),e!==null&&(Ec(e,1,t),Bn(e,t))}function Dt(e,t,s){if(e.tag===3)Cb(e,e,s);else for(;t!==null;){if(t.tag===3){Cb(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(hi===null||!hi.has(r))){e=pl(s,e),e=lC(t,e,1),t=di(t,e,1),e=En(),t!==null&&(Ec(t,1,e),Bn(t,e));break}}t=t.return}}function eM(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=En(),e.pingedLanes|=e.suspendedLanes&s,on===e&&(hn&s)===s&&(Qt===4||Qt===3&&(hn&130023424)===hn&&500>Lt()-Av?Xi(e,0):Ev|=s),Bn(e,t)}function EC(e,t){t===0&&(e.mode&1?(t=ou,ou<<=1,!(ou&130023424)&&(ou=4194304)):t=1);var s=En();e=zr(e,t),e!==null&&(Ec(e,t,s),Bn(e,s))}function tM(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),EC(e,s)}function nM(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(xe(314))}r!==null&&r.delete(t),EC(e,s)}var AC;AC=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||zn.current)Fn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Fn=!1,W2(e,t,s);Fn=!!(e.flags&131072)}else Fn=!1,Tt&&t.flags&1048576&&IS(t,Rd,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;ed(e,t),e=t.pendingProps;var i=dl(t,yn.current);nl(t,s),i=yv(null,t,r,e,i,s);var a=bv();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,Un(r)?(a=!0,Td(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,gv(t),i.updater=$h,t.stateNode=i,i._reactInternals=t,Vp(t,r,e,s),t=qp(null,t,r,!0,a,s)):(t.tag=0,Tt&&a&&cv(t),Sn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(ed(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=rM(r),e=Rs(r,e),i){case 0:t=Yp(null,t,r,e,s);break e;case 1:t=gb(null,t,r,e,s);break e;case 11:t=mb(null,t,r,e,s);break e;case 14:t=pb(null,t,r,Rs(r.type,e),s);break e}throw Error(xe(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Rs(r,i),Yp(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Rs(r,i),gb(e,t,r,i,s);case 3:e:{if(dC(t),e===null)throw Error(xe(387));r=t.pendingProps,a=t.memoizedState,i=a.element,FS(e,t),Md(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=pl(Error(xe(423)),t),t=xb(e,t,r,s,i);break e}else if(r!==i){i=pl(Error(xe(424)),t),t=xb(e,t,r,s,i);break e}else for(Xn=ui(t.stateNode.containerInfo.firstChild),es=t,Tt=!0,Ps=null,s=OS(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(hl(),r===i){t=Ur(e,t,s);break e}Sn(e,t,r,s)}t=t.child}return t;case 5:return _S(t),e===null&&Wp(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,Fp(r,i)?l=null:a!==null&&Fp(r,a)&&(t.flags|=32),uC(e,t),Sn(e,t,l,s),t.child;case 6:return e===null&&Wp(t),null;case 13:return hC(e,t,s);case 4:return xv(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=fl(t,null,r,s):Sn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Rs(r,i),mb(e,t,r,i,s);case 7:return Sn(e,t,t.pendingProps,s),t.child;case 8:return Sn(e,t,t.pendingProps.children,s),t.child;case 12:return Sn(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,bt(Id,r._currentValue),r._currentValue=l,a!==null)if(_s(a.value,l)){if(a.children===i.children&&!zn.current){t=Ur(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=Ir(-1,s&-s),c.tag=2;var u=a.updateQueue;if(u!==null){u=u.shared;var h=u.pending;h===null?c.next=c:(c.next=h.next,h.next=c),u.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),Hp(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(xe(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),Hp(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}Sn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,nl(t,s),i=Ns(i),r=r(i),t.flags|=1,Sn(e,t,r,s),t.child;case 14:return r=t.type,i=Rs(r,t.pendingProps),i=Rs(r.type,i),pb(e,t,r,i,s);case 15:return oC(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Rs(r,i),ed(e,t),t.tag=1,Un(r)?(e=!0,Td(t)):e=!1,nl(t,s),iC(t,r,i),Vp(t,r,i,s),qp(null,t,r,!0,e,s);case 19:return fC(e,t,s);case 22:return cC(e,t,s)}throw Error(xe(156,t.tag))};function TC(e,t){return nS(e,t)}function sM(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 ws(e,t,s,r){return new sM(e,t,s,r)}function Iv(e){return e=e.prototype,!(!e||!e.isReactComponent)}function rM(e){if(typeof e=="function")return Iv(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Qx)return 11;if(e===Xx)return 14}return 2}function mi(e,t){var s=e.alternate;return s===null?(s=ws(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 sd(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Iv(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case La:return Zi(s.children,i,a,t);case Jx:l=8,i|=8;break;case gp:return e=ws(12,s,t,i|2),e.elementType=gp,e.lanes=a,e;case xp:return e=ws(13,s,t,i),e.elementType=xp,e.lanes=a,e;case vp:return e=ws(19,s,t,i),e.elementType=vp,e.lanes=a,e;case _N:return Ph(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case LN:l=10;break e;case FN:l=9;break e;case Qx:l=11;break e;case Xx:l=14;break e;case Zr:l=16,r=null;break e}throw Error(xe(130,e==null?e:typeof e,""))}return t=ws(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function Zi(e,t,s,r){return e=ws(7,e,r,t),e.lanes=s,e}function Ph(e,t,s,r){return e=ws(22,e,r,t),e.elementType=_N,e.lanes=s,e.stateNode={isHidden:!1},e}function cm(e,t,s){return e=ws(6,e,null,t),e.lanes=s,e}function um(e,t,s){return t=ws(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function iM(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=Hf(0),this.expirationTimes=Hf(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Hf(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Pv(e,t,s,r,i,a,l,o,c){return e=new iM(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=ws(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},gv(a),e}function aM(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Oa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function $C(e){if(!e)return ji;e=e._reactInternals;e:{if(fa(e)!==e||e.tag!==1)throw Error(xe(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Un(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(xe(171))}if(e.tag===1){var s=e.type;if(Un(s))return $S(e,s,t)}return t}function RC(e,t,s,r,i,a,l,o,c){return e=Pv(s,r,!0,e,i,a,l,o,c),e.context=$C(null),s=e.current,r=En(),i=fi(s),a=Ir(r,i),a.callback=t??null,di(s,a,i),e.current.lanes=i,Ec(e,i,r),Bn(e,r),e}function Mh(e,t,s,r){var i=t.current,a=En(),l=fi(i);return s=$C(s),t.context===null?t.context=s:t.pendingContext=s,t=Ir(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=di(i,t,l),e!==null&&(Os(e,i,l,a),Qu(e,i,l)),l}function Bd(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 Eb(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function Mv(e,t){Eb(e,t),(e=e.alternate)&&Eb(e,t)}function lM(){return null}var IC=typeof reportError=="function"?reportError:function(e){console.error(e)};function Dv(e){this._internalRoot=e}Dh.prototype.render=Dv.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(xe(409));Mh(e,t,null,null)};Dh.prototype.unmount=Dv.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;aa(function(){Mh(null,e,null,null)}),t[_r]=null}};function Dh(e){this._internalRoot=e}Dh.prototype.unstable_scheduleHydration=function(e){if(e){var t=cS();e={blockedOn:null,target:e,priority:t};for(var s=0;s<ti.length&&t!==0&&t<ti[s].priority;s++);ti.splice(s,0,e),s===0&&dS(e)}};function Ov(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Oh(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Ab(){}function oM(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Bd(l);a.call(u)}}var l=RC(t,r,e,0,null,!1,!1,"",Ab);return e._reactRootContainer=l,e[_r]=l.current,Yo(e.nodeType===8?e.parentNode:e),aa(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Bd(c);o.call(u)}}var c=Pv(e,0,!1,null,null,!1,!1,"",Ab);return e._reactRootContainer=c,e[_r]=c.current,Yo(e.nodeType===8?e.parentNode:e),aa(function(){Mh(t,c,s,r)}),c}function Lh(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=Bd(l);o.call(c)}}Mh(t,l,e,i)}else l=oM(s,t,e,i,r);return Bd(l)}lS=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=wo(t.pendingLanes);s!==0&&(tv(t,s|1),Bn(t,Lt()),!(lt&6)&&(gl=Lt()+500,Ti()))}break;case 13:aa(function(){var r=zr(e,1);if(r!==null){var i=En();Os(r,e,1,i)}}),Mv(e,1)}};nv=function(e){if(e.tag===13){var t=zr(e,134217728);if(t!==null){var s=En();Os(t,e,134217728,s)}Mv(e,134217728)}};oS=function(e){if(e.tag===13){var t=fi(e),s=zr(e,t);if(s!==null){var r=En();Os(s,e,t,r)}Mv(e,t)}};cS=function(){return pt};uS=function(e,t){var s=pt;try{return pt=e,t()}finally{pt=s}};Ap=function(e,t,s){switch(t){case"input":if(yp(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=Eh(r);if(!i)throw Error(xe(90));UN(r),yp(r,i)}}}break;case"textarea":WN(e,s);break;case"select":t=s.value,t!=null&&Xa(e,!!s.multiple,t,!1)}};JN=Tv;QN=aa;var cM={usingClientEntryPoint:!1,Events:[Tc,Ua,Eh,YN,qN,Tv]},co={findFiberByHostInstance:Gi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},uM={bundleType:co.bundleType,version:co.version,rendererPackageName:co.rendererPackageName,rendererConfig:co.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Gr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=eS(e),e===null?null:e.stateNode},findFiberByHostInstance:co.findFiberByHostInstance||lM,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 ju=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!ju.isDisabled&&ju.supportsFiber)try{kh=ju.inject(uM),ar=ju}catch{}}is.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=cM;is.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Ov(t))throw Error(xe(200));return aM(e,t,null,s)};is.createRoot=function(e,t){if(!Ov(e))throw Error(xe(299));var s=!1,r="",i=IC;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Pv(e,1,!1,null,null,s,!1,r,i),e[_r]=t.current,Yo(e.nodeType===8?e.parentNode:e),new Dv(t)};is.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(xe(188)):(e=Object.keys(e).join(","),Error(xe(268,e)));return e=eS(t),e=e===null?null:e.stateNode,e};is.flushSync=function(e){return aa(e)};is.hydrate=function(e,t,s){if(!Oh(t))throw Error(xe(200));return Lh(null,e,t,!0,s)};is.hydrateRoot=function(e,t,s){if(!Ov(e))throw Error(xe(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=IC;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=RC(t,null,e,1,s??null,i,!1,a,l),e[_r]=t.current,Yo(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 Dh(t)};is.render=function(e,t,s){if(!Oh(t))throw Error(xe(200));return Lh(null,e,t,!1,s)};is.unmountComponentAtNode=function(e){if(!Oh(e))throw Error(xe(40));return e._reactRootContainer?(aa(function(){Lh(null,null,e,!1,function(){e._reactRootContainer=null,e[_r]=null})}),!0):!1};is.unstable_batchedUpdates=Tv;is.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Oh(s))throw Error(xe(200));if(e==null||e._reactInternals===void 0)throw Error(xe(38));return Lh(e,t,s,!1,r)};is.version="18.3.1-next-f1338f8080-20240426";function PC(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(PC)}catch(e){console.error(e)}}PC(),PN.exports=is;var Pl=PN.exports,MC,Tb=Pl;MC=Tb.createRoot,Tb.hydrateRoot;var dM=Object.defineProperty,Ml=(e,t)=>dM(e,"name",{value:t,configurable:!0}),DC=!!(typeof window<"u"&&window.document&&window.document.createElement);function Me(e,t,{checkForDefaultPrevented:s=!0}={}){return Ml(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}Ml(Me,"composeEventHandlers");function hM(e){var t;if(!DC)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}Ml(hM,"getOwnerWindow");function lg(e){if(!DC)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}Ml(lg,"getOwnerDocument");function OC(e,t=!1){const{activeElement:s}=lg(e);if(!(s!=null&&s.nodeName))return null;if(LC(s)&&s.contentDocument)return OC(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=lg(s).getElementById(r);if(i)return i}}return s}Ml(OC,"getActiveElement");function LC(e){return e.tagName==="IFRAME"}Ml(LC,"isFrame");var fM=Object.defineProperty,Lv=(e,t)=>fM(e,"name",{value:t,configurable:!0});function og(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Lv(og,"setRef");function FC(...e){return t=>{let s=!1;const r=e.map(i=>{const a=og(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():og(e[i],null)}}}}Lv(FC,"composeRefs");function wt(...e){return d.useCallback(FC(...e),e)}Lv(wt,"useComposedRefs");var mM=Object.defineProperty,js=(e,t)=>mM(e,"name",{value:t,configurable:!0});function pM(e,t){const s=d.createContext(t);s.displayName=e+"Context";const r=js(a=>{const{children:l,...o}=a,c=d.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=d.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return js(i,"useContext"),[r,i]}js(pM,"createContext");function Ws(e,t=[]){let s=[];function r(a,l){const o=d.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=js(f=>{var j;const{scope:m,children:p,...g}=f,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=d.useMemo(()=>g,Object.values(g));return n.jsx(v.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function h(f,m,p={}){var j;const{optional:g=!1}=p,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=d.useContext(v);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${a}\``)}return js(h,"useContext"),[u,h]}js(r,"createContext");const i=js(()=>{const a=s.map(l=>d.createContext(l));return js(function(o){const c=(o==null?void 0:o[e])||a;return d.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,_C(i,...t)]}js(Ws,"createContextScope");function _C(...e){const t=e[0];if(e.length===1)return t;const s=js(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return js(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...o,...f}},{});return d.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}js(_C,"composeContextScopes");var gM=Object.defineProperty,Hs=(e,t)=>gM(e,"name",{value:t,configurable:!0});function wi(e){const t=d.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];cg(i)&&typeof wu=="function"&&(i=wu(i._payload)),d.Children.forEach(i,m=>{var p;if(HC(m)){o=!0;const g=m;let v="child"in g.props?g.props.child:g.props.children;cg(v)&&typeof wu=="function"&&(v=wu(v._payload)),l=xM(g,v),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(i)===1&&d.isValidElement(i)&&(l=i);const u=l?WC(l):void 0,h=wt(r,u);if(!l){if(i||i===0)throw new Error(o?wM(e):jM(e));return i}const f=BC(a,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return t.displayName=`${e}.Slot`,t}Hs(wi,"createSlot");var zC=Symbol.for("radix.slottable");function UC(e){const t=Hs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=zC,t}Hs(UC,"createSlottable");var xM=Hs((e,t)=>{if("child"in e.props){const s=e.props.child;return d.isValidElement(s)?d.cloneElement(s,void 0,e.props.children(s.props.children)):null}return d.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function BC(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}}Hs(BC,"mergeProps");function WC(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)}Hs(WC,"getElementRef");function HC(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===zC}Hs(HC,"isSlottable");var vM=Symbol.for("react.lazy");function cg(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===vM&&"_payload"in e&&KC(e._payload)}Hs(cg,"isLazyComponent");function KC(e){return typeof e=="object"&&e!==null&&"then"in e}Hs(KC,"isPromiseLike");var jM=Hs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),wM=Hs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),wu=$l[" use ".trim().toString()],yM=Object.defineProperty,nn=(e,t)=>yM(e,"name",{value:t,configurable:!0});function Fh(e){const t=e+"CollectionProvider",[s,r]=Ws(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=nn(v=>{const{scope:b,children:j}=v,x=d.useRef(null),w=d.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:w,collectionRef:x,children:j})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=wi(o),u=d.forwardRef((v,b)=>{const{scope:j,children:x}=v,w=a(o,j),y=wt(b,w.collectionRef);return n.jsx(c,{ref:y,children:x})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=wi(h),p=d.forwardRef((v,b)=>{const{scope:j,children:x,...w}=v,y=d.useRef(null),k=wt(b,y),N=a(h,j);return d.useEffect(()=>(N.itemMap.set(y,{ref:y,...w}),()=>void N.itemMap.delete(y))),n.jsx(m,{[f]:"",ref:k,children:x})});p.displayName=h;function g(v){const b=a(e+"CollectionConsumer",v);return d.useCallback(()=>{const x=b.collectionRef.current;if(!x)return[];const w=Array.from(x.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((N,S)=>w.indexOf(N.ref.current)-w.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return nn(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}nn(Fh,"createCollection");var $b=new WeakMap,zt,Qn,dm=(Qn=class extends Map{constructor(s){super(s);wy(this,zt);Ff(this,zt,[...super.keys()]),$b.set(this,!0)}set(s,r){return $b.get(this)&&(this.has(s)?gn(this,zt)[gn(this,zt).indexOf(s)]=s:gn(this,zt).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=gn(this,zt).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 h=this.size+(a?0:1);o<0&&c++;const f=[...gn(this,zt)];let m,p=!1;for(let g=c;g<h;g++)if(c===g){let v=f[g];f[g]===r&&(v=f[g+1]),a&&this.delete(r),m=this.get(v),this.set(r,i)}else{!p&&f[g-1]===r&&(p=!0);const v=f[p?g:g-1],b=m;m=this.get(v),this.delete(v),this.set(v,b)}return this}with(s,r,i){const a=new Qn(this);return a.insert(s,r,i),a}before(s){const r=gn(this,zt).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=gn(this,zt).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=gn(this,zt).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=gn(this,zt).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return Ff(this,zt,[]),super.clear()}delete(s){const r=super.delete(s);return r&&gn(this,zt).splice(gn(this,zt).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=rd(gn(this,zt),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=rd(gn(this,zt),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return gn(this,zt).indexOf(s)}keyAt(s){return rd(gn(this,zt),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 Qn(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 Qn(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 Qn(r)}toReversed(){const s=new Qn;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 Qn(r)}slice(s,r){const i=new Qn;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}},zt=new WeakMap,nn(Qn,"OrderedDict"),Qn);function rd(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=VC(e,t);return s===-1?void 0:e[s]}nn(rd,"at");function VC(e,t){const s=e.length,r=Fv(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}nn(VC,"toSafeIndex");function Fv(e){return e!==e||e===0?0:Math.trunc(e)}nn(Fv,"toSafeInteger");function bM(e){const t=e+"CollectionProvider",[s,r]=Ws(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new dm,setItemMap:nn(()=>{},"setItemMap")}),l=nn(({state:w,...y})=>w?n.jsx(c,{...y,state:w}):n.jsx(o,{...y}),"CollectionProvider");l.displayName=t;const o=nn(w=>{const y=b();return n.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=t+"Init";const c=nn(w=>{const{scope:y,children:k,state:N}=w,S=d.useRef(null),[C,T]=d.useState(null),R=wt(S,T),[I,L]=N;return d.useEffect(()=>{if(!C)return;const W=qC(()=>{});return W.observe(C,{childList:!0,subtree:!0}),()=>{W.disconnect()}},[C]),n.jsx(i,{scope:y,itemMap:I,setItemMap:L,collectionRef:R,collectionRefObject:S,collectionElement:C,children:k})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",h=wi(u),f=d.forwardRef((w,y)=>{const{scope:k,children:N}=w,S=a(u,k),C=wt(y,S.collectionRef);return n.jsx(h,{ref:C,children:N})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=wi(m),v=d.forwardRef((w,y)=>{const{scope:k,children:N,...S}=w,C=d.useRef(null),[T,R]=d.useState(null),I=wt(y,C,R),L=a(m,k),{setItemMap:W}=L,$=d.useRef(S);GC($.current,S)||($.current=S);const P=$.current;return d.useEffect(()=>{const O=P;return W(M=>T?M.has(T)?M.set(T,{...O,element:T}).toSorted(ug):(M.set(T,{...O,element:T}),M.toSorted(ug)):M),()=>{W(M=>!T||!M.has(T)?M:(M.delete(T),new dm(M)))}},[T,P,W]),n.jsx(g,{[p]:"",ref:I,children:N})});v.displayName=m;function b(){return d.useState(new dm)}nn(b,"useInitCollection");function j(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return nn(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:v},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}nn(bM,"createCollection");function GC(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}nn(GC,"shallowEqual");function YC(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}nn(YC,"isElementPreceding");function ug(e,t){return!e[1].element||!t[1].element?0:YC(e[1].element,t[1].element)?-1:1}nn(ug,"sortByDocumentPosition");function qC(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}nn(qC,"getChildListObserver");var kM=Object.defineProperty,NM=(e,t)=>kM(e,"name",{value:t,configurable:!0}),SM=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],gt=SM.reduce((e,t)=>{const s=wi(`Primitive.${t}`),r=d.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function _h(e,t){e&&Pl.flushSync(()=>e.dispatchEvent(t))}NM(_h,"dispatchDiscreteCustomEvent");var CM=Object.defineProperty,EM=(e,t)=>CM(e,"name",{value:t,configurable:!0});function An(e){const t=d.useRef(e);return d.useEffect(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}EM(An,"useCallbackRef");var AM=Object.defineProperty,qt=(e,t)=>AM(e,"name",{value:t,configurable:!0}),dg="dismissableLayer.update",TM="dismissableLayer.pointerDownOutside",$M="dismissableLayer.focusOutside",Rb,_v=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),zh=d.forwardRef(qt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=t,f=d.useContext(_v),[m,p]=d.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,v]=d.useState({}),b=wt(s,p),j=Array.from(f.layers),[x]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=x?j.indexOf(x):-1,y=m?j.indexOf(m):-1,k=f.layersWithOutsidePointerEventsDisabled.size>0,N=y>=w,S=d.useRef(!1),C=QC(L=>{l==null||l(L),c==null||c(L),L.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(L=>{if(!(L instanceof Node))return!1;const W=[...f.branches].some($=>$.contains(L));return N&&!W},[f.branches,N])}),T=XC(L=>{if(i&&S.current)return;const W=L.target;[...f.branches].some(P=>P.contains(W))||(o==null||o(L),c==null||c(L),L.defaultPrevented||u==null||u())},g),R=m?y===j.length-1:!1,I=An(L=>{L.key==="Escape"&&(a==null||a(L),!L.defaultPrevented&&u&&(L.preventDefault(),u()))});return d.useEffect(()=>{if(R)return g.addEventListener("keydown",I,{capture:!0}),()=>g.removeEventListener("keydown",I,{capture:!0})},[g,R,I]),d.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Rb=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),hg(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Rb))}},[m,g,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),hg())},[m,f]),d.useEffect(()=>{const L=qt(()=>v({}),"handleUpdate");return document.addEventListener(dg,L),()=>document.removeEventListener(dg,L)},[]),n.jsx(gt.div,{...h,ref:b,style:{pointerEvents:k?N?"auto":"none":void 0,...t.style},onFocusCapture:Me(t.onFocusCapture,T.onFocusCapture),onBlurCapture:Me(t.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Me(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),RM=d.forwardRef(qt(function(t,s){const r=d.useContext(_v),i=d.useRef(null),a=wt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(gt.div,{...t,ref:a})},"DismissableLayerBranch"));function JC(){const e=d.useContext(_v),[t,s]=d.useState(null);return d.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}qt(JC,"useDismissableLayerSurface");var IM=qt(()=>!0,"IS_TRUE");function QC(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=IM}=t,o=An(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),f=d.useRef(()=>{});return d.useEffect(()=>{function m(){u.current=!1,i.current=!1,h.current.clear()}qt(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}qt(p,"isOutsideInteractionIntercepted");function g(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...a].some(N=>N.contains(y))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}qt(g,"handleInteractionCapture");function v(w){u.current&&h.current.set(w.type,!1)}qt(v,"handleInteractionBubble");const b=qt(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",f.current);const N=p();m(),N||zv(TM,o,k,{discrete:!0})};if(qt(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const k={originalEvent:w};u.current=!0,i.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?y():(s.removeEventListener("click",f.current),f.current=y,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),m();c.current=!1},"handlePointerDown"),j=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of j)s.addEventListener(w,g,!0),s.addEventListener(w,v);const x=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(x),s.removeEventListener("pointerdown",b),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,g,!0),s.removeEventListener(w,v)}},[s,o,r,i,a,l]),{onPointerDownCapture:qt(()=>c.current=!0,"onPointerDownCapture")}}qt(QC,"usePointerDownOutside");function XC(e,t=globalThis==null?void 0:globalThis.document){const s=An(e),r=d.useRef(!1);return d.useEffect(()=>{const i=qt(a=>{a.target&&!r.current&&zv($M,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:qt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:qt(()=>r.current=!1,"onBlurCapture")}}qt(XC,"useFocusOutside");function hg(){const e=new CustomEvent(dg);document.dispatchEvent(e)}qt(hg,"dispatchUpdate");function zv(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?_h(i,a):i.dispatchEvent(a)}qt(zv,"handleAndDispatchCustomEvent");var PM=zh,MM=RM,Wn=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},DM=Object.defineProperty,OM=(e,t)=>DM(e,"name",{value:t,configurable:!0}),Uh=d.forwardRef(OM(function(t,s){var c;const{container:r,...i}=t,[a,l]=d.useState(!1);Wn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?Pl.createPortal(n.jsx(gt.div,{...i,ref:s}),o):null},"Portal")),LM=Object.defineProperty,Br=(e,t)=>LM(e,"name",{value:t,configurable:!0});function ZC(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}Br(ZC,"useStateMachine");var gr=Br(e=>{const{present:t,children:s}=e,r=e1(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=t1(r.ref,n1(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null},"Presence");function e1(e){const[t,s]=d.useState(),r=d.useRef(null),i=d.useRef(e),a=d.useRef("none"),l=d.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=ZC(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{c==="mounted"?(a.current=l.current??Da(r.current),l.current=void 0):a.current="none"},[c]),Wn(()=>{const h=r.current,f=i.current;if(f!==e){const p=a.current,g=Da(h);e?(l.current=g,u("MOUNT")):g==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Wn(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=Br(g=>{const b=Da(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(u("ANIMATION_END"),!i.current)){const j=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},"handleAnimationEnd"),p=Br(g=>{g.target===t&&(a.current=Da(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=Da(f)}else r.current=null;s(h)},[])}}Br(e1,"usePresence");function fg(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Br(fg,"setRef");function t1(...e){const t=d.useRef(e);return t.current=e,d.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=fg(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():fg(r[l],null)}}},[])}Br(t1,"useStableComposedRefs");function Da(e){return(e==null?void 0:e.animationName)||"none"}Br(Da,"getAnimationName");function n1(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)}Br(n1,"getElementRef");var FM=Object.defineProperty,_M=(e,t)=>FM(e,"name",{value:t,configurable:!0}),Ib=$l[" useEffectEvent ".trim().toString()],Pb=$l[" useInsertionEffect ".trim().toString()];function s1(e){if(typeof Ib=="function")return Ib(e);const t=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof Pb=="function"?Pb(()=>{t.current=e}):Wn(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}_M(s1,"useEffectEvent");var zM=Object.defineProperty,Rc=(e,t)=>zM(e,"name",{value:t,configurable:!0}),UM=$l[" useInsertionEffect ".trim().toString()]||Wn;function $i({prop:e,defaultProp:t,onChange:s=Rc(()=>{},"onChange"),caller:r}){const[i,a,l]=r1({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=d.useCallback(h=>{var f;if(o){const m=i1(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}Rc($i,"useControllableState");function r1({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return UM(()=>{a.current=t},[t]),d.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}Rc(r1,"useUncontrolledState");function i1(e){return typeof e=="function"}Rc(i1,"isFunction");var Mb=Symbol("RADIX:SYNC_STATE");function BM(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=s1(l),h=[{...s,state:a}];r&&h.push(r);const[f,m]=d.useReducer((b,j)=>{if(j.type===Mb)return{...b,state:j.state};const x=e(b,j);return c&&!Object.is(x.state,b.state)&&u(x.state),x},...h),p=f.state,g=d.useRef(p);d.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const v=d.useMemo(()=>i!==void 0?{...f,state:i}:f,[f,i]);return d.useEffect(()=>{c&&!Object.is(i,f.state)&&m({type:Mb,state:i})},[i,f.state,c]),[v,m]}Rc(BM,"useControllableStateReducer");var WM=Object.defineProperty,HM=(e,t)=>WM(e,"name",{value:t,configurable:!0}),KM=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"}),Uv=d.forwardRef(HM(function(t,s){return n.jsx(gt.span,{...t,ref:s,style:{...KM,...t.style}})},"VisuallyHidden")),VM=Uv,GM=Object.defineProperty,vt=(e,t)=>GM(e,"name",{value:t,configurable:!0}),a1="ToastProvider",[Bv,l1,YM]=Fh("Toast"),[o1,uX]=Ws("Toast",[YM]),[qM,Bh]=o1(a1),JM=vt(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=d.useState(null),[h,f]=d.useState(0),m=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${a1}\`. Expected non-empty \`string\`.`),n.jsx(Bv.Provider,{scope:t,children:n.jsx(qM,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>f(p=>p+1),[]),onToastRemove:d.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),QM="ToastViewport",XM=["F8"],mg="toast.viewportPause",pg="toast.viewportResume",ZM=d.forwardRef(vt(function(t,s){const{__scopeToast:r,hotkey:i=XM,label:a="Notifications ({hotkey})",...l}=t,o=Bh(QM,r),c=l1(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=wt(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=o.toastCount>0;d.useEffect(()=>{const j=vt(x=>{var y;i.length!==0&&i.every(k=>x[k]||x.code===k)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[i]),d.useEffect(()=>{const j=u.current,x=m.current;if(v&&j&&x){const w=vt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(mg);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=vt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(pg);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),k=vt(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),N=vt(()=>{j.contains(document.activeElement)||y()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",k),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",N),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",k),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",N),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[v,o.isClosePausedRef]);const b=d.useCallback(({tabbingDirection:j})=>{const w=c().map(y=>{const k=y.ref.current,N=[k,...h1(k)];return j==="forwards"?N:N.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return d.useEffect(()=>{const j=m.current;if(j){const x=vt(w=>{var N,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const T=document.activeElement,R=w.shiftKey;if(w.target===j&&R){(N=h.current)==null||N.focus();return}const W=b({tabbingDirection:R?"backwards":"forwards"}),$=W.findIndex(P=>P===T);id(W.slice($+1))?w.preventDefault():R?(S=h.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",x),()=>j.removeEventListener("keydown",x)}},[c,b]),n.jsxs(MM,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&n.jsx(Db,{ref:h,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});id(j)}}),n.jsx(Bv.Slot,{scope:r,children:n.jsx(gt.ol,{tabIndex:-1,...l,ref:p})}),v&&n.jsx(Db,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});id(j)}})]})},"ToastViewport")),eD="ToastFocusProxy",Db=d.forwardRef(vt(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=Bh(eD,r);return n.jsx(Uv,{tabIndex:0,...a,ref:s,style:{position:"fixed"},onFocus:o=>{var h;const c=o.relatedTarget;!((h=l.viewport)!=null&&h.contains(c))&&i()}})},"ToastFocusProxy")),Wh="Toast",tD="toast.swipeStart",nD="toast.swipeMove",sD="toast.swipeCancel",rD="toast.swipeEnd",iD=d.forwardRef(vt(function(t,s){const{forceMount:r,open:i,defaultOpen:a,onOpenChange:l,...o}=t,[c,u]=$i({prop:i,defaultProp:a??!0,onChange:l,caller:Wh});return n.jsx(gr,{present:r||c,children:n.jsx(oD,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:An(t.onPause),onResume:An(t.onResume),onSwipeStart:Me(t.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Me(t.onSwipeMove,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:Me(t.onSwipeCancel,h=>{h.currentTarget.setAttribute("data-swipe","cancel"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Me(t.onSwipeEnd,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","end"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[aD,lD]=o1(Wh,{onClose(){}}),oD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,type:i="foreground",duration:a,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...v}=t,b=Bh(Wh,r),j=l1(r),[x,w]=d.useState(null),y=wt(s,w),k=d.useRef(null),N=d.useRef(null),S=a||b.duration,C=d.useRef(0),T=d.useRef(S),R=d.useRef(0),{onToastAdd:I,onToastRemove:L}=b,W=An(()=>{var M;(x==null?void 0:x.contains(document.activeElement))&&((M=b.viewport)==null||M.focus()),o()}),$=d.useCallback(O=>{!O||O===1/0||(window.clearTimeout(R.current),C.current=new Date().getTime(),R.current=window.setTimeout(W,O))},[W]);d.useEffect(()=>{const O=b.viewport;if(O){const M=vt(()=>{$(T.current),h==null||h()},"handleResume"),D=vt(()=>{const H=new Date().getTime()-C.current;T.current=T.current-H,window.clearTimeout(R.current),u==null||u()},"handlePause");return O.addEventListener(mg,D),O.addEventListener(pg,M),()=>{O.removeEventListener(mg,D),O.removeEventListener(pg,M)}}},[b.viewport,S,u,h,$]),d.useEffect(()=>{l&&!b.isClosePausedRef.current&&$(S)},[l,S,b.isClosePausedRef,$]),d.useEffect(()=>()=>{window.clearTimeout(R.current)},[]),d.useEffect(()=>(I(),()=>L()),[I,L]);const P=d.useMemo(()=>x?Wv(x):null,[x]);return b.viewport?n.jsxs(n.Fragment,{children:[P&&n.jsx(cD,{__scopeToast:r,role:"status","aria-live":i==="foreground"?"assertive":"polite",children:P}),n.jsx(aD,{scope:r,onClose:W,children:Pl.createPortal(n.jsx(Bv.ItemSlot,{scope:r,children:n.jsx(PM,{asChild:!0,onEscapeKeyDown:Me(c,O=>{j().some(D=>{var H;return(H=D.ref.current)==null?void 0:H.contains(O.target)})||W()}),children:n.jsx(gt.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":b.swipeDirection,...v,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:Me(t.onKeyDown,O=>{O.key==="Escape"&&(c==null||c(O.nativeEvent),O.nativeEvent.defaultPrevented||W())}),onPointerDown:Me(t.onPointerDown,O=>{O.button===0&&(k.current={x:O.clientX,y:O.clientY})}),onPointerMove:Me(t.onPointerMove,O=>{if(!k.current)return;const M=O.clientX-k.current.x,D=O.clientY-k.current.y,H=!!N.current,U=["left","right"].includes(b.swipeDirection),q=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,B=U?q(0,M):0,Y=U?0:q(0,D),F=O.pointerType==="touch"?10:2,X={x:B,y:Y},Q={originalEvent:O,delta:X};H?(N.current=X,bo(nD,m,Q,{discrete:!1})):Ob(X,b.swipeDirection,F)?(N.current=X,bo(tD,f,Q,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(M)>F||Math.abs(D)>F)&&(k.current=null)}),onPointerUp:Me(t.onPointerUp,O=>{const M=N.current,D=O.target;if(D.hasPointerCapture(O.pointerId)&&D.releasePointerCapture(O.pointerId),N.current=null,k.current=null,M){const H=O.currentTarget,U={originalEvent:O,delta:M};Ob(M,b.swipeDirection,b.swipeThreshold)?bo(rD,g,U,{discrete:!0}):bo(sD,p,U,{discrete:!0}),H.addEventListener("click",q=>q.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),cD=vt(e=>{const{__scopeToast:t,children:s,...r}=e,i=Bh(Wh,t),[a,l]=d.useState(!1),[o,c]=d.useState(!1);return u1(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:n.jsx(Uh,{asChild:!0,container:i.announcerContainer||void 0,children:n.jsx(Uv,{...r,children:a&&n.jsxs(n.Fragment,{children:[i.label," ",s]})})})},"ToastAnnounce"),uD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"ToastTitle")),dD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"ToastDescription")),hD="ToastAction",fD=d.forwardRef(vt(function(t,s){const{altText:r,...i}=t;return r.trim()?n.jsx(c1,{altText:r,asChild:!0,children:n.jsx(pD,{...i,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${hD}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),mD="ToastClose",pD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t,a=lD(mD,r);return n.jsx(c1,{asChild:!0,children:n.jsx(gt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,a.onClose)})})},"ToastClose")),c1=d.forwardRef(vt(function(t,s){const{__scopeToast:r,altText:i,...a}=t;return n.jsx(gt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":i||void 0,...a,ref:s})},"ToastAnnounceExclude"));function Wv(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),d1(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(...Wv(r))}}),t}vt(Wv,"getAnnounceTextContent");function bo(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?_h(i,a):i.dispatchEvent(a)}vt(bo,"handleAndDispatchCustomEvent");var Ob=vt((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 u1(e=()=>{}){const t=An(e);Wn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}vt(u1,"useNextFrame");function d1(e){return e.nodeType===e.ELEMENT_NODE}vt(d1,"isHTMLElement");function h1(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:vt(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}vt(h1,"getTabbableCandidates");function id(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}vt(id,"focusFirst");var Lb=JM,Fb=ZM,gD=iD,xD=uD,vD=dD,jD=fD,wD=Object.defineProperty,yD=(e,t)=>wD(e,"name",{value:t,configurable:!0}),bD=$l[" useId ".trim().toString()]||(()=>{}),kD=0;function Ls(e){const[t,s]=d.useState(bD());return Wn(()=>{e||s(r=>r??String(kD++))},[e]),e||(t?`radix-${t}`:"")}yD(Ls,"useId");const ND=["top","right","bottom","left"],yi=Math.min,Pr=Math.max,Wd=Math.round,yu=Math.floor,Mr=e=>({x:e,y:e}),SD={left:"right",right:"left",bottom:"top",top:"bottom"};function f1(e,t,s){return Pr(e,yi(t,s))}function Wr(e,t){return typeof e=="function"?e(t):e}function bi(e){return e.split("-")[0]}function Dl(e){return e.split("-")[1]}function Hv(e){return e==="x"?"y":"x"}function Kv(e){return e==="y"?"height":"width"}function rr(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Vv(e){return Hv(rr(e))}function CD(e,t,s){s===void 0&&(s=!1);const r=Dl(e),i=Vv(e),a=Kv(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Hd(l)),[l,Hd(l)]}function ED(e){const t=Hd(e);return[gg(e),t,gg(t)]}function gg(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const _b=["left","right"],zb=["right","left"],AD=["top","bottom"],TD=["bottom","top"];function $D(e,t,s){switch(e){case"top":case"bottom":return s?t?zb:_b:t?_b:zb;case"left":case"right":return t?AD:TD;default:return[]}}function RD(e,t,s,r){const i=Dl(e);let a=$D(bi(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(gg)))),a}function Hd(e){const t=bi(e);return SD[t]+e.slice(t.length)}function ID(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 m1(e){return typeof e!="number"?ID(e):{top:e,right:e,bottom:e,left:e}}function Kd(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 Ub(e,t,s){let{reference:r,floating:i}=e;const a=rr(t),l=Vv(t),o=Kv(l),c=bi(t),u=a==="y",h=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-i.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-i.width,y:f};break;default:p={x:r.x,y:r.y}}const g=Dl(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function PD(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=Wr(t,e),g=m1(p),b=o[m?f==="floating"?"reference":"floating":f],j=Kd(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),x=f==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),y=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},k=Kd(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:x,offsetParent:w,strategy:c}):x);return{top:(j.top-k.top+g.top)/y.y,bottom:(k.bottom-j.bottom+g.bottom)/y.y,left:(j.left-k.left+g.left)/y.x,right:(k.right-j.right+g.right)/y.x}}const MD=50,DD=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:PD},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:f}=Ub(u,r,c),m=r,p=0;const g={};for(let v=0;v<a.length;v++){const b=a[v];if(!b)continue;const{name:j,fn:x}=b,{x:w,y,data:k,reset:N}=await x({x:h,y:f,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});h=w??h,f=y??f,g[j]={...g[j],...k},N&&p<MD&&(p++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(u=N.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:h,y:f}=Ub(u,m,c)),v=-1)}return{x:h,y:f,placement:m,strategy:i,middlewareData:g}},OD=e=>({name:"arrow",options:e,async fn(t){const{x:s,y:r,placement:i,rects:a,platform:l,elements:o,middlewareData:c}=t,{element:u,padding:h=0}=Wr(e,t)||{};if(u==null)return{};const f=m1(h),m={x:s,y:r},p=Vv(i),g=Kv(p),v=await l.getDimensions(u),b=p==="y",j=b?"top":"left",x=b?"bottom":"right",w=b?"clientHeight":"clientWidth",y=a.reference[g]+a.reference[p]-m[p]-a.floating[g],k=m[p]-a.reference[p],N=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=N?N[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(N)))&&(S=o.floating[w]||a.floating[g]);const C=y/2-k/2,T=S/2-v[g]/2-1,R=yi(f[j],T),I=yi(f[x],T),L=S-v[g]-I,W=S/2-v[g]/2+C,$=f1(R,W,L),P=!c.arrow&&Dl(i)!=null&&W!==$&&a.reference[g]/2-(W<R?R:I)-v[g]/2<0,O=P?W<R?W-R:W-L:0;return{[p]:m[p]+O,data:{[p]:$,centerOffset:W-$-O,...P&&{alignmentOffset:O}},reset:P}}}),LD=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:v=!0,...b}=Wr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const j=bi(i),x=rr(o),w=bi(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),k=m||(w||!v?[Hd(o)]:ED(o)),N=g!=="none";!m&&N&&k.push(...RD(o,v,g,y));const S=[o,...k],C=await c.detectOverflow(t,b),T=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&T.push(C[j]),f){const $=CD(i,l,y);T.push(C[$[0]],C[$[1]])}if(R=[...R,{placement:i,overflows:T}],!T.every($=>$<=0)){var I,L;const $=(((I=a.flip)==null?void 0:I.index)||0)+1,P=S[$];if(P&&(!(f==="alignment"?x!==rr(P):!1)||R.every(D=>rr(D.placement)===x?D.overflows[0]>0:!0)))return{data:{index:$,overflows:R},reset:{placement:P}};let O=(L=R.filter(M=>M.overflows[0]<=0).sort((M,D)=>M.overflows[1]-D.overflows[1])[0])==null?void 0:L.placement;if(!O)switch(p){case"bestFit":{var W;const M=(W=R.filter(D=>{if(N){const H=rr(D.placement);return H===x||H==="y"}return!0}).map(D=>[D.placement,D.overflows.filter(H=>H>0).reduce((H,U)=>H+U,0)]).sort((D,H)=>D[1]-H[1])[0])==null?void 0:W[0];M&&(O=M);break}case"initialPlacement":O=o;break}if(i!==O)return{reset:{placement:O}}}return{}}}};function Bb(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Wb(e){return ND.some(t=>e[t]>=0)}const FD=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=Wr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=Bb(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:Wb(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=Bb(l,s.floating);return{data:{escapedOffsets:o,escaped:Wb(o)}}}default:return{}}}}},p1=new Set(["left","top"]);async function _D(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=bi(s),o=Dl(s),c=rr(s)==="y",u=p1.has(l)?-1:1,h=a&&c?-1:1,f=Wr(t,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof g=="number"&&(p=o==="end"?g*-1:g),c?{x:p*h,y:m*u}:{x:m*u,y:p*h}}const zD=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 _D(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}}}}},UD=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:x=>{let{x:w,y}=x;return{x:w,y}}},...u}=Wr(e,t),h={x:s,y:r},f=await a.detectOverflow(t,u),m=rr(i),p=Hv(m);let g=h[p],v=h[m];const b=(x,w)=>f1(w+f[x==="y"?"top":"left"],w,w-f[x==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(v=b(m,v));const j=c.fn({...t,[p]:g,[m]:v});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},BD=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:h=!0,crossAxis:f=!0}=Wr(e,t),m={x:i,y:a},p=rr(l),g=Hv(p);let v=m[g],b=m[p];const j=Wr(u,t),x=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){const k=g==="y"?"height":"width",N=o.reference[g]-o.floating[k]+x.mainAxis,S=o.reference[g]+o.reference[k]-x.mainAxis;v<N?v=N:v>S&&(v=S)}if(f){var w,y;const k=g==="y"?"width":"height",N=p1.has(bi(l)),S=o.reference[p]-o.floating[k]+(N&&((w=c.offset)==null?void 0:w[p])||0)+(N?0:x.crossAxis),C=o.reference[p]+o.reference[k]+(N?0:((y=c.offset)==null?void 0:y[p])||0)-(N?x.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[g]:v,[p]:b}}}},WD=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}=Wr(e,t),c=await i.detectOverflow(t,o),u=bi(s),h=Dl(s),f=rr(s)==="y",{width:m,height:p}=r.floating;let g,v;u==="top"||u==="bottom"?(g=u,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=u,g=h==="end"?"top":"bottom");const b=p-c.top-c.bottom,j=m-c.left-c.right,x=yi(p-c[g],b),w=yi(m-c[v],j),y=t.middlewareData.shift,k=!y;let N=x,S=w;y!=null&&y.enabled.x&&(S=j),y!=null&&y.enabled.y&&(N=b),k&&!h&&(f?S=m-2*Pr(c.left,c.right):N=p-2*Pr(c.top,c.bottom)),await l({...t,availableWidth:S,availableHeight:N});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Hh(){return typeof window<"u"}function Ol(e){return g1(e)?(e.nodeName||"").toLowerCase():"#document"}function Hn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Yr(e){var t;return(t=(g1(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function g1(e){return Hh()?e instanceof Node||e instanceof Hn(e).Node:!1}function cr(e){return Hh()?e instanceof Element||e instanceof Hn(e).Element:!1}function Ri(e){return Hh()?e instanceof HTMLElement||e instanceof Hn(e).HTMLElement:!1}function Hb(e){return!Hh()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Hn(e).ShadowRoot}function Kh(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=ur(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function HD(e){return/^(table|td|th)$/.test(Ol(e))}function Vh(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const KD=/transform|translate|scale|rotate|perspective|filter/,VD=/paint|layout|strict|content/,_i=e=>!!e&&e!=="none";let hm;function Gv(e){const t=cr(e)?ur(e):e;return _i(t.transform)||_i(t.translate)||_i(t.scale)||_i(t.rotate)||_i(t.perspective)||!Yv()&&(_i(t.backdropFilter)||_i(t.filter))||KD.test(t.willChange||"")||VD.test(t.contain||"")}function GD(e){let t=la(e);for(;Ri(t)&&!sc(t);){if(Gv(t))return t;if(Vh(t))return null;t=la(t)}return null}function Yv(){return hm==null&&(hm=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),hm}function sc(e){return/^(html|body|#document)$/.test(Ol(e))}function ur(e){return Hn(e).getComputedStyle(e)}function Gh(e){return cr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function la(e){if(Ol(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Hb(e)&&e.host||Yr(e);return Hb(t)?t.host:t}function x1(e){const t=la(e);return sc(t)?(e.ownerDocument||e).body:Ri(t)&&Kh(t)?t:x1(t)}function rc(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=x1(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Hn(i);if(a){const o=xg(l);return t.concat(l,l.visualViewport||[],Kh(i)?i:[],o&&s?rc(o):[])}else return t.concat(i,rc(i,[],s))}function xg(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function v1(e){const t=ur(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ri(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Wd(s)!==a||Wd(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function qv(e){return cr(e)?e:e.contextElement}function rl(e){const t=qv(e);if(!Ri(t))return Mr(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=v1(t);let l=(a?Wd(s.width):s.width)/r,o=(a?Wd(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const YD=Mr(0);function j1(e){const t=Hn(e);return!Yv()||!t.visualViewport?YD:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function qD(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Hn(e)}function oa(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=qv(e);let l=Mr(1);t&&(r?cr(r)&&(l=rl(r)):l=rl(e));const o=qD(a,s,r)?j1(a):Mr(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,h=i.width/l.x,f=i.height/l.y;if(a&&r){const m=Hn(a),p=cr(r)?Hn(r):r;let g=m,v=xg(g);for(;v&&p!==g;){const b=rl(v),j=v.getBoundingClientRect(),x=ur(v),w=j.left+(v.clientLeft+parseFloat(x.paddingLeft))*b.x,y=j.top+(v.clientTop+parseFloat(x.paddingTop))*b.y;c*=b.x,u*=b.y,h*=b.x,f*=b.y,c+=w,u+=y,g=Hn(v),v=xg(g)}}return Kd({width:h,height:f,x:c,y:u})}function Yh(e,t){const s=Gh(e).scrollLeft;return t?t.left+s:oa(Yr(e)).left+s}function w1(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-Yh(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function JD(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=Yr(r),o=t?Vh(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=Mr(1);const h=Mr(0),f=Ri(r);if((f||!a)&&((Ol(r)!=="body"||Kh(l))&&(c=Gh(r)),f)){const p=oa(r);u=rl(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!a?w1(l,c):Mr(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:s.y*u.y-c.scrollTop*u.y+h.y+m.y}}function QD(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function XD(e){const t=Gh(e),s=e.ownerDocument.body,r=Pr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=Pr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+Yh(e);const l=-t.scrollTop;return ur(s).direction==="rtl"&&(a+=Pr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const ZD=25;function eO(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Hn(e),a=Yr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!Yv()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(Yh(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),v=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-v),j=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;j<=ZD&&(o-=j)}return{width:o,height:c,x:u,y:h}}function tO(e,t){const s=oa(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=rl(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 Kb(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=eO(e,s,t);else if(t==="document")r=XD(Yr(e));else if(cr(t))r=tO(t,s);else{const i=j1(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Kd(r)}function nO(e,t){const s=t.get(e);if(s)return s;let r=rc(e,[],!1).filter(o=>cr(o)&&Ol(o)!=="body"),i=null;const a=ur(e).position==="fixed";let l=a?la(e):e;for(;cr(l)&&!sc(l);){const o=ur(l),c=Gv(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):i=o,l=la(l)}return t.set(e,r),r}function sO(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?Vh(t)?[]:nO(t,this._c):[].concat(s),r],o=Kb(t,l[0],i);let c=o.top,u=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=Kb(t,l[m],i);c=Pr(p.top,c),u=yi(p.right,u),h=yi(p.bottom,h),f=Pr(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function rO(e){const{width:t,height:s}=v1(e);return{width:t,height:s}}function iO(e,t,s){const r=Ri(t),i=Yr(t),a=s==="fixed",l=oa(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=Mr(0);if((r||!a)&&((Ol(t)!=="body"||Kh(i))&&(o=Gh(t)),r)){const m=oa(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=Yh(i));const u=i&&!r&&!a?w1(i,o):Mr(0),h=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:h,y:f,width:l.width,height:l.height}}function fm(e){return ur(e).position==="static"}function Vb(e,t){if(!Ri(e)||ur(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return Yr(e)===s&&(s=s.ownerDocument.body),s}function y1(e,t){const s=Hn(e);if(Vh(e))return s;if(!Ri(e)){let i=la(e);for(;i&&!sc(i);){if(cr(i)&&!fm(i))return i;i=la(i)}return s}let r=Vb(e,t);for(;r&&HD(r)&&fm(r);)r=Vb(r,t);return r&&sc(r)&&fm(r)&&!Gv(r)?s:r||GD(e)||s}const aO=async function(e){const t=this.getOffsetParent||y1,s=this.getDimensions,r=await s(e.floating);return{reference:iO(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function lO(e){return ur(e).direction==="rtl"}const oO={convertOffsetParentRelativeRectToViewportRelativeRect:JD,getDocumentElement:Yr,getClippingRect:sO,getOffsetParent:y1,getElementRects:aO,getClientRects:QD,getDimensions:rO,getScale:rl,isElement:cr,isRTL:lO};function b1(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function cO(e,t,s){let r=null,i;const a=Yr(e);function l(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function o(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:v,height:b}=m;if(h||t(),!v||!b)return;const j=yu(g),x=yu(a.clientWidth-(p+v)),w=yu(a.clientHeight-(g+b)),y=yu(p),N={rootMargin:-j+"px "+-x+"px "+-w+"px "+-y+"px",threshold:Pr(0,yi(1,f))||1};let S=!0;function C(T){const R=T[0].intersectionRatio;if(!b1(m,e.getBoundingClientRect()))return o();if(R!==f){if(!S)return o();R?o(!1,R):i=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...N,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,N)}r.observe(e)}const c=Hn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function uO(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=qv(e),h=i||a?[...u?rc(u):[],...t?rc(t):[]]:[];h.forEach(j=>{i&&j.addEventListener("scroll",s),a&&j.addEventListener("resize",s)});const f=u&&o?cO(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[x]=j;x&&x.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,v=c?oa(e):null;c&&b();function b(){const j=oa(e);v&&!b1(v,j)&&s(),v=j,g=requestAnimationFrame(b)}return s(),()=>{var j;h.forEach(x=>{i&&x.removeEventListener("scroll",s),a&&x.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const dO=zD,hO=UD,fO=LD,mO=WD,pO=FD,Gb=OD,gO=BD,xO=(e,t,s)=>{const r=new Map,i=s??{},a={...oO,...i.platform,_c:r};return DD(e,t,{...i,platform:a})};var vO=typeof document<"u",jO=function(){},ad=vO?d.useLayoutEffect:jO;function Vd(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(!Vd(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)&&!Vd(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function k1(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yb(e,t){const s=k1(e);return Math.round(t*s)/s}function mm(e){const t=d.useRef(e);return ad(()=>{t.current=e}),t}function wO(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,f]=d.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=d.useState(r);Vd(m,r)||p(r);const[g,v]=d.useState(null),[b,j]=d.useState(null),x=d.useCallback(D=>{D!==N.current&&(N.current=D,v(D))},[]),w=d.useCallback(D=>{D!==S.current&&(S.current=D,j(D))},[]),y=a||g,k=l||b,N=d.useRef(null),S=d.useRef(null),C=d.useRef(h),T=c!=null,R=mm(c),I=mm(i),L=mm(u),W=d.useCallback(()=>{if(!N.current||!S.current)return;const D={placement:t,strategy:s,middleware:m};I.current&&(D.platform=I.current),xO(N.current,S.current,D).then(H=>{const U={...H,isPositioned:L.current!==!1};$.current&&!Vd(C.current,U)&&(C.current=U,Pl.flushSync(()=>{f(U)}))})},[m,t,s,I,L]);ad(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(D=>({...D,isPositioned:!1})))},[u]);const $=d.useRef(!1);ad(()=>($.current=!0,()=>{$.current=!1}),[]),ad(()=>{if(y&&(N.current=y),k&&(S.current=k),y&&k){if(R.current)return R.current(y,k,W);W()}},[y,k,W,R,T]);const P=d.useMemo(()=>({reference:N,floating:S,setReference:x,setFloating:w}),[x,w]),O=d.useMemo(()=>({reference:y,floating:k}),[y,k]),M=d.useMemo(()=>{const D={position:s,left:0,top:0};if(!O.floating)return D;const H=Yb(O.floating,h.x),U=Yb(O.floating,h.y);return o?{...D,transform:"translate("+H+"px, "+U+"px)",...k1(O.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:H,top:U}},[s,o,O.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:W,refs:P,elements:O,floatingStyles:M}),[h,W,P,O,M])}const yO=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?Gb({element:r.current,padding:i}).fn(s):{}:r?Gb({element:r,padding:i}).fn(s):{}}}},bO=(e,t)=>{const s=dO(e);return{name:s.name,fn:s.fn,options:[e,t]}},kO=(e,t)=>{const s=hO(e);return{name:s.name,fn:s.fn,options:[e,t]}},NO=(e,t)=>({fn:gO(e).fn,options:[e,t]}),SO=(e,t)=>{const s=fO(e);return{name:s.name,fn:s.fn,options:[e,t]}},CO=(e,t)=>{const s=mO(e);return{name:s.name,fn:s.fn,options:[e,t]}},EO=(e,t)=>{const s=pO(e);return{name:s.name,fn:s.fn,options:[e,t]}},AO=(e,t)=>{const s=yO(e);return{name:s.name,fn:s.fn,options:[e,t]}};var TO=Object.defineProperty,$O=(e,t)=>TO(e,"name",{value:t,configurable:!0});function N1(e){const[t,s]=d.useState(void 0);return Wn(()=>{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}$O(N1,"useSize");var RO=Object.defineProperty,pi=(e,t)=>RO(e,"name",{value:t,configurable:!0}),S1="Popper",[C1,qh]=Ws(S1),[IO,E1]=C1(S1),PO=pi(e=>{const{__scopePopper:t,children:s}=e,[r,i]=d.useState(null),[a,l]=d.useState(void 0);return n.jsx(IO,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),MO="PopperAnchor",DO=d.forwardRef(pi(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=E1(MO,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(v=>{o.current=v,v&&c(v)},[c]),h=wt(s,u),f=d.useRef(null);d.useEffect(()=>{if(!i)return;const v=f.current;f.current=i.current,v!==f.current&&c(f.current)});const m=l.placementState&&Jh(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(gt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:h})},"PopperAnchor")),A1="PopperContent",[OO,dX]=C1(A1),LO=d.forwardRef(pi(function(t,s){var Oe,Ie,Fe,z,ne,J,ye;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:v,...b}=t,j=E1(A1,r),[x,w]=d.useState(null),y=wt(s,w),[k,N]=d.useState(null),S=N1(k),C=(S==null?void 0:S.width)??0,T=(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},L=Array.isArray(h)?h:[h],W=L.length>0,$={padding:I,boundary:L.filter(T1),altBoundary:W},{refs:P,floatingStyles:O,placement:M,isPositioned:D,middlewareData:H}=wO({strategy:"fixed",placement:R,whileElementsMounted:pi((...ge)=>uO(...ge,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[bO({mainAxis:a+T,alignmentAxis:o}),u&&kO({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?NO():void 0,...$}),u&&SO({...$}),CO({...$,apply:pi(({elements:ge,rects:$e,availableWidth:De,availableHeight:Je})=>{const{width:ze,height:Ne}=$e.reference,Ue=ge.floating.style;Ue.setProperty("--radix-popper-available-width",`${De}px`),Ue.setProperty("--radix-popper-available-height",`${Je}px`),Ue.setProperty("--radix-popper-anchor-width",`${ze}px`),Ue.setProperty("--radix-popper-anchor-height",`${Ne}px`)},"apply")}),k&&AO({element:k,padding:c}),FO({arrowWidth:C,arrowHeight:T}),p&&EO({strategy:"referenceHidden",...$,boundary:W?$.boundary:void 0})]}),U=j.setPlacementState;Wn(()=>(U(M),()=>{U(void 0)}),[M,U]);const[q,B]=Jh(M),Y=An(v);Wn(()=>{D&&(Y==null||Y())},[D,Y]);const F=(Oe=H.arrow)==null?void 0:Oe.x,X=(Ie=H.arrow)==null?void 0:Ie.y,Q=((Fe=H.arrow)==null?void 0:Fe.centerOffset)!==0,[ee,fe]=d.useState();return Wn(()=>{x&&fe(window.getComputedStyle(x).zIndex)},[x]),n.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...O,transform:D?O.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(z=H.transformOrigin)==null?void 0:z.x,(ne=H.transformOrigin)==null?void 0:ne.y].join(" "),...((J=H.hide)==null?void 0:J.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(OO,{scope:r,placedSide:q,placedAlign:B,onArrowChange:N,arrowX:F,arrowY:X,shouldHideArrow:Q,children:n.jsx(gt.div,{"data-side":q,"data-align":B,...b,ref:y,style:{...b.style,animation:D?(ye=b.style)==null?void 0:ye.animation:"none"}})})})},"PopperContent"));function T1(e){return e!==null}pi(T1,"isNotNull");var FO=pi(e=>({name:"transformOrigin",options:e,fn(t){var b,j,x;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=Jh(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=i.arrow)==null?void 0:j.x)??0)+o/2,p=(((x=i.arrow)==null?void 0:x.y)??0)+c/2;let g="",v="";return u==="bottom"?(g=l?f:`${m}px`,v=`${-c}px`):u==="top"?(g=l?f:`${m}px`,v=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,v=l?f:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,v=l?f:`${p}px`),{data:{x:g,y:v}}}}),"transformOrigin");function Jh(e){const[t,s="center"]=e.split("-");return[t,s]}pi(Jh,"getSideAndAlignFromPlacement");var Jv=PO,$1=DO,R1=LO,_O=Object.defineProperty,an=(e,t)=>_O(e,"name",{value:t,configurable:!0}),[Qv,hX]=Ws("Tooltip",[qh]),Xv=qh(),zO="TooltipProvider",UO=700,vg="tooltip.open",[BO,Zv]=Qv(zO),WO=an(e=>{const{__scopeTooltip:t,delayDuration:s=UO,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=d.useRef(!0),o=d.useRef(!1),c=d.useRef(0);return d.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(BO,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:d.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),jg="Tooltip",[HO,Ic]=Qv(jg),KO=an(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=Zv(jg,e.__scopeTooltip),u=Xv(t),[h,f]=d.useState(null),[m,p]=d.useState(void 0),g=Ls(),v=d.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,x=d.useRef(!1),[w,y]=$i({prop:r,defaultProp:i??!1,onChange:an(R=>{R?(c.onOpen(),document.dispatchEvent(new CustomEvent(vg))):c.onClose(),a==null||a(R)},"onChange"),caller:jg}),k=d.useMemo(()=>w?x.current?"delayed-open":"instant-open":"closed",[w]),N=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,y(!0)},[y]),S=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,y(!1)},[y]),C=d.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,y(!0),v.current=0},j)},[j,y]);d.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]);const T=m??g;return n.jsx(Jv,{...u,children:n.jsx(HO,{scope:t,contentId:T,setContentId:p,open:w,stateAttribute:k,trigger:h,onTriggerChange:f,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():N()},[c.isOpenDelayedRef,C,N]),onTriggerLeave:d.useCallback(()=>{b?S():(window.clearTimeout(v.current),v.current=0)},[S,b]),onOpen:N,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),qb="TooltipTrigger",VO=d.forwardRef(an(function(t,s){const{__scopeTooltip:r,...i}=t,a=Ic(qb,r),l=Zv(qb,r),o=Xv(r),c=d.useRef(null),u=wt(s,c,a.onTriggerChange),h=d.useRef(!1),f=d.useRef(!1),m=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx($1,{asChild:!0,...o,children:n.jsx(gt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Me(t.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),f.current=!0)}),onPointerLeave:Me(t.onPointerLeave,()=>{a.onTriggerLeave(),f.current=!1}),onPointerDown:Me(t.onPointerDown,()=>{a.open&&a.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Me(t.onFocus,()=>{h.current||a.onOpen()}),onBlur:Me(t.onBlur,a.onClose),onClick:Me(t.onClick,a.onClose)})})},"TooltipTrigger")),I1="TooltipPortal",[GO,YO]=Qv(I1,{forceMount:void 0}),qO=an(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=Ic(I1,t);return n.jsx(GO,{scope:t,forceMount:s,children:n.jsx(gr,{present:s||a.open,children:n.jsx(Uh,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),ic="TooltipContent",JO=d.forwardRef(an(function(t,s){const r=YO(ic,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=Ic(ic,t.__scopeTooltip);return n.jsx(gr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(P1,{side:a,...l,ref:s}):n.jsx(QO,{side:a,...l,ref:s})})},"TooltipContent")),QO=d.forwardRef(an(function(t,s){const r=Ic(ic,t.__scopeTooltip),i=Zv(ic,t.__scopeTooltip),a=d.useRef(null),l=wt(s,a),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,f=a.current,{onPointerInTransitChange:m}=i,p=d.useCallback(()=>{c(null),m(!1)},[m]),g=d.useCallback((v,b)=>{const j=v.currentTarget,x={x:v.clientX,y:v.clientY},w=M1(x,j.getBoundingClientRect()),y=D1(x,w),k=O1(b.getBoundingClientRect()),N=F1([...y,...k]);c(N),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const v=an(j=>g(j,f),"handleTriggerLeave"),b=an(j=>g(j,u),"handleContentLeave");return u.addEventListener("pointerleave",v),f.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",v),f.removeEventListener("pointerleave",b)}}},[u,f,g,p]),d.useEffect(()=>{if(o){const v=an(b=>{const j=b.target,x={x:b.clientX,y:b.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),y=!L1(x,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[u,f,o,h,p]),n.jsx(P1,{...t,ref:l})},"TooltipContentHoverable")),XO=UC("TooltipContent"),P1=d.forwardRef(an(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=Ic(ic,r),f=Xv(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener(vg,m),()=>document.removeEventListener(vg,m)),[m]),d.useEffect(()=>{if(h.trigger){const g=an(v=>{v.target instanceof Node&&v.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return Wn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(zh,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(R1,{"data-state":h.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:h.contentId,...f,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[n.jsx(XO,{children:i}),a?n.jsx(VM,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function M1(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")}}an(M1,"getExitSideFromRect");function D1(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}an(D1,"getPaddedExitPoints");function O1(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}]}an(O1,"getPointsFromRect");function L1(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}an(L1,"isPointInPolygon");function F1(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),_1(t)}an(F1,"getHull");function _1(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)}an(_1,"getHullPresorted");var Jb=WO,ac=KO,lc=VO,oc=qO,cc=JO;let Wt={time:"auto",date:"auto",locale:void 0};function ej(e){const t=e.timeFormat===void 0?Wt.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?Wt.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";Wt={time:t,date:s,locale:e.locale??Wt.locale}}function z1(){return{time:Wt.time,date:Wt.date}}function Pc(e,t){const s=Wt;ej(e);try{return t()}finally{Wt=s}}const wg="buddi:formats";function Mc(){if(Wt.locale)return Wt.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const Qb=new Map;function Ll(e,t){const s=`${e}|${JSON.stringify(t)}`;let r=Qb.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,t)}catch{r=new Intl.DateTimeFormat(e,{...t,timeZone:"UTC"})}Qb.set(s,r)}return r}function pm(e,t,s,r){return Object.fromEntries(Ll(s,{timeZone:t,...r}).formatToParts(e).map(i=>[i.type,i.value]))}function ZO(){return Wt.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:Wt.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Qh()?"numeric":"2-digit",minute:"2-digit"}}function eL(){return Wt.time==="auto"?Mc():"en-US"}function Vt(e,t){return Number.isNaN(e.getTime())?"—":Ll(eL(),{timeZone:t,...ZO()}).format(e)}function tL(e){return e>=1440&&!Qh()?"24:00":Vt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Qh(){var e;return Wt.time!=="auto"?Wt.time==="12h":((e=Ll(Mc(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function U1(){return`Profile (${Qh()?"12-hour":"24-hour"})`}function nL(){if(Wt.date!=="auto")return Wt.date==="short";const e=Ll(Mc(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(t=>t.type);return e.indexOf("month")<e.indexOf("day")}function xr(e,t,s={}){return sL(e,t,s).replace(/\bSept\b/g,"Sep")}function sL(e,t,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:i=!1,compact:a=!1}=s;switch(Wt.date){case"iso":{const l=pm(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=pm(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=pm(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 Ll(Mc(),{timeZone:t,month:a?"short":"long",day:"numeric",...i?{year:"numeric"}:{},...r?{weekday:a?"short":"long"}:{}}).format(e)}}function B1(e,t){if(Wt.date==="iso")return`${e}-${String(t).padStart(2,"0")}`;const s=new Date(Date.UTC(e,t-1,15)),r=Wt.date==="auto"?Mc():"en-GB";return Ll(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Dc(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:xr(r,"UTC",t)}function nt(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${xr(s,t,{year:!0,compact:!0})}, ${Vt(s,t)}`}function tj(e,t){return`${xr(e,t,{weekday:!0,compact:!0})}, ${Vt(e,t)}`}function Le(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 nj(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 rL(e,t=Date.now()){const s=nj(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function iL(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 Jt(e){return new Intl.NumberFormat("en-US").format(e)}function yg(e){return[...e.cacheRead?[`cached ${Jt(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Jt(e.cacheWrite)}`]:[]].join(", ")}function aL(e){const t=yg(e);return`${Jt(e.input)} in${t?` (${t})`:""} / ${Jt(e.output)} out`}function ss(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function uc(e,t=8){return e.length<=t?e:e.slice(0,t)}function zs(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function dc(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}const Xb="buddi_csrf",Fl="x-buddi-csrf",dr="buddi:agents-changed",Ji="buddi:status-changed",uo=e=>(window.dispatchEvent(new Event(Ji)),e),bg="buddi:locked",lL="This page's sign-in no longer matches its cookies. Reload the page and try again.";class ve extends Error{constructor(t,s,r){super(s),this.status=t,this.detail=r,this.name="ApiError"}}function ma(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${Xb}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${Xb}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Gd="buddi isn't answering.";let kg=null;const Ng=new Set;function ho(e){if(e!==(kg===null)){kg=e?null:Date.now();for(const t of Ng)t()}}function hc(){return kg}function sj(e){return Ng.add(e),()=>Ng.delete(e)}function Yd(e){return e instanceof ve&&(e.status===0||e.status===502||e.status===503)&&e.message===Gd}async function pa(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:(ho(!1),new ve(0,Gd,o))}if(s.status===401)throw ho(!0),new ve(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw ho(!0),window.dispatchEvent(new Event(bg)),new ve(423,"This dashboard is locked.");const r=await s.text(),i=r===""?null:oL(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 ho(!1),new ve(s.status,Gd,i);if(ho(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?lL:`request failed (${s.status})`);throw new ve(s.status,c,i)}return i}function oL(e){try{return JSON.parse(e)}catch{return null}}function gm(){return z1().time==="auto"?{hour:Qh()?"12":"24"}:{}}function je(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 pa(`/api${e}${r?`?${r}`:""}`)}function Sg(e,t){return pa(`/api${e}`,{method:"POST",headers:{[Fl]:ma()},body:t})}function tr(e){return pa(`/api${e}`,{method:"DELETE",headers:{[Fl]:ma()}})}function te(e,t={}){return pa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[Fl]:ma()},body:JSON.stringify(t??{})})}function W1(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return pa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[Fl]:ma(),"X-Filename":i,...r},body:t})}function Zb(e,t,s){return W1(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function cL(e,t={}){return pa(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[Fl]:ma()},body:JSON.stringify(t??{})})}function Js(e,t={}){return pa(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[Fl]:ma()},body:JSON.stringify(t??{})})}function uL(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 ld="gpt-oss:120b",dL=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Cg=["mon","tue","wed","thu","fri","sat","sun"],He={agents:()=>je("/chat/agents"),views:()=>je("/chat/views"),conversations:(e,t)=>je(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>te(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>je(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>tr(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,t)=>te(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>te(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>te(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),Sg("/chat/attachments",t)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>tr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>je("/groups"),group:e=>je(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,t)=>cL(`/groups/${encodeURIComponent(e)}`,t),deleteGroup:e=>tr(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>te(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>te(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>je(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>te(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>te(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function rj(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const A={providers:()=>je("/providers"),providerAccounts:()=>je("/provider-accounts"),probeModels:e=>te("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>te(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>te("/provider-accounts/save",e),testProviderAccount:e=>te(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>te(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>te(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>te(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>te(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>te(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>te(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>te(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>je("/host/browser-profiles",{app:e}),installedApps:()=>je("/host/apps"),browser:e=>je(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>te(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>te("/browser/settings",e),computerPermissions:(e=!1)=>te("/browser/permissions",{prompt:e}),browserInstall:()=>te("/browser/install",{}),browserCheck:()=>te("/browser/check",{}),previewLink:(e,t)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>je("/extension"),pairExtension:e=>te("/extension/pair",{code:e}),forgetExtension:()=>tr("/extension/pair"),session:()=>je("/session"),overview:()=>je("/overview"),events:e=>je("/events",e),eventKinds:()=>je("/events/kinds"),conversations:()=>je("/conversations"),conversation:e=>je(`/conversations/${encodeURIComponent(e)}`),missions:()=>je("/missions"),jobs:(e={})=>je("/jobs",e),approvals:()=>je("/approvals"),approval:e=>je(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>je("/offers"),dismissOffer:e=>te(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>te("/offers/dismiss-all",{ids:e}),agentOffers:()=>je("/agent-offers"),catalogue:(e=!1)=>je(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,t={})=>te(`/catalogue/${encodeURIComponent(e)}/plan`,t),catalogueInstall:(e,t)=>te(`/catalogue/${encodeURIComponent(e)}/install`,t),catalogueJob:e=>je(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,t)=>te(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:t}),catalogueUpdatePlan:(e,t)=>te(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:t}),catalogueUpdate:(e,t,s,r=!1)=>te(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:t,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>je(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>te(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,t)=>te(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>je("/proposals"),setDigestSchedule:(e,t)=>te("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>te(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),keepAllProposals:e=>te("/proposals/keep-all",{ids:e}),discardProposal:(e,t)=>te(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>je("/reminders"),sentinels:()=>je("/sentinels"),setSentinelEnabled:(e,t)=>te(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),widgets:(e="home")=>je("/widgets",{...e==="lock"?{surface:e}:{},...gm()}),saveWidgets:(e,t)=>Js(`/widgets/${e}`,{placements:t.map(({key:s,widget:r,size:i,settings:a})=>({...s?{key:s}:{},widget:r,size:i,settings:a}))}),widgetSettings:e=>je(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>te("/widgets/preview",{...e,...gm()}),refreshWidget:(e,t="home")=>te(`/widgets/${encodeURIComponent(e)}/refresh${t==="lock"?"?surface=lock":""}`),homeDismiss:(e,t)=>te("/home/dismiss",{slot:e,token:t}),setGlanceHidden:(e,t)=>te(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>je("/rail"),setRailHidden:(e,t,s)=>te(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlerts:(e,t,s)=>te("/alerts/snooze",{keys:e,snoozed:t,...s!==void 0?{days:s}:{}}),muteAlert:(e,t)=>te("/alerts/mute",{key:e,scope:t}),unmuteAlert:e=>te(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>te("/alerts/act",{entries:e}),askAboutAlerts:e=>te("/alerts/ask",{keys:e}),agents:()=>je("/agents"),library:e=>je("/artifacts",e),libraryEntry:(e,t=0)=>je(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>je("/onboarding"),onboardingStep:(e,t={})=>te("/onboarding/step",{step:e,...t}),takeOn:e=>te("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>je("/onboarding/take-on"),completeOnboarding:()=>te("/onboarding/complete"),skipOnboarding:()=>te("/onboarding/skip"),createFirstAgent:e=>te("/onboarding/agent",e),ollama:()=>je("/onboarding/ollama"),mlxh:()=>je("/onboarding/mlxh"),firstAgentPersona:()=>je("/onboarding/agent"),updateFirstAgent:e=>te("/onboarding/agent/update",e),bindBrain:e=>te("/onboarding/brain",e),pages:()=>je("/pages"),pageQuery:(e,t,s={})=>je(`/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)=>te(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>je("/telegram"),saveTelegramToken:e=>te("/telegram/token",{token:e}),telegramPairing:()=>te("/telegram/pairing"),telegramBot:()=>je("/telegram/bot"),telegramDevices:()=>je("/telegram/devices"),unpairTelegramDevice:e=>tr(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>je("/notifications",{limit:e}),notificationsNeedingYou:()=>je("/notifications",{needs:1}),notificationSeen:e=>te(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>je("/notifications/settings"),saveNotificationSettings:e=>Js("/notifications/settings",e),focus:()=>je("/notifications/focus"),lockState:()=>je("/lock"),lockScreen:()=>je("/lock/screen",gm()),lockNow:(e="owner")=>te("/lock",{reason:e}),unlock:e=>te("/lock/unlock",{pin:e}),lockActivity:()=>te("/lock/activity"),setPin:(e,t)=>Js("/lock/pin",t===void 0?{pin:e}:{pin:e,current:t}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>Js("/lock/settings",e),uploadLockBackground:e=>{const t=new FormData;return t.append("file",e),Sg("/lock/background",t)},removeLockBackground:()=>tr("/lock/background"),setFocus:(e,t)=>Js("/notifications/focus",t?{mode:e,duration:t}:{mode:e}).then(uo),testChannel:e=>te("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>te("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>je(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>je("/tips"),restoreTip:e=>te(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>te(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>te(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>te("/tips/seen-page",{page:e}),tipsSettings:()=>je("/tips/settings"),saveTipsSettings:e=>Js("/tips/settings",{enabled:e}),presence:e=>te("/presence",{state:e}),owner:()=>je("/owner"),setOwner:e=>te("/owner",e),findPlace:e=>te("/owner/places/find",{address:e}),savePlace:e=>te("/owner/places",e),removePlace:e=>te("/owner/places/remove",{id:e}),memory:e=>je(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>te("/memory/preferences",e),forgetPreference:e=>te("/memory/preferences/forget",e),updateNote:(e,t)=>te(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>te(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>te(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>je(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>je(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>te(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>je("/host",{agentId:e,conversationId:t}),connections:()=>je("/connections"),connection:e=>je(`/connections/${e}`),addConnection:(e,t)=>te("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>te("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>te(`/connections/${e}/program`,t),connectionConsent:(e,t)=>te(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>te(`/connections/${e}/token`,t),connectionDevice:e=>te(`/connections/${e}/device`,{}),connectionCallback:e=>te("/connections/callback",e),connectionReview:e=>je(`/connections/${e}/review`),saveConnectionReview:(e,t)=>te(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>te(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>te(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>tr(`/connections/${e}`),connectionSignals:()=>je("/connections/signals"),connectionTools:e=>je(`/connections/${e}/tools`),rememberedApprovals:e=>je(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>te("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>je("/secrets"),secretUses:(e,t)=>je("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>te("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>te("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>te("/host/revoke",{id:e}),decide:(e,t,s,r)=>te(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>te("/pause",{paused:e}).then(uo),service:()=>je("/service"),serviceAction:e=>te(`/service/${e}`),version:()=>je("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>Js("/version/check",{enabled:e}),tailscale:()=>je("/tailscale"),setTailscale:e=>Js("/tailscale",e),apiTokens:()=>je("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>tr(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>te("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>je(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>je("/backups"),startBackup:e=>te("/backups",{encrypt:e}),verifyArchive:e=>te("/backups/verify",{name:e}),restoreArchive:e=>te("/backups/restore",e),restoreUpload:(e,t)=>Zb("/backups/restore",e,t),backupJob:e=>je(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>je("/backups/schedule"),setBackupSchedule:e=>Js("/backups/schedule",e),backupPassphrase:()=>je("/backups/passphrase"),setBackupPassphrase:e=>Js("/backups/passphrase",{passphrase:e}),plugins:()=>je("/plugins"),market:(e=!1)=>je(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>je("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>te("/plugins/stage",{spec:e}),uploadPlugin:e=>W1("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>je(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>te(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,t,s)=>te(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>je("/recovery"),leaveRecovery:e=>te("/recovery/leave",e),firstRunRestore:(e,t)=>Zb("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>te(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),keepMission:e=>te(`/missions/${encodeURIComponent(e)}/keep`,{}),setMisfirePolicy:(e,t,s)=>te(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>te(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>te(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>je("/jobs/failures"),dismissJobs:e=>te("/jobs/dismiss",e).then(uo),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(uo),retryJobs:e=>te("/jobs/retry",e).then(uo),setDefaultAgent:e=>te("/agents/default",{agentId:e}),agentTools:e=>je(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>je(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),Sg(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>tr(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>te(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>te(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>te(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>te(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},Eg="buddi.chatDraft";function ij(e,t){try{window.sessionStorage.setItem(Eg,JSON.stringify({agentId:e,text:t}))}catch{}}function hL(e){try{const t=window.sessionStorage.getItem(Eg);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Eg),s.text)}catch{return null}}function H1(e){return e==="anthropic"||e==="openai"}function K1(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 fL="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var mL=Object.defineProperty,pL=(e,t)=>mL(e,"name",{value:t,configurable:!0}),gL=d.createContext(void 0);function Xh(e){const t=d.useContext(gL);return e||t||"ltr"}pL(Xh,"useDirection");var xL=Object.defineProperty,aj=(e,t)=>xL(e,"name",{value:t,configurable:!0}),bu=0,Qs=null;function vL(e){return Zh(),e.children}aj(vL,"FocusGuards");function Zh(){d.useEffect(()=>{Qs||(Qs={start:Ag(),end:Ag()});const{start:e,end:t}=Qs;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),bu++,()=>{bu===1&&(Qs==null||Qs.start.remove(),Qs==null||Qs.end.remove(),Qs=null),bu=Math.max(0,bu-1)}},[])}aj(Zh,"useFocusGuards");function Ag(){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}aj(Ag,"createFocusGuard");var jL=Object.defineProperty,Cn=(e,t)=>jL(e,"name",{value:t,configurable:!0}),xm="focusScope.autoFocusOnMount",vm="focusScope.autoFocusOnUnmount",ek={bubbles:!1,cancelable:!0},V1=d.forwardRef(Cn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=d.useState(null),h=An(a),f=An(l),m=d.useRef(null),p=wt(s,u),g=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(i){let b=function(y){if(g.paused||!c)return;const k=y.target;c.contains(k)?m.current=k:Nr(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const k=y.relatedTarget;k!==null&&(c.contains(k)||Nr(m.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const N of y)N.removedNodes.length>0&&Nr(c)};Cn(b,"handleFocusIn"),Cn(j,"handleFocusOut"),Cn(x,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",j);const w=new MutationObserver(x);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",j),w.disconnect()}}},[i,c,g.paused]),d.useEffect(()=>{if(c){tk.add(g);const b=document.activeElement;if(!c.contains(b)){const x=new CustomEvent(xm,ek);c.addEventListener(xm,h),c.dispatchEvent(x),x.defaultPrevented||(G1(X1(lj(c)),{select:!0}),document.activeElement===b&&Nr(c))}return()=>{c.removeEventListener(xm,h),setTimeout(()=>{const x=new CustomEvent(vm,ek);c.addEventListener(vm,f),c.dispatchEvent(x),x.defaultPrevented||Nr(b??document.body,{select:!0}),c.removeEventListener(vm,f),tk.remove(g)},0)}}},[c,h,f,g]);const v=d.useCallback(b=>{if(!r&&!i||g.paused)return;const j=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,x=document.activeElement;if(j&&x){const w=b.currentTarget,[y,k]=Y1(w);y&&k?!b.shiftKey&&x===k?(b.preventDefault(),r&&Nr(y,{select:!0})):b.shiftKey&&x===y&&(b.preventDefault(),r&&Nr(k,{select:!0})):x===w&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(gt.div,{tabIndex:-1,...o,ref:p,onKeyDown:v})},"FocusScope"));function G1(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(Nr(r,{select:t}),document.activeElement!==s)return}Cn(G1,"focusFirst");function Y1(e){const t=lj(e),s=Tg(t,e),r=Tg(t.reverse(),e);return[s,r]}Cn(Y1,"getTabbableEdges");function lj(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Cn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}Cn(lj,"getTabbableCandidates");function Tg(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):q1(r,{upTo:t})))return r}Cn(Tg,"findVisible");function q1(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}Cn(q1,"isHidden");function J1(e){return e instanceof HTMLInputElement&&"select"in e}Cn(J1,"isSelectableInput");function Nr(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&J1(e)&&t&&e.select()}}Cn(Nr,"focus");var tk=Q1();function Q1(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=$g(e,t),e.unshift(t)},remove(t){var s;e=$g(e,t),(s=e[0])==null||s.resume()}}}Cn(Q1,"createFocusScopesStack");function $g(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}Cn($g,"arrayRemove");function X1(e){return e.filter(t=>t.tagName!=="A")}Cn(X1,"removeLinks");var wL=Object.defineProperty,oj=(e,t)=>wL(e,"name",{value:t,configurable:!0}),jm=!1;function Z1(){const[e,t]=d.useState(jm);return d.useEffect(()=>{jm||(jm=!0,t(!0))},[]),e}oj(Z1,"useIsHydrated");var eE=$l[" useSyncExternalStore ".trim().toString()];function tE(){return()=>{}}oj(tE,"subscribe");function nE(){return eE(tE,()=>!0,()=>!1)}oj(nE,"useIsHydratedModern");var yL=typeof eE=="function"?nE:Z1,bL=Object.defineProperty,ga=(e,t)=>bL(e,"name",{value:t,configurable:!0}),wm="rovingFocusGroup.onEntryFocus",kL={bubbles:!1,cancelable:!0},ef="RovingFocusGroup",[Rg,sE,NL]=Fh(ef),[SL,tf]=Ws(ef,[NL]),[CL,EL]=SL(ef),AL=d.forwardRef(ga(function(t,s){return n.jsx(Rg.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Rg.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(TL,{...t,ref:s})})})},"RovingFocusGroup")),TL=d.forwardRef(ga(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=t,p=d.useRef(null),g=wt(s,p),v=Xh(l),[b,j]=$i({prop:o,defaultProp:c??null,onChange:u,caller:ef}),[x,w]=d.useState(!1),y=An(h),k=sE(r),N=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(wm,y),()=>T.removeEventListener(wm,y)},[y]),n.jsx(CL,{scope:r,orientation:i,dir:v,loop:a,currentTabStopId:b,onItemFocus:d.useCallback(T=>j(T),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(T=>T+1),[]),onFocusableItemRemove:d.useCallback(()=>C(T=>T-1),[]),children:n.jsx(gt.div,{tabIndex:x||S===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Me(t.onMouseDown,()=>{N.current=!0}),onFocus:Me(t.onFocus,T=>{const R=!N.current;if(T.target===T.currentTarget&&R&&!x){const I=new CustomEvent(wm,kL);if(T.currentTarget.dispatchEvent(I),!I.defaultPrevented){const L=k().filter(M=>M.focusable),W=L.find(M=>M.active),$=L.find(M=>M.id===b),O=[W,$,...L].filter(Boolean).map(M=>M.ref.current);cj(O,f)}}N.current=!1}),onBlur:Me(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),$L="RovingFocusGroupItem",RL=d.forwardRef(ga(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=Ls(),h=l||u,f=EL($L,r),m=f.currentTabStopId===h,p=sE(r),{onFocusableItemAdd:g,onFocusableItemRemove:v,currentTabStopId:b}=f,j=yL();return Wn(()=>{if(!(!j||!i))return g(),()=>v()},[j,i,g,v]),d.useEffect(()=>{if(!(j||!i))return g(),()=>v()},[j,i,g,v]),n.jsx(Rg.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(gt.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:Me(t.onMouseDown,x=>{i?f.onItemFocus(h):x.preventDefault()}),onFocus:Me(t.onFocus,()=>f.onItemFocus(h)),onKeyDown:Me(t.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){f.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const w=iE(x,f.orientation,f.dir);if(w!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let k=p().filter(N=>N.focusable).map(N=>N.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const N=k.indexOf(x.currentTarget);k=f.loop?aE(k,N+1):k.slice(N+1)}setTimeout(()=>cj(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),IL={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function rE(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}ga(rE,"getDirectionAwareKey");function iE(e,t,s){const r=rE(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return IL[r]}ga(iE,"getFocusIntent");function cj(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}ga(cj,"focusFirst");function aE(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ga(aE,"wrapArray");var lE=AL,oE=RL,PL=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ea=new WeakMap,ku=new WeakMap,Nu={},ym=0,cE=function(e){return e&&(e.host||cE(e.parentNode))},ML=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=cE(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})},DL=function(e,t,s,r){var i=ML(t,Array.isArray(e)?e:[e]);Nu[s]||(Nu[s]=new WeakMap);var a=Nu[s],l=[],o=new Set,c=new Set(i),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};i.forEach(u);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",v=(Ea.get(m)||0)+1,b=(a.get(m)||0)+1;Ea.set(m,v),a.set(m,b),l.push(m),v===1&&g&&ku.set(m,!0),b===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return h(t),o.clear(),ym++,function(){l.forEach(function(f){var m=Ea.get(f)-1,p=a.get(f)-1;Ea.set(f,m),a.set(f,p),m||(ku.has(f)||f.removeAttribute(r),ku.delete(f)),p||f.removeAttribute(s)}),ym--,ym||(Ea=new WeakMap,Ea=new WeakMap,ku=new WeakMap,Nu={})}},uE=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=PL(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),DL(r,i,s,"aria-hidden")):function(){return null}},sr=function(){return sr=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},sr.apply(this,arguments)};function dE(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 OL(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 od="right-scroll-bar-position",cd="width-before-scroll-bar",LL="with-scroll-bars-hidden",FL="--removed-body-scroll-bar-size";function bm(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function _L(e,t){var s=d.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var zL=typeof window<"u"?d.useLayoutEffect:d.useEffect,nk=new WeakMap;function UL(e,t){var s=_L(null,function(r){return e.forEach(function(i){return bm(i,r)})});return zL(function(){var r=nk.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||bm(o,null)}),a.forEach(function(o){i.has(o)||bm(o,l)})}nk.set(s,e)},[e]),s}function BL(e){return e}function WL(e,t){t===void 0&&(t=BL);var s=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(a){var l=t(a,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(a){for(r=!0;s.length;){var l=s;s=[],l.forEach(a)}s={push:function(o){return a(o)},filter:function(){return s}}},assignMedium:function(a){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(a),l=s}var c=function(){var h=l;l=[],h.forEach(a)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(h){l.push(h),u()},filter:function(h){return l=l.filter(h),s}}}};return i}function HL(e){e===void 0&&(e={});var t=WL(null);return t.options=sr({async:!0,ssr:!1},e),t}var hE=function(e){var t=e.sideCar,s=dE(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return d.createElement(r,sr({},s))};hE.isSideCarExport=!0;function KL(e,t){return e.useMedium(t),hE}var fE=HL(),km=function(){},nf=d.forwardRef(function(e,t){var s=d.useRef(null),r=d.useState({onScrollCapture:km,onWheelCapture:km,onTouchMoveCapture:km}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,v=e.inert,b=e.allowPinchZoom,j=e.as,x=j===void 0?"div":j,w=e.gapMode,y=dE(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,N=UL([s,t]),S=sr(sr({},y),i);return d.createElement(d.Fragment,null,h&&d.createElement(k,{sideCar:fE,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:v,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:w}),l?d.cloneElement(d.Children.only(o),sr(sr({},S),{ref:N})):d.createElement(x,sr({},S,{className:c,ref:N}),o))});nf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};nf.classNames={fullWidth:cd,zeroRight:od};var VL=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function GL(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=VL();return t&&e.setAttribute("nonce",t),e}function YL(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qL(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var JL=function(){var e=0,t=null;return{add:function(s){e==0&&(t=GL())&&(YL(t,s),qL(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},QL=function(){var e=JL();return function(t,s){d.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},mE=function(){var e=QL(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},XL={left:0,top:0,right:0,gap:0},Nm=function(e){return parseInt(e||"",10)||0},ZL=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[Nm(s),Nm(r),Nm(i)]},eF=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return XL;var t=ZL(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])}},tF=mE(),il="data-scroll-locked",nF=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(LL,` {
|
|
42
|
+
overflow: hidden `).concat(r,`;
|
|
43
|
+
padding-right: `).concat(o,"px ").concat(r,`;
|
|
44
|
+
}
|
|
45
|
+
body[`).concat(il,`] {
|
|
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(od,` {
|
|
59
|
+
right: `).concat(o,"px ").concat(r,`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.`).concat(cd,` {
|
|
63
|
+
margin-right: `).concat(o,"px ").concat(r,`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.`).concat(od," .").concat(od,` {
|
|
67
|
+
right: 0 `).concat(r,`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.`).concat(cd," .").concat(cd,` {
|
|
71
|
+
margin-right: 0 `).concat(r,`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body[`).concat(il,`] {
|
|
75
|
+
`).concat(FL,": ").concat(o,`px;
|
|
76
|
+
}
|
|
77
|
+
`)},sk=function(){var e=parseInt(document.body.getAttribute(il)||"0",10);return isFinite(e)?e:0},sF=function(){d.useEffect(function(){return document.body.setAttribute(il,(sk()+1).toString()),function(){var e=sk()-1;e<=0?document.body.removeAttribute(il):document.body.setAttribute(il,e.toString())}},[])},rF=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;sF();var a=d.useMemo(function(){return eF(i)},[i]);return d.createElement(tF,{styles:nF(a,!t,i,s?"":"!important")})},Ig=!1;if(typeof window<"u")try{var Su=Object.defineProperty({},"passive",{get:function(){return Ig=!0,!0}});window.addEventListener("test",Su,Su),window.removeEventListener("test",Su,Su)}catch{Ig=!1}var Aa=Ig?{passive:!1}:!1,iF=function(e){return e.tagName==="TEXTAREA"},pE=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!iF(e)&&s[t]==="visible")},aF=function(e){return pE(e,"overflowY")},lF=function(e){return pE(e,"overflowX")},rk=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=gE(e,r);if(i){var a=xE(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},oF=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},cF=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},gE=function(e,t){return e==="v"?aF(t):lF(t)},xE=function(e,t){return e==="v"?oF(t):cF(t)},uF=function(e,t){return e==="h"&&t==="rtl"?-1:1},dF=function(e,t,s,r,i){var a=uF(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=xE(e,o),g=p[0],v=p[1],b=p[2],j=v-b-a*g;(g||j)&&gE(e,o)&&(f+=j,m+=g);var x=o.parentNode;o=x&&x.nodeType===Node.DOCUMENT_FRAGMENT_NODE?x.host:x}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(u=!0),u},Cu=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ik=function(e){return[e.deltaX,e.deltaY]},ak=function(e){return e&&"current"in e?e.current:e},hF=function(e,t){return e[0]===t[0]&&e[1]===t[1]},fF=function(e){return`
|
|
78
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
79
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
80
|
+
`)},mF=0,Ta=[];function pF(e){var t=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),i=d.useState(mF++)[0],a=d.useState(mE)[0],l=d.useRef(e);d.useEffect(function(){l.current=e},[e]),d.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var v=OL([e.lockRef.current],(e.shards||[]).map(ak),!0).filter(Boolean);return v.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(v,b){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!l.current.allowPinchZoom;var j=Cu(v),x=s.current,w="deltaX"in v?v.deltaX:x[0]-j[0],y="deltaY"in v?v.deltaY:x[1]-j[1],k,N=v.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in v&&S==="h"&&N.type==="range")return!1;var C=window.getSelection(),T=C&&C.anchorNode,R=T?T===N||T.contains(N):!1;if(R)return!1;var I=rk(S,N);if(!I)return!0;if(I?k=S:(k=S==="v"?"h":"v",I=rk(S,N)),!I)return!1;if(!r.current&&"changedTouches"in v&&(w||y)&&(r.current=k),!k)return!0;var L=r.current||k;return dF(L,b,v,L==="h"?w:y)},[]),c=d.useCallback(function(v){var b=v;if(!(!Ta.length||Ta[Ta.length-1]!==a)){var j="deltaY"in b?ik(b):Cu(b),x=t.current.filter(function(k){return k.name===b.type&&(k.target===b.target||b.target===k.shadowParent)&&hF(k.delta,j)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var w=(l.current.shards||[]).map(ak).filter(Boolean).filter(function(k){return k.contains(b.target)}),y=w.length>0?o(b,w[0]):!l.current.noIsolation;y&&b.cancelable&&b.preventDefault()}}},[]),u=d.useCallback(function(v,b,j,x){var w={name:v,delta:b,target:j,should:x,shadowParent:gF(j)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(y){return y!==w})},1)},[]),h=d.useCallback(function(v){s.current=Cu(v),r.current=void 0},[]),f=d.useCallback(function(v){u(v.type,ik(v),v.target,o(v,e.lockRef.current))},[]),m=d.useCallback(function(v){u(v.type,Cu(v),v.target,o(v,e.lockRef.current))},[]);d.useEffect(function(){return Ta.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,Aa),document.addEventListener("touchmove",c,Aa),document.addEventListener("touchstart",h,Aa),function(){Ta=Ta.filter(function(v){return v!==a}),document.removeEventListener("wheel",c,Aa),document.removeEventListener("touchmove",c,Aa),document.removeEventListener("touchstart",h,Aa)}},[]);var p=e.removeScrollBar,g=e.inert;return d.createElement(d.Fragment,null,g?d.createElement(a,{styles:fF(i)}):null,p?d.createElement(rF,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function gF(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const xF=KL(fE,pF);var uj=d.forwardRef(function(e,t){return d.createElement(nf,sr({},e,{ref:t,sideCar:xF}))});uj.classNames=nf.classNames;var vF=Object.defineProperty,ot=(e,t)=>vF(e,"name",{value:t,configurable:!0}),Pg=["Enter"," "],jF=["ArrowDown","PageUp","Home"],vE=["ArrowUp","PageDown","End"],wF=[...jF,...vE],yF={ltr:[...Pg,"ArrowRight"],rtl:[...Pg,"ArrowLeft"]},bF={ltr:["ArrowLeft"],rtl:["ArrowRight"]},sf="Menu",[fc,kF,NF]=Fh(sf),[xa,jE]=Ws(sf,[NF,qh,tf]),rf=qh(),wE=tf(),[yE,Ii]=xa(sf),[SF,Oc]=xa(sf),CF=ot(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=rf(t),[c,u]=d.useState(null),h=d.useRef(!1),f=An(a),m=Xh(i);return d.useEffect(()=>{const p=ot(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=ot(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),d.useEffect(()=>{if(!s)return;const p=ot(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),n.jsx(Jv,{...o,children:n.jsx(yE,{scope:t,open:s,onOpenChange:f,content:c,onContentChange:u,children:n.jsx(SF,{scope:t,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),bE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t,a=rf(r);return n.jsx($1,{...a,...i,ref:s})},"MenuAnchor")),kE="MenuPortal",[EF,NE]=xa(kE,{forceMount:void 0}),AF=ot(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=Ii(kE,t);return n.jsx(EF,{scope:t,forceMount:s,children:n.jsx(gr,{present:s||a.open,children:n.jsx(Uh,{asChild:!0,container:i,children:r})})})},"MenuPortal"),Fs="MenuContent",[TF,dj]=xa(Fs),$F=d.forwardRef(ot(function(t,s){const r=NE(Fs,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=Ii(Fs,t.__scopeMenu),o=Oc(Fs,t.__scopeMenu);return n.jsx(fc.Provider,{scope:t.__scopeMenu,children:n.jsx(gr,{present:i||l.open,children:n.jsx(fc.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(RF,{...a,ref:s}):n.jsx(IF,{...a,ref:s})})})})},"MenuContent")),RF=d.forwardRef(ot(function(t,s){const r=Ii(Fs,t.__scopeMenu),i=d.useRef(null),a=wt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return uE(l)},[]),n.jsx(hj,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Me(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),IF=d.forwardRef(ot(function(t,s){const r=Ii(Fs,t.__scopeMenu);return n.jsx(hj,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),PF=wi("MenuContent.ScrollLock"),hj=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:v,...b}=t,j=Ii(Fs,r),x=Oc(Fs,r),w=rf(r),y=wE(r),k=kF(r),[N,S]=d.useState(null),C=d.useRef(null),T=wt(s,C,j.onContentChange),R=d.useRef(0),I=d.useRef(""),L=d.useRef(0),W=d.useRef(null),$=d.useRef("right"),P=d.useRef(0),O=v?uj:d.Fragment,M=v?{as:PF,allowPinchZoom:!0}:void 0,D=ot(U=>{var fe,Oe;const q=I.current+U,B=k().filter(Ie=>!Ie.disabled),Y=document.activeElement,F=(fe=B.find(Ie=>Ie.ref.current===Y))==null?void 0:fe.textValue,X=B.map(Ie=>Ie.textValue),Q=ME(X,q,F),ee=(Oe=B.find(Ie=>Ie.textValue===Q))==null?void 0:Oe.ref.current;ot(function Ie(Fe){I.current=Fe,window.clearTimeout(R.current),Fe!==""&&(R.current=window.setTimeout(()=>Ie(""),1e3))},"updateSearch")(q),ee&&setTimeout(()=>ee.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(R.current),[]),Zh();const H=d.useCallback(U=>{var B,Y;return $.current===((B=W.current)==null?void 0:B.side)&&OE(U,(Y=W.current)==null?void 0:Y.area)},[]);return n.jsx(TF,{scope:r,searchRef:I,onItemEnter:d.useCallback(U=>{H(U)&&U.preventDefault()},[H]),onItemLeave:d.useCallback(U=>{var q;H(U)||((q=C.current)==null||q.focus(),S(null))},[H]),onTriggerLeave:d.useCallback(U=>{H(U)&&U.preventDefault()},[H]),pointerGraceTimerRef:L,onPointerGraceIntentChange:d.useCallback(U=>{W.current=U},[]),children:n.jsx(O,{...M,children:n.jsx(V1,{asChild:!0,trapped:a,onMountAutoFocus:Me(l,U=>{var q;U.preventDefault(),(q=C.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(zh,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(lE,{asChild:!0,...y,dir:x.dir,orientation:"vertical",loop:i,currentTabStopId:N,onCurrentTabStopIdChange:S,onEntryFocus:Me(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(R1,{role:"menu","aria-orientation":"vertical","data-state":fj(j.open),"data-radix-menu-content":"",dir:x.dir,...w,...b,ref:T,style:{outline:"none",...b.style},onKeyDown:Me(b.onKeyDown,U=>{const B=U.target.closest("[data-radix-menu-content]")===U.currentTarget,Y=U.ctrlKey||U.altKey||U.metaKey,F=U.key.length===1;B&&(U.key==="Tab"&&U.preventDefault(),!Y&&F&&D(U.key));const X=C.current;if(U.target!==X||!wF.includes(U.key))return;U.preventDefault();const ee=k().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);vE.includes(U.key)&&ee.reverse(),IE(ee)}),onBlur:Me(t.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(R.current),I.current="")}),onPointerMove:Me(t.onPointerMove,xl(U=>{const q=U.target,B=P.current!==U.clientX;if(U.currentTarget.contains(q)&&B){const Y=U.clientX>P.current?"right":"left";$.current=Y,P.current=U.clientX}}))})})})})})})},"MenuContentImpl")),SE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{role:"group",...i,ref:s})},"MenuGroup")),MF=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"MenuLabel")),Mg="MenuItem",lk="menu.itemSelect",CE=d.forwardRef(ot(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=d.useRef(null),o=Oc(Mg,t.__scopeMenu),c=dj(Mg,t.__scopeMenu),u=wt(s,l),h=d.useRef(!1),f=ot(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(lk,{bubbles:!0,cancelable:!0});m.addEventListener(lk,g=>i==null?void 0:i(g),{once:!0}),_h(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(EE,{...a,ref:u,disabled:r,onClick:Me(t.onClick,f),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),h.current=!0},onPointerUp:Me(t.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Me(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Pg.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),EE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=dj(Mg,r),c=wE(r),u=d.useRef(null),h=wt(s,u),[f,m]=d.useState(!1),[p,g]=d.useState("");return d.useEffect(()=>{const v=u.current;v&&g((v.textContent??"").trim())},[l.children]),n.jsx(fc.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(oE,{asChild:!0,...c,focusable:!i,children:n.jsx(gt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:h,onPointerMove:Me(t.onPointerMove,xl(v=>{i?o.onItemLeave(v):(o.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Me(t.onPointerLeave,xl(v=>o.onItemLeave(v))),onFocus:Me(t.onFocus,()=>m(!0)),onBlur:Me(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),DF="MenuRadioGroup",[OF,LF]=xa(DF,{value:void 0,onValueChange:ot(()=>{},"onValueChange")}),FF=d.forwardRef(ot(function(t,s){const{value:r,onValueChange:i,...a}=t,l=An(i);return n.jsx(OF,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(SE,{...a,ref:s})})},"MenuRadioGroup")),_F="MenuRadioItem",zF=d.forwardRef(ot(function(t,s){const{value:r,...i}=t,a=LF(_F,t.__scopeMenu),l=r===a.value;return n.jsx(BF,{scope:t.__scopeMenu,checked:l,children:n.jsx(CE,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":RE(l),onSelect:Me(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),UF="MenuItemIndicator",[BF,fX]=xa(UF,{checked:!1}),WF=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),AE="MenuSub",[HF,TE]=xa(AE),KF=ot(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=Ii(AE,t),l=rf(t),[o,c]=d.useState(null),[u,h]=d.useState(null),f=An(i);return d.useEffect(()=>(a.open===!1&&f(!1),()=>f(!1)),[a.open,f]),n.jsx(Jv,{...l,children:n.jsx(yE,{scope:t,open:r,onOpenChange:f,content:u,onContentChange:h,children:n.jsx(HF,{scope:t,contentId:Ls(),triggerId:Ls(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Eu="MenuSubTrigger",VF=d.forwardRef(ot(function(t,s){const r=Ii(Eu,t.__scopeMenu),i=Oc(Eu,t.__scopeMenu),a=TE(Eu,t.__scopeMenu),l=dj(Eu,t.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:t.__scopeMenu},f=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>f,[f]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=wt(s,a.onTriggerChange);return n.jsx(bE,{asChild:!0,...h,children:n.jsx(EE,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":fj(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:Me(t.onPointerMove,xl(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:Me(t.onPointerLeave,xl(p=>{var v,b;f();const g=(v=r.content)==null?void 0:v.getBoundingClientRect();if(g){const j=(b=r.content)==null?void 0:b.dataset.side,x=j==="right",w=x?-5:5,y=g[x?"left":"right"],k=g[x?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:y,y:g.bottom}],side:j}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Me(t.onKeyDown,p=>{var v;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||yF[i.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})},"MenuSubTrigger")),GF="MenuSubContent",YF=d.forwardRef(ot(function(t,s){const r=NE(Fs,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=Ii(Fs,t.__scopeMenu),c=Oc(Fs,t.__scopeMenu),u=TE(GF,t.__scopeMenu),h=d.useRef(null),f=wt(s,h);return n.jsx(fc.Provider,{scope:t.__scopeMenu,children:n.jsx(gr,{present:i||o.open,children:n.jsx(fc.Slot,{scope:t.__scopeMenu,children:n.jsx(hj,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Me(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Me(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Me(t.onKeyDown,m=>{var v;const p=m.currentTarget.contains(m.target),g=bF[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(v=u.trigger)==null||v.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function fj(e){return e?"open":"closed"}ot(fj,"getOpenState");function $E(e){return e==="indeterminate"}ot($E,"isIndeterminate");function RE(e){return $E(e)?"indeterminate":e?"checked":"unchecked"}ot(RE,"getCheckedState");function IE(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}ot(IE,"focusFirst");function PE(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ot(PE,"wrapArray");function ME(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=PE(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}ot(ME,"getNextMatch");function DE(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}ot(DE,"isPointInPolygon");function OE(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return DE(s,t)}ot(OE,"isPointerInGraceArea");function xl(e){return t=>t.pointerType==="mouse"?e(t):void 0}ot(xl,"whenMouse");var qF=CF,JF=bE,QF=AF,XF=$F,ZF=SE,e_=MF,t_=CE,n_=FF,s_=zF,r_=WF,i_=KF,a_=VF,l_=YF,o_=Object.defineProperty,ls=(e,t)=>o_(e,"name",{value:t,configurable:!0}),mj="DropdownMenu",[c_,mX]=Ws(mj,[jE]),os=jE(),[u_,LE]=c_(mj),d_=ls(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=os(t),u=d.useRef(null),[h,f]=$i({prop:i,defaultProp:a??!1,onChange:l,caller:mj});return n.jsx(u_,{scope:t,triggerId:Ls(),triggerRef:u,contentId:Ls(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:n.jsx(qF,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),h_="DropdownMenuTrigger",f_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=LE(h_,r),o=os(r),c=wt(s,l.triggerRef);return n.jsx(JF,{asChild:!0,...o,children:n.jsx(gt.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:Me(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Me(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_=ls(e=>{const{__scopeDropdownMenu:t,...s}=e,r=os(t);return n.jsx(QF,{...r,...s})},"DropdownMenuPortal"),p_="DropdownMenuContent",g_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=LE(p_,r),l=os(r),o=d.useRef(!1);return n.jsx(XF,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Me(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Me(t.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,f=u.button===2||h;(!a.modal||f)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),x_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(ZF,{...a,...i,ref:s})},"DropdownMenuGroup")),v_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(e_,{...a,...i,ref:s})},"DropdownMenuLabel")),j_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(t_,{...a,...i,ref:s})},"DropdownMenuItem")),w_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(n_,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),y_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(s_,{...a,...i,ref:s})},"DropdownMenuRadioItem")),b_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(r_,{...a,...i,ref:s})},"DropdownMenuSeparator")),k_=ls(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=os(t),[o,c]=$i({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(i_,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),N_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(r);return n.jsx(a_,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),S_=d.forwardRef(ls(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=os(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")),Lc=d_,Fc=f_,_l=m_,_c=g_,FE=x_,ca=v_,xs=j_,C_=w_,E_=y_,Rr=b_,A_=k_,T_=N_,$_=S_,R_=Object.defineProperty,zl=(e,t)=>R_(e,"name",{value:t,configurable:!0}),pj="Tabs",[I_,pX]=Ws(pj,[tf]),_E=tf(),[P_,gj]=I_(pj),M_=d.forwardRef(zl(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,f=Xh(c),[m,p]=$i({prop:i,onChange:a,defaultProp:l??"",caller:pj});return n.jsx(P_,{scope:r,baseId:Ls(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:n.jsx(gt.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),D_="TabsList",O_=d.forwardRef(zl(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=gj(D_,r),o=_E(r);return n.jsx(lE,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(gt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),L_="TabsTrigger",F_=d.forwardRef(zl(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=gj(L_,r),c=_E(r),u=xj(o.baseId,i),h=vj(o.baseId,i),f=i===o.value;return n.jsx(oE,{asChild:!0,...c,focusable:!a,active:f,children:n.jsx(gt.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Me(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Me(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Me(t.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),__="TabsContent",z_=d.forwardRef(zl(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=gj(__,r),u=xj(c.baseId,i),h=vj(c.baseId,i),f=i===c.value,m=d.useRef(f);return d.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(gr,{present:a||f,children:({present:p})=>n.jsx(gt.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function xj(e,t){return`${e}-trigger-${t}`}zl(xj,"makeTriggerId");function vj(e,t){return`${e}-content-${t}`}zl(vj,"makeContentId");var U_=M_,B_=O_,W_=F_,H_=z_;function Zt(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?K_(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${ok(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Jt(r):ok(r):String(e)}case"date":return V_(String(e));default:return typeof e=="string"?e:typeof e=="number"?Jt(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 iL(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?Dc(t[0],{year:!0,compact:!0}):e}function Dg(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?Dc(t[0],{compact:!0}):e}function ok(e){return String(Math.round(e*100)/100)}function qd(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:Zt(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 J_(e){return e.replace(/\n$/,"").split(`
|
|
81
|
+
`).map(s=>({kind:Q_(s),text:s}))}function Q_(e){return e.startsWith("@@")?"hunk":Y_.test(e)||q_.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function X_({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 Jd({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=J_(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(X_,{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:Zt(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(Jd,{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 cn="#/",vl="#/needs",gi="#/chat",mt="#/agents",jt="#/activity",sn="#/settings",Hr="#/files",e4="#/welcome";function ud(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function Au(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`${Hr}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function t4(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 st(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function n4(e){if(zE(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 Hi(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function zE(e){const t=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{groupId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{}}}catch{return null}}function St(e,t,s){return`${mt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function s4(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t||t[1]===UE)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}const UE="catalogue",ck=`${mt}/${UE}`;function Bt(e){return e?`${ck}/${encodeURIComponent(e)}`:ck}function r4(e){return`${Bt(e)}?add=1`}function i4(e,t){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===t}function a4(e){const t=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return t?t[1]?{name:t[1]}:{}:null}function mc(e){return`${jt}/conversations/${encodeURIComponent(e)}`}const l4="#/p";function hr(e,t,s){const r=`${l4}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function jj(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 o4="p.";function Kr(e,t,s){const r=s?new URLSearchParams(s).toString():"";return`${sn}/${encodeURIComponent(WE(e,t))}${r?`?${r}`:""}`}function BE(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 c4(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 WE(e,t){return`${o4}${e}${t===e?"":`.${t}`}`}function Pe(e){return e?`${sn}/${e}`:sn}function HE(e){return`${Pe("accounts")}?account=${encodeURIComponent(e)}`}function u4(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function wj(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 KE(e){return`${Pe("connections")}?connection=${encodeURIComponent(e)}`}function d4(e){return wj(e,"connections","connection")}function h4(e){return wj(e,"secrets","secret")}const uk=`${Pe("secrets")}?add=1`;function f4(e){return wj(e,"secrets","add")==="1"}function m4(e){return`${Pe("plugins")}?install=${encodeURIComponent(e)}`}const p4=`${Pe("plugins")}?tab=browse`;function g4(e){return`${Pe("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function x4(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function yj(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function v4(e){var s,r;const t=(r=(s=yj(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function dk(e){var s;const t=(s=yj(e))==null?void 0:s.get("kind");return t==="plugins"||t==="agents"?t:"all"}function hk(e){const t=yj(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const j4=[{route:cn,label:"Home"},{route:gi,label:"Chat"},{route:mt,label:"Agents"},{route:jt,label:"Activity"},{route:Hr,label:"Files"},{route:sn,label:"Settings"}],w4=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],y4=[{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 b4(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const Og="#/settings/notifications/recent",Lg=Pe("backup");function k4(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return mc(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return hr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return hr("email","mail")}return e==="#/settings/email"?Kr("email","settings"):{"#/overview":cn,"#/approvals":cn,"#/events":`${jt}/events`,"#/jobs":`${jt}/jobs`,"#/conversations":jt,"#/missions":`${mt}?tab=missions`,"#/offers":`${mt}?tab=offers`,"#/reminders":`${mt}?tab=reminders`,"#/providers":Pe("accounts"),"#/browser":Pe("computer"),"#/sentinels":Pe("watchers"),"#/settings/sentinels":Pe("watchers")}[e]??null}function VE(e){if(e===""||e==="#"||e===cn)return cn;if(e.startsWith(gi))return gi;if(e.startsWith(mt))return mt;if(e.startsWith(jt))return jt;if(e.startsWith(Hr))return Hr;if(e.startsWith(sn))return sn;const t=jj(e);return t?hr(t.plugin,t.page):cn}const N4="#/chat?group=new";function S4(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 zc="front-desk",bj=[{id:zc,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."}],GE=new Set(bj.map(e=>e.id)),fk=e=>GE.has(e);function mk(e,t){const s=t.filter(r=>!GE.has(r));return[...bj.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function C4(e,t){return e.find(s=>(s.roles??[]).includes(t))}const pk=["coding","finance","mail","research","calendar","files","memory"],E4={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[zc]:"buddi"},A4=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function T4(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of A4)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Fg=null;function $4(e){Fg=e}function Uc(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=E4[s];if(r)return{key:r}}const t=T4(e.tools??[]);return t?{key:t}:Fg!==null&&e.id===Fg?{key:"buddi"}:{key:pk[R4(e.id)%pk.length]??"coding"}}function Bc(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function R4(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const I4=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function P4(e){const s=e.replace(/\r\n/g,`
|
|
82
|
+
`).split(`
|
|
83
|
+
|
|
84
|
+
`),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
|
|
85
|
+
`)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),f=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:I4.includes(o)?o:"ping",data:M4(c.join(`
|
|
86
|
+
`))})}return{events:i,rest:r}}function M4(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function af(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,h,f,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await t(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...i===null?{}:{"Last-Event-ID":i}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const v=g.body.getReader(),b=new TextDecoder;let j="";for(;;){const{done:x,value:w}=await v.read();if(x)break;j+=b.decode(w,{stream:!0});const{events:y,rest:k}=P4(j);j=k;for(const N of y)e.onEvent(N),N.id!==null&&(i=N.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const kj="0.1.0+4fe61a9";function Nj(e,t=kj){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function D4(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const O4=5*6e4,L4=6e4,F4=5e3,pc="buddi:stream-reconnected",YE="buddi.autoReloadedFor";function _4(){window.dispatchEvent(new Event(pc))}const gk=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let Sj=Date.now(),Tu=0;const xk=()=>{Sj=Date.now()};function z4(){if(Tu===0){Sj=Date.now();for(const e of gk)window.addEventListener(e,xk,{capture:!0,passive:!0})}return Tu+=1,()=>{if(Tu-=1,Tu===0)for(const e of gk)window.removeEventListener(e,xk,{capture:!0})}}function U4(e=Date.now()){return e-Sj}function qE(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 B4(e){return e.hidden?!0:e.idleMs>=L4&&!e.busy}function W4(e){try{return window.sessionStorage.getItem(YE)===e}catch{return!1}}function H4(e){try{window.sessionStorage.setItem(YE,e)}catch{}}function K4(e){const t=d.useRef(e);t.current=e,d.useEffect(()=>{const s=()=>t.current();return window.addEventListener(pc,s),()=>window.removeEventListener(pc,s)},[])}function V4(e,t=()=>window.location.reload(),s=kj){const r=Nj(e,s),i=d.useRef(t);i.current=t,d.useEffect(()=>z4(),[]),d.useEffect(()=>{if(!r||e===void 0||W4(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";B4({hidden:c,idleMs:U4(),busy:qE()})&&(a=!0,H4(e),i.current())};l();const o=window.setInterval(l,F4);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const G4=9e4,JE=5*6e4,Y4=500,q4=2e3,J4=3e3,Q4="/_buddi/ready",al={reload:()=>window.location.reload(),now:()=>Date.now()};let ki=null,Ya=null,ko=null;const _g=new Set;function Qd(e){ki=e;for(const t of _g)t()}function vk(){return ki}function X4(e){return _g.add(e),()=>_g.delete(e)}function Z4(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(t=>t.toString(16).padStart(2,"0")).join("")}async function Cj(e=J4){const t=new AbortController,s=setTimeout(()=>t.abort(),e);try{const r=await fetch(`${Q4}?challenge=${Z4()}`,{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 ez(){const e=await Cj();e&&(Ya=e)}function tz(){let e=Ya,t=!1,s=!1,r=Y4,i;const a=async()=>{if(t)return;const l=await Cj();if(!t){if(l===null)s=!0;else if(e!==null?l!==e:s){t=!0,al.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),q4),i=setTimeout(()=>void a(),r)}};return i=setTimeout(()=>void a(),r),()=>{t=!0,clearTimeout(i)}}function lf(e){if(ki){if(e.kind==="detected")return;Qd({...ki,...e});return}Qd({...e,startedAt:al.now()}),ko=tz()}function QE(e){ki&&Qd({...ki,...e})}function jl(){ko==null||ko(),ko=null,Qd(null)}async function of(e,t){lf(e);try{return await t()}catch(s){if(Yd(s))return;throw jl(),s}}function nz(e){lf({kind:e.for==="stop"?"stop":"detected"})}async function jk(){if(ki)return;const e=await Cj();if(Ya===null){e&&(Ya=e);return}if(!(!e||e===Ya||ki)){if(qE()){Ya=e;return}lf({kind:"detected"})}}function sz(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 rz="/api/chat/attention/stream";function XE(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 ZE(e,t){const s=XE(e,t);return[...s.top,...s.middle,...s.bottom]}function cf(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 iz(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 az(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function lz(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function oz(){const[e,t]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{je("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=af({url:rz,onEvent:a=>a.name==="closing"?nz(a.data):r(),onReconnect:_4});return()=>{s=!0,i.close()}},[]),lz(e)}const Wc="maker";function Ej(e){return e.filter(t=>t.available&&!t.roles.includes(Wc))}function eA(e){return Ej(e).length>=2}function cz(e){var t;return((t=e.find(s=>s.roles.includes(Wc)))==null?void 0:t.name)??"the agent maker"}const uz="{{default}}";function dz(e,t){return e.split(uz).join(t??"your assistant")}function hz(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>dz(s,t))}function fz(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 mz(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 tA(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 pz="Settings → Model accounts",gz="Install it in Settings → Plugins";function zg(e){return e!=null&&e.heldBack?{section:"plugins",label:gz}:{section:"accounts",label:pz}}const xz={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"})],search:[16,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7",cy:"7",r:"4.5"}),n.jsx("path",{d:"M10.5 10.5L14 14"})]})],alert:[16,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),n.jsx("path",{d:"M8 4.8v3.8M8 11.2v.01"})]})],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 ce({name:e,size:t,className:s,...r}){const[i,a,l,o]=xz[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 nA="buddi.rosterCollapsed";function vz(){try{return window.localStorage.getItem(nA)==="1"}catch{return!1}}function jz(e){try{window.localStorage.setItem(nA,e?"1":"0")}catch{}}function sA({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const f=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=d.useState(vz),v=b=>n.jsx(wz,{agent:b,active:b.id===t,attention:s.get(b.id),side:m,onSelect:r,lastAt:(a==null?void 0:a.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return n.jsxs("nav",{className:i==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":i==="vertical"&&p?"true":void 0,children:[e.top.map(v),e.top.length>0&&e.middle.length>0?n.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,i==="vertical"&&!p&&e.middle.length>0?n.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,n.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(v),u&&eA(f)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:n.jsx(ce,{name:"plus"})}):null]}),o.map(b=>n.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":b.id===c?"true":void 0,"aria-current":b.id===c?"true":void 0,"aria-label":`${b.name}, ${b.members.length} agents`,onClick:()=>u(b.id),children:[n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(j=>{const x=f.find(w=>w.id===j);return n.jsx(uf,{className:"wb-group-chip",id:j,name:(x==null?void 0:x.name)??"?",face:x,initials:1},j)})}),n.jsxs("span",{className:"wb-face-text",children:[n.jsx("span",{className:"wb-face-name",children:b.name}),n.jsx("span",{className:"wb-face-status",children:b.members.map(j=>{var x;return((x=f.find(w=>w.id===j))==null?void 0:x.name)??j}).join(", ")})]})]},b.id))]}):u?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsx("div",{className:"wb-groups-head",children:n.jsx("span",{className:"wb-groups-label",children:"Groups"})}),n.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",n.jsx("a",{href:mt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(v),i==="vertical"?n.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":p?"Show agent names":"Hide agent names","aria-pressed":p,onClick:()=>g(b=>(jz(!b),!b)),children:n.jsx(ce,{name:p?"chevron-right":"chevron-left"})}):null]})}function wz({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=cf(s),c=iz(s)??(e.available?a?rL(a):e.description:e.unavailableReason??"Cannot run right now"),u=az(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",f=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(ac,{children:[n.jsx(lc,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Bc(Uc(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(uf,{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(ce,{name:"out"})})]})}),n.jsx(oc,{children:n.jsxs(cc,{className:"ui-tip",side:r,sideOffset:8,children:[n.jsx("span",{className:"ui-tip-title",children:e.name}),n.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:h}),o?n.jsx("span",{className:"ui-tip-alert",children:yz(o)}):null]})})]})}function yz(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function bz(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const kz="modulepreload",Nz=function(e,t){return new URL(e,t).href},wk={},Sz=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=Nz(u,r),u in wk)return;wk[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const v=l[g];if(v.href===u&&(!h||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":kz,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((g,v)=>{p.addEventListener("load",g),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})},Cz="buddi",Ez=["core","coding","finance","garage","mail","maker","playground","research"],va=e=>`./mascot/${e}.png`,Az=["core"],Ug=(e,t)=>Az.includes(e)?`./mascot/anim/${e}-${t}.json`:null,Tz=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],$z="Introduce yourself by name and say one thing you can do today.",Rz=["Hello","A brain","What I take on","Reach me","Your assistant"],$u=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Sm=e=>e.charAt(0).toUpperCase()+e.slice(1),Iz=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Mo=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars, for a brief every morning.",note:"Weather needs nothing. Calendar asks for your calendar’s private link 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, kept on this computer.",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:"One picture from a prompt, with an account you pick.",note:"Image asks which account to draw with."}],Pz=["days","mail"],yk=[{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:Rz,mapNotes:["Two minutes. Everything can be changed later in Settings, and nothing leaves this computer until you say so.","One line decides which company sees your assistant’s conversations. You can add more brains later and give each agent its own.","Each choice installs a plugin from withbuddi.com. At the end I suggest teammates for what you picked; nothing runs until you have read its card, and you can say no to any of them.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,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 ${$u(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${$u(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":Sm(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":Sm(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: ${$u(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=>[e.days?"What’s my day like?":"What can you do?","Show me around",e.days?"Link my calendar":e.mail&&!e.mailbox?"Add my mailbox":"What do you know about me?","Remind me at 9 tomorrow"],starterLabel:"Ask first",waitingTitle:e=>`${Iz[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Sm($u(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 Ru=null;const bk=new Map;function Mz(){return Ru??(Ru=Sz(()=>import("./lottie_light-DdwKPR04.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Ru.catch(()=>{Ru=null}),Ru}function Dz(e){let t=bk.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),bk.set(e,t)),t}const kk="(prefers-reduced-motion: reduce)";function rA(){const[e,t]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(kk).matches);return d.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(kk),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 Hc({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=d.useRef(null),o=rA(),[c,u]=d.useState(!1),h=s==="xs"?null:Ug(e,t);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([Mz(),Dz(h)]).then(([p,g])=>{if(f||!g||!l.current)return;const v=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?v.pause():v.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),v.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[o,h]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??va(e),alt:"",onError:a})})}async function Nk(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 iA(e,t="core"){const s=rA(),r=e!==null&&Oz(e,t),[i,a]=d.useState(!1);return d.useEffect(()=>{if(a(!1),!e||r||!s||!Ug(t,"idle"))return;let l=!1;return Promise.all([Nk(e),Nk(va(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&Ug(t,"idle")!==null&&(r||i)}function Oz(e,t){const s=va(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 uf({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=d.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=h?"image":f==null?void 0:f.kind,p=t?Bc(Uc({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?n.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(f==null?void 0:f.kind)==="image"?n.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:mz(s).slice(0,o)})}function bn({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(uf,{className:"ui-avatar",id:e,tint:bz(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(bn,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const aA=d.createContext(null);function Lz({picture:e,children:t}){return n.jsx(aA.Provider,{value:e??null,children:t})}function lA({size:e,anim:t}){const s=d.useContext(aA),[r,i]=d.useState(null),a=iA(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(Hc,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const oA=d.createContext([]);function fr({text:e,className:t}){const s=Bg(e.replace(/\r\n/g,`
|
|
88
|
+
`).split(`
|
|
89
|
+
`));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(Wg,{block:r},i))})}const Sk=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Ck=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Ek=/^\s*([-*_])(\s*\1){2,}\s*$/,Iu=/^(\s*)([-*+])\s+(.*)$/,fo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Pu=/^\s*>\s?(.*)$/,Cm=/^\s*\|.*\|\s*$/,Ak=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Bg(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Sk.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=Ck.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Ek.test(r)){t.push({type:"hr"}),s+=1;continue}if(Pu.test(r)){const o=[];for(;s<e.length&&Pu.test(e[s]);)o.push(Pu.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:Bg(o),raw:o.join(`
|
|
91
|
+
`)});continue}if(Cm.test(r)&&s+1<e.length&&Ak.test(e[s+1])){const o=Am(r),c=Am(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&Cm.test(e[s]);)u.push(Am(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(Iu.test(r)||fo.test(r)){const o=fo.exec(r)??Iu.exec(r),c=fo.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?fo.exec(e[s]):Iu.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],v=g.trim()!==""&&Em(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Em(e[s+1])>u;if(!v&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(Em(g),u+2))),s+=1}f.push(Bg(p))}t.push({type:"list",ordered:c,start:h,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||Sk.test(o)||Ck.test(o)||Ek.test(o)||Pu.test(o)||Iu.test(o)||fo.test(o)||Cm.test(o)&&s+1<e.length&&Ak.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 Em(e){return e.length-e.trimStart().length}function Am(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 Wg({block:e}){switch(e.type){case"p":return n.jsx("p",{children:Ms(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:Ms(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(Tk,{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(Wg,{block:t},s))}),n.jsx(Tk,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(d.Fragment,{children:Ms(i.text)},a):n.jsx(Wg,{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:Ms(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:Ms(r)},i))},s))})]})})}}function Tk({text:e,what:t,always:s=!1}){const[r,i]=d.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function Fz({handle:e}){const s=d.useContext(oA).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(ac,{children:[n.jsx(lc,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:st(s.id),children:["@",s.handle]})}),n.jsx(oc,{children:n.jsxs(cc,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(bn,{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 _z=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 Ms(e){const t=[];let s=e,r=0;for(;s!=="";){const i=_z.exec(s);if(!i){t.push(...$k(s,r));break}i.index>0&&t.push(...$k(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:Ms(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:Ms(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:Ms(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:Ms(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:Ms(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:Ms(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(Fz,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function $k(e,t){return e.split(`
|
|
93
|
+
`).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function zz({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:Zt(t.value,t.unit,null)})]},t.label))}):null,e.kind==="image"&&e.src?n.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?n.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:n.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?n.jsx("div",{className:"wb-doc",children:n.jsx(fr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const Uz=["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 Ce(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:Ce(e,t.path)}function ts(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 ft(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function xi(e){return Array.isArray(e)?e:[]}function Bz(e,t){const s=xi(Ce(e,t.points)).map(i=>{const a=ts(Ce(i,t.y)),l=ft(Ce(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=ts(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:ft(Ve(e,t.currency)),label:ft(Ve(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:ts(Ve(e,t.shadeBelow)),events:Wz(e,t)}}function Wz(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=ft(Ce(a,s.label));if(o===null)return;const c=ft(Ce(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?ts(Ce(a,s.amount)):null})};if(s.parent){for(const a of xi(Ce(e,t.points))){const l=ft(Ce(a,t.x));for(const o of xi(Ce(a,s.parent)))i(o,l)}return r}for(const a of xi(Ce(e,s.path??t.points)))i(a,null);return r}function Hz(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=Ce(o,c.key);let h=null;if(c.bar){const f=ts(Ve(o,c.bar.max))??ts(Ve(e,c.bar.max)),m=ts(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:Vz(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:ft(Ve(o,c.currency))??ft(Ve(e,c.currency)),bar:h}}),i=xi(Ce(e,t.rows)),a=t.groupBy?Kz(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:ft(Ve(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function Kz(e,t,s){const r=new Map;for(const i of e){const a=String(Ce(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 Vz(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 Gz(e,t){return{bars:xi(Ce(e,t.bars)).map(r=>{const i=ts(Ce(r,t.value)),a=ft(Ce(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:ft(Ve(e,t.currency))}}function Yz(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text",currency:ft(Ve(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ce(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:wn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const qz=new Set(["good","warning","critical","neutral","accent"]),Jz=new Set(Uz);function Hg(e){return typeof e=="string"&&Jz.has(e)?e:null}function Aj(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=ft(Ce(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:Hg(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:xi(Ce(e,t.items)).map(l=>{const o=ft(Ce(l,t.value))??"",c=ft(Ce(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?ft(Ce(l,t.tone)):null;return{icon:Hg(Ve(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>ft(Ce(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&qz.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function Qz(e,t){const s=ft(Ve(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?ft(Ce(e,t.src)):null;return{kind:r,text:t.text?ft(Ce(e,t.text)):null,src:i&&uA(i)?i:null,title:ft(Ve(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Ve(e,a.value),unit:a.unit??"text"}))}}function Xz(e,t){const s=t.diff?Ce(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:ft(Ve(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text"}))}}function Zz(e,t){const s=t.output?Ce(e,t.output):void 0,r=l=>{const o=l?Ce(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?Ce(e,t.elapsedMs):void 0;return{command:ft(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 eU=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function cA(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&eU.test(t)?t.toLowerCase():null}function tU(e,t){return{artifactId:t.src?cA(Ce(e,t.src)):null,title:ft(Ve(e,t.title)),caption:ft(Ve(e,t.caption)),...t.captionLabel?{captionLabel:ft(Ve(e,t.captionLabel))}:{}}}function Rk(e){if(!uA(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 nU(e,t){const s=t.src?ft(Ce(e,t.src)):null,r=t.port?Ce(e,t.port):null,i=t.awaiting?ft(Ce(e,t.awaiting)):null;return{target:s?Rk(s):null,title:ft(Ve(e,t.title)),output:t.output?ft(Ce(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?Rk(i):null,reloadsItself:t.reloadsItself?Ce(e,t.reloadsItself)===!0:!1,ports:t.ports?sU(Ce(e,t.ports)):[]}}function sU(e){const t=xi(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function uA(e){return e.startsWith("/")&&!e.startsWith("//")}function wn(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 dA(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:Bz(t,s)};case"table":return{renderer:"table",props:Hz(t,s)};case"bars":return{renderer:"bars",props:Gz(t,s)};case"keyvalue":return{renderer:"keyvalue",props:Yz(t,s)};case"tiles":return{renderer:"tiles",props:Aj(t,s,e.tool)};case"document":return{renderer:"document",props:Qz(t,s)};case"diff":return{renderer:"diff",props:Xz(t,s)};case"terminal":return{renderer:"terminal",props:Zz(t,s)};case"image":return{renderer:"image",props:tU(t,s)};case"preview":return{renderer:"preview",props:nU(t,s)};default:return{renderer:"structured",props:{value:t}}}}var rU=Object.defineProperty,Cs=(e,t)=>rU(e,"name",{value:t,configurable:!0}),Tj="Dialog",[hA,gX]=Ws(Tj),[iU,vr]=hA(Tj),df=Cs(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=d.useRef(null),c=d.useRef(null),[u,h]=$i({prop:r,defaultProp:i??!1,onChange:a,caller:Tj}),[f,m]=d.useState(0),[p,g]=d.useState(0);return n.jsx(iU,{scope:t,triggerRef:o,contentRef:c,contentId:Ls(),titleId:Ls(),descriptionId:Ls(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(v=>!v),[h]),modal:l,children:s})},"Dialog"),aU="DialogTrigger",lU=d.forwardRef(Cs(function(t,s){const{__scopeDialog:r,...i}=t,a=vr(aU,r),l=wt(s,a.triggerRef);return n.jsx(gt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":pf(a.open),...i,ref:l,onClick:Me(t.onClick,a.onOpenToggle)})},"DialogTrigger")),fA="DialogPortal",[oU,mA]=hA(fA,{forceMount:void 0}),hf=Cs(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=vr(fA,t);return n.jsx(oU,{scope:t,forceMount:s,children:d.Children.map(r,l=>n.jsx(gr,{present:s||a.open,children:n.jsx(Uh,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),Kg="DialogOverlay",$j=d.forwardRef(Cs(function(t,s){const r=mA(Kg,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=vr(Kg,t.__scopeDialog);return l.modal?n.jsx(gr,{present:i||l.open,children:n.jsx(uU,{...a,ref:s})}):null},"DialogOverlay")),cU=wi("DialogOverlay.RemoveScroll"),uU=d.forwardRef(Cs(function(t,s){const{__scopeDialog:r,...i}=t,a=vr(Kg,r),l=JC(),o=wt(s,l);return n.jsx(uj,{as:cU,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(gt.div,{"data-state":pf(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),gc="DialogContent",ff=d.forwardRef(Cs(function(t,s){const r=mA(gc,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=vr(gc,t.__scopeDialog);return n.jsx(gr,{present:i||l.open,children:l.modal?n.jsx(dU,{...a,ref:s}):n.jsx(hU,{...a,ref:s})})},"DialogContent")),dU=d.forwardRef(Cs(function(t,s){const r=vr(gc,t.__scopeDialog),i=d.useRef(null),a=wt(s,r.contentRef,i);return d.useEffect(()=>{const l=i.current;if(l)return uE(l)},[]),n.jsx(pA,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Me(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Me(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Me(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),hU=d.forwardRef(Cs(function(t,s){const r=vr(gc,t.__scopeDialog),i=d.useRef(!1),a=d.useRef(!1);return n.jsx(pA,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=t.onCloseAutoFocus)==null||o.call(t,l),l.defaultPrevented||(i.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:l=>{var u,h;(u=t.onInteractOutside)==null||u.call(t,l),l.defaultPrevented||(i.current=!0,l.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),pA=d.forwardRef(Cs(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=vr(gc,r);return Zh(),n.jsx(n.Fragment,{children:n.jsx(V1,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(zh,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":pf(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),fU="DialogTitle",mf=d.forwardRef(Cs(function(t,s){const{__scopeDialog:r,...i}=t,a=vr(fU,r),{setTitleCount:l}=a;return Wn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(gt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),mU="DialogClose",Rj=d.forwardRef(Cs(function(t,s){const{__scopeDialog:r,...i}=t,a=vr(mU,r);return n.jsx(gt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function pf(e){return e?"open":"closed"}Cs(pf,"getState");const pU=5;function de(e,t,s){const[r,i]=d.useState(void 0),[a,l]=d.useState(null),[o,c]=d.useState(!0),[u,h]=d.useState(0),[f,m]=d.useState(0),p=d.useRef(e);return p.current=e,d.useEffect(()=>{let g=!1;return c(!0),p.current().then(v=>{g||(i(v),l(null),m(0))}).catch(v=>{g||(l(v instanceof ve?v.message:String(v)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),d.useEffect(()=>{if(!s||f>=pU)return;const g=window.setTimeout(()=>h(v=>v+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:a,loading:o,reload:()=>{m(0),h(g=>g+1)}}}const gA={width:480,height:160,top:10,right:10,bottom:22,left:40},xA={width:1200,height:180,top:10,right:40,bottom:22,left:40};function gU({xs:e,series:t}){const s=xA,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=W=>W.filter($=>$!==null&&Number.isFinite($)),l=t.filter(W=>W.type!=="bar"),o=t.filter(W=>W.type==="bar"),c=l.flatMap(W=>a(W.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let f=u,m=h;if(f===m)f-=1,m+=1;else{const W=(m-f)*.08;f-=W,m+=W}const p=W=>vs(s.top+i-(W-f)/(m-f)*i),g=o.length>0&&o.every(W=>W.unit==="percent"),v=g?100:Math.max(1,...o.flatMap(W=>a(W.values))),b=W=>vs(s.top+i-Math.max(0,W)/v*i),j=e.length,x=j>0?r/j:r,w=W=>vs(s.left+x*(W+.5)),y=t.map(W=>{if(W.type==="bar")return"";let $="M";const P=[];return W.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)){$="M";return}P.push(`${$}${w(M)},${p(O)}`),$="L"}),P.join(" ")}),k=[],N=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((W,$)=>{if(W.type!=="bar")return;const P=C++;W.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)||O<=0)return;const D=b(O);k.push({series:$,index:M,x:vs(w(M)-x*.3+N*P),y:D,width:vs(N),height:vs(S-D)})})});const T=c.length>0?qd(u,h,2).map(W=>({value:W,y:p(W)})):[],R=o.length===0?[]:(g?[0,50,100]:qd(0,v,2)).map(W=>({value:W,y:b(W),percent:g})),I=Math.max(1,Math.ceil(j/8)),L=e.flatMap((W,$)=>$%I===0?[{index:$,x:w($)}]:[]);return{lines:y,bars:k,targetY:null,ticks:T,xLabels:L,rightTicks:R}}function xU({xs:e,series:t,type:s="line",target:r=null}){const i=gA,a=i.width-i.left-i.right,l=i.height-i.top-i.bottom,o=t.flatMap(w=>w.values.filter(y=>y!==null&&Number.isFinite(y)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const w=(u-c)*.08;c-=w,u+=w}const h=w=>vs(i.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?a/f:a,p=w=>vs(s==="bar"?i.left+m*(w+.5):i.left+(f<=1?a/2:w/(f-1)*a)),g=s==="line"?t.map(w=>{let y="M";const k=[];return w.values.forEach((N,S)=>{if(N===null||!Number.isFinite(N)){y="M";return}k.push(`${y}${p(S)},${h(N)}`),y="L"}),k.join(" ")}):[],v=[];if(s==="bar"&&f>0){const w=m*.7,y=w/Math.max(1,t.length),k=h(0);t.forEach((N,S)=>{N.values.forEach((C,T)=>{if(C===null||!Number.isFinite(C))return;const R=h(C);v.push({series:S,index:T,x:vs(i.left+m*T+(m-w)/2+y*S),y:Math.min(R,k),width:vs(y),height:vs(Math.abs(k-R))})})})}const j=(o.length>0?qd(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),x=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:g,bars:v,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:j,xLabels:x.map(w=>({index:w,x:p(w)}))}}function vU(e){const t=e.formatX??(o=>o),s=e.formatY??(o=>String(o)),r=e.xs.length;if(r===0)return`${e.label??"Chart"}: nothing recorded yet.`;const i=r===1?`on ${t(e.xs[0])}`:`from ${t(e.xs[0])} to ${t(e.xs[r-1])}`,a=e.series.map(o=>{const c=o.values.filter(h=>h!==null&&Number.isFinite(h));if(c.length===0)return`${o.label}: no values`;const u=c[c.length-1];return`${o.label}: latest ${s(u)}, lowest ${s(Math.min(...c))}, highest ${s(Math.max(...c))}`}),l=e.target!==null&&e.target!==void 0&&Number.isFinite(e.target)?` Target ${s(e.target)}.`:"";return`${e.label??"Chart"}, ${r} ${r===1?"point":"points"} ${i}. ${a.join("; ")}.${l}`}function jU({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?xA:gA,u=o?gU({xs:e,series:t}):xU({xs:e,series:t,type:s,target:r}),h=vU({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),n.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>n.jsx("text",{x:c.width-c.right+6,y:f.y,textAnchor:"start",dominantBaseline:"middle",children:f.percent?`${f.value}%`:l(f.value)},`r-${f.value}`)),n.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(f=>n.jsx("rect",{className:"ui-chart-bar","data-series":f.series,x:f.x,y:f.y,width:f.width,height:f.height},`${f.series}-${f.index}`)),u.lines.map((f,m)=>f?n.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?n.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(f=>n.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&f.index===0?"start":f.index===e.length-1&&e.length>1?"end":"middle",children:a(e[f.index])},f.index))]}),n.jsx("figcaption",{className:"sr-only",children:h}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((f,m)=>n.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function vs(e){return Math.round(e*10)/10}const Ij="(max-width: 900px)";function bs(e){const[t,s]=d.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return d.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}function Pi(...e){return e.filter(Boolean).join(" ")}function E({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:Pi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Et({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:Pi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function wU({checked:e,onChange:t,label:s,disabled:r}){return n.jsxs("label",{className:"ui-switch","data-disabled":r?"true":void 0,children:[n.jsx("input",{type:"checkbox",role:"switch",checked:e,disabled:r,"aria-label":s,onChange:i=>t(i.target.checked)}),n.jsx("i",{"aria-hidden":"true"})]})}function ae({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:Pi("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function dt(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function oe({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=d.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function Us({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 we({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:Pi("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 Vg({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Kc({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(we,{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 ie({message:e}){return e?n.jsx(G,{tone:"critical",role:"alert",children:e}):null}function pe({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(lA,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function Tn({icon:e,title:t,action:s,children:r}){return n.jsxs("div",{className:"ui-empty-state",children:[e?n.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?n.jsx(ce,{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 Pj({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function wl({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 Pn({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(Pj,{children:[n.jsx(wl,{title:t,lede:s,actions:r}),i]})}function ue({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 Ge({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 cs({tone:e,title:t,meta:s,actions:r,children:i,foot:a,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())}}:{};return n.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[t||s||r?n.jsxs("div",{className:"ui-card-head",children:[t?n.jsx("h3",{className:"ui-card-title",children:t}):null,s,r?n.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,i,a?n.jsx("div",{className:"ui-card-foot",children:a}):null]})}function le({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 yU({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function gf({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function ir({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 Ht({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 jr({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function vA({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 Pt({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function At({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:Pi("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 qe({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(df,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(hf,{children:[n.jsx($j,{className:"ui-sheet-overlay"}),n.jsxs(ff,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(mf,{className:"ui-sheet-title",children:e}),n.jsx(Rj,{asChild:!0,children:n.jsx(E,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Ft({title:e,onClose:t,foot:s,children:r}){return n.jsx(df,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(hf,{children:[n.jsx($j,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(ff,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(mf,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function ja({label:e,items:t,note:s,trigger:r,sheet:i}){const a=bs(bU);return i&&a&&!r?n.jsx(kU,{label:e,items:t,title:i.title,sub:i.sub}):n.jsx(NU,{label:e,items:t,note:s,trigger:r})}const bU="(max-width: 720px)";function kU({label:e,items:t,title:s,sub:r}){const[i,a]=d.useState(!1);return n.jsxs(df,{open:i,onOpenChange:a,children:[n.jsx(lU,{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(ce,{name:"more"})})}),n.jsxs(hf,{children:[n.jsx($j,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),n.jsxs(ff,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[n.jsxs("div",{className:"ui-action-sheet-head",children:[n.jsx(mf,{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(Rj,{asChild:!0,children:n.jsx(E,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function NU({label:e,items:t,note:s,trigger:r}){const i=l=>l.stopPropagation(),a=d.useRef(!1);return n.jsxs(Lc,{modal:!1,onOpenChange:l=>{l&&(a.current=!1)},children:[n.jsx(Fc,{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(ce,{name:"more"})})}),n.jsx(_l,{children:n.jsxs(_c,{className:"ui-menu",align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:l=>{a.current&&l.preventDefault()},children:[s?n.jsx(ca,{className:"ui-menu-label",children:s}):null,t.map((l,o)=>l?l==="separator"?n.jsx(Rr,{className:"ui-menu-sep"},`sep-${o}`):"heading"in l?n.jsx(ca,{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs(xs,{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 SU({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(df,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(hf,{children:n.jsxs(ff,{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(mf,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(Rj,{asChild:!0,children:n.jsx(E,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Vc({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function yl({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 Kt({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 rt({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function et({href:e,onClick:t,lead:s,title:r,sub:i,side:a,dimmed:l,label:o}){const c=n.jsxs(n.Fragment,{children:[s,n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:r}),i?n.jsx("span",{className:"ui-list-sub",children:i}):null]}),a?n.jsx("span",{className:"ui-list-side",children:a}):null]}),u=l?"true":void 0;return e?n.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:t?h=>{h.preventDefault(),t()}:void 0,children:c}):t?n.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:t,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),t())},children:c}):n.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function jA({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 wA({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:Pi("ui-split",i),"data-open":t?"true":void 0,children:[n.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),n.jsx("section",{className:"ui-split-detail","data-empty":t?void 0:"true",children:t??n.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function Xd({children:e,onRemove:t,label:s,disabled:r}){return n.jsxs("span",{className:"ui-chip",children:[e,n.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:t,disabled:r,children:"×"})]})}const CU=8;function EU({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(0),p=d.useRef(null),g=d.useRef(null),v=d.useRef(null),b=d.useRef(null),j=d.useId(),x=$=>{var P;return((P=t.find(O=>O.value===$))==null?void 0:P.label)??$},w=i!==void 0&&s.length>=i,y=t.filter($=>!s.includes($.value)),k=t.length>CU,N=u.trim().toLowerCase(),S=N===""?y:y.filter($=>$.label.toLowerCase().includes(N)),C=Math.min(f,Math.max(0,S.length-1)),T=$=>{var P;c(!1),h(""),m(0),$&&((P=g.current)==null||P.focus())};d.useEffect(()=>{var P;if(!o)return;(P=k?v.current:b.current)==null||P.focus();const $=O=>{p.current&&!p.current.contains(O.target)&&T(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[o,k]);const R=$=>{const P=[...s,$];r(P),h(""),m(0);const O=i!==void 0&&P.length>=i;(O||P.length>=t.length)&&T(!O)},I=$=>{if($.key==="Escape")$.preventDefault(),T(!0);else if($.key==="ArrowDown")$.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if($.key==="ArrowUp")$.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if($.key==="Enter"){$.preventDefault();const P=S[C];P&&R(P.value)}else $.key==="Backspace"&&u===""&&s.length>0&&($.preventDefault(),r(s.slice(0,-1)))},L=$=>`${j}-${$}`,W=o&&S.length>0?L(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map($=>n.jsx(Xd,{label:x($),disabled:a,onRemove:()=>r(s.filter(P=>P!==$)),children:x($)},$)),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?T(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[k?n.jsx("input",{ref:v,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":W,value:u,onChange:$=>{h($.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":k?void 0:W,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[S.map(($,P)=>n.jsx("div",{id:L(P),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":P===C?"":void 0,onMouseEnter:()=>m(P),onMouseDown:O=>O.preventDefault(),onClick:()=>R($.value),children:$.label},$.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function yA({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 xf({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 $n({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(ce,{name:t})})}function Zd({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(ce,{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 bA({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(E,{"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 xc({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function kA({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:Pi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function AU({dock:e,className:t,children:s}){return n.jsxs("div",{className:Pi("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 TU(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function Mj(e){const[t,s]=d.useState({}),r=e??[],i={...TU(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(oe,{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 $U({props:e,timezone:t="UTC",onDecided:s}){var w;const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let y=!1;return i(null),l(null),A.approval(e.approvalId).then(k=>{y||i(k)}).catch(k=>{y||l(k instanceof ve?k.message:String(k))}),()=>{y=!0}},[e.approvalId]);const{values:f,controls:m}=Mj(r==null?void 0:r.choices),p=(y,k)=>{h(y),l(null),(f&&y==="approve"?A.decide(e.approvalId,y,k,f):A.decide(e.approvalId,y,k)).then(N=>{i(N.action),s==null||s(N.action)}).catch(N=>l(N instanceof ve?N.message:String(N))).finally(()=>h(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",v=(w=r.permissionScopes)==null?void 0:w.includes("always"),b=RU(r),j=(r.preview??"").split(`
|
|
94
|
+
`).length>12||(r.preview??"").length>900,x=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>wn(y)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[g?n.jsx(we,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(Kc,{state:r.state}),!g&&x?n.jsxs("span",{className:"wb-envelope-note",children:[" ",x]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children: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(ie,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:v?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),n.jsxs("div",{className:"wb-envelope-buttons",children:[n.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),v?n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,n.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":v?"Allow once":"Approve"})]})]}):null,n.jsxs("details",{className:"ui-details",children:[n.jsx("summary",{children:"The envelope, field by field"}),n.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(y=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:y.label}),y.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:y.value})}):n.jsx("dd",{className:y.mono?"mono":void 0,children:y.value})]},y.label))})]})]})}function RU(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(Ik(wn(i),a));else s!=null&&t.push({label:"Envelope",value:Dj(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 · ${wn(i)}`;t.some(o=>o.label===l)||t.push(Ik(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 Ik(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:Dj(t)}}function Dj(e){return e==null?"—":Array.isArray(e)?e.map(t=>Dj(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):Zt(e,"text",null)}const IU=new Set(["image/png","image/jpeg","image/gif","image/webp"]),PU=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function eh(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"||!PU.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 Oj(e){return IU.has(e.toLowerCase())}function Vr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function Ni(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function Kn(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 Lj(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 ea={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function dd(e){return`artifact:${e}`}function MU(e){const t=Lj(e.mime,e.filename);return{id:dd(e.artifactId),tool:ea[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function DU({props:e}){const t=cA(e.artifactId),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{if(t===null)return;let h=!0;return r(null),a(null),o(!1),A.libraryEntry(t).then(f=>{h&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[t]),t===null)return n.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?Kn(s.sizeBytes):null].filter(h=>h!==null);return n.jsxs("figure",{className:"wb-image",children:[n.jsx("div",{className:"wb-image-frame",children:l?n.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):n.jsx("a",{href:Vr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:Vr(t),alt:e.caption??c,onLoad:h=>{const f=h.currentTarget;f.naturalWidth>0&&a({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(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(Et,{size:"sm",href:Ni(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(At,{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 OU({props:e}){return e.pairs.length===0?n.jsx("p",{className:"wb-empty",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.pairs.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:"tnum",style:t.tone==="neutral"?void 0:{color:`var(--${t.tone})`},children:Zt(t.value,t.unit,t.currency)})]},t.label))})}const LU=8;function NA({text:e,label:t="Output",className:s}){const r=d.useRef(null),i=d.useRef(!0);return d.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=LU},children:e})}function FU(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 _U({text:e}){const[t,s]=d.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.jsx(E,{size:"sm",onClick:()=>{var r;if(s(""),!((r=navigator.clipboard)!=null&&r.writeText)){s("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>s("Copied"),()=>s("Copy failed; select the text to copy."))},children:"Copy"})]})}function zU({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(we,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:FU(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(_U,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",Kn(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(NA,{text:t}):n.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:s.label}),n.jsx("dd",{children:Zt(s.value,s.unit,null)})]},s.label))}):null]})}function UU(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function Pk(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function BU(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function WU({props:e}){var k;const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=((k=e.target)==null?void 0:k.plugin)??null,h=BU(e),[f,m]=d.useState(null),p=f!==null&&h.includes(f)?f:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,v=e.changes??0,b=d.useRef(v),[j,x]=d.useState(0);d.useEffect(()=>{v<=b.current||(b.current=v,e.reloadsItself||x(N=>N+1))},[v,e.reloadsItself]),d.useEffect(()=>{if(u===null||g===null)return;let N=!0;return s(null),i(null),l(null),x(0),A.previewLink(u,g).then(S=>{N&&(s(S.url),i(Pk(S.url)))}).catch(S=>{N&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{N=!1}},[u,g]);const w=()=>{u===null||g===null||A.previewLink(u,g).then(N=>i(N.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:N=>m(Number(N.target.value)),children:h.map(N=>n.jsxs("option",{value:N,children:[":",N]},N))}):null,y?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(N=>!N),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&UU()?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:Pk(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(NA,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const HU=50,KU=9,VU=24,GU=.6,YU=48,qU=/(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,JU=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,QU=/^id$|(^|[a-z0-9])Id$|_id$/;function qa(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Zn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function SA(...e){for(const t of e)if(Zn(t))for(const s of["currency","currencyCode"]){const r=t[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function CA(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&&qU.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&JU.test(i))?"date":"text"}function XU(e,t){if(!QU.test(e))return!1;const s=t.filter(r=>!Ul(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Ul(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:Zn(e)?Object.keys(e).length===0:!1}function Mk(e,t){const s=e.filter(Zn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,HU),i=new Map,a=[];for(const h of r)for(const f of Object.keys(h))i.has(f)||a.push(f),i.set(f,(i.get(f)??0)+1);if(i.size===0||i.size>VU||[...i.values()].reduce((h,f)=>h+f,0)/(i.size*r.length)<GU)return null;const o=[...i.keys()].sort((h,f)=>{const m=(i.get(f)??0)-(i.get(h)??0);return m!==0?m:a.indexOf(h)-a.indexOf(f)}),c=[],u=[];for(const h of o){const f=r.map(v=>v[h]),m=f.filter(v=>!Ul(v));if(m.length===0||XU(h,f))continue;const p=SA(r[0],t),g=CA(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(v=>qa(v)&&v===f[0])){u.push({label:wn(h),value:f[0],type:g,currency:p});continue}if(c.push({key:h,label:wn(h),type:g,currency:g==="currency"?p:null}),c.length===KU)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function ZU(e,t,s){const r=SA(s);return{label:wn(e),value:t,type:CA(e,[t],r),currency:r}}function EA(e){return typeof e=="string"&&e.length>YU}function e3(e){return e==null?"This tool returned nothing.":typeof e=="string"&&e.trim()===""?"This tool returned an empty string.":Array.isArray(e)&&e.length===0?"This tool returned no items.":Zn(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Gg(e){if(typeof e=="string"&&e.trim()!=="")return e;if(Zn(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(Zn(s)){const r=Gg(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Fj(e,t={}){if(t.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));Zn(m)&&(f=m)}catch{}return{kind:"error",summary:Gg(f),detail:Dk(f)}}if(Zn(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Gg(e),detail:Dk(e)}}const s=e3(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=Mk(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(qa)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!Zn(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[f,m]of r){if(!Array.isArray(m))continue;const p=Mk(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:f,candidate:p});continue}m.length>0&&m.every(qa)&&(!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(EA(m)){c.push(m);continue}if(qa(m)){if(m==="")continue;o.push(ZU(f,m,e));continue}m!==void 0&&u.push({label:wn(f),value:m})}if(i)return{kind:"table",label:wn(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:wn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return h.length>0&&h.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${h.map(([m])=>wn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>qa(f)||Zn(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function Dk(e){if(!Zn(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const th=25,t3=3,Yg=8,AA=6;function qg(e,t=0){if(t>AA||Ul(e)||EA(e))return 0;if(qa(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=qg(r,t+1),s>=Yg)return s;return s}if(Zn(e)){let s=0;for(const r of Object.values(e))if(s+=qg(r,t+1),s>=Yg)return s;return s}return 0}function Jg(e,t=0){if(t>AA)return!1;if(Array.isArray(e))return e.some(a=>Jg(a,t+1));if(!Zn(e))return!1;const s=e.artifactId??e.artifact_id;if(typeof s=="string"&&s.trim()!=="")return!0;const r=e.mime??e.mimeType??e.contentType,i=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof i=="string"&&i.trim()!==""?!0:Object.values(e).some(a=>Jg(a,t+1))}function n3(e){if(Jg(e))return!0;const t=Fj(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=t3;case"record":case"tree":return qg(e)>=Yg;default:return!1}}function Tm(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function _j(e){const t=Tm(e);if(!t)return null;const s=Tm(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:Tm(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function s3({text:e,label:t}){const[s,r]=d.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function $m({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(s3,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function r3({value:e,children:t}){const{result:s,command:r,input:i}=e,a=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([h,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx($m,{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($m,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx($m,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((h,f)=>n.jsx("p",{className:"wb-fail",children:h},f))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:ss({...c,...i?{input:i}:{}})})]})]})}const Mu=2,Ok=64;function i3({props:e}){const[t,s]=d.useState(!1),r=_j(e.value),i=a3((r==null?void 0:r.result)??e.value),a=d.useMemo(()=>Fj(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(Lk,{files:i}),t?n.jsx("pre",{className:"ui-code",children:ss(e.value)}):r?n.jsx(r3,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(Lk,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(Fk,{shape:a})]}):n.jsx(Fk,{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 a3(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 Lk({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(l3,{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 l3({file:e}){const[t,s]=d.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function Fk({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:vc(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(Rm,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=f3(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(Rm,{stats:e.stats}),n.jsx(Im,{notes:e.notes}),t?n.jsx(m3,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(c3,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(Pm,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(Rm,{stats:e.stats}),n.jsx(Im,{notes:e.notes}),e.label?n.jsx("h4",{className:"wb-sub",children:e.label}):null,n.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((t,s)=>n.jsx("li",{children:Zt(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(Pm,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(Im,{notes:e.notes}),n.jsx(o3,{pairs:e.pairs}),n.jsx(Pm,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:vc(e.value,0)})}}function Rm({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:zj(t.value,t.type,t.currency)})]},t.label))})}const _k=200;function Im({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=_k),s=e.filter(r=>r.length>_k);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 o3({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:zj(t.value,t.type,t.currency)})]},t.label))})}function Pm({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:vc(t.value,1)})]},t.label))})}function c3({label:e,columns:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=th+5?r:th,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:$A(c.type)?"num":void 0,children:c.label},c.key))})}),n.jsx("tbody",{children:o.map((c,u)=>n.jsx("tr",{children:t.map(h=>n.jsx(p3,{value:c[h.key],column:h},h.key))},u))})]})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}const u3=/^(title|name|headline|subject|label|heading)$/i,d3=/^(url|link|href|uri|permalink)$/i;function nh(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function h3(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function TA(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 Du(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 f3(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>d3.test(h.key)&&t.some(f=>nh(f[h.key])))??s.find(h=>{const f=t.map(m=>m[h.key]).filter(m=>!Ul(m));return f.length>0&&f.filter(nh).length/f.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>u3.test(h.key))??i.find(h=>Du(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,f)=>Du(t,f.key)-Du(t,h.key)),c=o[0]&&Du(t,o[0].key)>40?o[0]:null,u=e.filter(h=>h.key!==r.key&&h.key!==a.key&&h.key!==(c==null?void 0:c.key)).map(h=>h.key);return{url:r.key,title:a.key,description:(c==null?void 0:c.key)??null,meta:u}}function m3({label:e,plan:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=th+5?r:th,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[t.url],f=nh(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:f?TA(f):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=f?h3(f):null,v=t.meta.map(b=>c[b]).filter(b=>!Ul(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return n.jsxs("li",{className:"wb-record",children:[f?n.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[g?n.jsx("span",{className:"wb-record-host",title:f??void 0,children:g}):null,v.map((b,j)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},j))]}),p?n.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}function p3({value:e,column:t}){if(Ul(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(nh(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:TA(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:ss(e),children:i})}const s=zj(e,t.type,t.currency),r=s.length>Ok?`${s.slice(0,Ok-1)}…`:s;return n.jsx("td",{className:$A(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function $A(e){return e==="number"||e==="currency"}function zj(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":Zt(e,t==="text"?"text":t,s)}function vc(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,". "]}),vc(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=Mu?n.jsx(zk,{summary:`${e.length} items`,open:t===Mu,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:[wn(i),": "]}),vc(a,t+1)]},i))});return t>=Mu?n.jsx(zk,{summary:`${s.length} fields`,open:t===Mu,children:r}):r}function zk({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function g3({props:e}){const t=e.groups.every(s=>s.rows.length===0);return n.jsxs("div",{children:[e.summary.length>0?n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:s.label}),n.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:Zt(s.value,s.unit,s.currency)})]},s.label))}):null,t?n.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>n.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?n.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.columns.map(i=>n.jsx("th",{className:RA(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(x3,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function x3({cell:e}){const t=Zt(e.value,e.type,e.currency);return e.bar?n.jsx("td",{className:"num",children:n.jsxs("div",{className:"wb-row wb-row-end",children:[n.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t,children:n.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),n.jsx("span",{className:"tnum",children:t})]})}):n.jsx("td",{className:RA(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function RA(e){return e==="number"||e==="currency"||e==="percent"}const Uk={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 Bl(e){return(e&&Object.prototype.hasOwnProperty.call(Uk,e)?Uk[e]:void 0)??"dot"}function sh(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 rh="buddi:plugin-pages-changed";function v3(){window.dispatchEvent(new Event(rh))}function IA(e=!1){const[t,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>A.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(rh,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(rh,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:sh(t,"rail"),settings:sh(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}function PA(e,t){const s=(t??[]).filter(a=>a.plugin===e),r=sh(s,"rail")[0]??sh(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 hd=null;typeof window<"u"&&window.addEventListener(rh,()=>{hd=null});function j3(){return hd??(hd=Promise.resolve().then(()=>A.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(hd=null,[]))),hd}function Uj(e,t,s){return s==="settings"?Kr(e,t):hr(e,t)}function w3(e){const[t,s]=d.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return d.useEffect(()=>{if(!r||!i)return;let a=!1;return j3().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:Uj(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function MA({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(y3,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function y3({tile:e,picked:t,onPick:s}){const r=w3(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(ce,{name:Bl(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(cs,{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 $a=760,Mm=400,Ot={top:18,right:18,bottom:36,left:66},b3=5;function k3({props:e}){const{points:t,referenceLines:s,unit:r,currency:i}=e;if(t.length===0)return n.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const a=[...t.map(y=>y.y),...s.map(y=>y.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,f=$a-Ot.left-Ot.right,m=Mm-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)/(h-u)*m,v=qd(l,o,4),b=S3(t.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:C3(t.map(y=>y.y),e.shadeBelow),x=t.map((y,k)=>`${k===0?"M":"L"}${p(k)},${g(y.y)}`).join(" "),w=y=>Zt(y,r,i);return n.jsxs("div",{children:[e.label?n.jsx("p",{className:"ui-panel-sub",children:e.label}):null,n.jsxs("div",{className:"wb-chart-layout",children:[n.jsx("div",{className:"wb-chart-plot",children:n.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${$a} ${Mm}`,role:"img","aria-label":N3(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}`)),v.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Ot.left,x2:$a-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:$a-Ot.right,y1:g(y.value),y2:g(y.value)}),n.jsxs("text",{x:$a-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:$a-Ot.right,y1:Ot.top+m,y2:Ot.top+m}),n.jsx("path",{className:"wb-chart-series",d:x}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:g(t[b].y)+20,textAnchor:"middle",children:w(t[b].y)})]}):null,E3(t.length).map(y=>n.jsx("text",{x:p(y),y:Mm-10,textAnchor:"middle",children:Dg(t[y].x)},`x-${y}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,k)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Dg(y.at)}),y.label]}),y.amount===null?null:n.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:Zt(y.amount,r,i)})]},`${y.at}-${y.label}-${k}`))})]}):null]})]})}function N3(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 S3(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 C3(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 E3(e,t=b3){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 hs=e=>e,Qg={timeseries:hs(k3),table:hs(g3),bars:hs(G_),keyvalue:hs(OU),tiles:hs(MA),document:hs(zz),diff:hs(Z_),terminal:hs(zU),image:hs(DU),preview:hs(WU),envelope:hs($U),structured:hs(i3)},A3="structured";function T3(e){return(ih(e)?Qg[e]:void 0)??Qg[A3]}function ih(e){return Object.prototype.hasOwnProperty.call(Qg,e)}function $3({renderer:e,props:t,timezone:s,onDecided:r}){const i=T3(e),l=ih(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(Dm,{children:"Opens by default"}):null,n.jsx(Dm,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(Dm,{title:`A surface command that asks for "${s}" lands on this agent.`,children:wn(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(mo,{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(DA,{}),"Exact action"]})]})]})}),n.jsx(mo,{title:"What it can do",note:I3(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(P3,{family:s},s.family))}),n.jsx(mo,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(po,{label:"Provider",children:e.engine.provider}),n.jsx(po,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(po,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(po,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(po,{label:"Language",children:F3(e.engine.language)})]})}),e.skills.length>0?n.jsx(mo,{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(mo,{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 I3(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 P3({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:wn(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(M3,{tool:s},s.name))})]})}function M3({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:L3(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(DA,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:O3(e.tier),children:D3(e.tier)})]})}function D3(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function O3(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 L3(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function F3(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function mo({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 po({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 Dm({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function DA(){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 Bk=16e3,_3=10*6e4,z3="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",OA="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function U3(){const e=window;return e.AudioContext??e.webkitAudioContext}function B3(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?z3:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":OA}async function W3(e){var c;const t=U3();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(OA),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let f=0;for(let m=0;m<h.length;m++)f+=h[m]*h[m];e(Math.min(1,Math.sqrt(f/h.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),V3(K3(H3(l),u,Bk),Bk)},cancel:o}}function H3(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 K3(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 V3(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 Xg="buddi.readAloud";function LA(){try{return window.localStorage.getItem(Xg)==="on"}catch{return!1}}function FA(e){try{e?window.localStorage.setItem(Xg,"on"):window.localStorage.removeItem(Xg)}catch{}}let er=null,Do=null,jc=0,Zg=null;const ex=new Set;function ah(e){Zg!==e&&(Zg=e,ex.forEach(t=>t()))}function G3(){return Zg}function Y3(e){return ex.add(e),()=>ex.delete(e)}function _A(e){return Wl(),ah(e),jc}function Wk(e){return e===jc}function Wl(){jc++,er&&(er.pause(),er.removeAttribute("src")),Do&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Do),Do=null,ah(null)}async function q3(e,t,s=null){var i;const r=_A(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!==jc)return;er||(er=new Audio,(i=er.addEventListener)==null||i.call(er,"ended",()=>ah(null))),Do=URL.createObjectURL(l),er.src=Do,await er.play()}catch(a){throw r===jc&&ah(null),a}}const J3=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function zA(e){return J3.has(e.toLowerCase().split(";")[0].trim())}function Hk(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 UA({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=d.useRef(null),a=d.useRef(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(0),[g,v]=d.useState(null);d.useEffect(()=>()=>{var x;(x=i.current)==null||x.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const x=i.current;if(x){if(l){x.pause();return}Wl(),f(!1);try{if(!a.current){u(!0);const w=await fetch(Ni(e),{credentials:"same-origin"});if(!w.ok)throw new Error(String(w.status));a.current=URL.createObjectURL(new Blob([await w.arrayBuffer()],{type:s})),x.src=a.current}await x.play()}catch{f(!0)}finally{u(!1)}}},j=h?"Could not play. Download it instead.":`${Hk(m)} / ${Hk(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(ce,{name:l?"pause":"play",size:14})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:t,children:t}),n.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[c?"Loading…":j,!h&&Kn(r)?` · ${Kn(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:Ni(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(ce,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:x=>p(x.currentTarget.currentTime),onLoadedMetadata:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null),onDurationChange:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null)})]})}const Om=1e5,Lm=200,Fm=30;function BA({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=d.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:Vr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&zA(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(UA,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:Vr(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]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return a("loading"),fetch(Vr(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,Om),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Om})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(pe,{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(Z3,{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 ",Om.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 h=()=>{a.length<r?a.push(l):c=!0,l=""},f=()=>{h(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===t){h();continue}if(p!=="\r"){if(p===`
|
|
95
|
+
`){f();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&f(),{rows:i,truncatedRows:u,truncatedCols:c}}function Z3({text:e,delimiter:t}){const s=d.useMemo(()=>X3(e,t,Lm+1,Fm),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(Fm,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,Lm).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 ",Lm," rows",s.truncatedCols?` and ${Fm} columns`:"",". The download has the whole file."]}):null]})}function e6({attachment:e}){const t=Lj(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(BA,{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:[ea[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:Kn(e.sizeBytes)})]}):null,n.jsx("dt",{children:"Id"}),n.jsx("dd",{className:"mono",children:e.artifactId})]}),n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx("a",{className:"ui-btn",href:Ni(e.artifactId),download:s,children:"Download"})})]})}const Kk=80,t6=["query","path","url","dir"],n6=["message","task"];function Bj(e,t){const s=s6(t);if(!s)return null;const r=Ra(s.command);if(r!==null){const l=Ra(s.name);return Ou(l===null?r:`${l}: ${r}`)}for(const l of t6){const o=Ra(s[l]);if(o!==null)return Ou(o)}const i=Ra(s.action);if(i!==null){const l=n6.map(o=>Ra(s[o])).find(o=>o!==null)??null;return Ou(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?Ou(Ra(a[0])):null}function Ra(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function Ou(e){return e===null?null:e.length>Kk?`${e.slice(0,Kk-1)}…`:e}function s6(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const WA="owner.notify",Cr=e=>typeof e=="string"&&e.trim()!==""?e:null;function r6(e){const t=e!==null&&typeof e=="object"?e:{};return{title:Cr(t.title)??"(no title)",text:Cr(t.text),urgency:Cr(t.urgency)??"now",key:Cr(t.key),link:Cr(t.link)}}function HA(e){if(e===null||typeof e!="object")return Cr(e);const t=e;return Cr(t.delivered)??Cr(t.message)??Cr(t.error)}function i6(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 Si="agent.delegate";function a6(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 l6(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 tx="canvas.show",Vk="canvas.clear",Gk=12;function ll(e){return`${e.plugin}/${e.name}`}function o6(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function c6({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=dA(o,KA(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function u6({messages:e,descriptors:t,awaiting:s,folded:r,served:i}){var u;const a=new Map(t.map(h=>[h.tool,h])),l=new Map;let o=[],c=0;for(const h of e)for(const f of h.blocks??[]){if(f.type==="tool_use"){if(l.set(f.id,{name:f.name,input:f.input,at:h.at??null}),f.name===tx){const y=h6(f.id,f.input,h.at??null);y&&o.push(y)}if(f.name===Vk&&(o=[]),f.name===Si){const y=a6(f.input);y&&o.push({id:f.id,tool:Si,title:"Delegation",renderer:"delegate",props:{...y,result:null},at:h.at??null,source:"delegate",substantial:!0})}continue}if(f.type!=="tool_result"||f.name===tx||f.name===Vk)continue;const m=l.get(f.toolUseId),p=h.at??(m==null?void 0:m.at)??null,g=f.name||(m==null?void 0:m.name)||"tool",v=o.find(y=>y.source==="delegate"&&y.id===f.toolUseId);if(v&&((u=f.delegation)==null?void 0:u.state)==="waiting"){v.props={...v.props,result:null,waiting:{approvalId:f.delegation.approvalId}},f.delegation.approvalId&&(v.tone="warning");continue}if(v){v.props={...v.props,result:{ok:f.ok,text:l6(f.ok?f.output:f.error??f.output),...f.ok&&eh(f.output).length>0?{files:eh(f.output)}:{}}},f.ok||(v.tone="critical");continue}const b=f.approval?sx(f):(s==null?void 0:s.get(f.toolUseId))??sx(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===WA){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=KA(f.output);if(f.ok===!1){o.push({id:f.toolUseId,tool:g,title:or(g),renderer:"structured",props:{value:f.error??j??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}o6(j)&&(c+=1);const x=a.get(g);if(x){const y=dA(x,j),{renderer:k}=y;let{props:N}=y;if(k==="preview"){const S=N,C=S.target??(S.awaiting&&(i!=null&&i.has(ll(S.awaiting)))?S.awaiting:null);if(C===null)continue;N={...S,target:C,awaiting:null};const T=ll(C);o=o.filter(R=>!(R.source==="descriptor"&&R.renderer==="preview"&&R.props.target!==null&&ll(R.props.target)===T))}o.push({id:f.toolUseId,tool:g,title:x.title??or(g),renderer:k,props:N,at:p,source:"descriptor",substantial:nx(k,N)});continue}const w={value:_j(j)?{input:m==null?void 0:m.input,output:j}:j};f6("structured",w)&&o.push({id:f.toolUseId,tool:g,title:or(g),renderer:"structured",props:w,at:p,source:"fallback",substantial:nx("structured",w)})}for(const h of o)h.source==="descriptor"&&h.renderer==="preview"&&(h.props={...h.props,changes:c});return d6(o)}const Yk="forAgent";function KA(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(Yk in e))return e;const{[Yk]:t,...s}=e;return s}function d6(e){if(e.length<=Gk)return e;const t=e.length-Gk;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function h6(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&ih(r)?r:"structured";return{id:e,tool:tx,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!ih(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function f6(e,t){const s=t??{};return!!(s.failed===!0||nx(e,t)||Fj(s.value).kind==="error")}function nx(e,t){const s=t??{};switch(e){case"timeseries":return go(s.points)>0;case"bars":return go(s.bars)>0;case"keyvalue":return go(s.pairs)>0;case"tiles":return s.notice!==!0&&go(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=>go(i.rows)>0);default:return _j(s.value)?!0:s.failed===!0?!1:n3(s.value)}}function go(e){return Array.isArray(e)?e.length:0}function sx(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=GA(t,0);if(s)return s}return null}function m6(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)?VA(i.input):i.input;return{id:t,tool:i.name,title:or(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 p6=new Set(["value","text","password","secret","code"]);function VA(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=p6.has(s)&&typeof r=="string"?"— withheld —":VA(r);return t}function GA(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=GA(a,t+1);if(l)return l}return null}function or(e){const t=e.split(".");return t.length===1?wn(e):t.map(s=>wn(s)).join(" · ")}function vf({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=Lj(t,e),h=[ea[u],Kn(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(Wj,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":h})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:f}):n.jsx("span",{className:"wb-file-open",children:f}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Wj({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 g6(e,t,s){const r=Jk(e),i=Jk(t==null?void 0:t.input),a=zi(r==null?void 0:r.name)??y6(zi(r==null?void 0:r.handle))??zi(r==null?void 0:r.agent)??zi(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:zi(r==null?void 0:r.text)??zi(r==null?void 0:r.note),o=qk(r==null?void 0:r.durationMs)??qk(r==null?void 0:r.elapsedMs),c=t!=null&&t.at?Date.parse(t.at):NaN,u=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:a,question:zi(i==null?void 0:i.task),answer:l,files:eh(e),durationMs:o??h}}function x6(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===Si&&((r=a.delegation)==null?void 0:r.approvalId)===t&&(s=a.toolUseId);if(s===null)return null;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===s)return{input:a.input,at:i.at||null};return null}function v6({block:e,messages:t,answeredAt:s}){const r=g6(e.output,x6(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${j6(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(fr,{text:r.answer})}):n.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(a=>n.jsx("a",{role:"listitem",href:Ni(a.artifactId),download:!0,children:n.jsx(vf,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:Oj(a.mime)?Vr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(At,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:w6(e.output)})})]})}function j6(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 w6(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function y6(e){return e===null?null:`@${e.replace(/^@/,"")}`}function zi(e){return typeof e=="string"&&e.trim()!==""?e:null}function qk(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Jk(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const b6=1e3;function k6({messageId:e,text:t,onReadAloud:s}){const[r,i]=d.useState(!1),a=d.useRef(null),l=d.useSyncExternalStore(Y3,G3)===e;d.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),b6)},()=>{})};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(ce,{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?Wl():s(e,t),children:n.jsx(ce,{name:l?"stop":"play",size:14})}):null]})}function N6(e){const t=S6(e);if(!t)return null;const s=_m(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=_m(t.command),i=_m(t.plain),a=zm(t.exitCode);return r!==null&&(i!==null||a!==null||zm(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:zm(t.elapsedMs)}:null}function _m(e){return typeof e=="string"&&e.trim()!==""?e:null}function zm(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function S6(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const Qk="offer:",YA="owner:interjection";function C6(e){return e===YA}function E6(e){if(typeof e!="string"||!e.startsWith(Qk))return null;const t=e.slice(Qk.length).trim();return t===""?null:t}const Xk="brief:";function A6(e){if(typeof e!="string"||!e.startsWith(Xk))return null;const t=e.slice(Xk.length).trim();return t===""?null:t}function Hj({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:v,empty:b,plain:j=!1,workingLine:x,runs:w,onContinue:y}){var F;const k=d.useRef(null);d.useEffect(()=>{var X;(X=k.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 N=a&&!a.settled&&(a.text!==""||a.thinking!==""),S=e.filter(X=>(X.blocks??[]).some(_6)),C=L6(S,w??[]),T=c??l??[],R=X=>(o&&!c?T.find(Q=>Q.id===o):void 0)??T.find(Q=>Q.name===X)??null,I=o?T.find(X=>X.id===o)??null:null,L=i||t.length>0,W=L||!!N,$=!!N&&a.text!=="",P=L&&!$,O=S.at(-1),M=(O==null?void 0:O.role)!=="assistant"||!!h,D=h??g??"Assistant",H=S.filter((X,Q)=>{var ee;return Q===0||(c?(((ee=S[Q-1])==null?void 0:ee.speaker)??null)!==(X.speaker??null):S[Q-1].role!==X.role)}),U=W&&!M?((F=H.at(-1))==null?void 0:F.id)??null:null,q=(w??[]).reduce((X,Q)=>X===null||(Q.startedAt??"")>(X.startedAt??"")?Q:X,null),B=(w??[]).some(X=>X.finishedAt===null),Y=y&&!W&&!B&&O&&(q==null?void 0:q.stopped)==="max_turns"&&C.get(O.id)===q?O.id:null;return n.jsx(oA.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:v}):null,S.map((X,Q)=>{const ee=X.speaker??null,fe=c?ee==="owner"||ee===null&&X.role==="user":X.role==="user",Oe=c&&ee==="room",Ie=c&&ee&&ee!=="owner"&&ee!=="room"?c.find(Ne=>Ne.id===ee)??null:null,Fe=S[Q-1],z=Q===0||(c?((Fe==null?void 0:Fe.speaker)??null)!==ee:Fe.role!==X.role);if(Oe)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(X.blocks??[]).filter(Ne=>Ne.type==="text").map((Ne,Ue)=>n.jsx("span",{children:Ne.text},Ue))},X.id);const ne=(X.blocks??[]).filter(Ne=>Ne.type==="approval_result");if(ne.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:ne.map((Ne,Ue)=>n.jsx(z6,{block:Ne,messages:e,at:X.at||null},Ue))},X.id);const J=X.role==="user"&&C6(ee),ye=X.role==="user"?A6(ee):null;if(ye)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:ye})},X.id);const ge=X.role==="user"?E6(ee):null;if(ge){const Ne=(X.blocks??[]).filter(Ue=>Ue.type==="text").map(Ue=>Ue.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:Ne,children:ge})},X.id)}const $e=c&&Ie&&X.role==="user"?M6(X):null;if($e){const Ne=S.slice(Q+1).find(at=>at.role==="assistant"&&at.speaker&&at.speaker!==Ie.id),Ue=Ne!=null&&Ne.speaker?c.find(at=>at.id===Ne.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 ",(Ue==null?void 0:Ue.name)??"a member",$e.request?`: ${$e.request.length>120?`${$e.request.slice(0,119)}…`:$e.request}`:""]}),$e.request?n.jsx("p",{children:$e.request}):null]},X.id)}const De=C.get(X.id)??null,Je=O6(X,e),ze=!fe&&!J&&!j?D6(X):"";return n.jsxs("div",{className:"wb-msg","data-role":fe||J?"user":"assistant",children:[J?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,z&&!fe&&!J?n.jsx(Zk,{name:Ie?Ie.name:c&&ee&&ee!=="owner"&&ee!=="room"?ee:g??"Assistant",face:Ie??I??R(g),moving:P&&U===X.id,children:Ie&&u===Ie.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Je.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Je.map(Ne=>n.jsx("span",{role:"listitem",children:zA(Ne.mime)?n.jsx(UA,{artifactId:Ne.artifactId,name:Ne.filename??"Untitled file",mime:Ne.mime,sizeBytes:Ne.sizeBytes}):n.jsx(vf,{name:Ne.filename??"Untitled file",mime:Ne.mime,sizeBytes:Ne.sizeBytes,thumbnail:Oj(Ne.mime)?Vr(Ne.artifactId):null,...f?{onOpen:()=>f(Ne)}:{}})},Ne.artifactId))}):null,(X.blocks??[]).map((Ne,Ue)=>{const at=R6(X.blocks??[],Ue,e);if(at==="inside")return null;if(at)return n.jsx(I6,{refusals:at.refusals},Ue);if(Ne.type==="thinking")return j||Ne.text.trim()===""?null:n.jsx(rx,{text:Ne.text},Ue);if(Ne.type==="text")return Ne.text.trim()===""?null:fe?n.jsx("div",{className:"wb-bubble",children:Ne.text},Ue):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(fr,{text:Ne.text})},Ue);if(Ne.type==="attachment")return null;if(Ne.type==="tool_use"){if(j)return null;const Ye=Kj(e,Ne.id),kt=Ye?W6(Ye):null,Gt=!kt&&Ne.name===WA&&Ye?HA(Ye.output):null;return n.jsx(ix,{label:kt&&!(Ye!=null&&Ye.delegation)?`Approval · ${Ne.name}`:or(Ne.name),tool:Ne.name,ok:(Ye==null?void 0:Ye.ok)??null,running:Ye===null,...kt?{status:kt.status,waiting:kt.waiting,approval:!0}:Gt?{status:Gt}:{},gist:Bj(Ne.name,Ne.input),body:Ye?N6(Ye.output):null,opens:!0,onOpen:()=>r(Ne.id)},Ue)}return null}),De?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:F6(De)}),Y===X.id?n.jsx(E,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,X.feedback&&!fe&&!J?n.jsx(V6,{feedback:X.feedback}):null,ze!==""?n.jsx(k6,{messageId:X.id,text:ze,onReadAloud:m}):null]},X.id)}),W?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[M?n.jsx(Zk,{name:D,face:R(D)??I,moving:P}):null,N&&a.thinking!==""&&!j?n.jsx(rx,{text:a.thinking,live:a.text==="",seconds:P6(a.thinkingStartedAt,a.textStartedAt??s)}):null,$?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(fr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!N?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[x??`${h??g??"The agent"} is working`,n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):null,t.map(X=>n.jsx(ix,{label:or(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:k})]})})}function Zk({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=iA(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(Hc,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(bn,{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 T6(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 $6="delegation refused:";function R6(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==Si)return null;const o=Kj(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($6))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 I6({refusals:e}){const[t,s]=d.useState(!1),r=e.map(o=>T6(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(ce,{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:[or(Si)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function P6(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function rx({text:e,live:t=!1,seconds:s=null}){const[r,i]=d.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(ce,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(fr,{text:e})}):null]})}function M6(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 D6(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
|
|
97
|
+
|
|
98
|
+
`)}function O6(e,t){const s=[],r=new Set,i=a=>{r.has(a.artifactId)||(r.add(a.artifactId),s.push(a))};for(const a of e.blocks??[])if(a.type==="attachment"&&i(a),a.type==="tool_use"&&a.name===Si){const l=Kj(t,a.id);l!=null&&l.ok&&eh(l.output).forEach(i)}return s}function L6(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 F6(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 _6(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function z6({block:e,messages:t,at:s}){const[r,i]=d.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":or(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===Si?n.jsx(v6,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==Si?n.jsx("pre",{className:"wb-approval-output mono",children:U6(e.output)}):null]})}function U6(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const B6=40;function W6(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(sx(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 ix({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:f=null}){const[m,p]=d.useState(!1),g=n.jsxs(n.Fragment,{children:[r?n.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):n.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e}),h?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,i===void 0?null:n.jsxs("span",{className:"wb-tool-elapsed",children:[i,"s"]}),o||s===!1?n.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),v={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return f?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...v,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(ce,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(ac,{children:[n.jsx(lc,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(oc,{children:n.jsxs(cc,{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(H6,{body:f,onOpen:a?l:null}):null]}):a?n.jsxs(ac,{children:[n.jsx(lc,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...v,onClick:l,children:[g,n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(oc,{children:n.jsxs(cc,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):n.jsx("span",{className:"wb-tool","data-static":"true",...v,children:g})}function H6({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(Jd,{text:e.diff,limit:B6,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:K6(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 K6(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Kj(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 V6({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 qA="approval-dock";function G6(){var t;const e=document.getElementById(qA);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const Y6=["workspace","cwd","workdir","root"];function q6({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=d.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(J6,{item:h,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function J6({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState("");d.useEffect(()=>{let T=!1;return A.approval(e.approvalId).then(R=>{T||(u(R),R.state!=="pending"&&a(R))}).catch(R=>{T||f(R instanceof ve?R.message:String(R))}),()=>{T=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;d.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:j,controls:x}=Mj(c==null?void 0:c.choices),w=(T,R)=>{const I=g.trim();p(T),f(null),(j&&T==="approve"?A.decide(e.approvalId,T,R,j):A.decide(e.approvalId,T,R)).then(L=>{a(L.action),I&&l(I)}).catch(L=>{f(L instanceof ve?L.message:String(L)),p(null)})},y=m!==null||c===null||c.state!=="pending",k=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,N=c?Bj(c.tool,c.canonicalArgs)??X6(c.preview):null,S=c?Q6(c):null;return n.jsxs("section",{id:qA,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?or(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),N||S?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[N?n.jsx("code",{className:"wb-dock-gist",children:N}):null,S?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:S})]}):null]}):null,x?n.jsx("div",{className:"wb-dock-section",children:x}):null,n.jsx(ie,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:T=>v(T.target.value),onKeyDown:T=>{T.key==="Enter"&&T.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(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),k?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),n.jsx(E,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,n.jsx(E,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":k?"Allow once":"Approve"})]})]})}function Q6(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of Y6){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function X6(e){const t=(e??"").split(`
|
|
99
|
+
`).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const Z6=2e3;function eB({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=d.useState(l),u=!o||i!==null,{data:h,error:f}=de(()=>He.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?Z6:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(y=>y.runId===s)??null,g=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(y=>y.finishedAt!==null));d.useEffect(()=>{g&&c(!0)},[g]);const v=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":g?"done":"working",b=a.find(y=>y.id===t)??null,j=(b==null?void 0:b.name)??(h==null?void 0:h.agentId)??t,x=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??tB(x);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":v,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(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":v,role:"status",children:v==="working"?n.jsxs(n.Fragment,{children:["Working",n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):v==="waiting"?"Waiting for your approval":v==="failed"?"Failed":"Done"})]})]}),f?n.jsx("p",{className:"muted",children:f}):null,n.jsx("div",{className:"wb-delegate-work",children:x.map((y,k)=>n.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((N,S)=>{if(N.type==="thinking")return N.text.trim()===""?null:n.jsx(rx,{text:N.text},S);if(N.type==="tool_use"){const C=sB(nB(x,N.id));return n.jsx(ix,{label:or(N.name),tool:N.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Bj(N.name,N.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??k))}),w?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(fr,{text:w})}):v==="working"||v==="waiting"?n.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(y=>n.jsx("a",{role:"listitem",href:Ni(y.artifactId),download:!0,children:n.jsx(vf,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Oj(y.mime)?Vr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[v==="waiting"?n.jsx(E,{variant:"accent",onClick:()=>G6(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:st(t||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function tB(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 nB(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 sB(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 e0=1024*1024;function rB({files:e,agentId:t,root:s,revision:r}){const[i,a]=d.useState({kind:"dir",path:""});return d.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(iB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(aB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function JA({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 iB({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null);d.useEffect(()=>{let b=!1;return u(null),A.pageQuery(e.plugin,e.list,{agent:t,...r?{path:r}:{}}).then(j=>{b||o(j.data)}).catch(j=>{b||u(j instanceof Error?j.message:String(j))}),()=>{b=!0}},[e.plugin,e.list,t,r,i]),d.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const b=await fetch(A.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const y=await b.json().catch(()=>null);p((y==null?void 0:y.error)??"The archive could not be made.");return}const j=await b.blob(),x=URL.createObjectURL(j),w=document.createElement("a");w.href=x,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(x),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},v=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(JA,{root:s,path:r,go:a}),n.jsx(dt,{}),n.jsx(E,{size:"sm",onClick:()=>void g(),disabled:h||v===null||v.length===0,children:h?"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,v===null?c?null:n.jsx(pe,{children:"Reading the folder…"}):v.length===0?n.jsx(pe,{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:Hr,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(rt,{children:v.map(b=>n.jsx(et,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(oB,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?Kn(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 aB({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1);d.useEffect(()=>{let j=!1;return u(null),A.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(x=>{j||o(x.data)}).catch(x=>{j||u(x instanceof Error?x.message:String(x))}),()=>{j=!0}},[e.plugin,e.stat,t,r,i]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",v=A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=e0;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(JA,{root:s,path:r,go:a}),n.jsx(dt,{}),b?n.jsx(E,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,n.jsx(Et,{size:"sm",href:v,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(pe,{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(lB,{src:g,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(G,{children:m.type==="text"?`This file is over ${Kn(e0)}, 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(Ht,{items:[{label:"Size",value:Kn(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function lB({src:e,wrap:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1);return d.useEffect(()=>{let l=!1;return a(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(G,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(pe,{children:"Reading the file…"}):s===""?n.jsx(pe,{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 oB({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 cB({input:e,output:t,ok:s}){const r=r6(e),i=HA(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(we,{tone:i6(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(At,{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 uB=3,dB=152,hB=104,fB=100,mB=2,t0=5;function pB({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:f,agents:m,onClose:p,loading:g=!1}){const[v,b]=gB(h);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:v,"aria-hidden":"true",children:n.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),n.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:g?null:n.jsxs("div",{className:"wb-empty",children:[l?n.jsx("span",{className:"wb-empty-face",children:l}):null,n.jsx("p",{className:"ui-empty wb-empty-line",children:yB(u,bB(o??[],c??[]))})]})})]});const j=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:x,hidden:w}=xB(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:v,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(B_,{className:"wb-tabstrip","aria-label":"Canvas",children:x.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(W_,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:k=>{k.key==="Delete"&&p&&n0(y)&&(k.preventDefault(),p(y.id))},children:[y.tone==="warning"||y.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":y.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:y.title})]}),p&&n0(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(vB,{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":NB.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(e6,{...y.props}):y.source==="files"?n.jsx(rB,{...y.props}):y.source==="notify"?n.jsx(cB,{...y.props}):y.source==="delegate"?n.jsx(eB,{...y.props,agents:m??[]}):n.jsx($3,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function n0(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function gB(e){const[t,s]=d.useState(t0),r=d.useRef(null);return[d.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-fB-hB)/dB);s(Math.max(mB,Math.min(t0,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function xB(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 vB({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(Lc,{modal:!1,children:[n.jsx(Fc,{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(ce,{name:"chevron-down"})]})}),n.jsx(_l,{children:n.jsxs(_c,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(ca,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(xs,{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:jB(i.at,s)??i.tool})]},i.id))]})})]})}function jB(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Vt(s,t)}const wB={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 yB(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>wB[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function bB(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=kB(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,uB)}function kB(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 NB=new Set(["table","diff","files"]),SB=3.5*6e4,CB=2e3;function EB(e,t,s={}){const[r,i]=d.useState({served:new Set,live:new Set,scope:t}),a=d.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??A.previewCheck,o=s.everyMs??CB,c=e.map(u=>`${ll(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const g=ll(p);if(a.current.has(g))continue;const v=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(v)?0:v+SB,j=u.get(g);(!j||b>j.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let h=!1,f;const m=async()=>{const p=Date.now();for(const[g,v]of[...u]){const b=await l(v.plugin,v.name).catch(()=>null);if(h)return;const j=p<=v.until;b!=null&&b.ok?(u.delete(g),i(x=>{const w={served:new Set(x.served).add(g),live:j?new Set(x.live).add(g):x.live,scope:x.scope};return a.current=w.served,w})):j||u.delete(g)}!h&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,t,l,o]),r}const ax="workspace-files";function AB(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 TB(e){const[t,s]=d.useState(null);return d.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await A.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await A.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function $B(e,t){return{id:ax,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 lx(e){return`agent-properties:${e}`}function RB(e){return{id:lx(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function IB(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 QA({progress:e}){return n.jsxs(le,{gap:"sm",children:[n.jsx("span",{role:"status",children:IB(e)}),n.jsx(vA,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function PB(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(h,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function Um(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function s0(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const MB=4e3;function DB(e){return e.replace(/\r\n?/g,`
|
|
104
|
+
`).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,MB)}const OB=["left","middle","right"],LB=33;function FB(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function _B(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 zB(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function UB({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=d.useState("connecting"),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(!1),[g,v]=d.useState(0),b=d.useRef(null),j=d.useRef(null),x=d.useRef(null),w=d.useRef({at:0});d.useEffect(()=>{const $=r??(M=>new WebSocket(M));let P=!0,O;try{O=$(zB())}catch{a("lost");return}return O.binaryType="arraybuffer",b.current=O,O.onopen=()=>O.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),O.onmessage=M=>{if(!P)return;if(typeof M.data!="string"){const H=_B(M.data);if(!H||(f(U=>U&&FB(U,H.metadata)?U:H.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(H.jpeg).then(U=>{var B,Y,F;const q=j.current;if(!P||!q){(B=U.close)==null||B.call(U);return}(q.width!==U.width||q.height!==U.height)&&(q.width=U.width,q.height=U.height),(Y=q.getContext("2d"))==null||Y.drawImage(U,0,0),(F=U.close)==null||F.call(U)}).catch(()=>{});return}const D=JSON.parse(M.data);if(D.type==="driving"){a("driving"),o(null);return}(D.type==="refused"||D.type==="ended")&&(o(D.error??"The screen cannot be driven from here."),a("refused"))},O.onclose=()=>{P&&a(M=>M==="refused"?M:"lost")},O.onerror=()=>{P&&a(M=>M==="refused"?M:"lost")},()=>{P=!1,b.current=null;try{O.close()}catch{}}},[e,t,g,r]),d.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=d.useCallback($=>{const P=b.current;if(P)try{P.send(JSON.stringify({type:"input",input:$}))}catch{}},[]),k=$=>{var M;const P=j.current;if(!P||!h)return null;const O=(M=P.getBoundingClientRect)==null?void 0:M.call(P);return O?PB(O,h,$.clientX,$.clientY):null},N=$=>{const P=w.current,O=Date.now();clearTimeout(P.timer),P.timer=void 0;const M=P.at+LB-O;if(M<=0){P.at=O,P.pending=void 0,y($);return}P.pending=$,P.timer=setTimeout(()=>{const D=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),D&&y(D)},M)},S=()=>{const $=w.current;clearTimeout($.timer),$.timer=void 0;const P=$.pending;$.pending=void 0,P&&($.at=Date.now(),y(P))},C=$=>P=>{var D,H;const O=k(P);if(!O)return;$==="mousePressed"&&(P.preventDefault(),(H=(D=j.current)==null?void 0:D.focus)==null||H.call(D));const M={kind:"mouse",type:$,x:O.x,y:O.y,button:OB[P.button]??"left",clickCount:$==="mouseMoved"?0:Math.min(3,Math.max(1,P.detail||1)),modifiers:Um(P)};if($==="mouseMoved"){N(M);return}S(),y(M)},T=$=>{const P=k($);P&&(S(),y({kind:"wheel",x:P.x,y:P.y,deltaX:Math.round($.deltaX),deltaY:Math.round($.deltaY)}))},R=$=>$.ctrlKey||$.metaKey||$.altKey,I=$=>{var O,M;if($.key==="Escape"&&R($)){p(!1),(M=(O=$.target).blur)==null||M.call(O);return}if($.preventDefault(),($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))return;const P=Um($);if(s0($.key)&&!R($)){y({kind:"key",type:"char",key:$.key,code:$.code,text:$.key,modifiers:P});return}y({kind:"key",type:"keyDown",key:$.key,code:$.code,modifiers:P})},L=$=>{$.key==="Escape"&&R($)||($.preventDefault(),!(($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))&&(s0($.key)&&!R($)||y({kind:"key",type:"keyUp",key:$.key,code:$.code,modifiers:Um($)})))},W=$=>{var O;$.preventDefault();const P=DB(((O=$.clipboardData)==null?void 0:O.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(E,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var P,O,M,D;const $=!m;p($),$?(O=(P=x.current)==null?void 0:P.focus)==null||O.call(P):(D=(M=x.current)==null?void 0:M.blur)==null||D.call(M)},children:"Keyboard"}),n.jsx(E,{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(E,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),v($=>$+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:T,onKeyDown:I,onKeyUp:L,onPaste:W,onContextMenu:$=>$.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.jsx("input",{ref:x,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:I,onKeyUp:L,onPaste:W,onBlur:()=>p(!1)})]})}function BB(e){return e==="darwin"?"this Mac":"this computer"}let Bm=null;function jf(){const[e,t]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return Bm??(Bm=A.session().then(r=>r.platform,()=>{Bm=null})),Bm.then(r=>{s&&t(r)}),()=>{s=!1}},[]),BB(e)}function WB({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=de(()=>A.browser(),[],3e3),a=de(()=>A.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(Pn,{embedded:e,title:"Computer & browser",children:[n.jsx(ie,{message:r}),!s||!o?n.jsx(pe,{children:"Checking the host…"}):n.jsx(HB,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function HB({data:e,macOS:t,reload:s,timezone:r}){var S,C,T;const[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,f=(h==null?void 0:h.mode)??(!t&&e.mode==="computer"?"playwright":e.mode),m=f==="computer",p=(S=e.sessions)!=null&&S.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,v=async R=>{a(!0),o(null);try{await R()}catch(I){o(I instanceof Error?I.message:String(I))}finally{a(!1),s()}},b=R=>void v(()=>A.browserSettings(R)),j=e.permissions,x=f==="playwright"?e.browser:void 0,w=((C=x==null?void 0:x.install)==null?void 0:C.state)==="running",y=(x==null?void 0:x.engine)==="none",k=!!e.enabled&&!y&&!(x!=null&&x.problem)&&(!m||!(j!=null&&j.supported)||j.accessibility&&j.screenRecording),N=m?"Ready. Agents can use your computer within the apps you allow below.":f==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(x==null?void 0:x.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(le,{gap:"lg",children:[n.jsx(ie,{message:l}),n.jsx(ue,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",disabled:i,onClick:()=>void v(()=>A.computerPermissions(!1)),children:"Check again"}),m&&!k&&(j!=null&&j.supported)?n.jsx(E,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void v(()=>A.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(E,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void v(()=>A.browserInstall()),children:w?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(le,{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."]}):x!=null&&x.problem?n.jsx(G,{tone:"warning",children:x.message}):k?n.jsx(G,{tone:"good",children:N}):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(we,{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(we,{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,((T=x==null?void 0:x.install)==null?void 0:T.state)==="running"?n.jsx(QA,{progress:x.install.progress}):x!=null&&x.install?n.jsx("p",{className:"muted",role:"status",children:x.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${x.install.line??"no reason given"}`}):null,x!=null&&x.headless&&!y?n.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&(j!=null&&j.message)?n.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!k?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(ue,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(E,{variant:"danger",size:"sm",disabled:i,onClick:()=>void v(()=>A.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):n.jsx("div",{className:"ui-list",children:p.map(R=>n.jsxs("a",{className:"ui-list-row",href:st(R.session.agentId,R.session.conversationId),children:[n.jsx(bn,{id:R.session.agentId,name:R.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:R.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[R.session.agentId,", ",R.busy?"working":R.state,", ",R.session.steps," of ",R.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},R.session.id))})}),h?n.jsxs(n.Fragment,{children:[n.jsx(ue,{title:"How agents get a screen",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(Wm,{current:h.mode,value:"computer",disabled:i||g||!e.enabled,title:"Use my apps",body:"Agents work in your own windows, signed in as you, in the browser profile you choose below. One agent at a time. Releasing control leaves everything open.",onPick:()=>b({...h,mode:"computer"})}):null,n.jsx(Wm,{current:h.mode,value:"playwright",disabled:i||g||!e.enabled,title:"Give agents their own browser",body:"A separate browser profile with its own tabs, one per conversation. Your apps are never touched.",onPick:()=>b({...h,mode:"playwright"})}),n.jsx(Wm,{current:h.mode,value:"extension",disabled:i||g||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...h,mode:"extension"})})]}),t?null:n.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),g?n.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,h.mode==="extension"?n.jsx(ZB,{busy:i,timezone:r}):null]})}),t?n.jsx(ue,{title:"Apps agents may use",panel:!0,children:n.jsxs(le,{children:[h.mode!=="computer"?n.jsx("p",{className:"muted",children:"Only used by “Use my apps”. The list is kept for when you switch back."}):null,n.jsx(e5,{settings:h,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(At,{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(i5,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:R=>{u(!1),h.allowedApps.includes(R)||b({...h,allowedApps:[...h.allowedApps,R]})}}):null]}):null]})}const KB="kmbckpnnjfggeffkkbmkggojnolkdokb",VB="pbfpjefkiijjgefblpnlnlpmeaddfbah",GB="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",YB=[KB,VB].filter(Boolean);function qB(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 JB(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of YB)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 QB(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 XB(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function ZB({busy:e,timezone:t}){const{data:s,error:r,reload:i}=de(()=>A.extension(),[],3e3),a=jf(),l=de(()=>JB(),[],3e3).data??null,[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";d.useEffect(()=>{p&&c(p)},[p]);const g=async w=>{h(!0),m(null);try{await w()}catch(y){m(y instanceof Error?y.message:String(y))}finally{h(!1),i()}},v=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,j=QB(),x=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(le,{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(Et,{variant:"accent",href:GB,target:"_blank",rel:"noopener noreferrer",children:"Add to Chrome"})]}),n.jsx(At,{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(Pt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]})})]});return n.jsxs(le,{divided:!0,children:[n.jsx(ie,{message:r??f}),n.jsxs(ae,{children:[n.jsx(we,{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(le,{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)&&qB(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&&!XB(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(oe,{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(E,{variant:"accent",disabled:v||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await A.pairExtension(o),c("")}),children:"Pair"})]}):null,x?s!=null&&s.connected?n.jsx(At,{summary:"Pair a different browser",children:x}):x:null,n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"danger",disabled:v||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>A.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 e5({settings:e,disabled:t,onChange:s,onAdd:r}){const i=de(()=>A.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(pe,{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(bn,{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(we,{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&&r5(l)?n.jsx(E,{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(E,{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(E,{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"&&t5.includes(e.browserApp)?n.jsx(n5,{settings:e,disabled:t,onChange:s}):null]})}const t5=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function n5({settings:e,disabled:t,onChange:s}){var l;const i=((l=de(()=>A.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(oe,{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 s5=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function r5(e){return s5.includes(e)}function i5({chosen:e,onClose:t,onPick:s}){const r=de(()=>A.installedApps(),[]),[i,a]=d.useState(""),[l,o]=d.useState(""),c=d.useMemo(()=>{var f;const u=((f=r.data)==null?void 0:f.apps)??[],h=i.trim().toLowerCase();return u.filter(m=>!h||m.name.toLowerCase().includes(h)||m.id.toLowerCase().includes(h)).slice(0,60)},[r.data,i]);return n.jsxs(qe,{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(ie,{message:r.error}),r.data?c.length===0?n.jsx(pe,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const h=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(bn,{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(E,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(pe,{children:"Reading your Applications folder…"}),n.jsx(At,{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(E,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function a5({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var W,$,P;const[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(!1),w=jf(),y=async O=>{h(!0),m(null),b(null),x(!1);try{const M=O!=="stop"&&(e!=null&&e.session)?await A.browserControl(O,e.session.id):await A.browserControl(O);O==="takeover"?M.hand&&M.session?g(M.session.id):M.handReason==="browser-offline"?x(!0):b(M.handMessage??null):g(null)}catch(M){m(M instanceof Error?M.message:String(M))}finally{h(!1),s()}},k=async()=>{if(e!=null&&e.settings){h(!0),m(null);try{e.session&&await A.browserControl("release",e.session.id),await A.browserSettings({...e.settings,mode:"playwright"}),x(!1),g(null),b("Switched to buddi’s browser. Send the agent a message and it opens the page there.")}catch(O){m(O instanceof Error?O.message:String(O))}finally{h(!1),s()}}},N=p&&((W=e==null?void 0:e.session)==null?void 0:W.id)===p&&e.state==="paused"?p:null,S=!!(e!=null&&e.enabled)&&!u,C=(e==null?void 0:e.mode)==="computer",T=(e==null?void 0:e.mode)==="extension",R=C?"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.",I=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",L=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:C?"Computer":T?"Your browser":"Browser"})]}),n.jsx(we,{tone:L,children:n.jsx("span",{role:"status",children:I})})]}),r?n.jsx("a",{className:"browser-full-view",href:"#/browser",children:C?"Open computer view & settings ↗":"Open full browser view ↗"}):n.jsx("p",{className:"ui-page-lede",children:C?"Your apps, operated through macOS accessibility, screenshots and input. No browser debugging connection.":T?"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(ie,{message:t??f}),c?n.jsxs(ae,{children:[n.jsx(E,{variant:"danger",disabled:!S||(e==null?void 0:e.state)==="stopped",onClick:()=>void y("stop"),children:C?"Stop computer control":"Stop all browsers"}),n.jsx(E,{disabled:!S||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void y("takeover"),children:"Take over"}),n.jsx(E,{disabled:!S||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void y("resume"),children:"Resume access"}),n.jsx(E,{disabled:!S||!(e!=null&&e.session),onClick:()=>void y("release"),children:C?"Release control":"Close & release"})]}):null,c?r?n.jsx(At,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:R})}):n.jsx("p",{className:"muted",children:R}):null,v?n.jsx(G,{tone:"warning",role:"status",children:v}):null,j&&T?n.jsx(G,{tone:"warning",role:"status",title:"Your browser isn’t connected.",action:n.jsxs(ae,{align:"end",children:[e!=null&&e.settings?n.jsx(E,{size:"sm",disabled:u,onClick:()=>void k(),children:"Switch to buddi’s browser"}):null,n.jsx(E,{size:"sm",variant:"accent",disabled:u,onClick:()=>void y("takeover"),children:"Try again"})]}),children:`There is no Chrome tab to show or drive. Open Chrome on ${w}: the buddi extension reconnects by itself, then try again. Or switch every agent to buddi’s own browser (it doesn’t have your Chrome sign-ins; switch back on this page).`}):null,e!=null&&e.message&&!N&&!(j&&T)?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 ",Vt(new Date(e.session.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone)]})]}):n.jsx("p",{className:"browser-task muted",children:e!=null&&e.enabled?C?"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."}),N?n.jsx(UB,{sessionId:N,csrf:ma(),onGiveBack:()=>void y("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!N,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:(($=e==null?void 0:e.page)==null?void 0:$.url)??(C?"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 · ",Vt(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:C?"Your selected app will appear here":"Your browser activity will appear here"}),n.jsx("p",{children:C?"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."})]})]}),(((P=e==null?void 0:e.page)==null?void 0:P.tabs.length)??0)>1?n.jsx(At,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(O=>n.jsxs("li",{children:[O.title||O.id," — ",O.url]},O.id))})}):null,n.jsxs("p",{className:"muted",children:[C?"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."," ",N?"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 l5=2e3,o5=5;function c5(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 u5({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var w;const[l,o]=d.useState(0),[c,u]=d.useState(0),h=c>=o5;d.useEffect(()=>{if(!i||h)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(k=>k+1)},l5);return()=>window.clearInterval(y)},[i,h]);const f=d.useRef(null);i&&(e!=null&&e.session)&&(f.current=e);const[m,p]=d.useState(null),g=d.useRef(null),v=((w=e==null?void 0:e.page)==null?void 0:w.id)??null;d.useEffect(()=>{const y=i&&e?c5(e):null;if(!y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let k=!1;return(async()=>{try{const N=await fetch(y);if(!N.ok||k)return;const S=await N.blob();if(k)return;const C=URL.createObjectURL(S);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{k=!0}},[i,v]),d.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=f.current,j=i?e:b?m?b:{...b,hasScreenshot:!1}:e,x=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(a5,{data:j,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(y=>y+1),onScreenshotLoad:()=>u(0)}),i?h?n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"This session has ended. What is on this panel is the last thing it showed."}),n.jsx(d5,{steps:r,newestId:(x==null?void 0:x.id)??null,focusedId:a??null,live:i})]})}function d5({steps:e,newestId:t,focusedId:s,live:r}){const i=d.useRef(null);return d.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function h5({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=de(()=>A.host(e,t),[e,t],2e3),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return n.jsx(At,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:n.jsxs(le,{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(ie,{message:a??r}),h.map(p=>n.jsxs(ae,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(E,{size:"sm",disabled:o,onClick:()=>void u(()=>A.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),f.map(p=>n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx(Pt,{children:p.command}),n.jsx(Pt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
|
|
105
|
+
${p.stderr}`:"Waiting for output…"}),n.jsx(ae,{children:n.jsx(E,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>A.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const XA="browser.act",f5="browser.status",fd=new Set([XA,f5]);function m5(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 p5(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function g5(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===XA){const o={id:a.id,action:x5(a.input)??"act",target:v5(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:j5(a)}}return t}function r0(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=fd.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 x5(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function v5(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 j5(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 w5({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(0);return d.useEffect(()=>{let m=!1;return o(null),u(null),(t?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,h]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>f(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Hi(t,m.id):st(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 ZA="buddi.dismissedTabs";function y5(){try{const e=JSON.parse(sessionStorage.getItem(ZA)??"{}");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 i0(e){try{sessionStorage.setItem(ZA,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const b5=350,k5=60;function N5({conversationId:e,onText:t,onNotice:s}){const[r,i]=d.useState("idle"),a=d.useRef("idle"),l=x=>{a.current=x,i(x)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let x;try{x=await W3(k=>{var N;return(N=f.current)==null?void 0:N.call(f,k)})}catch(k){h.current=null,l("idle"),m.current.onNotice(B3(k));return}const w=c.current;c.current=null;const y=a.current;if(w==="discard"||y!=="starting"){x.cancel(),y==="starting"&&l("idle");return}o.current=x,l("recording"),u.current=window.setTimeout(()=>void v(!1),_3),w&&v(w.sendNow)},v=async x=>{h.current=null;const w=o.current;if(!w){a.current==="starting"&&(c.current={sendNow:x});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const k=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),N=await He.attach(k),S=m.current.conversationId,C=await He.transcribe({artifactId:N.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,x)}catch(y){m.current.onNotice(y instanceof ve||y instanceof Error?y.message:String(y))}finally{l("idle")}},b=()=>{h.current=null;const x=o.current;if(!x){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),x.cancel(),l("idle")};d.useEffect(()=>{const x=w=>{if(h.current===null)return;const y=Date.now()-h.current;h.current=null,y>=b5&&v(w.shiftKey)};return window.addEventListener("pointerup",x),()=>window.removeEventListener("pointerup",x)},[]);const j=r==="starting"||r==="recording";return d.useEffect(()=>{if(!j)return;const x=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),b()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),v(w.shiftKey)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[j]),d.useEffect(()=>()=>{var x;(x=o.current)==null||x.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),g()},start:()=>{h.current=null,g()},finish:x=>void v(x),discard:b,levels:f}}function S5({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(ce,{name:"mic"})})}function C5({voice:e}){const t=d.useRef(null),s=e.state==="transcribing";return d.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(E5,{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(ce,{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(ce,{name:"check"})})]})]})}function E5({sink:e,frozen:t}){const[s,r]=d.useState(()=>Array(k5).fill(0));return d.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const A5="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Lu="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",T5=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function $5(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(A5);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(T5(i))return null;throw new Error(Lu)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((h,f)=>{a.onloadedmetadata=()=>h(),a.onerror=()=>f(new Error(Lu))}),await a.play(),await new Promise(h=>{const f=a.requestVideoFrameCallback;typeof f=="function"?f.call(a,()=>h()):setTimeout(h,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(Lu);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(Lu);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 a0="Send files once the agent has answered.",ox="wb-composer-input",Vj=d.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:h,onOpenFile:f,mentions:m,history:p,threadKey:g,conversationId:v,readAloud:b,onReadAloud:j,placeholder:x,slim:w},y){var Vn;const k=g?`buddi.draft.${g}`:null,N=Z=>{if(!Z)return"";try{return window.localStorage.getItem(Z)??""}catch{return""}},[S,C]=d.useState(()=>N(k)),[T,R]=d.useState([]),[I,L]=d.useState(!1),[W,$]=d.useState(null),[P,O]=d.useState(!1),M=d.useRef(null),D=d.useRef(null),[H,U]=d.useState(null),[q,B]=d.useState(0),Y=H&&m?m.filter(Z=>Z.handle.toLowerCase().startsWith(H.query.toLowerCase())||Z.name.toLowerCase().startsWith(H.query.toLowerCase())).slice(0,6):[],F=(Z,Re)=>{if(!m||m.length===0){U(null);return}const Xe=Z.slice(0,Re),xt=/(^|\s)@([\w-]*)$/.exec(Xe);if(!xt){U(null);return}U({start:Re-xt[2].length-1,query:xt[2]}),B(0)},X=Z=>{if(!H)return;const Re=D.current,Xe=Re?Re.selectionStart:S.length,xt=`${S.slice(0,H.start)}@${Z} ${S.slice(Xe)}`;C(xt),ee<0&&Fe(xt),U(null),window.requestAnimationFrame(()=>{if(!Re)return;const V=H.start+Z.length+2;Re.focus(),Re.setSelectionRange(V,V),kt()})},Q=p??[],[ee,fe]=d.useState(-1),Oe=d.useRef(S),Ie=d.useRef(k);if(Ie.current!==k){Ie.current=k;const Z=N(k);Oe.current=Z,Z!==S&&(C(Z),fe(-1),U(null))}const Fe=Z=>{if(Oe.current=Z,!!k)try{Z===""?window.localStorage.removeItem(k):window.localStorage.setItem(k,Z)}catch{}},z=Z=>{C(Z),U(null);const Re=D.current;Re&&(Re.value=Z,Re.setSelectionRange(Z.length,Z.length)),window.requestAnimationFrame(kt)},ne=Z=>!Z.value.slice(0,Z.selectionStart??Z.value.length).includes(`
|
|
106
|
+
`),J=()=>S===""||ee>=0&&S===Q[ee],ye=()=>{ee<0||(fe(-1),z(Oe.current))},ge=T.some(Z=>Z.state==="uploading"),$e=T.length>0,De=s&&$e,Je=!t&&!ge&&!De&&S.trim()!=="",ze=Z=>{for(const Re of Array.from(Z??[])){const Xe=`${Re.name}:${Re.size}:${Math.random().toString(36).slice(2,8)}`,xt=Re.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Re):null;R(V=>[...V,{key:Xe,filename:Re.name||"Pasted image",mime:Re.type||"application/octet-stream",sizeBytes:Re.size,thumbnail:xt,state:"uploading"}]),He.attach(Re).then(V=>R(he=>he.map(Be=>Be.key===Xe?{...Be,state:"ready",uploaded:V}:Be))).catch(V=>R(he=>he.map(Be=>Be.key===Xe?{...Be,state:"failed",error:V instanceof ve?V.message:String(V)}:Be)))}},Ne=Z=>{Z.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Z.thumbnail)},Ue=Z=>{const Re=T.find(Xe=>Xe.key===Z);Re&&(Ne(Re),Re.state==="ready"&&Re.uploaded&&He.discardAttachment(Re.uploaded.artifactId).catch(()=>{})),R(Xe=>Xe.filter(xt=>xt.key!==Z))};d.useImperativeHandle(y,()=>({addFiles:Z=>{var Re;ze(Z),(Re=D.current)==null||Re.focus()},focus:()=>{var Z;return(Z=D.current)==null?void 0:Z.focus()}}));const at=d.useRef(T);at.current=T,d.useEffect(()=>()=>at.current.forEach(Ne),[]);const Ye=d.useRef(0);d.useEffect(()=>{if(!l||l.at===Ye.current)return;Ye.current=l.at,C(Re=>Re.trim()===""?l.text:Re),ee<0&&S.trim()===""&&Fe(l.text);const Z=D.current;Z&&(Z.focus(),window.requestAnimationFrame(()=>{Z.style.height="auto",Z.style.height=`${Math.min(Z.scrollHeight,200)}px`,Z.setSelectionRange(Z.value.length,Z.value.length)}))},[l]);const kt=()=>{const Z=D.current;Z&&(Z.style.height="auto",Z.style.height=`${Math.min(Z.scrollHeight,200)}px`)},Gt=Z=>{const Re=(Z??S).trim();if(Z===void 0?!Je:t||ge||De||Re==="")return;const Xe=T.filter(xt=>xt.state==="ready"&&xt.uploaded).map(xt=>xt.uploaded);r(Re,Xe),T.forEach(Ne),fe(-1),Fe(""),C(""),R([]),window.requestAnimationFrame(kt)},se=Z=>{if(H&&Y.length>0){if(Z.key==="ArrowDown"){Z.preventDefault(),B(Re=>(Re+1)%Y.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),B(Re=>(Re-1+Y.length)%Y.length);return}if(Z.key==="Enter"||Z.key==="Tab"){Z.preventDefault(),X(Y[q].handle);return}if(Z.key==="Escape"){Z.preventDefault(),U(null);return}}if(Z.key==="ArrowUp"&&!Z.shiftKey&&!Z.altKey&&!Z.metaKey&&!Z.ctrlKey){const Re=Z.currentTarget;if(Q.length>0&&ee+1<Q.length&&ne(Re)&&J()){Z.preventDefault(),ee<0&&(Oe.current=S),fe(ee+1),z(Q[ee+1]);return}}if(Z.key==="ArrowDown"&&!Z.shiftKey&&!Z.altKey&&!Z.metaKey&&!Z.ctrlKey&&ee>=0&&S===Q[ee]){if(Z.preventDefault(),ee===0){ye();return}fe(ee-1),z(Q[ee-1]);return}if(Z.key==="Escape"&&ee>=0){Z.preventDefault(),ye();return}Z.key==="Enter"&&!Z.shiftKey&&(Z.preventDefault(),Gt())},be=Z=>{var Xe;const Re=Array.from(((Xe=Z.clipboardData)==null?void 0:Xe.files)??[]);Re.length!==0&&(Z.preventDefault(),ze(Re))},Qe=T.filter(Z=>Z.state==="failed"),ct=Qe.length,yt=N5({conversationId:v??null,onNotice:$,onText:(Z,Re)=>{const Xe=S.trim()===""?Z:`${S.replace(/\s+$/,"")} ${Z}`;if(Re){Gt(Xe);return}z(Xe),ee<0&&Fe(Xe)}}),ut=yt.state!=="idle",mn=d.useRef(!1);return d.useEffect(()=>{var Z;mn.current&&!ut&&((Z=D.current)==null||Z.focus(),window.requestAnimationFrame(kt)),mn.current=ut},[ut]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-slim":w||void 0,"data-busy":S.trim()!==""||$e||ut?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":P||ut,"data-disabled":t,"data-listening":ut||void 0,children:[T.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:T.map(Z=>n.jsx("span",{role:"listitem",children:n.jsx(vf,{name:Z.filename,mime:Z.mime,sizeBytes:Z.sizeBytes,thumbnail:Z.thumbnail,state:Z.state,error:Z.error,onRemove:()=>Ue(Z.key),...f&&Z.state==="ready"&&Z.uploaded?{onOpen:()=>f(R5(Z.uploaded))}:{},size:"sm"})},Z.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:ox,children:["Message ",a]}),n.jsx("textarea",{id:ox,ref:D,value:S,rows:w?1:2,placeholder:s?`${a} is working…`:x??`Message ${a}`,onChange:Z=>{C(Z.target.value),ee<0&&Fe(Z.target.value),F(Z.target.value,Z.target.selectionStart??Z.target.value.length),kt()},onFocus:()=>O(!0),onBlur:()=>O(!1),onKeyDown:se,onPaste:be,disabled:t,hidden:ut}),ut?n.jsx(C5,{voice:yt}):null,!ut&&H&&Y.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:Y.map((Z,Re)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Re===q,className:"wb-mention","data-active":Re===q||void 0,onMouseDown:Xe=>{Xe.preventDefault(),X(Z.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",Z.handle]}),n.jsx("span",{className:"wb-mention-name",children:Z.name})]},Z.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:ut,children:[n.jsx("input",{ref:M,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:Z=>{ze(Z.target.files),Z.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 Z;return(Z=M.current)==null?void 0:Z.click()},disabled:t,children:n.jsx(ce,{name:"clip"})}),n.jsx(S5,{disabled:t,voice:yt}),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:()=>{$(null),L(!0),$5().then(Z=>{var Re;Z&&(ze([Z]),(Re=D.current)==null||Re.focus())}).catch(Z=>$(Z instanceof Error?Z.message:String(Z))).finally(()=>L(!1))},disabled:t||I,children:n.jsx(ce,{name:"camera"})}),o?c?n.jsxs("a",{className:"wb-composer-model",href:c,title:"The model this agent runs on. Click to change it.",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):n.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):null,h?n.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":Fu(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${Fu(u)?"on":"off"}`:Fu(u)?"Reasoning before the answer is on. Click to turn it off — answers come back faster.":"Reasoning before the answer is off. Click to turn it on.",onClick:()=>h(Fu(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(ce,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":S!==""&&!s||ct>0||De||W!==null,"data-tone":ct>0||W!==null?"critical":void 0,children:ct>0?ct===1&&((Vn=Qe[0])!=null&&Vn.error)?Qe[0].error:`${ct} files failed to upload and will not be sent`:W!==null?W:De?a0:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:De?a0:ge?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>Gt(),disabled:!Je,children:n.jsx(ce,{name:"send"})})]})]})})});function Fu(e){return(e??"on")==="on"}function R5(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function I5({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=d.useState("");return d.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(E,{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:P5(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 P5(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 M5(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 D5(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 O5(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 ${D5(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(M5(t,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Le(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${nt(s,i)}. ${l}`:l,tone:"quiet"}}function L5({text:e,onDelete:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null);return n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:n.jsxs(At,{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(E,{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 eT(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function tT(e,t){return e.members.map(s=>t.find(r=>r.id===s)).filter(s=>s!==void 0)}function F5(e,t){var i;const s=tT(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 _5(){return n.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function z5({group:e,agents:t,onClose:s,onSaved:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,h=Ej(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(v){o(v instanceof ve?v.message:String(v))}finally{a(!1)}},p=g=>void m({members:e.members.filter(v=>v!==g)});return n.jsxs(qe,{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(rt,{children:c.map(g=>{const v=t.find(j=>j.id===g),b=g===e.coordinator;return v?n.jsx(et,{lead:n.jsx(ln,{agents:t,id:g}),title:v.name,sub:v.description,side:n.jsxs(n.Fragment,{children:[b?n.jsx(we,{tone:"accent",children:"Coordinator"}):null,f&&v.available?n.jsx(E,{size:"sm",disabled:i,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,n.jsx(ja,{label:`More for ${v.name}`,...b?{note:"Coordinates the group"}:{},items:[!b&&v.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:g})},{label:`Open ${v.name}'s page`,onSelect:()=>{window.location.hash=St(g)}},!b&&"separator",!b&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(g):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},g):n.jsx(et,{lead:n.jsx(_5,{}),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(E,{size:"sm",disabled:i,onClick:()=>p(g),children:"Remove"}):void 0},g)})}),n.jsxs("div",{className:"group-add",children:[n.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?n.jsx(rt,{children:h.map(g=>n.jsx(et,{lead:n.jsx(ln,{agents:t,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:n.jsx(E,{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 U5({group:e,onClose:t,onSaved:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!a,h=async()=>{if(u){l(!0),c(null);try{s(await He.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof ve?f.message:String(f)),l(!1)}}};return n.jsx(Ft,{title:"Rename group",onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!u,onClick:()=>void h(),children:a?"Renaming…":"Rename"})]}),children:n.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:n.jsxs(le,{children:[n.jsx(oe,{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 nT(e){const[t,s]=d.useState(null);return d.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 B5(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function W5({group:e,onClose:t,onCleared:s}){const r=nT(e.id),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{a(!0),o(null);try{await He.clearGroup(e.id),s()}catch(h){o(h instanceof ve?h.message:String(h)),a(!1)}},u=r===0;return n.jsxs(Ft,{title:`Clear the history of ${e.name}?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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.":`${B5(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 H5({group:e,agents:t,onClose:s,onDeleted:r}){const i=nT(e.id),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=tT(e,t).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await He.deleteGroup(e.id);r(m)}catch(m){c(m instanceof ve?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(Ft,{title:`Delete ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:a,"data-testid":"group-delete-confirm",onClick:()=>void h(),children:a?"Deleting…":"Delete group"})]}),children:[n.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",f," and what it remembers."," ",u.length>0?`${eT(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 md=320,sT="buddi.chatWidth";function K5({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onGroupAction:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:v,requestedTab:b,onConversationOpened:j}){var hy,fy,my,py,gy,xy;const x=jf(),[w,y]=d.useState([]),[k,N]=d.useState(null),[S,C]=d.useState(null),[T,R]=d.useState(null),[I,L]=d.useState([]),[W,$]=d.useState([]),[P,O]=d.useState(null),[M,D]=d.useState(!1),[H,U]=d.useState(new Map),[q,B]=d.useState(null),[Y,F]=d.useState(y5),[X,Q]=d.useState([]),[ee,fe]=d.useState(!1),Oe=d.useRef(0),Ie=d.useRef(null),[Fe,z]=d.useState(!1),ne=d.useRef(g??0),J=d.useRef(s),ye=d.useRef({agentId:s,conversationId:k});ye.current={agentId:s,conversationId:k};const ge=Y[k??""]??[],[$e,De]=d.useState(null),[Je,ze]=d.useState(null),[Ne,Ue]=d.useState(null),[at,Ye]=d.useState([]),[kt,Gt]=d.useState(!1),[se,be]=d.useState(()=>Date.now()),[Qe,ct]=d.useState(V5),yt=d.useRef(null),[ut,mn]=d.useState(null),[Vn,Z]=d.useState(!1),[Re,Xe]=d.useState(null),[xt,V]=d.useState(LA),he=d.useRef(xt);he.current=xt;const Be=d.useRef(null),[_e,en]=d.useState(null),Es=d.useCallback(K=>{V(K),FA(K),K||Wl()},[]),[kn,As]=d.useState(null),[Ts,ke]=d.useState(null);d.useEffect(()=>{if(!s)return;const K=hL(s);K&&Xe({text:K,at:Date.now()})},[s]);const Ee=i?`group:${i.id}`:s??null,We=[...t.top,...t.middle,...t.bottom],me=We.find(K=>K.id===s)??null,Gn=de(()=>A.providerAccounts(),[]),Dn=i?i.members.map(K=>We.find(re=>re.id===K)).filter(K=>!!K):[],[Vs,Xl]=d.useState(null),Oi=M?Vs??s??null:null;d.useEffect(()=>{o==null||o(Oi)},[Oi,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let K=!1;return He.views().then(re=>{K||y(re.views??[])}).catch(()=>{}),()=>{K=!0}},[]),d.useEffect(()=>{if(!s)return;const K=J.current===s;if(J.current=s,K&&v&&v===ye.current.conversationId)return;let re=!1;return N(null),C(null),R(null),L([]),De(null),D(!1),B(null),Q([]),Jc(null),z(!1),mn(null),v?(v!=="new"?N(v):R(Ee),()=>{re=!0}):((i?He.groupConversations(i.id):He.conversations(s)).then(Se=>{if(re)return;const Ae=[...Se.conversations??[]].sort(G5)[0];Ae?(N(Ae.id),j==null||j(s,Ae.id)):R(Ee)}).catch(()=>{re||R(Ee)}),()=>{re=!0})},[s,i==null?void 0:i.id,Ee,v,j]);const On=d.useCallback(K=>He.conversation(K).then(re=>{if(ye.current.conversationId===K){if(re.agentId!==ye.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(re),L(Se=>Se.filter(Ae=>!Hm(re,Ae)))}}).catch(re=>{ye.current.conversationId===K&&De(Xr(re))}),[]);d.useEffect(()=>{if(!k)return;let K=!1;return U(new Map),$([]),He.conversation(k).then(re=>{if(!K){if(re.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(re),L(Se=>Se.filter(Ae=>!Hm(re,Ae)))}}).catch(re=>{K||De(Xr(re))}),()=>{K=!0}},[k,s]),d.useEffect(()=>{if(!k)return;let K=!1;const re=window.setInterval(()=>{He.conversation(k).then(Se=>{K||Se.agentId!==ye.current.agentId||(C(Se),L(Ae=>Ae.filter(Ze=>!Hm(Se,Ze))))}).catch(()=>{})},3e3);return()=>{K=!0,window.clearInterval(re)}},[k,s]),d.useEffect(()=>{if(!k)return;const K=af({url:He.streamUrl(k),onEvent:re=>{var Se;switch(re.name){case"run.started":Be.current=null,D(!0),O(null),Xl(un(re.data.agentId));break;case"live":{const Ae=un(re.data.runId)??"",Ze=Number(re.data.turn??0),Ke=re.data.kind==="thinking"?"thinking":"text",Nn=un(re.data.text)??"",br=Date.now();if(Ke==="text"){const Ys=Be.current;Be.current=Ys&&Ys.runId===Ae&&Ys.turn===Ze?{...Ys,text:Ys.text+Nn}:{runId:Ae,turn:Ze,text:Nn}}O(Ys=>{const Sa=Ys&&Ys.runId===Ae&&Ys.turn===Ze?Ys:{runId:Ae,turn:Ze,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ke==="thinking"?{...Sa,thinking:Sa.thinking+Nn,thinkingStartedAt:Sa.thinkingStartedAt??br}:{...Sa,text:Sa.text+Nn,textStartedAt:Sa.textStartedAt??br}});break}case"live.snapshot":{const Ae=un(re.data.runId)??"",Ze=Number(re.data.turn??0),Ke=un(re.data.text)??"",Nn=un(re.data.thinking)??"",br=Number(re.data.startedAt??Date.now());Be.current={runId:Ae,turn:Ze,text:Ke},O({runId:Ae,turn:Ze,text:Ke,thinking:Nn,thinkingStartedAt:Nn?br:null,textStartedAt:Ke?br:null,settled:!1});break}case"live.settle":{const Ae=un(re.data.runId)??"",Ze=Number(re.data.turn??0);O(Ke=>Ke&&Ke.runId===Ae&&Ke.turn===Ze?{...Ke,settled:!0}:Ke);break}case"tool.called":{const Ae=un(re.data.toolUseId)??un(re.data.id),Ze=un(re.data.name)??un(re.data.tool)??"tool";Ae&&$(Ke=>[...Ke.filter(Nn=>Nn.toolUseId!==Ae),{toolUseId:Ae,name:Ze,startedAt:Date.now()}]);break}case"tool.result":{const Ae=un(re.data.toolUseId)??un(re.data.id);Ae&&$(Ze=>Ze.filter(Ke=>Ke.toolUseId!==Ae)),On(k);break}case"reaction":On(k);break;case"message.appended":On(k).then(()=>{O(Ae=>Ae!=null&&Ae.settled?null:Ae)});break;case"awaiting-approval":{const Ae=un(re.data.approvalId)??un(re.data.actionId),Ze=un(re.data.toolUseId);Ae&&Ze&&U(Ke=>new Map(Ke).set(Ze,Ae)),$(Ke=>Ke.filter(Nn=>Nn.toolUseId!==Ze)),On(k);break}case"run.finished":{D(!1),$([]),O(null),Xl(null);const Ae=un(re.data.message);De(Ae??null);const Ze=((Se=Be.current)==null?void 0:Se.text.trim())??"";Be.current=null,!Ae&&Ze!==""&&he.current&&lh(Ze,k).then(Ke=>{Ke&&en(Ke)}),On(k);break}}}});return()=>K.close()},[k,On]),d.useEffect(()=>{const K=window.setInterval(()=>be(Date.now()),W.length===0?6e4:1e3);return()=>window.clearInterval(K)},[W.length]);const Li=de(()=>s&&k?A.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),yr=Li.error?void 0:Li.data,Jr=yr!=null&&yr.session&&yr.session.agentId===s&&yr.session.conversationId===k?yr:void 0,_t=m5(Jr,s,k),Gs=(_t==null?void 0:_t.id)??null,[Zl,bI]=d.useState(null),qw=Jr==null?void 0:Jr.mode;d.useEffect(()=>{_t&&s&&k&&bI({agentId:s,conversationId:k,tab:p5(_t,qw)})},[Gs,qw,s,k]);const kI=Zl&&Zl.agentId===s&&Zl.conversationId===k&&!ge.includes(Zl.tab.id)?Zl.tab:null,pn=_t??kI,NI=d.useMemo(()=>g5((S==null?void 0:S.messages)??[]),[S]),[SI,Jc]=d.useState(null),CI=d.useMemo(()=>c6({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),ka=EB(CI,k??null),If=TB(i?null:s),Jw=d.useMemo(()=>AB((S==null?void 0:S.messages)??[]),[S]),Yn=d.useMemo(()=>{const re=u6({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:H,served:ka.served,...pn?{folded:fd}:{}}).filter(Se=>Se.source==="approval"||!ge.includes(Se.id));if(q&&!ge.includes(q)&&!re.some(Se=>Se.id===q)){const Se=m6((S==null?void 0:S.messages)??[],q,{redactInputOf:fd});Se&&!fd.has(Se.tool)&&re.push(Se)}pn&&re.push(pn);for(const Se of X)re.push(MU(Se));return If&&re.unshift($B(If,Jw)),ut?[...re,RB(ut)]:re},[S,w,H,ut,Gs,pn==null?void 0:pn.title,q,Y,k,X,ka.served,If,Jw]),EI=d.useMemo(()=>{var re;const K=[];for(const Se of(S==null?void 0:S.messages)??[]){if(Se.role!=="user"||Se.speaker&&Se.speaker!=="owner")continue;const Ae=(re=Se.blocks.find(Ze=>Ze.type==="text"))==null?void 0:re.text.trim();Ae&&K.unshift(Ae)}return K},[S]),Pf=d.useMemo(()=>Yn.filter(K=>K.source==="approval"),[Yn]),Qc=Pf.at(-1)??null,Xc=d.useMemo(()=>[...Pf.map(K=>({approvalId:K.props.approvalId,toolUseId:K.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(K=>({approvalId:K.approvalId,toolUseId:K.toolUseId??"",askedBy:Q5(K.chain,We)}))],[Pf,S==null?void 0:S.delegatedApprovals]),eo=d.useMemo(()=>{for(let K=Yn.length-1;K>=0;K-=1){const re=Yn[K];if(re!=null&&re.substantial)return re.id}return null},[Yn]),Zc=d.useRef(null),Mf=((hy=Yn.filter(K=>(K.source!=="browser"||K.pinned===!0)&&K.id!==ax).at(-1))==null?void 0:hy.id)??((fy=Yn.filter(K=>K.id!==ax).at(-1))==null?void 0:fy.id)??null;d.useEffect(()=>{if(eo&&eo!==Zc.current){Zc.current=eo,B(eo);return}q===null&&Mf&&B(Mf)},[eo,q,Mf]);const Qw=d.useRef(ka.live);d.useEffect(()=>{const K=Qw.current;Qw.current=ka.live;const re=[...ka.live].filter(Ze=>!K.has(Ze));if(re.length===0||Qc||q!==null&&q!==Zc.current)return;const Ae=[...Yn].reverse().find(Ze=>Ze.source==="descriptor"&&Ze.renderer==="preview"&&Ze.props.target!==null&&re.includes(ll(Ze.props.target)));Ae&&B(Ae.id)},[ka.live,Yn,Qc,q]);const Xw=d.useRef(null);d.useEffect(()=>{Gs!==Xw.current&&(Xw.current=Gs,Gs&&!Qc&&B(Gs))},[Gs,Qc]);const Zw=d.useRef(null),to=b==="browser"?(pn==null?void 0:pn.id)??null:null;d.useEffect(()=>{!to||Zw.current===to||(Zw.current=to,B(to))},[to]);const Df=(pn==null?void 0:pn.id)??null;d.useEffect(()=>{!Df||!q||r0((S==null?void 0:S.messages)??[],q)!==null&&(Jc(q),B(Df))},[Df,q,S]);const ey=K=>{Q(re=>re.some(Se=>Se.artifactId===K.artifactId)?re:[...re,K]),B(dd(K.artifactId)),h&&(m==null||m())},eu=!i&&me&&!me.available?tA(me):null,ty=i?n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:i.members.slice(0,2).map(K=>{const re=We.find(Se=>Se.id===K);return n.jsx(uf,{className:"wb-group-chip",id:K,name:(re==null?void 0:re.name)??"?",face:re,initials:1},K)})}):null,Fi=i&&We.length>0?F5(i,We):null,ny=(Fi==null?void 0:Fi.kind)==="coordinator",sy=zg(i?null:me),Of=((S==null?void 0:S.offers)??[]).filter(K=>!at.includes(K.id)&&Date.parse(K.expiresAt)>se),AI=me&&Ts===me.id?kn:(me==null?void 0:me.thinking)??null,TI=K=>{if(!me)return;const re=me.id;ke(re),As(K),A.setAgentEngine(re,{thinking:K}).catch(Se=>{ke(null),De(Se instanceof ve?Se.message:String(Se))})},Lf=(K,re)=>{if(!s)return;const Se=re.map(Ke=>Ke.artifactId),Ae=M,Ze={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:K},...re.map(Ke=>({type:"attachment",artifactId:Ke.artifactId,filename:Ke.filename,mime:Ke.mime,kind:Ke.kind,sizeBytes:Ke.sizeBytes}))],...Ae?{speaker:YA}:{}};L(Ke=>Ae?[...Ke,Ze]:[Ze]),De(null),ze(null),D(!0),(i?He.sendToGroup(i.id,{...k?{conversationId:k}:{},text:K,attachmentIds:Se}):He.send(s,{...k?{conversationId:k}:{},text:K,attachmentIds:Se})).then(async Ke=>{ye.current.agentId!==s||ye.current.conversationId!==k||(ze(Ke.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ke.conversationId!==k?(C(null),N(Ke.conversationId)):await On(Ke.conversationId),Ke.queued===!0&&L(Nn=>Nn.filter(br=>br.id!==Ze.id)),j==null||j(s,Ke.conversationId))}).catch(Ke=>{L(Nn=>Nn.filter(br=>br.id!==Ze.id)),De(Xr(Ke)),D(!1)})},$I=K=>{var Se;const re=Of.find(Ae=>Ae.id===K);if(((Se=re==null?void 0:re.handoff)==null?void 0:Se.kind)==="install"){window.location.hash=r4(re.handoff.package);return}De(null),Ue(K),Ye(Ae=>[...Ae,K]),A.takeOffer(K,k??void 0).then(Ae=>{if(Ae.agentId&&Ae.agentId!==(me==null?void 0:me.id)){window.location.hash=st(Ae.agentId,Ae.conversationId??null);return}Ae.runId&&(ze(null),D(!0)),k&&On(k)}).catch(Ae=>{Ye(Ze=>Ze.filter(Ke=>Ke!==K)),De(Xr(Ae)),k&&On(k)}).finally(()=>Ue(null))},RI=(K,re)=>ry({answer:K,...re?{optionId:re}:{}}),II=()=>ry({answer:"",skipped:!0}),ry=K=>{const re=S==null?void 0:S.question;re&&(De(null),Gt(!0),D(!0),He.answerQuestion(re.id,K).then(()=>{if(k)return On(k)}).catch(Se=>{De(Xr(Se)),D(!1)}).finally(()=>Gt(!1)))},PI=()=>{if(s){if(ut){mn(null);return}Z(!0),A.agentProfile(s).then(K=>{mn(K),B(lx(K.id)),h&&(m==null||m())}).catch(K=>De(Xr(K))).finally(()=>Z(!1))}},MI=K=>{Xe({text:K.prompt,at:Date.now()}),l(K.agentId),h&&(p==null||p())},DI=()=>{k&&He.cancel(k).catch(K=>De(Xr(K))).finally(()=>{D(!1),$([])})},tu=d.useCallback(()=>{if(N(null),C(null),L([]),D(!1),De(null),ze(null),$([]),U(new Map),B(null),Q([]),Jc(null),Zc.current=null,i){He.startGroupConversation(i.id).then(({conversationId:K})=>{N(K),s&&(j==null||j(s,K))}).catch(K=>De(Xr(K)));return}R(Ee),s&&(j==null||j(s,"new"))},[s,i,Ee,j]);d.useEffect(()=>{g&&g!==ne.current&&(ne.current=g,tu())},[g,tu]);const iy=K=>{k&&On(k),A.overview().catch(()=>{}),K.state!=="pending"&&U(re=>new Map([...re].filter(([,Se])=>Se!==K.id)))},nu=d.useRef(!1);d.useEffect(()=>{const K=Se=>{if(!nu.current)return;const Ae=Math.max(md,Math.min(720,Se.clientX-52));ct(Ae)},re=()=>{if(nu.current){nu.current=!1;try{Qe!==null&&window.localStorage.setItem(sT,String(Qe))}catch{}}};return window.addEventListener("pointermove",K),window.addEventListener("pointerup",re),()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",re)}},[Qe]);const OI=((my=We.find(K=>K.id===r))==null?void 0:my.name)??null,ay=i?[]:hz(me,OI),ly=!(S&&S.conversationId===k)&&!(!k&&T!==null&&T===Ee),oy=ly?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&me?n.jsx(kA,{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:me.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${me.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:fz(me)}),ay.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${me.name}`,children:ay.map(K=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var re;Xe({text:K,at:Date.now()}),(re=Ie.current)==null||re.focus()},children:K},K))}):null]})}):null,cy=n.jsx(pB,{renderables:Yn,activeId:q,onActivate:B,onClose:K=>{ut&&K===lx(ut.id)?mn(null):X.some(re=>dd(re.artifactId)===K)?Q(re=>re.filter(Se=>dd(Se.artifactId)!==K)):k&&F(re=>{const Se={...re,[k]:[...new Set([...re[k]??[],K])]};return i0(Se),Se}),q===K&&B(null)},timezone:e,onDecided:iy,onChangeAgent:MI,agents:We,browserPanel:pn?n.jsx(u5,{status:Jr,error:Li.error,reload:Li.reload,steps:NI,live:_t!==null,focusedStepId:SI},pn.id):null,descriptors:w,grantedTools:i?Dn.flatMap(K=>K.tools??[]):(me==null?void 0:me.tools)??[],...me?{agentName:me.name}:{},loading:ly,...!i&&me?{face:n.jsx(ln,{agents:We,id:me.id,size:"xl"})}:{}}),uy=(gy=(py=[...(S==null?void 0:S.messages)??[],...I].find(K=>K.role==="user"))==null?void 0:py.blocks.find(K=>K.type==="text"))==null?void 0:gy.text.trim(),dy=uy?uy.split(`
|
|
107
|
+
`)[0]:"New conversation",Na=O5({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:se,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:yt,style:h||Qe===null?void 0:{width:Qe},"data-sized":!h&&Qe!==null?"true":void 0,"data-testid":"chat-column","data-dropping":ee||void 0,onDragEnter:K=>{_u(K)&&(K.preventDefault(),Oe.current+=1,fe(!0))},onDragOver:K=>{_u(K)&&(K.preventDefault(),K.dataTransfer.dropEffect="copy")},onDragLeave:K=>{_u(K)&&(Oe.current=Math.max(0,Oe.current-1),Oe.current===0&&fe(!1))},onDrop:K=>{var re;_u(K)&&(K.preventDefault(),Oe.current=0,fe(!1),s&&((re=Ie.current)==null||re.addFiles(K.dataTransfer.files)))},children:[ee?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(Y5,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:me?`It goes with your next message to ${me.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&me?Bc(Uc(me)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:ty}):me?n.jsx("a",{className:"wb-head-face",href:St(me.id),"aria-label":`${me.name}'s page`,children:n.jsx(ln,{agents:We,id:me.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:dy,children:dy}),n.jsx("span",{className:"wb-head-meta","data-tone":Na.tone,title:i?`${Dn.map(K=>K.name).join(", ")}. Coordinator: ${(me==null?void 0:me.name)??i.coordinator}.`:Na.title,children:i?`${Dn.map(K=>K.name).join(", ")} · ${Na.text}`:me?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:St(me.id),title:`${me.name}'s page`,children:me.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",me.handle]}),` · ${Na.tone==="quiet"&&Na.text==="New conversation"?`on ${x}`:Na.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:()=>{z(!1),tu()},children:n.jsx(ce,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":Fe,"data-open":Fe?"true":void 0,disabled:!s,onClick:()=>z(K=>!K),children:n.jsx(q5,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:Yn.length===0,children:["Canvas",Yn.length>0?` (${Yn.length})`:""]}):null,i?n.jsx(l0,{disabled:!1,label:"More about this group",title:i.name,sub:eT(Dn.map(K=>K.name)),face:ty,items:[{label:"Members",hint:`${i.members.length} agents · ${me?`${me.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(l0,{disabled:!s,label:"More about this agent",title:(me==null?void 0:me.name)??"Agent",...me?{sub:`@${me.handle}`,face:n.jsx(ln,{agents:We,id:me.id,size:"sm"})}:{},items:[{label:ut?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Vn,onSelect:PI},...me?[{label:"Set up",hint:"Identity, model and access",href:St(me.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:St(me.id)}]:[]]})]}),u?n.jsx(sA,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Oi?{working:new Set([Oi])}:{}}):null]}),Fe&&s?n.jsx(w5,{agentId:s,...i?{groupId:i.id}:{},currentId:k,timezone:e,onNew:()=>{z(!1),tu()},onSelect:K=>{if(K===k){z(!1);return}z(!1),C(null),L([]),D(!1),B(null),De(null),ze(null),Q([]),N(K),j==null||j(s,K,!1)}}):null,s&&k?n.jsx(h5,{agentId:s,conversationId:k},`${s}:${k}`):null,$e?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(ie,{message:$e})}):null,Je?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Je}):null,S!=null&&S.carriedOver?n.jsx(L5,{text:S.carriedOver,onDelete:async()=>{const K=S.conversationId;await He.deleteCarryOver(K),C(re=>{if(!re||re.conversationId!==K)return re;const{carriedOver:Se,...Ae}=re;return Ae})}},S.conversationId):null,n.jsx(Hj,{messages:[...(S==null?void 0:S.messages)??[],...I],live:W,now:se,working:M,partial:P,agents:We,...S!=null&&S.runs?{runs:S.runs}:{},...s&&k?{onContinue:()=>Lf("continue",[])}:{},...i?{speakers:We,coordinatorId:i.coordinator}:{},...Vs?{workingAs:((xy=We.find(K=>K.id===Vs))==null?void 0:xy.name)??Vs}:{},onOpenFile:ey,onReadAloud:(K,re)=>{en(null),lh(re,k??void 0,K).then(Se=>{Se&&en(Se)})},onOpen:K=>{if(pn){const re=r0([...(S==null?void 0:S.messages)??[],...I],K);if(re){Jc(re),B(pn.id),h&&(m==null||m());return}}k&&F(re=>{const Se={...re,[k]:(re[k]??[]).filter(Ae=>Ae!==K)};return i0(Se),Se}),B(K),h&&(m==null||m())},...me?{agentName:me.name,agentId:me.id}:{},...oy?{empty:oy}:{},emptyHint:i?`Give the team a task once; ${me?me.name:"the coordinator"} brings members in. @ addresses one of them.`:me?`Nothing here yet. Ask ${me.name} for something.`:"Loading agents…"}),Of.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Of.map(K=>{var re,Se;return n.jsx("button",{className:"ui-btn",disabled:Ne!==null,title:((re=K.handoff)==null?void 0:re.kind)==="install"?`Opens ${K.handoff.title}'s install sheet`:K.prompt,"data-handoff":(Se=K.handoff)==null?void 0:Se.kind,onClick:()=>$I(K.id),children:K.label},K.id)})}):null,Fi?n.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Fi.kind,children:n.jsx(G,{tone:ny?"warning":void 0,role:"status",children:n.jsxs("span",{children:[Fi.text," ",n.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>a==null?void 0:a("members"),children:Fi.action})]})})}):null,eu?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(G,{tone:"warning",role:"status",children:[eu," ",n.jsx("a",{href:Pe(sy.section),children:sy.label})]})}):Xc.length>0?n.jsx(q6,{approvals:Xc,timezone:e,now:se,version:S,onDecided:iy,onSay:K=>Lf(K,[]),onOpenFull:K=>{B(K),h&&(m==null||m())}}):null,eu||Xc.length>0?null:S!=null&&S.question?n.jsx(I5,{question:S.question,disabled:kt||M,onAnswer:RI,onSkip:II},S.question.id):null,eu||ny?null:n.jsxs("div",{hidden:Xc.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(Vj,{ref:Ie,disabled:!s,running:M,onSend:Lf,onStop:DI,agentName:i?i.name:(me==null?void 0:me.name)??"the agent",draft:Re,history:EI,threadKey:k??(i?`group:${i.id}`:s),model:i?null:(me==null?void 0:me.model)??null,setupHref:i?null:me?St(me.id,"setup","brain"):null,thinking:AI,...!i&&me&&H1(K1(me,Gn.data))?{onThinking:TI}:{},...i?{mentions:Dn.map(K=>({handle:K.handle,name:K.name}))}:{},onOpenFile:ey,conversationId:k??null,readAloud:xt,onReadAloud:Es}),_e?n.jsx("p",{className:"wb-voice-note",role:"status",children:_e}):null]})]}),h?f?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),cy]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:K=>{var re,Se;nu.current=!0,(Se=(re=K.currentTarget).setPointerCapture)==null||Se.call(re,K.pointerId)},onKeyDown:K=>{const re=Se=>{var Ae;return Se??((Ae=yt.current)==null?void 0:Ae.offsetWidth)??md};K.key==="ArrowLeft"&&ct(Se=>Math.max(md,re(Se)-16)),K.key==="ArrowRight"&&ct(Se=>Math.min(720,re(Se)+16))}}),cy]})]})}function V5(){try{const e=window.localStorage.getItem(sT),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=md?t:null}catch{return null}}function G5(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function un(e){return typeof e=="string"&&e!==""?e:null}function Xr(e){return e instanceof ve||e instanceof Error?e.message:String(e)}function Hm(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 _u(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function Y5(){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"})]})}function q5(){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 J5(){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 l0({items:e,disabled:t,label:s,title:r,sub:i,face:a}){const[l,o]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!l)return;const h=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",h),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",f)}},[l]);const u=h=>{const f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-menu-item-text",children:h.label}),h.hint?n.jsx("span",{className:"ui-menu-item-hint",children:h.hint}):null]});return h.href?n.jsx("a",{className:"ui-menu-item",role:"menuitem",href:h.href,"data-tone":h.tone,onClick:()=>o(!1),children:f},h.label):n.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":h.testId,"data-tone":h.tone,disabled:h.disabled,onClick:()=>{var m;o(!1),(m=h.onSelect)==null||m.call(h)},children:f},h.label)};return n.jsxs("div",{className:"wb-head-menu",ref:c,children:[n.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":l,"data-open":l?"true":void 0,disabled:t,onClick:()=>o(h=>!h),children:n.jsx(J5,{})}),l?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),n.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[n.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[a,n.jsxs("span",{className:"wb-head-menu-heading",children:[n.jsx("span",{className:"wb-head-menu-title",children:r}),i?n.jsx("span",{className:"wb-head-menu-sub",children:i}):null]})]}),e.map((h,f)=>h==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(h)),n.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}function Q5(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 o0=!1;const X5=new Set(["missing","unconfigured","not-english"]);async function lh(e,t,s=null){const r=_A(s);try{const i=await He.say({text:e,...t?{conversationId:t}:{}});return Wk(r)&&await q3(i.audioUrl,i.mime,s),null}catch(i){Wk(r)&&Wl();const a=i instanceof ve&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&X5.has(a)&&(s!==null||!o0)?(o0=!0,i.message):null}}let fs=null;function Z5(e){if(ud(e)!==null)return!1;const t=VE(e);return t!==cn&&t!==gi}function e8({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=d.useRef(null),l=d.useRef(s),o=`Ask ${e.name}`,[c,u]=d.useState(!1);return d.useEffect(()=>{if(s||!c||!fs)return;const h=af({url:He.streamUrl(fs.conversationId),lastEventId:fs.lastEventId??null,onEvent:f=>{f.name==="run.finished"&&u(!1)}});return()=>h.close()},[s,c]),d.useEffect(()=>{const h=f=>{!f.altKey||f.ctrlKey||f.metaKey||f.code!=="Slash"||(f.preventDefault(),r(!s))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s,r]),d.useEffect(()=>{var h;l.current&&!s&&((h=a.current)==null||h.focus()),l.current=s},[s]),s?n.jsx(n8,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(ac,{children:[n.jsx(lc,{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(t8,{busy:c})})}),n.jsx(oc,{children:n.jsx(cc,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function t8({busy:e}){const[t,s]=d.useState(!1);return t?n.jsx(xc,{size:"lg"}):n.jsx(Hc,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function n8({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=d.useRef(null),[l,o]=d.useState(fs&&fs.agentId===e.id?fs.conversationId:null),[c,u]=d.useState(null),[h,f]=d.useState([]),[m,p]=d.useState([]),[g,v]=d.useState(null),[b,j]=d.useState(!1),[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,T]=d.useState(Date.now()),[R,I]=d.useState(LA),L=d.useRef(R);L.current=R;const[W,$]=d.useState(null),P=d.useRef(null),O=d.useCallback(async Y=>{try{const F=await He.conversation(Y);u(F),f(X=>X.filter(Q=>!s8(F,Q)))}catch{}},[]);d.useEffect(()=>{l&&O(l)},[l,O]),d.useEffect(()=>{if(!l)return;const Y=af({url:He.streamUrl(l),onEvent:F=>{var X;switch(F.name){case"run.started":P.current=null,j(!0),v(null);break;case"live":{const Q=qn(F.data.runId)??"",ee=Number(F.data.turn??0),fe=F.data.kind==="thinking"?"thinking":"text",Oe=qn(F.data.text)??"",Ie=Date.now();if(fe==="text"){const Fe=P.current;P.current=Fe&&Fe.runId===Q&&Fe.turn===ee?{...Fe,text:Fe.text+Oe}:{runId:Q,turn:ee,text:Oe}}v(Fe=>{const z=Fe&&Fe.runId===Q&&Fe.turn===ee?Fe:{runId:Q,turn:ee,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return fe==="thinking"?{...z,thinking:z.thinking+Oe,thinkingStartedAt:z.thinkingStartedAt??Ie}:{...z,text:z.text+Oe,textStartedAt:z.textStartedAt??Ie}});break}case"live.snapshot":{const Q=qn(F.data.runId)??"",ee=Number(F.data.turn??0),fe=qn(F.data.text)??"",Oe=qn(F.data.thinking)??"",Ie=Number(F.data.startedAt??Date.now());P.current={runId:Q,turn:ee,text:fe},j(!0),v({runId:Q,turn:ee,text:fe,thinking:Oe,thinkingStartedAt:Oe?Ie:null,textStartedAt:fe?Ie:null,settled:!1});break}case"live.settle":{const Q=qn(F.data.runId)??"",ee=Number(F.data.turn??0);v(fe=>fe&&fe.runId===Q&&fe.turn===ee?{...fe,settled:!0}:fe);break}case"tool.called":{const Q=qn(F.data.toolUseId)??qn(F.data.id),ee=qn(F.data.name)??qn(F.data.tool)??"tool";Q&&p(fe=>[...fe.filter(Oe=>Oe.toolUseId!==Q),{toolUseId:Q,name:ee,startedAt:Date.now()}]);break}case"tool.result":{const Q=qn(F.data.toolUseId)??qn(F.data.id);Q&&p(ee=>ee.filter(fe=>fe.toolUseId!==Q)),O(l);break}case"message.appended":case"awaiting-approval":O(l).then(()=>v(Q=>Q!=null&&Q.settled?null:Q));break;case"run.finished":{j(!1),p([]),v(null);const Q=qn(F.data.message);k(Q??null);const ee=((X=P.current)==null?void 0:X.text.trim())??"";P.current=null,!Q&&ee!==""&&L.current&&lh(ee,l).then(fe=>{fe&&$(fe)}),O(l);break}}}});return()=>{fs&&fs.conversationId===l&&(fs.lastEventId=Y.lastEventId()),Y.close()}},[l,O]),d.useEffect(()=>{i(b||x)},[b,x,i]),d.useEffect(()=>{if(m.length===0)return;const Y=window.setInterval(()=>T(Date.now()),1e3);return()=>window.clearInterval(Y)},[m.length]);const M=(Y,F)=>{w(!0),k(null);const X={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:Y}]};f(Q=>[...Q,X]),(async()=>{try{const Q=l??(await He.startConversation(e.id)).conversationId;Q!==l&&(fs={agentId:e.id,conversationId:Q},o(Q));const ee=await He.send(e.id,{conversationId:Q,text:Y,...F.length>0?{attachmentIds:F.map(fe=>fe.artifactId)}:{}});ee.conversationId!==Q&&(fs={agentId:e.id,conversationId:ee.conversationId},o(ee.conversationId)),j(!0),O(ee.conversationId)}catch(Q){f(ee=>ee.filter(fe=>fe.id!==X.id)),k(Q instanceof ve?Q.message:String(Q)),S({text:Y,at:Date.now()})}finally{w(!1)}})()},D=()=>{l&&He.cancel(l).catch(Y=>k(String(Y))).finally(()=>j(!1))},H=()=>{var Y;fs=null,o(null),u(null),f([]),p([]),v(null),j(!1),k(null),(Y=a.current)==null||Y.focus()},U=Y=>{I(Y),FA(Y),Y||Wl()},q=l?st(e.id,l):st(e.id),B=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(SU,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:Y=>{var F;Y.preventDefault(),(F=a.current)==null||F.focus()},onCloseAutoFocus:Y=>Y.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",variant:"ghost",onClick:H,disabled:l===null&&h.length===0,children:"New"}),n.jsx(Et,{size:"sm",variant:"ghost",href:q,onClick:Y=>{Y.preventDefault(),s(q)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(Hj,{messages:B,live:m,now:C,working:b||x,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(q),onReadAloud:(Y,F)=>{$(null),lh(F,l??void 0,Y).then(X=>{X&&$(X)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(ie,{message:y}):null,n.jsx(Vj,{ref:a,disabled:x||!e.available,running:b,onSend:M,onStop:D,agentName:e.name,placeholder:`Message ${e.name}…`,draft:N,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:R,onReadAloud:U}),W?n.jsx("p",{className:"wb-voice-note",role:"status",children:W}):null]})]})}function qn(e){return typeof e=="string"?e:null}function s8(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 rT=3;function r8(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function i8(e,t){return e?t?"above-dock":"above-button":"corner"}function a8({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function l8(e){return e.state==="shown"&&e.seenAt===null}function o8(e){const[t,s]=d.useState([]),r=d.useRef(new Set),i=d.useRef(new Set),a=d.useCallback(()=>{e&&A.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>l8(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of t.slice(0,rT))i.current.has(o.id)||(i.current.add(o.id),A.notificationSeen(o.id).catch(()=>{}))},[t]);const l=d.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function c8({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,rT),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":r8(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:dc(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:u8(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 ${dc(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function u8(e){var t;return((t=e.split(`
|
|
108
|
+
`).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const d8=3e4,h8=1e3;function f8(e,t,s){const r=d.useRef(t);r.current=t;const i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",f=j=>{var x;l=Date.now(),A.presence(j).catch(w=>{var y;w instanceof ve&&w.status===401&&(a=!0,(y=i.current)==null||y.call(i))}),j==="active"&&((x=r.current)==null||x.call(r))},m=j=>{if(a||(o=j,c!==null))return;const x=l+h8-Date.now();if(x<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const w=o;o=null,f(w)},x)},p=()=>{u=!0,h()&&m("active")},g=()=>{u=!1,m("away")},v=()=>m(h()?"active":"away");h()&&m("active");const b=window.setInterval(()=>{h()&&u&&m("active")},d8);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",v),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",v)}},[e])}function m8({agents:e,onClose:t,onCreated:s}){return eA(e)?n.jsx(p8,{agents:Ej(e),onClose:t,...s?{onCreated:s}:{}}):n.jsx(qe,{title:"A new group",onClose:t,children:n.jsxs(G,{children:["A group needs two agents. Make another one with ",cz(e)," first."]})})}function p8({agents:e,onClose:t,onCreated:s}){var j,x;const[r,i]=d.useState(""),[a,l]=d.useState([]),[o,c]=d.useState(((j=e.find(w=>w.roles.includes(zc)))==null?void 0:j.id)??((x=e[0])==null?void 0:x.id)??""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=[...new Set([o,...a])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,v=w=>l(y=>y.includes(w)?y.filter(k=>k!==w):[...y,w]),b=async()=>{h(!0),m(null);try{s==null||s(await He.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof ve?w.message:String(w))}finally{h(!1)}};return n.jsx(qe,{title:"A new group",onClose:t,children:n.jsxs(le,{children:[n.jsx(oe,{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(oe,{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(oe,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(w=>w.id!==o).map(w=>n.jsxs("label",{className:"group-pick-row","data-on":a.includes(w.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:a.includes(w.id),onChange:()=>v(w.id)}),n.jsx(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(E,{onClick:t,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!g||u,onClick:()=>void b(),children:u?"Creating…":"Create group"})]})]})})}const g8=1e4;function oh({title:e,body:t,duration:s,onUndo:r,onGone:i}){return n.jsxs(gD,{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(xD,{className:"ui-toast-title",children:e}),t?n.jsx(vD,{className:"ui-toast-body",children:t}):null]}),r?n.jsx(jD,{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 Gj(e){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,h,f)=>{var p,g,v,b;s(c),l(null),i(null);let m;try{const j=f?await A.decide(c,u,h,f):await A.decide(c,u,h);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},i(u==="reject"?`Rejected ${j.action.tool}.`:((g=j.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((v=j.execution)==null?void 0:v.state)??"no execution"}${(b=j.execution)!=null&&b.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function Yj({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,f;const[a,l]=d.useState(!1),{values:o,controls:c}=Mj(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(cs,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(we,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx(Pt,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",nt(e.expiresAt,t)," (",Le(e.expiresAt),"). Policy v",e.policyVersion,", args ",uc(e.argsHash,12),e.jobId?`, job ${uc(e.jobId)}`:"","."]}),c,n.jsxs(ae,{children:[n.jsx(E,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(f=e.permissionScopes)!=null&&f.length?n.jsxs(n.Fragment,{children:[n.jsx(E,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(E,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(E,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(E,{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(ue,{title:"Envelope: everything that decides what the world will see",children:n.jsx(Pt,{children:ss(e.envelope)})}),n.jsx(ue,{title:"Canonical arguments",children:n.jsx(Pt,{children:ss(e.canonicalArgs)})})]}):null]})}function qj(e,t,s){const[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null);return{accept:()=>{e&&(i(!0),c(null),A.acceptPluginAgent(e,t).then(h=>{l(h.agent),s==null||s(h.agent)}).catch(h=>c(h instanceof ve?h.message:String(h))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function iT({agent:e}){return n.jsxs(G,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:st(e.id),children:["Talk to @",e.handle]})]})}function aT(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 x8(e,t){var i;const s=de(()=>A.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>aT(a,e,t)))??null,reload:s.reload}}function v8({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Gj(a=>t(a));return n.jsxs(le,{gap:"sm",children:[n.jsx(Yj,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(ie,{message:r})]})}function Jj({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var f;const l=qj(e,t),o=x8(e,t),[c,u]=d.useState(null),h=l.created??c;if(h)return n.jsx(iT,{agent:h});if(o.action){const m=i??((f=/@(\S+)/.exec(r))==null?void 0:f[1])??t;return n.jsxs(le,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx(v8,{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(le,{gap:"sm",children:[n.jsxs(ae,{children:[n.jsx("span",{children:s}),n.jsx(dt,{}),a?n.jsx(E,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(E,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(ie,{message:l.failure})]})}function lT(){var t;const e=de(()=>A.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function oT({offers:e,reload:t}){return e.length===0?null:n.jsx(ue,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(le,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(Jj,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{A.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const j8=512*1024,w8=/^[A-Za-z0-9+/]*={0,2}$/;function cT(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===""||!w8.test(r)||Math.floor(r.length*3/4)>j8+2?null:{mime:s,data:r}}function uT(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let Er=null,Oo=null,wc=null;const cx=new Set;function dT(){for(const e of cx)e()}function No(){Er&&(Er.onended=null,Er.onerror=null,Er.pause()),Oo&&URL.revokeObjectURL(Oo),Oo=null,wc!==null&&(wc=null,dT())}async function hT(e,t){No();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);Er??(Er=new Audio),Oo=URL.createObjectURL(new Blob([r],{type:e.mime})),wc=t,Er.onended=No,Er.onerror=No,Er.src=Oo,dT();try{await Er.play()}catch{throw No(),new Error("The browser would not play the sound.")}}function c0(e){e!==void 0&&wc!==e||No()}function y8(){return d.useSyncExternalStore(e=>(cx.add(e),()=>cx.delete(e)),()=>wc,()=>null)}const b8=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Xs=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],u0=/^\d{4}-\d{2}-\d{2}$/;function ta(e){return e.split("-").map(Number)}function wa(e,t){const[s,r,i]=ta(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function fT(e){const[t,s,r]=ta(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function mT(e){return b8[fT(e)]}function pT(e){return ta(e)[2]}function d0(e){return wa(e,-((fT(e)+6)%7))}function Dr(e){return Dc(e,{weekday:!0,compact:!0})}function k8(e,t){return e===t?`Today · ${Dr(e)}`:e===wa(t,1)?`Tomorrow · ${Dr(e)}`:Dr(e)}function Ki(e){return tL(e)}const h0=new Map;function ux(e,t){let s=h0.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"}),h0.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 N8(e,t=new Date){return ux(t,e).date}function S8(e,t){return e==="week"?{from:d0(t),days:7}:e==="month"?{from:d0(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function C8(e,t,s){if(e!=="month")return wa(t,s*7);const[r,i]=ta(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function E8(e,t,s,r){const[i,a]=ta(t);if(e==="month")return B1(i,a);const l=wa(s,r-1),[o,c,u]=ta(s),[h,f,m]=ta(l);return z1().date==="iso"?`${s} – ${l}`:nL()?c===f&&o===h?`${Xs[c-1]} ${u} – ${m}, ${h}`:o===h?`${Xs[c-1]} ${u} – ${Xs[f-1]} ${m}, ${h}`:`${Xs[c-1]} ${u}, ${o} – ${Xs[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${Xs[f-1]} ${h}`:o===h?`${u} ${Xs[c-1]} – ${m} ${Xs[f-1]} ${h}`:`${u} ${Xs[c-1]} ${o} – ${m} ${Xs[f-1]} ${h}`}function Ia(e){return e==null?"":String(e)}function A8(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=Ia(Ce(l,t.id)),u=Ia(Ce(l,t.title)),h=Ia(Ce(l,t.start)),f=Ia(Ce(l,t.end));if(c===""||a.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}a.add(c);const m=t.allDay===void 0?void 0:Ce(l,t.allDay),p=m===void 0?u0.test(h):m===!0||m==="true",g=t.tone===void 0?0:Number(Ce(l,t.tone)),v=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":Ia(Ce(l,t.calendar)),tone:v,location:t.location===void 0?"":Ia(Ce(l,t.location))};if(p){const k=h.slice(0,10),N=u0.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):wa(k,1);i.push({...b,allDay:!0,startDate:k,startMin:0,endDate:N,endMin:0});return}const j=new Date(h);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const x=new Date(f),w=ux(j,s),y=Number.isNaN(x.getTime())||x<j?w:ux(x,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function T8(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 Qj(e,t){return e.map(s=>({event:s,part:T8(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 Xj(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${Ki(t.to)}`:s&&t.to===1440?`from ${Ki(t.from)}`:t.from===t.to?Ki(t.from):`${Ki(t.from)}–${Ki(t.to)}`}function dx(e,t,s){return[Xj(e,t),e.title,e.location,e.calendar,Dr(s)].filter(Boolean).join(", ")}const gT=30;function $8(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+gT);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 R8={week:"Week",month:"Month",list:"List"},I8=["week","month","list"],P8="(max-width: 720px)";function M8(e){try{return window.localStorage.getItem(e)}catch{return null}}function D8(e,t){try{window.localStorage.setItem(e,t)}catch{}}function O8(e){const t=e.views&&e.views.length>0?e.views:I8,s=bs(P8),[r,i]=d.useState(()=>{const p=M8(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=d.useState(e.today),[u,h]=d.useState(null),{from:f,days:m}=S8(l,o);return{views:t,view:l,setView:p=>{i(p),D8(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:C8(l,o,p)),h(null)},from:f,days:m,to:wa(f,m),selected:u,select:h}}function L8({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,h=d.useMemo(()=>Array.from({length:u},(v,b)=>wa(c,b)),[c,u]),f=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,g=v=>{if(!v.target.closest('input, textarea, select, [contenteditable="true"]')&&!(v.altKey||v.ctrlKey||v.metaKey)){if(v.key==="ArrowLeft")e.go(-1);else if(v.key==="ArrowRight")e.go(1);else if(v.key==="t"||v.key==="T")e.go(0);else return;v.preventDefault()}};return n.jsxs("div",{className:"cal",role:"region","aria-label":i,tabIndex:0,onKeyDown:g,children:[n.jsxs("div",{className:"cal-bar",children:[n.jsx(E,{size:"sm","aria-label":`Previous ${f}`,onClick:()=>e.go(-1),children:n.jsx(ce,{name:"chevron-left",size:14})}),n.jsx(E,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(E,{size:"sm","aria-label":`Next ${f}`,onClick:()=>e.go(1),children:n.jsx(ce,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:E8(a,l,c,u)}),e.views.length>1?n.jsx(Kt,{label:"View",options:e.views.map(v=>({value:v,label:R8[v]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(F8,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(z8,{dates:h,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:h.map(v=>n.jsx(f0,{date:v,today:o,events:t,empty:r},v))}):null,p?n.jsx(f0,{date:p,today:o,events:t,empty:r}):null]})}function f0({date:e,today:t,events:s,empty:r}){const i=Qj(s,e);return n.jsx(Ge,{flush:!0,title:k8(e,t),children:n.jsx(rt,{children:i.length===0?n.jsx(et,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(et,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:Xj(a,l)},a.id))})})}function F8({dates:e,today:t,events:s,hours:r,onPick:i}){const a=d.useRef(null);d.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:Qj(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(Ge,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Dr(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":Dr(c),children:[n.jsx("span",{className:"cal-wd",children:mT(c)}),n.jsx("span",{className:"cal-num",children:pT(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(h=>h.part.allDay).map(({event:h,part:f})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":h.tone,"aria-label":dx(h,f,c),onClick:()=>i(c),children:h.title},h.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:Ki(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Dr(c),"data-today":o(c),children:$8(u.filter(h=>!h.part.allDay)).map(({event:h,part:f,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":h.tone,"data-short":f.to-f.from<60?"true":void 0,"data-lane":m,"aria-label":dx(h,f,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${f.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(f.to-f.from,gT)/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:Xj(h,f)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const _8=3;function z8({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(h,f)=>e.slice(f*7,f*7+7)),[o,c]=t.split("-").map(Number),u=B1(o,c);return n.jsx(Ge,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(h=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:mT(h)},h))}),l.map(h=>n.jsx("div",{className:"cal-row",role:"row",children:h.map(f=>{const m=Qj(r,f),p=m.slice(0,_8),g=m.length-p.length,v=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":f===i,"data-date":f,"data-today":f===s?"true":void 0,"data-outside":f.slice(0,7)!==t?"true":void 0,"data-selected":f===i?"true":void 0,onClick:()=>a(f),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${Dr(f)}, ${v}`,"aria-pressed":f===i,children:pT(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":dx(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:Ki(j.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${Dr(f)}`,children:["+",g]}):null]},f)})},h[0]))]})})}const xT={width:1200,height:200,top:28,right:12,bottom:24,left:36};function U8(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 zu(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function B8(e){const t=xT,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=>Vi(t.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=U8(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Vi(t.top+i-(j-h)/(f-h)*i),p=e.values.map((j,x)=>{const w=j!==null&&Number.isFinite(j);return{index:x,x:o(x),y:w?m(j):null,value:w?j:null}}),g=[],v=[];if(e.kind==="area"){let j=[];const x=()=>{if(j.length===0)return;const w=j.map((y,k)=>`${k===0?"M":"L"}${y.x},${y.y}`).join(" ");g.push(w),v.push(`${w} L${j[j.length-1].x},${a} L${j[0].x},${a} Z`),j=[]};for(const w of p)w.y===null?x():j.push(w);x()}const b=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Vi(j.x-l*.28),y:j.y,width:Vi(l*.56),height:Vi(a-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:v,bars:b,points:p,slot:l,floor:a}}function W8({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var k;const[l,o]=d.useState(((k=r[0])==null?void 0:k.id)??""),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=s.length,g=c??h,v=r.find(N=>N.id===l)??r[0],b=B8(v),j=xT,x=N=>N%a===0||N===g,w=v.values.filter(N=>N!==null&&Number.isFinite(N));d.useEffect(()=>{const N=m.current,S=g===null?null:N==null?void 0:N.children[g];!N||!S||typeof N.scrollTo!="function"||(S.offsetLeft<N.scrollLeft?N.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>N.scrollLeft+N.clientWidth&&N.scrollTo({left:S.offsetLeft+S.offsetWidth-N.clientWidth,behavior:"smooth"}))},[g]);const y=N=>{var T,R,I;const S=N.key==="ArrowRight"?1:N.key==="ArrowLeft"?-1:0,C=N.key==="Home"?0:N.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(h??-S)+S));C!==null&&(N.preventDefault(),f(C),(I=(R=(T=m.current)==null?void 0:T.children[C])==null?void 0:R.querySelector("button"))==null||I.focus())};return n.jsxs(Ge,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(N=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":N.id===v.id,onClick:()=>o(N.id),children:N.label},N.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":v.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(N=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:N.y,y2:N.y}),n.jsx("text",{className:"pg-series-tick",x:j.left-8,y:N.y,textAnchor:"end",dominantBaseline:"middle",children:zu(N.value,v.unit)})]},N.value)),b.areas.map((N,S)=>n.jsx("path",{className:"pg-series-area",d:N},`a${S}`)),b.lines.map((N,S)=>n.jsx("path",{className:"pg-series-line",d:N},`l${S}`)),b.bars.map(N=>n.jsx("rect",{className:"pg-series-bar","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y,width:N.width,height:N.height},N.index)),g!==null&&b.points[g]?n.jsx("line",{className:"pg-series-guide","data-index":g,x1:b.points[g].x,x2:b.points[g].x,y1:j.top-4,y2:b.floor}):null,v.kind==="area"?b.points.map(N=>N.y!==null&&x(N.index)?n.jsx("circle",{className:"pg-series-dot","data-index":N.index,"data-hover":N.index===g?"true":void 0,cx:N.x,cy:N.y,r:N.index===g?5:3},N.index):null):null,b.points.map(N=>N.y!==null&&N.value!==null&&x(N.index)?n.jsx("text",{className:"pg-series-value","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y-(v.kind==="area"?10:6),textAnchor:"middle",children:zu(N.value,v.unit)},N.index):null),b.points.map(N=>N.index%a===0?n.jsx("text",{className:"pg-series-x",x:N.x,y:j.height-6,textAnchor:"middle",children:s[N.index]},N.index):null),b.points.map(N=>n.jsx("rect",{className:"pg-series-hit","data-index":N.index,x:Vi(j.left+b.slot*N.index),y:0,width:Vi(b.slot),height:j.height,onMouseEnter:()=>u(N.index),onClick:()=>f(N.index)},N.index))]}),n.jsx("figcaption",{className:"sr-only",children:w.length===0?`${v.label}: no values.`:`${v.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${zu(Math.min(...w),v.unit)}, highest ${zu(Math.max(...w),v.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:i.map((N,S)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===h,"aria-label":[N.label,N.value,...N.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":N.icon??"dot",children:n.jsx(ce,{name:Bl(N.icon),size:22})}),N.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:N.value}):null,n.jsx("span",{className:"wb-tile-label",children:N.label}),N.lines.map((C,T)=>n.jsx("span",{className:"wb-tile-line",children:C},T))]})})},S))})]})]})}function Vi(e){return Math.round(e*10)/10}const Zj=d.createContext(null),ch=d.createContext(!1);function $t(){const e=d.useContext(Zj);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function hx(e,t=new Set){if(Array.isArray(e))for(const s of e)hx(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))hx(r,t)}return t}function vT(e,t){if(t.size===0)return!1;for(const s of hx(e))if(t.has(s))return!0;return!1}function jT(){const[e,t]=d.useState(!1);return d.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function wT({revealed:e,onToggle:t}){return n.jsx(E,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function yT(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function bT({children:e}){const[t,s]=jT();return n.jsxs(le,{gap:"sm",children:[n.jsx(ae,{align:"end",children:n.jsx(wT,{revealed:t,onToggle:s})}),t?n.jsx(ch.Provider,{value:!0,children:e}):n.jsx(yT,{})]})}function ew(e){return e===void 0||e==="neutral"?void 0:e}function fx(e){return ew(e)}function H8(e){const t=ew(e);return t==="accent"?void 0:t}function ks(e,t){if(!t)return!0;const s=Ce(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function tw(e,t,s){if("chat"in t){const a=Ve(s,t.chat);return a==null?"":st(String(a))}if("proposals"in t)return g4(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return Kr(e.plugin,t.page);const i=t.item===void 0?null:Ve(s,t.item);return hr(e.plugin,t.page,i==null?null:String(i))}function nw(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=Ce(t.row,r);return i==null?"":String(i)})}function mx(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 kT(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 ya(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ce(t.row,o.row);else if("field"in o){if((r=t.omit)!=null&&r.has(o.field))continue;const c=(i=t.fields)==null?void 0:i[o.field],u=(a=t.shape)==null?void 0:a.find(h=>h.name===o.field);if(c===""&&(u==null?void 0:u.required)!==!0&&(u===void 0||u.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=t.selected??[]:"param"in o?s[l]=t.scope.params[o.param]:s[l]=Ve(t.data,o);return s}function Mn(e,t,s,r){const i=$t(),a=e?{...kT(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=de(()=>e?A.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function Gc(){const e=$t(),t=d.useId(),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=(j,x)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=Ve(x,j.done);return w==null?null:String(w)},p=(j,x,w)=>{const y=j??"refresh";if(typeof y=="object"){const k=tw(e,y.route,x);k===""?e.refresh():e.navigate(k);return}y==="close"&&(w==null||w()),e.refresh()},g=async(j,x,w)=>{r(j.tool),a(null),o(null);try{const y=await A.pageAct(e.plugin,{tool:j.tool,args:x});if(y.approvalId){u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}});return}u(null),f(null);const k=cT(y.result);o(m(j,y.result)??(k?uT(y.result):null)),k&&await hT(k,t),p(j.then,y.result,w)}catch(y){a(y instanceof Error?y.message:String(y)),e.refresh()}finally{r(null)}},v=j=>{if(!j){e.refresh();return}const x=h;if(u(null),f(null),x&&j.decision==="approve"&&j.state==="succeeded"){o(m(x.ref,j.result)),p(x.then,void 0,x.onDone);return}e.refresh()},b=()=>{a(null),o(null)};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:v,run:g,reset:b}}function Hl({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=d.useState(!1),u=f=>nw(f,{...i===void 0?{}:{count:i},row:a}),h=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(E,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(E,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(E,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,t),children:r&&e.busy?e.busy:h})}function uh({id:e,onDecided:t}){const s=$t(),r=de(()=>A.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Gj(c=>{t?t(c):s.refresh()});return r.error?n.jsx(ie,{message:r.error}):r.data?n.jsxs(le,{children:[n.jsx(Yj,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,h,f)=>{o(c,u,h,f)}}),a?n.jsx(G,{tone:"good",role:"status",children:a}):null,n.jsx(ie,{message:l})]}):n.jsx(pe,{children:"Loading the approval…"})}function Kl({act:e}){return e.error?n.jsx(ie,{message:e.error}):e.approvalId?e.waiting?n.jsxs(le,{children:[n.jsx(G,{role:"status",children:e.waiting}),n.jsx(uh,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(uh,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(G,{tone:"good",role:"status",children:e.done}):null}function yc(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:Ce(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 NT(e,t,s){const r=$t(),i=e.optionsFrom,a=i?{...kT(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=de(()=>i?A.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:pr(o.data,i.rows).map(c=>({value:String(Ce(c,i.value)??""),label:String(Ce(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function K8({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=NT(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},h=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const m=Array.isArray(s)?s.map(String):[],g=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return n.jsx(oe,{label:e.label,hint:l?void 0:[h,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(EU,{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(V8,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:h,children:m}):n.jsx(oe,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return n.jsx(oe,{label:e.label,hint:h,wide:!0,children:n.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return n.jsx(oe,{label:e.label,hint:h,inline:!0,wide:!l,children:n.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const f=e.type==="secret"?"password":e.type==="number"?"number":e.type;return n.jsx(oe,{label:e.label,hint:h,children:n.jsx("input",{...u,type:f,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?G8(m.target.value):m.target.value)})})}function V8({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=$t(),u=d.useId(),h=y8()===u,[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>()=>c0(u),[u]);const w=sw(s,r,i),y=t.args!==void 0?ya(t.args,{data:i,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),k=async()=>{if(h){c0(u);return}m(!0),g(null),b(null),x(null);try{const S=await A.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){x(S.approvalId);return}g(uT(S.result));const C=cT(S.result);C&&await hT(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},N=h?"Stop":t.label;return n.jsx(oe,{label:e.label,hint:l,action:n.jsx(E,{"data-shape":"icon","aria-label":f?`${t.label}: working`:N,title:N,"aria-busy":f||void 0,"aria-pressed":t.icon==="play"?h:void 0,disabled:a===!0||f,onClick:()=>void k(),children:f?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(ce,{name:h?"stop":t.icon??"arrow"})}),after:v?n.jsx(ie,{message:v}):j?n.jsx(uh,{id:j,onDecided:()=>x(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function G8(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function ST(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function sw(e,t,s){const r=ST(t,s);return new Set(e.filter(i=>i.when!==void 0&&!ks(r,i.when)||i.disabledWhen!==void 0&&ks(r,i.disabledWhen)).map(i=>i.name))}function wf({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=ST(t,s);return n.jsx(Us,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||ks(o,c.when)).map(c=>n.jsx(K8,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&ks(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const bc=d.createContext(!1),CT=d.createContext(!1),ET=d.createContext(!1);function us({title:e,note:t,actions:s,children:r}){const i=d.useContext(bc);return n.jsx(ue,{title:e,aside:t,actions:s,panel:i,children:n.jsx(bc.Provider,{value:!1,children:n.jsx(CT.Provider,{value:i,children:r})})})}function mr({component:e,data:t,choose:s,chosen:r}){const i=$t(),a=d.useContext(ch);if(!ks(t,e.when))return null;if(e.kind!=="section"&&!a&&vT(e,i.sensitive))return n.jsx(bT,{children:n.jsx(mr,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(Y8,{component:e,data:t});case"notice":return n.jsx(G,{tone:ew(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(Ve(t,e.text)??"")});case"link":return n.jsx(q8,{component:e,data:t});case"progress":return n.jsx(Q8,{component:e,data:t});case"chart":return n.jsx(X8,{component:e,data:t});case"stats":return n.jsx(Z8,{component:e,data:t});case"list":return n.jsx(tW,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(sW,{component:e,data:t});case"detail":return n.jsx(aW,{component:e,data:t});case"form":return n.jsx(lW,{component:e,data:t});case"search":return n.jsx(uW,{component:e,data:t});case"list-detail":return n.jsx(dW,{component:e,data:t});case"repeat":return n.jsx(hW,{component:e,data:t});case"calendar":return n.jsx(fW,{component:e,data:t});case"tiles":return n.jsx(mW,{component:e,data:t});case"series-panel":return n.jsx(pW,{component:e,data:t});case"hero":return n.jsx(gW,{component:e,data:t});case"tabs":return n.jsx(xW,{component:e,data:t});case"expand":return n.jsx(vW,{component:e,data:t});case"button":return n.jsx(jW,{component:e,data:t});case"approval":return n.jsx(yW,{component:e,data:t});case"artifact":return n.jsx(bW,{component:e,data:t});case"editor":return n.jsx(kW,{component:e,data:t});case"agent-offer":return n.jsx(wW,{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 Y8({component:e,data:t}){const s=$t(),r=d.useContext(ch),[i,a]=jT(),l=!r&&vT(e.body,s.sensitive),o=l&&!i,c=d.useContext(bc);let u=e.body.length;const h=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&h(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(us,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(mr,{component:p,data:t},g)),l?n.jsx(wT,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(le,{gap:"lg",divided:c,children:o?n.jsx(yT,{}):n.jsx(ch.Provider,{value:r||l,children:f.map((p,g)=>n.jsx(mr,{component:p,data:t},g))})})})}function q8({component:e,data:t}){const s=$t(),r=tw(s,e.to,t);return r===""?null:n.jsx(ae,{children:n.jsx(Et,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function m0(e){return Math.round(e/1e6)}function J8(e,t){const s=ts(Ve(t,e.value))??0,r=e.total?ts(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?`${m0(s)} of ${Math.max(1,m0(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function Q8({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}=J8(e,t);return n.jsxs(le,{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(vA,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function X8({component:e,data:t}){const s=Mn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:pr(s.data,e.rows),i=r.map(h=>String(Ce(h,e.x)??"")),a=h=>r.map(f=>ts(Ce(f,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:a(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:a(h)})),u=e.target?ts(Ve(s.data,e.target))??null:null;return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Vl,{text:e.empty??"Nothing recorded yet."}):n.jsx(jU,{xs:i,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:h=>/^\d{4}-\d{2}-\d{2}/.test(h)?Dg(h):h,formatY:h=>Zt(h,"number",null)})]})}function Z8({component:e,data:t}){const s=Mn(e.query,t);return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(gf,{children:e.items.map((r,i)=>n.jsx(ir,{label:r.label,value:Zt(Ve(s.data,r.value),r.unit??"text",null),tone:H8(r.tone)},i))})]})}function AT(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?tw(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,h)=>{const f=Ve(s,u.value);if(f==null||f==="")return null;const m=eW(u,f,s);return n.jsx(we,{tone:fx(m.tone),children:m.text},h)});return{text:a,href:l,pills:n.jsx(n.Fragment,{children:c}),meta:i.join(" · "),title:l?n.jsx("a",{href:l,onClick:u=>{u.preventDefault(),e.navigate(l)},children:a}):a,sub:t.sub?String(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 eW(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]:mx(e.tone,s)}}function pr(e,t){const s=Ce(e,t);return Array.isArray(s)?s:[]}function TT(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:Ce(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 tW({component:e,data:t,onChoose:s,chosen:r}){var N;const i=$t(),a=d.useContext(ET),l=Mn(e.query,t),o=Gc(),[c,u]=d.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=pr(l.data,e.rows),m=e.collapsed?pr(l.data,e.collapsed.rows):[],p=$T(e.actions,f,o),g={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},v=TT([...f,...m],e.key??((N=e.select)==null?void 0:N.key),g),b=new Map(v.map(S=>[S.row,S.key])),j=new Set(v.map(S=>S.row)),x=new Set(v.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!ks(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>x.has(S)),y=d.useMemo(()=>{const S=f.filter(T=>j.has(T));if(!e.groupBy)return[{label:null,rows:S}];const C=new Map;for(const T of S){const R=String(Ce(T,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],T])}return[...C].map(([T,R])=>{var I,L;return{label:((L=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:L[T])??T,rows:R}})},[f,e.groupBy,v.length]),k=S=>S.map(C=>{var W;const T=AT(i,e.item,C,s),R=b.get(C);if(h&&(s||T.href))return n.jsx(jA,{href:T.href??"#",current:r===R,onClick:()=>s?s(R):i.navigate(T.href),title:T.text,meta:T.meta,sub:T.sub,side:T.pills},R);const I=((W=e.select)==null?void 0:W.disabledWhen)!==void 0&&ks(C,e.select.disabledWhen),L=(e.actions??[]).filter($=>ks(C,$.when));return n.jsx(et,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${T.text}`,disabled:I,checked:c.includes(R),onClick:$=>$.stopPropagation(),onChange:$=>u(P=>$.target.checked?[...P,R]:P.filter(O=>O!==R))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===R?"true":void 0,onClick:$=>{$.preventDefault(),s(R)},children:T.text}):T.title,sub:T.sub,side:n.jsxs(n.Fragment,{children:[T.side,L.map(($,P)=>n.jsx(RT,{action:$,row:C,data:l.data,act:o,onForm:p.show},P))]})},R)});return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:l.error}),p.open?null:n.jsx(Kl,{act:o}),p.open?n.jsx(IT,{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(pe,{children:"Loading…"}):n.jsx(Vl,{text:e.empty??"Nothing here yet."}):n.jsxs(rt,{children:[e.select?n.jsx(et,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&w.length===x.size,disabled:x.size===0,onChange:S=>u(S.target.checked?[...x]:[])}),title:n.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,y.map((S,C)=>n.jsxs("div",{children:[S.label?n.jsx("div",{className:"ui-list-group",children:S.label}):null,k(S.rows)]},C))]}),e.collapsed&&m.some(S=>j.has(S))?n.jsx(At,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:n.jsx(rt,{children:k(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 T=w.length>0||S.all!==!0?w:[...x];return n.jsx(Hl,{action:S,args:ya(S.args,{data:l.data,selected:T,scope:i}),count:T.length,disabled:o.busy||T.length===0,running:o.running===S.tool,onRun:(R,I)=>{u([]),o.run(R,I)}},C)})]}):null]})}function nW(e,t,s){return Object.entries(e).every(([r,i])=>{const a=typeof i=="string"?i:Ce(s,i.row);return a!=null&&t[r]===String(a)})}function $T(e,t,s){const r=$t(),[i,a]=d.useState(null);return d.useEffect(()=>{var l;if(!(i!==null||t.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=t.find(h=>ks(h,o.when)&&nW(c,r.params,h));if(u!==void 0){a({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(h=>[h,null])));return}}},[t.length,JSON.stringify(r.params)]),{open:i,show:(l,o)=>{s.reset(),a({action:l,row:o})},close:()=>{s.reset(),a(null)},finish:()=>a(null)}}function RT({action:e,row:t,data:s,act:r,onForm:i}){const a=$t();return e.form?n.jsx(E,{disabled:r.busy,onClick:()=>i(e,t),children:nw(e.label,{row:t})}):n.jsx(Hl,{action:e,args:ya(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 IT({open:e,data:t,act:s,onClose:r,onDone:i}){const a=$t(),{action:l,row:o}=e,c=l.form,[u,h]=d.useState(()=>yc(c.fields,o)),f=c.fields.some(v=>v.required&&(u[v.name]===""||u[v.name]===void 0)),{confirm:m,...p}=l,g={...p,label:c.submit};return n.jsx(qe,{title:nw(c.title,{row:o}),onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(Hl,{action:g,args:ya(l.args,{data:t,row:o,fields:u,shape:c.fields,scope:a}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(v,b)=>void s.run(v,b,i)})]}),children:n.jsxs(le,{children:[n.jsx(wf,{fields:c.fields,values:u,data:o,onChange:(v,b)=>h(j=>({...j,[v]:b}))}),n.jsx(ie,{message:s.error})]})})}function sW({component:e,data:t}){const s=Mn(e.query,t),r=Gc(),i=pr(s.data,e.rows),a=$T(e.actions,i,r);return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),a.open?null:n.jsx(Kl,{act:r}),a.open?n.jsx(IT,{open:a.open,data:s.data,act:r,onClose:a.close,onDone:a.finish}):null,i.length===0?s.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Vl,{text:e.empty??"Nothing here yet."}):n.jsxs(jr,{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:Zt(Ce(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:rW(c,l,u),children:c.pill?n.jsx(iW,{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=>ks(l,c.when)).map((c,u)=>n.jsx(RT,{action:c,row:l,data:s.data,act:r,onForm:a.show},u))})}):null]},o))})]})]})}function rW(e,t,s){if(e.hint){const r=Ce(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function iW({column:e,row:t}){var l,o;const s=Ce(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var v;const h=c,f=typeof h=="object"&&h!==null?h.value:c;if(f==null||f==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(v=e.pill)==null?void 0:v.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:Zt(f,e.type??"text",null);return n.jsx(we,{tone:fx(mx(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]:Zt(s,e.type??"text",null);return n.jsx(we,{tone:fx(mx((o=e.pill)==null?void 0:o.tone,t)),children:a})}function aW({component:e,data:t}){const s=Mn(e.query,t);return s.error?n.jsx(ie,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(us,{title:e.title,note:e.note,children:n.jsxs(le,{gap:"lg",children:[e.fields.length>0?n.jsx(Ht,{items:e.fields.map(r=>({key:r.label,label:r.label,value:Zt(Ve(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(mr,{component:r,data:s.data},i))]})})}function lW({component:e,data:t}){const s=$t(),r=Mn(e.initial,t),i=Gc(),[a,l]=d.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(oW,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(ue,{title:e.title,aside:e.note,actions:n.jsx(E,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(Kl,{act:i}),a?n.jsx(qe,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:r.error}),c]})}function oW({component:e,data:t,initialData:s,act:r,onDone:i}){const a=d.useContext(CT),l=$t(),[o,c]=d.useState(()=>yc(e.fields,s)),u=sw(e.fields,o,s),h=e.fields.some(f=>f.required&&!u.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return n.jsxs(le,{children:[n.jsx(wf,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:n.jsx(Kl,{act:r}),n.jsx(ae,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Hl,{action:e.submit,args:ya(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,i)})})]})}function cW(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 p0(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function uW({component:e,data:t}){const s=$t(),[r,i]=d.useState(()=>yc(e.fields,t)),[a,l]=d.useState(e.auto===!0),[o,c]=d.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=Mn(a&&u?e.query:void 0,t),f=pr(h.data,e.rows),m=e.count===void 0?void 0:Ce(h.data,e.count),p=e.note===void 0?void 0:Ce(h.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,v=e.fields.filter(C=>C!==g),b=C=>{s.setParams(Object.fromEntries(e.fields.map(T=>[T.name,String(C[T.name]??"")||null]))),l(!0)},j=(C,T)=>{const R={...r,[C]:T};i(R),e.auto&&b(R)},x=()=>{const C=yc(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(T=>[T.name,null]))),l(!1))},w=a?v.filter(C=>p0(s.params[C.name])):[],y=g?w.map(C=>n.jsx(Xd,{label:C.label,onRemove:()=>{const T={...r,[C.name]:C.type==="checkbox"?!1:""};i(T),b(T)},children:cW(C,String(s.params[C.name]))},C.name)):[],k=v.filter(C=>p0(r[C.name])).length,N=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(E,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:n.jsx(E,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return n.jsx(us,{title:e.title,children:n.jsxs(le,{children:[n.jsx(bA,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:g?n.jsx("input",{id:`f-${g.name}`,name:g.name,type:g.type==="email"?"email":"search","aria-label":g.label,placeholder:g.hint??g.label,title:g.hint,required:g.required,value:String(r[g.name]??""),onChange:C=>j(g.name,C.target.value)}):void 0,filters:v.length>0?n.jsx(wf,{fields:v,values:r,data:t,compact:!0,onChange:j}):void 0,...g&&v.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:k}:{},chips:y.length>0?y:void 0,actions:N}),n.jsx(ie,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${Zt(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?f.length===0?n.jsx(pe,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(rt,{children:f.map((C,T)=>{const R=AT(s,S,C);return n.jsx(et,{title:R.title,sub:R.sub,side:R.side},T)})})}):null]})})}function dW({component:e,data:t}){const s=$t(),r=e.selection==="local",[i,a]=d.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(le,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>n.jsx(mr,{component:u,data:t},h))});return n.jsx(bc.Provider,{value:!1,children:n.jsx(wA,{list:n.jsx(ET.Provider,{value:!0,children:n.jsx(mr,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(Zj.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function hW({component:e,data:t}){const s=$t(),[r,i]=d.useState(!1),a=Mn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&ks(a.data,e.poll.while);d.useEffect(()=>i(l),[l]);const o=pr(a.data,e.rows);return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:a.error}),o.length===0?a.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Vl,{text:e.empty??"Nothing here yet."}):n.jsx(le,{gap:"lg",divided:!0,children:TT(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(ue,{children:n.jsx(le,{children:e.body.map((h,f)=>n.jsx(mr,{component:h,data:u},f))})},c))})]})}function fW({component:e,data:t}){const s=$t(),r=O8({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:N8(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=Mn(e.query,t,void 0,{from:r.from,to:r.to}),a=d.useMemo(()=>A8(pr(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(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:i.error}),n.jsx(L8,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function mW({component:e,data:t}){var f;const s=$t(),r=Mn(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=pr(r.data,e.items).flatMap(m=>{const p=Aj([m],i).tiles[0];return p?[{tile:p,key:e.select?String(Ce(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((f=a[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,h=a.some(m=>m.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:r.error}),r.data===void 0?n.jsx(pe,{children:"Loading…"}):a.length===0?n.jsx(Vl,{text:e.empty??"Nothing to show."}):n.jsx(MA,{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 pW({component:e,data:t}){const s=Mn(e.query,t),r=pr(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(us,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Vl,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(Ce(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)=>Aj([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=>ts(Ce(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:s.error}),n.jsx(W8,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function gW({component:e,data:t}){const s=Mn(e.query,t),r=o=>{const c=Ce(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:s.error}),n.jsx(pe,{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(ce,{name:Bl(Hg(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 xW({component:e,data:t}){var u;const s=$t(),[r,i]=d.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=NT({name:(a==null?void 0:a.param)??"",label:(a==null?void 0:a.label)??"",...a!=null&&a.options?{options:a.options}:{},...a!=null&&a.optionsFrom?{optionsFrom:a.optionsFrom}:{}},{},t),o=a?l.some(h=>h.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(h=>h.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,children:[a&&l.length>1?n.jsx(Kt,{label:a.label,options:l,value:o,onChange:h=>s.setParams({[a.param]:h})}):null,e.tabs.length>1?n.jsx(Kt,{label:e.title??"View",options:e.tabs.map(h=>({value:h.id,label:h.label})),value:c.id,onChange:i}):null]}),c.body.map((h,f)=>n.jsx(mr,{component:h,data:t},`${c.id}-${f}`))]})}function vW({component:e,data:t}){const[s,r]=d.useState(!1),i=Mn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Ve(t,e.label)??"");return n.jsxs(At,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(ie,{message:i.error}),i.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(le,{children:e.body.map((l,o)=>n.jsx(mr,{component:l,data:i.data},o))})]})}function jW({component:e,data:t}){const s=$t(),r=Gc();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{align:"end",children:n.jsx(Hl,{action:e.action,args:ya(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(Kl,{act:r})]})}function wW({component:e}){const t=$t();return n.jsx(Jj,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function yW({component:e,data:t}){const s=Ce(t,e.path);return typeof s!="string"||s===""?null:n.jsx(uh,{id:s})}function bW({component:e,data:t}){const s=Ce(t,e.path);return typeof s!="string"||s===""?null:n.jsx(ae,{children:n.jsx("a",{href:Ni(s),children:e.label})})}function kW({component:e,data:t}){const s=Mn(e.query,t),r=Gc();return s.error?n.jsx(ie,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(Kl,{act:r}),n.jsx(NW,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function NW({component:e,data:t,loaded:s,act:r}){const i=$t(),[a,l]=d.useState(()=>yc(e.fields,s)),o={...a,version:Ce(s,e.version)},c=sw(e.fields,a,s),u=e.readOnlyWhen!==void 0&&ks(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Hl,{action:p,args:ya(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(v,b)=>void r.run(v,b)},`${p.tool}-${g}`);return n.jsx(us,{title:e.title,note:e.note,children:n.jsxs(le,{children:[n.jsx(wf,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(v=>({...v,[p]:g}))}),u?null:n.jsxs(ae,{align:"end",children:[h.map(m),h.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 rw({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a,params:l}){const[o,c]=d.useState(()=>({...l})),u=JSON.stringify(l??{});d.useEffect(()=>{l&&Object.keys(l).length>0&&c(b=>({...b,...l}))},[u]);const[h,f]=d.useState(0),m={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...o,...t?{item:t}:{},...CW(e,t)},setParams:b=>c(j=>{const x={...j};for(const[w,y]of Object.entries(b))y===null?delete x[w]:x[w]=y;return x}),navigate:s,timezone:r,version:h,refresh:()=>f(b=>b+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],g=!i&&(p==null?void 0:p.kind)==="notice"&&typeof p.text=="string"&&p.when===void 0&&p.title===void 0&&(p.tone===void 0||p.tone==="neutral")?p.text:void 0,v=g===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(Zj.Provider,{value:m,children:n.jsx(Pn,{embedded:i,title:e.title,lede:g,children:n.jsx(SW,{page:v,boxed:i===!0})})})}function SW({page:e,boxed:t}){const s=$t();return e.data&&s.sensitive.has(e.data.query)?n.jsx(bT,{children:n.jsx(g0,{page:e,boxed:t})}):n.jsx(g0,{page:e,boxed:t})}function g0({page:e,boxed:t}){const s=Mn(e.data,null);return n.jsxs(le,{gap:"lg",divided:!t,children:[n.jsx(ie,{message:s.error}),n.jsx(bc.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(mr,{component:r,data:s.data??null},i))})]})}function CW(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 EW(e){return n.jsx(rw,{...e,embedded:!0})}function Vl({text:e}){const t=e.search(/[.!?]\s/),s=t===-1?e.replace(/[.]$/,""):e.slice(0,t+(e[t]==="."?0:1)),r=t===-1?"":e.slice(t+1).trim();return n.jsx(Tn,{title:s,children:r||null})}const x0=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],AW=["","image","pdf","table","text","code","audio","video","archive","file"];function TW({hash:e,timezone:t,navigate:s,agents:r}){var W;const i=t4(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,h]=d.useState(c);d.useEffect(()=>{h(c)},[c]);const f=($,P=!1)=>s(Au(a,{q:c,origin:l,family:o,...$}),P);d.useEffect(()=>{if(u===c)return;const $=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout($)},[u]);const[m,p]=d.useState(null),[g,v]=d.useState(null),[b,j]=d.useState(null),[x,w]=d.useState(!1),[y,k]=d.useState(!1),N=$=>{var P;return $?((P=r.find(O=>O.id===$))==null?void 0:P.name)??$:""},S=d.useRef(0);d.useEffect(()=>{const $=++S.current;p(null),v(null),w(!1),j(null),A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(P=>{S.current===$&&(p(P.entries),v(P.next))}).catch(P=>{S.current===$&&j(P instanceof ve?P.message:String(P))})},[c,l,o]);const C=()=>{if(!g||x)return;w(!0);const $=S.current;A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(P=>{S.current===$&&(p(O=>{const M=new Set((O??[]).map(D=>D.id));return[...O??[],...P.entries.filter(D=>!M.has(D.id))]}),v(P.next))}).catch(P=>{S.current===$&&j(P instanceof ve?P.message:String(P))}).finally(()=>{S.current===$&&w(!1)})},T=(l?1:0)+(o?1:0),R=((W=x0.find($=>$.id===l))==null?void 0:W.label)??l,I=n.jsxs(n.Fragment,{children:[m===null?n.jsx(pe,{children:"Loading…"}):m.length===0?n.jsx(pe,{children:"No file matches that."}):n.jsx(rt,{children:m.map($=>n.jsx(jA,{href:Au($.id,{q:c,origin:l,family:o}),current:$.id===a,onClick:()=>s(Au($.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":$.family,children:$.family==="image"&&!$.deleted?n.jsx("img",{src:Vr($.id),alt:"",loading:"lazy"}):n.jsx(Wj,{family:$.family})}),title:$.filename??"Untitled file",meta:n.jsx("span",{title:nt($.createdAt,t),children:Le($.createdAt)}),sub:`${ea[$.family]} · ${Kn($.sizeBytes)} · ${PT($,N)}${$W($,N)}`},$.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(E,{size:"sm",onClick:C,disabled:x,children:x?"Loading…":"Show more"})}):null]}),L=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."})]}),L?n.jsx(Tn,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):n.jsxs(n.Fragment,{children:[n.jsx(bA,{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:$=>h($.target.value)}),filters:n.jsxs(Us,{dense:!0,children:[n.jsx(oe,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:$=>f({origin:$.target.value}),children:x0.map($=>n.jsx("option",{value:$.id,children:$.label},$.id))})}),n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:$=>f({family:$.target.value}),children:AW.map($=>n.jsx("option",{value:$,children:$===""?"Any kind":ea[$]},$))})})]}),filtersOpen:y,onToggleFilters:()=>k($=>!$),active:T,chips:T>0?n.jsxs(n.Fragment,{children:[l?n.jsx(Xd,{label:"Origin",onRemove:()=>f({origin:""}),children:R}):null,o?n.jsx(Xd,{label:"Kind",onRemove:()=>f({family:""}),children:ea[o]}):null]}):void 0}),n.jsx(ie,{message:b}),n.jsx(wA,{className:"files-split",label:"Files",list:I,detail:a?n.jsx(RW,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(Au(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function $W(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 PT(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 RW({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let x=!1;return l(null),h(null),A.libraryEntry(e).then(w=>{x||l(w)}).catch(w=>{x||h(w instanceof ve&&w.status===404?"This file is no longer in the library.":w instanceof ve?w.message:String(w))}),()=>{x=!0}},[e]);const f=x=>{var w;return x?((w=s.find(y=>y.id===x))==null?void 0:w.name)??x:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(E,{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(pe,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:v}=a,b=m.filename??"Untitled file",j=()=>{c(!0),A.libraryEntry(e,p.length).then(x=>l(w=>w&&{...w,contexts:[...w.contexts,...x.contexts],contextsTotal:x.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(E,{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(Wj,{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:[ea[m.family]," · ",Kn(m.sizeBytes)," · ",nt(m.createdAt,t)]})]}),v?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:Ni(m.id),download:b,children:"Download"}):null]}),v?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(BA,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:v}),n.jsx(Ht,{items:[{label:"Origin",value:PT(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(x=>{const w=x.groupId?Hi(x.groupId,x.conversationId):st(x.conversationAgentId,x.conversationId),y=x.groupId?x.groupName??"a group":f(x.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:x.groupId?`Group: ${y}`:y}),n.jsxs("span",{className:"muted",children:[" · ",x.kind==="produced"?`made by ${f(x.agentId)||"an agent"}`:x.kind==="reused"?"sent again":"sent by you"," · ",Le(x.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:k=>{k.preventDefault(),r(w)},children:"Open conversation"})]},`${x.conversationId}:${x.kind}`)})}),p.length<g?n.jsx(ae,{align:"end",children:n.jsx(E,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const IW={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 MT(e){return e&&IW[e]||"plug"}const DT="buddi.keepClose";let bl=null;const px=new Set;function gx(){for(const e of px)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),bl=e,gx()}),window.addEventListener("appinstalled",()=>{bl=null,aw(),gx()}));function yf(){const[e,t]=d.useState(bl);return d.useEffect(()=>{const s=()=>t(bl);return px.add(s),s(),()=>{px.delete(s)}},[]),OT()?null:e}async function iw(e){try{await e.prompt();const t=await e.userChoice;bl===e&&(bl=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&aw(),gx(),s}catch{return!1}}function PW(){try{return window.localStorage.getItem(DT)!==null}catch{return!1}}function aw(){try{window.localStorage.setItem(DT,"dismissed")}catch{}}function OT(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function MW(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function LT(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 DW(e){return/Mac|iPhone|iPad/.test(e)}function OW(){const e=yf(),[t,s]=d.useState(PW);if(t||!e)return null;const r=()=>{aw(),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(E,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>{iw(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function LW(){const e=yf(),[t,s]=d.useState(void 0),[r]=d.useState(OT);if(d.useEffect(()=>{if(r)return;let o=!0;return A.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=MW(),l=e?null:LT(i);return n.jsx(ue,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>{iw(e)},children:"Install the app"})}):void 0,children:n.jsxs(le,{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 ",DW(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 FW=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,_W=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,zW="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=",xx={desk:FW,phone:_W,thumb:zW},Km={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function UW(e){return e?xx.phone:xx.desk}function FT(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const BW=3,_T=8e3,WW={hiddenHere:new Set,restoredHere:new Set};function HW(e,t){return t.hiddenHere.has(e.id)?!0:e.hidden&&!t.restoredHere.has(e.id)}function KW(e,t=WW){return(e??[]).filter(s=>!HW(s,t)).slice(0,BW)}function zT(e){const[t,s]=d.useState(new Set),[r,i]=d.useState(new Set),[a,l]=d.useState(null),o=d.useRef(e);o.current=e;const c=(m,p)=>new Set(m).add(p),u=(m,p)=>{const g=new Set(m);return g.delete(p),g};return d.useEffect(()=>{if(!a)return;const m=window.setTimeout(()=>l(null),_T);return()=>window.clearTimeout(m)},[a]),{hiddenHere:t,restoredHere:r,justHidden:a,hide:(m,p)=>{s(g=>c(g,m.id)),i(g=>u(g,m.id)),l({glance:m,spot:p}),A.setGlanceHidden(m.id,!0).then(()=>{var g;return(g=o.current)==null?void 0:g.call(o)},()=>{s(g=>u(g,m.id)),l(g=>(g==null?void 0:g.glance.id)===m.id?null:g)})},undo:()=>{if(!a)return;const{glance:m}=a;l(null),s(p=>u(p,m.id)),i(p=>c(p,m.id)),A.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{i(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function VW({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(E,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function GW(e){return e.link?Uj(e.link.plugin,e.link.page,e.link.place):null}function YW({glances:e,navigate:t,onChanged:s,except:r,hiding:i}){var u,h;const a=zT(s),l=i??a,o=KW(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=n.jsx(VW,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:n.jsxs("span",{className:"home-glances",children:[((h=l.justHidden)==null?void 0:h.spot)==="line"?n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(f=>{const m=GW(f),p=n.jsxs(n.Fragment,{children:[n.jsx(ce,{name:Bl(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(ce,{name:"close",size:10})})]},f.id)})]})}function qW(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 JW({points:e,className:t="wg-spark"}){const s=qW(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 Pa=Math.PI/180;function QW(e,t,s){const r=e.getTime()/864e5+24405875e-1-2451545,i=(357.529+.98560028*r)*Pa,l=(280.459+.98564736*r+1.915*Math.sin(i)+.02*Math.sin(2*i))*Pa,o=(23.439-36e-8*r)*Pa,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)*Pa-c,m=t*Pa,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)))/Pa}function XW(e,t,s){return QW(e,t,s)>-.833}const ZW={small:2,medium:4},v0=new Map;function eH(e){let t=v0.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"}),v0.set(e,t)),t}function j0(e,t){const s=Object.fromEntries(eH(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 tH(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 nH(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 sH(e,t,s,r,i){const a=j0(e,t.zone),l=j0(e,s),o=a.date===l.date?"Today":a.date>l.date?"Tomorrow":"Yesterday",c=a.offset-l.offset,u=Pc(i?{timeFormat:i}:{},()=>Vt(e,t.zone)),h=r?"your time":nH(c);return{...a,day:o,daytime:typeof t.latitude=="number"&&typeof t.longitude=="number"?XW(e,t.latitude,t.longitude):a.h>=6&&a.h<18,offsetText:r?"Here":tH(c),time:u,label:`${t.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function rH(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 iH(e){const[t,s]=d.useState(()=>new Date);return d.useEffect(()=>{const r=e?1e3:6e4;let i;const a=()=>{i=setTimeout(()=>{s(new Date),a()},r-Date.now()%r+5)};return s(new Date),a(),()=>clearTimeout(i)},[e]),t}function w0({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 aH=Array.from({length:12},(e,t)=>t);function lH({time:e,seconds:t}){const s=rH(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"}),aH.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(w0,{angle:s.hour,length:24,width:4.6}),n.jsx(w0,{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 oH({body:e,size:t}){const s=bs("(prefers-reduced-motion: reduce)"),r=iH(!s),i=e.clocks.slice(0,ZW[t]);return n.jsx("div",{className:"wg-clocks","data-count":i.length,children:i.map((a,l)=>{let o;try{o=sH(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(lH,{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 cH=3,uH={small:4,medium:6};function Vm({icon:e,size:t}){return e?n.jsx("span",{className:"wg-icon",children:n.jsx(ce,{name:Bl(e),size:t})}):null}function lw({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(Vm,{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(JW,{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,cH).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(Vm,{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,uH[t]).map((s,r)=>n.jsxs("span",{className:"wg-tile",children:[n.jsx("span",{className:"wg-tile-label",children:s.label}),n.jsx(Vm,{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(oH,{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(ce,{name:Bl(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 vx({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(ce,{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 y0(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function dH(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 hH({field:e,value:t,places:s,onChange:r}){const i=Array.isArray(t)?t:t?[t]:[],[a,l]=d.useState(""),[o,c]=d.useState([]),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=new Map;for(const y of s)p.set(y.id,{value:{place:y.id},label:y.label,sub:y.name});for(const y of[...i,...o])"place"in y||p.set(y0(y),{value:y,label:y.label,sub:y.name});const g=[...p.entries()].map(([y,k])=>({value:y,label:k.label,sub:k.sub})),v=i.map(y0),b=s.find(y=>y.id==="home"||y.label.toLowerCase()==="home")??s[0],j=e.multiple?v:v[0]??(b==null?void 0:b.id)??"",x=y=>{const k=(Array.isArray(y)?y:[y]).map(N=>{var S;return(S=p.get(N))==null?void 0:S.value}).filter(N=>!!N);r(e.multiple?k.slice(-3):k[0]??null)},w=()=>{const y=a.trim();y.length<2||(h(!0),m(null),A.findPlace(y).then(({found:k})=>{const N=k.slice(0,3).map(dH);c(N),N.length===0?m(`Nothing found for “${y}”.`):e.multiple?r([...i,N[0]].slice(-3)):r(N[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return n.jsxs("div",{className:"wg-field-stack",children:[g.length>0?n.jsx(vx,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:x}):null,n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{value:a,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),w())}}),n.jsx(E,{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 fH({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(Kt,{label:e.label,options:l,value:o,onChange:r}):n.jsx(vx,{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(vx,{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(hH,{field:e,value:t,places:s.places,onChange:r});break;case"timeFormat":i=n.jsx(Kt,{label:e.label,options:[{value:"profile",label:U1()},{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 mH({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(lw,{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 UT({info:e,placement:t,surface:s,onSave:r,onRemove:i,onClose:a}){const l=de(()=>A.widgetSettings(e.id),[e.id]),[o,c]=d.useState(t.settings??{}),[u,h]=d.useState(null),[f,m]=d.useState(t.label??e.title),[p,g]=d.useState(!1),[v,b]=d.useState(null),j=d.useRef(0),x=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const k=++j.current,N=window.setTimeout(()=>{A.previewWidget({widget:e.id,size:t.size,settings:o}).then(S=>{k===j.current&&(h(S.view),m(S.label))}).catch(()=>{k===j.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(N)},[x,e.id,t.size]);const w=()=>{g(!0),b(null),r(o).then(k=>{g(!1),k||b("Couldn’t keep these settings. Try again.")})},y=s==="lock"?"the lock screen":"Home";return n.jsx(qe,{title:f,onClose:a,foot:n.jsxs(ae,{children:[n.jsxs(E,{variant:"danger-ghost",onClick:i,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:a,children:"Cancel"}),n.jsx(E,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"wg-sheet",children:[n.jsx(mH,{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(ie,{message:v??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>n.jsx(fH,{field:k,value:o[k.key],sheet:l.data,onChange:N=>c({...o,[k.key]:N})},k.key)):l.error?null:n.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const pH=6e4,BT="buddi.clock",WT="buddi.home.widgets";function gH(){try{const e=Number(window.localStorage.getItem(WT));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function xH(e){try{window.localStorage.setItem(WT,String(e))}catch{}}function HT(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}`}function KT(e,t){const s=d.useRef(t);s.current=t,d.useEffect(()=>{if(!e)return;let r;const i=()=>{r=setTimeout(()=>{s.current(),i()},6e4-Date.now()%6e4+1e3)};return i(),()=>clearTimeout(r)},[e])}function vH(){const e=de(()=>A.widgets("home"),[],pH),[t,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{t&&xH(t.home.length)},[t]),KT((t==null?void 0:t.home.some(r=>{var i,a;return r.widget===BT&&((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 jH(e){return new Set(((e==null?void 0:e.home)??[]).map(t=>t.widget))}function wH(e){const[t,s]=d.useState(!1);return d.useEffect(()=>{if(!e||!t)return;const r=()=>{(document.visibilityState==="hidden"||!document.hasFocus())&&s(!1)};return document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r)}},[e,t]),[t,s]}const VT=(e,t)=>e.label??(t==null?void 0:t.title)??e.widget;function yH({info:e,placement:t,view:s,index:r,count:i,editing:a,navigate:l,act:o,onRetry:c,retrying:u,drag:h}){var S;const[f,m]=wH(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,v=e.link?Uj(e.link.plugin,e.link.page,e.link.place):null,b=v!==null&&!a&&p!=="error"&&!g,j=t.size==="small"?"medium":"small",x=VT(t,e),w=t.key,y=(((S=e.settings)==null?void 0:S.length)??0)>0;let k;!s&&a?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?n.jsxs("span",{className:"wg-state-sub",children:[bH(s.error),"."]}):null,a?null:n.jsx(E,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),n.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),a?null:n.jsx(E,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=n.jsx(lw,{body:s.body,size:t.size});const N=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),h.start(w)};return n.jsxs("div",{className:"wg-frame",role:"group","aria-label":x,"data-id":e.id,"data-key":w,"data-size":t.size,"data-kind":s!=null&&s.body&&!g&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":b?"true":void 0,"data-dragging":h.dragging===w?"true":void 0,"data-over":h.over===w&&h.dragging!==w?"true":void 0,draggable:a?!0:void 0,onDragStart:a?N:void 0,onDragOver:a?C=>{h.dragging&&(C.preventDefault(),h.enter(w))}:void 0,onDrop:a?C=>{C.preventDefault(),h.drop(w)}:void 0,onDragEnd:a?()=>h.end():void 0,children:[n.jsxs("div",{className:"wg-head",children:[a?n.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":w,"aria-label":`Move ${x}, position ${r+1} of ${i}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:n.jsx(ce,{name:"grip",size:14})}):null,n.jsx("span",{className:"wg-title",children:x}),p==="stale"?n.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${nj(s.updatedAt)} old`:"Not current"}):null,a&&y?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${x}`,title:"Settings",onClick:()=>o("settings"),children:n.jsx(ce,{name:"settings",size:14})}):null,a?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${x} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:n.jsx(ce,{name:"close",size:12})}):n.jsx("span",{className:"wg-more",children:n.jsx(ja,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Le(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[y?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<i-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(j)?{label:`Make it ${j}`,onSelect:()=>o("size",j)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),b?n.jsx("a",{className:"wg-body",href:v,onClick:C=>{C.preventDefault(),l(v)},children:k}):n.jsx("div",{className:"wg-body",children:k}),a?n.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?n.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${x}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>n.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":t.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):n.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),n.jsxs("span",{className:"wg-edit-move",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:earlier`,"aria-label":`Move ${x} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:n.jsx(ce,{name:"chevron-left"})}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${x} later`,title:"Move later",disabled:r===i-1,onClick:()=>o("later"),children:n.jsx(ce,{name:"chevron-right"})})]})]}):null]})}function bH(e){const t=e.replace(/\.$/,"");return t.charAt(0).toUpperCase()+t.slice(1)}function kH({widgets:e,navigate:t}){const{answer:s,apply:r}=e,[i,a]=d.useState(!1),[l,o]=d.useState([]),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(null),[g,v]=d.useState(!1),[b,j]=d.useState(null),[x,w]=d.useState(null),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,T]=d.useState(new Set),[R]=d.useState(gH),I=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const z=window.setTimeout(()=>u(null),_T);return()=>window.clearTimeout(z)},[c]),d.useEffect(()=>{var ne;const z=I.current;z&&(I.current=null,(ne=document.querySelector(`[data-grip="${CSS.escape(z)}"], [data-move="${CSS.escape(z)}"]`))==null||ne.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},(z,ne)=>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"})]})]},ne))})]});if(s.available.every(z=>z.builtIn)&&s.home.length===0)return null;const L=new Map(s.available.map(z=>[z.id,z])),W=i?l:s.home,$=z=>VT(z,L.get(z.widget)),P=(z,ne)=>(p(null),r({...ne,home:z,arranged:{...ne.arranged,home:!0}}),A.saveWidgets("home",z).then(J=>(r(J),!0),J=>(r(ne),p(`Couldn't save your widgets: ${J instanceof Error?J.message:String(J)}`),!1))),O=(z,ne,J)=>{if(J<0||J>=z.length||ne===J)return null;const ye=z.slice(),[ge]=ye.splice(ne,1);return ye.splice(J,0,ge),f(`${$(ge)}, position ${J+1} of ${ye.length}.`),ye},M=()=>{o(s.home),T(new Set),u(null),p(null),a(!0)},D=z=>(ne,J)=>{const ye=W[z];if(ne==="edit"){M();return}if(ne==="settings"){S(ye.key);return}if(i){if(ne==="earlier"||ne==="later"){const ge=O(l,z,ne==="earlier"?z-1:z+1);if(ge){const $e=document.activeElement;I.current=($e==null?void 0:$e.dataset.grip)??($e==null?void 0:$e.dataset.move)??null,o(ge)}}ne==="size"&&J&&(o(l.map((ge,$e)=>$e===z?{...ge,size:J}:ge)),T(new Set([...C,ye.key]))),ne==="hide"&&(o(l.filter((ge,$e)=>$e!==z)),f(`${$(ye)} taken off.`));return}if(ne==="earlier"||ne==="later"){const ge=O(s.home,z,ne==="earlier"?z-1:z+1);ge&&P(ge,s)}ne==="size"&&J&&P(s.home.map((ge,$e)=>$e===z?{...ge,size:J}:ge),s),ne==="hide"&&P(s.home.filter((ge,$e)=>$e!==z),s).then(ge=>{ge&&u({item:ye,at:z})})},H=()=>{if(!c)return;const z=s.home.filter(ne=>ne.key!==c.item.key);z.splice(Math.min(c.at,z.length),0,c.item),u(null),P(z,s)},U=()=>{v(!0),P(l,s).then(z=>{v(!1),z&&(a(!1),f("Widgets saved."))})},q=z=>{j(z),A.refreshWidget(z).then(r,()=>{}).finally(()=>j(null))},B=z=>{var ye;const ne={key:HT(),widget:z.id,size:z.sizes[0],settings:{}},J=l.some(ge=>ge.widget===z.id);o([...l,ne]),f(`${z.title} added.`),J&&(((ye=z.settings)==null?void 0:ye.length)??0)>0&&S(ne.key)},Y=(z,ne)=>i?(o(l.map(J=>{if(J.key!==z)return J;const{label:ye,...ge}=J;return{...ge,settings:ne}})),T(new Set([...C,z])),S(null),Promise.resolve(!0)):P(s.home.map(J=>J.key===z?{...J,settings:ne}:J),s).then(J=>(J&&(S(null),f("Settings saved.")),J)),F=z=>{S(null);const ne=W.findIndex(J=>J.key===z);ne>=0&&D(ne)("hide")},X={dragging:x,over:y,start:z=>w(z),enter:z=>{y!==z&&k(z)},end:()=>{w(null),k(null)},drop:z=>{const ne=l.findIndex(ge=>ge.key===x),J=l.findIndex(ge=>ge.key===z),ye=ne>=0&&J>=0?O(l,ne,J):null;ye&&o(ye),w(null),k(null)}},Q=c?n.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[n.jsxs("span",{children:[$(c.item)," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:H,children:"Undo"})]},"undo"):null,ee=[];W.forEach((z,ne)=>{const J=L.get(z.widget);if(!J)return;c&&!i&&c.at===ne&&ee.push(Q);const ye=i&&(C.has(z.key)||!s.home.some(ge=>ge.key===z.key));ee.push(n.jsx(yH,{info:J,placement:z,view:ye?void 0:s.views[z.key],index:ne,count:W.length,editing:i,navigate:t,act:D(ne),onRetry:()=>q(z.key),retrying:b===z.key,drag:X},z.key))}),c&&!i&&c.at>=W.length&&ee.push(Q);const fe=s.available.filter(z=>!z.builtIn),Oe=fe.length-2,Ie=N?W.find(z=>z.key===N):void 0,Fe=Ie?L.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(E,{size:"sm",variant:"ghost",onClick:()=>{a(!1),o([])},disabled:g,children:"Cancel"}),n.jsx(E,{size:"sm",variant:"accent",onClick:U,disabled:g,children:g?"Saving…":"Done"})]}):W.length>0?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(E,{size:"sm",variant:"ghost",onClick:M,children:"Edit"})}):null]}),n.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),m?n.jsx(G,{tone:"critical",role:"alert",children:m}):null,W.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:"," ",(fe.length>0?fe:s.available).slice(0,2).map(z=>z.title).join(", "),Oe>0?` and ${Oe} more`:"","."]})]}),n.jsx(E,{size:"sm",variant:"accent",onClick:M,children:"Add widgets"})]}):ee.length>0?n.jsx("div",{className:"wg-grid","data-editing":i?"true":void 0,children:ee}):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:Pe("lock"),onClick:z=>{z.preventDefault(),t(Pe("lock"))},children:"The lock screen has its own pick"})]}),n.jsx("ul",{className:"wg-gallery-list",children:s.available.map(z=>{var De;const ne=l.filter(Je=>Je.widget===z.id).length,J=(((De=z.settings)==null?void 0:De.length)??0)>0,ye=z.builtIn?"Built in":`${z.plugin} plugin`,ge=z.sizes.length>1?"small or medium":`${z.sizes[0]} only`,$e=ne>1?` · ${ne} on Home`:ne===1&&J?" · 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:z.title}),n.jsxs("span",{className:"wg-add-sub",children:[ye," · ",ge,z.sensitive?" · hidden until you show it":"",$e]})]}),ne>0&&!J?n.jsx("span",{className:"wg-add-note",children:"On Home"}):n.jsxs(E,{size:"sm","aria-label":`${ne>0?"Add another":"Add"} ${z.title}`,onClick:()=>B(z),children:[n.jsx(ce,{name:"plus",size:12})," ",ne>0?"Add another":"Add"]})]},z.id)})})]}):null,Ie&&Fe?n.jsx(UT,{info:Fe,placement:Ie,surface:"home",onClose:()=>S(null),onSave:z=>Y(Ie.key,z),onRemove:()=>F(Ie.key)}):null]})}function ow(e,t){return!e||e==="image"&&!t?"earth":e}const NH="(max-width: 720px)",SH=3e4,CH={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Gm(e,t){return{time:Vt(e,t),day:xr(e,t,{weekday:!0})}}function cw(e,t){return e?Pc({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},t):t()}function EH(e,t,s=new Date,r){return cw(r,()=>AH(e,t,s))}function AH(e,t,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),a=Gm(r,t).day===Gm(s,t).day?Gm(r,t).time:tj(r,t);return e.reason==="idle"?`Locked after ${e.delayMinutes?CH[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 TH(e){const t=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=d.useState(t);return d.useEffect(()=>{if(r(t()),!e)return;const i=window.setInterval(()=>r(t()),500);return()=>window.clearInterval(i)},[e]),s}const $H=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function b0({size:e=16}){return n.jsx(ce,{name:"lock",size:e})}function GT({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 RH(){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 k0({text:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("div",{className:"so-cmd",children:[n.jsx("code",{className:"so-cmd-text",children:e}),n.jsx(E,{size:"sm",onClick:r,children:t?"Copied":"Copy"})]})}function IH({onClose:e}){return n.jsx(Ft,{title:"Forgot your PIN?",onClose:e,foot:n.jsx(E,{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(k0,{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(k0,{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 PH({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 MH(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 DH({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=MH(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(lw,{body:i.view.body,size:a})}),n.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function OH({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 N0(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 LH(e,t,s){try{const r=N0(e,t)-N0(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 FH(e,t,s){const r=s??{date:null,zone:null};return cw(s,()=>({time:Vt(e,t),day:r.date==="off"?null:xr(e,t,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Vt(e,r.zone.timezone),offset:LH(e,r.zone.timezone,t)}:null}))}function YT({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=FH(t,l,e==null?void 0:e.clockView),c=ow(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,h=u?cw(e==null?void 0:e.clockView,()=>s?UH(kc(u,l,t)):`${Qi[u.mode]} ${kc(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:UW(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(xc,{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(ce,{name:"moon",size:13}),n.jsx("span",{children:h})]}):null]}),n.jsxs("div",{className:"lk-main",children:[o.day?n.jsx("p",{className:"lk-date",children:o.day}):null,n.jsx(OH,{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(PH,{approvals:e.approvals,needs:e.needs??0,after:i??null,...a?{onPick:a}:{}}),r||!e?null:n.jsx(DH,{widgets:e.widgets,phone:s})]})]})}function _H({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(RH,{})}),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(GT,{size:18})})]})}function zH({initial:e,onUnlocked:t}){const s=bs(NH),r=FT(),[i,a]=d.useState(null),l=i??e,[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState((e==null?void 0:e.waitUntil)??null),[p,g]=d.useState(!1),[v,b]=d.useState(!1),[j,x]=d.useState(!1),[w,y]=d.useState(!1),[k,N]=d.useState(!1),[S,C]=d.useState(null),T=d.useRef(null),R=TH(f),I=R>0,L=d.useRef(t),W=d.useRef(S);W.current=S,L.current=Y=>{W.current&&(window.location.hash=vl),t(Y)};const $=Y=>{var F;C(Y),s&&Y?y(!0):(F=T.current)==null||F.focus()},P=d.useCallback(()=>{A.lockScreen().then(Y=>{b(!1),a(Y),m(Y.waitUntil),Y.locked||L.current(Y)}).catch(Y=>{Y instanceof ve&&Y.status===401?window.location.reload():Yd(Y)&&b(!0)})},[]);d.useEffect(()=>{P();const Y=window.setInterval(P,SH),F=()=>{document.visibilityState==="visible"&&P()};return document.addEventListener("visibilitychange",F),()=>{window.clearInterval(Y),document.removeEventListener("visibilitychange",F)}},[P]),KT((i==null?void 0:i.widgets.some(Y=>Y.id===BT&&Y.view.body.kind!=="clocks"))??!1,P),d.useEffect(()=>{var Y;!s&&!j&&!I&&((Y=T.current)==null||Y.focus())},[s,j,I,p]),d.useEffect(()=>{!I&&f&&h(null)},[I,f]);const O=Y=>{Y==null||Y.preventDefault(),!(p||I||o.length<4)&&(g(!0),A.unlock(o).then(F=>{var Q;if(c(""),F.locked){g(!1);return}if((Q=window.matchMedia)==null?void 0:Q.call(window,"(prefers-reduced-motion: reduce)").matches){L.current(F);return}N(!0),window.setTimeout(()=>L.current(F),240)}).catch(F=>{if(g(!1),c(""),!(F instanceof ve))return h("Something went wrong. Try again.");const X=F.detail??{};if(F.status===403||F.status===429){X.waitUntil&&m(X.waitUntil);const Q=X.triesLeft??0;h(X.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${Q} ${Q===1?"try":"tries"} left.`)}else Yd(F)?h("buddi isn’t answering. Try again in a moment."):h(F.message)}))},M=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,D=ow(l==null?void 0:l.background,l==null?void 0:l.image),H=(i==null?void 0:i.owner)??null,U=v?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:I?{tone:"critical",text:`Too many tries. Try again in ${$H(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?EH(l,M,r,i==null?void 0:i.clockView):"Locked"},q=Y=>Y.replace(/\D/g,"").slice(0,8),B=n.jsxs("div",{className:"lk-who",children:[n.jsx("span",{className:"lk-face","aria-hidden":"true",children:(H??"You").slice(0,1).toUpperCase()}),H?n.jsx("span",{className:"lk-owner",children:H}):null]});return n.jsxs("div",{className:"lk","data-bg":D,"data-phone":s?"true":void 0,"data-view":w?"pad":"glance","data-opening":k?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[n.jsx(YT,{data:i??(l?{...BH(l)}:null),now:r,phone:s,pad:w,after:S,onPick:$}),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(b0,{size:14}),n.jsx("span",{children:"Enter PIN"})]}),n.jsx("p",{className:"lk-note","data-tone":U.tone,role:"status","aria-live":"polite",children:U.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((Y,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":U.tone,role:"status","aria-live":"polite",children:U.text}),n.jsx(_H,{value:o,disabled:I||p,onDigit:Y=>{h(null),c(q(o+Y))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>O()}),n.jsxs("div",{className:"lk-pad-foot",children:[n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),c(""),h(null)},children:"Cancel"})]})]}):n.jsxs(n.Fragment,{children:[B,n.jsxs("form",{className:"lk-pin","data-state":u&&!I?"wrong":I?"wait":void 0,onSubmit:O,children:[n.jsx(b0,{size:15}),n.jsx("input",{ref:T,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:Y=>{h(null),c(q(Y.target.value))}}),n.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:n.jsx(GT,{})})]}),n.jsx("p",{className:"lk-note",id:"lk-note","data-tone":U.tone,role:"status","aria-live":"polite",children:U.text}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"})]})}),j?n.jsx(IH,{onClose:()=>x(!1)}):null]})}function UH(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function BH(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const WH=3e4,HH=5e3,KH="buddi-lock",jx="buddi-locked",VH=Pe("lock");function qT(){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 GH(e=qT()){return e?"⌃⌘L":"Ctrl+Alt+L"}function YH(e,t=qT()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:t?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const JT=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function bf(){return d.useContext(JT)}function Uu(e){try{e?localStorage.setItem(jx,"1"):localStorage.removeItem(jx)}catch{}}function qH(){try{return localStorage.getItem(jx)==="1"}catch{return!1}}function JH(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(KH)}catch{return null}}function QH({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(null),a=d.useRef(null),l=d.useRef(Date.now()),o=d.useRef(0),c=d.useRef(0),u=d.useRef(0),h=d.useCallback((v,b)=>{v&&i(v),s(b?"locked":"open"),Uu(b),b||(l.current=Date.now())},[]),f=d.useCallback(()=>{A.lockState().then(v=>h(v,v.locked)).catch(v=>{if(v instanceof ve&&v.status===401)return s("open");h(null,qH())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((v="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=VH;return}s("locked"),Uu(!0),(b=a.current)==null||b.postMessage({type:"locked"}),A.lockNow(v).then(j=>h(j,j.locked)).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const v=()=>{s("locked"),Uu(!0),f()};return window.addEventListener(bg,v),()=>window.removeEventListener(bg,v)},[f]),d.useEffect(()=>{const v=JH();if(a.current=v,!!v)return v.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Uu(!0)):(j==null?void 0:j.type)==="unlocked"?f():(j==null?void 0:j.type)==="activity"&&typeof j.at=="number"&&(l.current=Math.max(l.current,j.at))},()=>{v.close(),a.current=null}},[f]),d.useEffect(()=>{const v=b=>{YH(b)&&(b.preventDefault(),t==="open"&&m("owner"))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[t,m]);const p=r!=null&&r.pin?r.delayMinutes:null;d.useEffect(()=>{if(t!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const v=()=>{var N;const k=Date.now();l.current=k,k-u.current>1e4&&(u.current=k,(N=a.current)==null||N.postMessage({type:"activity",at:k}))},b=()=>{const k=Date.now();l.current<=c.current||k-o.current<WH||(o.current=k,c.current=l.current,A.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}b()},x=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const k of x)window.addEventListener(k,v,{passive:!0,capture:!0});const w=window.setInterval(j,HH),y=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",y),()=>{for(const k of x)window.removeEventListener(k,v,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",y)}},[t,r==null?void 0:r.pin,p,m]);const g=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:v=>h(v,v.locked),shortcut:GH()}),[r,m,h]);return t==="checking"?null:t==="locked"?n.jsx(zH,{initial:r,onUnlocked:v=>{var b;(b=a.current)==null||b.postMessage({type:"unlocked"}),h(v,!1)}}):n.jsx(JT.Provider,{value:g,children:e})}const QT="a connection needs you";function XH({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:f,status:m}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:cn,onClick:p=>{p.preventDefault(),s(cn)},"aria-label":"buddi home",children:n.jsx(xc,{})}),j4.filter(p=>p.route!==sn).map(p=>n.jsx(Ym,{label:p.label,href:p.route,active:t===p.route,badge:p.route===cn?e:0,onClick:()=>s(p.route),children:S0[p.route]},p.route)),a.map(p=>{const g=hr(p.plugin,p.id);return n.jsx(Ym,{label:p.title,href:g,active:t===g,badge:0,onClick:()=>s(g),children:n.jsx(ce,{name:MT(p.icon)})},g)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(Ym,{label:"Settings",href:sn,active:t===sn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(sn),children:S0[sn]}),m,n.jsx(eK,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const ZH=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function eK({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var y,k,N;const o=de(()=>A.owner(),[]),c=bf(),u=de(()=>A.focus(),[],6e4),h=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{A.setFocus(S,C).finally(()=>u.reload())},m=((N=(k=o.data)==null?void 0:k.preferredName)==null?void 0:N.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[g]=d.useState(D4),[v]=d.useState(sK),b=yf(),j=m?`You: ${m}`:"You",x=h?`${Qi[h.mode]} ${kc(h,l)}`:null,w=[j,x,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Lc,{modal:!1,children:[n.jsx(Fc,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":w,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,h?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(ce,{name:"moon",size:10})}):null]})}),n.jsx(_l,{children:n.jsxs(_c,{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(Rr,{className:"ui-menu-sep"}),n.jsx(nK,{focus:h,timezone:l,onSwitch:f}),n.jsx(Rr,{className:"ui-menu-sep"}),n.jsx(ca,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(Kt,{label:"Theme",options:ZH,value:e,onChange:t})}),n.jsx(Rr,{className:"ui-menu-sep"}),c.pin?n.jsxs(xs,{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(xs,{className:"ui-menu-item",onSelect:()=>s(Pe("lock")),children:"Set up a lock screen…"}),n.jsx(xs,{className:"ui-menu-item",onSelect:()=>s(Pe("appearance")),children:"Change appearance"}),b?n.jsx(xs,{className:"ui-menu-item",onSelect:()=>{iw(b)},children:"Install the app"}):null,g||i?n.jsxs(xs,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),v?n.jsx("kbd",{className:"rail-owner-kbd",children:v}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Rr,{className:"ui-menu-sep"}),n.jsxs(xs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Pe("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 Qi={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},tK=[{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 kc(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=Vt(r,i);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:i,weekday:"short"}).format(r)} ${l}`}function nK({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?Qi[e.mode]:"Off"})]}),n.jsx(_l,{children:n.jsxs($_,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Qi[e.mode]} ${kc(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(FE,{children:[n.jsx(Rr,{className:"ui-menu-sep"}),n.jsx(ca,{className:"ui-menu-label",children:Qi[r]}),tK.map(i=>n.jsx(xs,{className:"ui-menu-item","aria-label":`${Qi[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Rr,{className:"ui-menu-sep"}),n.jsx(xs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function sK(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function Ym({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 S0={[Hr]:n.jsx(ce,{name:"files"}),[cn]:n.jsx(ce,{name:"home"}),[gi]:n.jsx(ce,{name:"chat"}),[mt]:n.jsx(ce,{name:"agents"}),[jt]:n.jsx(ce,{name:"activity"}),[sn]:n.jsx(ce,{name:"settings"})},Nc=e=>`${e.plugin}:${e.id}`,rK=new Set;let uw=rK,C0=!1;const wx=new Set;function yx(e){uw=e;for(const t of wx)t()}function iK(e){return wx.add(e),()=>wx.delete(e)}const E0=()=>uw;function aK(){C0||(C0=!0,Promise.resolve().then(()=>A.rail()).then(e=>yx(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function lK(e,t){const s=uw,r=new Set(s);t?r.add(Nc(e)):r.delete(Nc(e)),yx(r);try{await A.setRailHidden(e.plugin,e.id,t)}catch(i){throw yx(s),i}}function XT(){return d.useEffect(aK,[]),d.useSyncExternalStore(iK,E0,E0)}function oK(e,t){return e.filter(s=>!t.has(Nc(s)))}function cK(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function uK(e,t=!0,s){d.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||cK(i.target))return;i.preventDefault();const a=document.getElementById(ox);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(cn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const ZT="buddi.theme";function dK(e=e$()){try{const t=e==null?void 0:e.getItem(ZT);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function hK(e,t=e$()){try{t==null||t.setItem(ZT,e)}catch{}}function fK(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function e$(){try{return window.localStorage}catch{return}}const t$="buddi.ground",n$="buddi.pageWidth";function mK(e=i$()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(t$),r=t(n$);return{theme:dK(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function s$(e,t=document.documentElement){t&&(fK(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 pK(e,t=i$()){hK(e.theme,t);try{t==null||t.setItem(t$,e.ground),t==null||t.setItem(n$,e.width)}catch{}}let ol=null;const bx=new Set;function kx(){return ol||(ol=mK()),ol}function gK(e){return bx.add(e),()=>bx.delete(e)}function xK(e){ol={...kx(),...e},s$(ol),pK(ol);for(const t of bx)t()}function r$(){return[d.useSyncExternalStore(gK,kx,kx),xK]}function i$(){try{return window.localStorage}catch{return}}const A0=7,vK=1e4;function jK({timezone:e,embedded:t,agents:s=[],navigate:r}){const{data:i,error:a,reload:l}=de(()=>A.sentinels(),[],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=i==null?void 0:i.alerts,y=(w==null?void 0:w.open)??[],k=M=>{r?r(M):window.location.hash=M},N=M=>{var D;return M?((D=s.find(H=>H.id===M))==null?void 0:D.name)??null:null},S=async M=>{c(null);try{await M()}catch(D){c(D instanceof ve||D instanceof Error?D.message:String(D))}finally{l()}},C=M=>h({...M,id:Date.now()}),T=(M,D,H)=>S(async()=>{const{keys:U}=await A.snoozeAlerts(M,!0,H);C({title:D,undo:()=>A.snoozeAlerts(U,!1)})}),R=M=>S(async()=>{const{id:D}=await A.muteAlert(M.keys[0],M.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>A.unmuteAlert(D)})}),I=M=>S(async()=>{const{agentId:D,conversationId:H}=await A.askAboutAlerts(M.keys);k(st(D,H))}),L=M=>S(async()=>{const[D]=(await A.actOnAlerts([{key:M.key,action:M.index}])).results;if(D!=null&&D.error)throw new Error(D.error);D!=null&&D.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${M.label}: done`})}),W=(M,D)=>{D.kind==="open"?k(D.place==="files"?Hr:D.plugin&&D.page?hr(D.plugin,D.page,D.item):Hr):D.kind==="ask"?I(M):D.kind==="dismiss"?T(M.keys,"Set aside until it changes"):D.kind==="fill"?m(D):D.confirm?g(D):L(D)},$=()=>{const M=y.flatMap(D=>D.keys);T(M,`Cleared ${y.length} for a week`,A0)},P=w==null?void 0:w.recap,O=wK((P==null?void 0:P.nextAt)??null,e);return n.jsxs(Pn,{embedded:t,title:"Alerts",lede:"What needs a decision from you.",children:[n.jsx(ie,{message:a??o}),n.jsxs(Ge,{flush:!0,title:"Needs a decision",tool:y.length>0?String(y.length):void 0,actions:y.length>1?n.jsx(E,{size:"sm",variant:"ghost",onClick:$,children:"Clear all"}):void 0,children:[i?y.length===0?n.jsxs("div",{className:"al-empty",children:[n.jsx(ce,{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 ",O,"."]})]})]}):n.jsx("ul",{className:"al-list",children:y.map(M=>n.jsx(T0,{group:M,agentName:N(M.agentId),onAct:W,onStop:R,onNotNow:D=>void T(D.keys,"Snoozed for a week",A0)},M.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 ",O]}),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:()=>x(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:()=>x(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?n.jsx(Ge,{flush:!0,title:"Snoozed",children:n.jsx("ul",{className:"al-list",children:w.snoozed.map(M=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:M.title}),n.jsx("p",{className:"al-sub",children:M.snoozedUntil?`Back ${Le(M.snoozedUntil)}`:"Until it changes"})]}),n.jsx("div",{className:"al-actions",children:n.jsx(E,{size:"sm",onClick:()=>void S(async()=>{await A.snoozeAlerts(M.keys,!1)}),children:"Bring back"})})]},M.id))})}):null,j==="resolved"&&w?n.jsx(Ge,{flush:!0,title:"Resolved this week",children:n.jsx("ul",{className:"al-list",children:w.resolved.map(M=>n.jsx("li",{className:"al-row",children:n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:M.title}),n.jsx("p",{className:"al-sub",children:M.resolvedAt?`Resolved ${Le(M.resolvedAt)}`:null})]})},M.id))})}):null,v&&P?n.jsxs(qe,{title:yK(O),onClose:()=>b(!1),children:[n.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",O,"; 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(M=>n.jsx(T0,{group:M,agentName:N(M.agentId),recap:!0,onAct:(D,H)=>{H.kind!=="fill"&&b(!1),W(D,H)},onStop:D=>{R(D)}},M.id))})]}):null,f?n.jsx(bK,{action:f,onClose:()=>m(null),onSaved:M=>{m(null),b(!1),C({title:`Saved ${M}`}),l()}}):null,p?n.jsx(Ft,{title:p.label,onClose:()=>g(null),foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),n.jsx(E,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const M=p;g(null),L(M)},children:p.label})]}),children:n.jsx("p",{children:p.confirm})}):null,u?n.jsx(oh,{title:u.title,...u.body?{body:u.body}:{},duration:vK,...u.undo?{onUndo:()=>{const M=u.undo;S(async()=>{await M()})}}:{},onGone:()=>h(null)},u.id):null]})}function wK(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 yK(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Bu(e,t){return e.kind==="ask"?e.label??(t?`Ask ${t}`:"Ask about it"):e.label}function T0({group:e,agentName:t,recap:s,onAct:r,onNotNow:i,onStop:a}){const[l,o]=d.useState(!1),[c,u,...h]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return 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 ",Le(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,v)=>n.jsx(E,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:Bu(g,t)},v))}):null]},p.key))}):null]}),n.jsxs("div",{className:"al-actions",children:[c?n.jsx(E,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Bu(c,t)}):null,u?n.jsx(E,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Bu(u,t)}):null,i?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(e),children:"Not now"}):null,n.jsx("span",{className:"al-more",children:n.jsx(ja,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:Bu(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 bK({action:e,onClose:t,onSaved:s}){const r=e.fields.length===1,[i,a]=d.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=d.useState({}),[c,u]=d.useState(!1),[h,f]=d.useState(null),m=async()=>{const p=e.fields.filter(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 A.actOnAlerts(p),v=Object.fromEntries(g.filter(b=>b.error).map(b=>[b.key,b.error]));o(v),Object.keys(v).length===0&&s(p.length)}catch(g){f(g instanceof Error?g.message:String(g))}finally{u(!1)}};return n.jsx(qe,{title:e.title,onClose:t,foot:n.jsxs("div",{className:"al-form-foot",children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"al-form",children:[n.jsx(ie,{message:h}),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(v=>({...v,[p.key]:g.target.value}))}),l[p.key]?n.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function kK({mutes:e,onChanged:t}){const[s,r]=d.useState(null);return e.length===0?null:n.jsxs(Ge,{flush:!0,title:"Silenced",tool:String(e.length),children:[n.jsx(ie,{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” ",Le(i.createdAt)]})]}),n.jsx("div",{className:"al-actions",children:n.jsx(E,{size:"sm",onClick:()=>{r(null),A.unmuteAlert(i.id).then(t,a=>r(a instanceof Error?a.message:String(a)))},children:"Tell me again"})})]},i.id))})]})}const $0=5e3,R0=50;function NK({timezone:e,embedded:t}){var j;const[s,r]=d.useState(""),[i,a]=d.useState(""),[l,o]=d.useState(null),c=de(()=>A.eventKinds(),[]),{data:u,error:h}=de(()=>A.events({kind:s||void 0,q:i||void 0,limit:R0}),[s,i],$0),[f,m]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);const p=f.events.length>0?f.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(x=>({...x,busy:!0,error:null}));try{const x=await A.events({kind:s||void 0,q:i||void 0,before:p,limit:R0});m(w=>({events:[...w.events,...x.events],cursor:x.nextCursor,busy:!1,error:null}))}catch(x){m(w=>({...w,busy:!1,error:x instanceof Error?x.message:String(x)}))}}},v=new Set(((u==null?void 0:u.events)??[]).map(x=>x.id)),b=[...(u==null?void 0:u.events)??[],...f.events.filter(x=>!v.has(x.id))];return n.jsxs(Pn,{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:x=>r(x.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(x=>n.jsxs("option",{value:x.kind,children:[x.kind," (",x.count,")"]},x.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:x=>a(x.target.value),size:28}),s||i?n.jsx(E,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",$0/1e3,"s"]})]}),n.jsx(ie,{message:h}),n.jsx(Ge,{flush:!0,children:!u||b.length===0?n.jsx(pe,{children:"No events match."}):n.jsxs(jr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(x=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(x),children:[n.jsx("td",{className:"mono muted",children:x.id}),n.jsxs("td",{className:"nowrap",children:[nt(x.createdAt,e),n.jsx("div",{className:"sub",children:Le(x.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:x.kind}),n.jsx("td",{className:"mono muted",children:zs(ss(x.payload).replace(/\s+/g," "),120)})]},x.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(E,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(qe,{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(Pt,{children:ss(l.payload)})]}):null]})}const I0=["pending","leased","suspended","failed","succeeded","cancelled"],xo=50,SK=1e4,CK=(e,t,s=`${t}s`)=>e===1?t:s;function EK({timezone:e,embedded:t,initialState:s}){var U,q;const[r,i]=d.useState(s??""),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=r==="failed",{data:g,error:v,reload:b}=de(()=>A.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(xo)}),[r],1e4),j=de(()=>A.jobFailures(),[],1e4),[x,w]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const y=async()=>{w(B=>({...B,busy:!0}));try{const B=await A.jobs({...r?{state:r}:{dismissed:"0"},limit:String(xo),offset:String(xo+x.jobs.length)});w(Y=>({jobs:[...Y.jobs,...B.jobs],done:B.jobs.length<xo,busy:!1}))}catch(B){c(B instanceof Error?B.message:String(B)),w(Y=>({...Y,busy:!1}))}},k=new Set(((g==null?void 0:g.jobs)??[]).map(B=>B.id)),N=[...(g==null?void 0:g.jobs)??[],...x.jobs.filter(B=>!k.has(B.id))],S=(g==null?void 0:g.counts)??{},C=r?S[r]??0:I0.reduce((B,Y)=>B+(S[Y]??0),0),T=!x.done&&N.length<C&&((g==null?void 0:g.jobs.length)??0)>=xo,R=((U=j.data)==null?void 0:U.open)??[],I=((q=j.data)==null?void 0:q.dismissed)??[],L=R.reduce((B,Y)=>B+Y.count,0),W=I.reduce((B,Y)=>B+Y.count,0),$=()=>{b(),j.reload()},P=B=>h({...B,id:Date.now()}),O=async B=>{c(null);try{await B()}catch(Y){c(Y instanceof Error?Y.message:String(Y))}finally{$()}},M=async B=>{await O(async()=>{await B,l(null)})},D=B=>O(async()=>{const{ids:Y}=await A.dismissJobs(B==="all"?{all:!0}:{ids:B});Y.length!==0&&P({title:`Dismissed ${Y.length===1?"it":Y.length}`,body:"Kept under Dismissed, below.",undo:()=>A.undismissJobs(Y)})}),H=(B,Y)=>O(async()=>{const{jobs:F}=await A.retryJobs({ids:B});if(F.length===0)return;const X=F.length===1;P({title:`Retrying ${X?"it":F.length}`,body:Y?`${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(Pn,{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(E,{size:"sm",variant:g!=null&&g.paused?"accent":void 0,onClick:()=>M(A.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[n.jsx(ie,{message:v??j.error??o}),R.length>0?n.jsxs(Ge,{flush:!0,title:"Gave up",tool:String(L),actions:L>1?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>void D("all"),children:"Dismiss all"}):void 0,children:[n.jsx("ul",{className:"al-list",children:R.map(B=>n.jsx(M0,{group:B,timezone:e,onOpen:l,onRetry:Y=>void H(Y,B.likelyFixed),onDismiss:Y=>void D(Y)},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(Ge,{flush:!0,children:n.jsxs("div",{className:"al-empty",children:[n.jsx(ce,{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:W>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,W>0||p?n.jsxs("p",{className:"al-quiet jb-quiet",children:[W>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(B=>!B),children:[W," dismissed"]}):null,W>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(Ge,{flush:!0,title:"Dismissed",children:n.jsx("ul",{className:"al-list",children:I.map(B=>n.jsx(M0,{group:B,timezone:e,dismissed:!0,onOpen:l,onRetry:Y=>void H(Y,B.likelyFixed)},B.key))})}):null,p?null:n.jsx(Ge,{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"}),I0.map(B=>n.jsxs("option",{value:B,children:[B," (",S[B]??0,")"]},B))]}),children:!g||N.length===0?n.jsx(pe,{children:"No jobs match."}):n.jsxs(jr,{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:N.map(B=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(B),children:[B.kind,n.jsx("div",{className:"sub mono",children:uc(B.id)})]}),n.jsxs("td",{children:[n.jsx(Kc,{state:B.state}),B.suspendedReason?n.jsx("div",{className:"sub",children:zs(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?zs(B.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[nt(B.updatedAt,e),n.jsx("div",{className:"sub",children:Le(B.updatedAt)})]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[["failed","cancelled","suspended"].includes(B.state)?n.jsx(E,{size:"sm",onClick:()=>M(A.retryJob(B.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(B.state)?n.jsx(E,{size:"sm",variant:"danger",onClick:()=>M(A.cancelJob(B.id)),children:"Cancel"}):null]})})]},B.id))})]})}),T&&!p?n.jsxs(ae,{children:[n.jsxs("span",{className:"muted",children:[N.length," of ",C," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(E,{disabled:x.busy,onClick:()=>void y(),children:x.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(qe,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),a.lastError?n.jsx(ue,{title:"Last error",children:n.jsx(Pt,{children:a.lastError})}):null,n.jsx(ue,{title:"Payload",children:n.jsx(Pt,{children:ss(a.payload)})}),n.jsx(ue,{title:"Result",children:n.jsx(Pt,{children:ss(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null,u?n.jsx(oh,{title:u.title,...u.body?{body:u.body}:{},duration:SK,...u.undo?{onUndo:()=>{const B=u.undo;O(async()=>{await B()})}}:{},onGone:()=>h(null)},u.id):null]})}function P0(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()!==""?zs(t.trim().split(`
|
|
109
|
+
`)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function M0({group:e,timezone:t,dismissed:s,onOpen:r,onRetry:i,onDismiss:a}){var g;const[l,o]=d.useState(!1),c=e.jobs.length>1,u=e.jobs.map(v=>v.job.id),h=e.agents.map(v=>v.name??v.id),f=e.jobs[0],m=e.jobs.every(v=>v.job.acknowledgedBy==="auto"),p=s?m?"dismissed on its own after 14 days":`dismissed ${Le(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Le(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:[h.length>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:h.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:P0(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(v=>!v),children:l?"Hide":`Show the ${e.count}`})]}):null]}),l&&c?n.jsx("ul",{className:"al-items",children:e.jobs.map(v=>n.jsxs("li",{className:"al-item jb-item",children:[v.agentName||v.agentId?n.jsx("span",{className:"al-item-who",children:v.agentName??v.agentId}):null,n.jsxs("span",{className:"al-item-note",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(v.job),children:P0(v)})," · ",tj(new Date(v.job.updatedAt),t)," · tried ",v.job.attempts," ",CK(v.job.attempts,"time")]}),n.jsxs("span",{className:"jb-item-acts",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([v.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([v.job.id]),children:"Dismiss"})]}):null]})]},v.job.id))}):null]}),n.jsxs("div",{className:"al-actions",children:[n.jsx(E,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>i(u),children:c?"Retry all":"Retry"}),a?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(u),children:"Dismiss"}):null]})]})}const AK=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function TK({hash:e,timezone:t,navigate:s,agents:r}){var u,h;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(i){let f=i[1];try{f=decodeURIComponent(f)}catch{}return n.jsx(IK,{id:f,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=f=>m=>{m.preventDefault(),s(f)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(wl,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(DK,{})}),n.jsx(OK,{}),n.jsx(Vc,{children:AK.map(f=>{const m=f.id==="conversations"?jt:`${jt}/${f.id}`;return n.jsx(yl,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?n.jsx($K,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(EK,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(RK,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(jK,{timezone:t,embedded:!0,agents:r,navigate:s}):null,l==="events"?n.jsx(NK,{timezone:t,embedded:!0}):null]})}function $K({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=de(()=>A.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:a}),n.jsx(Ge,{flush:!0,children:i?i.conversations.length===0?n.jsx(Tn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(rt,{children:i.conversations.map(l=>n.jsx(et,{href:mc(l.id),onClick:()=>t(mc(l.id)),lead:n.jsx(ln,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?zs(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${aL(l.usage)}`,side:n.jsx("span",{title:nt(l.lastMessageAt??l.createdAt,e),children:Le(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(pe,{children:"Loading…"})})]})}function RK({timezone:e,nameOf:t}){const{data:s,error:r}=de(()=>A.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:r}),n.jsx(Ge,{flush:!0,children:s?i.length===0?n.jsx(Tn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(jr,{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:uc(a.id)})]}),n.jsx("td",{children:n.jsx(Kc,{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:Le(a.createdAt)})]})]},a.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}function IK({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null);d.useEffect(()=>{let u=!1;return A.conversation(e).then(h=>{u||a(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:jt,onClick:c(jt),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(E,{size:"sm",onClick:()=>s(jt),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Et,{size:"sm",href:st(i.agentId,e),onClick:c(st(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(ie,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(gf,{children:[n.jsx(ir,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(ir,{label:"Runs",value:i.runs.length}),n.jsx(ir,{label:"Tokens",value:`${Jt(i.usage.input)} / ${Jt(i.usage.output)}`,note:yg(i.usage)?`input / output, ${yg(i.usage)}`:"input / output"}),n.jsx(ir,{label:"Started",value:nt(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(Ge,{title:"Runs",flush:!0,children:n.jsxs(jr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Started"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{className:"num",children:"Turns"}),n.jsx("th",{children:"Stopped"}),n.jsx("th",{className:"num",children:"Tokens"}),n.jsx("th",{className:"num",children:"Cached"})]})}),n.jsx("tbody",{children:i.runs.map((u,h)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(u.startedAt,t)," ",u.resumed?n.jsx(we,{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 ",uc(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[Jt(u.usage.input)," / ",Jt(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?Jt((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,n.jsx(ue,{title:"Messages",children:n.jsx(le,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===D0?"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===D0?u.blocks.map((h,f)=>n.jsx(PK,{block:h},f)):u.blocks.map((h,f)=>n.jsx(MK,{block:h},f))]})]},u.id))})})]}):n.jsx(pe,{children:"Loading…"})]})}const D0="approval:resume";function PK({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(Pt,{children:e.type==="text"?e.text??"":ss(e)})]})}function MK({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(fr,{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(fr,{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(Pt,{children:ss(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(Pt,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(Pt,{children:ss(e.ref)})]})}function DK(){const{data:e,reload:t}=de(()=>A.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const i=()=>{r(!0),A.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(E,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function OK(){const{data:e,reload:t}=de(()=>A.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener(Ji,t),()=>window.removeEventListener(Ji,t)),[t]),!e)return null;const s=i=>e.jobs[i]??0,r=s("leased");return n.jsxs(gf,{children:[n.jsx(ir,{label:"Jobs done",value:Jt(s("succeeded"))}),n.jsx(ir,{label:"Failed",value:Jt(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),n.jsx(ir,{label:"Queued",value:Jt(s("pending")),note:`${r} running`}),n.jsx(ir,{label:"Approvals",value:Jt(e.approvals.pending),note:"waiting for you"})]})}const LK=["replay-all","coalesce","latest-only","skip-after-deadline"];function a$({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=de(()=>A.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await h,a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(Pn,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(ie,{message:i??o}),!r||l.length===0?n.jsxs(Tn,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(le,{children:l.map(h=>n.jsx(FK,{mission:h,timezone:e,onRun:u},h.id))})]})}function FK({mission:e,timezone:t,onRun:s}){const[r,i]=d.useState(!1);return n.jsxs(cs,{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(we,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(we,{children:"always delivers"}):null,e.enabled?null:n.jsx(we,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?n.jsx(we,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",onClick:()=>s(A.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(a=>!a),"aria-expanded":r,children:r?"Less":"More"})]}),children:[e.stillUsefulAskedAt?n.jsx(G,{tone:"warning",title:"Still useful?",action:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",onClick:()=>s(A.setMissionEnabled(e.id,!1)),children:"Stop"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>s(A.keepMission(e.id)),children:"Keep"})]}),children:`It has run ${e.quietRuns??"many"} times in a row without anything to tell you.`}):null,e.stopWhen||e.endsAt?n.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${nt(e.endedAt,t)}.`:e.endsAt?`Ends ${nt(e.endsAt,t)}.`:""]}):null,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)} (${Le(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"} ${Le(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(oe,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(A.setMisfirePolicy(e.id,a.target.value)),children:LK.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(ue,{title:"Prompt",children:n.jsx(Pt,{children:e.prompt})}),n.jsx(ue,{title:"Recent occurrences",children:n.jsx(Ge,{flush:!0,children:e.occurrences.length===0?n.jsx(pe,{children:"Never run."}):n.jsxs(jr,{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(Kc,{state:a.state})}),n.jsx("td",{className:"nowrap",children:nt(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?zs(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function _K(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 l$({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=d.useState(!1),[l,o]=d.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:_K(r,t)}),n.jsx(E,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),A.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(E,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function o$({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=de(()=>A.offers(),[],2e4),l=j=>!t||j.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),v=async(j,x)=>{h(null),m(j);try{const w=await A.takeOffer(j);g(w.jobId?`On it — ${x}. Started as job ${w.jobId}.`:`Taken — ${x}. No worker is running here, so nothing has started yet.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},b=async(j,x)=>{h(null),m(j);try{await A.dismissOffer(j),g(`Dismissed — ${x}. It will not come back.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return n.jsxs(Pn,{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(ie,{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(l$,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx(Tn,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):n.jsx(le,{children:o.map(j=>n.jsx(cs,{tone:"accent",title:j.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{mono:!0,children:j.agentId}),n.jsxs("span",{className:"muted",children:["expires ",Le(j.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void b(j.id,j.label),children:"Not now"}),n.jsx(E,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void v(j.id,j.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?n.jsxs(At,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(Ge,{flush:!0,children:n.jsx(rt,{children:c.map(j=>n.jsx(et,{title:j.label,sub:`${j.agentId} — ${uL(j)}`,side:Le(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 zK={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},dw=e=>zK[e]??kf(e);function kf(e){return e.charAt(0).toUpperCase()+e.slice(1)}function rn(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function kl(e){return e.replace(/\.0$/,"")}function UK(e){return e.avatar?A.marketAssetUrl(e.avatar):void 0}const BK={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:Kr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:Kr("image","settings")}};function hw(e){return BK[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:Pe()}}const Nf=e=>kf(e);function c$(e){return e.kind==="plugin"?e.title:hw(e.name).title}function u$(e){if(e.kind==="need"){const t=hw(e.name);return{label:t.fix,route:t.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:Pe("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:Pe("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:Pe("plugins")}}function WK(e,t,s){const r=new Set((e.missing??[]).map(o=>o.name)),a=[...Object.keys(e.requires),...Object.keys(e.optional)].filter(o=>!r.has(o)&&t.has(o)).map(Nf),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&a.push("your mailbox"),a}function qm(e){return kf(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const O0=(e,t)=>e.includes(t),HK={email:{title:"Mail",line:e=>O0(e,"email.draft")||O0(e,"email.*")?"Reads and searches your mail. Writes drafts; you send them.":"Searches and reads your mail."},calendar:{title:"Calendar",line:()=>"Reads your calendars. Never adds or moves an event."},weather:{title:"Weather",line:()=>"Reads the forecast for your places."},reminder:{title:"Reminders",line:e=>e.some(t=>t.startsWith("schedule."))?"Sets reminders and runs its own missions.":"Sets reminders."},memory:{title:"Memory",line:()=>"Remembers what you tell it. You can read every note."},owner:{title:"You",line:()=>"Messages you when something needs you."},web:{title:"Web",line:()=>"Searches and reads web pages."},artifacts:{title:"Files",line:()=>"Reads what you share in Files."},finance:{title:"Finance",line:()=>"Reads your accounts, cards, loans and statements."},image:{title:"Image",line:()=>"Makes pictures with your drawing account."},speech:{title:"Speech",line:()=>"Says words out loud."},goal:{title:"Goals",line:()=>"Keeps your goals and progress."},canvas:{title:"Canvas",line:()=>"Draws on the canvas beside your chat."}},KK={schedule:"reminder",browser:"web"};function dh(e,t=new Map){const s=[],r=new Map;for(const i of e){const a=i.replace(/\?$/,""),l=a.split(".")[0]??a,o=KK[l]??l;r.has(o)||(r.set(o,[]),s.push(o)),r.get(o).push(a)}return s.map(i=>{const a=r.get(i),l=HK[i],o=a.some(u=>t.get(u)==="gated"||u.endsWith(".*")&&[...t].some(([h,f])=>f==="gated"&&h.startsWith(u.slice(0,-1)))),c=l?l.line(a):`${a.length===1?"One of its tools":`${a.length} of its tools`}.`;return[(l==null?void 0:l.title)??kf(i),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function L0(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${rn(e.map(([t])=>t))}.`}function hh(e){return new Map((e??[]).filter(t=>t.tier).map(t=>[t.name,t.tier]))}function Gl({entry:e,size:t}){const s=UK(e);return n.jsx("span",{className:"cat-face","data-size":t,children:n.jsx(bn,{id:e.name,name:e.title,size:t==="xxl"?"xl":t,face:{tools:e.tools,...s?{picture:s}:{}}})})}const d$=800,VK=e=>{var t;return((t=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:t[0])??e.trim()},cl=e=>e instanceof ve?e.message:String(e);function Ar({entry:e,children:t}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Gl,{entry:e,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsx("span",{children:t}),n.jsxs("span",{className:"plugins-sheet-by",children:["by ",e.author.name,e.trust==="by-buddi"?n.jsxs(n.Fragment,{children:[" · ",n.jsx(we,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function Jm({state:e,children:t}){return n.jsxs("li",{className:"cat-step","data-state":e,children:[n.jsx("span",{className:"cat-step-mark",children:e==="done"?n.jsx(ce,{name:"check",size:12}):e==="failed"?n.jsx(ce,{name:"alert",size:14}):null}),n.jsx("span",{children:t})]})}function Qm(e){const t=e.kind==="plugin"?["Installing","Installed"]:["Adding","Added"];return e.state==="done"?{state:"done",words:`${t[1]} ${e.title}`}:e.state==="failed"?{state:"failed",words:e.kind==="plugin"?`${e.title} didn’t install`:`${e.title} wasn’t added`}:e.state==="waiting"?{state:"next",words:`${t[0]} ${e.title}`}:{state:"now",words:`${t[0]} ${e.title}…`}}function GK(e){const[t,s]=d.useState(null),[r,i]=d.useState(null);return d.useEffect(()=>{if(s(null),i(null),!e)return;let a=!1,l;const o=()=>{A.catalogueJob(e).then(c=>{a||(s(c),c.state==="running"&&(l=window.setTimeout(o,d$)))}).catch(c=>{a||i(cl(c))})};return o(),()=>{a=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:t,error:r,setJob:s}}function h$({entry:e,navigate:t,onClose:s,onAdded:r}){var Fe;const i=bs("(max-width: 720px)"),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState({}),[f,m]=d.useState(""),[p,g]=d.useState([]),[v,b]=d.useState(!1),[j,x]=d.useState(null),[w,y]=d.useState(!1),[k,N]=d.useState(null),{job:S,error:C,setJob:T}=GK(j),[R,I]=d.useState(!1),[L,W]=d.useState(null),[$,P]=d.useState(!1),O=d.useRef(!1),[M,D]=d.useState([]);d.useEffect(()=>{if(!a||a.plugins.length===0)return;let z=!1;return Promise.resolve().then(()=>A.market()).then(ne=>{z||D((ne==null?void 0:ne.plugins)??[])}).catch(()=>{}),()=>{z=!0}},[a]),d.useEffect(()=>{let z=!1;return A.cataloguePlan(e.name).then(ne=>{z||(l(ne),h(Object.fromEntries(ne.fills.map(J=>[J.id,J.value]))),m(ne.handle))}).catch(ne=>{z||c(cl(ne))}),()=>{z=!0}},[e.name]),d.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!O.current&&(O.current=!0,r==null||r(S.agent))},[S,r]);const H=()=>{a&&(y(!0),N(null),O.current=!1,A.catalogueInstall(e.name,{version:a.version,fills:u,handle:f,missionsOn:p,tools:a.tools.map(z=>z.name)}).then(z=>x(z.jobId)).catch(z=>N(cl(z))).finally(()=>y(!1)))},U=()=>{x(null),H()},q=e.title,B=S==null?void 0:S.agent,Y=z=>{B&&(z&&ij(B.id,z),s(),t(st(B.id)))},F=z=>{S&&(I(!0),W(null),A.catalogueConfirm(S.id,z).then(ne=>{T(ne),z||s()}).catch(ne=>W(cl(ne))).finally(()=>I(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const z=dh(S.confirm.tools.map(J=>J.name),hh(S.confirm.tools)),ne=S.steps.filter(J=>J.kind==="plugin"&&J.state==="done").map(J=>J.title);return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:["Add ",q]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(dt,{}),n.jsx(E,{variant:"ghost",disabled:R,onClick:()=>F(!1),children:"Don’t add it"}),n.jsxs(E,{variant:"accent",disabled:R,onClick:()=>F(!0),children:["Add ",q]})]}),children:[n.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(J=>J.kind==="plugin").map(J=>{const{state:ye,words:ge}=Qm(J);return n.jsx(Jm,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),n.jsxs(G,{tone:"warning",title:`${q} would get more than the list showed.`,children:[ne.length>0?`With ${rn(ne)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${rn(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),n.jsx(ie,{message:L}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[L0(z)," ",n.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>P(!$),children:$?"Hide":"See all"})]}),$?n.jsx("dl",{className:"cat-reach",children:z.map(([J,ye])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:J}),n.jsx("dd",{children:ye})]},J))}):null]}),n.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!S||S.state==="running")){const z=S==null?void 0:S.steps[S.steps.length-1],ne=(S==null?void 0:S.approvalId)&&(z==null?void 0:z.state)==="adding";return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:["Add ",q]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{onClick:s,children:"Close"})}),children:[n.jsx("ol",{className:"cat-steps","aria-live":"polite","data-testid":"cat-progress",children:((S==null?void 0:S.steps)??[]).map(J=>{const{state:ye,words:ge}=Qm(J);return n.jsx(Jm,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),ne?n.jsxs(G,{tone:"accent",action:n.jsx(E,{size:"sm",onClick:()=>{s(),t(vl)},children:"Open it"}),children:["Adding ",q," waits for your approval in Needs you."]}):null,n.jsx(ie,{message:C}),n.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",q," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const z=S.steps.filter(ye=>ye.kind==="plugin").map(ye=>ye.title),ne=(a==null?void 0:a.missions.length)??e.missions.length,J=p.length;return n.jsxs(qe,{title:n.jsx(Ar,{entry:e,children:q}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"ghost",onClick:()=>{s(),t(Bt())},children:"Back to teammates"}),n.jsx(dt,{}),n.jsx(E,{variant:"accent",onClick:()=>Y(),children:"Say hello"})]}),children:[n.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[n.jsx(Gl,{entry:e,size:"xxl"}),n.jsxs("p",{className:"cat-done-title",children:[q," is on your team."]}),n.jsxs("p",{className:"cat-small",children:["@",(B==null?void 0:B.handle)??f,z.length?` · ${rn(z)} installed`:"",ne>0&&J<ne?` · ${ne-J===1?"a mission":"missions"} off until you turn ${ne-J===1?"it":"them"} on`:""]})]}),e.examples.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Try one"}),n.jsx("div",{className:"wb-starters",children:e.examples.map(ye=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>Y(ye),children:ye},ye))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const z=S.steps.find(ne=>ne.kind==="plugin"&&ne.state==="failed");return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:[q," wasn’t added"]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Close"}),n.jsx(E,{variant:"accent",disabled:w,onClick:U,children:"Try again"})]}),children:[n.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(ne=>{const{state:J,words:ye}=Qm(ne);return n.jsx(Jm,{state:J==="now"?"next":J,children:J==="now"?ye.replace(/…$/,""):ye},`${ne.kind}-${ne.name}`)})}),n.jsx(G,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?n.jsx(E,{size:"sm",onClick:()=>{s(),t(vl)},children:"Open the approval"}):void 0,children:n.jsxs("p",{children:["Nothing was added and nothing else changed.",z?n.jsxs(n.Fragment,{children:[" ",z.title," waits in"," ",n.jsx("a",{href:Pe("plugins"),onClick:ne=>{ne.preventDefault(),s(),t(Pe("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),n.jsx(ie,{message:k})]})}const X=(a==null?void 0:a.plugins.filter(z=>z.fix==="install"&&z.byBuddi))??[],Q=(a==null?void 0:a.blocked)??[],ee=Q[0],fe=ee?u$(ee):null,Oe=dh(a?a.tools.map(z=>z.name):e.tools,hh([...((Fe=e.claims)==null?void 0:Fe.tools)??[],...((a==null?void 0:a.tools)??[]).filter(z=>z.tier!=="unknown")])),Ie=z=>{var ne;return((ne=e.missions.find(J=>J.id===z))==null?void 0:ne.when)??""};return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:["Add ",q]}),onClose:s,foot:n.jsxs(ae,{children:[i?null:n.jsx("span",{className:"plugins-foot-note",children:X.length?`Installs ${rn(X.map(z=>z.title))}, then adds ${q}.`:"Nothing runs until you add it."}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsxs(E,{variant:"accent",disabled:!a||Q.length>0||w||f.length<2,onClick:H,children:["Add ",q]})]}),children:[n.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),n.jsx(ie,{message:o??k}),!a&&!o?n.jsx(pe,{children:"Reading what it needs…"}):a?n.jsxs(le,{divided:!0,gap:"lg",children:[X.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Installed on the way"}),n.jsx("ul",{className:"cat-plugins",children:X.map(z=>{const ne=M.find(J=>J.name===z.name);return n.jsxs("li",{children:[n.jsx($n,{svg:ne==null?void 0:ne.iconSvg}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsxs("span",{className:"cat-plugin-name",children:[z.title," ",z.version?n.jsx("span",{className:"plugins-ver",children:z.version}):null]}),n.jsx("span",{className:"cat-small",children:ne!=null&&ne.summary?VK(ne.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),n.jsx(we,{tone:"accent",children:"by buddi"})]},z.name)})})]}):null,ee?n.jsxs(G,{tone:"warning",action:fe?n.jsx(E,{size:"sm",onClick:()=>{s(),t(fe.route)},children:fe.label}):void 0,children:[q," needs ",rn(Q.map(c$))," first. Add ",Q.length===1?"it":"them",", then come back; nothing is added until then."]}):null,a.fills.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["A few picks ",n.jsx("span",{className:"cat-block-aside",children:"filled in for you"})]}),n.jsx("div",{className:"cat-fills",children:a.fills.map(z=>n.jsx(oe,{label:n.jsxs(n.Fragment,{children:[z.label,z.optional?n.jsx("span",{className:"faint",children:" · optional"}):null]}),children:z.choices&&z.choices.length>0?n.jsxs("select",{value:u[z.id]??"",onChange:ne=>h({...u,[z.id]:ne.target.value}),children:[z.kind==="calendar"?n.jsx("option",{value:"",children:"All of them"}):null,z.choices.map(ne=>n.jsx("option",{value:ne,children:ne},ne))]}):z.kind==="time"?n.jsx("input",{type:"time",value:u[z.id]??"",onChange:ne=>h({...u,[z.id]:ne.target.value})}):n.jsx("input",{value:u[z.id]??"",onChange:ne=>h({...u,[z.id]:ne.target.value})})},z.id))})]}):null,n.jsx("div",{className:"cat-block",children:n.jsx(oe,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:n.jsxs("span",{className:"cat-handle",children:[n.jsx("span",{className:"mono faint",children:"@"}),n.jsx("input",{className:"mono","aria-label":"Handle",value:f,onChange:z=>m(z.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]})})}),a.missions.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["Missions ",n.jsx("span",{className:"cat-block-aside",children:"off unless you turn one on"})]}),n.jsx("ul",{className:"cat-missions","data-switches":"true",children:a.missions.map(z=>n.jsxs("li",{children:[n.jsx("span",{className:"cat-mission-name",children:z.name}),n.jsx("span",{className:"cat-mission-when",children:Ie(z.id)}),n.jsx(wU,{checked:p.includes(z.id),label:`Turn on ${z.name}`,onChange:ne=>g(ne?[...p,z.id]:p.filter(J=>J!==z.id))})]},z.id))})]}):null,n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[L0(Oe)," ",n.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>b(!v),children:v?"Hide":"See all"})]}),v?n.jsx("dl",{className:"cat-reach",children:Oe.map(([z,ne])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:z}),n.jsx("dd",{children:ne})]},z))}):null]})]}):null]})}function F0({lines:e,label:t}){return n.jsx("div",{className:"cat-diff",role:"region","aria-label":t,children:e.map((s,r)=>{const i=s.startsWith("+ ")?"+":s.startsWith("- ")?"-":" ";return n.jsxs("div",{className:"cat-diff-line","data-kind":i==="+"?"add":i==="-"?"del":void 0,children:[n.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:i}),n.jsx("span",{children:(i===" "?s:s.slice(2))||" "})]},r)})})}function f$({entry:e,agentId:t,onClose:s,onUpdated:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(!1);d.useEffect(()=>{let w=!1;return A.catalogueUpdatePlan(e.name,t).then(y=>{w||a(y)}).catch(y=>{w||o(cl(y))}),()=>{w=!0}},[e.name,t]);const g=kl((i==null?void 0:i.version)??e.version),v=w=>{i&&(f(!0),o(null),A.catalogueUpdate(e.name,t,i.plan,w).then(()=>{p(!0),r==null||r()}).catch(y=>{o(cl(y)),A.catalogueUpdatePlan(e.name,t).then(a).catch(()=>{})}).finally(()=>f(!1)))};if(m)return n.jsx(qe,{title:n.jsxs(Ar,{entry:e,children:[e.title," ",g]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:s,children:"Done"})}),children:n.jsx(G,{tone:"good",title:`${e.title} is on ${g}.`,role:"status",children:i!=null&&i.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!i)return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:["Update ",e.title]}),onClose:s,children:[n.jsx(ie,{message:l}),l?null:n.jsx(pe,{children:"Reading what changed…"})]});const b=i.personaDiff.filter(w=>w.startsWith("+ ")).length,j=i.personaDiff.filter(w=>w.startsWith("- ")).length;if(i.edited)return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:[e.title," ",g," is out"]}),onClose:s,foot:n.jsxs(ae,{children:[c?null:n.jsx(E,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Keep mine"}),n.jsx(E,{variant:"danger",disabled:h,onClick:()=>v(!0),children:"Replace my changes"})]}),children:[n.jsx(G,{tone:"accent",children:i.replacesOwn&&i.replacesOwn.length>0?`${g} brings ${i.replacesOwn.length===1?"a skill":"skills"} named like your own (${rn(i.replacesOwn)}), so nothing is updated on its own. Yours stay exactly as they are unless you replace them; replaced, they go to the trash folder.`:`You’ve changed ${e.title} since you added it, so nothing is updated on its own. Your file stays exactly as it is unless you replace it.`}),n.jsx(ie,{message:l}),n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["New in ",g]}),n.jsx("p",{className:"cat-prose",children:i.changes})]}),n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["Your file and ",g," ",n.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>u(!c),children:c?"Hide":"See what changed"})]}),c?n.jsxs(n.Fragment,{children:[n.jsx(F0,{lines:i.personaDiff,label:`Your ${e.title} against ${g}`}),n.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",g,"; + is new in ",g,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):n.jsxs("p",{className:"cat-small",children:[j===1?"1 line":`${j} lines`," only in your file, ",b===1?"1 line":`${b} lines`," new in ",g,"."]})]})]})]});const x=i.added.length>0?`New: ${rn(dh(i.added.map(w=>w.name),hh(i.added)).map(([w])=>w))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return n.jsxs(qe,{title:n.jsxs(Ar,{entry:e,children:["Update ",e.title," to ",g]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Not now"}),n.jsxs(E,{variant:"accent",disabled:h,onClick:()=>v(!1),children:["Update ",e.title]})]}),children:[n.jsx("p",{className:"cat-lede",children:i.changes}),n.jsx(ie,{message:l}),n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What changes in its file"}),i.personaDiff.length>0?n.jsx(F0,{lines:i.personaDiff,label:`${e.title} ${kl(i.fromVersion)} against ${g}`}):n.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[x,i.removed.length>0?` No longer: ${i.removed.join(", ")}.`:""]})]}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Missions"}),n.jsx("p",{className:"cat-prose",children:i.missionsAdded.length>0?`${rn(i.missionsAdded.map(w=>w.name))} added, off until you turn ${i.missionsAdded.length===1?"it":"them"} on. Yours stay as they are.`:"None added. Yours stay as they are."})]}),i.retires&&i.retires.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Skills"}),n.jsxs("p",{className:"cat-prose",children:[g," no longer has ",rn(i.retires),"; ",i.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function Mi(e){if(e.state==="unavailable")return"unavailable";const t=e.installed;return e.state!=="installed"||!t?"ready":t.via&&(t.drift==="edited"||t.drift==="edited-update")?"replaced":t.drift==="update"?"update":t.drift==="edited-update"?"edited":"added"}function fw(){const e=de(()=>A.plugins(),[]);return d.useMemo(()=>{var t;return new Set((((t=e.data)==null?void 0:t.installed)??[]).filter(s=>s.loaded&&s.enabled!==!1).map(s=>s.name))},[e.data])}function mw(){return n.jsx(ce,{name:"check",size:14})}function YK({entry:e,loaded:t,mailbox:s}){const r=Mi(e);if(r==="unavailable")return n.jsx("span",{className:"cat-chips",children:n.jsx("span",{className:"cat-chip","data-need":"true",children:"Needs a newer buddi"})});const i=e.missing??[];if(i.length>0)return n.jsx("span",{className:"cat-chips",children:n.jsxs("span",{className:"cat-chip","data-need":"true",children:["Needs ",rn(i.map(c$))]})});if(r!=="ready")return null;const a=WK(e,t,s);if(a.length===0)return null;const l=`Uses ${rn(a)}`;return n.jsx("span",{className:"cat-uses",title:l,children:l})}function qK({entry:e,onAdd:t,onUpdate:s}){const r=Mi(e),i=a=>l=>{l.stopPropagation(),a()};return r==="added"||r==="replaced"?n.jsxs("span",{className:"cat-added",children:[n.jsx(mw,{}),"Added"]}):r==="update"?n.jsx(E,{size:"sm",onClick:i(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?n.jsx(E,{size:"sm",onClick:i(s),children:"See what changed"}):r==="unavailable"?null:n.jsx(E,{size:"sm",variant:"accent",onClick:i(t),"aria-label":`Add ${e.title}`,children:"Add"})}function JK({entry:e}){var r,i;const t=Mi(e),s=kl(e.version);return t==="update"?n.jsxs("p",{className:"cat-note",children:[s," is out: ",e.changes.charAt(0).toLowerCase()+e.changes.slice(1)]}):t==="edited"?n.jsxs("p",{className:"cat-note",children:["You’ve changed ",e.title,"; ",s," is out."]}):t==="replaced"?n.jsxs("p",{className:"cat-note","data-quiet":"true",children:["You have @",(r=e.installed)==null?void 0:r.handle,", which does this."]}):t==="added"?n.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",(i=e.installed)==null?void 0:i.handle]}):t==="unavailable"?n.jsx("p",{className:"cat-note","data-quiet":"true",children:e.reason}):null}function m$({entry:e,loaded:t,mailbox:s,onOpen:r,onAdd:i,onUpdate:a}){return n.jsx("div",{className:"cat-card","data-state":Mi(e),"data-testid":`cat-card-${e.name}`,children:n.jsxs(cs,{onClick:r,label:`${e.title}: details`,children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx(Gl,{entry:e,size:"lg"}),n.jsxs("div",{className:"cat-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.title}),n.jsx("div",{className:"cat-card-kind",children:dw(e.category)})]})]}),n.jsx("p",{className:"cat-pitch",children:e.pitch}),n.jsx(JK,{entry:e}),n.jsxs("div",{className:"cat-card-foot",children:[n.jsx(YK,{entry:e,loaded:t,mailbox:s}),n.jsx(dt,{}),n.jsx(qK,{entry:e,onAdd:i,onUpdate:a})]})]})})}function QK({row:e,agents:t,navigate:s,pages:r}){const i=qj(e.plugin,e.agent,()=>window.dispatchEvent(new Event(dr))),a=i.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?PA(e.plugin,r.all):Nf(e.plugin);return n.jsx("div",{className:"cat-card","data-state":a?"added":"ready","data-testid":`cat-card-${e.agent}`,children:n.jsxs(cs,{onClick:a?()=>s(St(a.id)):void 0,label:a?`Open @${a.handle}`:void 0,children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx("span",{className:"cat-face","data-size":"lg",children:n.jsx(bn,{id:e.agent,name:e.name,size:"lg",face:t.find(o=>o.id===e.agent)})}),n.jsxs("div",{className:"cat-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.name}),n.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),n.jsx("p",{className:"cat-pitch",children:e.text}),a?n.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",a.handle]}):null,n.jsxs("div",{className:"cat-card-foot",children:[n.jsx(ie,{message:i.failure}),n.jsx(dt,{}),a?n.jsxs("span",{className:"cat-added",children:[n.jsx(mw,{}),"Added"]}):n.jsx(E,{size:"sm",variant:"accent",disabled:i.busy,onClick:o=>{o.stopPropagation(),i.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function XK({n:e=6}){return n.jsx("div",{className:"cat-grid","aria-busy":"true","aria-label":"Loading the catalogue","data-testid":"cat-loading",children:Array.from({length:e},(t,s)=>n.jsxs("div",{className:"ui-card cat-skel",children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx("i",{className:"cat-skel-face"}),n.jsxs("span",{className:"cat-card-name",children:[n.jsx("i",{className:"cat-skel-line","data-w":"40"}),n.jsx("i",{className:"cat-skel-line","data-w":"20"})]})]}),n.jsx("i",{className:"cat-skel-line","data-w":"90"}),n.jsx("i",{className:"cat-skel-line","data-w":"70"})]},s))})}function ZK(e,t,s){const r=e.find(i=>i.roles.includes(Wc));r&&(s.trim()&&ij(r.id,`I'd like a teammate for this: ${s.trim()}`),t(st(r.id)))}function eV({sheet:e,view:t,navigate:s,onClose:r,onChanged:i}){const a=e?t==null?void 0:t.agents.find(l=>l.name===e.name):void 0;return!e||!a?null:e.kind==="update"&&a.installed?n.jsx(f$,{entry:a,agentId:a.installed.agentId,onClose:r,onUpdated:i}):n.jsx(h$,{entry:a,navigate:s,onClose:r,onAdded:i})}const tV=[{value:"all",label:"All"},{value:"work",label:"Work"},{value:"money",label:"Money"},{value:"home",label:"Home"},{value:"health",label:"Health"},{value:"learning",label:"Learning"},{value:"life",label:"Life"}];function nV(e,t){return[e.title,e.pitch,e.about,e.description,dw(e.category)].some(s=>s.toLowerCase().includes(t))}function sV({name:e,agents:t,navigate:s,pluginPages:r}){const[i,a]=d.useState(0),l=de(()=>A.catalogue(i>0),[i]),o=fw(),[c,u]=d.useState(""),[h,f]=d.useState("all"),[m,p]=d.useState(null),g=l.data,v=()=>{l.reload(),window.dispatchEvent(new Event(dr))},b=()=>a(T=>T+1),j=n.jsx(eV,{sheet:m,view:g,navigate:s,onClose:()=>p(null),onChanged:v}),x=e?g==null?void 0:g.agents.find(T=>T.name===e):void 0,w=d.useRef(!1);if(d.useEffect(()=>{w.current||!x||!i4(window.location.hash,x.name)||(w.current=!0,Mi(x)==="ready"&&p({kind:"install",name:x.name}))},[x]),e&&g&&!g.unavailable&&x)return n.jsxs(n.Fragment,{children:[n.jsx(aV,{entry:x,loaded:o,agents:t,navigate:s,onAdd:()=>p({kind:"install",name:x.name}),onUpdate:()=>p({kind:"update",name:x.name})}),j]});const y=c.trim().toLowerCase(),N=((g==null?void 0:g.agents)??[]).filter(T=>(h==="all"||T.category===h)&&(!y||nV(T,y))),S=((g==null?void 0:g.fromPlugins)??[]).filter(T=>h==="all"&&(!y||[T.name,T.text,T.description].some(R=>R.toLowerCase().includes(y)))),C=T=>()=>s(T);return n.jsxs(Pj,{children:[n.jsx(wl,{before:n.jsx(Zd,{inline:!0,items:[{label:"Agents",href:mt,onClick:C(mt)}]}),title:"Add a teammate",lede:"Agents tested with the plugins they use. Adding one is one approval, and it becomes a file on this computer you can change."}),e&&g&&!g.unavailable&&!x?n.jsxs(G,{tone:"warning",children:["The catalogue lists no teammate called “",e,"”. Here is everyone it does list."]}):null,n.jsxs("div",{className:"cat-bar",children:[n.jsxs("div",{className:"cat-search",children:[n.jsx(ce,{name:"search",size:16}),n.jsx(xf,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),n.jsx("div",{className:"cat-cats",children:n.jsx(yA,{label:"Category",options:tV,value:h,onChange:f})})]}),g&&!g.unavailable?g.stale?n.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[n.jsx(ce,{name:"globe",size:14}),"From the list kept ",g.fetchedAt?rV(g.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",n.jsx("button",{type:"button",className:"plugins-link",onClick:b,children:"Try again"})]}):n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!g?n.jsx(pe,{warm:!0,title:"The catalogue didn’t load",action:n.jsx(E,{variant:"accent",size:"sm",onClick:b,children:"Try again"}),children:l.error}):g?g.unavailable?n.jsx(pe,{warm:!0,title:"The catalogue needs withbuddi.com",action:n.jsx(E,{variant:"accent",size:"sm",disabled:l.loading,onClick:b,children:"Try again"}),children:"This computer can’t reach it right now, and there’s no saved copy yet. Try again when you’re online."}):N.length+S.length>0?n.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[N.map(T=>n.jsx(m$,{entry:T,loaded:o,mailbox:g.mailbox,onOpen:()=>s(Bt(T.name)),onAdd:()=>p({kind:"install",name:T.name}),onUpdate:()=>p({kind:"update",name:T.name})},T.name)),S.map(T=>n.jsx(QK,{row:T,agents:t,navigate:s,pages:r},`${T.plugin}/${T.agent}`))]}):n.jsx(pe,{warm:!0,title:"No teammate for that yet",action:n.jsxs("span",{className:"cat-empty-acts",children:[n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>ZK(t,s,c),children:"Ask Agent Father"})]}),children:y?n.jsxs(n.Fragment,{children:["Nothing in the catalogue does “",c.trim(),"”. Agent Father can make one for you; your words go with you."]}):"Nothing in this category yet."}):n.jsx(XK,{}),g&&!g.unavailable&&g.delisted.length>0?n.jsx(Ge,{title:"No longer in the catalogue",children:n.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:g.delisted.map(T=>n.jsxs("li",{children:[n.jsx(ln,{agents:t,id:T.agentId,size:"sm"}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("a",{className:"cat-plugin-name",href:St(T.agentId),onClick:R=>{R.preventDefault(),s(St(T.agentId))},children:T.name??`@${T.handle}`}),n.jsxs("span",{className:"cat-small",children:["@",T.handle," keeps working as it is; no updates will come."]})]})]},T.agentId))})}):null,j]})}function rV(e){const t=Math.round((Date.now()-Date.parse(e))/36e5);if(!Number.isFinite(t)||t<1)return"an hour ago";if(t<24)return`${t} h ago`;const s=Math.round(t/24);return s===1?"yesterday":`${s} days ago`}function Ui({title:e,children:t}){return n.jsxs("section",{className:"cat-row",children:[n.jsx("h2",{className:"cat-row-title",children:e}),n.jsx("div",{className:"cat-row-body",children:t})]})}function iV({entry:e,loaded:t,navigate:s}){const r=new Map((e.missing??[]).map(a=>[a.name,a])),i=[...Object.keys(e.requires).map(a=>({name:a,needed:!0,need:!1})),...Object.keys(e.optional).map(a=>({name:a,needed:!1,need:!1})),...e.needs.map(a=>({name:a.replace(/\?$/,""),needed:!a.endsWith("?"),need:!0}))];return i.length===0?n.jsx("p",{className:"cat-small",children:"None. It works with what buddi has."}):n.jsx("ul",{className:"cat-plugins",children:i.map(({name:a,needed:l,need:o})=>{const c=r.get(a),u=c?u$(c):null,h=o?hw(a).title:(c==null?void 0:c.kind)==="plugin"?c.title:Nf(a),f=o?l&&!c:t.has(a);return n.jsxs("li",{children:[n.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:n.jsx(ce,{name:o?a==="mailbox"?"mail":"key":"plug",size:14})}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("span",{className:"cat-plugin-name",children:h.charAt(0).toUpperCase()+h.slice(1)}),n.jsx("span",{className:"cat-small",children:l?"Needed":"Better with it"})]}),u?n.jsx(E,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?n.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?n.jsxs("span",{className:"cat-added",children:[n.jsx(mw,{}),o?"You have one":"Installed"]}):n.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${a}`)})})}function aV({entry:e,loaded:t,agents:s,navigate:r,onAdd:i,onUpdate:a}){var p,g,v;const l=Mi(e),c=(p=e.installed)==null?void 0:p.agentId,u=kl(e.version),h=b=>{c&&(b&&ij(c,b),r(st(c)))},f=dh(e.tools,hh((g=e.claims)==null?void 0:g.tools)),m=e.replaces.map(b=>qm(b.split("/")[1]??b));return n.jsxs(Pj,{children:[n.jsxs("a",{className:"cat-back",href:Bt(),onClick:b=>{b.preventDefault(),r(Bt())},children:[n.jsx(ce,{name:"chevron-left",size:12}),"Teammates"]}),n.jsxs("header",{className:"cat-hero",children:[n.jsx(Gl,{entry:e,size:"xxl"}),n.jsxs("div",{className:"cat-hero-text",children:[n.jsx("h1",{className:"cat-hero-title",children:e.title}),n.jsx("p",{className:"cat-hero-pitch",children:e.pitch}),n.jsxs("p",{className:"cat-hero-meta",children:[e.trust==="by-buddi"?n.jsx(we,{tone:"accent",children:"by buddi"}):null,n.jsx("span",{children:dw(e.category)}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{className:"mono",children:((v=e.installed)==null?void 0:v.version)??e.version}),e.installed?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsxs("span",{children:["on your team as ",n.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),n.jsx("div",{className:"cat-hero-act",children:l==="ready"?n.jsxs(E,{variant:"accent",onClick:i,children:["Add ",e.title]}):l==="update"?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>h(),children:"Open chat"}),n.jsxs(E,{variant:"accent",onClick:a,children:["Update to ",u]})]}):l==="edited"?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>h(),children:"Open chat"}),n.jsx(E,{onClick:a,children:"See what changed"})]}):l==="unavailable"?null:n.jsx(E,{variant:"accent",onClick:()=>h(),children:"Open chat"})})]}),l==="edited"?n.jsxs(G,{tone:"accent",children:["You’ve changed ",e.title," since you added it, so ",u," isn’t applied on its own. Your file stays as it is unless you replace it."]}):l==="unavailable"?n.jsx(G,{tone:"warning",children:e.reason}):null,n.jsx(Ge,{flush:!0,children:n.jsxs("div",{className:"cat-rows",children:[n.jsxs(Ui,{title:"What it does",children:[n.jsx("p",{className:"cat-prose",children:e.about}),m.length>0?n.jsxs("p",{className:"cat-small",children:["Does what ",rn(m)," did. If you have ",rn(m)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?n.jsxs(Ui,{title:"Ask it",children:[n.jsx("div",{className:"wb-starters",children:e.examples.map(b=>n.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>h(b),children:b},b))}),c?null:n.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,n.jsx(Ui,{title:"Skills",children:e.skills.length===0?n.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(b=>n.jsxs("li",{children:[n.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:n.jsx(ce,{name:"files",size:14})}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("span",{className:"cat-plugin-name",children:qm(b.name)}),b.description?n.jsx("span",{className:"cat-small",children:b.description}):null,n.jsx(At,{summary:"Read it",children:n.jsx(Pt,{label:`${qm(b.name)}: the skill's text`,children:b.text})})]})]},b.name))}),n.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?n.jsxs(n.Fragment,{children:["Read and change them on ",n.jsx("a",{href:St(c,"skills"),onClick:b=>{b.preventDefault(),r(St(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),n.jsxs(Ui,{title:"What it can reach",children:[n.jsx("dl",{className:"cat-reach",children:f.map(([b,j])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:b}),n.jsx("dd",{children:j})]},b))}),n.jsx("p",{className:"cat-small",children:"Anything that sends or pays still asks you first, every time. You can change any of this on its page."})]}),n.jsx(Ui,{title:"Missions",children:e.missions.length>0?n.jsx("ul",{className:"cat-missions",children:e.missions.map(b=>n.jsxs("li",{children:[n.jsx("span",{className:"cat-mission-name",children:b.name}),n.jsx("span",{className:"cat-mission-when",children:b.when}),n.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},b.id))}):n.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),n.jsx(Ui,{title:"Plugins",children:n.jsx(iV,{entry:e,loaded:t,navigate:r})}),n.jsxs(Ui,{title:"Version",children:[n.jsxs("p",{className:"cat-prose",children:[n.jsx("span",{className:"mono",children:e.version})," · ",e.changes]}),n.jsx("p",{className:"cat-small",children:"Reviewed in withbuddi/buddi-market. An update always asks you, and never touches a file you changed."})]})]})})]})}function lV(e){var r,i;const t=de(()=>A.agents(),[e]),s=(i=(r=t.data)==null?void 0:r.catalogue)==null?void 0:i[e];return{entry:s?{...s,agentId:e}:void 0,reload:t.reload}}function oV({entry:e,navigate:t,onUpdated:s}){const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=e.delisted?null:e.drift==="update"?"update":e.drift==="edited-update"&&!e.via?"edited":null,h=()=>{c(!0),l(null),A.catalogue().then(f=>{const m=f.agents.find(p=>p.name===e.package);m?i(m):l(f.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(f=>l(f instanceof ve?f.message:String(f))).finally(()=>c(!1))};return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?n.jsx("span",{children:"No longer in the catalogue"}):n.jsx("a",{href:Bt(e.package),onClick:f=>{f.preventDefault(),t(Bt(e.package))},children:"From the catalogue"}),n.jsx("span",{"aria-hidden":"true",children:" · "}),n.jsxs("span",{children:[e.title," ",e.via?`(was ${e.via.split("/")[1]??e.via})`:kl(e.version)]}),e.delisted?n.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?n.jsx(E,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${kl(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),a?n.jsx(ie,{message:a}):null,r?n.jsx(f$,{entry:r,agentId:e.agentId,onClose:()=>i(null),onUpdated:s}):null]})}function cV(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function uV({agentId:e,name:t,navigate:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),f=b=>b instanceof ve?b.message:String(b),m=()=>{i(!0),c(null),l(null),A.agentRemovePreview(e).then(l).catch(b=>c(f(b)))},p=()=>{h(!0),c(null),A.removeAgent(e).then(()=>{window.dispatchEvent(new Event(dr)),i(!1),s(mt)}).catch(b=>c(f(b))).finally(()=>h(!1))},g=(a==null?void 0:a.pausesMissions.map(cV))??[],v=(a==null?void 0:a.unusedPlugins)??[];return n.jsxs(Ge,{children:[n.jsxs(ae,{children:[n.jsxs("div",{className:"agent-remove-text",children:[n.jsx("strong",{children:"Remove from team"}),n.jsx("span",{className:"muted",children:"Its file goes to the trash folder; what it remembers and its conversations stay."})]}),n.jsxs(E,{variant:"danger-ghost",onClick:m,children:["Remove ",t,"…"]})]}),r?n.jsxs(Ft,{title:`Remove ${t} from your team?`,onClose:()=>i(!1),foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:u||!a,onClick:p,children:"Remove from team"})]}),children:[n.jsx(ie,{message:o}),a?n.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[n.jsxs("p",{children:["@",a.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),g.length>0?n.jsxs("p",{children:["Its ",g.length===1?"mission":"missions"," ",rn(g)," ",g.length===1?"is":"are"," paused."]}):null,v.length>0?n.jsxs("p",{children:["No other agent uses ",rn(v.map(Nf)),"; it stays installed."," ",n.jsxs("a",{href:Pe("plugins"),onClick:b=>{b.preventDefault(),i(!1),s(Pe("plugins"))},children:["Remove ",v.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:n.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const dV=["fact","observation","todo"];function p$({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=de(()=>A.memory(r),[r],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),p=y=>{var k;return y==="shared"?"Everyone":((k=t.find(N=>N.id===y))==null?void 0:k.name)??y},g=async y=>{m(null);try{await y,l()}catch(k){m(k instanceof ve?k.message:String(k))}},v={nameOf:p,timezone:s,onChangePreference:y=>c({key:y.key,scope:y.scope}),onForgetPreference:y=>void g(A.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>h(y),onForgetNote:y=>void g(A.forgetNote(y.id))},b=r?p(r):"",j=r&&i?{preferences:i.preferences.filter(y=>y.scope===r),notes:i.notes.filter(y=>y.scope===r)}:null,x=r&&i?{preferences:i.preferences.filter(y=>y.scope==="shared"),notes:i.notes.filter(y=>y.scope==="shared")}:null,w=n.jsx(E,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(Pn,{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(ie,{message:a??f}),j&&x?n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Preferences",aside:`what you told ${b} alone`,actions:w,panel:!0,flush:!0,children:n.jsx(Xm,{preferences:j.preferences,empty:`Nothing stated to ${b} alone yet.`,...v})}),n.jsx(ue,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(Zm,{notes:j.notes,empty:`${b} has kept no private notes yet.`,...v})}),n.jsx(At,{summary:`Shared with every agent, which ${b} also reads · ${x.preferences.length} preferences, ${x.notes.length} notes`,children:n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(Xm,{preferences:x.preferences,empty:"No shared preferences.",...v})}),n.jsx(ue,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(Zm,{notes:x.notes,empty:"No shared notes.",...v})})]})})]}):n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Preferences",aside:"what you said you want, one current value each",actions:w,panel:!0,flush:!0,children:i?n.jsx(Xm,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...v}):n.jsx(pe,{children:"Loading…"})}),n.jsx(ue,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(Zm,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...v}):n.jsx(pe,{children:"Loading…"})})]}),o?n.jsx(hV,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await g((async()=>{await A.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await A.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(fV,{note:u,agents:t,onClose:()=>h(null),onSave:y=>g(A.updateNote(u.id,y)).then(()=>h(null))}):null]})}function Xm({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(jr,{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(g$,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?Le(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function Zm({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(jr,{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(we,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(g$,{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?Le(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",xr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function g$({scope:e,name:t}){return n.jsx(we,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function x$({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 hV({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(x=>x.key===s.key&&x.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((a==null?void 0:a.value)??""),[h,f]=d.useState(s.scope),[m,p]=d.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=t.find(x=>x.key===g&&x.scope===h),b=!a||g!==a.key||c.trim()!==a.value||h!==a.scope,j=g!==""&&c.trim()!==""&&b;return n.jsx(qe,{title:"A preference",onClose:r,children:n.jsxs(le,{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(oe,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:x=>o(x.target.value),placeholder:"reporting_currency"})}),n.jsx(oe,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:x=>u(x.target.value),placeholder:"EUR"})}),n.jsx(oe,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(x$,{value:h,agents:e,onChange:f})}),v&&v!==a?n.jsxs(G,{tone:"warning",children:['This replaces the value already stored for this key here, "',v.value,'" (revision ',v.revision,")."]}):null,a&&h!==a.scope?n.jsxs(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(E,{onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),i({key:g,value:c.trim(),scope:h}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function fV({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=d.useState(e.content),[l,o]=d.useState(e.scope),[c,u]=d.useState(e.kind),[h,f]=d.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(qe,{title:"A note",onClose:s,children:n.jsxs(le,{children:[n.jsx(oe,{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(Us,{children:[n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:dV.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(oe,{label:"Who sees it",children:n.jsx(x$,{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?`, ${Le(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:s,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!m||i.trim()===""||h,onClick:()=>{f(!0);const g={};i.trim()!==e.content&&(g.content=i.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>f(!1))},children:"Save"})]})]})})}const Ma=e=>`/skills/${encodeURIComponent(e)}`,_n={list:()=>je("/skills"),detail:e=>je(Ma(e)),downloadUrl:e=>`/api${Ma(e)}/download`,create:e=>te("/skills",e),saveText:(e,t)=>te(`${Ma(e)}/text`,{text:t}),grant:(e,t)=>te(`${Ma(e)}/grants`,t),trust:e=>te(`${Ma(e)}/trust`),remove:e=>tr(Ma(e))};function mV(e){return`${mt}?tab=skills`}function pV(e){var s;const t=(s=/[?&]skill=([^&]+)/.exec(e))==null?void 0:s[1];if(!t)return null;try{return decodeURIComponent(t)}catch{return null}}function v$(e){const t=document.createElement("a");t.href=_n.downloadUrl(e),t.download="",document.body.appendChild(t),t.click(),t.remove()}const pw=[{id:"mine",title:"Yours",aside:"Written or uploaded by you."},{id:"learned",title:"Learned",aside:"An agent proposed it and you kept it."},{id:"plugin",title:"From plugins",aside:"Comes with a plugin and goes with it."},{id:"catalogue",title:"From the catalogue",aside:"Came with a teammate. Yours to change."}];function j$(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Or(e,t){var s;return((s=e.find(r=>r.id===t))==null?void 0:s.name)??t}function gw(e){return e.charAt(0).toUpperCase()+e.slice(1)}function gV(e,t){if(e.every)return"Every agent";const s=e.holders.map(r=>Or(t,r.agent));return s.length?j$(s):"No agent uses it yet"}function xV(e){return!e.every&&e.holders.length===0}function vV(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function _0(e){return e.slice(0,10)===vV()?"today":`on ${Dc(e,{compact:!0})}`}function xw(e,t,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(f=>f.agent===c),h=e.learned.keptAt?` · kept ${Le(e.learned.keptAt)}`:"";return`${u?"":`learned by ${Or(t,c)} · `}v${e.learned.version}${e.learned.edited?" with your correction":""}${h}`}const r=e.from;if((r==null?void 0:r.kind)==="plugin")return`from ${gw(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Or(t,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${_0(e.created)}`:""} · ${r.filename}`;const i=((l=e.created)==null?void 0:l.slice(0,10))??null,a=((o=e.updatedAt)==null?void 0:o.slice(0,10))??null;return i&&(!a||a<=i)?`written by you ${_0(i)}`:e.updatedAt?`edited by you ${Le(e.updatedAt)}`:"written by you"}function w$(e){return e.charAt(0).toUpperCase()+e.slice(1)}function vw(e,t){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Or(t,((s=e.learned)==null?void 0:s.by)??e.home??"")} proposed it.`:"Untrusted: it came from a file, so agents read it as outside text."}function jV(e){const t=e.file.split(/[\\/]/).pop()??e.file;return e.home?`agents/${e.home}/skills/${t}`:`skills/${t}`}function jw(e){return e.every?[]:e.holders.map(t=>t.agent)}function wV(e,t){var s;if(e.learned){const r=Or(t,e.learned.by);return`Saved as v${e.learned.version+1}, your correction. v${e.learned.version} stays in ${r}’s folder.`}return((s=e.from)==null?void 0:s.kind)==="catalogue"?`${Or(t,e.from.agent)}’s next update will ask before it replaces your change.`:null}function yV(e,t,s){var o;const r=t.stops.map(c=>Or(s,c)),i=e.learned?Or(s,e.learned.by):"";if(e.learned&&!t.every&&t.stops.length===1&&t.stops[0]===e.learned.by)return`${i} stops using it and won’t propose it again for 90 days. Earlier versions stay in its folder.`;const a=t.every?"Every agent stops using it.":r.length===0?"No agent uses it, so nothing changes.":`${j$(r)} ${r.length>1?"stop":"stops"} using it.`,l=t.then==="versions-kept"?`${i} won’t propose it again for 90 days. Earlier versions stay in its folder.`:t.then==="catalogue-asks"?`${((o=e.from)==null?void 0:o.kind)==="catalogue"?Or(s,e.from.agent):"Its teammate"}’s next update asks before bringing it back.`:"The file goes to the trash folder.";return`${a} ${l}`}function bV(e,t){var c,u;const s=t.replace(/\r\n/g,`
|
|
110
|
+
`),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),i=h=>{var m;return(r?((m=new RegExp(`^${h}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:m[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},a=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(a))==null?void 0:c[1])==null?void 0:u.trim(),o=i("name");return{title:l||(o?w$(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:i("description"),body:a}}const kV=5e4,ua=e=>e instanceof ve?e.message:String(e),NV=e=>t=>{t.stopPropagation(),e==null||e()};function SV({faces:e,navigate:t,command:s,openSkill:r}){const i=de(()=>_n.list(),[]),[a,l]=d.useState(r?{id:r}:null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),v=d.useRef(null);d.useEffect(()=>{r&&l({id:r})},[r]),d.useEffect(()=>{var w;s&&(s.kind==="write"?c({kind:"write"}):(w=v.current)==null||w.click())},[s]);const b=w=>{var N;const y=(N=w.target.files)==null?void 0:N[0];if(w.target.value="",!y)return;if(!/\.md$/i.test(y.name)){h(`“${y.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(y.size>kV){h(`“${y.name}” is over 50 KB. A skill is a short text.`);return}const k=new FileReader;k.onload=()=>{h(null),c({kind:"upload",file:{name:y.name,size:y.size,...bV(y.name,String(k.result))}})},k.readAsText(y)},j=w=>{m(null),w!==void 0&&g(w),i.reload()};return n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:v,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:b}),u?n.jsx(G,{tone:"warning",action:n.jsx(E,{size:"sm",onClick:()=>{var w;h(null),(w=v.current)==null||w.click()},children:"Pick another file"}),children:u}):null,n.jsx(ie,{message:f}),p?n.jsx(G,{tone:"good",role:"status",children:p}):null,n.jsx(CV,{view:i,onOpen:w=>l({id:w.id}),onAct:(w,y)=>x(w,y)}),n.jsx(y$,{view:i.data,faces:e,open:a,setOpen:l,dialog:o,setDialog:c,navigate:t,onChanged:j,onFailed:m}),(o==null?void 0:o.kind)==="write"&&i.data?n.jsx(z0,{agents:i.data.agents,faces:e,onClose:()=>c(null),onSaved:w=>{c(null),j(`Saved “${w.title}”.`)}}):null,(o==null?void 0:o.kind)==="upload"&&i.data?n.jsx(z0,{agents:i.data.agents,faces:e,upload:o.file,onClose:()=>c(null),onSaved:w=>{c(null),j(`Saved “${w.title}”.`)}}):null]});function x(w,y){g(null),y==="trust"?_n.trust(w.id).then(()=>j(),k=>m(ua(k))):y==="download"?v$(w.id):y==="plugin"?t(Pe("plugins")):y==="edit"?(c(null),l({id:w.id,edit:!0})):c({kind:y,id:w.id})}}function CV({view:e,onOpen:t,onAct:s}){if(!e.data&&e.error)return n.jsx(pe,{warm:!0,title:"Couldn’t load your skills",action:n.jsx(E,{variant:"accent",size:"sm",onClick:e.reload,children:"Try again"}),children:"buddi didn’t answer. Your skill files are untouched."});if(!e.data)return n.jsx(AV,{});const{skills:r,agents:i}=e.data;return r.length===0?n.jsx(pe,{warm:!0,title:"No skills yet",children:"A skill teaches an agent one kind of task, in plain words. Write one here, or upload a .md file you already have."}):n.jsx(Ge,{flush:!0,children:pw.map(a=>{const l=r.filter(o=>o.group===a.id);return l.length?n.jsxs("section",{className:"skills-group","aria-label":a.title,children:[n.jsxs("header",{className:"skills-group-head",children:[n.jsx("h3",{className:"skills-group-title",children:a.title}),n.jsx("span",{className:"skills-group-aside",children:a.aside})]}),n.jsx(rt,{children:l.map(o=>n.jsx(EV,{row:o,agents:i,onOpen:t,onAct:s},o.id))})]},a.id):null})})}function EV({row:e,agents:t,onOpen:s,onAct:r}){var l,o,c;const i=e.untrusted?["trust","Mark as mine"]:xV(e)?["picker","Choose agents"]:null,a=gV(e,t);return n.jsx(et,{onClick:()=>s(e),label:`${e.title}: details`,lead:n.jsx($n,{icon:"files"}),title:e.title,sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"skills-line",children:e.description}),n.jsxs("span",{className:"skills-line skills-meta",children:[a," · ",xw(e,t,!0)]}),e.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:vw(e,t)}):null]}),side:n.jsxs("span",{className:"skills-side",children:[i?n.jsx(E,{size:"sm",onClick:NV(()=>r(e,i[0])),children:i[1]}):null,n.jsx(ja,{label:`More for ${e.title}`,sheet:{title:e.title,sub:a},items:[{label:"Choose agents…",hint:"Give it or take it away",onSelect:()=>r(e,"picker")},e.editable?{label:"Edit text",onSelect:()=>r(e,"edit")}:null,{label:"Download",hint:".md file",onSelect:()=>r(e,"download")},((l=e.from)==null?void 0:l.kind)==="plugin"?{label:`Open ${gw(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((o=e.from)==null?void 0:o.kind)!=="plugin"?"separator":null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function AV(){return n.jsx(Ge,{flush:!0,children:n.jsxs("div",{className:"skills-group skills-loading","aria-busy":"true","aria-label":"Loading skills",children:[n.jsx("header",{className:"skills-group-head",children:n.jsx("i",{className:"cat-skel-line","data-w":"20"})}),n.jsx(rt,{children:[0,1,2].map(e=>n.jsxs("div",{className:"ui-list-row",children:[n.jsx("span",{className:"ui-app-icon"}),n.jsxs("span",{className:"ui-list-main skills-skel",children:[n.jsx("i",{className:"cat-skel-line","data-w":"40"}),n.jsx("i",{className:"cat-skel-line","data-w":"70"})]})]},e))})]})})}function y$({view:e,faces:t,open:s,setOpen:r,dialog:i,setDialog:a,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=m=>e.skills.find(p=>p.id===m),h=s?u(s.id):void 0,f=i&&"id"in i?u(i.id):void 0;return n.jsxs(n.Fragment,{children:[h?n.jsx($V,{row:h,agents:e.agents,faces:t,initialEdit:!!(s!=null&&s.edit),onClose:()=>r(null),onPicker:()=>a({kind:"picker",id:h.id}),onDelete:()=>a({kind:"delete",id:h.id}),onChanged:o,onFailed:c,navigate:l},`${h.id}-${s!=null&&s.edit?"edit":"read"}`):null,(i==null?void 0:i.kind)==="picker"&&f?n.jsx(RV,{row:f,agents:e.agents,faces:t,onCancel:()=>a(null),onSaved:()=>{a(null),o()}}):null,(i==null?void 0:i.kind)==="delete"&&f?n.jsx(PV,{row:f,agents:e.agents,onCancel:()=>a(null),onDeleted:m=>{a(null),r(null),o(m)}}):null]})}function b$({title:e,sub:t}){return n.jsxs("span",{className:"skills-sheet-title",children:[n.jsx($n,{icon:"files",size:"lg"}),n.jsxs("span",{className:"skills-sheet-name",children:[n.jsx("span",{children:e}),n.jsx("span",{className:"skills-sheet-by",children:t})]})]})}function pd({title:e,aside:t,children:s}){return n.jsxs("section",{className:"skills-sec","aria-label":e,children:[n.jsxs("header",{className:"skills-sec-head",children:[n.jsx("h3",{className:"skills-sec-title",children:e}),t?n.jsx("span",{className:"skills-sec-aside",children:t}):null]}),s]})}function TV({file:e,body:t,text:s}){const[r,i]=d.useState("read");return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"skills-text-bar",children:[n.jsx(Kt,{label:"Show the text as",value:r,onChange:i,options:[{value:"read",label:"Read"},{value:"source",label:"Source"}]}),n.jsx("span",{className:"skills-file mono",children:e})]}),r==="read"?n.jsx(fr,{className:"wb-md skills-md",text:t}):n.jsx(Pt,{label:e,children:s})]})}function $V({row:e,agents:t,faces:s,initialEdit:r,onClose:i,onPicker:a,onDelete:l,onChanged:o,onFailed:c,navigate:u}){var L,W,$;const h=de(()=>_n.detail(e.id),[e.id,e.updatedAt,e.untrusted,(L=e.learned)==null?void 0:L.version]),[f,m]=d.useState(!!r&&e.editable),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=((W=h.data)==null?void 0:W.text)??"",y=w$(xw(e,t)),k=wV(e,t),N=(($=e.from)==null?void 0:$.kind)==="plugin"?gw(e.from.plugin):null,S=P=>s.find(O=>O.id===P),C=async(P,O)=>{b(!0),x(null);try{await P(),O==null||O(),o()}catch(M){x(ua(M)),c(ua(M))}finally{b(!1)}},T=P=>{C(()=>_n.grant(e.id,{agents:jw(e).filter(O=>O!==P)}))},R=()=>{C(()=>_n.saveText(e.id,p??w),()=>{m(!1),g(null)})},I=(P,O)=>{var M,D;if(((M=e.learned)==null?void 0:M.by)===P)return"Proposed it";if(((D=e.from)==null?void 0:D.kind)==="catalogue"&&e.from.agent===P)return"Came with it";if(O==="home")return"In its own folder"};return n.jsxs(qe,{size:"wide",title:n.jsx(b$,{title:e.title,sub:y}),onClose:i,foot:f?n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",disabled:v,onClick:()=>{m(!1),g(null)},children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:v||!h.data,onClick:R,children:"Save"})]}):n.jsxs(ae,{children:[e.deletable&&!N?n.jsx(E,{variant:"danger-ghost",onClick:l,children:"Delete…"}):null,n.jsx(dt,{}),n.jsx(E,{onClick:()=>v$(e.id),children:"Download"}),e.editable?n.jsx(E,{variant:e.untrusted?void 0:"accent",onClick:()=>m(!0),children:"Edit text"}):null]}),children:[e.untrusted?n.jsxs(G,{tone:"warning",action:n.jsx(E,{size:"sm",variant:"accent",disabled:v,onClick:()=>void C(()=>_n.trust(e.id)),children:"Mark as mine"}),children:[vw(e,t)," Mark it as yours once you’ve read it."]}):null,n.jsx(ie,{message:j}),n.jsxs("div",{className:"skills-sheet",children:[n.jsx(pd,{title:"When it’s used",children:n.jsx("p",{className:"skills-desc",children:e.description})}),n.jsx(pd,{title:"Used by",aside:n.jsx(E,{size:"sm",onClick:a,children:"Change…"}),children:e.every?n.jsx(rt,{children:n.jsx(et,{lead:n.jsx($n,{icon:"agents"}),title:"Every agent",sub:"Now, and any you add later."})}):e.holders.length?n.jsx(rt,{children:e.holders.map(P=>{const O=t.find(M=>M.id===P.agent);return n.jsx(et,{lead:n.jsx(bn,{id:P.agent,name:(O==null?void 0:O.name)??P.agent,size:"sm",face:S(P.agent)}),title:n.jsxs(n.Fragment,{children:[(O==null?void 0:O.name)??P.agent," ",n.jsxs("span",{className:"skills-handle",children:["@",(O==null?void 0:O.handle)??P.agent]})]}),sub:I(P.agent,P.how),side:P.how==="home"?void 0:n.jsx(E,{size:"sm",variant:"ghost",disabled:v,onClick:()=>T(P.agent),"aria-label":`Take away from ${(O==null?void 0:O.name)??P.agent}`,children:"Take away"})},P.agent)})}):n.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})}),n.jsxs(pd,{title:"The text",children:[h.data?f?n.jsx("textarea",{className:"skills-editor",value:p??w,onChange:P=>g(P.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}):n.jsx(TV,{file:jV(e),body:h.data.body,text:w}):h.error?n.jsx(ie,{message:h.error}):n.jsx(pe,{children:"Reading the file…"}),f&&k?n.jsx("p",{className:"skills-note",children:k}):null,N?n.jsxs("p",{className:"skills-note",children:["Comes with ",N,", so it’s changed there. To stop an agent using it, take it away above."," ",n.jsx("a",{href:Pe("plugins"),onClick:P=>{P.preventDefault(),u(Pe("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function fh({checked:e,disabled:t,onChange:s,lead:r,title:i,sub:a}){return n.jsxs("label",{className:"skills-pick-row","data-disabled":t?"true":void 0,children:[n.jsx("input",{type:"checkbox",checked:e,disabled:t,onChange:l=>s(l.target.checked)}),r,n.jsxs("span",{className:"skills-pick-text",children:[n.jsx("span",{className:"skills-pick-title",children:i}),a?n.jsx("span",{className:"skills-pick-sub",children:a}):null]})]})}function k$({label:e,value:t,onChange:s}){return n.jsxs("div",{className:"cat-search",children:[n.jsx(ce,{name:"search",size:16}),n.jsx(xf,{label:e,value:t,placeholder:e,onChange:s})]})}function RV({row:e,agents:t,faces:s,onCancel:r,onSaved:i}){const[a,l]=d.useState(e.every),[o,c]=d.useState(jw(e)),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=u.trim().toLowerCase(),b=t.filter(w=>!v||`${w.name} ${w.handle}`.toLowerCase().includes(v)),j=(w,y)=>c(y?[...o,w]:o.filter(k=>k!==w)),x=async()=>{m(!0),g(null);try{await _n.grant(e.id,a?{every:!0,agents:[]}:{agents:o}),i()}catch(w){g(ua(w))}finally{m(!1)}};return n.jsx(Ft,{title:`Who uses “${e.title}”?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:f,onClick:()=>void x(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(k$,{label:"Find an agent",value:u,onChange:h}),n.jsx(ie,{message:p}),n.jsxs("div",{className:"skills-pick-list",children:[v||!e.shareable?null:n.jsx(fh,{checked:a,onChange:l,lead:n.jsx($n,{icon:"agents"}),title:"Every agent",sub:"Now, and any you add later."}),b.map(w=>{const y=e.home===w.id,k=y||!w.writable;return n.jsx(fh,{checked:a||y||o.includes(w.id),disabled:a||k,onChange:N=>j(w.id,N),lead:n.jsx(bn,{id:w.id,name:w.name,size:"sm",face:s.find(N=>N.id===w.id)}),title:n.jsxs(n.Fragment,{children:[w.name," ",n.jsxs("span",{className:"skills-handle",children:["@",w.handle]})]}),sub:y?"Its own skill, in its folder":w.writable?void 0:"Ships with buddi, so its file doesn’t change"},w.id)}),b.length?null:n.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",u.trim(),"”."]})]}),n.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function IV({agent:e,view:t,onCancel:s,onSaved:r}){const i=x=>x.every||x.holders.some(w=>w.agent===e.id),[a,l]=d.useState(t.skills.filter(i).map(x=>x.id)),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=o.trim().toLowerCase(),g=x=>!p||`${x.title} ${x.description}`.toLowerCase().includes(p),v=x=>x.every||x.home===e.id||!e.writable,b=async()=>{h(!0),m(null);try{for(const x of t.skills){if(v(x))continue;const w=a.includes(x.id);if(w===i(x))continue;const y=jw(x);await _n.grant(x.id,{agents:w?[...y,e.id]:y.filter(k=>k!==e.id)})}r()}catch(x){m(ua(x))}finally{h(!1)}},j=t.skills.some(g);return n.jsx(Ft,{title:`Skills ${e.name} uses`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:u||!e.writable,onClick:()=>void b(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(k$,{label:"Find a skill",value:o,onChange:c}),n.jsx(ie,{message:f}),e.writable?null:n.jsxs("p",{className:"skills-note",children:[e.name," ships with buddi, so its file doesn’t change. Ask Agent Father to make it yours first."]}),n.jsxs("div",{className:"skills-pick-list",children:[pw.map(x=>{const w=t.skills.filter(y=>y.group===x.id&&g(y));return w.length?n.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":x.title,children:[n.jsx("div",{className:"skills-pick-group-title",children:x.title}),w.map(y=>n.jsx(fh,{checked:y.every||a.includes(y.id),disabled:v(y),onChange:k=>l(k?[...a,y.id]:a.filter(N=>N!==y.id)),title:y.title,sub:y.every?"Every agent uses it":y.home===e.id?"Its own skill, in its folder":y.description},y.id))]},x.id):null}),j?null:n.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function z0({agents:e,faces:t,upload:s,onClose:r,onSaved:i}){const[a,l]=d.useState((s==null?void 0:s.title)??""),[o,c]=d.useState((s==null?void 0:s.description)??""),[u,h]=d.useState((s==null?void 0:s.body)??""),[f,m]=d.useState([]),[p,g]=d.useState(!1),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=a.trim()!==""&&o.trim()!==""&&u.trim()!=="",y=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",k=async()=>{b(!0),x(null);try{const{skill:N}=await _n.create({title:a.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});i(N)}catch(N){x(ua(N))}finally{b(!1)}};return n.jsxs(qe,{size:"wide",title:s?n.jsx(b$,{title:s.name,sub:`${y} · read, not saved yet`}):"Write a skill",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!w||v,onClick:()=>void k(),children:"Save skill"})]}),children:[n.jsx(ie,{message:j}),n.jsxs("div",{className:"skills-sheet",children:[n.jsxs("section",{className:"skills-sec skills-form",children:[n.jsx(oe,{label:"Name",hint:"Short, like a task: “Weekly money recap”.",children:n.jsx("input",{value:a,onChange:N=>l(N.target.value),autoFocus:!s})}),n.jsx(oe,{label:"When it’s used",hint:"One line. Agents read it to decide when the skill applies.",children:n.jsx("input",{value:o,onChange:N=>c(N.target.value),placeholder:"When I ask about the week’s spending"})}),n.jsx(oe,{label:"The text",hint:"Plain Markdown: steps, rules, what a good answer looks like.",children:n.jsx("textarea",{className:"skills-editor",value:u,onChange:N=>h(N.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
|
|
111
|
+
2. The three biggest charges.
|
|
112
|
+
3. Anything odd.`})})]}),n.jsxs(pd,{title:"Who uses it",children:[n.jsx("div",{className:"skills-who",children:e.map(N=>n.jsx(fh,{checked:f.includes(N.id),disabled:!N.writable,onChange:S=>m(S?[...f,N.id]:f.filter(C=>C!==N.id)),lead:n.jsx(bn,{id:N.id,name:N.name,size:"sm",face:t.find(S=>S.id===N.id)}),title:N.name},N.id))}),n.jsx("p",{className:"skills-note",children:"You can change this later. With nobody ticked it’s kept and does nothing."})]}),s?n.jsx("section",{className:"skills-sec",children:n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:p,onChange:N=>g(N.target.checked)}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),n.jsx("span",{className:"plugins-check-hint",children:"I wrote it, or I’ve read it and trust it. Otherwise agents read it as outside text."})]})]})}):null]})]})}function PV({row:e,agents:t,onCancel:s,onDeleted:r}){const i=de(()=>_n.detail(e.id),[e.id]),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>i.data?yV(e,i.data.onDelete,t):null,[i.data,e,t]),h=async()=>{l(!0),c(null);try{const f=await _n.remove(e.id);r(`Deleted “${e.title}”.${f.movedTo?" The file is in the trash folder.":f.versionsKept?" Its earlier versions are kept.":""}`)}catch(f){c(ua(f)),l(!1)}};return n.jsxs(Ft,{title:`Delete “${e.title}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:a||!i.data,onClick:()=>void h(),children:"Delete"})]}),children:[n.jsx(ie,{message:o??i.error}),n.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function MV(e){var t;return((t=pw.find(s=>s.id===e.group))==null?void 0:t.title)??""}function DV({agentId:e,agentName:t,faces:s=[],navigate:r}){const i=de(()=>_n.list(),[e]),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),v=k=>{m(null),g(k??null),i.reload()},b=k=>{_n.trust(k.id).then(()=>v(),N=>m(N instanceof Error?N.message:String(N)))};if(!i.data)return i.error?n.jsx(pe,{warm:!0,title:"Couldn’t load the skills",action:n.jsx(E,{variant:"accent",size:"sm",onClick:i.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):n.jsx(pe,{children:"Loading…"});const j=i.data,x=j.agents.find(k=>k.id===e)??{id:e,handle:e,name:t,writable:!1},w=j.skills.filter(k=>k.every||k.holders.some(N=>N.agent===e)),y=mV();return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:f}),p?n.jsx(G,{tone:"good",role:"status",children:p}):null,n.jsx(Ge,{flush:!0,title:"Skills",actions:n.jsxs(n.Fragment,{children:[n.jsxs("a",{className:"skills-all",href:y,onClick:k=>{k.preventDefault(),r(y)},children:["All skills",n.jsx(ce,{name:"chevron-right",size:12})]}),n.jsx(E,{size:"sm",onClick:()=>h(!0),children:"Choose skills…"})]}),children:w.length?n.jsx("div",{className:"skills-group",children:n.jsx(rt,{children:w.map(k=>n.jsx(et,{onClick:()=>l({id:k.id}),label:`${k.title}: details`,lead:n.jsx($n,{icon:"files"}),title:k.title,sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"skills-line",children:k.description}),n.jsxs("span",{className:"skills-line skills-meta",children:[MV(k)," · ",k.every?"every agent uses it":xw(k,j.agents,!0)]}),k.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:vw(k,j.agents)}):null]}),side:n.jsx("span",{className:"skills-side",children:k.untrusted?n.jsx(E,{size:"sm",onClick:N=>{N.stopPropagation(),b(k)},children:"Mark as mine"}):n.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:n.jsx(ce,{name:"chevron-right",size:14})})})},k.id))})}):n.jsxs(pe,{children:[t," uses no skills yet. Choose some, or write one on the Skills page."]})}),n.jsx(y$,{view:j,faces:s,open:a,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:v,onFailed:m}),u?n.jsx(IV,{agent:x,view:j,onCancel:()=>h(!1),onSaved:()=>{h(!1),v()}}):null]})}function N$({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=de(()=>A.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await A.cancelReminder(h),a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(Pn,{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(ie,{message:i??o}),n.jsx(Ge,{flush:!0,children:r?l.length===0?n.jsx(Tn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(jr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Due"}),n.jsx("th",{children:"Agent"}),n.jsx("th",{children:"Note"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:l.map(h=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(h.dueAt,e),n.jsx("div",{className:"sub",children:Le(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx(At,{summary:"context",children:n.jsx(Pt,{children:ss(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Kc,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(E,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}const OV=/(flux|klein|schnell|qwen[-_]?image|image)/i;function S$(e){return e.kind==="image"||e.kind===void 0&&OV.test(e.id)}function LV(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!S$(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Nx(e){return LV(e)[0]}function ww(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function FV(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 C$(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 E$="an image model; pick it in the Image plugin, not here";function yw({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),p=d.useRef(0),g=async x=>{if(!e)return;const w=++p.current;c(!0),h("");try{const y=await A.accountModels(e,x);w===p.current&&l(y)}catch(y){w===p.current&&h(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(d.useEffect(()=>(l(null),m(!1),h(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const v=(a==null?void 0:a.models)??[],b=!!s&&!v.some(x=>x.id===s),j=[a&&!v.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:t,children:n.jsxs("select",{value:f?"__buddi_custom__":s,disabled:i,onChange:x=>{x.target.value==="__buddi_custom__"?m(!0):(m(!1),r(x.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),v.map(x=>n.jsxs("option",{value:x.id,children:[x.name===x.id?x.id:`${x.name} — ${x.id}`,x.isDefault?" (provider default)":"",x.image?` — ${E$}`:""]},x.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(E,{disabled:i||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),f&&n.jsx(oe,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function _V(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 zV(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const UV="This agent will not remember anything between conversations.";function BV({view:e,chosen:t,onChange:s,disabled:r}){var k;const[i,a]=d.useState(""),[l,o]=d.useState(null),[c,u]=d.useState(()=>new Set),h=N=>u(S=>{const C=new Set(S);return C.has(N)?C.delete(N):C.add(N),C}),f=N=>{a(N),u(new Set)},m=d.useId(),p=new Set(t),g=new Set(e.groups.flatMap(N=>N.tools.filter(S=>S.core).map(S=>S.name))),v=(N,S)=>{const C=S.filter(T=>p.has(T));if(C.length!==0){if(C.some(T=>g.has(T))){o({plugin:N,names:C});return}s(t.filter(T=>!C.includes(T)))}},b=N=>{s([...t,...N.filter(S=>!p.has(S))])},j=i.trim().toLowerCase(),x=(N,S)=>j===""||N.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(N=>({group:N,tools:N.tools.filter(S=>x(S.name,S.description))})).filter(N=>N.tools.length>0),y=(((k=e.suggested)==null?void 0:k.tools)??[]).filter(N=>!p.has(N.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(N=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:N.name}),n.jsx("span",{className:"ui-list-sub",children:N.description})]}),n.jsx(E,{size:"sm",disabled:r,"aria-label":`Add ${N.name}`,onClick:()=>b([N.name]),children:"Add"})]},N.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:N=>f(N.target.value)})]}),w.length===0?n.jsxs(pe,{children:["No installed tool matches “",i.trim(),"”."]}):null,w.map(({group:N,tools:S})=>{const C=N.tools.filter($=>$.grantable).map($=>$.name),T=N.tools.filter($=>p.has($.name)).length,R=!!N.glob&&T===N.tools.length,I=`${m}-${N.plugin}`,L=`${m}-${N.plugin}-list`,W=j!==""?!c.has(N.plugin):c.has(N.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":W?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":W,"aria-controls":L,onClick:()=>h(N.plugin),children:[n.jsx(WV,{}),n.jsx("span",{id:I,className:"tool-picker-plugin",children:N.plugin}),n.jsx("span",{className:"muted",children:R?`all ${N.tools.length}`:`${T} of ${N.tools.length} granted`})]}),n.jsx(E,{size:"sm",variant:"ghost","aria-label":`All ${N.plugin} tools`,disabled:r||C.every($=>p.has($)),onClick:()=>b(C),children:"all"}),n.jsx(E,{size:"sm",variant:"ghost","aria-label":`No ${N.plugin} tools`,disabled:r||!C.some($=>p.has($)),onClick:()=>v(N.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===N.plugin?n.jsx(G,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:UV}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(E,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(E,{size:"sm",variant:"danger",onClick:()=>{s(t.filter($=>!l.names.includes($))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:L,className:"ui-list tool-picker-list",hidden:!W,children:S.map($=>{const P=`${m}-${$.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:P,checked:p.has($.name),disabled:r||!$.grantable,onChange:O=>O.target.checked?b([$.name]):v(N.plugin,[$.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:$.name}),$.core?n.jsx(we,{tone:"accent",children:"core"}):null,$.gated?n.jsx(we,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:$.grantable?$.description:`${$.description} Granted only by editing the file by hand.`})]})]},$.name)})})]},N.plugin)})]})}function WV(){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 ms={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."},ii=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function A$(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(ms.json)}if(!ii(t))throw new Error(ms.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!ii(u))throw new Error(ms.empty);const h=Object.keys(u);if(h.length===0)throw new Error(ms.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const f=u[s];if(!ii(f))throw new Error(ms.url);r=f}if("command"in r)throw new Error(ms.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(ms.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(ms.url);const a=ii(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,h]=l,f=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?h.trim().slice(f[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Lo={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 $$=/^[A-Za-z_][A-Za-z0-9_]*$/;function HV(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function R$(e,t){const s=HV(t);return{name:e,value:s?"":t,secret:T$(e),placeholder:s}}function I$(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!==`
|
|
113
|
+
`&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
|
|
114
|
+
`||o==="\r"&&e[a+1]===`
|
|
115
|
+
`){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(Lo.quote);return r&&t.push(s),t}function KV(e){const t=I$(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=h=>{const f=h.indexOf("="),m=f>0?h.slice(0,f).trim():"";if(!$$.test(m))throw new Error(Lo.env);r.push(R$(m,h.slice(f+1)))},u=[];for(;s<t.length;s+=1){const h=t[s];if(h==="--"){o=t.slice(s+1);break}const[f,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(Lo.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(ms.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:A$(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(Lo.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function VV(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return KV(t);let s;try{s=JSON.parse(t)}catch{throw new Error(ms.json)}if(!ii(s))throw new Error(ms.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!ii(c))throw new Error(ms.empty);const u=Object.keys(c);u.length===1&&ii(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:A$(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(Lo.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=ii(i.env)?Object.entries(i.env).filter(([c])=>$$.test(c)).map(([c,u])=>R$(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function bw({code:e,label:t="Your code",large:s=!1}){const[r,i]=d.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{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(E,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function P$(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 GV="It can delete or destroy something, so it asks you every time and is never remembered.";function YV(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 M$="buddi-connections",qV="/connections/callback",JV="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.",D$="Services and programs your team can use, and the tools each one brings.",kw=(e,t,s)=>`${e} ${e===1?t:s}`;function U0(e,t){return e.transport==="stdio"?void 0:t.find(s=>Sw(s.url,e.url))}function Nw({connection:e,card:t,size:s}){return t?n.jsx($n,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx($n,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function O$({connection:e}){const t=P$(e);return n.jsx(we,{tone:t.tone,dot:t.dot,children:t.label})}const ep=e=>t=>{t.stopPropagation(),e()},gd=[{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"}],L$="buddi.connections.add-way";function QV(){try{const e=window.localStorage.getItem(L$);return gd.some(t=>t.value===e)?e:"address"}catch{return"address"}}function XV({embedded:e,timezone:t,connection:s}={}){const r=de(()=>A.connections(),[],3e4),[i,a]=d.useState(null),[l,o]=d.useState(s??null);d.useEffect(()=>{s&&o(s)},[s]);const[c,u]=d.useState(null),[h,f]=d.useState(null),m=r.data,p=N=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===N))==null?void 0:S.name)??N},g=t??Intl.DateTimeFormat().resolvedOptions().timeZone,v=(m==null?void 0:m.connections)??[],b=(m==null?void 0:m.catalog)??[],j=b.filter(N=>!v.some(S=>S.transport!=="stdio"&&Sw(N.url,S.url))),x=l?v.find(N=>N.id===l):void 0,w=c?v.find(N=>N.id===c):void 0,y=h?v.find(N=>N.id===h):void 0,k=N=>{o(null),a(N)};return n.jsxs(Pn,{embedded:e,title:"Connections",lede:D$,children:[n.jsxs(le,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ce,{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:Pe("plugins"),children:"Plugins"})]})]}),!m&&!r.error?n.jsx(pe,{children:"Reading your connections…"}):null,n.jsx(ie,{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(Ge,{flush:!0,title:"Your connections",tool:v.length>0?kw(v.length,"connection","connections"):void 0,children:v.length===0?n.jsx(pe,{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(rt,{children:v.map(N=>n.jsx(ZV,{connection:N,card:U0(N,b),twin:N.slug!==null&&v.some(S=>S.id!==N.id&&S.name===N.name),onOpen:()=>o(N.id),onFlow:k},N.id))})})}):null,m&&j.length>0?n.jsx(Ge,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:j.map(N=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(Nw,{card:N}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:N.name}),n.jsx("span",{className:"connections-tile-blurb",children:N.blurb})]}),n.jsx(E,{size:"sm",onClick:()=>k({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,m?n.jsx(r9,{onFlow:N=>k({step:N})}):null]}),x?n.jsx(t9,{connection:x,card:U0(x,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:k,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,y&&m?n.jsx(n9,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?n.jsx(s9,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,i&&m?n.jsx(i9,{start:i,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{a(null),r.reload()}}):null]})}function ZV({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":kw(e.toolCount,"tool","tools");return n.jsx(et,{onClick:r,label:`${l}: details`,lead:n.jsx(Nw,{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(E,{size:"sm",variant:"accent",onClick:ep(()=>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(E,{size:"sm",onClick:ep(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(E,{size:"sm",onClick:ep(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(O$,{connection:e}),n.jsx(ce,{name:"chevron-right",size:14})]})})}const e9={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 t9({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>a({step:"consent",connection:e,keepGrants:!0}),f=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(qe,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Nw,{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(O$,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(dt,{}),u?n.jsx(E,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(E,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(E,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(E,{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(E,{size:"sm",variant:"accent",onClick:h,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?n.jsxs(G,{tone:"warning",action:n.jsx(E,{size:"sm",variant:"accent",onClick:f,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?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(Ht,{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:e9[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${kw(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Le(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(E,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?n.jsx(ue,{title:"What the program last said",children:n.jsx(Pt,{label:"Its last lines on stderr",children:e.stderr.join(`
|
|
116
|
+
`)})}):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(E,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function n9({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=d.useState(()=>new Set(e.agents)),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=(p,g)=>a(v=>{const b=new Set(v);return g?b.add(p):b.delete(p),b}),f=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await A.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Bs(p))}finally{o(!1)}};return n.jsxs(Ft,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:g=>h(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(ie,{message:c})]})}function s9({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await A.disconnect(e.id),r()}catch(h){o(Bs(h))}finally{a(!1)}};return n.jsxs(Ft,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(E,{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(ie,{message:l})]})}function r9({onFlow:e}){const[t,s]=d.useState(QV),r=gd.find(a=>a.value===t)??gd[0],i=a=>{s(a);try{window.localStorage.setItem(L$,a)}catch{}};return n.jsx(Ge,{title:"Add your own",actions:n.jsx(Kt,{label:"How to add it",options:gd.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(E,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function i9({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=d.useState(e.step),[c,u]=d.useState(e.connection),[h,f]=d.useState("unknown"),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(y=>b!==void 0&&Sw(y.url,b)),x=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${x}`:l==="review"?`What ${x} brings`:"Who gets these tools";return n.jsxs(qe,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(a9,{onRead:y=>{y.kind==="program"?(v(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(l9,{card:j,pasted:m,onDone:(y,k)=>{u(y),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?n.jsx(p9,{connection:c,pasted:g,tokens:r,onDone:y=>{var k;v(null),u(y),e.keepGrants&&!((k=y.program)!=null&&k.changedSinceReview)&&y.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(u9,{connection:c,signIn:h,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:y=>{p(null),u(y),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(g9,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(x9,{connection:c,agents:t,onDone:i}):null]})}function Sw(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Bs(e){return e instanceof Error?e.message:String(e)}function a9({onRead:e}){const[t,s]=d.useState(""),[r,i]=d.useState(null),a=()=>{try{const l=VV(t);s(""),i(null),e(l)}catch(l){i(Bs(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(oe,{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(ie,{message:r}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function l9({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=d.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{l(!0),c(null);try{const g=await A.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Bs(g))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",f=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return n.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?n.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):n.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),n.jsx(oe,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>i(g.target.value)})}),e&&!e.verified?n.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?n.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(ie,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const o9={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function c9(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 u9({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var H,U;const[c,u]=d.useState(t),h=(H=s==null?void 0:s.auth)!=null&&H.device?s.auth.recommended==="device"?"first":"offered":"none",f=c9(c,a,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((U=s==null?void 0:s.auth)==null?void 0:U.recommended)==="token"),[p,g]=d.useState(()=>m&&f.includes("token")?"token":f[0]),v=f.includes(p)?p:f[0],[b,j]=d.useState(JV),[x,w]=d.useState(""),[y,k]=d.useState(null),[N,S]=d.useState(!1),[C,T]=d.useState(null),[R,I]=d.useState(!1),[L,W]=d.useState(null),$=`${location.origin}${qV}`,P=d.useRef(o);P.current=o,d.useEffect(()=>{if(!R)return;let q=!1;const B=async()=>{if(!q){q=!0;try{P.current(await A.connection(e.id))}catch(ee){T(Bs(ee))}}},Y=typeof BroadcastChannel=="function"?new BroadcastChannel(M$):null;Y&&(Y.onmessage=ee=>{var fe;((fe=ee.data)==null?void 0:fe.id)===e.id&&B()});let F;const X=Date.now(),Q=async()=>{if(!q){try{const ee=await A.connection(e.id);if((!e.signedIn||e.authKind==="token")&&ee.signedIn&&ee.authKind==="oauth"){B();return}}catch{}if(Date.now()-X>10*6e4){I(!1),T("The sign-in did not come back within ten minutes. Start it again.");return}F=window.setTimeout(()=>void Q(),l)}};return F=window.setTimeout(()=>void Q(),l),()=>{q=!0,Y==null||Y.close(),window.clearTimeout(F)}},[R,e,l]);const O=async q=>{var B;S(!0),T(null);try{const{authorizeUrl:Y}=await A.connectionConsent(e.id,q);k(Y)}catch(Y){Y instanceof ve&&((B=Y.detail)==null?void 0:B.code)==="client-id"?(j(Y.message),u("manual"),g("client")):T(Bs(Y))}finally{S(!1)}};d.useEffect(()=>{v!=="oauth"||y!==null||O()},[v]);const M=q=>{const B=window.open(q,"_blank");B?(B.opener=null,W(null)):W(q),I(!0)},D=q=>{g(q),k(null),T(null),I(!1),W(null)};return n.jsxs("div",{className:"ui-stack",children:[f.length>1?n.jsx(Kt,{label:"How to sign in",options:f.map(q=>({value:q,label:o9[q]})),value:v,onChange:D}):null,v==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),N?n.jsxs(pe,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,v==="client"?n.jsxs(n.Fragment,{children:[n.jsx(G,{tone:"warning",children:b}),n.jsx(oe,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:x,onChange:q=>{w(q.target.value),k(null),I(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:$})]})]}):null,v==="token"?n.jsx(f9,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,v==="device"?n.jsx(h9,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(v==="oauth"||v==="client")&&R?n.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(v==="oauth"||v==="client")&&L?n.jsx("p",{children:n.jsxs("a",{href:L,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,v==="oauth"||v==="client"?n.jsx(ie,{message:C}):null,v==="oauth"?n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>{y&&M(y)},disabled:y===null,children:R?"Open it again":`Sign in to ${e.name}`})}):null,v==="client"?n.jsx(ae,{align:"end",children:y===null?n.jsx(E,{variant:"accent",onClick:()=>void O(x.trim()),disabled:N||x.trim()==="",children:N?"Checking…":"Continue"}):n.jsx(E,{variant:"accent",onClick:()=>M(y),children:R?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function d9(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function h9({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(0),[h,f]=d.useState(null),m=d.useRef(r);m.current=r,d.useEffect(()=>{let v=!1,b;a(null),o(null),f(null);const j=async()=>{var x,w;if(!v){try{const y=await A.connection(e.id);if(v)return;if(((x=y.device)==null?void 0:x.state)==="done"){m.current(y);return}if(((w=y.device)==null?void 0:w.state)==="failed"){o(y.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void j(),s)}};return(async()=>{try{const x=await A.connectionDevice(e.id);if(v)return;a({userCode:x.userCode,verificationUri:x.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(x){v||o(Bs(x))}})(),()=>{v=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=v=>{const b=window.open(v,"_blank");b?(b.opener=null,f(null)):f(v)},g=i?d9(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(pe,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(bw,{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,"…"]}),h?n.jsx("p",{children:n.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(ae,{align:"end",children:n.jsxs(E,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:l}),n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function f9({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var j,x;const[a,l]=d.useState((s==null?void 0:s.value)??""),[o,c]=d.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=d.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=async()=>{m(!0),g(null);try{const w=await A.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){g(Bs(w))}finally{m(!1)}},b=(j=t==null?void 0:t.auth)==null?void 0:j.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),v()},children:[n.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(G,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(oe,{label:"Token",hint:(x=t==null?void 0:t.auth)==null?void 0:x.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:w=>l(w.target.value)})}),n.jsxs(Us,{columns:2,dense:!0,children:[n.jsx(oe,{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(oe,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:w=>h(w.target.value)})})]}),n.jsx(ie,{message:p}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:f||a.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function m9(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function p9({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=d.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=d.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,h]=d.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[f,m]=d.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map($=>({key:l(),value:$}))),[p,g]=d.useState(()=>i?i.env.map($=>({key:l(),name:$.name,value:$.value??"",secret:$.secret,kept:$.secret})):((t==null?void 0:t.env)??[]).map($=>({key:l(),name:$.name,value:$.value,secret:$.secret,kept:!1}))),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=/\s/.test(u.trim())?I$(u.trim()):[u.trim()],y=w[0]??"",k=[...w.slice(1),...f.map($=>$.value)],N=[y,...k].filter(($,P)=>P>0||$!==""),S=()=>{w.length<2||(h(y),m($=>[...w.slice(1).map(P=>({key:l(),value:P})),...$]))},C=N.map(m9).join(" "),T=p.filter($=>$.secret&&$.value===""&&!$.kept).map($=>$.name||"a variable"),R=((t==null?void 0:t.env)??[]).filter($=>$.placeholder).map($=>$.name),I=($,P)=>m(O=>O.map(M=>M.key===$?{...M,value:P}:M)),L=($,P)=>g(O=>O.map(M=>M.key===$?{...M,...P}:M)),W=async()=>{b(!0),x(null);const $={name:o.trim(),command:y,args:k,env:p.filter(P=>P.name.trim()!=="").map(P=>({name:P.name.trim(),value:P.value,secret:P.secret}))};try{r(e?await A.updateProgram(e.id,$):(await A.addProgram($)).connection),g(P=>P.map(O=>O.secret?{...O,value:""}:O))}catch(P){x(Bs(P))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:$=>{$.preventDefault(),W()},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(Us,{columns:2,children:[n.jsx(oe,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:$=>c($.target.value)})}),n.jsx(oe,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:n.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:$=>h($.target.value),onBlur:S})})]}),n.jsx(oe,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map(($,P)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${P+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:$.value,onChange:O=>I($.key,O.target.value)}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove argument ${P+1}`,children:"Remove"})]},$.key)),n.jsx(ae,{children:n.jsx(E,{size:"sm",onClick:()=>m($=>[...$,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(oe,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map(($,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:$.name,onChange:O=>{const M=O.target.value;L($.key,$.value===""&&!$.kept?{name:M,secret:T$(M)}:{name:M})}}),n.jsx("input",{"aria-label":`Variable ${P+1} value`,type:$.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:$.kept&&$.value===""?"Kept. Type to replace it.":"value",value:$.value,onChange:O=>L($.key,{value:O.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:$.secret,onChange:O=>L($.key,{secret:O.target.checked,kept:O.target.checked&&$.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>g(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove variable ${P+1}`,children:"Remove"})]},$.key)),n.jsx(ae,{children:n.jsx(E,{size:"sm",onClick:()=>g($=>[...$,{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($=>$.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(Pt,{label:"The command line",children:C||"…"})]}),n.jsx(ie,{message:j}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:v||o.trim()===""||u.trim()===""||T.length>0,title:T.length>0?`Give ${T.join(", ")} a value.`:void 0,children:v?"Saving…":e?"Save":"Continue"})})]})}function g9({connection:e,onKept:t}){const s=de(()=>A.connectionReview(e.id),[e.id]),[r,i]=d.useState(null),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{t(await A.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(g){g instanceof ve&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Bs(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(ie,{message:s.error}):e.transport==="stdio"?n.jsxs(pe,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(pe,{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(le,{gap:"sm",children:[n.jsx(Pt,{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(oe,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(pe,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=YV(p),v=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return n.jsx("div",{className:"ui-list-row connections-tool",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("span",{className:"mono",children:v}),p.problem?n.jsx(we,{tone:"muted",children:"Cannot be used"}):n.jsx(we,{tone:g.tone,children:g.label}),p.change==="added"?n.jsx(Vg,{children:"New"}):p.change==="changed"?n.jsx(Vg,{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?GV:"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(ie,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>void f(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function x9({connection:e,agents:t,onDone:s}){var b;const r=t.find(j=>j.frontDesk)??t[0],[i,a]=d.useState(()=>new Set(r?[r.id]:[])),o=(((b=de(()=>A.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=(j,x)=>{a(w=>{const y=new Set(w);return x?y.add(j):y.delete(j),y})},v=async()=>{f(!0),p(null);try{const j=await A.grantConnection(e.id,[...i]);if(j.failed.length>0){p(j.failed.map(x=>`${x.agent}: ${x.message}`).join(" "));return}for(const x of j.granted)for(const w of c)await A.setRememberedApproval(x,w,!0);s()}catch(j){p(Bs(j))}finally{f(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(j=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(j.id),onChange:x=>g(j.id,x.target.checked)}),n.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),n.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?n.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[n.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(j=>n.jsxs(le,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:x=>u(w=>{const y=new Set(w);return x.target.checked?y.add(j.tool):y.delete(j.tool),y})}),n.jsx("span",{className:"mono",children:j.tool})]}),j.why?n.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,n.jsx(ie,{message:m}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:s,disabled:h,children:"Not now"}),n.jsx(E,{variant:"accent",onClick:()=>void v(),disabled:h||i.size===0,children:"Give them"})]})]})}const v9=(e,t,s)=>`${e} ${e===1?t:s}`;function j9(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 w9({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=d.useState({}),o=de(()=>A.connections().then(w=>(l({}),w)),[r]),[c,u]=d.useState(null),[h,f]=d.useState(null),m=Pe("connections"),p=async(w,y)=>{u(w.id),f(null);try{const k=await A.setConnectionHolder(w.id,e,y);l(N=>({...N,[w.id]:k.held})),i==null||i()}catch(k){f(k instanceof Error?k.message:String(k))}finally{u(null)}},g=o.data,v=(g==null?void 0:g.connections)??[],b=w=>a[w.id]??w.agents.includes(e),j=g?g.agents.some(w=>w.id===e):!0,x=v.filter(b).length;return n.jsxs(ue,{title:"Connections",aside:g&&v.length>0?`holds ${x} of ${v.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(ie,{message:o.error??h}),g?v.length===0?n.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",n.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?n.jsxs(n.Fragment,{children:[s?n.jsx(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:v.map(w=>{const y=b(w),k=j9(w),N=w.transport==="stdio"?"on this computer":w.host,S=w.slug?v9(w.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${w.id}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",role:"switch",id:C,checked:y,"aria-checked":y,disabled:s||c!==null||k!==null&&!y,onChange:T=>void p(w,T.target.checked)}),n.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[w.name,k?n.jsxs(n.Fragment,{children:[" ",n.jsx(we,{tone:"warning",children:P$(w).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${N} · ${S}`}),k?n.jsxs("span",{className:"ui-list-sub",children:[k," ",n.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},w.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[t," makes and changes agents, so it holds no connections."]}):o.error?null:n.jsx(pe,{children:"Loading the connections…"})]})}const y9=(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 F$(e){const t=await fetch(va(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 b9({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,Ez.map(o=>{const c={kind:"mascot",role:o},u=y9(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:va(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:Tz.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 k9=["mirror","en","fr"],N9=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],tp=10,np=500,_$=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],B0=e=>{var t;return e==="access"?"tools":((t=_$.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function S9({agentId:e,section:t,navigate:s}){var v,b,j;const{data:r,error:i,reload:a}=de(()=>A.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(B0(t));d.useEffect(()=>f(B0(t)),[t]);const m=x=>{f(x),s==null||s(St(e,"setup",x))},p=async x=>{o(null),u(null);try{const w=await x;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),a()}catch(w){o(w instanceof Error?w.message:String(w))}},g=r==null?void 0:r.agents.find(x=>x.id===e);return n.jsxs(le,{gap:"lg",children:[n.jsx(Vc,{level:"secondary",label:"Setup",children:_$.map(x=>n.jsx(yl,{href:St(e,"setup",x.id),active:h===x.id,onClick:w=>{w.preventDefault(),m(x.id)},children:x.label},x.id))}),n.jsx(ie,{message:i??l}),c?n.jsx(G,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(C9,{agent:g,all:r.agents,engine:r.engines.find(x=>x.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:a},`${g.id}:${(v=r.engines.find(x=>x.id===g.id))==null?void 0:v.model}:${(j=(b=r.providerAccounts)==null?void 0:b.bindings.find(x=>x.agentId===g.id))==null?void 0:j.accountId}`):n.jsx(pe,{children:"This agent is not installed as a file."}):n.jsx(pe,{children:"Loading…"})]})}function C9({agent:e,all:t,engine:s,providers:r,accounts:i,shown:a,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(N=>N.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,v]=d.useState(null),b=N=>{o(A.setAgentEngine(e.id,N))},j=N=>{const S=r.find(C=>C.kind===N);b({provider:N,model:(S==null?void 0:S.defaultModel)??f})},x=(h==null?void 0:h.models.map(N=>N.id))??[],w=x.includes(f)?x:[f,...x],y=s?s.available:!0,k=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(le,{gap:"lg",children:[y?null:n.jsxs(G,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:St(e.id,"setup","brain"),onClick:N=>{N.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(E9,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(le,{gap:"lg",children:[y?null:n.jsxs(G,{tone:"warning",children:["This agent cannot run right now: ",k,"."]}),n.jsx(ue,{panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{title:"Runs on",children:[i?n.jsx(M9,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(Us,{children:[n.jsx(oe,{label:"Provider",children:n.jsx("select",{value:u,onChange:N=>j(N.target.value),children:r.map(N=>n.jsxs("option",{value:N.kind,children:[N.kind,N.usable?"":" (no credential)"]},N.kind))})}),n.jsxs(oe,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:N=>{N.target.value.trim()!==""&&N.target.value.trim()!==f&&b({model:N.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:w.map(N=>n.jsx("option",{value:N},N))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(ue,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(Us,{children:[n.jsx(oe,{label:"Steps per reply",hint:`${s!=null&&s.maxTurnsIsDefault?`Default ${s.defaultMaxTurns??40}. `:""}Each tool call is a step; a reply that uses them all stops and offers Continue.`,after:g?n.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:n.jsx("input",{type:"number",min:tp,max:np,value:m,onChange:N=>{p(N.target.value),v(null)},onBlur:()=>{const N=Number(m);if(!Number.isInteger(N)||N<tp||N>np){v(`Between ${tp} and ${np}.`);return}N!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:N})}})}),n.jsx(oe,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:N=>b({language:N.target.value}),children:k9.map(N=>n.jsx("option",{value:N,children:N},N))})}),s?n.jsx(oe,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:n.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:N=>b({idleRollover:N.target.value==="3h"?null:N.target.value}),children:N9.map(N=>n.jsx("option",{value:N.value,children:N.label},N.value))})}):null,H1(K1(s??{id:e.id,provider:u},i))?n.jsx(oe,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:N=>b({thinking:N.target.value==="default"?null:N.target.value}),children:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(oe,{label:"Thinking",hint:fL,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(At,{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(le,{gap:"lg",children:[n.jsx(A9,{agent:e,all:t,onSaved:c}),n.jsx(w9,{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(le,{gap:"lg",children:n.jsx(F9,{agent:e,all:t,onSaved:c})})})]})}function z$({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(E,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const U$=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 E9({agent:e,onSaved:t}){var W;const[s,r]=d.useState(e.name),[i,a]=d.useState(e.handle),[l,o]=d.useState(e.description),[c,u]=d.useState(e.avatar??""),[h,f]=d.useState(!1),m=de(()=>A.agentFile(e.id),[e.id]),[p,g]=d.useState(null),v=((W=m.data)==null?void 0:W.persona.trim())??"",b=p??v,j=m.data!==void 0&&p!==null&&p.trim()!==v,[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,T=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),R=Sx(T?{...e,avatar:c.trim()}:e),I={...R?{avatar:R}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!T&&e.picture?{picture:e.picture}:{}},L=async()=>{w(!0),k(null),S(null);try{const $=await A.updateAgentFile(e.id,{name:s.trim(),handle:i.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...j&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await A.removeAgentPicture(e.id),window.dispatchEvent(new Event(dr))),g(null),m.reload(),S($.message),t()}catch($){k($ instanceof Error?$.message:String($))}finally{w(!1)}};return n.jsx(ue,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(z$,{dirty:C,busy:x,failure:y,label:"Save who it is",onSave:()=>void L()}),children:n.jsxs(le,{children:[e.isExample?U$:null,N?n.jsx(G,{tone:"good",role:"status",children:N}):null,n.jsxs(Us,{children:[n.jsx(oe,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:x||e.isExample,onChange:$=>r($.target.value)})}),n.jsx(oe,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:x||e.isExample,onChange:$=>a($.target.value)})})]}),n.jsxs(ae,{children:[n.jsx(bn,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),n.jsx(E,{"aria-expanded":h,onClick:()=>f($=>!$),children:h?"Hide faces":"Change face"})]}),h?n.jsx(I9,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:x}):null,n.jsx(oe,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:x||e.isExample,onChange:$=>o($.target.value)})}),n.jsx(oe,{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(ie,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
|
|
117
|
+
`).length+1),disabled:x||e.isExample,onChange:$=>g($.target.value)}):n.jsx(pe,{children:"Reading its file…"})})]})})}function A9({agent:e,all:t,onSaved:s}){var T;const r=de(()=>A.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(fk))),[c,u]=d.useState((e.roles??[]).filter(R=>!fk(R)).join(", ")),[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(R,I)=>R.split(I).map(L=>L.trim()).filter(L=>L!==""),j=((T=r.data)==null?void 0:T.granted)??e.tools,x=i??j,w=r.data!==void 0&&!zV(x,j),y=mk(l,b(c,/[\n,]/)),k=R=>o(I=>{const L=new Set(I);return L.has(R)?L.delete(R):L.add(R),L}),S=w||!((R,I)=>R.join(",")===I.join(","))(y,mk(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),v(null);try{const R=await A.updateAgentFile(e.id,{...w&&r.data?{tools:_V(r.data.groups,x)}:{},roles:y});v(R.message),a(null),r.reload(),s()}catch(R){p(R instanceof Error?R.message:String(R))}finally{f(!1)}};return n.jsx(ue,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(z$,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(le,{children:[e.isExample?U$: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:bj.map(R=>{const I=C4(t,R.id),L=I&&I.id!==e.id?I:void 0;return n.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(R.id),"data-on":l.has(R.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>k(R.id),children:[n.jsx("span",{className:"role-chip-label",children:R.label}),n.jsx("span",{className:"role-chip-meaning",children:R.meaning}),L?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",L.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(oe,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:h||e.isExample,onChange:R=>u(R.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?n.jsx(ie,{message:r.error}):r.data?n.jsx(BV,{view:r.data,chosen:x,onChange:a,disabled:h||e.isExample}):n.jsx(pe,{children:"Loading the installed tools…"})]}),n.jsx(T9,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),$9(j)?n.jsx(R9,{agentId:e.id}):null]})})}function T9({agentId:e,version:t,disabled:s}){var g;const r=de(()=>Promise.resolve().then(()=>A.rememberedApprovals(e)),[e,t]),i=de(()=>Promise.resolve().then(()=>A.connections()).catch(()=>null),[]),[a,l]=d.useState(null),[o,c]=d.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const h=async(v,b)=>{l(v),c(null);try{await A.setRememberedApproval(e,v,b),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const v of u)f.set(v.connection,[...f.get(v.connection)??[],v]);const m=v=>{var b,j;return((j=(b=i.data)==null?void 0:b.connections.find(x=>x.slug===v))==null?void 0:j.name)??v},p=v=>v.tool.split(".").slice(2).join(".")||v.tool;return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...f].map(([v,b])=>{const j=b.filter(k=>k.rememberable),x=b.filter(k=>!k.rememberable),w=j.filter(k=>k.remembered),y=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(v)}),n.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return n.jsxs(At,{summary:y,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(v)}: remember my approval`,children:j.map(k=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:k.remembered,disabled:s||a!==null,onChange:N=>void h(k.tool,N.target.checked),"aria-label":`Remember my approval for ${k.tool}`}),n.jsx("span",{className:"mono",children:p(k)})]},k.tool))}),x.length>0?n.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",n.jsx("span",{className:"mono",children:x.map(p).join(", ")})]}):null]},v)})}),n.jsx(ie,{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 $9(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function R9({agentId:e}){var h,f;const t=de(()=>A.notificationSettings(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=s??((f=(h=t.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),A.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>a(!1))};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Messages to you"}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:c,disabled:i||!t.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),n.jsx("span",{children:"Mute its messages"})]}),n.jsx(ie,{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 Sx(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 I9({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(f?{kind:"emoji",value:t.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(h(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await A.uploadAgentPicture(e.id,await F$(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(dr))}catch(v){h(v instanceof Error?v.message:String(v))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(b9,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(P9,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function P9({agent:e,onChanged:t}){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(0);d.useEffect(()=>{if(!s)return a(null);const S=URL.createObjectURL(s);return a(S),()=>URL.revokeObjectURL(S)},[s]);const g=S=>{r(null),p(C=>C+1),f(S),t(),window.dispatchEvent(new Event(dr))},v=async S=>{o(!0),u(null),f(null);try{g(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>v(async()=>(await A.uploadAgentPicture(e.id,s)).note??null),j=()=>v(async()=>(await A.removeAgentPicture(e.id),null)),x={avatar:Sx(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[w,y]=d.useState(!1),k=d.useRef(null),N=S=>{u(null),f(null),r(S??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||y(!0)},onDragLeave:()=>y(!1),onDrop:S=>{var C;S.preventDefault(),y(!1),l||N((C=S.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(ae,{children:[n.jsx(bn,{id:e.id,name:e.name,size:"xl",face:x}),n.jsx("input",{ref:k,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return N((C=S.target.files)==null?void 0:C[0])}},m),n.jsx(E,{disabled:l,onClick:()=>{var S;return(S=k.current)==null?void 0:S.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(E,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,n.jsx(E,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?n.jsx("span",{className:"critical save-error",role:"alert",children:c}):n.jsx("span",{className:"ui-field-hint",children:h??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function M9({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=d.useState((r==null?void 0:r.accountId)??""),[l,o]=d.useState((r==null?void 0:r.model)??""),[c,u]=d.useState(!1),h=t.accounts.find(p=>p.id===i),f=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(v=>v.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[n.jsx("option",{value:"",children:"Choose an account"}),t.accounts.map(p=>n.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),n.jsx(yw,{accountId:h!=null&&h.configured?i:void 0,label:"Model",value:l,onChange:o,disabled:c},`${i}:${h==null?void 0:h.revision}`)]}),n.jsxs(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(E,{variant:"accent",disabled:c||!i||!l.trim()||!f,onClick:()=>{u(!0),s(A.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const D9=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],sp=e=>e.tools.some(t=>D9.includes(t)),O9=["front-desk","maker"],L9={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function F9({agent:e,all:t,onSaved:s}){const[r,i]=d.useState(e.delegates),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(e.delegates),[p,g]=d.useState(e.asksEveryone),[v,b]=d.useState(!1),j=t.filter(R=>R.id!==e.id),x=O9.find(R=>{var I;return(I=e.roles)==null?void 0:I.includes(R)}),w=p===void 0||v,y=v||[...r].sort().join(",")!==[...f].sort().join(","),k=t.filter(R=>R.id!==e.id&&(R.delegates.includes(e.id)||R.asksEveryone!==void 0&&!sp(e))),N=R=>i(I=>I.includes(R)?I.filter(L=>L!==R):[...I,R]),S=async R=>{l(!0),c(null),h(!1);try{const I=await A.setDelegates(e.id,R);m(I.delegates),i(I.delegates),g(I.asksEveryone),b(!1),h(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{i(j.filter(R=>!sp(R)).map(R=>R.id)),b(!0),h(!1)},T=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(ue,{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:T}),n.jsx("span",{className:"ui-toolbar-spacer"}),w&&x!==void 0?n.jsx(E,{disabled:a,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?n.jsx(E,{variant:"accent",disabled:!y||a,onClick:()=>void S(r),children:"Save who it can ask"}):n.jsx(E,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{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(ie,{message:o}),w?j.length===0?n.jsx(pe,{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=sp(R);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${R.id}`,checked:r.includes(R.id),disabled:I||e.isExample||a,onChange:()=>N(R.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${R.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[R.name," ",n.jsxs("span",{className:"mono muted",children:["@",R.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":R.description})]})]},R.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[L9[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(ue,{title:"Asked by",children:k.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(yU,{children:k.map(R=>n.jsx(we,{children:R.name},R.id))})})]})})}const _9=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],z9=[{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 U9(e){const t=a4(e.hash);return t?n.jsx(sV,{name:t.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):n.jsx(B9,{...e})}function B9({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var j,x,w,y,k;const l=s4(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=N=>S=>{S.preventDefault(),s(N)},u=de(()=>A.agents(),[]),h=jf(),f=de(()=>A.offers(),[],2e4),m=lT(),p=(((x=f.data)==null?void 0:x.offers.length)??0)+m.offers.length,g=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??a??null,[v,b]=d.useState(null);return n.jsxs("div",{className:"ui-page",children:[n.jsx(wl,{title:"Agents",lede:o==="skills"?`Skills are short texts an agent follows for one kind of task. Each is a file on ${h}.`:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:o==="skills"?n.jsxs(n.Fragment,{children:[n.jsx(E,{onClick:()=>b({kind:"upload",at:Date.now()}),children:"Upload a .md"}),n.jsx(E,{variant:"accent",onClick:()=>b({kind:"write",at:Date.now()}),children:"Write a skill"})]}):n.jsx(Et,{variant:"accent",href:Bt(),onClick:c(Bt()),children:"Add a teammate"})}),n.jsx(Vc,{children:_9.map(N=>n.jsx(yl,{href:N.id==="team"?mt:`${mt}?tab=${N.id}`,active:o===N.id,count:N.id==="offers"?p:void 0,onClick:c(N.id==="team"?mt:`${mt}?tab=${N.id}`),children:N.label},N.id))}),o==="missions"?n.jsx(a$,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(oT,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(o$,{embedded:!0}):null,o==="reminders"?n.jsx(N$,{timezone:t,embedded:!0}):null,o==="skills"?n.jsx(SV,{faces:r,navigate:s,command:v,openSkill:pV(e)}):null,o==="team"?n.jsx(W9,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(Tn,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):n.jsx("div",{className:"agents-grid",children:ZE(r,g).map(N=>{const S=cf(i.get(N.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Bc(Uc(N)),"data-unavailable":N.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(bn,{id:N.id,name:N.name,size:"xl",unavailable:!N.available,face:N})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:St(N.id,"conversations"),onClick:c(St(N.id,"conversations")),children:N.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",N.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:N.description})]}),n.jsxs("div",{className:"ui-row",children:[N.id===g?n.jsx(Vg,{children:"front desk"}):null,S?n.jsx(we,{tone:"critical",dot:!0,children:"waiting for you"}):N.available?n.jsx(we,{tone:"good",dot:!0,children:"ready"}):n.jsx(we,{tone:"warning",children:zs(N.unavailableReason??"cannot run",60)}),n.jsx(we,{mono:!0,children:N.model}),n.jsx(Et,{className:"agent-card-talk",size:"sm",href:st(N.id),onClick:c(st(N.id)),"aria-label":`Talk to ${N.name}`,children:"Talk"})]})]},N.id)})}):null,l?n.jsx(qe,{title:((k=r.find(N=>N.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(mt),children:n.jsx(H9,{agentId:l.agentId,agent:r.find(N=>N.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function W9({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null);if(t)return n.jsx(ie,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,v=r.problem,b=x=>x.map(w=>{var y;return((y=r.choices.find(k=>k.id===w))==null?void 0:y.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const x=await A.setDefaultAgent(p);f(x.note),a(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return n.jsx(Ge,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(ie,{message:c}),(v==null?void 0:v.code)==="multiple-defaults"?n.jsx(G,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(v.agents)}. The one chosen here wins.`}):(v==null?void 0:v.code)==="no-default-agent"?n.jsx(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,h?n.jsx(G,{tone:"good",role:"status",children:h}):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:x=>a(x.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(x=>n.jsxs("option",{value:x.id,disabled:!x.available,children:[x.name," @",x.handle,x.available?"":" (cannot run)"]},x.id))]}),n.jsx(E,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function H9({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=p=>g=>{g.preventDefault(),l(p)},u=cf(o.get(e)),h=(t==null?void 0:t.name)??e,f=lV(e),m=t!==void 0&&!t.roles.includes(Wc)&&!t.roles.includes(zc);return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(bn,{id:e,name:h,size:"xl",unavailable:t?!t.available:!1,face:t}),n.jsxs("div",{className:"agent-head-text",children:[n.jsx("p",{className:"ui-page-lede",children:(t==null?void 0:t.description)??"This agent is not in the roster right now."}),f.entry?n.jsx(oV,{entry:f.entry,navigate:l,onUpdated:f.reload}):null,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(we,{tone:"critical",children:u}):t&&!t.available?n.jsx(we,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(Et,{variant:"accent",href:st(e),onClick:c(st(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(G,{tone:"warning",role:"status",children:[tA(t)," ",n.jsx("a",{href:Pe(zg(t).section),children:zg(t).label})]}):null,n.jsx(Vc,{children:z9.map(p=>n.jsx(yl,{href:St(e,p.id),active:r===p.id,onClick:c(St(e,p.id)),children:p.label},p.id))}),r==="conversations"?n.jsx(K9,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(a$,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(o$,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(N$,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(p$,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(DV,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?n.jsx(S9,{agentId:e,section:i,navigate:l}):null,r==="setup"&&m?n.jsx(uV,{agentId:e,name:h,navigate:l}):null]})}function K9({agentId:e,navigate:t}){const{data:s,error:r}=de(()=>He.conversations(e,50),[e]);if(r)return n.jsx(pe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(Ge,{flush:!0,children:s?i.length===0?n.jsx(Tn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(rt,{children:i.map(a=>n.jsx(et,{href:st(e,a.id),onClick:()=>t(st(e,a.id)),title:zs(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:Le(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(pe,{children:"Loading…"})})}const V9=3e4;function B$(){const{data:e,reload:t}=de(()=>A.recovery(),[],V9),s=d.useRef(t);return s.current=t,d.useEffect(()=>{const r=()=>s.current(),i=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",i)}},[]),{data:e,reload:t}}function W0(e){return e.kind==="account"?e.accountId?HE(e.accountId):Pe("accounts"):e.kind==="telegram"?Pe("telegram"):e.kind==="connection"?e.connectionId?KE(e.connectionId):Pe("connections"):e.kind==="email"?e.settingsRoute:Pe("secrets")}function G9(e){return e.install?m4(e.install):p4}const Y9=Pe("system");function q9(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 W$="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function J9({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,l=e.checklist.keptTables??[],[o,c]=d.useState(!0),[u,h]=d.useState([]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(!1),j=r.filter(k=>!k.installed||k.waiting!==void 0||k.loadsAtRestart===!0),x=i.jobs+i.missions+i.approvals+i.telegramChats,w=k=>{h(N=>N.includes(k)?N.filter(S=>S!==k):[...N,k])},y=()=>{m(!0),g(null),of({kind:"recovery"},()=>A.leaveRecovery({dropPending:o,keepGrants:u})).then(k=>{k&&k.restarting===!1&&jl(),b(!0),t==null||t()}).catch(k=>g(k instanceof ve?k.message:String(k))).finally(()=>m(!1))};return n.jsx(Ge,{title:"Back from a backup",children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{children:[n.jsx(Ht,{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(ue,{title:"Keys to paste again",children:s.length===0?n.jsx(pe,{children:"Nothing is missing."}):n.jsx(rt,{children:s.map(k=>n.jsx(et,{title:k.label??k.name,sub:k.name?n.jsx("span",{className:"mono",children:k.name}):void 0,side:k.signIn?n.jsx(Et,{size:"sm",href:W0(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):n.jsx(Et,{size:"sm",href:W0(k),"aria-label":`Fix ${k.label??k.name}`,children:"Fix"})},`${k.kind}:${k.accountId??k.name}`))})}),n.jsx(ue,{title:"Add-ons to install again",children:j.length===0&&l.length===0?n.jsx(pe,{children:"Everything the backup named is installed."}):n.jsxs(rt,{children:[j.map(k=>n.jsx(et,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:k.name})," ",k.version]}),sub:q9(k),side:k.loadsAtRestart?n.jsx(Et,{size:"sm",href:Y9,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:n.jsx(Et,{size:"sm",href:G9(k),"aria-label":`Install ${k.name} again`,children:k.install?"Install":"Find it"})},k.name)),l.map(k=>n.jsx(et,{title:n.jsx("span",{className:"mono",children:k.table}),sub:k.sentence},`kept:${k.table}`))]})}),n.jsx(ue,{title:"Work that was waiting",children:x===0?n.jsx(pe,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(le,{gap:"sm",children:[n.jsx(Ht,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(ue,{title:"Standing permissions",children:a.length===0?n.jsx(pe,{children:"No agent had a standing permission."}):n.jsxs(le,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),n.jsx("ul",{className:"recovery-list",children:a.map(k=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:u.includes(k.id),onChange:()=>w(k.id),"aria-label":`Keep ${k.tool} for ${k.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:k.tool})," for ",k.agent," ",n.jsx("span",{className:"ui-card-meta",children:k.scope}),k.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",k.description]}):null]})]})},k.id))})]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:p}),v?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(E,{variant:"accent",disabled:f||v,onClick:y,children:"Leave recovery mode"})})]})})]})})}function Q9({days:e,mailbox:t,money:s,pictures:r}){const i=[];(t||e)&&i.push("chief-of-staff"),s&&i.push("cfo"),r&&i.push("illustrator");for(const a of["researcher","tutor"])i.length<3&&i.push(a);return i.slice(0,4)}function H$(e,t,s=4){const r=a=>!!a&&Mi(a)==="ready"&&a.addable,i=Q9(t).map(a=>e.find(l=>l.name===a)).filter(r);for(const a of["researcher","tutor"]){if(i.length>=3)break;const l=e.find(o=>o.name===a);r(l)&&!i.includes(l)&&i.push(l)}return i.slice(0,s)}function X9(e,t){const s=e.filter(r=>r.id!==t&&!r.roles.includes(zc)&&!r.roles.includes(Wc));return e.length>0&&s.length<=1}async function Z9(e,t=d$){try{const{jobId:s}=await A.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await A.catalogueJob(s);if(r.state!=="running")return r;await new Promise(i=>setTimeout(i,t))}}catch(s){return{error:s instanceof ve?s.message:String(s)}}}function e7({entry:e,checked:t,onChange:s}){return n.jsxs("label",{className:"cat-pick","data-checked":t?"true":void 0,children:[n.jsx("input",{type:"checkbox",checked:t,onChange:r=>s(r.target.checked)}),n.jsx(Gl,{entry:e,size:"lg"}),n.jsxs("span",{className:"cat-pick-text",children:[n.jsx("span",{className:"cat-pick-name",children:e.title}),n.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]})]})}function t7({entry:e,added:t,onOpen:s,onAdd:r}){return n.jsxs("div",{className:"cat-suggest",role:"button",tabIndex:0,"aria-label":`${e.title}: details`,"data-testid":`cat-suggest-${e.name}`,onClick:s,onKeyDown:i=>{i.target===i.currentTarget&&i.key==="Enter"&&s()},children:[n.jsx(Gl,{entry:e,size:"lg"}),n.jsxs("span",{className:"cat-pick-text",children:[n.jsx("span",{className:"cat-pick-name",children:e.title}),n.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]}),t?n.jsxs("span",{className:"cat-added",children:[n.jsx(ce,{name:"check",size:14}),"Added"]}):n.jsx(E,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:i=>{i.stopPropagation(),r()},children:"Add"})]})}function n7({navigate:e}){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState([]),o=fw();d.useEffect(()=>{let u=!1;return A.catalogue().then(h=>{u||s(h.unavailable?[]:h.agents)}).catch(()=>{u||s([])}),()=>{u=!0}},[]);const c=d.useMemo(()=>t===null?null:H$(t,{days:!0,mailbox:!0,money:o.has("finance"),pictures:o.has("image")},3),[t,o]);return!c||c.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"cat-suggest-lede",children:"Teammates who could take a job off your hands, from what you set up:"}),n.jsx("div",{className:"cat-suggests","data-testid":"home-suggestions",children:c.map(u=>n.jsx(t7,{entry:u,added:a.includes(u.name),onOpen:()=>e(Bt(u.name)),onAdd:()=>i(u)},u.name))}),r?n.jsx(h$,{entry:r,navigate:e,onClose:()=>i(null),onAdded:()=>{l(u=>[...u,r.name]),window.dispatchEvent(new Event(dr))}}):null]})}function s7({setUp:e,navigate:t}){var j;const[s,r]=d.useState(null),[i,a]=d.useState([]),[l,o]=d.useState("picking"),[c,u]=d.useState([]),[h,f]=d.useState([]),m=JSON.stringify(e);if(d.useEffect(()=>{let x=!1;return A.catalogue().then(w=>{if(x)return;const y=w.unavailable?[]:H$(w.agents,e);r(y),a(y.map(k=>k.name))}).catch(()=>{x||r([])}),()=>{x=!0}},[m]),!s||s.length===0)return null;const p=()=>t(Bt()),g=async()=>{o("adding");const x=[],w=[];for(const y of s.filter(k=>i.includes(k.name))){const k=await Z9(y);"error"in k&&!("state"in k)?w.push({entry:y,error:k.error}):k.state==="done"?x.push(y):k.state==="confirm"?w.push({entry:y,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):w.push({entry:y,error:k.error??"it stopped before it finished"})}u(x),f(w),o("added"),x.length>0&&window.dispatchEvent(new Event(dr))},v=i.length,b=l==="adding"?`Adding ${v===1?((j=s.find(x=>x.name===i[0]))==null?void 0:j.title)??"1":v}…`:v===s.length?"Add these":v>0?`Add these ${v}`:"Tick one to add";return n.jsx("section",{className:"handover-team","aria-label":"Who do you want on your team?","data-testid":"handover-team",children:l==="added"?n.jsxs(n.Fragment,{children:[c.length>0?n.jsxs(G,{tone:"good",role:"status",title:`${rn(c.map(x=>x.title))} ${c.length===1?"is":"are"} on your team.`,action:n.jsx(E,{variant:"ghost",size:"sm",onClick:p,children:"See all teammates"}),children:["Say hello in Chat. ",c.length===1?"Its missions are":"Their missions are"," off until you turn them on."]}):null,h.length>0?n.jsxs(G,{tone:"critical",role:"alert",title:`${rn(h.map(x=>x.entry.title))} ${h.length===1?"wasn’t":"weren’t"} added.`,action:c.length===0?n.jsx(E,{variant:"ghost",size:"sm",onClick:p,children:"See all teammates"}):void 0,children:[h.map(x=>`${x.entry.title}: ${x.error.replace(/[.\s]+$/,"")}.`).join(" ")," Nothing else changed; try again from the catalogue."]}):null]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"handover-team-head",children:[n.jsx("h2",{className:"handover-team-title",children:"Who do you want on your team?"}),n.jsx("p",{className:"cat-small",children:"Picked from what you just set up. Their plugins are already in, so one click adds them all."})]}),n.jsx("div",{className:"cat-picks",children:s.map(x=>n.jsx(e7,{entry:x,checked:i.includes(x.name),onChange:w=>a(w?[...i,x.name]:i.filter(y=>y!==x.name))},x.name))}),n.jsx("div",{className:"handover-team-foot",children:n.jsxs(ae,{children:[n.jsx(E,{variant:"ghost",onClick:p,children:"See all teammates"}),n.jsx(dt,{}),n.jsx(E,{variant:"accent",disabled:v===0||l==="adding",onClick:()=>void g(),children:b})]})})]})})}const H0=3,r7=40;function i7({agent:e,navigate:t}){var g;const s=d.useRef(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null),u=de(()=>He.conversations(e.id,H0),[e.id],3e4),h=bs(Ij),f=bs("(pointer: coarse)");d.useEffect(()=>{var v;!h&&!f&&((v=s.current)==null||v.focus())},[]);const m=(v,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:j}=await He.startConversation(e.id),x=await He.send(e.id,{conversationId:j,text:v,...b.length>0?{attachmentIds:b.map(w=>w.artifactId)}:{}});t(st(e.id,x.conversationId))}catch(j){l(j instanceof ve?j.message:String(j)),c({text:v,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,H0);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(ie,{message:a}):null,n.jsx(Vj,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(v=>{const b=st(e.id,v.id),j=v.opening??v.preview??"Untitled conversation",x=nj(v.lastMessageAt??v.createdAt??v.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:j,onClick:w=>{w.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:zs(j,r7)}),x?n.jsx("span",{className:"home-continue-when",children:x}):null]})},v.id)})})]}):null]})}function a7(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 l7({navigate:e,preview:t,hidden:s}){var c;const r=de(()=>A.currentTip(t),[t]),[i,a]=d.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?A.dismissTip(l.id):A.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(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(ce,{name:"close"})})]}),n.jsxs(ae,{children:[n.jsx(dt,{}),n.jsx(E,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(E,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const Cx="buddi.tipsOpen";function o7(e){return Dc(e,{compact:!0})}function c7(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 ${o7(e.shownAt)}`:"Shown"}}function u7(){try{return window.localStorage.getItem(Cx)==="1"}catch{return!1}}function d7(){const e=de(()=>A.tips(),[]),[t,s]=d.useState(u7),r=d.useCallback(i=>{s(i);try{i?window.localStorage.setItem(Cx,"1"):window.localStorage.removeItem(Cx)}catch{}},[]);return{open:t,setOpen:r,list:e}}function h7({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(ce,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function f7({tips:e,navigate:t}){var b,j;const{open:s,setOpen:r,list:i}=e,[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null);if(!s)return null;const f=((b=i.data)==null?void 0:b.tips)??null,m=u??((j=i.data)==null?void 0:j.enabled)??!0,p=x=>l(x instanceof ve?x.message:String(x)),g=x=>{c(x),l(null),A.restoreTip(x).then(()=>i.reload(),p).finally(()=>c(null))},v=x=>{c("switch"),l(null),h(x),A.saveTipsSettings(x).then(w=>{h(w.enabled),i.reload()}).catch(w=>{h(!x),p(w)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(ue,{title:"Tips",children:[n.jsx(ie,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(f??[]).map(x=>n.jsx("div",{className:"tips-card","data-tip":x.id,"data-status":x.status,children:n.jsxs(cs,{tone:x.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(we,{tone:x.status==="today"?"accent":"muted",children:c7(x)})}),n.jsx("p",{className:"tips-card-text",children:x.text}),n.jsxs(ae,{children:[n.jsx(dt,{}),x.status==="dismissed"?n.jsx(E,{size:"sm",disabled:o===x.id,onClick:()=>g(x.id),children:"Bring back"}):n.jsx(E,{size:"sm",variant:x.status==="today"?"accent":void 0,onClick:()=>t(x.action.route),children:x.action.label})]})]})},x.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:x=>v(x.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const K$="buddi.needsYouView";function m7(){try{return window.localStorage.getItem(K$)==="list"?"list":"deck"}catch{return"deck"}}function p7(e){try{window.localStorage.setItem(K$,e)}catch{}}function g7(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function x7({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=d.useState(0);if(e.length===0)return n.jsx(pe,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,h=v=>l((o+v+e.length)%e.length),f=()=>r(c),m=()=>i(c),p=v=>{const b=v.target;b.closest('input, textarea, select, [contenteditable="true"]')||(v.key==="ArrowRight"&&u?(v.preventDefault(),h(1)):v.key==="ArrowLeft"&&u?(v.preventDefault(),h(-1)):v.key==="Enter"&&!b.closest("button, a")?(v.preventDefault(),(c.link||c.agentId)&&f()):(v.key==="d"||v.key==="Delete")&&!v.metaKey&&!v.ctrlKey&&!v.altKey&&(v.preventDefault(),m()))},g=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(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(cs,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Le(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(E,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(ce,{name:"chevron-left"})}),n.jsx(E,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:n.jsx(ce,{name:"chevron-right"})})]}),foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:m,children:"Done"}),c.link||c.agentId?n.jsx(E,{variant:"accent",onClick:f,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:dc(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 v7({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o="",pluginPages:c}){var Ye,kt,Gt,se,be,Qe,ct,yt,ut,mn,Vn,Z,Re,Xe,xt;const u=de(()=>A.overview(),[],15e3),h=de(()=>A.approvals(),[],1e4),f=de(()=>A.missions(),[],6e4),m=de(()=>A.reminders(),[],6e4),p=de(()=>A.conversations(),[],3e4),g=de(()=>A.offers(),[],3e4),v=de(()=>A.proposals(),[],6e4),b=de(()=>A.agentOffers(),[],6e4),j=de(()=>A.owner(),[]),x=de(()=>A.notificationsNeedingYou(),[],3e4),w=d.useMemo(()=>ZE(s,r??null),[s,r]),y=X9(s,r),{busy:k,note:N,failure:S,decide:C}=Gj(()=>{h.reload(),u.reload()}),T=u.data,R=s.find(V=>V.id===r)??null,I=V=>{var he;return((he=s.find(Be=>Be.id===V))==null?void 0:he.name)??V},L=V=>he=>{he.preventDefault(),t(V)},W=((Ye=h.data)==null?void 0:Ye.pending)??[],$=((kt=T==null?void 0:T.jobs)==null?void 0:kt.failed)??0,P=((Gt=T==null?void 0:T.sentinels)==null?void 0:Gt.openUrgent)??0,O=((se=v.data)==null?void 0:se.open.length)??0,M=(((be=b.data)==null?void 0:be.offers)??[]).filter(V=>!W.some(he=>aT(he,V.plugin,V.agent))),D=w7(((Qe=x.data)==null?void 0:Qe.notifications)??[],W),[H,U]=d.useState(new Set),[q,B]=d.useState(m7),Y=D.filter(V=>!H.has(V.id)),F=V=>{U(he=>new Set(he).add(V.id)),A.notificationSeen(V.id).catch(()=>{})},X=V=>{F(V);const he=V.link??(V.agentId?st(V.agentId):null);he&&t(he)},Q=V=>g7(V.agentId?I(V.agentId):V.pluginId?PA(V.pluginId,c==null?void 0:c.all):j7[V.kind],V,I),ee=N7(T==null?void 0:T.dismissed,()=>u.reload()),fe=(((ct=T==null?void 0:T.sentinels)==null?void 0:ct.errors)??[]).filter(V=>!ee.is(`watcher-error:${V.sentinelId}`,V.error)),Oe=((T==null?void 0:T.mail)??[]).filter(V=>V.lastError&&!ee.is(`source-error:${V.sourceId}`,V.lastError)),Ie=y7(i),Fe=l.filter(V=>!ee.is(`connection:${V.id}`,V.sentence)),z=(((yt=T==null?void 0:T.needsYou)==null?void 0:yt.recovery)??0)>0,ne=W.length+Ie.length+($>0?1:0)+(P>0?1:0)+(O>0?1:0)+M.length+D.length+Fe.length+(z?1:0);d.useEffect(()=>{var V,he;o===vl&&((he=(V=document.getElementById(Ex))==null?void 0:V.scrollIntoView)==null||he.call(V,{behavior:"smooth",block:"start"}))},[o]);const J=d.useMemo(()=>{var V,he;return A7(((V=f.data)==null?void 0:V.missions)??[],((he=m.data)==null?void 0:he.reminders)??[])},[f.data,m.data]),ye=(((ut=p.data)==null?void 0:ut.conversations)??[]).slice(0,5),ge=((mn=g.data)==null?void 0:mn.offers)??[],$e=ge.slice(0,S7),De=d7(),Je=ge.length-$e.length,ze=zT(()=>u.reload()),Ne=vH(),Ue=d.useMemo(()=>jH(Ne.answer),[Ne.answer]),at=M7((T==null?void 0:T.needsYou)??{approvals:W.length,questions:Ie.length,failed:$,urgent:P,proposals:O,agentsToSetUp:M.length,asks:D.length,signIns:Fe.length,recovery:z?1:0},(T==null?void 0:T.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:R7(T==null?void 0:T.now,e)}),n.jsx(YW,{glances:T==null?void 0:T.glances,navigate:t,except:Ue,hiding:ze}),n.jsx(h7,{tips:De})]}),n.jsx("h1",{className:"home-greeting",children:$7(T==null?void 0:T.now,e,((Vn=j.data)==null?void 0:Vn.preferredName)||((Z=j.data)==null?void 0:Z.displayName))}),n.jsx(D7,{items:at,navigate:t})]}),n.jsx("div",{className:"home-side",children:n.jsx(lA,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[R?n.jsx(i7,{agent:R,navigate:t},R.id):null,n.jsx(f7,{tips:De,navigate:t}),n.jsx(l7,{navigate:t,preview:a7(o),hidden:De.open}),a&&a.updateAvailable&&!a.checkout&&a.latest&&!ee.is("update",a.latest)?n.jsx(G,{tone:"accent",action:n.jsx(Ja,{label:"Not now — tell me at the next version",onClick:()=>ee.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:Pe("system"),onClick:L(Pe("system")),children:"Upgrade from Settings → Version."})]})}):null,fe.map(V=>n.jsxs(G,{tone:"warning",action:n.jsx(Ja,{label:"Hide until the error changes",onClick:()=>ee.close(`watcher-error:${V.sentinelId}`,V.error)}),children:["Watcher ",V.sentinelId," failed: ",V.error]},V.sentinelId)),Oe.map(V=>n.jsxs(G,{tone:"warning",action:n.jsx(Ja,{label:"Hide until the error changes",onClick:()=>ee.close(`source-error:${V.sourceId}`,V.lastError)}),children:["Source ",V.sourceId,": ",V.lastError]},V.sourceId)),n.jsx(ie,{message:u.error??h.error??S}),N?n.jsx(G,{tone:"good",role:"status",children:N}):null,ne>0?n.jsx("div",{id:Ex,className:"home-needs",children:n.jsx(ue,{title:"Needs you",aside:n.jsx("a",{href:Og,onClick:L(Og),children:"All notifications"}),actions:D.length>0?n.jsx(Kt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:q,onChange:V=>{B(V),p7(V)}}):void 0,children:n.jsxs(le,{children:[W.map(V=>n.jsx(Yj,{action:V,timezone:e,busy:k===V.id,onDecide:C,agentName:I(V.agentId)},V.id)),P>0?n.jsx(G,{tone:"warning",children:n.jsx("a",{href:`${jt}/alerts`,onClick:L(`${jt}/alerts`),children:P7(P,((Re=T==null?void 0:T.sentinels)==null?void 0:Re.decisions)??[])})}):null,Ie.length>0||D.length>0&&q==="list"?n.jsx(Ge,{flush:!0,children:n.jsxs(rt,{children:[Ie.map(V=>n.jsx(et,{href:V.route,onClick:()=>t(V.route),lead:n.jsx(ln,{agents:s,id:V.agentId,size:"sm"}),title:"Asked you a question",sub:`${I(V.agentId)} · waiting for your answer`,side:Le(V.at)},V.agentId)),q==="list"?Y.map(V=>n.jsx(et,{href:V.link??void 0,onClick:()=>X(V),lead:V.agentId?n.jsx(ln,{agents:s,id:V.agentId,size:"sm"}):void 0,title:dc(V),sub:V.action?`${Q(V)} · ${V.action}`:Q(V),side:V.state==="held"?"today":Le(V.createdAt)},V.id)):null]})}):null,D.length>0&&q==="deck"?n.jsx(x7,{rows:Y,agents:s,label:Q,onOpen:X,onDone:F}):null,$>0?n.jsx(G,{tone:"critical",children:n.jsxs("a",{href:`${jt}/jobs?state=failed`,onClick:L(`${jt}/jobs?state=failed`),children:[$," failed job",$===1?"":"s",". See why, then retry or dismiss ",$===1?"it":"them","."]})}):null,O>0?n.jsx(G,{tone:"accent",children:n.jsxs("a",{href:Pe("proposals"),onClick:L(Pe("proposals")),children:[O," proposal",O===1?"":"s"," from your agents to keep or discard."]})}):null,Fe.map(V=>n.jsx(G,{tone:"accent",action:n.jsx(Ja,{label:"Not now — tell me if it changes",onClick:()=>ee.close(`connection:${V.id}`,V.sentence)}),children:n.jsxs("p",{children:[V.sentence," ",n.jsx("a",{href:Pe("connections"),onClick:L(Pe("connections")),children:"Settings → Connections."})]})},V.id)),M.map(V=>n.jsx(Ge,{children:n.jsx(Jj,{plugin:V.plugin,agent:V.agent,text:V.text,label:`Create @${V.handle}`,handle:V.handle,onDismiss:()=>{A.dismissAgentOffer(V.plugin,V.agent).then(()=>b.reload())}})},`${V.plugin}/${V.agent}`)),z?n.jsx(G,{tone:"warning",children:n.jsxs("p",{children:[W$," ",n.jsx("a",{href:Lg,onClick:L(Lg),children:"Open the checklist."})]})}):null]})})}):null,n.jsx(kH,{widgets:Ne,navigate:t}),n.jsxs(ue,{title:"Your team",aside:y?n.jsx("a",{href:Bt(),onClick:L(Bt()),children:"See all teammates"}):n.jsx("a",{href:mt,onClick:L(mt),children:"All agents"}),children:[s.length===0?n.jsx(pe,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsxs("div",{className:"home-team",children:[w.map(V=>{const he=cf(i.get(V.id));return n.jsxs("a",{className:"home-face",...Bc(Uc(V)),href:st(V.id),onClick:L(st(V.id)),"data-waiting":he?"true":void 0,"data-unavailable":V.available?void 0:"true",children:[n.jsx(bn,{id:V.id,name:V.name,size:"lg",unavailable:!V.available,face:V}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:V.name}),n.jsx("span",{className:"home-face-status",children:he?O7(he):V.available?zs(V.description,60):V.unavailableReason??"Cannot run right now."})]})]},V.id)}),y?null:n.jsxs("a",{className:"team-add",href:Bt(),onClick:L(Bt()),"data-testid":"team-add",children:[n.jsx(ce,{name:"plus",size:14}),"Add a teammate"]})]}),y?n.jsx(n7,{navigate:t}):null]}),$e.length>0?n.jsx(ue,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[Je>0?n.jsxs("a",{href:`${mt}?tab=offers`,onClick:L(`${mt}?tab=offers`),children:[Je," more"]}):null,n.jsx(l$,{ids:ge.map(V=>V.id),onDone:()=>g.reload()})]}),children:n.jsx("div",{className:"home-offers",children:$e.map(V=>n.jsx(E7,{offer:V,agents:s,open:L(St(V.agentId,"offers")),onDismissed:()=>g.reload()},V.id))})}):null,n.jsx(OW,{}),(xt=(Xe=v.data)==null?void 0:Xe.digest)!=null&&xt.latest&&k7(v.data.digest.latest,T==null?void 0:T.now,ee.is)?n.jsx(I7,{digest:v.data.digest.latest,go:L,onClose:()=>ee.close(V$,v.data.digest.latest.at)}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(ue,{title:"Coming up",aside:n.jsx("a",{href:`${mt}?tab=missions`,onClick:L(`${mt}?tab=missions`),children:"All missions"}),children:n.jsx(Ge,{flush:!0,children:J.length===0?n.jsx(pe,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(rt,{children:J.map(V=>n.jsx(et,{href:V.route,onClick:()=>t(V.route),lead:n.jsx(ln,{agents:s,id:V.agentId,size:"sm"}),title:V.title,sub:`${V.kind} for ${I(V.agentId)}`,side:Le(V.at)},V.key))})})}),n.jsx(ue,{title:"Lately",aside:n.jsx("a",{href:jt,onClick:L(jt),children:"All activity"}),children:n.jsx(Ge,{flush:!0,children:ye.length===0?n.jsx(pe,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(rt,{children:ye.map(V=>n.jsx(et,{href:st(V.agentId,V.id),onClick:()=>t(st(V.agentId,V.id)),lead:n.jsx(ln,{agents:s,id:V.agentId,size:"sm"}),title:V.opening?zs(V.opening,80):"Untitled conversation",sub:`${I(V.agentId)}, ${V.messageCount} message${V.messageCount===1?"":"s"}`,side:Le(V.lastMessageAt??V.createdAt)},V.id))})})})]}),((T==null?void 0:T.home)??[]).filter(V=>!ee.is(K0(V.id),V0)).map(V=>n.jsx(L7,{block:V,onHide:()=>ee.close(K0(V.id),V0)},V.id)),T!=null&&T.jobs&&T.missions?n.jsxs("p",{className:"home-foot muted",children:[Jt(T.jobs.pending??0)," queued, ",Jt(T.jobs.leased??0)," running, ",Jt(T.missions.enabled)," of ",Jt(T.missions.total)," missions on."," ",T.paused?n.jsx(we,{tone:"warning",children:"paused"}):n.jsx(we,{tone:"good",children:"running"})," ",n.jsx("a",{href:mc("").replace(/\/conversations\/$/,""),onClick:L(jt),children:"Activity"})," · ",n.jsx("a",{href:Pe("system"),onClick:L(Pe("system")),children:"System"})]}):null]})]})}const j7={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function w7(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 y7(e){const t=[];for(const s of e.values())s.question&&t.push({agentId:s.agentId,at:s.question.at,route:st(s.agentId,s.question.conversationId)});return t.sort((s,r)=>s.at.localeCompare(r.at))}const V$="digest",b7=3*864e5;function K0(e){return`block:${e}`}const V0="hidden";function k7(e,t,s){if(s(V$,e.at))return!1;const r=Date.parse(e.at),i=t?Date.parse(t):Date.now();return Number.isFinite(r)&&i-r<b7}function N7(e,t){const[s,r]=d.useState({});return{is:(l,o)=>(s[l]??(e==null?void 0:e[l]))===o,close:(l,o)=>{r(c=>({...c,[l]:o})),A.homeDismiss(l,o).then(t,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function Ja({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(ce,{name:"close"})})}const S7=6,C7=500;function E7({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=d.useState(!1),l=d.useRef(null),o=d.useRef(!1),c=()=>{i||(a(!0),A.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:St(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},C7)},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 A7(e,t){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:St(r.agentId,"missions")});for(const r of t)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:St(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function T7(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 $7(e,t,s){const r=T7(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 R7(e,t){try{return xr(e?new Date(e):new Date,t,{weekday:!0})}catch{return nt(e??null,t)}}function I7({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(ue,{title:"What buddi learned this week",aside:n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:Le(e.at)}),s?n.jsx(Ja,{label:"Hide until next week",onClick:s}):null]}),children:n.jsx(Ge,{children:n.jsxs(le,{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 P7(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 Ex="home-needs";function M7(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:`${jt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${jt}/jobs?state=failed`}),t&&r.push({key:"paused",count:null,label:"Paused",route:`${jt}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:Pe("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 D7({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(Ex))==null?void 0:r.scrollIntoView)==null||i.call(r,{behavior:"smooth",block:"start"})};return n.jsx("p",{className:"home-counts",children:e.map((r,i)=>{const a=n.jsxs(n.Fragment,{children:[r.count!==null?n.jsxs(n.Fragment,{children:[n.jsx("strong",{children:r.count})," "]}):null,r.label]});return n.jsxs(d.Fragment,{children:[i>0?n.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?n.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),t(r.route)},children:a}):n.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:a})]},r.key)})})}function O7(e){return e.charAt(0).toUpperCase()+e.slice(1)}function L7({block:e,onHide:t}){const[s,r]=d.useState(!1),i=e.sensitive===!0&&!s;d.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(E,{size:"sm",variant:"ghost","aria-pressed":!i,onClick:()=>r(l=>!l),children:i?"Show":"Hide"}):null,n.jsx(Ja,{label:`Hide ${e.title} from Home`,onClick:t})]});return n.jsxs(ue,{title:e.title,aside:a,children:[e.note?n.jsx(G,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(gf,{children:e.stats.map(l=>n.jsx(ir,{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(Ge,{flush:!0,children:n.jsx(rt,{children:e.rows.map((l,o)=>n.jsx(et,{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 F7=2e3,_7={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 Ax(e){return _7[e.phase]??e.detail??e.phase}const z7=new Set(["done","failed","rolled-back"]);function G$(e){return e!==void 0&&(z7.has(e.phase)||!!e.finishedAt)}function U7(e,t=!1){const[s,r]=d.useState(void 0),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=d.useRef(!1);return d.useEffect(()=>{if(!e){r(void 0),a(!1),c.current=!1;return}let u=!1;const h=()=>{t&&c.current||A.backupJob(e).then(m=>{if(!u){if(t&&(QE({step:Ax(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&jl()),c.current){window.location.reload();return}r(m),o(null),G$(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof ve&&m.status!==0&&m.status<500){t&&jl(),o(m.message);return}c.current=!0,t||a(!0)}})};h();const f=window.setInterval(h,F7);return()=>{u=!0,window.clearInterval(f)}},[e,t]),{job:s,away:i,error:l}}function B7({job:e,away:t,error:s}){return s?n.jsx(ie,{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:[Ax(e)," ",e.error??""]}):n.jsxs(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Ax(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function W7(){var x,w,y,k,N,S,C;const e=de(()=>A.backups(),[],3e4),t=B$(),s=de(()=>A.service(),[]),[r,i]=d.useState(null),[a,l]=d.useState(!1),o=U7(r,a),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=((x=e.data)==null?void 0:x.supervised)??((w=s.data)==null?void 0:w.supervised),v=m!==null||g===!1,b=((y=e.data)==null?void 0:y.archives)??[],j=(T,R=!1)=>{f(!0),u(null),l(R),T().then(I=>{var L;R&&I.job&&lf({kind:"restore",patienceMs:JE}),i(((L=I.job)==null?void 0:L.id)??null)}).catch(I=>{I instanceof ve&&I.status===409?p(I.message):u(I instanceof ve?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return d.useEffect(()=>{G$(o.job)&&e.reload()},[(k=o.job)==null?void 0:k.phase]),n.jsxs(le,{gap:"lg",children:[(N=t.data)!=null&&N.active?n.jsx(J9,{view:t.data,onLeft:t.reload}):null,n.jsx(ie,{message:e.error??c}),n.jsx(B7,{...o}),n.jsx(K7,{onSaved:()=>e.reload()}),n.jsx(ue,{title:"Backups",panel:!0,actions:n.jsx(E,{variant:"accent",size:"sm",disabled:h,onClick:()=>j(()=>A.startBackup(!0)),children:"Back up now"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{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(ue,{children:e.data&&b.length===0?n.jsx(Tn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(jr,{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(T=>{var R;return n.jsx(V7,{archive:T,busy:h,database:(R=e.data)==null?void 0:R.database,checkout:v,onVerify:()=>j(()=>A.verifyArchive(T.name)),onRestore:(I,L)=>j(()=>A.restoreArchive({name:T.name,...I?{passphrase:I}:{},...L?{confirm:L}:{}}),!0)},T.name)})})]}):n.jsx(pe,{children:"Loading…"})})]})}),n.jsx(G7,{}),n.jsx(Y7,{busy:h,checkout:v,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(T,R,I)=>j(()=>A.restoreUpload(T,{passphrase:R,confirm:I}),!0)})]})}const H7={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function K7({onSaved:e}){var p;const t=de(()=>A.backupSchedule(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1);d.useEffect(()=>{t.data&&r(t.data)},[t.data]);const h={...H7,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(ue,{title:"Every night",panel:!0,children:n.jsx(ue,{children:n.jsx(G,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...h,...g})},m=()=>{a(!0),o(null),A.setBackupSchedule(h).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof ve?g.message:String(g))).finally(()=>a(!1))};return n.jsx(ue,{title:"Every night",panel:!0,foot:n.jsx(E,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.enabled,onChange:g=>f({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(Us,{children:[n.jsx(oe,{label:"At",children:n.jsx("input",{type:"time",value:h.time,onChange:g=>f({time:g.target.value})})}),n.jsx(oe,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(oe,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(G,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Le(h.lastRunAt)}.`:""]}):null]})})]})})}function V7({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,f]=d.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:Le(e.createdAt)}),n.jsx("td",{children:Kn(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(we,{tone:"good",children:"locked"}):n.jsx(we,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(we,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(E,{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:Y$}):n.jsx(q$,{what:`${e.name}, taken ${Le(e.createdAt)}, ${Kn(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:f,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,h)})})}):null]})}const Y$="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function q$({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=t??"",f=h===""?a.trim()!=="":a.trim()===h;return n.jsxs(le,{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(oe,{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(oe,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:n.jsx("input",{value:a,onChange:m=>l(m.target.value)})}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function G7(){const[e,t]=d.useState(null),[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=()=>{a(!0),o(null),A.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof ve?m.message:String(m))).finally(()=>a(!1))},f=()=>{a(!0),o(null),A.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof ve?m.message:String(m))).finally(()=>a(!1))};return n.jsx(ue,{title:"The passphrase",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{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(E,{disabled:i,onClick:h,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(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(oe,{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(E,{variant:"accent",disabled:i||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function Y7({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(!1);return t?n.jsx(ue,{title:"Restore from a file",panel:!0,children:n.jsx(ue,{children:n.jsx(G,{tone:"warning",children:s??Y$})})}):n.jsx(ue,{title:"Restore from a file",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(Us,{children:[n.jsx(oe,{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(oe,{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(E,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),f&&a?n.jsx(ue,{children:n.jsx(q$,{what:`${a.name}, ${Kn(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const J$="gemini-2.5-pro";function Sf(e){return e.replace(/^models\//,"")}const Cw=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function Q$(e){const t=e.map(Sf);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||Cw.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||mh(a,s.version)>0||mh(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 X$(e){let t;for(const s of e.map(Sf)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Cw.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||mh(i,t.version)>0||mh(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function Z$(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Sf(e))}function q7(e){return[...new Set(e.map(Sf).filter(t=>t.startsWith("gemini-")&&!Cw.test(t)))]}function eR(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function mh(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 tR(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function J7({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=de(()=>A.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState(!1),[b,j]=d.useState(t??null);d.useEffect(()=>{t&&j(t)},[t]);const x=s==null?void 0:s.accounts.some(S=>{var C;return((C=S.login)==null?void 0:C.state)==="pending"&&S.login.expiresAt&&Date.parse(S.login.expiresAt)>Date.now()});d.useEffect(()=>{if(!x)return;const S=setInterval(i,2e3);return()=>clearInterval(S)},[x,i]);const w=async(S,C)=>{o(!0),u(null),f(""),v(!1);try{const T=await S();return f((T==null?void 0:T.warning)??C),i(),!0}catch(T){return u(T instanceof Error?T.message:"Could not apply change."),i(),!1}finally{o(!1)}},y=(s==null?void 0:s.accounts)??[],k=y.find(S=>S.id===b)??y[0],N=S=>{var C;return tR(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":nR(S)};return n.jsxs(Pn,{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(ie,{message:r??c}),h&&n.jsx(G,{tone:"good",role:"status",children:h}),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(pe,{children:"Loading accounts…"}),r&&n.jsx(ae,{children:n.jsx(E,{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(qe,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(aG,{accounts:y,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),n.jsx(ue,{title:"Accounts",aside:`Secrets live in the ${Q7(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),f(""),v(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.jsx(E,{variant:"accent",size:"sm",disabled:l,"aria-expanded":m,"aria-controls":"new-provider-account",onClick:()=>p(!m),children:"Add account"})]}),panel:!0,flush:!0,children:y.length===0?n.jsx(Tn,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:y.map(S=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(k==null?void 0:k.id)===S.id,onClick:()=>j(S.id),children:[n.jsx(X7,{kind:S.kind,auth:S.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:S.label}),ph(S)?n.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[N(S)," · back at ",Ew(ph(S).until)]}):n.jsxs("span",{className:"accounts-row-sub",children:[N(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(rR,{account:S})]},S.id))}),k?n.jsx(sG,{account:k,provider:N(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${k.id}:${k.revision}`):null]})})]})]})}function Q7(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function nR(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":ww(e)?"mlxh":"OpenAI-compatible"}function sR(e){return e.detectedContextWindowSource==="mlxh"?FV(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function X7({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 Z7(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function ph(e,t=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>t?s:null}const eG=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Ew(e,t=new Date,s=eG()){const r=new Date(e),i=a=>a.toLocaleDateString("en-CA",{timeZone:s});return i(r)===i(t)?Vt(r,s):i(r)===i(new Date(t.getTime()+864e5))?`tomorrow at ${Vt(r,s)}`:tj(r,s)}function rR({account:e,long:t}){const s=ph(e);if(s){const a=`Rate-limited until ${Ew(s.until)}`;return n.jsx("span",{title:a,children:n.jsx(we,{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(we,{tone:r,children:i})}function tG({id:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("span",{className:"accounts-id",children:[n.jsx("code",{className:"accounts-id-text",children:e}),n.jsx(E,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:t?"Copied":"Copy"})]})}function nG({account:e,provider:t}){const s=ph(e);if(!s)return null;const r=s.provider??t,i=Ew(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(Et,{size:"sm",href:a.length===1?St(a[0],"setup","brain"):mt,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 Aw(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 sG({account:e,provider:t,busy:s,run:r,anthropicOAuthEnabled:i}){const[a,l]=d.useState(!1),[o,c]=d.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(rR,{account:e,long:!0})]}),n.jsx(Ht,{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?"":` (${sR(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>n.jsx("a",{href:St(u,"setup","brain"),children:u},u))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:mt,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(tG,{id:e.id})}]}),n.jsx(nG,{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(lR,{account:e,enabled:!!i,busy:s,run:r}),e.kind==="codex"&&n.jsx(iR,{account:e,busy:s,run:r}),e.auth==="device-key"&&n.jsx(aR,{account:e,busy:s,run:r}),n.jsxs(ae,{children:[n.jsx(E,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),n.jsx(E,{disabled:s||e.removalPending,onClick:()=>void r(()=>A.saveProviderAccount({...Aw(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(E,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>A.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(E,{variant:"danger",disabled:s||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>c(!0),children:"Remove account"})]}),e.test&&n.jsxs(n.Fragment,{children:[n.jsxs(G,{role:"status",tone:Z7(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(qe,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:n.jsx(rG,{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(E,{variant:"danger",disabled:s,onClick:()=>void r(()=>A.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(E,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),n.jsx(At,{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 iR({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(E,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>A.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(E,{disabled:t,onClick:()=>void s(()=>A.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(E,{disabled:t||!e.configured,onClick:()=>void s(()=>A.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(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(bw,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(ae,{children:n.jsx(Et,{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 ",Vt(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 rG({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=d.useState((e==null?void 0:e.label)??""),[c,u]=d.useState((e==null?void 0:e.kind)??"anthropic"),[h,f]=d.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=d.useState((e==null?void 0:e.baseUrl)??""),[g,v]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,j]=d.useState(""),[x,w]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=N=>{u(N),f(N==="codex"?"chatgpt":"api-key"),j(""),p(N==="openai-compatible"?"http://localhost:11434/v1":""),v(N==="anthropic"?"claude-sonnet-5":N==="openai"?"gpt-5":"")},k=!l.trim()||!g.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:N=>{N.preventDefault();const S=b;j(""),s(()=>A.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:x.trim()?Number(x):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(oe,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:N=>o(N.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(oe,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:N=>{N.target.value==="anthropic-oauth"?(y("anthropic"),f("anthropic-oauth")):y(N.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:N=>p(N.target.value)})}),n.jsx(oe,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:h,onChange:N=>{f(N.target.value),j("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(ae,{valign:"end",children:n.jsx(yw,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:v,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(oe,{label:"Context window",hint:ww(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:x,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${sR(e)})`:"assumed from the model",onChange:N=>w(N.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&n.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),h==="api-key"&&n.jsx(oe,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:N=>j(N.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:r,children:"Cancel"}),n.jsx(E,{type:"submit",variant:"accent",disabled:k,children:"Save account"})]})]}),k&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function aR({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,A.ollamaPoll(e.id,r.attemptId).then(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?i.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):i.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await A.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return n.jsxs(n.Fragment,{children:[l&&n.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),n.jsxs(ae,{children:[n.jsx(E,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(E,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await A.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&&Vt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function lR({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,h;const[i,a]=d.useState("");return d.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(G,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(ae,{children:[n.jsx(E,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>A.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&n.jsx(E,{disabled:s,onClick:()=>{a(""),r(()=>A.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(E,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>A.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((h=e.login)==null?void 0:h.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=i;a(""),r(()=>A.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&Vt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),n.jsx(oe,{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(E,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const rp={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function ip(e,t,s){return Tx(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 Tx(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 iG="That key was refused. Check it and paste it again.";function aG({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(J=>J.label),[c,u]=d.useState(null),[h,f]=d.useState("anthropic"),[m,p]=d.useState("api-key"),[g,v]=d.useState(()=>ip("anthropic","api-key",o)),[b,j]=d.useState(!1),[x,w]=d.useState(""),[y,k]=d.useState(""),[N,S]=d.useState(null),[C,T]=d.useState(!1),[R,I]=d.useState(""),[L,W]=d.useState(""),[$,P]=d.useState(!1),[O,M]=d.useState(!1),[D,H]=d.useState(!1),[U,q]=d.useState(void 0),B=(J,ye,ge=!1)=>{f(J),p(ye),k(""),S(null),I(""),W(""),P(!1),M(ge),H(!1),q(void 0),w(ge?"":J==="openai-compatible"?"http://localhost:11434/v1":""),b||v(ge?ip(J,"device-key",o):ip(J,ye,o))},Y=J=>{B("openai-compatible",J?"api-key":"device-key",!0),J&&A.ollama().then(ye=>w(ye.cloudBaseUrl)).catch(()=>{})},F=()=>{l&&(B("openai-compatible","api-key"),H(!0),w(l.baseUrl),b||v(Tx("Gemini",o)))},X=()=>{B("openai-compatible","none"),q(null),b||v(Tx("mlxh",o)),A.mlxh().then(J=>{q(J),w(J.baseUrl)}).catch(()=>q(void 0))},Q=U!==void 0,ee=c?e.find(J=>J.id===c):void 0;if(c)return ee?n.jsx(lG,{account:ee,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(ee.id)}):n.jsx(pe,{children:"Saving…"});const fe=h==="openai-compatible"&&m!=="device-key",Oe=h==="codex"||m==="anthropic-oauth"||m==="device-key",Ie=!Oe&&(m==="none"||y.trim()!=="")&&(!fe||x.trim()!==""),Fe=async()=>{var J,ye;T(!0),I("");try{const ge=await A.probeModels({kind:h,auth:m,...fe?{baseUrl:x}:{},...y.trim()?{secret:y}:{}});S(ge),L||W(((J=ge.models.find($e=>$e.isDefault))==null?void 0:J.id)??((ye=ge.models[0])==null?void 0:ye.id)??"")}catch(ge){I(ge instanceof Error?ge.message:"Could not load models. You can still enter a custom model.")}finally{T(!1)}},z=L.trim(),ne=!g.trim()||fe&&!x.trim()||fe&&!D&&!Q&&!z||D&&!y.trim()||Q&&!(U!=null&&U.running);return n.jsxs("form",{className:"ui-stack",onSubmit:J=>{var De;J.preventDefault();const ye=y;k("");let ge=z||(Q?Nx(U)??((De=U==null?void 0:U.models[0])==null?void 0:De.id):void 0)||(m==="device-key"?ld:rp[h])||"claude-sonnet-5",$e;(async()=>{if(D){ge=J$;try{const at=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:ye})).models.map(Ye=>Ye.id);ge=Q$(at)??ge,$e=Z$(ge)?X$(at):void 0}catch{}}let Je,ze=!1;!await s(async()=>{if(Je=await A.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:x,defaultModel:ge,enabled:!0,...ye.trim()?{secret:ye}:{}}),m!=="api-key")return Je;const Ue=await A.testProviderAccount(Je.id);if(Ue.state==="connected")return Je;if(rj(Ue)){const at=Je.id;Je=void 0;try{const Ye=(await A.providerAccounts()).accounts.find(kt=>kt.id===at);Ye&&await A.removeProviderAccount(at,Ye.revision)}catch{}throw new Error(iG)}if(D&&$e&&eR(Ue)){const at=(await A.providerAccounts()).accounts.find(Ye=>Ye.id===Je.id);if(at&&(await A.saveProviderAccount({...Aw(at),defaultModel:$e}),(await A.testProviderAccount(Je.id)).state==="connected"))return{...Je,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${$e}; turn on billing at Google to use Pro.`}}return ze=!0,{...Je,warning:`Account saved. ${Ue.message}`}},"Account saved.")||!Je||(D||Q||ze?u(Je.id):z||!Oe?r(Je.id):u(Je.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(oe,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":O?"ollama-cloud":D?"gemini":Q?"mlxh":h,onChange:J=>{if(J.target.value==="anthropic-oauth")B("anthropic","anthropic-oauth");else if(J.target.value==="gemini")F();else if(J.target.value==="mlxh")X();else if(J.target.value==="ollama-cloud")B("openai-compatible","device-key",!0);else{const ye=J.target.value;B(ye,ye==="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(oe,{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:J=>{v(J.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),O&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:J=>Y(J.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),fe&&n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:x,onChange:J=>{w(J.target.value),S(null)}})}),!D&&!Q&&n.jsx(oe,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:J=>{p(J.target.value),k(""),S(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(oe,{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:J=>{k(J.target.value),S(null)}})}),Q?U===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):U!=null&&U.running?n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",U.models.length===1?"one model":`${U.models.length} models`,". No key: mlxh takes any. buddi starts on ",Nx(U)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),U.models.some(J=>J.kind==="image")?n.jsxs("p",{className:"muted",children:[U.models.filter(J=>J.kind==="image").map(J=>J.id).join(", "),": ",E$,"."]}):null]}):n.jsx(G,{tone:"warning",children:C$((U==null?void 0:U.baseUrl)??x)}):D&&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."]}):Oe?n.jsx("p",{className:"muted",children:h==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),N?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:$?"__custom__":L,onChange:J=>{J.target.value==="__custom__"?(P(!0),W("")):(P(!1),W(J.target.value))},children:[N.models.map(J=>n.jsxs("option",{value:J.id,children:[J.name===J.id?J.id:`${J.name} — ${J.id}`,J.isDefault?" (provider default)":"",J.thinks?" · thinks":""]},J.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(E,{size:"sm",disabled:C||!Ie,onClick:()=>void Fe(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(E,{disabled:C||!Ie,onClick:()=>void Fe(),children:C?"Loading models…":"Load models"}),fe?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",rp[h]," is used until you pick one."]})]}),$||fe&&!N?n.jsx("input",{"aria-label":"Custom model",required:fe,maxLength:150,value:L,onChange:J=>W(J.target.value),placeholder:fe?"qwen3:8b":rp[h]}):null,R?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:R}):null,N!=null&&N.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:()=>r(),children:"Cancel"}),n.jsx(E,{type:"submit",variant:"accent",disabled:ne,children:"Save account"})]})]}),ne&&!Q&&n.jsxs("p",{className:"muted",children:["Enter an account name",D?" and a key":fe?", an endpoint and a model":""," to enable Save account."]})]})}function lG({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=d.useState(e.defaultModel),o=e.configured;return n.jsxs(le,{gap:"lg",children:[n.jsxs(G,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(lR,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(iR,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(aR,{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(yw,{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(E,{onClick:i,children:"Skip for now"}),n.jsx(E,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>A.saveProviderAccount({...Aw(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(ae,{children:n.jsx(E,{onClick:i,children:"Finish later"})})]})}const G0=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 oG(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||G0.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return G0.has(`*.${s}`)}function cG(e){return typeof e=="string"&&e.includes("*")}function uG(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"}:oG(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const Y0=["every-time","first-time","pre-approved"];function oR(e){const t=Y0.indexOf(e);return Y0.slice(0,t<0?1:t+1)}function ba(e){return e.endsWith(".account")}const dG="Stored, not usable until it has a binding.";function hG(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":ba(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const cR={"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})}},fG="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",mG=e=>`That is a public suffix; ${e} would match every site.`,q0="Give the site as an origin, like https://en.wikipedia.org.";function J0(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(cG(e)){const s=uG(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:fG};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:mG(r)}}return{ok:!1,error:q0}}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:q0}}}function pG(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 gG(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 J0(s);if(e==="browser.native.type"||ba(e))return{ok:!0,target:s};const r=cR[e];if(r===void 0)return{ok:!0,target:s};const i=pG(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=J0(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 xG(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function uR(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=cR[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 Yl="accounts.provider";function dR(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 hR(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 vG(e){const t=dR(e,"found");return t.length?`The value already sits in ${hR(t)}.`:""}function jG(e){const t=dR(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${hR(t)}.`:""}const wG=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,yG=/^MCP_(TOKEN|ENV|CONNECTION)_/,fR="GMAIL_APP_PASSWORD";function qr(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===fR)return"mail";if(t.some(r=>r.kind==="model-account")||s.includes(Yl)||wG.test(e.name))return"models";if(t.some(r=>r.kind==="connection")||s.includes("mcp.env")||yG.test(e.name))return"connections";for(const r of e.bindings){if(r.kind==="http.url"&&Tw(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(ba(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function bG(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 kG(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 mR(e){return e==="models"||e==="connections"}function Tw(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Q0(e){const t=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return t.startsWith("*.")?`any ${t.slice(2)} site`:t}const $w=e=>(e.usedBy??[]).flatMap(t=>t.kind==="mailbox"?[t]:[]),Cf=e=>(e.usedBy??[]).find(t=>t.kind==="model-account"),Rw=e=>(e.usedBy??[]).find(t=>t.kind==="connection");function Fo(e,t=new Map){var r,i;const s=qr(e);if(s==="mail"){const a=$w(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=Cf(e),l=(a==null?void 0:a.id)??((r=e.bindings.find(c=>c.kind===Yl&&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=Rw(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 NG(e,t){var r,i,a;if(qr(e)!=="models")return null;const s=((r=Cf(e))==null?void 0:r.id)??((i=e.bindings.find(l=>l.kind===Yl&&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 pR(e,t){const s=Tw(t)?t:{},r=i=>typeof s[i]=="string"?s[i]:"";return e==="browser.field"&&typeof t=="string"?`Filled on ${Q0(t)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${Q0(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===Yl?"Used by a model account":ba(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${uR(e,t)}`}function SG(e,t){return ba(e)||e===Yl?"Signed in":pR(e,t).replace(/^Sent only to/,"Sent to")}const CG={"api-key":"API key for this model account",chatgpt:"ChatGPT sign-in for this model account","anthropic-oauth":"Claude sign-in for this model account","device-key":"Ollama device key for this model account"};function EG(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Iw(e){const t=qr(e);if(t==="mail"){const a=$w(e).map(l=>l.address);return a.length?`Used by the ${a.length===1?"mailbox":"mailboxes"} ${EG(a)}`:e.name===fR?"From the old .env setup":"No mailbox uses it"}if(t==="models"){const a=Cf(e);return a?CG[a.auth]??"Key for this model account":"No model account uses it"}if(t==="connections"){const a=Rw(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&&Tw(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=>pR(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 AG(e,t=Date.now()){return e.lastUse?`Last used ${Le(e.lastUse.at,t)}`:"Never used"}function $x(e){return Kr("email","settings",{account:e,set:"password"})}function gR(e){var s,r;const t=qr(e);if(t==="models"){const i=(s=Cf(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:i?HE(i):Pe("accounts")}}if(t==="connections"){const i=(r=Rw(e))==null?void 0:r.id;return{label:"Managed in Connections",href:i?KE(i):Pe("connections")}}return null}function xR(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 vR(e,t=Date.now()){if(e.unused)return null;const s=qr(e),r=$w(e)[0],i=gR(e),a=()=>r?{label:"Set password",href:$x(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?Le(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 ${Le(r.loginFailedAt,t)}.`,fix:{label:"Set password",href:$x(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"?xR(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}: ${wR(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:vl}}: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 jR(e){if(!e.unused)return"";const t=qr(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 Rx(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function Qa(e){return!!e.unused&&!mR(qr(e))}function TG(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const t=Iw(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 $G={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function RG(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",[Yl]:"A model account"};return t[e]?t[e]:ba(e)?`A ${e.slice(0,-8)} account`:e}const IG={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function wR(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)?xR(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 PG(e){return e==="browser.field"?"www.pnc.com":e==="browser.form.data"?"www.pnc.com card-number":e==="browser.native.type"?"com.bank.app":e==="http.header"?"api.github.com Authorization":e==="http.url"?"calendar calendar.google.com":e==="developer.env"?"my-app ADMIN_PASSWORD":ba(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function gh(e){return oR(e).includes("first-time")?"first-time":e}function MG(e){const t=SG(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${wR(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 da(e,t,s,r){s(!0),r(null);try{return(await A.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}const yR="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function DG(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 OG({embedded:e,timezone:t,secret:s,adding:r,navigate:i}={}){const a=de(()=>A.secrets(),[]),l=de(()=>A.providerAccounts(),[]),o=d.useMemo(()=>{var g;return new Map((((g=l.data)==null?void 0:g.accounts)??[]).map(v=>[v.id,{label:v.label,provider:nR(v)}]))},[l.data]),[c,u]=d.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);d.useEffect(()=>{s&&u({what:"replace",name:s})},[s]),d.useEffect(()=>{r&&u({what:"add"})},[r]);const h=()=>{u(null),(s||r)&&i&&i(Pe("secrets"))},f=a.data,m=d.useMemo(()=>{const g=new Map;for(const v of(f==null?void 0:f.secrets)??[]){const b=qr(v);g.set(b,[...g.get(b)??[],v])}return[...g.entries()].sort(([v],[b])=>kG(v,b))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(g=>g.name===c.name))??null:null;return n.jsxs(Pn,{embedded:e,title:"Keys and secrets",lede:yR,actions:e?void 0:n.jsx(E,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[n.jsxs(le,{gap:"lg",children:[!f&&!a.error?n.jsx(pe,{children:"Opening the vault…"}):null,a.error?n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:a.error}),n.jsx(ae,{children:n.jsx(E,{onClick:a.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?n.jsx(Ge,{children:n.jsx(Tn,{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(Ge,{flush:!0,children:m.map(([g,v])=>{const b=bG(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(rt,{children:v.map(j=>n.jsx(FG,{secret:j,group:g,accounts:o,onOpen:x=>u({what:x,name:j.name})},j.name))})]},g)})}):null,f&&f.ownKeys.length>0?n.jsx(At,{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,v)=>n.jsxs("span",{children:[v>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(UG,{destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?n.jsx(_G,{secret:p,accounts:o,timezone:t,onClose:h,onOpen:g=>u({what:g,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?n.jsx(BG,{secret:p,title:Fo(p,o),onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="rename"?n.jsx(WG,{secret:p,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?n.jsx(HG,{secret:p,title:Fo(p,o),destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="delete"?n.jsx(KG,{secret:p,title:Fo(p,o),onClose:h,onChanged:a.reload}):null]})}const xh=e=>t=>{t.stopPropagation(),e==null||e()};function bR({fix:e,onOpen:t}){return"href"in e?n.jsx(Et,{size:"sm",href:e.href,onClick:xh(),children:e.label}):n.jsx(E,{size:"sm",onClick:xh(()=>t(e.action)),children:e.label})}function LG(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=$x(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},Qa(e)?"separator":null,Qa(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")},Qa(e)?"separator":null,Qa(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function FG({secret:e,group:t,accounts:s,onOpen:r}){const i=Fo(e,s),a=NG(e,s),l=[Iw(e),AG(e)].filter(Boolean).join(" · "),o=vR(e),c=jR(e),u=Rx(e),h=mR(t)?gR(e):null;return n.jsx(et,{onClick:()=>r("sheet"),label:`${i}: details`,lead:n.jsx($n,{icon:DG(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(bR,{fix:o.fix,onOpen:r}):null,c&&Qa(e)?n.jsx(E,{size:"sm",variant:"ghost",onClick:xh(()=>r("delete")),children:"Remove…"}):null,h?n.jsxs("a",{className:"secrets-managed",href:h.href,onClick:xh(),children:[h.label,n.jsx(ce,{name:"chevron-right",size:12})]}):n.jsx(ja,{label:`More for ${i}`,items:LG(e,t,r),sheet:{title:i,sub:l}})]})})}function _G({secret:e,accounts:t,timezone:s,onClose:r,onOpen:i}){const a=qr(e),l=Fo(e,t),o=vR(e),c=jR(e),u=[...new Set(e.bindings.map(m=>m.rule))],h=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:n.jsx("code",{className:"mono secrets-mono",children:m.id})}));return n.jsx(qe,{title:l,onClose:r,foot:a==="mine"?n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:()=>i("delete"),children:"Delete…"}),n.jsx(dt,{}),n.jsx(E,{onClick:()=>i("rename"),children:"Rename…"}),n.jsx(E,{variant:"accent",onClick:()=>i("replace"),children:"Replace value…"})]}):void 0,children:n.jsxs(le,{gap:"lg",children:[n.jsx(Ht,{items:[{label:"Where it may go",value:Iw(e)||"Nowhere yet"},...u.length===1&&a==="mine"?[{label:"Asks you",value:$G[u[0]]}]:[],{label:"Last used",value:h?`${Le(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?n.jsx(G,{tone:"warning",action:o.fix?n.jsx(bR,{fix:o.fix,onOpen:i}):void 0,children:o.text}):null,c?Qa(e)?n.jsxs(G,{action:n.jsx(E,{size:"sm",onClick:()=>i("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):n.jsx(G,{children:c}):null,Rx(e)?n.jsx(G,{children:Rx(e)}):null,n.jsxs(le,{gap:"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),n.jsx(zG,{name:e.name,timezone:s})]}),n.jsx(At,{summary:"Details",children:n.jsxs(le,{gap:"sm",children:[n.jsx(Ht,{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," ",uR(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 zG({name:e,timezone:t}){const s=de(()=>A.secretUses(e,50),[e]);if(s.error)return n.jsx(ie,{message:s.error});if(!s.data)return n.jsx(pe,{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(rt,{children:r.map((i,a)=>{const l=MG(i);return n.jsx(et,{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 kR({title:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a}){const l=vG(t);return n.jsxs(le,{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(ie,{message:i}),l?n.jsx(ae,{children:n.jsx(E,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":jG(s)||"Nothing of it was left to replace."})}):null]})}function NR({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(le,{gap:"sm",children:[t.map((a,l)=>{const o=e.find(h=>h.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(oe,{label:"Kind of place",children:n.jsx("select",{value:a.kind,disabled:s,onChange:h=>{var p;const f=h.target.value,m=(p=e.find(g=>g.kind===f))==null?void 0:p.maxRule;i(l,{kind:f,rule:m?gh(m):a.rule})},children:u.map(h=>n.jsx("option",{value:h.kind,children:RG(h.kind)},h.kind))})}),n.jsx(oe,{label:"The place",children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:PG(a.kind),onChange:h=>i(l,{target:h.target.value})})}),n.jsx(oe,{label:"Asks you",children:n.jsx("select",{value:a.rule,disabled:s,onChange:h=>i(l,{rule:h.target.value}),children:oR(c).map(h=>n.jsx("option",{value:h,children:IG[h]},h))})}),n.jsx(E,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((h,f)=>f!==l)),children:"Remove"}),n.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",hG(a.kind),"."]})]},l)}),t.length===0?n.jsx("p",{className:"ui-field-hint",children:dG}):null,e.length?n.jsx(ae,{children:n.jsx(E,{size:"sm",disabled:s,onClick:()=>r([...t,{kind:e[0].kind,target:"",rule:gh(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 SR(e){const t=e.map(r=>gG(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 UG({destinations:e,onClose:t,onChanged:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:gh(e[0].maxRule)}]:[]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null),w=async()=>{const k=SR(u);if(!k.ok){g(k.error);return}const N=a;l("");const S=await da("secrets.put",{name:r.trim(),value:N,totp:o,bindings:k.bindings},m,g);S!==null&&(b({name:r.trim(),result:S}),s())},y=async()=>{const k=await da("secrets.scrub_history",{name:(v==null?void 0:v.name)??""},m,g);k!==null&&(x(k),s())};return v?n.jsx(qe,{title:"Add a secret",onClose:t,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{onClick:t,children:"Done"})}),children:n.jsx(kR,{title:v.name,result:v.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y()})}):n.jsx(qe,{title:"Add a secret",size:"wide",onClose:t,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:t,children:"Cancel"}),n.jsx(E,{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:k=>{k.preventDefault(),w()},children:[n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx(oe,{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:k=>i(k.target.value),placeholder:"PNC password"})}),n.jsx(oe,{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:k=>l(k.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"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(NR,{destinations:e,bindings:u,disabled:f,onChange:h})]}),p?n.jsx(G,{tone:"critical",role:"alert",children:p}):null]})})}function BG({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=d.useState(""),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),g=async()=>{const b=i;a("");const j=await da("secrets.put",{name:e.name,value:b,totp:e.totp,bindings:e.bindings.map(({kind:x,target:w,rule:y})=>({kind:x,target:w,rule:y}))},o,u);j!==null&&(f(j),r())},v=async()=>{const b=await da("secrets.scrub_history",{name:e.name},o,u);b!==null&&(p(b),r())};return h?n.jsx(Ft,{title:`Replaced the value of “${t}”`,onClose:s,foot:n.jsx(E,{variant:"accent",onClick:s,children:"Done"}),children:n.jsx(kR,{title:t,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void v()})}):n.jsx(Ft,{title:`Replace the value of “${t}”`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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(oe,{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(ie,{message:c})]})})}function WG({secret:e,onClose:t,onChanged:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name,h=async()=>{await da("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(Ft,{title:`Rename “${e.name}”`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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&&h()},children:[n.jsx(oe,{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(ie,{message:o})]})})}function HG({secret:e,title:t,destinations:s,onClose:r,onChanged:i}){const[a,l]=d.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:xG(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:gh(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=async()=>{const m=SR(a);if(!m.ok){h(m.error);return}await da("secrets.rebind",{name:e.name,bindings:m.bindings},c,h)!==null&&(i(),r())};return n.jsx(qe,{title:`Where “${t}” may go`,size:"wide",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:r,children:"Cancel"}),n.jsx(E,{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(NR,{destinations:s,bindings:a,disabled:o,onChange:l}),u?n.jsx(G,{tone:"critical",role:"alert",children:u}):null]})})}function KG({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=!!e.unused,u=async()=>{await da("secrets.delete",{name:e.name},a,o)!==null&&(r(),s())};return n.jsxs(Ft,{title:`${c?"Remove":"Delete"} “${t}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:i,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[n.jsxs("p",{className:"secrets-dialog-text",children:[TG(e)," The value is gone for good; its usage history stays, under its name."]}),n.jsx(ie,{message:l})]})}function VG({timezone:e,embedded:t}){var p;const{data:s,error:r,reload:i}=de(()=>A.sentinels(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(g=>g.lastError),f=u.filter(g=>!g.enabled),m=(g,v)=>{l(g),c(null),A.setSentinelEnabled(g,v).catch(b=>c(b instanceof ve?b.message:String(b))).finally(()=>{l(null),i()})};return n.jsxs(Pn,{embedded:t,title:"Watchers",children:[n.jsx(ie,{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."}),h.length>0?n.jsx(G,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,f.length>0?n.jsxs(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(ue,{title:"Installed",aside:n.jsx("a",{href:`${jt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx(Tn,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(rt,{children:u.map(g=>{const v=s.runs.find(b=>b.sentinelId===g.id);return n.jsx(et,{lead:n.jsx(we,{tone:g.enabled?v!=null&&v.lastError?"critical":v?"good":void 0:"muted",children:g.enabled?v!=null&&v.lastError?"failed":v?"ok":"never ran":"off"}),title:g.description,sub:`${g.id}, every ${GG(g.every)}${v!=null&&v.lastError?`. ${v.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:v?nt(v.lastRunAt,e):void 0,children:v?Le(v.lastRunAt):"never ran"}),n.jsx(E,{size:"sm",disabled:a===g.id,onClick:()=>m(g.id,!g.enabled),children:g.enabled?"Turn off":"Turn on"})]})},g.id)})}):n.jsx(pe,{children:"Loading…"})}),n.jsx(kK,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:i})]})}function GG(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 X0=4,YG={time:"profile",date:"profile",zone:null};function qG({data:e,phone:t}){const s=d.useRef(null),r=FT(),[i,a]=d.useState(.4),l=t?390:1280,o=t?780:800;d.useEffect(()=>{const u=s.current;if(!u)return;const h=()=>a(u.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(h);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return n.jsx("div",{ref:s,className:"lke-preview","data-phone":t?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:n.jsxs("div",{className:"lk","data-preview":"true","data-bg":ow(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(YT,{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(ce,{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(ce,{name:"lock",size:15}),n.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function JG({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(Kt,{label:`Size of ${c}`,options:["small","medium"].filter(h=>e.sizes.includes(h)).map(h=>({value:h,label:h==="small"?"Small":"Medium"})),value:t.size,onChange:i}):null,n.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:a,children:n.jsx(ce,{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(ce,{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(ce,{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(ce,{name:"close",size:12})})]})]})]})}function Z0(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function QG({clock:e,onClock:t,version:s}){var q,B,Y;const r=e??YG,i=de(()=>A.lockScreen(),[s]),a=de(()=>A.widgets("lock"),[]),l=de(()=>A.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>{a.data&&c(a.data)},[a.data]);const w=((q=i.data)==null?void 0:q.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(F=>[F.id,F])),N=y.length>=X0,S=F=>{if(!o)return Promise.resolve(!1);const X=o;return m(null),c({...o,lock:F,arranged:{...o.arranged,lock:!0}}),A.saveWidgets("lock",F).then(Q=>(c(Q),i.reload(),!0),Q=>(c(X),m(`Couldn't save the lock screen's widgets: ${Q instanceof Error?Q.message:String(Q)}`),!1))},C=(F,X)=>{const Q=y.slice(),[ee]=Q.splice(F,1);Q.splice(F+X,0,ee),S(Q)},T=(F,X)=>{const Q=k.get(F);!Q||N||S([...y,{key:HT(),widget:F,size:Q.sizes.includes("small")?"small":Q.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(!v||v.query.trim().length<2)return;const F=v.query.trim();b({query:v.query,found:[],busy:!0}),A.findPlace(F).then(({found:X})=>{var Oe;const Q=X.filter(Ie=>Ie.timezone);if(Q.length===0){b({query:F,found:[],busy:!1,missed:`Nothing with a timezone found for “${F}”.`});return}const ee=Q[0],fe={label:((Oe=ee.name.split(",")[0])==null?void 0:Oe.trim())||ee.name,timezone:ee.timezone};x(fe),b(null),t({...r,zone:fe})}).catch(()=>b({query:F,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},L=new Date,W=F=>Pc({dateFormat:F},()=>xr(L,w,{weekday:!0})),$=(((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,O=((o==null?void 0:o.home)??[]).filter(F=>k.has(F.widget)&&!k.get(F.widget).sensitive),M=((o==null?void 0:o.available)??[]).filter(F=>!F.sensitive),D=((o==null?void 0:o.available)??[]).filter(F=>F.sensitive).map(F=>F.title),H=p?y.find(F=>F.key===p):void 0,U=H?k.get(H.widget):void 0;return n.jsxs(ue,{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(qG,{data:i.data,phone:u}),n.jsxs("div",{className:"lke-look-foot",children:[n.jsx(Kt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:F=>h(F==="phone")}),n.jsxs("span",{className:"lke-look-note",children:["As it shows now",(Y=i.data)!=null&&Y.focus?", with your focus on":"","."]})]})]}),n.jsxs("div",{className:"lke-controls",children:[n.jsx(ie,{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(Kt,{label:"Time",options:[{value:"profile",label:U1()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:F=>t({...r,time:F})})]}),n.jsx(oe,{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 · ",W(null)]}),n.jsx("option",{value:"short",children:W("short")}),n.jsx("option",{value:"long",children:W("long")}),n.jsx("option",{value:"iso",children:W("iso")}),n.jsx("option",{value:"off",children:"No date"})]})}),n.jsx(oe,{label:"A second clock",hint:"A place in another zone, under the time.",children:n.jsxs("select",{value:v?"find":Z0(r.zone),onChange:F=>R(F.target.value),children:[n.jsx("option",{value:"",children:"None"}),$.map(F=>n.jsxs("option",{value:`place:${F.id}`,children:[F.label," — ",F.name.split(",")[0]]},F.id)),r.zone&&"place"in r.zone&&!$.some(F=>F.id===r.zone.place)?n.jsx("option",{value:Z0(r.zone),children:"A place no longer in another zone"}):null,P?n.jsx("option",{value:`town:${P.timezone}:${P.label}`,children:P.label}):null,n.jsx("option",{value:"find",children:"Another town…"})]})}),v?n.jsxs("div",{className:"wg-field-stack",children:[n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{autoFocus:!0,value:v.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:F=>b({...v,query:F.target.value}),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),I()),F.key==="Escape"&&b(null)}}),n.jsx(E,{size:"sm",disabled:v.busy||v.query.trim().length<2,onClick:I,children:v.busy?"Finding…":"Find"})]}),v.missed?n.jsx("span",{className:"ui-field-hint",children:v.missed}):null]}):null]}),n.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[n.jsxs("div",{className:"lke-group-head",children:[n.jsxs("p",{className:"lke-group-title",children:["Widgets ",n.jsxs("span",{className:"lke-count",children:[y.length," of ",X0]})]}),N||!o?n.jsxs(E,{size:"sm",disabled:!0,children:[n.jsx(ce,{name:"plus",size:12})," Add a widget"]}):n.jsx(ja,{label:"Add a widget",trigger:n.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[n.jsx(ce,{name:"plus",size:12})," Add a widget"]}),items:[O.length>0?{heading:"As on Home"}:null,...O.map(F=>({label:F.label??k.get(F.widget).title,hint:"same settings",onSelect:()=>T(F.widget,F.settings)})),O.length>0?"separator":null,{heading:"Every widget"},...M.map(F=>({label:F.title,onSelect:()=>T(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 Q=k.get(F.widget);return Q?n.jsx(JG,{info:Q,placement:F,index:X,count:y.length,onSize:ee=>void S(y.map(fe=>fe.key===F.key?{...fe,size:ee}:fe)),onSettings:()=>g(F.key),onMove:ee=>C(X,ee),onRemove:()=>void S(y.filter(ee=>ee.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:[N?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",D.length>0?` A sensitive widget — ${D.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(ce,{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."})]})]})]}),H&&U?n.jsx(UT,{info:U,placement:H,surface:"lock",onClose:()=>g(null),onSave:F=>S(y.map(X=>X.key===H.key?{...X,settings:F}:X)).then(X=>(X&&g(null),X)),onRemove:()=>{g(null),S(y.filter(F=>F.key!==H.key))}}):null]})}const XG=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],ZG=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],eY=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Ix(e){if(e instanceof ve){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 tY({kind:e,onClose:t,onDone:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=e==="remove",g=e!=="set",v=!f&&(!g||r.length>=4)&&(p||a.length>=4&&o.length>=4),b=y=>y.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",x=y=>{if(y==null||y.preventDefault(),!v)return;if(!p&&a!==o){h("The two PINs aren’t the same.");return}m(!0),h(null),(p?A.removePin(r):A.setPin(a,g?r:void 0)).then(s).catch(N=>{m(!1),h(Ix(N))})},w=(y,k,N,S)=>n.jsx(oe,{label:y,children:n.jsx("input",{type:"password",inputMode:"numeric",autoComplete:y==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:k,onChange:C=>{h(null),N(b(C.target.value))}})});return n.jsx(Ft,{title:j,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{variant:p?"danger":"accent",disabled:!v,onClick:()=>x(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:n.jsxs("form",{className:"lk-form",onSubmit:x,children:[n.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),g?w("Current PIN",r,i,!0):null,p?null:w(e==="set"?"PIN":"New PIN",a,l,!g),p?null:w("The same again",o,c,!1),u?n.jsx(G,{tone:"critical",children:u}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function nY(e){const t=bf(),s=de(()=>A.lockState(),[]),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=d.useRef(null),h=s.data??t.state,f=b=>{t.update(b),s.reload()},m=b=>{l(null),b.then(f).catch(j=>l(Ix(j)))},p=b=>{b&&(c(!0),l(null),A.uploadLockBackground(b).then(f).catch(j=>l(Ix(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!h)return n.jsx(ue,{title:"Lock screen",panel:!0,children:n.jsx(ie,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=h.pin,v=(b,j)=>n.jsxs("button",{type:"button",className:"lk-swatch","data-bg":b,"aria-pressed":h.background===b,"aria-label":j,title:j,onClick:()=>m(A.setLockSettings({background:b})),children:[b==="image"&&h.image?n.jsx("img",{src:h.image,alt:""}):b==="earth"?n.jsx("img",{src:xx.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(ue,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:g?n.jsxs(E,{size:"sm",onClick:()=>t.lockNow(),children:[n.jsx(ce,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[n.jsxs(le,{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(ie,{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(E,{size:"sm",variant:"ghost",onClick:()=>i("remove"),children:"Remove…"}),n.jsx(E,{size:"sm",onClick:()=>i("change"),children:"Change…"})]}):n.jsx(E,{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(Kt,{label:"Lock after",options:ZG,value:g?eY(h):"",onChange:b=>{g&&m(A.setLockSettings({delayMinutes:b==="never"?null:Number(b)}))}})]}),n.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"Background"}),n.jsx("div",{className:"ui-field-hint",children:"Behind the time and your widgets, on every device. A picture is kept as a JPEG of at most 2560 pixels, without its location or other details."})]}),n.jsxs("div",{className:"lk-swatches",role:"group","aria-label":"Background",children:[XG.map(b=>v(b.id,b.label)),h.image?v("image","Your picture"):null,n.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o?"true":void 0,children:[n.jsx("input",{ref:u,type:"file",accept:"image/jpeg,image/png",className:"lk-sr",disabled:o,onChange:b=>{var j;return p((j=b.target.files)==null?void 0:j[0])}}),n.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:n.jsx(ce,{name:"plus",size:16})}),n.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":h.image?"Replace":"Your picture"})]})]}),n.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",n.jsx("a",{href:Km.authorUrl,target:"_blank",rel:"noreferrer",children:Km.author})," on ",n.jsx("a",{href:Km.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),h.image?n.jsx(ae,{align:"end",children:n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(A.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?n.jsx(tY,{kind:r,onClose:()=>i(null),onDone:b=>{i(null),f(b)}}):null]}),n.jsx(QG,{clock:h.clock,onClock:b=>m(A.setLockSettings({clock:b})),version:`${h.background}:${h.image??""}:${JSON.stringify(h.clock??null)}`})]})}const ap=60;function CR(e){return e instanceof ve?e.message:"Something went wrong. Try again."}function sY(e,t,s=Date.now()){const r=`made ${xr(new Date(e.createdAt),t,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Le(e.lastUsedAt,s)}`:"never used"}`}function rY({onClose:e,onMade:t}){const[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),m=!i&&s.trim()!==""&&s.trim().length<=ap,p=g=>{g==null||g.preventDefault(),m&&(a(!0),o(null),A.createApiToken(s.trim()).then(v=>{u({token:v.token,name:v.apiToken.name}),t()}).catch(v=>o(CR(v))).finally(()=>a(!1)))};if(c){const g=()=>{var v;(v=navigator.clipboard)==null||v.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return n.jsx(Ft,{title:`Token for ${c.name}`,onClose:e,foot:n.jsx(E,{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(E,{size:"sm",onClick:g,children:h?"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(Ft,{title:"Make a token",onClose:e,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:e,children:"Cancel"}),n.jsx(E,{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(oe,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${ap} characters.`,children:n.jsx("input",{autoFocus:!0,value:s,maxLength:ap,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 iY({token:e,onClose:t,onRevoked:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.revokeApiToken(e.id).then(()=>{s(),t()}).catch(c=>{i(!1),l(CR(c))})};return n.jsxs(Ft,{title:`Revoke “${e.name}”?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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 aY({timezone:e}){var o;const t=de(()=>A.apiTokens(),[]),[s,r]=d.useState(!1),[i,a]=d.useState(null),l=((o=t.data)==null?void 0:o.tokens)??[];return n.jsxs(le,{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(ie,{message:t.error?"Couldn’t read the API tokens.":null}),n.jsx(ue,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:n.jsx(E,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:t.data&&l.length===0?n.jsxs(pe,{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(rt,{children:l.map(c=>n.jsx(et,{lead:n.jsx($n,{icon:"key"}),title:c.name,sub:sY(c,e),side:n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(c),children:"Revoke…"})},c.id))})}),n.jsxs(ue,{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(rY,{onClose:()=>r(!1),onMade:()=>t.reload()}):null,i?n.jsx(iY,{token:i,onClose:()=>a(null),onRevoked:()=>t.reload()}):null]})}function lY({embedded:e}){const{data:t,error:s,reload:r}=de(()=>A.owner(),[]);return n.jsxs(Pn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(ie,{message:s}),t?n.jsxs(le,{gap:"lg",children:[n.jsx(uY,{initial:t,onSaved:r}),n.jsx(mY,{initial:t})]}):null]})}const ER=new Date(Date.UTC(2026,9,1,14,5));function oY(){return[["",`Auto (${Pc({timeFormat:null},()=>Vt(ER,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function cY(){return[["",`Auto (${Pc({dateFormat:null},()=>xr(ER,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function uY({initial:e,onSaved:t}){const[s,r]=d.useState(e.preferredName??""),[i,a]=d.useState(e.timezone??""),[l,o]=d.useState(e.timeFormat??""),[c,u]=d.useState(e.dateFormat??""),[h,f]=d.useState(e.language??""),[m,p]=d.useState(e.about??""),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(null);d.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??"")},[e.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??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??""),k=async()=>{v(!0),w(null);try{const C=await A.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:h.trim()===""?null:h.trim(),about:m.trim()===""?null:m.trim()});ej({timeFormat:C.timeFormat??null,dateFormat:C.dateFormat??null}),window.dispatchEvent(new Event(wg)),j(!0),t()}catch(C){w(C instanceof ve?C.message:String(C))}finally{v(!1)}},N=e.zones.length>0?e.zones:[e.detectedTimezone],S=C=>T=>{j(!1),C(T)};return n.jsx(ue,{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(E,{variant:"accent",disabled:!y||g,onClick:()=>void k(),children:g?"Saving…":"Save"})]}),children:n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsx(ue,{title:"Name, time and language",children:n.jsxs(Us,{children:[n.jsx(oe,{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(oe,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:C=>S(a)(C.target.value),children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),N.map(C=>n.jsx("option",{value:C,children:C},C))]})}),n.jsx(oe,{label:"Time",children:n.jsx("select",{value:l,onChange:C=>S(o)(C.target.value),children:oY().map(([C,T])=>n.jsx("option",{value:C,children:T},C))})}),n.jsx(oe,{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:cY().map(([C,T])=>n.jsx("option",{value:C,children:T},C))})}),n.jsx(oe,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:h,maxLength:40,placeholder:"English, français…",onChange:C=>S(f)(C.target.value)})})]})}),n.jsxs(ue,{title:"About you",children:[n.jsx(oe,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:n.jsx("textarea",{rows:4,maxLength:1e3,value:m,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:C=>S(p)(C.target.value)})}),x?n.jsx(G,{tone:"critical",children:x}):null]})]})})}const dY=["Home","Work"];function hY(e){const t=e.trim().toLowerCase();return t==="home"?"home":t==="work"?"briefcase":"pin"}function eN({label:e,empty:t}){return n.jsx("span",{className:"place-glyph","data-empty":t?"true":void 0,"aria-hidden":"true",children:n.jsx(ce,{name:hY(e),size:18})})}function fY(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 mY({initial:e}){var c;const[t,s]=d.useState(e.places??[]);d.useEffect(()=>s(e.places??[]),[e]);const[r,i]=d.useState(null),a=e.timezone??e.detectedTimezone,l=dY.filter(u=>!t.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[t]);return n.jsxs(ue,{title:"Places",aside:"the front desk, and plugins you allow",actions:n.jsx(E,{size:"sm",onClick:()=>i({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[n.jsxs(rt,{children:[t.map(u=>n.jsx(et,{label:`${u.label}: edit`,onClick:()=>i({place:u,label:u.label}),lead:n.jsx(eN,{label:u.label}),title:u.label,sub:fY(u),side:u.timezone&&u.timezone!==a?n.jsxs(we,{children:[Vt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>n.jsx(et,{label:`${u}: add`,onClick:()=>i({label:u}),lead:n.jsx(eN,{label:u,empty:!0}),title:n.jsx("span",{className:"muted",children:u}),sub:"Not set",side:n.jsx(E,{size:"sm",onClick:h=>{h.stopPropagation(),i({label:u})},children:"Add"})},u))]}),n.jsx("p",{className:"place-note",children:"Only the town is looked up, on Open-Meteo, to find where it is and its timezone. The address stays on this computer."}),r?n.jsx(pY,{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 pY({editing:e,zones:t,onClose:s,onSaved:r}){const i=e.place,[a,l]=d.useState(e.label),[o,c]=d.useState((i==null?void 0:i.address)??""),[u,h]=d.useState(i?[{name:i.name,latitude:i.latitude,longitude:i.longitude,...i.timezone?{timezone:i.timezone}:{}}]:null),[f,m]=d.useState(0),[p,g]=d.useState((i==null?void 0:i.timezone)??""),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState((i==null?void 0:i.address)??""),k=u==null?void 0:u[f],N=()=>{o.trim().length<2||(b("find"),x(null),A.findPlace(o.trim()).then(I=>{var L;h(I.found),y(o.trim()),m(0),g(((L=I.found[0])==null?void 0:L.timezone)??""),I.found.length===0&&x("Nothing found by that name. Try the town, with its country.")}).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},S=()=>{k&&(b("save"),x(null),A.savePlace({...i?{id:i.id}:{},label:a.trim(),address:o.trim()===""?null:o.trim(),name:k.name,latitude:k.latitude,longitude:k.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},C=()=>{i&&(b("remove"),x(null),A.removePlace(i.id).then(I=>r(I.places)).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},T=i?i.label:e.label?`Add ${e.label}`:"Add a place",R=p!==""&&!t.includes(p)?[p,...t]:t;return n.jsx(qe,{title:T,onClose:s,foot:n.jsxs(ae,{children:[i?n.jsx(E,{variant:"danger-ghost",disabled:v!==null,onClick:C,children:v==="remove"?"Removing…":"Remove"}):null,n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!k||a.trim()===""||v!==null,onClick:S,children:v==="save"?"Saving…":"Save"})]}),children:n.jsxs(le,{gap:"lg",children:[n.jsx(oe,{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(oe,{label:"Address",hint:"A street address, or just the town.",action:n.jsx(E,{disabled:o.trim().length<2||v!==null,onClick:N,children:v==="find"?"Finding…":"Find"}),children:n.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!i,placeholder:"12 Elm Street, Portland, Maine",onChange:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),N())}})}),u&&u.length>0?n.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,L)=>n.jsxs("button",{type:"button",role:"radio","aria-checked":L===f,className:"place-option","data-on":L===f?"true":void 0,onClick:()=>{m(L),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(oe,{label:"Its timezone",hint:k?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:n.jsxs("select",{value:p,disabled:!k,onChange:I=>g(I.target.value),children:[n.jsx("option",{value:"",children:"Not known"}),R.map(I=>n.jsx("option",{value:I,children:I},I))]})}),n.jsx(ie,{message:j})]})})}const gY=2e6;function tN(e,t){const s=e.replace(/\r\n/g,`
|
|
118
|
+
`).replace(/\n+$/,"").split(`
|
|
119
|
+
`),r=t.replace(/\r\n/g,`
|
|
120
|
+
`).replace(/\n+$/,"").split(`
|
|
121
|
+
`);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>gY)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
|
|
122
|
+
`);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(`
|
|
123
|
+
`)}const AR={skill:"skill",policy:"rule",change:"change to itself"};function xY(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 Px(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function vY(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Px(s.current??""));return Px(t).filter(i=>!r.has(i))}function jY(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 wY(e){return"cards"in e}function nN(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function yY({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=de(()=>A.proposals(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState({}),p=async(x,w,y=!1)=>{l(null),c(null),h(x),m(({[x]:k,...N})=>N);try{c(await w()),i()}catch(k){const N=k instanceof Error?k.message:String(k);y?m(S=>({...S,[x]:N})):l(N)}finally{h(null)}},g=lT(),v=((s==null?void 0:s.open)??[]).filter(x=>nN(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>nN(x,t)),j=x=>n.jsx(CY,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:w=>void p(x.id,async()=>{const y=await A.keepProposal(x.id,w);return`${x.title}: ${y.note}`},!0),onDiscard:w=>void p(x.id,async()=>(await A.discardProposal(x.id,w),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id);return n.jsxs(Pn,{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(ie,{message:r??a}),t?n.jsxs(G,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:Pe("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(G,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(oT,{offers:g.offers,reload:g.reload}),!s||v.length===0?n.jsx(ue,{title:"Waiting",panel:!0,children:s?t?n.jsx(Tn,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(Tn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(pe,{children:"Loading…"})}):n.jsx(ue,{title:"Waiting",aside:`${v.length} to decide`,children:jY(v).map(x=>wY(x)?n.jsx(bY,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const w=await A.keepAllProposals(x.cards.map(y=>y.id));return`${x.label}: ${w.note}`}),card:w=>j(w)},x.key):j(x))}),b.length>0?n.jsx(ue,{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(rt,{children:b.map(x=>{var w;return n.jsx(et,{title:x.title,sub:`${x.agent}: ${kY(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((w=x.skill)!=null&&w.live)?n.jsxs(ae,{align:"end",children:[n.jsx("span",{className:"muted",children:Le(x.decidedAt??x.createdAt)}),n.jsx(E,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const y=x.skill;return await A.removeSkill(x.agent,y.name),`Removed ${y.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Le(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(SY,{schedule:s.digest.schedule,onSaved:i}):null]})}function bY({group:e,busy:t,onKeepAll:s,card:r}){const i=e.cards.length,a=e.cards.some(l=>l.untrusted);return n.jsx(cs,{tone:a?"warning":"accent",title:`${e.label} (${i})`,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:AR.policy}),n.jsx(we,{mono:!0,children:e.plugin})]}),foot:n.jsx(ae,{align:"end",children:n.jsxs(E,{variant:"accent",size:"sm",disabled:t,onClick:s,children:["Keep all (",i,")"]})}),children:n.jsxs(le,{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(At,{summary:`Show each of the ${i}`,children:n.jsx(le,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function kY(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 NY=Array.from({length:24},(e,t)=>t),sN=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function SY({schedule:e,onSaved:t}){const[s,r]=d.useState(e.day),[i,a]=d.useState(e.hour),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=s!==e.day||i!==e.hour,f=async()=>{o(!0),u(null);try{await A.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${sN[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(ue,{title:"Weekly digest",panel:!0,foot:n.jsx(E,{variant:"accent",disabled:l||!h,onClick:()=>void f(),children:"Save"}),children:n.jsxs(le,{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: ${Le(e.next)}.`:""]}),n.jsxs(ae,{children:[n.jsx(oe,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:sN.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(oe,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:NY.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 rN(e,t){return e==="tools"?Px(t).join(`
|
|
124
|
+
`):t}function CY({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=d.useState(e.editable??""),[o,c]=d.useState(""),u=e.editable!==null&&a!==e.editable,h=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=vY(e,a);return n.jsx(cs,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:AR[e.kind]}),n.jsx(we,{mono:!0,children:e.agent}),e.untrusted?n.jsx(we,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(we,{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(E,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(E,{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(le,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Le(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:mc(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 h.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.jsxs("a",{href:St(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),n.jsx(Jd,{text:tN(e.skill.steps,a),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(oe,{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(Jd,{text:tN(rN(m.part,m.current),rN(m.part,a)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?n.jsx(At,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(Pt,{children:h.before})}):null,n.jsx(oe,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?n.jsx(Ht,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:xY(h.matcher??{})})},{label:"Does",value:String(h.action??"")},{label:"Learned from",value:(()=>{const g=Array.isArray(h.verdicts)?h.verdicts.length:0;return`${g} ${g===1?"decision":"decisions"}`})()}]}):null]})})}function EY(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 AY({start:e,onPick:t,onClose:s}){const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(""),u=(p,g=!1)=>{l(null),A.pluginFolders(p).then(v=>{i(v),c("")}).catch(v=>{g&&p!==void 0?u(void 0):l(v instanceof ve?v.message:String(v))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?EY(r):[];return n.jsxs(qe,{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(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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(Zd,{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(xf,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(ie,{message:a}),r?f.length===0?n.jsx(pe,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(Ge,{flush:!0,children:n.jsx(rt,{children:f.map(p=>n.jsx(et,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx($n,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(we,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(pe,{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 TY="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 iN(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ce,{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:Pe("connections"),children:"Connections"})]})]})}const $Y=1500,RY={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."},IY="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",TR=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],$R="buddi.plugins.install-mode";function PY(){try{const e=window.localStorage.getItem($R);if(TR.some(t=>t.value===e))return e}catch{}return"npm"}function MY(e){try{window.localStorage.setItem($R,e)}catch{}}const Wu=".tgz",Lr=(e,t,s)=>`${e} ${e===1?t:s}`;function RR(e){const t=[];return e.tools>0&&t.push(Lr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Lr(e.views,"view","views")),e.agents>0&&t.push(`${Lr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function Mx(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 IR(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Pw(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function PR(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Ef({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 Dx({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 MR(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function Mw(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 Ci=e=>e instanceof ve?e.message:String(e);function DY(e){const[t,s]=d.useState(void 0),[r,i]=d.useState(null);return d.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{A.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(Ci(c)),a=!0)})};l();const o=window.setInterval(l,$Y);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function OY({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=hr(a.plugin,a.id);return n.jsx(Et,{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 DR({plugin:e}){var s;if(e.enabled===!1)return n.jsx(we,{children:"disabled"});const t=(s=e.needs)==null?void 0:s[0];return t?n.jsxs(we,{tone:"warning",children:["needs ",t.plugin]}):e.loadsAtRestart?n.jsx(we,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?n.jsx(we,{tone:"warning",children:"needs setup"}):e.loaded?n.jsx(we,{tone:"good",dot:!0,children:"loaded"}):n.jsx(we,{tone:"critical",children:"did not load"})}function Dw({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(we,{tone:"accent",children:"by buddi"}):n.jsxs(we,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const Ox=Pe("plugins"),lp={installed:Ox,browse:`${Ox}?tab=browse`};function LY({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=de(()=>A.plugins(),[],2e4),[a,l]=d.useState(null),{job:o,error:c}=DY(a),[u,h]=d.useState(null),[f,m]=d.useState(()=>hk(r));d.useEffect(()=>m(hk(r)),[r]);const[p,g]=d.useState(()=>dk(r));d.useEffect(()=>g(dk(r)),[r]);const[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),[k,N]=d.useState(null),[S,C]=d.useState(!1),T=se=>{C(!0),A.market(se).then(N).catch(be=>N({plugins:[],unavailable:Ci(be)})).finally(()=>C(!1))};d.useEffect(()=>{f==="browse"&&k===null&&!S&&T(!1)},[f]);const R=se=>{h(null),l(se)},I=se=>h(Ci(se)),[L,W]=d.useState(!1),$=se=>{W(!0),b(null),se.then(be=>{R(be.job.id),m("installed")}).catch(I).finally(()=>W(!1))},P=d.useRef(null);d.useEffect(()=>{const se=v4(r);if(!(se===null||P.current===se)){P.current=se,m("installed"),$(A.stagePlugin(se));try{window.history.replaceState(window.history.state,"",Ox)}catch{}}},[r]);const O=se=>be=>{be.preventDefault(),m(se),b(null),s==null||s(lp[se])};d.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const M=i.data,D=(M==null?void 0:M.checkout)??!0,H=(M==null?void 0:M.installed)??[],U=se=>k==null?void 0:k.plugins.find(be=>be.installed!==void 0&&(be.installed.name??be.name)===se.name),q=se=>e.some(be=>be.plugin===se),B=(se,be)=>q(se)?n.jsx(OY,{plugin:se,pages:e,navigate:s,variant:be}):void 0,Y=se=>{const be=e.find(Qe=>Qe.plugin===se);be&&s&&s(hr(be.plugin,be.id))},F=se=>{const be=t.find(Qe=>Qe.plugin===se);if(!(!be||!s))return()=>s(Kr(be.plugin,be.id))},X=((k==null?void 0:k.plugins)??[]).filter(se=>se.update).length,Q=(se,be)=>A.setPluginEnabled(se,be).then(Qe=>{v3(),y({name:se,notes:Qe.notes??[]}),i.reload()}),ee=(se,be,Qe)=>A.uninstallPlugin(se,be?{purge:!0,confirm:Qe}:{}).then(ct=>{b(null),y({name:se,notes:ct.notes??[]}),i.reload()}),fe=se=>{h(null),Q(se,!0).catch(I)},Oe=(se,be)=>{const Qe=k==null?void 0:k.plugins.find(yt=>{var ut;return(((ut=yt.installed)==null?void 0:ut.name)??yt.name)===se&&yt.installed!==void 0}),ct=Qe&&be?`${Qe.npm}@${be}`:void 0;$(ct?A.updatePlugin(se,be,ct):A.updatePlugin(se,be))},Ie=se=>{h(null);const be=Qe=>{const ct=Qe.plugins.find(yt=>{var ut;return yt.name===se||((ut=yt.installed)==null?void 0:ut.name)===se});if(!ct){h(`${se} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}$(A.stagePlugin(`${ct.npm}@${ct.version}`))};if(k&&k.plugins.length>0)return be(k);W(!0),A.market(!1).then(Qe=>{N(Qe),be(Qe)}).catch(I).finally(()=>W(!1))},Fe=(se,be)=>be===void 0?void 0:be.place==="settings"?Kr(se,be.id):hr(se,be.id),z=se=>{var Qe;if(se.enabled===!1)return;const be=(Qe=se.needs)==null?void 0:Qe[0];if(be)switch(be.state){case"missing":return{label:`Install ${be.plugin}`,run:()=>Ie(be.plugin)};case"disabled":return{label:`Enable ${be.plugin}`,run:()=>fe(be.plugin)};case"range":return{label:`Update ${be.plugin}`,run:()=>Oe(be.plugin)};case"setup":{const ct=Fe(be.plugin,be.page),yt=ct&&s?()=>s(ct):F(be.plugin);return yt?{label:`Set up ${be.plugin}`,run:yt}:void 0}default:return{label:`See ${be.plugin}`,run:()=>b({kind:"installed",name:be.plugin})}}if(se.loaded&&se.setup){const ct=Fe(se.name,se.setup.page),yt=ct&&s?()=>s(ct):F(se.name);return yt?{label:"Set it up",run:yt}:void 0}},ne=n.jsxs(Vc,{label:"Plugins",children:[n.jsx(yl,{href:lp.installed,active:f==="installed",count:X,onClick:O("installed"),children:"Installed"}),n.jsx(yl,{href:lp.browse,active:f==="browse",onClick:O("browse"),children:"Browse"})]}),J=(M==null?void 0:M.staged)??[],ye=KY(J,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),ge=J.find(se=>se.id===ye),$e=J.filter(se=>se.id!==ye),De=se=>{b(null),GY(se),l(null),i.reload()},Je=(v==null?void 0:v.kind)==="staged"?$e.find(se=>se.id===v.name):void 0,ze=(v==null?void 0:v.kind)==="installed"?H.find(se=>se.name===v.name):void 0,Ne=(v==null?void 0:v.kind)==="market"?k==null?void 0:k.plugins.find(se=>se.name===v.name):void 0,Ue=w&&!(ze&&ze.name===w.name)&&w.notes.length>0?w.notes:null,at=Je?n.jsx(WY,{staged:Je,onClose:()=>b(null),onInstalled:De,onInstallFirst:Ie,onGone:()=>{b(null),i.reload()}},Je.id):ze?n.jsx(eq,{plugin:ze,listing:U(ze),notes:(w==null?void 0:w.name)===ze.name?w.notes:null,canOpen:q(ze.name)&&ze.enabled!==!1,onOpen:()=>Y(ze.name),onClose:()=>b(null),onDisable:()=>x({kind:"disable",name:ze.name}),onEnable:()=>fe(ze.name),onRemove:()=>x({kind:"remove",name:ze.name}),onUpdate:se=>Oe(ze.name,se),onSettings:ze.enabled===!1?void 0:F(ze.name),firstStep:z(ze),busy:L}):Ne?n.jsx(oq,{entry:Ne,canOpen:Ne.installed!==void 0&&q(Ne.installed.name??Ne.name),onOpen:()=>{var se;return Y(((se=Ne.installed)==null?void 0:se.name)??Ne.name)},onClose:()=>b(null),onInstall:()=>$(A.stagePlugin(`${Ne.npm}@${Ne.version}`)),onUpdate:se=>{var be;return Oe(((be=Ne.installed)==null?void 0:be.name)??Ne.name,se)},busy:L}):null,Ye=j?H.find(se=>se.name===j.name):void 0,kt=j?n.jsx(tq,{kind:j.kind,name:j.name,canDisable:(Ye==null?void 0:Ye.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>Q(j.name,!1).then(()=>x(null)),onRemove:(se,be)=>ee(j.name,se,be).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return n.jsxs(le,{gap:"lg",children:[n.jsx(iN,{}),ne,n.jsx(ie,{message:u}),n.jsx(cq,{kind:p,onKind:g,navigate:s,market:k,loading:S,busy:L,onRetry:()=>T(!0),onOpen:se=>b({kind:"market",name:se.name}),onInstall:se=>$(A.stagePlugin(`${se.npm}@${se.version}`)),onUpdate:(se,be)=>{var Qe;return Oe(((Qe=se.installed)==null?void 0:Qe.name)??se.name,be)}}),at]});const Gt=(M==null?void 0:M.builtIn)??[];return n.jsxs(le,{gap:"lg",children:[n.jsx(iN,{}),ne,n.jsx(ie,{message:i.error??u??c}),M!=null&&M.unavailable?n.jsx(G,{tone:"warning",children:M.unavailable}):null,Ue?n.jsx(G,{role:"status",children:Ue.join(" ")}):null,n.jsx(FY,{trust:(M==null?void 0:M.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:R,onFailed:h}),ge?n.jsx(UY,{staged:ge,onInstalled:De,onGone:()=>i.reload(),onInstallFirst:Ie},ge.id):null,$e.length>0?n.jsx(Ge,{flush:!0,title:"Waiting for you",tool:Lr($e.length,"package","packages"),children:n.jsx("div",{className:"plugins-rows",children:n.jsx(rt,{children:$e.map(se=>n.jsx(BY,{staged:se,onReview:()=>{LR(se),b({kind:"staged",name:se.id})},onReject:()=>{h(null),A.rejectStaged(se.id).then(()=>i.reload()).catch(I)}},se.id))})})}):null,M!=null&&M.restartNeeded?n.jsx(VY,{checkout:D,waiting:H.filter(se=>se.loadsAtRestart)}):null,n.jsx(qY,{list:H,firstStepFor:z}),n.jsx(Ge,{flush:!0,title:"Installed",tool:M?Lr(H.length,"plugin","plugins"):void 0,children:M?H.length===0?n.jsx(pe,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(rt,{children:H.map(se=>n.jsx(QY,{plugin:se,listing:U(se),open:se.enabled===!1?void 0:B(se.name,"ghost"),canOpen:q(se.name)&&se.enabled!==!1,busy:L,onDetails:()=>b({kind:"installed",name:se.name}),onOpen:()=>Y(se.name),onSettings:se.enabled===!1?void 0:F(se.name),onDisable:()=>x({kind:"disable",name:se.name}),onEnable:()=>fe(se.name),onRemove:()=>x({kind:"remove",name:se.name}),onUpdate:be=>Oe(se.name,be),firstStep:z(se)},se.name))})}):n.jsx(pe,{children:"Loading…"})}),Gt.length>0?n.jsx(nq,{plugins:Gt,openFor:B}):null,at,kt]})}function FY({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=d.useState(PY),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(!1),w=d.useRef(null),y=C=>i(Ci(C)),k=C=>{l(C),MY(C),g(null)},N=()=>{h(!0),A.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Wu)){m(null),g(`${C.name} is not a ${Wu}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),A.uploadPlugin(C).then(T=>r(T.job.id)).catch(y).finally(()=>h(!1))}};return n.jsxs(Ge,{title:"Add a plugin",actions:n.jsx(Kt,{label:"Where it comes from",options:TR,value:a,onChange:k}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":v?"over":p?"refused":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var T,R;C.preventDefault(),b(!1),S((R=(T=C.dataTransfer)==null?void 0:T.files)==null?void 0:R[0])},children:[n.jsx(ce,{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:Wu})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(E,{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:Wu,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var T;S((T=C.target.files)==null?void 0:T[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{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(E,{onClick:()=>x(!0),children:"Browse…"}):null,n.jsx(E,{variant:"accent",disabled:s||u||o.trim()==="",onClick:N,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[RY[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(G,{tone:"warning",children:e})})]}),j?n.jsx(AY,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function _Y({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?Mw([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(we,{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 OR(e,t,s){const[r,i]=d.useState(e.plan??null),[a,l]=d.useState(!1),[o,c]=d.useState(null);return{plan:r,busy:a,failed:o,approve:f=>{l(!0),c(null),A.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?t(e.name):m.plan&&i(m.plan)}).catch(m=>c(Ci(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),A.rejectStaged(e.id).then(()=>s()).catch(f=>c(Ci(f))).finally(()=>l(!1))}}}function LR(e){e.openedAt||A.openedStaged(e.id).catch(()=>{})}function zY({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(we,{tone:"warning",children:"not installed"}),t?n.jsxs(E,{size:"sm",onClick:()=>t(s.plugin),children:["Install ",s.plugin," first"]}):null]}):n.jsx(we,{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(Ht,{items:[...e.author?[{label:"By",value:n.jsx(Ef,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Mx(e.source)},{label:"Published by",value:Pw(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Mx(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(_Y,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:n.jsx(zY,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:n.jsx(Dx,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(Dx,{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(Ht,{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 _R({plan:e,busy:t,onReject:s,onInstallAnyway:r}){return n.jsxs(cs,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(we,{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(E,{variant:"ghost",disabled:t,onClick:s,children:"Not this one"}),n.jsx(E,{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(zR,{unlocks:e.agents??[]})]})}function UY({staged:e,onInstalled:t,onGone:s,onInstallFirst:r}){const{plan:i,busy:a,failed:l,approve:o,reject:c}=OR(e,t,s);d.useEffect(()=>LR(e),[e.id]);const u=(i==null?void 0:i.drift)??[];return n.jsxs(le,{gap:"sm",children:[n.jsxs(cs,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(we,{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(E,{variant:"ghost",disabled:a,onClick:c,children:"Not this one"}),n.jsx(E,{variant:"accent",disabled:a||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[n.jsx(ie,{message:l}),n.jsx(FR,{staged:e,onInstallFirst:r})]}),i&&u.length>0?n.jsx(_R,{plan:i,busy:a,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function BY({staged:e,onReview:t,onReject:s}){const r=Le(e.createdAt);return n.jsx(et,{onClick:t,label:`${e.name}: review`,lead:n.jsx($n,{svg:void 0}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${IR(e.source)}${r?` · read ${r}`:""}`,side:n.jsxs("span",{className:"plugins-side",children:[n.jsxs("span",{className:"plugins-wait-extra",children:[n.jsx(we,{children:"read, not installed"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:Nl(s),children:"Not this one"})]}),n.jsx(E,{size:"sm",onClick:Nl(t),children:"Review"})]})})}function WY({staged:e,onClose:t,onInstalled:s,onGone:r,onInstallFirst:i}){const{plan:a,busy:l,failed:o,approve:c,reject:u}=OR(e,s,r),h=(a==null?void 0:a.drift)??[];return n.jsxs(qe,{title:n.jsx(Fw,{svg:void 0,name:e.name,version:e.version,by:e.author?n.jsx(Ef,{author:e.author}):Pw(e.source,e.publisher),pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(we,{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(E,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),n.jsx(E,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[n.jsx(ie,{message:o}),n.jsx(FR,{staged:e,inSheet:!0,onInstallFirst:i}),a&&h.length>0?n.jsx(_R,{plan:a,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const HY=10*60*1e3;function KY(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<HY?r.id:null}function VY({checkout:e,waiting:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null),l=sz(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(le,{gap:"sm",children:[n.jsx(ie,{message:i}),n.jsxs(G,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(E,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),of({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>A.serviceAction("restart")).catch(c=>a(Ci(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?IY:`${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 Ow="buddi.plugins.justInstalled";function GY(e){try{window.sessionStorage.setItem(Ow,e)}catch{}}function YY(){try{return window.sessionStorage.getItem(Ow)}catch{return null}}function qY({list:e,firstStepFor:t}){var u;const[s,r]=d.useState(()=>YY()),i=s?e.find(h=>h.name===s):void 0,a=i!==void 0&&(i.loaded||i.needs!==void 0),l=a&&(i.needs!==void 0||i.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(Ow)}catch{}r(null)};if(d.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(E,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?n.jsx(E,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:i.needs?`${i.name} is installed and waits. ${Lw(i)}.`:`${i.name} is loaded. First: ${((u=i.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const Nl=e=>t=>{t.stopPropagation(),e()},JY=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function Lw(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 QY({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=JY(e),v=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return n.jsx(et,{onClick:a,label:`${e.name}: details`,dimmed:p,lead:n.jsx($n,{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:[Lr(g,"agent","agents")," to accept"]}):null]}),sub:v?n.jsx("span",{className:"plugins-sub","data-tone":"warning",children:Lw(e)}):`by ${PR(e)} · from ${IR(e.source)} · ${RR(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[v&&m?n.jsx(E,{size:"sm",onClick:Nl(m.run),children:m.label}):null,t!=null&&t.update?n.jsxs(E,{size:"sm",disabled:i,onClick:Nl(()=>f(t.update)),children:["Update to ",t.update]}):null,v?null:s,!v&&!r&&o?n.jsx(E,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,n.jsx(DR,{plugin:e}),n.jsx(ja,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!i?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>f()}:null,p?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const XY={"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 zR({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(ue,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(rt,{children:t.map(s=>n.jsx(ZY,{plugin:e,unlock:s},s.id))})}),n.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",n.jsx("a",{href:mt,children:"on the Agents page"}),"."]})]})}function ZY({plugin:e,unlock:t}){const s=qj(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=XY[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(et,{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(we,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(E,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(ie,{message:s.failure}),s.created?n.jsx(iT,{agent:s.created}):null]})}function Fw({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx($n,{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 eq({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){var x,w;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",v=(t==null?void 0:t.summary)??e.description,b=(e.network??((w=(x=t==null?void 0:t.claims)==null?void 0:x.manifest)==null?void 0:w.network)??[]).map(y=>y.host),j=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(qe,{title:n.jsx(Fw,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(Ef,{author:e.author}):PR(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(Dw,{entry:t})]}):null," · ",n.jsx(DR,{plugin:e})]})}),onClose:o,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(dt,{}),l?n.jsx(E,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(E,{onClick:a,children:"Open"}):null,p?n.jsx(E,{onClick:u,children:"Enable"}):n.jsx(E,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(E,{variant:"accent",disabled:i,onClick:()=>f(t.update),children:["Update to ",t.update]}):n.jsx(E,{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(E,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",Lw(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(E,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,v?n.jsx("p",{className:"plugins-summary-full",children:v}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Ht,{items:[{label:"From",value:Mx(e.source)},...g?[]:[{label:"Published by",value:Pw(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(Dx,{value:e.integrity})},{label:"Installed",value:Le(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:RR(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:MR(b)}]:[],...j?[{label:"Reaches in buddi",value:Mw(j)}]:[]]})}),n.jsx(zR,{plugin:e.name,unlocks:e.unlocks})]})}function tq({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=j=>{m(!0),g(null),j().catch(x=>g(Ci(x))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Ft,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:f,onClick:()=>v(a),children:"Disable"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),n.jsx(ie,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Ft,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(E,{variant:"ghost",size:"sm",disabled:f,onClick:i,children:"Disable instead"}):null,n.jsx(dt,{}),n.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:f||!b,onClick:()=>v(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",t," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),n.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:j=>{c(j.target.checked),h("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(oe,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:j=>h(j.target.value)})}):null]}),n.jsx(ie,{message:p})]})}function nq({plugins:e,openFor:t}){return n.jsxs(At,{boxed:!0,summary:`Ships with buddi · ${Lr(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"),Lr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const sq=[{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 rq(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function iq({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 aq({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(cs,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx($n,{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(Dw,{entry:e}),e.installed?n.jsxs(we,{children:["installed ",e.installed.version]}):null,n.jsx(dt,{}),e.update?n.jsxs(E,{size:"sm",disabled:t,onClick:Nl(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(E,{size:"sm",variant:"accent",disabled:t,onClick:Nl(r),children:"Install"})]})]})}function lq(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 oq({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,v,b,j,x,w;const o=(m=e.screenshots)==null?void 0:m[0],c=(((g=(p=e.claims)==null?void 0:p.manifest)==null?void 0:g.network)??[]).map(y=>y.host),u=lq(e),h=((j=(b=(v=e.claims)==null?void 0:v.manifest)==null?void 0:b.agents)==null?void 0:j.length)??0,f=(w=(x=e.claims)==null?void 0:x.package)==null?void 0:w.dependencies;return n.jsxs(qe,{title:n.jsx(Fw,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(Ef,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(Dw,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(we,{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(E,{onClick:r,children:"Open"}):null,e.update?n.jsxs(E,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(E,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:A.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Ht,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Lr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:MR(c)},{label:"Reaches in buddi",value:Mw(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(iq,{pricing:e.pricing})]})}]})})]})}function cq({kind:e="all",onKind:t,navigate:s,market:r,loading:i,busy:a,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[h,f]=d.useState(""),[m,p]=d.useState("all"),g=(r==null?void 0:r.plugins)??[],v=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...sq.filter(y=>g.some(k=>k.category===y.value))],b=g.filter(y=>m==="recommended"&&(y.trust!=="by-buddi"||y.installed)||m!=="all"&&m!=="recommended"&&y.category!==m?!1:rq(y,h)),j=h.trim(),x=n.jsx("div",{className:"plugins-kind",children:n.jsx(Kt,{label:"Show",options:uq,value:e,onChange:y=>t==null?void 0:t(y)})}),w=e==="plugins"?null:n.jsx(dq,{kind:e,navigate:s});return e==="agents"?n.jsxs(le,{gap:"lg",children:[x,n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),w]}):n.jsxs(le,{gap:"lg",children:[x,n.jsxs(ae,{children:[n.jsx(xf,{grow:!0,label:"Search plugins",value:h,placeholder:"Search plugins: weather, money, calendar…",onChange:f}),n.jsx(yA,{label:"Show",options:v,value:m,onChange:p})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{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:i,onClick:l,children:"Refresh"})]}),r===null||i&&r.unavailable?n.jsx(pe,{children:"Asking withbuddi.com…"}):r.unavailable?n.jsx(G,{tone:"warning",action:n.jsx(E,{size:"sm",disabled:i,onClick:l,children:"Try again"}),children:r.unavailable}):n.jsxs(n.Fragment,{children:[r.stale?n.jsxs(G,{tone:"warning",action:n.jsx(E,{size:"sm",disabled:i,onClick:l,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",r.fetchedAt?` ${Le(r.fetchedAt)}`:" last time","."]}):null,b.length>0?n.jsx("div",{className:"plugins-grid",children:b.map(y=>n.jsx(aq,{entry:y,busy:a,onOpen:()=>o(y),onInstall:()=>c(y),onUpdate:k=>u(y,k)},y.npm))}):n.jsx(pe,{warm:!0,title:"Nothing listed matches",children:j!==""?`No plugin on withbuddi.com mentions “${j}”.`:g.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),w]})}const uq=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"agents",label:"Agents"}];function dq({kind:e,navigate:t}){const s=de(()=>A.catalogue(),[]),r=fw(),i=c=>t==null?void 0:t(c),a=s.data;if(!a)return s.error?n.jsx(G,{tone:"warning",children:s.error}):n.jsx(pe,{children:"Asking withbuddi.com…"});if(a.unavailable)return e==="agents"?n.jsx(G,{tone:"warning",children:a.unavailable}):null;const l=a.agents.filter(c=>Mi(c)==="ready"),o=e==="all"?l.slice(0,3):a.agents;return o.length===0?null:n.jsx(ue,{title:e==="all"?"Teammates":void 0,aside:n.jsx("a",{href:Bt(),onClick:c=>{c.preventDefault(),i(Bt())},children:e==="all"?`See all ${a.agents.length}`:"Open the catalogue"}),children:n.jsx("div",{className:"plugins-grid","data-testid":"browse-agents",children:o.map(c=>n.jsx(m$,{entry:c,loaded:r,onOpen:()=>i(Bt(c.name)),onAdd:()=>i(Bt(c.name)),onUpdate:()=>i(Bt(c.name))},c.name))})})}var Yc={},hq=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},UR={},ds={};let _w;const fq=[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];ds.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};ds.getSymbolTotalCodewords=function(t){return fq[t]};ds.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};ds.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');_w=t};ds.isKanjiModeEnabled=function(){return typeof _w<"u"};ds.toSJIS=function(t){return _w(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 BR(){this.buffer=[],this.length=0}BR.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 mq=BR;function qc(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)}qc.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};qc.prototype.get=function(e,t){return this.data[e*this.size+t]};qc.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};qc.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var pq=qc,WR={};(function(e){const t=ds.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}})(WR);var HR={};const gq=ds.getSymbolSize,aN=7;HR.getPositions=function(t){const s=gq(t);return[[0,0],[s-aN,0],[0,s-aN]]};var KR={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,h=null;for(let f=0;f<a;f++){o=c=0,u=h=null;for(let m=0;m<a;m++){let p=i.get(f,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,f),p===h?c++:(c>=5&&(l+=t.N1+(c-5)),h=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let h=0;h<a;h++)o=o<<1&2047|i.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const h=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),h<c&&(c=h,o=u)}return o}})(KR);var Tf={};const ai=Af,Hu=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],Ku=[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];Tf.getBlocksCount=function(t,s){switch(s){case ai.L:return Hu[(t-1)*4+0];case ai.M:return Hu[(t-1)*4+1];case ai.Q:return Hu[(t-1)*4+2];case ai.H:return Hu[(t-1)*4+3];default:return}};Tf.getTotalCodewordsCount=function(t,s){switch(s){case ai.L:return Ku[(t-1)*4+0];case ai.M:return Ku[(t-1)*4+1];case ai.Q:return Ku[(t-1)*4+2];case ai.H:return Ku[(t-1)*4+3];default:return}};var VR={},$f={};const _o=new Uint8Array(512),vh=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)_o[s]=t,vh[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)_o[s]=_o[s-255]})();$f.log=function(t){if(t<1)throw new Error("log("+t+")");return vh[t]};$f.exp=function(t){return _o[t]};$f.mul=function(t,s){return t===0||s===0?0:_o[vh[t]+vh[s]]};(function(e){const t=$f;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}})(VR);const GR=VR;function zw(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}zw.prototype.initialize=function(t){this.degree=t,this.genPoly=GR.generateECPolynomial(this.degree)};zw.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=GR.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 xq=zw,YR={},Di={},Uw={};Uw.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var wr={};const qR="[0-9]+",vq="[A-Z $%*+\\-./:]+";let Sc="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Sc=Sc.replace(/u/g,"\\u");const jq="(?:(?![A-Z0-9 $%*+\\-./:]|"+Sc+`)(?:.|[\r
|
|
125
|
+
]))+`;wr.KANJI=new RegExp(Sc,"g");wr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");wr.BYTE=new RegExp(jq,"g");wr.NUMERIC=new RegExp(qR,"g");wr.ALPHANUMERIC=new RegExp(vq,"g");const wq=new RegExp("^"+Sc+"$"),yq=new RegExp("^"+qR+"$"),bq=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");wr.testKanji=function(t){return wq.test(t)};wr.testNumeric=function(t){return yq.test(t)};wr.testAlphanumeric=function(t){return bq.test(t)};(function(e){const t=Uw,s=wr;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(a,l){if(!a.ccBits)throw new Error("Invalid mode: "+a);if(!t.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?a.ccBits[0]:l<27?a.ccBits[1]:a.ccBits[2]},e.getBestModeForData=function(a){return s.testNumeric(a)?e.NUMERIC:s.testAlphanumeric(a)?e.ALPHANUMERIC:s.testKanji(a)?e.KANJI:e.BYTE},e.toString=function(a){if(a&&a.id)return a.id;throw new Error("Invalid mode")},e.isValid=function(a){return a&&a.bit&&a.ccBits};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+i)}}e.from=function(a,l){if(e.isValid(a))return a;try{return r(a)}catch{return l}}})(Di);(function(e){const t=ds,s=Tf,r=Af,i=Di,a=Uw,l=7973,o=t.getBCHDigit(l);function c(m,p,g){for(let v=1;v<=40;v++)if(p<=e.getCapacity(v,g,m))return v}function u(m,p){return i.getCharCountIndicator(m,p)+4}function h(m,p){let g=0;return m.forEach(function(v){const b=u(v.mode,p);g+=b+v.getBitsLength()}),g}function f(m,p){for(let g=1;g<=40;g++)if(h(m,g)<=e.getCapacity(g,p,i.MIXED))return g}e.from=function(p,g){return a.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,v){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof v>"u"&&(v=i.BYTE);const b=t.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),x=(b-j)*8;if(v===i.MIXED)return x;const w=x-u(v,p);switch(v){case i.NUMERIC:return Math.floor(w/10*3);case i.ALPHANUMERIC:return Math.floor(w/11*2);case i.KANJI:return Math.floor(w/13);case i.BYTE:default:return Math.floor(w/8)}},e.getBestVersionForData=function(p,g){let v;const b=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,b);if(p.length===0)return 1;v=p[0]}else v=p;return c(v.mode,v.getLength(),b)},e.getEncodedBits=function(p){if(!a.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;t.getBCHDigit(g)-o>=0;)g^=l<<t.getBCHDigit(g)-o;return p<<12|g}})(YR);var JR={};const Lx=ds,QR=1335,kq=21522,lN=Lx.getBCHDigit(QR);JR.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Lx.getBCHDigit(i)-lN>=0;)i^=QR<<Lx.getBCHDigit(i)-lN;return(r<<10|i)^kq};var XR={};const Nq=Di;function Sl(e){this.mode=Nq.NUMERIC,this.data=e.toString()}Sl.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Sl.prototype.getLength=function(){return this.data.length};Sl.prototype.getBitsLength=function(){return Sl.getBitsLength(this.data.length)};Sl.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 Sq=Sl;const Cq=Di,op=["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 Cl(e){this.mode=Cq.ALPHANUMERIC,this.data=e}Cl.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};Cl.prototype.getLength=function(){return this.data.length};Cl.prototype.getBitsLength=function(){return Cl.getBitsLength(this.data.length)};Cl.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=op.indexOf(this.data[s])*45;r+=op.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(op.indexOf(this.data[s]),6)};var Eq=Cl;const Aq=Di;function El(e){this.mode=Aq.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}El.getBitsLength=function(t){return t*8};El.prototype.getLength=function(){return this.data.length};El.prototype.getBitsLength=function(){return El.getBitsLength(this.data.length)};El.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var Tq=El;const $q=Di,Rq=ds;function Al(e){this.mode=$q.KANJI,this.data=e}Al.getBitsLength=function(t){return t*13};Al.prototype.getLength=function(){return this.data.length};Al.prototype.getBitsLength=function(){return Al.getBitsLength(this.data.length)};Al.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=Rq.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]+`
|
|
126
|
+
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var Iq=Al,ZR={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,h,f,m,p,g,v,b;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],g=f+p,v=l[h],b=typeof l[h]>"u",(b||v>g)&&(l[h]=g,o.push(h,g),a[h]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var j=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(j)}return a},extract_shortest_path_from_predecessor_list:function(s,r){for(var i=[],a=r;a;)i.push(a),s[a],a=s[a];return i.reverse(),i},find_path:function(s,r,i){var a=t.single_source_shortest_paths(s,r,i);return t.extract_shortest_path_from_predecessor_list(a,i)},PriorityQueue:{make:function(s){var r=t.PriorityQueue,i={},a;s=s||{};for(a in r)r.hasOwnProperty(a)&&(i[a]=r[a]);return i.queue=[],i.sorter=s.sorter||r.default_sorter,i},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var i={value:s,cost:r};this.queue.push(i),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(ZR);var Pq=ZR.exports;(function(e){const t=Di,s=Sq,r=Eq,i=Tq,a=Iq,l=wr,o=ds,c=Pq;function u(j){return unescape(encodeURIComponent(j)).length}function h(j,x,w){const y=[];let k;for(;(k=j.exec(w))!==null;)y.push({data:k[0],index:k.index,mode:x,length:k[0].length});return y}function f(j){const x=h(l.NUMERIC,t.NUMERIC,j),w=h(l.ALPHANUMERIC,t.ALPHANUMERIC,j);let y,k;return o.isKanjiModeEnabled()?(y=h(l.BYTE,t.BYTE,j),k=h(l.KANJI,t.KANJI,j)):(y=h(l.BYTE_KANJI,t.BYTE,j),k=[]),x.concat(w,y,k).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,x){switch(x){case t.NUMERIC:return s.getBitsLength(j);case t.ALPHANUMERIC:return r.getBitsLength(j);case t.KANJI:return a.getBitsLength(j);case t.BYTE:return i.getBitsLength(j)}}function p(j){return j.reduce(function(x,w){const y=x.length-1>=0?x[x.length-1]:null;return y&&y.mode===w.mode?(x[x.length-1].data+=w.data,x):(x.push(w),x)},[])}function g(j){const x=[];for(let w=0;w<j.length;w++){const y=j[w];switch(y.mode){case t.NUMERIC:x.push([y,{data:y.data,mode:t.ALPHANUMERIC,length:y.length},{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.ALPHANUMERIC:x.push([y,{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.KANJI:x.push([y,{data:y.data,mode:t.BYTE,length:u(y.data)}]);break;case t.BYTE:x.push([{data:y.data,mode:t.BYTE,length:u(y.data)}])}}return x}function v(j,x){const w={},y={start:{}};let k=["start"];for(let N=0;N<j.length;N++){const S=j[N],C=[];for(let T=0;T<S.length;T++){const R=S[T],I=""+N+T;C.push(I),w[I]={node:R,lastCount:0},y[I]={};for(let L=0;L<k.length;L++){const W=k[L];w[W]&&w[W].node.mode===R.mode?(y[W][I]=m(w[W].lastCount+R.length,R.mode)-m(w[W].lastCount,R.mode),w[W].lastCount+=R.length):(w[W]&&(w[W].lastCount=R.length),y[W][I]=m(R.length,R.mode)+4+t.getCharCountIndicator(R.mode,x))}}k=C}for(let N=0;N<k.length;N++)y[k[N]].end=0;return{map:y,table:w}}function b(j,x){let w;const y=t.getBestModeForData(j);if(w=t.from(x,y),w!==t.BYTE&&w.bit<y.bit)throw new Error('"'+j+'" cannot be encoded with mode '+t.toString(w)+`.
|
|
127
|
+
Suggested mode is: `+t.toString(y));switch(w===t.KANJI&&!o.isKanjiModeEnabled()&&(w=t.BYTE),w){case t.NUMERIC:return new s(j);case t.ALPHANUMERIC:return new r(j);case t.KANJI:return new a(j);case t.BYTE:return new i(j)}}e.fromArray=function(x){return x.reduce(function(w,y){return typeof y=="string"?w.push(b(y,null)):y.data&&w.push(b(y.data,y.mode)),w},[])},e.fromString=function(x,w){const y=f(x,o.isKanjiModeEnabled()),k=g(y),N=v(k,w),S=c.find_path(N.map,"start","end"),C=[];for(let T=1;T<S.length-1;T++)C.push(N.table[S[T]].node);return e.fromArray(p(C))},e.rawSplit=function(x){return e.fromArray(f(x,o.isKanjiModeEnabled()))}})(XR);const Rf=ds,cp=Af,Mq=mq,Dq=pq,Oq=WR,Lq=HR,Fx=KR,_x=Tf,Fq=xq,jh=YR,_q=JR,zq=Di,up=XR;function Uq(e,t){const s=e.size,r=Lq.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 Bq(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 Wq(e,t){const s=Oq.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 Hq(e,t){const s=e.size,r=jh.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 dp(e,t,s){const r=e.size,i=_q.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 Kq(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 Vq(e,t,s){const r=new Mq;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),zq.getCharCountIndicator(c.mode,e)),c.write(r)});const i=Rf.getSymbolTotalCodewords(e),a=_x.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 Gq(r,e,t)}function Gq(e,t,s){const r=Rf.getSymbolTotalCodewords(t),i=_x.getTotalCodewordsCount(t,s),a=r-i,l=_x.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(a/l),f=h+1,m=u-h,p=new Fq(m);let g=0;const v=new Array(l),b=new Array(l);let j=0;const x=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:f;v[S]=x.slice(g,g+C),b[S]=p.encode(v[S]),g+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let y=0,k,N;for(k=0;k<j;k++)for(N=0;N<l;N++)k<v[N].length&&(w[y++]=v[N][k]);for(k=0;k<m;k++)for(N=0;N<l;N++)w[y++]=b[N][k];return w}function Yq(e,t,s,r){let i;if(Array.isArray(e))i=up.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=up.rawSplit(e);u=jh.getBestVersionForData(h,s)}i=up.fromString(e,u||40)}else throw new Error("Invalid data");const a=jh.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(`
|
|
128
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
129
|
+
Minimum version required to store current data is: `+a+`.
|
|
130
|
+
`);const l=Vq(t,s,i),o=Rf.getSymbolSize(t),c=new Dq(o);return Uq(c,t),Bq(c),Wq(c,t),dp(c,s,0),t>=7&&Hq(c,t),Kq(c,l),isNaN(r)&&(r=Fx.getBestMask(c,dp.bind(null,c,s))),Fx.applyMask(r,c),dp(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}UR.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=cp.M,i,a;return typeof s<"u"&&(r=cp.from(s.errorCorrectionLevel,cp.M),i=jh.from(s.version),a=Fx.from(s.maskPattern),s.toSJISFunc&&Rf.setToSJISFunction(s.toSJISFunc)),Yq(t,i,r,a)};var eI={},Bw={};(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),h=a.margin*c,f=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,v=a.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const b=Math.floor((m-h)/c),j=Math.floor((p-h)/c);v=f[o[b*l+j]?1:0]}r[g++]=v.r,r[g++]=v.g,r[g++]=v.b,r[g]=v.a}}})(Bw);(function(e){const t=Bw;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const h=t.getImageWidth(a.modules.size,c),f=u.getContext("2d"),m=f.createImageData(h,h);return t.qrToImageData(m.data,a,c),s(f,u,h),f.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(h,f.quality)}})(eI);var tI={};const qq=Bw;function oN(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function hp(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function Jq(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?hp("M",c+s,.5+u+s):hp("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=hp("h",l),l=0)):i++}return r}tI.render=function(t,s,r){const i=qq.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+oN(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+oN(i.color.dark,"stroke")+' d="'+Jq(l,a,i.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
131
|
+
`;return typeof r=="function"&&r(null,m),m};const Qq=hq,zx=UR,nI=eI,Xq=tI;function Ww(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!Qq())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(i=s,s=t,t=r=void 0):l===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=s,s=t,t=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=t,t=r=void 0):l===2&&!t.getContext&&(r=s,s=t,t=void 0),new Promise(function(c,u){try{const h=zx.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=zx.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}Yc.create=zx.create;Yc.toCanvas=Ww.bind(null,nI.render);Yc.toDataURL=Ww.bind(null,nI.renderToDataURL);Yc.toString=Ww.bind(null,function(e,t,s){return Xq.render(e,s)});async function Zq(e){const t=await Yc.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const cN=10*6e4,eJ=2e3;function Hw(e,t){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),h=d.useRef(e);h.current=e;const f=d.useRef(t);f.current=t;const m=d.useCallback(async()=>{const p=await A.telegramPairing();r(p),u(!1),o(!1),a(await Zq(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+cN,Date.now()+cN),v=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}h.current().then(b=>{var j;p||!b||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},eJ);return()=>{p=!0,window.clearInterval(v)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function Kw({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 sI=new Set(["approval","question"]),xd={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."}},tJ=new Set(["agent"]),nJ={maxUrgency:"now",muted:[]};function sJ(e,t){var i;const s=xd[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 rJ({timezone:e}){var j,x,w;const t=de(()=>A.notificationSettings(),[]),s=de(()=>A.agents(),[]),r=de(()=>A.notifications(20),[],3e4),i=d.useRef(!1);d.useEffect(()=>{var y,k;i.current||!r.data||window.location.hash!==Og||(i.current=!0,(k=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||k.call(y,{block:"start"}))},[r.data]);const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=((j=t.data)==null?void 0:j.channels)??[],g=a??((x=t.data)==null?void 0:x.settings),v=y=>{g&&(h(!1),l({...g,...y}))},b=()=>{g&&(c(!0),h(!1),m(null),A.saveNotificationSettings(g).then(()=>{h(!0),l(null),t.reload()}).catch(y=>m(y instanceof ve?y.message:String(y))).finally(()=>c(!1)))};return n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(E,{variant:"accent",disabled:o||!g,onClick:b,children:"Save"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ie,{message:t.error??f}),n.jsx(ue,{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:Pe("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(le,{gap:"sm",children:[p.map(y=>{var k;return n.jsx(dJ,{channel:y,checked:(g.defaultChannel??((k=p[0])==null?void 0:k.kind))===y.kind,onPick:()=>v({defaultChannel:y.kind})},y.kind)}),p.some(y=>y.kind==="telegram")?null:n.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",n.jsx("a",{href:Pe("telegram"),children:"Set up Telegram"})]})]}):n.jsx(pe,{children:"Loading…"})}),n.jsx(ue,{title:"By kind",children:g?n.jsxs(le,{gap:"sm",children:[dL.filter(y=>!tJ.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:xd[y].label}),n.jsx("span",{className:"ui-field-hint",children:xd[y].hint})]}),n.jsxs("select",{"aria-label":xd[y].label,value:hJ(g,y,p),onChange:k=>{const N={...g.perKind};k.target.value==="default"?delete N[y]:N[y]=k.target.value,v({perKind:N})},children:[n.jsx("option",{value:"default",children:"Default"}),p.map(k=>n.jsx("option",{value:k.kind,children:k.label},k.kind)),sI.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(ue,{title:"Messages from your agents",children:g?n.jsx(iJ,{settings:g,agents:((w=s.data)==null?void 0:w.agents)??[],onChange:v}):null}),n.jsx(ue,{title:"Focus schedules",children:g?n.jsxs(le,{gap:"sm",children:[n.jsx(pJ,{schedules:g.schedules,onChange:y=>v({schedules:y})}),n.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(oe,{label:"End of the day",children:n.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>v({endOfDay:y.target.value})})})}),n.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),u?n.jsx(G,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(aJ,{}),n.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:n.jsxs(ue,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(ie,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(pe,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(rt,{children:r.data.notifications.map(y=>{var k;return n.jsx(et,{title:dc(y),sub:`${nt(y.createdAt,e)} · ${sJ(y,((k=s.data)==null?void 0:k.agents)??[])} · ${fJ(y,p)}`,side:n.jsx(mJ,{row:y})},y.id)})}):n.jsx(pe,{children:"Loading…"})]})})]})}function iJ({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??nJ,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(le,{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 aJ(){var u;const e=de(()=>A.tipsSettings(),[]),[t,s]=d.useState(!1),[r,i]=d.useState(null),[a,l]=d.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),i(null),l(h),A.saveTipsSettings(h).then(f=>l(f.enabled)).catch(f=>{l(!h),i(f instanceof ve?f.message:String(f))}).finally(()=>s(!1))};return n.jsx(ue,{title:"Tips",panel:!0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:h=>c(h.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx("p",{className:"ui-field-hint",children:"When something in buddi has gone unused, Home may say so in one sentence, at most once a day."})]})})}function lJ({timezone:e}){return n.jsx(oJ,{timezone:e,onChange:()=>{}})}function oJ({timezone:e,onChange:t}){var C,T;const s=de(()=>A.telegramBot(),[]),r=de(()=>A.telegramDevices(),[]),[i,a]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(null),g=d.useRef(new Set),v=Hw(()=>A.telegramDevices().then(R=>R.devices.some(I=>!g.current.has(I.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,j=!b||i,x=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const R=i&&(((I=s.data)==null?void 0:I.running)??!1);A.saveTelegramToken(l.trim()).then(L=>{o(""),a(!1),f(L.restartNeeded?{ok:!1,text:L.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(L=>f({ok:!1,text:L instanceof ve?L.message:String(L)})).finally(()=>u(!1))},w=()=>{var R;p(null),g.current=new Set((((R=r.data)==null?void 0:R.devices)??[]).map(I=>I.id)),v.ask().catch(I=>p(I instanceof ve?I.message:String(I)))},{offer:y,square:k,paired:N,stale:S}=v;return n.jsx(ue,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{title:"The bot",foot:j?n.jsxs(n.Fragment,{children:[i?n.jsx(E,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(E,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:s.error}),!s.data&&!s.error?n.jsx(pe,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:(T=s.data)!=null&&T.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(E,{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(oe,{label:"Bot token",grow:!0,children:n.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:R=>o(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),x())}})})]}):null,h?n.jsx(G,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),n.jsxs(ue,{title:"Your devices",children:[n.jsx(ie,{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(rt,{children:r.data.devices.map(R=>n.jsx(et,{title:R.name??`Telegram user ${R.userId}`,sub:`Paired ${nt(R.pairedAt,e)} · ${R.lastSeenAt?`last spoke ${Le(R.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(cJ,{id:R.id,onGone:()=>{r.reload(),t()}})},R.id))}):r.error?null:n.jsx(pe,{children:"Loading…"})]}),n.jsx(ue,{title:"Pair a device",foot:b&&(!y||N)?n.jsx(E,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):b&&S?n.jsx(E,{variant:"accent",onClick:w,children:"New code"}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:m}),b?N?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(Kw,{offer:y,square:k,children:n.jsx(uJ,{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 cJ({id:e,onGone:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(!1),[l,o]=d.useState(null);if(!s)return n.jsx(E,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),A.unpairTelegramDevice(e).then(t).catch(u=>o(u instanceof ve?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(E,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(E,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function uJ({text:e}){const[t,s]=d.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(E,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function dJ({channel:e,checked:t,onPick:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof ve?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(E,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function hJ(e,t,s){const r=e.perKind[t];return r==="off"?sI.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function fJ(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 mJ({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 uN={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},dN={mode:"do-not-disturb",days:[...Cg],from:"22:00",to:"07:00"};function pJ({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(le,{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:Cg.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${uN[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Cg.filter(c=>c===l||r.days.includes(c))}),children:uN[l]},l)})}),n.jsx(oe,{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(oe,{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(E,{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(E,{size:"sm",onClick:()=>t([...e,{...dN,days:[...dN.days]}]),children:"Add a schedule"})})]})}const gJ={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 xJ(e){const t=y4.map(r=>({id:r.id,route:Pe(r.id),label:r.label,icon:gJ[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:WE(r.plugin,r.id),route:Kr(r.plugin,r.id),label:r.title,icon:MT(r.icon),group:"plugins"}));return[...t,...s]}function rI(e){return w4.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function iI(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function vJ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=d.useRef(null),l=rI(e),o=e.some(h=>h.id===t)?t:(u=e[0])==null?void 0:u.id,c=h=>{var g;const f=[...((g=a.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=v=>{var b;h.preventDefault(),(b=f[Math.max(0,Math.min(f.length-1,v))])==null||b.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(f.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const v=f[m].getAttribute("href");v&&i(v)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(h=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(f=>{const m=f.id===t,p=s[f.id],g=r[f.id];return n.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":iI(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:v=>{v.preventDefault(),i(f.route)},children:[n.jsx(ce,{name:f.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:f.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},h.id))})}function jJ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=rI(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Lc,{modal:!1,children:[n.jsx(Fc,{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(ce,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(ce,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(_l,{children:n.jsx(_c,{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(FE,{children:[c>0?n.jsx(Rr,{className:"ui-menu-sep"}):null,n.jsx(ca,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=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":iI(u.label,h,f),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(ce,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):f?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function wJ({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var x,w,y;const a=b4(e),l=IA(i!==void 0),o=i??l,c=c4(e),u=c?o.find(c.plugin,c.page):void 0,h=bs(Ij),f=xJ(o.settings),p={proposals:((w=(x=de(()=>Promise.resolve().then(()=>A.proposals()),[],3e4).data)==null?void 0:x.open)==null?void 0:w.length)??0},g=de(()=>A.version(),[]),v=de(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((y=v.data)==null?void 0:y.signals)??[]).length>0&&(b.connections=QT);const j={entries:f,active:a,counts:p,dots:b,navigate:k=>s(k)};return n.jsxs("div",{className:"settings",children:[h?null:n.jsx(vJ,{...j}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="secrets"?n.jsx(wl,{before:n.jsx(Zd,{inline:!0,items:[{label:"Settings",href:sn,onClick:()=>s(sn)}]}),title:"Keys and secrets",lede:yR,actions:n.jsx(Et,{variant:"accent",size:"sm",href:uk,onClick:k=>{k.preventDefault(),s(uk)},children:"Add a secret"})}):a==="plugins"||a==="connections"?n.jsx(wl,{before:n.jsx(Zd,{inline:!0,items:[{label:"Settings",href:sn,onClick:()=>s(sn)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?TY:D$}):n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Settings"}),n.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),h?n.jsx(jJ,{...j}):null,u?n.jsx(EW,{page:u,params:BE(e),navigate:s,timezone:t,siblings:o.all.filter(k=>k.plugin===u.plugin)}):null,a==="you"?n.jsx(lY,{embedded:!0}):null,a==="appearance"?n.jsx(yJ,{railPages:o.rail}):null,a==="notifications"?n.jsx(rJ,{timezone:t}):null,a==="telegram"?n.jsx(lJ,{timezone:t}):null,a==="memory"?n.jsx(p$,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(yY,{embedded:!0,plugin:x4(e)}):null,a==="accounts"?n.jsx(J7,{embedded:!0,account:u4(e)}):null,a==="computer"?n.jsx(WB,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(OG,{embedded:!0,timezone:t,secret:h4(e),adding:f4(e),navigate:s}):null,a==="connections"?n.jsx(XV,{embedded:!0,timezone:t,connection:d4(e)}):null,a==="lock"?n.jsx(nY,{navigate:s}):null,a==="api"?n.jsx(aY,{timezone:t}):null,a==="watchers"?n.jsx(VG,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(W7,{}):null,a==="plugins"?n.jsx(LY,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(NJ,{timezone:t}):null]})})]})}function yJ({railPages:e}){const[t,s]=r$();return n.jsx(ue,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsx(fp,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(Kt,{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(fp,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(Kt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(fp,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(Kt,{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(kJ,{pages:e}),n.jsx(bJ,{})]})})}function bJ(){var c,u,h;const e=de(()=>A.overview(),[]),[t,s]=d.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],i=((u=e.data)==null?void 0:u.home)??[],a=((h=e.data)==null?void 0:h.dismissed)??{};if(r.length===0&&i.length===0)return null;const l=(f,m)=>{s(f),A.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),A.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(le,{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(le,{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 kJ({pages:e}){const t=XT(),[s,r]=d.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),lK(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(le,{gap:"sm",children:[n.jsx(ie,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Nc(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Nc(a)))]})]})}function fp({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 NJ({timezone:e}){const t=de(()=>A.overview(),[],15e3),s=de(()=>A.session(),[]),r=de(()=>A.providerAccounts(),[]),i=t.data;return n.jsxs(le,{gap:"lg",children:[n.jsx(ie,{message:t.error}),n.jsx(LJ,{}),i?n.jsx(ue,{title:"The queue",panel:!0,actions:n.jsx(E,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{A.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(we,{tone:"warning",children:"paused"}):n.jsx(we,{tone:"good",children:"running"})]})}):null,n.jsxs(ue,{title:"This host",panel:!0,children:[n.jsx(Ht,{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?AJ(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(EJ,{}),n.jsx(LW,{}),n.jsx(SJ,{}),n.jsx(ue,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(pe,{children:"No sources are installed."}):n.jsx(Ht,{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 ",Le(a.lastRunAt)]})}))}):n.jsx(pe,{children:"Loading…"})})]})}function SJ(){var p;const e=de(()=>A.tailscale(),[]),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=e.data,h=t??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),f=(u==null?void 0:u.proxied)===!0,m=g=>{i(!0),l(null),c(!1),A.setTailscale({enabled:g,login:h.trim()}).then(()=>{c(!0)}).catch(v=>l(v instanceof ve?v.message:String(v))).finally(()=>{i(!1),e.reload()})};return n.jsx(ue,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(E,{variant:"accent",disabled:r||!u||f,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(le,{divided:!0,children:n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{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 ${h}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||f,onChange:g=>m(g.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(oe,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:h,placeholder:"you@example.com",disabled:r||!u||f,onChange:g=>s(g.target.value)})}),n.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),n.jsxs("div",{className:"tailscale-command",children:[n.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),n.jsx(E,{size:"sm",disabled:r||!u,onClick:()=>{CJ((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 CJ(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function EJ(){var u;const e=de(()=>A.service(),[],1e4),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{i(!0),l(null),of({kind:h},()=>A.serviceAction(h)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{i(!1)})};return n.jsx(ue,{title:"Service",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsx(Ht,{items:[{label:"Database",value:n.jsx(hN,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(hN,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{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(E,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(E,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(E,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function hN({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(we,{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 AJ(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const TJ=2e3,wh={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."},$J=new Set(["done","failed","rolled-back"]),RJ="The check asks the npm registry for the newest version and sends nothing else.",IJ="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",PJ="A checkout upgrades with git pull, then buddi upgrade in a terminal.",MJ=15*6e4;function DJ(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 fN(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<MJ?s:null}function OJ(e,t){const[s,r]=d.useState(void 0),[i,a]=d.useState(null),l=d.useRef(t);return l.current=t,d.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||A.upgradeJob(e).then(f=>{var m;o||(r(f),a(null),QE({step:wh[f.phase]??f.detail??f.phase}),($J.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(jl(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof ve&&f.status!==0&&f.status<500?(o=!0,jl(),a(f.message)):c=!0)})};u();const h=window.setInterval(u,TJ);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:i}}function LJ(){const e=de(()=>A.version(),[]),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(null),f=d.useCallback(j=>{s(null),h(j)},[]),m=OJ(t,f),p=e.data,g=()=>{l(!0),c(null),A.checkVersion().catch(j=>c(j instanceof ve?j.message:String(j))).finally(()=>{l(!1),e.reload()})},v=j=>{l(!0),c(null),A.setVersionCheck(j).catch(x=>c(x instanceof ve?x.message:String(x))).finally(()=>{l(!1),e.reload()})},b=()=>{l(!0),c(null),h(null),of({kind:"upgrade",line:p!=null&&p.latest?`Upgrading to ${p.latest}…`:"Upgrading…",step:wh.starting,patienceMs:JE},()=>A.startUpgrade(p==null?void 0:p.latest)).then(j=>{var x;i(!1),s(((x=j==null?void 0:j.job)==null?void 0:x.id)??null)}).catch(j=>c(j instanceof ve?j.message:String(j))).finally(()=>l(!1))};return p!=null&&p.checkout?n.jsx(ue,{title:"Version",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsx(Ht,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:p.current})}]})}),n.jsx(ue,{children:n.jsx("p",{className:"ui-card-meta",children:PJ})})]})}):n.jsx(ue,{title:"Version",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{message:e.error??o}),n.jsx(Ht,{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 ",Le(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(E,{disabled:a,onClick:g,children:"Check now"})})]})}),n.jsx(ue,{children:n.jsxs(le,{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=>v(j.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:RJ})]})}),p!=null&&p.updateAvailable&&p.latest&&p.latestNotes?n.jsx(ue,{title:`What changes in ${p.latest}`,children:n.jsx(fr,{text:p.latestNotes})}):null,n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(FJ,{...m,job:m.job??u??void 0}),!m.job&&!u&&!m.error&&p&&fN(p.history)?n.jsx(G,{tone:"critical",role:"alert",children:DJ(fN(p.history))}):null,r?n.jsx(G,{tone:"warning",role:"alert",children:IJ}):null,n.jsx(ae,{align:"end",children:r?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:a,onClick:()=>i(!1),children:"Cancel"}),n.jsxs(E,{variant:"accent",disabled:a,onClick:b,children:["Upgrade to ",p==null?void 0:p.latest]})]}):n.jsx(E,{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(ue,{title:"Upgrades so far",children:n.jsx(Ht,{items:p.history.slice().reverse().map(j=>({key:j.startedAt,label:n.jsxs("span",{className:"mono",children:[j.from," → ",j.to]}),value:n.jsx(_J,{attempt:j})}))})}):null]})})}function FJ({job:e,error:t}){return t?n.jsx(ie,{message:t}):e?e.phase==="failed"?n.jsxs(G,{tone:"critical",role:"alert",children:[wh.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:wh[e.phase]??e.detail??e.phase}):null}function _J({attempt:e}){return n.jsxs("span",{children:[n.jsx(we,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Le(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 yh=["hello","brain","takeOn","reach","assistant","handover"],aI={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function lI(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function zJ(e){var a,l,o;const t=lI(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 oI(e){var a,l,o,c,u;const t=zJ(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 cI(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 vd(e){return yh.find(t=>!cI(e,t))??"handover"}function UJ(e){const t=yh.indexOf(e);return t>0?yh[t-1]:null}function mN(e,t,s){return s===t?"now":cI(e,s)?"done":"todo"}function BJ(e,t){return{...e}}const Ux="buddi.firstRun.restore";function Bx(e){try{e===null?window.sessionStorage.removeItem(Ux):window.sessionStorage.setItem(Ux,e)}catch{}}function uI(){try{return window.sessionStorage.getItem(Ux)}catch{return null}}function WJ(e){const t=oI(e),s=vd(t);return{answers:t,open:s,stay:s!=="handover"}}function HJ(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function KJ(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 VJ=6e4,GJ=5*6e4,dI=1500,YJ=2e3,qJ="(max-width: 720px)";function ql(){const e=d.useRef(null);return d.useEffect(()=>{let t=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const Vw=d.createContext({busy:0,report:()=>{}});function JJ({children:e}){const[t,s]=d.useState(0),r=d.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=d.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(Vw.Provider,{value:i,children:e})}function ht({children:e}){const{busy:t}=d.useContext(Vw);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Hc,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function it({children:e}){return n.jsx(n.Fragment,{children:e})}function Ks({line:e}){const{report:t}=d.useContext(Vw);return d.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const Gw=d.createContext(null);function Xt({children:e,actions:t}){const s=d.useContext(Gw),r=t==null?null:s?Pl.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 rs({onClick:e,disabled:t}){return n.jsxs(E,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ce,{name:"chevron-left"}),_.back]})}function Jl({children:e,onClick:t,disabled:s}){return n.jsxs(E,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ce,{name:"arrow"})]})}function QJ({navigate:e,timezone:t}){var mn,Vn,Z,Re,Xe,xt,V;const s=bs(qJ),[r,i]=d.useState(void 0);d.useEffect(()=>{A.session().then(he=>i(he.platform)).catch(()=>{})},[]);const[a,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[f,m]=d.useState(void 0),[p,g]=d.useState([]),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[T,R]=d.useState(null),[I,L]=d.useState(null),[W,$]=d.useState(()=>uI()?"running":"idle"),[P,O]=d.useState({}),[M,D]=d.useState([]),[H,U]=d.useState(0),q=d.useRef(void 0),[B,Y]=d.useState(null),F=d.useCallback(()=>{Promise.resolve().then(()=>A.takeOnProgress()).then(he=>{he&&Array.isArray(he.plugins)&&Y(he)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(B!=null&&B.running))return;const he=window.setInterval(F,YJ);return()=>window.clearInterval(he)},[B==null?void 0:B.running,F]);const X=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),Q=d.useRef(e);Q.current=e;const ee=d.useCallback(async(he=!0,Be=!1)=>{var Gn,Dn,Vs,Xl,Oi,On,Li,yr,Jr;const[_e,en,Es,kn,As,Ts]=await Promise.all([A.onboarding().catch(()=>{}),A.owner().catch(()=>{}),A.providerAccounts().catch(()=>{}),He.agents().catch(()=>{}),A.browser().catch(()=>{}),A.providers().catch(()=>{})]);h(Es);const ke=(Dn=(Gn=Ts==null?void 0:Ts.providers.find(_t=>_t.kind==="anthropic"))==null?void 0:Gn.defaultModel)==null?void 0:Dn.trim();m(ke||void 0),g((en==null?void 0:en.zones)??[]),N(((Vs=_e==null?void 0:_e.details)==null?void 0:Vs.conversationId)??null);const Ee=(kn==null?void 0:kn.agents.find(_t=>_t.id===kn.defaultAgentId))??(kn==null?void 0:kn.agents[0]);Ee&&b(Ee),C(_e&&!_e.needs.agent&&Ee?{id:Ee.id,name:Ee.name,avatar:((Xl=Ee.avatar)==null?void 0:Xl.kind)==="emoji"?Ee.avatar.value:"",description:Ee.description,...Ee.picture?{picture:Ee.picture}:{}}:null),Array.isArray((Oi=_e==null?void 0:_e.details)==null?void 0:Oi.takeOn)&&F();const We={onboarding:_e,owner:en,accounts:Es,browser:(On=As==null?void 0:As.browser)==null?void 0:On.engine,...Ee?{assistant:{id:Ee.id,name:Ee.name,avatar:((Li=Ee.avatar)==null?void 0:Li.kind)==="emoji"?Ee.avatar.value:""}}:{}};if(Be){const _t=WJ(We);if(l(_t.answers),c(_t.open),!_t.stay){const Gs=(yr=_e==null?void 0:_e.details)==null?void 0:yr.conversationId;Q.current(Gs&&Ee?st(Ee.id,Gs):cn,!0)}return}if(he&&(_e==null?void 0:_e.state)==="done"){const _t=(Jr=_e.details)==null?void 0:Jr.conversationId;Q.current(_t&&Ee?st(Ee.id,_t):cn,!0);return}if(!he)return;const me=oI(We);l(me),c(_t=>_t??vd(me))},[]);d.useEffect(()=>{ee()},[ee]);const fe=(he,Be={})=>{Promise.resolve().then(()=>A.onboardingStep(aI[he],Be)).catch(()=>{})},Oe=he=>vd(he)==="brain"&&P.brain?{...he,brain:P.brain}:he,Ie=(he,Be)=>{const _e=Oe(Be);_e.brain&&(q.current=_e.brain),x(null),D([]),l(_e),he==="brain"&&_e.brain?fe(he,{accountId:_e.brain.accountId}):he==="reach"?fe(he,_e.reach?{reach:_e.reach}:{}):he!=="takeOn"&&fe(he),c(vd(_e))},Fe=(he,Be)=>{x(null),l(Be),Be.brain&&(q.current=Be.brain),he==="brain"&&Be.brain&&fe(he,{accountId:Be.brain.accountId})},z=he=>{x(null),l(Be=>BJ(Be)),c(he)},ne=()=>{if(!o)return;const he=UJ(o==="handover"?"handover":o);he&&z(he)},J=()=>{const he=a.brain??q.current,Be=((B==null?void 0:B.plugins)??[]).filter(_e=>_e.state==="ready").map(_e=>_e.title);x(null),O({}),D([]),l({}),c("hello"),U(_e=>_e+1),(async()=>{var ke;const[_e,en,Es]=await Promise.all([Promise.resolve().then(()=>A.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>A.telegram()).catch(()=>{}),Promise.resolve().then(()=>A.browser()).catch(()=>{})]),kn=lI(_e),As=he&&kn.some(Ee=>Ee.id===he.accountId)?he:void 0;_e&&h(_e),O(As?{brain:As}:{});const Ts=[...new Set(kn.map(Ee=>Ee.label)),...en!=null&&en.paired?[_.startOver.telegram]:[],...((ke=Es==null?void 0:Es.browser)==null?void 0:ke.engine)==="chromium"?[_.startOver.browser]:[],...Be];D(Ts.length>0?[_.startOver.said(Ts.join(", "))]:[])})()},ye=()=>{y(!0),A.skipOnboarding().then(()=>e(cn)).catch(he=>x(he instanceof ve?he.message:String(he))).finally(()=>y(!1))},ge=de(()=>A.version().catch(()=>({current:""})),[]),$e=d.useRef(null);d.useEffect(()=>{$e.current&&($e.current.scrollTop=0)},[o]);const De=W==="running",Je=Object.keys(a).length===0,ze={answers:a,accounts:u,claudeModel:f,zones:p,browserZone:X,assistantAgent:v,met:k,onMet:N,existing:S,progress:B,onProgress:F,navigate:e,onSettled:he=>o&&Ie(o,he),onKept:he=>o&&Fe(o,he),onBack:ne,onTrouble:x,onReload:()=>void ee(!1),onPickAnotherBrain:()=>z("brain"),onSpoken:L},Ne=(a.takeOn??[]).map(he=>{var Be;return((Be=Mo.find(_e=>_e.id===he))==null?void 0:Be.title)??he}),Ue=(B==null?void 0:B.plugins)??[],at=Ue.filter(he=>he.state==="ready").length,Ye=Ue.length===0?null:B!=null&&B.running?_.takeOn.installing(at,Ue.length):at===Ue.length?_.takeOn.installed:null,kt=[(mn=a.reach)!=null&&mn.phone?_.reach.done.phone:null,(Vn=a.reach)!=null&&Vn.mailbox?_.reach.done.mailbox:null,(Z=a.reach)!=null&&Z.app||(Re=a.reach)!=null&&Re.browser?_.reach.done.app:null].filter(he=>he!==null),Gt={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(Ne),sub:Ye},reach:{answer:_.reach.answer(kt)},assistant:{answer:((xt=a.assistant)==null?void 0:xt.name)??""}},se=yh.filter(he=>he!=="handover"),be=o===null||o==="handover"?se.length:se.indexOf(o),Qe=Math.min(be,se.length-1),ct=I?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:ye,children:_.later}),o==="hello"&&Je&&W==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>$("form"),children:_.restore.offer}):!De&&o!==null&&!(o==="hello"&&Je)?n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:J,children:_.startOver.link}):null]}),yt=r===void 0||r==="darwin"?_.tagline:_.taglineElsewhere,ut=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:_.count(be+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(Gw.Provider,{value:T,children:n.jsx(JJ,{children:n.jsxs(kA,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:$e,"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(xc,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?_.count(be+1):void 0,children:se.map(he=>n.jsx("i",{"data-state":mN(a,o,he)},he))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?_.strip(be+1,_.chapters[be]??""):_.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(xc,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:yt}),(V=ge.data)!=null&&V.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",ge.data.current]}):null]})]}),se.map((he,Be)=>{const _e=De?he==="hello"?"now":"todo":mN(a,o,he),en=Gt[he];return n.jsxs("div",{className:"wiz-ch","data-state":_e,"aria-current":_e==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":_e,children:_e==="done"?n.jsx(ce,{name:"check",size:12}):Be+1}),n.jsxs("span",{className:"wiz-ch-label",children:[_e==="done"?en.answer:_.chapters[Be],_e==="done"&&en.sub?n.jsx("span",{className:"wiz-ch-sub",children:en.sub}):null]}),_e==="done"&&!De?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>z(he),children:_.change}):null]},he)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:_.mapNotes[Qe]}),ct]}),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(AU,{dock:n.jsxs(n.Fragment,{children:[ut,n.jsx("div",{className:"wiz-dock-actions",ref:R})]}),children:[De?n.jsx(CQ,{onDone:he=>{$("idle"),D([...he?[_.restore.welcome(he)]:[],_.restore.keys]),ee(!0,!0)},onFailed:he=>{$("idle"),x(he)}}):o==="hello"?n.jsx(XJ,{...ze}):o==="brain"?n.jsx(eQ,{...ze}):o==="takeOn"?n.jsx(gQ,{...ze}):o==="reach"?n.jsx(xQ,{...ze}):o==="assistant"?n.jsx(bQ,{...ze}):o==="handover"?n.jsx(kQ,{...ze}):n.jsx(Ks,{}),M.length>0||j?n.jsxs(it,{children:[M.map(he=>n.jsx(ht,{children:he},he)),j?n.jsx(ht,{children:j}):null]}):null]},`${H}-${o??""}-${De?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:ct}):null]})})]})}),W==="form"?n.jsx(SQ,{onCancel:()=>$("idle"),onStarted:()=>$("running"),onTrouble:x}):null]})})})}function Ql({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function pN(e){try{return Vt(new Date,e)}catch{return""}}function XJ({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=ql(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,f]=d.useState(!1),[m,p]=d.useState(!1),g=()=>{const v=l.trim();v===""||m||(p(!0),A.setOwner({preferredName:v,timezone:c}).then(()=>r({...e,name:v,clock:c})).catch(b=>i(b instanceof ve?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.hello.title}),n.jsx(it,{children:_.hello.opening.map(v=>n.jsx(ht,{children:v},v))}),n.jsxs(Xt,{actions:n.jsx(Jl,{onClick:g,disabled:m||l.trim()==="",children:_.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(oe,{label:_.name.label,children:n.jsx("input",{ref:a,placeholder:_.name.placeholder,maxLength:80,value:l,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}})}),h?n.jsx(oe,{label:_.clock.label,hint:_.clock.hint(pN(c)),children:n.jsx("select",{value:c,onChange:v=>u(v.target.value),children:(t.includes(c)?t:[c,...t]).map(v=>n.jsx("option",{value:v,children:v},v))})}):n.jsx(oe,{label:_.clock.label,hint:_.clock.hint(pN(c)),action:n.jsx(E,{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 ZJ={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 eQ(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=d.useState(null),[u,h]=d.useState("key"),[f,m]=d.useState(null),[p,g]=d.useState(!1),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),k=(t==null?void 0:t.anthropicOAuthEnabled)===!0,N=(t==null?void 0:t.codexEnabled)===!0,S=t==null?void 0:t.gemini,[C,T]=d.useState(null);d.useEffect(()=>{let H=!1;const U=()=>{Promise.resolve().then(()=>A.ollama()).then(B=>{!H&&B&&b(B)}).catch(()=>{}),Promise.resolve().then(()=>A.mlxh()).then(B=>{!H&&B&&x(B)}).catch(()=>{H||x({running:!1,baseUrl:"",manager:!1,models:[]})})};U();const q=window.setInterval(U,4e3);return()=>{H=!0,window.clearInterval(q)}},[]);const R=async H=>{if(s.assistant??e.existing)try{await A.bindBrain({accountId:H.accountId,model:H.model})}catch(U){return U instanceof ve?U.message:String(U)}return a(),i({...s,brain:H}),C==null||C.close(),T(null),c(null),y(null),null},I=async(H,U,q)=>{g(!0),m(null);try{const B=await A.saveProviderAccount(H);let Y=await A.testProviderAccount(B.id),F=H.defaultModel,X=!1;if(Y.state!=="connected"&&q&&q!==F&&eR(Y)){const ee=(await A.providerAccounts()).accounts.find(fe=>fe.id===B.id);ee&&(await A.saveProviderAccount({id:ee.id,revision:ee.revision,label:ee.label,kind:ee.kind,auth:ee.auth,baseUrl:ee.baseUrl,defaultModel:q,enabled:ee.enabled}),Y=await A.testProviderAccount(B.id),Y.state==="connected"&&(F=q,X=!0))}if(Y.state!=="connected"){try{const ee=(await A.providerAccounts()).accounts.find(fe=>fe.id===B.id);ee&&await A.removeProviderAccount(B.id,ee.revision)}catch{}return m(Y.message),Y}const Q=await R({accountId:B.id,label:U,model:F,...X?{freeTier:X}:{}});return Q&&m(Q),Y}catch(B){return m(B instanceof ve?B.message:String(B)),null}finally{g(!1)}},L=async H=>{g(!0),m(null);try{const U=await A.saveProviderAccount(H);let q;try{q=await A.testProviderAccount(U.id)}finally{try{const B=(await A.providerAccounts()).accounts.find(Y=>Y.id===U.id);B&&await A.removeProviderAccount(U.id,B.revision)}catch{}}return q.state!=="connected"&&m(q.message),q}catch(U){return m(U instanceof ve?U.message:String(U)),null}finally{g(!1)}},W=(H,U,q)=>{if(H.length<=1){I(U(H[0]??""),q);return}y({models:H,make:U,label:q})},$=H=>{if(H===o)return;C==null||C.close(),T((H==="free"||H==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(H)},P=()=>{C==null||C.close(),T(null),y(null),m(null),c(null)},O=fI(v,j),M=["free",...k?["claude"]:[],...N?["chatgpt"]:[],"key","local"];let D=null;return w?D=n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:_.brain.model.ask})}),p?n.jsx(Ks,{line:_.brain.checking.service}):f?n.jsx(it,{children:n.jsx(ht,{children:f})}):null,n.jsx(tQ,{busy:p,models:w.models,onBack:P,onUse:H=>void I(w.make(H),w.label)})]}):o==="key"?D=n.jsxs(n.Fragment,{children:[n.jsx(Kt,{label:_.brain.keyKinds.label,value:u,onChange:H=>{m(null),h(H)},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(sQ,{busy:p,problem:f,preset:S,onBack:P,onUse:I},"gemini"):u==="service"?n.jsx(iQ,{busy:p,problem:f,address:(v==null?void 0:v.cloudBaseUrl)??"",onBack:P,onOffer:W,onTrial:L,onUse:I},"service"):n.jsx(nQ,{busy:p,problem:f,onBack:P,onUse:I},"key")]}):o==="local"?D=n.jsx(rQ,{busy:p,problem:f,probe:v,mlxh:j,onBack:P,onOffer:W,onUse:I}):o==="free"?D=n.jsx(lQ,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="chatgpt"?D=n.jsx(uQ,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="claude"&&(D=n.jsx(hQ,{...e,busy:p,problem:f,onBack:P,onConnected:R})),n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.brain.title}),n.jsx(it,{children:n.jsx(ht,{children:_.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":_.brain.ask,children:M.map(H=>{const U=ZJ[H],q=_.brain.cards[H];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===H,"data-wide":U.wide?"true":void 0,onClick:()=>$(H),children:[n.jsx("span",{className:"wiz-glyph","data-tone":U.tone,"aria-hidden":"true",children:n.jsx(ce,{name:U.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:q.title}),n.jsx("span",{className:"wiz-opt-line",children:H==="local"?O:q.line}),"pill"in q?n.jsx(we,{tone:"good",children:q.pill}):null]})]},H)})}),D,D===null&&s.brain?n.jsxs(it,{children:[n.jsx(ht,{children:s.brain.freeTier?_.brain.worksOnFlash(s.brain.model):_.brain.works(s.brain.model)}),n.jsx(oQ,{...e})]}):null,D===null?n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:l}),n.jsx(Jl,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:_.brain.submit})]})}):null]})}function tQ({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=d.useState(t[0]??"");return n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:s,disabled:e}),n.jsx(E,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:_.brain.model.submit})]}),children:n.jsx(oe,{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 hI({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(oe,{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 nQ({busy:e,problem:t,onBack:s,onUse:r}){const i=ql(),[a,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(""),[v,b]=d.useState(!1),j=e||u,x=!v&&t!==null&&f.length>0,w=o??HJ(a),y=()=>{const k=a.trim();k===""||j||(h(!0),b(!1),(async()=>{var T;let N=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")N=p;else try{const R=await A.probeModels({kind:w,auth:"api-key",secret:k});N=((T=R.models.find(I=>I.isDefault))==null?void 0:T.id)??N,S=R.models.map(I=>I.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?_.brain.key.anthropic:_.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:N,enabled:!0,secret:k},w==="anthropic"?_.brain.key.anthropic:_.brain.key.openai);if(!(!C||C.state==="connected")){if(rj(C)){b(!0),m([]);return}m(S.includes(N)||S.length===0?S:[N,...S]),g(N)}})())};return n.jsxs(n.Fragment,{children:[j?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.key})}):v?n.jsx(it,{children:n.jsx(ht,{children:_.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:s,disabled:j}),n.jsx(E,{variant:"accent",size:"lg",disabled:j||a.trim()==="",onClick:y,children:x?_.brain.model.retry:_.brain.key.submit})]}),children:[n.jsx(oe,{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:k=>{l(k.target.value),m([])},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),y())}})}),x?n.jsx(hI,{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 sQ({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=ql(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState([]),[m,p]=d.useState(""),g=e||c,v=t!==null&&h.length>0,b=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let x=J$,w;if(v&&m!=="")x=m;else try{const k=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(N=>N.id);x=Q$(k)??x,w=Z$(x)?X$(k):void 0,f(q7(k)),p(w??x)}catch{}u(!1),await i({label:_.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:x,enabled:!0,secret:j},_.brain.gemini.label,w)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.gemini})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:r,disabled:g}),n.jsx(E,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:_.brain.gemini.submit})]}),children:[n.jsx(oe,{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())}})}),v?n.jsx(oe,{label:_.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:h.map(j=>n.jsx("option",{value:j,children:j},j))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:_.brain.gemini.get})]})]})}function fI(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 rQ({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Nx(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)},h=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(it,{children:n.jsx(Ks,{line:_.brain.checking.ollama})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(E,{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(E,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:_.brain.mlxh.connect}):null,h&&s?n.jsx(Et,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[fI(s,r),r!=null&&r.running&&!c?` ${_.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${C$(r.baseUrl)}`:""]})})]})}function iQ({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=ql(),[c,u]=d.useState(s),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState([]),[b,j]=d.useState(""),[x,w]=d.useState(!1),y=e||m,k=!x&&t!==null&&g.length>0,N=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var P;const S=h.trim()?"api-key":"none",C=O=>({label:_.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:O,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),T=(O,M,D)=>{if(!(!O||O.state==="connected")){if(rj(O)){w(!0),v([]);return}v(M),j(D)}};if(S==="api-key"&&k&&b!==""){p(!1),T(await l(C(b),_.brain.service.label),g,b);return}let R=[],I;try{const O=await A.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});R=O.models.map(M=>M.id),I=(P=O.models.find(M=>M.isDefault))==null?void 0:P.id}catch{}p(!1);const L=I?[I]:R;if(S==="none"){i(L,C,_.brain.service.label);return}const W=L[0]??"";if(L.length<=1){T(await l(C(W),_.brain.service.label),R,W);return}const $=await a(C(W));($==null?void 0:$.state)==="connected"?i(L,C,_.brain.service.label):T($,R,W)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.service})}):x?n.jsx(it,{children:n.jsx(ht,{children:_.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:r,disabled:y}),n.jsx(E,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:N,children:k?_.brain.model.retry:_.brain.service.submit})]}),children:[n.jsx(oe,{label:_.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:_.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),v([])}})}),n.jsx(oe,{label:_.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{f(S.target.value),v([])}})}),k?n.jsx(hI,{models:g,picked:b,disabled:y,onPick:j}):null]})]})}const aQ=2e3;function lQ({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=_.brain.cloud.label;d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?t:g.current;(async()=>{try{const x=((i==null?void 0:i.accounts)??[]).find(N=>N.auth==="device-key"),w=x?{id:x.id}:await A.saveProviderAccount({label:v,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:ld,enabled:!0}),y=(await A.providerAccounts()).accounts.find(N=>N.id===w.id),k=await A.ollamaConnect(y.id,y.revision);h({id:y.id,attemptId:k.attemptId,url:k.verificationUrl}),j&&(j.location.href=k.verificationUrl)}catch(x){j==null||j.close(),c(x instanceof ve?x.message:String(x))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let j=!1,x=!1;const w=async()=>{if(!(j||x)){x=!0;try{const k=await A.ollamaPoll(u.id,u.attemptId);if(j||k.state==="waiting")return;if(j=!0,h(null),k.state==="failed"){c(k.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{x=!1}}},y=window.setInterval(()=>void w(),aQ);return()=>{j=!0,window.clearInterval(y)}},[u]);const b=async j=>{try{const x=(await A.accountModels(j).catch(()=>({models:[]}))).models.map(N=>N.id),w=x.length===0||x.includes(ld)?ld:x[0],y=(await A.providerAccounts()).accounts.find(N=>N.id===j);y&&y.defaultModel!==w&&await A.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const k=await A.testProviderAccount(j);return k.state!=="connected"?k.message:await r({accountId:j,label:v,model:w})}catch(x){return x instanceof ve?x.message:String(x)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.cloud})}):o?n.jsx(it,{children:n.jsx(ht,{children:o})}):u?n.jsx(it,{children:n.jsx(ht,{children:_.brain.cloud.waiting})}):null,n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:s,disabled:a||e}),u?n.jsx(Et,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.brain.cloud.open}):o?n.jsx(E,{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 oQ({answers:e,accounts:t,onKept:s,onTrouble:r}){var p;const i=e.brain,a=i?((t==null?void 0:t.accounts)??[]).find(g=>g.id===i.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=ww(a),f=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&tR(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!a)return;let g=!1;return A.accountModels(a.id).then(v=>{const b=h?v.models.filter(j=>!S$({id:j.id,...j.image?{kind:"image"}:{}})):v.models;g||o(b.map(j=>j.id))}).catch(()=>{}),()=>{g=!0}},[f,a==null?void 0:a.id]),!f||!a||!i||l.length<2)return null;const m=g=>{g===i.model||c||(u(!0),r(null),(async()=>{try{await A.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:g,enabled:a.enabled}),e.assistant&&await A.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(v){r(v instanceof ve?v.message:String(v))}finally{u(!1)}})())};return n.jsx(ht,{children:n.jsx(oe,{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 gN="gpt-5.5",cQ=2e3;function uQ({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=d.useRef(null),b=_.brain.chatgpt.label;d.useEffect(()=>()=>{const w=v.current;v.current=null,w&&A.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]),d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const w=f===0?t:g.current;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),k=y?{id:y.id}:await A.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:gN,enabled:!0}),N=(await A.providerAccounts()).accounts.find(C=>C.id===k.id),S=await A.codexAccountAction(N.id,"login",N.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??_.brain.chatgpt.failed);v.current={id:N.id,revision:N.revision},h({id:N.id,revision:N.revision,url:S.verificationUrl,code:S.userCode}),w&&(w.location.href=S.verificationUrl)}catch(y){w==null||w.close(),c(y instanceof ve||y instanceof Error?y.message:String(y))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let w=!1,y=!1;const k=async()=>{if(!(w||y)){y=!0;try{const S=(await A.providerAccounts()).accounts.find(T=>T.id===u.id);if(w)return;const C=S==null?void 0:S.login;if(!C||C.state==="pending")return;if(w=!0,v.current=null,h(null),C.state!=="connected"){c(C.message??_.brain.chatgpt.failed);return}l(!0),c(await j(u.id)),l(!1)}catch{}finally{y=!1}}},N=window.setInterval(()=>void k(),cQ);return()=>{w=!0,window.clearInterval(N)}},[u]);const j=async w=>{var y,k;try{const N=(await A.accountModels(w).catch(()=>({models:[]}))).models,S=((y=N.find(T=>T.isDefault))==null?void 0:y.id)??((k=N[0])==null?void 0:k.id)??gN,C=(await A.providerAccounts()).accounts.find(T=>T.id===w);return C&&C.defaultModel!==S&&await A.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:S,enabled:C.enabled}),await r({accountId:w,label:b,model:S})}catch(N){return N instanceof ve?N.message:String(N)}},x=()=>{const w=v.current;v.current=null,w&&A.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.chatgpt})}):o?n.jsx(it,{children:n.jsx(ht,{children:o})}):u?n.jsx(it,{children:n.jsxs(ht,{children:[_.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),_.brain.chatgpt.codeAfter]})}):null,n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:x,disabled:a||e}),u?n.jsx(Et,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.brain.chatgpt.open}):o?n.jsx(E,{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(bw,{code:u.code,label:_.brain.chatgpt.code}):null})]})}const dQ="claude-sonnet-5";function hQ({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(""),g=d.useRef(null);d.useEffect(()=>()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const v=()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??dQ,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(T=>T.auth==="anthropic-oauth"),k=y?{id:y.id}:await A.saveProviderAccount({label:_.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await A.providerAccounts()).accounts.find(T=>T.id===k.id),C=await A.anthropicAccountAction(S.id,"login",S.revision);g.current={id:S.id,revision:S.revision+1},f({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(y){w==null||w.close(),u(y instanceof ve?y.message:String(y))}finally{o(!1)}})()},x=()=>{!h||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await A.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await A.testProviderAccount(h.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:h.id,label:_.brain.claude.label,model:b}))}catch(w){u(w instanceof ve?w.message:String(w))}finally{o(!1)}})())};return n.jsxs(n.Fragment,{children:[l||e?n.jsx(it,{children:n.jsx(Ks,{line:_.brain.checking.claude})}):t??c?n.jsx(it,{children:n.jsx(ht,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:_.brain.claude.waiting})}),n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:v,disabled:l}),n.jsx(Et,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:_.brain.claude.open}),n.jsx(E,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:x,children:_.brain.claude.finish})]}),children:n.jsx(oe,{label:_.brain.claude.paste,grow:!0,children:n.jsx(fQ,{value:m,onChange:p})})})]}):n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:v,disabled:e||l}),n.jsx(E,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:_.brain.claude.start})]})})]})}function fQ({value:e,onChange:t}){const s=ql();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const mQ={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function pQ(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 gQ({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=d.useState(()=>e.takeOn??[...Pz]),[c,u]=d.useState(!1),h=Mo.filter(g=>l.includes(g.id)),f=g=>o(v=>v.includes(g)?v.filter(b=>b!==g):[...v,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>A.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(v=>a(v instanceof ve?v.message:String(v))).finally(()=>u(!1)))},p=pQ(t);return n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.takeOn.title}),n.jsx(it,{children:n.jsx(ht,{children:_.takeOn.ask})}),n.jsxs(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:i,disabled:c}),n.jsx(E,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:_.takeOn.none}),n.jsx(Jl,{onClick:()=>m(Mo.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:Mo.map(g=>{const v=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":v,onClick:()=>f(g.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ce,{name:mQ[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:v?n.jsx(ce,{name:"check",size:12}):null})]}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:g.title}),n.jsx("span",{className:"wiz-opt-plugins",children:g.plugins})]}),n.jsx("span",{className:"wiz-opt-line",children:g.line})]},g.id)})}),h.length>0?n.jsxs("div",{className:"wiz-stack",children:[p?n.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[n.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),n.jsx("span",{children:p.line}),l.includes("mail")?n.jsx("span",{className:"wiz-busy-side",children:_.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:h.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:_.takeOn.nothing})]})]})}function xQ({answers:e,navigate:t,onSettled:s,onBack:r}){var g,v,b;const[i,a]=d.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=d.useState(((v=e.reach)==null?void 0:v.mailbox)===!0),[c,u]=d.useState(((b=e.reach)==null?void 0:b.app)===!0),[h,f]=d.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const j={phone:i,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>A.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.reach.title}),n.jsx(it,{children:n.jsx(ht,{children:_.reach.ask})}),n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:r}),n.jsx(Jl,{onClick:p,children:_.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(vQ,{paired:i,onPaired:()=>a(!0)}),n.jsx(wQ,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(yQ,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),i?n.jsx(G,{tone:"good",role:"status",children:_.reach.phone.hello}):null]})})]})}function vQ({paired:e,onPaired:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1),l=d.useRef(t);l.current=t,d.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>A.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ce,{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(we,{tone:"good",dot:!0,children:_.reach.phone.paired})}):o?n.jsx(jQ,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(E,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:_.reach.phone.setUp})}),i?n.jsx(qe,{title:_.telegram.sheet,onClose:()=>a(!1),children:n.jsx(EQ,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function jQ({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=Hw(()=>A.telegram().then(o=>o.paired),e),l=d.useRef(!1);return d.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(we,{tone:"good",dot:!0,children:_.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(E,{size:"lg",onClick:()=>void a().catch(()=>{}),children:_.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(Kw,{offer:t,square:s})})}function wQ({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=d.useState(void 0),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=d.useCallback(()=>{Promise.resolve().then(()=>A.pageQuery("email","accounts")).then(m=>{var g,v,b;const p=((b=(v=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:v[0])==null?void 0:b.address)??null;h(p),s(p!==null)}).catch(()=>{})},[]);return d.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>A.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),v=g.find(b=>b.id==="settings")??null;l(v?{page:v,siblings:g}:null)}).catch(()=>{m||l(null)}),f(),()=>{m=!0}},[f]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(ce,{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(we,{tone:"good",dot:!0,mono:u!==null,children:u??_.reach.mailbox.added}):a?n.jsx(E,{size:"lg",onClick:()=>c(!0),children:_.reach.mailbox.add}):null}),o&&a?n.jsx(qe,{title:_.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:n.jsx(rw,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function yQ({app:e,onApp:t,browser:s,onBrowser:r}){const i=yf(),a=typeof navigator>"u"?null:LT(navigator.userAgent),[l,o]=d.useState(null),[c,u]=d.useState("idle"),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState(void 0),b=d.useRef(!1),j=d.useRef(!0);d.useEffect(()=>(j.current=!0,Promise.resolve().then(()=>A.browser()).then(C=>{var R;if(!j.current)return;const T=C==null?void 0:C.browser;T?((R=T.install)==null?void 0:R.state)==="running"?(o("none"),b.current=!0,u("installing"),y()):o(T.engine):o("other")}).catch(()=>{j.current&&o("other")}),()=>{j.current=!1}),[]);const x=(C,T)=>{j.current&&(b.current=!1,u("failed"),f(C),p(T??null))},w=async C=>{u("launching");let T;try{T=await A.browserCheck()}catch(R){return x(R instanceof ve?R.message:String(R))}if(j.current){if(T.ok){u("idle"),o(C),r(b.current?"installed":C);return}x(T.message,T.command)}},y=async()=>{var R,I;let C;try{C=await A.browser()}catch(L){return x(L instanceof ve?L.message:String(L))}if(!j.current)return;const T=C.browser;if(!T)return x(_.browser.failed(""));if(((R=T.install)==null?void 0:R.state)==="running"){u("installing"),v(T.install.progress),window.setTimeout(()=>void y(),1e3);return}return T.engine!=="none"?w(T.engine):x(((I=T.install)==null?void 0:I.line)??"")},k=()=>{if(p(null),l==="chrome"||l==="chromium"){w(l);return}b.current=!0,u("installing"),v(void 0),Promise.resolve().then(()=>A.browserInstall()).then(()=>{j.current&&window.setTimeout(()=>void y(),1e3)}).catch(C=>x(C instanceof ve?C.message:String(C)))},N=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(ce,{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(we,{tone:"good",dot:!0,children:_.reach.app.installed}):i?n.jsx(E,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:_.reach.app.install}):null,N?n.jsx(we,{tone:"good",dot:!0,children:_.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(E,{size:"lg",disabled:S,onClick:k,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(QA,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Ks,{line:_.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:_.browser.failed(h??"")}),m?n.jsx(NQ,{command:m}):null]}):null]})}function bQ({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=d.useState(()=>(t==null?void 0:t.name)??Cz),[c,u]=d.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[h,f]=d.useState(t?null:_.assistant.purposeValue),[m,p]=d.useState(t?"":_.assistant.purposeValue);d.useEffect(()=>{if(!t)return;let w=!1;return A.firstAgentPersona().then(y=>{w||(f(y.persona),p(y.persona))},y=>{w||r(y instanceof ve?y.message:String(y))}),()=>{w=!0}},[t==null?void 0:t.id]);const[g,v]=d.useState(!1),b=Mo.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),j=yk.find(w=>w.id===c),x=()=>{if(l.trim()===""||g)return;v(!0);const w=!t||h!==null&&m.trim()!==""&&m.trim()!==h.trim()?{instructions:m.trim()}:{},y=t?A.updateFirstAgent({name:l.trim(),...w}):A.createFirstAgent({name:l.trim(),handle:KJ(l),description:"",...w,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let k;try{k=await y}catch(S){r(S instanceof ve?S.message:String(S)),v(!1);return}let N=null;try{j&&await A.uploadAgentPicture(k.id,await F$(j.role))}catch(S){N=S instanceof ve?S.message:String(S)}v(!1),i(),s({...e,assistant:{id:k.id,name:l.trim(),avatar:j?"":(t==null?void 0:t.avatar)??""}}),N&&r(N)})()};return n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.assistant.title}),n.jsx(it,{children:n.jsxs(ht,{children:[_.assistant.ask,b.length>0?_.assistant.team(b):""]})}),n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(rs,{onClick:a,disabled:g}),n.jsx(Jl,{onClick:x,disabled:g||l.trim()===""||h===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:va(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:yk.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(oe,{label:_.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:w=>o(w.target.value)})}),n.jsx(oe,{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 kQ({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var P,O;const u=e.assistant,[h,f]=d.useState(s),[m,p]=d.useState([]),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(!0),[y,k]=d.useState(!1),N=d.useRef(!1),S=d.useMemo(()=>t?[t]:[],[t]);d.useEffect(()=>{c()},[]),d.useEffect(()=>{if(!u||N.current)return;if(N.current=!0,s){f(s);return}let M=!1;return(async()=>{try{const D=await He.startConversation(u.id);if(M)return;f(D.conversationId),r(D.conversationId),await A.onboardingStep(aI.handover,{conversationId:D.conversationId}).catch(()=>{}),await He.send(u.id,{conversationId:D.conversationId,text:$z,opening:!0})}catch{M||(w(!1),v(!0))}})(),()=>{M=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let M=!1;const D=Date.now(),H=()=>{He.conversation(h).then(q=>{if(M)return;p(q.messages);const B=Date.now()-D;if(q.messages.some(xN)){w(!1),v(!1),j(!1);return}const Y=q.runs??[],F=Y.some(Q=>Q.finishedAt===null),X=Y.length>0&&!F;j(F&&B>=VJ),(X||B>=GJ)&&(w(!1),v(!0))}).catch(()=>{})};H();const U=window.setInterval(H,dI);return()=>{M=!0,window.clearInterval(U)}},[h]);const C=u&&h?st(u.id,h):null,T=m.some(xN);d.useEffect(()=>{T&&C&&l(C)},[T,C,l]);const R=e.takeOn??[],I=_.handover.starters({days:R.includes("days"),mail:R.includes("mail"),mailbox:((P=e.reach)==null?void 0:P.mailbox)===!0}),L={days:R.includes("days"),mailbox:((O=e.reach)==null?void 0:O.mailbox)===!0,money:R.includes("money"),pictures:R.includes("pictures")},W=(o==null?void 0:o.waiting)??[],$=M=>{!u||!h||y||(k(!0),Promise.resolve().then(()=>He.send(u.id,{conversationId:h,text:M})).then(()=>i(st(u.id,h),!0)).catch(()=>k(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(Hj,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:x,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(it,{children:n.jsx(ht,{children:_.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:_.handover.silent})}),n.jsx(Xt,{actions:n.jsx(Jl,{onClick:a,children:_.handover.again})})]}):null,T?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":_.handover.starterLabel,children:I.map(M=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>$(M),children:M},M))}):null,T?n.jsx(s7,{setUp:L,navigate:M=>i(M,!0)}):null,T&&W.length>0?n.jsx(G,{tone:"warm",title:_.handover.waitingTitle(W.length),action:n.jsx(E,{variant:"accent",onClick:()=>i(cn,!0),children:_.handover.home}),children:_.handover.waitingBody(W)}):null,T&&C?n.jsx(Xt,{actions:n.jsx(Et,{variant:"accent",size:"lg",href:C,onClick:M=>{M.preventDefault(),i(C,!0)},children:_.done.open})}):null]})}function NQ({command:e}){const[t,s]=d.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(le,{gap:"sm",children:[n.jsx(Pt,{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(E,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function xN(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function SQ({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=d.useState(null),[a,l]=d.useState(""),[o,c]=d.useState(!1),u=()=>{!r||o||(c(!0),s(null),A.firstRunRestore(r,a.trim()).then(h=>{Bx(h.job.id),t()}).catch(h=>s(h instanceof ve?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(qe,{title:_.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:_.restore.lede}),n.jsx(oe,{label:_.restore.file,children:n.jsx("input",{type:"file",onChange:h=>{var f;return i(((f=h.target.files)==null?void 0:f[0])??null)}})}),n.jsx(oe,{label:_.restore.passphrase,hint:_.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:h=>l(h.target.value)})}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:e,children:_.restore.cancel}),n.jsx(E,{variant:"accent",disabled:o||!r,onClick:u,children:_.restore.submit})]})]})})}function CQ({onDone:e,onFailed:t}){const[s,r]=d.useState([]),i=d.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},d.useEffect(()=>{const l=uI();if(!l)return;let o=!1;const c=()=>{A.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,Bx(null),A.owner().then(f=>i.current.onDone(f.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Bx(null),i.current.onFailed(h.error??_.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,dI);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in _.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(Ql,{children:_.restore.title}),n.jsxs(it,{children:[n.jsx(ht,{children:_.restore.started}),a.map(l=>n.jsx(ht,{children:_.restore.phases[l]},l))]}),n.jsx(Ks,{})]})}function EQ(e){return n.jsx(Gw.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(AQ,{...e})})})}function AQ({onPaired:e,onDismiss:t}){const s=ql(),[r,i]=d.useState(""),[a,l]=d.useState(!1),[o,c]=d.useState(null),{offer:u,square:h,paired:f,stale:m,ask:p}=Hw(()=>A.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await A.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??_.telegram.restart);return}await p()}catch(b){c(b instanceof ve?b.message:String(b))}finally{l(!1)}})())},v=()=>{c(null),p().catch(b=>c(b instanceof ve?b.message:String(b)))};return f?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:_.telegram.paired})}),n.jsx(Xt,{actions:n.jsx(E,{variant:"accent",onClick:t,children:_.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:m?_.telegram.expired:_.telegram.scan})}),n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:_.telegram.notNow}),m?n.jsx(E,{variant:"accent",onClick:v,children:_.telegram.newCode}):null]}),children:m?null:n.jsx(Kw,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(it,{children:[n.jsx(ht,{children:_.telegram.how}),o?n.jsx(ht,{children:o}):null]}),n.jsx(Xt,{actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:_.telegram.notNow}),n.jsx(E,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:_.telegram.submit})]}),children:n.jsx(oe,{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 mp={recovery:0,lost:1,paused:2},TQ="Lost buddi. Retrying…",$Q="The queue is paused. Nothing is being claimed until you resume it.";function RQ(e){const t=[];return e.recovery&&t.push({id:"recovery",priority:mp.recovery,tone:"warning",text:W$,action:{label:"Finish the checklist",href:Lg}}),e.lost&&t.push({id:"lost",priority:mp.lost,tone:"critical",text:TQ}),e.paused&&t.push({id:"paused",priority:mp.paused,tone:"warning",text:$Q,action:{label:"Resume",onClick:()=>{A.setPaused(!1).catch(()=>{})}}}),t}function IQ({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(`
|
|
132
|
+
`),children:["+",i.length," more"]}):null,a!=null&&a.href?n.jsx(Et,{size:"sm",href:a.href,onClick:l=>{l.preventDefault(),t(a.href)},children:a.label}):a?n.jsx(E,{size:"sm",onClick:a.onClick,children:a.label}):null]})}const mI=1e4,PQ=3e4,pI=6e3,Yw=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function MQ(e){return Yw.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 gI(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new ve(0,Gd)),e)});try{return{up:!0,version:await Promise.race([A.version(),s])}}catch(r){return Yd(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function xI(e){var t;return e.up&&Nj((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function DQ({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:va("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:MQ(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(E,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function OQ({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(!1),a=d.useRef(!1),l=d.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await gI(pI);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":xI(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),mI);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(DQ,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsx(n.Fragment,{children:e})}function LQ(e=PQ){const[t,s]=d.useState(!1);return d.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=hc();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=sj(i);return()=>{a(),clearTimeout(r)}},[e]),t}function FQ(){const e=LQ();return d.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{gI(pI).then(xI)},mI);return()=>window.clearInterval(t)},[e]),e}const _Q={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},vN=(e,t,s=`${t}s`)=>e===1?t:s;function zQ(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function UQ(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function BQ(e,t){return t?"reconnecting":Yw.test(e)?"local":"tailnet"}function vI(e,t,s=zQ()){const r=[],i=_Q[e.link];if(r.push({key:"link",route:Pe("system"),dot:e.link==="reconnecting"?"warning":"good",text:i,label:`Connection: ${i}`}),e.focus){const u=`${Qi[e.focus.mode]} ${kc(e.focus,e.timezone,t)}`;r.push({key:"focus",route:Pe("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const a=[];if(e.working>0&&a.push({key:"working",dot:"working",text:`${e.working} ${vN(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?`${jt}/jobs?state=failed`:`${jt}/jobs`,parts:a,label:`Work: ${a.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${vN(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:vl,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:Pe("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=Vt(t,l),c=l!==s;return r.push({key:"time",route:Pe("you"),end:!0,time:o,...c?{zone:UQ(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function WQ(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 jI(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function HQ(){const[e,t]=d.useState(()=>hc()!==null);return d.useEffect(()=>sj(()=>t(hc()!==null)),[]),e}function wI({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(ce,{name:e.icon,size:12}):null,e.count?n.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(t=e.parts)==null?void 0:t.map((s,r)=>n.jsxs(d.Fragment,{children:[r>0?n.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?n.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,n.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?n.jsx("span",{children:e.text}):null,e.mono?n.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?n.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?n.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?n.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function KQ({status:e,onNavigate:t}){const s=jI(),r=bf(),i=vI(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(wI,{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(ce,{name:"lock",size:13})}):null]})}function VQ({status:e,onNavigate:t}){const s=jI(),r=bf(),i=WQ(e);return n.jsx("div",{className:"rail-status",children:n.jsxs(Lc,{modal:!1,children:[n.jsx(Fc,{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(_l,{children:n.jsxs(_c,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[n.jsx(ca,{className:"ui-menu-label",children:"Status"}),vI(e,s).map(a=>n.jsx(xs,{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(wI,{item:a})})})},a.key)),r.pin?n.jsxs(n.Fragment,{children:[n.jsx(Rr,{className:"ui-menu-sep"}),n.jsx(xs,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:n.jsxs("span",{className:"rail-status-line",children:[n.jsx(ce,{name:"lock",size:12}),n.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const GQ=1e4;function yI(){return d.useSyncExternalStore(X4,vk,vk)}function YQ(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 jN(e){const t=Math.max(0,Math.floor(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function qQ({command:e}){const[t,s]=d.useState(!1);return d.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(E,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:t?"Copied":"Copy"})]})}function JQ({state:e,elapsedMs:t,hostname:s=window.location.hostname,onReload:r=()=>al.reload()}){const i=YQ(e),a=e.kind==="stop",l=!a&&t>=(e.patienceMs??G4),o=Yw.test(s),c=d.useRef(null);d.useEffect(()=>{var h;return(h=c.current)==null?void 0:h.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(Hc,{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(qQ,{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?`${jN(t)} · still checking every few seconds`:t>=GQ?`${jN(t)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),a||l?n.jsx(E,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function QQ(e){const[t,s]=d.useState(()=>al.now());return d.useEffect(()=>{if(!e)return;s(al.now());const r=window.setInterval(()=>s(al.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,t-e.startedAt):0}function XQ({children:e}){const t=yI(),s=QQ(t),r=d.useRef(null);return d.useEffect(()=>{ez();let i=hc()!==null;const a=sj(()=>{const o=hc()!==null;i&&!o&&jk(),i=o}),l=()=>void jk();return window.addEventListener(pc,l),()=>{a(),window.removeEventListener(pc,l)}},[]),d.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(JQ,{state:t,elapsedMs:s}):null]})}const ZQ="(max-width: 1080px)",eX="(max-width: 720px)";function tX(){const[e,t]=d.useState(()=>window.location.hash||cn);d.useEffect(()=>{const r=()=>t(window.location.hash||cn);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=d.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function nX(){const[e,t]=r$();d.useEffect(()=>{s$(e)},[e]);const s=d.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const wN=new Map;function sX(){var Es,kn,As,Ts;const[e,t]=tX(),[s,r]=d.useState("UTC"),[i,a]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=nX(),c=bs(Ij),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState([]),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[T,R]=d.useState(0),[I,L]=d.useState(null),W=oz(),$=f.find(ke=>ke.id===p)??null,P=$!==null&&Z5(e),[O,M]=d.useState(!1),D=d.useCallback(()=>M(!0),[]);d.useEffect(()=>{P||M(!1)},[P]),uK(t,ud(e)===null,P?D:void 0);const H=bs(ZQ),U=B$(),q=IA(),B=XT(),Y=de(()=>Promise.resolve().then(()=>A.version()),[],O4),F=Y.data;K4(Y.reload);const X=F&&!F.checkout&&F.updateAvailable?F:null,Q=Nj(F==null?void 0:F.web);V4(F==null?void 0:F.web);const ee=((Es=de(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4).data)==null?void 0:Es.signals)??[],[fe,Oe]=d.useState(null),Ie=d.useMemo(()=>new Set(fe?[fe]:[]),[fe]),[Fe,z]=d.useState(new Map);d.useEffect(()=>{const ke=()=>{A.conversations().then(We=>{const me=new Map;for(const Gn of We.conversations){const Dn=Gn.lastMessageAt??Gn.createdAt,Vs=me.get(Gn.agentId);(!Vs||Dn>Vs)&&me.set(Gn.agentId,Dn)}z(me)}).catch(()=>{})};ke();const Ee=window.setInterval(ke,3e4);return()=>window.clearInterval(Ee)},[e]);const[ne,J]=d.useState(!1);d.useEffect(()=>{if(ne)return;let ke=!1;return A.onboarding().then(Ee=>{ke||(J(!0),Ee.state==="pending"&&Ee.needs.model&&!ud(window.location.hash)&&t(e4,!0))}).catch(()=>{ke||J(!0)}),()=>{ke=!0}},[ne,t]),d.useEffect(()=>{const ke=k4(e);ke&&t(ke,!0)},[e,t]),d.useEffect(()=>{let ke=!1;const Ee=()=>{He.agents().then(me=>{ke||(m(me.agents),$4(me.defaultAgentId??null),g(me.defaultAgentId??null),b(Gn=>{var Dn;return Gn??me.defaultAgentId??((Dn=me.agents[0])==null?void 0:Dn.id)??null}))}).catch(()=>{})};Ee();const We=window.setInterval(Ee,15e3);return window.addEventListener("focus",Ee),window.addEventListener(dr,Ee),()=>{ke=!0,window.clearInterval(We),window.removeEventListener("focus",Ee),window.removeEventListener(dr,Ee)}},[e]),d.useEffect(()=>{let ke=!1;const Ee=()=>{He.groups().then(me=>{ke||x(me.groups)}).catch(()=>{})};Ee();const We=window.setInterval(Ee,3e4);return()=>{ke=!0,window.clearInterval(We)}},[e]);const ye=XE(f,p),ge=n4(e),$e=zE(e),De=$e?j.find(ke=>ke.id===$e.groupId)??null:null,Je=$e?null:(ge==null?void 0:ge.agentId)??v;d.useEffect(()=>{ge&&b(ge.agentId)},[ge==null?void 0:ge.agentId]);const ze=d.useRef(null);ge&&(ze.current=e);const Ne=ke=>{b(ke),t(st(ke))},Ue=ke=>t(Hi(ke)),at=d.useCallback((ke,Ee,We=!0)=>t($e?Hi($e.groupId,Ee):st(ke,Ee),We),[t,$e==null?void 0:$e.groupId]),[Ye,kt]=d.useState(!1),[,Gt]=d.useState(0);d.useEffect(()=>{const ke=()=>{Gt(Ee=>Ee+1),A.session().then(Ee=>r(Ee.timezone)).catch(()=>{})};return window.addEventListener(wg,ke),()=>window.removeEventListener(wg,ke)},[]),d.useEffect(()=>{A.session().then(ke=>{ej({timeFormat:ke.timeFormat??null,dateFormat:ke.dateFormat??null}),r(ke.timezone),kt(!0)}).catch(()=>{})},[]);const se=o8(Ye);f8(Ye,se.refresh,()=>kt(!1)),d.useEffect(()=>{const ke=()=>{A.overview().then(We=>{var me;return a({approvals:We.approvals.pending,failed:We.jobs.failed??0,paused:We.paused,running:We.running??0,needs:((me=We.needsYou)==null?void 0:me.total)??We.approvals.pending+(We.jobs.failed??0)})}).catch(()=>{})};ke();const Ee=window.setInterval(ke,2e4);return window.addEventListener(Ji,ke),()=>{window.clearInterval(Ee),window.removeEventListener(Ji,ke)}},[]);const be=de(()=>Promise.resolve().then(()=>A.focus()),[],6e4),Qe=d.useRef(be.reload);Qe.current=be.reload,d.useEffect(()=>{const ke=()=>Qe.current();return window.addEventListener(Ji,ke),()=>window.removeEventListener(Ji,ke)},[]);const ct=HQ(),yt=FQ(),ut=yI()!==null,mn=bs(eX);d.useEffect(()=>{if(!Ye)return;if(e===N4){y(!0),t(gi,!0);return}const ke=S4(e),Ee=new Date().toDateString();!ke||wN.get(ke)===Ee||(wN.set(ke,Ee),A.tipsSeenPage(ke).catch(()=>{}))},[e,Ye,t]);const Vn={link:BQ(window.location.hostname,ct&&!ut),focus:((kn=be.data)==null?void 0:kn.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},Z=RQ({recovery:((As=U.data)==null?void 0:As.active)===!0,lost:yt&&!ut,paused:i.paused}),Re=ud(e),Xe=VE(e),xt=Xe===gi,V=k?j.find(ke=>ke.id===k.groupId)??null:null,he=ke=>x(Ee=>Ee.map(We=>We.id===ke.id?ke:We)),Be=()=>N(null),_e=w?n.jsx(m8,{agents:f,onClose:()=>y(!1),onCreated:ke=>{x(Ee=>[...Ee,ke]),y(!1),t(Hi(ke.id))}}):V&&(k==null?void 0:k.kind)==="members"?n.jsx(z5,{group:V,agents:f,onClose:Be,onSaved:he}):V&&(k==null?void 0:k.kind)==="rename"?n.jsx(U5,{group:V,onClose:Be,onSaved:ke=>{he(ke),Be()}}):V&&(k==null?void 0:k.kind)==="clear"?n.jsx(W5,{group:V,onClose:Be,onCleared:()=>{Be(),R(ke=>ke+1),t(Hi(V.id),!0)}}):V&&(k==null?void 0:k.kind)==="delete"?n.jsx(H5,{group:V,agents:f,onClose:Be,onDeleted:ke=>{const Ee=j.findIndex(We=>We.id===V.id);Be(),x(We=>We.filter(me=>me.id!==V.id)),C({group:V,index:Ee,until:ke}),t(ze.current??gi)}}):null,en=()=>{const ke=S;ke&&(C(null),He.restoreGroup(ke.group.id).then(Ee=>{x(We=>{if(We.some(Gn=>Gn.id===Ee.id))return We;const me=[...We];return me.splice(Math.min(Math.max(ke.index,0),me.length),0,Ee),me}),t(Hi(Ee.id))}).catch(()=>L(ke.group.name)))};return Re?n.jsx(Jb,{delayDuration:400,children:n.jsxs(Lb,{swipeDirection:"right",children:[n.jsx(QJ,{navigate:t,timezone:s}),n.jsx(Fb,{className:"ui-toasts"})]})}):n.jsx(Lz,{picture:(Ts=f.find(ke=>ke.id===p))==null?void 0:Ts.picture,children:n.jsx(Jb,{delayDuration:400,children:n.jsxs(Lb,{swipeDirection:"right",children:[_e,n.jsxs("div",{className:"wb-shell",children:[n.jsx(IQ,{banners:Z,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(XH,{attention:i.needs,place:Xe,onNavigate:t,theme:l,onTheme:o,plugins:oK(q.rail,B),updateAvailable:X!==null,settingsDot:ee.length>0?QT:void 0,stale:Q,timezone:s,version:F&&!F.checkout?{current:F.current,latest:F.latest,updateAvailable:F.updateAvailable}:F?{current:F.current,updateAvailable:!1}:void 0,status:mn?n.jsx(VQ,{status:Vn,onNavigate:t}):void 0}),xt&&!H?n.jsx(sA,{agents:ye,currentId:Je,attention:W,onSelect:Ne,lastActivity:Fe,working:Ie,groups:j,currentGroupId:(De==null?void 0:De.id)??null,onSelectGroup:Ue,onNewGroup:()=>y(!0)}):null,xt?n.jsx(K5,{timezone:s,agents:ye,agentId:De?De.coordinator:Je,defaultAgentId:p,group:De,...De?{onGroupAction:ke=>N({kind:ke,groupId:De.id})}:{},requestedConversationId:($e==null?void 0:$e.conversationId)??(ge==null?void 0:ge.conversationId),requestedTab:ge==null?void 0:ge.tab,onConversationOpened:at,onSelectAgent:Ne,onWorking:Oe,attention:W,agentsInHeader:H,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${T}`):n.jsx("main",{"data-ground":rX(Xe,e)?"plain":void 0,"data-layout":Xe===sn?"split":void 0,children:n.jsx(iX,{hash:e,place:Xe,timezone:s,navigate:t,agents:f,defaultAgentId:p,attention:W,pluginPages:q,update:X,connectionSignals:ee})})]}),mn?null:n.jsx(KQ,{status:Vn,onNavigate:t})]}),P&&$?n.jsx(e8,{agent:$,agents:f,open:O,onOpenChange:M,navigate:t}):null,n.jsxs(a8,{placement:i8(P,O),children:[n.jsx(c8,{queue:se.queue,agents:f,navigate:t,onDismiss:se.dismiss}),S?n.jsx(oh,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:g8,onUndo:en,onGone:()=>C(null)},S.group.id):null,I?n.jsx(oh,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>L(null)},`late-${I}`):null,n.jsx(Fb,{className:"ui-toasts"})]})]})})})}function rX(e,t){return jj(t)!==null}function iX({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=jj(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(rw,{page:a,item:i.item??null,params:BE(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 mt:return n.jsx(U9,{...r});case jt:return n.jsx(TK,{...s});case sn:return n.jsx(wJ,{...r});case Hr:return n.jsx(TW,{...s});default:return n.jsx(v7,{...r})}}function aX(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(kj)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function lX({search:e=location.search}){const[t,s]=d.useState(null),r=d.useRef(!1);return d.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;A.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(M$);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(le,{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(Et,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const yN=document.getElementById("root");yN&&MC(yN).render(n.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(lX,{}):n.jsx(XQ,{children:n.jsx(OQ,{children:n.jsx(QH,{children:n.jsx(sX,{})})})})}));aX();export{cX as c,FI as g};
|