@withbuddi/buddi 0.1.0-pre.25 → 0.1.0-pre.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/agents/agent-father/agent.md +1 -0
- package/extension/manifest.json +2 -2
- package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor-probes.js +29 -8
- package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.d.ts +8 -1
- package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.js +19 -2
- package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
- package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/agents/catalog.js +11 -2
- package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
- package/node_modules/@buddi/core/dist/agents/skills.d.ts +4 -4
- package/node_modules/@buddi/core/dist/notifications/agent.d.ts +54 -0
- package/node_modules/@buddi/core/dist/notifications/agent.d.ts.map +1 -0
- package/node_modules/@buddi/core/dist/notifications/agent.js +134 -0
- package/node_modules/@buddi/core/dist/notifications/agent.js.map +1 -0
- package/node_modules/@buddi/core/dist/notifications/index.d.ts +1 -0
- package/node_modules/@buddi/core/dist/notifications/index.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/index.js +1 -0
- package/node_modules/@buddi/core/dist/notifications/index.js.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/notify.d.ts +4 -0
- package/node_modules/@buddi/core/dist/notifications/notify.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/notify.js +19 -7
- package/node_modules/@buddi/core/dist/notifications/notify.js.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/store.d.ts +8 -1
- package/node_modules/@buddi/core/dist/notifications/store.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/store.js +55 -6
- package/node_modules/@buddi/core/dist/notifications/store.js.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/types.d.ts +26 -2
- package/node_modules/@buddi/core/dist/notifications/types.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/notifications/types.js +1 -1
- package/node_modules/@buddi/core/dist/notifications/types.js.map +1 -1
- package/node_modules/@buddi/core/dist/vault/resolve.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/vault/resolve.js +0 -1
- package/node_modules/@buddi/core/dist/vault/resolve.js.map +1 -1
- package/node_modules/@buddi/core/migrations/054_agent_messages.sql +15 -0
- package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts +34 -1
- package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents/owner-tools.js +87 -4
- package/node_modules/@buddi/gateway/dist/agents/owner-tools.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/bootstrap.js +3 -3
- package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/owner-secrets.d.ts +77 -8
- package/node_modules/@buddi/gateway/dist/owner-secrets.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/owner-secrets.js +142 -14
- package/node_modules/@buddi/gateway/dist/owner-secrets.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/serve.js +24 -8
- package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/system-context.d.ts +2 -0
- package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/system-context.js +5 -1
- package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts +7 -0
- package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/channel.js +14 -2
- package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/connections.d.ts +3 -0
- package/node_modules/@buddi/gateway/dist/web/connections.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/connections.js +48 -6
- package/node_modules/@buddi/gateway/dist/web/connections.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/notifications.d.ts +6 -0
- package/node_modules/@buddi/gateway/dist/web/notifications.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/notifications.js +14 -1
- package/node_modules/@buddi/gateway/dist/web/notifications.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/onboarding.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/onboarding.js +5 -2
- package/node_modules/@buddi/gateway/dist/web/onboarding.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/recovery.d.ts +10 -0
- package/node_modules/@buddi/gateway/dist/web/recovery.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/recovery.js +113 -33
- package/node_modules/@buddi/gateway/dist/web/recovery.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 +16 -5
- package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/sessions.d.ts +8 -0
- package/node_modules/@buddi/gateway/dist/web/sessions.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/sessions.js +24 -1
- package/node_modules/@buddi/gateway/dist/web/sessions.js.map +1 -1
- package/node_modules/@buddi/gateway/src/agents/starter/keeper/agent.md +2 -2
- package/node_modules/@buddi/gateway/src/agents/starter/planner/agent.md +1 -1
- package/node_modules/@buddi/gateway/src/agents/starter/scout/agent.md +1 -1
- package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/runtime/dist/delegate.js +1 -1
- package/node_modules/@buddi/runtime/dist/delegate.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-email/dist/config.d.ts +13 -9
- package/node_modules/@buddi/tool-email/dist/config.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/config.js +33 -40
- package/node_modules/@buddi/tool-email/dist/config.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/index.d.ts +1 -1
- package/node_modules/@buddi/tool-email/dist/index.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/index.js +1 -1
- package/node_modules/@buddi/tool-email/dist/index.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/accounts.d.ts +1 -2
- package/node_modules/@buddi/tool-email/dist/pages/accounts.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/accounts.js +42 -18
- package/node_modules/@buddi/tool-email/dist/pages/accounts.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/queries.js +7 -5
- package/node_modules/@buddi/tool-email/dist/pages/queries.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/ports.d.ts +5 -1
- package/node_modules/@buddi/tool-email/dist/ports.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/tools/shared.js +1 -1
- package/node_modules/@buddi/tool-email/dist/tools/shared.js.map +1 -1
- package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-web/dist/providers/index.d.ts +1 -2
- package/node_modules/@buddi/tool-web/dist/providers/index.d.ts.map +1 -1
- package/node_modules/@buddi/tool-web/dist/providers/index.js +1 -2
- package/node_modules/@buddi/tool-web/dist/providers/index.js.map +1 -1
- package/node_modules/hono/dist/cjs/jsx/utils.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -2
- package/node_modules/hono/dist/jsx/utils.js +1 -1
- package/node_modules/hono/dist/middleware/combine/index.js +3 -1
- package/node_modules/hono/dist/middleware/etag/index.js +2 -2
- package/node_modules/hono/dist/middleware/language/language.js +1 -1
- package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/aws-lambda/types.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/bun/websocket.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/service-worker/handler.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/service-worker/index.d.ts +2 -1
- package/node_modules/hono/dist/types/adapter/service-worker/types.d.ts +2 -1
- package/node_modules/hono/dist/types/client/types.d.ts +2 -1
- package/node_modules/hono/dist/types/context.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/cookie/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/css/common.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/css/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/dev/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/proxy/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/ssg/middleware.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/ssg/utils.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/hono-base.d.ts +2 -1
- package/node_modules/hono/dist/types/http-exception.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +4 -3
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/client.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/render.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/types.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/body-limit/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/combine/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/compress/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/cors/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/csrf/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/etag/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/jwt/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/language/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/logger/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/method-override/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/powered-by/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/pretty-json/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/request-id/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/secure-headers/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/timing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/timing/timing.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/trailing-slash/index.d.ts +2 -1
- package/node_modules/hono/dist/types/request.d.ts +2 -1
- package/node_modules/hono/dist/types/router/reg-exp-router/prepared-router.d.ts +2 -1
- package/node_modules/hono/dist/types/types.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/body.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/buffer.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/crypto.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/filepath.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/html.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/mime.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/types.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/url.d.ts +2 -1
- package/node_modules/hono/dist/types/validator/utils.d.ts +2 -1
- package/node_modules/hono/dist/types/validator/validator.d.ts +2 -1
- package/node_modules/hono/package.json +2 -2
- package/node_modules/pg/lib/client.js +18 -0
- package/node_modules/pg/lib/connection.js +8 -1
- package/node_modules/pg/lib/crypto/cert-signatures.js +1 -1
- package/node_modules/pg/lib/native/client.js +11 -3
- package/node_modules/pg/lib/native/query.js +3 -1
- package/node_modules/pg/lib/query.js +5 -1
- package/node_modules/pg/lib/utils.js +19 -1
- package/node_modules/pg/package.json +5 -5
- package/node_modules/pg-connection-string/index.js +1 -1
- package/node_modules/pg-connection-string/package.json +2 -3
- package/node_modules/pg-protocol/dist/buffer-writer.d.ts +5 -1
- package/node_modules/pg-protocol/dist/buffer-writer.js +10 -1
- package/node_modules/pg-protocol/dist/buffer-writer.js.map +1 -1
- package/node_modules/pg-protocol/dist/serializer.js +20 -18
- package/node_modules/pg-protocol/dist/serializer.js.map +1 -1
- package/node_modules/pg-protocol/package.json +2 -2
- package/node_modules/pg-protocol/src/buffer-writer.ts +12 -2
- package/node_modules/pg-protocol/src/serializer.ts +26 -20
- package/package.json +2 -2
- package/packages/cli/dist/.tsbuildinfo +1 -1
- package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
- package/packages/cli/dist/doctor-probes.js +29 -8
- package/packages/cli/dist/doctor-probes.js.map +1 -1
- package/packages/cli/dist/doctor.d.ts +8 -1
- package/packages/cli/dist/doctor.d.ts.map +1 -1
- package/packages/cli/dist/doctor.js +19 -2
- package/packages/cli/dist/doctor.js.map +1 -1
- package/packages/core/dist/.tsbuildinfo +1 -1
- package/packages/core/dist/agents/catalog.d.ts.map +1 -1
- package/packages/core/dist/agents/catalog.js +11 -2
- package/packages/core/dist/agents/catalog.js.map +1 -1
- package/packages/core/dist/agents/skills.d.ts +4 -4
- package/packages/core/dist/notifications/agent.d.ts +54 -0
- package/packages/core/dist/notifications/agent.d.ts.map +1 -0
- package/packages/core/dist/notifications/agent.js +134 -0
- package/packages/core/dist/notifications/agent.js.map +1 -0
- package/packages/core/dist/notifications/index.d.ts +1 -0
- package/packages/core/dist/notifications/index.d.ts.map +1 -1
- package/packages/core/dist/notifications/index.js +1 -0
- package/packages/core/dist/notifications/index.js.map +1 -1
- package/packages/core/dist/notifications/notify.d.ts +4 -0
- package/packages/core/dist/notifications/notify.d.ts.map +1 -1
- package/packages/core/dist/notifications/notify.js +19 -7
- package/packages/core/dist/notifications/notify.js.map +1 -1
- package/packages/core/dist/notifications/store.d.ts +8 -1
- package/packages/core/dist/notifications/store.d.ts.map +1 -1
- package/packages/core/dist/notifications/store.js +55 -6
- package/packages/core/dist/notifications/store.js.map +1 -1
- package/packages/core/dist/notifications/types.d.ts +26 -2
- package/packages/core/dist/notifications/types.d.ts.map +1 -1
- package/packages/core/dist/notifications/types.js +1 -1
- package/packages/core/dist/notifications/types.js.map +1 -1
- package/packages/core/dist/vault/resolve.d.ts.map +1 -1
- package/packages/core/dist/vault/resolve.js +0 -1
- package/packages/core/dist/vault/resolve.js.map +1 -1
- package/packages/core/migrations/054_agent_messages.sql +15 -0
- package/packages/gateway/dist/.tsbuildinfo +1 -1
- package/packages/gateway/dist/agents/owner-tools.d.ts +34 -1
- package/packages/gateway/dist/agents/owner-tools.d.ts.map +1 -1
- package/packages/gateway/dist/agents/owner-tools.js +87 -4
- package/packages/gateway/dist/agents/owner-tools.js.map +1 -1
- package/packages/gateway/dist/bootstrap.js +3 -3
- package/packages/gateway/dist/bootstrap.js.map +1 -1
- package/packages/gateway/dist/owner-secrets.d.ts +77 -8
- package/packages/gateway/dist/owner-secrets.d.ts.map +1 -1
- package/packages/gateway/dist/owner-secrets.js +142 -14
- package/packages/gateway/dist/owner-secrets.js.map +1 -1
- package/packages/gateway/dist/serve.d.ts.map +1 -1
- package/packages/gateway/dist/serve.js +24 -8
- package/packages/gateway/dist/serve.js.map +1 -1
- package/packages/gateway/dist/system-context.d.ts +2 -0
- package/packages/gateway/dist/system-context.d.ts.map +1 -1
- package/packages/gateway/dist/system-context.js +5 -1
- package/packages/gateway/dist/system-context.js.map +1 -1
- package/packages/gateway/dist/telegram/channel.d.ts +7 -0
- package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
- package/packages/gateway/dist/telegram/channel.js +14 -2
- package/packages/gateway/dist/telegram/channel.js.map +1 -1
- package/packages/gateway/dist/web/connections.d.ts +3 -0
- package/packages/gateway/dist/web/connections.d.ts.map +1 -1
- package/packages/gateway/dist/web/connections.js +48 -6
- package/packages/gateway/dist/web/connections.js.map +1 -1
- package/packages/gateway/dist/web/notifications.d.ts +6 -0
- package/packages/gateway/dist/web/notifications.d.ts.map +1 -1
- package/packages/gateway/dist/web/notifications.js +14 -1
- package/packages/gateway/dist/web/notifications.js.map +1 -1
- package/packages/gateway/dist/web/onboarding.d.ts.map +1 -1
- package/packages/gateway/dist/web/onboarding.js +5 -2
- package/packages/gateway/dist/web/onboarding.js.map +1 -1
- package/packages/gateway/dist/web/recovery.d.ts +10 -0
- package/packages/gateway/dist/web/recovery.d.ts.map +1 -1
- package/packages/gateway/dist/web/recovery.js +113 -33
- package/packages/gateway/dist/web/recovery.js.map +1 -1
- package/packages/gateway/dist/web/server.d.ts.map +1 -1
- package/packages/gateway/dist/web/server.js +16 -5
- package/packages/gateway/dist/web/server.js.map +1 -1
- package/packages/gateway/dist/web/sessions.d.ts +8 -0
- package/packages/gateway/dist/web/sessions.d.ts.map +1 -1
- package/packages/gateway/dist/web/sessions.js +24 -1
- package/packages/gateway/dist/web/sessions.js.map +1 -1
- package/packages/gateway/src/agents/starter/keeper/agent.md +2 -2
- package/packages/gateway/src/agents/starter/planner/agent.md +1 -1
- package/packages/gateway/src/agents/starter/scout/agent.md +1 -1
- package/packages/install/dist/.tsbuildinfo +1 -1
- package/packages/runtime/dist/.tsbuildinfo +1 -1
- package/packages/runtime/dist/delegate.js +1 -1
- package/packages/runtime/dist/delegate.js.map +1 -1
- package/packages/tools/email/dist/.tsbuildinfo +1 -1
- package/packages/tools/email/dist/config.d.ts +13 -9
- package/packages/tools/email/dist/config.d.ts.map +1 -1
- package/packages/tools/email/dist/config.js +33 -40
- package/packages/tools/email/dist/config.js.map +1 -1
- package/packages/tools/email/dist/index.d.ts +1 -1
- package/packages/tools/email/dist/index.d.ts.map +1 -1
- package/packages/tools/email/dist/index.js +1 -1
- package/packages/tools/email/dist/index.js.map +1 -1
- package/packages/tools/email/dist/pages/accounts.d.ts +1 -2
- package/packages/tools/email/dist/pages/accounts.d.ts.map +1 -1
- package/packages/tools/email/dist/pages/accounts.js +42 -18
- package/packages/tools/email/dist/pages/accounts.js.map +1 -1
- package/packages/tools/email/dist/pages/queries.d.ts.map +1 -1
- package/packages/tools/email/dist/pages/queries.js +7 -5
- package/packages/tools/email/dist/pages/queries.js.map +1 -1
- package/packages/tools/email/dist/ports.d.ts +5 -1
- package/packages/tools/email/dist/ports.d.ts.map +1 -1
- package/packages/tools/email/dist/tools/shared.js +1 -1
- package/packages/tools/email/dist/tools/shared.js.map +1 -1
- package/packages/tools/web/dist/.tsbuildinfo +1 -1
- package/packages/tools/web/dist/providers/index.d.ts +1 -2
- package/packages/tools/web/dist/providers/index.d.ts.map +1 -1
- package/packages/tools/web/dist/providers/index.js +1 -2
- package/packages/tools/web/dist/providers/index.js.map +1 -1
- package/packages/web/dist/assets/{index-DIXokQ4n.css → index-BxbiKNMS.css} +1 -1
- package/packages/web/dist/assets/index-Rrze3bGo.js +130 -0
- package/packages/web/dist/assets/{lottie_light-j3HICV9o.js → lottie_light-7wQnGwdw.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/packages/web/dist/sw.js +5 -3
- package/packages/web/dist/assets/index-uqQyuYjR.js +0 -128
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var Qv=e=>{throw TypeError(e)};var Jv=(e,t,s)=>t.has(e)||Qv("Cannot "+s);var an=(e,t,s)=>(Jv(e,t,"read from private field"),s?s.call(e):t.get(e)),Xv=(e,t,s)=>t.has(e)?Qv("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),fh=(e,t,s,r)=>(Jv(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function WA(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 QK=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function HA(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Nb={exports:{}},md={},Cb={exports:{}},Ue={};/**
|
|
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 Oo=Symbol.for("react.element"),KA=Symbol.for("react.portal"),VA=Symbol.for("react.fragment"),GA=Symbol.for("react.strict_mode"),YA=Symbol.for("react.profiler"),qA=Symbol.for("react.provider"),QA=Symbol.for("react.context"),JA=Symbol.for("react.forward_ref"),XA=Symbol.for("react.suspense"),ZA=Symbol.for("react.memo"),eT=Symbol.for("react.lazy"),Zv=Symbol.iterator;function tT(e){return e===null||typeof e!="object"?null:(e=Zv&&e[Zv]||e["@@iterator"],typeof e=="function"?e:null)}var Eb={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Ab=Object.assign,Tb={};function Xa(e,t,s){this.props=e,this.context=t,this.refs=Tb,this.updater=s||Eb}Xa.prototype.isReactComponent={};Xa.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")};Xa.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Rb(){}Rb.prototype=Xa.prototype;function Gp(e,t,s){this.props=e,this.context=t,this.refs=Tb,this.updater=s||Eb}var Yp=Gp.prototype=new Rb;Yp.constructor=Gp;Ab(Yp,Xa.prototype);Yp.isPureReactComponent=!0;var ej=Array.isArray,Ib=Object.prototype.hasOwnProperty,qp={current:null},Pb={key:!0,ref:!0,__self:!0,__source:!0};function $b(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)Ib.call(t,r)&&!Pb.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:Oo,type:e,key:a,ref:l,props:i,_owner:qp.current}}function nT(e,t){return{$$typeof:Oo,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Qp(e){return typeof e=="object"&&e!==null&&e.$$typeof===Oo}function sT(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var tj=/\/+/g;function mh(e,t){return typeof e=="object"&&e!==null&&e.key!=null?sT(""+e.key):t.toString(36)}function qc(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 Oo:case KA:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+mh(l,0):r,ej(i)?(s="",e!=null&&(s=e.replace(tj,"$&/")+"/"),qc(i,t,s,"",function(u){return u})):i!=null&&(Qp(i)&&(i=nT(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(tj,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",ej(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+mh(a,o);l+=qc(a,t,s,c,i)}else if(c=tT(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+mh(a,o++),l+=qc(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 ac(e,t,s){if(e==null)return e;var r=[],i=0;return qc(e,r,"","",function(a){return t.call(s,a,i++)}),r}function rT(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var jn={current:null},Qc={transition:null},iT={ReactCurrentDispatcher:jn,ReactCurrentBatchConfig:Qc,ReactCurrentOwner:qp};function Mb(){throw Error("act(...) is not supported in production builds of React.")}Ue.Children={map:ac,forEach:function(e,t,s){ac(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return ac(e,function(){t++}),t},toArray:function(e){return ac(e,function(t){return t})||[]},only:function(e){if(!Qp(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};Ue.Component=Xa;Ue.Fragment=VA;Ue.Profiler=YA;Ue.PureComponent=Gp;Ue.StrictMode=GA;Ue.Suspense=XA;Ue.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=iT;Ue.act=Mb;Ue.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=Ab({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=qp.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)Ib.call(t,c)&&!Pb.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:Oo,type:e.type,key:i,ref:a,props:r,_owner:l}};Ue.createContext=function(e){return e={$$typeof:QA,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:qA,_context:e},e.Consumer=e};Ue.createElement=$b;Ue.createFactory=function(e){var t=$b.bind(null,e);return t.type=e,t};Ue.createRef=function(){return{current:null}};Ue.forwardRef=function(e){return{$$typeof:JA,render:e}};Ue.isValidElement=Qp;Ue.lazy=function(e){return{$$typeof:eT,_payload:{_status:-1,_result:e},_init:rT}};Ue.memo=function(e,t){return{$$typeof:ZA,type:e,compare:t===void 0?null:t}};Ue.startTransition=function(e){var t=Qc.transition;Qc.transition={};try{e()}finally{Qc.transition=t}};Ue.unstable_act=Mb;Ue.useCallback=function(e,t){return jn.current.useCallback(e,t)};Ue.useContext=function(e){return jn.current.useContext(e)};Ue.useDebugValue=function(){};Ue.useDeferredValue=function(e){return jn.current.useDeferredValue(e)};Ue.useEffect=function(e,t){return jn.current.useEffect(e,t)};Ue.useId=function(){return jn.current.useId()};Ue.useImperativeHandle=function(e,t,s){return jn.current.useImperativeHandle(e,t,s)};Ue.useInsertionEffect=function(e,t){return jn.current.useInsertionEffect(e,t)};Ue.useLayoutEffect=function(e,t){return jn.current.useLayoutEffect(e,t)};Ue.useMemo=function(e,t){return jn.current.useMemo(e,t)};Ue.useReducer=function(e,t,s){return jn.current.useReducer(e,t,s)};Ue.useRef=function(e){return jn.current.useRef(e)};Ue.useState=function(e){return jn.current.useState(e)};Ue.useSyncExternalStore=function(e,t,s){return jn.current.useSyncExternalStore(e,t,s)};Ue.useTransition=function(){return jn.current.useTransition()};Ue.version="18.3.1";Cb.exports=Ue;var f=Cb.exports;const aT=HA(f),Za=WA({__proto__:null,default:aT},[f]);/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.production.min.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var lT=f,oT=Symbol.for("react.element"),cT=Symbol.for("react.fragment"),uT=Object.prototype.hasOwnProperty,dT=lT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,hT={key:!0,ref:!0,__self:!0,__source:!0};function Ob(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)uT.call(t,r)&&!hT.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:oT,type:e,key:a,ref:l,props:i,_owner:dT.current}}md.Fragment=cT;md.jsx=Ob;md.jsxs=Ob;Nb.exports=md;var n=Nb.exports,Db={exports:{}},Kn={},_b={exports:{}},Lb={};/**
|
|
18
|
+
* @license React
|
|
19
|
+
* scheduler.production.min.js
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/(function(e){function t(M,W){var D=M.length;M.push(W);e:for(;0<D;){var U=D-1>>>1,V=M[U];if(0<i(V,W))M[U]=W,M[D]=V,D=U;else break e}}function s(M){return M.length===0?null:M[0]}function r(M){if(M.length===0)return null;var W=M[0],D=M.pop();if(D!==W){M[0]=D;e:for(var U=0,V=M.length,Z=V>>>1;U<Z;){var ue=2*(U+1)-1,Ae=M[ue],X=ue+1,le=M[X];if(0>i(Ae,D))X<V&&0>i(le,Ae)?(M[U]=le,M[X]=D,U=X):(M[U]=Ae,M[ue]=D,U=ue);else if(X<V&&0>i(le,D))M[U]=le,M[X]=D,U=X;else break e}}return W}function i(M,W){var D=M.sortIndex-W.sortIndex;return D!==0?D:M.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=1,d=null,m=3,p=!1,g=!1,y=!1,b=typeof setTimeout=="function"?setTimeout:null,x=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function j(M){for(var W=s(u);W!==null;){if(W.callback===null)r(u);else if(W.startTime<=M)r(u),W.sortIndex=W.expirationTime,t(c,W);else break;W=s(u)}}function w(M){if(y=!1,j(M),!g)if(s(c)!==null)g=!0,_(S);else{var W=s(u);W!==null&&B(w,W.startTime-M)}}function S(M,W){g=!1,y&&(y=!1,x(C),C=-1),p=!0;var D=m;try{for(j(W),d=s(c);d!==null&&(!(d.expirationTime>W)||M&&!O());){var U=d.callback;if(typeof U=="function"){d.callback=null,m=d.priorityLevel;var V=U(d.expirationTime<=W);W=e.unstable_now(),typeof V=="function"?d.callback=V:d===s(c)&&r(c),j(W)}else r(c);d=s(c)}if(d!==null)var Z=!0;else{var ue=s(u);ue!==null&&B(w,ue.startTime-W),Z=!1}return Z}finally{d=null,m=D,p=!1}}var k=!1,N=null,C=-1,I=5,A=-1;function O(){return!(e.unstable_now()-A<I)}function z(){if(N!==null){var M=e.unstable_now();A=M;var W=!0;try{W=N(!0,M)}finally{W?L():(k=!1,N=null)}}else k=!1}var L;if(typeof v=="function")L=function(){v(z)};else if(typeof MessageChannel<"u"){var E=new MessageChannel,$=E.port2;E.port1.onmessage=z,L=function(){$.postMessage(null)}}else L=function(){b(z,0)};function _(M){N=M,k||(k=!0,L())}function B(M,W){C=b(function(){M(e.unstable_now())},W)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(M){M.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,_(S))},e.unstable_forceFrameRate=function(M){0>M||125<M?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):I=0<M?Math.floor(1e3/M):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(M){switch(m){case 1:case 2:case 3:var W=3;break;default:W=m}var D=m;m=W;try{return M()}finally{m=D}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(M,W){switch(M){case 1:case 2:case 3:case 4:case 5:break;default:M=3}var D=m;m=M;try{return W()}finally{m=D}},e.unstable_scheduleCallback=function(M,W,D){var U=e.unstable_now();switch(typeof D=="object"&&D!==null?(D=D.delay,D=typeof D=="number"&&0<D?U+D:U):D=U,M){case 1:var V=-1;break;case 2:V=250;break;case 5:V=1073741823;break;case 4:V=1e4;break;default:V=5e3}return V=D+V,M={id:h++,callback:W,priorityLevel:M,startTime:D,expirationTime:V,sortIndex:-1},D>U?(M.sortIndex=D,t(u,M),s(c)===null&&M===s(u)&&(y?(x(C),C=-1):y=!0,B(w,D-U))):(M.sortIndex=V,t(c,M),g||p||(g=!0,_(S))),M},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(M){var W=m;return function(){var D=m;m=W;try{return M.apply(this,arguments)}finally{m=D}}}})(Lb);_b.exports=Lb;var fT=_b.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 mT=f,Wn=fT;function re(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)t+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var Fb=new Set,Zl={};function Bi(e,t){Oa(e,t),Oa(e+"Capture",t)}function Oa(e,t){for(Zl[e]=t,e=0;e<t.length;e++)Fb.add(t[e])}var cr=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Mf=Object.prototype.hasOwnProperty,pT=/^[: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]*$/,nj={},sj={};function gT(e){return Mf.call(sj,e)?!0:Mf.call(nj,e)?!1:pT.test(e)?sj[e]=!0:(nj[e]=!0,!1)}function xT(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 vT(e,t,s,r){if(t===null||typeof t>"u"||xT(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 yn(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 Zt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Zt[e]=new yn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Zt[t]=new yn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Zt[e]=new yn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Zt[e]=new yn(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){Zt[e]=new yn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Zt[e]=new yn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Zt[e]=new yn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Zt[e]=new yn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Zt[e]=new yn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Jp=/[\-:]([a-z])/g;function Xp(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(Jp,Xp);Zt[t]=new yn(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(Jp,Xp);Zt[t]=new yn(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(Jp,Xp);Zt[t]=new yn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Zt[e]=new yn(e,1,!1,e.toLowerCase(),null,!1,!1)});Zt.xlinkHref=new yn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Zt[e]=new yn(e,1,!1,e.toLowerCase(),null,!0,!0)});function Zp(e,t,s,r){var i=Zt.hasOwnProperty(t)?Zt[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(vT(t,s,i,r)&&(s=null),r||i===null?gT(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 xr=mT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,lc=Symbol.for("react.element"),ca=Symbol.for("react.portal"),ua=Symbol.for("react.fragment"),eg=Symbol.for("react.strict_mode"),Of=Symbol.for("react.profiler"),zb=Symbol.for("react.provider"),Ub=Symbol.for("react.context"),tg=Symbol.for("react.forward_ref"),Df=Symbol.for("react.suspense"),_f=Symbol.for("react.suspense_list"),ng=Symbol.for("react.memo"),Tr=Symbol.for("react.lazy"),Bb=Symbol.for("react.offscreen"),rj=Symbol.iterator;function jl(e){return e===null||typeof e!="object"?null:(e=rj&&e[rj]||e["@@iterator"],typeof e=="function"?e:null)}var wt=Object.assign,ph;function $l(e){if(ph===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);ph=t&&t[1]||""}return`
|
|
34
|
+
`+ph+e}var gh=!1;function xh(e,t){if(!e||gh)return"";gh=!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{gh=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?$l(e):""}function jT(e){switch(e.tag){case 5:return $l(e.type);case 16:return $l("Lazy");case 13:return $l("Suspense");case 19:return $l("SuspenseList");case 0:case 2:case 15:return e=xh(e.type,!1),e;case 11:return e=xh(e.type.render,!1),e;case 1:return e=xh(e.type,!0),e;default:return""}}function Lf(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 ua:return"Fragment";case ca:return"Portal";case Of:return"Profiler";case eg:return"StrictMode";case Df:return"Suspense";case _f:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Ub:return(e.displayName||"Context")+".Consumer";case zb:return(e._context.displayName||"Context")+".Provider";case tg:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ng:return t=e.displayName||null,t!==null?t:Lf(e.type)||"Memo";case Tr:t=e._payload,e=e._init;try{return Lf(e(t))}catch{}}return null}function yT(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 Lf(t);case 8:return t===eg?"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 Jr(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Wb(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function wT(e){var t=Wb(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 oc(e){e._valueTracker||(e._valueTracker=wT(e))}function Hb(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=Wb(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function yu(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 Ff(e,t){var s=t.checked;return wt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function ij(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=Jr(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 Kb(e,t){t=t.checked,t!=null&&Zp(e,"checked",t,!1)}function zf(e,t){Kb(e,t);var s=Jr(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")?Uf(e,t.type,s):t.hasOwnProperty("defaultValue")&&Uf(e,t.type,Jr(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function aj(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 Uf(e,t,s){(t!=="number"||yu(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var Ml=Array.isArray;function ka(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=""+Jr(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 Bf(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(re(91));return wt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function lj(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(re(92));if(Ml(s)){if(1<s.length)throw Error(re(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:Jr(s)}}function Vb(e,t){var s=Jr(t.value),r=Jr(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 oj(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function Gb(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 Wf(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?Gb(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var cc,Yb=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(cc=cc||document.createElement("div"),cc.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=cc.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function eo(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Fl={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},bT=["Webkit","ms","Moz","O"];Object.keys(Fl).forEach(function(e){bT.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Fl[t]=Fl[e]})});function qb(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Fl.hasOwnProperty(e)&&Fl[e]?(""+t).trim():t+"px"}function Qb(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=qb(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var kT=wt({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 Hf(e,t){if(t){if(kT[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(re(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(re(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(re(61))}if(t.style!=null&&typeof t.style!="object")throw Error(re(62))}}function Kf(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 Vf=null;function sg(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Gf=null,Sa=null,Na=null;function cj(e){if(e=Lo(e)){if(typeof Gf!="function")throw Error(re(280));var t=e.stateNode;t&&(t=jd(t),Gf(e.stateNode,e.type,t))}}function Jb(e){Sa?Na?Na.push(e):Na=[e]:Sa=e}function Xb(){if(Sa){var e=Sa,t=Na;if(Na=Sa=null,cj(e),t)for(e=0;e<t.length;e++)cj(t[e])}}function Zb(e,t){return e(t)}function e0(){}var vh=!1;function t0(e,t,s){if(vh)return e(t,s);vh=!0;try{return Zb(e,t,s)}finally{vh=!1,(Sa!==null||Na!==null)&&(e0(),Xb())}}function to(e,t){var s=e.stateNode;if(s===null)return null;var r=jd(s);if(r===null)return null;s=r[t];e:switch(t){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(s&&typeof s!="function")throw Error(re(231,t,typeof s));return s}var Yf=!1;if(cr)try{var yl={};Object.defineProperty(yl,"passive",{get:function(){Yf=!0}}),window.addEventListener("test",yl,yl),window.removeEventListener("test",yl,yl)}catch{Yf=!1}function ST(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 zl=!1,wu=null,bu=!1,qf=null,NT={onError:function(e){zl=!0,wu=e}};function CT(e,t,s,r,i,a,l,o,c){zl=!1,wu=null,ST.apply(NT,arguments)}function ET(e,t,s,r,i,a,l,o,c){if(CT.apply(this,arguments),zl){if(zl){var u=wu;zl=!1,wu=null}else throw Error(re(198));bu||(bu=!0,qf=u)}}function Wi(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 n0(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 uj(e){if(Wi(e)!==e)throw Error(re(188))}function AT(e){var t=e.alternate;if(!t){if(t=Wi(e),t===null)throw Error(re(188));return t!==e?null:e}for(var s=e,r=t;;){var i=s.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){s=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===s)return uj(i),e;if(a===r)return uj(i),t;a=a.sibling}throw Error(re(188))}if(s.return!==r.return)s=i,r=a;else{for(var l=!1,o=i.child;o;){if(o===s){l=!0,s=i,r=a;break}if(o===r){l=!0,r=i,s=a;break}o=o.sibling}if(!l){for(o=a.child;o;){if(o===s){l=!0,s=a,r=i;break}if(o===r){l=!0,r=a,s=i;break}o=o.sibling}if(!l)throw Error(re(189))}}if(s.alternate!==r)throw Error(re(190))}if(s.tag!==3)throw Error(re(188));return s.stateNode.current===s?e:t}function s0(e){return e=AT(e),e!==null?r0(e):null}function r0(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=r0(e);if(t!==null)return t;e=e.sibling}return null}var i0=Wn.unstable_scheduleCallback,dj=Wn.unstable_cancelCallback,TT=Wn.unstable_shouldYield,RT=Wn.unstable_requestPaint,Rt=Wn.unstable_now,IT=Wn.unstable_getCurrentPriorityLevel,rg=Wn.unstable_ImmediatePriority,a0=Wn.unstable_UserBlockingPriority,ku=Wn.unstable_NormalPriority,PT=Wn.unstable_LowPriority,l0=Wn.unstable_IdlePriority,pd=null,zs=null;function $T(e){if(zs&&typeof zs.onCommitFiberRoot=="function")try{zs.onCommitFiberRoot(pd,e,void 0,(e.current.flags&128)===128)}catch{}}var gs=Math.clz32?Math.clz32:DT,MT=Math.log,OT=Math.LN2;function DT(e){return e>>>=0,e===0?32:31-(MT(e)/OT|0)|0}var uc=64,dc=4194304;function Ol(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 Su(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=Ol(o):(a&=l,a!==0&&(r=Ol(a)))}else l=s&~i,l!==0?r=Ol(l):a!==0&&(r=Ol(a));if(r===0)return 0;if(t!==0&&t!==r&&!(t&i)&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if(r&4&&(r|=s&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)s=31-gs(t),i=1<<s,r|=e[s],t&=~i;return r}function _T(e,t){switch(e){case 1:case 2:case 4:return t+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function LT(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-gs(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=_T(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function Qf(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function o0(){var e=uc;return uc<<=1,!(uc&4194240)&&(uc=64),e}function jh(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Do(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-gs(t),e[t]=s}function FT(e,t){var s=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var i=31-gs(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function ig(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-gs(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var Ze=0;function c0(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var u0,ag,d0,h0,f0,Jf=!1,hc=[],Lr=null,Fr=null,zr=null,no=new Map,so=new Map,Ir=[],zT="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 hj(e,t){switch(e){case"focusin":case"focusout":Lr=null;break;case"dragenter":case"dragleave":Fr=null;break;case"mouseover":case"mouseout":zr=null;break;case"pointerover":case"pointerout":no.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":so.delete(t.pointerId)}}function wl(e,t,s,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:s,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=Lo(t),t!==null&&ag(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function UT(e,t,s,r,i){switch(t){case"focusin":return Lr=wl(Lr,e,t,s,r,i),!0;case"dragenter":return Fr=wl(Fr,e,t,s,r,i),!0;case"mouseover":return zr=wl(zr,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return no.set(a,wl(no.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,so.set(a,wl(so.get(a)||null,e,t,s,r,i)),!0}return!1}function m0(e){var t=ki(e.target);if(t!==null){var s=Wi(t);if(s!==null){if(t=s.tag,t===13){if(t=n0(s),t!==null){e.blockedOn=t,f0(e.priority,function(){d0(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 Jc(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=Xf(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Vf=r,s.target.dispatchEvent(r),Vf=null}else return t=Lo(s),t!==null&&ag(t),e.blockedOn=s,!1;t.shift()}return!0}function fj(e,t,s){Jc(e)&&s.delete(t)}function BT(){Jf=!1,Lr!==null&&Jc(Lr)&&(Lr=null),Fr!==null&&Jc(Fr)&&(Fr=null),zr!==null&&Jc(zr)&&(zr=null),no.forEach(fj),so.forEach(fj)}function bl(e,t){e.blockedOn===t&&(e.blockedOn=null,Jf||(Jf=!0,Wn.unstable_scheduleCallback(Wn.unstable_NormalPriority,BT)))}function ro(e){function t(i){return bl(i,e)}if(0<hc.length){bl(hc[0],e);for(var s=1;s<hc.length;s++){var r=hc[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Lr!==null&&bl(Lr,e),Fr!==null&&bl(Fr,e),zr!==null&&bl(zr,e),no.forEach(t),so.forEach(t),s=0;s<Ir.length;s++)r=Ir[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Ir.length&&(s=Ir[0],s.blockedOn===null);)m0(s),s.blockedOn===null&&Ir.shift()}var Ca=xr.ReactCurrentBatchConfig,Nu=!0;function WT(e,t,s,r){var i=Ze,a=Ca.transition;Ca.transition=null;try{Ze=1,lg(e,t,s,r)}finally{Ze=i,Ca.transition=a}}function HT(e,t,s,r){var i=Ze,a=Ca.transition;Ca.transition=null;try{Ze=4,lg(e,t,s,r)}finally{Ze=i,Ca.transition=a}}function lg(e,t,s,r){if(Nu){var i=Xf(e,t,s,r);if(i===null)Th(e,t,r,Cu,s),hj(e,r);else if(UT(i,e,t,s,r))r.stopPropagation();else if(hj(e,r),t&4&&-1<zT.indexOf(e)){for(;i!==null;){var a=Lo(i);if(a!==null&&u0(a),a=Xf(e,t,s,r),a===null&&Th(e,t,r,Cu,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else Th(e,t,r,null,s)}}var Cu=null;function Xf(e,t,s,r){if(Cu=null,e=sg(r),e=ki(e),e!==null)if(t=Wi(e),t===null)e=null;else if(s=t.tag,s===13){if(e=n0(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 Cu=e,null}function p0(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(IT()){case rg:return 1;case a0:return 4;case ku:case PT:return 16;case l0:return 536870912;default:return 16}default:return 16}}var $r=null,og=null,Xc=null;function g0(){if(Xc)return Xc;var e,t=og,s=t.length,r,i="value"in $r?$r.value:$r.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 Xc=i.slice(e,1<r?1-r:void 0)}function Zc(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 fc(){return!0}function mj(){return!1}function Vn(e){function t(s,r,i,a,l){this._reactName=s,this._targetInst=i,this.type=r,this.nativeEvent=a,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(a):a[o]);return this.isDefaultPrevented=(a.defaultPrevented!=null?a.defaultPrevented:a.returnValue===!1)?fc:mj,this.isPropagationStopped=mj,this}return wt(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=fc)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=fc)},persist:function(){},isPersistent:fc}),t}var el={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},cg=Vn(el),_o=wt({},el,{view:0,detail:0}),KT=Vn(_o),yh,wh,kl,gd=wt({},_o,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:ug,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!==kl&&(kl&&e.type==="mousemove"?(yh=e.screenX-kl.screenX,wh=e.screenY-kl.screenY):wh=yh=0,kl=e),yh)},movementY:function(e){return"movementY"in e?e.movementY:wh}}),pj=Vn(gd),VT=wt({},gd,{dataTransfer:0}),GT=Vn(VT),YT=wt({},_o,{relatedTarget:0}),bh=Vn(YT),qT=wt({},el,{animationName:0,elapsedTime:0,pseudoElement:0}),QT=Vn(qT),JT=wt({},el,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),XT=Vn(JT),ZT=wt({},el,{data:0}),gj=Vn(ZT),eR={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},tR={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"},nR={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function sR(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=nR[e])?!!t[e]:!1}function ug(){return sR}var rR=wt({},_o,{key:function(e){if(e.key){var t=eR[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Zc(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?tR[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:ug,charCode:function(e){return e.type==="keypress"?Zc(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Zc(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),iR=Vn(rR),aR=wt({},gd,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),xj=Vn(aR),lR=wt({},_o,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:ug}),oR=Vn(lR),cR=wt({},el,{propertyName:0,elapsedTime:0,pseudoElement:0}),uR=Vn(cR),dR=wt({},gd,{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}),hR=Vn(dR),fR=[9,13,27,32],dg=cr&&"CompositionEvent"in window,Ul=null;cr&&"documentMode"in document&&(Ul=document.documentMode);var mR=cr&&"TextEvent"in window&&!Ul,x0=cr&&(!dg||Ul&&8<Ul&&11>=Ul),vj=" ",jj=!1;function v0(e,t){switch(e){case"keyup":return fR.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function j0(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var da=!1;function pR(e,t){switch(e){case"compositionend":return j0(t);case"keypress":return t.which!==32?null:(jj=!0,vj);case"textInput":return e=t.data,e===vj&&jj?null:e;default:return null}}function gR(e,t){if(da)return e==="compositionend"||!dg&&v0(e,t)?(e=g0(),Xc=og=$r=null,da=!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 x0&&t.locale!=="ko"?null:t.data;default:return null}}var xR={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 yj(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!xR[e.type]:t==="textarea"}function y0(e,t,s,r){Jb(r),t=Eu(t,"onChange"),0<t.length&&(s=new cg("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var Bl=null,io=null;function vR(e){I0(e,0)}function xd(e){var t=ma(e);if(Hb(t))return e}function jR(e,t){if(e==="change")return t}var w0=!1;if(cr){var kh;if(cr){var Sh="oninput"in document;if(!Sh){var wj=document.createElement("div");wj.setAttribute("oninput","return;"),Sh=typeof wj.oninput=="function"}kh=Sh}else kh=!1;w0=kh&&(!document.documentMode||9<document.documentMode)}function bj(){Bl&&(Bl.detachEvent("onpropertychange",b0),io=Bl=null)}function b0(e){if(e.propertyName==="value"&&xd(io)){var t=[];y0(t,io,e,sg(e)),t0(vR,t)}}function yR(e,t,s){e==="focusin"?(bj(),Bl=t,io=s,Bl.attachEvent("onpropertychange",b0)):e==="focusout"&&bj()}function wR(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return xd(io)}function bR(e,t){if(e==="click")return xd(t)}function kR(e,t){if(e==="input"||e==="change")return xd(t)}function SR(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var ws=typeof Object.is=="function"?Object.is:SR;function ao(e,t){if(ws(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(!Mf.call(t,i)||!ws(e[i],t[i]))return!1}return!0}function kj(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Sj(e,t){var s=kj(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=kj(s)}}function k0(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?k0(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function S0(){for(var e=window,t=yu();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=yu(e.document)}return t}function hg(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 NR(e){var t=S0(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&k0(s.ownerDocument.documentElement,s)){if(r!==null&&hg(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=Sj(s,a);var l=Sj(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 CR=cr&&"documentMode"in document&&11>=document.documentMode,ha=null,Zf=null,Wl=null,em=!1;function Nj(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;em||ha==null||ha!==yu(r)||(r=ha,"selectionStart"in r&&hg(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}),Wl&&ao(Wl,r)||(Wl=r,r=Eu(Zf,"onSelect"),0<r.length&&(t=new cg("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=ha)))}function mc(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var fa={animationend:mc("Animation","AnimationEnd"),animationiteration:mc("Animation","AnimationIteration"),animationstart:mc("Animation","AnimationStart"),transitionend:mc("Transition","TransitionEnd")},Nh={},N0={};cr&&(N0=document.createElement("div").style,"AnimationEvent"in window||(delete fa.animationend.animation,delete fa.animationiteration.animation,delete fa.animationstart.animation),"TransitionEvent"in window||delete fa.transitionend.transition);function vd(e){if(Nh[e])return Nh[e];if(!fa[e])return e;var t=fa[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in N0)return Nh[e]=t[s];return e}var C0=vd("animationend"),E0=vd("animationiteration"),A0=vd("animationstart"),T0=vd("transitionend"),R0=new Map,Cj="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 ai(e,t){R0.set(e,t),Bi(t,[e])}for(var Ch=0;Ch<Cj.length;Ch++){var Eh=Cj[Ch],ER=Eh.toLowerCase(),AR=Eh[0].toUpperCase()+Eh.slice(1);ai(ER,"on"+AR)}ai(C0,"onAnimationEnd");ai(E0,"onAnimationIteration");ai(A0,"onAnimationStart");ai("dblclick","onDoubleClick");ai("focusin","onFocus");ai("focusout","onBlur");ai(T0,"onTransitionEnd");Oa("onMouseEnter",["mouseout","mouseover"]);Oa("onMouseLeave",["mouseout","mouseover"]);Oa("onPointerEnter",["pointerout","pointerover"]);Oa("onPointerLeave",["pointerout","pointerover"]);Bi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Bi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Bi("onBeforeInput",["compositionend","keypress","textInput","paste"]);Bi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Bi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Bi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Dl="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(" "),TR=new Set("cancel close invalid load scroll toggle".split(" ").concat(Dl));function Ej(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,ET(r,t,void 0,e),e.currentTarget=null}function I0(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;Ej(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;Ej(i,o,u),a=c}}}if(bu)throw e=qf,bu=!1,qf=null,e}function ot(e,t){var s=t[im];s===void 0&&(s=t[im]=new Set);var r=e+"__bubble";s.has(r)||(P0(t,e,2,!1),s.add(r))}function Ah(e,t,s){var r=0;t&&(r|=4),P0(s,e,r,t)}var pc="_reactListening"+Math.random().toString(36).slice(2);function lo(e){if(!e[pc]){e[pc]=!0,Fb.forEach(function(s){s!=="selectionchange"&&(TR.has(s)||Ah(s,!1,e),Ah(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[pc]||(t[pc]=!0,Ah("selectionchange",!1,t))}}function P0(e,t,s,r){switch(p0(t)){case 1:var i=WT;break;case 4:i=HT;break;default:i=lg}s=i.bind(null,t,s,e),i=void 0,!Yf||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 Th(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=ki(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}t0(function(){var u=a,h=sg(s),d=[];e:{var m=R0.get(e);if(m!==void 0){var p=cg,g=e;switch(e){case"keypress":if(Zc(s)===0)break e;case"keydown":case"keyup":p=iR;break;case"focusin":g="focus",p=bh;break;case"focusout":g="blur",p=bh;break;case"beforeblur":case"afterblur":p=bh;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=pj;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=GT;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=oR;break;case C0:case E0:case A0:p=QT;break;case T0:p=uR;break;case"scroll":p=KT;break;case"wheel":p=hR;break;case"copy":case"cut":case"paste":p=XT;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=xj}var y=(t&4)!==0,b=!y&&e==="scroll",x=y?m!==null?m+"Capture":null:m;y=[];for(var v=u,j;v!==null;){j=v;var w=j.stateNode;if(j.tag===5&&w!==null&&(j=w,x!==null&&(w=to(v,x),w!=null&&y.push(oo(v,w,j)))),b)break;v=v.return}0<y.length&&(m=new p(m,g,null,s,h),d.push({event:m,listeners:y}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Vf&&(g=s.relatedTarget||s.fromElement)&&(ki(g)||g[ur]))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?ki(g):null,g!==null&&(b=Wi(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(y=pj,w="onMouseLeave",x="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(y=xj,w="onPointerLeave",x="onPointerEnter",v="pointer"),b=p==null?m:ma(p),j=g==null?m:ma(g),m=new y(w,v+"leave",p,s,h),m.target=b,m.relatedTarget=j,w=null,ki(h)===u&&(y=new y(x,v+"enter",g,s,h),y.target=j,y.relatedTarget=b,w=y),b=w,p&&g)t:{for(y=p,x=g,v=0,j=y;j;j=ea(j))v++;for(j=0,w=x;w;w=ea(w))j++;for(;0<v-j;)y=ea(y),v--;for(;0<j-v;)x=ea(x),j--;for(;v--;){if(y===x||x!==null&&y===x.alternate)break t;y=ea(y),x=ea(x)}y=null}else y=null;p!==null&&Aj(d,m,p,y,!1),g!==null&&b!==null&&Aj(d,b,g,y,!0)}}e:{if(m=u?ma(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var S=jR;else if(yj(m))if(w0)S=kR;else{S=wR;var k=yR}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(S=bR);if(S&&(S=S(e,u))){y0(d,S,s,h);break e}k&&k(e,m,u),e==="focusout"&&(k=m._wrapperState)&&k.controlled&&m.type==="number"&&Uf(m,"number",m.value)}switch(k=u?ma(u):window,e){case"focusin":(yj(k)||k.contentEditable==="true")&&(ha=k,Zf=u,Wl=null);break;case"focusout":Wl=Zf=ha=null;break;case"mousedown":em=!0;break;case"contextmenu":case"mouseup":case"dragend":em=!1,Nj(d,s,h);break;case"selectionchange":if(CR)break;case"keydown":case"keyup":Nj(d,s,h)}var N;if(dg)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 da?v0(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(x0&&s.locale!=="ko"&&(da||C!=="onCompositionStart"?C==="onCompositionEnd"&&da&&(N=g0()):($r=h,og="value"in $r?$r.value:$r.textContent,da=!0)),k=Eu(u,C),0<k.length&&(C=new gj(C,e,null,s,h),d.push({event:C,listeners:k}),N?C.data=N:(N=j0(s),N!==null&&(C.data=N)))),(N=mR?pR(e,s):gR(e,s))&&(u=Eu(u,"onBeforeInput"),0<u.length&&(h=new gj("onBeforeInput","beforeinput",null,s,h),d.push({event:h,listeners:u}),h.data=N))}I0(d,t)})}function oo(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Eu(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=to(e,s),a!=null&&r.unshift(oo(e,a,i)),a=to(e,t),a!=null&&r.push(oo(e,a,i))),e=e.return}return r}function ea(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Aj(e,t,s,r,i){for(var a=t._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,u=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&u!==null&&(o=u,i?(c=to(s,a),c!=null&&l.unshift(oo(s,c,o))):i||(c=to(s,a),c!=null&&l.push(oo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var RR=/\r\n?/g,IR=/\u0000|\uFFFD/g;function Tj(e){return(typeof e=="string"?e:""+e).replace(RR,`
|
|
38
|
+
`).replace(IR,"")}function gc(e,t,s){if(t=Tj(t),Tj(e)!==t&&s)throw Error(re(425))}function Au(){}var tm=null,nm=null;function sm(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 rm=typeof setTimeout=="function"?setTimeout:void 0,PR=typeof clearTimeout=="function"?clearTimeout:void 0,Rj=typeof Promise=="function"?Promise:void 0,$R=typeof queueMicrotask=="function"?queueMicrotask:typeof Rj<"u"?function(e){return Rj.resolve(null).then(e).catch(MR)}:rm;function MR(e){setTimeout(function(){throw e})}function Rh(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),ro(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);ro(t)}function Ur(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 Ij(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 tl=Math.random().toString(36).slice(2),Ds="__reactFiber$"+tl,co="__reactProps$"+tl,ur="__reactContainer$"+tl,im="__reactEvents$"+tl,OR="__reactListeners$"+tl,DR="__reactHandles$"+tl;function ki(e){var t=e[Ds];if(t)return t;for(var s=e.parentNode;s;){if(t=s[ur]||s[Ds]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=Ij(e);e!==null;){if(s=e[Ds])return s;e=Ij(e)}return t}e=s,s=e.parentNode}return null}function Lo(e){return e=e[Ds]||e[ur],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function ma(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(re(33))}function jd(e){return e[co]||null}var am=[],pa=-1;function li(e){return{current:e}}function ct(e){0>pa||(e.current=am[pa],am[pa]=null,pa--)}function rt(e,t){pa++,am[pa]=e.current,e.current=t}var Xr={},fn=li(Xr),Cn=li(!1),Ii=Xr;function Da(e,t){var s=e.type.contextTypes;if(!s)return Xr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in s)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function En(e){return e=e.childContextTypes,e!=null}function Tu(){ct(Cn),ct(fn)}function Pj(e,t,s){if(fn.current!==Xr)throw Error(re(168));rt(fn,t),rt(Cn,s)}function $0(e,t,s){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(re(108,yT(e)||"Unknown",i));return wt({},s,r)}function Ru(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Xr,Ii=fn.current,rt(fn,e),rt(Cn,Cn.current),!0}function $j(e,t,s){var r=e.stateNode;if(!r)throw Error(re(169));s?(e=$0(e,t,Ii),r.__reactInternalMemoizedMergedChildContext=e,ct(Cn),ct(fn),rt(fn,e)):ct(Cn),rt(Cn,s)}var er=null,yd=!1,Ih=!1;function M0(e){er===null?er=[e]:er.push(e)}function _R(e){yd=!0,M0(e)}function oi(){if(!Ih&&er!==null){Ih=!0;var e=0,t=Ze;try{var s=er;for(Ze=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}er=null,yd=!1}catch(i){throw er!==null&&(er=er.slice(e+1)),i0(rg,oi),i}finally{Ze=t,Ih=!1}}return null}var ga=[],xa=0,Iu=null,Pu=0,ts=[],ns=0,Pi=null,sr=1,rr="";function ji(e,t){ga[xa++]=Pu,ga[xa++]=Iu,Iu=e,Pu=t}function O0(e,t,s){ts[ns++]=sr,ts[ns++]=rr,ts[ns++]=Pi,Pi=e;var r=sr;e=rr;var i=32-gs(r)-1;r&=~(1<<i),s+=1;var a=32-gs(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,sr=1<<32-gs(t)+i|s<<i|r,rr=a+e}else sr=1<<a|s<<i|r,rr=e}function fg(e){e.return!==null&&(ji(e,1),O0(e,1,0))}function mg(e){for(;e===Iu;)Iu=ga[--xa],ga[xa]=null,Pu=ga[--xa],ga[xa]=null;for(;e===Pi;)Pi=ts[--ns],ts[ns]=null,rr=ts[--ns],ts[ns]=null,sr=ts[--ns],ts[ns]=null}var Un=null,Fn=null,ht=!1,ms=null;function D0(e,t){var s=is(5,null,null,0);s.elementType="DELETED",s.stateNode=t,s.return=e,t=e.deletions,t===null?(e.deletions=[s],e.flags|=16):t.push(s)}function Mj(e,t){switch(e.tag){case 5:var s=e.type;return t=t.nodeType!==1||s.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,Un=e,Fn=Ur(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,Un=e,Fn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=Pi!==null?{id:sr,overflow:rr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=is(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,Un=e,Fn=null,!0):!1;default:return!1}}function lm(e){return(e.mode&1)!==0&&(e.flags&128)===0}function om(e){if(ht){var t=Fn;if(t){var s=t;if(!Mj(e,t)){if(lm(e))throw Error(re(418));t=Ur(s.nextSibling);var r=Un;t&&Mj(e,t)?D0(r,s):(e.flags=e.flags&-4097|2,ht=!1,Un=e)}}else{if(lm(e))throw Error(re(418));e.flags=e.flags&-4097|2,ht=!1,Un=e}}}function Oj(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Un=e}function xc(e){if(e!==Un)return!1;if(!ht)return Oj(e),ht=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!sm(e.type,e.memoizedProps)),t&&(t=Fn)){if(lm(e))throw _0(),Error(re(418));for(;t;)D0(e,t),t=Ur(t.nextSibling)}if(Oj(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(re(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Fn=Ur(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Fn=null}}else Fn=Un?Ur(e.stateNode.nextSibling):null;return!0}function _0(){for(var e=Fn;e;)e=Ur(e.nextSibling)}function _a(){Fn=Un=null,ht=!1}function pg(e){ms===null?ms=[e]:ms.push(e)}var LR=xr.ReactCurrentBatchConfig;function Sl(e,t,s){if(e=s.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(s._owner){if(s=s._owner,s){if(s.tag!==1)throw Error(re(309));var r=s.stateNode}if(!r)throw Error(re(147,e));var i=r,a=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===a?t.ref:(t=function(l){var o=i.refs;l===null?delete o[a]:o[a]=l},t._stringRef=a,t)}if(typeof e!="string")throw Error(re(284));if(!s._owner)throw Error(re(290,e))}return e}function vc(e,t){throw e=Object.prototype.toString.call(t),Error(re(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function Dj(e){var t=e._init;return t(e._payload)}function L0(e){function t(x,v){if(e){var j=x.deletions;j===null?(x.deletions=[v],x.flags|=16):j.push(v)}}function s(x,v){if(!e)return null;for(;v!==null;)t(x,v),v=v.sibling;return null}function r(x,v){for(x=new Map;v!==null;)v.key!==null?x.set(v.key,v):x.set(v.index,v),v=v.sibling;return x}function i(x,v){return x=Kr(x,v),x.index=0,x.sibling=null,x}function a(x,v,j){return x.index=j,e?(j=x.alternate,j!==null?(j=j.index,j<v?(x.flags|=2,v):j):(x.flags|=2,v)):(x.flags|=1048576,v)}function l(x){return e&&x.alternate===null&&(x.flags|=2),x}function o(x,v,j,w){return v===null||v.tag!==6?(v=Lh(j,x.mode,w),v.return=x,v):(v=i(v,j),v.return=x,v)}function c(x,v,j,w){var S=j.type;return S===ua?h(x,v,j.props.children,w,j.key):v!==null&&(v.elementType===S||typeof S=="object"&&S!==null&&S.$$typeof===Tr&&Dj(S)===v.type)?(w=i(v,j.props),w.ref=Sl(x,v,j),w.return=x,w):(w=au(j.type,j.key,j.props,null,x.mode,w),w.ref=Sl(x,v,j),w.return=x,w)}function u(x,v,j,w){return v===null||v.tag!==4||v.stateNode.containerInfo!==j.containerInfo||v.stateNode.implementation!==j.implementation?(v=Fh(j,x.mode,w),v.return=x,v):(v=i(v,j.children||[]),v.return=x,v)}function h(x,v,j,w,S){return v===null||v.tag!==7?(v=Ei(j,x.mode,w,S),v.return=x,v):(v=i(v,j),v.return=x,v)}function d(x,v,j){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Lh(""+v,x.mode,j),v.return=x,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case lc:return j=au(v.type,v.key,v.props,null,x.mode,j),j.ref=Sl(x,null,v),j.return=x,j;case ca:return v=Fh(v,x.mode,j),v.return=x,v;case Tr:var w=v._init;return d(x,w(v._payload),j)}if(Ml(v)||jl(v))return v=Ei(v,x.mode,j,null),v.return=x,v;vc(x,v)}return null}function m(x,v,j,w){var S=v!==null?v.key:null;if(typeof j=="string"&&j!==""||typeof j=="number")return S!==null?null:o(x,v,""+j,w);if(typeof j=="object"&&j!==null){switch(j.$$typeof){case lc:return j.key===S?c(x,v,j,w):null;case ca:return j.key===S?u(x,v,j,w):null;case Tr:return S=j._init,m(x,v,S(j._payload),w)}if(Ml(j)||jl(j))return S!==null?null:h(x,v,j,w,null);vc(x,j)}return null}function p(x,v,j,w,S){if(typeof w=="string"&&w!==""||typeof w=="number")return x=x.get(j)||null,o(v,x,""+w,S);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case lc:return x=x.get(w.key===null?j:w.key)||null,c(v,x,w,S);case ca:return x=x.get(w.key===null?j:w.key)||null,u(v,x,w,S);case Tr:var k=w._init;return p(x,v,j,k(w._payload),S)}if(Ml(w)||jl(w))return x=x.get(j)||null,h(v,x,w,S,null);vc(v,w)}return null}function g(x,v,j,w){for(var S=null,k=null,N=v,C=v=0,I=null;N!==null&&C<j.length;C++){N.index>C?(I=N,N=null):I=N.sibling;var A=m(x,N,j[C],w);if(A===null){N===null&&(N=I);break}e&&N&&A.alternate===null&&t(x,N),v=a(A,v,C),k===null?S=A:k.sibling=A,k=A,N=I}if(C===j.length)return s(x,N),ht&&ji(x,C),S;if(N===null){for(;C<j.length;C++)N=d(x,j[C],w),N!==null&&(v=a(N,v,C),k===null?S=N:k.sibling=N,k=N);return ht&&ji(x,C),S}for(N=r(x,N);C<j.length;C++)I=p(N,x,C,j[C],w),I!==null&&(e&&I.alternate!==null&&N.delete(I.key===null?C:I.key),v=a(I,v,C),k===null?S=I:k.sibling=I,k=I);return e&&N.forEach(function(O){return t(x,O)}),ht&&ji(x,C),S}function y(x,v,j,w){var S=jl(j);if(typeof S!="function")throw Error(re(150));if(j=S.call(j),j==null)throw Error(re(151));for(var k=S=null,N=v,C=v=0,I=null,A=j.next();N!==null&&!A.done;C++,A=j.next()){N.index>C?(I=N,N=null):I=N.sibling;var O=m(x,N,A.value,w);if(O===null){N===null&&(N=I);break}e&&N&&O.alternate===null&&t(x,N),v=a(O,v,C),k===null?S=O:k.sibling=O,k=O,N=I}if(A.done)return s(x,N),ht&&ji(x,C),S;if(N===null){for(;!A.done;C++,A=j.next())A=d(x,A.value,w),A!==null&&(v=a(A,v,C),k===null?S=A:k.sibling=A,k=A);return ht&&ji(x,C),S}for(N=r(x,N);!A.done;C++,A=j.next())A=p(N,x,C,A.value,w),A!==null&&(e&&A.alternate!==null&&N.delete(A.key===null?C:A.key),v=a(A,v,C),k===null?S=A:k.sibling=A,k=A);return e&&N.forEach(function(z){return t(x,z)}),ht&&ji(x,C),S}function b(x,v,j,w){if(typeof j=="object"&&j!==null&&j.type===ua&&j.key===null&&(j=j.props.children),typeof j=="object"&&j!==null){switch(j.$$typeof){case lc:e:{for(var S=j.key,k=v;k!==null;){if(k.key===S){if(S=j.type,S===ua){if(k.tag===7){s(x,k.sibling),v=i(k,j.props.children),v.return=x,x=v;break e}}else if(k.elementType===S||typeof S=="object"&&S!==null&&S.$$typeof===Tr&&Dj(S)===k.type){s(x,k.sibling),v=i(k,j.props),v.ref=Sl(x,k,j),v.return=x,x=v;break e}s(x,k);break}else t(x,k);k=k.sibling}j.type===ua?(v=Ei(j.props.children,x.mode,w,j.key),v.return=x,x=v):(w=au(j.type,j.key,j.props,null,x.mode,w),w.ref=Sl(x,v,j),w.return=x,x=w)}return l(x);case ca:e:{for(k=j.key;v!==null;){if(v.key===k)if(v.tag===4&&v.stateNode.containerInfo===j.containerInfo&&v.stateNode.implementation===j.implementation){s(x,v.sibling),v=i(v,j.children||[]),v.return=x,x=v;break e}else{s(x,v);break}else t(x,v);v=v.sibling}v=Fh(j,x.mode,w),v.return=x,x=v}return l(x);case Tr:return k=j._init,b(x,v,k(j._payload),w)}if(Ml(j))return g(x,v,j,w);if(jl(j))return y(x,v,j,w);vc(x,j)}return typeof j=="string"&&j!==""||typeof j=="number"?(j=""+j,v!==null&&v.tag===6?(s(x,v.sibling),v=i(v,j),v.return=x,x=v):(s(x,v),v=Lh(j,x.mode,w),v.return=x,x=v),l(x)):s(x,v)}return b}var La=L0(!0),F0=L0(!1),$u=li(null),Mu=null,va=null,gg=null;function xg(){gg=va=Mu=null}function vg(e){var t=$u.current;ct($u),e._currentValue=t}function cm(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 Ea(e,t){Mu=e,gg=va=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Sn=!0),e.firstContext=null)}function os(e){var t=e._currentValue;if(gg!==e)if(e={context:e,memoizedValue:t,next:null},va===null){if(Mu===null)throw Error(re(308));va=e,Mu.dependencies={lanes:0,firstContext:e}}else va=va.next=e;return t}var Si=null;function jg(e){Si===null?Si=[e]:Si.push(e)}function z0(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,jg(t)):(s.next=i.next,i.next=s),t.interleaved=s,dr(e,r)}function dr(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 Rr=!1;function yg(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function U0(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 Br(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ke&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,dr(e,s)}return i=r.interleaved,i===null?(t.next=t,jg(r)):(t.next=i.next,i.next=t),r.interleaved=t,dr(e,s)}function eu(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,ig(e,s)}}function _j(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 Ou(e,t,s,r){var i=e.updateQueue;Rr=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;l=0,h=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,y=o;switch(m=t,p=s,y.tag){case 1:if(g=y.payload,typeof g=="function"){d=g.call(p,d,m);break e}d=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=y.payload,m=typeof g=="function"?g.call(p,d,m):g,m==null)break e;d=wt({},d,m);break e;case 2:Rr=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=d):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(h===null&&(c=d),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=h,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);Mi|=l,e.lanes=l,e.memoizedState=d}}function Lj(e,t,s){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],i=r.callback;if(i!==null){if(r.callback=null,r=s,typeof i!="function")throw Error(re(191,i));i.call(r)}}}var Fo={},Us=li(Fo),uo=li(Fo),ho=li(Fo);function Ni(e){if(e===Fo)throw Error(re(174));return e}function wg(e,t){switch(rt(ho,t),rt(uo,e),rt(Us,Fo),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Wf(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Wf(t,e)}ct(Us),rt(Us,t)}function Fa(){ct(Us),ct(uo),ct(ho)}function B0(e){Ni(ho.current);var t=Ni(Us.current),s=Wf(t,e.type);t!==s&&(rt(uo,e),rt(Us,s))}function bg(e){uo.current===e&&(ct(Us),ct(uo))}var mt=li(0);function Du(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 Ph=[];function kg(){for(var e=0;e<Ph.length;e++)Ph[e]._workInProgressVersionPrimary=null;Ph.length=0}var tu=xr.ReactCurrentDispatcher,$h=xr.ReactCurrentBatchConfig,$i=0,xt=null,Ot=null,Bt=null,_u=!1,Hl=!1,fo=0,FR=0;function ln(){throw Error(re(321))}function Sg(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!ws(e[s],t[s]))return!1;return!0}function Ng(e,t,s,r,i,a){if($i=a,xt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,tu.current=e===null||e.memoizedState===null?WR:HR,e=s(r,i),Hl){a=0;do{if(Hl=!1,fo=0,25<=a)throw Error(re(301));a+=1,Bt=Ot=null,t.updateQueue=null,tu.current=KR,e=s(r,i)}while(Hl)}if(tu.current=Lu,t=Ot!==null&&Ot.next!==null,$i=0,Bt=Ot=xt=null,_u=!1,t)throw Error(re(300));return e}function Cg(){var e=fo!==0;return fo=0,e}function Ms(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Bt===null?xt.memoizedState=Bt=e:Bt=Bt.next=e,Bt}function cs(){if(Ot===null){var e=xt.alternate;e=e!==null?e.memoizedState:null}else e=Ot.next;var t=Bt===null?xt.memoizedState:Bt.next;if(t!==null)Bt=t,Ot=e;else{if(e===null)throw Error(re(310));Ot=e,e={memoizedState:Ot.memoizedState,baseState:Ot.baseState,baseQueue:Ot.baseQueue,queue:Ot.queue,next:null},Bt===null?xt.memoizedState=Bt=e:Bt=Bt.next=e}return Bt}function mo(e,t){return typeof t=="function"?t(e):t}function Mh(e){var t=cs(),s=t.queue;if(s===null)throw Error(re(311));s.lastRenderedReducer=e;var r=Ot,i=r.baseQueue,a=s.pending;if(a!==null){if(i!==null){var l=i.next;i.next=a.next,a.next=l}r.baseQueue=i=a,s.pending=null}if(i!==null){a=i.next,r=r.baseState;var o=l=null,c=null,u=a;do{var h=u.lane;if(($i&h)===h)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var d={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=d,l=r):c=c.next=d,xt.lanes|=h,Mi|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,ws(r,t.memoizedState)||(Sn=!0),t.memoizedState=r,t.baseState=l,t.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){i=e;do a=i.lane,xt.lanes|=a,Mi|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function Oh(e){var t=cs(),s=t.queue;if(s===null)throw Error(re(311));s.lastRenderedReducer=e;var r=s.dispatch,i=s.pending,a=t.memoizedState;if(i!==null){s.pending=null;var l=i=i.next;do a=e(a,l.action),l=l.next;while(l!==i);ws(a,t.memoizedState)||(Sn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function W0(){}function H0(e,t){var s=xt,r=cs(),i=t(),a=!ws(r.memoizedState,i);if(a&&(r.memoizedState=i,Sn=!0),r=r.queue,Eg(G0.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||Bt!==null&&Bt.memoizedState.tag&1){if(s.flags|=2048,po(9,V0.bind(null,s,r,i,t),void 0,null),Kt===null)throw Error(re(349));$i&30||K0(s,t,i)}return i}function K0(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=xt.updateQueue,t===null?(t={lastEffect:null,stores:null},xt.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function V0(e,t,s,r){t.value=s,t.getSnapshot=r,Y0(t)&&q0(e)}function G0(e,t,s){return s(function(){Y0(t)&&q0(e)})}function Y0(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!ws(e,s)}catch{return!0}}function q0(e){var t=dr(e,1);t!==null&&xs(t,e,1,-1)}function Fj(e){var t=Ms();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:mo,lastRenderedState:e},t.queue=e,e=e.dispatch=BR.bind(null,xt,e),[t.memoizedState,e]}function po(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=xt.updateQueue,t===null?(t={lastEffect:null,stores:null},xt.updateQueue=t,t.lastEffect=e.next=e):(s=t.lastEffect,s===null?t.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,t.lastEffect=e)),e}function Q0(){return cs().memoizedState}function nu(e,t,s,r){var i=Ms();xt.flags|=e,i.memoizedState=po(1|t,s,void 0,r===void 0?null:r)}function wd(e,t,s,r){var i=cs();r=r===void 0?null:r;var a=void 0;if(Ot!==null){var l=Ot.memoizedState;if(a=l.destroy,r!==null&&Sg(r,l.deps)){i.memoizedState=po(t,s,a,r);return}}xt.flags|=e,i.memoizedState=po(1|t,s,a,r)}function zj(e,t){return nu(8390656,8,e,t)}function Eg(e,t){return wd(2048,8,e,t)}function J0(e,t){return wd(4,2,e,t)}function X0(e,t){return wd(4,4,e,t)}function Z0(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 ek(e,t,s){return s=s!=null?s.concat([e]):null,wd(4,4,Z0.bind(null,t,e),s)}function Ag(){}function tk(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Sg(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function nk(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Sg(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function sk(e,t,s){return $i&21?(ws(s,t)||(s=o0(),xt.lanes|=s,Mi|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Sn=!0),e.memoizedState=s)}function zR(e,t){var s=Ze;Ze=s!==0&&4>s?s:4,e(!0);var r=$h.transition;$h.transition={};try{e(!1),t()}finally{Ze=s,$h.transition=r}}function rk(){return cs().memoizedState}function UR(e,t,s){var r=Hr(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},ik(e))ak(t,s);else if(s=z0(e,t,s,r),s!==null){var i=vn();xs(s,e,r,i),lk(s,t,r)}}function BR(e,t,s){var r=Hr(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(ik(e))ak(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,ws(o,l)){var c=t.interleaved;c===null?(i.next=i,jg(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=z0(e,t,i,r),s!==null&&(i=vn(),xs(s,e,r,i),lk(s,t,r))}}function ik(e){var t=e.alternate;return e===xt||t!==null&&t===xt}function ak(e,t){Hl=_u=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function lk(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,ig(e,s)}}var Lu={readContext:os,useCallback:ln,useContext:ln,useEffect:ln,useImperativeHandle:ln,useInsertionEffect:ln,useLayoutEffect:ln,useMemo:ln,useReducer:ln,useRef:ln,useState:ln,useDebugValue:ln,useDeferredValue:ln,useTransition:ln,useMutableSource:ln,useSyncExternalStore:ln,useId:ln,unstable_isNewReconciler:!1},WR={readContext:os,useCallback:function(e,t){return Ms().memoizedState=[e,t===void 0?null:t],e},useContext:os,useEffect:zj,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,nu(4194308,4,Z0.bind(null,t,e),s)},useLayoutEffect:function(e,t){return nu(4194308,4,e,t)},useInsertionEffect:function(e,t){return nu(4,2,e,t)},useMemo:function(e,t){var s=Ms();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Ms();return t=s!==void 0?s(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=UR.bind(null,xt,e),[r.memoizedState,e]},useRef:function(e){var t=Ms();return e={current:e},t.memoizedState=e},useState:Fj,useDebugValue:Ag,useDeferredValue:function(e){return Ms().memoizedState=e},useTransition:function(){var e=Fj(!1),t=e[0];return e=zR.bind(null,e[1]),Ms().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=xt,i=Ms();if(ht){if(s===void 0)throw Error(re(407));s=s()}else{if(s=t(),Kt===null)throw Error(re(349));$i&30||K0(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,zj(G0.bind(null,r,a,e),[e]),r.flags|=2048,po(9,V0.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Ms(),t=Kt.identifierPrefix;if(ht){var s=rr,r=sr;s=(r&~(1<<32-gs(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=fo++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=FR++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},HR={readContext:os,useCallback:tk,useContext:os,useEffect:Eg,useImperativeHandle:ek,useInsertionEffect:J0,useLayoutEffect:X0,useMemo:nk,useReducer:Mh,useRef:Q0,useState:function(){return Mh(mo)},useDebugValue:Ag,useDeferredValue:function(e){var t=cs();return sk(t,Ot.memoizedState,e)},useTransition:function(){var e=Mh(mo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:W0,useSyncExternalStore:H0,useId:rk,unstable_isNewReconciler:!1},KR={readContext:os,useCallback:tk,useContext:os,useEffect:Eg,useImperativeHandle:ek,useInsertionEffect:J0,useLayoutEffect:X0,useMemo:nk,useReducer:Oh,useRef:Q0,useState:function(){return Oh(mo)},useDebugValue:Ag,useDeferredValue:function(e){var t=cs();return Ot===null?t.memoizedState=e:sk(t,Ot.memoizedState,e)},useTransition:function(){var e=Oh(mo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:W0,useSyncExternalStore:H0,useId:rk,unstable_isNewReconciler:!1};function hs(e,t){if(e&&e.defaultProps){t=wt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function um(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:wt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var bd={isMounted:function(e){return(e=e._reactInternals)?Wi(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=vn(),i=Hr(e),a=ir(r,i);a.payload=t,s!=null&&(a.callback=s),t=Br(e,a,i),t!==null&&(xs(t,e,i,r),eu(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=vn(),i=Hr(e),a=ir(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=Br(e,a,i),t!==null&&(xs(t,e,i,r),eu(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=vn(),r=Hr(e),i=ir(s,r);i.tag=2,t!=null&&(i.callback=t),t=Br(e,i,r),t!==null&&(xs(t,e,r,s),eu(t,e,r))}};function Uj(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?!ao(s,r)||!ao(i,a):!0}function ok(e,t,s){var r=!1,i=Xr,a=t.contextType;return typeof a=="object"&&a!==null?a=os(a):(i=En(t)?Ii:fn.current,r=t.contextTypes,a=(r=r!=null)?Da(e,i):Xr),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=bd,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Bj(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&&bd.enqueueReplaceState(t,t.state,null)}function dm(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},yg(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=os(a):(a=En(t)?Ii:fn.current,i.context=Da(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(um(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&&bd.enqueueReplaceState(i,i.state,null),Ou(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function za(e,t){try{var s="",r=t;do s+=jT(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 Dh(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function hm(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var VR=typeof WeakMap=="function"?WeakMap:Map;function ck(e,t,s){s=ir(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){zu||(zu=!0,bm=r),hm(e,t)},s}function uk(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(){hm(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){hm(e,t),typeof r!="function"&&(Wr===null?Wr=new Set([this]):Wr.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function Wj(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new VR;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=aI.bind(null,e,t,s),t.then(e,e))}function Hj(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 Kj(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,Br(s,t,1))),s.lanes|=1),e)}var GR=xr.ReactCurrentOwner,Sn=!1;function gn(e,t,s,r){t.child=e===null?F0(t,null,s,r):La(t,e.child,s,r)}function Vj(e,t,s,r,i){s=s.render;var a=t.ref;return Ea(t,i),r=Ng(e,t,s,r,a,i),s=Cg(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,hr(e,t,i)):(ht&&s&&fg(t),t.flags|=1,gn(e,t,r,i),t.child)}function Gj(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Dg(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,dk(e,t,a,r,i)):(e=au(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:ao,s(l,r)&&e.ref===t.ref)return hr(e,t,i)}return t.flags|=1,e=Kr(a,r),e.ref=t.ref,e.return=t,t.child=e}function dk(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(ao(a,r)&&e.ref===t.ref)if(Sn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Sn=!0);else return t.lanes=e.lanes,hr(e,t,i)}return fm(e,t,s,r,i)}function hk(e,t,s){var r=t.pendingProps,i=r.children,a=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},rt(ya,_n),_n|=s;else{if(!(s&1073741824))return e=a!==null?a.baseLanes|s:s,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,rt(ya,_n),_n|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,rt(ya,_n),_n|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,rt(ya,_n),_n|=r;return gn(e,t,i,s),t.child}function fk(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function fm(e,t,s,r,i){var a=En(s)?Ii:fn.current;return a=Da(t,a),Ea(t,i),s=Ng(e,t,s,r,a,i),r=Cg(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,hr(e,t,i)):(ht&&r&&fg(t),t.flags|=1,gn(e,t,s,i),t.child)}function Yj(e,t,s,r,i){if(En(s)){var a=!0;Ru(t)}else a=!1;if(Ea(t,i),t.stateNode===null)su(e,t),ok(t,s,r),dm(t,s,r,i),r=!0;else if(e===null){var l=t.stateNode,o=t.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=os(u):(u=En(s)?Ii:fn.current,u=Da(t,u));var h=s.getDerivedStateFromProps,d=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";d||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Bj(t,l,r,u),Rr=!1;var m=t.memoizedState;l.state=m,Ou(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Cn.current||Rr?(typeof h=="function"&&(um(t,s,h,r),c=t.memoizedState),(o=Rr||Uj(t,s,o,r,m,c,u))?(d||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(t.flags|=4194308)):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{l=t.stateNode,U0(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:hs(t.type,o),l.props=u,d=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=os(c):(c=En(s)?Ii:fn.current,c=Da(t,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==d||m!==c)&&Bj(t,l,r,c),Rr=!1,m=t.memoizedState,l.state=m,Ou(t,r,l,i);var g=t.memoizedState;o!==d||m!==g||Cn.current||Rr?(typeof p=="function"&&(um(t,s,p,r),g=t.memoizedState),(u=Rr||Uj(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 mm(e,t,s,r,a,i)}function mm(e,t,s,r,i,a){fk(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&$j(t,s,!1),hr(e,t,a);r=t.stateNode,GR.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=La(t,e.child,null,a),t.child=La(t,null,o,a)):gn(e,t,o,a),t.memoizedState=r.state,i&&$j(t,s,!0),t.child}function mk(e){var t=e.stateNode;t.pendingContext?Pj(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Pj(e,t.context,!1),wg(e,t.containerInfo)}function qj(e,t,s,r,i){return _a(),pg(i),t.flags|=256,gn(e,t,s,r),t.child}var pm={dehydrated:null,treeContext:null,retryLane:0};function gm(e){return{baseLanes:e,cachePool:null,transitions:null}}function pk(e,t,s){var r=t.pendingProps,i=mt.current,a=!1,l=(t.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(i&2)!==0),o?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),rt(mt,i&1),e===null)return om(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=Nd(l,r,0,null),e=Ei(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=gm(s),t.memoizedState=pm,e):Tg(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return YR(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=Kr(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=Kr(o,a):(a=Ei(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?gm(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=pm,r}return a=e.child,e=a.sibling,r=Kr(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 Tg(e,t){return t=Nd({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function jc(e,t,s,r){return r!==null&&pg(r),La(t,e.child,null,s),e=Tg(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function YR(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=Dh(Error(re(422))),jc(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Nd({mode:"visible",children:r.children},i,0,null),a=Ei(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&La(t,e.child,null,l),t.child.memoizedState=gm(l),t.memoizedState=pm,a);if(!(t.mode&1))return jc(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(re(419)),r=Dh(a,r,void 0),jc(e,t,l,r)}if(o=(l&e.childLanes)!==0,Sn||o){if(r=Kt,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,dr(e,i),xs(r,e,i,-1))}return Og(),r=Dh(Error(re(421))),jc(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=lI.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Fn=Ur(i.nextSibling),Un=t,ht=!0,ms=null,e!==null&&(ts[ns++]=sr,ts[ns++]=rr,ts[ns++]=Pi,sr=e.id,rr=e.overflow,Pi=t),t=Tg(t,r.children),t.flags|=4096,t)}function Qj(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),cm(e.return,t,s)}function _h(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 gk(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(gn(e,t,r.children,s),r=mt.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Qj(e,s,t);else if(e.tag===19)Qj(e,s,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(rt(mt,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&&Du(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),_h(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&&Du(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}_h(t,!0,s,null,a);break;case"together":_h(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function su(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function hr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),Mi|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(re(153));if(t.child!==null){for(e=t.child,s=Kr(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=Kr(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function qR(e,t,s){switch(t.tag){case 3:mk(t),_a();break;case 5:B0(t);break;case 1:En(t.type)&&Ru(t);break;case 4:wg(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;rt($u,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(rt(mt,mt.current&1),t.flags|=128,null):s&t.child.childLanes?pk(e,t,s):(rt(mt,mt.current&1),e=hr(e,t,s),e!==null?e.sibling:null);rt(mt,mt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return gk(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),rt(mt,mt.current),r)break;return null;case 22:case 23:return t.lanes=0,hk(e,t,s)}return hr(e,t,s)}var xk,xm,vk,jk;xk=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}};xm=function(){};vk=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Ni(Us.current);var a=null;switch(s){case"input":i=Ff(e,i),r=Ff(e,r),a=[];break;case"select":i=wt({},i,{value:void 0}),r=wt({},r,{value:void 0}),a=[];break;case"textarea":i=Bf(e,i),r=Bf(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Au)}Hf(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"&&(Zl.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"&&(Zl.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&ot("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)}};jk=function(e,t,s,r){s!==r&&(t.flags|=4)};function Nl(e,t){if(!ht)switch(e.tailMode){case"hidden":t=e.tail;for(var s=null;t!==null;)t.alternate!==null&&(s=t),t=t.sibling;s===null?e.tail=null:s.sibling=null;break;case"collapsed":s=e.tail;for(var r=null;s!==null;)s.alternate!==null&&(r=s),s=s.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function on(e){var t=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(t)for(var i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=s,t}function QR(e,t,s){var r=t.pendingProps;switch(mg(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return on(t),null;case 1:return En(t.type)&&Tu(),on(t),null;case 3:return r=t.stateNode,Fa(),ct(Cn),ct(fn),kg(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(xc(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,ms!==null&&(Nm(ms),ms=null))),xm(e,t),on(t),null;case 5:bg(t);var i=Ni(ho.current);if(s=t.type,e!==null&&t.stateNode!=null)vk(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(re(166));return on(t),null}if(e=Ni(Us.current),xc(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[Ds]=t,r[co]=a,e=(t.mode&1)!==0,s){case"dialog":ot("cancel",r),ot("close",r);break;case"iframe":case"object":case"embed":ot("load",r);break;case"video":case"audio":for(i=0;i<Dl.length;i++)ot(Dl[i],r);break;case"source":ot("error",r);break;case"img":case"image":case"link":ot("error",r),ot("load",r);break;case"details":ot("toggle",r);break;case"input":ij(r,a),ot("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},ot("invalid",r);break;case"textarea":lj(r,a),ot("invalid",r)}Hf(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&&gc(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&gc(r.textContent,o,e),i=["children",""+o]):Zl.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&ot("scroll",r)}switch(s){case"input":oc(r),aj(r,a,!0);break;case"textarea":oc(r),oj(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Au)}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=Gb(s)),e==="http://www.w3.org/1999/xhtml"?s==="script"?(e=l.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=l.createElement(s,{is:r.is}):(e=l.createElement(s),s==="select"&&(l=e,r.multiple?l.multiple=!0:r.size&&(l.size=r.size))):e=l.createElementNS(e,s),e[Ds]=t,e[co]=r,xk(e,t,!1,!1),t.stateNode=e;e:{switch(l=Kf(s,r),s){case"dialog":ot("cancel",e),ot("close",e),i=r;break;case"iframe":case"object":case"embed":ot("load",e),i=r;break;case"video":case"audio":for(i=0;i<Dl.length;i++)ot(Dl[i],e);i=r;break;case"source":ot("error",e),i=r;break;case"img":case"image":case"link":ot("error",e),ot("load",e),i=r;break;case"details":ot("toggle",e),i=r;break;case"input":ij(e,r),i=Ff(e,r),ot("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=wt({},r,{value:void 0}),ot("invalid",e);break;case"textarea":lj(e,r),i=Bf(e,r),ot("invalid",e);break;default:i=r}Hf(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?Qb(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&Yb(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&eo(e,c):typeof c=="number"&&eo(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Zl.hasOwnProperty(a)?c!=null&&a==="onScroll"&&ot("scroll",e):c!=null&&Zp(e,a,c,l))}switch(s){case"input":oc(e),aj(e,r,!1);break;case"textarea":oc(e),oj(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Jr(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?ka(e,!!r.multiple,a,!1):r.defaultValue!=null&&ka(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Au)}switch(s){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return on(t),null;case 6:if(e&&t.stateNode!=null)jk(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(re(166));if(s=Ni(ho.current),Ni(Us.current),xc(t)){if(r=t.stateNode,s=t.memoizedProps,r[Ds]=t,(a=r.nodeValue!==s)&&(e=Un,e!==null))switch(e.tag){case 3:gc(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&gc(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Ds]=t,t.stateNode=r}return on(t),null;case 13:if(ct(mt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(ht&&Fn!==null&&t.mode&1&&!(t.flags&128))_0(),_a(),t.flags|=98560,a=!1;else if(a=xc(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(re(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(re(317));a[Ds]=t}else _a(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;on(t),a=!1}else ms!==null&&(Nm(ms),ms=null),a=!0;if(!a)return t.flags&65536?t:null}return t.flags&128?(t.lanes=s,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||mt.current&1?Lt===0&&(Lt=3):Og())),t.updateQueue!==null&&(t.flags|=4),on(t),null);case 4:return Fa(),xm(e,t),e===null&&lo(t.stateNode.containerInfo),on(t),null;case 10:return vg(t.type._context),on(t),null;case 17:return En(t.type)&&Tu(),on(t),null;case 19:if(ct(mt),a=t.memoizedState,a===null)return on(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)Nl(a,!1);else{if(Lt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=Du(e),l!==null){for(t.flags|=128,Nl(a,!1),r=l.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=s,s=t.child;s!==null;)a=s,e=r,a.flags&=14680066,l=a.alternate,l===null?(a.childLanes=0,a.lanes=e,a.child=null,a.subtreeFlags=0,a.memoizedProps=null,a.memoizedState=null,a.updateQueue=null,a.dependencies=null,a.stateNode=null):(a.childLanes=l.childLanes,a.lanes=l.lanes,a.child=l.child,a.subtreeFlags=0,a.deletions=null,a.memoizedProps=l.memoizedProps,a.memoizedState=l.memoizedState,a.updateQueue=l.updateQueue,a.type=l.type,e=l.dependencies,a.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return rt(mt,mt.current&1|2),t.child}e=e.sibling}a.tail!==null&&Rt()>Ua&&(t.flags|=128,r=!0,Nl(a,!1),t.lanes=4194304)}else{if(!r)if(e=Du(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),Nl(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!ht)return on(t),null}else 2*Rt()-a.renderingStartTime>Ua&&s!==1073741824&&(t.flags|=128,r=!0,Nl(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=Rt(),t.sibling=null,s=mt.current,rt(mt,r?s&1|2:s&1),t):(on(t),null);case 22:case 23:return Mg(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?_n&1073741824&&(on(t),t.subtreeFlags&6&&(t.flags|=8192)):on(t),null;case 24:return null;case 25:return null}throw Error(re(156,t.tag))}function JR(e,t){switch(mg(t),t.tag){case 1:return En(t.type)&&Tu(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Fa(),ct(Cn),ct(fn),kg(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return bg(t),null;case 13:if(ct(mt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(re(340));_a()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ct(mt),null;case 4:return Fa(),null;case 10:return vg(t.type._context),null;case 22:case 23:return Mg(),null;case 24:return null;default:return null}}var yc=!1,un=!1,XR=typeof WeakSet=="function"?WeakSet:Set,je=null;function ja(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Nt(e,t,r)}else s.current=null}function vm(e,t,s){try{s()}catch(r){Nt(e,t,r)}}var Jj=!1;function ZR(e,t){if(tm=Nu,e=S0(),hg(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,d=e,m=null;t:for(;;){for(var p;d!==s||i!==0&&d.nodeType!==3||(o=l+i),d!==a||r!==0&&d.nodeType!==3||(c=l+r),d.nodeType===3&&(l+=d.nodeValue.length),(p=d.firstChild)!==null;)m=d,d=p;for(;;){if(d===e)break t;if(m===s&&++u===i&&(o=l),m===a&&++h===r&&(c=l),(p=d.nextSibling)!==null)break;d=m,m=d.parentNode}d=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(nm={focusedElem:e,selectionRange:s},Nu=!1,je=t;je!==null;)if(t=je,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,je=e;else for(;je!==null;){t=je;try{var g=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var y=g.memoizedProps,b=g.memoizedState,x=t.stateNode,v=x.getSnapshotBeforeUpdate(t.elementType===t.type?y:hs(t.type,y),b);x.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var j=t.stateNode.containerInfo;j.nodeType===1?j.textContent="":j.nodeType===9&&j.documentElement&&j.removeChild(j.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(re(163))}}catch(w){Nt(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,je=e;break}je=t.return}return g=Jj,Jj=!1,g}function Kl(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&&vm(t,s,a)}i=i.next}while(i!==r)}}function kd(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var s=t=t.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==t)}}function jm(e){var t=e.ref;if(t!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof t=="function"?t(e):t.current=e}}function yk(e){var t=e.alternate;t!==null&&(e.alternate=null,yk(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ds],delete t[co],delete t[im],delete t[OR],delete t[DR])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function wk(e){return e.tag===5||e.tag===3||e.tag===4}function Xj(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||wk(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ym(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=Au));else if(r!==4&&(e=e.child,e!==null))for(ym(e,t,s),e=e.sibling;e!==null;)ym(e,t,s),e=e.sibling}function wm(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.insertBefore(e,t):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(wm(e,t,s),e=e.sibling;e!==null;)wm(e,t,s),e=e.sibling}var Jt=null,fs=!1;function Er(e,t,s){for(s=s.child;s!==null;)bk(e,t,s),s=s.sibling}function bk(e,t,s){if(zs&&typeof zs.onCommitFiberUnmount=="function")try{zs.onCommitFiberUnmount(pd,s)}catch{}switch(s.tag){case 5:un||ja(s,t);case 6:var r=Jt,i=fs;Jt=null,Er(e,t,s),Jt=r,fs=i,Jt!==null&&(fs?(e=Jt,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):Jt.removeChild(s.stateNode));break;case 18:Jt!==null&&(fs?(e=Jt,s=s.stateNode,e.nodeType===8?Rh(e.parentNode,s):e.nodeType===1&&Rh(e,s),ro(e)):Rh(Jt,s.stateNode));break;case 4:r=Jt,i=fs,Jt=s.stateNode.containerInfo,fs=!0,Er(e,t,s),Jt=r,fs=i;break;case 0:case 11:case 14:case 15:if(!un&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,l=a.destroy;a=a.tag,l!==void 0&&(a&2||a&4)&&vm(s,t,l),i=i.next}while(i!==r)}Er(e,t,s);break;case 1:if(!un&&(ja(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Nt(s,t,o)}Er(e,t,s);break;case 21:Er(e,t,s);break;case 22:s.mode&1?(un=(r=un)||s.memoizedState!==null,Er(e,t,s),un=r):Er(e,t,s);break;default:Er(e,t,s)}}function Zj(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new XR),t.forEach(function(r){var i=oI.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function ds(e,t){var s=t.deletions;if(s!==null)for(var r=0;r<s.length;r++){var i=s[r];try{var a=e,l=t,o=l;e:for(;o!==null;){switch(o.tag){case 5:Jt=o.stateNode,fs=!1;break e;case 3:Jt=o.stateNode.containerInfo,fs=!0;break e;case 4:Jt=o.stateNode.containerInfo,fs=!0;break e}o=o.return}if(Jt===null)throw Error(re(160));bk(a,l,i),Jt=null,fs=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Nt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)kk(t,e),t=t.sibling}function kk(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(ds(t,e),Ps(e),r&4){try{Kl(3,e,e.return),kd(3,e)}catch(y){Nt(e,e.return,y)}try{Kl(5,e,e.return)}catch(y){Nt(e,e.return,y)}}break;case 1:ds(t,e),Ps(e),r&512&&s!==null&&ja(s,s.return);break;case 5:if(ds(t,e),Ps(e),r&512&&s!==null&&ja(s,s.return),e.flags&32){var i=e.stateNode;try{eo(i,"")}catch(y){Nt(e,e.return,y)}}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&&Kb(i,a),Kf(o,l);var u=Kf(o,a);for(l=0;l<c.length;l+=2){var h=c[l],d=c[l+1];h==="style"?Qb(i,d):h==="dangerouslySetInnerHTML"?Yb(i,d):h==="children"?eo(i,d):Zp(i,h,d,u)}switch(o){case"input":zf(i,a);break;case"textarea":Vb(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?ka(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?ka(i,!!a.multiple,a.defaultValue,!0):ka(i,!!a.multiple,a.multiple?[]:"",!1))}i[co]=a}catch(y){Nt(e,e.return,y)}}break;case 6:if(ds(t,e),Ps(e),r&4){if(e.stateNode===null)throw Error(re(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(y){Nt(e,e.return,y)}}break;case 3:if(ds(t,e),Ps(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{ro(t.containerInfo)}catch(y){Nt(e,e.return,y)}break;case 4:ds(t,e),Ps(e);break;case 13:ds(t,e),Ps(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Pg=Rt())),r&4&&Zj(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(un=(u=un)||h,ds(t,e),un=u):ds(t,e),Ps(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(je=e,h=e.child;h!==null;){for(d=je=h;je!==null;){switch(m=je,p=m.child,m.tag){case 0:case 11:case 14:case 15:Kl(4,m,m.return);break;case 1:ja(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(y){Nt(r,s,y)}}break;case 5:ja(m,m.return);break;case 22:if(m.memoizedState!==null){ty(d);continue}}p!==null?(p.return=m,je=p):ty(d)}h=h.sibling}e:for(h=null,d=e;;){if(d.tag===5){if(h===null){h=d;try{i=d.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=d.stateNode,c=d.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=qb("display",l))}catch(y){Nt(e,e.return,y)}}}else if(d.tag===6){if(h===null)try{d.stateNode.nodeValue=u?"":d.memoizedProps}catch(y){Nt(e,e.return,y)}}else if((d.tag!==22&&d.tag!==23||d.memoizedState===null||d===e)&&d.child!==null){d.child.return=d,d=d.child;continue}if(d===e)break e;for(;d.sibling===null;){if(d.return===null||d.return===e)break e;h===d&&(h=null),d=d.return}h===d&&(h=null),d.sibling.return=d.return,d=d.sibling}}break;case 19:ds(t,e),Ps(e),r&4&&Zj(e);break;case 21:break;default:ds(t,e),Ps(e)}}function Ps(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(wk(s)){var r=s;break e}s=s.return}throw Error(re(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(eo(i,""),r.flags&=-33);var a=Xj(e);wm(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=Xj(e);ym(e,o,l);break;default:throw Error(re(161))}}catch(c){Nt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function eI(e,t,s){je=e,Sk(e)}function Sk(e,t,s){for(var r=(e.mode&1)!==0;je!==null;){var i=je,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||yc;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||un;o=yc;var u=un;if(yc=l,(un=c)&&!u)for(je=i;je!==null;)l=je,c=l.child,l.tag===22&&l.memoizedState!==null?ny(i):c!==null?(c.return=l,je=c):ny(i);for(;a!==null;)je=a,Sk(a),a=a.sibling;je=i,yc=o,un=u}ey(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,je=a):ey(e)}}function ey(e){for(;je!==null;){var t=je;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:un||kd(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!un)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:hs(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&Lj(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}Lj(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var d=h.dehydrated;d!==null&&ro(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(re(163))}un||t.flags&512&&jm(t)}catch(m){Nt(t,t.return,m)}}if(t===e){je=null;break}if(s=t.sibling,s!==null){s.return=t.return,je=s;break}je=t.return}}function ty(e){for(;je!==null;){var t=je;if(t===e){je=null;break}var s=t.sibling;if(s!==null){s.return=t.return,je=s;break}je=t.return}}function ny(e){for(;je!==null;){var t=je;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{kd(4,t)}catch(c){Nt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Nt(t,i,c)}}var a=t.return;try{jm(t)}catch(c){Nt(t,a,c)}break;case 5:var l=t.return;try{jm(t)}catch(c){Nt(t,l,c)}}}catch(c){Nt(t,t.return,c)}if(t===e){je=null;break}var o=t.sibling;if(o!==null){o.return=t.return,je=o;break}je=t.return}}var tI=Math.ceil,Fu=xr.ReactCurrentDispatcher,Rg=xr.ReactCurrentOwner,as=xr.ReactCurrentBatchConfig,Ke=0,Kt=null,$t=null,Xt=0,_n=0,ya=li(0),Lt=0,go=null,Mi=0,Sd=0,Ig=0,Vl=null,kn=null,Pg=0,Ua=1/0,Xs=null,zu=!1,bm=null,Wr=null,wc=!1,Mr=null,Uu=0,Gl=0,km=null,ru=-1,iu=0;function vn(){return Ke&6?Rt():ru!==-1?ru:ru=Rt()}function Hr(e){return e.mode&1?Ke&2&&Xt!==0?Xt&-Xt:LR.transition!==null?(iu===0&&(iu=o0()),iu):(e=Ze,e!==0||(e=window.event,e=e===void 0?16:p0(e.type)),e):1}function xs(e,t,s,r){if(50<Gl)throw Gl=0,km=null,Error(re(185));Do(e,s,r),(!(Ke&2)||e!==Kt)&&(e===Kt&&(!(Ke&2)&&(Sd|=s),Lt===4&&Pr(e,Xt)),An(e,r),s===1&&Ke===0&&!(t.mode&1)&&(Ua=Rt()+500,yd&&oi()))}function An(e,t){var s=e.callbackNode;LT(e,t);var r=Su(e,e===Kt?Xt:0);if(r===0)s!==null&&dj(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&dj(s),t===1)e.tag===0?_R(sy.bind(null,e)):M0(sy.bind(null,e)),$R(function(){!(Ke&6)&&oi()}),s=null;else{switch(c0(r)){case 1:s=rg;break;case 4:s=a0;break;case 16:s=ku;break;case 536870912:s=l0;break;default:s=ku}s=Pk(s,Nk.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function Nk(e,t){if(ru=-1,iu=0,Ke&6)throw Error(re(327));var s=e.callbackNode;if(Aa()&&e.callbackNode!==s)return null;var r=Su(e,e===Kt?Xt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Bu(e,r);else{t=r;var i=Ke;Ke|=2;var a=Ek();(Kt!==e||Xt!==t)&&(Xs=null,Ua=Rt()+500,Ci(e,t));do try{rI();break}catch(o){Ck(e,o)}while(!0);xg(),Fu.current=a,Ke=i,$t!==null?t=0:(Kt=null,Xt=0,t=Lt)}if(t!==0){if(t===2&&(i=Qf(e),i!==0&&(r=i,t=Sm(e,i))),t===1)throw s=go,Ci(e,0),Pr(e,r),An(e,Rt()),s;if(t===6)Pr(e,r);else{if(i=e.current.alternate,!(r&30)&&!nI(i)&&(t=Bu(e,r),t===2&&(a=Qf(e),a!==0&&(r=a,t=Sm(e,a))),t===1))throw s=go,Ci(e,0),Pr(e,r),An(e,Rt()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(re(345));case 2:yi(e,kn,Xs);break;case 3:if(Pr(e,r),(r&130023424)===r&&(t=Pg+500-Rt(),10<t)){if(Su(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){vn(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=rm(yi.bind(null,e,kn,Xs),t);break}yi(e,kn,Xs);break;case 4:if(Pr(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-gs(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=Rt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*tI(r/1960))-r,10<r){e.timeoutHandle=rm(yi.bind(null,e,kn,Xs),r);break}yi(e,kn,Xs);break;case 5:yi(e,kn,Xs);break;default:throw Error(re(329))}}}return An(e,Rt()),e.callbackNode===s?Nk.bind(null,e):null}function Sm(e,t){var s=Vl;return e.current.memoizedState.isDehydrated&&(Ci(e,t).flags|=256),e=Bu(e,t),e!==2&&(t=kn,kn=s,t!==null&&Nm(t)),e}function Nm(e){kn===null?kn=e:kn.push.apply(kn,e)}function nI(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(!ws(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 Pr(e,t){for(t&=~Ig,t&=~Sd,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-gs(t),r=1<<s;e[s]=-1,t&=~r}}function sy(e){if(Ke&6)throw Error(re(327));Aa();var t=Su(e,0);if(!(t&1))return An(e,Rt()),null;var s=Bu(e,t);if(e.tag!==0&&s===2){var r=Qf(e);r!==0&&(t=r,s=Sm(e,r))}if(s===1)throw s=go,Ci(e,0),Pr(e,t),An(e,Rt()),s;if(s===6)throw Error(re(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,yi(e,kn,Xs),An(e,Rt()),null}function $g(e,t){var s=Ke;Ke|=1;try{return e(t)}finally{Ke=s,Ke===0&&(Ua=Rt()+500,yd&&oi())}}function Oi(e){Mr!==null&&Mr.tag===0&&!(Ke&6)&&Aa();var t=Ke;Ke|=1;var s=as.transition,r=Ze;try{if(as.transition=null,Ze=1,e)return e()}finally{Ze=r,as.transition=s,Ke=t,!(Ke&6)&&oi()}}function Mg(){_n=ya.current,ct(ya)}function Ci(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,PR(s)),$t!==null)for(s=$t.return;s!==null;){var r=s;switch(mg(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Tu();break;case 3:Fa(),ct(Cn),ct(fn),kg();break;case 5:bg(r);break;case 4:Fa();break;case 13:ct(mt);break;case 19:ct(mt);break;case 10:vg(r.type._context);break;case 22:case 23:Mg()}s=s.return}if(Kt=e,$t=e=Kr(e.current,null),Xt=_n=t,Lt=0,go=null,Ig=Sd=Mi=0,kn=Vl=null,Si!==null){for(t=0;t<Si.length;t++)if(s=Si[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}Si=null}return e}function Ck(e,t){do{var s=$t;try{if(xg(),tu.current=Lu,_u){for(var r=xt.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}_u=!1}if($i=0,Bt=Ot=xt=null,Hl=!1,fo=0,Rg.current=null,s===null||s.return===null){Lt=1,go=t,$t=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=Xt,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,d=h.tag;if(!(h.mode&1)&&(d===0||d===11||d===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=Hj(l);if(p!==null){p.flags&=-257,Kj(p,l,o,a,t),p.mode&1&&Wj(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var y=new Set;y.add(c),t.updateQueue=y}else g.add(c);break e}else{if(!(t&1)){Wj(a,u,t),Og();break e}c=Error(re(426))}}else if(ht&&o.mode&1){var b=Hj(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),Kj(b,l,o,a,t),pg(za(c,o));break e}}a=c=za(c,o),Lt!==4&&(Lt=2),Vl===null?Vl=[a]:Vl.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var x=ck(a,c,t);_j(a,x);break e;case 1:o=c;var v=a.type,j=a.stateNode;if(!(a.flags&128)&&(typeof v.getDerivedStateFromError=="function"||j!==null&&typeof j.componentDidCatch=="function"&&(Wr===null||!Wr.has(j)))){a.flags|=65536,t&=-t,a.lanes|=t;var w=uk(a,o,t);_j(a,w);break e}}a=a.return}while(a!==null)}Tk(s)}catch(S){t=S,$t===s&&s!==null&&($t=s=s.return);continue}break}while(!0)}function Ek(){var e=Fu.current;return Fu.current=Lu,e===null?Lu:e}function Og(){(Lt===0||Lt===3||Lt===2)&&(Lt=4),Kt===null||!(Mi&268435455)&&!(Sd&268435455)||Pr(Kt,Xt)}function Bu(e,t){var s=Ke;Ke|=2;var r=Ek();(Kt!==e||Xt!==t)&&(Xs=null,Ci(e,t));do try{sI();break}catch(i){Ck(e,i)}while(!0);if(xg(),Ke=s,Fu.current=r,$t!==null)throw Error(re(261));return Kt=null,Xt=0,Lt}function sI(){for(;$t!==null;)Ak($t)}function rI(){for(;$t!==null&&!TT();)Ak($t)}function Ak(e){var t=Ik(e.alternate,e,_n);e.memoizedProps=e.pendingProps,t===null?Tk(e):$t=t,Rg.current=null}function Tk(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=JR(s,t),s!==null){s.flags&=32767,$t=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Lt=6,$t=null;return}}else if(s=QR(s,t,_n),s!==null){$t=s;return}if(t=t.sibling,t!==null){$t=t;return}$t=t=e}while(t!==null);Lt===0&&(Lt=5)}function yi(e,t,s){var r=Ze,i=as.transition;try{as.transition=null,Ze=1,iI(e,t,s,r)}finally{as.transition=i,Ze=r}return null}function iI(e,t,s,r){do Aa();while(Mr!==null);if(Ke&6)throw Error(re(327));s=e.finishedWork;var i=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(re(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(FT(e,a),e===Kt&&($t=Kt=null,Xt=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||wc||(wc=!0,Pk(ku,function(){return Aa(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=as.transition,as.transition=null;var l=Ze;Ze=1;var o=Ke;Ke|=4,Rg.current=null,ZR(e,s),kk(s,e),NR(nm),Nu=!!tm,nm=tm=null,e.current=s,eI(s),RT(),Ke=o,Ze=l,as.transition=a}else e.current=s;if(wc&&(wc=!1,Mr=e,Uu=i),a=e.pendingLanes,a===0&&(Wr=null),$T(s.stateNode),An(e,Rt()),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(zu)throw zu=!1,e=bm,bm=null,e;return Uu&1&&e.tag!==0&&Aa(),a=e.pendingLanes,a&1?e===km?Gl++:(Gl=0,km=e):Gl=0,oi(),null}function Aa(){if(Mr!==null){var e=c0(Uu),t=as.transition,s=Ze;try{if(as.transition=null,Ze=16>e?16:e,Mr===null)var r=!1;else{if(e=Mr,Mr=null,Uu=0,Ke&6)throw Error(re(331));var i=Ke;for(Ke|=4,je=e.current;je!==null;){var a=je,l=a.child;if(je.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(je=u;je!==null;){var h=je;switch(h.tag){case 0:case 11:case 15:Kl(8,h,a)}var d=h.child;if(d!==null)d.return=h,je=d;else for(;je!==null;){h=je;var m=h.sibling,p=h.return;if(yk(h),h===u){je=null;break}if(m!==null){m.return=p,je=m;break}je=p}}}var g=a.alternate;if(g!==null){var y=g.child;if(y!==null){g.child=null;do{var b=y.sibling;y.sibling=null,y=b}while(y!==null)}}je=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,je=l;else e:for(;je!==null;){if(a=je,a.flags&2048)switch(a.tag){case 0:case 11:case 15:Kl(9,a,a.return)}var x=a.sibling;if(x!==null){x.return=a.return,je=x;break e}je=a.return}}var v=e.current;for(je=v;je!==null;){l=je;var j=l.child;if(l.subtreeFlags&2064&&j!==null)j.return=l,je=j;else e:for(l=v;je!==null;){if(o=je,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:kd(9,o)}}catch(S){Nt(o,o.return,S)}if(o===l){je=null;break e}var w=o.sibling;if(w!==null){w.return=o.return,je=w;break e}je=o.return}}if(Ke=i,oi(),zs&&typeof zs.onPostCommitFiberRoot=="function")try{zs.onPostCommitFiberRoot(pd,e)}catch{}r=!0}return r}finally{Ze=s,as.transition=t}}return!1}function ry(e,t,s){t=za(s,t),t=ck(e,t,1),e=Br(e,t,1),t=vn(),e!==null&&(Do(e,1,t),An(e,t))}function Nt(e,t,s){if(e.tag===3)ry(e,e,s);else for(;t!==null;){if(t.tag===3){ry(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Wr===null||!Wr.has(r))){e=za(s,e),e=uk(t,e,1),t=Br(t,e,1),e=vn(),t!==null&&(Do(t,1,e),An(t,e));break}}t=t.return}}function aI(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=vn(),e.pingedLanes|=e.suspendedLanes&s,Kt===e&&(Xt&s)===s&&(Lt===4||Lt===3&&(Xt&130023424)===Xt&&500>Rt()-Pg?Ci(e,0):Ig|=s),An(e,t)}function Rk(e,t){t===0&&(e.mode&1?(t=dc,dc<<=1,!(dc&130023424)&&(dc=4194304)):t=1);var s=vn();e=dr(e,t),e!==null&&(Do(e,t,s),An(e,s))}function lI(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),Rk(e,s)}function oI(e,t){var s=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(s=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(re(314))}r!==null&&r.delete(t),Rk(e,s)}var Ik;Ik=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Cn.current)Sn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Sn=!1,qR(e,t,s);Sn=!!(e.flags&131072)}else Sn=!1,ht&&t.flags&1048576&&O0(t,Pu,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;su(e,t),e=t.pendingProps;var i=Da(t,fn.current);Ea(t,s),i=Ng(null,t,r,e,i,s);var a=Cg();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,En(r)?(a=!0,Ru(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,yg(t),i.updater=bd,t.stateNode=i,i._reactInternals=t,dm(t,r,e,s),t=mm(null,t,r,!0,a,s)):(t.tag=0,ht&&a&&fg(t),gn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(su(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=uI(r),e=hs(r,e),i){case 0:t=fm(null,t,r,e,s);break e;case 1:t=Yj(null,t,r,e,s);break e;case 11:t=Vj(null,t,r,e,s);break e;case 14:t=Gj(null,t,r,hs(r.type,e),s);break e}throw Error(re(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),fm(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),Yj(e,t,r,i,s);case 3:e:{if(mk(t),e===null)throw Error(re(387));r=t.pendingProps,a=t.memoizedState,i=a.element,U0(e,t),Ou(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=za(Error(re(423)),t),t=qj(e,t,r,s,i);break e}else if(r!==i){i=za(Error(re(424)),t),t=qj(e,t,r,s,i);break e}else for(Fn=Ur(t.stateNode.containerInfo.firstChild),Un=t,ht=!0,ms=null,s=F0(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(_a(),r===i){t=hr(e,t,s);break e}gn(e,t,r,s)}t=t.child}return t;case 5:return B0(t),e===null&&om(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,sm(r,i)?l=null:a!==null&&sm(r,a)&&(t.flags|=32),fk(e,t),gn(e,t,l,s),t.child;case 6:return e===null&&om(t),null;case 13:return pk(e,t,s);case 4:return wg(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=La(t,null,r,s):gn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),Vj(e,t,r,i,s);case 7:return gn(e,t,t.pendingProps,s),t.child;case 8:return gn(e,t,t.pendingProps.children,s),t.child;case 12:return gn(e,t,t.pendingProps.children,s),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,l=i.value,rt($u,r._currentValue),r._currentValue=l,a!==null)if(ws(a.value,l)){if(a.children===i.children&&!Cn.current){t=hr(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),cm(a.return,s,t),o.lanes|=s;break}c=c.next}}else if(a.tag===10)l=a.type===t.type?null:a.child;else if(a.tag===18){if(l=a.return,l===null)throw Error(re(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),cm(l,s,t),l=a.sibling}else l=a.child;if(l!==null)l.return=a;else for(l=a;l!==null;){if(l===t){l=null;break}if(a=l.sibling,a!==null){a.return=l.return,l=a;break}l=l.return}a=l}gn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,Ea(t,s),i=os(i),r=r(i),t.flags|=1,gn(e,t,r,s),t.child;case 14:return r=t.type,i=hs(r,t.pendingProps),i=hs(r.type,i),Gj(e,t,r,i,s);case 15:return dk(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),su(e,t),t.tag=1,En(r)?(e=!0,Ru(t)):e=!1,Ea(t,s),ok(t,r,i),dm(t,r,i,s),mm(null,t,r,!0,e,s);case 19:return gk(e,t,s);case 22:return hk(e,t,s)}throw Error(re(156,t.tag))};function Pk(e,t){return i0(e,t)}function cI(e,t,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function is(e,t,s,r){return new cI(e,t,s,r)}function Dg(e){return e=e.prototype,!(!e||!e.isReactComponent)}function uI(e){if(typeof e=="function")return Dg(e)?1:0;if(e!=null){if(e=e.$$typeof,e===tg)return 11;if(e===ng)return 14}return 2}function Kr(e,t){var s=e.alternate;return s===null?(s=is(e.tag,t,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=t,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,t=e.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function au(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Dg(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case ua:return Ei(s.children,i,a,t);case eg:l=8,i|=8;break;case Of:return e=is(12,s,t,i|2),e.elementType=Of,e.lanes=a,e;case Df:return e=is(13,s,t,i),e.elementType=Df,e.lanes=a,e;case _f:return e=is(19,s,t,i),e.elementType=_f,e.lanes=a,e;case Bb:return Nd(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case zb:l=10;break e;case Ub:l=9;break e;case tg:l=11;break e;case ng:l=14;break e;case Tr:l=16,r=null;break e}throw Error(re(130,e==null?e:typeof e,""))}return t=is(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function Ei(e,t,s,r){return e=is(7,e,r,t),e.lanes=s,e}function Nd(e,t,s,r){return e=is(22,e,r,t),e.elementType=Bb,e.lanes=s,e.stateNode={isHidden:!1},e}function Lh(e,t,s){return e=is(6,e,null,t),e.lanes=s,e}function Fh(e,t,s){return t=is(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function dI(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=jh(0),this.expirationTimes=jh(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=jh(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function _g(e,t,s,r,i,a,l,o,c){return e=new dI(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=is(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},yg(a),e}function hI(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ca,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function $k(e){if(!e)return Xr;e=e._reactInternals;e:{if(Wi(e)!==e||e.tag!==1)throw Error(re(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(En(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(re(171))}if(e.tag===1){var s=e.type;if(En(s))return $0(e,s,t)}return t}function Mk(e,t,s,r,i,a,l,o,c){return e=_g(s,r,!0,e,i,a,l,o,c),e.context=$k(null),s=e.current,r=vn(),i=Hr(s),a=ir(r,i),a.callback=t??null,Br(s,a,i),e.current.lanes=i,Do(e,i,r),An(e,r),e}function Cd(e,t,s,r){var i=t.current,a=vn(),l=Hr(i);return s=$k(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=Br(i,t,l),e!==null&&(xs(e,i,l,a),eu(e,i,l)),l}function Wu(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 iy(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function Lg(e,t){iy(e,t),(e=e.alternate)&&iy(e,t)}function fI(){return null}var Ok=typeof reportError=="function"?reportError:function(e){console.error(e)};function Fg(e){this._internalRoot=e}Ed.prototype.render=Fg.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(re(409));Cd(e,t,null,null)};Ed.prototype.unmount=Fg.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Oi(function(){Cd(null,e,null,null)}),t[ur]=null}};function Ed(e){this._internalRoot=e}Ed.prototype.unstable_scheduleHydration=function(e){if(e){var t=h0();e={blockedOn:null,target:e,priority:t};for(var s=0;s<Ir.length&&t!==0&&t<Ir[s].priority;s++);Ir.splice(s,0,e),s===0&&m0(e)}};function zg(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Ad(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function ay(){}function mI(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Wu(l);a.call(u)}}var l=Mk(t,r,e,0,null,!1,!1,"",ay);return e._reactRootContainer=l,e[ur]=l.current,lo(e.nodeType===8?e.parentNode:e),Oi(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Wu(c);o.call(u)}}var c=_g(e,0,!1,null,null,!1,!1,"",ay);return e._reactRootContainer=c,e[ur]=c.current,lo(e.nodeType===8?e.parentNode:e),Oi(function(){Cd(t,c,s,r)}),c}function Td(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=Wu(l);o.call(c)}}Cd(t,l,e,i)}else l=mI(s,t,e,i,r);return Wu(l)}u0=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=Ol(t.pendingLanes);s!==0&&(ig(t,s|1),An(t,Rt()),!(Ke&6)&&(Ua=Rt()+500,oi()))}break;case 13:Oi(function(){var r=dr(e,1);if(r!==null){var i=vn();xs(r,e,1,i)}}),Lg(e,1)}};ag=function(e){if(e.tag===13){var t=dr(e,134217728);if(t!==null){var s=vn();xs(t,e,134217728,s)}Lg(e,134217728)}};d0=function(e){if(e.tag===13){var t=Hr(e),s=dr(e,t);if(s!==null){var r=vn();xs(s,e,t,r)}Lg(e,t)}};h0=function(){return Ze};f0=function(e,t){var s=Ze;try{return Ze=e,t()}finally{Ze=s}};Gf=function(e,t,s){switch(t){case"input":if(zf(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=jd(r);if(!i)throw Error(re(90));Hb(r),zf(r,i)}}}break;case"textarea":Vb(e,s);break;case"select":t=s.value,t!=null&&ka(e,!!s.multiple,t,!1)}};Zb=$g;e0=Oi;var pI={usingClientEntryPoint:!1,Events:[Lo,ma,jd,Jb,Xb,$g]},Cl={findFiberByHostInstance:ki,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},gI={bundleType:Cl.bundleType,version:Cl.version,rendererPackageName:Cl.rendererPackageName,rendererConfig:Cl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:xr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=s0(e),e===null?null:e.stateNode},findFiberByHostInstance:Cl.findFiberByHostInstance||fI,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var bc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!bc.isDisabled&&bc.supportsFiber)try{pd=bc.inject(gI),zs=bc}catch{}}Kn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=pI;Kn.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!zg(t))throw Error(re(200));return hI(e,t,null,s)};Kn.createRoot=function(e,t){if(!zg(e))throw Error(re(299));var s=!1,r="",i=Ok;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=_g(e,1,!1,null,null,s,!1,r,i),e[ur]=t.current,lo(e.nodeType===8?e.parentNode:e),new Fg(t)};Kn.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(re(188)):(e=Object.keys(e).join(","),Error(re(268,e)));return e=s0(t),e=e===null?null:e.stateNode,e};Kn.flushSync=function(e){return Oi(e)};Kn.hydrate=function(e,t,s){if(!Ad(t))throw Error(re(200));return Td(null,e,t,!0,s)};Kn.hydrateRoot=function(e,t,s){if(!zg(e))throw Error(re(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=Ok;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=Mk(t,null,e,1,s??null,i,!1,a,l),e[ur]=t.current,lo(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 Ed(t)};Kn.render=function(e,t,s){if(!Ad(t))throw Error(re(200));return Td(null,e,t,!1,s)};Kn.unmountComponentAtNode=function(e){if(!Ad(e))throw Error(re(40));return e._reactRootContainer?(Oi(function(){Td(null,null,e,!1,function(){e._reactRootContainer=null,e[ur]=null})}),!0):!1};Kn.unstable_batchedUpdates=$g;Kn.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Ad(s))throw Error(re(200));if(e==null||e._reactInternals===void 0)throw Error(re(38));return Td(e,t,s,!1,r)};Kn.version="18.3.1-next-f1338f8080-20240426";function Dk(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Dk)}catch(e){console.error(e)}}Dk(),Db.exports=Kn;var zo=Db.exports,_k,ly=zo;_k=ly.createRoot,ly.hydrateRoot;var xI=Object.defineProperty,nl=(e,t)=>xI(e,"name",{value:t,configurable:!0}),Lk=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ie(e,t,{checkForDefaultPrevented:s=!0}={}){return nl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}nl(Ie,"composeEventHandlers");function vI(e){var t;if(!Lk)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}nl(vI,"getOwnerWindow");function Cm(e){if(!Lk)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}nl(Cm,"getOwnerDocument");function Fk(e,t=!1){const{activeElement:s}=Cm(e);if(!(s!=null&&s.nodeName))return null;if(zk(s)&&s.contentDocument)return Fk(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=Cm(s).getElementById(r);if(i)return i}}return s}nl(Fk,"getActiveElement");function zk(e){return e.tagName==="IFRAME"}nl(zk,"isFrame");var jI=Object.defineProperty,Ug=(e,t)=>jI(e,"name",{value:t,configurable:!0});function Em(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Ug(Em,"setRef");function Uk(...e){return t=>{let s=!1;const r=e.map(i=>{const a=Em(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():Em(e[i],null)}}}}Ug(Uk,"composeRefs");function ut(...e){return f.useCallback(Uk(...e),e)}Ug(ut,"useComposedRefs");var yI=Object.defineProperty,rs=(e,t)=>yI(e,"name",{value:t,configurable:!0});function wI(e,t){const s=f.createContext(t);s.displayName=e+"Context";const r=rs(a=>{const{children:l,...o}=a,c=f.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=f.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return rs(i,"useContext"),[r,i]}rs(wI,"createContext");function Ns(e,t=[]){let s=[];function r(a,l){const o=f.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=rs(d=>{var x;const{scope:m,children:p,...g}=d,y=((x=m==null?void 0:m[e])==null?void 0:x[c])||o,b=f.useMemo(()=>g,Object.values(g));return n.jsx(y.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function h(d,m,p={}){var x;const{optional:g=!1}=p,y=((x=m==null?void 0:m[e])==null?void 0:x[c])||o,b=f.useContext(y);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${d}\` must be used within \`${a}\``)}return rs(h,"useContext"),[u,h]}rs(r,"createContext");const i=rs(()=>{const a=s.map(l=>f.createContext(l));return rs(function(o){const c=(o==null?void 0:o[e])||a;return f.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,Bk(i,...t)]}rs(Ns,"createContextScope");function Bk(...e){const t=e[0];if(e.length===1)return t;const s=rs(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return rs(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const d=c(a)[`__scope${u}`];return{...o,...d}},{});return f.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}rs(Bk,"composeContextScopes");var bI=Object.defineProperty,Cs=(e,t)=>bI(e,"name",{value:t,configurable:!0});function Zr(e){const t=f.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];Am(i)&&typeof kc=="function"&&(i=kc(i._payload)),f.Children.forEach(i,m=>{var p;if(Gk(m)){o=!0;const g=m;let y="child"in g.props?g.props.child:g.props.children;Am(y)&&typeof kc=="function"&&(y=kc(y._payload)),l=kI(g,y),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=f.cloneElement(l,void 0,c):!o&&f.Children.count(i)===1&&f.isValidElement(i)&&(l=i);const u=l?Vk(l):void 0,h=ut(r,u);if(!l){if(i||i===0)throw new Error(o?CI(e):NI(e));return i}const d=Kk(a,l.props??{});return l.type!==f.Fragment&&(d.ref=r?h:u),f.cloneElement(l,d)});return t.displayName=`${e}.Slot`,t}Cs(Zr,"createSlot");var Wk=Symbol.for("radix.slottable");function Hk(e){const t=Cs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Wk,t}Cs(Hk,"createSlottable");var kI=Cs((e,t)=>{if("child"in e.props){const s=e.props.child;return f.isValidElement(s)?f.cloneElement(s,void 0,e.props.children(s.props.children)):null}return f.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function Kk(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...o)=>{const c=a(...o);return i(...o),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}Cs(Kk,"mergeProps");function Vk(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Cs(Vk,"getElementRef");function Gk(e){return f.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Wk}Cs(Gk,"isSlottable");var SI=Symbol.for("react.lazy");function Am(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===SI&&"_payload"in e&&Yk(e._payload)}Cs(Am,"isLazyComponent");function Yk(e){return typeof e=="object"&&e!==null&&"then"in e}Cs(Yk,"isPromiseLike");var NI=Cs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),CI=Cs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),kc=Za[" use ".trim().toString()],EI=Object.defineProperty,Wt=(e,t)=>EI(e,"name",{value:t,configurable:!0});function Rd(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=Wt(y=>{const{scope:b,children:x}=y,v=f.useRef(null),j=f.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:j,collectionRef:v,children:x})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=Zr(o),u=f.forwardRef((y,b)=>{const{scope:x,children:v}=y,j=a(o,x),w=ut(b,j.collectionRef);return n.jsx(c,{ref:w,children:v})});u.displayName=o;const h=e+"CollectionItemSlot",d="data-radix-collection-item",m=Zr(h),p=f.forwardRef((y,b)=>{const{scope:x,children:v,...j}=y,w=f.useRef(null),S=ut(b,w),k=a(h,x);return f.useEffect(()=>(k.itemMap.set(w,{ref:w,...j}),()=>void k.itemMap.delete(w))),n.jsx(m,{[d]:"",ref:S,children:v})});p.displayName=h;function g(y){const b=a(e+"CollectionConsumer",y);return f.useCallback(()=>{const v=b.collectionRef.current;if(!v)return[];const j=Array.from(v.querySelectorAll(`[${d}]`));return Array.from(b.itemMap.values()).sort((k,N)=>j.indexOf(k.ref.current)-j.indexOf(N.ref.current))},[b.collectionRef,b.itemMap])}return Wt(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}Wt(Rd,"createCollection");var oy=new WeakMap,Pt,Ln,zh=(Ln=class extends Map{constructor(s){super(s);Xv(this,Pt);fh(this,Pt,[...super.keys()]),oy.set(this,!0)}set(s,r){return oy.get(this)&&(this.has(s)?an(this,Pt)[an(this,Pt).indexOf(s)]=s:an(this,Pt).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=an(this,Pt).length,o=Bg(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||a&&u===this.size-1||u===-1)return this.set(r,i),this;const h=this.size+(a?0:1);o<0&&c++;const d=[...an(this,Pt)];let m,p=!1;for(let g=c;g<h;g++)if(c===g){let y=d[g];d[g]===r&&(y=d[g+1]),a&&this.delete(r),m=this.get(y),this.set(r,i)}else{!p&&d[g-1]===r&&(p=!0);const y=d[p?g:g-1],b=m;m=this.get(y),this.delete(y),this.set(y,b)}return this}with(s,r,i){const a=new Ln(this);return a.insert(s,r,i),a}before(s){const r=an(this,Pt).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=an(this,Pt).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=an(this,Pt).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,i){const a=an(this,Pt).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return fh(this,Pt,[]),super.clear()}delete(s){const r=super.delete(s);return r&&an(this,Pt).splice(an(this,Pt).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=lu(an(this,Pt),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=lu(an(this,Pt),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return an(this,Pt).indexOf(s)}keyAt(s){return lu(an(this,Pt),s)}from(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.at(a)}keyFrom(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.keyAt(a)}find(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return a;i++}}findIndex(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return i;i++}return-1}filter(s,r){const i=[];let a=0;for(const l of this)Reflect.apply(s,r,[l,a,this])&&i.push(l),a++;return new Ln(i)}map(s,r){const i=[];let a=0;for(const l of this)i.push([l[0],Reflect.apply(s,r,[l,a,this])]),a++;return new Ln(i)}reduce(...s){const[r,i]=s;let a=0,l=i??this.at(0);for(const o of this)a===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,a,this]),a++;return l}reduceRight(...s){const[r,i]=s;let a=i??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?a=o:a=Reflect.apply(r,this,[a,o,l,this])}return a}toSorted(s){const r=[...this.entries()].sort(s);return new Ln(r)}toReversed(){const s=new Ln;for(let r=this.size-1;r>=0;r--){const i=this.keyAt(r),a=this.get(i);s.set(i,a)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new Ln(r)}slice(s,r){const i=new Ln;let a=this.size-1;if(s===void 0)return i;s<0&&(s=s+this.size),r!==void 0&&r>0&&(a=r-1);for(let l=s;l<=a;l++){const o=this.keyAt(l),c=this.get(o);i.set(o,c)}return i}every(s,r){let i=0;for(const a of this){if(!Reflect.apply(s,r,[a,i,this]))return!1;i++}return!0}some(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return!0;i++}return!1}},Pt=new WeakMap,Wt(Ln,"OrderedDict"),Ln);function lu(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=qk(e,t);return s===-1?void 0:e[s]}Wt(lu,"at");function qk(e,t){const s=e.length,r=Bg(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}Wt(qk,"toSafeIndex");function Bg(e){return e!==e||e===0?0:Math.trunc(e)}Wt(Bg,"toSafeInteger");function AI(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new zh,setItemMap:Wt(()=>{},"setItemMap")}),l=Wt(({state:j,...w})=>j?n.jsx(c,{...w,state:j}):n.jsx(o,{...w}),"CollectionProvider");l.displayName=t;const o=Wt(j=>{const w=b();return n.jsx(c,{...j,state:w})},"CollectionInit");o.displayName=t+"Init";const c=Wt(j=>{const{scope:w,children:S,state:k}=j,N=f.useRef(null),[C,I]=f.useState(null),A=ut(N,I),[O,z]=k;return f.useEffect(()=>{if(!C)return;const L=Xk(()=>{});return L.observe(C,{childList:!0,subtree:!0}),()=>{L.disconnect()}},[C]),n.jsx(i,{scope:w,itemMap:O,setItemMap:z,collectionRef:A,collectionRefObject:N,collectionElement:C,children:S})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",h=Zr(u),d=f.forwardRef((j,w)=>{const{scope:S,children:k}=j,N=a(u,S),C=ut(w,N.collectionRef);return n.jsx(h,{ref:C,children:k})});d.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=Zr(m),y=f.forwardRef((j,w)=>{const{scope:S,children:k,...N}=j,C=f.useRef(null),[I,A]=f.useState(null),O=ut(w,C,A),z=a(m,S),{setItemMap:L}=z,E=f.useRef(N);Qk(E.current,N)||(E.current=N);const $=E.current;return f.useEffect(()=>{const _=$;return L(B=>I?B.has(I)?B.set(I,{..._,element:I}).toSorted(Tm):(B.set(I,{..._,element:I}),B.toSorted(Tm)):B),()=>{L(B=>!I||!B.has(I)?B:(B.delete(I),new zh(B)))}},[I,$,L]),n.jsx(g,{[p]:"",ref:O,children:k})});y.displayName=m;function b(){return f.useState(new zh)}Wt(b,"useInitCollection");function x(j){const{itemMap:w}=a(e+"CollectionConsumer",j);return w}return Wt(x,"useCollection"),[{Provider:l,Slot:d,ItemSlot:y},{createCollectionScope:r,useCollection:x,useInitCollection:b}]}Wt(AI,"createCollection");function Qk(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e==null||t==null)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const i of s)if(!Object.prototype.hasOwnProperty.call(t,i)||e[i]!==t[i])return!1;return!0}Wt(Qk,"shallowEqual");function Jk(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Wt(Jk,"isElementPreceding");function Tm(e,t){return!e[1].element||!t[1].element?0:Jk(e[1].element,t[1].element)?-1:1}Wt(Tm,"sortByDocumentPosition");function Xk(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Wt(Xk,"getChildListObserver");var TI=Object.defineProperty,RI=(e,t)=>TI(e,"name",{value:t,configurable:!0}),II=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bt=II.reduce((e,t)=>{const s=Zr(`Primitive.${t}`),r=f.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Id(e,t){e&&zo.flushSync(()=>e.dispatchEvent(t))}RI(Id,"dispatchDiscreteCustomEvent");var PI=Object.defineProperty,$I=(e,t)=>PI(e,"name",{value:t,configurable:!0});function us(e){const t=f.useRef(e);return f.useEffect(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}$I(us,"useCallbackRef");var MI=Object.defineProperty,Dt=(e,t)=>MI(e,"name",{value:t,configurable:!0}),Rm="dismissableLayer.update",OI="dismissableLayer.pointerDownOutside",DI="dismissableLayer.focusOutside",cy,Wg=f.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Hg=f.forwardRef(Dt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=t,d=f.useContext(Wg),[m,p]=f.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,y]=f.useState({}),b=ut(s,p),x=Array.from(d.layers),[v]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),j=v?x.indexOf(v):-1,w=m?x.indexOf(m):-1,S=d.layersWithOutsidePointerEventsDisabled.size>0,k=w>=j,N=f.useRef(!1),C=eS(z=>{l==null||l(z),c==null||c(z),z.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:N,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:f.useCallback(z=>{if(!(z instanceof Node))return!1;const L=[...d.branches].some(E=>E.contains(z));return k&&!L},[d.branches,k])}),I=tS(z=>{if(i&&N.current)return;const L=z.target;[...d.branches].some($=>$.contains(L))||(o==null||o(z),c==null||c(z),z.defaultPrevented||u==null||u())},g),A=m?w===x.length-1:!1,O=us(z=>{z.key==="Escape"&&(a==null||a(z),!z.defaultPrevented&&u&&(z.preventDefault(),u()))});return f.useEffect(()=>{if(A)return g.addEventListener("keydown",O,{capture:!0}),()=>g.removeEventListener("keydown",O,{capture:!0})},[g,A,O]),f.useEffect(()=>{if(m)return r&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(cy=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(m)),d.layers.add(m),Im(),()=>{r&&(d.layersWithOutsidePointerEventsDisabled.delete(m),d.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=cy))}},[m,g,r,d]),f.useEffect(()=>()=>{m&&(d.layers.delete(m),d.layersWithOutsidePointerEventsDisabled.delete(m),Im())},[m,d]),f.useEffect(()=>{const z=Dt(()=>y({}),"handleUpdate");return document.addEventListener(Rm,z),()=>document.removeEventListener(Rm,z)},[]),n.jsx(bt.div,{...h,ref:b,style:{pointerEvents:S?k?"auto":"none":void 0,...t.style},onFocusCapture:Ie(t.onFocusCapture,I.onFocusCapture),onBlurCapture:Ie(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:Ie(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),_I=f.forwardRef(Dt(function(t,s){const r=f.useContext(Wg),i=f.useRef(null),a=ut(s,i);return f.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(bt.div,{...t,ref:a})},"DismissableLayerBranch"));function Zk(){const e=f.useContext(Wg),[t,s]=f.useState(null);return f.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Dt(Zk,"useDismissableLayerSurface");var LI=Dt(()=>!0,"IS_TRUE");function eS(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=LI}=t,o=us(e),c=f.useRef(!1),u=f.useRef(!1),h=f.useRef(new Map),d=f.useRef(()=>{});return f.useEffect(()=>{function m(){u.current=!1,i.current=!1,h.current.clear()}Dt(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}Dt(p,"isOutsideInteractionIntercepted");function g(j){if(!u.current)return;const w=j.target;w instanceof Node&&[...a].some(k=>k.contains(w))||h.current.set(j.type,!0),j.type==="click"&&window.setTimeout(()=>{u.current&&d.current()},0)}Dt(g,"handleInteractionCapture");function y(j){u.current&&h.current.set(j.type,!1)}Dt(y,"handleInteractionBubble");const b=Dt(j=>{if(j.target&&!c.current){let w=function(){s.removeEventListener("click",d.current);const k=p();m(),k||Kg(OI,o,S,{discrete:!0})};if(Dt(w,"handleAndDispatchPointerDownOutsideEvent"),!l(j.target)){s.removeEventListener("click",d.current),m(),c.current=!1;return}const S={originalEvent:j};u.current=!0,i.current=r&&j.button===0,h.current.clear(),!r||j.button!==0?w():(s.removeEventListener("click",d.current),d.current=w,s.addEventListener("click",d.current,{once:!0}))}else s.removeEventListener("click",d.current),m();c.current=!1},"handlePointerDown"),x=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const j of x)s.addEventListener(j,g,!0),s.addEventListener(j,y);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",b),s.removeEventListener("click",d.current);for(const j of x)s.removeEventListener(j,g,!0),s.removeEventListener(j,y)}},[s,o,r,i,a,l]),{onPointerDownCapture:Dt(()=>c.current=!0,"onPointerDownCapture")}}Dt(eS,"usePointerDownOutside");function tS(e,t=globalThis==null?void 0:globalThis.document){const s=us(e),r=f.useRef(!1);return f.useEffect(()=>{const i=Dt(a=>{a.target&&!r.current&&Kg(DI,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:Dt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Dt(()=>r.current=!1,"onBlurCapture")}}Dt(tS,"useFocusOutside");function Im(){const e=new CustomEvent(Rm);document.dispatchEvent(e)}Dt(Im,"dispatchUpdate");function Kg(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?Id(i,a):i.dispatchEvent(a)}Dt(Kg,"handleAndDispatchCustomEvent");var FI=_I,Tn=globalThis!=null&&globalThis.document?f.useLayoutEffect:()=>{},zI=Object.defineProperty,UI=(e,t)=>zI(e,"name",{value:t,configurable:!0}),Vg=f.forwardRef(UI(function(t,s){var c;const{container:r,...i}=t,[a,l]=f.useState(!1);Tn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?zo.createPortal(n.jsx(bt.div,{...i,ref:s}),o):null},"Portal")),BI=Object.defineProperty,fr=(e,t)=>BI(e,"name",{value:t,configurable:!0});function nS(e,t){return f.useReducer((s,r)=>t[s][r]??s,e)}fr(nS,"useStateMachine");var vr=fr(e=>{const{present:t,children:s}=e,r=sS(t),i=typeof s=="function"?s({present:r.isPresent}):f.Children.only(s),a=rS(r.ref,iS(i));return typeof s=="function"||r.isPresent?f.cloneElement(i,{ref:a}):null},"Presence");function sS(e){const[t,s]=f.useState(),r=f.useRef(null),i=f.useRef(e),a=f.useRef("none"),l=f.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=nS(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return f.useEffect(()=>{c==="mounted"?(a.current=l.current??la(r.current),l.current=void 0):a.current="none"},[c]),Tn(()=>{const h=r.current,d=i.current;if(d!==e){const p=a.current,g=la(h);e?(l.current=g,u("MOUNT")):g==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(d&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Tn(()=>{if(t){let h;const d=t.ownerDocument.defaultView??window,m=fr(g=>{const b=la(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(u("ANIMATION_END"),!i.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",h=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},"handleAnimationEnd"),p=fr(g=>{g.target===t&&(a.current=la(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{d.clearTimeout(h),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:f.useCallback(h=>{if(h){const d=getComputedStyle(h);r.current=d,l.current=la(d)}else r.current=null;s(h)},[])}}fr(sS,"usePresence");function Pm(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}fr(Pm,"setRef");function rS(...e){const t=f.useRef(e);return t.current=e,f.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=Pm(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():Pm(r[l],null)}}},[])}fr(rS,"useStableComposedRefs");function la(e){return(e==null?void 0:e.animationName)||"none"}fr(la,"getAnimationName");function iS(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)}fr(iS,"getElementRef");var WI=Object.defineProperty,HI=(e,t)=>WI(e,"name",{value:t,configurable:!0}),uy=Za[" useEffectEvent ".trim().toString()],dy=Za[" useInsertionEffect ".trim().toString()];function aS(e){if(typeof uy=="function")return uy(e);const t=f.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof dy=="function"?dy(()=>{t.current=e}):Tn(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}HI(aS,"useEffectEvent");var KI=Object.defineProperty,Uo=(e,t)=>KI(e,"name",{value:t,configurable:!0}),VI=Za[" useInsertionEffect ".trim().toString()]||Tn;function Hi({prop:e,defaultProp:t,onChange:s=Uo(()=>{},"onChange"),caller:r}){const[i,a,l]=lS({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=f.useCallback(h=>{var d;if(o){const m=oS(h)?h(e):h;m!==e&&((d=l.current)==null||d.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}Uo(Hi,"useControllableState");function lS({defaultProp:e,onChange:t}){const[s,r]=f.useState(e),i=f.useRef(s),a=f.useRef(t);return VI(()=>{a.current=t},[t]),f.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}Uo(lS,"useUncontrolledState");function oS(e){return typeof e=="function"}Uo(oS,"isFunction");var hy=Symbol("RADIX:SYNC_STATE");function GI(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=aS(l),h=[{...s,state:a}];r&&h.push(r);const[d,m]=f.useReducer((b,x)=>{if(x.type===hy)return{...b,state:x.state};const v=e(b,x);return c&&!Object.is(v.state,b.state)&&u(v.state),v},...h),p=d.state,g=f.useRef(p);f.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const y=f.useMemo(()=>i!==void 0?{...d,state:i}:d,[d,i]);return f.useEffect(()=>{c&&!Object.is(i,d.state)&&m({type:hy,state:i})},[i,d.state,c]),[y,m]}Uo(GI,"useControllableStateReducer");var YI=Object.defineProperty,qI=(e,t)=>YI(e,"name",{value:t,configurable:!0}),QI=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"}),cS=f.forwardRef(qI(function(t,s){return n.jsx(bt.span,{...t,ref:s,style:{...QI,...t.style}})},"VisuallyHidden")),JI=cS,XI=Object.defineProperty,cn=(e,t)=>XI(e,"name",{value:t,configurable:!0}),uS="ToastProvider",[dS,ZI,eP]=Rd("Toast"),[hS,JK]=Ns("Toast",[eP]),[tP,fS]=hS(uS),nP=cn(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=f.useState(null),[h,d]=f.useState(0),m=f.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${uS}\`. Expected non-empty \`string\`.`),n.jsx(dS.Provider,{scope:t,children:n.jsx(tP,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:f.useCallback(()=>d(p=>p+1),[]),onToastRemove:f.useCallback(()=>d(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),sP="ToastViewport",rP=["F8"],iP="toast.viewportPause",aP="toast.viewportResume",lP=f.forwardRef(cn(function(t,s){const{__scopeToast:r,hotkey:i=rP,label:a="Notifications ({hotkey})",...l}=t,o=fS(sP,r),c=ZI(r),u=f.useRef(null),h=f.useRef(null),d=f.useRef(null),m=f.useRef(null),p=ut(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=o.toastCount>0;f.useEffect(()=>{const x=cn(v=>{var w;i.length!==0&&i.every(S=>v[S]||v.code===S)&&((w=m.current)==null||w.focus())},"handleKeyDown");return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[i]),f.useEffect(()=>{const x=u.current,v=m.current;if(y&&x&&v){const j=cn(()=>{if(!o.isClosePausedRef.current){const N=new CustomEvent(iP);v.dispatchEvent(N),o.isClosePausedRef.current=!0}},"handlePause"),w=cn(()=>{if(o.isClosePausedRef.current){const N=new CustomEvent(aP);v.dispatchEvent(N),o.isClosePausedRef.current=!1}},"handleResume"),S=cn(N=>{!x.contains(N.relatedTarget)&&w()},"handleFocusOutResume"),k=cn(()=>{x.contains(document.activeElement)||w()},"handlePointerLeaveResume");return x.addEventListener("focusin",j),x.addEventListener("focusout",S),x.addEventListener("pointermove",j),x.addEventListener("pointerleave",k),window.addEventListener("blur",j),window.addEventListener("focus",w),()=>{x.removeEventListener("focusin",j),x.removeEventListener("focusout",S),x.removeEventListener("pointermove",j),x.removeEventListener("pointerleave",k),window.removeEventListener("blur",j),window.removeEventListener("focus",w)}}},[y,o.isClosePausedRef]);const b=f.useCallback(({tabbingDirection:x})=>{const j=c().map(w=>{const S=w.ref.current,k=[S,...gS(S)];return x==="forwards"?k:k.reverse()});return(x==="forwards"?j.reverse():j).flat()},[c]);return f.useEffect(()=>{const x=m.current;if(x){const v=cn(j=>{var k,N,C;const w=j.altKey||j.ctrlKey||j.metaKey;if(j.key==="Tab"&&!w){const I=document.activeElement,A=j.shiftKey;if(j.target===x&&A){(k=h.current)==null||k.focus();return}const L=b({tabbingDirection:A?"backwards":"forwards"}),E=L.findIndex($=>$===I);ou(L.slice(E+1))?j.preventDefault():A?(N=h.current)==null||N.focus():(C=d.current)==null||C.focus()}},"handleKeyDown");return x.addEventListener("keydown",v),()=>x.removeEventListener("keydown",v)}},[c,b]),n.jsxs(FI,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:y?void 0:"none"},children:[y&&n.jsx(fy,{ref:h,onFocusFromOutsideViewport:()=>{const x=b({tabbingDirection:"forwards"});ou(x)}}),n.jsx(dS.Slot,{scope:r,children:n.jsx(bt.ol,{tabIndex:-1,...l,ref:p})}),y&&n.jsx(fy,{ref:d,onFocusFromOutsideViewport:()=>{const x=b({tabbingDirection:"backwards"});ou(x)}})]})},"ToastViewport")),oP="ToastFocusProxy",fy=f.forwardRef(cn(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=fS(oP,r);return n.jsx(cS,{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")),cP="Toast",[XK,ZK]=hS(cP,{onClose(){}});function mS(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),pS(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(...mS(r))}}),t}cn(mS,"getAnnounceTextContent");function uP(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?Id(i,a):i.dispatchEvent(a)}cn(uP,"handleAndDispatchCustomEvent");function dP(e=()=>{}){const t=us(e);Tn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}cn(dP,"useNextFrame");function pS(e){return e.nodeType===e.ELEMENT_NODE}cn(pS,"isHTMLElement");function gS(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(gS,"getTabbableCandidates");function ou(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}cn(ou,"focusFirst");var my=nP,py=lP,hP=Object.defineProperty,fP=(e,t)=>hP(e,"name",{value:t,configurable:!0}),mP=Za[" useId ".trim().toString()]||(()=>{}),pP=0;function vs(e){const[t,s]=f.useState(mP());return Tn(()=>{e||s(r=>r??String(pP++))},[e]),e||(t?`radix-${t}`:"")}fP(vs,"useId");const gP=["top","right","bottom","left"],ei=Math.min,ar=Math.max,Hu=Math.round,Sc=Math.floor,lr=e=>({x:e,y:e}),xP={left:"right",right:"left",bottom:"top",top:"bottom"};function xS(e,t,s){return ar(e,ei(t,s))}function mr(e,t){return typeof e=="function"?e(t):e}function ti(e){return e.split("-")[0]}function sl(e){return e.split("-")[1]}function Gg(e){return e==="x"?"y":"x"}function Yg(e){return e==="y"?"height":"width"}function Ls(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function qg(e){return Gg(Ls(e))}function vP(e,t,s){s===void 0&&(s=!1);const r=sl(e),i=qg(e),a=Yg(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Ku(l)),[l,Ku(l)]}function jP(e){const t=Ku(e);return[$m(e),t,$m(t)]}function $m(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gy=["left","right"],xy=["right","left"],yP=["top","bottom"],wP=["bottom","top"];function bP(e,t,s){switch(e){case"top":case"bottom":return s?t?xy:gy:t?gy:xy;case"left":case"right":return t?yP:wP;default:return[]}}function kP(e,t,s,r){const i=sl(e);let a=bP(ti(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map($m)))),a}function Ku(e){const t=ti(e);return xP[t]+e.slice(t.length)}function SP(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 vS(e){return typeof e!="number"?SP(e):{top:e,right:e,bottom:e,left:e}}function Vu(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 vy(e,t,s){let{reference:r,floating:i}=e;const a=Ls(t),l=qg(t),o=Yg(l),c=ti(t),u=a==="y",h=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-i.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:d};break;case"left":p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}const g=sl(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function NP(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:d="floating",altBoundary:m=!1,padding:p=0}=mr(t,e),g=vS(p),b=o[m?d==="floating"?"reference":"floating":d],x=Vu(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),v=d==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,j=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),w=await(a.isElement==null?void 0:a.isElement(j))&&await(a.getScale==null?void 0:a.getScale(j))||{x:1,y:1},S=Vu(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:j,strategy:c}):v);return{top:(x.top-S.top+g.top)/w.y,bottom:(S.bottom-x.bottom+g.bottom)/w.y,left:(x.left-S.left+g.left)/w.x,right:(S.right-x.right+g.right)/w.x}}const CP=50,EP=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:NP},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:d}=vy(u,r,c),m=r,p=0;const g={};for(let y=0;y<a.length;y++){const b=a[y];if(!b)continue;const{name:x,fn:v}=b,{x:j,y:w,data:S,reset:k}=await v({x:h,y:d,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});h=j??h,d=w??d,g[x]={...g[x],...S},k&&p<CP&&(p++,typeof k=="object"&&(k.placement&&(m=k.placement),k.rects&&(u=k.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):k.rects),{x:h,y:d}=vy(u,m,c)),y=-1)}return{x:h,y:d,placement:m,strategy:i,middlewareData:g}},AP=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}=mr(e,t)||{};if(u==null)return{};const d=vS(h),m={x:s,y:r},p=qg(i),g=Yg(p),y=await l.getDimensions(u),b=p==="y",x=b?"top":"left",v=b?"bottom":"right",j=b?"clientHeight":"clientWidth",w=a.reference[g]+a.reference[p]-m[p]-a.floating[g],S=m[p]-a.reference[p],k=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let N=k?k[j]:0;(!N||!await(l.isElement==null?void 0:l.isElement(k)))&&(N=o.floating[j]||a.floating[g]);const C=w/2-S/2,I=N/2-y[g]/2-1,A=ei(d[x],I),O=ei(d[v],I),z=N-y[g]-O,L=N/2-y[g]/2+C,E=xS(A,L,z),$=!c.arrow&&sl(i)!=null&&L!==E&&a.reference[g]/2-(L<A?A:O)-y[g]/2<0,_=$?L<A?L-A:L-z:0;return{[p]:m[p]+_,data:{[p]:E,centerOffset:L-E-_,...$&&{alignmentOffset:_}},reset:$}}}),TP=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:h=!0,crossAxis:d=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...b}=mr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const x=ti(i),v=Ls(o),j=ti(o)===o,w=await(c.isRTL==null?void 0:c.isRTL(u.floating)),S=m||(j||!y?[Ku(o)]:jP(o)),k=g!=="none";!m&&k&&S.push(...kP(o,y,g,w));const N=[o,...S],C=await c.detectOverflow(t,b),I=[];let A=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&I.push(C[x]),d){const E=vP(i,l,w);I.push(C[E[0]],C[E[1]])}if(A=[...A,{placement:i,overflows:I}],!I.every(E=>E<=0)){var O,z;const E=(((O=a.flip)==null?void 0:O.index)||0)+1,$=N[E];if($&&(!(d==="alignment"?v!==Ls($):!1)||A.every(M=>Ls(M.placement)===v?M.overflows[0]>0:!0)))return{data:{index:E,overflows:A},reset:{placement:$}};let _=(z=A.filter(B=>B.overflows[0]<=0).sort((B,M)=>B.overflows[1]-M.overflows[1])[0])==null?void 0:z.placement;if(!_)switch(p){case"bestFit":{var L;const B=(L=A.filter(M=>{if(k){const W=Ls(M.placement);return W===v||W==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(W=>W>0).reduce((W,D)=>W+D,0)]).sort((M,W)=>M[1]-W[1])[0])==null?void 0:L[0];B&&(_=B);break}case"initialPlacement":_=o;break}if(i!==_)return{reset:{placement:_}}}return{}}}};function jy(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function yy(e){return gP.some(t=>e[t]>=0)}const RP=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=mr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=jy(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:yy(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=jy(l,s.floating);return{data:{escapedOffsets:o,escaped:yy(o)}}}default:return{}}}}},jS=new Set(["left","top"]);async function IP(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=ti(s),o=sl(s),c=Ls(s)==="y",u=jS.has(l)?-1:1,h=a&&c?-1:1,d=mr(t,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.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 PP=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 IP(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}}}}},$P=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:v=>{let{x:j,y:w}=v;return{x:j,y:w}}},...u}=mr(e,t),h={x:s,y:r},d=await a.detectOverflow(t,u),m=Ls(i),p=Gg(m);let g=h[p],y=h[m];const b=(v,j)=>xS(j+d[v==="y"?"top":"left"],j,j-d[v==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(y=b(m,y));const x=c.fn({...t,[p]:g,[m]:y});return{...x,data:{x:x.x-s,y:x.y-r,enabled:{[p]:l,[m]:o}}}}}},MP=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:h=!0,crossAxis:d=!0}=mr(e,t),m={x:i,y:a},p=Ls(l),g=Gg(p);let y=m[g],b=m[p];const x=mr(u,t),v=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:(s=x.mainAxis)!=null?s:0,crossAxis:(r=x.crossAxis)!=null?r:0};if(h){const S=g==="y"?"height":"width",k=o.reference[g]-o.floating[S]+v.mainAxis,N=o.reference[g]+o.reference[S]-v.mainAxis;y<k?y=k:y>N&&(y=N)}if(d){var j,w;const S=g==="y"?"width":"height",k=jS.has(ti(l)),N=o.reference[p]-o.floating[S]+(k&&((j=c.offset)==null?void 0:j[p])||0)+(k?0:v.crossAxis),C=o.reference[p]+o.reference[S]+(k?0:((w=c.offset)==null?void 0:w[p])||0)-(k?v.crossAxis:0);b<N?b=N:b>C&&(b=C)}return{[g]:y,[p]:b}}}},OP=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}=mr(e,t),c=await i.detectOverflow(t,o),u=ti(s),h=sl(s),d=Ls(s)==="y",{width:m,height:p}=r.floating;let g,y;u==="top"||u==="bottom"?(g=u,y=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=u,g=h==="end"?"top":"bottom");const b=p-c.top-c.bottom,x=m-c.left-c.right,v=ei(p-c[g],b),j=ei(m-c[y],x),w=t.middlewareData.shift,S=!w;let k=v,N=j;w!=null&&w.enabled.x&&(N=x),w!=null&&w.enabled.y&&(k=b),S&&!h&&(d?N=m-2*ar(c.left,c.right):k=p-2*ar(c.top,c.bottom)),await l({...t,availableWidth:N,availableHeight:k});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Pd(){return typeof window<"u"}function rl(e){return yS(e)?(e.nodeName||"").toLowerCase():"#document"}function Rn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jr(e){var t;return(t=(yS(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function yS(e){return Pd()?e instanceof Node||e instanceof Rn(e).Node:!1}function Ws(e){return Pd()?e instanceof Element||e instanceof Rn(e).Element:!1}function ci(e){return Pd()?e instanceof HTMLElement||e instanceof Rn(e).HTMLElement:!1}function wy(e){return!Pd()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rn(e).ShadowRoot}function $d(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=Hs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function DP(e){return/^(table|td|th)$/.test(rl(e))}function Md(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const _P=/transform|translate|scale|rotate|perspective|filter/,LP=/paint|layout|strict|content/,gi=e=>!!e&&e!=="none";let Uh;function Qg(e){const t=Ws(e)?Hs(e):e;return gi(t.transform)||gi(t.translate)||gi(t.scale)||gi(t.rotate)||gi(t.perspective)||!Jg()&&(gi(t.backdropFilter)||gi(t.filter))||_P.test(t.willChange||"")||LP.test(t.contain||"")}function FP(e){let t=Di(e);for(;ci(t)&&!xo(t);){if(Qg(t))return t;if(Md(t))return null;t=Di(t)}return null}function Jg(){return Uh==null&&(Uh=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Uh}function xo(e){return/^(html|body|#document)$/.test(rl(e))}function Hs(e){return Rn(e).getComputedStyle(e)}function Od(e){return Ws(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Di(e){if(rl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||wy(e)&&e.host||jr(e);return wy(t)?t.host:t}function wS(e){const t=Di(e);return xo(t)?(e.ownerDocument||e).body:ci(t)&&$d(t)?t:wS(t)}function vo(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=wS(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Rn(i);if(a){const o=Mm(l);return t.concat(l,l.visualViewport||[],$d(i)?i:[],o&&s?vo(o):[])}else return t.concat(i,vo(i,[],s))}function Mm(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bS(e){const t=Hs(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=ci(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Hu(s)!==a||Hu(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function Xg(e){return Ws(e)?e:e.contextElement}function Ta(e){const t=Xg(e);if(!ci(t))return lr(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=bS(t);let l=(a?Hu(s.width):s.width)/r,o=(a?Hu(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const zP=lr(0);function kS(e){const t=Rn(e);return!Jg()||!t.visualViewport?zP:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function UP(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Rn(e)}function _i(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=Xg(e);let l=lr(1);t&&(r?Ws(r)&&(l=Ta(r)):l=Ta(e));const o=UP(a,s,r)?kS(a):lr(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,h=i.width/l.x,d=i.height/l.y;if(a&&r){const m=Rn(a),p=Ws(r)?Rn(r):r;let g=m,y=Mm(g);for(;y&&p!==g;){const b=Ta(y),x=y.getBoundingClientRect(),v=Hs(y),j=x.left+(y.clientLeft+parseFloat(v.paddingLeft))*b.x,w=x.top+(y.clientTop+parseFloat(v.paddingTop))*b.y;c*=b.x,u*=b.y,h*=b.x,d*=b.y,c+=j,u+=w,g=Rn(y),y=Mm(g)}}return Vu({width:h,height:d,x:c,y:u})}function Dd(e,t){const s=Od(e).scrollLeft;return t?t.left+s:_i(jr(e)).left+s}function SS(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-Dd(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function BP(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=jr(r),o=t?Md(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=lr(1);const h=lr(0),d=ci(r);if((d||!a)&&((rl(r)!=="body"||$d(l))&&(c=Od(r)),d)){const p=_i(r);u=Ta(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!d&&!a?SS(l,c):lr(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 WP(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function HP(e){const t=Od(e),s=e.ownerDocument.body,r=ar(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=ar(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+Dd(e);const l=-t.scrollTop;return Hs(s).direction==="rtl"&&(a+=ar(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const KP=25;function VP(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Rn(e),a=jr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!Jg()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(Dd(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),y=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-y),x=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;x<=KP&&(o-=x)}return{width:o,height:c,x:u,y:h}}function GP(e,t){const s=_i(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=Ta(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 by(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=VP(e,s,t);else if(t==="document")r=HP(jr(e));else if(Ws(t))r=GP(t,s);else{const i=kS(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Vu(r)}function YP(e,t){const s=t.get(e);if(s)return s;let r=vo(e,[],!1).filter(o=>Ws(o)&&rl(o)!=="body"),i=null;const a=Hs(e).position==="fixed";let l=a?Di(e):e;for(;Ws(l)&&!xo(l);){const o=Hs(l),c=Qg(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(d=>d!==l):i=o,l=Di(l)}return t.set(e,r),r}function qP(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?Md(t)?[]:YP(t,this._c):[].concat(s),r],o=by(t,l[0],i);let c=o.top,u=o.right,h=o.bottom,d=o.left;for(let m=1;m<l.length;m++){const p=by(t,l[m],i);c=ar(p.top,c),u=ei(p.right,u),h=ei(p.bottom,h),d=ar(p.left,d)}return{width:u-d,height:h-c,x:d,y:c}}function QP(e){const{width:t,height:s}=bS(e);return{width:t,height:s}}function JP(e,t,s){const r=ci(t),i=jr(t),a=s==="fixed",l=_i(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=lr(0);if((r||!a)&&((rl(t)!=="body"||$d(i))&&(o=Od(t)),r)){const m=_i(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=Dd(i));const u=i&&!r&&!a?SS(i,o):lr(0),h=l.left+o.scrollLeft-c.x-u.x,d=l.top+o.scrollTop-c.y-u.y;return{x:h,y:d,width:l.width,height:l.height}}function Bh(e){return Hs(e).position==="static"}function ky(e,t){if(!ci(e)||Hs(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return jr(e)===s&&(s=s.ownerDocument.body),s}function NS(e,t){const s=Rn(e);if(Md(e))return s;if(!ci(e)){let i=Di(e);for(;i&&!xo(i);){if(Ws(i)&&!Bh(i))return i;i=Di(i)}return s}let r=ky(e,t);for(;r&&DP(r)&&Bh(r);)r=ky(r,t);return r&&xo(r)&&Bh(r)&&!Qg(r)?s:r||FP(e)||s}const XP=async function(e){const t=this.getOffsetParent||NS,s=this.getDimensions,r=await s(e.floating);return{reference:JP(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ZP(e){return Hs(e).direction==="rtl"}const e2={convertOffsetParentRelativeRectToViewportRelativeRect:BP,getDocumentElement:jr,getClippingRect:qP,getOffsetParent:NS,getElementRects:XP,getClientRects:WP,getDimensions:QP,getScale:Ta,isElement:Ws,isRTL:ZP};function CS(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function t2(e,t,s){let r=null,i;const a=jr(e);function l(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function o(h,d){h===void 0&&(h=!1),d===void 0&&(d=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:y,height:b}=m;if(h||t(),!y||!b)return;const x=Sc(g),v=Sc(a.clientWidth-(p+y)),j=Sc(a.clientHeight-(g+b)),w=Sc(p),k={rootMargin:-x+"px "+-v+"px "+-j+"px "+-w+"px",threshold:ar(0,ei(1,d))||1};let N=!0;function C(I){const A=I[0].intersectionRatio;if(!CS(m,e.getBoundingClientRect()))return o();if(A!==d){if(!N)return o();A?o(!1,A):i=setTimeout(()=>{o(!1,1e-7)},1e3)}N=!1}try{r=new IntersectionObserver(C,{...k,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,k)}r.observe(e)}const c=Rn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function n2(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=Xg(e),h=i||a?[...u?vo(u):[],...t?vo(t):[]]:[];h.forEach(x=>{i&&x.addEventListener("scroll",s),a&&x.addEventListener("resize",s)});const d=u&&o?t2(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(x=>{let[v]=x;v&&v.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var j;(j=p)==null||j.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,y=c?_i(e):null;c&&b();function b(){const x=_i(e);y&&!CS(y,x)&&s(),y=x,g=requestAnimationFrame(b)}return s(),()=>{var x;h.forEach(v=>{i&&v.removeEventListener("scroll",s),a&&v.removeEventListener("resize",s)}),d==null||d(),(x=p)==null||x.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const s2=PP,r2=$P,i2=TP,a2=OP,l2=RP,Sy=AP,o2=MP,c2=(e,t,s)=>{const r=new Map,i=s??{},a={...e2,...i.platform,_c:r};return EP(e,t,{...i,platform:a})};var u2=typeof document<"u",d2=function(){},cu=u2?f.useLayoutEffect:d2;function Gu(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(!Gu(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)&&!Gu(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function ES(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ny(e,t){const s=ES(e);return Math.round(t*s)/s}function Wh(e){const t=f.useRef(e);return cu(()=>{t.current=e}),t}function h2(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,d]=f.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=f.useState(r);Gu(m,r)||p(r);const[g,y]=f.useState(null),[b,x]=f.useState(null),v=f.useCallback(M=>{M!==k.current&&(k.current=M,y(M))},[]),j=f.useCallback(M=>{M!==N.current&&(N.current=M,x(M))},[]),w=a||g,S=l||b,k=f.useRef(null),N=f.useRef(null),C=f.useRef(h),I=c!=null,A=Wh(c),O=Wh(i),z=Wh(u),L=f.useCallback(()=>{if(!k.current||!N.current)return;const M={placement:t,strategy:s,middleware:m};O.current&&(M.platform=O.current),c2(k.current,N.current,M).then(W=>{const D={...W,isPositioned:z.current!==!1};E.current&&!Gu(C.current,D)&&(C.current=D,zo.flushSync(()=>{d(D)}))})},[m,t,s,O,z]);cu(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,d(M=>({...M,isPositioned:!1})))},[u]);const E=f.useRef(!1);cu(()=>(E.current=!0,()=>{E.current=!1}),[]),cu(()=>{if(w&&(k.current=w),S&&(N.current=S),w&&S){if(A.current)return A.current(w,S,L);L()}},[w,S,L,A,I]);const $=f.useMemo(()=>({reference:k,floating:N,setReference:v,setFloating:j}),[v,j]),_=f.useMemo(()=>({reference:w,floating:S}),[w,S]),B=f.useMemo(()=>{const M={position:s,left:0,top:0};if(!_.floating)return M;const W=Ny(_.floating,h.x),D=Ny(_.floating,h.y);return o?{...M,transform:"translate("+W+"px, "+D+"px)",...ES(_.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:W,top:D}},[s,o,_.floating,h.x,h.y]);return f.useMemo(()=>({...h,update:L,refs:$,elements:_,floatingStyles:B}),[h,L,$,_,B])}const f2=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?Sy({element:r.current,padding:i}).fn(s):{}:r?Sy({element:r,padding:i}).fn(s):{}}}},m2=(e,t)=>{const s=s2(e);return{name:s.name,fn:s.fn,options:[e,t]}},p2=(e,t)=>{const s=r2(e);return{name:s.name,fn:s.fn,options:[e,t]}},g2=(e,t)=>({fn:o2(e).fn,options:[e,t]}),x2=(e,t)=>{const s=i2(e);return{name:s.name,fn:s.fn,options:[e,t]}},v2=(e,t)=>{const s=a2(e);return{name:s.name,fn:s.fn,options:[e,t]}},j2=(e,t)=>{const s=l2(e);return{name:s.name,fn:s.fn,options:[e,t]}},y2=(e,t)=>{const s=f2(e);return{name:s.name,fn:s.fn,options:[e,t]}};var w2=Object.defineProperty,b2=(e,t)=>w2(e,"name",{value:t,configurable:!0});function AS(e){const[t,s]=f.useState(void 0);return Tn(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let l,o;if("borderBoxSize"in a){const c=a.borderBoxSize,u=Array.isArray(c)?c[0]:c;l=u.inlineSize,o=u.blockSize}else l=e.offsetWidth,o=e.offsetHeight;s({width:l,height:o})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),t}b2(AS,"useSize");var k2=Object.defineProperty,Vr=(e,t)=>k2(e,"name",{value:t,configurable:!0}),TS="Popper",[RS,_d]=Ns(TS),[S2,IS]=RS(TS),N2=Vr(e=>{const{__scopePopper:t,children:s}=e,[r,i]=f.useState(null),[a,l]=f.useState(void 0);return n.jsx(S2,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),C2="PopperAnchor",E2=f.forwardRef(Vr(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=IS(C2,r),o=f.useRef(null),c=l.onAnchorChange,u=f.useCallback(y=>{o.current=y,y&&c(y)},[c]),h=ut(s,u),d=f.useRef(null);f.useEffect(()=>{if(!i)return;const y=d.current;d.current=i.current,y!==d.current&&c(d.current)});const m=l.placementState&&Ld(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(bt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:h})},"PopperAnchor")),PS="PopperContent",[A2,eV]=RS(PS),T2=f.forwardRef(Vr(function(t,s){var $e,ke,we,Ce,dt,fe,Me;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:d=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:y,...b}=t,x=IS(PS,r),[v,j]=f.useState(null),w=ut(s,j),[S,k]=f.useState(null),N=AS(S),C=(N==null?void 0:N.width)??0,I=(N==null?void 0:N.height)??0,A=i+(l!=="center"?"-"+l:""),O=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},z=Array.isArray(h)?h:[h],L=z.length>0,E={padding:O,boundary:z.filter($S),altBoundary:L},{refs:$,floatingStyles:_,placement:B,isPositioned:M,middlewareData:W}=h2({strategy:"fixed",placement:A,whileElementsMounted:Vr((...ce)=>n2(...ce,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:x.anchor},middleware:[m2({mainAxis:a+I,alignmentAxis:o}),u&&p2({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?g2():void 0,...E}),u&&x2({...E}),v2({...E,apply:Vr(({elements:ce,rects:Te,availableWidth:G,availableHeight:ie})=>{const{width:Pe,height:it}=Te.reference,Ye=ce.floating.style;Ye.setProperty("--radix-popper-available-width",`${G}px`),Ye.setProperty("--radix-popper-available-height",`${ie}px`),Ye.setProperty("--radix-popper-anchor-width",`${Pe}px`),Ye.setProperty("--radix-popper-anchor-height",`${it}px`)},"apply")}),S&&y2({element:S,padding:c}),R2({arrowWidth:C,arrowHeight:I}),p&&j2({strategy:"referenceHidden",...E,boundary:L?E.boundary:void 0})]}),D=x.setPlacementState;Tn(()=>(D(B),()=>{D(void 0)}),[B,D]);const[U,V]=Ld(B),Z=us(y);Tn(()=>{M&&(Z==null||Z())},[M,Z]);const ue=($e=W.arrow)==null?void 0:$e.x,Ae=(ke=W.arrow)==null?void 0:ke.y,X=((we=W.arrow)==null?void 0:we.centerOffset)!==0,[le,me]=f.useState();return Tn(()=>{v&&me(window.getComputedStyle(v).zIndex)},[v]),n.jsx("div",{ref:$.setFloating,"data-radix-popper-content-wrapper":"",style:{..._,transform:M?_.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:le,"--radix-popper-transform-origin":[(Ce=W.transformOrigin)==null?void 0:Ce.x,(dt=W.transformOrigin)==null?void 0:dt.y].join(" "),...((fe=W.hide)==null?void 0:fe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(A2,{scope:r,placedSide:U,placedAlign:V,onArrowChange:k,arrowX:ue,arrowY:Ae,shouldHideArrow:X,children:n.jsx(bt.div,{"data-side":U,"data-align":V,...b,ref:w,style:{...b.style,animation:M?(Me=b.style)==null?void 0:Me.animation:"none"}})})})},"PopperContent"));function $S(e){return e!==null}Vr($S,"isNotNull");var R2=Vr(e=>({name:"transformOrigin",options:e,fn(t){var b,x,v;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=Ld(s),d={start:"0%",center:"50%",end:"100%"}[h],m=(((x=i.arrow)==null?void 0:x.x)??0)+o/2,p=(((v=i.arrow)==null?void 0:v.y)??0)+c/2;let g="",y="";return u==="bottom"?(g=l?d:`${m}px`,y=`${-c}px`):u==="top"?(g=l?d:`${m}px`,y=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,y=l?d:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,y=l?d:`${p}px`),{data:{x:g,y}}}}),"transformOrigin");function Ld(e){const[t,s="center"]=e.split("-");return[t,s]}Vr(Ld,"getSideAndAlignFromPlacement");var Zg=N2,MS=E2,OS=T2,I2=Object.defineProperty,Ht=(e,t)=>I2(e,"name",{value:t,configurable:!0}),[ex,tV]=Ns("Tooltip",[_d]),tx=_d(),P2="TooltipProvider",$2=700,Om="tooltip.open",[M2,nx]=ex(P2),O2=Ht(e=>{const{__scopeTooltip:t,delayDuration:s=$2,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=f.useRef(!0),o=f.useRef(!1),c=f.useRef(0);return f.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(M2,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:f.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),Dm="Tooltip",[D2,Bo]=ex(Dm),_2=Ht(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=nx(Dm,e.__scopeTooltip),u=tx(t),[h,d]=f.useState(null),[m,p]=f.useState(void 0),g=vs(),y=f.useRef(0),b=l??c.disableHoverableContent,x=o??c.delayDuration,v=f.useRef(!1),[j,w]=Hi({prop:r,defaultProp:i??!1,onChange:Ht(A=>{A?(c.onOpen(),document.dispatchEvent(new CustomEvent(Om))):c.onClose(),a==null||a(A)},"onChange"),caller:Dm}),S=f.useMemo(()=>j?v.current?"delayed-open":"instant-open":"closed",[j]),k=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,v.current=!1,w(!0)},[w]),N=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,w(!1)},[w]),C=f.useCallback(()=>{window.clearTimeout(y.current),y.current=window.setTimeout(()=>{v.current=!0,w(!0),y.current=0},x)},[x,w]);f.useEffect(()=>()=>{y.current&&(window.clearTimeout(y.current),y.current=0)},[]);const I=m??g;return n.jsx(Zg,{...u,children:n.jsx(D2,{scope:t,contentId:I,setContentId:p,open:j,stateAttribute:S,trigger:h,onTriggerChange:d,onTriggerEnter:f.useCallback(()=>{c.isOpenDelayedRef.current?C():k()},[c.isOpenDelayedRef,C,k]),onTriggerLeave:f.useCallback(()=>{b?N():(window.clearTimeout(y.current),y.current=0)},[N,b]),onOpen:k,onClose:N,disableHoverableContent:b,children:s})})},"Tooltip"),Cy="TooltipTrigger",L2=f.forwardRef(Ht(function(t,s){const{__scopeTooltip:r,...i}=t,a=Bo(Cy,r),l=nx(Cy,r),o=tx(r),c=f.useRef(null),u=ut(s,c,a.onTriggerChange),h=f.useRef(!1),d=f.useRef(!1),m=f.useCallback(()=>h.current=!1,[]);return f.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx(MS,{asChild:!0,...o,children:n.jsx(bt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Ie(t.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),d.current=!0)}),onPointerLeave:Ie(t.onPointerLeave,()=>{a.onTriggerLeave(),d.current=!1}),onPointerDown:Ie(t.onPointerDown,()=>{a.open&&a.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Ie(t.onFocus,()=>{h.current||a.onOpen()}),onBlur:Ie(t.onBlur,a.onClose),onClick:Ie(t.onClick,a.onClose)})})},"TooltipTrigger")),DS="TooltipPortal",[F2,z2]=ex(DS,{forceMount:void 0}),U2=Ht(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=Bo(DS,t);return n.jsx(F2,{scope:t,forceMount:s,children:n.jsx(vr,{present:s||a.open,children:n.jsx(Vg,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),jo="TooltipContent",B2=f.forwardRef(Ht(function(t,s){const r=z2(jo,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=Bo(jo,t.__scopeTooltip);return n.jsx(vr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(_S,{side:a,...l,ref:s}):n.jsx(W2,{side:a,...l,ref:s})})},"TooltipContent")),W2=f.forwardRef(Ht(function(t,s){const r=Bo(jo,t.__scopeTooltip),i=nx(jo,t.__scopeTooltip),a=f.useRef(null),l=ut(s,a),[o,c]=f.useState(null),{trigger:u,onClose:h}=r,d=a.current,{onPointerInTransitChange:m}=i,p=f.useCallback(()=>{c(null),m(!1)},[m]),g=f.useCallback((y,b)=>{const x=y.currentTarget,v={x:y.clientX,y:y.clientY},j=LS(v,x.getBoundingClientRect()),w=FS(v,j),S=zS(b.getBoundingClientRect()),k=BS([...w,...S]);c(k),m(!0)},[m]);return f.useEffect(()=>()=>p(),[p]),f.useEffect(()=>{if(u&&d){const y=Ht(x=>g(x,d),"handleTriggerLeave"),b=Ht(x=>g(x,u),"handleContentLeave");return u.addEventListener("pointerleave",y),d.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",y),d.removeEventListener("pointerleave",b)}}},[u,d,g,p]),f.useEffect(()=>{if(o){const y=Ht(b=>{const x=b.target,v={x:b.clientX,y:b.clientY},j=(u==null?void 0:u.contains(x))||(d==null?void 0:d.contains(x)),w=!US(v,o);j?p():w&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",y),()=>document.removeEventListener("pointermove",y)}},[u,d,o,h,p]),n.jsx(_S,{...t,ref:l})},"TooltipContentHoverable")),H2=Hk("TooltipContent"),_S=f.forwardRef(Ht(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=Bo(jo,r),d=tx(r),{onClose:m}=h;f.useEffect(()=>(document.addEventListener(Om,m),()=>document.removeEventListener(Om,m)),[m]),f.useEffect(()=>{if(h.trigger){const g=Ht(y=>{y.target instanceof Node&&y.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 Tn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(Hg,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(OS,{"data-state":h.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:h.contentId,...d,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[n.jsx(H2,{children:i}),a?n.jsx(JI,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function LS(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")}}Ht(LS,"getExitSideFromRect");function FS(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}Ht(FS,"getPaddedExitPoints");function zS(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}]}Ht(zS,"getPointsFromRect");function US(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,d=c.x,m=c.y;h>r!=m>r&&s<(d-u)*(r-h)/(m-h)+u&&(i=!i)}return i}Ht(US,"isPointInPolygon");function BS(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),WS(t)}Ht(BS,"getHull");function WS(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)}Ht(WS,"getHullPresorted");var Ey=O2,yo=_2,wo=L2,bo=U2,ko=B2;const Ay="buddi_csrf",il="x-buddi-csrf",So="buddi:agents-changed",K2="This page's sign-in no longer matches its cookies. Reload the page and try again.";class pe extends Error{constructor(t,s,r){super(s),this.status=t,this.detail=r,this.name="ApiError"}}function Ki(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${Ay}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${Ay}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Yu="buddi isn't answering.";let _m=null;const Lm=new Set;function Nc(e){if(e!==(_m===null)){_m=e?null:Date.now();for(const t of Lm)t()}}function V2(){return _m}function G2(e){return Lm.add(e),()=>Lm.delete(e)}function Y2(e){return e instanceof pe&&(e.status===0||e.status===502||e.status===503)&&e.message===Yu}async function Vi(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:(Nc(!1),new pe(0,Yu,o))}if(s.status===401)throw Nc(!0),new pe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");const r=await s.text(),i=r===""?null:q2(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 Nc(!1),new pe(s.status,Yu,i);if(Nc(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?K2:`request failed (${s.status})`);throw new pe(s.status,c,i)}return i}function q2(e){try{return JSON.parse(e)}catch{return null}}function he(e,t={}){const s=new URLSearchParams;for(const[i,a]of Object.entries(t))a!==void 0&&a!==""&&s.set(i,String(a));const r=s.toString();return Vi(`/api${e}${r?`?${r}`:""}`)}function HS(e,t){return Vi(`/api${e}`,{method:"POST",headers:{[il]:Ki()},body:t})}function wa(e){return Vi(`/api${e}`,{method:"DELETE",headers:{[il]:Ki()}})}function ne(e,t={}){return Vi(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[il]:Ki()},body:JSON.stringify(t??{})})}function KS(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return Vi(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[il]:Ki(),"X-Filename":i,...r},body:t})}function Ty(e,t,s){return KS(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function Q2(e,t={}){return Vi(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[il]:Ki()},body:JSON.stringify(t??{})})}function xi(e,t={}){return Vi(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[il]:Ki()},body:JSON.stringify(t??{})})}function J2(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 uu="gpt-oss:120b",X2=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Fm=["mon","tue","wed","thu","fri","sat","sun"],Le={agents:()=>he("/chat/agents"),views:()=>he("/chat/views"),conversations:(e,t)=>he(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>ne(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>he(`/chat/conversations/${encodeURIComponent(e)}`),send:(e,t)=>ne(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>ne(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>ne(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),HS("/chat/attachments",t)},transcribe:e=>ne("/speech/transcribe",e),say:e=>ne("/speech/say",e),discardAttachment:e=>wa(`/artifacts/${encodeURIComponent(e)}`),groups:()=>he("/groups"),group:e=>he(`/groups/${encodeURIComponent(e)}`),createGroup:e=>ne("/groups",e),updateGroup:(e,t)=>Q2(`/groups/${encodeURIComponent(e)}`,t),archiveGroup:e=>wa(`/groups/${encodeURIComponent(e)}`),groupConversations:e=>he(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>ne(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>ne(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function sx(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>he("/providers"),providerAccounts:()=>he("/provider-accounts"),probeModels:e=>ne("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>ne(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>ne("/provider-accounts/save",e),testProviderAccount:e=>ne(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>ne(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>ne(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>ne(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>ne(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>ne(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>ne(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>ne(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>he("/host/browser-profiles",{app:e}),installedApps:()=>he("/host/apps"),browser:e=>he(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>ne(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>ne("/browser/settings",e),computerPermissions:(e=!1)=>ne("/browser/permissions",{prompt:e}),browserInstall:()=>ne("/browser/install",{}),browserCheck:()=>ne("/browser/check",{}),previewLink:(e,t)=>he(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>he(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>he("/extension"),pairExtension:e=>ne("/extension/pair",{code:e}),forgetExtension:()=>wa("/extension/pair"),session:()=>he("/session"),overview:()=>he("/overview"),events:e=>he("/events",e),eventKinds:()=>he("/events/kinds"),conversations:()=>he("/conversations"),conversation:e=>he(`/conversations/${encodeURIComponent(e)}`),missions:()=>he("/missions"),jobs:(e={})=>he("/jobs",e),approvals:()=>he("/approvals"),approval:e=>he(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>he("/offers"),dismissOffer:e=>ne(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>ne("/offers/dismiss-all",{ids:e}),agentOffers:()=>he("/agent-offers"),teammates:()=>he("/teammates"),dismissAgentOffer:(e,t)=>ne(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>he("/proposals"),setDigestSchedule:(e,t)=>ne("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),discardProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>he("/reminders"),sentinels:()=>he("/sentinels"),setSentinelEnabled:(e,t)=>ne(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),setGlanceHidden:(e,t)=>ne(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>he("/rail"),setRailHidden:(e,t,s)=>ne(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlert:(e,t)=>ne(`/alerts/${encodeURIComponent(e)}/snooze`,{snoozed:t}),agents:()=>he("/agents"),library:e=>he("/artifacts",e),libraryEntry:(e,t=0)=>he(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>he("/onboarding"),onboardingStep:(e,t={})=>ne("/onboarding/step",{step:e,...t}),takeOn:e=>ne("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>he("/onboarding/take-on"),completeOnboarding:()=>ne("/onboarding/complete"),skipOnboarding:()=>ne("/onboarding/skip"),createFirstAgent:e=>ne("/onboarding/agent",e),ollama:()=>he("/onboarding/ollama"),mlxh:()=>he("/onboarding/mlxh"),firstAgentPersona:()=>he("/onboarding/agent"),updateFirstAgent:e=>ne("/onboarding/agent/update",e),bindBrain:e=>ne("/onboarding/brain",e),pages:()=>he("/pages"),pageQuery:(e,t,s={})=>he(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,s),pageFileUrl:(e,t,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,i])=>i!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r?`?${r}`:""}`},pageAct:(e,t)=>ne(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>he("/telegram"),saveTelegramToken:e=>ne("/telegram/token",{token:e}),telegramPairing:()=>ne("/telegram/pairing"),telegramBot:()=>he("/telegram/bot"),telegramDevices:()=>he("/telegram/devices"),unpairTelegramDevice:e=>wa(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>he("/notifications",{limit:e}),notificationSeen:e=>ne(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>he("/notifications/settings"),saveNotificationSettings:e=>xi("/notifications/settings",e),focus:()=>he("/notifications/focus"),setFocus:(e,t)=>xi("/notifications/focus",t?{mode:e,duration:t}:{mode:e}),testChannel:e=>ne("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>ne("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>he(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>he("/tips"),restoreTip:e=>ne(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>ne(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>ne(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>ne("/tips/seen-page",{page:e}),tipsSettings:()=>he("/tips/settings"),saveTipsSettings:e=>xi("/tips/settings",{enabled:e}),presence:e=>ne("/presence",{state:e}),owner:()=>he("/owner"),setOwner:e=>ne("/owner",e),memory:e=>he(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>ne("/memory/preferences",e),forgetPreference:e=>ne("/memory/preferences/forget",e),updateNote:(e,t)=>ne(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>ne(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>he(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>he(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>he("/host",{agentId:e,conversationId:t}),connections:()=>he("/connections"),connection:e=>he(`/connections/${e}`),addConnection:(e,t)=>ne("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>ne("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>ne(`/connections/${e}/program`,t),connectionConsent:(e,t)=>ne(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>ne(`/connections/${e}/token`,t),connectionDevice:e=>ne(`/connections/${e}/device`,{}),connectionCallback:e=>ne("/connections/callback",e),connectionReview:e=>he(`/connections/${e}/review`),saveConnectionReview:(e,t)=>ne(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>ne(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>ne(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>wa(`/connections/${e}`),connectionSignals:()=>he("/connections/signals"),connectionTools:e=>he(`/connections/${e}/tools`),rememberedApprovals:e=>he(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>ne("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>he("/secrets"),secretUses:(e,t)=>he("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>ne("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>ne("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>ne("/host/revoke",{id:e}),decide:(e,t,s,r)=>ne(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>ne("/pause",{paused:e}),service:()=>he("/service"),serviceAction:e=>ne(`/service/${e}`),version:()=>he("/version"),checkVersion:()=>ne("/version/check"),setVersionCheck:e=>xi("/version/check",{enabled:e}),tailscale:()=>he("/tailscale"),setTailscale:e=>xi("/tailscale",e),startUpgrade:e=>ne("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>he(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>he("/backups"),startBackup:e=>ne("/backups",{encrypt:e}),verifyArchive:e=>ne("/backups/verify",{name:e}),restoreArchive:e=>ne("/backups/restore",e),restoreUpload:(e,t)=>Ty("/backups/restore",e,t),backupJob:e=>he(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>he("/backups/schedule"),setBackupSchedule:e=>xi("/backups/schedule",e),backupPassphrase:()=>he("/backups/passphrase"),setBackupPassphrase:e=>xi("/backups/passphrase",{passphrase:e}),plugins:()=>he("/plugins"),market:(e=!1)=>he(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>he("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>ne("/plugins/stage",{spec:e}),uploadPlugin:e=>KS("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>he(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>ne(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>ne(`/plugins/staged/${encodeURIComponent(e)}/reject`),updatePlugin:(e,t,s)=>ne(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>he("/recovery"),leaveRecovery:e=>ne("/recovery/leave",e),firstRunRestore:(e,t)=>Ty("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>ne(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),setMisfirePolicy:(e,t,s)=>ne(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>ne(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>ne(`/jobs/${encodeURIComponent(e)}/cancel`),setDefaultAgent:e=>ne("/agents/default",{agentId:e}),agentTools:e=>he(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>he(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),HS(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>wa(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>ne(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>ne(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})};function VS(e){return e==="anthropic"||e==="openai"}function GS(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 Z2="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var e$=Object.defineProperty,t$=(e,t)=>e$(e,"name",{value:t,configurable:!0}),n$=f.createContext(void 0);function Fd(e){const t=f.useContext(n$);return e||t||"ltr"}t$(Fd,"useDirection");var s$=Object.defineProperty,rx=(e,t)=>s$(e,"name",{value:t,configurable:!0}),Cc=0,$s=null;function r$(e){return zd(),e.children}rx(r$,"FocusGuards");function zd(){f.useEffect(()=>{$s||($s={start:zm(),end:zm()});const{start:e,end:t}=$s;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Cc++,()=>{Cc===1&&($s==null||$s.start.remove(),$s==null||$s.end.remove(),$s=null),Cc=Math.max(0,Cc-1)}},[])}rx(zd,"useFocusGuards");function zm(){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}rx(zm,"createFocusGuard");var i$=Object.defineProperty,xn=(e,t)=>i$(e,"name",{value:t,configurable:!0}),Hh="focusScope.autoFocusOnMount",Kh="focusScope.autoFocusOnUnmount",Ry={bubbles:!1,cancelable:!0},YS=f.forwardRef(xn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=f.useState(null),h=us(a),d=us(l),m=f.useRef(null),p=ut(s,u),g=f.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;f.useEffect(()=>{if(i){let b=function(w){if(g.paused||!c)return;const S=w.target;c.contains(S)?m.current=S:Zs(m.current,{select:!0})},x=function(w){if(g.paused||!c)return;const S=w.relatedTarget;S!==null&&(c.contains(S)||Zs(m.current,{select:!0}))},v=function(w){if(document.activeElement===document.body)for(const k of w)k.removedNodes.length>0&&Zs(c)};xn(b,"handleFocusIn"),xn(x,"handleFocusOut"),xn(v,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",x);const j=new MutationObserver(v);return c&&j.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",x),j.disconnect()}}},[i,c,g.paused]),f.useEffect(()=>{if(c){Iy.add(g);const b=document.activeElement;if(!c.contains(b)){const v=new CustomEvent(Hh,Ry);c.addEventListener(Hh,h),c.dispatchEvent(v),v.defaultPrevented||(qS(eN(ix(c)),{select:!0}),document.activeElement===b&&Zs(c))}return()=>{c.removeEventListener(Hh,h),setTimeout(()=>{const v=new CustomEvent(Kh,Ry);c.addEventListener(Kh,d),c.dispatchEvent(v),v.defaultPrevented||Zs(b??document.body,{select:!0}),c.removeEventListener(Kh,d),Iy.remove(g)},0)}}},[c,h,d,g]);const y=f.useCallback(b=>{if(!r&&!i||g.paused)return;const x=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,v=document.activeElement;if(x&&v){const j=b.currentTarget,[w,S]=QS(j);w&&S?!b.shiftKey&&v===S?(b.preventDefault(),r&&Zs(w,{select:!0})):b.shiftKey&&v===w&&(b.preventDefault(),r&&Zs(S,{select:!0})):v===j&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(bt.div,{tabIndex:-1,...o,ref:p,onKeyDown:y})},"FocusScope"));function qS(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(Zs(r,{select:t}),document.activeElement!==s)return}xn(qS,"focusFirst");function QS(e){const t=ix(e),s=Um(t,e),r=Um(t.reverse(),e);return[s,r]}xn(QS,"getTabbableEdges");function ix(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}xn(ix,"getTabbableCandidates");function Um(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):JS(r,{upTo:t})))return r}xn(Um,"findVisible");function JS(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}xn(JS,"isHidden");function XS(e){return e instanceof HTMLInputElement&&"select"in e}xn(XS,"isSelectableInput");function Zs(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&XS(e)&&t&&e.select()}}xn(Zs,"focus");var Iy=ZS();function ZS(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Bm(e,t),e.unshift(t)},remove(t){var s;e=Bm(e,t),(s=e[0])==null||s.resume()}}}xn(ZS,"createFocusScopesStack");function Bm(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}xn(Bm,"arrayRemove");function eN(e){return e.filter(t=>t.tagName!=="A")}xn(eN,"removeLinks");var a$=Object.defineProperty,ax=(e,t)=>a$(e,"name",{value:t,configurable:!0}),Vh=!1;function tN(){const[e,t]=f.useState(Vh);return f.useEffect(()=>{Vh||(Vh=!0,t(!0))},[]),e}ax(tN,"useIsHydrated");var nN=Za[" useSyncExternalStore ".trim().toString()];function sN(){return()=>{}}ax(sN,"subscribe");function rN(){return nN(sN,()=>!0,()=>!1)}ax(rN,"useIsHydratedModern");var l$=typeof nN=="function"?rN:tN,o$=Object.defineProperty,Gi=(e,t)=>o$(e,"name",{value:t,configurable:!0}),Gh="rovingFocusGroup.onEntryFocus",c$={bubbles:!1,cancelable:!0},Ud="RovingFocusGroup",[Wm,iN,u$]=Rd(Ud),[d$,Bd]=Ns(Ud,[u$]),[h$,f$]=d$(Ud),m$=f.forwardRef(Gi(function(t,s){return n.jsx(Wm.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Wm.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(p$,{...t,ref:s})})})},"RovingFocusGroup")),p$=f.forwardRef(Gi(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:d=!1,...m}=t,p=f.useRef(null),g=ut(s,p),y=Fd(l),[b,x]=Hi({prop:o,defaultProp:c??null,onChange:u,caller:Ud}),[v,j]=f.useState(!1),w=us(h),S=iN(r),k=f.useRef(!1),[N,C]=f.useState(0);return f.useEffect(()=>{const I=p.current;if(I)return I.addEventListener(Gh,w),()=>I.removeEventListener(Gh,w)},[w]),n.jsx(h$,{scope:r,orientation:i,dir:y,loop:a,currentTabStopId:b,onItemFocus:f.useCallback(I=>x(I),[x]),onItemShiftTab:f.useCallback(()=>j(!0),[]),onFocusableItemAdd:f.useCallback(()=>C(I=>I+1),[]),onFocusableItemRemove:f.useCallback(()=>C(I=>I-1),[]),children:n.jsx(bt.div,{tabIndex:v||N===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Ie(t.onMouseDown,()=>{k.current=!0}),onFocus:Ie(t.onFocus,I=>{const A=!k.current;if(I.target===I.currentTarget&&A&&!v){const O=new CustomEvent(Gh,c$);if(I.currentTarget.dispatchEvent(O),!O.defaultPrevented){const z=S().filter(B=>B.focusable),L=z.find(B=>B.active),E=z.find(B=>B.id===b),_=[L,E,...z].filter(Boolean).map(B=>B.ref.current);lx(_,d)}}k.current=!1}),onBlur:Ie(t.onBlur,()=>j(!1))})})},"RovingFocusGroupImpl")),g$="RovingFocusGroupItem",x$=f.forwardRef(Gi(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=vs(),h=l||u,d=f$(g$,r),m=d.currentTabStopId===h,p=iN(r),{onFocusableItemAdd:g,onFocusableItemRemove:y,currentTabStopId:b}=d,x=l$();return Tn(()=>{if(!(!x||!i))return g(),()=>y()},[x,i,g,y]),f.useEffect(()=>{if(!(x||!i))return g(),()=>y()},[x,i,g,y]),n.jsx(Wm.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(bt.span,{tabIndex:m?0:-1,"data-orientation":d.orientation,...c,ref:s,onMouseDown:Ie(t.onMouseDown,v=>{i?d.onItemFocus(h):v.preventDefault()}),onFocus:Ie(t.onFocus,()=>d.onItemFocus(h)),onKeyDown:Ie(t.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const j=lN(v,d.orientation,d.dir);if(j!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(j==="last")S.reverse();else if(j==="prev"||j==="next"){j==="prev"&&S.reverse();const k=S.indexOf(v.currentTarget);S=d.loop?oN(S,k+1):S.slice(k+1)}setTimeout(()=>lx(S))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),v$={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function aN(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}Gi(aN,"getDirectionAwareKey");function lN(e,t,s){const r=aN(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return v$[r]}Gi(lN,"getFocusIntent");function lx(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}Gi(lx,"focusFirst");function oN(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Gi(oN,"wrapArray");var cN=m$,uN=x$,j$=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ta=new WeakMap,Ec=new WeakMap,Ac={},Yh=0,dN=function(e){return e&&(e.host||dN(e.parentNode))},y$=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=dN(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})},w$=function(e,t,s,r){var i=y$(t,Array.isArray(e)?e:[e]);Ac[s]||(Ac[s]=new WeakMap);var a=Ac[s],l=[],o=new Set,c=new Set(i),u=function(d){!d||o.has(d)||(o.add(d),u(d.parentNode))};i.forEach(u);var h=function(d){!d||c.has(d)||Array.prototype.forEach.call(d.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",y=(ta.get(m)||0)+1,b=(a.get(m)||0)+1;ta.set(m,y),a.set(m,b),l.push(m),y===1&&g&&Ec.set(m,!0),b===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",m,x)}})};return h(t),o.clear(),Yh++,function(){l.forEach(function(d){var m=ta.get(d)-1,p=a.get(d)-1;ta.set(d,m),a.set(d,p),m||(Ec.has(d)||d.removeAttribute(r),Ec.delete(d)),p||d.removeAttribute(s)}),Yh--,Yh||(ta=new WeakMap,ta=new WeakMap,Ec=new WeakMap,Ac={})}},hN=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=j$(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),w$(r,i,s,"aria-hidden")):function(){return null}},_s=function(){return _s=Object.assign||function(t){for(var s,r=1,i=arguments.length;r<i;r++){s=arguments[r];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},_s.apply(this,arguments)};function fN(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 b$(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 du="right-scroll-bar-position",hu="width-before-scroll-bar",k$="with-scroll-bars-hidden",S$="--removed-body-scroll-bar-size";function qh(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function N$(e,t){var s=f.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var C$=typeof window<"u"?f.useLayoutEffect:f.useEffect,Py=new WeakMap;function E$(e,t){var s=N$(null,function(r){return e.forEach(function(i){return qh(i,r)})});return C$(function(){var r=Py.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||qh(o,null)}),a.forEach(function(o){i.has(o)||qh(o,l)})}Py.set(s,e)},[e]),s}function A$(e){return e}function T$(e,t){t===void 0&&(t=A$);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 R$(e){e===void 0&&(e={});var t=T$(null);return t.options=_s({async:!0,ssr:!1},e),t}var mN=function(e){var t=e.sideCar,s=fN(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return f.createElement(r,_s({},s))};mN.isSideCarExport=!0;function I$(e,t){return e.useMedium(t),mN}var pN=R$(),Qh=function(){},Wd=f.forwardRef(function(e,t){var s=f.useRef(null),r=f.useState({onScrollCapture:Qh,onWheelCapture:Qh,onTouchMoveCapture:Qh}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,d=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,y=e.inert,b=e.allowPinchZoom,x=e.as,v=x===void 0?"div":x,j=e.gapMode,w=fN(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=m,k=E$([s,t]),N=_s(_s({},w),i);return f.createElement(f.Fragment,null,h&&f.createElement(S,{sideCar:pN,removeScrollBar:u,shards:d,noRelative:p,noIsolation:g,inert:y,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:j}),l?f.cloneElement(f.Children.only(o),_s(_s({},N),{ref:k})):f.createElement(v,_s({},N,{className:c,ref:k}),o))});Wd.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Wd.classNames={fullWidth:hu,zeroRight:du};var P$=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $$(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=P$();return t&&e.setAttribute("nonce",t),e}function M$(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function O$(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var D$=function(){var e=0,t=null;return{add:function(s){e==0&&(t=$$())&&(M$(t,s),O$(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_$=function(){var e=D$();return function(t,s){f.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},gN=function(){var e=_$(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},L$={left:0,top:0,right:0,gap:0},Jh=function(e){return parseInt(e||"",10)||0},F$=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[Jh(s),Jh(r),Jh(i)]},z$=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return L$;var t=F$(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])}},U$=gN(),Ra="data-scroll-locked",B$=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(k$,` {
|
|
42
|
+
overflow: hidden `).concat(r,`;
|
|
43
|
+
padding-right: `).concat(o,"px ").concat(r,`;
|
|
44
|
+
}
|
|
45
|
+
body[`).concat(Ra,`] {
|
|
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(du,` {
|
|
59
|
+
right: `).concat(o,"px ").concat(r,`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.`).concat(hu,` {
|
|
63
|
+
margin-right: `).concat(o,"px ").concat(r,`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.`).concat(du," .").concat(du,` {
|
|
67
|
+
right: 0 `).concat(r,`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.`).concat(hu," .").concat(hu,` {
|
|
71
|
+
margin-right: 0 `).concat(r,`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body[`).concat(Ra,`] {
|
|
75
|
+
`).concat(S$,": ").concat(o,`px;
|
|
76
|
+
}
|
|
77
|
+
`)},$y=function(){var e=parseInt(document.body.getAttribute(Ra)||"0",10);return isFinite(e)?e:0},W$=function(){f.useEffect(function(){return document.body.setAttribute(Ra,($y()+1).toString()),function(){var e=$y()-1;e<=0?document.body.removeAttribute(Ra):document.body.setAttribute(Ra,e.toString())}},[])},H$=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;W$();var a=f.useMemo(function(){return z$(i)},[i]);return f.createElement(U$,{styles:B$(a,!t,i,s?"":"!important")})},Hm=!1;if(typeof window<"u")try{var Tc=Object.defineProperty({},"passive",{get:function(){return Hm=!0,!0}});window.addEventListener("test",Tc,Tc),window.removeEventListener("test",Tc,Tc)}catch{Hm=!1}var na=Hm?{passive:!1}:!1,K$=function(e){return e.tagName==="TEXTAREA"},xN=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!K$(e)&&s[t]==="visible")},V$=function(e){return xN(e,"overflowY")},G$=function(e){return xN(e,"overflowX")},My=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=vN(e,r);if(i){var a=jN(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},Y$=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},q$=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},vN=function(e,t){return e==="v"?V$(t):G$(t)},jN=function(e,t){return e==="v"?Y$(t):q$(t)},Q$=function(e,t){return e==="h"&&t==="rtl"?-1:1},J$=function(e,t,s,r,i){var a=Q$(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,h=l>0,d=0,m=0;do{if(!o)break;var p=jN(e,o),g=p[0],y=p[1],b=p[2],x=y-b-a*g;(g||x)&&vN(e,o)&&(d+=x,m+=g);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(h&&Math.abs(d)<1||!h&&Math.abs(m)<1)&&(u=!0),u},Rc=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Oy=function(e){return[e.deltaX,e.deltaY]},Dy=function(e){return e&&"current"in e?e.current:e},X$=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Z$=function(e){return`
|
|
78
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
79
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
80
|
+
`)},eM=0,sa=[];function tM(e){var t=f.useRef([]),s=f.useRef([0,0]),r=f.useRef(),i=f.useState(eM++)[0],a=f.useState(gN)[0],l=f.useRef(e);f.useEffect(function(){l.current=e},[e]),f.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var y=b$([e.lockRef.current],(e.shards||[]).map(Dy),!0).filter(Boolean);return y.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),y.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=f.useCallback(function(y,b){if("touches"in y&&y.touches.length===2||y.type==="wheel"&&y.ctrlKey)return!l.current.allowPinchZoom;var x=Rc(y),v=s.current,j="deltaX"in y?y.deltaX:v[0]-x[0],w="deltaY"in y?y.deltaY:v[1]-x[1],S,k=y.target,N=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in y&&N==="h"&&k.type==="range")return!1;var C=window.getSelection(),I=C&&C.anchorNode,A=I?I===k||I.contains(k):!1;if(A)return!1;var O=My(N,k);if(!O)return!0;if(O?S=N:(S=N==="v"?"h":"v",O=My(N,k)),!O)return!1;if(!r.current&&"changedTouches"in y&&(j||w)&&(r.current=S),!S)return!0;var z=r.current||S;return J$(z,b,y,z==="h"?j:w)},[]),c=f.useCallback(function(y){var b=y;if(!(!sa.length||sa[sa.length-1]!==a)){var x="deltaY"in b?Oy(b):Rc(b),v=t.current.filter(function(S){return S.name===b.type&&(S.target===b.target||b.target===S.shadowParent)&&X$(S.delta,x)})[0];if(v&&v.should){b.cancelable&&b.preventDefault();return}if(!v){var j=(l.current.shards||[]).map(Dy).filter(Boolean).filter(function(S){return S.contains(b.target)}),w=j.length>0?o(b,j[0]):!l.current.noIsolation;w&&b.cancelable&&b.preventDefault()}}},[]),u=f.useCallback(function(y,b,x,v){var j={name:y,delta:b,target:x,should:v,shadowParent:nM(x)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),h=f.useCallback(function(y){s.current=Rc(y),r.current=void 0},[]),d=f.useCallback(function(y){u(y.type,Oy(y),y.target,o(y,e.lockRef.current))},[]),m=f.useCallback(function(y){u(y.type,Rc(y),y.target,o(y,e.lockRef.current))},[]);f.useEffect(function(){return sa.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:m}),document.addEventListener("wheel",c,na),document.addEventListener("touchmove",c,na),document.addEventListener("touchstart",h,na),function(){sa=sa.filter(function(y){return y!==a}),document.removeEventListener("wheel",c,na),document.removeEventListener("touchmove",c,na),document.removeEventListener("touchstart",h,na)}},[]);var p=e.removeScrollBar,g=e.inert;return f.createElement(f.Fragment,null,g?f.createElement(a,{styles:Z$(i)}):null,p?f.createElement(H$,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function nM(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const sM=I$(pN,tM);var ox=f.forwardRef(function(e,t){return f.createElement(Wd,_s({},e,{ref:t,sideCar:sM}))});ox.classNames=Wd.classNames;var rM=Object.defineProperty,Ve=(e,t)=>rM(e,"name",{value:t,configurable:!0}),Km=["Enter"," "],iM=["ArrowDown","PageUp","Home"],yN=["ArrowUp","PageDown","End"],aM=[...iM,...yN],lM={ltr:[...Km,"ArrowRight"],rtl:[...Km,"ArrowLeft"]},oM={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Hd="Menu",[No,cM,uM]=Rd(Hd),[Yi,wN]=Ns(Hd,[uM,_d,Bd]),Kd=_d(),bN=Bd(),[kN,ui]=Yi(Hd),[dM,Wo]=Yi(Hd),hM=Ve(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=Kd(t),[c,u]=f.useState(null),h=f.useRef(!1),d=us(a),m=Fd(i);return f.useEffect(()=>{const p=Ve(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=Ve(()=>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})}},[]),f.useEffect(()=>{if(!s)return;const p=Ve(()=>d(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,d]),n.jsx(Zg,{...o,children:n.jsx(kN,{scope:t,open:s,onOpenChange:d,content:c,onContentChange:u,children:n.jsx(dM,{scope:t,onClose:f.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),SN=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,...i}=t,a=Kd(r);return n.jsx(MS,{...a,...i,ref:s})},"MenuAnchor")),NN="MenuPortal",[fM,CN]=Yi(NN,{forceMount:void 0}),mM=Ve(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=ui(NN,t);return n.jsx(fM,{scope:t,forceMount:s,children:n.jsx(vr,{present:s||a.open,children:n.jsx(Vg,{asChild:!0,container:i,children:r})})})},"MenuPortal"),js="MenuContent",[pM,cx]=Yi(js),gM=f.forwardRef(Ve(function(t,s){const r=CN(js,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=ui(js,t.__scopeMenu),o=Wo(js,t.__scopeMenu);return n.jsx(No.Provider,{scope:t.__scopeMenu,children:n.jsx(vr,{present:i||l.open,children:n.jsx(No.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(xM,{...a,ref:s}):n.jsx(vM,{...a,ref:s})})})})},"MenuContent")),xM=f.forwardRef(Ve(function(t,s){const r=ui(js,t.__scopeMenu),i=f.useRef(null),a=ut(s,i);return f.useEffect(()=>{const l=i.current;if(l)return hN(l)},[]),n.jsx(ux,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Ie(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),vM=f.forwardRef(Ve(function(t,s){const r=ui(js,t.__scopeMenu);return n.jsx(ux,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),jM=Zr("MenuContent.ScrollLock"),ux=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:d,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:y,...b}=t,x=ui(js,r),v=Wo(js,r),j=Kd(r),w=bN(r),S=cM(r),[k,N]=f.useState(null),C=f.useRef(null),I=ut(s,C,x.onContentChange),A=f.useRef(0),O=f.useRef(""),z=f.useRef(0),L=f.useRef(null),E=f.useRef("right"),$=f.useRef(0),_=y?ox:f.Fragment,B=y?{as:jM,allowPinchZoom:!0}:void 0,M=Ve(D=>{var me,$e;const U=O.current+D,V=S().filter(ke=>!ke.disabled),Z=document.activeElement,ue=(me=V.find(ke=>ke.ref.current===Z))==null?void 0:me.textValue,Ae=V.map(ke=>ke.textValue),X=DN(Ae,U,ue),le=($e=V.find(ke=>ke.textValue===X))==null?void 0:$e.ref.current;Ve(function ke(we){O.current=we,window.clearTimeout(A.current),we!==""&&(A.current=window.setTimeout(()=>ke(""),1e3))},"updateSearch")(U),le&&setTimeout(()=>le.focus())},"handleTypeaheadSearch");f.useEffect(()=>()=>window.clearTimeout(A.current),[]),zd();const W=f.useCallback(D=>{var V,Z;return E.current===((V=L.current)==null?void 0:V.side)&&LN(D,(Z=L.current)==null?void 0:Z.area)},[]);return n.jsx(pM,{scope:r,searchRef:O,onItemEnter:f.useCallback(D=>{W(D)&&D.preventDefault()},[W]),onItemLeave:f.useCallback(D=>{var U;W(D)||((U=C.current)==null||U.focus(),N(null))},[W]),onTriggerLeave:f.useCallback(D=>{W(D)&&D.preventDefault()},[W]),pointerGraceTimerRef:z,onPointerGraceIntentChange:f.useCallback(D=>{L.current=D},[]),children:n.jsx(_,{...B,children:n.jsx(YS,{asChild:!0,trapped:a,onMountAutoFocus:Ie(l,D=>{var U;D.preventDefault(),(U=C.current)==null||U.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(Hg,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:d,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(cN,{asChild:!0,...w,dir:v.dir,orientation:"vertical",loop:i,currentTabStopId:k,onCurrentTabStopIdChange:N,onEntryFocus:Ie(u,D=>{v.isUsingKeyboardRef.current||D.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(OS,{role:"menu","aria-orientation":"vertical","data-state":dx(x.open),"data-radix-menu-content":"",dir:v.dir,...j,...b,ref:I,style:{outline:"none",...b.style},onKeyDown:Ie(b.onKeyDown,D=>{const V=D.target.closest("[data-radix-menu-content]")===D.currentTarget,Z=D.ctrlKey||D.altKey||D.metaKey,ue=D.key.length===1;V&&(D.key==="Tab"&&D.preventDefault(),!Z&&ue&&M(D.key));const Ae=C.current;if(D.target!==Ae||!aM.includes(D.key))return;D.preventDefault();const le=S().filter(me=>!me.disabled).map(me=>me.ref.current);yN.includes(D.key)&&le.reverse(),MN(le)}),onBlur:Ie(t.onBlur,D=>{D.currentTarget.contains(D.target)||(window.clearTimeout(A.current),O.current="")}),onPointerMove:Ie(t.onPointerMove,Ba(D=>{const U=D.target,V=$.current!==D.clientX;if(D.currentTarget.contains(U)&&V){const Z=D.clientX>$.current?"right":"left";E.current=Z,$.current=D.clientX}}))})})})})})})},"MenuContentImpl")),EN=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{role:"group",...i,ref:s})},"MenuGroup")),yM=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{...i,ref:s})},"MenuLabel")),Vm="MenuItem",_y="menu.itemSelect",AN=f.forwardRef(Ve(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=f.useRef(null),o=Wo(Vm,t.__scopeMenu),c=cx(Vm,t.__scopeMenu),u=ut(s,l),h=f.useRef(!1),d=Ve(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(_y,{bubbles:!0,cancelable:!0});m.addEventListener(_y,g=>i==null?void 0:i(g),{once:!0}),Id(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(TN,{...a,ref:u,disabled:r,onClick:Ie(t.onClick,d),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),h.current=!0},onPointerUp:Ie(t.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Ie(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Km.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),TN=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=cx(Vm,r),c=bN(r),u=f.useRef(null),h=ut(s,u),[d,m]=f.useState(!1),[p,g]=f.useState("");return f.useEffect(()=>{const y=u.current;y&&g((y.textContent??"").trim())},[l.children]),n.jsx(No.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(uN,{asChild:!0,...c,focusable:!i,children:n.jsx(bt.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:h,onPointerMove:Ie(t.onPointerMove,Ba(y=>{i?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ie(t.onPointerLeave,Ba(y=>o.onItemLeave(y))),onFocus:Ie(t.onFocus,()=>m(!0)),onBlur:Ie(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),wM="MenuRadioGroup",[bM,kM]=Yi(wM,{value:void 0,onValueChange:Ve(()=>{},"onValueChange")}),SM=f.forwardRef(Ve(function(t,s){const{value:r,onValueChange:i,...a}=t,l=us(i);return n.jsx(bM,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(EN,{...a,ref:s})})},"MenuRadioGroup")),NM="MenuRadioItem",CM=f.forwardRef(Ve(function(t,s){const{value:r,...i}=t,a=kM(NM,t.__scopeMenu),l=r===a.value;return n.jsx(AM,{scope:t.__scopeMenu,checked:l,children:n.jsx(AN,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":$N(l),onSelect:Ie(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),EM="MenuItemIndicator",[AM,nV]=Yi(EM,{checked:!1}),TM=f.forwardRef(Ve(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),RN="MenuSub",[RM,IN]=Yi(RN),IM=Ve(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=ui(RN,t),l=Kd(t),[o,c]=f.useState(null),[u,h]=f.useState(null),d=us(i);return f.useEffect(()=>(a.open===!1&&d(!1),()=>d(!1)),[a.open,d]),n.jsx(Zg,{...l,children:n.jsx(kN,{scope:t,open:r,onOpenChange:d,content:u,onContentChange:h,children:n.jsx(RM,{scope:t,contentId:vs(),triggerId:vs(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Ic="MenuSubTrigger",PM=f.forwardRef(Ve(function(t,s){const r=ui(Ic,t.__scopeMenu),i=Wo(Ic,t.__scopeMenu),a=IN(Ic,t.__scopeMenu),l=cx(Ic,t.__scopeMenu),o=f.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:t.__scopeMenu},d=f.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);f.useEffect(()=>d,[d]),f.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=ut(s,a.onTriggerChange);return n.jsx(SN,{asChild:!0,...h,children:n.jsx(TN,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":dx(r.open),...t,ref:m,onClick:p=>{var g;(g=t.onClick)==null||g.call(t,p),!(t.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Ie(t.onPointerMove,Ba(p=>{l.onItemEnter(p),!p.defaultPrevented&&!t.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),d()},100))})),onPointerLeave:Ie(t.onPointerLeave,Ba(p=>{var y,b;d();const g=(y=r.content)==null?void 0:y.getBoundingClientRect();if(g){const x=(b=r.content)==null?void 0:b.dataset.side,v=x==="right",j=v?-5:5,w=g[v?"left":"right"],S=g[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+j,y:p.clientY},{x:w,y:g.top},{x:S,y:g.top},{x:S,y:g.bottom},{x:w,y:g.bottom}],side:x}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Ie(t.onKeyDown,p=>{var y;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||lM[i.dir].includes(p.key)&&(r.onOpenChange(!0),(y=r.content)==null||y.focus(),p.preventDefault())})})})},"MenuSubTrigger")),$M="MenuSubContent",MM=f.forwardRef(Ve(function(t,s){const r=CN(js,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=ui(js,t.__scopeMenu),c=Wo(js,t.__scopeMenu),u=IN($M,t.__scopeMenu),h=f.useRef(null),d=ut(s,h);return n.jsx(No.Provider,{scope:t.__scopeMenu,children:n.jsx(vr,{present:i||o.open,children:n.jsx(No.Slot,{scope:t.__scopeMenu,children:n.jsx(ux,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:d,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Ie(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Ie(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Ie(t.onKeyDown,m=>{var y;const p=m.currentTarget.contains(m.target),g=oM[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(y=u.trigger)==null||y.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function dx(e){return e?"open":"closed"}Ve(dx,"getOpenState");function PN(e){return e==="indeterminate"}Ve(PN,"isIndeterminate");function $N(e){return PN(e)?"indeterminate":e?"checked":"unchecked"}Ve($N,"getCheckedState");function MN(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}Ve(MN,"focusFirst");function ON(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Ve(ON,"wrapArray");function DN(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=ON(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}Ve(DN,"getNextMatch");function _N(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,d=c.x,m=c.y;h>r!=m>r&&s<(d-u)*(r-h)/(m-h)+u&&(i=!i)}return i}Ve(_N,"isPointInPolygon");function LN(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return _N(s,t)}Ve(LN,"isPointerInGraceArea");function Ba(e){return t=>t.pointerType==="mouse"?e(t):void 0}Ve(Ba,"whenMouse");var OM=hM,DM=SN,_M=mM,LM=gM,FM=EN,zM=yM,UM=AN,BM=SM,WM=CM,HM=TM,KM=IM,VM=PM,GM=MM,YM=Object.defineProperty,Gn=(e,t)=>YM(e,"name",{value:t,configurable:!0}),hx="DropdownMenu",[qM,sV]=Ns(hx,[wN]),Yn=wN(),[QM,FN]=qM(hx),JM=Gn(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=Yn(t),u=f.useRef(null),[h,d]=Hi({prop:i,defaultProp:a??!1,onChange:l,caller:hx});return n.jsx(QM,{scope:t,triggerId:vs(),triggerRef:u,contentId:vs(),open:h,onOpenChange:d,onOpenToggle:f.useCallback(()=>d(m=>!m),[d]),modal:o,children:n.jsx(OM,{...c,open:h,onOpenChange:d,dir:r,modal:o,children:s})})},"DropdownMenu"),XM="DropdownMenuTrigger",ZM=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=FN(XM,r),o=Yn(r),c=ut(s,l.triggerRef);return n.jsx(DM,{asChild:!0,...o,children:n.jsx(bt.button,{type:"button",id:l.triggerId,"aria-haspopup":"menu","aria-expanded":l.open,"aria-controls":l.open?l.contentId:void 0,"data-state":l.open?"open":"closed","data-disabled":i?"":void 0,disabled:i,...a,ref:c,onPointerDown:Ie(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Ie(t.onKeyDown,u=>{i||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),eO=Gn(e=>{const{__scopeDropdownMenu:t,...s}=e,r=Yn(t);return n.jsx(_M,{...r,...s})},"DropdownMenuPortal"),tO="DropdownMenuContent",nO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=FN(tO,r),l=Yn(r),o=f.useRef(!1);return n.jsx(LM,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Ie(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Ie(t.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,d=u.button===2||h;(!a.modal||d)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),sO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(FM,{...a,...i,ref:s})},"DropdownMenuGroup")),rO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(zM,{...a,...i,ref:s})},"DropdownMenuLabel")),iO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(UM,{...a,...i,ref:s})},"DropdownMenuItem")),aO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(BM,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),lO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(WM,{...a,...i,ref:s})},"DropdownMenuRadioItem")),oO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(HM,{...a,...i,ref:s})},"DropdownMenuSeparator")),cO=Gn(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=Yn(t),[o,c]=Hi({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(KM,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),uO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(VM,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),dO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(GM,{...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")),Vd=JM,Gd=ZM,Ho=eO,Yd=nO,zN=sO,qd=rO,Ai=iO,hO=aO,fO=lO,Or=oO,mO=cO,pO=uO,gO=dO,xO=Object.defineProperty,al=(e,t)=>xO(e,"name",{value:t,configurable:!0}),fx="Tabs",[vO,rV]=Ns(fx,[Bd]),UN=Bd(),[jO,mx]=vO(fx),yO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,d=Fd(c),[m,p]=Hi({prop:i,onChange:a,defaultProp:l??"",caller:fx});return n.jsx(jO,{scope:r,baseId:vs(),value:m,onValueChange:p,orientation:o,dir:d,activationMode:u,children:n.jsx(bt.div,{dir:d,"data-orientation":o,...h,ref:s})})},"Tabs")),wO="TabsList",bO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=mx(wO,r),o=UN(r);return n.jsx(cN,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(bt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),kO="TabsTrigger",SO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=mx(kO,r),c=UN(r),u=px(o.baseId,i),h=gx(o.baseId,i),d=i===o.value;return n.jsx(uN,{asChild:!0,...c,focusable:!a,active:d,children:n.jsx(bt.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":h,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Ie(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Ie(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Ie(t.onFocus,()=>{const m=o.activationMode!=="manual";!d&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),NO="TabsContent",CO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=mx(NO,r),u=px(c.baseId,i),h=gx(c.baseId,i),d=i===c.value,m=f.useRef(d);return f.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(vr,{present:a||d,children:({present:p})=>n.jsx(bt.div,{"data-state":d?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function px(e,t){return`${e}-trigger-${t}`}al(px,"makeTriggerId");function gx(e,t){return`${e}-content-${t}`}al(gx,"makeContentId");var EO=yO,AO=bO,TO=SO,RO=CO;function We(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(s)}function Fe(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-t)/1e3),i=Math.abs(r),[a,l]=i<60?[r,"second"]:i<3600?[Math.round(r/60),"minute"]:i<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(a,l)}function BN(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((t-s)/1e3));return r<60?"now":r<3600?`${Math.floor(r/60)} min`:r<86400?`${Math.floor(r/3600)} h`:`${Math.floor(r/86400)} d`}function IO(e,t=Date.now()){const s=BN(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function PO(e,t){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function _t(e){return new Intl.NumberFormat("en-US").format(e)}function Gm(e){return[...e.cacheRead?[`cached ${_t(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${_t(e.cacheWrite)}`]:[]].join(", ")}function $O(e){const t=Gm(e);return`${_t(e.input)} in${t?` (${t})`:""} / ${_t(e.output)} out`}function In(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Co(e,t=8){return e.length<=t?e:e.slice(0,t)}function Ks(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function Wa(e){return e.replace(/<<<[^<>]*>>>/g,"")}function zt(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?MO(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${Ly(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?_t(r):Ly(r):String(e)}case"date":return OO(String(e));default:return typeof e=="string"?e:typeof e=="number"?_t(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function MO(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return PO(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function OO(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short",year:"numeric"}).format(s)}function Ym(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short"}).format(s)}function Ly(e){return String(Math.round(e*100)/100)}function qu(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 DO({props:e}){if(e.bars.length===0)return n.jsx("p",{className:"wb-empty",children:"No categories came back."});const t=e.bars.map(a=>a.value),s=Math.max(0,...t),r=Math.min(0,...t),i=s-r||1;return n.jsx("div",{className:"wb-bars",children:e.bars.map(a=>{const l=Math.abs(a.value)/i;return n.jsxs("div",{className:"wb-bar-row",children:[n.jsx("div",{className:"wb-bar-cat",title:a.category,children:a.category}),n.jsx("div",{className:"wb-bar-track",children:n.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:a.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),n.jsx("div",{className:"wb-bar-val",children:zt(a.value,e.unit,e.currency)})]},a.category)})})}const _O=/^(diff --git |index [0-9a-f]|--- (a\/|\/dev\/null)|\+\+\+ (b\/|\/dev\/null)|new file mode|deleted file mode|similarity index|rename (from|to) |old mode|new mode|Binary files )/,LO=/^(… |\.\.\. |\(no change\)$|\)/;function FO(e){return e.replace(/\n$/,"").split(`
|
|
81
|
+
`).map(s=>({kind:zO(s),text:s}))}function zO(e){return e.startsWith("@@")?"hunk":_O.test(e)||LO.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function UO({text:e,marks:t}){const s=e.toLowerCase(),r=[];for(const l of t){const o=l.trim().toLowerCase();if(o!=="")for(let c=s.indexOf(o);c!==-1;c=s.indexOf(o,c+o.length))r.push([c,c+o.length])}if(r.length===0)return n.jsx(n.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const i=[];let a=0;for(const[l,o]of r)l<a||(l>a&&i.push(n.jsx("span",{children:e.slice(a,l)},`t${a}`)),i.push(n.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),a=o);return a<e.length&&i.push(n.jsx("span",{children:e.slice(a)},`t${a}`)),n.jsx(n.Fragment,{children:i})}function Qu({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=FO(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(UO,{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 BO({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:zt(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(Qu,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):n.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const Vt="#/",Gr="#/chat",pt="#/agents",Ct="#/activity",dn="#/settings",Li="#/files",WO="#/welcome";function fu(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function Pc(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`${Li}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function HO(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 Ge(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function KO(e){if(WN(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 Yl(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function WN(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 gt(e,t,s){return`${pt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function VO(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}function Ha(e){return`${Ct}/conversations/${encodeURIComponent(e)}`}const GO="#/p";function ni(e,t,s){const r=`${GO}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function xx(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 YO="p.";function ll(e,t){return`${dn}/${encodeURIComponent(HN(e,t))}`}function qO(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 HN(e,t){return`${YO}${e}${t===e?"":`.${t}`}`}function ze(e){return e?`${dn}/${e}`:dn}function QO(e){return`${ze("accounts")}?account=${encodeURIComponent(e)}`}function JO(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function XO(e){return`${ze("plugins")}?install=${encodeURIComponent(e)}`}const ZO=`${ze("plugins")}?tab=browse`;function eD(e){return`${ze("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function tD(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function KN(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function nD(e){var s,r;const t=(r=(s=KN(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Fy(e){const t=KN(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const sD=[{route:Vt,label:"Home"},{route:Gr,label:"Chat"},{route:pt,label:"Agents"},{route:Ct,label:"Activity"},{route:Li,label:"Files"},{route:dn,label:"Settings"}],rD=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],iD=[{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:"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 aD(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const zy=ze("backup");function lD(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return Ha(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return ni("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return ni("email","mail")}return e==="#/settings/email"?ll("email","settings"):{"#/overview":Vt,"#/approvals":Vt,"#/events":`${Ct}/events`,"#/jobs":`${Ct}/jobs`,"#/conversations":Ct,"#/missions":`${pt}?tab=missions`,"#/offers":`${pt}?tab=offers`,"#/reminders":`${pt}?tab=reminders`,"#/providers":ze("accounts"),"#/browser":ze("computer"),"#/sentinels":ze("watchers"),"#/settings/sentinels":ze("watchers")}[e]??null}function VN(e){if(e===""||e==="#"||e===Vt)return Vt;if(e.startsWith(Gr))return Gr;if(e.startsWith(pt))return pt;if(e.startsWith(Ct))return Ct;if(e.startsWith(Li))return Li;if(e.startsWith(dn))return dn;const t=xx(e);return t?ni(t.plugin,t.page):Vt}const oD="#/chat?group=new";function cD(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 vx="front-desk",jx=[{id:vx,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."}],GN=new Set(jx.map(e=>e.id)),Uy=e=>GN.has(e);function By(e,t){const s=t.filter(r=>!GN.has(r));return[...jx.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function uD(e,t){return e.find(s=>(s.roles??[]).includes(t))}const Wy=["coding","finance","mail","research","calendar","files","memory"],dD={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[vx]:"buddi"},hD=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function fD(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of hD)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let qm=null;function mD(e){qm=e}function Ko(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=dD[s];if(r)return{key:r}}const t=fD(e.tools??[]);return t?{key:t}:qm!==null&&e.id===qm?{key:"buddi"}:{key:Wy[pD(e.id)%Wy.length]??"coding"}}function Vo(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function pD(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const gD=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","live","live.settle","live.snapshot","attention","ping"];function xD(e){const s=e.replace(/\r\n/g,`
|
|
82
|
+
`).split(`
|
|
83
|
+
|
|
84
|
+
`),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
|
|
85
|
+
`)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),d=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");d==="id"?l=m:d==="event"?o=m:d==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:gD.includes(o)?o:"ping",data:vD(c.join(`
|
|
86
|
+
`))})}return{events:i,rest:r}}function vD(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function Qd(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,h,d,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const 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&&((d=e.onReconnect)==null||d.call(e));const y=g.body.getReader(),b=new TextDecoder;let x="";for(;;){const{done:v,value:j}=await y.read();if(v)break;x+=b.decode(j,{stream:!0});const{events:w,rest:S}=xD(x);x=S;for(const k of w)e.onEvent(k),k.id!==null&&(i=k.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const yx="0.1.0+88a5fa2";function wx(e,t=yx){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function jD(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const yD=5*6e4,wD=6e4,bD=5e3,Qm="buddi:stream-reconnected",YN="buddi.autoReloadedFor";function kD(){window.dispatchEvent(new Event(Qm))}const Hy=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let bx=Date.now(),$c=0;const Ky=()=>{bx=Date.now()};function SD(){if($c===0){bx=Date.now();for(const e of Hy)window.addEventListener(e,Ky,{capture:!0,passive:!0})}return $c+=1,()=>{if($c-=1,$c===0)for(const e of Hy)window.removeEventListener(e,Ky,{capture:!0})}}function ND(e=Date.now()){return e-bx}function CD(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 ED(e){return e.hidden?!0:e.idleMs>=wD&&!e.busy}function AD(e){try{return window.sessionStorage.getItem(YN)===e}catch{return!1}}function TD(e){try{window.sessionStorage.setItem(YN,e)}catch{}}function RD(e){const t=f.useRef(e);t.current=e,f.useEffect(()=>{const s=()=>t.current();return window.addEventListener(Qm,s),()=>window.removeEventListener(Qm,s)},[])}function ID(e,t=()=>window.location.reload(),s=yx){const r=wx(e,s),i=f.useRef(t);i.current=t,f.useEffect(()=>SD(),[]),f.useEffect(()=>{if(!r||e===void 0||AD(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";ED({hidden:c,idleMs:ND(),busy:CD()})&&(a=!0,TD(e),i.current())};l();const o=window.setInterval(l,bD);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const PD="/api/chat/attention/stream";function qN(e,t){const s=(a,l)=>a.name.localeCompare(l.name),r=a=>e.filter(l=>l.anchor===a).sort(s),i=e.filter(a=>a.anchor!=="top"&&a.anchor!=="bottom").sort((a,l)=>a.id===t?l.id===t?0:-1:l.id===t?1:s(a,l));return{top:r("top"),middle:i,bottom:r("bottom")}}function QN(e,t){const s=qN(e,t);return[...s.top,...s.middle,...s.bottom]}function Jd(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 $D(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 MD(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function OD(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function DD(){const[e,t]=f.useState(null);return f.useEffect(()=>{let s=!1;const r=()=>{he("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=Qd({url:PD,onEvent:()=>r(),onReconnect:kD});return()=>{s=!0,i.close()}},[]),OD(e)}const Xd="maker";function JN(e){return e.filter(t=>t.available&&!t.roles.includes(Xd))}function XN(e){return JN(e).length>=2}function _D(e){var t;return((t=e.find(s=>s.roles.includes(Xd)))==null?void 0:t.name)??"the agent maker"}const LD="{{default}}";function FD(e,t){return e.split(LD).join(t??"your assistant")}function zD(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>FD(s,t))}function UD(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 BD(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 ZN(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 WD="Settings → Model accounts",HD="Install it in Settings → Plugins";function Jm(e){return e!=null&&e.heldBack?{section:"plugins",label:HD}:{section:"accounts",label:WD}}const KD={home:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),n.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),n.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),n.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),n.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),n.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,n.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),n.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),n.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),n.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),n.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),n.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,n.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),n.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),n.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),n.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),n.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],terminal:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),n.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),n.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],sun:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),n.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),n.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),n.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),n.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],eye:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),n.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),n.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),n.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),n.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,n.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,n.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,n.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,n.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],dot:[20,1.6,n.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),n.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,n.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),n.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),n.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,n.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,n.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,n.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],thought:[13,1.4,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),n.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,n.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),n.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,n.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,n.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,n.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,n.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),n.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,n.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,n.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,n.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],more:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,n.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,n.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),n.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),n.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,n.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,n.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,n.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,n.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,n.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,n.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,n.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,n.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],"shape-structured":[16,1.4,n.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function ye({name:e,size:t,className:s,...r}){const[i,a,l,o]=KD[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 e1="buddi.rosterCollapsed";function VD(){try{return window.localStorage.getItem(e1)==="1"}catch{return!1}}function GD(e){try{window.localStorage.setItem(e1,e?"1":"0")}catch{}}function t1({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const d=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=f.useState(VD),y=b=>n.jsx(YD,{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(y),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(y),u&&XN(d)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:n.jsx(ye,{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(x=>{const v=d.find(j=>j.id===x);return n.jsx(kx,{className:"wb-group-chip",id:x,name:(v==null?void 0:v.name)??"?",face:v,initials:1},x)})}),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(x=>{var v;return((v=d.find(j=>j.id===x))==null?void 0:v.name)??x}).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:pt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(y),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=>(GD(!b),!b)),children:n.jsx(ye,{name:p?"chevron-right":"chevron-left"})}):null]})}function YD({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=Jd(s),c=$D(s)??(e.available?a?IO(a):e.description:e.unavailableReason??"Cannot run right now"),u=MD(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",d=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Vo(Ko(e)),"data-active":t?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":d,"aria-current":t?"true":void 0,disabled:!e.available,onClick:()=>e.available&&i(e.id),children:[n.jsxs("span",{className:"wb-face-frame",children:[n.jsx(kx,{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(ye,{name:"out"})})]})}),n.jsx(bo,{children:n.jsxs(ko,{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:qD(o)}):null]})})]})}function qD(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function QD(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const JD="modulepreload",XD=function(e,t){return new URL(e,t).href},Vy={},ZD=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=XD(u,r),u in Vy)return;Vy[u]=!0;const h=u.endsWith(".css"),d=h?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const y=l[g];if(y.href===u&&(!h||y.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${d}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":JD,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((g,y)=>{p.addEventListener("load",g),p.addEventListener("error",()=>y(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)})},e_="buddi",t_=["core","coding","finance","garage","mail","maker","playground","research"],qi=e=>`./mascot/${e}.png`,n_=["core"],Xm=(e,t)=>n_.includes(e)?`./mascot/anim/${e}-${t}.json`:null,s_=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],r_="Introduce yourself by name and say one thing you can do today.",i_=["Hello","A brain","What I take on","Reach me","Your assistant"],El=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Xh=e=>e.charAt(0).toUpperCase()+e.slice(1),a_=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Ia=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars. A morning brief from Planner.",mate:"Planner",note:"Weather needs nothing. Calendar asks for your calendar’s private link later, on its own page."},{id:"mail",title:"My mail",plugins:"Mail Triage (built in)",line:"Mail Triage reads new mail and brings you only what needs you.",mate:"Mail Triage",note:"Mail asks for a mailbox in chapter 4."},{id:"money",title:"My money",plugins:"Finance",line:"Accounts, cards and cash flow. Ledger answers “can I afford this?”.",mate:"Ledger",note:"Finance asks for your bank on its own page."},{id:"voice",title:"Voice",plugins:"Speech",line:"Talk to me and hear me back, here and on your phone. Runs on this computer.",note:"Speech needs nothing."},{id:"code",title:"My code",plugins:"Developer",line:"Developer works in one folder you name, and shows you what it changed.",mate:"Developer",note:"Developer asks for its folder the first time you talk."},{id:"pictures",title:"Pictures",plugins:"Image",line:"Illustrator makes one image from a prompt, with an account you pick.",mate:"Illustrator",note:"Image asks which account to draw with."}],l_=["days","mail"],Gy=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],P={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:i_,mapNotes:["Two minutes. Everything can be changed later in Settings, and nothing leaves this computer until you say so.","One line decides which company sees your assistant’s conversations. You can add more brains later and give each agent its own.","Each choice installs a plugin from withbuddi.com and proposes an agent for it. Only plugins made by buddi are installed for you; you can remove any of them later.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,t)=>`${e} · ${t}`,hello:{title:"Hi. I’m buddi.",opening:["I live on this computer and I’m about to introduce you to your first assistant. Nothing you tell me leaves this machine, except what your assistant sends to the AI you pick next.","First, what should we call you, and what time is it where you are?"],foot:"Your agents use your name in every reply, and your clock for reminders and the morning brief.",submit:"That’s me",answer:e=>e},name:{label:"Your first name",placeholder:"Sam"},clock:{label:"Your clock",hint:e=>`What this browser says. ${e} right now.`,change:"Change"},brain:{title:"Which AI should your team think with?",ask:"Pick what you already have. I test it with one small call before we go on.",submit:"Use this brain",cards:{free:{title:"Free to start, no key",line:"Ollama Cloud, one tap. Good enough to meet your assistant today.",pill:"Recommended to begin"},claude:{title:"I pay for Claude",line:"Sign in with your Claude account. Uses its extra usage."},chatgpt:{title:"I pay for ChatGPT",line:"Sign in with a code on openai.com. Uses your plan."},key:{title:"I have an API key",line:"Anthropic, OpenAI, Google AI, or another service with an address."},local:{title:"On this computer",line:"Free and private. Looking on this computer…"}},keyKinds:{label:"Which key",key:"Anthropic or OpenAI",gemini:"Google AI",service:"Another service"},claude:{label:"Claude",start:"Sign in with Claude",open:"Open the Claude sign-in page",paste:"Paste what Claude gave you",finish:"Done",waiting:"Sign in on the claude.ai page that just opened, then paste the code Claude shows you."},chatgpt:{label:"ChatGPT",codeBefore:"Here is your code: ",codeAfter:". Type it on the openai.com page that just opened and approve buddi. I’ll notice.",code:"Your code",open:"Open openai.com",again:"Try again",failed:"The sign-in did not finish. Try again."},cloud:{label:"Ollama Cloud",waiting:"Press Connect on the ollama.com page that just opened. Sign in there first if it asks. I’ll notice.",open:"Open the ollama.com page",again:"Try again"},gemini:{label:"Gemini",field:"Your Google AI key",placeholder:"Paste it here",submit:"Use this key",get:"Get a key at aistudio.google.com"},key:{field:"Your key",placeholder:"Paste it here",hint:"I can tell which AI it belongs to from the key. It stays on this computer.",submit:"Use this key",which:"Not right?",anthropic:"Anthropic",openai:"OpenAI",refused:"That key was refused. Check it and paste it again."},local:{looking:"Free and private. Looking on this computer…",found:e=>{const t=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${t(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${t(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Nothing local answered; Ollama or mlxh, once installed, shows here."},mlxh:{label:"mlxh",connect:"Use mlxh",noBrain:"mlxh has no language model installed. Pull one with `mlxh pull`, then come back."},ollama:{label:"Ollama",connect:"Use Ollama",download:"Get Ollama"},model:{ask:"Which one should it think with?",label:"The model",submit:"Use this one",retry:"Try again",change:"Think with another"},checking:{key:"Checking that key…",service:"Asking the service…",ollama:"Asking the first model one small question. It can take a minute.",cloud:"Asking Ollama Cloud…",claude:"Checking with Claude…",chatgpt:"Asking ChatGPT…",gemini:"Asking Gemini…"},service:{label:"Another service",address:"Address",addressPlaceholder:"The address they gave you",key:"Key",submit:"Connect it"},works:e=>`That works. Your assistant will think with ${e}.`,worksOnFlash:e=>`That works. Google's free tier has no Pro allowance, so your assistant will think with ${e}; turn on billing at Google to use Pro.`,answer:e=>e},takeOn:{title:"What should I take on for you?",ask:"Pick a few. Each one brings a plugin and, for some, a teammate who owns that job. Skip this and I stay a plain assistant; you can add any of it later.",submit:"Take these on",none:"Just an assistant for now",nothing:"Nothing picked. I’ll be a plain assistant, and Home will offer these again.",builtIn:"Mail is built in.",nothingToFetch:"Nothing to fetch.",fetching:(e,t,s)=>`Fetching ${El(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${El(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":Xh(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":Xh(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: ${El(e)}, waiting to be introduced.`,name:"Name",face:"A face",colour:"A colour for the face",swatch:e=>`Colour: ${e.toLowerCase()}`,mascot:e=>e==="core"?"Buddi Blob":`Buddi Blob, ${e}`,purpose:"How it works",purposeHint:"Plain text. It becomes the assistant’s file, which is yours from then on.",purposeValue:["You're not a chatbot. You're becoming someone this person can count on.","","Some starting truths:","",`- Help for real. No "Great question", no "I'd be happy to". Do the thing, then say what you did.`,"- Have a view. Prefer things, disagree when you should, say when something is a bad idea. A search engine with manners is not a colleague.","- Look before you ask. Read the file, check what you remember, try it. Come back with an answer and one question at most.","- You are a guest here. You can see messages, files and a calendar. Treat that with care, keep what you learn to yourself, and never lecture.","- Remember what matters. Names, preferences, the things they said once and expect you to keep.","- When you change how you work, say so. This file is yours to grow, and the owner should always know what it says."].join(`
|
|
87
|
+
`),submit:"Introduce us"},restore:{offer:"I have a backup",sheet:"Restore from a backup",lede:"Pick the backup file buddi made and type its passphrase. Your agents, memory and settings come back as they were; this chapter map is skipped.",file:"Backup file",passphrase:"Passphrase",passphraseHint:"The one you typed when you turned backups on, if it was locked with one. I can’t recover it.",submit:"Restore",cancel:"Never mind",title:"Bringing your buddi back.",started:"Right. Give me a couple of minutes.",phases:{stopping:"Putting everything down for a moment.",snapshot:"Keeping a copy of what is here now, just in case.",database:"Bringing back your conversations and everything you told it to remember.",recovery:"Almost there. Nothing will run on its own until you say so.",files:"Bringing back your files.",starting:"Starting back up.",done:"That is everything.","rolled-back":"That did not work, so I put everything back the way it was.",failed:"That did not work."},welcome:e=>`Welcome back, ${e}.`,keys:"A backup never carries keys, so the AI you think with needs its key one more time."},handover:{waiting:"One moment.",looking:e=>`${e} is looking around…`,slow:"Still waking up. A brain on this computer takes a minute the first time.",silent:"Your assistant isn't answering. The AI you picked may be down; try again, or pick another brain.",again:"Pick another brain",starters:(e,t)=>[e.days?"What’s my day like?":"What can you do?",t.length>0?`Meet ${El(t)}`:"Show me around",e.days?"Link my calendar":e.mail&&!e.mailbox?"Add my mailbox":"What do you know about me?","Remind me at 9 tomorrow"],starterLabel:"Ask first",waitingTitle:e=>`${a_[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Xh(El(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 Mc=null;const Yy=new Map;function o_(){return Mc??(Mc=ZD(()=>import("./lottie_light-7wQnGwdw.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Mc.catch(()=>{Mc=null}),Mc}function c_(e){let t=Yy.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),Yy.set(e,t)),t}const qy="(prefers-reduced-motion: reduce)";function n1(){const[e,t]=f.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(qy).matches);return f.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(qy),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 Zd({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=f.useRef(null),o=n1(),[c,u]=f.useState(!1),h=s==="xs"?null:Xm(e,t);return f.useEffect(()=>{if(u(!1),!o||!h)return;let d=!1,m=null;return Promise.all([o_(),c_(h)]).then(([p,g])=>{if(d||!g||!l.current)return;const y=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?y.pause():y.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),y.destroy()},u(!0)}).catch(()=>{}),()=>{d=!0,m==null||m()}},[o,h]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??qi(e),alt:"",onError:a})})}async function Qy(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 s1(e,t="core"){const s=n1(),r=e!==null&&u_(e,t),[i,a]=f.useState(!1);return f.useEffect(()=>{if(a(!1),!e||r||!s||!Xm(t,"idle"))return;let l=!1;return Promise.all([Qy(e),Qy(qi(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,d,m)=>h+Math.abs(d-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&Xm(t,"idle")!==null&&(r||i)}function u_(e,t){const s=qi(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 kx({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=f.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,d=r==null?void 0:r.avatar,m=h?"image":d==null?void 0:d.kind,p=t?Vo(Ko({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?n.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(d==null?void 0:d.kind)==="image"?n.jsx("img",{src:d.url,alt:""}):(d==null?void 0:d.kind)==="emoji"?d.value:BD(s).slice(0,o)})}function Es({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(kx,{className:"ui-avatar",id:e,tint:QD(e),name:t,size:s,unavailable:r,face:i})}function Nn({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Es,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const r1=f.createContext(null);function d_({picture:e,children:t}){return n.jsx(r1.Provider,{value:e??null,children:t})}function i1({size:e,anim:t}){const s=f.useContext(r1),[r,i]=f.useState(null),a=s1(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(Zd,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const a1=f.createContext([]);function pr({text:e,className:t}){const s=Zm(e.replace(/\r\n/g,`
|
|
88
|
+
`).split(`
|
|
89
|
+
`));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(ep,{block:r},i))})}const Jy=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Xy=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Zy=/^\s*([-*_])(\s*\1){2,}\s*$/,Oc=/^(\s*)([-*+])\s+(.*)$/,Al=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Dc=/^\s*>\s?(.*)$/,Zh=/^\s*\|.*\|\s*$/,ew=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Zm(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Jy.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=Xy.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Zy.test(r)){t.push({type:"hr"}),s+=1;continue}if(Dc.test(r)){const o=[];for(;s<e.length&&Dc.test(e[s]);)o.push(Dc.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:Zm(o),raw:o.join(`
|
|
91
|
+
`)});continue}if(Zh.test(r)&&s+1<e.length&&ew.test(e[s+1])){const o=tf(r),c=tf(e[s+1]).map(h=>{const d=h.startsWith(":"),m=h.endsWith(":");return d&&m?"center":m?"right":d?"left":null});s+=2;const u=[];for(;s<e.length&&Zh.test(e[s]);)u.push(tf(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(Oc.test(r)||Al.test(r)){const o=Al.exec(r)??Oc.exec(r),c=Al.test(r),u=o[1].length,h=c?Number(o[2]):1,d=[];for(;s<e.length;){const m=c?Al.exec(e[s]):Oc.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],y=g.trim()!==""&&ef(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&ef(e[s+1])>u;if(!y&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(ef(g),u+2))),s+=1}d.push(Zm(p))}t.push({type:"list",ordered:c,start:h,items:d});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||Jy.test(o)||Xy.test(o)||Zy.test(o)||Dc.test(o)||Oc.test(o)||Al.test(o)||Zh.test(o)&&s+1<e.length&&ew.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 ef(e){return e.length-e.trimStart().length}function tf(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let i=0;i<t.length;i+=1){const a=t[i];if(a==="\\"&&t[i+1]==="|"){r+="|",i+=1;continue}if(a==="|"){s.push(r.trim()),r="";continue}r+=a}return s.push(r.trim()),s}function ep({block:e}){switch(e.type){case"p":return n.jsx("p",{children:ps(e.text)});case"h":{const t=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(t+2,6)}`;return n.jsx(s,{className:"wb-md-h","data-level":t,children:ps(e.text)})}case"code":return n.jsxs("div",{className:"wb-md-code-frame",children:[n.jsxs("div",{className:"wb-md-code-head",children:[n.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),n.jsx(tw,{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(ep,{block:t},s))}),n.jsx(tw,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(f.Fragment,{children:ps(i.text)},a):n.jsx(ep,{block:i},a))},r));return e.ordered?n.jsx("ol",{start:e.start,children:t}):n.jsx("ul",{children:t})}case"table":return n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table wb-md-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.head.map((t,s)=>n.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:ps(t)},s))})}),n.jsx("tbody",{children:e.rows.map((t,s)=>n.jsx("tr",{children:t.map((r,i)=>n.jsx("td",{style:e.align[i]?{textAlign:e.align[i]}:void 0,children:ps(r)},i))},s))})]})})}}function tw({text:e,what:t,always:s=!1}){const[r,i]=f.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function h_({handle:e}){const s=f.useContext(a1).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:Ge(s.id),children:["@",s.handle]})}),n.jsx(bo,{children:n.jsxs(ko,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Es,{id:s.id,name:s.name,face:s,unavailable:!s.available}),n.jsxs("span",{className:"wb-agent-card-text",children:[n.jsx("span",{className:"wb-agent-card-name",children:s.name}),n.jsx("span",{className:"wb-agent-card-desc",children:s.description}),n.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):n.jsxs(n.Fragment,{children:["@",e]})}const f_=new RegExp("(`+)([\\s\\S]*?[^`])\\1(?!`)|\\*\\*([^*]+?)\\*\\*|__([^_]+?)__|~~([^~]+?)~~|(?<![\\w*])\\*([^*\\n]+?)\\*(?![\\w*])|(?<![\\w_])_([^_\\n]+?)_(?![\\w_])|\\[([^\\]\\n]+)\\]\\((https?:\\/\\/[^\\s)]+)\\)|<?(https?:\\/\\/[^\\s<>)\\]]+[^\\s<>)\\].,;:!?'\"])>?|(?<![\\w@/])@([a-z0-9][a-z0-9_-]{0,63})(?![\\w-])","i");function ps(e){const t=[];let s=e,r=0;for(;s!=="";){const i=f_.exec(s);if(!i){t.push(...nw(s,r));break}i.index>0&&t.push(...nw(s.slice(0,i.index),r)),r+=100,i[2]!==void 0?t.push(n.jsx("code",{children:i[2]},r)):i[3]!==void 0?t.push(n.jsx("strong",{children:ps(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:ps(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:ps(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:ps(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:ps(i[7])},r)):i[8]!==void 0&&i[9]!==void 0?t.push(n.jsx("a",{href:i[9],target:"_blank",rel:"noopener noreferrer",children:ps(i[8])},r)):i[10]!==void 0?t.push(n.jsx("a",{href:i[10],target:"_blank",rel:"noopener noreferrer",children:i[10]},r)):i[11]!==void 0&&t.push(n.jsx(h_,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function nw(e,t){return e.split(`
|
|
93
|
+
`).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function m_({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(pr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const p_=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear"];function xe(e,t){if(t===""||t==="$")return e;let s=e;for(const r of t.split(".")){const i=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!i)return;const[,a="",l=""]=i;if(a!==""){if(s===null||typeof s!="object")return;s=s[a]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function Oe(e,t){if(t)return"const"in t?t.const:xe(e,t.path)}function Bn(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null}function Xe(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Yr(e){return Array.isArray(e)?e:[]}function g_(e,t){const s=Yr(xe(e,t.points)).map(i=>{const a=Bn(xe(i,t.y)),l=Xe(xe(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=Bn(Oe(e,i.value));return a===null?null:{value:a,label:i.label,tone:i.tone??"neutral"}}).filter(i=>i!==null);return{points:s,unit:t.unit??"number",currency:Xe(Oe(e,t.currency)),label:Xe(Oe(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:Bn(Oe(e,t.shadeBelow)),events:x_(e,t)}}function x_(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=Xe(xe(a,s.label));if(o===null)return;const c=Xe(xe(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Bn(xe(a,s.amount)):null})};if(s.parent){for(const a of Yr(xe(e,t.points))){const l=Xe(xe(a,t.x));for(const o of Yr(xe(a,s.parent)))i(o,l)}return r}for(const a of Yr(xe(e,s.path??t.points)))i(a,null);return r}function v_(e,t){const s=(t.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(t.columns??[]).map(c=>{const u=xe(o,c.key);let h=null;if(c.bar){const d=Bn(Oe(o,c.bar.max))??Bn(Oe(e,c.bar.max)),m=Bn(u);if(d!==null&&d>0&&m!==null){const p=Math.max(0,Math.min(1,m/d));h={fraction:p,tone:y_(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:Xe(Oe(o,c.currency))??Xe(Oe(e,c.currency)),bar:h}}),i=Yr(xe(e,t.rows)),a=t.groupBy?j_(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:Oe(e,o.value),unit:o.unit??"text",currency:Xe(Oe(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function j_(e,t,s){const r=new Map;for(const i of e){const a=String(xe(i,t.key)??""),l=r.get(a);l?l.push(i):r.set(a,[i])}return[...r.entries()].map(([i,a])=>{var l;return{label:((l=t.labels)==null?void 0:l[i])??i,rows:a.map(s)}})}function y_(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 w_(e,t){return{bars:Yr(xe(e,t.bars)).map(r=>{const i=Bn(xe(r,t.value)),a=Xe(xe(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:Xe(Oe(e,t.currency))}}function b_(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text",currency:Xe(Oe(e,r.currency)),tone:r.tone??"neutral"}))};const s=xe(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:hn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const k_=new Set(["good","warning","critical","neutral","accent"]),S_=new Set(p_);function tp(e){return typeof e=="string"&&S_.has(e)?e:null}function Sx(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=Xe(xe(e,t.notice.text));if(l!==null&&l.trim()!==""){const o=t.notice.link&&i!==""?{plugin:i,page:t.notice.link.page}:null;return{tiles:[{icon:tp(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Yr(xe(e,t.items)).map(l=>{const o=Xe(xe(l,t.value))??"",c=Xe(xe(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?Xe(xe(l,t.tone)):null;return{icon:tp(Oe(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>Xe(xe(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&k_.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function N_(e,t){const s=Xe(Oe(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?Xe(xe(e,t.src)):null;return{kind:r,text:t.text?Xe(xe(e,t.text)):null,src:i&&o1(i)?i:null,title:Xe(Oe(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Oe(e,a.value),unit:a.unit??"text"}))}}function C_(e,t){const s=t.diff?xe(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:Xe(Oe(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text"}))}}function E_(e,t){const s=t.output?xe(e,t.output):void 0,r=l=>{const o=l?xe(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?xe(e,t.elapsedMs):void 0;return{command:Xe(Oe(e,t.command)),output:typeof s=="string"?s:null,exitCode:r(t.exitCode),elapsedMs:typeof a=="number"&&Number.isFinite(a)&&a>=0?a:null,omittedBytes:i!==null&&i>0?i:null,metadata:(t.metadata??[]).map(l=>({label:l.label,value:Oe(e,l.value),unit:l.unit??"text"}))}}const A_=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function l1(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&A_.test(t)?t.toLowerCase():null}function T_(e,t){return{artifactId:t.src?l1(xe(e,t.src)):null,title:Xe(Oe(e,t.title)),caption:Xe(Oe(e,t.caption)),...t.captionLabel?{captionLabel:Xe(Oe(e,t.captionLabel))}:{}}}function sw(e){if(!o1(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 R_(e,t){const s=t.src?Xe(xe(e,t.src)):null,r=t.port?xe(e,t.port):null,i=t.awaiting?Xe(xe(e,t.awaiting)):null;return{target:s?sw(s):null,title:Xe(Oe(e,t.title)),output:t.output?Xe(xe(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?sw(i):null,reloadsItself:t.reloadsItself?xe(e,t.reloadsItself)===!0:!1,ports:t.ports?I_(xe(e,t.ports)):[]}}function I_(e){const t=Yr(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function o1(e){return e.startsWith("/")&&!e.startsWith("//")}function hn(e){const t=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function c1(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:g_(t,s)};case"table":return{renderer:"table",props:v_(t,s)};case"bars":return{renderer:"bars",props:w_(t,s)};case"keyvalue":return{renderer:"keyvalue",props:b_(t,s)};case"tiles":return{renderer:"tiles",props:Sx(t,s,e.tool)};case"document":return{renderer:"document",props:N_(t,s)};case"diff":return{renderer:"diff",props:C_(t,s)};case"terminal":return{renderer:"terminal",props:E_(t,s)};case"image":return{renderer:"image",props:T_(t,s)};case"preview":return{renderer:"preview",props:R_(t,s)};default:return{renderer:"structured",props:{value:t}}}}var P_=Object.defineProperty,As=(e,t)=>P_(e,"name",{value:t,configurable:!0}),Nx="Dialog",[u1,iV]=Ns(Nx),[$_,yr]=u1(Nx),Cx=As(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=f.useRef(null),c=f.useRef(null),[u,h]=Hi({prop:r,defaultProp:i??!1,onChange:a,caller:Nx}),[d,m]=f.useState(0),[p,g]=f.useState(0);return n.jsx($_,{scope:t,triggerRef:o,contentRef:c,contentId:vs(),titleId:vs(),descriptionId:vs(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:h,onOpenToggle:f.useCallback(()=>h(y=>!y),[h]),modal:l,children:s})},"Dialog"),d1="DialogPortal",[M_,h1]=u1(d1,{forceMount:void 0}),Ex=As(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=yr(d1,t);return n.jsx(M_,{scope:t,forceMount:s,children:f.Children.map(r,l=>n.jsx(vr,{present:s||a.open,children:n.jsx(Vg,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),np="DialogOverlay",f1=f.forwardRef(As(function(t,s){const r=h1(np,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=yr(np,t.__scopeDialog);return l.modal?n.jsx(vr,{present:i||l.open,children:n.jsx(D_,{...a,ref:s})}):null},"DialogOverlay")),O_=Zr("DialogOverlay.RemoveScroll"),D_=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=yr(np,r),l=Zk(),o=ut(s,l);return n.jsx(ox,{as:O_,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(bt.div,{"data-state":Rx(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),Eo="DialogContent",Ax=f.forwardRef(As(function(t,s){const r=h1(Eo,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=yr(Eo,t.__scopeDialog);return n.jsx(vr,{present:i||l.open,children:l.modal?n.jsx(__,{...a,ref:s}):n.jsx(L_,{...a,ref:s})})},"DialogContent")),__=f.forwardRef(As(function(t,s){const r=yr(Eo,t.__scopeDialog),i=f.useRef(null),a=ut(s,r.contentRef,i);return f.useEffect(()=>{const l=i.current;if(l)return hN(l)},[]),n.jsx(m1,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Ie(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ie(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Ie(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),L_=f.forwardRef(As(function(t,s){const r=yr(Eo,t.__scopeDialog),i=f.useRef(!1),a=f.useRef(!1);return n.jsx(m1,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=t.onCloseAutoFocus)==null||o.call(t,l),l.defaultPrevented||(i.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:l=>{var u,h;(u=t.onInteractOutside)==null||u.call(t,l),l.defaultPrevented||(i.current=!0,l.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),m1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=yr(Eo,r);return zd(),n.jsx(n.Fragment,{children:n.jsx(YS,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(Hg,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Rx(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),F_="DialogTitle",Tx=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=yr(F_,r),{setTitleCount:l}=a;return Tn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(bt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),z_="DialogClose",p1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=yr(z_,r);return n.jsx(bt.button,{type:"button",...i,ref:s,onClick:Ie(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function Rx(e){return e?"open":"closed"}As(Rx,"getState");const U_=5;function ae(e,t,s){const[r,i]=f.useState(void 0),[a,l]=f.useState(null),[o,c]=f.useState(!0),[u,h]=f.useState(0),[d,m]=f.useState(0),p=f.useRef(e);return p.current=e,f.useEffect(()=>{let g=!1;return c(!0),p.current().then(y=>{g||(i(y),l(null),m(0))}).catch(y=>{g||(l(y instanceof pe?y.message:String(y)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),f.useEffect(()=>{if(!s||d>=U_)return;const g=window.setTimeout(()=>h(y=>y+1),s*2**d);return()=>window.clearTimeout(g)},[s,d,u]),{data:r,error:a,loading:o,reload:()=>{m(0),h(g=>g+1)}}}const g1={width:480,height:160,top:10,right:10,bottom:22,left:40},x1={width:1200,height:180,top:10,right:40,bottom:22,left:40};function B_({xs:e,series:t}){const s=x1,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=L=>L.filter(E=>E!==null&&Number.isFinite(E)),l=t.filter(L=>L.type!=="bar"),o=t.filter(L=>L.type==="bar"),c=l.flatMap(L=>a(L.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let d=u,m=h;if(d===m)d-=1,m+=1;else{const L=(m-d)*.08;d-=L,m+=L}const p=L=>ss(s.top+i-(L-d)/(m-d)*i),g=o.length>0&&o.every(L=>L.unit==="percent"),y=g?100:Math.max(1,...o.flatMap(L=>a(L.values))),b=L=>ss(s.top+i-Math.max(0,L)/y*i),x=e.length,v=x>0?r/x:r,j=L=>ss(s.left+v*(L+.5)),w=t.map(L=>{if(L.type==="bar")return"";let E="M";const $=[];return L.values.forEach((_,B)=>{if(_===null||!Number.isFinite(_)){E="M";return}$.push(`${E}${j(B)},${p(_)}`),E="L"}),$.join(" ")}),S=[],k=v*.6/Math.max(1,o.length),N=s.height-s.bottom;let C=0;t.forEach((L,E)=>{if(L.type!=="bar")return;const $=C++;L.values.forEach((_,B)=>{if(_===null||!Number.isFinite(_)||_<=0)return;const M=b(_);S.push({series:E,index:B,x:ss(j(B)-v*.3+k*$),y:M,width:ss(k),height:ss(N-M)})})});const I=c.length>0?qu(u,h,2).map(L=>({value:L,y:p(L)})):[],A=o.length===0?[]:(g?[0,50,100]:qu(0,y,2)).map(L=>({value:L,y:b(L),percent:g})),O=Math.max(1,Math.ceil(x/8)),z=e.flatMap((L,E)=>E%O===0?[{index:E,x:j(E)}]:[]);return{lines:w,bars:S,targetY:null,ticks:I,xLabels:z,rightTicks:A}}function W_({xs:e,series:t,type:s="line",target:r=null}){const i=g1,a=i.width-i.left-i.right,l=i.height-i.top-i.bottom,o=t.flatMap(j=>j.values.filter(w=>w!==null&&Number.isFinite(w)));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 j=(u-c)*.08;c-=j,u+=j}const h=j=>ss(i.top+l-(j-c)/(u-c)*l),d=e.length,m=d>0?a/d:a,p=j=>ss(s==="bar"?i.left+m*(j+.5):i.left+(d<=1?a/2:j/(d-1)*a)),g=s==="line"?t.map(j=>{let w="M";const S=[];return j.values.forEach((k,N)=>{if(k===null||!Number.isFinite(k)){w="M";return}S.push(`${w}${p(N)},${h(k)}`),w="L"}),S.join(" ")}):[],y=[];if(s==="bar"&&d>0){const j=m*.7,w=j/Math.max(1,t.length),S=h(0);t.forEach((k,N)=>{k.values.forEach((C,I)=>{if(C===null||!Number.isFinite(C))return;const A=h(C);y.push({series:N,index:I,x:ss(i.left+m*I+(m-j)/2+w*N),y:Math.min(A,S),width:ss(w),height:ss(Math.abs(S-A))})})})}const x=(o.length>0?qu(Math.min(...o),Math.max(...o),2):[]).map(j=>({value:j,y:h(j)})),v=d===0?[]:d===1?[0]:d<5?[0,d-1]:[0,Math.floor((d-1)/2),d-1];return{lines:g,bars:y,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:x,xLabels:v.map(j=>({index:j,x:p(j)}))}}function H_(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 K_({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?x1:g1,u=o?B_({xs:e,series:t}):W_({xs:e,series:t,type:s,target:r}),h=H_({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(d=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:d.y,y2:d.y}),n.jsx("text",{x:c.left-6,y:d.y,textAnchor:"end",dominantBaseline:"middle",children:l(d.value)})]},d.value)),(u.rightTicks??[]).map(d=>n.jsx("text",{x:c.width-c.right+6,y:d.y,textAnchor:"start",dominantBaseline:"middle",children:d.percent?`${d.value}%`:l(d.value)},`r-${d.value}`)),n.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(d=>n.jsx("rect",{className:"ui-chart-bar","data-series":d.series,x:d.x,y:d.y,width:d.width,height:d.height},`${d.series}-${d.index}`)),u.lines.map((d,m)=>d?n.jsx("path",{className:"ui-chart-line","data-series":m,d},m):null),u.targetY!==null?n.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(d=>n.jsx("text",{x:d.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&d.index===0?"start":d.index===e.length-1&&e.length>1?"end":"middle",children:a(e[d.index])},d.index))]}),n.jsx("figcaption",{className:"sr-only",children:h}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((d,m)=>n.jsx("li",{"data-series":m,"data-type":o?d.type??"line":void 0,children:d.label},d.label))}):null]})}function ss(e){return Math.round(e*10)/10}function di(...e){return e.filter(Boolean).join(" ")}function R({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:di("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Ut({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:di("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function J({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:di("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function en(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function ee({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=f.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function bs({children:e,dense:t,columns:s}){return n.jsx("div",{className:"ui-formgrid","data-dense":t?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function ge({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:di("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 Pa({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Go({state:e}){const t=e==="succeeded"||e==="approved"||e==="fired"||e==="running"||e==="leased"?"good":e==="failed"||e==="rejected"||e==="unknown"||e==="error"||e==="refused"?"critical":e==="pending"||e==="suspended"||e==="expired"||e==="paused"?"warning":void 0;return n.jsx(ge,{tone:t,children:e})}function H({tone:e,title:t,children:s,role:r,action:i}){return i?n.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:n.jsxs("div",{className:"ui-notice-row",children:[n.jsxs("div",{className:"ui-notice-body",children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]}),i]})}):n.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]})}function se({message:e}){return e?n.jsx(H,{tone:"critical",role:"alert",children:e}):null}function oe({mascot:e,warm:t,title:s,action:r,children:i}){return t||s?n.jsxs("div",{className:"ui-empty","data-warm":t?"true":void 0,children:[s?n.jsx("div",{className:"ui-empty-title",children:s}):null,n.jsx("div",{children:i}),r]}):e?n.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[n.jsx(i1,{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(ye,{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 V_({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function eh({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 wn({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(V_,{children:[n.jsx(eh,{title:t,lede:s,actions:r}),i]})}function te({title:e,aside:t,actions:s,panel:r,flush:i,foot:a,children:l}){const o=e||t||s?n.jsxs("div",{className:"ui-section-head",children:[e?n.jsx("h3",{className:"ui-section-title",children:e}):n.jsx("span",{}),t||s?n.jsxs("div",{className:"ui-section-side",children:[t?n.jsx("span",{className:"ui-section-aside",children:t}):null,s?n.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return n.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?n.jsxs("div",{className:"ui-panel","data-flush":i?"true":void 0,children:[l,a?n.jsx("div",{className:"ui-panel-foot",children:a}):null]}):n.jsxs(n.Fragment,{children:[l,a?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:a}):null]})]})}function Qe({title:e,tool:t,actions:s,flush:r,children:i}){return n.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||t||s?n.jsxs("header",{className:"ui-panel-head",children:[e?n.jsx("h3",{className:"ui-panel-title",children:e}):n.jsx("span",{}),t?n.jsx("span",{className:"ui-panel-tool",children:t}):null,s?n.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,i]})}function ks({tone:e,title:t,meta:s,actions:r,children:i,foot:a,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())}}:{};return n.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[t||s||r?n.jsxs("div",{className:"ui-card-head",children:[t?n.jsx("h3",{className:"ui-card-title",children:t}):null,s,r?n.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,i,a?n.jsx("div",{className:"ui-card-foot",children:a}):null]})}function Q({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 G_({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function th({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function Fs({label:e,value:t,note:s,tone:r,size:i}){return n.jsxs("div",{className:"ui-stat",children:[n.jsx("div",{className:"ui-stat-k",children:e}),n.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":i,children:t}),s?n.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Gt({items:e}){return n.jsx("dl",{className:"ui-kv",children:e.map((t,s)=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:t.value})]},t.key??s))})}function Pn({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function v1({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 vt({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function Et({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:di("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 kt({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(Cx,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(Ex,{children:[n.jsx(f1,{className:"ui-sheet-overlay"}),n.jsxs(Ax,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(Tx,{className:"ui-sheet-title",children:e}),n.jsx(p1,{asChild:!0,children:n.jsx(R,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Ju({title:e,onClose:t,foot:s,children:r}){return n.jsx(Cx,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(Ex,{children:[n.jsx(f1,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(Ax,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(Tx,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Y_({label:e,items:t}){const s=i=>i.stopPropagation(),r=f.useRef(!1);return n.jsxs(Vd,{modal:!1,onOpenChange:i=>{i&&(r.current=!1)},children:[n.jsx(Gd,{asChild:!0,children:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:s,children:n.jsx(ye,{name:"more"})})}),n.jsx(Ho,{children:n.jsx(Yd,{className:"ui-menu",align:"end",sideOffset:4,onClick:s,onKeyDown:s,onCloseAutoFocus:i=>{r.current&&i.preventDefault()},children:t.map((i,a)=>i?i==="separator"?n.jsx(Or,{className:"ui-menu-sep"},`sep-${a}`):n.jsxs(Ai,{className:"ui-menu-item","data-tone":i.tone,onSelect:()=>{r.current=!0,i.onSelect()},children:[n.jsx("span",{children:i.label}),i.hint?n.jsx("span",{className:"ui-menu-item-hint",children:i.hint}):null]},a):null)})})]})}function q_({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(Cx,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(Ex,{children:n.jsxs(Ax,{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(Tx,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(p1,{asChild:!0,children:n.jsx(R,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Yo({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function Ka({href:e,active:t,count:s,onClick:r,children:i}){return n.jsxs("a",{className:"ui-tab",href:e,"aria-current":t?"page":void 0,onClick:r,children:[i,s?n.jsx("span",{className:"ui-count",children:s}):null]})}function ls({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function jt({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function yt({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 j1({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 y1({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:di("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 Xu({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 Q_=8;function J_({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(0),p=f.useRef(null),g=f.useRef(null),y=f.useRef(null),b=f.useRef(null),x=f.useId(),v=E=>{var $;return(($=t.find(_=>_.value===E))==null?void 0:$.label)??E},j=i!==void 0&&s.length>=i,w=t.filter(E=>!s.includes(E.value)),S=t.length>Q_,k=u.trim().toLowerCase(),N=k===""?w:w.filter(E=>E.label.toLowerCase().includes(k)),C=Math.min(d,Math.max(0,N.length-1)),I=E=>{var $;c(!1),h(""),m(0),E&&(($=g.current)==null||$.focus())};f.useEffect(()=>{var $;if(!o)return;($=S?y.current:b.current)==null||$.focus();const E=_=>{p.current&&!p.current.contains(_.target)&&I(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[o,S]);const A=E=>{const $=[...s,E];r($),h(""),m(0);const _=i!==void 0&&$.length>=i;(_||$.length>=t.length)&&I(!_)},O=E=>{if(E.key==="Escape")E.preventDefault(),I(!0);else if(E.key==="ArrowDown")E.preventDefault(),m(N.length===0?0:(C+1)%N.length);else if(E.key==="ArrowUp")E.preventDefault(),m(N.length===0?0:(C-1+N.length)%N.length);else if(E.key==="Enter"){E.preventDefault();const $=N[C];$&&A($.value)}else E.key==="Backspace"&&u===""&&s.length>0&&(E.preventDefault(),r(s.slice(0,-1)))},z=E=>`${x}-${E}`,L=o&&N.length>0?z(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(E=>n.jsx(Xu,{label:v(E),disabled:a,onRemove:()=>r(s.filter($=>$!==E)),children:v(E)},E)),n.jsxs("div",{className:"ui-chippicker-add",children:[n.jsx("button",{ref:g,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?x:void 0,disabled:a||j||w.length===0,onClick:()=>o?I(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:O,children:[S?n.jsx("input",{ref:y,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":x,"aria-activedescendant":L,value:u,onChange:E=>{h(E.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:x,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":S?void 0:L,tabIndex:S?-1:0,className:"ui-chippicker-list",children:[N.map((E,$)=>n.jsx("div",{id:z($),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":$===C?"":void 0,onMouseEnter:()=>m($),onMouseDown:_=>_.preventDefault(),onClick:()=>A(E.value),children:E.label},E.value)),N.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function X_({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function w1({label:e,value:t,onChange:s,placeholder:r,grow:i}){return n.jsx("span",{className:"ui-search","data-grow":i?"true":void 0,children:n.jsx("input",{type:"search","aria-label":e,value:t,placeholder:r,onChange:a=>s(a.target.value)})})}function Va({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(ye,{name:t})})}function b1({items:e,label:t="Where this is",inline:s}){const r=e.map((i,a)=>{const l=i.key??String(a);if(i.current)return n.jsx("span",{className:"ui-crumb","aria-current":"page",children:i.label},l);const o=i.href?n.jsx("a",{className:"ui-crumb",href:i.href,onClick:i.onClick?c=>{var u;c.preventDefault(),(u=i.onClick)==null||u.call(i)}:void 0,children:i.label}):n.jsx("button",{type:"button",className:"ui-crumb",onClick:i.onClick,children:i.label});return n.jsxs("span",{className:"ui-crumb-step",children:[o,n.jsx(ye,{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 k1({main:e,filters:t,filtersOpen:s,onToggleFilters:r,active:i,chips:a,actions:l,onSubmit:o,label:c}){return n.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[n.jsxs("div",{className:"ui-searchbar-row",children:[e?n.jsx("div",{className:"ui-searchbar-main",children:e}):null,t&&r?n.jsxs(R,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",i?n.jsx("span",{className:"ui-count",children:i}):null]}):null,!r&&t?n.jsx("div",{className:"ui-searchbar-inline",children:t}):null,l?n.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),t&&r&&s?n.jsx("div",{className:"ui-searchbar-filters",children:t}):null,a?n.jsx("div",{className:"ui-searchbar-chips",children:a}):null]})}function Zu({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function S1({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:di("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function Z_({dock:e,className:t,children:s}){return n.jsxs("div",{className:di("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 eL(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function Ix(e){const[t,s]=f.useState({}),r=e??[],i={...eL(r),...t};return r.length===0?{values:void 0,controls:null}:{values:i,controls:n.jsx("div",{className:"ui-choices",children:r.map(a=>n.jsx(ee,{label:a.label,inline:!0,children:n.jsx("select",{value:i[a.key],onChange:l=>s(o=>({...o,[a.key]:l.target.value})),children:a.options.map(l=>n.jsx("option",{value:l,children:l},l))})},a.key))})}}function tL({props:e,timezone:t="UTC",onDecided:s}){var j;const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null);f.useEffect(()=>{let w=!1;return i(null),l(null),T.approval(e.approvalId).then(S=>{w||i(S)}).catch(S=>{w||l(S instanceof pe?S.message:String(S))}),()=>{w=!0}},[e.approvalId]);const{values:d,controls:m}=Ix(r==null?void 0:r.choices),p=(w,S)=>{h(w),l(null),(d&&w==="approve"?T.decide(e.approvalId,w,S,d):T.decide(e.approvalId,w,S)).then(k=>{i(k.action),s==null||s(k.action)}).catch(k=>l(k instanceof pe?k.message:String(k))).finally(()=>h(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",y=(j=r.permissionScopes)==null?void 0:j.includes("always"),b=nL(r),x=(r.preview??"").split(`
|
|
94
|
+
`).length>12||(r.preview??"").length>900,v=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(w=>hn(w)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[g?n.jsx(ge,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(Go,{state:r.state}),!g&&v?n.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children:We(g?r.expiresAt:r.decidedAt,t)})]}),n.jsxs("div",{className:"envelope-body","data-clamp":x&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",x&&!o?n.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),n.jsx(se,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:y?"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"}),y?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…":y?"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(w=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:w.label}),w.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:w.value})}):n.jsx("dd",{className:w.mono?"mono":void 0,children:w.value})]},w.label))})]})]})}function nL(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(rw(hn(i),a));else s!=null&&t.push({label:"Envelope",value:Px(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r)){const l=`Argument · ${hn(i)}`;t.some(o=>o.label===l)||t.push(rw(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 rw(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:Px(t)}}function Px(e){return e==null?"—":Array.isArray(e)?e.map(t=>Px(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):zt(e,"text",null)}const sL=new Set(["image/png","image/jpeg","image/gif","image/webp"]),rL=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function ed(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"||!rL.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 $x(e){return sL.has(e.toLowerCase())}function gr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function si(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function $n(e){return e==null||!Number.isFinite(e)?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(e<10*1024?1:0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Mx(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 Ti={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function mu(e){return`artifact:${e}`}function iL(e){const t=Mx(e.mime,e.filename);return{id:mu(e.artifactId),tool:Ti[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function aL({props:e}){const t=l1(e.artifactId),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1);if(f.useEffect(()=>{if(t===null)return;let h=!0;return r(null),a(null),o(!1),T.libraryEntry(t).then(d=>{h&&r({filename:d.entry.filename,sizeBytes:d.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[t]),t===null)return n.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?$n(s.sizeBytes):null].filter(h=>h!==null);return n.jsxs("figure",{className:"wb-image",children:[n.jsx("div",{className:"wb-image-frame",children:l?n.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):n.jsx("a",{href:gr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:gr(t),alt:e.caption??c,onLoad:h=>{const d=h.currentTarget;d.naturalWidth>0&&a({width:d.naturalWidth,height:d.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(J,{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(Ut,{size:"sm",href:si(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(Et,{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 lL({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 oL=8;function N1({text:e,label:t="Output",className:s}){const r=f.useRef(null),i=f.useRef(!0);return f.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=oL},children:e})}function cL(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 uL({text:e}){const[t,s]=f.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.jsx(R,{size:"sm",onClick:()=>{var r;if(s(""),!((r=navigator.clipboard)!=null&&r.writeText)){s("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>s("Copied"),()=>s("Copy failed; select the text to copy."))},children:"Copy"})]})}function dL({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(J,{className:"wb-terminal-head",children:[e.command!==null?n.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?n.jsxs(ge,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:cL(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(uL,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",$n(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(N1,{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 hL(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function iw(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function fL(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function mL({props:e}){var S;const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=((S=e.target)==null?void 0:S.plugin)??null,h=fL(e),[d,m]=f.useState(null),p=d!==null&&h.includes(d)?d:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,y=e.changes??0,b=f.useRef(y),[x,v]=f.useState(0);f.useEffect(()=>{y<=b.current||(b.current=y,e.reloadsItself||v(k=>k+1))},[y,e.reloadsItself]),f.useEffect(()=>{if(u===null||g===null)return;let k=!0;return s(null),i(null),l(null),v(0),T.previewLink(u,g).then(N=>{k&&(s(N.url),i(iw(N.url)))}).catch(N=>{k&&l(N instanceof Error?N.message:"That preview could not be opened.")}),()=>{k=!1}},[u,g]);const j=()=>{u===null||g===null||T.previewLink(u,g).then(k=>i(k.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const w=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:k=>m(Number(k.target.value)),children:h.map(k=>n.jsxs("option",{value:k,children:[":",k]},k))}):null,w?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(k=>!k),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:j,onFocus:j,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&hL()?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:x===0?t:iw(t),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},x):n.jsx("p",{className:"wb-empty wb-preview-frame",children:a??"Opening the preview…"}),w&&o?n.jsx(N1,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const pL=50,gL=9,xL=24,vL=.6,jL=48,yL=/(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,wL=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,bL=/^id$|(^|[a-z0-9])Id$|_id$/;function ba(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 C1(...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 E1(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&&yL.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&wL.test(i))?"date":"text"}function kL(e,t){if(!bL.test(e))return!1;const s=t.filter(r=>!ol(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function ol(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:zn(e)?Object.keys(e).length===0:!1}function aw(e,t){const s=e.filter(zn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,pL),i=new Map,a=[];for(const h of r)for(const d of Object.keys(h))i.has(d)||a.push(d),i.set(d,(i.get(d)??0)+1);if(i.size===0||i.size>xL||[...i.values()].reduce((h,d)=>h+d,0)/(i.size*r.length)<vL)return null;const o=[...i.keys()].sort((h,d)=>{const m=(i.get(d)??0)-(i.get(h)??0);return m!==0?m:a.indexOf(h)-a.indexOf(d)}),c=[],u=[];for(const h of o){const d=r.map(y=>y[h]),m=d.filter(y=>!ol(y));if(m.length===0||kL(h,d))continue;const p=C1(r[0],t),g=E1(h,d,p);if(r.length>=4&&m.length===d.length&&d.every(y=>ba(y)&&y===d[0])){u.push({label:hn(h),value:d[0],type:g,currency:p});continue}if(c.push({key:h,label:hn(h),type:g,currency:g==="currency"?p:null}),c.length===gL)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function SL(e,t,s){const r=C1(s);return{label:hn(e),value:t,type:E1(e,[t],r),currency:r}}function A1(e){return typeof e=="string"&&e.length>jL}function NL(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 sp(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=sp(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Ox(e,t={}){if(t.failed){let d=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));zn(m)&&(d=m)}catch{}return{kind:"error",summary:sp(d),detail:lw(d)}}if(zn(e)){const d=e.error,m=e.ok;if(typeof d=="string"&&d.trim()!==""||m===!1)return{kind:"error",summary:sp(e),detail:lw(e)}}const s=NL(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const d=aw(e,e);return d?{kind:"table",label:null,columns:d.columns,rows:d.rows,total:d.rows.length,stats:d.constants,notes:[],asides:[]}:e.every(ba)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!zn(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[d,m]of r){if(!Array.isArray(m))continue;const p=aw(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:d,candidate:p});continue}m.length>0&&m.every(ba)&&(!a||m.length>a.items.length)&&(a={key:d,items:m})}const l=(i==null?void 0:i.key)??(a==null?void 0:a.key)??null,o=[],c=[],u=[];for(const[d,m]of r)if(d!==l){if(A1(m)){c.push(m);continue}if(ba(m)){if(m==="")continue;o.push(SL(d,m,e));continue}m!==void 0&&u.push({label:hn(d),value:m})}if(i)return{kind:"table",label:hn(i.key),columns:i.candidate.columns,rows:i.candidate.rows,total:i.candidate.rows.length,stats:[...o,...i.candidate.constants],notes:c,asides:u};if(a)return{kind:"list",label:hn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,d])=>Array.isArray(d)&&d.length===0);return h.length>0&&h.length===r.filter(([,d])=>Array.isArray(d)).length?{kind:"empty",note:`No ${h.map(([m])=>hn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,d])=>ba(d)||zn(d)||Array.isArray(d))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function lw(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 td=25,CL=3,rp=8,T1=6;function ip(e,t=0){if(t>T1||ol(e)||A1(e))return 0;if(ba(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=ip(r,t+1),s>=rp)return s;return s}if(zn(e)){let s=0;for(const r of Object.values(e))if(s+=ip(r,t+1),s>=rp)return s;return s}return 0}function ap(e,t=0){if(t>T1)return!1;if(Array.isArray(e))return e.some(a=>ap(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=>ap(a,t+1))}function EL(e){if(ap(e))return!0;const t=Ox(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=CL;case"record":case"tree":return ip(e)>=rp;default:return!1}}function nf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Dx(e){const t=nf(e);if(!t)return null;const s=nf(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:nf(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function AL({text:e,label:t}){const[s,r]=f.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function sf({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(AL,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function TL({value:e,children:t}){const{result:s,command:r,input:i}=e,a=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([h,d])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&d!==null&&d!==void 0&&d!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx(sf,{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(sf,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(sf,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((h,d)=>n.jsx("p",{className:"wb-fail",children:h},d))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:In({...c,...i?{input:i}:{}})})]})]})}const _c=2,ow=64;function RL({props:e}){const[t,s]=f.useState(!1),r=Dx(e.value),i=IL((r==null?void 0:r.result)??e.value),a=f.useMemo(()=>Ox(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(cw,{files:i}),t?n.jsx("pre",{className:"ui-code",children:In(e.value)}):r?n.jsx(TL,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(cw,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(uw,{shape:a})]}):n.jsx(uw,{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 IL(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 cw({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(PL,{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 PL({file:e}){const[t,s]=f.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function uw({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:Ao(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(rf,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=LL(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(rf,{stats:e.stats}),n.jsx(af,{notes:e.notes}),t?n.jsx(FL,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(ML,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(lf,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(rf,{stats:e.stats}),n.jsx(af,{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(lf,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(af,{notes:e.notes}),n.jsx($L,{pairs:e.pairs}),n.jsx(lf,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:Ao(e.value,0)})}}function rf({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:_x(t.value,t.type,t.currency)})]},t.label))})}const dw=200;function af({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=dw),s=e.filter(r=>r.length>dw);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 $L({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:_x(t.value,t.type,t.currency)})]},t.label))})}function lf({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:Ao(t.value,1)})]},t.label))})}function ML({label:e,columns:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=td+5?r:td,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:I1(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(zL,{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 OL=/^(title|name|headline|subject|label|heading)$/i,DL=/^(url|link|href|uri|permalink)$/i;function nd(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function _L(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function R1(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 Lc(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 LL(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>DL.test(h.key)&&t.some(d=>nd(d[h.key])))??s.find(h=>{const d=t.map(m=>m[h.key]).filter(m=>!ol(m));return d.length>0&&d.filter(nd).length/d.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>OL.test(h.key))??i.find(h=>Lc(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,d)=>Lc(t,d.key)-Lc(t,h.key)),c=o[0]&&Lc(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 FL({label:e,plan:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=td+5?r:td,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[t.url],d=nd(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:d?R1(d):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=d?_L(d):null,y=t.meta.map(b=>c[b]).filter(b=>!ol(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return n.jsxs("li",{className:"wb-record",children:[d?n.jsx("a",{className:"wb-record-title",href:d,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[g?n.jsx("span",{className:"wb-record-host",title:d??void 0,children:g}):null,y.map((b,x)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},x))]}),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 zL({value:e,column:t}){if(ol(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(nd(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:R1(i)})})}if(e!==null&&typeof e=="object"){const i=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return n.jsx("td",{className:"wb-cell-soft",title:In(e),children:i})}const s=_x(e,t.type,t.currency),r=s.length>ow?`${s.slice(0,ow-1)}…`:s;return n.jsx("td",{className:I1(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function I1(e){return e==="number"||e==="currency"}function _x(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":zt(e,t==="text"?"text":t,s)}function Ao(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,". "]}),Ao(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=_c?n.jsx(hw,{summary:`${e.length} items`,open:t===_c,children:i}):i}const s=Object.entries(e);if(s.length===0)return n.jsx("span",{className:"wb-tree-null",children:"empty"});const r=n.jsx("div",{className:t===0?void 0:"wb-tree-branch",children:s.map(([i,a])=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[hn(i),": "]}),Ao(a,t+1)]},i))});return t>=_c?n.jsx(hw,{summary:`${s.length} fields`,open:t===_c,children:r}):r}function hw({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function UL({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:P1(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(BL,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function BL({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:P1(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function P1(e){return e==="number"||e==="currency"||e==="percent"}const fw={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun","partly-cloudy":"partly-cloudy",cloud:"cloud",rain:"rain",drizzle:"drizzle",snow:"snow",storm:"storm",fog:"fog",wind:"wind","moon-clear":"moon-clear"};function nh(e){return(e&&Object.prototype.hasOwnProperty.call(fw,e)?fw[e]:void 0)??"dot"}function mw(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 sd="buddi:plugin-pages-changed";function WL(){window.dispatchEvent(new Event(sd))}function $1(e=!1){const[t,s]=f.useState([]);return f.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>T.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(sd,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(sd,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:mw(t,"rail"),settings:mw(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}let pu=null;typeof window<"u"&&window.addEventListener(sd,()=>{pu=null});function HL(){return pu??(pu=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(pu=null,[]))),pu}function M1(e,t,s){return s==="settings"?ll(e,t):ni(e,t)}function KL(e){const[t,s]=f.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return f.useEffect(()=>{if(!r||!i)return;let a=!1;return HL().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:M1(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function O1({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(VL,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function VL({tile:e,picked:t,onPick:s}){const r=KL(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(ye,{name:nh(e.icon),size:22})}),e.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,n.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>n.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-tone":t?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":t?"true":void 0,"aria-pressed":t===!0,"aria-label":i,onClick:s,children:a})}):n.jsxs("li",{className:"wb-tile",children:[n.jsx("span",{className:"sr-only",children:i}),n.jsxs(ks,{tone:e.tone==="neutral"?void 0:e.tone,children:[a,r?n.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const ra=760,of=400,Tt={top:18,right:18,bottom:36,left:66},GL=5;function YL({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(w=>w.y),...s.map(w=>w.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,d=ra-Tt.left-Tt.right,m=of-Tt.top-Tt.bottom,p=w=>Tt.left+(t.length===1?d/2:w/(t.length-1)*d),g=w=>Tt.top+m-(w-u)/(h-u)*m,y=qu(l,o,4),b=QL(t.map(w=>w.y),e.mark),x=e.shadeBelow===null?[]:JL(t.map(w=>w.y),e.shadeBelow),v=t.map((w,S)=>`${S===0?"M":"L"}${p(S)},${g(w.y)}`).join(" "),j=w=>zt(w,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 ${ra} ${of}`,role:"img","aria-label":qL(e,j),preserveAspectRatio:"xMidYMid meet",children:[x.map(w=>n.jsx("rect",{className:"wb-chart-breach",x:p(w.from),width:Math.max(2,p(w.to)-p(w.from)),y:Tt.top,height:m},`band-${w.from}`)),y.map(w=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Tt.left,x2:ra-Tt.right,y1:g(w),y2:g(w)}),n.jsx("text",{x:Tt.left-8,y:g(w)+4,textAnchor:"end",children:j(w)})]},`tick-${w}`)),s.map(w=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-floor",x1:Tt.left,x2:ra-Tt.right,y1:g(w.value),y2:g(w.value)}),n.jsxs("text",{x:ra-Tt.right,y:g(w.value)-6,textAnchor:"end",children:[w.label," ",j(w.value)]})]},`rule-${w.label}`)),n.jsx("line",{className:"wb-chart-axis",x1:Tt.left,x2:Tt.left,y1:Tt.top,y2:Tt.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:Tt.left,x2:ra-Tt.right,y1:Tt.top+m,y2:Tt.top+m}),n.jsx("path",{className:"wb-chart-series",d:v}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:g(t[b].y)+20,textAnchor:"middle",children:j(t[b].y)})]}):null,XL(t.length).map(w=>n.jsx("text",{x:p(w),y:of-10,textAnchor:"middle",children:Ym(t[w].x)},`x-${w}`))]})}),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((w,S)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Ym(w.at)}),w.label]}),w.amount===null?null:n.jsx("span",{className:w.amount<0?"tnum critical":"tnum good",children:zt(w.amount,r,i)})]},`${w.at}-${w.label}-${S}`))})]}):null]})]})}function qL(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 QL(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 JL(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 XL(e,t=GL){if(e<=0)return[];if(e<=t)return[...Array(e).keys()];const s=e-1,r=new Set;for(let i=0;i<t;i+=1)r.add(Math.round(i/(t-1)*s));return[...r].sort((i,a)=>i-a)}const Xn=e=>e,lp={timeseries:Xn(YL),table:Xn(UL),bars:Xn(DO),keyvalue:Xn(lL),tiles:Xn(O1),document:Xn(m_),diff:Xn(BO),terminal:Xn(dL),image:Xn(aL),preview:Xn(mL),envelope:Xn(tL),structured:Xn(RL)},ZL="structured";function eF(e){return(rd(e)?lp[e]:void 0)??lp[ZL]}function rd(e){return Object.prototype.hasOwnProperty.call(lp,e)}function tF({renderer:e,props:t,timezone:s,onDecided:r}){const i=eF(e),l=rd(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function nF({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(cf,{children:"Opens by default"}):null,n.jsx(cf,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(cf,{title:`A surface command that asks for "${s}" lands on this agent.`,children:hn(s)},s))]}),e.available?null:n.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[n.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>n.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),n.jsx(Tl,{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(D1,{}),"Exact action"]})]})]})}),n.jsx(Tl,{title:"What it can do",note:sF(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(rF,{family:s},s.family))}),n.jsx(Tl,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(Rl,{label:"Provider",children:e.engine.provider}),n.jsx(Rl,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(Rl,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(Rl,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(Rl,{label:"Language",children:cF(e.engine.language)})]})}),e.skills.length>0?n.jsx(Tl,{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(Tl,{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 sF(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 rF({family:e}){const t=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return n.jsxs("section",{className:"wb-prof-family",children:[n.jsxs("h4",{className:"wb-prof-family-head",children:[n.jsx("span",{className:"wb-prof-family-name",children:hn(e.family)}),n.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),n.jsx("ul",{className:"wb-prof-list",children:t.map(s=>n.jsx(iF,{tool:s},s.name))})]})}function iF({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:oF(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(D1,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:lF(e.tier),children:aF(e.tier)})]})}function aF(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function lF(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 oF(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function cF(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Tl({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 Rl({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 cf({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function D1(){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 pw=16e3,uF=10*6e4,dF="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",_1="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function hF(){const e=window;return e.AudioContext??e.webkitAudioContext}function fF(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?dF:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":_1}async function mF(e){var c;const t=hF();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(_1),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let d=0;for(let m=0;m<h.length;m++)d+=h[m]*h[m];e(Math.min(1,Math.sqrt(d/h.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),xF(gF(pF(l),u,pw),pw)},cancel:o}}function pF(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 gF(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 xF(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 op="buddi.readAloud";function L1(){try{return window.localStorage.getItem(op)==="on"}catch{return!1}}function F1(e){try{e?window.localStorage.setItem(op,"on"):window.localStorage.removeItem(op)}catch{}}let Os=null,ql=null,To=0,cp=null;const up=new Set;function id(e){cp!==e&&(cp=e,up.forEach(t=>t()))}function vF(){return cp}function jF(e){return up.add(e),()=>up.delete(e)}function z1(e){return cl(),id(e),To}function gw(e){return e===To}function cl(){To++,Os&&(Os.pause(),Os.removeAttribute("src")),ql&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(ql),ql=null,id(null)}async function yF(e,t,s=null){var i;const r=z1(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!==To)return;Os||(Os=new Audio,(i=Os.addEventListener)==null||i.call(Os,"ended",()=>id(null))),ql=URL.createObjectURL(l),Os.src=ql,await Os.play()}catch(a){throw r===To&&id(null),a}}const wF=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function U1(e){return wF.has(e.toLowerCase().split(";")[0].trim())}function xw(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 B1({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=f.useRef(null),a=f.useRef(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),[h,d]=f.useState(!1),[m,p]=f.useState(0),[g,y]=f.useState(null);f.useEffect(()=>()=>{var v;(v=i.current)==null||v.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const v=i.current;if(v){if(l){v.pause();return}cl(),d(!1);try{if(!a.current){u(!0);const j=await fetch(si(e),{credentials:"same-origin"});if(!j.ok)throw new Error(String(j.status));a.current=URL.createObjectURL(new Blob([await j.arrayBuffer()],{type:s})),v.src=a.current}await v.play()}catch{d(!0)}finally{u(!1)}}},x=h?"Could not play. Download it instead.":`${xw(m)} / ${xw(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(ye,{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…":x,!h&&$n(r)?` · ${$n(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:si(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(ye,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:v=>p(v.currentTarget.currentTime),onLoadedMetadata:v=>y(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null),onDurationChange:v=>y(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null)})]})}const uf=1e5,df=200,hf=30;function W1({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=f.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:gr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&U1(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(B1,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:gr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(H,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(bF,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(H,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(H,{children:"The file is no longer available; its record is kept."})}function bF({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=f.useState("loading");if(f.useEffect(()=>{let o=!1;return a("loading"),fetch(gr(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,uf),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>uf})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(oe,{children:"Loading preview…"})});if(i==="failed")return n.jsx(H,{children:"The preview could not be loaded. Download the file to open it."});const l=r==="table"&&(/csv|tab-separated/.test(s)||/\.(csv|tsv)$/i.test(t??""));return n.jsxs("div",{className:"file-preview",children:[l?n.jsx(SF,{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 ",uf.toLocaleString()," characters. The download has the whole file."]}):null]})}function kF(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const h=()=>{a.length<r?a.push(l):c=!0,l=""},d=()=>{h(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===t){h();continue}if(p!=="\r"){if(p===`
|
|
95
|
+
`){d();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&d(),{rows:i,truncatedRows:u,truncatedCols:c}}function SF({text:e,delimiter:t}){const s=f.useMemo(()=>kF(e,t,df+1,hf),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(hf,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,df).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 ",df," rows",s.truncatedCols?` and ${hf} columns`:"",". The download has the whole file."]}):null]})}function NF({attachment:e}){const t=Mx(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(W1,{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:[Ti[t],n.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Size"}),n.jsx("dd",{children:$n(e.sizeBytes)})]}):null,n.jsx("dt",{children:"Id"}),n.jsx("dd",{className:"mono",children:e.artifactId})]}),n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx("a",{className:"ui-btn",href:si(e.artifactId),download:s,children:"Download"})})]})}const vw=80,CF=["query","path","url","dir"],EF=["message","task"];function Lx(e,t){const s=AF(t);if(!s)return null;const r=ia(s.command);if(r!==null){const l=ia(s.name);return Fc(l===null?r:`${l}: ${r}`)}for(const l of CF){const o=ia(s[l]);if(o!==null)return Fc(o)}const i=ia(s.action);if(i!==null){const l=EF.map(o=>ia(s[o])).find(o=>o!==null)??null;return Fc(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?Fc(ia(a[0])):null}function ia(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function Fc(e){return e===null?null:e.length>vw?`${e.slice(0,vw-1)}…`:e}function AF(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const H1="owner.notify",tr=e=>typeof e=="string"&&e.trim()!==""?e:null;function TF(e){const t=e!==null&&typeof e=="object"?e:{};return{title:tr(t.title)??"(no title)",text:tr(t.text),urgency:tr(t.urgency)??"now",key:tr(t.key),link:tr(t.link)}}function K1(e){if(e===null||typeof e!="object")return tr(e);const t=e;return tr(t.delivered)??tr(t.message)??tr(t.error)}function RF(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 ri="agent.delegate";function IF(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 PF(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 dp="canvas.show",jw="canvas.clear",yw=12;function $a(e){return`${e.plugin}/${e.name}`}function $F(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function MF({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=c1(o,V1(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function OF({messages:e,descriptors:t,awaiting:s,folded:r,served:i}){var u;const a=new Map(t.map(h=>[h.tool,h])),l=new Map;let o=[],c=0;for(const h of e)for(const d of h.blocks??[]){if(d.type==="tool_use"){if(l.set(d.id,{name:d.name,input:d.input,at:h.at??null}),d.name===dp){const w=_F(d.id,d.input,h.at??null);w&&o.push(w)}if(d.name===jw&&(o=[]),d.name===ri){const w=IF(d.input);w&&o.push({id:d.id,tool:ri,title:"Delegation",renderer:"delegate",props:{...w,result:null},at:h.at??null,source:"delegate",substantial:!0})}continue}if(d.type!=="tool_result"||d.name===dp||d.name===jw)continue;const m=l.get(d.toolUseId),p=h.at??(m==null?void 0:m.at)??null,g=d.name||(m==null?void 0:m.name)||"tool",y=o.find(w=>w.source==="delegate"&&w.id===d.toolUseId);if(y&&((u=d.delegation)==null?void 0:u.state)==="waiting"){y.props={...y.props,result:null,waiting:{approvalId:d.delegation.approvalId}},d.delegation.approvalId&&(y.tone="warning");continue}if(y){y.props={...y.props,result:{ok:d.ok,text:PF(d.ok?d.output:d.error??d.output),...d.ok&&ed(d.output).length>0?{files:ed(d.output)}:{}}},d.ok||(y.tone="critical");continue}const b=d.approval?fp(d):(s==null?void 0:s.get(d.toolUseId))??fp(d);if(b){o.push({id:d.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===H1){o.push({id:d.toolUseId,tool:g,title:"Message to you",renderer:"notify",props:{input:(m==null?void 0:m.input)??null,output:d.output??null,ok:d.ok!==!1},at:p,tone:d.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const x=V1(d.output);if(d.ok===!1){o.push({id:d.toolUseId,tool:g,title:Bs(g),renderer:"structured",props:{value:d.error??x??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}$F(x)&&(c+=1);const v=a.get(g);if(v){const w=c1(v,x),{renderer:S}=w;let{props:k}=w;if(S==="preview"){const N=k,C=N.target??(N.awaiting&&(i!=null&&i.has($a(N.awaiting)))?N.awaiting:null);if(C===null)continue;k={...N,target:C,awaiting:null};const I=$a(C);o=o.filter(A=>!(A.source==="descriptor"&&A.renderer==="preview"&&A.props.target!==null&&$a(A.props.target)===I))}o.push({id:d.toolUseId,tool:g,title:v.title??Bs(g),renderer:S,props:k,at:p,source:"descriptor",substantial:hp(S,k)});continue}const j={value:Dx(x)?{input:m==null?void 0:m.input,output:x}:x};LF("structured",j)&&o.push({id:d.toolUseId,tool:g,title:Bs(g),renderer:"structured",props:j,at:p,source:"fallback",substantial:hp("structured",j)})}for(const h of o)h.source==="descriptor"&&h.renderer==="preview"&&(h.props={...h.props,changes:c});return DF(o)}const ww="forAgent";function V1(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(ww in e))return e;const{[ww]:t,...s}=e;return s}function DF(e){if(e.length<=yw)return e;const t=e.length-yw;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function _F(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&rd(r)?r:"structured";return{id:e,tool:dp,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!rd(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function LF(e,t){const s=t??{};return!!(s.failed===!0||hp(e,t)||Ox(s.value).kind==="error")}function hp(e,t){const s=t??{};switch(e){case"timeseries":return Il(s.points)>0;case"bars":return Il(s.bars)>0;case"keyvalue":return Il(s.pairs)>0;case"tiles":return s.notice!==!0&&Il(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=>Il(i.rows)>0);default:return Dx(s.value)?!0:s.failed===!0?!1:EL(s.value)}}function Il(e){return Array.isArray(e)?e.length:0}function fp(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=Y1(t,0);if(s)return s}return null}function FF(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)?G1(i.input):i.input;return{id:t,tool:i.name,title:Bs(i.name),renderer:"structured",props:{value:{input:l,...(a==null?void 0:a.type)==="tool_result"?{status:((c=a.approval)==null?void 0:c.state)??(a.ok?"completed":"failed"),output:a.output,...a.error?{error:a.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const zF=new Set(["value","text","password","secret","code"]);function G1(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=zF.has(s)&&typeof r=="string"?"— withheld —":G1(r);return t}function Y1(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=Y1(a,t+1);if(l)return l}return null}function Bs(e){const t=e.split(".");return t.length===1?hn(e):t.map(s=>hn(s)).join(" · ")}function sh({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=Mx(t,e),h=[Ti[u],$n(s)].filter(Boolean).join(" · "),d=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-file-visual","data-family":u,children:r?n.jsx("img",{src:r,alt:""}):n.jsx(Fx,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":h})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:d}):n.jsx("span",{className:"wb-file-open",children:d}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Fx({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 UF(e,t,s){const r=kw(e),i=kw(t==null?void 0:t.input),a=vi(r==null?void 0:r.name)??VF(vi(r==null?void 0:r.handle))??vi(r==null?void 0:r.agent)??vi(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:vi(r==null?void 0:r.text)??vi(r==null?void 0:r.note),o=bw(r==null?void 0:r.durationMs)??bw(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:vi(i==null?void 0:i.task),answer:l,files:ed(e),durationMs:o??h}}function BF(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===ri&&((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 WF({block:e,messages:t,answeredAt:s}){const r=UF(e.output,BF(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${HF(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(pr,{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:si(a.artifactId),download:!0,children:n.jsx(sh,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:$x(a.mime)?gr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(Et,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:KF(e.output)})})]})}function HF(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 KF(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function VF(e){return e===null?null:`@${e.replace(/^@/,"")}`}function vi(e){return typeof e=="string"&&e.trim()!==""?e:null}function bw(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function kw(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const GF=1e3;function YF({messageId:e,text:t,onReadAloud:s}){const[r,i]=f.useState(!1),a=f.useRef(null),l=f.useSyncExternalStore(jF,vF)===e;f.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),GF)},()=>{})};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(ye,{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?cl():s(e,t),children:n.jsx(ye,{name:l?"stop":"play",size:14})}):null]})}function qF(e){const t=QF(e);if(!t)return null;const s=ff(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=ff(t.command),i=ff(t.plain),a=mf(t.exitCode);return r!==null&&(i!==null||a!==null||mf(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:mf(t.elapsedMs)}:null}function ff(e){return typeof e=="string"&&e.trim()!==""?e:null}function mf(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function QF(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const Sw="offer:",q1="owner:interjection";function JF(e){return e===q1}function XF(e){if(typeof e!="string"||!e.startsWith(Sw))return null;const t=e.slice(Sw.length).trim();return t===""?null:t}function zx({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:d,onReadAloud:m,children:p,agentName:g,emptyHint:y,empty:b,plain:x=!1,workingLine:v,runs:j}){var D;const w=f.useRef(null);f.useEffect(()=>{var U;(U=w.current)==null||U.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const S=a&&!a.settled&&(a.text!==""||a.thinking!==""),k=e.filter(U=>(U.blocks??[]).some(c4)),N=l4(k,j??[]),C=c??l??[],I=U=>(o&&!c?C.find(V=>V.id===o):void 0)??C.find(V=>V.name===U)??null,A=o?C.find(U=>U.id===o)??null:null,O=i||t.length>0,z=O||!!S,L=!!S&&a.text!=="",E=O&&!L,$=k.at(-1),_=($==null?void 0:$.role)!=="assistant"||!!h,B=h??g??"Assistant",M=k.filter((U,V)=>{var Z;return V===0||(c?(((Z=k[V-1])==null?void 0:Z.speaker)??null)!==(U.speaker??null):k[V-1].role!==U.role)}),W=z&&!_?((D=M.at(-1))==null?void 0:D.id)??null:null;return n.jsx(a1.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[k.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:y}):null,k.map((U,V)=>{const Z=U.speaker??null,ue=c?Z==="owner"||Z===null&&U.role==="user":U.role==="user",Ae=c&&Z==="room",X=c&&Z&&Z!=="owner"&&Z!=="room"?c.find(ce=>ce.id===Z)??null:null,le=k[V-1],me=V===0||(c?((le==null?void 0:le.speaker)??null)!==Z:le.role!==U.role);if(Ae)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(U.blocks??[]).filter(ce=>ce.type==="text").map((ce,Te)=>n.jsx("span",{children:ce.text},Te))},U.id);const $e=(U.blocks??[]).filter(ce=>ce.type==="approval_result");if($e.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:$e.map((ce,Te)=>n.jsx(u4,{block:ce,messages:e,at:U.at||null},Te))},U.id);const ke=U.role==="user"&&JF(Z),we=U.role==="user"?XF(Z):null;if(we){const ce=(U.blocks??[]).filter(Te=>Te.type==="text").map(Te=>Te.text).join(`
|
|
96
|
+
`);return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",title:ce,children:we})},U.id)}const Ce=c&&X&&U.role==="user"?r4(U):null;if(Ce){const ce=k.slice(V+1).find(G=>G.role==="assistant"&&G.speaker&&G.speaker!==X.id),Te=ce!=null&&ce.speaker?c.find(G=>G.id===ce.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[X.name," asked ",(Te==null?void 0:Te.name)??"a member",Ce.request?`: ${Ce.request.length>120?`${Ce.request.slice(0,119)}…`:Ce.request}`:""]}),Ce.request?n.jsx("p",{children:Ce.request}):null]},U.id)}const dt=N.get(U.id)??null,fe=a4(U,e),Me=!ue&&!ke&&!x?i4(U):"";return n.jsxs("div",{className:"wb-msg","data-role":ue||ke?"user":"assistant",children:[ke?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,me&&!ue&&!ke?n.jsx(Nw,{name:X?X.name:g??"Assistant",face:X??A??I(g),moving:E&&W===U.id,children:X&&u===X.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,fe.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:fe.map(ce=>n.jsx("span",{role:"listitem",children:U1(ce.mime)?n.jsx(B1,{artifactId:ce.artifactId,name:ce.filename??"Untitled file",mime:ce.mime,sizeBytes:ce.sizeBytes}):n.jsx(sh,{name:ce.filename??"Untitled file",mime:ce.mime,sizeBytes:ce.sizeBytes,thumbnail:$x(ce.mime)?gr(ce.artifactId):null,...d?{onOpen:()=>d(ce)}:{}})},ce.artifactId))}):null,(U.blocks??[]).map((ce,Te)=>{const G=t4(U.blocks??[],Te,e);if(G==="inside")return null;if(G)return n.jsx(n4,{refusals:G.refusals},Te);if(ce.type==="thinking")return x||ce.text.trim()===""?null:n.jsx(mp,{text:ce.text},Te);if(ce.type==="text")return ce.text.trim()===""?null:ue?n.jsx("div",{className:"wb-bubble",children:ce.text},Te):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(pr,{text:ce.text})},Te);if(ce.type==="attachment")return null;if(ce.type==="tool_use"){if(x)return null;const ie=Ux(e,ce.id),Pe=ie?f4(ie):null,it=!Pe&&ce.name===H1&&ie?K1(ie.output):null;return n.jsx(pp,{label:Pe&&!(ie!=null&&ie.delegation)?`Approval · ${ce.name}`:Bs(ce.name),tool:ce.name,ok:(ie==null?void 0:ie.ok)??null,running:ie===null,...Pe?{status:Pe.status,waiting:Pe.waiting,approval:!0}:it?{status:it}:{},gist:Lx(ce.name,ce.input),body:ie?qF(ie.output):null,opens:!0,onOpen:()=>r(ce.id)},Te)}return null}),dt?n.jsx("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:o4(dt)}):null,Me!==""?n.jsx(YF,{messageId:U.id,text:Me,onReadAloud:m}):null]},U.id)}),z?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[_?n.jsx(Nw,{name:B,face:I(B)??A,moving:E}):null,S&&a.thinking!==""&&!x?n.jsx(mp,{text:a.thinking,live:a.text==="",seconds:s4(a.thinkingStartedAt,a.textStartedAt??s)}):null,L?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(pr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!S?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${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(U=>n.jsx(pp,{label:Bs(U.name),tool:U.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-U.startedAt)/1e3)),opens:!1,onOpen:()=>r(U.toolUseId)},U.toolUseId))]}):null,p,n.jsx("div",{ref:w})]})})}function Nw({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=s1(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(Zd,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Es,{id:(t==null?void 0:t.id)??e,name:(t==null?void 0:t.name)??e,unavailable:t?!t.available:!1,...t?{face:t}:{}})}),n.jsx("span",{children:e}),r]})}function ZF(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 e4="delegation refused:";function t4(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==ri)return null;const o=Ux(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(e4))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 n4({refusals:e}){const[t,s]=f.useState(!1),r=e.map(o=>ZF(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(ye,{name:"arrow",className:"wb-tool-arrow"})]}),t?n.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>n.jsxs("div",{className:"wb-refusal",children:[n.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsxs("span",{className:"wb-tool-label",children:[Bs(ri)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function s4(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function mp({text:e,live:t=!1,seconds:s=null}){const[r,i]=f.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(ye,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(pr,{text:e})}):null]})}function r4(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 i4(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
|
|
97
|
+
|
|
98
|
+
`)}function a4(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===ri){const l=Ux(t,a.id);l!=null&&l.ok&&ed(l.output).forEach(i)}return s}function l4(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 o4(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 c4(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function u4({block:e,messages:t,at:s}){const[r,i]=f.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":Bs(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===ri?n.jsx(WF,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==ri?n.jsx("pre",{className:"wb-approval-output mono",children:d4(e.output)}):null]})}function d4(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const h4=40;function f4(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(fp(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 pp({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:d=null}){const[m,p]=f.useState(!1),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]}),y={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return d?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...y,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(ye,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(bo,{children:n.jsxs(ko,{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(m4,{body:d,onOpen:a?l:null}):null]}):a?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...y,onClick:l,children:[g,n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(bo,{children:n.jsxs(ko,{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",...y,children:g})}function m4({body:e,onOpen:t}){const s=t?{label:"Open on the canvas",onClick:t}:void 0;if(e.kind==="diff")return n.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:n.jsx(Qu,{text:e.diff,limit:h4,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:p4(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 p4(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Ux(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}const Q1="approval-dock";function g4(){var t;const e=document.getElementById(Q1);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const x4=["workspace","cwd","workdir","root"];function v4({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=f.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const d=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(j4,{item:h,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{d(h.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function j4({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(null),[g,y]=f.useState("");f.useEffect(()=>{let I=!1;return T.approval(e.approvalId).then(A=>{I||(u(A),A.state!=="pending"&&a(A))}).catch(A=>{I||d(A instanceof pe?A.message:String(A))}),()=>{I=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;f.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:x,controls:v}=Ix(c==null?void 0:c.choices),j=(I,A)=>{const O=g.trim();p(I),d(null),(x&&I==="approve"?T.decide(e.approvalId,I,A,x):T.decide(e.approvalId,I,A)).then(z=>{a(z.action),O&&l(O)}).catch(z=>{d(z instanceof pe?z.message:String(z)),p(null)})},w=m!==null||c===null||c.state!=="pending",S=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,k=c?Lx(c.tool,c.canonicalArgs)??w4(c.preview):null,N=c?y4(c):null;return n.jsxs("section",{id:Q1,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),t>1?n.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",t]}):null,n.jsx("strong",{children:c?Bs(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),k||N?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[k?n.jsx("code",{className:"wb-dock-gist",children:k}):null,N?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:N})]}):null]}):null,v?n.jsx("div",{className:"wb-dock-section",children:v}):null,n.jsx(se,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:I=>y(I.target.value),onKeyDown:I=>{I.key==="Enter"&&I.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),n.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[n.jsxs("span",{className:"wb-dock-meta",children:[c?n.jsxs(n.Fragment,{children:["Expires ",We(c.expiresAt,s)," · "]}):null,n.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),n.jsx(R,{variant:"ghost",size:"sm",disabled:w,onClick:()=>j("reject"),children:m==="reject"?"Rejecting…":"Reject"}),S?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:w,onClick:()=>j("approve","conversation"),children:"Auto: this conversation"}),n.jsx(R,{size:"sm",disabled:w,onClick:()=>j("approve","always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"good",size:"sm",disabled:w,onClick:()=>j("approve"),children:m==="approve"?"Approving…":S?"Allow once":"Approve"})]})]})}function y4(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of x4){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function w4(e){const t=(e??"").split(`
|
|
99
|
+
`).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const b4=2e3;function k4({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=f.useState(l),u=!o||i!==null,{data:h,error:d}=ae(()=>Le.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?b4:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(w=>w.runId===s)??null,g=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(w=>w.finishedAt!==null));f.useEffect(()=>{g&&c(!0)},[g]);const y=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":g?"done":"working",b=a.find(w=>w.id===t)??null,x=(b==null?void 0:b.name)??(h==null?void 0:h.agentId)??t,v=(h==null?void 0:h.messages)??[],j=(r==null?void 0:r.text)??S4(v);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":y,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(Nn,{agents:a,id:t}),n.jsxs("div",{className:"wb-delegate-who",children:[n.jsx("strong",{children:x}),n.jsx("span",{className:"wb-delegate-status","data-status":y,role:"status",children:y==="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",{})]})]}):y==="waiting"?"Waiting for your approval":y==="failed"?"Failed":"Done"})]})]}),d?n.jsx("p",{className:"muted",children:d}):null,n.jsx("div",{className:"wb-delegate-work",children:v.map((w,S)=>n.jsx("div",{className:"wb-delegate-turn",children:(w.blocks??[]).map((k,N)=>{if(k.type==="thinking")return k.text.trim()===""?null:n.jsx(mp,{text:k.text},N);if(k.type==="tool_use"){const C=C4(N4(v,k.id));return n.jsx(pp,{label:Bs(k.name),tool:k.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Lx(k.name,k.input),opens:!1,onOpen:()=>{}},N)}return null})},w.id??S))}),j?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(pr,{text:j})}):y==="working"||y==="waiting"?n.jsxs("p",{className:"muted",children:[x," 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 ${x} made`,"data-testid":"delegate-files",children:r.files.map(w=>n.jsx("a",{role:"listitem",href:si(w.artifactId),download:!0,children:n.jsx(sh,{name:w.filename??"Untitled file",mime:w.mime,sizeBytes:w.sizeBytes,thumbnail:$x(w.mime)?gr(w.artifactId):null})},w.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[y==="waiting"?n.jsx(R,{variant:"accent",onClick:()=>g4(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:Ge(t||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function S4(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 N4(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 C4(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 Cw=1024*1024;function E4({files:e,agentId:t,root:s,revision:r}){const[i,a]=f.useState({kind:"dir",path:""});return f.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(A4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(T4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function J1({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 A4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(!1),[m,p]=f.useState(null);f.useEffect(()=>{let b=!1;return u(null),T.pageQuery(e.plugin,e.list,{agent:t,...r?{path:r}:{}}).then(x=>{b||o(x.data)}).catch(x=>{b||u(x instanceof Error?x.message:String(x))}),()=>{b=!0}},[e.plugin,e.list,t,r,i]),f.useEffect(()=>p(null),[r]);const g=async()=>{d(!0),p(null);try{const b=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const w=await b.json().catch(()=>null);p((w==null?void 0:w.error)??"The archive could not be made.");return}const x=await b.blob(),v=URL.createObjectURL(x),j=document.createElement("a");j.href=v,j.download=`${r===""?s:r.split("/").at(-1)}.zip`,j.click(),window.setTimeout(()=>URL.revokeObjectURL(v),1e4)}catch{p("The archive could not be made.")}finally{d(!1)}},y=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(J1,{root:s,path:r,go:a}),n.jsx(en,{}),n.jsx(R,{size:"sm",onClick:()=>void g(),disabled:h||y===null||y.length===0,children:h?"Packing…":"Download as archive"})]}),m?n.jsx(H,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,y===null?c?null:n.jsx(oe,{children:"Reading the folder…"}):y.length===0?n.jsx(oe,{children:r===""?n.jsxs(n.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",n.jsx("a",{href:Li,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(jt,{children:y.map(b=>n.jsx(yt,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(I4,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?$n(b.bytes):void 0},b.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?n.jsxs("p",{className:"wb-files-note",children:[l.truncated?`Only the first ${l.entries.length} entries are shown. `:"",l.skipped>0?`${l.skipped} ${l.skipped===1?"entry is":"entries are"} not shown: symbolic links and protected paths are never read.`:""]}):null]})}function T4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(!1);f.useEffect(()=>{let x=!1;return u(null),T.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(v=>{x||o(v.data)}).catch(v=>{x||u(v instanceof Error?v.message:String(v))}),()=>{x=!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?T.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",y=T.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=Cw;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(J1,{root:s,path:r,go:a}),n.jsx(en,{}),b?n.jsx(R,{size:"sm","aria-pressed":h,onClick:()=>d(x=>!x),children:"Wrap"}):null,n.jsx(Ut,{size:"sm",href:y,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(oe,{children:"Reading the file…"}):m.type==="image"?n.jsx("figure",{className:"wb-files-picture",children:n.jsx("img",{src: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(H,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(R4,{src:g,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(H,{children:m.type==="text"?`This file is over ${$n(Cw)}, 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(Gt,{items:[{label:"Size",value:$n(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function R4({src:e,wrap:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1);return f.useEffect(()=>{let l=!1;return a(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(H,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(oe,{children:"Reading the file…"}):s===""?n.jsx(oe,{children:"This file is empty."}):n.jsx("pre",{className:"wb-files-text","data-wrap":t?"true":void 0,"data-testid":"files-text",children:s})}function I4({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 P4({input:e,output:t,ok:s}){const r=TF(e),i=K1(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(ge,{tone:RF(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(Et,{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 $4=3,M4=152,O4=104,D4=100,_4=2,Ew=5;function L4({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:d,agents:m,onClose:p,loading:g=!1}){const[y,b]=F4(h);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:y,"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:H4(u,K4(o??[],c??[]))})]})})]});const x=e.some(w=>w.id===t)?t:e[e.length-1].id,{shown:v,hidden:j}=z4(e,x,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(EO,{value:x,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:y,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(AO,{className:"wb-tabstrip","aria-label":"Canvas",children:v.map(w=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(TO,{value:w.id,className:"wb-tab","data-tone":w.tone,onKeyDown:S=>{S.key==="Delete"&&p&&Aw(w)&&(S.preventDefault(),p(w.id))},children:[w.tone==="warning"||w.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":w.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:w.title})]}),p&&Aw(w)?n.jsx("button",{className:"wb-tab-close","aria-label":`Close ${w.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>p(w.id),children:"×"}):null]},w.id))}),n.jsx(U4,{items:j,onActivate:s,timezone:r})]}),e.map(w=>n.jsx(RO,{value:w.id,className:"wb-canvas-body","data-renderer":w.source==="descriptor"&&w.renderer==="preview"?"preview":void 0,"data-dense":G4.has(w.renderer)?"true":void 0,children:n.jsxs("section",{className:"ui-panel","data-flush":w.source==="descriptor"&&w.renderer==="preview"?"true":void 0,children:[w.source!=="browser"&&w.source!=="files"&&!(w.source==="descriptor"&&w.renderer==="preview")?n.jsxs("header",{className:"ui-panel-head",children:[n.jsx("h2",{className:"ui-panel-title",children:w.title}),n.jsx("span",{className:"ui-panel-tool mono",children:w.tool})]}):null,w.tone==="critical"?n.jsxs("p",{className:"muted",children:["Recorded tool failure",w.at?` · ${new Date(w.at).toLocaleString()}`:"",". This is history, not live session status."]}):null,w.source==="browser"?d:w.source==="profile"?n.jsx(nF,{...w.props,...a?{onChange:a}:{}}):w.source==="artifact"?n.jsx(NF,{...w.props}):w.source==="files"?n.jsx(E4,{...w.props}):w.source==="notify"?n.jsx(P4,{...w.props}):w.source==="delegate"?n.jsx(k4,{...w.props,agents:m??[]}):n.jsx(tF,{renderer:w.renderer,props:w.props,timezone:r,onDecided:i})]})},w.id))]})})}function Aw(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function F4(e){const[t,s]=f.useState(Ew),r=f.useRef(null);return[f.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-D4-O4)/M4);s(Math.max(_4,Math.min(Ew,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function z4(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 U4({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(Vd,{modal:!1,children:[n.jsx(Gd,{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(ye,{name:"chevron-down"})]})}),n.jsx(Ho,{children:n.jsxs(Yd,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(qd,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(Ai,{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:B4(i.at,s)??i.tool})]},i.id))]})})]})}function B4(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:new Intl.DateTimeFormat("en-GB",{timeZone:t,hour:"2-digit",minute:"2-digit"}).format(s)}const W4={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 H4(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>W4[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function K4(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=V4(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,$4)}function V4(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 G4=new Set(["table","diff","files"]),Y4=3.5*6e4,q4=2e3;function Q4(e,t,s={}){const[r,i]=f.useState({served:new Set,live:new Set,scope:t}),a=f.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??T.previewCheck,o=s.everyMs??q4,c=e.map(u=>`${$a(u)}@${u.at??""}`).join("|");return f.useEffect(()=>{const u=new Map;for(const p of e){const g=$a(p);if(a.current.has(g))continue;const y=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(y)?0:y+Y4,x=u.get(g);(!x||b>x.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let h=!1,d;const m=async()=>{const p=Date.now();for(const[g,y]of[...u]){const b=await l(y.plugin,y.name).catch(()=>null);if(h)return;const x=p<=y.until;b!=null&&b.ok?(u.delete(g),i(v=>{const j={served:new Set(v.served).add(g),live:x?new Set(v.live).add(g):v.live,scope:v.scope};return a.current=j.served,j})):x||u.delete(g)}!h&&u.size>0&&(d=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,d!==void 0&&clearTimeout(d)}},[c,t,l,o]),r}const gp="workspace-files";function J4(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 X4(e){const[t,s]=f.useState(null);return f.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await T.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await T.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function Z4(e,t){return{id:gp,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 xp(e){return`agent-properties:${e}`}function e3(e){return{id:xp(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function t3(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 X1({progress:e}){return n.jsxs(Q,{gap:"sm",children:[n.jsx("span",{role:"status",children:t3(e)}),n.jsx(v1,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function n3(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(h,d)=>Math.max(0,Math.min(Math.round(h),Math.round(d)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function pf(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function Tw(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const s3=4e3;function r3(e){return e.replace(/\r\n?/g,`
|
|
104
|
+
`).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,s3)}const i3=["left","middle","right"],a3=33;function l3(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function o3(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 c3(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function u3({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=f.useState("connecting"),[l,o]=f.useState(null),[c,u]=f.useState(!1),[h,d]=f.useState(null),[m,p]=f.useState(!1),[g,y]=f.useState(0),b=f.useRef(null),x=f.useRef(null),v=f.useRef(null),j=f.useRef({at:0});f.useEffect(()=>{const E=r??(B=>new WebSocket(B));let $=!0,_;try{_=E(c3())}catch{a("lost");return}return _.binaryType="arraybuffer",b.current=_,_.onopen=()=>_.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),_.onmessage=B=>{if(!$)return;if(typeof B.data!="string"){const W=o3(B.data);if(!W||(d(D=>D&&l3(D,W.metadata)?D:W.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(W.jpeg).then(D=>{var V,Z,ue;const U=x.current;if(!$||!U){(V=D.close)==null||V.call(D);return}(U.width!==D.width||U.height!==D.height)&&(U.width=D.width,U.height=D.height),(Z=U.getContext("2d"))==null||Z.drawImage(D,0,0),(ue=D.close)==null||ue.call(D)}).catch(()=>{});return}const M=JSON.parse(B.data);if(M.type==="driving"){a("driving"),o(null);return}(M.type==="refused"||M.type==="ended")&&(o(M.error??"The screen cannot be driven from here."),a("refused"))},_.onclose=()=>{$&&a(B=>B==="refused"?B:"lost")},_.onerror=()=>{$&&a(B=>B==="refused"?B:"lost")},()=>{$=!1,b.current=null;try{_.close()}catch{}}},[e,t,g,r]),f.useEffect(()=>()=>{clearTimeout(j.current.timer)},[]);const w=f.useCallback(E=>{const $=b.current;if($)try{$.send(JSON.stringify({type:"input",input:E}))}catch{}},[]),S=E=>{var B;const $=x.current;if(!$||!h)return null;const _=(B=$.getBoundingClientRect)==null?void 0:B.call($);return _?n3(_,h,E.clientX,E.clientY):null},k=E=>{const $=j.current,_=Date.now();clearTimeout($.timer),$.timer=void 0;const B=$.at+a3-_;if(B<=0){$.at=_,$.pending=void 0,w(E);return}$.pending=E,$.timer=setTimeout(()=>{const M=j.current.pending;j.current.timer=void 0,j.current.pending=void 0,j.current.at=Date.now(),M&&w(M)},B)},N=()=>{const E=j.current;clearTimeout(E.timer),E.timer=void 0;const $=E.pending;E.pending=void 0,$&&(E.at=Date.now(),w($))},C=E=>$=>{var M,W;const _=S($);if(!_)return;E==="mousePressed"&&($.preventDefault(),(W=(M=x.current)==null?void 0:M.focus)==null||W.call(M));const B={kind:"mouse",type:E,x:_.x,y:_.y,button:i3[$.button]??"left",clickCount:E==="mouseMoved"?0:Math.min(3,Math.max(1,$.detail||1)),modifiers:pf($)};if(E==="mouseMoved"){k(B);return}N(),w(B)},I=E=>{const $=S(E);$&&(N(),w({kind:"wheel",x:$.x,y:$.y,deltaX:Math.round(E.deltaX),deltaY:Math.round(E.deltaY)}))},A=E=>E.ctrlKey||E.metaKey||E.altKey,O=E=>{var _,B;if(E.key==="Escape"&&A(E)){p(!1),(B=(_=E.target).blur)==null||B.call(_);return}if(E.preventDefault(),(E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))return;const $=pf(E);if(Tw(E.key)&&!A(E)){w({kind:"key",type:"char",key:E.key,code:E.code,text:E.key,modifiers:$});return}w({kind:"key",type:"keyDown",key:E.key,code:E.code,modifiers:$})},z=E=>{E.key==="Escape"&&A(E)||(E.preventDefault(),!((E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))&&(Tw(E.key)&&!A(E)||w({kind:"key",type:"keyUp",key:E.key,code:E.code,modifiers:pf(E)})))},L=E=>{var _;E.preventDefault();const $=r3(((_=E.clipboardData)==null?void 0:_.getData("text/plain"))??"");$!==""&&w({kind:"text",text:$})};return n.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":i,"aria-label":"Driving the host browser",children:[n.jsxs("div",{className:"hand-bar",children:[n.jsx("span",{className:"hand-said",role:"status",children:"You are driving. Nothing you type here is kept."}),n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var $,_,B,M;const E=!m;p(E),E?(_=($=v.current)==null?void 0:$.focus)==null||_.call($):(M=(B=v.current)==null?void 0:B.blur)==null||M.call(B)},children:"Keyboard"}),n.jsx(R,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(H,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),y(E=>E+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(H,{tone:"warning",role:"status",children:l}):null,n.jsx("div",{className:"hand-screen",children:c?n.jsx("canvas",{ref:x,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:C("mousePressed"),onMouseUp:C("mouseReleased"),onMouseMove:C("mouseMoved"),onWheel:I,onKeyDown:O,onKeyUp:z,onPaste:L,onContextMenu:E=>E.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.jsx("input",{ref:v,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:O,onKeyUp:z,onPaste:L,onBlur:()=>p(!1)})]})}function d3(e){return e==="darwin"?"this Mac":"this computer"}let gf=null;function Bx(){const[e,t]=f.useState(void 0);return f.useEffect(()=>{let s=!0;return gf??(gf=T.session().then(r=>r.platform,()=>{gf=null})),gf.then(r=>{s&&t(r)}),()=>{s=!1}},[]),d3(e)}function h3({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=ae(()=>T.browser(),[],3e3),a=ae(()=>T.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(wn,{embedded:e,title:"Computer & browser",children:[n.jsx(se,{message:r}),!s||!o?n.jsx(oe,{children:"Checking the host…"}):n.jsx(f3,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function f3({data:e,macOS:t,reload:s,timezone:r}){var N,C,I;const[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),h=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,d=(h==null?void 0:h.mode)??(!t&&e.mode==="computer"?"playwright":e.mode),m=d==="computer",p=(N=e.sessions)!=null&&N.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,y=async A=>{a(!0),o(null);try{await A()}catch(O){o(O instanceof Error?O.message:String(O))}finally{a(!1),s()}},b=A=>void y(()=>T.browserSettings(A)),x=e.permissions,v=d==="playwright"?e.browser:void 0,j=((C=v==null?void 0:v.install)==null?void 0:C.state)==="running",w=(v==null?void 0:v.engine)==="none",S=!!e.enabled&&!w&&!(v!=null&&v.problem)&&(!m||!(x!=null&&x.supported)||x.accessibility&&x.screenRecording),k=m?"Ready. Agents can use your computer within the apps you allow below.":d==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(v==null?void 0:v.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(Q,{gap:"lg",children:[n.jsx(se,{message:l}),n.jsx(te,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",disabled:i,onClick:()=>void y(()=>T.computerPermissions(!1)),children:"Check again"}),m&&!S&&(x!=null&&x.supported)?n.jsx(R,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void y(()=>T.computerPermissions(!0)),children:"Request macOS permissions"}):null,w||j?n.jsx(R,{size:"sm",variant:"accent",disabled:i||j,onClick:()=>void y(()=>T.browserInstall()),children:j?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(Q,{children:[e.enabled?w?n.jsxs(H,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):v!=null&&v.problem?n.jsx(H,{tone:"warning",children:v.message}):S?n.jsx(H,{tone:"good",children:k}):n.jsx(H,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(H,{tone:"warning",children:"The host is not available. Start buddi serve on a machine with a desktop session."}),m?x!=null&&x.supported?n.jsxs("ul",{className:"perm-list",children:[n.jsxs("li",{className:"perm-row",children:[n.jsx(ge,{tone:x.accessibility?"good":"warning",children:x.accessibility?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Accessibility"}),n.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),n.jsxs("li",{className:"perm-row",children:[n.jsx(ge,{tone:x.screenRecording?"good":"warning",children:x.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."})]})]}):x?n.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null:null,((I=v==null?void 0:v.install)==null?void 0:I.state)==="running"?n.jsx(X1,{progress:v.install.progress}):v!=null&&v.install?n.jsx("p",{className:"muted",role:"status",children:v.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${v.install.line??"no reason given"}`}):null,v!=null&&v.headless&&!w?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&&(x!=null&&x.message)?n.jsx("p",{className:"muted",children:x.message}):null,m&&(x!=null&&x.supported)&&!S?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(te,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(R,{variant:"danger",size:"sm",disabled:i,onClick:()=>void y(()=>T.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):n.jsx("div",{className:"ui-list",children:p.map(A=>n.jsxs("a",{className:"ui-list-row",href:Ge(A.session.agentId,A.session.conversationId),children:[n.jsx(Es,{id:A.session.agentId,name:A.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:A.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[A.session.agentId,", ",A.busy?"working":A.state,", ",A.session.steps," of ",A.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},A.session.id))})}),h?n.jsxs(n.Fragment,{children:[n.jsx(te,{title:"How agents get a screen",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(xf,{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(xf,{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(xf,{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(y3,{busy:i,timezone:r}):null]})}),t?n.jsx(te,{title:"Apps agents may use",panel:!0,children:n.jsxs(Q,{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(w3,{settings:h,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(Et,{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(C3,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:A=>{u(!1),h.allowedApps.includes(A)||b({...h,allowedApps:[...h.allowedApps,A]})}}):null]}):null]})}const m3="kmbckpnnjfggeffkkbmkggojnolkdokb",p3="",g3=[m3,p3].filter(Boolean);function x3(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 v3(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of g3)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 j3(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function y3({busy:e,timezone:t}){const{data:s,error:r,reload:i}=ae(()=>T.extension(),[],3e3),a=Bx(),l=ae(()=>v3(),[],3e3).data??null,[o,c]=f.useState(""),[u,h]=f.useState(!1),[d,m]=f.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";f.useEffect(()=>{p&&c(p)},[p]);const g=async v=>{h(!0),m(null);try{await v()}catch(j){m(j instanceof Error?j.message:String(j))}finally{h(!1),i()}},y=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,x=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(vt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]});return n.jsxs(Q,{divided:!0,children:[n.jsx(se,{message:r??d}),n.jsxs(J,{children:[n.jsx(ge,{tone:s!=null&&s.connected?"good":"warning",children:s!=null&&s.connected?"Connected":"Not connected"}),n.jsxs("span",{className:"muted",children:[s!=null&&s.connected&&s.pairedAt?`Paired with Chrome on ${a} since ${We(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(Q,{children:[n.jsxs("p",{className:"muted",children:[l?`The browser you are reading this in has the extension, version ${l.version}.`:s!=null&&s.connected?"The browser you are reading this in has no buddi extension. You only need it here to pair this browser instead.":"The browser you are reading this in has no buddi extension yet.",(l==null?void 0:l.state)==="paired"?" It is already paired with a buddi.":"",(l==null?void 0:l.state)==="disconnected"?" It is not connected yet: press Connect in its popup.":""]}),l&&(s!=null&&s.buddi)&&x3(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&&!j3(l.gateway)?n.jsx(H,{tone:"warning",children:`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in the popup.`}):null]}),s!=null&&s.pending?n.jsxs(J,{valign:"end",children:[n.jsx(ee,{grow:!0,label:"Pair your browser",hint:"Type the six digits the buddi extension is showing.",children:n.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",placeholder:"482 913",value:o,onChange:v=>c(v.target.value)})}),n.jsx(en,{}),n.jsx(R,{variant:"accent",disabled:y||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await T.pairExtension(o),c("")}),children:"Pair"})]}):null,s!=null&&s.connected?n.jsx(Et,{summary:"Pair a different browser",children:x}):x,n.jsx(J,{align:"end",children:n.jsx(R,{variant:"danger",disabled:y||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>T.forgetExtension()),children:"Forget this browser"})})]})}function xf({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 w3({settings:e,disabled:t,onChange:s,onAdd:r}){const i=ae(()=>T.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(oe,{children:"No apps yet. Agents cannot touch anything until you add one."}):n.jsx("ul",{className:"ui-list","aria-label":"Allowed apps",children:e.allowedApps.map(l=>n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:l,name:a(l),size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[a(l),l===e.browserApp?n.jsx(ge,{tone:"accent",className:"app-role",children:"browser"}):null]}),n.jsx("span",{className:"ui-list-sub mono",children:l})]}),n.jsxs(J,{children:[l!==e.browserApp&&N3(l)?n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,browserApp:l}),children:"Use as browser"}):null,l===e.browserApp?n.jsx("span",{className:"muted",children:"In use as the browser"}):n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),n.jsxs(J,{children:[n.jsx(R,{variant:"accent",disabled:t,onClick:r,children:"Add an app"}),n.jsx("span",{className:"muted",children:"The app marked as browser is the one agents open websites in."})]}),e.mode==="computer"&&b3.includes(e.browserApp)?n.jsx(k3,{settings:e,disabled:t,onChange:s}):null]})}const b3=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function k3({settings:e,disabled:t,onChange:s}){var l;const i=((l=ae(()=>T.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(ee,{label:"Browser profile",hint:e.browserProfile?"Websites open in this profile, signed in as it is.":"Not chosen: websites open in whichever profile’s window is in front, or the last one you used.",children:n.jsxs("select",{value:e.browserProfile??"",disabled:t,onChange:o=>{const{browserProfile:c,...u}=e;s(o.target.value?{...u,browserProfile:o.target.value}:u)},children:[n.jsx("option",{value:"",children:"Whichever is in front"}),!a&&e.browserProfile?n.jsxs("option",{value:e.browserProfile,children:[e.browserProfile," (not found)"]}):null,i.map(o=>n.jsxs("option",{value:o.directory,children:[o.name,o.directory==="Default"?"":` (${o.directory})`]},o.directory))]})})}const S3=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function N3(e){return S3.includes(e)}function C3({chosen:e,onClose:t,onPick:s}){const r=ae(()=>T.installedApps(),[]),[i,a]=f.useState(""),[l,o]=f.useState(""),c=f.useMemo(()=>{var d;const u=((d=r.data)==null?void 0:d.apps)??[],h=i.trim().toLowerCase();return u.filter(m=>!h||m.name.toLowerCase().includes(h)||m.id.toLowerCase().includes(h)).slice(0,60)},[r.data,i]);return n.jsxs(kt,{title:"Add an app",onClose:t,children:[n.jsx("input",{autoFocus:!0,"aria-label":"Search apps",placeholder:"Search installed apps",value:i,onChange:u=>a(u.target.value)}),n.jsx(se,{message:r.error}),r.data?c.length===0?n.jsx(oe,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const h=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:u.id,name:u.name,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:u.name}),n.jsx("span",{className:"ui-list-sub mono",children:u.id})]}),n.jsx(R,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(oe,{children:"Reading your Applications folder…"}),n.jsx(Et,{summary:"Add by bundle identifier instead",children:n.jsxs(J,{children:[n.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),n.jsx(R,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function E3({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var I,A,O;const[u,h]=f.useState(!1),[d,m]=f.useState(null),[p,g]=f.useState(null),[y,b]=f.useState(null),x=async z=>{h(!0),m(null),b(null);try{const L=z!=="stop"&&(e!=null&&e.session)?await T.browserControl(z,e.session.id):await T.browserControl(z);z==="takeover"?L.hand&&L.session?g(L.session.id):b(L.handMessage??null):g(null)}catch(L){m(L instanceof Error?L.message:String(L))}finally{h(!1),s()}},v=p&&((I=e==null?void 0:e.session)==null?void 0:I.id)===p&&e.state==="paused"?p:null,j=!!(e!=null&&e.enabled)&&!u,w=(e==null?void 0:e.mode)==="computer",S=(e==null?void 0:e.mode)==="extension",k=w?"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.",N=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",C=e!=null&&e.busy||(e==null?void 0:e.state)==="running"?"good":(e==null?void 0:e.state)==="stopped"||(e==null?void 0:e.state)==="error"?"critical":void 0;return n.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[n.jsxs("div",{className:"browser-heading",children:[n.jsxs("div",{children:[r?null:n.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),n.jsx("h2",{className:"browser-title",children:w?"Computer":S?"Your browser":"Browser"})]}),n.jsx(ge,{tone:C,children:n.jsx("span",{role:"status",children:N})})]}),r?n.jsx("a",{className:"browser-full-view",href:"#/browser",children:w?"Open computer view & settings ↗":"Open full browser view ↗"}):n.jsx("p",{className:"ui-page-lede",children:w?"Your apps, operated through macOS accessibility, screenshots and input. No browser debugging connection.":S?"Your own Chrome, signed in as you, working in background tabs grouped as “buddi”. You keep browsing.":"A real browser window, driven by your assistant. You stay in control."}),n.jsx(se,{message:t??d}),c?n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:!j||(e==null?void 0:e.state)==="stopped",onClick:()=>void x("stop"),children:w?"Stop computer control":"Stop all browsers"}),n.jsx(R,{disabled:!j||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void x("takeover"),children:"Take over"}),n.jsx(R,{disabled:!j||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void x("resume"),children:"Resume access"}),n.jsx(R,{disabled:!j||!(e!=null&&e.session),onClick:()=>void x("release"),children:w?"Release control":"Close & release"})]}):null,c?r?n.jsx(Et,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:k})}):n.jsx("p",{className:"muted",children:k}):null,y?n.jsx(H,{tone:"warning",role:"status",children:y}):null,e!=null&&e.message&&!v?n.jsx(H,{tone:"warning",role:"status",children:e.message}):null,e!=null&&e.session?n.jsxs("div",{className:"browser-task",children:[n.jsxs("div",{className:"ui-row",children:[n.jsx("strong",{children:e.session.agentId}),n.jsxs("span",{className:"muted",children:[e.session.steps," / ",e.session.maxSteps," steps"]})]}),r?null:n.jsx("p",{children:e.session.task}),n.jsxs("p",{className:"muted",children:["Last action: ",e.lastAction??"None"," · Access expires ",new Date(e.session.expiresAt).toLocaleTimeString()]})]}):n.jsx("p",{className:"browser-task muted",children:e!=null&&e.enabled?w?"No agent is driving. Ask an agent granted browser.* to open a website or an allowed native app.":"No agent is driving. Ask an agent granted browser.* to open a website.":"The host browser is unavailable. Start buddi serve on a machine with a desktop session."}),v?n.jsx(u3,{sessionId:v,csrf:Ki(),onGiveBack:()=>void x("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!v,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((A=e==null?void 0:e.page)==null?void 0:A.url)??(w?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?n.jsxs("figure",{children:[n.jsx("img",{src:a??`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:""}${i?`&tick=${i}`:""}`,alt:`Last browser observation: ${e.page.title||e.page.url}`,...l?{onError:l}:{},...o?{onLoad:o}:{}},a??e.page.id),n.jsxs("figcaption",{children:["Last observation · ",new Date(e.page.capturedAt).toLocaleTimeString()," · ",e.page.title||"Untitled page"]})]}):n.jsxs("div",{className:"browser-empty",children:[n.jsx("strong",{children:w?"Your selected app will appear here":"Your browser activity will appear here"}),n.jsx("p",{children:w?"Only the selected app window is captured, not the whole desktop. This preview is not interactive.":"This is a view of the host browser, not a second browser or a remote desktop."})]})]}),(((O=e==null?void 0:e.page)==null?void 0:O.tabs.length)??0)>1?n.jsx(Et,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(z=>n.jsxs("li",{children:[z.title||z.id," — ",z.url]},z.id))})}):null,n.jsxs("p",{className:"muted",children:[w?"Sign in directly in the host app during takeover. Don’t send passwords or MFA codes in chat. Native apps retain your existing logins and documents. Secure accessibility fields are masked; other sensitive window content can still appear in screenshots.":"Sign in directly in this conversation’s host tab during takeover. Don’t send passwords or MFA codes in chat. Agent tabs share saved logins and cookies."," ",v?"While you are driving this is a live view of the page; nothing you type is kept.":"Screenshots update after agent actions; this is not a live video feed."]})]})}const A3=2e3,T3=5;function R3(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 I3({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var j;const[l,o]=f.useState(0),[c,u]=f.useState(0),h=c>=T3;f.useEffect(()=>{if(!i||h)return;const w=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(S=>S+1)},A3);return()=>window.clearInterval(w)},[i,h]);const d=f.useRef(null);i&&(e!=null&&e.session)&&(d.current=e);const[m,p]=f.useState(null),g=f.useRef(null),y=((j=e==null?void 0:e.page)==null?void 0:j.id)??null;f.useEffect(()=>{const w=i&&e?R3(e):null;if(!w||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let S=!1;return(async()=>{try{const k=await fetch(w);if(!k.ok||S)return;const N=await k.blob();if(S)return;const C=URL.createObjectURL(N);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{S=!0}},[i,y]),f.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=d.current,x=i?e:b?m?b:{...b,hasScreenshot:!1}:e,v=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(E3,{data:x,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(w=>w+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(P3,{steps:r,newestId:(v==null?void 0:v.id)??null,focusedId:a??null,live:i})]})}function P3({steps:e,newestId:t,focusedId:s,live:r}){const i=f.useRef(null);return f.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function $3({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=ae(()=>T.host(e,t),[e,t],2e3),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],d=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return n.jsx(Et,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${d.length?` · ${d.length} running`:""}`,children:n.jsxs(Q,{gap:"sm",children:[n.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),n.jsx(se,{message:a??r}),h.map(p=>n.jsxs(J,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(R,{size:"sm",disabled:o,onClick:()=>void u(()=>T.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),d.map(p=>n.jsxs(Q,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx(vt,{children:p.command}),n.jsx(vt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
|
|
105
|
+
${p.stderr}`:"Waiting for output…"}),n.jsx(J,{children:n.jsx(R,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const Z1="browser.act",M3="browser.status",gu=new Set([Z1,M3]);function O3(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 D3(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function _3(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===Z1){const o={id:a.id,action:L3(a.input)??"act",target:F3(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:z3(a)}}return t}function Rw(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=gu.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 L3(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function F3(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 z3(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 U3({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(0);return f.useEffect(()=>{let m=!1;return o(null),u(null),(t?Le.groupConversations(t):Le.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,h]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>d(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Yl(t,m.id):Ge(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:[We(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 eC="buddi.dismissedTabs";function B3(){try{const e=JSON.parse(sessionStorage.getItem(eC)??"{}");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 Iw(e){try{sessionStorage.setItem(eC,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const W3=350,H3=60;function K3({conversationId:e,onText:t,onNotice:s}){const[r,i]=f.useState("idle"),a=f.useRef("idle"),l=v=>{a.current=v,i(v)},o=f.useRef(null),c=f.useRef(null),u=f.useRef(null),h=f.useRef(null),d=f.useRef(null),m=f.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let v;try{v=await mF(S=>{var k;return(k=d.current)==null?void 0:k.call(d,S)})}catch(S){h.current=null,l("idle"),m.current.onNotice(fF(S));return}const j=c.current;c.current=null;const w=a.current;if(j==="discard"||w!=="starting"){v.cancel(),w==="starting"&&l("idle");return}o.current=v,l("recording"),u.current=window.setTimeout(()=>void y(!1),uF),j&&y(j.sendNow)},y=async v=>{h.current=null;const j=o.current;if(!j){a.current==="starting"&&(c.current={sendNow:v});return}o.current=null,p(),l("transcribing");try{const w=await j.stop();if(w.size<=44){m.current.onNotice("Nothing was recorded.");return}const S=new File([w],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),k=await Le.attach(S),N=m.current.conversationId,C=await Le.transcribe({artifactId:k.artifactId,...N?{conversationId:N}:{}});m.current.onText(C.text,v)}catch(w){m.current.onNotice(w instanceof pe||w instanceof Error?w.message:String(w))}finally{l("idle")}},b=()=>{h.current=null;const v=o.current;if(!v){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};f.useEffect(()=>{const v=j=>{if(h.current===null)return;const w=Date.now()-h.current;h.current=null,w>=W3&&y(j.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const x=r==="starting"||r==="recording";return f.useEffect(()=>{if(!x)return;const v=j=>{j.isComposing||j.repeat||(j.key==="Escape"?(j.preventDefault(),j.stopPropagation(),b()):j.key==="Enter"&&(j.preventDefault(),j.stopPropagation(),y(j.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[x]),f.useEffect(()=>()=>{var v;(v=o.current)==null||v.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),g()},start:()=>{h.current=null,g()},finish:v=>void y(v),discard:b,levels:d}}function V3({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(ye,{name:"mic"})})}function G3({voice:e}){const t=f.useRef(null),s=e.state==="transcribing";return f.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(Y3,{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(ye,{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(ye,{name:"check"})})]})]})}function Y3({sink:e,frozen:t}){const[s,r]=f.useState(()=>Array(H3).fill(0));return f.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const q3="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",zc="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",Q3=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function J3(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(q3);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(Q3(i))return null;throw new Error(zc)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((h,d)=>{a.onloadedmetadata=()=>h(),a.onerror=()=>d(new Error(zc))}),await a.play(),await new Promise(h=>{const d=a.requestVideoFrameCallback;typeof d=="function"?d.call(a,()=>h()):setTimeout(h,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(zc);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(zc);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 Pw="Send files once the agent has answered.",vp="wb-composer-input",Wx=f.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:h,onOpenFile:d,mentions:m,history:p,threadKey:g,conversationId:y,readAloud:b,onReadAloud:x,placeholder:v},j){var nn;const w=g?`buddi.draft.${g}`:null,S=K=>{if(!K)return"";try{return window.localStorage.getItem(K)??""}catch{return""}},[k,N]=f.useState(()=>S(w)),[C,I]=f.useState([]),[A,O]=f.useState(!1),[z,L]=f.useState(null),[E,$]=f.useState(!1),_=f.useRef(null),B=f.useRef(null),[M,W]=f.useState(null),[D,U]=f.useState(0),V=M&&m?m.filter(K=>K.handle.toLowerCase().startsWith(M.query.toLowerCase())||K.name.toLowerCase().startsWith(M.query.toLowerCase())).slice(0,6):[],Z=(K,Ne)=>{if(!m||m.length===0){W(null);return}const nt=K.slice(0,Ne),St=/(^|\s)@([\w-]*)$/.exec(nt);if(!St){W(null);return}W({start:Ne-St[2].length-1,query:St[2]}),U(0)},ue=K=>{if(!M)return;const Ne=B.current,nt=Ne?Ne.selectionStart:k.length,St=`${k.slice(0,M.start)}@${K} ${k.slice(nt)}`;N(St),X<0&&ke(St),W(null),window.requestAnimationFrame(()=>{if(!Ne)return;const qt=M.start+K.length+2;Ne.focus(),Ne.setSelectionRange(qt,qt),ft()})},Ae=p??[],[X,le]=f.useState(-1),me=f.useRef(k),$e=f.useRef(w);if($e.current!==w){$e.current=w;const K=S(w);me.current=K,K!==k&&(N(K),le(-1),W(null))}const ke=K=>{if(me.current=K,!!w)try{K===""?window.localStorage.removeItem(w):window.localStorage.setItem(w,K)}catch{}},we=K=>{N(K),W(null);const Ne=B.current;Ne&&(Ne.value=K,Ne.setSelectionRange(K.length,K.length)),window.requestAnimationFrame(ft)},Ce=K=>!K.value.slice(0,K.selectionStart??K.value.length).includes(`
|
|
106
|
+
`),dt=()=>k===""||X>=0&&k===Ae[X],fe=()=>{X<0||(le(-1),we(me.current))},Me=C.some(K=>K.state==="uploading"),ce=C.length>0,Te=s&&ce,G=!t&&!Me&&!Te&&k.trim()!=="",ie=K=>{for(const Ne of Array.from(K??[])){const nt=`${Ne.name}:${Ne.size}:${Math.random().toString(36).slice(2,8)}`,St=Ne.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Ne):null;I(qt=>[...qt,{key:nt,filename:Ne.name||"Pasted image",mime:Ne.type||"application/octet-stream",sizeBytes:Ne.size,thumbnail:St,state:"uploading"}]),Le.attach(Ne).then(qt=>I(wr=>wr.map(de=>de.key===nt?{...de,state:"ready",uploaded:qt}:de))).catch(qt=>I(wr=>wr.map(de=>de.key===nt?{...de,state:"failed",error:qt instanceof pe?qt.message:String(qt)}:de)))}},Pe=K=>{K.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(K.thumbnail)},it=K=>{const Ne=C.find(nt=>nt.key===K);Ne&&(Pe(Ne),Ne.state==="ready"&&Ne.uploaded&&Le.discardAttachment(Ne.uploaded.artifactId).catch(()=>{})),I(nt=>nt.filter(St=>St.key!==K))};f.useImperativeHandle(j,()=>({addFiles:K=>{var Ne;ie(K),(Ne=B.current)==null||Ne.focus()},focus:()=>{var K;return(K=B.current)==null?void 0:K.focus()}}));const Ye=f.useRef(C);Ye.current=C,f.useEffect(()=>()=>Ye.current.forEach(Pe),[]);const at=f.useRef(0);f.useEffect(()=>{if(!l||l.at===at.current)return;at.current=l.at,N(Ne=>Ne.trim()===""?l.text:Ne),X<0&&k.trim()===""&&ke(l.text);const K=B.current;K&&(K.focus(),window.requestAnimationFrame(()=>{K.style.height="auto",K.style.height=`${Math.min(K.scrollHeight,200)}px`,K.setSelectionRange(K.value.length,K.value.length)}))},[l]);const ft=()=>{const K=B.current;K&&(K.style.height="auto",K.style.height=`${Math.min(K.scrollHeight,200)}px`)},Y=K=>{const Ne=(K??k).trim();if(K===void 0?!G:t||Me||Te||Ne==="")return;const nt=C.filter(St=>St.state==="ready"&&St.uploaded).map(St=>St.uploaded);r(Ne,nt),C.forEach(Pe),le(-1),ke(""),N(""),I([]),window.requestAnimationFrame(ft)},lt=K=>{if(M&&V.length>0){if(K.key==="ArrowDown"){K.preventDefault(),U(Ne=>(Ne+1)%V.length);return}if(K.key==="ArrowUp"){K.preventDefault(),U(Ne=>(Ne-1+V.length)%V.length);return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault(),ue(V[D].handle);return}if(K.key==="Escape"){K.preventDefault(),W(null);return}}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey){const Ne=K.currentTarget;if(Ae.length>0&&X+1<Ae.length&&Ce(Ne)&&dt()){K.preventDefault(),X<0&&(me.current=k),le(X+1),we(Ae[X+1]);return}}if(K.key==="ArrowDown"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey&&X>=0&&k===Ae[X]){if(K.preventDefault(),X===0){fe();return}le(X-1),we(Ae[X-1]);return}if(K.key==="Escape"&&X>=0){K.preventDefault(),fe();return}K.key==="Enter"&&!K.shiftKey&&(K.preventDefault(),Y())},Yt=K=>{var nt;const Ne=Array.from(((nt=K.clipboardData)==null?void 0:nt.files)??[]);Ne.length!==0&&(K.preventDefault(),ie(Ne))},Se=C.filter(K=>K.state==="failed"),De=Se.length,st=K3({conversationId:y??null,onNotice:L,onText:(K,Ne)=>{const nt=k.trim()===""?K:`${k.replace(/\s+$/,"")} ${K}`;if(Ne){Y(nt);return}we(nt),X<0&&ke(nt)}}),tt=st.state!=="idle",Mt=f.useRef(!1);return f.useEffect(()=>{var K;Mt.current&&!tt&&((K=B.current)==null||K.focus(),window.requestAnimationFrame(ft)),Mt.current=tt},[tt]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-busy":k.trim()!==""||ce||tt?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":E||tt,"data-disabled":t,"data-listening":tt||void 0,children:[C.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:C.map(K=>n.jsx("span",{role:"listitem",children:n.jsx(sh,{name:K.filename,mime:K.mime,sizeBytes:K.sizeBytes,thumbnail:K.thumbnail,state:K.state,error:K.error,onRemove:()=>it(K.key),...d&&K.state==="ready"&&K.uploaded?{onOpen:()=>d(X3(K.uploaded))}:{},size:"sm"})},K.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:vp,children:["Message ",a]}),n.jsx("textarea",{id:vp,ref:B,value:k,rows:2,placeholder:s?`${a} is working…`:v??`Message ${a}`,onChange:K=>{N(K.target.value),X<0&&ke(K.target.value),Z(K.target.value,K.target.selectionStart??K.target.value.length),ft()},onFocus:()=>$(!0),onBlur:()=>$(!1),onKeyDown:lt,onPaste:Yt,disabled:t,hidden:tt}),tt?n.jsx(G3,{voice:st}):null,!tt&&M&&V.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:V.map((K,Ne)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ne===D,className:"wb-mention","data-active":Ne===D||void 0,onMouseDown:nt=>{nt.preventDefault(),ue(K.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",K.handle]}),n.jsx("span",{className:"wb-mention-name",children:K.name})]},K.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:tt,children:[n.jsx("input",{ref:_,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:K=>{ie(K.target.files),K.target.value=""}}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Attach a file",title:"Attach a file — or paste one, or drop it anywhere on the chat",onClick:()=>{var K;return(K=_.current)==null?void 0:K.click()},disabled:t,children:n.jsx(ye,{name:"clip"})}),n.jsx(V3,{disabled:t,voice:st}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Snap a tab",title:"Snap a tab — one picture of another tab in this browser, attached here",onClick:()=>{L(null),O(!0),J3().then(K=>{var Ne;K&&(ie([K]),(Ne=B.current)==null||Ne.focus())}).catch(K=>L(K instanceof Error?K.message:String(K))).finally(()=>O(!1))},disabled:t||A,children:n.jsx(ye,{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":Uc(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${Uc(u)?"on":"off"}`:Uc(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(Uc(u)?"off":"on"),children:[n.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,x?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:()=>x(!b),children:n.jsx(ye,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":k!==""&&!s||De>0||Te||z!==null,"data-tone":De>0||z!==null?"critical":void 0,children:De>0?De===1&&((nn=Se[0])!=null&&nn.error)?Se[0].error:`${De} files failed to upload and will not be sent`:z!==null?z:Te?Pw:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:Te?Pw:Me?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>Y(),disabled:!G,children:n.jsx(ye,{name:"send"})})]})]})})});function Uc(e){return(e??"on")==="on"}function X3(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function Z3({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=f.useState("");return f.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(R,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:t,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),n.jsx("strong",{children:ez(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 ez(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 tz(e,t){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null?!1:t-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function nz(e){const t=e/36e5;if(t>=1&&Number.isInteger(t))return`${t} hour${t===1?"":"s"}`;const s=Math.round(e/6e4);return`${s} minute${s===1?"":"s"}`}function sz(e){const{lifetime:t,startedAt:s,now:r,timezone:i}=e;if(!t||t.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const a=`A conversation ends after ${nz(t.idleTimeoutMs)} idle, or once its transcript grows past ${Math.round(t.maxChars/1e3)}k characters. What the agent remembers about you carries over.`,l=`${t.messages} message${t.messages===1?"":"s"}`;if(tz(t,r))return{text:`${l} · your next message starts a fresh one`,title:a,tone:"note"};const o=s?Fe(s,r):"";return{text:o===""?l:`${l} · started ${o}`,title:s?`Started ${We(s,i)}. ${a}`:a,tone:"quiet"}}const xu=320,tC="buddi.chatWidth";function rz({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onEditGroup:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:d,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:y,requestedTab:b,onConversationOpened:x}){var Hv,Kv,Vv,Gv,Yv,qv;const v=Bx(),[j,w]=f.useState([]),[S,k]=f.useState(null),[N,C]=f.useState(null),[I,A]=f.useState(null),[O,z]=f.useState([]),[L,E]=f.useState([]),[$,_]=f.useState(null),[B,M]=f.useState(!1),[W,D]=f.useState(new Map),[U,V]=f.useState(null),[Z,ue]=f.useState(B3),[Ae,X]=f.useState([]),[le,me]=f.useState(!1),$e=f.useRef(0),ke=f.useRef(null),[we,Ce]=f.useState(!1),dt=f.useRef(g??0),fe=f.useRef(s),Me=f.useRef({agentId:s,conversationId:S});Me.current={agentId:s,conversationId:S};const ce=Z[S??""]??[],[Te,G]=f.useState(null),[ie,Pe]=f.useState(null),[it,Ye]=f.useState(null),[at,ft]=f.useState([]),[Y,lt]=f.useState(!1),[Yt,Se]=f.useState(()=>Date.now()),[De,st]=f.useState(iz),tt=f.useRef(null),[Mt,nn]=f.useState(null),[K,Ne]=f.useState(!1),[nt,St]=f.useState(null),[qt,wr]=f.useState(L1),de=f.useRef(qt);de.current=qt;const et=f.useRef(null),[Re,sn]=f.useState(null),br=f.useCallback(F=>{wr(F),F1(F),F||cl()},[]),[Jn,kr]=f.useState(null),[Sr,Nr]=f.useState(null);f.useEffect(()=>{if(!s)return;const F=cz(s);F&&St({text:F,at:Date.now()})},[s]);const qe=i?`group:${i.id}`:s??null,mn=[...t.top,...t.middle,...t.bottom],be=mn.find(F=>F.id===s)??null,Xo=ae(()=>T.providerAccounts(),[]),qs=i?i.members.map(F=>mn.find(q=>q.id===F)).filter(F=>!!F):[],[fi,pl]=f.useState(null),mi=B?fi??s??null:null;f.useEffect(()=>{o==null||o(mi)},[mi,o]),f.useEffect(()=>()=>o==null?void 0:o(null),[o]),f.useEffect(()=>{let F=!1;return Le.views().then(q=>{F||w(q.views??[])}).catch(()=>{}),()=>{F=!0}},[]),f.useEffect(()=>{if(!s)return;const F=fe.current===s;if(fe.current=s,F&&y&&y===Me.current.conversationId)return;let q=!1;return k(null),C(null),A(null),z([]),G(null),M(!1),V(null),X([]),Zo(null),Ce(!1),nn(null),y?(y!=="new"?k(y):A(qe),()=>{q=!0}):((i?Le.groupConversations(i.id):Le.conversations(s)).then(ve=>{if(q)return;const Ee=[...ve.conversations??[]].sort(az)[0];Ee?(k(Ee.id),x==null||x(s,Ee.id)):A(qe)}).catch(()=>{q||A(qe)}),()=>{q=!0})},[s,i==null?void 0:i.id,qe,y,x]);const Mn=f.useCallback(F=>Le.conversation(F).then(q=>{if(Me.current.conversationId===F){if(q.agentId!==Me.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(ve=>ve.filter(Ee=>!vf(q,Ee)))}}).catch(q=>{Me.current.conversationId===F&&G(Ar(q))}),[]);f.useEffect(()=>{if(!S)return;let F=!1;return D(new Map),E([]),Le.conversation(S).then(q=>{if(!F){if(q.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(ve=>ve.filter(Ee=>!vf(q,Ee)))}}).catch(q=>{F||G(Ar(q))}),()=>{F=!0}},[S,s]),f.useEffect(()=>{if(!S)return;let F=!1;const q=window.setInterval(()=>{Le.conversation(S).then(ve=>{F||ve.agentId!==Me.current.agentId||(C(ve),z(Ee=>Ee.filter(Be=>!vf(ve,Be))))}).catch(()=>{})},3e3);return()=>{F=!0,window.clearInterval(q)}},[S,s]),f.useEffect(()=>{if(!S)return;const F=Qd({url:Le.streamUrl(S),onEvent:q=>{var ve;switch(q.name){case"run.started":et.current=null,M(!0),_(null),pl(Qt(q.data.agentId));break;case"live":{const Ee=Qt(q.data.runId)??"",Be=Number(q.data.turn??0),_e=q.data.kind==="thinking"?"thinking":"text",pn=Qt(q.data.text)??"",Js=Date.now();if(_e==="text"){const Is=et.current;et.current=Is&&Is.runId===Ee&&Is.turn===Be?{...Is,text:Is.text+pn}:{runId:Ee,turn:Be,text:pn}}_(Is=>{const Zi=Is&&Is.runId===Ee&&Is.turn===Be?Is:{runId:Ee,turn:Be,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return _e==="thinking"?{...Zi,thinking:Zi.thinking+pn,thinkingStartedAt:Zi.thinkingStartedAt??Js}:{...Zi,text:Zi.text+pn,textStartedAt:Zi.textStartedAt??Js}});break}case"live.snapshot":{const Ee=Qt(q.data.runId)??"",Be=Number(q.data.turn??0),_e=Qt(q.data.text)??"",pn=Qt(q.data.thinking)??"",Js=Number(q.data.startedAt??Date.now());et.current={runId:Ee,turn:Be,text:_e},_({runId:Ee,turn:Be,text:_e,thinking:pn,thinkingStartedAt:pn?Js:null,textStartedAt:_e?Js:null,settled:!1});break}case"live.settle":{const Ee=Qt(q.data.runId)??"",Be=Number(q.data.turn??0);_(_e=>_e&&_e.runId===Ee&&_e.turn===Be?{..._e,settled:!0}:_e);break}case"tool.called":{const Ee=Qt(q.data.toolUseId)??Qt(q.data.id),Be=Qt(q.data.name)??Qt(q.data.tool)??"tool";Ee&&E(_e=>[..._e.filter(pn=>pn.toolUseId!==Ee),{toolUseId:Ee,name:Be,startedAt:Date.now()}]);break}case"tool.result":{const Ee=Qt(q.data.toolUseId)??Qt(q.data.id);Ee&&E(Be=>Be.filter(_e=>_e.toolUseId!==Ee)),Mn(S);break}case"message.appended":Mn(S).then(()=>{_(Ee=>Ee!=null&&Ee.settled?null:Ee)});break;case"awaiting-approval":{const Ee=Qt(q.data.approvalId)??Qt(q.data.actionId),Be=Qt(q.data.toolUseId);Ee&&Be&&D(_e=>new Map(_e).set(Be,Ee)),E(_e=>_e.filter(pn=>pn.toolUseId!==Be)),Mn(S);break}case"run.finished":{M(!1),E([]),_(null),pl(null);const Ee=Qt(q.data.message);G(Ee??null);const Be=((ve=et.current)==null?void 0:ve.text.trim())??"";et.current=null,!Ee&&Be!==""&&de.current&&ad(Be,S).then(_e=>{_e&&sn(_e)}),Mn(S);break}}}});return()=>F.close()},[S,Mn]),f.useEffect(()=>{const F=window.setInterval(()=>Se(Date.now()),L.length===0?6e4:1e3);return()=>window.clearInterval(F)},[L.length]);const pi=ae(()=>s&&S?T.browser({agentId:s,conversationId:S}):Promise.resolve(void 0),[s,S],1500),Qs=pi.error?void 0:pi.data,Cr=Qs!=null&&Qs.session&&Qs.session.agentId===s&&Qs.session.conversationId===S?Qs:void 0,It=O3(Cr,s,S),Rs=(It==null?void 0:It.id)??null,[gl,AA]=f.useState(null),Ev=Cr==null?void 0:Cr.mode;f.useEffect(()=>{It&&s&&S&&AA({agentId:s,conversationId:S,tab:D3(It,Ev)})},[Rs,Ev,s,S]);const TA=gl&&gl.agentId===s&&gl.conversationId===S&&!ce.includes(gl.tab.id)?gl.tab:null,rn=It??TA,RA=f.useMemo(()=>_3((N==null?void 0:N.messages)??[]),[N]),[IA,Zo]=f.useState(null),PA=f.useMemo(()=>MF({messages:(N==null?void 0:N.messages)??[],descriptors:j}),[N,j]),Ji=Q4(PA,S??null),ch=X4(i?null:s),Av=f.useMemo(()=>J4((N==null?void 0:N.messages)??[]),[N]),On=f.useMemo(()=>{const q=OF({messages:(N==null?void 0:N.messages)??[],descriptors:j,awaiting:W,served:Ji.served,...rn?{folded:gu}:{}}).filter(ve=>ve.source==="approval"||!ce.includes(ve.id));if(U&&!ce.includes(U)&&!q.some(ve=>ve.id===U)){const ve=FF((N==null?void 0:N.messages)??[],U,{redactInputOf:gu});ve&&!gu.has(ve.tool)&&q.push(ve)}rn&&q.push(rn);for(const ve of Ae)q.push(iL(ve));return ch&&q.unshift(Z4(ch,Av)),Mt?[...q,e3(Mt)]:q},[N,j,W,Mt,Rs,rn==null?void 0:rn.title,U,Z,S,Ae,Ji.served,ch,Av]),$A=f.useMemo(()=>{var q;const F=[];for(const ve of(N==null?void 0:N.messages)??[]){if(ve.role!=="user"||ve.speaker&&ve.speaker!=="owner")continue;const Ee=(q=ve.blocks.find(Be=>Be.type==="text"))==null?void 0:q.text.trim();Ee&&F.unshift(Ee)}return F},[N]),uh=f.useMemo(()=>On.filter(F=>F.source==="approval"),[On]),ec=uh.at(-1)??null,tc=f.useMemo(()=>[...uh.map(F=>({approvalId:F.props.approvalId,toolUseId:F.id})),...((N==null?void 0:N.delegatedApprovals)??[]).map(F=>({approvalId:F.approvalId,toolUseId:F.toolUseId??"",askedBy:fz(F.chain,mn)}))],[uh,N==null?void 0:N.delegatedApprovals]),xl=f.useMemo(()=>{for(let F=On.length-1;F>=0;F-=1){const q=On[F];if(q!=null&&q.substantial)return q.id}return null},[On]),nc=f.useRef(null),dh=((Hv=On.filter(F=>(F.source!=="browser"||F.pinned===!0)&&F.id!==gp).at(-1))==null?void 0:Hv.id)??((Kv=On.filter(F=>F.id!==gp).at(-1))==null?void 0:Kv.id)??null;f.useEffect(()=>{if(xl&&xl!==nc.current){nc.current=xl,V(xl);return}U===null&&dh&&V(dh)},[xl,U,dh]);const Tv=f.useRef(Ji.live);f.useEffect(()=>{const F=Tv.current;Tv.current=Ji.live;const q=[...Ji.live].filter(Be=>!F.has(Be));if(q.length===0||ec||U!==null&&U!==nc.current)return;const Ee=[...On].reverse().find(Be=>Be.source==="descriptor"&&Be.renderer==="preview"&&Be.props.target!==null&&q.includes($a(Be.props.target)));Ee&&V(Ee.id)},[Ji.live,On,ec,U]);const Rv=f.useRef(null);f.useEffect(()=>{Rs!==Rv.current&&(Rv.current=Rs,Rs&&!ec&&V(Rs))},[Rs,ec]);const Iv=f.useRef(null),vl=b==="browser"?(rn==null?void 0:rn.id)??null:null;f.useEffect(()=>{!vl||Iv.current===vl||(Iv.current=vl,V(vl))},[vl]);const hh=(rn==null?void 0:rn.id)??null;f.useEffect(()=>{!hh||!U||Rw((N==null?void 0:N.messages)??[],U)!==null&&(Zo(U),V(hh))},[hh,U,N]);const Pv=F=>{X(q=>q.some(ve=>ve.artifactId===F.artifactId)?q:[...q,F]),V(mu(F.artifactId)),h&&(m==null||m())},sc=!i&&be&&!be.available?ZN(be):null,$v=Jm(i?null:be),Mv=((N==null?void 0:N.offers)??[]).filter(F=>!at.includes(F.id)&&Date.parse(F.expiresAt)>Yt),MA=be&&Sr===be.id?Jn:(be==null?void 0:be.thinking)??null,OA=F=>{if(!be)return;const q=be.id;Nr(q),kr(F),T.setAgentEngine(q,{thinking:F}).catch(ve=>{Nr(null),G(ve instanceof pe?ve.message:String(ve))})},Ov=(F,q)=>{if(!s)return;const ve=q.map(_e=>_e.artifactId),Ee=B,Be={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:F},...q.map(_e=>({type:"attachment",artifactId:_e.artifactId,filename:_e.filename,mime:_e.mime,kind:_e.kind,sizeBytes:_e.sizeBytes}))],...Ee?{speaker:q1}:{}};z(_e=>Ee?[..._e,Be]:[Be]),G(null),Pe(null),M(!0),(i?Le.sendToGroup(i.id,{...S?{conversationId:S}:{},text:F,attachmentIds:ve}):Le.send(s,{...S?{conversationId:S}:{},text:F,attachmentIds:ve})).then(async _e=>{Me.current.agentId!==s||Me.current.conversationId!==S||(Pe(_e.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),_e.conversationId!==S?(C(null),k(_e.conversationId)):await Mn(_e.conversationId),_e.queued===!0&&z(pn=>pn.filter(Js=>Js.id!==Be.id)),x==null||x(s,_e.conversationId))}).catch(_e=>{z(pn=>pn.filter(Js=>Js.id!==Be.id)),G(Ar(_e)),M(!1)})},DA=F=>{G(null),Ye(F),ft(q=>[...q,F]),T.takeOffer(F,S??void 0).then(q=>{q.runId&&(Pe(null),M(!0)),S&&Mn(S)}).catch(q=>{ft(ve=>ve.filter(Ee=>Ee!==F)),G(Ar(q)),S&&Mn(S)}).finally(()=>Ye(null))},_A=(F,q)=>Dv({answer:F,...q?{optionId:q}:{}}),LA=()=>Dv({answer:"",skipped:!0}),Dv=F=>{const q=N==null?void 0:N.question;q&&(G(null),lt(!0),M(!0),Le.answerQuestion(q.id,F).then(()=>{if(S)return Mn(S)}).catch(ve=>{G(Ar(ve)),M(!1)}).finally(()=>lt(!1)))},FA=()=>{if(s){if(Mt){nn(null);return}Ne(!0),T.agentProfile(s).then(F=>{nn(F),V(xp(F.id)),h&&(m==null||m())}).catch(F=>G(Ar(F))).finally(()=>Ne(!1))}},zA=F=>{St({text:F.prompt,at:Date.now()}),l(F.agentId),h&&(p==null||p())},UA=()=>{S&&Le.cancel(S).catch(F=>G(Ar(F))).finally(()=>{M(!1),E([])})},rc=f.useCallback(()=>{if(k(null),C(null),z([]),M(!1),G(null),Pe(null),E([]),D(new Map),V(null),X([]),Zo(null),nc.current=null,i){Le.startGroupConversation(i.id).then(({conversationId:F})=>{k(F),s&&(x==null||x(s,F))}).catch(F=>G(Ar(F)));return}A(qe),s&&(x==null||x(s,"new"))},[s,i,qe,x]);f.useEffect(()=>{g&&g!==dt.current&&(dt.current=g,rc())},[g,rc]);const _v=F=>{S&&Mn(S),T.overview().catch(()=>{}),F.state!=="pending"&&D(q=>new Map([...q].filter(([,ve])=>ve!==F.id)))},ic=f.useRef(!1);f.useEffect(()=>{const F=ve=>{if(!ic.current)return;const Ee=Math.max(xu,Math.min(720,ve.clientX-52));st(Ee)},q=()=>{if(ic.current){ic.current=!1;try{De!==null&&window.localStorage.setItem(tC,String(De))}catch{}}};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",q),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",q)}},[De]);const BA=((Vv=mn.find(F=>F.id===r))==null?void 0:Vv.name)??null,Lv=i?[]:zD(be,BA),Fv=!(N&&N.conversationId===S)&&!(!S&&I!==null&&I===qe),zv=Fv?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&be?n.jsx(S1,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(Nn,{agents:mn,id:be.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${be.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:UD(be)}),Lv.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${be.name}`,children:Lv.map(F=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var q;St({text:F,at:Date.now()}),(q=ke.current)==null||q.focus()},children:F},F))}):null]})}):null,Uv=n.jsx(L4,{renderables:On,activeId:U,onActivate:V,onClose:F=>{Mt&&F===xp(Mt.id)?nn(null):Ae.some(q=>mu(q.artifactId)===F)?X(q=>q.filter(ve=>mu(ve.artifactId)!==F)):S&&ue(q=>{const ve={...q,[S]:[...new Set([...q[S]??[],F])]};return Iw(ve),ve}),U===F&&V(null)},timezone:e,onDecided:_v,onChangeAgent:zA,agents:mn,browserPanel:rn?n.jsx(I3,{status:Cr,error:pi.error,reload:pi.reload,steps:RA,live:It!==null,focusedStepId:IA},rn.id):null,descriptors:j,grantedTools:i?qs.flatMap(F=>F.tools??[]):(be==null?void 0:be.tools)??[],...be?{agentName:be.name}:{},loading:Fv,...!i&&be?{face:n.jsx(Nn,{agents:mn,id:be.id,size:"xl"})}:{}}),Bv=(Yv=(Gv=[...(N==null?void 0:N.messages)??[],...O].find(F=>F.role==="user"))==null?void 0:Gv.blocks.find(F=>F.type==="text"))==null?void 0:Yv.text.trim(),Wv=Bv?Bv.split(`
|
|
107
|
+
`)[0]:"New conversation",Xi=sz({lifetime:(N==null?void 0:N.lifetime)??null,startedAt:(N==null?void 0:N.startedAt)??null,now:Yt,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:tt,style:h||De===null?void 0:{width:De},"data-sized":!h&&De!==null?"true":void 0,"data-testid":"chat-column","data-dropping":le||void 0,onDragEnter:F=>{Bc(F)&&(F.preventDefault(),$e.current+=1,me(!0))},onDragOver:F=>{Bc(F)&&(F.preventDefault(),F.dataTransfer.dropEffect="copy")},onDragLeave:F=>{Bc(F)&&($e.current=Math.max(0,$e.current-1),$e.current===0&&me(!1))},onDrop:F=>{var q;Bc(F)&&(F.preventDefault(),$e.current=0,me(!1),s&&((q=ke.current)==null||q.addFiles(F.dataTransfer.files)))},children:[le?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(lz,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:be?`It goes with your next message to ${be.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&be?Vo(Ko(be)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face wb-head-group","aria-hidden":"true",children:qs.slice(0,3).map(F=>n.jsx(Nn,{agents:mn,id:F.id,size:"sm"},F.id))}):be?n.jsx("a",{className:"wb-head-face",href:gt(be.id),"aria-label":`${be.name}'s page`,children:n.jsx(Nn,{agents:mn,id:be.id})}):null,n.jsxs("div",{className:"wb-head-text",children:[i?n.jsx("span",{className:"wb-head-title",children:i.name}):n.jsx("span",{className:"wb-head-title",title:Wv,children:Wv}),n.jsx("span",{className:"wb-head-meta","data-tone":Xi.tone,title:i?`${qs.map(F=>F.name).join(", ")}. Coordinator: ${(be==null?void 0:be.name)??i.coordinator}.`:Xi.title,children:i?`${qs.map(F=>F.name).join(", ")} · ${Xi.text}`:be?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:gt(be.id),title:`${be.name}'s page`,children:be.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",be.handle]}),` · ${Xi.tone==="quiet"&&Xi.text==="New conversation"?`on ${v}`:Xi.text}`]}):"No agent"})]}),n.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{Ce(!1),rc()},children:n.jsx(ye,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":we,"data-open":we?"true":void 0,disabled:!s,onClick:()=>Ce(F=>!F),children:n.jsx(uz,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:On.length===0,children:["Canvas",On.length>0?` (${On.length})`:""]}):null,n.jsx(hz,{disabled:!s,items:i?[...qs.map(F=>({label:F.name,hint:F.id===i.coordinator?"Coordinator · open page":"Member · open page",href:gt(F.id)})),...a?[{label:"Members…",hint:"Name, coordinator, who is in the room",testId:"group-members",onSelect:a}]:[]]:[{label:Mt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:K,onSelect:FA},...be?[{label:"Set up",hint:"Identity, model and access",href:gt(be.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:gt(be.id)}]:[]]})]}),u?n.jsx(t1,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...mi?{working:new Set([mi])}:{}}):null]}),we&&s?n.jsx(U3,{agentId:s,...i?{groupId:i.id}:{},currentId:S,timezone:e,onNew:()=>{Ce(!1),rc()},onSelect:F=>{if(F===S){Ce(!1);return}Ce(!1),C(null),z([]),M(!1),V(null),G(null),Pe(null),X([]),k(F),x==null||x(s,F,!1)}}):null,s&&S?n.jsx($3,{agentId:s,conversationId:S},`${s}:${S}`):null,Te?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(se,{message:Te})}):null,ie?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:ie}):null,N!=null&&N.carriedOver?n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:N.carriedOver}):null,n.jsx(zx,{messages:[...(N==null?void 0:N.messages)??[],...O],live:L,now:Yt,working:B,partial:$,agents:mn,...N!=null&&N.runs?{runs:N.runs}:{},...i?{speakers:mn,coordinatorId:i.coordinator}:{},...fi?{workingAs:((qv=mn.find(F=>F.id===fi))==null?void 0:qv.name)??fi}:{},onOpenFile:Pv,onReadAloud:(F,q)=>{sn(null),ad(q,S??void 0,F).then(ve=>{ve&&sn(ve)})},onOpen:F=>{if(rn){const q=Rw([...(N==null?void 0:N.messages)??[],...O],F);if(q){Zo(q),V(rn.id),h&&(m==null||m());return}}S&&ue(q=>{const ve={...q,[S]:(q[S]??[]).filter(Ee=>Ee!==F)};return Iw(ve),ve}),V(F),h&&(m==null||m())},...be?{agentName:be.name,agentId:be.id}:{},...zv?{empty:zv}:{},emptyHint:be?`Nothing here yet. Ask ${be.name} for something.`:"Loading agents…"}),Mv.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Mv.map(F=>n.jsx("button",{className:"ui-btn",disabled:it!==null,title:F.prompt,onClick:()=>DA(F.id),children:F.label},F.id))}):null,sc?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(H,{tone:"warning",role:"status",children:[sc," ",n.jsx("a",{href:ze($v.section),children:$v.label})]})}):tc.length>0?n.jsx(v4,{approvals:tc,timezone:e,now:Yt,version:N,onDecided:_v,onSay:F=>Ov(F,[]),onOpenFull:F=>{V(F),h&&(m==null||m())}}):null,sc||tc.length>0?null:N!=null&&N.question?n.jsx(Z3,{question:N.question,disabled:Y||B,onAnswer:_A,onSkip:LA},N.question.id):null,sc?null:n.jsxs("div",{hidden:tc.length>0||!!(N!=null&&N.question),"data-testid":"composer-slot",children:[n.jsx(Wx,{ref:ke,disabled:!s,running:B,onSend:Ov,onStop:UA,agentName:i?i.name:(be==null?void 0:be.name)??"the agent",draft:nt,history:$A,threadKey:S??(i?`group:${i.id}`:s),model:i?null:(be==null?void 0:be.model)??null,setupHref:i?null:be?gt(be.id,"setup","brain"):null,thinking:MA,...!i&&be&&VS(GS(be,Xo.data))?{onThinking:OA}:{},...i?{mentions:qs.map(F=>({handle:F.handle,name:F.name}))}:{},onOpenFile:Pv,conversationId:S??null,readAloud:qt,onReadAloud:br}),Re?n.jsx("p",{className:"wb-voice-note",role:"status",children:Re}):null]})]}),h?d?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),Uv]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:F=>{var q,ve;ic.current=!0,(ve=(q=F.currentTarget).setPointerCapture)==null||ve.call(q,F.pointerId)},onKeyDown:F=>{const q=ve=>{var Ee;return ve??((Ee=tt.current)==null?void 0:Ee.offsetWidth)??xu};F.key==="ArrowLeft"&&st(ve=>Math.max(xu,q(ve)-16)),F.key==="ArrowRight"&&st(ve=>Math.min(720,q(ve)+16))}}),Uv]})]})}function iz(){try{const e=window.localStorage.getItem(tC),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=xu?t:null}catch{return null}}function az(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function Qt(e){return typeof e=="string"&&e!==""?e:null}function Ar(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function vf(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 Bc(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function lz(){return n.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})}const jp="buddi.chatDraft";function oz(e,t){try{window.sessionStorage.setItem(jp,JSON.stringify({agentId:e,text:t}))}catch{}}function cz(e){try{const t=window.sessionStorage.getItem(jp);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(jp),s.text)}catch{return null}}function uz(){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 dz(){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 hz({items:e,disabled:t}){const[s,r]=f.useState(!1),i=f.useRef(null);return f.useEffect(()=>{if(!s)return;const a=o=>{i.current&&!i.current.contains(o.target)&&r(!1)},l=o=>{o.key==="Escape"&&r(!1)};return window.addEventListener("mousedown",a),window.addEventListener("keydown",l),()=>{window.removeEventListener("mousedown",a),window.removeEventListener("keydown",l)}},[s]),n.jsxs("div",{className:"wb-head-menu",ref:i,children:[n.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":"More about this agent","aria-haspopup":"menu","aria-expanded":s,"data-open":s?"true":void 0,disabled:t,onClick:()=>r(a=>!a),children:n.jsx(dz,{})}),s?n.jsx("div",{className:"ui-menu wb-head-menu-list",role:"menu",children:e.map(a=>a.href?n.jsxs("a",{className:"ui-menu-item",role:"menuitem",href:a.href,onClick:()=>r(!1),children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label):n.jsxs("button",{className:"ui-menu-item",role:"menuitem","data-testid":a.testId,disabled:a.disabled,onClick:()=>{var l;r(!1),(l=a.onSelect)==null||l.call(a)},children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label))}):null]})}function fz(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 $w=!1;const mz=new Set(["missing","unconfigured","not-english"]);async function ad(e,t,s=null){const r=z1(s);try{const i=await Le.say({text:e,...t?{conversationId:t}:{}});return gw(r)&&await yF(i.audioUrl,i.mime,s),null}catch(i){gw(r)&&cl();const a=i instanceof pe&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&mz.has(a)&&(s!==null||!$w)?($w=!0,i.message):null}}let Zn=null;function pz(e){if(fu(e)!==null)return!1;const t=VN(e);return t!==Vt&&t!==Gr}function gz({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=f.useRef(null),l=f.useRef(s),o=`Ask ${e.name}`,[c,u]=f.useState(!1);return f.useEffect(()=>{if(s||!c||!Zn)return;const h=Qd({url:Le.streamUrl(Zn.conversationId),lastEventId:Zn.lastEventId??null,onEvent:d=>{d.name==="run.finished"&&u(!1)}});return()=>h.close()},[s,c]),f.useEffect(()=>{const h=d=>{!d.altKey||d.ctrlKey||d.metaKey||d.code!=="Slash"||(d.preventDefault(),r(!s))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s,r]),f.useEffect(()=>{var h;l.current&&!s&&((h=a.current)==null||h.focus()),l.current=s},[s]),s?n.jsx(vz,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{ref:a,type:"button",className:"wb-ask-fab","data-busy":c?"true":void 0,"aria-label":o,onClick:()=>r(!0),children:n.jsx(xz,{busy:c})})}),n.jsx(bo,{children:n.jsx(ko,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function xz({busy:e}){const[t,s]=f.useState(!1);return t?n.jsx(Zu,{size:"lg"}):n.jsx(Zd,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function vz({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=f.useRef(null),[l,o]=f.useState(Zn&&Zn.agentId===e.id?Zn.conversationId:null),[c,u]=f.useState(null),[h,d]=f.useState([]),[m,p]=f.useState([]),[g,y]=f.useState(null),[b,x]=f.useState(!1),[v,j]=f.useState(!1),[w,S]=f.useState(null),[k,N]=f.useState(null),[C,I]=f.useState(Date.now()),[A,O]=f.useState(L1),z=f.useRef(A);z.current=A;const[L,E]=f.useState(null),$=f.useRef(null),_=f.useCallback(async Z=>{try{const ue=await Le.conversation(Z);u(ue),d(Ae=>Ae.filter(X=>!jz(ue,X)))}catch{}},[]);f.useEffect(()=>{l&&_(l)},[l,_]),f.useEffect(()=>{if(!l)return;const Z=Qd({url:Le.streamUrl(l),onEvent:ue=>{var Ae;switch(ue.name){case"run.started":$.current=null,x(!0),y(null);break;case"live":{const X=Dn(ue.data.runId)??"",le=Number(ue.data.turn??0),me=ue.data.kind==="thinking"?"thinking":"text",$e=Dn(ue.data.text)??"",ke=Date.now();if(me==="text"){const we=$.current;$.current=we&&we.runId===X&&we.turn===le?{...we,text:we.text+$e}:{runId:X,turn:le,text:$e}}y(we=>{const Ce=we&&we.runId===X&&we.turn===le?we:{runId:X,turn:le,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return me==="thinking"?{...Ce,thinking:Ce.thinking+$e,thinkingStartedAt:Ce.thinkingStartedAt??ke}:{...Ce,text:Ce.text+$e,textStartedAt:Ce.textStartedAt??ke}});break}case"live.snapshot":{const X=Dn(ue.data.runId)??"",le=Number(ue.data.turn??0),me=Dn(ue.data.text)??"",$e=Dn(ue.data.thinking)??"",ke=Number(ue.data.startedAt??Date.now());$.current={runId:X,turn:le,text:me},x(!0),y({runId:X,turn:le,text:me,thinking:$e,thinkingStartedAt:$e?ke:null,textStartedAt:me?ke:null,settled:!1});break}case"live.settle":{const X=Dn(ue.data.runId)??"",le=Number(ue.data.turn??0);y(me=>me&&me.runId===X&&me.turn===le?{...me,settled:!0}:me);break}case"tool.called":{const X=Dn(ue.data.toolUseId)??Dn(ue.data.id),le=Dn(ue.data.name)??Dn(ue.data.tool)??"tool";X&&p(me=>[...me.filter($e=>$e.toolUseId!==X),{toolUseId:X,name:le,startedAt:Date.now()}]);break}case"tool.result":{const X=Dn(ue.data.toolUseId)??Dn(ue.data.id);X&&p(le=>le.filter(me=>me.toolUseId!==X)),_(l);break}case"message.appended":case"awaiting-approval":_(l).then(()=>y(X=>X!=null&&X.settled?null:X));break;case"run.finished":{x(!1),p([]),y(null);const X=Dn(ue.data.message);S(X??null);const le=((Ae=$.current)==null?void 0:Ae.text.trim())??"";$.current=null,!X&&le!==""&&z.current&&ad(le,l).then(me=>{me&&E(me)}),_(l);break}}}});return()=>{Zn&&Zn.conversationId===l&&(Zn.lastEventId=Z.lastEventId()),Z.close()}},[l,_]),f.useEffect(()=>{i(b||v)},[b,v,i]),f.useEffect(()=>{if(m.length===0)return;const Z=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(Z)},[m.length]);const B=(Z,ue)=>{j(!0),S(null);const Ae={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:Z}]};d(X=>[...X,Ae]),(async()=>{try{const X=l??(await Le.startConversation(e.id)).conversationId;X!==l&&(Zn={agentId:e.id,conversationId:X},o(X));const le=await Le.send(e.id,{conversationId:X,text:Z,...ue.length>0?{attachmentIds:ue.map(me=>me.artifactId)}:{}});le.conversationId!==X&&(Zn={agentId:e.id,conversationId:le.conversationId},o(le.conversationId)),x(!0),_(le.conversationId)}catch(X){d(le=>le.filter(me=>me.id!==Ae.id)),S(X instanceof pe?X.message:String(X)),N({text:Z,at:Date.now()})}finally{j(!1)}})()},M=()=>{l&&Le.cancel(l).catch(Z=>S(String(Z))).finally(()=>x(!1))},W=()=>{var Z;Zn=null,o(null),u(null),d([]),p([]),y(null),x(!1),S(null),(Z=a.current)==null||Z.focus()},D=Z=>{O(Z),F1(Z),Z||cl()},U=l?Ge(e.id,l):Ge(e.id),V=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(q_,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:Z=>{var ue;Z.preventDefault(),(ue=a.current)==null||ue.focus()},onCloseAutoFocus:Z=>Z.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",onClick:W,disabled:l===null&&h.length===0,children:"New"}),n.jsx(Ut,{size:"sm",variant:"ghost",href:U,onClick:Z=>{Z.preventDefault(),s(U)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(zx,{messages:V,live:m,now:C,working:b||v,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(U),onReadAloud:(Z,ue)=>{E(null),ad(ue,l??void 0,Z).then(Ae=>{Ae&&E(Ae)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[w?n.jsx(se,{message:w}):null,n.jsx(Wx,{ref:a,disabled:v||!e.available,running:b,onSend:B,onStop:M,agentName:e.name,placeholder:`Message ${e.name}…`,draft:k,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:A,onReadAloud:D}),L?n.jsx("p",{className:"wb-voice-note",role:"status",children:L}):null]})]})}function Dn(e){return typeof e=="string"?e:null}function jz(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 nC=3;function yz(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function wz(e,t){return e?t?"above-dock":"above-button":"corner"}function bz({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function kz(e){return e.state==="shown"&&e.seenAt===null}function Sz(e){const[t,s]=f.useState([]),r=f.useRef(new Set),i=f.useRef(new Set),a=f.useCallback(()=>{e&&T.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>kz(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),d=c.filter(m=>!h.has(m.id));return d.length===0?u:[...u,...d].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);f.useEffect(()=>{for(const o of t.slice(0,nC))i.current.has(o.id)||(i.current.add(o.id),T.notificationSeen(o.id).catch(()=>{}))},[t]);const l=f.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function Nz({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,nC),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":yz(l.kind),role:"status",children:[l.agentId?n.jsx(Nn,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:l.title}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:Cz(l.text)}):null,l.link?n.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),n.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${l.title}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function Cz(e){var t;return((t=e.split(`
|
|
108
|
+
`).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const Ez=3e4,Az=1e3;function Tz(e,t,s){const r=f.useRef(t);r.current=t;const i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",d=x=>{var v;l=Date.now(),T.presence(x).catch(j=>{var w;j instanceof pe&&j.status===401&&(a=!0,(w=i.current)==null||w.call(i))}),x==="active"&&((v=r.current)==null||v.call(r))},m=x=>{if(a||(o=x,c!==null))return;const v=l+Az-Date.now();if(v<=0){o=null,d(x);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const j=o;o=null,d(j)},v)},p=()=>{u=!0,h()&&m("active")},g=()=>{u=!1,m("away")},y=()=>m(h()?"active":"away");h()&&m("active");const b=window.setInterval(()=>{h()&&u&&m("active")},Ez);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",y),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",y)}},[e])}function Mw({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){return!t&&!XN(e)?n.jsx(kt,{title:"A new group",onClose:s,children:n.jsxs(H,{children:["A group needs two agents. Make another one with ",_D(e)," first."]})}):n.jsx(Iz,{agents:Rz(e,t),group:t??null,onClose:s,...r?{onCreated:r}:{},...i?{onSaved:i}:{},...a?{onArchived:a}:{}})}function Rz(e,t){const s=JN(e),r=((t==null?void 0:t.members)??[]).filter(i=>!s.some(a=>a.id===i)).map(i=>e.find(a=>a.id===i)).filter(i=>i!==void 0);return[...s,...r]}function Iz({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){var C,I;const l=t!==null,[o,c]=f.useState((t==null?void 0:t.name)??""),[u,h]=f.useState((t==null?void 0:t.members)??[]),[d,m]=f.useState((t==null?void 0:t.coordinator)??((C=e.find(A=>A.roles.includes(vx)))==null?void 0:C.id)??((I=e[0])==null?void 0:I.id)??""),[p,g]=f.useState(!1),[y,b]=f.useState(!1),[x,v]=f.useState(null),j=[...new Set([d,...u])].filter(Boolean),w=o.trim()!==""&&d!==""&&j.length>=2,S=A=>h(O=>O.includes(A)?O.filter(z=>z!==A):[...O,A]),k=async()=>{g(!0),v(null);try{t?i==null||i(await Le.updateGroup(t.id,{name:o.trim(),coordinator:d,members:j})):r==null||r(await Le.createGroup({name:o.trim(),coordinator:d,members:j.filter(A=>A!==d)}))}catch(A){v(A instanceof pe?A.message:String(A))}finally{g(!1)}},N=async()=>{if(t){g(!0),v(null);try{await Le.archiveGroup(t.id),a==null||a(t.id)}catch(A){v(A instanceof pe?A.message:String(A)),g(!1)}}};return n.jsx(kt,{title:l?`${t.name}: members`:"A new group",onClose:s,children:n.jsxs(Q,{children:[n.jsx(ee,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:o,autoFocus:!0,maxLength:80,onChange:A=>c(A.target.value),placeholder:"Household finances"})}),n.jsx(ee,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:n.jsx("select",{value:d,onChange:A=>m(A.target.value),children:e.map(A=>n.jsx("option",{value:A.id,children:A.name},A.id))})}),n.jsx(ee,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(A=>A.id!==d).map(A=>n.jsxs("label",{className:"group-pick-row","data-on":u.includes(A.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:u.includes(A.id),onChange:()=>S(A.id)}),n.jsx(Nn,{agents:e,id:A.id,size:"sm"}),n.jsxs("span",{className:"group-pick-text",children:[n.jsx("span",{className:"group-pick-name",children:A.name}),n.jsx("span",{className:"group-pick-desc",children:A.description})]})]},A.id))})}),n.jsx(H,{children:"Members read what is said in this group and what they recall from shared and group memory. Nothing an agent knows privately is brought in on its own: what enters the room is seen by the room."}),l?n.jsx(H,{children:"Taking a member out leaves everything it already said in the transcript. It simply takes no new turns."}):null,x?n.jsx(H,{tone:"critical",children:x}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!w||p,onClick:()=>void k(),children:p?l?"Saving…":"Creating…":l?"Save":"Create group"})]}),l?n.jsx("div",{className:"group-archive",children:y?n.jsxs(Q,{children:[n.jsxs(H,{tone:"warning",children:["Archive ",t.name,"? It leaves the rail and takes no new requests. Everything said in it stays readable."]}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:()=>b(!1),children:"Keep it"}),n.jsx(R,{variant:"danger",disabled:p,"data-testid":"group-archive-confirm",onClick:()=>void N(),children:"Archive group"})]})]}):n.jsx(R,{variant:"ghost",disabled:p,"data-testid":"group-archive",onClick:()=>b(!0),children:"Archive group"})}):null]})})}function Hx(e){const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,h,d)=>{var p,g,y,b;s(c),l(null),i(null);let m;try{const x=d?await T.decide(c,u,h,d):await T.decide(c,u,h);m={decision:u,...(p=x.execution)!=null&&p.state?{state:x.execution.state}:{},...x.execution&&"result"in x.execution?{result:x.execution.result}:{}},i(u==="reject"?`Rejected ${x.action.tool}.`:((g=x.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${x.action.tool}.`:`Approved ${x.action.tool}: ${((y=x.execution)==null?void 0:y.state)??"no execution"}${(b=x.execution)!=null&&b.message?` (${x.execution.message})`:""}`)}catch(x){l(x instanceof Error?x.message:String(x))}finally{s(null),e(m)}}}}function Kx({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,d;const[a,l]=f.useState(!1),{values:o,controls:c}=Ix(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(ks,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(ge,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx(vt,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",We(e.expiresAt,t)," (",Fe(e.expiresAt),"). Policy v",e.policyVersion,", args ",Co(e.argsHash,12),e.jobId?`, job ${Co(e.jobId)}`:"","."]}),c,n.jsxs(J,{children:[n.jsx(R,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(d=e.permissionScopes)!=null&&d.length?n.jsxs(n.Fragment,{children:[n.jsx(R,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(R,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(R,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":a,children:a?"Hide envelope":"Show envelope"})]}),a?n.jsxs("div",{className:"ui-card-foot",children:[n.jsx(te,{title:"Envelope: everything that decides what the world will see",children:n.jsx(vt,{children:In(e.envelope)})}),n.jsx(te,{title:"Canonical arguments",children:n.jsx(vt,{children:In(e.canonicalArgs)})})]}):null]})}function Vx(e,t,s){const[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null);return{accept:()=>{e&&(i(!0),c(null),T.acceptPluginAgent(e,t).then(h=>{l(h.agent)}).catch(h=>c(h instanceof pe?h.message:String(h))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function sC({agent:e}){return n.jsxs(H,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:Ge(e.id),children:["Talk to @",e.handle]})]})}function rC(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 Pz(e,t){var i;const s=ae(()=>T.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>rC(a,e,t)))??null,reload:s.reload}}function $z({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Hx(a=>t(a));return n.jsxs(Q,{gap:"sm",children:[n.jsx(Kx,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(se,{message:r})]})}function Gx({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var d;const l=Vx(e,t),o=Pz(e,t),[c,u]=f.useState(null),h=l.created??c;if(h)return n.jsx(sC,{agent:h});if(o.action){const m=i??((d=/@(\S+)/.exec(r))==null?void 0:d[1])??t;return n.jsxs(Q,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx($z,{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(Q,{gap:"sm",children:[n.jsxs(J,{children:[n.jsx("span",{children:s}),n.jsx(en,{}),a?n.jsx(R,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(R,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(se,{message:l.failure})]})}function iC(){var t;const e=ae(()=>T.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function aC({offers:e,reload:t}){return e.length===0?null:n.jsx(te,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(Q,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(Gx,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{T.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const Mz=512*1024,Oz=/^[A-Za-z0-9+/]*={0,2}$/;function lC(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===""||!Oz.test(r)||Math.floor(r.length*3/4)>Mz+2?null:{mime:s,data:r}}function oC(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let nr=null,Ql=null,Ro=null;const yp=new Set;function cC(){for(const e of yp)e()}function _l(){nr&&(nr.onended=null,nr.onerror=null,nr.pause()),Ql&&URL.revokeObjectURL(Ql),Ql=null,Ro!==null&&(Ro=null,cC())}async function uC(e,t){_l();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);nr??(nr=new Audio),Ql=URL.createObjectURL(new Blob([r],{type:e.mime})),Ro=t,nr.onended=_l,nr.onerror=_l,nr.src=Ql,cC();try{await nr.play()}catch{throw _l(),new Error("The browser would not play the sound.")}}function Ow(e){e!==void 0&&Ro!==e||_l()}function Dz(){return f.useSyncExternalStore(e=>(yp.add(e),()=>yp.delete(e)),()=>Ro,()=>null)}const _z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],oa=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Lz=["January","February","March","April","May","June","July","August","September","October","November","December"],Dw=/^\d{4}-\d{2}-\d{2}$/;function qr(e){return e.split("-").map(Number)}function Qi(e,t){const[s,r,i]=qr(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function dC(e){const[t,s,r]=qr(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function Yx(e){return _z[dC(e)]}function hC(e){return qr(e)[2]}function _w(e){return Qi(e,-((dC(e)+6)%7))}function or(e){const[,t,s]=qr(e);return`${Yx(e)} ${s} ${oa[t-1]}`}function Fz(e,t){return e===t?`Today · ${or(e)}`:e===Qi(t,1)?`Tomorrow · ${or(e)}`:or(e)}function wi(e){return`${String(Math.floor(e/60)).padStart(2,"0")}:${String(e%60).padStart(2,"0")}`}const Lw=new Map;function wp(e,t){let s=Lw.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"}),Lw.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 zz(e,t=new Date){return wp(t,e).date}function Uz(e,t){return e==="week"?{from:_w(t),days:7}:e==="month"?{from:_w(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function Bz(e,t,s){if(e!=="month")return Qi(t,s*7);const[r,i]=qr(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function Wz(e,t,s,r){const[i,a]=qr(t);if(e==="month")return`${Lz[a-1]} ${i}`;const l=Qi(s,r-1),[o,c,u]=qr(s),[h,d,m]=qr(l);return c===d&&o===h?`${u} – ${m} ${oa[d-1]} ${h}`:o===h?`${u} ${oa[c-1]} – ${m} ${oa[d-1]} ${h}`:`${u} ${oa[c-1]} ${o} – ${m} ${oa[d-1]} ${h}`}function aa(e){return e==null?"":String(e)}function Hz(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=aa(xe(l,t.id)),u=aa(xe(l,t.title)),h=aa(xe(l,t.start)),d=aa(xe(l,t.end));if(c===""||a.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}a.add(c);const m=t.allDay===void 0?void 0:xe(l,t.allDay),p=m===void 0?Dw.test(h):m===!0||m==="true",g=t.tone===void 0?0:Number(xe(l,t.tone)),y=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":aa(xe(l,t.calendar)),tone:y,location:t.location===void 0?"":aa(xe(l,t.location))};if(p){const S=h.slice(0,10),k=Dw.test(d.slice(0,10))&&d.slice(0,10)>S?d.slice(0,10):Qi(S,1);i.push({...b,allDay:!0,startDate:S,startMin:0,endDate:k,endMin:0});return}const x=new Date(h);if(Number.isNaN(x.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const v=new Date(d),j=wp(x,s),w=Number.isNaN(v.getTime())||v<x?j:wp(v,s);i.push({...b,allDay:!1,startDate:j.date,startMin:j.minutes,endDate:w.date,endMin:w.minutes})}),i}function Kz(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 qx(e,t){return e.map(s=>({event:s,part:Kz(s,t)})).filter(s=>s.part!==null).sort((s,r)=>Number(r.part.allDay)-Number(s.part.allDay)||s.part.from-r.part.from||r.part.to-s.part.to)}function Qx(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${wi(t.to)}`:s&&t.to===1440?`from ${wi(t.from)}`:t.from===t.to?wi(t.from):`${wi(t.from)}–${wi(t.to)}`}function bp(e,t,s){return[Qx(e,t),e.title,e.location,e.calendar,or(s)].filter(Boolean).join(", ")}const fC=30;function Vz(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+fC);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 Jx="(max-width: 900px)";function Fi(e){const[t,s]=f.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return f.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}const Gz={week:"Week",month:"Month",list:"List"},Yz=["week","month","list"],qz="(max-width: 720px)";function Qz(e){try{return window.localStorage.getItem(e)}catch{return null}}function Jz(e,t){try{window.localStorage.setItem(e,t)}catch{}}function Xz(e){const t=e.views&&e.views.length>0?e.views:Yz,s=Fi(qz),[r,i]=f.useState(()=>{const p=Qz(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=f.useState(e.today),[u,h]=f.useState(null),{from:d,days:m}=Uz(l,o);return{views:t,view:l,setView:p=>{i(p),Jz(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:Bz(l,o,p)),h(null)},from:d,days:m,to:Qi(d,m),selected:u,select:h}}function Zz({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,h=f.useMemo(()=>Array.from({length:u},(y,b)=>Qi(c,b)),[c,u]),d=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,g=y=>{if(!y.target.closest('input, textarea, select, [contenteditable="true"]')&&!(y.altKey||y.ctrlKey||y.metaKey)){if(y.key==="ArrowLeft")e.go(-1);else if(y.key==="ArrowRight")e.go(1);else if(y.key==="t"||y.key==="T")e.go(0);else return;y.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(R,{size:"sm","aria-label":`Previous ${d}`,onClick:()=>e.go(-1),children:n.jsx(ye,{name:"chevron-left",size:14})}),n.jsx(R,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(R,{size:"sm","aria-label":`Next ${d}`,onClick:()=>e.go(1),children:n.jsx(ye,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:Wz(a,l,c,u)}),e.views.length>1?n.jsx(ls,{label:"View",options:e.views.map(y=>({value:y,label:Gz[y]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(eU,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(nU,{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(y=>n.jsx(Fw,{date:y,today:o,events:t,empty:r},y))}):null,p?n.jsx(Fw,{date:p,today:o,events:t,empty:r}):null]})}function Fw({date:e,today:t,events:s,empty:r}){const i=qx(s,e);return n.jsx(Qe,{flush:!0,title:Fz(e,t),children:n.jsx(jt,{children:i.length===0?n.jsx(yt,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(yt,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:Qx(a,l)},a.id))})})}function eU({dates:e,today:t,events:s,hours:r,onPick:i}){const a=f.useRef(null);f.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:qx(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(Qe,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${or(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":or(c),children:[n.jsx("span",{className:"cal-wd",children:Yx(c)}),n.jsx("span",{className:"cal-num",children:hC(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(h=>h.part.allDay).map(({event:h,part:d})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":h.tone,"aria-label":bp(h,d,c),onClick:()=>i(c),children:h.title},h.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:wi(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":or(c),"data-today":o(c),children:Vz(u.filter(h=>!h.part.allDay)).map(({event:h,part:d,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":h.tone,"data-short":d.to-d.from<60?"true":void 0,"data-lane":m,"aria-label":bp(h,d,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${d.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(d.to-d.from,fC)/60})`,left:`calc((100% - var(--space-1)) * ${m/p} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${p} - var(--space-0))`},children:[n.jsx("span",{className:"cal-event-time",children:Qx(h,d)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const tU=3;function nU({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(h,d)=>e.slice(d*7,d*7+7)),[o,c]=t.split("-").map(Number),u=new Intl.DateTimeFormat("en-GB",{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(Date.UTC(o,c-1,1)));return n.jsx(Qe,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(h=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:Yx(h)},h))}),l.map(h=>n.jsx("div",{className:"cal-row",role:"row",children:h.map(d=>{const m=qx(r,d),p=m.slice(0,tU),g=m.length-p.length,y=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":d===i,"data-date":d,"data-today":d===s?"true":void 0,"data-outside":d.slice(0,7)!==t?"true":void 0,"data-selected":d===i?"true":void 0,onClick:()=>a(d),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${or(d)}, ${y}`,"aria-pressed":d===i,children:hC(d)}),p.map(({event:b,part:x})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":b.tone,"data-timed":x.allDay?void 0:"true","aria-label":bp(b,x,d),children:x.allDay?b.title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"cal-dot","data-tone":b.tone,"aria-hidden":"true"}),n.jsx("span",{className:"cal-chip-time",children:wi(x.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${or(d)}`,children:["+",g]}):null]},d)})},h[0]))]})})}const mC={width:1200,height:200,top:28,right:12,bottom:24,left:36};function sU(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 Wc(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function rU(e){const t=mC,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=x=>bi(t.left+l*(x+.5)),c=e.values.filter(x=>x!==null&&Number.isFinite(x)),u=sU(c,e.unit),h=u[0],d=u[u.length-1],m=x=>bi(t.top+i-(x-h)/(d-h)*i),p=e.values.map((x,v)=>{const j=x!==null&&Number.isFinite(x);return{index:v,x:o(v),y:j?m(x):null,value:j?x:null}}),g=[],y=[];if(e.kind==="area"){let x=[];const v=()=>{if(x.length===0)return;const j=x.map((w,S)=>`${S===0?"M":"L"}${w.x},${w.y}`).join(" ");g.push(j),y.push(`${j} L${x[x.length-1].x},${a} L${x[0].x},${a} Z`),x=[]};for(const j of p)j.y===null?v():x.push(j);v()}const b=e.kind==="bars"?p.flatMap(x=>x.y===null?[]:[{index:x.index,x:bi(x.x-l*.28),y:x.y,width:bi(l*.56),height:bi(a-x.y)}]):[];return{ticks:u.map(x=>({value:x,y:m(x)})),lines:g,areas:y,bars:b,points:p,slot:l,floor:a}}function iU({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var S;const[l,o]=f.useState(((S=r[0])==null?void 0:S.id)??""),[c,u]=f.useState(null),[h,d]=f.useState(null),m=f.useRef(null),p=s.length,g=c??h,y=r.find(k=>k.id===l)??r[0],b=rU(y),x=mC,v=k=>k%a===0||k===g,j=y.values.filter(k=>k!==null&&Number.isFinite(k));f.useEffect(()=>{const k=m.current,N=g===null?null:k==null?void 0:k.children[g];!k||!N||typeof k.scrollTo!="function"||(N.offsetLeft<k.scrollLeft?k.scrollTo({left:N.offsetLeft,behavior:"smooth"}):N.offsetLeft+N.offsetWidth>k.scrollLeft+k.clientWidth&&k.scrollTo({left:N.offsetLeft+N.offsetWidth-k.clientWidth,behavior:"smooth"}))},[g]);const w=k=>{var I,A,O;const N=k.key==="ArrowRight"?1:k.key==="ArrowLeft"?-1:0,C=k.key==="Home"?0:k.key==="End"?p-1:N===0?null:Math.max(0,Math.min(p-1,(h??-N)+N));C!==null&&(k.preventDefault(),d(C),(O=(A=(I=m.current)==null?void 0:I.children[C])==null?void 0:A.querySelector("button"))==null||O.focus())};return n.jsxs(Qe,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(k=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":k.id===y.id,onClick:()=>o(k.id),children:k.label},k.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":y.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${x.width} ${x.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(k=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:x.left,x2:x.width-x.right,y1:k.y,y2:k.y}),n.jsx("text",{className:"pg-series-tick",x:x.left-8,y:k.y,textAnchor:"end",dominantBaseline:"middle",children:Wc(k.value,y.unit)})]},k.value)),b.areas.map((k,N)=>n.jsx("path",{className:"pg-series-area",d:k},`a${N}`)),b.lines.map((k,N)=>n.jsx("path",{className:"pg-series-line",d:k},`l${N}`)),b.bars.map(k=>n.jsx("rect",{className:"pg-series-bar","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y,width:k.width,height:k.height},k.index)),g!==null&&b.points[g]?n.jsx("line",{className:"pg-series-guide","data-index":g,x1:b.points[g].x,x2:b.points[g].x,y1:x.top-4,y2:b.floor}):null,y.kind==="area"?b.points.map(k=>k.y!==null&&v(k.index)?n.jsx("circle",{className:"pg-series-dot","data-index":k.index,"data-hover":k.index===g?"true":void 0,cx:k.x,cy:k.y,r:k.index===g?5:3},k.index):null):null,b.points.map(k=>k.y!==null&&k.value!==null&&v(k.index)?n.jsx("text",{className:"pg-series-value","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y-(y.kind==="area"?10:6),textAnchor:"middle",children:Wc(k.value,y.unit)},k.index):null),b.points.map(k=>k.index%a===0?n.jsx("text",{className:"pg-series-x",x:k.x,y:x.height-6,textAnchor:"middle",children:s[k.index]},k.index):null),b.points.map(k=>n.jsx("rect",{className:"pg-series-hit","data-index":k.index,x:bi(x.left+b.slot*k.index),y:0,width:bi(b.slot),height:x.height,onMouseEnter:()=>u(k.index),onClick:()=>d(k.index)},k.index))]}),n.jsx("figcaption",{className:"sr-only",children:j.length===0?`${y.label}: no values.`:`${y.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Wc(Math.min(...j),y.unit)}, highest ${Wc(Math.max(...j),y.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:w,children:i.map((k,N)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":N,"data-hover":N===g?"true":void 0,"aria-pressed":N===h,"aria-label":[k.label,k.value,...k.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(N),onClick:()=>d(N),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":k.icon??"dot",children:n.jsx(ye,{name:nh(k.icon),size:22})}),k.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:k.value}):null,n.jsx("span",{className:"wb-tile-label",children:k.label}),k.lines.map((C,I)=>n.jsx("span",{className:"wb-tile-line",children:C},I))]})})},N))})]})]})}function bi(e){return Math.round(e*10)/10}const Xx=f.createContext(null),ld=f.createContext(!1);function At(){const e=f.useContext(Xx);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function kp(e,t=new Set){if(Array.isArray(e))for(const s of e)kp(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))kp(r,t)}return t}function pC(e,t){if(t.size===0)return!1;for(const s of kp(e))if(t.has(s))return!0;return!1}function gC(){const[e,t]=f.useState(!1);return f.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function xC({revealed:e,onToggle:t}){return n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function vC(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function jC({children:e}){const[t,s]=gC();return n.jsxs(Q,{gap:"sm",children:[n.jsx(J,{align:"end",children:n.jsx(xC,{revealed:t,onToggle:s})}),t?n.jsx(ld.Provider,{value:!0,children:e}):n.jsx(vC,{})]})}function Zx(e){return e===void 0||e==="neutral"?void 0:e}function Sp(e){return Zx(e)}function aU(e){const t=Zx(e);return t==="accent"?void 0:t}function ys(e,t){if(!t)return!0;const s=xe(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function ev(e,t,s){if("chat"in t){const a=Oe(s,t.chat);return a==null?"":Ge(String(a))}if("proposals"in t)return eD(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return ll(e.plugin,t.page);const i=t.item===void 0?null:Oe(s,t.item);return ni(e.plugin,t.page,i==null?null:String(i))}function lU(e,t){return e.replace(/\{count\}/g,String(t.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,i)=>(t.count??0)===1?r:i).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const i=xe(t.row,r);return i==null?"":String(i)})}function Np(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=Oe(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function yC(e,t,s){const r={};for(const[i,a]of Object.entries(e??{})){let l;"param"in a?l=s.params[a.param]:"route"in a?l=a.route==="plugin"?s.plugin:a.route==="page"?s.page:s.item:l=Oe(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function zi(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=xe(t.row,o.row);else if("field"in o){if((r=t.omit)!=null&&r.has(o.field))continue;const c=(i=t.fields)==null?void 0:i[o.field],u=(a=t.shape)==null?void 0:a.find(h=>h.name===o.field);if(c===""&&(u==null?void 0:u.required)!==!0&&(u===void 0||u.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=t.selected??[]:"param"in o?s[l]=t.scope.params[o.param]:s[l]=Oe(t.data,o);return s}function bn(e,t,s,r){const i=At(),a=e?{...yC(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=ae(()=>e?T.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function qo(){const e=At(),t=f.useId(),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(null),m=(b,x)=>{if(b.done===void 0)return null;if(typeof b.done=="string")return b.done;const v=Oe(x,b.done);return v==null?null:String(v)},p=(b,x,v)=>{const j=b??"refresh";if(typeof j=="object"){const w=ev(e,j.route,x);w===""?e.refresh():e.navigate(w);return}j==="close"&&(v==null||v()),e.refresh()},g=async(b,x,v)=>{r(b.tool),a(null),o(null);try{const j=await T.pageAct(e.plugin,{tool:b.tool,args:x});if(j.approvalId){u(j.approvalId),d({then:b.then,ref:b,...v?{onDone:v}:{}});return}u(null),d(null);const w=lC(j.result);o(m(b,j.result)??(w?oC(j.result):null)),w&&await uC(w,t),p(b.then,j.result,v)}catch(j){a(j instanceof Error?j.message:String(j)),e.refresh()}finally{r(null)}},y=b=>{if(!b){e.refresh();return}const x=h;if(u(null),d(null),x&&b.decision==="approve"&&b.state==="succeeded"){o(m(x.ref,b.result)),p(x.then,void 0,x.onDone);return}e.refresh()};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:y,run:g}}function Ga({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=f.useState(!1),u=d=>lU(d,{...i===void 0?{}:{count:i},row:a}),h=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(R,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(R,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(R,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,t),children:r&&e.busy?e.busy:h})}function od({id:e,onDecided:t}){const s=At(),r=ae(()=>T.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Hx(c=>{t?t(c):s.refresh()});return r.error?n.jsx(se,{message:r.error}):r.data?n.jsxs(Q,{children:[n.jsx(Kx,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,h,d)=>{o(c,u,h,d)}}),a?n.jsx(H,{tone:"good",role:"status",children:a}):null,n.jsx(se,{message:l})]}):n.jsx(oe,{children:"Loading the approval…"})}function ul({act:e}){return e.error?n.jsx(se,{message:e.error}):e.approvalId?e.waiting?n.jsxs(Q,{children:[n.jsx(H,{role:"status",children:e.waiting}),n.jsx(od,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(od,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(H,{tone:"good",role:"status",children:e.done}):null}function cd(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:xe(t,r.from);s[r.name]=r.multiple?Array.isArray(i)?i.map(String):[]:i!==void 0?i:r.type==="checkbox"?!1:""}return s}function wC(e,t,s){const r=At(),i=e.optionsFrom,a=i?{...yC(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=ae(()=>i?T.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:Gs(o.data,i.rows).map(c=>({value:String(xe(c,i.value)??""),label:String(xe(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function oU({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=wC(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(ee,{label:e.label,hint:l?void 0:[h,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(J_,{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(cU,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:h,children:m}):n.jsx(ee,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return n.jsx(ee,{label:e.label,hint:h,wide:!0,children:n.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return n.jsx(ee,{label:e.label,hint:h,inline:!0,wide:!l,children:n.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const d=e.type==="secret"?"password":e.type==="number"?"number":e.type;return n.jsx(ee,{label:e.label,hint:h,children:n.jsx("input",{...u,type:d,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?uU(m.target.value):m.target.value)})})}function cU({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=At(),u=f.useId(),h=Dz()===u,[d,m]=f.useState(!1),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState(null);f.useEffect(()=>()=>Ow(u),[u]);const j=tv(s,r,i),w=t.args!==void 0?zi(t.args,{data:i,fields:r,shape:s,omit:j,scope:c}):Object.fromEntries(Object.entries(r).filter(([N,C])=>!j.has(N)&&C!=="")),S=async()=>{if(h){Ow(u);return}m(!0),g(null),b(null),v(null);try{const N=await T.pageAct(c.plugin,{tool:t.tool,args:w});if(N.approvalId){v(N.approvalId);return}g(oC(N.result));const C=lC(N.result);C&&await uC(C,u)}catch(N){b(N instanceof Error?N.message:String(N))}finally{m(!1)}},k=h?"Stop":t.label;return n.jsx(ee,{label:e.label,hint:l,action:n.jsx(R,{"data-shape":"icon","aria-label":d?`${t.label}: working`:k,title:k,"aria-busy":d||void 0,"aria-pressed":t.icon==="play"?h:void 0,disabled:a===!0||d,onClick:()=>void S(),children:d?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(ye,{name:h?"stop":t.icon??"arrow"})}),after:y?n.jsx(se,{message:y}):x?n.jsx(od,{id:x,onDecided:()=>v(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function uU(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function bC(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function tv(e,t,s){const r=bC(t,s);return new Set(e.filter(i=>i.when!==void 0&&!ys(r,i.when)||i.disabledWhen!==void 0&&ys(r,i.disabledWhen)).map(i=>i.name))}function nv({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=bC(t,s);return n.jsx(bs,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||ys(o,c.when)).map(c=>n.jsx(oU,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&ys(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const Io=f.createContext(!1),kC=f.createContext(!1),SC=f.createContext(!1);function qn({title:e,note:t,actions:s,children:r}){const i=f.useContext(Io);return n.jsx(te,{title:e,aside:t,actions:s,panel:i,children:n.jsx(Io.Provider,{value:!1,children:n.jsx(kC.Provider,{value:i,children:r})})})}function Vs({component:e,data:t,choose:s,chosen:r}){const i=At(),a=f.useContext(ld);if(!ys(t,e.when))return null;if(e.kind!=="section"&&!a&&pC(e,i.sensitive))return n.jsx(jC,{children:n.jsx(Vs,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(dU,{component:e,data:t});case"notice":return n.jsx(H,{tone:Zx(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(Oe(t,e.text)??"")});case"link":return n.jsx(hU,{component:e,data:t});case"progress":return n.jsx(mU,{component:e,data:t});case"chart":return n.jsx(pU,{component:e,data:t});case"stats":return n.jsx(gU,{component:e,data:t});case"list":return n.jsx(vU,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(jU,{component:e,data:t});case"detail":return n.jsx(bU,{component:e,data:t});case"form":return n.jsx(kU,{component:e,data:t});case"search":return n.jsx(CU,{component:e,data:t});case"list-detail":return n.jsx(EU,{component:e,data:t});case"repeat":return n.jsx(AU,{component:e,data:t});case"calendar":return n.jsx(TU,{component:e,data:t});case"tiles":return n.jsx(RU,{component:e,data:t});case"series-panel":return n.jsx(IU,{component:e,data:t});case"hero":return n.jsx(PU,{component:e,data:t});case"tabs":return n.jsx($U,{component:e,data:t});case"expand":return n.jsx(MU,{component:e,data:t});case"button":return n.jsx(OU,{component:e,data:t});case"approval":return n.jsx(_U,{component:e,data:t});case"artifact":return n.jsx(LU,{component:e,data:t});case"editor":return n.jsx(FU,{component:e,data:t});case"agent-offer":return n.jsx(DU,{component:e});default:return n.jsx(H,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function dU({component:e,data:t}){const s=At(),r=f.useContext(ld),[i,a]=gC(),l=!r&&pC(e.body,s.sensitive),o=l&&!i,c=f.useContext(Io);let u=e.body.length;const h=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&h(e.body[u-1]);)u-=1;const d=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(qn,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(Vs,{component:p,data:t},g)),l?n.jsx(xC,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(Q,{gap:"lg",divided:c,children:o?n.jsx(vC,{}):n.jsx(ld.Provider,{value:r||l,children:d.map((p,g)=>n.jsx(Vs,{component:p,data:t},g))})})})}function hU({component:e,data:t}){const s=At(),r=ev(s,e.to,t);return r===""?null:n.jsx(J,{children:n.jsx(Ut,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function zw(e){return Math.round(e/1e6)}function fU(e,t){const s=Bn(Oe(t,e.value))??0,r=e.total?Bn(Oe(t,e.total)):null,i=e.total?r&&r>0?s/r:0:s,a=Math.max(0,Math.min(1,i)),l=Math.floor(a*100),o=i>=1,c=e.total&&r&&r>0?`${zw(s)} of ${Math.max(1,zw(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function mU({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Oe(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=fU(e,t);return n.jsxs(Q,{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(v1,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function pU({component:e,data:t}){const s=bn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:Gs(s.data,e.rows),i=r.map(h=>String(xe(h,e.x)??"")),a=h=>r.map(d=>Bn(xe(d,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:a(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:a(h)})),u=e.target?Bn(Oe(s.data,e.target))??null:null;return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing recorded yet."}):n.jsx(K_,{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)?Ym(h):h,formatY:h=>zt(h,"number",null)})]})}function gU({component:e,data:t}){const s=bn(e.query,t);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsx(th,{children:e.items.map((r,i)=>n.jsx(Fs,{label:r.label,value:zt(Oe(s.data,r.value),r.unit??"text",null),tone:aU(r.tone)},i))})]})}function NC(e,t,s,r){const i=(t.meta??[]).map(u=>String(Oe(s,u)??"")).filter(u=>u!==""),a=String(Oe(s,t.title)??""),l=t.to&&!r?ev(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,h)=>{const d=Oe(s,u.value);if(d==null||d==="")return null;const m=xU(u,d,s);return n.jsx(ge,{tone:Sp(m.tone),children:m.text},h)});return{text:a,href:l,pills:n.jsx(n.Fragment,{children:c}),meta:i.join(" · "),title:l?n.jsx("a",{href:l,onClick:u=>{u.preventDefault(),e.navigate(l)},children:a}):a,sub:t.sub?String(Oe(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function xU(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]:Np(e.tone,s)}}function Gs(e,t){const s=xe(e,t);return Array.isArray(s)?s:[]}function CC(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:xe(a,t),c=o==null||o===""?null:String(o);if(c===null){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: row ${l} has no value at "${t??"(no key)"}" — not drawn`);return}if(i.has(c)){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: two rows share the key "${c}" — the second is not drawn`);return}i.add(c),r.push({key:c,row:a})}),r}function vU({component:e,data:t,onChoose:s,chosen:r}){var S;const i=At(),a=f.useContext(SC),l=bn(e.query,t),o=qo(),[c,u]=f.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,d=Gs(l.data,e.rows),m=e.collapsed?Gs(l.data,e.collapsed.rows):[],p={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},g=CC([...d,...m],e.key??((S=e.select)==null?void 0:S.key),p),y=new Map(g.map(k=>[k.row,k.key])),b=new Set(g.map(k=>k.row)),x=new Set(g.filter(({row:k})=>{var N;return((N=e.select)==null?void 0:N.disabledWhen)===void 0||!ys(k,e.select.disabledWhen)}).map(({key:k})=>k)),v=c.filter(k=>x.has(k)),j=f.useMemo(()=>{const k=d.filter(C=>b.has(C));if(!e.groupBy)return[{label:null,rows:k}];const N=new Map;for(const C of k){const I=String(xe(C,e.groupBy.key)??"");N.set(I,[...N.get(I)??[],C])}return[...N].map(([C,I])=>{var A,O;return{label:((O=(A=e.groupBy)==null?void 0:A.labels)==null?void 0:O[C])??C,rows:I}})},[d,e.groupBy,g.length]),w=k=>k.map(N=>{var z;const C=NC(i,e.item,N,s),I=y.get(N);if(h&&(s||C.href))return n.jsx(j1,{href:C.href??"#",current:r===I,onClick:()=>s?s(I):i.navigate(C.href),title:C.text,meta:C.meta,sub:C.sub,side:C.pills},I);const A=((z=e.select)==null?void 0:z.disabledWhen)!==void 0&&ys(N,e.select.disabledWhen),O=(e.actions??[]).filter(L=>ys(N,L.when));return n.jsx(yt,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${C.text}`,disabled:A,checked:c.includes(I),onClick:L=>L.stopPropagation(),onChange:L=>u(E=>L.target.checked?[...E,I]:E.filter($=>$!==I))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===I?"true":void 0,onClick:L=>{L.preventDefault(),s(I)},children:C.text}):C.title,sub:C.sub,side:n.jsxs(n.Fragment,{children:[C.side,O.map((L,E)=>n.jsx(Ga,{action:L,args:zi(L.args,{data:l.data,row:N,scope:i}),disabled:o.busy,running:o.running===L.tool,row:N,onRun:($,_)=>void o.run($,_)},E))]})},I)});return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:l.error}),n.jsx(ul,{act:o}),j.every(k=>k.rows.length===0)?l.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsxs(jt,{children:[e.select?n.jsx(yt,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&v.length===x.size,disabled:x.size===0,onChange:k=>u(k.target.checked?[...x]:[])}),title:n.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,j.map((k,N)=>n.jsxs("div",{children:[k.label?n.jsx("div",{className:"ui-list-group",children:k.label}):null,w(k.rows)]},N))]}),e.collapsed&&m.some(k=>b.has(k))?n.jsx(Et,{summary:`${e.collapsed.label} (${m.filter(k=>b.has(k)).length})`,children:n.jsx(jt,{children:w(m.filter(k=>b.has(k)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(J,{align:"end",children:[n.jsxs("span",{className:"ui-toolbar-note",children:[v.length," selected"]}),e.bulk.map((k,N)=>{const C=v.length>0||k.all!==!0?v:[...x];return n.jsx(Ga,{action:k,args:zi(k.args,{data:l.data,selected:C,scope:i}),count:C.length,disabled:o.busy||C.length===0,running:o.running===k.tool,onRun:(I,A)=>{u([]),o.run(I,A)}},N)})]}):null]})}function jU({component:e,data:t}){const s=At(),r=bn(e.query,t),i=qo(),a=Gs(r.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),n.jsx(ul,{act:i}),a.length===0?r.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[e.columns.map(l=>n.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?n.jsx("th",{"aria-label":"Actions"}):null]})}),n.jsx("tbody",{children:a.map((l,o)=>n.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:zt(xe(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:yU(c,l,u),children:c.pill?n.jsx(wU,{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(J,{align:"end",children:e.actions.filter(c=>ys(l,c.when)).map((c,u)=>n.jsx(Ga,{action:c,args:zi(c.args,{data:r.data,row:l,scope:s}),disabled:i.busy,running:i.running===c.tool,row:l,onRun:(h,d)=>void i.run(h,d)},u))})}):null]},o))})]})]})}function yU(e,t,s){if(e.hint){const r=xe(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function wU({column:e,row:t}){var l,o;const s=xe(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var y;const h=c,d=typeof h=="object"&&h!==null?h.value:c;if(d==null||d==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(y=e.pill)==null?void 0:y.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(d))?p[String(d)]:zt(d,e.type??"text",null);return n.jsx(ge,{tone:Sp(Np(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(ge,{tone:Sp(Np((o=e.pill)==null?void 0:o.tone,t)),children:a})}function bU({component:e,data:t}){const s=bn(e.query,t);return s.error?n.jsx(se,{message:s.error}):s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(Q,{gap:"lg",children:[e.fields.length>0?n.jsx(Gt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:zt(Oe(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(Vs,{component:r,data:s.data},i))]})})}function kU({component:e,data:t}){const s=At(),r=bn(e.initial,t),i=qo(),[a,l]=f.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(SU,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(te,{title:e.title,aside:e.note,actions:n.jsx(R,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(ul,{act:i}),a?n.jsx(kt,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),c]})}function SU({component:e,data:t,initialData:s,act:r,onDone:i}){const a=f.useContext(kC),l=At(),[o,c]=f.useState(()=>cd(e.fields,s)),u=tv(e.fields,o,s),h=e.fields.some(d=>d.required&&!u.has(d.name)&&(o[d.name]===""||o[d.name]===void 0||Array.isArray(o[d.name])&&o[d.name].length===0));return n.jsxs(Q,{children:[n.jsx(nv,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(d,m)=>c(p=>({...p,[d]:m}))}),e.drawer?null:n.jsx(ul,{act:r}),n.jsx(J,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Ga,{action:e.submit,args:zi(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(d,m)=>void r.run(d,m,i)})})]})}function NU(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 Uw(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function CU({component:e,data:t}){const s=At(),[r,i]=f.useState(()=>cd(e.fields,t)),[a,l]=f.useState(e.auto===!0),[o,c]=f.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=bn(a&&u?e.query:void 0,t),d=Gs(h.data,e.rows),m=e.count===void 0?void 0:xe(h.data,e.count),p=e.note===void 0?void 0:xe(h.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,y=e.fields.filter(C=>C!==g),b=C=>{s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,String(C[I.name]??"")||null]))),l(!0)},x=(C,I)=>{const A={...r,[C]:I};i(A),e.auto&&b(A)},v=()=>{const C=cd(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,null]))),l(!1))},j=a?y.filter(C=>Uw(s.params[C.name])):[],w=g?j.map(C=>n.jsx(Xu,{label:C.label,onRemove:()=>{const I={...r,[C.name]:C.type==="checkbox"?!1:""};i(I),b(I)},children:NU(C,String(s.params[C.name]))},C.name)):[],S=y.filter(C=>Uw(r[C.name])).length,k=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(R,{variant:"ghost",onClick:v,children:"Clear"}):null,e.auto?null:n.jsx(R,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),N=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return n.jsx(qn,{title:e.title,children:n.jsxs(Q,{children:[n.jsx(k1,{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=>x(g.name,C.target.value)}):void 0,filters:y.length>0?n.jsx(nv,{fields:y,values:r,data:t,compact:!0,onChange:x}):void 0,...g&&y.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:S}:{},chips:w.length>0?w:void 0,actions:k}),n.jsx(se,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${zt(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?d.length===0?n.jsx(oe,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(jt,{children:d.map((C,I)=>{const A=NC(s,N,C);return n.jsx(yt,{title:A.title,sub:A.sub,side:A.side},I)})})}):null]})})}function EU({component:e,data:t}){const s=At(),r=e.selection==="local",[i,a]=f.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(Q,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>n.jsx(Vs,{component:u,data:t},h))});return n.jsx(Io.Provider,{value:!1,children:n.jsx(y1,{list:n.jsx(SC.Provider,{value:!0,children:n.jsx(Vs,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(Xx.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function AU({component:e,data:t}){const s=At(),[r,i]=f.useState(!1),a=bn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&ys(a.data,e.poll.while);f.useEffect(()=>i(l),[l]);const o=Gs(a.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:a.error}),o.length===0?a.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsx(Q,{gap:"lg",divided:!0,children:CC(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(te,{children:n.jsx(Q,{children:e.body.map((h,d)=>n.jsx(Vs,{component:h,data:u},d))})},c))})]})}function TU({component:e,data:t}){const s=At(),r=Xz({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:zz(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=bn(e.query,t,void 0,{from:r.from,to:r.to}),a=f.useMemo(()=>Hz(Gs(i.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[i.data,e.events,e.map,s.timezone,s.plugin,s.page]);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:i.error}),n.jsx(Zz,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function RU({component:e,data:t}){var d;const s=At(),r=bn(e.query,t),i={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},a=Gs(r.data,e.items).flatMap(m=>{const p=Sx([m],i).tiles[0];return p?[{tile:p,key:e.select?String(xe(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((d=a[0])==null?void 0:d.key)??"",u=l?s.params[l.param]:void 0,h=a.some(m=>m.key===u);return f.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),r.data===void 0?n.jsx(oe,{children:"Loading…"}):a.length===0?n.jsx(dl,{text:e.empty??"Nothing to show."}):n.jsx(O1,{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 IU({component:e,data:t}){const s=bn(e.query,t),r=Gs(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),s.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(xe(c,e.x)??"")),a={items:"$",icon:e.tiles.icon,value:e.tiles.value,label:e.tiles.label,...e.tiles.lines?{lines:e.tiles.lines}:{}},l=r.map((c,u)=>Sx([c],a).tiles[0]??{icon:null,value:"",label:i[u]??"",lines:[],tone:"neutral",link:null}),o=e.series.map(c=>({id:c.id,label:c.label,kind:c.kind,...c.unit?{unit:c.unit}:{},values:r.map(u=>Bn(xe(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:s.error}),n.jsx(iU,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function PU({component:e,data:t}){const s=bn(e.query,t),r=o=>{const c=xe(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:s.error}),n.jsx(oe,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const i=r(e.value),a=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return n.jsxs("section",{className:"pg-hero","aria-label":[i,a,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[n.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[n.jsx("span",{className:"pg-hero-icon",children:n.jsx(ye,{name:nh(tp(Oe(s.data,e.icon))),size:44})}),n.jsx("span",{className:"pg-hero-value",children:i}),a?n.jsx("span",{className:"pg-hero-title",children:a}):null]}),l.length>0?n.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>n.jsxs("div",{className:"pg-hero-fact",children:[n.jsx("dt",{children:o.label}),n.jsx("dd",{children:o.value})]},o.label))}):null]})}function $U({component:e,data:t}){var u;const s=At(),[r,i]=f.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=wC({name:(a==null?void 0:a.param)??"",label:(a==null?void 0:a.label)??"",...a!=null&&a.options?{options:a.options}:{},...a!=null&&a.optionsFrom?{optionsFrom:a.optionsFrom}:{}},{},t),o=a?l.some(h=>h.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(h=>h.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar",children:[a&&l.length>1?n.jsx(ls,{label:a.label,options:l,value:o,onChange:h=>s.setParams({[a.param]:h})}):null,n.jsx(ls,{label:e.title??"View",options:e.tabs.map(h=>({value:h.id,label:h.label})),value:c.id,onChange:i})]}),c.body.map((h,d)=>n.jsx(Vs,{component:h,data:t},`${c.id}-${d}`))]})}function MU({component:e,data:t}){const[s,r]=f.useState(!1),i=bn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Oe(t,e.label)??"");return n.jsxs(Et,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(se,{message:i.error}),i.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(Q,{children:e.body.map((l,o)=>n.jsx(Vs,{component:l,data:i.data},o))})]})}function OU({component:e,data:t}){const s=At(),r=qo();return n.jsxs(n.Fragment,{children:[n.jsx(J,{align:"end",children:n.jsx(Ga,{action:e.action,args:zi(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(ul,{act:r})]})}function DU({component:e}){const t=At();return n.jsx(Gx,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function _U({component:e,data:t}){const s=xe(t,e.path);return typeof s!="string"||s===""?null:n.jsx(od,{id:s})}function LU({component:e,data:t}){const s=xe(t,e.path);return typeof s!="string"||s===""?null:n.jsx(J,{children:n.jsx("a",{href:si(s),children:e.label})})}function FU({component:e,data:t}){const s=bn(e.query,t),r=qo();return s.error?n.jsx(se,{message:s.error}):s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(ul,{act:r}),n.jsx(zU,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function zU({component:e,data:t,loaded:s,act:r}){const i=At(),[a,l]=f.useState(()=>cd(e.fields,s)),o={...a,version:xe(s,e.version)},c=tv(e.fields,a,s),u=e.readOnlyWhen!==void 0&&ys(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),d=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Ga,{action:p,args:zi(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(y,b)=>void r.run(y,b)},`${p.tool}-${g}`);return n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(Q,{children:[n.jsx(nv,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(y=>({...y,[p]:g}))}),u?null:n.jsxs(J,{align:"end",children:[h.map(m),h.length>0?n.jsx(en,{}):null,m(e.save,-1),d.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function sv({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a}){const[l,o]=f.useState({}),[c,u]=f.useState(0),h={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...l,...t?{item:t}:{},...BU(e,t)},setParams:g=>o(y=>{const b={...y};for(const[x,v]of Object.entries(g))v===null?delete b[x]:b[x]=v;return b}),navigate:s,timezone:r,version:c,refresh:()=>u(g=>g+1),sensitive:new Set(e.sensitive??[])},d=e.body[0],m=!i&&(d==null?void 0:d.kind)==="notice"&&typeof d.text=="string"&&d.when===void 0&&d.title===void 0&&(d.tone===void 0||d.tone==="neutral")?d.text:void 0,p=m===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(Xx.Provider,{value:h,children:n.jsx(wn,{embedded:i,title:e.title,lede:m,children:n.jsx(UU,{page:p,boxed:i===!0})})})}function UU({page:e,boxed:t}){const s=At();return e.data&&s.sensitive.has(e.data.query)?n.jsx(jC,{children:n.jsx(Bw,{page:e,boxed:t})}):n.jsx(Bw,{page:e,boxed:t})}function Bw({page:e,boxed:t}){const s=bn(e.data,null);return n.jsxs(Q,{gap:"lg",divided:!t,children:[n.jsx(se,{message:s.error}),n.jsx(Io.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(Vs,{component:r,data:s.data??null},i))})]})}function BU(e,t){if(!t)return{};const s=[],r=i=>{for(const a of i)a.kind==="list-detail"?(s.push(a.param),r(a.detail)):(a.kind==="section"||a.kind==="detail"||a.kind==="expand")&&r(a.body)};return r(e.body),Object.fromEntries(s.map(i=>[i,t]))}function WU(e){return n.jsx(sv,{...e,embedded:!0})}function dl({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 Ww=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],HU=["","image","pdf","table","text","code","audio","video","archive","file"];function KU({hash:e,timezone:t,navigate:s,agents:r}){var L;const i=HO(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,h]=f.useState(c);f.useEffect(()=>{h(c)},[c]);const d=(E,$=!1)=>s(Pc(a,{q:c,origin:l,family:o,...E}),$);f.useEffect(()=>{if(u===c)return;const E=window.setTimeout(()=>d({q:u},!0),250);return()=>window.clearTimeout(E)},[u]);const[m,p]=f.useState(null),[g,y]=f.useState(null),[b,x]=f.useState(null),[v,j]=f.useState(!1),[w,S]=f.useState(!1),k=E=>{var $;return E?(($=r.find(_=>_.id===E))==null?void 0:$.name)??E:""},N=f.useRef(0);f.useEffect(()=>{const E=++N.current;p(null),y(null),j(!1),x(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then($=>{N.current===E&&(p($.entries),y($.next))}).catch($=>{N.current===E&&x($ instanceof pe?$.message:String($))})},[c,l,o]);const C=()=>{if(!g||v)return;j(!0);const E=N.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then($=>{N.current===E&&(p(_=>{const B=new Set((_??[]).map(M=>M.id));return[..._??[],...$.entries.filter(M=>!B.has(M.id))]}),y($.next))}).catch($=>{N.current===E&&x($ instanceof pe?$.message:String($))}).finally(()=>{N.current===E&&j(!1)})},I=(l?1:0)+(o?1:0),A=((L=Ww.find(E=>E.id===l))==null?void 0:L.label)??l,O=n.jsxs(n.Fragment,{children:[m===null?n.jsx(oe,{children:"Loading…"}):m.length===0?n.jsx(oe,{children:"No file matches that."}):n.jsx(jt,{children:m.map(E=>n.jsx(j1,{href:Pc(E.id,{q:c,origin:l,family:o}),current:E.id===a,onClick:()=>s(Pc(E.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":E.family,children:E.family==="image"&&!E.deleted?n.jsx("img",{src:gr(E.id),alt:"",loading:"lazy"}):n.jsx(Fx,{family:E.family})}),title:E.filename??"Untitled file",meta:n.jsx("span",{title:We(E.createdAt,t),children:Fe(E.createdAt)}),sub:`${Ti[E.family]} · ${$n(E.sizeBytes)} · ${EC(E,k)}${VU(E,k)}`},E.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(R,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),z=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return n.jsxs("div",{className:"ui-page files","data-selected":a?"true":void 0,children:[n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Files"}),n.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),z?n.jsx(tn,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):n.jsxs(n.Fragment,{children:[n.jsx(k1,{label:"Files",onSubmit:()=>d({q:u},!0),main:n.jsx("input",{type:"search",value:u,placeholder:"Search by filename","aria-label":"Search files by name",onChange:E=>h(E.target.value)}),filters:n.jsxs(bs,{dense:!0,children:[n.jsx(ee,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:E=>d({origin:E.target.value}),children:Ww.map(E=>n.jsx("option",{value:E.id,children:E.label},E.id))})}),n.jsx(ee,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:E=>d({family:E.target.value}),children:HU.map(E=>n.jsx("option",{value:E,children:E===""?"Any kind":Ti[E]},E))})})]}),filtersOpen:w,onToggleFilters:()=>S(E=>!E),active:I,chips:I>0?n.jsxs(n.Fragment,{children:[l?n.jsx(Xu,{label:"Origin",onRemove:()=>d({origin:""}),children:A}):null,o?n.jsx(Xu,{label:"Kind",onRemove:()=>d({family:""}),children:Ti[o]}):null]}):void 0}),n.jsx(se,{message:b}),n.jsx(y1,{className:"files-split",label:"Files",list:O,detail:a?n.jsx(GU,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(Pc(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function VU(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 EC(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 GU({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null);f.useEffect(()=>{let v=!1;return l(null),h(null),T.libraryEntry(e).then(j=>{v||l(j)}).catch(j=>{v||h(j instanceof pe&&j.status===404?"This file is no longer in the library.":j instanceof pe?j.message:String(j))}),()=>{v=!0}},[e]);const d=v=>{var j;return v?((j=s.find(w=>w.id===v))==null?void 0:j.name)??v:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(H,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(oe,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:y}=a,b=m.filename??"Untitled file",x=()=>{c(!0),T.libraryEntry(e,p.length).then(v=>l(j=>j&&{...j,contexts:[...j.contexts,...v.contexts],contextsTotal:v.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsxs("header",{className:"files-detail-head",children:[n.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:n.jsx(Fx,{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:[Ti[m.family]," · ",$n(m.sizeBytes)," · ",We(m.createdAt,t)]})]}),y?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:si(m.id),download:b,children:"Download"}):null]}),y?null:n.jsx(H,{tone:"warning",children:"The file's bytes are no longer on this machine. What is known about it stays here; the download will not work."}),n.jsx(W1,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:y}),n.jsx(Gt,{items:[{label:"Origin",value:EC(m,d)},...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(Nn,{agents:s,id:m.agentId,size:"sm"}),d(m.agentId)]})}]:[],{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:n.jsx("span",{className:"mono",children:m.id})}]}),n.jsxs("section",{className:"files-conversations",children:[n.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?n.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):n.jsx("ul",{className:"files-ctx",role:"list",children:p.map(v=>{const j=v.groupId?Yl(v.groupId,v.conversationId):Ge(v.conversationAgentId,v.conversationId),w=v.groupId?v.groupName??"a group":d(v.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:v.groupId?`Group: ${w}`:w}),n.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${d(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",Fe(v.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:j,onClick:S=>{S.preventDefault(),r(j)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<g?n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",onClick:x,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const YU={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 AC(e){return e&&YU[e]||"plug"}const TC="a connection needs you";function qU({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:d}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:Vt,onClick:m=>{m.preventDefault(),s(Vt)},"aria-label":"buddi home",children:n.jsx(Zu,{})}),sD.filter(m=>m.route!==dn).map(m=>n.jsx(jf,{label:m.label,href:m.route,active:t===m.route,badge:m.route===Vt?e:0,onClick:()=>s(m.route),children:Hw[m.route]},m.route)),a.map(m=>{const p=ni(m.plugin,m.id);return n.jsx(jf,{label:m.title,href:p,active:t===p,badge:0,onClick:()=>s(p),children:n.jsx(ye,{name:AC(m.icon)})},p)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(jf,{label:"Settings",href:dn,active:t===dn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(dn),children:Hw[dn]}),n.jsx(JU,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:d})]})}const QU=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function JU({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var v,j,w;const o=ae(()=>T.owner(),[]),c=ae(()=>T.focus(),[],6e4),u=((v=c.data)==null?void 0:v.focus)??null,h=(S,k)=>{T.setFocus(S,k).finally(()=>c.reload())},d=((w=(j=o.data)==null?void 0:j.preferredName)==null?void 0:w.trim())||null,m=(d??"You").slice(0,1).toUpperCase(),[p]=f.useState(jD),[g]=f.useState(e6),y=d?`You: ${d}`:"You",b=u?`${Ll[u.mode]} ${RC(u,l)}`:null,x=[y,b,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Vd,{modal:!1,children:[n.jsx(Gd,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":x,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:m}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,u?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(ye,{name:"moon",size:10})}):null]})}),n.jsx(Ho,{children:n.jsxs(Yd,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[n.jsxs("div",{className:"rail-owner-head",children:[n.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:m}),n.jsxs("span",{className:"rail-owner-who",children:[n.jsx("span",{className:"rail-owner-name",children:d??"You"}),n.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),n.jsx(Or,{className:"ui-menu-sep"}),n.jsx(ZU,{focus:u,timezone:l,onSwitch:h}),n.jsx(Or,{className:"ui-menu-sep"}),n.jsx(qd,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(ls,{label:"Theme",options:QU,value:e,onChange:t})}),n.jsx(Or,{className:"ui-menu-sep"}),n.jsx(Ai,{className:"ui-menu-item",onSelect:()=>s(ze("appearance")),children:"Change appearance"}),p||i?n.jsxs(Ai,{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"}),g?n.jsx("kbd",{className:"rail-owner-kbd",children:g}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Or,{className:"ui-menu-sep"}),n.jsxs(Ai,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(ze("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 Ll={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},XU=[{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 RC(e,t,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),i=t?{timeZone:t}:{},a=c=>new Intl.DateTimeFormat("en-CA",{...i,dateStyle:"short"}).format(c),l=new Intl.DateTimeFormat("en-GB",{...i,hour:"2-digit",minute:"2-digit"}).format(r);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-GB",{...i,weekday:"short"}).format(r)} ${l}`}function ZU({focus:e,timezone:t,onSwitch:s}){return n.jsxs(mO,{children:[n.jsxs(pO,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?Ll[e.mode]:"Off"})]}),n.jsx(Ho,{children:n.jsxs(gO,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Ll[e.mode]} ${RC(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(zN,{children:[n.jsx(Or,{className:"ui-menu-sep"}),n.jsx(qd,{className:"ui-menu-label",children:Ll[r]}),XU.map(i=>n.jsx(Ai,{className:"ui-menu-item","aria-label":`${Ll[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Or,{className:"ui-menu-sep"}),n.jsx(Ai,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function e6(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function jf({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 Hw={[Li]:n.jsx(ye,{name:"files"}),[Vt]:n.jsx(ye,{name:"home"}),[Gr]:n.jsx(ye,{name:"chat"}),[pt]:n.jsx(ye,{name:"agents"}),[Ct]:n.jsx(ye,{name:"activity"}),[dn]:n.jsx(ye,{name:"settings"})},Po=e=>`${e.plugin}:${e.id}`,t6=new Set;let rv=t6,Kw=!1;const Cp=new Set;function Ep(e){rv=e;for(const t of Cp)t()}function n6(e){return Cp.add(e),()=>Cp.delete(e)}const Vw=()=>rv;function s6(){Kw||(Kw=!0,Promise.resolve().then(()=>T.rail()).then(e=>Ep(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function r6(e,t){const s=rv,r=new Set(s);t?r.add(Po(e)):r.delete(Po(e)),Ep(r);try{await T.setRailHidden(e.plugin,e.id,t)}catch(i){throw Ep(s),i}}function IC(){return f.useEffect(s6,[]),f.useSyncExternalStore(n6,Vw,Vw)}function i6(e,t){return e.filter(s=>!t.has(Po(s)))}function a6(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function l6(e,t=!0,s){f.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||a6(i.target))return;i.preventDefault();const a=document.getElementById(vp);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(Vt)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const PC="buddi.theme";function o6(e=$C()){try{const t=e==null?void 0:e.getItem(PC);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function c6(e,t=$C()){try{t==null||t.setItem(PC,e)}catch{}}function u6(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function $C(){try{return window.localStorage}catch{return}}const MC="buddi.ground",OC="buddi.pageWidth";function d6(e=LC()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(MC),r=t(OC);return{theme:o6(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function DC(e,t=document.documentElement){t&&(u6(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 h6(e,t=LC()){c6(e.theme,t);try{t==null||t.setItem(MC,e.ground),t==null||t.setItem(OC,e.width)}catch{}}let Ma=null;const Ap=new Set;function Tp(){return Ma||(Ma=d6()),Ma}function f6(e){return Ap.add(e),()=>Ap.delete(e)}function m6(e){Ma={...Tp(),...e},DC(Ma),h6(Ma);for(const t of Ap)t()}function _C(){return[f.useSyncExternalStore(f6,Tp,Tp),m6]}function LC(){try{return window.localStorage}catch{return}}function p6({timezone:e,embedded:t}){var m,p;const{data:s,error:r,reload:i}=ae(()=>T.sentinels(),[],3e4),a=ae(()=>T.missions(),[]),[l,o]=f.useState(null),c=((p=(m=a.data)==null?void 0:m.missions.find(g=>g.id==="sentinel-wake"))==null?void 0:p.agentId)??null,u=async(g,y)=>{o(null);try{await T.snoozeAlert(g,y),i()}catch(b){o(b instanceof Error?b.message:String(b))}},h=((s==null?void 0:s.open)??[]).filter(g=>!g.snoozedAt),d=((s==null?void 0:s.open)??[]).filter(g=>g.snoozedAt);return n.jsxs(wn,{embedded:t,title:"Alerts",lede:"What the watchers found.",children:[n.jsx(se,{message:r??l}),n.jsx(H,{children:"An alert closes on its own once the fact behind it changes: record the payment, update the balance, and the watcher clears it on its next run. Snooze one you have decided to live with; it stays quiet until it resolves."}),n.jsx(yf,{title:"Open",findings:h,timezone:e,askAgentId:c,onSnooze:g=>u(g,!0),empty:"Nothing open. Your watchers are quiet."}),d.length>0?n.jsx(yf,{title:"Snoozed",findings:d,timezone:e,askAgentId:c,onSnooze:g=>u(g,!1),empty:""}):null,n.jsx(yf,{title:"Resolved",findings:(s==null?void 0:s.resolved)??[],timezone:e,empty:"Nothing has resolved yet."}),n.jsx(Qe,{title:"Waiting for the weekly recap",flush:!0,children:!s||s.digest.length===0?n.jsx(tn,{icon:"bell",title:"Nothing waiting for the recap"}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Title"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Noted"})]})}),n.jsx("tbody",{children:s.digest.map(g=>n.jsxs("tr",{children:[n.jsxs("td",{children:[Wa(g.title),n.jsx(zC,{text:Wa(g.detail)})]}),n.jsx("td",{children:n.jsx(FC,{severity:g.severity})}),n.jsx("td",{className:"nowrap",children:We(g.createdAt,e)})]},g.id))})]})})]})}function FC({severity:e}){return n.jsx(ge,{tone:e==="urgent"?"critical":void 0,children:e})}function zC({text:e}){const[t,s]=f.useState(!1),r=e.length>240||e.split(`
|
|
109
|
+
`).length>3;return n.jsxs("div",{className:"sub alert-detail","data-clamp":r&&!t?"true":void 0,children:[e,r?n.jsx("button",{type:"button",className:"wb-link alert-more",onClick:()=>s(i=>!i),children:t?"Less":"More"}):null]})}function g6(e){return`About this alert: "${Wa(e.title)}". ${Wa(e.detail)}
|
|
110
|
+
|
|
111
|
+
What should I do about it, and what do you need from me to clear it?`}function yf({title:e,findings:t,timezone:s,askAgentId:r,onSnooze:i,empty:a}){const l=e==="Snoozed";return n.jsx(Qe,{title:e,flush:!0,children:t.length===0?n.jsx(oe,{children:a}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Finding"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Since"}),i?n.jsx("th",{}):null]})}),n.jsx("tbody",{children:t.map(o=>n.jsxs("tr",{children:[n.jsxs("td",{children:[n.jsx("strong",{children:Wa(o.title)}),n.jsx(zC,{text:Wa(o.detail)}),o.data?n.jsx(Et,{summary:"evidence",children:n.jsx(vt,{children:In(o.data)})}):null]}),n.jsx("td",{children:n.jsx(FC,{severity:o.severity})}),n.jsxs("td",{className:"nowrap",children:[We(o.firstSeenAt,s),n.jsxs("div",{className:"sub",title:We(o.lastSeenAt,s),children:["last seen ",Fe(o.lastSeenAt)]})]}),i?n.jsx("td",{children:n.jsxs(J,{align:"end",children:[r?n.jsx(Ut,{size:"sm",href:Ge(r,"new"),onClick:()=>oz(r,g6(o)),children:"Ask about it"}):null,n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(o.key),children:l?"Wake":"Snooze"})]})}):null]},o.key))})]})})}const Gw=5e3,Yw=50;function x6({timezone:e,embedded:t}){var x;const[s,r]=f.useState(""),[i,a]=f.useState(""),[l,o]=f.useState(null),c=ae(()=>T.eventKinds(),[]),{data:u,error:h}=ae(()=>T.events({kind:s||void 0,q:i||void 0,limit:Yw}),[s,i],Gw),[d,m]=f.useState({events:[],cursor:null,busy:!1,error:null});f.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);const p=d.events.length>0?d.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(v=>({...v,busy:!0,error:null}));try{const v=await T.events({kind:s||void 0,q:i||void 0,before:p,limit:Yw});m(j=>({events:[...j.events,...v.events],cursor:v.nextCursor,busy:!1,error:null}))}catch(v){m(j=>({...j,busy:!1,error:v instanceof Error?v.message:String(v)}))}}},y=new Set(((u==null?void 0:u.events)??[]).map(v=>v.id)),b=[...(u==null?void 0:u.events)??[],...d.events.filter(v=>!y.has(v.id))];return n.jsxs(wn,{embedded:t,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[n.jsxs(J,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((x=c.data)==null?void 0:x.kinds)??[]).map(v=>n.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:v=>a(v.target.value),size:28}),s||i?n.jsx(R,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",Gw/1e3,"s"]})]}),n.jsx(se,{message:h}),n.jsx(Qe,{flush:!0,children:!u||b.length===0?n.jsx(oe,{children:"No events match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(v=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[n.jsx("td",{className:"mono muted",children:v.id}),n.jsxs("td",{className:"nowrap",children:[We(v.createdAt,e),n.jsx("div",{className:"sub",children:Fe(v.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:v.kind}),n.jsx("td",{className:"mono muted",children:Ks(In(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||d.error?n.jsxs(J,{children:[n.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),d.error?n.jsx("span",{className:"critical",children:d.error}):null,p?n.jsx(R,{disabled:d.busy,onClick:()=>void g(),children:d.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(kt,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",We(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx(vt,{children:In(l.payload)})]}):null]})}const v6=["pending","leased","suspended","failed","succeeded","cancelled"],Pl=50;function j6({timezone:e,embedded:t,initialState:s}){const[r,i]=f.useState(s??""),[a,l]=f.useState(null),[o,c]=f.useState(null),{data:u,error:h,reload:d}=ae(()=>T.jobs({...r?{state:r}:{},limit:String(Pl)}),[r],1e4),[m,p]=f.useState({jobs:[],done:!1,busy:!1});f.useEffect(()=>{p({jobs:[],done:!1,busy:!1})},[r]);const g=async()=>{p(N=>({...N,busy:!0}));try{const N=await T.jobs({...r?{state:r}:{},limit:String(Pl),offset:String(Pl+m.jobs.length)});p(C=>({jobs:[...C.jobs,...N.jobs],done:N.jobs.length<Pl,busy:!1}))}catch(N){c(N instanceof Error?N.message:String(N)),p(C=>({...C,busy:!1}))}},y=new Set(((u==null?void 0:u.jobs)??[]).map(N=>N.id)),b=[...(u==null?void 0:u.jobs)??[],...m.jobs.filter(N=>!y.has(N.id))],x=r?(u==null?void 0:u.counts[r])??0:Object.values((u==null?void 0:u.counts)??{}).reduce((N,C)=>N+C,0),v=!m.done&&b.length<x&&((u==null?void 0:u.jobs.length)??0)>=Pl,[j,w]=f.useState(null),S=async N=>{c(null),w(N);try{const C=(await T.jobs({state:"failed",limit:"500"})).jobs;for(const I of C)await(N==="retry"?T.retryJob(I.id):T.cancelJob(I.id));d()}catch(C){c(C instanceof Error?C.message:String(C))}finally{w(null)}},k=async N=>{c(null);try{await N,l(null),d()}catch(C){c(C instanceof Error?C.message:String(C))}};return n.jsxs(wn,{embedded:t,title:"Jobs",lede:`${u!=null&&u.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:t?void 0:n.jsx(R,{size:"sm",variant:u!=null&&u.paused?"accent":void 0,onClick:()=>k(T.setPaused(!((u==null?void 0:u.paused)??!1))),children:u!=null&&u.paused?"Resume the queue":"Pause the queue"}),children:[n.jsxs(J,{children:[n.jsxs("select",{"aria-label":"Job state",value:r,onChange:N=>i(N.target.value),children:[n.jsx("option",{value:"",children:"every state"}),v6.map(N=>n.jsxs("option",{value:N,children:[N," (",(u==null?void 0:u.counts[N])??0,")"]},N))]}),((u==null?void 0:u.counts.failed)??0)>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("span",{className:"muted",children:[u.counts.failed," failed."]}),n.jsx(R,{size:"sm",disabled:j!==null,onClick:()=>void S("retry"),children:j==="retry"?"Retrying…":"Retry all failed"}),n.jsx(R,{size:"sm",variant:"danger",disabled:j!==null,onClick:()=>void S("cancel"),children:j==="cancel"?"Cancelling…":"Cancel all failed"})]}):null]}),n.jsx(se,{message:h??o}),n.jsx(Qe,{flush:!0,children:!u||b.length===0?n.jsx(oe,{children:"No jobs match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"State"}),n.jsx("th",{className:"num",children:"Attempts"}),n.jsx("th",{children:"Last error"}),n.jsx("th",{children:"Updated"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:b.map(N=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(N),children:[N.kind,n.jsx("div",{className:"sub mono",children:Co(N.id)})]}),n.jsxs("td",{children:[n.jsx(Go,{state:N.state}),N.suspendedReason?n.jsx("div",{className:"sub",children:Ks(N.suspendedReason,40)}):null]}),n.jsxs("td",{className:"num",children:[N.attempts,"/",N.maxAttempts]}),n.jsx("td",{className:N.lastError?"critical":"muted",children:N.lastError?Ks(N.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[We(N.updatedAt,e),n.jsx("div",{className:"sub",children:Fe(N.updatedAt)})]}),n.jsx("td",{children:n.jsxs(J,{align:"end",children:[["failed","cancelled","suspended"].includes(N.state)?n.jsx(R,{size:"sm",onClick:()=>k(T.retryJob(N.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(N.state)?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>k(T.cancelJob(N.id)),children:"Cancel"}):null]})})]},N.id))})]})}),v?n.jsxs(J,{children:[n.jsxs("span",{className:"muted",children:[b.length," of ",x," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{disabled:m.busy,onClick:()=>void g(),children:m.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(kt,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),n.jsx(te,{title:"Payload",children:n.jsx(vt,{children:In(a.payload)})}),n.jsx(te,{title:"Result",children:n.jsx(vt,{children:In(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null]})}const y6=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function w6({hash:e,timezone:t,navigate:s,agents:r}){var u,h;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=d=>{var m;return((m=r.find(p=>p.id===d))==null?void 0:m.name)??d};if(i){let d=i[1];try{d=decodeURIComponent(d)}catch{}return n.jsx(S6,{id:d,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=d=>m=>{m.preventDefault(),s(d)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(eh,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(E6,{})}),n.jsx(A6,{}),n.jsx(Yo,{children:y6.map(d=>{const m=d.id==="conversations"?Ct:`${Ct}/${d.id}`;return n.jsx(Ka,{href:m,active:l===d.id,onClick:c(m),children:d.label},d.id)})}),l==="conversations"?n.jsx(b6,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(j6,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(k6,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(p6,{timezone:t,embedded:!0}):null,l==="events"?n.jsx(x6,{timezone:t,embedded:!0}):null]})}function b6({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=ae(()=>T.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:a}),n.jsx(Qe,{flush:!0,children:i?i.conversations.length===0?n.jsx(tn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(jt,{children:i.conversations.map(l=>n.jsx(yt,{href:Ha(l.id),onClick:()=>t(Ha(l.id)),lead:n.jsx(Nn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Ks(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${$O(l.usage)}`,side:n.jsx("span",{title:We(l.lastMessageAt??l.createdAt,e),children:Fe(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(oe,{children:"Loading…"})})]})}function k6({timezone:e,nameOf:t}){const{data:s,error:r}=ae(()=>T.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:r}),n.jsx(Qe,{flush:!0,children:s?i.length===0?n.jsx(tn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Tool"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Asked by"}),n.jsx("th",{children:"Decided"}),n.jsx("th",{children:"Created"})]})}),n.jsx("tbody",{children:i.map(a=>n.jsxs("tr",{children:[n.jsxs("td",{children:[a.tool,n.jsx("div",{className:"sub mono",children:Co(a.id)})]}),n.jsx("td",{children:n.jsx(Go,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[We(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[We(a.createdAt,e),n.jsx("div",{className:"sub",children:Fe(a.createdAt)})]})]},a.id))})]}):n.jsx(oe,{children:"Loading…"})})]})}function S6({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null);f.useEffect(()=>{let u=!1;return T.conversation(e).then(h=>{u||a(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:Ct,onClick:c(Ct),children:"Activity"})}),n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[n.jsx(R,{size:"sm",onClick:()=>s(Ct),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Ut,{size:"sm",href:Ge(i.agentId,e),onClick:c(Ge(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(se,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(th,{children:[n.jsx(Fs,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(Fs,{label:"Runs",value:i.runs.length}),n.jsx(Fs,{label:"Tokens",value:`${_t(i.usage.input)} / ${_t(i.usage.output)}`,note:Gm(i.usage)?`input / output, ${Gm(i.usage)}`:"input / output"}),n.jsx(Fs,{label:"Started",value:We(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(Qe,{title:"Runs",flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Started"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{className:"num",children:"Turns"}),n.jsx("th",{children:"Stopped"}),n.jsx("th",{className:"num",children:"Tokens"}),n.jsx("th",{className:"num",children:"Cached"})]})}),n.jsx("tbody",{children:i.runs.map((u,h)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[We(u.startedAt,t)," ",u.resumed?n.jsx(ge,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:We(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 ",Co(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[_t(u.usage.input)," / ",_t(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?_t((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,n.jsx(te,{title:"Messages",children:n.jsx(Q,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===qw?"approved action, result":u.role,", ",We(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===qw?u.blocks.map((h,d)=>n.jsx(N6,{block:h},d)):u.blocks.map((h,d)=>n.jsx(C6,{block:h},d))]})]},u.id))})})]}):n.jsx(oe,{children:"Loading…"})]})}const qw="approval:resume";function N6({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(vt,{children:e.type==="text"?e.text??"":In(e)})]})}function C6({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(pr,{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(pr,{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(vt,{children:In(e.input)})]}):e.type==="tool_result"?n.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),n.jsx(vt,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(vt,{children:In(e.ref)})]})}function E6(){const{data:e,reload:t}=ae(()=>T.overview(),[],1e4),[s,r]=f.useState(!1);if(!e)return null;const i=()=>{r(!0),T.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(R,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function A6(){const{data:e}=ae(()=>T.overview(),[],1e4);if(!e)return null;const t=r=>e.jobs[r]??0,s=t("leased");return n.jsxs(th,{children:[n.jsx(Fs,{label:"Jobs done",value:_t(t("succeeded"))}),n.jsx(Fs,{label:"Failed",value:_t(t("failed")),...t("failed")>0?{tone:"critical"}:{}}),n.jsx(Fs,{label:"Queued",value:_t(t("pending")),note:`${s} running`}),n.jsx(Fs,{label:"Approvals",value:_t(e.approvals.pending),note:"waiting for you"})]})}const T6=["replay-all","coalesce","latest-only","skip-after-deadline"];function UC({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ae(()=>T.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=f.useState(null),u=async h=>{c(null);try{await h,a()}catch(d){c(d instanceof Error?d.message:String(d))}};return n.jsxs(wn,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(se,{message:i??o}),!r||l.length===0?n.jsxs(tn,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(Q,{children:l.map(h=>n.jsx(R6,{mission:h,timezone:e,onRun:u},h.id))})]})}function R6({mission:e,timezone:t,onRun:s}){const[r,i]=f.useState(!1);return n.jsxs(ks,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"mono muted",children:e.id})]}),meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(ge,{children:"always delivers"}):null,e.enabled?null:n.jsx(ge,{tone:"warning",children:"disabled"}),e.pausedReason?n.jsx(ge,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",onClick:()=>s(T.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a=>!a),"aria-expanded":r,children:r?"Less":"More"})]}),children:[n.jsxs("p",{className:"ui-card-meta",children:[e.schedule?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezone," · rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${We(e.nextRun,t)} (${Fe(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",n.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Fe(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(J,{children:[n.jsx(ee,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(T.setMisfirePolicy(e.id,a.target.value)),children:T6.map(a=>n.jsx("option",{value:a,children:a},a))})}),n.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,n.jsx(te,{title:"Prompt",children:n.jsx(vt,{children:e.prompt})}),n.jsx(te,{title:"Recent occurrences",children:n.jsx(Qe,{flush:!0,children:e.occurrences.length===0?n.jsx(oe,{children:"Never run."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Scheduled"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{children:"Detail"})]})}),n.jsx("tbody",{children:e.occurrences.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"nowrap",children:We(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(Go,{state:a.state})}),n.jsx("td",{className:"nowrap",children:We(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Ks(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function I6(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 BC({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=f.useState(!1),[l,o]=f.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:I6(r,t)}),n.jsx(R,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),T.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(R,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function WC({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=ae(()=>T.offers(),[],2e4),l=x=>!t||x.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=f.useState(null),[d,m]=f.useState(null),[p,g]=f.useState(null),y=async(x,v)=>{h(null),m(x);try{const j=await T.takeOffer(x);g(j.jobId?`On it — ${v}. Started as job ${j.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),a()}catch(j){h(j instanceof Error?j.message:String(j))}finally{m(null)}},b=async(x,v)=>{h(null),m(x);try{await T.dismissOffer(x),g(`Dismissed — ${v}. It will not come back.`),a()}catch(j){h(j instanceof Error?j.message:String(j))}finally{m(null)}};return n.jsxs(wn,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[n.jsx(se,{message:i??u}),p?n.jsx(H,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(J,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(BC,{ids:o.map(x=>x.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(Q,{children:o.map(x=>n.jsx(ks,{tone:"accent",title:x.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{mono:!0,children:x.agentId}),n.jsxs("span",{className:"muted",children:["expires ",Fe(x.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",disabled:d===x.id,onClick:()=>void b(x.id,x.label),children:"Not now"}),n.jsx(R,{variant:"accent",size:"sm",disabled:d===x.id,onClick:()=>void y(x.id,x.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:x.prompt})},x.id))}),c.length>0?n.jsxs(Et,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(Qe,{flush:!0,children:n.jsx(jt,{children:c.map(x=>n.jsx(yt,{title:x.label,sub:`${x.agentId} — ${J2(x)}`,side:Fe(x.dismissedAt??x.lapsedAt??x.createdAt)},x.id))})}),n.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const P6="Add a teammate",$6="Each one keeps its own memory and tools, and can work on a schedule. Add the ones you want; Agent Father can make others.",M6="front-desk";function HC(e,t){return e.length>0&&e.every(s=>s.id===t||s.roles.includes(M6)||s.roles.includes(Xd))}const O6={plugins:{label:"Plugins",route:ze("plugins")},mailbox:{label:"Add a mailbox",route:ll("email","settings")},accounts:{label:"Accounts",route:ze("accounts")}},D6="Your starter team is complete. Agent Father can make others.";function Rp({navigate:e,standing:t=!1}){var h;const s=ae(()=>T.teammates(),[]),[r,i]=f.useState(new Set),a=(((h=s.data)==null?void 0:h.teammates)??[]).filter(d=>!r.has(`${d.plugin}/${d.agent}`));if(a.length===0)return null;const l=d=>{i(m=>new Set(m).add(`${d.plugin}/${d.agent}`)),T.dismissAgentOffer(d.plugin,d.agent).then(s.reload,s.reload)},o=d=>m=>{m.preventDefault(),e(d)},c=t?a.filter(d=>d.state!=="added"):a,u=t?a.filter(d=>d.state==="added"):[];return n.jsx(te,{title:P6,children:c.length===0?n.jsx("p",{className:"teammates-lede","data-testid":"teammates-complete",children:D6}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"teammates-lede",children:$6}),n.jsx("div",{className:"teammates-grid","data-testid":"teammates",children:c.map(d=>n.jsx(_6,{row:d,navigate:e,onDismiss:()=>l(d)},`${d.plugin}/${d.agent}`))}),u.length>0?n.jsx("ul",{className:"teammates-added","data-testid":"teammates-added",children:u.map(d=>n.jsx("li",{children:n.jsxs("a",{className:"teammates-added-chip",href:gt(d.agent),onClick:o(gt(d.agent)),children:["Added · open @",d.handle]})},`${d.plugin}/${d.agent}`))}):null]})})}function _6({row:e,navigate:t,onDismiss:s}){const r=Vx(e.plugin,e.agent),i=c=>u=>{u.preventDefault(),t(c)},a=r.created??(e.state==="added"?{id:e.agent,handle:e.handle,name:e.name}:null),l=a?"added":e.state,o=e.fix?O6[e.fix]:null;return n.jsx("div",{className:"teammate","data-state":l,"data-testid":`teammate-${e.agent}`,children:n.jsxs(ks,{title:e.name,actions:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Dismiss ${e.name}`,title:"Not now",onClick:s,children:n.jsx(ye,{name:"close"})}),foot:n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[l==="unavailable"?n.jsx("span",{className:"teammate-reason",children:e.reason}):null,n.jsx(en,{}),a?n.jsxs("a",{href:gt(a.id),onClick:i(gt(a.id)),children:["Added, open @",a.handle]}):l==="unavailable"?o?n.jsx("a",{href:o.route,onClick:i(o.route),children:o.label}):null:n.jsx(R,{variant:"accent",size:"sm",disabled:r.busy,onClick:r.accept,"aria-label":`Add ${e.name}`,children:"Add"})]}),n.jsx(se,{message:r.failure})]}),children:[n.jsx("p",{className:"ui-card-meta",children:e.text}),n.jsx("p",{className:"teammate-needs",children:e.needs})]})})}const L6=["fact","observation","todo"];function KC({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=ae(()=>T.memory(r),[r],3e4),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(null),p=w=>{var S;return w==="shared"?"Everyone":((S=t.find(k=>k.id===w))==null?void 0:S.name)??w},g=async w=>{m(null);try{await w,l()}catch(S){m(S instanceof pe?S.message:String(S))}},y={nameOf:p,timezone:s,onChangePreference:w=>c({key:w.key,scope:w.scope}),onForgetPreference:w=>void g(T.forgetPreference({key:w.key,scope:w.scope})),onEditNote:w=>h(w),onForgetNote:w=>void g(T.forgetNote(w.id))},b=r?p(r):"",x=r&&i?{preferences:i.preferences.filter(w=>w.scope===r),notes:i.notes.filter(w=>w.scope===r)}:null,v=r&&i?{preferences:i.preferences.filter(w=>w.scope==="shared"),notes:i.notes.filter(w=>w.scope==="shared")}:null,j=n.jsx(R,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(wn,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[n.jsx(se,{message:a??d}),x&&v?n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:`what you told ${b} alone`,actions:j,panel:!0,flush:!0,children:n.jsx(wf,{preferences:x.preferences,empty:`Nothing stated to ${b} alone yet.`,...y})}),n.jsx(te,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(bf,{notes:x.notes,empty:`${b} has kept no private notes yet.`,...y})}),n.jsx(Et,{summary:`Shared with every agent, which ${b} also reads · ${v.preferences.length} preferences, ${v.notes.length} notes`,children:n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(wf,{preferences:v.preferences,empty:"No shared preferences.",...y})}),n.jsx(te,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(bf,{notes:v.notes,empty:"No shared notes.",...y})})]})})]}):n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:"what you said you want, one current value each",actions:j,panel:!0,flush:!0,children:i?n.jsx(wf,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...y}):n.jsx(oe,{children:"Loading…"})}),n.jsx(te,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(bf,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...y}):n.jsx(oe,{children:"Loading…"})})]}),o?n.jsx(F6,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async w=>{await g((async()=>{await T.setPreference(w),o.key===w.key&&o.scope!==w.scope&&await T.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(z6,{note:u,agents:t,onClose:()=>h(null),onSave:w=>g(T.updateNote(u.id,w)).then(()=>h(null))}):null]})}function wf({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(oe,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Preference"}),n.jsx("th",{children:"Value"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{className:"num",children:"Since"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:a.key}),n.jsx("td",{children:a.value}),n.jsx("td",{children:n.jsx(VC,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?Fe(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function bf({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(oe,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Note"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{children:"Written by"}),n.jsx("th",{className:"num",children:"When"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(l=>n.jsxs("tr",{children:[n.jsx("td",{className:"memory-note",children:l.content}),n.jsx("td",{children:n.jsx(ge,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(VC,{scope:l.scope,name:s(l.scope)})}),n.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),n.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Fe(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",new Date(l.expiresAt).toLocaleDateString(void 0,{timeZone:r})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function VC({scope:e,name:t}){return n.jsx(ge,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function GC({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 F6({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=f.useState(s.key),[c,u]=f.useState((a==null?void 0:a.value)??""),[h,d]=f.useState(s.scope),[m,p]=f.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),y=t.find(v=>v.key===g&&v.scope===h),b=!a||g!==a.key||c.trim()!==a.value||h!==a.scope,x=g!==""&&c.trim()!==""&&b;return n.jsx(kt,{title:"A preference",onClose:r,children:n.jsxs(Q,{children:[n.jsx(H,{children:'A preference is a standing choice, in your words: "paid biweekly on Thursdays", "answers short, numbers first". Storing the same key again records a correction and keeps the old value in the history.'}),n.jsx(ee,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:v=>o(v.target.value),placeholder:"reporting_currency"})}),n.jsx(ee,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>u(v.target.value),placeholder:"EUR"})}),n.jsx(ee,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(GC,{value:h,agents:e,onChange:d})}),y&&y!==a?n.jsxs(H,{tone:"warning",children:['This replaces the value already stored for this key here, "',y.value,'" (revision ',y.revision,")."]}):null,a&&h!==a.scope?n.jsxs(H,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!x||m,onClick:()=>{p(!0),i({key:g,value:c.trim(),scope:h}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function z6({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=f.useState(e.content),[l,o]=f.useState(e.scope),[c,u]=f.useState(e.kind),[h,d]=f.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(kt,{title:"A note",onClose:s,children:n.jsxs(Q,{children:[n.jsx(ee,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:n.jsx("textarea",{rows:4,value:i,maxLength:2e3,autoFocus:!0,onChange:g=>a(g.target.value)})}),n.jsxs(bs,{children:[n.jsx(ee,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:L6.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(ee,{label:"Who sees it",children:n.jsx(GC,{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?`, ${Fe(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!m||i.trim()===""||h,onClick:()=>{d(!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(()=>d(!1))},children:"Save"})]})]})})}function U6({agentId:e,agentName:t}){const{data:s,error:r,reload:i}=ae(()=>T.agentSkills(e),[e],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),d=async g=>{l(null),c(null),h(g.name);try{const y=await T.removeSkill(e,g.name);c(`Removed ${y.name}. Its versions are kept, and ${t} will not propose it again for 90 days.`),i()}catch(y){l(y instanceof pe?y.message:String(y))}finally{h(null)}};if(!s)return r?n.jsx(se,{message:r}):n.jsx(oe,{children:"Loading…"});const m=s.skills.filter(g=>g.learned!==null),p=s.skills.filter(g=>g.learned===null);return n.jsxs(Q,{divided:!0,children:[n.jsx(se,{message:r??a}),o?n.jsx(H,{tone:"good",role:"status",children:o}):null,n.jsx(te,{title:"Learned",aside:n.jsxs("span",{className:"muted",children:["what ",t," proposed and you kept"]}),children:m.length===0?n.jsx(tn,{icon:"bulb",title:"Nothing learned yet",children:s.writable?`When ${t} proposes a procedure and you keep it on Settings → Proposals, it appears here.`:`${t} ships with buddi, so it keeps no learned skills of its own until it is yours.`}):n.jsx(Qe,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"Version"}),n.jsx("th",{children:"Came from"}),n.jsx("th",{className:"num",children:"Kept"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:m.map(g=>n.jsx(W6,{skill:g,busy:u===g.name,onRemove:()=>void d(g)},g.name))})]})})}),n.jsx(te,{title:"From files and plugins",aside:n.jsx("span",{className:"muted",children:"read-only here"}),children:p.length===0?n.jsx(oe,{children:"No other skills."}):n.jsx(Qe,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"What it is for"}),n.jsx("th",{children:"Whose"})]})}),n.jsx("tbody",{children:p.map(g=>n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Et,{summary:n.jsx("span",{className:"mono",children:g.name}),children:[n.jsx(vt,{children:g.body}),n.jsx("p",{className:"muted mono skill-file",children:g.file})]})}),n.jsx("td",{children:g.description}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(ge,{children:g.scope==="shared"?"shared":`${t} only`}),n.jsx("span",{className:"muted",children:B6(g)})]})})]},`${g.scope}:${g.name}`))})]})})})]})}function B6(e){return e.provenance==="imported"?e.source?`from ${e.source}`:"imported":e.provenance==="agent"?"written by an agent":"yours"}function W6({skill:e,busy:t,onRemove:s}){const r=e.learned;return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Et,{summary:n.jsxs("span",{children:[r.title," ",n.jsx("span",{className:"muted mono",children:e.name})]}),children:[n.jsxs("p",{className:"muted",children:["When: ",e.description]}),n.jsx(vt,{children:e.body}),n.jsxs("p",{className:"muted mono skill-file",children:[e.file,r.versions.length>1?` · earlier versions in ${r.versionsDir}`:""]})]})}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[n.jsxs("span",{children:["v",r.version,r.edited?" · your correction":""]}),r.untrusted?n.jsx(ge,{tone:"warning",children:"untrusted text in view"}):null]})}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[r.conversation?n.jsx("a",{href:Ha(r.conversation),children:r.turn?`conversation, turn ${r.turn}`:"conversation"}):n.jsx("span",{className:"muted",children:"no conversation"}),n.jsx("a",{href:ze("proposals"),children:"the proposal"}),r.sources.length>0?n.jsx("ul",{className:"proposal-sources",children:r.sources.map(i=>n.jsx("li",{className:"mono",children:i},i))}):null]})}),n.jsx("td",{className:"num muted",title:r.keptAt,children:r.keptAt?Fe(r.keptAt,Date.now()):""}),n.jsx("td",{className:"num",children:n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:s,children:"Remove"})})})]})}function YC({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=ae(()=>T.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=f.useState(null),u=async h=>{c(null);try{await T.cancelReminder(h),a()}catch(d){c(d instanceof Error?d.message:String(d))}};return n.jsxs(wn,{embedded:t,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[n.jsx(se,{message:i??o}),n.jsx(Qe,{flush:!0,children:r?l.length===0?n.jsx(tn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Due"}),n.jsx("th",{children:"Agent"}),n.jsx("th",{children:"Note"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:l.map(h=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[We(h.dueAt,e),n.jsx("div",{className:"sub",children:Fe(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx(Et,{summary:"context",children:n.jsx(vt,{children:In(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Go,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(oe,{children:"Loading…"})})]})}const H6=/(flux|klein|schnell|qwen[-_]?image|image)/i;function qC(e){return e.kind==="image"||e.kind===void 0&&H6.test(e.id)}function K6(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!qC(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Ip(e){return K6(e)[0]}function iv(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function V6(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 QC(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 JC="an image model; pick it in the Image plugin, not here";function av({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(!1),p=f.useRef(0),g=async v=>{if(!e)return;const j=++p.current;c(!0),h("");try{const w=await T.accountModels(e,v);j===p.current&&l(w)}catch(w){j===p.current&&h(w instanceof Error?w.message:"Could not load models. Custom entry is still available.")}finally{j===p.current&&c(!1)}};if(f.useEffect(()=>(l(null),m(!1),h(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const y=(a==null?void 0:a.models)??[],b=!!s&&!y.some(v=>v.id===s),x=[a&&!y.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:t,children:n.jsxs("select",{value:d?"__buddi_custom__":s,disabled:i,onChange:v=>{v.target.value==="__buddi_custom__"?m(!0):(m(!1),r(v.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),y.map(v=>n.jsxs("option",{value:v.id,children:[v.name===v.id?v.id:`${v.name} — ${v.id}`,v.isDefault?" (provider default)":"",v.image?` — ${JC}`:""]},v.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(R,{disabled:i||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),d&&n.jsx(ee,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),x.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:x.join(" ")})]})}function G6(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 Y6(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const q6="This agent will not remember anything between conversations.";function Q6({view:e,chosen:t,onChange:s,disabled:r}){var S;const[i,a]=f.useState(""),[l,o]=f.useState(null),[c,u]=f.useState(()=>new Set),h=k=>u(N=>{const C=new Set(N);return C.has(k)?C.delete(k):C.add(k),C}),d=k=>{a(k),u(new Set)},m=f.useId(),p=new Set(t),g=new Set(e.groups.flatMap(k=>k.tools.filter(N=>N.core).map(N=>N.name))),y=(k,N)=>{const C=N.filter(I=>p.has(I));if(C.length!==0){if(C.some(I=>g.has(I))){o({plugin:k,names:C});return}s(t.filter(I=>!C.includes(I)))}},b=k=>{s([...t,...k.filter(N=>!p.has(N))])},x=i.trim().toLowerCase(),v=(k,N)=>x===""||k.toLowerCase().includes(x)||N.toLowerCase().includes(x),j=e.groups.map(k=>({group:k,tools:k.tools.filter(N=>v(N.name,N.description))})).filter(k=>k.tools.length>0),w=(((S=e.suggested)==null?void 0:S.tools)??[]).filter(k=>!p.has(k.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&w.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:w.map(k=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:k.name}),n.jsx("span",{className:"ui-list-sub",children:k.description})]}),n.jsx(R,{size:"sm",disabled:r,"aria-label":`Add ${k.name}`,onClick:()=>b([k.name]),children:"Add"})]},k.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:k=>d(k.target.value)})]}),j.length===0?n.jsxs(oe,{children:["No installed tool matches “",i.trim(),"”."]}):null,j.map(({group:k,tools:N})=>{const C=k.tools.filter(E=>E.grantable).map(E=>E.name),I=k.tools.filter(E=>p.has(E.name)).length,A=!!k.glob&&I===k.tools.length,O=`${m}-${k.plugin}`,z=`${m}-${k.plugin}-list`,L=x!==""?!c.has(k.plugin):c.has(k.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":O,"data-open":L?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":L,"aria-controls":z,onClick:()=>h(k.plugin),children:[n.jsx(J6,{}),n.jsx("span",{id:O,className:"tool-picker-plugin",children:k.plugin}),n.jsx("span",{className:"muted",children:A?`all ${k.tools.length}`:`${I} of ${k.tools.length} granted`})]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`All ${k.plugin} tools`,disabled:r||C.every(E=>p.has(E)),onClick:()=>b(C),children:"all"}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`No ${k.plugin} tools`,disabled:r||!C.some(E=>p.has(E)),onClick:()=>y(k.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===k.plugin?n.jsx(H,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:q6}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",onClick:()=>{s(t.filter(E=>!l.names.includes(E))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:z,className:"ui-list tool-picker-list",hidden:!L,children:N.map(E=>{const $=`${m}-${E.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:$,checked:p.has(E.name),disabled:r||!E.grantable,onChange:_=>_.target.checked?b([E.name]):y(k.plugin,[E.name])}),n.jsxs("label",{htmlFor:$,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:E.name}),E.core?n.jsx(ge,{tone:"accent",children:"core"}):null,E.gated?n.jsx(ge,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:E.grantable?E.description:`${E.description} Granted only by editing the file by hand.`})]})]},E.name)})})]},k.plugin)})]})}function J6(){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 es={json:"That is not JSON. Paste the whole block, braces included.",empty:"There is no server in it.",command:'It starts a program on this computer rather than naming an address. Use "A program on this computer" instead.',sse:"buddi speaks Streamable HTTP; this server is SSE-only.",url:"It has no url. buddi connects to a server by its https:// address."},Dr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function XC(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(es.json)}if(!Dr(t))throw new Error(es.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!Dr(u))throw new Error(es.empty);const h=Object.keys(u);if(h.length===0)throw new Error(es.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const d=u[s];if(!Dr(d))throw new Error(es.url);r=d}if("command"in r)throw new Error(es.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(es.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(es.url);const a=Dr(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,h]=l,d=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=d?`${d[1].charAt(0).toUpperCase()}${d[1].slice(1).toLowerCase()} `:"";let p=d?h.trim().slice(d[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Jl={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 ZC(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const eE=/^[A-Za-z_][A-Za-z0-9_]*$/;function X6(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function tE(e,t){const s=X6(t);return{name:e,value:s?"":t,secret:ZC(e),placeholder:s}}function nE(e){const t=[];let s="",r=!1,i=null;for(let a=0;a<e.length;a+=1){const l=e[a];if(i==="'"){l==="'"?i=null:s+=l;continue}if(i==='"'){if(l==='"')i=null;else if(l==="\\"&&a+1<e.length&&'"\\$`\n'.includes(e[a+1])){const o=e[++a];o!==`
|
|
112
|
+
`&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
|
|
113
|
+
`||o==="\r"&&e[a+1]===`
|
|
114
|
+
`){o==="\r"&&(a+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){i=l,r=!0;continue}if(/\s/.test(l)){r&&(t.push(s),s="",r=!1);continue}s+=l,r=!0}if(i)throw new Error(Jl.quote);return r&&t.push(s),t}function Z6(e){const t=nE(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=h=>{const d=h.indexOf("="),m=d>0?h.slice(0,d).trim():"";if(!eE.test(m))throw new Error(Jl.env);r.push(tE(m,h.slice(d+1)))},u=[];for(;s<t.length;s+=1){const h=t[s];if(h==="--"){o=t.slice(s+1);break}const[d,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(d==="-e"||d==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(Jl.env);continue}if(d==="-s"||d==="--scope"){m===void 0&&(s+=1);continue}if(d==="-t"||d==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(d==="-H"||d==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(d.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(es.url);const d={};for(const m of i){const p=m.indexOf(":");p>0&&(d[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:XC(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:d}}}))}}if(!l||o.length===0)throw new Error(Jl.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function eB(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return Z6(t);let s;try{s=JSON.parse(t)}catch{throw new Error(es.json)}if(!Dr(s))throw new Error(es.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!Dr(c))throw new Error(es.empty);const u=Object.keys(c);u.length===1&&Dr(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:XC(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(Jl.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=Dr(i.env)?Object.entries(i.env).filter(([c])=>eE.test(c)).map(([c,u])=>tE(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function lv({code:e,label:t="Your code",large:s=!1}){const[r,i]=f.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(J,{valign:"end",children:[n.jsx(ee,{label:t,grow:!0,children:n.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),n.jsx(R,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function sE(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 tB="It can delete or destroy something, so it asks you every time and is never remembered.";function nB(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 rE="buddi-connections",sB="/connections/callback",rB="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.",iE="Services and programs your team can use, and the tools each one brings.",ov=(e,t,s)=>`${e} ${e===1?t:s}`;function Qw(e,t){return e.transport==="stdio"?void 0:t.find(s=>uv(s.url,e.url))}function cv({connection:e,card:t,size:s}){return t?n.jsx(Va,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(Va,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function aE({connection:e}){const t=sE(e);return n.jsx(ge,{tone:t.tone,dot:t.dot,children:t.label})}const kf=e=>t=>{t.stopPropagation(),e()},vu=[{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"}],lE="buddi.connections.add-way";function iB(){try{const e=window.localStorage.getItem(lE);return vu.some(t=>t.value===e)?e:"address"}catch{return"address"}}function aB({embedded:e,timezone:t}={}){const s=ae(()=>T.connections(),[],3e4),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),d=s.data,m=S=>{var k;return((k=d==null?void 0:d.agents.find(N=>N.id===S))==null?void 0:k.name)??S},p=t??Intl.DateTimeFormat().resolvedOptions().timeZone,g=(d==null?void 0:d.connections)??[],y=(d==null?void 0:d.catalog)??[],b=y.filter(S=>!g.some(k=>k.transport!=="stdio"&&uv(S.url,k.url))),x=a?g.find(S=>S.id===a):void 0,v=o?g.find(S=>S.id===o):void 0,j=u?g.find(S=>S.id===u):void 0,w=S=>{l(null),i(S)};return n.jsxs(wn,{embedded:e,title:"Connections",lede:iE,children:[n.jsxs(Q,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ye,{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:ze("plugins"),children:"Plugins"})]})]}),!d&&!s.error?n.jsx(oe,{children:"Reading your connections…"}):null,n.jsx(se,{message:s.error}),d&&!d.vault?n.jsx(H,{tone:"warning",children:"This installation has no vault, so a service that asks for a sign-in cannot be connected. Turn the vault on first."}):null,d?n.jsx(Qe,{flush:!0,title:"Your connections",tool:g.length>0?ov(g.length,"connection","connections"):void 0,children:g.length===0?n.jsx(oe,{title:"Nothing connected yet",children:"Pick a service below, or add your own: an address, a program on this computer, or a config you already have."}):n.jsx("div",{className:"connections-rows",children:n.jsx(jt,{children:g.map(S=>n.jsx(lB,{connection:S,card:Qw(S,y),twin:S.slug!==null&&g.some(k=>k.id!==S.id&&k.name===S.name),onOpen:()=>l(S.id),onFlow:w},S.id))})})}):null,d&&b.length>0?n.jsx(Qe,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:b.map(S=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(cv,{card:S}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:S.name}),n.jsx("span",{className:"connections-tile-blurb",children:S.blurb})]}),n.jsx(R,{size:"sm",onClick:()=>w({step:"address",card:S}),"aria-label":`Connect ${S.name}`,children:"Connect"})]},S.id))})}):null,d?n.jsx(hB,{onFlow:S=>w({step:S})}):null]}),x?n.jsx(cB,{connection:x,card:Qw(x,y),agentName:m,timezone:p,onClose:()=>l(null),onFlow:w,onDisconnect:()=>c(x.id),onHolders:()=>h(x.id)}):null,j&&d?n.jsx(uB,{connection:j,agents:d.agents,onCancel:()=>h(null),onDone:()=>{h(null),s.reload()}},j.id):null,v?n.jsx(dB,{connection:v,agentName:m,onCancel:()=>c(null),onDone:()=>{c(null),l(null),s.reload()}},v.id):null,r&&d?n.jsx(fB,{start:r,agents:d.agents,catalog:d.catalog,tokens:d.tokens??d.vault,onClose:()=>{i(null),s.reload()}}):null]})}function lB({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":ov(e.toolCount,"tool","tools");return n.jsx(yt,{onClick:r,label:`${l}: details`,lead:n.jsx(cv,{connection:e,card:t}),title:l,sub:n.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:n.jsxs("span",{className:"plugins-side",children:[a?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",variant:"accent",onClick:kf(()=>i({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:kf(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:kf(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(aE,{connection:e}),n.jsx(ye,{name:"chevron-right",size:14})]})})}const oB={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 cB({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>a({step:"consent",connection:e,keepGrants:!0}),d=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(kt,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(cv,{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(aE,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(J,{children:[n.jsx(R,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(en,{}),u?n.jsx(R,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(R,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(R,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(R,{variant:e.state==="needs-review"?"accent":void 0,onClick:d,children:"Review again"})]}),children:[c?n.jsx(H,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(H,{tone:"warning",action:e.authKind!=="none"?n.jsx(R,{size:"sm",variant:"accent",onClick:h,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?n.jsxs(H,{tone:"warning",action:n.jsx(R,{size:"sm",variant:"accent",onClick:d,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?n.jsx(H,{tone:"critical",children:u?`It stopped answering at ${We(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${We(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(H,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?n.jsx(H,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{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:oB[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${ov(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Fe(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:n.jsxs("span",{className:"connections-holders",children:[n.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),n.jsx(R,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?n.jsx(te,{title:"What the program last said",children:n.jsx(vt,{label:"Its last lines on stderr",children:e.stderr.join(`
|
|
115
|
+
`)})}):null,t&&!c?n.jsxs("div",{className:"connections-another",children:[n.jsxs("p",{children:["Another ",t.name," account or workspace? It connects beside this one, with its own sign-in and its own name. In the browser, sign in as that other account."]}),n.jsx(R,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function uB({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=f.useState(()=>new Set(e.agents)),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=(p,g)=>a(y=>{const b=new Set(y);return g?b.add(p):b.delete(p),b}),d=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await T.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Ss(p))}finally{o(!1)}};return n.jsxs(Ju,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:l||d,onClick:()=>void m(),children:"Save"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:g=>h(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(se,{message:c})]})}function dB({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await T.disconnect(e.id),r()}catch(h){o(Ss(h))}finally{a(!1)}};return n.jsxs(Ju,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:i,onClick:()=>void u(),children:"Disconnect"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),n.jsx(se,{message:l})]})}function hB({onFlow:e}){const[t,s]=f.useState(iB),r=vu.find(a=>a.value===t)??vu[0],i=a=>{s(a);try{window.localStorage.setItem(lE,a)}catch{}};return n.jsx(Qe,{title:"Add your own",actions:n.jsx(ls,{label:"How to add it",options:vu.map(({value:a,label:l})=>({value:a,label:l})),value:t,onChange:i}),children:n.jsxs("div",{className:"connections-add",children:[n.jsx("p",{className:"connections-add-text",children:r.text}),n.jsx(R,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function fB({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=f.useState(e.step),[c,u]=f.useState(e.connection),[h,d]=f.useState("unknown"),[m,p]=f.useState(null),[g,y]=f.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),x=e.card??s.find(w=>b!==void 0&&uv(w.url,b)),v=(c==null?void 0:c.name)??(x==null?void 0:x.name)??(m==null?void 0:m.name)??"the service",j=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${v}`:l==="review"?`What ${v} brings`:"Who gets these tools";return n.jsxs(kt,{title:j,onClose:i,size:"wide",children:[l==="paste"?n.jsx(mB,{onRead:w=>{w.kind==="program"?(y(w.program),o("program")):(p(w.config),o("address"))}}):null,l==="address"?n.jsx(pB,{card:x,pasted:m,onDone:(w,S)=>{u(w),S==="none"?o("review"):(d(S),o("consent"))}}):null,l==="program"?n.jsx(kB,{connection:c,pasted:g,tokens:r,onDone:w=>{var S;y(null),u(w),e.keepGrants&&!((S=w.program)!=null&&S.changedSinceReview)&&w.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(vB,{connection:c,signIn:h,card:x,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:w=>{p(null),u(w),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(SB,{connection:c,onKept:w=>{u(w),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(NB,{connection:c,agents:t,onDone:i}):null]})}function uv(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Ss(e){return e instanceof Error?e.message:String(e)}function mB({onRead:e}){const[t,s]=f.useState(""),[r,i]=f.useState(null),a=()=>{try{const l=eB(t);s(""),i(null),e(l)}catch(l){i(Ss(l))}};return n.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),a()},children:[n.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",n.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",n.jsx("span",{className:"mono",children:"claude mcp add"})," line its docs print. A remote server gives its address, name and one header; a program its command, arguments and variables. Nothing is kept before you have read it on the next screen."]}),n.jsx(ee,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:n.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:t,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),n.jsx(se,{message:r}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function pB({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=f.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{l(!0),c(null);try{const g=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Ss(g))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",d=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return n.jsxs("form",{className:"ui-stack",onSubmit: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(ee,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange: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,d?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?n.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(se,{message:o}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const gB={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function xB(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 vB({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var W,D;const[c,u]=f.useState(t),h=(W=s==null?void 0:s.auth)!=null&&W.device?s.auth.recommended==="device"?"first":"offered":"none",d=xB(c,a,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((D=s==null?void 0:s.auth)==null?void 0:D.recommended)==="token"),[p,g]=f.useState(()=>m&&d.includes("token")?"token":d[0]),y=d.includes(p)?p:d[0],[b,x]=f.useState(rB),[v,j]=f.useState(""),[w,S]=f.useState(null),[k,N]=f.useState(!1),[C,I]=f.useState(null),[A,O]=f.useState(!1),[z,L]=f.useState(null),E=`${location.origin}${sB}`,$=f.useRef(o);$.current=o,f.useEffect(()=>{if(!A)return;let U=!1;const V=async()=>{if(!U){U=!0;try{$.current(await T.connection(e.id))}catch(le){I(Ss(le))}}},Z=typeof BroadcastChannel=="function"?new BroadcastChannel(rE):null;Z&&(Z.onmessage=le=>{var me;((me=le.data)==null?void 0:me.id)===e.id&&V()});let ue;const Ae=Date.now(),X=async()=>{if(!U){try{const le=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&le.signedIn&&le.authKind==="oauth"){V();return}}catch{}if(Date.now()-Ae>10*6e4){O(!1),I("The sign-in did not come back within ten minutes. Start it again.");return}ue=window.setTimeout(()=>void X(),l)}};return ue=window.setTimeout(()=>void X(),l),()=>{U=!0,Z==null||Z.close(),window.clearTimeout(ue)}},[A,e,l]);const _=async U=>{var V;N(!0),I(null);try{const{authorizeUrl:Z}=await T.connectionConsent(e.id,U);S(Z)}catch(Z){Z instanceof pe&&((V=Z.detail)==null?void 0:V.code)==="client-id"?(x(Z.message),u("manual"),g("client")):I(Ss(Z))}finally{N(!1)}};f.useEffect(()=>{y!=="oauth"||w!==null||_()},[y]);const B=U=>{const V=window.open(U,"_blank");V?(V.opener=null,L(null)):L(U),O(!0)},M=U=>{g(U),S(null),I(null),O(!1),L(null)};return n.jsxs("div",{className:"ui-stack",children:[d.length>1?n.jsx(ls,{label:"How to sign in",options:d.map(U=>({value:U,label:gB[U]})),value:y,onChange:M}):null,y==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),k?n.jsxs(oe,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,y==="client"?n.jsxs(n.Fragment,{children:[n.jsx(H,{tone:"warning",children:b}),n.jsx(ee,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:U=>{j(U.target.value),S(null),O(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:E})]})]}):null,y==="token"?n.jsx(wB,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,y==="device"?n.jsx(yB,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(y==="oauth"||y==="client")&&A?n.jsxs(H,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(y==="oauth"||y==="client")&&z?n.jsx("p",{children:n.jsxs("a",{href:z,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,y==="oauth"||y==="client"?n.jsx(se,{message:C}):null,y==="oauth"?n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>{w&&B(w)},disabled:w===null,children:A?"Open it again":`Sign in to ${e.name}`})}):null,y==="client"?n.jsx(J,{align:"end",children:w===null?n.jsx(R,{variant:"accent",onClick:()=>void _(v.trim()),disabled:k||v.trim()==="",children:k?"Checking…":"Continue"}):n.jsx(R,{variant:"accent",onClick:()=>B(w),children:A?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function jB(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function yB({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(0),[h,d]=f.useState(null),m=f.useRef(r);m.current=r,f.useEffect(()=>{let y=!1,b;a(null),o(null),d(null);const x=async()=>{var v,j;if(!y){try{const w=await T.connection(e.id);if(y)return;if(((v=w.device)==null?void 0:v.state)==="done"){m.current(w);return}if(((j=w.device)==null?void 0:j.state)==="failed"){o(w.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void x(),s)}};return(async()=>{try{const v=await T.connectionDevice(e.id);if(y)return;a({userCode:v.userCode,verificationUri:v.verificationUri}),b=window.setTimeout(()=>void x(),s)}catch(v){y||o(Ss(v))}})(),()=>{y=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=y=>{const b=window.open(y,"_blank");b?(b.opener=null,d(null)):d(y)},g=i?jB(i.verificationUri):"";return n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["Type this code on ",t,"’s site and say yes there. buddi keeps the sign-in in its vault and sends it only to"," ",n.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),i===null&&l===null?n.jsxs(oe,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(lv,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(H,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),h?n.jsx("p",{children:n.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(J,{align:"end",children:n.jsxs(R,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(se,{message:l}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>u(y=>y+1),children:"Start again"})})]}):null]})}function wB({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var x,v;const[a,l]=f.useState((s==null?void 0:s.value)??""),[o,c]=f.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=f.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[d,m]=f.useState(!1),[p,g]=f.useState(null),y=async()=>{m(!0),g(null);try{const j=await T.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(j.connection)}catch(j){g(Ss(j))}finally{m(!1)}},b=(x=t==null?void 0:t.auth)==null?void 0:x.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:j=>{j.preventDefault(),y()},children:[n.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(H,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(ee,{label:"Token",hint:(v=t==null?void 0:t.auth)==null?void 0:v.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:j=>l(j.target.value)})}),n.jsxs(bs,{columns:2,dense:!0,children:[n.jsx(ee,{label:"Header",hint:"Most services want Authorization.",children:n.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:j=>c(j.target.value)})}),n.jsx(ee,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:j=>h(j.target.value)})})]}),n.jsx(se,{message:p}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:d||a.trim()===""||o.trim()==="",children:d?"Trying it…":"Try it and keep it"})})]})}function bB(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function kB({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=f.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=f.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,h]=f.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[d,m]=f.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(E=>({key:l(),value:E}))),[p,g]=f.useState(()=>i?i.env.map(E=>({key:l(),name:E.name,value:E.value??"",secret:E.secret,kept:E.secret})):((t==null?void 0:t.env)??[]).map(E=>({key:l(),name:E.name,value:E.value,secret:E.secret,kept:!1}))),[y,b]=f.useState(!1),[x,v]=f.useState(null),j=/\s/.test(u.trim())?nE(u.trim()):[u.trim()],w=j[0]??"",S=[...j.slice(1),...d.map(E=>E.value)],k=[w,...S].filter((E,$)=>$>0||E!==""),N=()=>{j.length<2||(h(w),m(E=>[...j.slice(1).map($=>({key:l(),value:$})),...E]))},C=k.map(bB).join(" "),I=p.filter(E=>E.secret&&E.value===""&&!E.kept).map(E=>E.name||"a variable"),A=((t==null?void 0:t.env)??[]).filter(E=>E.placeholder).map(E=>E.name),O=(E,$)=>m(_=>_.map(B=>B.key===E?{...B,value:$}:B)),z=(E,$)=>g(_=>_.map(B=>B.key===E?{...B,...$}:B)),L=async()=>{b(!0),v(null);const E={name:o.trim(),command:w,args:S,env:p.filter($=>$.name.trim()!=="").map($=>({name:$.name.trim(),value:$.value,secret:$.secret}))};try{r(e?await T.updateProgram(e.id,E):(await T.addProgram(E)).connection),g($=>$.map(_=>_.secret?{..._,value:""}:_))}catch($){v(Ss($))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:E=>{E.preventDefault(),L()},children:[n.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),n.jsxs(bs,{columns:2,children:[n.jsx(ee,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:E=>c(E.target.value)})}),n.jsx(ee,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:n.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:E=>h(E.target.value),onBlur:N})})]}),n.jsx(ee,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[d.map((E,$)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${$+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:E.value,onChange:_=>O(E.key,_.target.value)}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>m(_=>_.filter(B=>B.key!==E.key)),"aria-label":`Remove argument ${$+1}`,children:"Remove"})]},E.key)),n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>m(E=>[...E,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(ee,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((E,$)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${$+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:E.name,onChange:_=>{const B=_.target.value;z(E.key,E.value===""&&!E.kept?{name:B,secret:ZC(B)}:{name:B})}}),n.jsx("input",{"aria-label":`Variable ${$+1} value`,type:E.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:E.kept&&E.value===""?"Kept. Type to replace it.":"value",value:E.value,onChange:_=>z(E.key,{value:_.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:E.secret,onChange:_=>z(E.key,{secret:_.target.checked,kept:_.target.checked&&E.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>g(_=>_.filter(B=>B.key!==E.key)),"aria-label":`Remove variable ${$+1}`,children:"Remove"})]},E.key)),n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>g(E=>[...E,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),A.length>0?n.jsxs(H,{tone:"accent",children:["Your config had a placeholder for ",A.join(", "),". Type the value itself."]}):null,!s&&p.some(E=>E.secret)?n.jsx(H,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,n.jsx("p",{className:"ui-card-meta",children:"A server that signs you in through a browser opens it on this computer, so it needs a screen. On a machine without one, give it a token as a secret variable instead."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"It will run"}),n.jsx(vt,{label:"The command line",children:C||"…"})]}),n.jsx(se,{message:x}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:y||o.trim()===""||u.trim()===""||I.length>0,title:I.length>0?`Give ${I.join(", ")} a value.`:void 0,children:y?"Saving…":e?"Save":"Continue"})})]})}function SB({connection:e,onKept:t}){const s=ae(()=>T.connectionReview(e.id),[e.id]),[r,i]=f.useState(null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",d=async()=>{var p;if(u){l(!0),c(null);try{t(await T.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(g){g instanceof pe&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Ss(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(se,{message:s.error}):e.transport==="stdio"?n.jsxs(oe,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(oe,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?n.jsx(H,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(Q,{gap:"sm",children:[n.jsx(vt,{label:"The command",children:u.program.line}),n.jsx("p",{children:"It can read and change what you can, and reach the network. buddi starts it with only the variables below, stops it after ten quiet minutes, and asks you again if its command changes."}),u.program.env.length>0?n.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):n.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",n.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?n.jsxs(H,{tone:"warning",children:[e.name," says nothing about what its tools do, so every one of them asks you first."]}):null,u.changes&&u.changes.added.length+u.changes.changed.length+u.changes.removed.length>0?n.jsxs(H,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[n.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?n.jsxs("li",{children:["New: ",n.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?n.jsxs("li",{children:["Changed: ",n.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?n.jsxs("li",{children:["Gone: ",n.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),n.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?n.jsx(ee,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(oe,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=nB(p),y=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:y}),p.problem?n.jsx(ge,{tone:"muted",children:"Cannot be used"}):n.jsx(ge,{tone:g.tone,children:g.label}),p.change==="added"?n.jsx(Pa,{children:"New"}):p.change==="changed"?n.jsx(Pa,{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?tB:"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(se,{message:o}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>void d(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function NB({connection:e,agents:t,onDone:s}){var b;const r=t.find(x=>x.frontDesk)??t[0],[i,a]=f.useState(()=>new Set(r?[r.id]:[])),o=(((b=ae(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(x=>x.tier==="gated"),[c,u]=f.useState(()=>new Set),[h,d]=f.useState(!1),[m,p]=f.useState(null),g=(x,v)=>{a(j=>{const w=new Set(j);return v?w.add(x):w.delete(x),w})},y=async()=>{d(!0),p(null);try{const x=await T.grantConnection(e.id,[...i]);if(x.failed.length>0){p(x.failed.map(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of x.granted)for(const j of c)await T.setRememberedApproval(v,j,!0);s()}catch(x){p(Ss(x))}finally{d(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(x=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(x.id),onChange:v=>g(x.id,v.target.checked)}),n.jsxs("span",{children:[x.name,x.frontDesk?" (front desk)":""]})]},x.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(x=>n.jsxs(Q,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!x.rememberable,checked:c.has(x.tool),onChange:v=>u(j=>{const w=new Set(j);return v.target.checked?w.add(x.tool):w.delete(x.tool),w})}),n.jsx("span",{className:"mono",children:x.tool})]}),x.why?n.jsx("p",{className:"ui-card-meta",children:x.why}):null]},x.tool))]}):null,n.jsx(se,{message:m}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,disabled:h,children:"Not now"}),n.jsx(R,{variant:"accent",onClick:()=>void y(),disabled:h||i.size===0,children:"Give them"})]})]})}const CB=(e,t,s)=>`${e} ${e===1?t:s}`;function EB(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 AB({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=f.useState({}),o=ae(()=>T.connections().then(j=>(l({}),j)),[r]),[c,u]=f.useState(null),[h,d]=f.useState(null),m=ze("connections"),p=async(j,w)=>{u(j.id),d(null);try{const S=await T.setConnectionHolder(j.id,e,w);l(k=>({...k,[j.id]:S.held})),i==null||i()}catch(S){d(S instanceof Error?S.message:String(S))}finally{u(null)}},g=o.data,y=(g==null?void 0:g.connections)??[],b=j=>a[j.id]??j.agents.includes(e),x=g?g.agents.some(j=>j.id===e):!0,v=y.filter(b).length;return n.jsxs(te,{title:"Connections",aside:g&&y.length>0?`holds ${v} of ${y.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(se,{message:o.error??h}),g?y.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"})]}):x?n.jsxs(n.Fragment,{children:[s?n.jsx(H,{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:y.map(j=>{const w=b(j),S=EB(j),k=j.transport==="stdio"?"on this computer":j.host,N=j.slug?CB(j.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${j.id}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",role:"switch",id:C,checked:w,"aria-checked":w,disabled:s||c!==null||S!==null&&!w,onChange:I=>void p(j,I.target.checked)}),n.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[j.name,S?n.jsxs(n.Fragment,{children:[" ",n.jsx(ge,{tone:"warning",children:sE(j).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${k} · ${N}`}),S?n.jsxs("span",{className:"ui-list-sub",children:[S," ",n.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},j.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[t," makes and changes agents, so it holds no connections."]}):o.error?null:n.jsx(oe,{children:"Loading the connections…"})]})}const TB=(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 oE(e){const t=await fetch(qi(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 RB({face:e,onPick:t,label:s=P.assistant.face,kept:r,disabled:i,disableEmoji:a,children:l}){return n.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[n.jsxs("div",{className:"meet-face-row",children:[r?n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":(e==null?void 0:e.kind)==="kept"?"true":void 0,"aria-pressed":(e==null?void 0:e.kind)==="kept","aria-label":"The current picture",disabled:i,onClick:()=>t({kind:"kept",url:r}),children:n.jsx("img",{src:r,alt:""})}):null,t_.map(o=>{const c={kind:"mascot",role:o},u=TB(e,c);return n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":P.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:qi(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:s_.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 IB=["mirror","en","fr"],cE=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],Jw=e=>{var t;return e==="access"?"tools":((t=cE.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function PB({agentId:e,section:t,navigate:s}){var y,b,x;const{data:r,error:i,reload:a}=ae(()=>T.agents(),[]),[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(Jw(t));f.useEffect(()=>d(Jw(t)),[t]);const m=v=>{d(v),s==null||s(gt(e,"setup",v))},p=async v=>{o(null),u(null);try{const j=await v;u(j.changed.length===0?`No file change needed. ${j.note}.`:`Changed ${j.changed.join(", ")}. ${j.note}.`),a()}catch(j){o(j instanceof Error?j.message:String(j))}},g=r==null?void 0:r.agents.find(v=>v.id===e);return n.jsxs(Q,{gap:"lg",children:[n.jsx(Yo,{level:"secondary",label:"Setup",children:cE.map(v=>n.jsx(Ka,{href:gt(e,"setup",v.id),active:h===v.id,onClick:j=>{j.preventDefault(),m(v.id)},children:v.label},v.id))}),n.jsx(se,{message:i??l}),c?n.jsx(H,{tone:"good",role:"status",children:c}):null,r?g?n.jsx($B,{agent:g,all:r.agents,engine:r.engines.find(v=>v.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:a},`${g.id}:${(y=r.engines.find(v=>v.id===g.id))==null?void 0:y.model}:${(x=(b=r.providerAccounts)==null?void 0:b.bindings.find(v=>v.agentId===g.id))==null?void 0:x.accountId}`):n.jsx(oe,{children:"This agent is not installed as a file."}):n.jsx(oe,{children:"Loading…"})]})}function $B({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(w=>w.kind===u),d=(s==null?void 0:s.model)??e.model,[m,p]=f.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),g=w=>{o(T.setAgentEngine(e.id,w))},y=w=>{const S=r.find(k=>k.kind===w);g({provider:w,model:(S==null?void 0:S.defaultModel)??d})},b=(h==null?void 0:h.models.map(w=>w.id))??[],x=b.includes(d)?b:[d,...b],v=s?s.available:!0,j=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(Q,{gap:"lg",children:[v?null:n.jsxs(H,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:gt(e.id,"setup","brain"),onClick:w=>{w.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(MB,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(Q,{gap:"lg",children:[v?null:n.jsxs(H,{tone:"warning",children:["This agent cannot run right now: ",j,"."]}),n.jsx(te,{panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{title:"Runs on",children:[i?n.jsx(UB,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(bs,{children:[n.jsx(ee,{label:"Provider",children:n.jsx("select",{value:u,onChange:w=>y(w.target.value),children:r.map(w=>n.jsxs("option",{value:w.kind,children:[w.kind,w.usable?"":" (no credential)"]},w.kind))})}),n.jsxs(ee,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:d,onBlur:w=>{w.target.value.trim()!==""&&w.target.value.trim()!==d&&g({model:w.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:x.map(w=>n.jsx("option",{value:w},w))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(te,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(bs,{children:[n.jsx(ee,{label:"Max turns",hint:"Per run. The agent stops when it runs out.",children:n.jsx("input",{type:"number",min:1,value:m,onChange:w=>p(w.target.value),onBlur:()=>{const w=Number(m);Number.isInteger(w)&&w>=1&&w!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&g({maxTurns:w})}})}),n.jsx(ee,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:w=>g({language:w.target.value}),children:IB.map(w=>n.jsx("option",{value:w,children:w},w))})}),VS(GS(s??{id:e.id,provider:u},i))?n.jsx(ee,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:w=>g({thinking:w.target.value==="default"?null:w.target.value}),children:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(ee,{label:"Thinking",hint:Z2,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(Et,{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(Q,{gap:"lg",children:[n.jsx(OB,{agent:e,all:t,onSaved:c}),n.jsx(AB,{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(Q,{gap:"lg",children:n.jsx(KB,{agent:e,all:t,onSaved:c})})})]})}function uE({dirty:e,busy:t,failure:s,label:r,onSave:i}){return n.jsxs(n.Fragment,{children:[s?n.jsx("span",{className:"critical save-error",role:"alert",children:s}):n.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const dE=n.jsx(H,{tone:"warning",children:"This agent ships with buddi, so its file is read-only here. Ask Agent Father to make it yours, then these fields can change."});function MB({agent:e,onSaved:t}){var L;const[s,r]=f.useState(e.name),[i,a]=f.useState(e.handle),[l,o]=f.useState(e.description),[c,u]=f.useState(e.avatar??""),[h,d]=f.useState(!1),m=ae(()=>T.agentFile(e.id),[e.id]),[p,g]=f.useState(null),y=((L=m.data)==null?void 0:L.persona.trim())??"",b=p??y,x=m.data!==void 0&&p!==null&&p.trim()!==y,[v,j]=f.useState(!1),[w,S]=f.useState(null),[k,N]=f.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||x,I=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),A=Pp(I?{...e,avatar:c.trim()}:e),O={...A?{avatar:A}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!I&&e.picture?{picture:e.picture}:{}},z=async()=>{j(!0),S(null),N(null);try{const E=await T.updateAgentFile(e.id,{name:s.trim(),handle:i.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...x&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(So))),g(null),m.reload(),N(E.message),t()}catch(E){S(E instanceof Error?E.message:String(E))}finally{j(!1)}};return n.jsx(te,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(uE,{dirty:C,busy:v,failure:w,label:"Save who it is",onSave:()=>void z()}),children:n.jsxs(Q,{children:[e.isExample?dE:null,k?n.jsx(H,{tone:"good",role:"status",children:k}):null,n.jsxs(bs,{children:[n.jsx(ee,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:v||e.isExample,onChange:E=>r(E.target.value)})}),n.jsx(ee,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:v||e.isExample,onChange:E=>a(E.target.value)})})]}),n.jsxs(J,{children:[n.jsx(Es,{id:e.id,name:s.trim()||e.name,size:"xl",face:O}),n.jsx(R,{"aria-expanded":h,onClick:()=>d(E=>!E),children:h?"Hide faces":"Change face"})]}),h?n.jsx(FB,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:v}):null,n.jsx(ee,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:v||e.isExample,onChange:E=>o(E.target.value)})}),n.jsx(ee,{label:"Persona",hint:n.jsxs(n.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",n.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?n.jsx(se,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
|
|
116
|
+
`).length+1),disabled:v||e.isExample,onChange:E=>g(E.target.value)}):n.jsx(oe,{children:"Reading its file…"})})]})})}function OB({agent:e,all:t,onSaved:s}){var I;const r=ae(()=>T.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=f.useState(null),[l,o]=f.useState(()=>new Set((e.roles??[]).filter(Uy))),[c,u]=f.useState((e.roles??[]).filter(A=>!Uy(A)).join(", ")),[h,d]=f.useState(!1),[m,p]=f.useState(null),[g,y]=f.useState(null),b=(A,O)=>A.split(O).map(z=>z.trim()).filter(z=>z!==""),x=((I=r.data)==null?void 0:I.granted)??e.tools,v=i??x,j=r.data!==void 0&&!Y6(v,x),w=By(l,b(c,/[\n,]/)),S=A=>o(O=>{const z=new Set(O);return z.has(A)?z.delete(A):z.add(A),z}),N=j||!((A,O)=>A.join(",")===O.join(","))(w,By(new Set(e.roles??[]),e.roles??[])),C=async()=>{d(!0),p(null),y(null);try{const A=await T.updateAgentFile(e.id,{...j&&r.data?{tools:G6(r.data.groups,v)}:{},roles:w});y(A.message),a(null),r.reload(),s()}catch(A){p(A instanceof Error?A.message:String(A))}finally{d(!1)}};return n.jsx(te,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(uE,{dirty:N,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(Q,{children:[e.isExample?dE:null,g?n.jsx(H,{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:jx.map(A=>{const O=uD(t,A.id),z=O&&O.id!==e.id?O:void 0;return n.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(A.id),"data-on":l.has(A.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>S(A.id),children:[n.jsx("span",{className:"role-chip-label",children:A.label}),n.jsx("span",{className:"role-chip-meaning",children:A.meaning}),z?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",z.name,". If both claim it, the one listed first keeps it."]}):null]},A.id)})}),n.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),n.jsx(ee,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:h||e.isExample,onChange:A=>u(A.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",x.length," granted"]}),r.error?n.jsx(se,{message:r.error}):r.data?n.jsx(Q6,{view:r.data,chosen:v,onChange:a,disabled:h||e.isExample}):n.jsx(oe,{children:"Loading the installed tools…"})]}),n.jsx(DB,{agentId:e.id,version:x.join(","),disabled:h||e.isExample}),_B(x)?n.jsx(LB,{agentId:e.id}):null]})})}function DB({agentId:e,version:t,disabled:s}){var g;const r=ae(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,t]),i=ae(()=>Promise.resolve().then(()=>T.connections()).catch(()=>null),[]),[a,l]=f.useState(null),[o,c]=f.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const h=async(y,b)=>{l(y),c(null);try{await T.setRememberedApproval(e,y,b),r.reload()}catch(x){c(x instanceof Error?x.message:String(x))}finally{l(null)}},d=new Map;for(const y of u)d.set(y.connection,[...d.get(y.connection)??[],y]);const m=y=>{var b,x;return((x=(b=i.data)==null?void 0:b.connections.find(v=>v.slug===y))==null?void 0:x.name)??y},p=y=>y.tool.split(".").slice(2).join(".")||y.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:[...d].map(([y,b])=>{const x=b.filter(S=>S.rememberable),v=b.filter(S=>!S.rememberable),j=x.filter(S=>S.remembered),w=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(y)}),n.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,j.length>0?` · ${j.length} remembered: ${j.map(p).join(", ")}`:""]})]});return n.jsxs(Et,{summary:w,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(y)}: remember my approval`,children:x.map(S=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:S.remembered,disabled:s||a!==null,onChange:k=>void h(S.tool,k.target.checked),"aria-label":`Remember my approval for ${S.tool}`}),n.jsx("span",{className:"mono",children:p(S)})]},S.tool))}),v.length>0?n.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",n.jsx("span",{className:"mono",children:v.map(p).join(", ")})]}):null]},y)})}),n.jsx(se,{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 _B(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function LB({agentId:e}){var h,d;const t=ae(()=>T.notificationSettings(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(null),c=s??((d=(h=t.data)==null?void 0:h.settings.agents)==null?void 0:d.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),T.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>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(se,{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 Pp(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 FB({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null),d=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(d?{kind:"emoji",value:t.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async 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 T.uploadAgentPicture(e.id,await oE(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(So))}catch(y){h(y instanceof Error?y.message:String(y))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(RB,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(zB,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function zB({agent:e,onChanged:t}){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(0);f.useEffect(()=>{if(!s)return a(null);const N=URL.createObjectURL(s);return a(N),()=>URL.revokeObjectURL(N)},[s]);const g=N=>{r(null),p(C=>C+1),d(N),t(),window.dispatchEvent(new Event(So))},y=async N=>{o(!0),u(null),d(null);try{g(await N())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>y(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),x=()=>y(async()=>(await T.removeAgentPicture(e.id),null)),v={avatar:Pp(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[j,w]=f.useState(!1),S=f.useRef(null),k=N=>{u(null),d(null),r(N??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":j?"true":void 0,onDragOver:N=>{N.preventDefault(),l||w(!0)},onDragLeave:()=>w(!1),onDrop:N=>{var C;N.preventDefault(),w(!1),l||k((C=N.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(J,{children:[n.jsx(Es,{id:e.id,name:e.name,size:"xl",face:v}),n.jsx("input",{ref:S,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:N=>{var C;return k((C=N.target.files)==null?void 0:C[0])}},m),n.jsx(R,{disabled:l,onClick:()=>{var N;return(N=S.current)==null?void 0:N.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>void x(),children:"Remove picture"}):null,n.jsx(R,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?n.jsx("span",{className:"critical save-error",role:"alert",children:c}):n.jsx("span",{className:"ui-field-hint",children:h??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function UB({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=f.useState((r==null?void 0:r.accountId)??""),[l,o]=f.useState((r==null?void 0:r.model)??""),[c,u]=f.useState(!1),h=t.accounts.find(p=>p.id===i),d=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(J,{valign:"end",children:[n.jsx(ee,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(y=>y.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(av,{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(J,{children:[d&&i&&l.trim()?n.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):n.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:c||!i||!l.trim()||!d,onClick:()=>{u(!0),s(T.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const BB=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],Sf=e=>e.tools.some(t=>BB.includes(t)),WB=["front-desk","maker"],HB={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function KB({agent:e,all:t,onSaved:s}){const[r,i]=f.useState(e.delegates),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(!1),[d,m]=f.useState(e.delegates),[p,g]=f.useState(e.asksEveryone),[y,b]=f.useState(!1),x=t.filter(A=>A.id!==e.id),v=WB.find(A=>{var O;return(O=e.roles)==null?void 0:O.includes(A)}),j=p===void 0||y,w=y||[...r].sort().join(",")!==[...d].sort().join(","),S=t.filter(A=>A.id!==e.id&&(A.delegates.includes(e.id)||A.asksEveryone!==void 0&&!Sf(e))),k=A=>i(O=>O.includes(A)?O.filter(z=>z!==A):[...O,A]),N=async A=>{l(!0),c(null),h(!1);try{const O=await T.setDelegates(e.id,A);m(O.delegates),i(O.delegates),g(O.asksEveryone),b(!1),h(!0),s()}catch(O){c(O instanceof Error?O.message:String(O))}finally{l(!1)}},C=()=>{i(x.filter(A=>!Sf(A)).map(A=>A.id)),b(!0),h(!1)},I=w?"Not saved yet.":u?"Saved. Applies to the next run.":j?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return n.jsx(te,{title:"Delegation",aside:e.tools.includes("agent.delegate")?"holds agent.delegate":"no agent.delegate tool: it cannot ask anyone until granted",panel:!0,foot:e.isExample?void 0:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:w?"warning":"muted",children:I}),n.jsx("span",{className:"ui-toolbar-spacer"}),j&&v!==void 0?n.jsx(R,{disabled:a,onClick:()=>void N(["*"]),children:"Let it ask everyone"}):null,j?n.jsx(R,{variant:"accent",disabled:!w||a,onClick:()=>void N(r),children:"Save who it can ask"}):n.jsx(R,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{title:"Can ask",children:[e.isExample?n.jsx(H,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,n.jsx(se,{message:o}),j?x.length===0?n.jsx(oe,{children:"Nobody else is installed."}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),n.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:x.map(A=>{const O=Sf(A);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${A.id}`,checked:r.includes(A.id),disabled:O||e.isExample||a,onChange:()=>k(A.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${A.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[A.name," ",n.jsxs("span",{className:"mono muted",children:["@",A.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:O?"Makes and changes agents. Never reachable by delegation.":A.description})]})]},A.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[HB[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(te,{title:"Asked by",children:S.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(G_,{children:S.map(A=>n.jsx(ge,{children:A.name},A.id))})})]})})}const VB=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"}],GB=[{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 YB({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var x,v,j,w,S;const l=VO(e),o=((x=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:x[1])??"team",c=k=>N=>{N.preventDefault(),s(k)},u=ae(()=>T.agents(),[]),h=Bx(),d=ae(()=>T.offers(),[],2e4),m=iC(),p=(((v=d.data)==null?void 0:v.offers.length)??0)+m.offers.length,g=((w=(j=u.data)==null?void 0:j.default)==null?void 0:w.defaultAgentId)??a??null,y=r.find(k=>k.roles.includes(Xd)),b=HC(r,g);return n.jsxs("div",{className:"ui-page",children:[n.jsx(eh,{title:"Agents",lede:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:y?n.jsx(Ut,{variant:"accent",href:Ge(y.id),onClick:c(Ge(y.id)),children:"Add an agent"}):null}),n.jsx(Yo,{children:VB.map(k=>n.jsx(Ka,{href:k.id==="team"?pt:`${pt}?tab=${k.id}`,active:o===k.id,count:k.id==="offers"?p:void 0,onClick:c(k.id==="team"?pt:`${pt}?tab=${k.id}`),children:k.label},k.id))}),o==="missions"?n.jsx(UC,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(aC,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(WC,{embedded:!0}):null,o==="reminders"?n.jsx(YC,{timezone:t,embedded:!0}):null,o==="team"&&b?n.jsx(Rp,{navigate:s,standing:!0}):null,o==="team"?n.jsx(qB,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(tn,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):n.jsx("div",{className:"agents-grid",children:QN(r,g).map(k=>{const N=Jd(i.get(k.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Vo(Ko(k)),"data-unavailable":k.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Es,{id:k.id,name:k.name,size:"xl",unavailable:!k.available,face:k})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:gt(k.id,"conversations"),onClick:c(gt(k.id,"conversations")),children:k.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",k.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:k.description})]}),n.jsxs("div",{className:"ui-row",children:[k.id===g?n.jsx(Pa,{children:"front desk"}):null,N?n.jsx(ge,{tone:"critical",dot:!0,children:"waiting for you"}):k.available?n.jsx(ge,{tone:"good",dot:!0,children:"ready"}):n.jsx(ge,{tone:"warning",children:Ks(k.unavailableReason??"cannot run",60)}),n.jsx(ge,{mono:!0,children:k.model}),n.jsx(Ut,{className:"agent-card-talk",size:"sm",href:Ge(k.id),onClick:c(Ge(k.id)),"aria-label":`Talk to ${k.name}`,children:"Talk"})]})]},k.id)})}):null,o==="team"&&!b?n.jsx(Rp,{navigate:s,standing:!0}):null,l?n.jsx(kt,{title:((S=r.find(k=>k.id===l.agentId))==null?void 0:S.name)??l.agentId,size:"wide",onClose:()=>s(pt),children:n.jsx(QB,{agentId:l.agentId,agent:r.find(k=>k.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function qB({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null);if(t)return n.jsx(se,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,y=r.problem,b=v=>v.map(j=>{var w;return((w=r.choices.find(S=>S.id===j))==null?void 0:w.name)??j}).join(" and "),x=async()=>{o(!0),u(null),d(null);try{const v=await T.setDefaultAgent(p);d(v.note),a(null),s()}catch(v){u(v instanceof Error?v.message:String(v))}finally{o(!1)}};return n.jsx(Qe,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(se,{message:c}),(y==null?void 0:y.code)==="multiple-defaults"?n.jsx(H,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(y.agents)}. The one chosen here wins.`}):(y==null?void 0:y.code)==="no-default-agent"?n.jsx(H,{tone:"warning",role:"status",children:"No agent file claims the default and this installation has not recorded one. Choose who answers when you name nobody."}):null,h?n.jsx(H,{tone:"good",role:"status",children:h}):null,n.jsxs(J,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:v=>a(v.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>n.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),n.jsx(R,{variant:"accent",disabled:l||!g,onClick:()=>void x(),children:"Save"})]})]})})}function QB({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=d=>m=>{m.preventDefault(),l(d)},u=Jd(o.get(e)),h=(t==null?void 0:t.name)??e;return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(Es,{id:e,name:h,size:"xl",unavailable:t?!t.available:!1,face:t}),n.jsxs("div",{className:"agent-head-text",children:[n.jsx("p",{className:"ui-page-lede",children:(t==null?void 0:t.description)??"This agent is not in the roster right now."}),n.jsxs("div",{className:"ui-row",children:[t?n.jsxs("span",{className:"muted mono",children:["@",t.handle]}):null,t?n.jsx("span",{className:"muted",children:t.model}):null,u?n.jsx(ge,{tone:"critical",children:u}):t&&!t.available?n.jsx(ge,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(Ut,{variant:"accent",href:Ge(e),onClick:c(Ge(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(H,{tone:"warning",role:"status",children:[ZN(t)," ",n.jsx("a",{href:ze(Jm(t).section),children:Jm(t).label})]}):null,n.jsx(Yo,{children:GB.map(d=>n.jsx(Ka,{href:gt(e,d.id),active:r===d.id,onClick:c(gt(e,d.id)),children:d.label},d.id))}),r==="conversations"?n.jsx(JB,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(UC,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(WC,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(YC,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(KC,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(U6,{agentId:e,agentName:h}):null,r==="setup"?n.jsx(PB,{agentId:e,section:i,navigate:l}):null]})}function JB({agentId:e,navigate:t}){const{data:s,error:r}=ae(()=>Le.conversations(e,50),[e]);if(r)return n.jsx(oe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(Qe,{flush:!0,children:s?i.length===0?n.jsx(tn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(jt,{children:i.map(a=>n.jsx(yt,{href:Ge(e,a.id),onClick:()=>t(Ge(e,a.id)),title:Ks(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:Fe(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(oe,{children:"Loading…"})})}const Xw=3,XB=40;function ZB({agent:e,navigate:t}){var g;const s=f.useRef(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null),u=ae(()=>Le.conversations(e.id,Xw),[e.id],3e4),h=Fi(Jx),d=Fi("(pointer: coarse)");f.useEffect(()=>{var y;!h&&!d&&((y=s.current)==null||y.focus())},[]);const m=(y,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:x}=await Le.startConversation(e.id),v=await Le.send(e.id,{conversationId:x,text:y,...b.length>0?{attachmentIds:b.map(j=>j.artifactId)}:{}});t(Ge(e.id,v.conversationId))}catch(x){l(x instanceof pe?x.message:String(x)),c({text:y,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,Xw);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(se,{message:a}):null,n.jsx(Wx,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`}),p.length>0?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(y=>{const b=Ge(e.id,y.id),x=y.opening??y.preview??"Untitled conversation",v=BN(y.lastMessageAt??y.createdAt??y.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:x,onClick:j=>{j.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:Ks(x,XB)}),v?n.jsx("span",{className:"home-continue-when",children:v}):null]})},y.id)})})]}):null]})}const hE="buddi.keepClose";let Ri=null;const $o=new Set;function Zw(){for(const e of $o)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),Ri=e,Zw()}),window.addEventListener("appinstalled",()=>{Ri=null,fE(),Zw()}));function e5(){const[e,t]=f.useState(Ri);return f.useEffect(()=>{const s=()=>t(Ri);return $o.add(s),()=>{$o.delete(s)}},[]),mE()?null:e}function eb(){try{return window.localStorage.getItem(hE)!==null}catch{return!1}}function fE(){try{window.localStorage.setItem(hE,"dismissed")}catch{}}function mE(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function t5(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function pE(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 n5(e){return/Mac|iPhone|iPad/.test(e)}function s5(){const[e,t]=f.useState(()=>eb()||mE()),[s,r]=f.useState(Ri),[i,a]=f.useState(void 0);if(f.useEffect(()=>{const d=()=>{r(Ri),eb()&&t(!0)};return $o.add(d),()=>{$o.delete(d)}},[]),f.useEffect(()=>{if(e)return;let d=!0;return T.session().then(m=>{d&&a(m.platform)},()=>{}),()=>{d=!1}},[e]),e)return null;const l=typeof navigator>"u"?"":navigator.userAgent,o=t5(),c=s?null:pE(l),u=()=>{fE(),t(!0)},h=()=>{const d=s;d&&d.prompt().then(async()=>{const m=await d.userChoice;Ri=null,r(null),(m==null?void 0:m.outcome)==="accepted"&&u()},()=>{})};return n.jsxs(H,{tone:"accent",title:"Keep buddi one click away.",children:[n.jsxs("p",{children:[c?`${c} `:null,"Or bookmark it with ",n5(l)?"⌘D":"Ctrl+D",".",o?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),o&&i==="darwin"?n.jsxs("p",{children:["On this Mac, ",n.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications (docs/cli.md, under Everyday)."]}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:u,children:"Not now"}),s?n.jsx(R,{variant:"accent",onClick:h,children:"Install app"}):null]})]})}function r5(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 i5({navigate:e,preview:t,hidden:s}){var c;const r=ae(()=>T.currentTip(t),[t]),[i,a]=f.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?T.dismissTip(l.id):T.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(H,{children:[n.jsxs("div",{className:"ui-notice-row",children:[n.jsx("p",{className:"ui-notice-body",children:l.text}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:n.jsx(ye,{name:"close"})})]}),n.jsxs(J,{children:[n.jsx(en,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(R,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const $p="buddi.tipsOpen";function a5(e){const t=new Date(`${e}T12:00:00Z`);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",timeZone:"UTC"}).format(t)}function l5(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 ${a5(e.shownAt)}`:"Shown"}}function o5(){try{return window.localStorage.getItem($p)==="1"}catch{return!1}}function c5(){const e=ae(()=>T.tips(),[]),[t,s]=f.useState(o5),r=f.useCallback(i=>{s(i);try{i?window.localStorage.setItem($p,"1"):window.localStorage.removeItem($p)}catch{}},[]);return{open:t,setOpen:r,list:e}}function u5({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(ye,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function d5({tips:e,navigate:t}){var b,x;const{open:s,setOpen:r,list:i}=e,[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null);if(!s)return null;const d=((b=i.data)==null?void 0:b.tips)??null,m=u??((x=i.data)==null?void 0:x.enabled)??!0,p=v=>l(v instanceof pe?v.message:String(v)),g=v=>{c(v),l(null),T.restoreTip(v).then(()=>i.reload(),p).finally(()=>c(null))},y=v=>{c("switch"),l(null),h(v),T.saveTipsSettings(v).then(j=>{h(j.enabled),i.reload()}).catch(j=>{h(!v),p(j)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(te,{title:"Tips",children:[n.jsx(se,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(d??[]).map(v=>n.jsx("div",{className:"tips-card","data-tip":v.id,"data-status":v.status,children:n.jsxs(ks,{tone:v.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(ge,{tone:v.status==="today"?"accent":"muted",children:l5(v)})}),n.jsx("p",{className:"tips-card-text",children:v.text}),n.jsxs(J,{children:[n.jsx(en,{}),v.status==="dismissed"?n.jsx(R,{size:"sm",disabled:o===v.id,onClick:()=>g(v.id),children:"Bring back"}):n.jsx(R,{size:"sm",variant:v.status==="today"?"accent":void 0,onClick:()=>t(v.action.route),children:v.action.label})]})]})},v.id))}),n.jsxs(J,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||d===null,onChange:v=>y(v.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const h5=3;function f5(e,t=new Set){return(e??[]).filter(s=>!s.hidden&&!t.has(s.id)).slice(0,h5)}function m5({glances:e,navigate:t,onChanged:s}){const[r,i]=f.useState(new Set),a=f5(e,r);if(a.length===0)return null;const l=o=>{i(c=>new Set(c).add(o.id)),T.setGlanceHidden(o.id,!0).then(()=>s==null?void 0:s(),()=>{i(c=>{const u=new Set(c);return u.delete(o.id),u})})};return n.jsx("span",{className:"home-glances",children:a.map(o=>{const c=o.link?M1(o.link.plugin,o.link.page,o.link.place):null,u=n.jsxs(n.Fragment,{children:[n.jsx(ye,{name:nh(o.icon),size:14}),n.jsx("span",{children:o.text})]});return n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c?n.jsx("a",{className:"home-glance-text",href:c,onClick:h=>{h.preventDefault(),t(c)},children:u}):n.jsx("span",{className:"home-glance-text",children:u}),n.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${o.title} from Home`,title:"Hide from Home",onClick:()=>l(o),children:n.jsx(ye,{name:"close",size:10})})]},o.id)})})}const gE="buddi.needsYouView";function p5(){try{return window.localStorage.getItem(gE)==="list"?"list":"deck"}catch{return"deck"}}function g5(e){try{window.localStorage.setItem(gE,e)}catch{}}function x5(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function v5({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=f.useState(0);if(e.length===0)return n.jsx(oe,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,h=y=>l((o+y+e.length)%e.length),d=()=>r(c),m=()=>i(c),p=y=>{const b=y.target;b.closest('input, textarea, select, [contenteditable="true"]')||(y.key==="ArrowRight"&&u?(y.preventDefault(),h(1)):y.key==="ArrowLeft"&&u?(y.preventDefault(),h(-1)):y.key==="Enter"&&!b.closest("button, a")?(y.preventDefault(),c.link&&d()):(y.key==="d"||y.key==="Delete")&&!y.metaKey&&!y.ctrlKey&&!y.altKey&&(y.preventDefault(),m()))},g=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(Nn,{agents:t,id:c.agentId,size:"sm"}):null,n.jsx("span",{children:s(c)})]});return n.jsx("div",{className:"home-deck","data-depth":Math.min(e.length-1,2),role:"region","aria-label":"Needs you, one at a time","aria-roledescription":"deck",tabIndex:0,onKeyDown:p,children:n.jsx(ks,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Fe(c.createdAt)}),actions:n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(ye,{name:"chevron-left"})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:n.jsx(ye,{name:"chevron-right"})})]}),foot:n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:m,children:"Done"}),c.link?n.jsx(R,{variant:"accent",onClick:d,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:c.title}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null]})})})}function j5({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o=""}){var Ce,dt,fe,Me,ce,Te,G,ie,Pe,it,Ye,at,ft;const c=ae(()=>T.overview(),[],15e3),u=ae(()=>T.approvals(),[],1e4),h=ae(()=>T.missions(),[],6e4),d=ae(()=>T.reminders(),[],6e4),m=ae(()=>T.conversations(),[],3e4),p=ae(()=>T.offers(),[],3e4),g=ae(()=>T.proposals(),[],6e4),y=ae(()=>T.agentOffers(),[],6e4),b=ae(()=>T.owner(),[]),x=ae(()=>T.notifications(20),[],3e4),v=f.useMemo(()=>QN(s,r??null),[s,r]),{busy:j,note:w,failure:S,decide:k}=Hx(()=>{u.reload(),c.reload()}),N=c.data,C=s.find(Y=>Y.id===r)??null,I=Y=>{var lt;return((lt=s.find(Yt=>Yt.id===Y))==null?void 0:lt.name)??Y},A=Y=>lt=>{lt.preventDefault(),t(Y)},O=((Ce=u.data)==null?void 0:Ce.pending)??[],z=((dt=N==null?void 0:N.jobs)==null?void 0:dt.failed)??0,L=((fe=N==null?void 0:N.sentinels)==null?void 0:fe.openUrgent)??0,E=((Me=g.data)==null?void 0:Me.open.length)??0,$=(((ce=y.data)==null?void 0:ce.offers)??[]).filter(Y=>!O.some(lt=>rC(lt,Y.plugin,Y.agent))),_=b5(((Te=x.data)==null?void 0:Te.notifications)??[],O),[B,M]=f.useState(new Set),[W,D]=f.useState(p5),U=_.filter(Y=>!B.has(Y.id)),V=Y=>{M(lt=>new Set(lt).add(Y.id)),T.notificationSeen(Y.id).catch(()=>{})},Z=Y=>{V(Y),Y.link&&t(Y.link)},ue=Y=>x5(Y.agentId?I(Y.agentId):Y.pluginId??w5[Y.kind],Y,I),Ae=O.length+(z>0?1:0)+(L>0?1:0)+(N!=null&&N.paused?1:0)+(E>0?1:0)+$.length+_.length,X=f.useMemo(()=>{var Y,lt;return C5(((Y=h.data)==null?void 0:Y.missions)??[],((lt=d.data)==null?void 0:lt.reminders)??[])},[h.data,d.data]),le=(((G=m.data)==null?void 0:G.conversations)??[]).slice(0,5),me=((ie=p.data)==null?void 0:ie.offers)??[],$e=me.slice(0,k5),ke=c5(),we=me.length-$e.length;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"home-band",children:n.jsxs("header",{className:"home-hero",children:[n.jsxs("div",{className:"home-hero-text",children:[n.jsxs("p",{className:"home-date",children:[n.jsx("span",{children:T5(N==null?void 0:N.now,e)}),n.jsx(m5,{glances:N==null?void 0:N.glances,navigate:t,onChanged:()=>c.reload()})]}),n.jsx("h1",{className:"home-greeting",children:A5(N==null?void 0:N.now,e,((Pe=b.data)==null?void 0:Pe.preferredName)||((it=b.data)==null?void 0:it.displayName))}),n.jsx("p",{className:"home-lede",children:I5(Ae,O.length,z,L,(N==null?void 0:N.paused)??!1,E,$.length,_.length)})]}),n.jsxs("div",{className:"home-hero-side",children:[n.jsx(u5,{tips:ke}),n.jsx(i1,{size:"lg",anim:"idle"})]})]})}),n.jsxs("div",{className:"home",children:[n.jsx(d5,{tips:ke,navigate:t}),C?n.jsx(ZB,{agent:C,navigate:t},C.id):null,n.jsx(s5,{}),n.jsx(i5,{navigate:t,preview:r5(o),hidden:ke.open}),a&&a.updateAvailable&&!a.checkout&&a.latest?n.jsx(H,{tone:"accent",children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:ze("system"),onClick:A(ze("system")),children:"Upgrade from Settings → Version."})]})}):null,l.map(Y=>n.jsx(H,{tone:"accent",children:n.jsxs("p",{children:[Y.sentence," ",n.jsx("a",{href:ze("connections"),onClick:A(ze("connections")),children:"Settings → Connections."})]})},Y.id)),n.jsx(se,{message:c.error??u.error??S}),w?n.jsx(H,{tone:"good",role:"status",children:w}):null,Ae>0?n.jsx(te,{title:"Needs you",actions:_.length>0?n.jsx(ls,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:W,onChange:Y=>{D(Y),g5(Y)}}):void 0,children:n.jsxs(Q,{children:[N!=null&&N.paused?n.jsxs(H,{tone:"warning",title:"The installation is paused.",children:["Nothing is being claimed until you resume it."," ",n.jsx(R,{size:"sm",onClick:()=>{T.setPaused(!1).then(()=>c.reload())},children:"Resume"})]}):null,O.map(Y=>n.jsx(Kx,{action:Y,timezone:e,busy:j===Y.id,onDecide:k,agentName:I(Y.agentId)},Y.id)),_.length>0&&W==="deck"?n.jsx(v5,{rows:U,agents:s,label:ue,onOpen:Z,onDone:V}):null,_.length>0&&W==="list"?n.jsx(Qe,{flush:!0,children:n.jsx(jt,{children:U.map(Y=>n.jsx(yt,{href:Y.link??void 0,onClick:()=>Z(Y),lead:Y.agentId?n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}):void 0,title:Y.title,sub:ue(Y),side:Y.state==="held"?"today":Fe(Y.createdAt)},Y.id))})}):null,z>0?n.jsx(H,{tone:"critical",children:n.jsxs("a",{href:`${Ct}/jobs?state=failed`,onClick:A(`${Ct}/jobs?state=failed`),children:[z," failed job",z===1?"":"s",". See why, then retry or cancel them, one by one or all at once."]})}):null,L>0?n.jsx(H,{tone:"critical",children:n.jsxs("a",{href:`${Ct}/alerts`,onClick:A(`${Ct}/alerts`),children:[L," urgent alert",L===1?"":"s"," from your watchers."]})}):null,$.map(Y=>n.jsx(Qe,{children:n.jsx(Gx,{plugin:Y.plugin,agent:Y.agent,text:Y.text,label:`Create @${Y.handle}`,handle:Y.handle,onDismiss:()=>{T.dismissAgentOffer(Y.plugin,Y.agent).then(()=>y.reload())}})},`${Y.plugin}/${Y.agent}`)),E>0?n.jsx(H,{tone:"accent",children:n.jsxs("a",{href:ze("proposals"),onClick:A(ze("proposals")),children:[E," proposal",E===1?"":"s"," from your agents to keep or discard."]})}):null,(((Ye=N==null?void 0:N.sentinels)==null?void 0:Ye.errors)??[]).map(Y=>n.jsxs(H,{tone:"warning",children:["Watcher ",Y.sentinelId," failed: ",Y.error]},Y.sentinelId)),((N==null?void 0:N.mail)??[]).filter(Y=>Y.lastError).map(Y=>n.jsxs(H,{tone:"warning",children:["Source ",Y.sourceId,": ",Y.lastError]},Y.sourceId))]})}):null,n.jsx(te,{title:"Your team",aside:n.jsx("a",{href:pt,onClick:A(pt),children:"All agents"}),children:s.length===0?n.jsx(oe,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsx("div",{className:"home-team",children:v.map(Y=>{const lt=Jd(i.get(Y.id));return n.jsxs("a",{className:"home-face",...Vo(Ko(Y)),href:Ge(Y.id),onClick:A(Ge(Y.id)),"data-waiting":lt?"true":void 0,"data-unavailable":Y.available?void 0:"true",children:[n.jsx(Es,{id:Y.id,name:Y.name,size:"lg",unavailable:!Y.available,face:Y}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:Y.name}),n.jsx("span",{className:"home-face-status",children:lt?xE(lt):Y.available?Ks(Y.description,60):Y.unavailableReason??"Cannot run right now."})]})]},Y.id)})})}),HC(s,r)?n.jsx(Rp,{navigate:t}):null,$e.length>0?n.jsx(te,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[we>0?n.jsxs("a",{href:`${pt}?tab=offers`,onClick:A(`${pt}?tab=offers`),children:[we," more"]}):null,n.jsx(BC,{ids:me.map(Y=>Y.id),onDone:()=>p.reload()})]}),children:n.jsx("div",{className:"home-offers",children:$e.map(Y=>n.jsx(N5,{offer:Y,agents:s,open:A(gt(Y.agentId,"offers")),onDismissed:()=>p.reload()},Y.id))})}):null,(ft=(at=g.data)==null?void 0:at.digest)!=null&&ft.latest?n.jsx(R5,{digest:g.data.digest.latest,go:A}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(te,{title:"Coming up",aside:n.jsx("a",{href:`${pt}?tab=missions`,onClick:A(`${pt}?tab=missions`),children:"All missions"}),children:n.jsx(Qe,{flush:!0,children:X.length===0?n.jsx(oe,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(jt,{children:X.map(Y=>n.jsx(yt,{href:Y.route,onClick:()=>t(Y.route),lead:n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}),title:Y.title,sub:`${Y.kind} for ${I(Y.agentId)}`,side:Fe(Y.at)},Y.key))})})}),n.jsx(te,{title:"Lately",aside:n.jsx("a",{href:Ct,onClick:A(Ct),children:"All activity"}),children:n.jsx(Qe,{flush:!0,children:le.length===0?n.jsx(oe,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(jt,{children:le.map(Y=>n.jsx(yt,{href:Ge(Y.agentId,Y.id),onClick:()=>t(Ge(Y.agentId,Y.id)),lead:n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}),title:Y.opening?Ks(Y.opening,80):"Untitled conversation",sub:`${I(Y.agentId)}, ${Y.messageCount} message${Y.messageCount===1?"":"s"}`,side:Fe(Y.lastMessageAt??Y.createdAt)},Y.id))})})})]}),((N==null?void 0:N.home)??[]).map(Y=>n.jsx(P5,{block:Y},Y.id)),N!=null&&N.jobs&&N.missions?n.jsxs("p",{className:"home-foot muted",children:[_t(N.jobs.pending??0)," queued, ",_t(N.jobs.leased??0)," running, ",_t(N.missions.enabled)," of ",_t(N.missions.total)," missions on."," ",N.paused?n.jsx(ge,{tone:"warning",children:"paused"}):n.jsx(ge,{tone:"good",children:"running"})," ",n.jsx("a",{href:Ha("").replace(/\/conversations\/$/,""),onClick:A(Ct),children:"Activity"})," · ",n.jsx("a",{href:ze("system"),onClick:A(ze("system")),children:"System"})]}):null]})]})}const y5=new Set(["watcher","reminder","failure","recap","plugin","agent"]),w5={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function b5(e,t){const s=new Set(t.map(r=>r.id));return e.filter(r=>y5.has(r.kind)&&r.actedAt===null&&r.state!=="stored"&&(r.seenAt===null||r.state==="held")&&!(r.actionId&&s.has(r.actionId)))}const k5=6,S5=500;function N5({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=f.useState(!1),l=f.useRef(null),o=f.useRef(!1),c=()=>{i||(a(!0),T.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:gt(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()},S5)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(Nn,{agents:t,id:e.agentId,size:"sm"}),n.jsx("span",{children:e.label})]}),n.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:i,onClick:c,children:"×"})]})}function C5(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:gt(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:gt(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function E5(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 A5(e,t,s){const r=E5(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 T5(e,t){try{const s=e?new Date(e):new Date,r=new Intl.DateTimeFormat("en-GB",{weekday:"long",timeZone:t}).format(s),i=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",timeZone:t}).format(s);return`${r}, ${i}`}catch{return We(e??null,t)}}function Hc(e,t,s){return e.count===0?null:`${e.count} ${e.count===1?t:s}${e.names.length>0?`: ${e.names.join("; ")}${e.count>e.names.length?"; …":""}`:""}`}function R5({digest:e,go:t}){const s=[Hc(e.memory,"memory note","memory notes"),Hc(e.skills,"skill kept","skills kept"),Hc(e.rules,"rule kept","rules kept"),Hc(e.changes,"change to an agent kept","changes to agents kept")].filter(i=>i!==null),r=e.stopped===null?"Not measured yet.":e.stopped.total>0?`Rules you kept acted ${e.stopped.total} time${e.stopped.total===1?"":"s"} (${Object.entries(e.stopped.byPlugin).filter(([,i])=>i>0).map(([i,a])=>`${i} ${a}`).join(", ")}).`:"No rule you kept acted this week.";return n.jsx(te,{title:"What buddi learned this week",aside:n.jsx("span",{className:"muted",children:Fe(e.at)}),children:n.jsx(Qe,{children:n.jsxs(Q,{divided:!0,children:[n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Learned"}),s.length===0?n.jsx("p",{children:"Nothing new."}):n.jsx("ul",{className:"home-digest-list",children:s.map(i=>n.jsx("li",{children:i},i))})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Proposes"}),n.jsx("p",{children:e.open>0?n.jsxs("a",{href:ze("proposals"),onClick:t(ze("proposals")),children:[e.open," proposal",e.open===1?"":"s"," waiting for you to keep or discard."]}):"Nothing was waiting for you."})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Stopped doing"}),n.jsx("p",{children:r})]})]})})})}function I5(e,t,s,r,i,a=0,l=0,o=0){if(e===0)return"Nothing needs you. Your agents are on it.";const c=[];t>0&&c.push(`${t} approval${t===1?"":"s"} waiting`),s>0&&c.push(`${s} failed job${s===1?"":"s"}`),r>0&&c.push(`${r} urgent alert${r===1?"":"s"}`),i&&c.push("the installation is paused"),a>0&&c.push(`${a} proposal${a===1?"":"s"} to review`),l>0&&c.push(`${l===1?"an agent":`${l} agents`} to set up`),o>0&&c.push(`${o} message${o===1?"":"s"} for you`);const u=c.length<=1?c.join(""):`${c.slice(0,-1).join(", ")} and ${c[c.length-1]}`;return`${xE(u)}.`}function xE(e){return e.charAt(0).toUpperCase()+e.slice(1)}function P5({block:e}){const[t,s]=f.useState(!1),r=e.sensitive===!0&&!t;f.useEffect(()=>{if(!e.sensitive||!t)return;const a=()=>{document.visibilityState==="hidden"&&s(!1)};return document.addEventListener("visibilitychange",a),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("blur",a)}},[e.sensitive,t]);const i=n.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!r?n.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":!r,onClick:()=>s(a=>!a),children:r?"Show":"Hide"}):null]});return n.jsxs(te,{title:e.title,aside:i,children:[e.note?n.jsx(H,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(th,{children:e.stats.map(a=>n.jsx(Fs,{label:a.label,value:r?"••••":a.value,note:r?void 0:a.note,tone:r?void 0:a.tone},a.label))}):null,e.rows.length>0?r?n.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):n.jsx(Qe,{flush:!0,children:n.jsx(jt,{children:e.rows.map((a,l)=>n.jsx(yt,{title:a.title,sub:a.sub,side:a.side?n.jsx("span",{className:a.tone==="critical"?"critical":a.tone==="good"?"good":void 0,children:a.side}):void 0},`${a.title}-${l}`))})}):null]})}const $5=3e4;function vE(){const{data:e,reload:t}=ae(()=>T.recovery(),[],$5),s=f.useRef(t);return s.current=t,f.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 M5(e){return e.kind==="account"?e.accountId?QO(e.accountId):ze("accounts"):e.kind==="telegram"?ze("telegram"):ze("secrets")}function O5(e){return e.install?XO(e.install):ZO}const D5="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function _5({active:e,onNavigate:t}){return e?n.jsxs("div",{className:"recovery-banner",role:"status",children:[n.jsx("span",{children:D5}),n.jsx("a",{href:zy,onClick:s=>{s.preventDefault(),t(zy)},children:"Finish the checklist"})]}):null}function L5({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,[l,o]=f.useState(!0),[c,u]=f.useState([]),[h,d]=f.useState(!1),[m,p]=f.useState(null),[g,y]=f.useState(!1),b=r.filter(w=>!w.installed),x=i.jobs+i.missions+i.approvals+i.telegramChats,v=w=>{u(S=>S.includes(w)?S.filter(k=>k!==w):[...S,w])},j=()=>{d(!0),p(null),T.leaveRecovery({dropPending:l,keepGrants:c}).then(()=>{y(!0),t==null||t()}).catch(w=>p(w instanceof pe?w.message:String(w))).finally(()=>d(!1))};return n.jsx(Qe,{title:"Back from a backup",children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{children:[n.jsx(Gt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:n.jsx("span",{className:"mono",children:e.archive??"—"})}]}),n.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),n.jsx(te,{title:"Keys to paste again",children:s.length===0?n.jsx(oe,{children:"Nothing is missing."}):n.jsx(jt,{children:s.map(w=>n.jsx(yt,{title:w.label??w.name,sub:w.name?n.jsx("span",{className:"mono",children:w.name}):void 0,side:n.jsx(Ut,{size:"sm",href:M5(w),"aria-label":`Fix ${w.label??w.name}`,children:"Fix"})},`${w.kind}:${w.accountId??w.name}`))})}),n.jsx(te,{title:"Add-ons to install again",children:b.length===0?n.jsx(oe,{children:"Everything the backup named is installed."}):n.jsx(jt,{children:b.map(w=>n.jsx(yt,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:w.name})," ",w.version]}),sub:w.source,side:n.jsx(Ut,{size:"sm",href:O5(w),"aria-label":`Install ${w.name} again`,children:w.install?"Install":"Find it"})},w.name))})}),n.jsx(te,{title:"Work that was waiting",children:x===0?n.jsx(oe,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(Q,{gap:"sm",children:[n.jsx(Gt,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:l,onChange:w=>o(w.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(te,{title:"Standing permissions",children:a.length===0?n.jsx(oe,{children:"No agent had a standing permission."}):n.jsxs(Q,{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(w=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:c.includes(w.id),onChange:()=>v(w.id),"aria-label":`Keep ${w.tool} for ${w.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:w.tool})," for ",w.agent," ",n.jsx("span",{className:"ui-card-meta",children:w.scope}),w.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",w.description]}):null]})]})},w.id))})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:m}),g?n.jsx(H,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):n.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:h||g,onClick:j,children:"Leave recovery mode"})})]})})]})})}const F5=2e3,z5={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 tb(e){return z5[e.phase]??e.detail??e.phase}const U5=new Set(["done","failed","rolled-back"]);function jE(e){return e!==void 0&&(U5.has(e.phase)||!!e.finishedAt)}function B5(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=f.useRef(!1);return f.useEffect(()=>{if(!e){s(void 0),i(!1),o.current=!1;return}let c=!1;const u=()=>{T.backupJob(e).then(d=>{if(!c){if(o.current){window.location.reload();return}s(d),l(null),jE(d)&&(c=!0)}}).catch(d=>{if(!c){if(d instanceof pe&&d.status!==0&&d.status<500){l(d.message);return}o.current=!0,i(!0)}})};u();const h=window.setInterval(u,F5);return()=>{c=!0,window.clearInterval(h)}},[e]),{job:t,away:r,error:a}}function W5({job:e,away:t,error:s}){return s?n.jsx(se,{message:s}):t?n.jsx(H,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?n.jsxs(H,{tone:"critical",role:"alert",children:[tb(e)," ",e.error??""]}):n.jsxs(H,{tone:e.phase==="done"?"good":void 0,role:"status",children:[tb(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function H5(){var b,x,v,j,w,S,k;const e=ae(()=>T.backups(),[],3e4),t=vE(),s=ae(()=>T.service(),[]),[r,i]=f.useState(null),a=B5(r),[l,o]=f.useState(null),[c,u]=f.useState(!1),[h,d]=f.useState(null),m=((b=e.data)==null?void 0:b.supervised)??((x=s.data)==null?void 0:x.supervised),p=h!==null||m===!1,g=((v=e.data)==null?void 0:v.archives)??[],y=N=>{u(!0),o(null),N.then(C=>{var I;return i(((I=C.job)==null?void 0:I.id)??null)}).catch(C=>{C instanceof pe&&C.status===409?d(C.message):o(C instanceof pe?C.message:String(C))}).finally(()=>{u(!1),e.reload()})};return f.useEffect(()=>{jE(a.job)&&e.reload()},[(j=a.job)==null?void 0:j.phase]),n.jsxs(Q,{gap:"lg",children:[(w=t.data)!=null&&w.active?n.jsx(L5,{view:t.data,onLeft:t.reload}):null,n.jsx(se,{message:e.error??l}),n.jsx(W5,{...a}),n.jsx(V5,{onSaved:()=>e.reload()}),n.jsx(te,{title:"Backups",panel:!0,actions:n.jsx(R,{variant:"accent",size:"sm",disabled:c,onClick:()=>y(T.startBackup(!0)),children:"Back up now"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{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(te,{children:e.data&&g.length===0?n.jsx(tn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Name"}),n.jsx("th",{children:"Taken"}),n.jsx("th",{children:"Size"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:g.map(N=>{var C;return n.jsx(G5,{archive:N,busy:c,database:(C=e.data)==null?void 0:C.database,checkout:p,onVerify:()=>y(T.verifyArchive(N.name)),onRestore:(I,A)=>y(T.restoreArchive({name:N.name,...I?{passphrase:I}:{},...A?{confirm:A}:{}}))},N.name)})})]}):n.jsx(oe,{children:"Loading…"})})]})}),n.jsx(Y5,{}),n.jsx(q5,{busy:c,checkout:p,checkoutSaid:h,database:(k=e.data)==null?void 0:k.database,onRestore:(N,C,I)=>y(T.restoreUpload(N,{passphrase:C,confirm:I}))})]})}const K5={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function V5({onSaved:e}){var p;const t=ae(()=>T.backupSchedule(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1);f.useEffect(()=>{t.data&&r(t.data)},[t.data]);const h={...K5,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(te,{title:"Every night",panel:!0,children:n.jsx(te,{children:n.jsx(H,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const d=g=>{u(!1),r({...h,...g})},m=()=>{a(!0),o(null),T.setBackupSchedule(h).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof pe?g.message:String(g))).finally(()=>a(!1))};return n.jsx(te,{title:"Every night",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.enabled,onChange:g=>d({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(bs,{children:[n.jsx(ee,{label:"At",children:n.jsx("input",{type:"time",value:h.time,onChange:g=>d({time:g.target.value})})}),n.jsx(ee,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:g=>d({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:g=>d({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(ee,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>d({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(H,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Fe(h.lastRunAt)}.`:""]}):null]})})]})})}function G5({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(""),[h,d]=f.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:Fe(e.createdAt)}),n.jsx("td",{children:$n(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(ge,{tone:"good",children:"locked"}):n.jsx(ge,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(ge,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?n.jsx("tr",{children:n.jsx("td",{colSpan:5,children:r?n.jsx(H,{tone:"warning",children:yE}):n.jsx(wE,{what:`${e.name}, taken ${Fe(e.createdAt)}, ${$n(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:d,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,h)})})}):null]})}const yE="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function wE({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=t??"",d=h===""?a.trim()!=="":a.trim()===h;return n.jsxs(Q,{gap:"sm",children:[n.jsxs(H,{tone:"warning",children:["This replaces everything in this buddi with ",e,". What is here now is copied first, so a restore that fails puts it back."]}),s?n.jsx(ee,{label:"The passphrase this one was locked with",children:n.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>i(m.target.value)})}):null,n.jsx(ee,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:n.jsx("input",{value:a,onChange:m=>l(m.target.value)})}),n.jsxs(J,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:o||!d||s&&r==="",onClick:u,children:"Restore"})]})]})}function Y5(){const[e,t]=f.useState(null),[s,r]=f.useState(""),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),h=()=>{a(!0),o(null),T.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))},d=()=>{a(!0),o(null),T.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))};return n.jsx(te,{title:"The passphrase",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:l}),n.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?n.jsx("p",{className:"backup-phrase mono",children:e}):n.jsx(J,{align:"end",children:n.jsx(R,{disabled:i,onClick:h,children:"Show it"})}),c?n.jsx(H,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(ee,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:n.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:m=>{u(!1),r(m.target.value)}})}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:i||s.trim()==="",onClick:d,children:"Use this one"})})]})})]})})}function q5({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=f.useState(null),[o,c]=f.useState(""),[u,h]=f.useState(""),[d,m]=f.useState(!1);return t?n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsx(te,{children:n.jsx(H,{tone:"warning",children:s??yE})})}):n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(bs,{children:[n.jsx(ee,{label:"The backup file",children:n.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),n.jsx(ee,{label:"Its passphrase",hint:"Only if it was locked with one.",children:n.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),d?null:n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),d&&a?n.jsx(te,{children:n.jsx(wE,{what:`${a.name}, ${$n(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const bE="gemini-2.5-pro";function rh(e){return e.replace(/^models\//,"")}const dv=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function kE(e){const t=e.map(rh);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||dv.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||ud(a,s.version)>0||ud(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 SE(e){let t;for(const s of e.map(rh)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||dv.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||ud(i,t.version)>0||ud(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function NE(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(rh(e))}function Q5(e){return[...new Set(e.map(rh).filter(t=>t.startsWith("gemini-")&&!dv.test(t)))]}function CE(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function ud(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 J5(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function X5({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=ae(()=>T.providerAccounts(),[]),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(""),[m,p]=f.useState(!1),[g,y]=f.useState(!1),[b,x]=f.useState(t??null);f.useEffect(()=>{t&&x(t)},[t]);const v=s==null?void 0:s.accounts.some(k=>{var N;return((N=k.login)==null?void 0:N.state)==="pending"&&k.login.expiresAt&&Date.parse(k.login.expiresAt)>Date.now()});f.useEffect(()=>{if(!v)return;const k=setInterval(i,2e3);return()=>clearInterval(k)},[v,i]);const j=async(k,N)=>{o(!0),u(null),d(""),y(!1);try{const C=await k();return d((C==null?void 0:C.warning)??N),i(),!0}catch(C){return u(C instanceof Error?C.message:"Could not apply change."),i(),!1}finally{o(!1)}},w=(s==null?void 0:s.accounts)??[],S=w.find(k=>k.id===b)??w[0];return n.jsxs(wn,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[n.jsx(se,{message:r??c}),h&&n.jsx(H,{tone:"good",role:"status",children:h}),g&&n.jsx(H,{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(oe,{children:"Loading accounts…"}),r&&n.jsx(J,{children:n.jsx(R,{onClick:i,children:"Retry"})}),s&&n.jsxs(n.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&n.jsx(H,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&n.jsx(kt,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(i8,{accounts:w,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:j,onDone:k=>{p(!1),k&&x(k)}})})}),n.jsx(te,{title:"Accounts",aside:`Secrets live in the ${Z5(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),d(""),y(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.jsx(R,{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:w.length===0?n.jsx(tn,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:w.map(k=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(S==null?void 0:S.id)===k.id,onClick:()=>x(k.id),children:[n.jsx(e8,{kind:k.kind,auth:k.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:k.label}),n.jsxs("span",{className:"accounts-row-sub",children:[hv(k)," · ",k.assignedAgents.length===0?"no agents":`${k.assignedAgents.length} agent${k.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(AE,{account:k})]},k.id))}),S?n.jsx(n8,{account:S,anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:j},`${S.id}:${S.revision}`):null]})})]})]})}function Z5(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function hv(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":iv(e)?"mlxh":"OpenAI-compatible"}function EE(e){return e.detectedContextWindowSource==="mlxh"?V6(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function e8({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 t8(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function AE({account:e}){const t=e.enabled?e.configured?"good":"warning":void 0,s=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return n.jsx(ge,{tone:t,children:s})}function fv(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 n8({account:e,busy:t,run:s,anthropicOAuthEnabled:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(AE,{account:e})]}),n.jsx(Gt,{items:[{label:"Provider",value:hv(e)},{label:"Default model",value:n.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:n.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${EE(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(c=>n.jsx("a",{href:gt(c,"setup","brain"),children:c},c))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:pt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${new Date(e.tokenExpiresAt).toLocaleString()} (not your subscription renewal date)`}]:[]]}),e.removalPending&&n.jsx(H,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(H,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(IE,{account:e,enabled:!!r,busy:t,run:s}),e.kind==="codex"&&n.jsx(TE,{account:e,busy:t,run:s}),e.auth==="device-key"&&n.jsx(RE,{account:e,busy:t,run:s}),n.jsxs(J,{children:[n.jsx(R,{disabled:t||e.removalPending,onClick:()=>a(!0),children:"Edit account"}),n.jsx(R,{disabled:t||e.removalPending,onClick:()=>void s(()=>T.saveProviderAccount({...fv(e),enabled:!e.enabled}),e.enabled?"Account disabled. Subsequent model calls will stop; already-sent requests cannot be recalled.":"Account enabled."),children:e.enabled?"Disable":"Enable"}),e.kind!=="codex"&&n.jsx(R,{disabled:t||!e.enabled||!e.configured,onClick:()=>void s(()=>T.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(R,{variant:"danger",disabled:t||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>o(!0),children:"Remove account"})]}),e.test&&n.jsxs(n.Fragment,{children:[n.jsxs(H,{role:"status",tone:t8(e.test.state),children:[n.jsx("p",{children:e.test.message}),e.test.retryAt?n.jsxs("p",{children:["Provider suggested retry time: ",new Date(e.test.retryAt).toLocaleString(),". This is retry advice, not a guaranteed quota reset."]}):["rate-limited","quota-exhausted"].includes(e.test.state)&&n.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),n.jsxs("p",{className:"muted",children:["Tested at ",new Date(e.test.checkedAt).toLocaleString(),e.test.httpStatus?` · HTTP ${e.test.httpStatus}`:"",". This is not a quota reset or subscription renewal date."]})]}),i&&n.jsx(kt,{title:`Edit ${e.label}`,onClose:()=>a(!1),children:n.jsx(s8,{account:e,busy:t,run:s,onDone:()=>a(!1)})}),l&&n.jsxs(H,{tone:"critical",children:[n.jsxs("p",{children:["Remove “",e.label,"” and its stored credential from Buddi? This does not revoke it at the provider or remove it from backups."]}),n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:t,onClick:()=>void s(()=>T.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(R,{disabled:t,onClick:()=>o(!1),children:"Cancel"})]})]}),n.jsx(Et,{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 TE({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(R,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>T.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(R,{disabled:t,onClick:()=>void s(()=>T.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(R,{disabled:t||!e.configured,onClick:()=>void s(()=>T.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(H,{tone:"accent",role:"status",children:[n.jsxs("p",{children:["Here is your code: ",n.jsx("strong",{children:e.login.userCode}),". Open the link, enter it, and approve buddi on openai.com."]}),e.login.userCode&&n.jsx(lv,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(J,{children:n.jsx(Ut,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&n.jsxs("p",{className:"muted",children:["The code works until ",new Date(e.login.expiresAt).toLocaleTimeString(),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&n.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function s8({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=f.useState((e==null?void 0:e.label)??""),[c,u]=f.useState((e==null?void 0:e.kind)??"anthropic"),[h,d]=f.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=f.useState((e==null?void 0:e.baseUrl)??""),[g,y]=f.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,x]=f.useState(""),[v,j]=f.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),w=k=>{u(k),d(k==="codex"?"chatgpt":"api-key"),x(""),p(k==="openai-compatible"?"http://localhost:11434/v1":""),y(k==="anthropic"?"claude-sonnet-5":k==="openai"?"gpt-5":"")},S=!l.trim()||!g.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:k=>{k.preventDefault();const N=b;x(""),s(()=>T.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:v.trim()?Number(v):null,...N.trim()?{secret:N}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ee,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:k=>o(k.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(ee,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:k=>{k.target.value==="anthropic-oauth"?(w("anthropic"),d("anthropic-oauth")):w(k.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:k=>p(k.target.value)})}),n.jsx(ee,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:h,onChange:k=>{d(k.target.value),x("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(J,{valign:"end",children:n.jsx(av,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:y,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(ee,{label:"Context window",hint:iv(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${EE(e)})`:"assumed from the model",onChange:k=>j(k.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&n.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),h==="api-key"&&n.jsx(ee,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:k=>x(k.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:S,children:"Save account"})]})]}),S&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function RE({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,T.ollamaPoll(e.id,r.attemptId).then(d=>{c||d.state==="waiting"||(c=!0,d.state==="connected"?i.current(async()=>{},`Connected as ${d.username}, device ${d.deviceName}.`):i.current(async()=>{throw new Error(d.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await T.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return n.jsxs(n.Fragment,{children:[l&&n.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),n.jsxs(J,{children:[n.jsx(R,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(R,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await T.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(H,{tone:"accent",role:"status",children:[n.jsxs("p",{children:[n.jsx("a",{href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open the ollama.com page"})," and press Connect. Sign in there first if it asks."]}),n.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&new Date(r.expiresAt).toLocaleTimeString(),"."]})]})]})}function IE({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,h;const[i,a]=f.useState("");return f.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(H,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(J,{children:[n.jsx(R,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>T.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&n.jsx(R,{disabled:s,onClick:()=>{a(""),r(()=>T.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(R,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>T.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((h=e.login)==null?void 0:h.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:d=>{d.preventDefault();const m=i;a(""),r(()=>T.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&new Date(e.login.expiresAt).toLocaleTimeString(),"; restarting Buddi also ends it."]}),n.jsx(ee,{label:"Claude authorization code",children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:i,onChange:d=>a(d.target.value),disabled:s})}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const Nf={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function Cf(e,t,s){return Mp(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 Mp(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 r8="That key was refused. Check it and paste it again.";function i8({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(fe=>fe.label),[c,u]=f.useState(null),[h,d]=f.useState("anthropic"),[m,p]=f.useState("api-key"),[g,y]=f.useState(()=>Cf("anthropic","api-key",o)),[b,x]=f.useState(!1),[v,j]=f.useState(""),[w,S]=f.useState(""),[k,N]=f.useState(null),[C,I]=f.useState(!1),[A,O]=f.useState(""),[z,L]=f.useState(""),[E,$]=f.useState(!1),[_,B]=f.useState(!1),[M,W]=f.useState(!1),[D,U]=f.useState(void 0),V=(fe,Me,ce=!1)=>{d(fe),p(Me),S(""),N(null),O(""),L(""),$(!1),B(ce),W(!1),U(void 0),j(ce?"":fe==="openai-compatible"?"http://localhost:11434/v1":""),b||y(ce?Cf(fe,"device-key",o):Cf(fe,Me,o))},Z=fe=>{V("openai-compatible",fe?"api-key":"device-key",!0),fe&&T.ollama().then(Me=>j(Me.cloudBaseUrl)).catch(()=>{})},ue=()=>{l&&(V("openai-compatible","api-key"),W(!0),j(l.baseUrl),b||y(Mp("Gemini",o)))},Ae=()=>{V("openai-compatible","none"),U(null),b||y(Mp("mlxh",o)),T.mlxh().then(fe=>{U(fe),j(fe.baseUrl)}).catch(()=>U(void 0))},X=D!==void 0,le=c?e.find(fe=>fe.id===c):void 0;if(c)return le?n.jsx(a8,{account:le,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(le.id)}):n.jsx(oe,{children:"Saving…"});const me=h==="openai-compatible"&&m!=="device-key",$e=h==="codex"||m==="anthropic-oauth"||m==="device-key",ke=!$e&&(m==="none"||w.trim()!=="")&&(!me||v.trim()!==""),we=async()=>{var fe,Me;I(!0),O("");try{const ce=await T.probeModels({kind:h,auth:m,...me?{baseUrl:v}:{},...w.trim()?{secret:w}:{}});N(ce),z||L(((fe=ce.models.find(Te=>Te.isDefault))==null?void 0:fe.id)??((Me=ce.models[0])==null?void 0:Me.id)??"")}catch(ce){O(ce instanceof Error?ce.message:"Could not load models. You can still enter a custom model.")}finally{I(!1)}},Ce=z.trim(),dt=!g.trim()||me&&!v.trim()||me&&!M&&!X&&!Ce||M&&!w.trim()||X&&!(D!=null&&D.running);return n.jsxs("form",{className:"ui-stack",onSubmit:fe=>{var G;fe.preventDefault();const Me=w;S("");let ce=Ce||(X?Ip(D)??((G=D==null?void 0:D.models[0])==null?void 0:G.id):void 0)||(m==="device-key"?uu:Nf[h])||"claude-sonnet-5",Te;(async()=>{if(M){ce=bE;try{const at=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:Me})).models.map(ft=>ft.id);ce=kE(at)??ce,Te=NE(ce)?SE(at):void 0}catch{}}let ie,Pe=!1;!await s(async()=>{if(ie=await T.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:v,defaultModel:ce,enabled:!0,...Me.trim()?{secret:Me}:{}}),m!=="api-key")return ie;const Ye=await T.testProviderAccount(ie.id);if(Ye.state==="connected")return ie;if(sx(Ye)){const at=ie.id;ie=void 0;try{const ft=(await T.providerAccounts()).accounts.find(Y=>Y.id===at);ft&&await T.removeProviderAccount(at,ft.revision)}catch{}throw new Error(r8)}if(M&&Te&&CE(Ye)){const at=(await T.providerAccounts()).accounts.find(ft=>ft.id===ie.id);if(at&&(await T.saveProviderAccount({...fv(at),defaultModel:Te}),(await T.testProviderAccount(ie.id)).state==="connected"))return{...ie,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${Te}; turn on billing at Google to use Pro.`}}return Pe=!0,{...ie,warning:`Account saved. ${Ye.message}`}},"Account saved.")||!ie||(M||X||Pe?u(ie.id):Ce||!$e?r(ie.id):u(ie.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ee,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":_?"ollama-cloud":M?"gemini":X?"mlxh":h,onChange:fe=>{if(fe.target.value==="anthropic-oauth")V("anthropic","anthropic-oauth");else if(fe.target.value==="gemini")ue();else if(fe.target.value==="mlxh")Ae();else if(fe.target.value==="ollama-cloud")V("openai-compatible","device-key",!0);else{const Me=fe.target.value;V(Me,Me==="codex"?"chatgpt":"api-key")}},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),l&&n.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),n.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),a&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),i&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),n.jsx(ee,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:fe=>{y(fe.target.value),x(!0)},placeholder:"Anthropic — Personal"})}),_&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:fe=>Z(fe.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),me&&n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:v,onChange:fe=>{j(fe.target.value),N(null)}})}),!M&&!X&&n.jsx(ee,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:fe=>{p(fe.target.value),S(""),N(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(ee,{label:"API key",hint:"Stored in the vault, never shown again.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:w,onChange:fe=>{S(fe.target.value),N(null)}})}),X?D===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):D!=null&&D.running?n.jsxs(Q,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",D.models.length===1?"one model":`${D.models.length} models`,". No key: mlxh takes any. buddi starts on ",Ip(D)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),D.models.some(fe=>fe.kind==="image")?n.jsxs("p",{className:"muted",children:[D.models.filter(fe=>fe.kind==="image").map(fe=>fe.id).join(", "),": ",JC,"."]}):null]}):n.jsx(H,{tone:"warning",children:QC((D==null?void 0:D.baseUrl)??v)}):M&&l?n.jsxs("p",{className:"muted",children:[n.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):$e?n.jsx("p",{className:"muted",children:h==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),k?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:E?"__custom__":z,onChange:fe=>{fe.target.value==="__custom__"?($(!0),L("")):($(!1),L(fe.target.value))},children:[k.models.map(fe=>n.jsxs("option",{value:fe.id,children:[fe.name===fe.id?fe.id:`${fe.name} — ${fe.id}`,fe.isDefault?" (provider default)":"",fe.thinks?" · thinks":""]},fe.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(R,{size:"sm",disabled:C||!ke,onClick:()=>void we(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(R,{disabled:C||!ke,onClick:()=>void we(),children:C?"Loading models…":"Load models"}),me?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",Nf[h]," is used until you pick one."]})]}),E||me&&!k?n.jsx("input",{"aria-label":"Custom model",required:me,maxLength:150,value:z,onChange:fe=>L(fe.target.value),placeholder:me?"qwen3:8b":Nf[h]}):null,A?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:A}):null,k!=null&&k.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:()=>r(),children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:dt,children:"Save account"})]})]}),dt&&!X&&n.jsxs("p",{className:"muted",children:["Enter an account name",M?" and a key":me?", an endpoint and a model":""," to enable Save account."]})]})}function a8({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=f.useState(e.defaultModel),o=e.configured;return n.jsxs(Q,{gap:"lg",children:[n.jsxs(H,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(IE,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(TE,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(RE,{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(J,{valign:"end",children:n.jsx(av,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:i,children:"Skip for now"}),n.jsx(R,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>T.saveProviderAccount({...fv(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(J,{children:n.jsx(R,{onClick:i,children:"Finish later"})})]})}const nb=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 l8(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||nb.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return nb.has(`*.${s}`)}function o8(e){return typeof e=="string"&&e.includes("*")}function c8(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"}:l8(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const sb=["every-time","first-time","pre-approved"],PE={"every-time":"every time","first-time":"first time only","pre-approved":"pre-approved"};function u8(e){const t=sb.indexOf(e);return sb.slice(0,t<0?1:t+1)}function $E(e){return e.endsWith(".account")}const d8="This account’s process holds the value for as long as its connection lives.",mv="Stored, not usable until it has a binding.";function h8(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":$E(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const ME={"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})}},f8="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",m8=e=>`That is a public suffix; ${e} would match every site.`,rb="Give the site as an origin, like https://en.wikipedia.org.";function ib(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(o8(e)){const s=c8(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:f8};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:m8(r)}}return{ok:!1,error:rb}}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:rb}}}function p8(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 OE(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 ib(s);if(e==="browser.native.type"||$E(e))return{ok:!0,target:s};const r=ME[e];if(r===void 0)return{ok:!0,target:s};const i=p8(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=ib(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 g8(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function x8(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=ME[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 DE="accounts.provider";function v8(e,t){for(const s of e)if(s.kind===DE&&typeof s.target=="string"){const r=t.get(s.target);if(r)return r}}function Op(e,t,s){if(e===DE&&typeof t=="string"){const r=s.get(t);if(r)return r.label}return x8(e,t)}function _E(e){if(e==="delivered")return"good";if(e==="held"||e==="pending")return"warning";if(e==="refused"||e==="failed")return"critical"}function LE(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 FE(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 j8(e){const t=LE(e,"found");return t.length?`The value already sits in ${FE(t)}.`:""}function y8(e){const t=LE(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${FE(t)}.`:""}async function Ui(e,t,s,r){s(!0),r(null);try{return(await T.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}function w8({embedded:e,timezone:t}={}){const s=ae(()=>T.secrets(),[]),r=ae(()=>T.providerAccounts(),[]),i=f.useMemo(()=>{var c;return new Map((((c=r.data)==null?void 0:c.accounts)??[]).map(u=>[u.id,{label:u.label,provider:hv(u)}]))},[r.data]),[a,l]=f.useState(!1),o=s.data;return n.jsxs(wn,{embedded:e,title:"Keys and secrets",lede:"What the agents may use and never see: a name, a value buddi keeps, and the exact places the value may go.",children:[n.jsxs(Q,{gap:"lg",children:[!o&&!s.error?n.jsx(oe,{children:"Opening the vault…"}):null,s.error?n.jsx(J,{children:n.jsx(R,{onClick:s.reload,children:"Retry"})}):null,o?n.jsx(te,{title:"Secrets",aside:"A value the agents use and never see: bound to where it may go, never shown again.",actions:n.jsx(R,{variant:"accent",size:"sm",onClick:()=>l(!0),children:"Add a secret"}),panel:!0,children:n.jsx(Q,{divided:!0,children:o.secrets.length===0?n.jsx(tn,{icon:"key",title:"Nothing stored yet",children:"Add one — a site password, an API token — and bind it to the places an agent may use it."}):o.secrets.map(c=>n.jsx(b8,{secret:c,accounts:i,destinations:o.destinations,timezone:t,onChanged:s.reload},c.name))})}):null,o?n.jsx(te,{title:"buddi’s own keys",aside:"Read-only.",children:n.jsxs(Q,{gap:"sm",children:[o.ownKeys.length===0?n.jsx(oe,{children:"No keys of buddi’s own right now."}):n.jsx("div",{className:"ui-list",children:o.ownKeys.map(c=>n.jsx("div",{className:"ui-list-row",children:n.jsx("span",{className:"ui-list-main",children:n.jsx("span",{className:"mono",children:c})})},c))}),n.jsx("p",{className:"ui-card-meta",children:"These are the keys buddi itself runs on. They cannot be bound or replaced here, and the scrubber replaces them in what buddi sends out, exactly like your own secrets."})]})}):null]}),a&&o?n.jsx(S8,{destinations:o.destinations,onClose:()=>l(!1),onChanged:s.reload}):null]})}function b8({secret:e,accounts:t,destinations:s,timezone:r,onChanged:i}){const[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(!1),[p,g]=f.useState(!1),y=async()=>{await Ui("secrets.delete",{name:e.name},l,c)!==null&&(m(!1),i())},b=e.lastUse,x=v8(e.bindings,t);return n.jsxs(Q,{gap:"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:x?x.label:e.name}),x?n.jsx(Pa,{children:x.provider}):null,e.totp?n.jsx(Pa,{children:"TOTP"}):null,b?n.jsx(ge,{tone:_E(b.outcome),children:b.outcome}):null]}),x?n.jsx("p",{className:"ui-card-meta mono",children:e.name}):null,e.bindings.length===0?n.jsx("p",{className:"ui-card-meta",children:mv}):n.jsx("div",{className:"ui-stack","data-gap":"sm",children:e.bindings.map((v,j)=>n.jsxs("div",{className:"ui-row",children:[n.jsx(Pa,{children:v.kind}),n.jsx("span",{className:"mono",children:Op(v.kind,v.target,t)}),n.jsx(ge,{tone:"muted",children:PE[v.rule]??v.rule})]},j))}),e.bindings.some(v=>v.heldByPlugin)?n.jsx("p",{className:"ui-card-meta",children:d8}):null,n.jsx("p",{className:"ui-card-meta",children:b?`Last used ${Fe(b.at)}${b.agentId?` by ${b.agentId}`:""} — ${b.kind}, ${Op(b.kind,b.target,t)}.`:"Never used."}),n.jsx(se,{message:o}),d?n.jsxs(H,{tone:"critical",role:"alert",children:[n.jsxs("p",{children:["Delete “",e.name,"”? The value and its bindings go; the use log stays, under the name."]}),n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:a,onClick:()=>void y(),children:"Delete it"}),n.jsx(R,{disabled:a,onClick:()=>m(!1),children:"Cancel"})]})]}):null,n.jsxs(J,{children:[n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("replace"),children:"Replace value"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("rename"),children:"Rename"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("rebind"),children:e.bindings.length===0?"Add a binding":"Rebind"}),n.jsx(R,{size:"sm",variant:"danger",disabled:a,onClick:()=>m(!0),children:"Delete"}),n.jsx(R,{size:"sm",variant:"ghost","aria-expanded":p,onClick:()=>g(!p),children:"Use log"})]}),p?n.jsx(k8,{name:e.name,accounts:t,timezone:r}):null,u==="replace"?n.jsx(N8,{secret:e,onClose:()=>h(null),onChanged:i}):null,u==="rename"?n.jsx(C8,{secret:e,onClose:()=>h(null),onChanged:i}):null,u==="rebind"?n.jsx(E8,{secret:e,destinations:s,onClose:()=>h(null),onChanged:i}):null]})}function k8({name:e,accounts:t,timezone:s}){const r=ae(()=>T.secretUses(e,50),[e]);if(r.error)return n.jsx(se,{message:r.error});if(!r.data)return n.jsx(oe,{children:"Reading the log…"});const i=r.data.uses;return i.length===0?n.jsx(oe,{children:"No uses yet."}):n.jsx("div",{className:"ui-list",children:i.map((a,l)=>n.jsxs("div",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[We(a.at,s??"UTC")," — ",a.kind,", ",Op(a.kind,a.target,t)]}),n.jsxs("span",{className:"ui-list-sub",children:[a.agent?a.agent:"the owner",a.plugin?` · ${a.plugin}`:"",a.detail?` · ${a.detail}`:""]})]}),n.jsx("span",{className:"ui-list-side",children:n.jsx(ge,{tone:_E(a.outcome),children:a.outcome})})]},l))})}function zE({name:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a,onDone:l}){const o=j8(t);return n.jsxs(Q,{gap:"sm",children:[n.jsxs(H,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),n.jsx("p",{className:"ui-card-meta",children:o||"Nothing of the value sits where buddi already holds text."}),n.jsx(se,{message:i}),o?n.jsx(J,{children:n.jsx(R,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":y8(s)||"Nothing of it was left to replace."})}):null,n.jsx(J,{align:"end",children:n.jsx(R,{onClick:l,children:"Done"})})]})}function UE({destinations:e,bindings:t,disabled:s,onChange:r}){const i=(a,l)=>{r(t.map((o,c)=>c===a?{...o,...l}:o))};return n.jsx(Q,{gap:"sm",children:t.map((a,l)=>{const o=e.find(u=>u.kind===a.kind),c=(o==null?void 0:o.maxRule)??a.rule;return n.jsxs(J,{valign:"end",children:[n.jsx(ee,{label:"Kind",inline:!0,children:n.jsx("select",{value:a.kind,disabled:s,onChange:u=>{var d;const h=u.target.value;i(l,{kind:h,rule:((d=e.find(m=>m.kind===h))==null?void 0:d.maxRule)??a.rule})},children:(o?e:[...e,{kind:a.kind,plugin:"",maxRule:a.rule}]).map(u=>n.jsx("option",{value:u.kind,children:u.kind},u.kind))})}),n.jsx(ee,{label:"Target",inline:!0,grow:!0,children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:h8(a.kind),onChange:u=>i(l,{target:u.target.value})})}),n.jsx(ee,{label:"Rule",inline:!0,children:n.jsx("select",{value:a.rule,disabled:s,onChange:u=>i(l,{rule:u.target.value}),children:u8(c).map(u=>n.jsx("option",{value:u,children:PE[u]},u))})}),n.jsx(R,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((u,h)=>h!==l)),children:"Remove"})]},l)})})}function S8({destinations:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(""),[o,c]=f.useState(!1),[u,h]=f.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:e[0].maxRule}]:[]),[d,m]=f.useState(!1),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState(null),j=async()=>{const S=u.map(I=>OE(I.kind,I.target)),k=S.findIndex(I=>!I.ok);if(k!==-1){g(`Binding ${k+1}: ${S[k].error}`);return}const N=a;l("");const C=await Ui("secrets.put",{name:r.trim(),value:N,totp:o,bindings:u.map((I,A)=>({kind:I.kind,target:S[A].target,rule:I.rule}))},m,g);C!==null&&(b({name:r.trim(),result:C}),s())},w=async()=>{const S=await Ui("secrets.scrub_history",{name:(y==null?void 0:y.name)??""},m,g);S!==null&&(v(S),s())};return n.jsx(kt,{title:"Add a secret",onClose:t,children:y?n.jsx(zE,{name:y.name,result:y.result,scrubbed:x,busy:d,failure:p,onScrub:()=>void w(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:S=>{S.preventDefault(),j()},children:n.jsxs("fieldset",{disabled:d,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"Name",hint:"What an agent calls it. Saving a name that exists replaces that secret’s value.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:S=>i(S.target.value),placeholder:"PNC password"})}),n.jsx(ee,{label:"Value",hint:"Kept in the vault, never shown again — not even here.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:a,onChange:S=>l(S.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:S=>c(S.target.checked)}),n.jsx("span",{children:"The code comes from this secret"})]}),n.jsx("p",{className:"ui-field-hint",children:"The seed and the code are one thing buddi holds — the owner’s explicit choice per secret."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"Bindings — the places this value may go"}),n.jsx(UE,{destinations:e,bindings:u,disabled:d,onChange:h}),u.length===0?n.jsx("p",{className:"ui-field-hint",children:mv}):null,e.length?n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>h([...u,{kind:e[0].kind,target:"",rule:e[0].maxRule}]),children:"Add a binding"})}):n.jsx("p",{className:"ui-field-hint",children:"No destination is registered on this installation yet, so there is nothing to bind to."})]}),p?n.jsx(H,{tone:"critical",role:"alert",children:p}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save secret"})]})]})})})}function N8({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(null),p=async()=>{const y=r;i("");const b=await Ui("secrets.put",{name:e.name,value:y,totp:e.totp,bindings:e.bindings.map(({kind:x,target:v,rule:j})=>({kind:x,target:v,rule:j}))},l,c);b!==null&&(h(b),s())},g=async()=>{const y=await Ui("secrets.scrub_history",{name:e.name},l,c);y!==null&&(m(y),s())};return n.jsx(kt,{title:`Replace the value of “${e.name}”`,onClose:t,children:u?n.jsx(zE,{name:e.name,result:u,scrubbed:d,busy:a,failure:o,onScrub:()=>void g(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:y=>{y.preventDefault(),p()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"New value",hint:"Replaces what is stored. The bindings stay as they are.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,value:r,onChange:y=>i(y.target.value)})}),o?n.jsx(H,{tone:"critical",role:"alert",children:o}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save value"})]})]})})})}function C8({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(e.name),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{await Ui("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(kt,{title:`Rename “${e.name}”`,onClose:t,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:h=>{h.preventDefault(),u()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"New name",hint:"The vault entry never moves; only the name the agents ask for does.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:h=>i(h.target.value)})}),o?n.jsx(H,{tone:"critical",role:"alert",children:o}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:!r.trim()||r.trim()===e.name,children:"Save name"})]})]})})})}function E8({secret:e,destinations:t,onClose:s,onChanged:r}){const[i,a]=f.useState(()=>e.bindings.map(d=>({kind:d.kind,target:g8(d.target),rule:d.rule}))),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=async()=>{const d=i.map(g=>OE(g.kind,g.target)),m=d.findIndex(g=>!g.ok);if(m!==-1){u(`Binding ${m+1}: ${d[m].error}`);return}await Ui("secrets.rebind",{name:e.name,bindings:i.map((g,y)=>({kind:g.kind,target:d[y].target,rule:g.rule}))},o,u)!==null&&(r(),s())};return n.jsx(kt,{title:`Rebind “${e.name}”`,onClose:s,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:d=>{d.preventDefault(),h()},children:n.jsxs("fieldset",{disabled:l,className:"ui-stack","data-gap":"sm",children:[n.jsx(UE,{destinations:t,bindings:i,disabled:l,onChange:a}),i.length===0?n.jsx("p",{className:"ui-field-hint",children:mv}):null,t.length?n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>a([...i,{kind:t[0].kind,target:"",rule:t[0].maxRule}]),children:"Add a binding"})}):null,c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save bindings"})]})]})})})}function A8({timezone:e,embedded:t}){const{data:s,error:r,reload:i}=ae(()=>T.sentinels(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(p=>p.lastError),d=u.filter(p=>!p.enabled),m=(p,g)=>{l(p),c(null),T.setSentinelEnabled(p,g).catch(y=>c(y instanceof pe?y.message:String(y))).finally(()=>{l(null),i()})};return n.jsxs(wn,{embedded:t,title:"Watchers",children:[n.jsx(se,{message:r??o}),n.jsx(H,{children:"Watchers are small checks that run on their own, with no model involved. An urgent finding wakes an agent, which verifies it before it tells you. The rest waits for the weekly recap."}),h.length>0?n.jsx(H,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,d.length>0?n.jsxs(H,{tone:"warning",children:[d.length===1?"One watcher is off.":`${d.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,n.jsx(te,{title:"Installed",aside:n.jsx("a",{href:`${Ct}/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(jt,{children:u.map(p=>{const g=s.runs.find(y=>y.sentinelId===p.id);return n.jsx(yt,{lead:n.jsx(ge,{tone:p.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:p.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:p.description,sub:`${p.id}, every ${T8(p.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:g?We(g.lastRunAt,e):void 0,children:g?Fe(g.lastRunAt):"never ran"}),n.jsx(R,{size:"sm",disabled:a===p.id,onClick:()=>m(p.id,!p.enabled),children:p.enabled?"Turn off":"Turn on"})]})},p.id)})}):n.jsx(oe,{children:"Loading…"})})]})}function T8(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const t=Math.max(1,Math.round(e/60));return t===1?"minute":`${t} minutes`}function R8({embedded:e}){const{data:t,error:s,reload:r}=ae(()=>T.owner(),[]);return n.jsxs(wn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(se,{message:s}),t?n.jsx(I8,{initial:t,onSaved:r}):null]})}function I8({initial:e,onSaved:t}){const[s,r]=f.useState(e.preferredName??""),[i,a]=f.useState(e.timezone??""),[l,o]=f.useState(e.language??""),[c,u]=f.useState(e.about??""),[h,d]=f.useState(!1),[m,p]=f.useState(!1),[g,y]=f.useState(null);f.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.language??""),u(e.about??"")},[e]);const b=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l.trim()!==(e.language??"")||c.trim()!==(e.about??""),x=async()=>{d(!0),y(null);try{await T.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,language:l.trim()===""?null:l.trim(),about:c.trim()===""?null:c.trim()}),p(!0),t()}catch(j){y(j instanceof pe?j.message:String(j))}finally{d(!1)}},v=e.zones.length>0?e.zones:[e.detectedTimezone];return n.jsx(te,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:n.jsxs(n.Fragment,{children:[m&&!b?n.jsx("span",{className:"muted",children:"Saved"}):null,n.jsx(R,{variant:"accent",disabled:!b||h,onClick:()=>void x(),children:h?"Saving…":"Save"})]}),children:n.jsxs(Q,{divided:!0,gap:"lg",children:[n.jsx(te,{title:"Name and place",children:n.jsxs(bs,{children:[n.jsx(ee,{label:"What the agents call you",children:n.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:j=>{p(!1),r(j.target.value)}})}),n.jsx(ee,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:j=>{p(!1),a(j.target.value)},children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),v.map(j=>n.jsx("option",{value:j,children:j},j))]})}),n.jsx(ee,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:l,maxLength:40,placeholder:"English, français…",onChange:j=>{p(!1),o(j.target.value)}})})]})}),n.jsxs(te,{title:"About you",children:[n.jsx(ee,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:n.jsx("textarea",{rows:4,maxLength:1e3,value:c,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:j=>{p(!1),u(j.target.value)}})}),g?n.jsx(H,{tone:"critical",children:g}):null]})]})})}const P8=2e6;function ab(e,t){const s=e.replace(/\r\n/g,`
|
|
117
|
+
`).replace(/\n+$/,"").split(`
|
|
118
|
+
`),r=t.replace(/\r\n/g,`
|
|
119
|
+
`).replace(/\n+$/,"").split(`
|
|
120
|
+
`);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>P8)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
|
|
121
|
+
`);const i=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)i[c][u]=s[c]===r[u]?i[c+1][u+1]+1:Math.max(i[c+1][u],i[c][u+1]);const a=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(a.push(` ${s[l]}`),l++,o++):i[l+1][o]>=i[l][o+1]?a.push(`-${s[l++]}`):a.push(`+${r[o++]}`);for(;l<s.length;)a.push(`-${s[l++]}`);for(;o<r.length;)a.push(`+${r[o++]}`);return a.join(`
|
|
122
|
+
`)}const $8={skill:"skill",policy:"rule",change:"change to itself"};function M8(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 Dp(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function O8(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Dp(s.current??""));return Dp(t).filter(i=>!r.has(i))}function lb(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function D8({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=ae(()=>T.proposals(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState({}),p=async(x,v,j=!1)=>{l(null),c(null),h(x),m(({[x]:w,...S})=>S);try{c(await v()),i()}catch(w){const S=w instanceof Error?w.message:String(w);j?m(k=>({...k,[x]:S})):l(S)}finally{h(null)}},g=iC(),y=((s==null?void 0:s.open)??[]).filter(x=>lb(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>lb(x,t));return n.jsxs(wn,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Nothing here applies itself. Keep what is right, correct what is nearly right, discard the rest.",children:[n.jsx(se,{message:r??a}),t?n.jsxs(H,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:ze("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(H,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(aC,{offers:g.offers,reload:g.reload}),!s||y.length===0?n.jsx(te,{title:"Waiting",panel:!0,children:s?t?n.jsx(tn,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(tn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(oe,{children:"Loading…"})}):n.jsx(te,{title:"Waiting",aside:`${y.length} to decide`,children:y.map(x=>n.jsx(z8,{proposal:x,busy:u===x.id,refusal:d[x.id]??null,onKeep:v=>void p(x.id,async()=>{const j=await T.keepProposal(x.id,v);return`${x.title}: ${j.note}`},!0),onDiscard:v=>void p(x.id,async()=>(await T.discardProposal(x.id,v),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id))}),b.length>0?n.jsx(te,{title:`Kept, discarded and expired (${b.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:n.jsx(jt,{children:b.map(x=>{var v;return n.jsx(yt,{title:x.title,sub:`${x.agent}: ${_8(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((v=x.skill)!=null&&v.live)?n.jsxs(J,{align:"end",children:[n.jsx("span",{className:"muted",children:Fe(x.decidedAt??x.createdAt)}),n.jsx(R,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const j=x.skill;return await T.removeSkill(x.agent,j.name),`Removed ${j.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Fe(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(F8,{schedule:s.digest.schedule,onSaved:i}):null]})}function _8(e){switch(e.state){case"kept":return e.kind==="skill"&&e.skill?e.skill.live?`Kept as ${e.skill.name}, version ${e.skill.version}; it loads on the agent's next run.`:`Kept; ${e.skill.name} has a newer version now (${e.skill.version}).`:e.note??"Kept.";case"discarded":return e.reason?`Discarded: ${e.reason}`:"Discarded.";case"expired":return`Expired: ${e.reason??"not decided in 30 days"}.`;default:return"Waiting."}}const L8=Array.from({length:24},(e,t)=>t),ob=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function F8({schedule:e,onSaved:t}){const[s,r]=f.useState(e.day),[i,a]=f.useState(e.hour),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=s!==e.day||i!==e.hour,d=async()=>{o(!0),u(null);try{await T.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${ob[s]} at ${String(i).padStart(2,"0")}:00.`}),t()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return n.jsx(te,{title:"Weekly digest",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:l||!h,onClick:()=>void d(),children:"Save"}),children:n.jsxs(Q,{children:[n.jsxs("p",{className:"muted",children:["Once a week, one message on Telegram and a card on Home: what your agents learned, what waits here, and what the rules you kept stopped them doing. No message when nothing was learned and nothing waits.",e.next?` Next: ${Fe(e.next)}.`:""]}),n.jsxs(J,{children:[n.jsx(ee,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:ob.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(ee,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:L8.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(H,{tone:c.tone,role:"status",children:c.text}):null]})})}function cb(e,t){return e==="tools"?Dp(t).join(`
|
|
123
|
+
`):t}function z8({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=f.useState(e.editable??""),[o,c]=f.useState(""),u=e.editable!==null&&a!==e.editable,h=e.payload,d=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=O8(e,a);return n.jsx(ks,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{children:$8[e.kind]}),n.jsx(ge,{mono:!0,children:e.agent}),e.untrusted?n.jsx(ge,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(ge,{tone:"warning",children:"widens its tools"}):null]}),foot:n.jsxs(J,{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(R,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(R,{variant:"accent",size:"sm",disabled:t||e.editable!==null&&a.trim()==="",onClick:()=>r(u?a:void 0),children:u?"Keep my version":"Keep"})]}),children:n.jsxs(Q,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Fe(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:Ha(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(H,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",n.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>n.jsx("li",{className:"mono",children:g},g))}),d.length>0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),n.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:d.map(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(Q,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.jsxs("a",{href:gt(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),n.jsx(Qu,{text:ab(e.skill.steps,a),marks:d,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(ee,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?n.jsxs(n.Fragment,{children:[p.length>0?n.jsxs(H,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?n.jsx(H,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(Qu,{text:ab(cb(m.part,m.current),cb(m.part,a)),marks:d,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?n.jsx(Et,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(vt,{children:h.before})}):null,n.jsx(ee,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?n.jsx(Gt,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:M8(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 U8(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 B8({start:e,onPick:t,onClose:s}){const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(""),u=(p,g=!1)=>{l(null),T.pluginFolders(p).then(y=>{i(y),c("")}).catch(y=>{g&&p!==void 0?u(void 0):l(y instanceof pe?y.message:String(y))})};f.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),d=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?U8(r):[];return n.jsxs(kt,{title:"Choose the folder",onClose:s,foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!r,onClick:()=>r&&t(r.path),children:"Use this folder"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Folders on the computer buddi runs on, inside your home directory. The one you want holds the plugin's package.json and is already built."}),r?n.jsx(b1,{label:"Folder",items:m.map((p,g)=>g===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,n.jsx(w1,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(se,{message:a}),r?d.length===0?n.jsx(oe,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(Qe,{flush:!0,children:n.jsx(jt,{children:d.map(p=>n.jsx(yt,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(Va,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(ge,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(oe,{children:"Reading the folders…"}),r!=null&&r.truncated?n.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const W8="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 ub(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ye,{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:ze("connections"),children:"Connections"})]})]})}const H8=1500,K8={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."},V8="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",BE=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],WE="buddi.plugins.install-mode";function G8(){try{const e=window.localStorage.getItem(WE);if(BE.some(t=>t.value===e))return e}catch{}return"npm"}function Y8(e){try{window.localStorage.setItem(WE,e)}catch{}}const Kc=".tgz",Qr=(e,t,s)=>`${e} ${e===1?t:s}`;function HE(e){const t=[];return e.tools>0&&t.push(Qr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Qr(e.views,"view","views")),e.agents>0&&t.push(`${Qr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function _p(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 q8(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function KE(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function VE(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function pv({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 Lp({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 GE(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function gv(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 ii=e=>e instanceof pe?e.message:String(e);function Q8(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(null);return f.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{T.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(ii(c)),a=!0)})};l();const o=window.setInterval(l,H8);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function J8({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=ni(a.plugin,a.id);return n.jsx(Ut,{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 YE({plugin:e}){return e.enabled===!1?n.jsx(ge,{children:"disabled"}):e.loaded?n.jsx(ge,{tone:"good",dot:!0,children:"loaded"}):n.jsx(ge,{tone:"critical",children:"did not load"})}function xv({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(ge,{tone:"accent",children:"by buddi"}):n.jsxs(ge,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const Fp=ze("plugins"),Ef={installed:Fp,browse:`${Fp}?tab=browse`};function X8({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=ae(()=>T.plugins(),[],2e4),[a,l]=f.useState(null),{job:o,error:c}=Q8(a),[u,h]=f.useState(null),[d,m]=f.useState(null),[p,g]=f.useState(()=>Fy(r));f.useEffect(()=>g(Fy(r)),[r]);const[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(null),[S,k]=f.useState(null),[N,C]=f.useState(!1),I=G=>{C(!0),T.market(G).then(k).catch(ie=>k({plugins:[],unavailable:ii(ie)})).finally(()=>C(!1))};f.useEffect(()=>{p==="browse"&&S===null&&!N&&I(!1)},[p]);const A=G=>{h(null),m(null),l(G)},O=G=>h(ii(G)),[z,L]=f.useState(!1),E=G=>{L(!0),b(null),G.then(ie=>{A(ie.job.id),g("installed")}).catch(O).finally(()=>L(!1))},$=f.useRef(null);f.useEffect(()=>{const G=nD(r);if(!(G===null||$.current===G)){$.current=G,g("installed"),E(T.stagePlugin(G));try{window.history.replaceState(window.history.state,"",Fp)}catch{}}},[r]);const _=G=>ie=>{ie.preventDefault(),g(G),b(null),s==null||s(Ef[G])};f.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const B=i.data,M=(B==null?void 0:B.checkout)??!0,W=(B==null?void 0:B.installed)??[],D=G=>S==null?void 0:S.plugins.find(ie=>ie.installed!==void 0&&(ie.installed.name??ie.name)===G.name),U=G=>e.some(ie=>ie.plugin===G),V=(G,ie)=>U(G)?n.jsx(J8,{plugin:G,pages:e,navigate:s,variant:ie}):void 0,Z=G=>{const ie=e.find(Pe=>Pe.plugin===G);ie&&s&&s(ni(ie.plugin,ie.id))},ue=G=>{const ie=t.find(Pe=>Pe.plugin===G);if(!(!ie||!s))return()=>s(ll(ie.plugin,ie.id))},Ae=((S==null?void 0:S.plugins)??[]).filter(G=>G.update).length,X=(G,ie)=>T.setPluginEnabled(G,ie).then(Pe=>{WL(),w({name:G,notes:Pe.notes??[]}),i.reload()}),le=(G,ie,Pe)=>T.uninstallPlugin(G,ie?{purge:!0,confirm:Pe}:{}).then(it=>{b(null),w({name:G,notes:it.notes??[]}),i.reload()}),me=G=>{h(null),X(G,!0).catch(O)},$e=(G,ie)=>{const Pe=S==null?void 0:S.plugins.find(Ye=>{var at;return(((at=Ye.installed)==null?void 0:at.name)??Ye.name)===G&&Ye.installed!==void 0}),it=Pe&&ie?`${Pe.npm}@${ie}`:void 0;E(it?T.updatePlugin(G,ie,it):T.updatePlugin(G,ie))},ke=n.jsxs(Yo,{label:"Plugins",children:[n.jsx(Ka,{href:Ef.installed,active:p==="installed",count:Ae,onClick:_("installed"),children:"Installed"}),n.jsx(Ka,{href:Ef.browse,active:p==="browse",onClick:_("browse"),children:"Browse"})]}),we=(y==null?void 0:y.kind)==="installed"?W.find(G=>G.name===y.name):void 0,Ce=(y==null?void 0:y.kind)==="market"?S==null?void 0:S.plugins.find(G=>G.name===y.name):void 0,dt=j&&!(we&&we.name===j.name)&&j.notes.length>0?j.notes:null,fe=we?n.jsx(lW,{plugin:we,listing:D(we),notes:(j==null?void 0:j.name)===we.name?j.notes:null,canOpen:U(we.name)&&we.enabled!==!1,onOpen:()=>Z(we.name),onClose:()=>b(null),onDisable:()=>v({kind:"disable",name:we.name}),onEnable:()=>me(we.name),onRemove:()=>v({kind:"remove",name:we.name}),onUpdate:G=>$e(we.name,G),onSettings:we.enabled===!1?void 0:ue(we.name),busy:z}):Ce?n.jsx(pW,{entry:Ce,canOpen:Ce.installed!==void 0&&U(Ce.installed.name??Ce.name),onOpen:()=>{var G;return Z(((G=Ce.installed)==null?void 0:G.name)??Ce.name)},onClose:()=>b(null),onInstall:()=>E(T.stagePlugin(`${Ce.npm}@${Ce.version}`)),onUpdate:G=>{var ie;return $e(((ie=Ce.installed)==null?void 0:ie.name)??Ce.name,G)},busy:z}):null,Me=x?W.find(G=>G.name===x.name):void 0,ce=x?n.jsx(oW,{kind:x.kind,name:x.name,canDisable:(Me==null?void 0:Me.enabled)!==!1,onCancel:()=>v(null),onDisableInstead:()=>v({kind:"disable",name:x.name}),onDisable:()=>X(x.name,!1).then(()=>v(null)),onRemove:(G,ie)=>le(x.name,G,ie).then(()=>v(null))},`${x.kind}:${x.name}`):null;if(p==="browse")return n.jsxs(Q,{gap:"lg",children:[n.jsx(ub,{}),ke,n.jsx(se,{message:u}),n.jsx(gW,{market:S,loading:N,busy:z,onRetry:()=>I(!0),onOpen:G=>b({kind:"market",name:G.name}),onInstall:G=>E(T.stagePlugin(`${G.npm}@${G.version}`)),onUpdate:(G,ie)=>{var Pe;return $e(((Pe=G.installed)==null?void 0:Pe.name)??G.name,ie)}}),fe]});const Te=(B==null?void 0:B.builtIn)??[];return n.jsxs(Q,{gap:"lg",children:[n.jsx(ub,{}),ke,n.jsx(se,{message:i.error??u??c}),B!=null&&B.unavailable?n.jsx(H,{tone:"warning",children:B.unavailable}):null,dt?n.jsx(H,{role:"status",children:dt.join(" ")}):null,n.jsx(Z8,{trust:(B==null?void 0:B.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:A,onFailed:h}),((B==null?void 0:B.staged)??[]).map(G=>n.jsx(tW,{staged:G,onInstalled:ie=>{m(ie),l(null),i.reload()},onGone:()=>i.reload()},G.id)),d||B!=null&&B.restartNeeded?n.jsx(nW,{checkout:M,name:d}):null,n.jsx(Qe,{flush:!0,title:"Installed",tool:B?Qr(W.length,"plugin","plugins"):void 0,children:B?W.length===0?n.jsx(oe,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(jt,{children:W.map(G=>n.jsx(rW,{plugin:G,listing:D(G),open:G.enabled===!1?void 0:V(G.name,"ghost"),canOpen:U(G.name)&&G.enabled!==!1,busy:z,onDetails:()=>b({kind:"installed",name:G.name}),onOpen:()=>Z(G.name),onSettings:G.enabled===!1?void 0:ue(G.name),onDisable:()=>v({kind:"disable",name:G.name}),onEnable:()=>me(G.name),onRemove:()=>v({kind:"remove",name:G.name}),onUpdate:ie=>$e(G.name,ie)},G.name))})}):n.jsx(oe,{children:"Loading…"})}),Te.length>0?n.jsx(cW,{plugins:Te,openFor:V}):null,fe,ce]})}function Z8({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=f.useState(G8),[o,c]=f.useState(""),[u,h]=f.useState(!1),[d,m]=f.useState(null),[p,g]=f.useState(null),[y,b]=f.useState(!1),[x,v]=f.useState(!1),j=f.useRef(null),w=C=>i(ii(C)),S=C=>{l(C),Y8(C),g(null)},k=()=>{h(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(w).finally(()=>h(!1))},N=C=>{if(C){if(!C.name.toLowerCase().endsWith(Kc)){m(null),g(`${C.name} is not a ${Kc}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),T.uploadPlugin(C).then(I=>r(I.job.id)).catch(w).finally(()=>h(!1))}};return n.jsxs(Qe,{title:"Add a plugin",actions:n.jsx(ls,{label:"Where it comes from",options:BE,value:a,onChange:S}),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":y?"over":p?"refused":d?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var I,A;C.preventDefault(),b(!1),N((A=(I=C.dataTransfer)==null?void 0:I.files)==null?void 0:A[0])},children:[n.jsx(ye,{name:"drop",size:20}),n.jsx("span",{className:"plugins-drop-text",children:p??(d?`${d} — reading it.`:n.jsxs(n.Fragment,{children:["Drop a ",n.jsx("span",{className:"mono",children:Kc})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(R,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=j.current)==null?void 0:C.click()},children:"Choose a file"}),n.jsx("input",{ref:j,type:"file",accept:Kc,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var I;N((I=C.target.files)==null?void 0:I[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(J,{valign:"end",children:[n.jsx(ee,{grow:!0,label:a==="npm"?"Package":"The directory it is in",children:n.jsx("input",{type:"text",value:o,placeholder:a==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),a==="directory"?n.jsx(R,{onClick:()=>v(!0),children:"Browse…"}):null,n.jsx(R,{variant:"accent",disabled:s||u||o.trim()==="",onClick:k,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[K8[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(H,{tone:"warning",children:e})})]}),x?n.jsx(B8,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function eW({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?gv([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(ge,{tone:"warning",children:["new in ",e.version]}):null]},a.use)),s.length>0?n.jsxs("span",{className:"muted",children:["No longer: ",s.map(a=>a.words).join("; "),"."]}):null]})}function tW({staged:e,onInstalled:t,onGone:s}){const[r,i]=f.useState(e.plan??null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=p=>{l(!0),c(null),T.approveStaged(e.id,{integrity:e.integrity??"",...p?{acknowledgeDrift:!0}:{}}).then(g=>{g.installed?t(e.name):g.plan&&i(g.plan)}).catch(g=>c(ii(g))).finally(()=>l(!1))},h=()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(p=>c(ii(p))).finally(()=>l(!1))},d=(r==null?void 0:r.drift)??[],m=e.dependencies;return n.jsxs(Q,{gap:"sm",children:[n.jsxs(ks,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(ge,{children:"read, not installed"}),foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:h,children:"Not this one"}),n.jsx(R,{variant:"accent",disabled:a||d.length>0,onClick:()=>u(!1),children:"Install"})]}),children:[n.jsx(se,{message:o}),n.jsxs("div",{className:"plugins-staged",children:[n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[...e.author?[{label:"By",value:n.jsx(pv,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:_p(e.source)},{label:"Published by",value:KE(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${_p(e.previousSource)}`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?n.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:m.count===0?"none":`${m.count}${m.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${m.withScripts.join(", ")}`}`},{label:"What it reaches",value:n.jsx(eW,{staged:e})},{label:"Integrity",value:n.jsx(Lp,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(Lp,{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(Gt,{items:[{label:"Schema it owns",value:e.claims.schema?n.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":n.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})]}),d.length>0?n.jsxs(ks,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(ge,{tone:"warning",children:"read this first"}),foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:h,children:"Not this one"}),n.jsx(R,{variant:"danger",disabled:a,onClick:()=>u(!0),children:"Install anyway"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),n.jsx("ul",{className:"plugins-drift",children:d.map(p=>n.jsx("li",{children:p},p))}),n.jsx(qE,{unlocks:(r==null?void 0:r.agents)??[]})]}):null]})}function nW({checkout:e,name:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(null),l=t?`${t} is installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:i}),n.jsxs(H,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(R,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),T.serviceAction("restart").catch(o=>a(ii(o))).finally(()=>r(!1))},children:"Restart to load it"}),children:[l," ",e?V8:`${t?"Its tools appear":"It takes effect"} once buddi restarts. That closes this dashboard for a few seconds.`]})]})}const zp=e=>t=>{t.stopPropagation(),e()},sW=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function rW({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:d}){const m=e.enabled===!1,p=sW(e);return n.jsx(yt,{onClick:a,label:`${e.name}: details`,dimmed:m,lead:n.jsx(Va,{svg:t==null?void 0:t.iconSvg}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version}),p>0?n.jsxs("span",{className:"plugins-ask",children:[Qr(p,"agent","agents")," to accept"]}):null]}),sub:`by ${VE(e)} · from ${q8(e.source)} · ${HE(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[t!=null&&t.update?n.jsxs(R,{size:"sm",disabled:i,onClick:zp(()=>d(t.update)),children:["Update to ",t.update]}):null,s,!r&&o?n.jsx(R,{size:"sm",variant:"ghost",onClick:g=>{g.stopPropagation(),o()},children:"Settings"}):null,n.jsx(YE,{plugin:e}),n.jsx(Y_,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,m?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const iW={"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 qE({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(te,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(jt,{children:t.map(s=>n.jsx(aW,{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:pt,children:"on the Agents page"}),"."]})]})}function aW({plugin:e,unlock:t}){const s=Vx(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=iW[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(yt,{title:n.jsxs("span",{className:"plugins-handle",children:["@",t.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":t.drift.message,side:n.jsxs("span",{className:"plugins-side",children:[n.jsx(ge,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(R,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(se,{message:s.failure}),s.created?n.jsx(sC,{agent:s.created}):null]})}function QE({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Va,{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 lW({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:d}){var x,v;const m=e.enabled===!1,p=e.author!==void 0&&e.source.kind==="directory",g=(t==null?void 0:t.summary)??e.description,y=(e.network??((v=(x=t==null?void 0:t.claims)==null?void 0:x.manifest)==null?void 0:v.network)??[]).map(j=>j.host),b=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(kt,{title:n.jsx(QE,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(pv,{author:e.author}):VE(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(xv,{entry:t})]}):null," · ",n.jsx(YE,{plugin:e})]})}),onClose:o,foot:n.jsxs(J,{children:[n.jsx(R,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(en,{}),l?n.jsx(R,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(R,{onClick:a,children:"Open"}):null,m?n.jsx(R,{onClick:u,children:"Enable"}):n.jsx(R,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(R,{variant:"accent",disabled:i,onClick:()=>d(t.update),children:["Update to ",t.update]}):n.jsx(R,{disabled:i,onClick:()=>d(),children:"Check for an update"})]}),children:[e.error?n.jsx(H,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(H,{role:"status",children:s.join(" ")}):null,m?n.jsx(H,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,g?n.jsx("p",{className:"plugins-summary-full",children:g}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"From",value:_p(e.source)},...p?[]:[{label:"Published by",value:KE(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(Lp,{value:e.integrity})},{label:"Installed",value:Fe(e.installedAt)},{label:"Contributes",value:HE(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:GE(y)}]:[],...b?[{label:"Reaches in buddi",value:gv(b)}]:[]]})}),n.jsx(qE,{plugin:e.name,unlocks:e.unlocks})]})}function oW({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(!1),[p,g]=f.useState(null),y=x=>{m(!0),g(null),x().catch(v=>g(ii(v))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Ju,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:d,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:d,onClick:()=>y(a),children:"Disable"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),n.jsx(se,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Ju,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(R,{variant:"ghost",size:"sm",disabled:d,onClick:i,children:"Disable instead"}):null,n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:d,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:d||!b,onClick:()=>y(()=>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:x=>{c(x.target.checked),h("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(ee,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:x=>h(x.target.value)})}):null]}),n.jsx(se,{message:p})]})}function cW({plugins:e,openFor:t}){return n.jsxs(Et,{boxed:!0,summary:`Ships with buddi · ${Qr(e.length,"plugin","plugins")}`,children:[n.jsx("p",{className:"plugins-note",children:"Compiled into this buddi: nothing to approve, nothing to remove. An agent still reaches one only if its own tools line names it."}),n.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(a=>a.host),i=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return n.jsxs("div",{className:"plugins-builtin",title:i||void 0,children:[n.jsx("span",{className:"mono",children:s.name}),n.jsxs("span",{className:"plugins-builtin-n",children:[t(s.name,"ghost"),Qr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const uW=[{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 dW(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function hW({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 fW({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(ks,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(Va,{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(xv,{entry:e}),e.installed?n.jsxs(ge,{children:["installed ",e.installed.version]}):null,n.jsx(en,{}),e.update?n.jsxs(R,{size:"sm",disabled:t,onClick:zp(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{size:"sm",variant:"accent",disabled:t,onClick:zp(r),children:"Install"})]})]})}function mW(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 pW({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,y,b,x,v,j;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(w=>w.host),u=mW(e),h=((x=(b=(y=e.claims)==null?void 0:y.manifest)==null?void 0:b.agents)==null?void 0:x.length)??0,d=(j=(v=e.claims)==null?void 0:v.package)==null?void 0:j.dependencies;return n.jsxs(kt,{title:n.jsx(QE,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(pv,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(xv,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(ge,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:e.installed&&!e.update?"This is the version you have.":"Install reads it first. Nothing of it runs until you say yes."}),n.jsx(en,{}),t?n.jsx(R,{onClick:r,children:"Open"}):null,e.update?n.jsxs(R,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:T.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Qr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:GE(c)},{label:"Reaches in buddi",value:gv(e.usesWords??[])},...d?[{label:"Dependencies",value:d.count===0?"none":`${d.count}${d.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${d.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:n.jsxs(n.Fragment,{children:[e.license??"not stated"," · ",n.jsx(hW,{pricing:e.pricing})]})}]})})]})}function gW({market:e,loading:t,busy:s,onRetry:r,onOpen:i,onInstall:a,onUpdate:l}){const[o,c]=f.useState(""),[u,h]=f.useState("all"),d=(e==null?void 0:e.plugins)??[],m=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...uW.filter(y=>d.some(b=>b.category===y.value))],p=d.filter(y=>u==="recommended"&&(y.trust!=="by-buddi"||y.installed)||u!=="all"&&u!=="recommended"&&y.category!==u?!1:dW(y,o)),g=o.trim();return n.jsxs(Q,{gap:"lg",children:[n.jsxs(J,{children:[n.jsx(w1,{grow:!0,label:"Search plugins",value:o,placeholder:"Search plugins: weather, money, calendar…",onChange:c}),n.jsx(X_,{label:"Show",options:m,value:u,onChange:h})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ye,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",n.jsx("button",{type:"button",className:"plugins-link",disabled:t,onClick:r,children:"Refresh"})]}),e===null||t&&e.unavailable?n.jsx(oe,{children:"Asking withbuddi.com…"}):e.unavailable?n.jsx(H,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:e.unavailable}):n.jsxs(n.Fragment,{children:[e.stale?n.jsxs(H,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",e.fetchedAt?` ${Fe(e.fetchedAt)}`:" last time","."]}):null,p.length>0?n.jsx("div",{className:"plugins-grid",children:p.map(y=>n.jsx(fW,{entry:y,busy:s,onOpen:()=>i(y),onInstall:()=>a(y),onUpdate:b=>l(y,b)},y.npm))}):n.jsx(oe,{warm:!0,title:"Nothing listed matches",children:g!==""?`No plugin on withbuddi.com mentions “${g}”.`:d.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]})]})}var Qo={},xW=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},JE={},Qn={};let vv;const vW=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Qn.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};Qn.getSymbolTotalCodewords=function(t){return vW[t]};Qn.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};Qn.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');vv=t};Qn.isKanjiModeEnabled=function(){return typeof vv<"u"};Qn.toSJIS=function(t){return vv(t)};var ih={};(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}}})(ih);function XE(){this.buffer=[],this.length=0}XE.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 jW=XE;function Jo(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)}Jo.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};Jo.prototype.get=function(e,t){return this.data[e*this.size+t]};Jo.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};Jo.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var yW=Jo,ZE={};(function(e){const t=Qn.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const i=Math.floor(r/7)+2,a=t(r),l=a===145?26:Math.ceil((a-13)/(2*i-2))*2,o=[a-7];for(let c=1;c<i-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const i=[],a=e.getRowColCoords(r),l=a.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||i.push([a[o],a[c]]);return i}})(ZE);var eA={};const wW=Qn.getSymbolSize,db=7;eA.getPositions=function(t){const s=wW(t);return[[0,0],[s-db,0],[0,s-db]]};var tA={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,h=null;for(let d=0;d<a;d++){o=c=0,u=h=null;for(let m=0;m<a;m++){let p=i.get(d,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,d),p===h?c++:(c>=5&&(l+=t.N1+(c-5)),h=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let h=0;h<a;h++)o=o<<1&2047|i.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const h=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),h<c&&(c=h,o=u)}return o}})(tA);var ah={};const _r=ih,Vc=[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],Gc=[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];ah.getBlocksCount=function(t,s){switch(s){case _r.L:return Vc[(t-1)*4+0];case _r.M:return Vc[(t-1)*4+1];case _r.Q:return Vc[(t-1)*4+2];case _r.H:return Vc[(t-1)*4+3];default:return}};ah.getTotalCodewordsCount=function(t,s){switch(s){case _r.L:return Gc[(t-1)*4+0];case _r.M:return Gc[(t-1)*4+1];case _r.Q:return Gc[(t-1)*4+2];case _r.H:return Gc[(t-1)*4+3];default:return}};var nA={},lh={};const Xl=new Uint8Array(512),dd=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Xl[s]=t,dd[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Xl[s]=Xl[s-255]})();lh.log=function(t){if(t<1)throw new Error("log("+t+")");return dd[t]};lh.exp=function(t){return Xl[t]};lh.mul=function(t,s){return t===0||s===0?0:Xl[dd[t]+dd[s]]};(function(e){const t=lh;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}})(nA);const sA=nA;function jv(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}jv.prototype.initialize=function(t){this.degree=t,this.genPoly=sA.generateECPolynomial(this.degree)};jv.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=sA.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 bW=jv,rA={},hi={},yv={};yv.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var Ys={};const iA="[0-9]+",kW="[A-Z $%*+\\-./:]+";let Mo="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Mo=Mo.replace(/u/g,"\\u");const SW="(?:(?![A-Z0-9 $%*+\\-./:]|"+Mo+`)(?:.|[\r
|
|
124
|
+
]))+`;Ys.KANJI=new RegExp(Mo,"g");Ys.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Ys.BYTE=new RegExp(SW,"g");Ys.NUMERIC=new RegExp(iA,"g");Ys.ALPHANUMERIC=new RegExp(kW,"g");const NW=new RegExp("^"+Mo+"$"),CW=new RegExp("^"+iA+"$"),EW=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Ys.testKanji=function(t){return NW.test(t)};Ys.testNumeric=function(t){return CW.test(t)};Ys.testAlphanumeric=function(t){return EW.test(t)};(function(e){const t=yv,s=Ys;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(a,l){if(!a.ccBits)throw new Error("Invalid mode: "+a);if(!t.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?a.ccBits[0]:l<27?a.ccBits[1]:a.ccBits[2]},e.getBestModeForData=function(a){return s.testNumeric(a)?e.NUMERIC:s.testAlphanumeric(a)?e.ALPHANUMERIC:s.testKanji(a)?e.KANJI:e.BYTE},e.toString=function(a){if(a&&a.id)return a.id;throw new Error("Invalid mode")},e.isValid=function(a){return a&&a.bit&&a.ccBits};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+i)}}e.from=function(a,l){if(e.isValid(a))return a;try{return r(a)}catch{return l}}})(hi);(function(e){const t=Qn,s=ah,r=ih,i=hi,a=yv,l=7973,o=t.getBCHDigit(l);function c(m,p,g){for(let y=1;y<=40;y++)if(p<=e.getCapacity(y,g,m))return y}function u(m,p){return i.getCharCountIndicator(m,p)+4}function h(m,p){let g=0;return m.forEach(function(y){const b=u(y.mode,p);g+=b+y.getBitsLength()}),g}function d(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,y){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof y>"u"&&(y=i.BYTE);const b=t.getSymbolTotalCodewords(p),x=s.getTotalCodewordsCount(p,g),v=(b-x)*8;if(y===i.MIXED)return v;const j=v-u(y,p);switch(y){case i.NUMERIC:return Math.floor(j/10*3);case i.ALPHANUMERIC:return Math.floor(j/11*2);case i.KANJI:return Math.floor(j/13);case i.BYTE:default:return Math.floor(j/8)}},e.getBestVersionForData=function(p,g){let y;const b=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return d(p,b);if(p.length===0)return 1;y=p[0]}else y=p;return c(y.mode,y.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}})(rA);var aA={};const Up=Qn,lA=1335,AW=21522,hb=Up.getBCHDigit(lA);aA.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Up.getBCHDigit(i)-hb>=0;)i^=lA<<Up.getBCHDigit(i)-hb;return(r<<10|i)^AW};var oA={};const TW=hi;function Ya(e){this.mode=TW.NUMERIC,this.data=e.toString()}Ya.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Ya.prototype.getLength=function(){return this.data.length};Ya.prototype.getBitsLength=function(){return Ya.getBitsLength(this.data.length)};Ya.prototype.write=function(t){let s,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 RW=Ya;const IW=hi,Af=["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 qa(e){this.mode=IW.ALPHANUMERIC,this.data=e}qa.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};qa.prototype.getLength=function(){return this.data.length};qa.prototype.getBitsLength=function(){return qa.getBitsLength(this.data.length)};qa.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Af.indexOf(this.data[s])*45;r+=Af.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(Af.indexOf(this.data[s]),6)};var PW=qa;const $W=hi;function Qa(e){this.mode=$W.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}Qa.getBitsLength=function(t){return t*8};Qa.prototype.getLength=function(){return this.data.length};Qa.prototype.getBitsLength=function(){return Qa.getBitsLength(this.data.length)};Qa.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var MW=Qa;const OW=hi,DW=Qn;function Ja(e){this.mode=OW.KANJI,this.data=e}Ja.getBitsLength=function(t){return t*13};Ja.prototype.getLength=function(){return this.data.length};Ja.prototype.getBitsLength=function(){return Ja.getBitsLength(this.data.length)};Ja.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=DW.toSJIS(this.data[t]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
|
|
125
|
+
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var _W=Ja,cA={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,h,d,m,p,g,y,b;!o.empty();){c=o.pop(),u=c.value,d=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],g=d+p,y=l[h],b=typeof l[h]>"u",(b||y>g)&&(l[h]=g,o.push(h,g),a[h]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var x=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(x)}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})(cA);var LW=cA.exports;(function(e){const t=hi,s=RW,r=PW,i=MW,a=_W,l=Ys,o=Qn,c=LW;function u(x){return unescape(encodeURIComponent(x)).length}function h(x,v,j){const w=[];let S;for(;(S=x.exec(j))!==null;)w.push({data:S[0],index:S.index,mode:v,length:S[0].length});return w}function d(x){const v=h(l.NUMERIC,t.NUMERIC,x),j=h(l.ALPHANUMERIC,t.ALPHANUMERIC,x);let w,S;return o.isKanjiModeEnabled()?(w=h(l.BYTE,t.BYTE,x),S=h(l.KANJI,t.KANJI,x)):(w=h(l.BYTE_KANJI,t.BYTE,x),S=[]),v.concat(j,w,S).sort(function(N,C){return N.index-C.index}).map(function(N){return{data:N.data,mode:N.mode,length:N.length}})}function m(x,v){switch(v){case t.NUMERIC:return s.getBitsLength(x);case t.ALPHANUMERIC:return r.getBitsLength(x);case t.KANJI:return a.getBitsLength(x);case t.BYTE:return i.getBitsLength(x)}}function p(x){return x.reduce(function(v,j){const w=v.length-1>=0?v[v.length-1]:null;return w&&w.mode===j.mode?(v[v.length-1].data+=j.data,v):(v.push(j),v)},[])}function g(x){const v=[];for(let j=0;j<x.length;j++){const w=x[j];switch(w.mode){case t.NUMERIC:v.push([w,{data:w.data,mode:t.ALPHANUMERIC,length:w.length},{data:w.data,mode:t.BYTE,length:w.length}]);break;case t.ALPHANUMERIC:v.push([w,{data:w.data,mode:t.BYTE,length:w.length}]);break;case t.KANJI:v.push([w,{data:w.data,mode:t.BYTE,length:u(w.data)}]);break;case t.BYTE:v.push([{data:w.data,mode:t.BYTE,length:u(w.data)}])}}return v}function y(x,v){const j={},w={start:{}};let S=["start"];for(let k=0;k<x.length;k++){const N=x[k],C=[];for(let I=0;I<N.length;I++){const A=N[I],O=""+k+I;C.push(O),j[O]={node:A,lastCount:0},w[O]={};for(let z=0;z<S.length;z++){const L=S[z];j[L]&&j[L].node.mode===A.mode?(w[L][O]=m(j[L].lastCount+A.length,A.mode)-m(j[L].lastCount,A.mode),j[L].lastCount+=A.length):(j[L]&&(j[L].lastCount=A.length),w[L][O]=m(A.length,A.mode)+4+t.getCharCountIndicator(A.mode,v))}}S=C}for(let k=0;k<S.length;k++)w[S[k]].end=0;return{map:w,table:j}}function b(x,v){let j;const w=t.getBestModeForData(x);if(j=t.from(v,w),j!==t.BYTE&&j.bit<w.bit)throw new Error('"'+x+'" cannot be encoded with mode '+t.toString(j)+`.
|
|
126
|
+
Suggested mode is: `+t.toString(w));switch(j===t.KANJI&&!o.isKanjiModeEnabled()&&(j=t.BYTE),j){case t.NUMERIC:return new s(x);case t.ALPHANUMERIC:return new r(x);case t.KANJI:return new a(x);case t.BYTE:return new i(x)}}e.fromArray=function(v){return v.reduce(function(j,w){return typeof w=="string"?j.push(b(w,null)):w.data&&j.push(b(w.data,w.mode)),j},[])},e.fromString=function(v,j){const w=d(v,o.isKanjiModeEnabled()),S=g(w),k=y(S,j),N=c.find_path(k.map,"start","end"),C=[];for(let I=1;I<N.length-1;I++)C.push(k.table[N[I]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(d(v,o.isKanjiModeEnabled()))}})(oA);const oh=Qn,Tf=ih,FW=jW,zW=yW,UW=ZE,BW=eA,Bp=tA,Wp=ah,WW=bW,hd=rA,HW=aA,KW=hi,Rf=oA;function VW(e,t){const s=e.size,r=BW.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 GW(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 YW(e,t){const s=UW.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 qW(e,t){const s=e.size,r=hd.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 If(e,t,s){const r=e.size,i=HW.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 QW(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 JW(e,t,s){const r=new FW;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),KW.getCharCountIndicator(c.mode,e)),c.write(r)});const i=oh.getSymbolTotalCodewords(e),a=Wp.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 XW(r,e,t)}function XW(e,t,s){const r=oh.getSymbolTotalCodewords(t),i=Wp.getTotalCodewordsCount(t,s),a=r-i,l=Wp.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(a/l),d=h+1,m=u-h,p=new WW(m);let g=0;const y=new Array(l),b=new Array(l);let x=0;const v=new Uint8Array(e.buffer);for(let N=0;N<l;N++){const C=N<c?h:d;y[N]=v.slice(g,g+C),b[N]=p.encode(y[N]),g+=C,x=Math.max(x,C)}const j=new Uint8Array(r);let w=0,S,k;for(S=0;S<x;S++)for(k=0;k<l;k++)S<y[k].length&&(j[w++]=y[k][S]);for(S=0;S<m;S++)for(k=0;k<l;k++)j[w++]=b[k][S];return j}function ZW(e,t,s,r){let i;if(Array.isArray(e))i=Rf.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=Rf.rawSplit(e);u=hd.getBestVersionForData(h,s)}i=Rf.fromString(e,u||40)}else throw new Error("Invalid data");const a=hd.getBestVersionForData(i,s);if(!a)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=a;else if(t<a)throw new Error(`
|
|
127
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
128
|
+
Minimum version required to store current data is: `+a+`.
|
|
129
|
+
`);const l=JW(t,s,i),o=oh.getSymbolSize(t),c=new zW(o);return VW(c,t),GW(c),YW(c,t),If(c,s,0),t>=7&&qW(c,t),QW(c,l),isNaN(r)&&(r=Bp.getBestMask(c,If.bind(null,c,s))),Bp.applyMask(r,c),If(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}JE.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Tf.M,i,a;return typeof s<"u"&&(r=Tf.from(s.errorCorrectionLevel,Tf.M),i=hd.from(s.version),a=Bp.from(s.maskPattern),s.toSJISFunc&&oh.setToSJISFunction(s.toSJISFunc)),ZW(t,i,r,a)};var uA={},wv={};(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),h=a.margin*c,d=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,y=a.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const b=Math.floor((m-h)/c),x=Math.floor((p-h)/c);y=d[o[b*l+x]?1:0]}r[g++]=y.r,r[g++]=y.g,r[g++]=y.b,r[g]=y.a}}})(wv);(function(e){const t=wv;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const h=t.getImageWidth(a.modules.size,c),d=u.getContext("2d"),m=d.createImageData(h,h);return t.qrToImageData(m.data,a,c),s(d,u,h),d.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),h=c.type||"image/png",d=c.rendererOpts||{};return u.toDataURL(h,d.quality)}})(uA);var dA={};const eH=wv;function fb(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Pf(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function tH(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?Pf("M",c+s,.5+u+s):Pf("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=Pf("h",l),l=0)):i++}return r}dA.render=function(t,s,r){const i=eH.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+fb(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+fb(i.color.dark,"stroke")+' d="'+tH(l,a,i.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
130
|
+
`;return typeof r=="function"&&r(null,m),m};const nH=xW,Hp=JE,hA=uA,sH=dA;function bv(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!nH())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=Hp.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=Hp.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}Qo.create=Hp.create;Qo.toCanvas=bv.bind(null,hA.render);Qo.toDataURL=bv.bind(null,hA.renderToDataURL);Qo.toString=bv.bind(null,function(e,t,s){return sH.render(e,s)});async function rH(e){const t=await Qo.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const mb=10*6e4,iH=2e3;function kv(e,t){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),h=f.useRef(e);h.current=e;const d=f.useRef(t);d.current=t;const m=f.useCallback(async()=>{const p=await T.telegramPairing();r(p),u(!1),o(!1),a(await rH(p.link).catch(()=>""))},[]);return f.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+mb,Date.now()+mb),y=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}h.current().then(b=>{var x;p||!b||(o(!0),(x=d.current)==null||x.call(d))}).catch(()=>{})},iH);return()=>{p=!0,window.clearInterval(y)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function Sv({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 fA=new Set(["approval","question"]),Yc={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."}},aH=new Set(["agent"]),lH={maxUrgency:"now",muted:[]};function oH({timezone:e}){var b,x,v;const t=ae(()=>T.notificationSettings(),[]),s=ae(()=>T.agents(),[]),r=ae(()=>T.notifications(20),[],3e4),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),[h,d]=f.useState(null),m=((b=t.data)==null?void 0:b.channels)??[],p=i??((x=t.data)==null?void 0:x.settings),g=j=>{p&&(u(!1),a({...p,...j}))},y=()=>{p&&(o(!0),u(!1),d(null),T.saveNotificationSettings(p).then(()=>{u(!0),a(null),t.reload()}).catch(j=>d(j instanceof pe?j.message:String(j))).finally(()=>o(!1)))};return n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:l||!p,onClick:y,children:"Save"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(se,{message:t.error??h}),n.jsx(te,{title:"Where buddi reaches you",children:p?m.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",n.jsx("a",{href:ze("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(Q,{gap:"sm",children:[m.map(j=>{var w;return n.jsx(pH,{channel:j,checked:(p.defaultChannel??((w=m[0])==null?void 0:w.kind))===j.kind,onPick:()=>g({defaultChannel:j.kind})},j.kind)}),m.some(j=>j.kind==="telegram")?null:n.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",n.jsx("a",{href:ze("telegram"),children:"Set up Telegram"})]})]}):n.jsx(oe,{children:"Loading…"})}),n.jsx(te,{title:"By kind",children:p?n.jsxs(Q,{gap:"sm",children:[X2.filter(j=>!aH.has(j)).map(j=>n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:Yc[j].label}),n.jsx("span",{className:"ui-field-hint",children:Yc[j].hint})]}),n.jsxs("select",{"aria-label":Yc[j].label,value:gH(p,j,m),onChange:w=>{const S={...p.perKind};w.target.value==="default"?delete S[j]:S[j]=w.target.value,g({perKind:S})},children:[n.jsx("option",{value:"default",children:"Default"}),m.map(w=>n.jsx("option",{value:w.kind,children:w.label},w.kind)),fA.has(j)?null:n.jsx("option",{value:"off",children:"Off"})]})]},j)),n.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),n.jsx(te,{title:"Messages from your agents",children:p?n.jsx(cH,{settings:p,agents:((v=s.data)==null?void 0:v.agents)??[],onChange:g}):null}),n.jsx(te,{title:"Focus schedules",children:p?n.jsxs(Q,{gap:"sm",children:[n.jsx(jH,{schedules:p.schedules,onChange:j=>g({schedules:j})}),n.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(ee,{label:"End of the day",children:n.jsx("input",{type:"time",value:p.endOfDay,onChange:j=>g({endOfDay:j.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}),c?n.jsx(H,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(uH,{}),n.jsxs(te,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(se,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(oe,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(jt,{children:r.data.notifications.map(j=>n.jsx(yt,{title:j.title,sub:`${We(j.createdAt,e)} · ${Yc[j.kind].label.toLowerCase()} · ${xH(j,m)}`,side:n.jsx(vH,{row:j})},j.id))}):n.jsx(oe,{children:"Loading…"})]})]})}function cH({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??lH,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(Q,{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, shown as "@agent: title". 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 uH(){var u;const e=ae(()=>T.tipsSettings(),[]),[t,s]=f.useState(!1),[r,i]=f.useState(null),[a,l]=f.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),i(null),l(h),T.saveTipsSettings(h).then(d=>l(d.enabled)).catch(d=>{l(!h),i(d instanceof pe?d.message:String(d))}).finally(()=>s(!1))};return n.jsx(te,{title:"Tips",panel:!0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:h=>c(h.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx("p",{className:"ui-field-hint",children:"When something in buddi has gone unused, Home may say so in one sentence, at most once a day."})]})})}function dH({timezone:e}){return n.jsx(hH,{timezone:e,onChange:()=>{}})}function hH({timezone:e,onChange:t}){var C,I;const s=ae(()=>T.telegramBot(),[]),r=ae(()=>T.telegramDevices(),[]),[i,a]=f.useState(!1),[l,o]=f.useState(""),[c,u]=f.useState(!1),[h,d]=f.useState(null),[m,p]=f.useState(null),g=f.useRef(new Set),y=kv(()=>T.telegramDevices().then(A=>A.devices.some(O=>!g.current.has(O.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,x=!b||i,v=()=>{var O;if(l.trim()===""||c)return;u(!0),d(null);const A=i&&(((O=s.data)==null?void 0:O.running)??!1);T.saveTelegramToken(l.trim()).then(z=>{o(""),a(!1),d(z.restartNeeded?{ok:!1,text:z.note??"Saved. It will be ready the next time buddi starts."}:A?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),t()}).catch(z=>d({ok:!1,text:z instanceof pe?z.message:String(z)})).finally(()=>u(!1))},j=()=>{var A;p(null),g.current=new Set((((A=r.data)==null?void 0:A.devices)??[]).map(O=>O.id)),y.ask().catch(O=>p(O instanceof pe?O.message:String(O)))},{offer:w,square:S,paired:k,stale:N}=y;return n.jsx(te,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{title:"The bot",foot:x?n.jsxs(n.Fragment,{children:[i?n.jsx(R,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(R,{variant:"accent",disabled:c||l.trim()==="",onClick:v,children:"Save token"})]}):void 0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:s.error}),!s.data&&!s.error?n.jsx(oe,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:(I=s.data)!=null&&I.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>{a(!0),d(null)},children:"Replace token"})]}):null,x?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),n.jsx(ee,{label:"Bot token",grow:!0,children:n.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:A=>o(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),v())}})})]}):null,h?n.jsx(H,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),n.jsxs(te,{title:"Your devices",children:[n.jsx(se,{message:r.error}),r.data?r.data.devices.length===0?n.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):n.jsx(jt,{children:r.data.devices.map(A=>n.jsx(yt,{title:A.name??`Telegram user ${A.userId}`,sub:`Paired ${We(A.pairedAt,e)} · ${A.lastSeenAt?`last spoke ${Fe(A.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(fH,{id:A.id,onGone:()=>{r.reload(),t()}})},A.id))}):r.error?null:n.jsx(oe,{children:"Loading…"})]}),n.jsx(te,{title:"Pair a device",foot:b&&(!w||k)?n.jsx(R,{variant:w?void 0:"accent",onClick:j,children:"Pair a phone"}):b&&N?n.jsx(R,{variant:"accent",onClick:j,children:"New code"}):void 0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:m}),b?k?n.jsx(H,{tone:"good",role:"status",children:"Paired."}):w&&N?n.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):w?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(Sv,{offer:w,square:S,children:n.jsx(mH,{text:w.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",We(w.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 fH({id:e,onGone:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(!1),[l,o]=f.useState(null);if(!s)return n.jsx(R,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),T.unpairTelegramDevice(e).then(t).catch(u=>o(u instanceof pe?u.message:String(u))).finally(()=>a(!1))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),n.jsx(R,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function mH({text:e}){const[t,s]=f.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(R,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function pH({channel:e,checked:t,onPick:s}){const[r,i]=f.useState(!1),[a,l]=f.useState(null),o=()=>{i(!0),l(null),T.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof pe?c.message:String(c)})).finally(()=>i(!1))};return n.jsxs("div",{className:"nt-channel",children:[n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"nt-default-channel",checked:t,onChange:s}),n.jsxs("span",{className:"nt-channel-text",children:[n.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),n.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),a?n.jsx("span",{className:"nt-channel-sent","data-tone":a.ok?void 0:"critical",role:"status",children:a.text}):null]})]}),n.jsx(R,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function gH(e,t,s){const r=e.perKind[t];return r==="off"?fA.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function xH(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 vH({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 pb={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},gb={mode:"do-not-disturb",days:[...Fm],from:"22:00",to:"07:00"};function jH({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(Q,{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:Fm.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${pb[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Fm.filter(c=>c===l||r.days.includes(c))}),children:pb[l]},l)})}),n.jsx(ee,{label:"From",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} from`,value:r.from,onChange:l=>s(i,{from:l.target.value})})}),n.jsx(ee,{label:"To",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} to`,value:r.to,onChange:l=>s(i,{to:l.target.value})})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${a}`,onClick:()=>t(e.filter((l,o)=>o!==i)),children:"Remove"})]},i)}),n.jsx("div",{className:"nt-schedule-add",children:n.jsx(R,{size:"sm",onClick:()=>t([...e,{...gb,days:[...gb.days]}]),children:"Add a schedule"})})]})}const yH={you:"person",appearance:"sun",notifications:"bell",telegram:"send",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function wH(e){const t=iD.map(r=>({id:r.id,route:ze(r.id),label:r.label,icon:yH[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:HN(r.plugin,r.id),route:ll(r.plugin,r.id),label:r.title,icon:AC(r.icon),group:"plugins"}));return[...t,...s]}function mA(e){return rD.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function pA(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function bH({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=f.useRef(null),l=mA(e),o=e.some(h=>h.id===t)?t:(u=e[0])==null?void 0:u.id,c=h=>{var g;const d=[...((g=a.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=d.indexOf(document.activeElement);if(m===-1)return;const p=y=>{var b;h.preventDefault(),(b=d[Math.max(0,Math.min(d.length-1,y))])==null||b.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(d.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const y=d[m].getAttribute("href");y&&i(y)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(h=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(d=>{const m=d.id===t,p=s[d.id],g=r[d.id];return n.jsxs("a",{className:"settings-nav-link",href:d.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":pA(d.label,p,g),tabIndex:d.id===o?0:-1,onClick:y=>{y.preventDefault(),i(d.route)},children:[n.jsx(ye,{name:d.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:d.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},d.id)})]},h.id))})}function kH({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=mA(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Vd,{modal:!1,children:[n.jsx(Gd,{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(ye,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(ye,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(Ho,{children:n.jsx(Yd,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(hO,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(zN,{children:[c>0?n.jsx(Or,{className:"ui-menu-sep"}):null,n.jsx(qd,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],d=r[u.id];return n.jsxs(fO,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":pA(u.label,h,d),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(ye,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):d?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function SH({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var v,j,w;const a=aD(e),l=$1(i!==void 0),o=i??l,c=qO(e),u=c?o.find(c.plugin,c.page):void 0,h=Fi(Jx),d=wH(o.settings),p={proposals:((j=(v=ae(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:v.open)==null?void 0:j.length)??0},g=ae(()=>T.version(),[]),y=ae(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((w=y.data)==null?void 0:w.signals)??[]).length>0&&(b.connections=TC);const x={entries:d,active:a,counts:p,dots:b,navigate:S=>s(S)};return n.jsxs("div",{className:"settings",children:[h?null:n.jsx(bH,{...x}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="plugins"||a==="connections"?n.jsx(eh,{before:n.jsx(b1,{inline:!0,items:[{label:"Settings",href:dn,onClick:()=>s(dn)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?W8:iE}):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(kH,{...x}):null,u?n.jsx(WU,{page:u,navigate:s,timezone:t,siblings:o.all.filter(S=>S.plugin===u.plugin)}):null,a==="you"?n.jsx(R8,{embedded:!0}):null,a==="appearance"?n.jsx(NH,{railPages:o.rail}):null,a==="notifications"?n.jsx(oH,{timezone:t}):null,a==="telegram"?n.jsx(dH,{timezone:t}):null,a==="memory"?n.jsx(KC,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(D8,{embedded:!0,plugin:tD(e)}):null,a==="accounts"?n.jsx(X5,{embedded:!0,account:JO(e)}):null,a==="computer"?n.jsx(h3,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(w8,{embedded:!0,timezone:t}):null,a==="connections"?n.jsx(aB,{embedded:!0,timezone:t}):null,a==="watchers"?n.jsx(A8,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(H5,{}):null,a==="plugins"?n.jsx(X8,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(AH,{timezone:t}):null]})})]})}function NH({railPages:e}){const[t,s]=_C();return n.jsx(te,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(Q,{divided:!0,gap:"lg",children:[n.jsx($f,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(ls,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:t.theme,onChange:r=>s({theme:r})})}),n.jsx($f,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(ls,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx($f,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(ls,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:t.width,onChange:r=>s({width:r})})}),n.jsx(EH,{pages:e}),n.jsx(CH,{})]})})}function CH(){var a;const e=ae(()=>T.overview(),[]),[t,s]=f.useState(null),r=((a=e.data)==null?void 0:a.glances)??[];if(r.length===0)return null;const i=(l,o)=>{s(l),T.setGlanceHidden(l,!o).then(()=>e.reload()).finally(()=>s(null))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home glances"}),n.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),n.jsx(Q,{gap:"sm",children:r.map(l=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!l.hidden,disabled:t===l.id,onChange:o=>i(l.id,o.target.checked)}),n.jsx("span",{children:l.title})]},l.id))})]})}function EH({pages:e}){const t=IC(),[s,r]=f.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),r6(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(Q,{gap:"sm",children:[n.jsx(se,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Po(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Po(a)))]})]})}function $f({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 AH({timezone:e}){const t=ae(()=>T.overview(),[],15e3),s=ae(()=>T.session(),[]),r=ae(()=>T.providerAccounts(),[]),i=t.data;return n.jsxs(Q,{gap:"lg",children:[n.jsx(se,{message:t.error}),n.jsx(BH,{}),i?n.jsx(te,{title:"The queue",panel:!0,actions:n.jsx(R,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{T.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(ge,{tone:"warning",children:"paused"}):n.jsx(ge,{tone:"good",children:"running"})]})}):null,n.jsxs(te,{title:"This host",panel:!0,children:[n.jsx(Gt,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?We(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?PH(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(H,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(IH,{}),n.jsx(TH,{}),n.jsx(te,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(oe,{children:"No sources are installed."}):n.jsx(Gt,{items:i.mail.map(a=>({key:a.sourceId,label:n.jsx("span",{className:"mono",children:a.sourceId}),value:a.lastError?n.jsx("span",{className:"critical",children:a.lastError}):n.jsxs("span",{children:["polled ",Fe(a.lastRunAt)]})}))}):n.jsx(oe,{children:"Loading…"})})]})}function TH(){var p;const e=ae(()=>T.tailscale(),[]),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=e.data,h=t??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),d=(u==null?void 0:u.proxied)===!0,m=g=>{i(!0),l(null),c(!1),T.setTailscale({enabled:g,login:h.trim()}).then(()=>{c(!0)}).catch(y=>l(y instanceof pe?y.message:String(y))).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:r||!u||d,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(Q,{divided:!0,children:n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:e.error??a}),n.jsx("p",{className:"ui-card-meta",children:u?u.available&&u.self?`Tailscale is running on this machine as ${u.self.login}.`:u.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),d?n.jsxs(n.Fragment,{children:[n.jsx(H,{tone:"warning",children:"Change this from the computer buddi runs on."}),n.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${h}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||d,onChange:g=>m(g.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(ee,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:h,placeholder:"you@example.com",disabled:r||!u||d,onChange: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(R,{size:"sm",disabled:r||!u,onClick:()=>{RH((u==null?void 0:u.serveCommand)??"")},children:"Copy"})]}),n.jsx("p",{className:"ui-card-meta",children:"This gives your tailnet the trust this machine already has: buddi cannot tell the Tailscale proxy from another program running here, and any program that can reach the dashboard on this machine can already read buddi’s files."}),o?n.jsx(H,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function RH(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function IH(){var u;const e=ae(()=>T.service(),[],1e4),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{i(!0),l(null),T.serviceAction(h).then(()=>{s(null)}).catch(d=>{l(d.message)}).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Service",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsx(Gt,{items:[{label:"Database",value:n.jsx(xb,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(xb,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:a}),t?n.jsx(H,{tone:"warning",role:"alert",children:t==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway closes this dashboard for a few seconds. If it does not come back on its own, run buddi in a terminal."}):n.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),n.jsx(J,{align:"end",children:t?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(R,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(R,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function xb({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(ge,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",t===null?n.jsx("span",{className:"ui-card-meta",children:"no process"}):n.jsxs("span",{className:"mono",children:["pid ",t]})]})}function PH(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const $H=2e3,vb={starting:"Getting started.",backup:"Taking a backup first, so there is a way back.",stopping:"Stopping the gateway. The database stays up.",installing:"Installing the new version.",restarting:"Restarting buddi on the new version.",migrating:"Bringing the database up to date.",done:"Done.",failed:"That did not work."},MH=new Set(["done","failed","rolled-back"]),OH="The check asks the npm registry for the newest version and sends nothing else.",DH="This takes a backup, installs the new version and restarts buddi. This page closes and comes back on its own.",_H="A checkout upgrades with git pull, then buddi upgrade in a terminal.",LH=10*6e4,FH="buddi did not come back. Run buddi doctor in a terminal.";function zH(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 UH(e,t,s,r){const[i,a]=f.useState(void 0),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=f.useRef(!1),d=f.useRef(s),m=f.useRef(r);return d.current=s,m.current=r,f.useEffect(()=>{if(!e){a(void 0),o(!1),h.current=!1;return}let p=!1,g=0;const y=()=>{h.current=!0,g=Date.now()+LH,o(!0)},b=()=>{if(Date.now()<g){T.session().then(j=>{p||j.version!==void 0&&j.version===t||(p=!0,d.current())}).catch(()=>{}),T.version().then(j=>{const w=j.history[j.history.length-1];p||(w==null?void 0:w.outcome)!=="failed"||(p=!0,o(!1),u(zH(w)))}).catch(()=>{});return}p=!0,o(!1),u(FH)},x=()=>{if(!p){if(h.current)return b();T.upgradeJob(e).then(j=>{var w;p||(a(j),u(null),(MH.has(j.phase)||j.finishedAt)&&(p=!0,j.phase==="failed"&&((w=m.current)==null||w.call(m,j))))}).catch(j=>{p||(j instanceof pe&&j.status!==0&&j.status<500?u(j.message):y())})}};x();const v=window.setInterval(x,$H);return()=>{p=!0,window.clearInterval(v)}},[e,t]),{job:i,away:l,error:c}}function BH({reload:e}){var w;const t=ae(()=>T.version(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),m=(w=t.data)==null?void 0:w.current,p=e??(()=>window.location.reload()),g=f.useCallback(S=>{r(null),d(S)},[]),y=UH(s,m,p,g),b=t.data,x=()=>{o(!0),u(null),T.checkVersion().catch(S=>u(S instanceof pe?S.message:String(S))).finally(()=>{o(!1),t.reload()})},v=S=>{o(!0),u(null),T.setVersionCheck(S).catch(k=>u(k instanceof pe?k.message:String(k))).finally(()=>{o(!1),t.reload()})},j=()=>{o(!0),u(null),d(null),T.startUpgrade(b==null?void 0:b.latest).then(S=>{var k;a(!1),r(((k=S.job)==null?void 0:k.id)??null)}).catch(S=>u(S instanceof pe?S.message:String(S))).finally(()=>o(!1))};return b!=null&&b.checkout?n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsx(Gt,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:b.current})}]})}),n.jsx(te,{children:n.jsx("p",{className:"ui-card-meta",children:_H})})]})}):n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(se,{message:t.error??c}),n.jsx(Gt,{items:[{label:"Running",value:b?n.jsx("span",{className:"mono",children:b.current}):"…"},{label:"Newest",value:b?b.updateAvailable&&b.latest?n.jsxs("span",{children:["A newer buddi is available: ",n.jsx("span",{className:"mono",children:b.latest})]}):b.checkedAt?n.jsxs("span",{children:["This is the latest, as of ",Fe(b.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),b!=null&&b.error?n.jsxs(H,{tone:"warning",children:["The last check did not get an answer: ",b.error]}):null,n.jsx(J,{align:"end",children:n.jsx(R,{disabled:l,onClick:x,children:"Check now"})})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(b==null?void 0:b.checkEnabled)??!1,disabled:l||!b,onChange:S=>v(S.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:OH})]})}),b!=null&&b.updateAvailable&&b.latest&&b.latestNotes?n.jsx(te,{title:`What changes in ${b.latest}`,children:n.jsx(pr,{text:b.latestNotes})}):null,n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(WH,{...y,job:y.job??h??void 0}),i?n.jsx(H,{tone:"warning",role:"alert",children:DH}):null,n.jsx(J,{align:"end",children:i?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Cancel"}),n.jsxs(R,{variant:"accent",disabled:l,onClick:j,children:["Upgrade to ",b==null?void 0:b.latest]})]}):n.jsx(R,{variant:"accent",disabled:l||s!==null||!(b!=null&&b.updateAvailable),onClick:()=>a(!0),children:b!=null&&b.updateAvailable&&b.latest?`Upgrade to ${b.latest}`:"Upgrade"})})]})}),b&&b.history.length>0?n.jsx(te,{title:"Upgrades so far",children:n.jsx(Gt,{items:b.history.slice().reverse().map(S=>({key:S.startedAt,label:n.jsxs("span",{className:"mono",children:[S.from," → ",S.to]}),value:n.jsx(HH,{attempt:S})}))})}):null]})})}function WH({job:e,away:t,error:s}){return s?n.jsx(se,{message:s}):t?n.jsx(H,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="failed"?n.jsxs(H,{tone:"critical",role:"alert",children:[vb.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(H,{tone:e.phase==="done"?"good":void 0,role:"status",children:vb[e.phase]??e.detail??e.phase}):null}function HH({attempt:e}){return n.jsxs("span",{children:[n.jsx(ge,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Fe(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?n.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",n.jsx("span",{className:"mono",children:e.backup})]}):null]})}const fd=["hello","brain","takeOn","reach","assistant","handover"],gA={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function xA(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function KH(e){var a,l,o;const t=xA(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 vA(e){var a,l,o,c,u;const t=KH(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 jA(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 ju(e){return fd.find(t=>!jA(e,t))??"handover"}function VH(e){const t=fd.indexOf(e);return t>0?fd[t-1]:null}function jb(e,t,s){return s===t?"now":jA(e,s)?"done":"todo"}function GH(e,t){return{...e}}const Kp="buddi.firstRun.restore";function Vp(e){try{e===null?window.sessionStorage.removeItem(Kp):window.sessionStorage.setItem(Kp,e)}catch{}}function yA(){try{return window.sessionStorage.getItem(Kp)}catch{return null}}function YH(e){const t=vA(e),s=ju(t);return{answers:t,open:s,stay:s!=="handover"}}function qH(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function QH(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 JH=6e4,XH=5*6e4,wA=1500,ZH=2e3,eK="(max-width: 720px)";function hl(){const e=f.useRef(null);return f.useEffect(()=>{let t=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const Nv=f.createContext({busy:0,report:()=>{}});function tK({children:e}){const[t,s]=f.useState(0),r=f.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=f.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(Nv.Provider,{value:i,children:e})}function Je({children:e}){const{busy:t}=f.useContext(Nv);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Zd,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function He({children:e}){return n.jsx(n.Fragment,{children:e})}function Ts({line:e}){const{report:t}=f.useContext(Nv);return f.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const Cv=f.createContext(null);function Ft({children:e,actions:t}){const s=f.useContext(Cv),r=t==null?null:s?zo.createPortal(t,s):n.jsx("div",{className:"wiz-dock-inline",children:t});return n.jsxs(n.Fragment,{children:[e?n.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function Hn({onClick:e,disabled:t}){return n.jsxs(R,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ye,{name:"chevron-left"}),P.back]})}function fl({children:e,onClick:t,disabled:s}){return n.jsxs(R,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ye,{name:"arrow"})]})}function nK({navigate:e,timezone:t}){var nn,K,Ne,nt,St,qt,wr;const s=Fi(eK),[r,i]=f.useState(void 0);f.useEffect(()=>{T.session().then(de=>i(de.platform)).catch(()=>{})},[]);const[a,l]=f.useState({}),[o,c]=f.useState(null),[u,h]=f.useState(void 0),[d,m]=f.useState(void 0),[p,g]=f.useState([]),[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(!1),[S,k]=f.useState(null),[N,C]=f.useState(null),[I,A]=f.useState(null),[O,z]=f.useState(null),[L,E]=f.useState(()=>yA()?"running":"idle"),[$,_]=f.useState({}),[B,M]=f.useState([]),[W,D]=f.useState(0),U=f.useRef(void 0),[V,Z]=f.useState(null),ue=f.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(de=>{de&&Array.isArray(de.plugins)&&Z(de)}).catch(()=>{})},[]);f.useEffect(()=>{if(!(V!=null&&V.running))return;const de=window.setInterval(ue,ZH);return()=>window.clearInterval(de)},[V==null?void 0:V.running,ue]);const Ae=f.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),X=f.useRef(e);X.current=e;const le=f.useCallback(async(de=!0,et=!1)=>{var Xo,qs,fi,pl,mi,Mn,pi,Qs,Cr;const[Re,sn,br,Jn,kr,Sr]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),Le.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);h(br);const Nr=(qs=(Xo=Sr==null?void 0:Sr.providers.find(It=>It.kind==="anthropic"))==null?void 0:Xo.defaultModel)==null?void 0:qs.trim();m(Nr||void 0),g((sn==null?void 0:sn.zones)??[]),k(((fi=Re==null?void 0:Re.details)==null?void 0:fi.conversationId)??null);const qe=(Jn==null?void 0:Jn.agents.find(It=>It.id===Jn.defaultAgentId))??(Jn==null?void 0:Jn.agents[0]);qe&&b(qe),C(Re&&!Re.needs.agent&&qe?{id:qe.id,name:qe.name,avatar:((pl=qe.avatar)==null?void 0:pl.kind)==="emoji"?qe.avatar.value:"",description:qe.description,...qe.picture?{picture:qe.picture}:{}}:null),Array.isArray((mi=Re==null?void 0:Re.details)==null?void 0:mi.takeOn)&&ue();const mn={onboarding:Re,owner:sn,accounts:br,browser:(Mn=kr==null?void 0:kr.browser)==null?void 0:Mn.engine,...qe?{assistant:{id:qe.id,name:qe.name,avatar:((pi=qe.avatar)==null?void 0:pi.kind)==="emoji"?qe.avatar.value:""}}:{}};if(et){const It=YH(mn);if(l(It.answers),c(It.open),!It.stay){const Rs=(Qs=Re==null?void 0:Re.details)==null?void 0:Qs.conversationId;X.current(Rs&&qe?Ge(qe.id,Rs):Vt,!0)}return}if(de&&(Re==null?void 0:Re.state)==="done"){const It=(Cr=Re.details)==null?void 0:Cr.conversationId;X.current(It&&qe?Ge(qe.id,It):Vt,!0);return}if(!de)return;const be=vA(mn);l(be),c(It=>It??ju(be))},[]);f.useEffect(()=>{le()},[le]);const me=(de,et={})=>{Promise.resolve().then(()=>T.onboardingStep(gA[de],et)).catch(()=>{})},$e=de=>ju(de)==="brain"&&$.brain?{...de,brain:$.brain}:de,ke=(de,et)=>{const Re=$e(et);Re.brain&&(U.current=Re.brain),v(null),M([]),l(Re),de==="brain"&&Re.brain?me(de,{accountId:Re.brain.accountId}):de==="reach"?me(de,Re.reach?{reach:Re.reach}:{}):de!=="takeOn"&&me(de),c(ju(Re))},we=(de,et)=>{v(null),l(et),et.brain&&(U.current=et.brain),de==="brain"&&et.brain&&me(de,{accountId:et.brain.accountId})},Ce=de=>{v(null),l(et=>GH(et)),c(de)},dt=()=>{if(!o)return;const de=VH(o==="handover"?"handover":o);de&&Ce(de)},fe=()=>{const de=a.brain??U.current,et=((V==null?void 0:V.plugins)??[]).filter(Re=>Re.state==="ready").map(Re=>Re.title);v(null),_({}),M([]),l({}),c("hello"),D(Re=>Re+1),(async()=>{var Nr;const[Re,sn,br]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),Jn=xA(Re),kr=de&&Jn.some(qe=>qe.id===de.accountId)?de:void 0;Re&&h(Re),_(kr?{brain:kr}:{});const Sr=[...new Set(Jn.map(qe=>qe.label)),...sn!=null&&sn.paired?[P.startOver.telegram]:[],...((Nr=br==null?void 0:br.browser)==null?void 0:Nr.engine)==="chromium"?[P.startOver.browser]:[],...et];M(Sr.length>0?[P.startOver.said(Sr.join(", "))]:[])})()},Me=()=>{w(!0),T.skipOnboarding().then(()=>e(Vt)).catch(de=>v(de instanceof pe?de.message:String(de))).finally(()=>w(!1))},ce=ae(()=>T.version().catch(()=>({current:""})),[]),Te=f.useRef(null);f.useEffect(()=>{Te.current&&(Te.current.scrollTop=0)},[o]);const G=L==="running",ie=Object.keys(a).length===0,Pe={answers:a,accounts:u,claudeModel:d,zones:p,browserZone:Ae,assistantAgent:y,met:S,onMet:k,existing:N,progress:V,onProgress:ue,navigate:e,onSettled:de=>o&&ke(o,de),onKept:de=>o&&we(o,de),onBack:dt,onTrouble:v,onReload:()=>void le(!1),onPickAnotherBrain:()=>Ce("brain"),onSpoken:z},it=(a.takeOn??[]).map(de=>{var et;return((et=Ia.find(Re=>Re.id===de))==null?void 0:et.title)??de}),Ye=(V==null?void 0:V.plugins)??[],at=Ye.filter(de=>de.state==="ready").length,ft=Ye.length===0?null:V!=null&&V.running?P.takeOn.installing(at,Ye.length):at===Ye.length?P.takeOn.installed:null,Y=[(nn=a.reach)!=null&&nn.phone?P.reach.done.phone:null,(K=a.reach)!=null&&K.mailbox?P.reach.done.mailbox:null,(Ne=a.reach)!=null&&Ne.app||(nt=a.reach)!=null&&nt.browser?P.reach.done.app:null].filter(de=>de!==null),lt={hello:{answer:P.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:P.brain.answer(((St=a.brain)==null?void 0:St.label)??"")},takeOn:{answer:P.takeOn.answer(it),sub:ft},reach:{answer:P.reach.answer(Y)},assistant:{answer:((qt=a.assistant)==null?void 0:qt.name)??""}},Yt=fd.filter(de=>de!=="handover"),Se=o===null||o==="handover"?Yt.length:Yt.indexOf(o),De=Math.min(Se,Yt.length-1),st=O?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:j,onClick:Me,children:P.later}),o==="hello"&&ie&&L==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>E("form"),children:P.restore.offer}):!G&&o!==null&&!(o==="hello"&&ie)?n.jsx("button",{type:"button",className:"wiz-link",disabled:j,onClick:fe,children:P.startOver.link}):null]}),tt=r===void 0||r==="darwin"?P.tagline:P.taglineElsewhere,Mt=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:P.count(Se+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(Cv.Provider,{value:I,children:n.jsx(tK,{children:n.jsxs(S1,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:Te,"data-phone":s?"true":void 0,"data-testid":"meet",children:n.jsxs("div",{className:"wiz-frame",children:[s?n.jsxs("div",{className:"wiz-strip",children:[n.jsx(Zu,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?P.count(Se+1):void 0,children:Yt.map(de=>n.jsx("i",{"data-state":jb(a,o,de)},de))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?P.strip(Se+1,P.chapters[Se]??""):P.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(Zu,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:tt}),(wr=ce.data)!=null&&wr.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",ce.data.current]}):null]})]}),Yt.map((de,et)=>{const Re=G?de==="hello"?"now":"todo":jb(a,o,de),sn=lt[de];return n.jsxs("div",{className:"wiz-ch","data-state":Re,"aria-current":Re==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":Re,children:Re==="done"?n.jsx(ye,{name:"check",size:12}):et+1}),n.jsxs("span",{className:"wiz-ch-label",children:[Re==="done"?sn.answer:P.chapters[et],Re==="done"&&sn.sub?n.jsx("span",{className:"wiz-ch-sub",children:sn.sub}):null]}),Re==="done"&&!G?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>Ce(de),children:P.change}):null]},de)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:P.mapNotes[De]}),st]}),n.jsx("div",{className:"wiz-stage",role:"main",children:n.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[n.jsxs(Z_,{dock:n.jsxs(n.Fragment,{children:[Mt,n.jsx("div",{className:"wiz-dock-actions",ref:A})]}),children:[G?n.jsx(IK,{onDone:de=>{E("idle"),M([...de?[P.restore.welcome(de)]:[],P.restore.keys]),le(!0,!0)},onFailed:de=>{E("idle"),v(de)}}):o==="hello"?n.jsx(sK,{...Pe}):o==="brain"?n.jsx(iK,{...Pe}):o==="takeOn"?n.jsx(wK,{...Pe}):o==="reach"?n.jsx(bK,{...Pe}):o==="assistant"?n.jsx(EK,{...Pe}):o==="handover"?n.jsx(AK,{...Pe}):n.jsx(Ts,{}),B.length>0||x?n.jsxs(He,{children:[B.map(de=>n.jsx(Je,{children:de},de)),x?n.jsx(Je,{children:x}):null]}):null]},`${W}-${o??""}-${G?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:st}):null]})})]})}),L==="form"?n.jsx(RK,{onCancel:()=>E("idle"),onStarted:()=>E("running"),onTrouble:v}):null]})})})}function ml({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function yb(e){try{return new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",timeZone:e}).format(new Date)}catch{return""}}function sK({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=hl(),[l,o]=f.useState(e.name??""),[c,u]=f.useState(e.clock??s),[h,d]=f.useState(!1),[m,p]=f.useState(!1),g=()=>{const y=l.trim();y===""||m||(p(!0),T.setOwner({preferredName:y,timezone:c}).then(()=>r({...e,name:y,clock:c})).catch(b=>i(b instanceof pe?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.hello.title}),n.jsx(He,{children:P.hello.opening.map(y=>n.jsx(Je,{children:y},y))}),n.jsxs(Ft,{actions:n.jsx(fl,{onClick:g,disabled:m||l.trim()==="",children:P.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(ee,{label:P.name.label,children:n.jsx("input",{ref:a,placeholder:P.name.placeholder,maxLength:80,value:l,onChange:y=>o(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),g())}})}),h?n.jsx(ee,{label:P.clock.label,hint:P.clock.hint(yb(c)),children:n.jsx("select",{value:c,onChange:y=>u(y.target.value),children:(t.includes(c)?t:[c,...t]).map(y=>n.jsx("option",{value:y,children:y},y))})}):n.jsx(ee,{label:P.clock.label,hint:P.clock.hint(yb(c)),action:n.jsx(R,{size:"lg",onClick:()=>d(!0),children:P.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:P.hello.foot})]})]})}const rK={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 iK(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=f.useState(null),[u,h]=f.useState("key"),[d,m]=f.useState(null),[p,g]=f.useState(!1),[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(null),S=(t==null?void 0:t.anthropicOAuthEnabled)===!0,k=(t==null?void 0:t.codexEnabled)===!0,N=t==null?void 0:t.gemini,[C,I]=f.useState(null);f.useEffect(()=>{let W=!1;const D=()=>{Promise.resolve().then(()=>T.ollama()).then(V=>{!W&&V&&b(V)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(V=>{!W&&V&&v(V)}).catch(()=>{W||v({running:!1,baseUrl:"",manager:!1,models:[]})})};D();const U=window.setInterval(D,4e3);return()=>{W=!0,window.clearInterval(U)}},[]);const A=async W=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:W.accountId,model:W.model})}catch(D){return D instanceof pe?D.message:String(D)}return a(),i({...s,brain:W}),C==null||C.close(),I(null),c(null),w(null),null},O=async(W,D,U)=>{g(!0),m(null);try{const V=await T.saveProviderAccount(W);let Z=await T.testProviderAccount(V.id),ue=W.defaultModel,Ae=!1;if(Z.state!=="connected"&&U&&U!==ue&&CE(Z)){const le=(await T.providerAccounts()).accounts.find(me=>me.id===V.id);le&&(await T.saveProviderAccount({id:le.id,revision:le.revision,label:le.label,kind:le.kind,auth:le.auth,baseUrl:le.baseUrl,defaultModel:U,enabled:le.enabled}),Z=await T.testProviderAccount(V.id),Z.state==="connected"&&(ue=U,Ae=!0))}if(Z.state!=="connected"){try{const le=(await T.providerAccounts()).accounts.find(me=>me.id===V.id);le&&await T.removeProviderAccount(V.id,le.revision)}catch{}return m(Z.message),Z}const X=await A({accountId:V.id,label:D,model:ue,...Ae?{freeTier:Ae}:{}});return X&&m(X),Z}catch(V){return m(V instanceof pe?V.message:String(V)),null}finally{g(!1)}},z=async W=>{g(!0),m(null);try{const D=await T.saveProviderAccount(W);let U;try{U=await T.testProviderAccount(D.id)}finally{try{const V=(await T.providerAccounts()).accounts.find(Z=>Z.id===D.id);V&&await T.removeProviderAccount(D.id,V.revision)}catch{}}return U.state!=="connected"&&m(U.message),U}catch(D){return m(D instanceof pe?D.message:String(D)),null}finally{g(!1)}},L=(W,D,U)=>{if(W.length<=1){O(D(W[0]??""),U);return}w({models:W,make:D,label:U})},E=W=>{if(W===o)return;C==null||C.close(),I((W==="free"||W==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),w(null),h("key"),c(W)},$=()=>{C==null||C.close(),I(null),w(null),m(null),c(null)},_=kA(y,x),B=["free",...S?["claude"]:[],...k?["chatgpt"]:[],"key","local"];let M=null;return j?M=n.jsxs(n.Fragment,{children:[n.jsx(He,{children:n.jsx(Je,{children:P.brain.model.ask})}),p?n.jsx(Ts,{line:P.brain.checking.service}):d?n.jsx(He,{children:n.jsx(Je,{children:d})}):null,n.jsx(aK,{busy:p,models:j.models,onBack:$,onUse:W=>void O(j.make(W),j.label)})]}):o==="key"?M=n.jsxs(n.Fragment,{children:[n.jsx(ls,{label:P.brain.keyKinds.label,value:u,onChange:W=>{m(null),h(W)},options:[{value:"key",label:P.brain.keyKinds.key},...N?[{value:"gemini",label:P.brain.keyKinds.gemini}]:[],{value:"service",label:P.brain.keyKinds.service}]}),u==="gemini"&&N?n.jsx(oK,{busy:p,problem:d,preset:N,onBack:$,onUse:O},"gemini"):u==="service"?n.jsx(uK,{busy:p,problem:d,address:(y==null?void 0:y.cloudBaseUrl)??"",onBack:$,onOffer:L,onTrial:z,onUse:O},"service"):n.jsx(lK,{busy:p,problem:d,onBack:$,onUse:O},"key")]}):o==="local"?M=n.jsx(cK,{busy:p,problem:d,probe:y,mlxh:x,onBack:$,onOffer:L,onUse:O}):o==="free"?M=n.jsx(hK,{...e,busy:p,consent:C,onBack:$,onConnected:A}):o==="chatgpt"?M=n.jsx(pK,{...e,busy:p,consent:C,onBack:$,onConnected:A}):o==="claude"&&(M=n.jsx(xK,{...e,busy:p,problem:d,onBack:$,onConnected:A})),n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.brain.title}),n.jsx(He,{children:n.jsx(Je,{children:P.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":P.brain.ask,children:B.map(W=>{const D=rK[W],U=P.brain.cards[W];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===W,"data-wide":D.wide?"true":void 0,onClick:()=>E(W),children:[n.jsx("span",{className:"wiz-glyph","data-tone":D.tone,"aria-hidden":"true",children:n.jsx(ye,{name:D.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:U.title}),n.jsx("span",{className:"wiz-opt-line",children:W==="local"?_:U.line}),"pill"in U?n.jsx(ge,{tone:"good",children:U.pill}):null]})]},W)})}),M,M===null&&s.brain?n.jsxs(He,{children:[n.jsx(Je,{children:s.brain.freeTier?P.brain.worksOnFlash(s.brain.model):P.brain.works(s.brain.model)}),n.jsx(fK,{...e})]}):null,M===null?n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:l}),n.jsx(fl,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:P.brain.submit})]})}):null]})}function aK({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=f.useState(t[0]??"");return n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:e}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:P.brain.model.submit})]}),children:n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:i,onChange:l=>a(l.target.value),children:t.map(l=>n.jsx("option",{value:l,children:l},l))})})})}function bA({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:t,disabled:s,onChange:i=>r(i.target.value),children:e.map(i=>n.jsx("option",{value:i,children:i},i))})})}function lK({busy:e,problem:t,onBack:s,onUse:r}){const i=hl(),[a,l]=f.useState(""),[o,c]=f.useState(null),[u,h]=f.useState(!1),[d,m]=f.useState([]),[p,g]=f.useState(""),[y,b]=f.useState(!1),x=e||u,v=!y&&t!==null&&d.length>0,j=o??qH(a),w=()=>{const S=a.trim();S===""||x||(h(!0),b(!1),(async()=>{var I;let k=j==="anthropic"?"claude-sonnet-5":"gpt-5",N=d;if(v&&p!=="")k=p;else try{const A=await T.probeModels({kind:j,auth:"api-key",secret:S});k=((I=A.models.find(O=>O.isDefault))==null?void 0:I.id)??k,N=A.models.map(O=>O.id)}catch{N=[]}h(!1);const C=await r({label:j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai,kind:j,auth:"api-key",baseUrl:"",defaultModel:k,enabled:!0,secret:S},j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai);if(!(!C||C.state==="connected")){if(sx(C)){b(!0),m([]);return}m(N.includes(k)||N.length===0?N:[k,...N]),g(k)}})())};return n.jsxs(n.Fragment,{children:[x?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.key})}):y?n.jsx(He,{children:n.jsx(Je,{children:P.brain.key.refused})}):t?n.jsx(He,{children:n.jsx(Je,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:x}),n.jsx(R,{variant:"accent",size:"lg",disabled:x||a.trim()==="",onClick:w,children:v?P.brain.model.retry:P.brain.key.submit})]}),children:[n.jsx(ee,{label:P.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.key.placeholder,value:a,onChange:S=>{l(S.target.value),m([])},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),w())}})}),v?n.jsx(bA,{models:d,picked:p,disabled:x,onPick:g}):null,n.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(j==="anthropic"?"openai":"anthropic"),children:[j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai," · ",P.brain.key.which]})]})]})}function oK({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=hl(),[l,o]=f.useState(""),[c,u]=f.useState(!1),[h,d]=f.useState([]),[m,p]=f.useState(""),g=e||c,y=t!==null&&h.length>0,b=()=>{const x=l.trim();x===""||g||(u(!0),(async()=>{let v=bE,j;if(y&&m!=="")v=m;else try{const S=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:x})).models.map(k=>k.id);v=kE(S)??v,j=NE(v)?SE(S):void 0,d(Q5(S)),p(j??v)}catch{}u(!1),await i({label:P.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:x},P.brain.gemini.label,j)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.gemini})}):t?n.jsx(He,{children:n.jsx(Je,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:g}),n.jsx(R,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:P.brain.gemini.submit})]}),children:[n.jsx(ee,{label:P.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.gemini.placeholder,value:l,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),b())}})}),y?n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:x=>p(x.target.value),children:h.map(x=>n.jsx("option",{value:x,children:x},x))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:P.brain.gemini.get})]})]})}function kA(e,t){return e===null||t===null?P.brain.local.looking:!e.running&&!t.running?P.brain.local.missing:P.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function cK({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Ip(r),u=()=>{!(r!=null&&r.running)||!c||l({label:P.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},P.brain.mlxh.label)},h=s!==null&&r!==null&&!s.running&&!r.running,d=()=>{s&&a(o,m=>({label:P.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),P.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.ollama})}):t?n.jsx(He,{children:n.jsx(Je,{children:t})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(R,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e||o.length===0,onClick:d,children:P.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(R,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:P.brain.mlxh.connect}):null,h&&s?n.jsx(Ut,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:P.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[kA(s,r),r!=null&&r.running&&!c?` ${P.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${QC(r.baseUrl)}`:""]})})]})}function uK({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=hl(),[c,u]=f.useState(s),[h,d]=f.useState(""),[m,p]=f.useState(!1),[g,y]=f.useState([]),[b,x]=f.useState(""),[v,j]=f.useState(!1),w=e||m,S=!v&&t!==null&&g.length>0,k=()=>{c.trim()===""||w||(p(!0),j(!1),(async()=>{var $;const N=h.trim()?"api-key":"none",C=_=>({label:P.brain.service.label,kind:"openai-compatible",auth:N,baseUrl:c.trim(),defaultModel:_,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),I=(_,B,M)=>{if(!(!_||_.state==="connected")){if(sx(_)){j(!0),y([]);return}y(B),x(M)}};if(N==="api-key"&&S&&b!==""){p(!1),I(await l(C(b),P.brain.service.label),g,b);return}let A=[],O;try{const _=await T.probeModels({kind:"openai-compatible",auth:N,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});A=_.models.map(B=>B.id),O=($=_.models.find(B=>B.isDefault))==null?void 0:$.id}catch{}p(!1);const z=O?[O]:A;if(N==="none"){i(z,C,P.brain.service.label);return}const L=z[0]??"";if(z.length<=1){I(await l(C(L),P.brain.service.label),A,L);return}const E=await a(C(L));(E==null?void 0:E.state)==="connected"?i(z,C,P.brain.service.label):I(E,A,L)})())};return n.jsxs(n.Fragment,{children:[w?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.service})}):v?n.jsx(He,{children:n.jsx(Je,{children:P.brain.key.refused})}):t?n.jsx(He,{children:n.jsx(Je,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:w}),n.jsx(R,{variant:"accent",size:"lg",disabled:w||c.trim()==="",onClick:k,children:S?P.brain.model.retry:P.brain.service.submit})]}),children:[n.jsx(ee,{label:P.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:P.brain.service.addressPlaceholder,onChange:N=>{u(N.target.value),y([])}})}),n.jsx(ee,{label:P.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:N=>{d(N.target.value),y([])}})}),S?n.jsx(bA,{models:g,picked:b,disabled:w,onPick:x}):null]})]})}const dK=2e3;function hK({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(0),p=f.useRef(-1),g=f.useRef(null),y=P.brain.cloud.label;f.useEffect(()=>{if(p.current===d)return;p.current=d,l(!0),c(null);const x=d===0?t:g.current;(async()=>{try{const v=((i==null?void 0:i.accounts)??[]).find(k=>k.auth==="device-key"),j=v?{id:v.id}:await T.saveProviderAccount({label:y,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:uu,enabled:!0}),w=(await T.providerAccounts()).accounts.find(k=>k.id===j.id),S=await T.ollamaConnect(w.id,w.revision);h({id:w.id,attemptId:S.attemptId,url:S.verificationUrl}),x&&(x.location.href=S.verificationUrl)}catch(v){x==null||x.close(),c(v instanceof pe?v.message:String(v))}finally{l(!1)}})()},[d]),f.useEffect(()=>{if(!u)return;let x=!1,v=!1;const j=async()=>{if(!(x||v)){v=!0;try{const S=await T.ollamaPoll(u.id,u.attemptId);if(x||S.state==="waiting")return;if(x=!0,h(null),S.state==="failed"){c(S.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{v=!1}}},w=window.setInterval(()=>void j(),dK);return()=>{x=!0,window.clearInterval(w)}},[u]);const b=async x=>{try{const v=(await T.accountModels(x).catch(()=>({models:[]}))).models.map(k=>k.id),j=v.length===0||v.includes(uu)?uu:v[0],w=(await T.providerAccounts()).accounts.find(k=>k.id===x);w&&w.defaultModel!==j&&await T.saveProviderAccount({id:w.id,revision:w.revision,label:w.label,kind:w.kind,auth:w.auth,baseUrl:w.baseUrl,defaultModel:j,enabled:w.enabled});const S=await T.testProviderAccount(x);return S.state!=="connected"?S.message:await r({accountId:x,label:y,model:j})}catch(v){return v instanceof pe?v.message:String(v)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.cloud})}):o?n.jsx(He,{children:n.jsx(Je,{children:o})}):u?n.jsx(He,{children:n.jsx(Je,{children:P.brain.cloud.waiting})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:a||e}),u?n.jsx(Ut,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.cloud.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(x=>x+1)},children:P.brain.cloud.again}):null]})})]})}function fK({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]=f.useState([]),[c,u]=f.useState(!1),h=iv(a),d=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&J5(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(f.useEffect(()=>{if(!d||!a)return;let g=!1;return T.accountModels(a.id).then(y=>{const b=h?y.models.filter(x=>!qC({id:x.id,...x.image?{kind:"image"}:{}})):y.models;g||o(b.map(x=>x.id))}).catch(()=>{}),()=>{g=!0}},[d,a==null?void 0:a.id]),!d||!a||!i||l.length<2)return null;const m=g=>{g===i.model||c||(u(!0),r(null),(async()=>{try{await T.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:g,enabled:a.enabled}),e.assistant&&await T.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(y){r(y instanceof pe?y.message:String(y))}finally{u(!1)}})())};return n.jsx(Je,{children:n.jsx(ee,{label:P.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 wb="gpt-5.5",mK=2e3;function pK({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(0),p=f.useRef(-1),g=f.useRef(null),y=f.useRef(null),b=P.brain.chatgpt.label;f.useEffect(()=>()=>{const j=y.current;y.current=null,j&&T.codexAccountAction(j.id,"cancel-login",j.revision).catch(()=>{})},[]),f.useEffect(()=>{if(p.current===d)return;p.current=d,l(!0),c(null);const j=d===0?t:g.current;(async()=>{try{const w=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),S=w?{id:w.id}:await T.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:wb,enabled:!0}),k=(await T.providerAccounts()).accounts.find(C=>C.id===S.id),N=await T.codexAccountAction(k.id,"login",k.revision);if(!(N!=null&&N.verificationUrl)||!N.userCode)throw new Error((N==null?void 0:N.message)??P.brain.chatgpt.failed);y.current={id:k.id,revision:k.revision},h({id:k.id,revision:k.revision,url:N.verificationUrl,code:N.userCode}),j&&(j.location.href=N.verificationUrl)}catch(w){j==null||j.close(),c(w instanceof pe||w instanceof Error?w.message:String(w))}finally{l(!1)}})()},[d]),f.useEffect(()=>{if(!u)return;let j=!1,w=!1;const S=async()=>{if(!(j||w)){w=!0;try{const N=(await T.providerAccounts()).accounts.find(I=>I.id===u.id);if(j)return;const C=N==null?void 0:N.login;if(!C||C.state==="pending")return;if(j=!0,y.current=null,h(null),C.state!=="connected"){c(C.message??P.brain.chatgpt.failed);return}l(!0),c(await x(u.id)),l(!1)}catch{}finally{w=!1}}},k=window.setInterval(()=>void S(),mK);return()=>{j=!0,window.clearInterval(k)}},[u]);const x=async j=>{var w,S;try{const k=(await T.accountModels(j).catch(()=>({models:[]}))).models,N=((w=k.find(I=>I.isDefault))==null?void 0:w.id)??((S=k[0])==null?void 0:S.id)??wb,C=(await T.providerAccounts()).accounts.find(I=>I.id===j);return C&&C.defaultModel!==N&&await T.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:N,enabled:C.enabled}),await r({accountId:j,label:b,model:N})}catch(k){return k instanceof pe?k.message:String(k)}},v=()=>{const j=y.current;y.current=null,j&&T.codexAccountAction(j.id,"cancel-login",j.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.chatgpt})}):o?n.jsx(He,{children:n.jsx(Je,{children:o})}):u?n.jsx(He,{children:n.jsxs(Je,{children:[P.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),P.brain.chatgpt.codeAfter]})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:v,disabled:a||e}),u?n.jsx(Ut,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.chatgpt.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:P.brain.chatgpt.again}):null]}),children:u?n.jsx(lv,{code:u.code,label:P.brain.chatgpt.code}):null})]})}const gK="claude-sonnet-5";function xK({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(""),g=f.useRef(null);f.useEffect(()=>()=>{const j=g.current;g.current=null,j&&T.anthropicAccountAction(j.id,"cancel-login",j.revision).catch(()=>{})},[]);const y=()=>{const j=g.current;g.current=null,j&&T.anthropicAccountAction(j.id,"cancel-login",j.revision).catch(()=>{}),s()},b=a??gK,x=()=>{o(!0),u(null);const j=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const w=((i==null?void 0:i.accounts)??[]).find(I=>I.auth==="anthropic-oauth"),S=w?{id:w.id}:await T.saveProviderAccount({label:P.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),N=(await T.providerAccounts()).accounts.find(I=>I.id===S.id),C=await T.anthropicAccountAction(N.id,"login",N.revision);g.current={id:N.id,revision:N.revision+1},d({id:N.id,revision:N.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),j&&C.verificationUrl?j.location.href=C.verificationUrl:j==null||j.close()}catch(w){j==null||j.close(),u(w instanceof pe?w.message:String(w))}finally{o(!1)}})()},v=()=>{!h||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await T.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const j=await T.testProviderAccount(h.id);if(j.state!=="connected"){u(j.message);return}u(await r({accountId:h.id,label:P.brain.claude.label,model:b}))}catch(j){u(j instanceof pe?j.message:String(j))}finally{o(!1)}})())};return n.jsxs(n.Fragment,{children:[l||e?n.jsx(He,{children:n.jsx(Ts,{line:P.brain.checking.claude})}):t??c?n.jsx(He,{children:n.jsx(Je,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(He,{children:n.jsx(Je,{children:P.brain.claude.waiting})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:y,disabled:l}),n.jsx(Ut,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:P.brain.claude.open}),n.jsx(R,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:P.brain.claude.finish})]}),children:n.jsx(ee,{label:P.brain.claude.paste,grow:!0,children:n.jsx(vK,{value:m,onChange:p})})})]}):n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:y,disabled:e||l}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||l,onClick:x,children:P.brain.claude.start})]})})]})}function vK({value:e,onChange:t}){const s=hl();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const jK={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function yK(e){const t=(e==null?void 0:e.plugins)??[];if(t.length===0)return null;const s=t.map(i=>i.title),r=t.filter(i=>i.state==="failed");if(e!=null&&e.running){const i=t.filter(a=>a.state==="ready"||a.state==="failed").length;return{line:P.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>P.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:P.takeOn.ready(s),done:!0}}function wK({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=f.useState(()=>e.takeOn??[...l_]),[c,u]=f.useState(!1),h=Ia.filter(g=>l.includes(g.id)),d=g=>o(y=>y.includes(g)?y.filter(b=>b!==g):[...y,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>T.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(y=>a(y instanceof pe?y.message:String(y))).finally(()=>u(!1)))},p=yK(t);return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.takeOn.title}),n.jsx(He,{children:n.jsx(Je,{children:P.takeOn.ask})}),n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:c}),n.jsx(R,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:P.takeOn.none}),n.jsx(fl,{onClick:()=>m(Ia.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:P.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":P.takeOn.title,children:Ia.map(g=>{const y=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":y,onClick:()=>d(g.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ye,{name:jK[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:y?n.jsx(ye,{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:P.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:h.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:P.takeOn.nothing})]})]})}function bK({answers:e,navigate:t,onSettled:s,onBack:r}){var g,y,b;const[i,a]=f.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=f.useState(((y=e.reach)==null?void 0:y.mailbox)===!0),[c,u]=f.useState(((b=e.reach)==null?void 0:b.app)===!0),[h,d]=f.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const x={phone:i,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>T.onboardingStep("browser")).catch(()=>{}),s({...e,reach:x,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.reach.title}),n.jsx(He,{children:n.jsx(Je,{children:P.reach.ask})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r}),n.jsx(fl,{onClick:p,children:P.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(kK,{paired:i,onPaired:()=>a(!0)}),n.jsx(NK,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(CK,{app:c,onApp:()=>u(!0),browser:h,onBrowser:d}),i?n.jsx(H,{tone:"good",role:"status",children:P.reach.phone.hello}):null]})})]})}function kK({paired:e,onPaired:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1),l=f.useRef(t);l.current=t,f.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>T.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ye,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ge,{tone:"good",dot:!0,children:P.reach.phone.paired})}):o?n.jsx(SK,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:P.reach.phone.setUp})}),i?n.jsx(kt,{title:P.telegram.sheet,onClose:()=>a(!1),children:n.jsx(PK,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function SK({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=kv(()=>T.telegram().then(o=>o.paired),e),l=f.useRef(!1);return f.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ge,{tone:"good",dot:!0,children:P.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",onClick:()=>void a().catch(()=>{}),children:P.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(Sv,{offer:t,square:s})})}function NK({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=f.useState(void 0),[o,c]=f.useState(!1),[u,h]=f.useState(null),d=f.useCallback(()=>{Promise.resolve().then(()=>T.pageQuery("email","accounts")).then(m=>{var g,y,b;const p=((b=(y=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:y[0])==null?void 0:b.address)??null;h(p),s(p!==null)}).catch(()=>{})},[]);return f.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>T.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),y=g.find(b=>b.id==="settings")??null;l(y?{page:y,siblings:g}:null)}).catch(()=>{m||l(null)}),d(),()=>{m=!0}},[d]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(ye,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?P.reach.mailbox.forTriage:P.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?P.reach.mailbox.unavailable:P.reach.mailbox.line})]}),n.jsx("span",{className:"wiz-row-side",children:t||u?n.jsx(ge,{tone:"good",dot:!0,mono:u!==null,children:u??P.reach.mailbox.added}):a?n.jsx(R,{size:"lg",onClick:()=>c(!0),children:P.reach.mailbox.add}):null}),o&&a?n.jsx(kt,{title:P.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),d()},children:n.jsx(sv,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function CK({app:e,onApp:t,browser:s,onBrowser:r}){const i=e5(),a=typeof navigator>"u"?null:pE(navigator.userAgent),[l,o]=f.useState(null),[c,u]=f.useState("idle"),[h,d]=f.useState(null),[m,p]=f.useState(null),[g,y]=f.useState(void 0),b=f.useRef(!1),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,Promise.resolve().then(()=>T.browser()).then(C=>{var A;if(!x.current)return;const I=C==null?void 0:C.browser;I?((A=I.install)==null?void 0:A.state)==="running"?(o("none"),b.current=!0,u("installing"),w()):o(I.engine):o("other")}).catch(()=>{x.current&&o("other")}),()=>{x.current=!1}),[]);const v=(C,I)=>{x.current&&(b.current=!1,u("failed"),d(C),p(I??null))},j=async C=>{u("launching");let I;try{I=await T.browserCheck()}catch(A){return v(A instanceof pe?A.message:String(A))}if(x.current){if(I.ok){u("idle"),o(C),r(b.current?"installed":C);return}v(I.message,I.command)}},w=async()=>{var A,O;let C;try{C=await T.browser()}catch(z){return v(z instanceof pe?z.message:String(z))}if(!x.current)return;const I=C.browser;if(!I)return v(P.browser.failed(""));if(((A=I.install)==null?void 0:A.state)==="running"){u("installing"),y(I.install.progress),window.setTimeout(()=>void w(),1e3);return}return I.engine!=="none"?j(I.engine):v(((O=I.install)==null?void 0:O.line)??"")},S=()=>{if(p(null),l==="chrome"||l==="chromium"){j(l);return}b.current=!0,u("installing"),y(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{x.current&&window.setTimeout(()=>void w(),1e3)}).catch(C=>v(C instanceof pe?C.message:String(C)))},k=s==="chrome"||s==="chromium"||s==="installed",N=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(ye,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(ge,{tone:"good",dot:!0,children:P.reach.app.installed}):i?n.jsx(R,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:P.reach.app.install}):null,k?n.jsx(ge,{tone:"good",dot:!0,children:P.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(R,{size:"lg",disabled:N,onClick:S,children:N?P.browser.installing:c==="failed"?P.browser.retry:l==="chrome"?P.reach.app.chrome:l==="chromium"?P.reach.app.chromium:P.reach.app.fetch})]}),!e&&!i&&a?n.jsx("span",{className:"wiz-row-note",children:a}):null,c==="installing"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.needs}),n.jsx(X1,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Ts,{line:P.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.failed(h??"")}),m?n.jsx(TK,{command:m}):null]}):null]})}function EK({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=f.useState(()=>(t==null?void 0:t.name)??e_),[c,u]=f.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[h,d]=f.useState(t?null:P.assistant.purposeValue),[m,p]=f.useState(t?"":P.assistant.purposeValue);f.useEffect(()=>{if(!t)return;let j=!1;return T.firstAgentPersona().then(w=>{j||(d(w.persona),p(w.persona))},w=>{j||r(w instanceof pe?w.message:String(w))}),()=>{j=!0}},[t==null?void 0:t.id]);const[g,y]=f.useState(!1),b=Ia.filter(j=>(e.takeOn??[]).includes(j.id)&&"mate"in j).map(j=>j.mate),x=Gy.find(j=>j.id===c),v=()=>{if(l.trim()===""||g)return;y(!0);const j=!t||h!==null&&m.trim()!==""&&m.trim()!==h.trim()?{instructions:m.trim()}:{},w=t?T.updateFirstAgent({name:l.trim(),...j}):T.createFirstAgent({name:l.trim(),handle:QH(l),description:"",...j,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let S;try{S=await w}catch(N){r(N instanceof pe?N.message:String(N)),y(!1);return}let k=null;try{x&&await T.uploadAgentPicture(S.id,await oE(x.role))}catch(N){k=N instanceof pe?N.message:String(N)}y(!1),i(),s({...e,assistant:{id:S.id,name:l.trim(),avatar:x?"":(t==null?void 0:t.avatar)??""}}),k&&r(k)})()};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.assistant.title}),n.jsx(He,{children:n.jsxs(Je,{children:[P.assistant.ask,b.length>0?P.assistant.team(b):""]})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:a,disabled:g}),n.jsx(fl,{onClick:v,disabled:g||l.trim()===""||h===null,children:P.assistant.submit})]}),children:n.jsxs("div",{className:"wiz-meet",children:[n.jsxs("div",{className:"wiz-face",children:[n.jsx("span",{className:"wiz-face-tile","data-agent":(x==null?void 0:x.id)??"buddi","aria-hidden":"true",children:x?n.jsx("img",{src:qi(x.role),alt:""}):t!=null&&t.picture?n.jsx("img",{src:t.picture,alt:""}):n.jsx("span",{className:"wiz-face-emoji",children:(t==null?void 0:t.avatar)??""})}),n.jsx("div",{className:"wiz-swatches",role:"group","aria-label":P.assistant.colour,children:Gy.map(j=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":j.id,"aria-label":P.assistant.swatch(j.label),"aria-pressed":c===j.id,onClick:()=>u(j.id)},j.id))}),n.jsx("span",{className:"wiz-face-cap",children:P.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(ee,{label:P.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:j=>o(j.target.value)})}),n.jsx(ee,{label:P.assistant.purpose,hint:P.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:j=>p(j.target.value)})})]})]})})]})}function AK({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var $;const u=e.assistant,[h,d]=f.useState(s),[m,p]=f.useState([]),[g,y]=f.useState(!1),[b,x]=f.useState(!1),[v,j]=f.useState(!0),[w,S]=f.useState(!1),k=f.useRef(!1),N=f.useMemo(()=>t?[t]:[],[t]);f.useEffect(()=>{c()},[]),f.useEffect(()=>{if(!u||k.current)return;if(k.current=!0,s){d(s);return}let _=!1;return(async()=>{try{const B=await Le.startConversation(u.id);if(_)return;d(B.conversationId),r(B.conversationId),await T.onboardingStep(gA.handover,{conversationId:B.conversationId}).catch(()=>{}),await Le.send(u.id,{conversationId:B.conversationId,text:r_,opening:!0})}catch{_||(j(!1),y(!0))}})(),()=>{_=!0}},[u==null?void 0:u.id,s]),f.useEffect(()=>{if(!h)return;let _=!1;const B=Date.now(),M=()=>{Le.conversation(h).then(D=>{if(_)return;p(D.messages);const U=Date.now()-B;if(D.messages.some(bb)){j(!1),y(!1),x(!1);return}const V=D.runs??[],Z=V.some(Ae=>Ae.finishedAt===null),ue=V.length>0&&!Z;x(Z&&U>=JH),(ue||U>=XH)&&(j(!1),y(!0))}).catch(()=>{})};M();const W=window.setInterval(M,wA);return()=>{_=!0,window.clearInterval(W)}},[h]);const C=u&&h?Ge(u.id,h):null,I=m.some(bb);f.useEffect(()=>{I&&C&&l(C)},[I,C,l]);const A=e.takeOn??[],O=Ia.filter(_=>A.includes(_.id)&&"mate"in _).map(_=>_.mate),z=P.handover.starters({days:A.includes("days"),mail:A.includes("mail"),mailbox:(($=e.reach)==null?void 0:$.mailbox)===!0},O),L=(o==null?void 0:o.waiting)??[],E=_=>{!u||!h||w||(S(!0),Promise.resolve().then(()=>Le.send(u.id,{conversationId:h,text:_})).then(()=>i(Ge(u.id,h),!0)).catch(()=>S(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(zx,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:N,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:P.handover.waiting,plain:!0,workingLine:P.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?n.jsx(He,{children:n.jsx(Je,{children:P.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(He,{children:n.jsx(Je,{children:P.handover.silent})}),n.jsx(Ft,{actions:n.jsx(fl,{onClick:a,children:P.handover.again})})]}):null,I?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":P.handover.starterLabel,children:z.map(_=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:w,onClick:()=>E(_),children:_},_))}):null,I&&L.length>0?n.jsx(H,{tone:"warm",title:P.handover.waitingTitle(L.length),action:n.jsx(R,{variant:"accent",onClick:()=>i(Vt,!0),children:P.handover.home}),children:P.handover.waitingBody(L)}):null,I&&C?n.jsx(Ft,{actions:n.jsx(Ut,{variant:"accent",size:"lg",href:C,onClick:_=>{_.preventDefault(),i(C,!0)},children:P.done.open})}):null]})}function TK({command:e}){const[t,s]=f.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(Q,{gap:"sm",children:[n.jsx(vt,{label:"The command to run",children:e}),n.jsxs(J,{align:"end",children:[t==="failed"?n.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,n.jsx(R,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function bb(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function RK({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=f.useState(null),[a,l]=f.useState(""),[o,c]=f.useState(!1),u=()=>{!r||o||(c(!0),s(null),T.firstRunRestore(r,a.trim()).then(h=>{Vp(h.job.id),t()}).catch(h=>s(h instanceof pe?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(kt,{title:P.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:P.restore.lede}),n.jsx(ee,{label:P.restore.file,children:n.jsx("input",{type:"file",onChange:h=>{var d;return i(((d=h.target.files)==null?void 0:d[0])??null)}})}),n.jsx(ee,{label:P.restore.passphrase,hint:P.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:h=>l(h.target.value)})}),n.jsxs(J,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:e,children:P.restore.cancel}),n.jsx(R,{variant:"accent",disabled:o||!r,onClick:u,children:P.restore.submit})]})]})})}function IK({onDone:e,onFailed:t}){const[s,r]=f.useState([]),i=f.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},f.useEffect(()=>{const l=yA();if(!l)return;let o=!1;const c=()=>{T.backupJob(l).then(h=>{o||(r(d=>d.includes(h.phase)?d:[...d,h.phase]),h.phase==="done"?(o=!0,Vp(null),T.owner().then(d=>i.current.onDone(d.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Vp(null),i.current.onFailed(h.error??P.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,wA);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in P.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.restore.title}),n.jsxs(He,{children:[n.jsx(Je,{children:P.restore.started}),a.map(l=>n.jsx(Je,{children:P.restore.phases[l]},l))]}),n.jsx(Ts,{})]})}function PK(e){return n.jsx(Cv.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx($K,{...e})})})}function $K({onPaired:e,onDismiss:t}){const s=hl(),[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),{offer:u,square:h,paired:d,stale:m,ask:p}=kv(()=>T.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await T.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??P.telegram.restart);return}await p()}catch(b){c(b instanceof pe?b.message:String(b))}finally{l(!1)}})())},y=()=>{c(null),p().catch(b=>c(b instanceof pe?b.message:String(b)))};return d?n.jsxs(n.Fragment,{children:[n.jsx(He,{children:n.jsx(Je,{children:P.telegram.paired})}),n.jsx(Ft,{actions:n.jsx(R,{variant:"accent",onClick:t,children:P.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(He,{children:n.jsx(Je,{children:m?P.telegram.expired:P.telegram.scan})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),m?n.jsx(R,{variant:"accent",onClick:y,children:P.telegram.newCode}):null]}),children:m?null:n.jsx(Sv,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(He,{children:[n.jsx(Je,{children:P.telegram.how}),o?n.jsx(Je,{children:o}):null]}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),n.jsx(R,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:P.telegram.submit})]}),children:n.jsx(ee,{label:P.telegram.field,grow:!0,children:n.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g())}})})})]})}const MK="(max-width: 1080px)";function OK(){const[e,t]=f.useState(()=>window.location.hash||Vt);f.useEffect(()=>{const r=()=>t(window.location.hash||Vt);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=f.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function DK(){const[e,t]=_C();f.useEffect(()=>{DC(e)},[e]);const s=f.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const kb=new Map;function _K(){var Y,lt,Yt;const[e,t]=OK(),[s,r]=f.useState("UTC"),[i,a]=f.useState({approvals:0,failed:0}),[l,o]=DK(),c=Fi(Jx),[u,h]=f.useState(!1),[d,m]=f.useState([]),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState([]),[j,w]=f.useState(!1),[S,k]=f.useState(null),N=DD(),C=d.find(Se=>Se.id===p)??null,I=C!==null&&pz(e),[A,O]=f.useState(!1),z=f.useCallback(()=>O(!0),[]);f.useEffect(()=>{I||O(!1)},[I]),l6(t,fu(e)===null,I?z:void 0);const L=Fi(MK),E=vE(),$=$1(),_=IC(),B=ae(()=>Promise.resolve().then(()=>T.version()),[],yD),M=B.data;RD(B.reload);const W=M&&!M.checkout&&M.updateAvailable?M:null,D=wx(M==null?void 0:M.web);ID(M==null?void 0:M.web);const U=((Y=ae(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:Y.signals)??[],[V,Z]=f.useState(null),ue=f.useMemo(()=>new Set(V?[V]:[]),[V]),[Ae,X]=f.useState(new Map);f.useEffect(()=>{const Se=()=>{T.conversations().then(st=>{const tt=new Map;for(const Mt of st.conversations){const nn=Mt.lastMessageAt??Mt.createdAt,K=tt.get(Mt.agentId);(!K||nn>K)&&tt.set(Mt.agentId,nn)}X(tt)}).catch(()=>{})};Se();const De=window.setInterval(Se,3e4);return()=>window.clearInterval(De)},[e]);const[le,me]=f.useState(!1);f.useEffect(()=>{if(le)return;let Se=!1;return T.onboarding().then(De=>{Se||(me(!0),De.state==="pending"&&De.needs.model&&!fu(window.location.hash)&&t(WO,!0))}).catch(()=>{Se||me(!0)}),()=>{Se=!0}},[le,t]),f.useEffect(()=>{const Se=lD(e);Se&&t(Se,!0)},[e,t]),f.useEffect(()=>{let Se=!1;const De=()=>{Le.agents().then(tt=>{Se||(m(tt.agents),mD(tt.defaultAgentId??null),g(tt.defaultAgentId??null),b(Mt=>{var nn;return Mt??tt.defaultAgentId??((nn=tt.agents[0])==null?void 0:nn.id)??null}))}).catch(()=>{})};De();const st=window.setInterval(De,15e3);return window.addEventListener("focus",De),window.addEventListener(So,De),()=>{Se=!0,window.clearInterval(st),window.removeEventListener("focus",De),window.removeEventListener(So,De)}},[e]),f.useEffect(()=>{let Se=!1;const De=()=>{Le.groups().then(tt=>{Se||v(tt.groups)}).catch(()=>{})};De();const st=window.setInterval(De,3e4);return()=>{Se=!0,window.clearInterval(st)}},[e]);const $e=qN(d,p),ke=KO(e),we=WN(e),Ce=we?x.find(Se=>Se.id===we.groupId)??null:null,dt=we?null:(ke==null?void 0:ke.agentId)??y;f.useEffect(()=>{ke&&b(ke.agentId)},[ke==null?void 0:ke.agentId]);const fe=Se=>{b(Se),t(Ge(Se))},Me=Se=>t(Yl(Se)),ce=f.useCallback((Se,De,st=!0)=>t(we?Yl(we.groupId,De):Ge(Se,De),st),[t,we==null?void 0:we.groupId]),[Te,G]=f.useState(!1);f.useEffect(()=>{T.session().then(Se=>{r(Se.timezone),G(!0)}).catch(()=>{})},[]);const ie=Sz(Te);Tz(Te,ie.refresh,()=>G(!1)),f.useEffect(()=>{const Se=()=>{T.overview().then(st=>a({approvals:st.approvals.pending,failed:st.jobs.failed??0})).catch(()=>{})};Se();const De=window.setInterval(Se,2e4);return()=>window.clearInterval(De)},[]),f.useEffect(()=>{if(!Te)return;if(e===oD){w(!0),t(Gr,!0);return}const Se=cD(e),De=new Date().toDateString();!Se||kb.get(Se)===De||(kb.set(Se,De),T.tipsSeenPage(Se).catch(()=>{}))},[e,Te,t]);const Pe=fu(e),it=VN(e),Ye=it===Gr,at=S?x.find(Se=>Se.id===S)??null:null,ft=j?n.jsx(Mw,{agents:d,onClose:()=>w(!1),onCreated:Se=>{v(De=>[...De,Se]),w(!1),t(Yl(Se.id))}}):at?n.jsx(Mw,{agents:d,group:at,onClose:()=>k(null),onSaved:Se=>{v(De=>De.map(st=>st.id===Se.id?Se:st)),k(null)},onArchived:Se=>{v(De=>De.filter(st=>st.id!==Se)),k(null),t(Gr)}}):null;return Pe?n.jsx(Ey,{delayDuration:400,children:n.jsxs(my,{swipeDirection:"right",children:[n.jsx(nK,{navigate:t,timezone:s}),n.jsx(py,{className:"ui-toasts"})]})}):n.jsx(d_,{picture:(lt=d.find(Se=>Se.id===p))==null?void 0:lt.picture,children:n.jsx(Ey,{delayDuration:400,children:n.jsxs(my,{swipeDirection:"right",children:[ft,n.jsxs("div",{className:"wb-shell",children:[n.jsx(_5,{active:((Yt=E.data)==null?void 0:Yt.active)===!0,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(qU,{attention:i.approvals+i.failed,place:it,onNavigate:t,theme:l,onTheme:o,plugins:i6($.rail,_),updateAvailable:W!==null,settingsDot:U.length>0?TC:void 0,stale:D,timezone:s,version:M&&!M.checkout?{current:M.current,latest:M.latest,updateAvailable:M.updateAvailable}:M?{current:M.current,updateAvailable:!1}:void 0}),Ye&&!L?n.jsx(t1,{agents:$e,currentId:dt,attention:N,onSelect:fe,lastActivity:Ae,working:ue,groups:x,currentGroupId:(Ce==null?void 0:Ce.id)??null,onSelectGroup:Me,onNewGroup:()=>w(!0)}):null,Ye?n.jsx(rz,{timezone:s,agents:$e,agentId:Ce?Ce.coordinator:dt,defaultAgentId:p,group:Ce,onEditGroup:Ce?()=>k(Ce.id):void 0,requestedConversationId:(we==null?void 0:we.conversationId)??(ke==null?void 0:ke.conversationId),requestedTab:ke==null?void 0:ke.tab,onConversationOpened:ce,onSelectAgent:fe,onWorking:Z,attention:N,agentsInHeader:L,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)}):n.jsx("main",{"data-ground":LK(it,e)?"plain":void 0,"data-layout":it===dn?"split":void 0,children:n.jsx(FK,{hash:e,place:it,timezone:s,navigate:t,agents:d,defaultAgentId:p,attention:N,pluginPages:$,update:W,connectionSignals:U})})]})]}),I&&C?n.jsx(gz,{agent:C,agents:d,open:A,onOpenChange:O,navigate:t}):null,n.jsxs(bz,{placement:wz(I,A),children:[n.jsx(Nz,{queue:ie.queue,agents:d,navigate:t,onDismiss:ie.dismiss}),n.jsx(py,{className:"ui-toasts"})]})]})})})}function LK(e,t){return xx(t)!==null}function FK({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=xx(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(sv,{page:a,item:i.item??null,navigate:s.navigate,timezone:s.timezone,siblings:t.all.filter(l=>l.plugin===i.plugin)});if(t.all.length===0)return n.jsx(n.Fragment,{})}switch(e){case pt:return n.jsx(YB,{...s});case Ct:return n.jsx(w6,{...s});case dn:return n.jsx(SH,{...r});case Li:return n.jsx(KU,{...s});default:return n.jsx(j5,{...s})}}function zK(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(yx)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}const SA=1e4,UK=3e4,NA=6e3,BK=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function WK(e){return BK.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 CA(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new pe(0,Yu)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return Y2(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function EA(e){var t;return e.up&&wx((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function HK({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:qi("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:WK(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(R,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function KK({children:e}){const[t,s]=f.useState("checking"),[r,i]=f.useState(!1),a=f.useRef(!1),l=f.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await CA(NA);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":EA(o)?"up":"down")},[]);return f.useEffect(()=>{l()},[l]),f.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),SA);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(HK,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsxs(n.Fragment,{children:[n.jsx(GK,{}),e]})}function VK(e=UK){const[t,s]=f.useState(!1);return f.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=V2();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=G2(i);return()=>{a(),clearTimeout(r)}},[e]),t}function GK(){const e=VK();return f.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{CA(NA).then(EA)},SA);return()=>window.clearInterval(t)},[e]),e?n.jsx("div",{className:"lost-bar",role:"status",children:"Lost buddi. Retrying…"}):null}function YK({search:e=location.search}){const[t,s]=f.useState(null),r=f.useRef(!1);return f.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;T.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(rE);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(Q,{gap:"lg",children:[n.jsx("h2",{className:"ui-page-title",children:"Connections"}),t===null?n.jsx(H,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(H,{tone:"good",role:"status",title:`Signed in to ${t.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",t.cli?"the terminal carries on.":"the other one carries on."]}):null,t&&!t.ok?n.jsx(H,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(Ut,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const Sb=document.getElementById("root");Sb&&_k(Sb).render(n.jsx(f.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(YK,{}):n.jsx(KK,{children:n.jsx(_K,{})})}));zK();export{QK as c,HA as g};
|