cartethyia 2.7.4 → 2.7.5
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/.env.example +2 -0
- package/README.md +17 -5
- package/dist/dashboard/assets/{BannedPage-ChG5svFb.js → BannedPage-Cj15GsMp.js} +1 -1
- package/dist/dashboard/assets/BannedPage-Cj15GsMp.js.gz +0 -0
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js +1 -0
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-BIcWQun7.js → CliToolDetailPage-DZKmVuJN.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-DZKmVuJN.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-Bf2VelDe.js → CliToolsPage-BIccZmeL.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-BIccZmeL.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js +1 -0
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-D5rol2j2.js +1 -0
- package/dist/dashboard/assets/ConsoleLogPage-D5rol2j2.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-ggeMSjte.js → CustomizationPage-BKj_r0rp.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-BKj_r0rp.js.gz +0 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-B5nZvmf0.js +656 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-B5nZvmf0.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-U6AKaJcF.js → LoginPage-DkXb6dx-.js} +1 -1
- package/dist/dashboard/assets/LoginPage-DkXb6dx-.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-BMS2t8BA.js → ModelPicker-DnQPSIA8.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-DnQPSIA8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js +1 -0
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js +5 -0
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js +1 -0
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-lsrx7NYg.js → ProxyPage-5SnUSy3j.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-5SnUSy3j.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js +1 -0
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-BJtRZ4qD.js +1 -0
- package/dist/dashboard/assets/SettingsPage-BJtRZ4qD.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-f0DE1h0-.js → SetupPage-WTa0sktC.js} +1 -1
- package/dist/dashboard/assets/SetupPage-WTa0sktC.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-Cq5tW7hW.js → StudioPage-BfAb5-o_.js} +3 -3
- package/dist/dashboard/assets/StudioPage-BfAb5-o_.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BNzeZ2Vk.js +56 -0
- package/dist/dashboard/assets/UsagePage-BNzeZ2Vk.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-l29JROPv.js +1 -0
- package/dist/dashboard/assets/api-keys-l29JROPv.js.gz +0 -0
- package/dist/dashboard/assets/app--PJWq8_C.css +2 -0
- package/dist/dashboard/assets/app--PJWq8_C.css.gz +0 -0
- package/dist/dashboard/assets/assert-C0K-c4eo.js +1 -0
- package/dist/dashboard/assets/assert-C0K-c4eo.js.gz +0 -0
- package/dist/dashboard/assets/{badge-D9CS6dZk.js → badge-DfbhQU4k.js} +1 -1
- package/dist/dashboard/assets/badge-DfbhQU4k.js.gz +0 -0
- package/dist/dashboard/assets/{banner-DympBNq4.js → banner-BllT4LcF.js} +1 -1
- package/dist/dashboard/assets/banner-BllT4LcF.js.gz +0 -0
- package/dist/dashboard/assets/brand/login_register.jpg +0 -0
- package/dist/dashboard/assets/brand/login_register_initial.jpg +0 -0
- package/dist/dashboard/assets/brand/og_bansos.jpg +0 -0
- package/dist/dashboard/assets/brand/og_image.jpg +0 -0
- package/dist/dashboard/assets/{card-ibRWU_uT.js → card-CtkX66Wd.js} +1 -1
- package/dist/dashboard/assets/card-CtkX66Wd.js.gz +0 -0
- package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js +1 -0
- package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-CQXVMn4P.js +1 -0
- package/dist/dashboard/assets/cli-tools-CQXVMn4P.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-DJm-9pz7.js → clipboard-button-BQqBQd2n.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-BQqBQd2n.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-8fiE6tec.js → dialog-BEK7KP0H.js} +1 -1
- package/dist/dashboard/assets/dialog-BEK7KP0H.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-CqGYeOrd.js → drawer-BrTEZ8zu.js} +1 -1
- package/dist/dashboard/assets/drawer-BrTEZ8zu.js.gz +0 -0
- package/dist/dashboard/assets/entry-CHWxbS56.js +1 -0
- package/dist/dashboard/assets/entry-CHWxbS56.js.gz +0 -0
- package/dist/dashboard/assets/{entry-BSAsYsmV.js → entry-EBHJ3DrE.js} +1 -1
- package/dist/dashboard/assets/entry-EBHJ3DrE.js.gz +0 -0
- package/dist/dashboard/assets/entry-LCS85hiq.js +4 -0
- package/dist/dashboard/assets/entry-LCS85hiq.js.gz +0 -0
- package/dist/dashboard/assets/{formatters-D-MTJxMr.js → formatters-BAACA727.js} +1 -1
- package/dist/dashboard/assets/formatters-BAACA727.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-CPK47xQx.js → github-badge-YSCE4UC2.js} +1 -1
- package/dist/dashboard/assets/github-badge-YSCE4UC2.js.gz +0 -0
- package/dist/dashboard/assets/{index-DBNPOfhV.js → index-FQlj0HUT.js} +2 -2
- package/dist/dashboard/assets/index-FQlj0HUT.js.gz +0 -0
- package/dist/dashboard/assets/{inline-BT0zntEr.js → inline-C4gU5iOL.js} +1 -1
- package/dist/dashboard/assets/inline-C4gU5iOL.js.gz +0 -0
- package/dist/dashboard/assets/{input-Da2ZViWg.js → input-BHHX_Tmm.js} +1 -1
- package/dist/dashboard/assets/input-BHHX_Tmm.js.gz +0 -0
- package/dist/dashboard/assets/{layout-BXNeLw6M.js → layout-CajrYUnD.js} +1 -1
- package/dist/dashboard/assets/layout-CajrYUnD.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-BycOrrIV.js → list-row-Bx2I7XUe.js} +1 -1
- package/dist/dashboard/assets/list-row-Bx2I7XUe.js.gz +0 -0
- package/dist/dashboard/assets/live-DNNqRbj2.js +1 -0
- package/dist/dashboard/assets/live-DNNqRbj2.js.gz +0 -0
- package/dist/dashboard/assets/network-C5UBACrJ.js +1 -0
- package/dist/dashboard/assets/network-C5UBACrJ.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CUWAZK4J.js +2 -0
- package/dist/dashboard/assets/numbers-CUWAZK4J.js.gz +0 -0
- package/dist/dashboard/assets/pagination-Xsi9Qx04.js +1 -0
- package/dist/dashboard/assets/pagination-Xsi9Qx04.js.gz +0 -0
- package/dist/dashboard/assets/quota-DvQbD_sr.js +1 -0
- package/dist/dashboard/assets/quota-DvQbD_sr.js.gz +0 -0
- package/dist/dashboard/assets/routing-in0f_IfK.js +1 -0
- package/dist/dashboard/assets/routing-in0f_IfK.js.gz +0 -0
- package/dist/dashboard/assets/{select-BIYIBkMU.js → select-BLULNqTp.js} +1 -1
- package/dist/dashboard/assets/select-BLULNqTp.js.gz +0 -0
- package/dist/dashboard/assets/settings-CcGczj6I.js +1 -0
- package/dist/dashboard/assets/settings-CcGczj6I.js.gz +0 -0
- package/dist/dashboard/assets/shield-BMQNxORh.js +1 -0
- package/dist/dashboard/assets/shield-BMQNxORh.js.gz +0 -0
- package/dist/dashboard/assets/{stack-DfgnFDWY.js → stack-D2lIR0tg.js} +1 -1
- package/dist/dashboard/assets/stack-D2lIR0tg.js.gz +0 -0
- package/dist/dashboard/assets/{state-CkfdYWel.js → state-DTARjfiW.js} +1 -1
- package/dist/dashboard/assets/state-DTARjfiW.js.gz +0 -0
- package/dist/dashboard/assets/{switch-SYm237HG.js → switch-c0oPSnqW.js} +1 -1
- package/dist/dashboard/assets/switch-c0oPSnqW.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-BQqCRNIi.js → useMutation-m8WGNPrz.js} +1 -1
- package/dist/dashboard/assets/useMutation-m8WGNPrz.js.gz +0 -0
- package/dist/dashboard/console-backgrounds.jpg +0 -0
- package/dist/dashboard/console-backgrounds_initial.jpg +0 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +56 -55
- package/migrations/full-postgres/0036_system_prompt_presets_refs.sql +10 -0
- package/migrations/full-postgres/0037_share_concurrency_scope.sql +3 -0
- package/migrations/full-postgres/0038_add_accounts_quota_snapshot.sql +7 -0
- package/migrations/full-postgres/0039_add_telemetry_provider_model_indexes.sql +13 -0
- package/migrations/full-postgres/0040_add_models_dialect.sql +3 -0
- package/migrations/full-postgres/0041_add_daily_checkin_ledger_account_fk.sql +7 -0
- package/migrations/lite-sqlite3/0036_system_prompt_presets_refs.sql +14 -0
- package/migrations/lite-sqlite3/0037_share_concurrency_scope.sql +3 -0
- package/migrations/lite-sqlite3/0038_add_accounts_quota_snapshot.sql +4 -0
- package/migrations/lite-sqlite3/0039_add_telemetry_provider_model_indexes.sql +6 -0
- package/migrations/lite-sqlite3/0040_add_models_dialect.sql +3 -0
- package/migrations/lite-sqlite3/0041_add_daily_checkin_ledger_account_fk.sql +26 -0
- package/package.json +4 -6
- package/scripts/cli/update.ts +15 -41
- package/src/boot/app.ts +58 -2
- package/src/boot/dependencies.ts +786 -732
- package/src/boot/lifecycle.ts +11 -12
- package/src/config/cooldowns.ts +34 -55
- package/src/config/network.ts +1 -1
- package/src/config/package-paths.ts +1 -1
- package/src/config/providers.ts +13 -14
- package/src/config/resources.ts +0 -5
- package/src/config/runtime.ts +2 -5
- package/src/config/spec.ts +26 -6
- package/src/console/api-keys/ban-constants.ts +38 -0
- package/src/console/api-keys/contracts.ts +71 -62
- package/src/console/api-keys/routes.ts +48 -12
- package/src/console/auth/access.ts +4 -4
- package/src/console/auth/account-reset.ts +1 -1
- package/src/console/auth/audit-recorder.ts +1 -1
- package/src/console/auth/lockout.ts +7 -3
- package/src/console/auth/row-coercion.ts +57 -12
- package/src/console/auth/session-resolver.ts +1 -1
- package/src/console/auth/session-service.ts +8 -2
- package/src/console/auth/session.ts +37 -31
- package/src/console/auth/setup-service.ts +4 -3
- package/src/console/auth/user-store.ts +1 -1
- package/src/console/backup/9router-map.ts +0 -3
- package/src/console/backup/contracts.ts +9 -9
- package/src/console/backup/export-endpoint.ts +5 -6
- package/src/console/backup/nine-router.ts +1 -7
- package/src/console/backup/routes.ts +29 -33
- package/src/console/backup/service.ts +468 -468
- package/src/console/backup/store.ts +47 -29
- package/src/console/backup/validate.ts +11 -1
- package/src/console/cli-tools/contracts.ts +7 -7
- package/src/console/cli-tools/injectors/cline.ts +110 -110
- package/src/console/cli-tools/injectors/codex.ts +181 -181
- package/src/console/cli-tools/injectors/copilot.ts +108 -108
- package/src/console/cli-tools/injectors/driver.ts +247 -247
- package/src/console/cli-tools/injectors/jcode.ts +115 -115
- package/src/console/cli-tools/injectors/openclaw.ts +161 -161
- package/src/console/cli-tools/injectors/opencode.ts +153 -153
- package/src/console/cli-tools/routes.ts +1 -1
- package/src/console/cli-tools/service.ts +1 -1
- package/src/console/cli-tools/store.ts +2 -2
- package/src/console/console-router.ts +32 -0
- package/src/console/dashboard-assets.ts +9 -9
- package/src/console/domain-registration.ts +16 -2
- package/src/console/inferhub/client.ts +0 -7
- package/src/console/inferhub/key-store.ts +1 -1
- package/src/console/inferhub/normalize.ts +2 -2
- package/src/console/inferhub/routes.ts +1 -1
- package/src/console/inferhub/types.ts +1 -1
- package/src/console/observability/contracts.ts +1 -1
- package/src/console/observability/live.ts +31 -18
- package/src/console/observability/logs.ts +1 -1
- package/src/console/observability/sse.ts +62 -8
- package/src/console/observability/store.ts +20 -4
- package/src/console/providers/catalog/catalog-projections.ts +1 -1
- package/src/console/providers/catalog/contracts.ts +39 -0
- package/src/console/providers/catalog/model-operations.ts +1 -1
- package/src/console/providers/catalog/provider-operations.ts +95 -17
- package/src/console/providers/catalog/public-model-store.ts +0 -0
- package/src/console/providers/catalog/routes.ts +27 -3
- package/src/console/providers/catalog/store.ts +147 -8
- package/src/console/providers/detail/routes.ts +1 -1
- package/src/console/providers/oauth/callback-listener.ts +100 -18
- package/src/console/providers/oauth/routes.ts +92 -13
- package/src/console/quota/account-quota-global.ts +41 -3
- package/src/console/quota/account-quota-shared.ts +10 -3
- package/src/console/quota/account-quota-tenant.ts +259 -66
- package/src/console/quota/daily-growth-job.ts +308 -0
- package/src/console/quota/native-identity.ts +2 -2
- package/src/console/quota/quota-view.ts +1 -1
- package/src/console/remote-support/routes.ts +1 -1
- package/src/console/remote-support/service.ts +2 -2
- package/src/console/routing/model/contracts.ts +1 -1
- package/src/console/routing/pools/contracts.ts +2 -2
- package/src/console/routing/pools/import-parse.ts +3 -3
- package/src/console/routing/pools/relay-deploy.ts +3 -3
- package/src/console/settings/contracts.ts +29 -2
- package/src/console/settings/store.ts +20 -0
- package/src/console/share/share-router.ts +100 -32
- package/src/console/share/share-stats.ts +4 -4
- package/src/console/share/share-usage.ts +1 -1
- package/src/console/shared/errors.ts +2 -2
- package/src/console/shared/object.ts +18 -0
- package/src/console/shared/read-through-cache.ts +4 -4
- package/src/console/shared/transaction.ts +14 -0
- package/src/console/system-prompt/contracts.ts +89 -12
- package/src/console/system-prompt/routes.ts +98 -45
- package/src/console/updates/apply-update.ts +244 -0
- package/src/console/updates/routes.ts +252 -97
- package/src/main.ts +11 -5
- package/src/network/http2-bidi.ts +1 -1
- package/src/network/ip-utils.ts +298 -0
- package/src/network/outbound-fetch.ts +1 -1
- package/src/network/pool/agent.ts +7 -6
- package/src/network/pool/byte-accounting.ts +1 -1
- package/src/network/pool/resolver.ts +16 -12
- package/src/network/pool/selector.ts +150 -136
- package/src/network/pool-health-machine.ts +1 -1
- package/src/network/rate-limit-verdict.ts +1 -1
- package/src/network/retry.ts +1 -1
- package/src/network/ssrf.ts +20 -71
- package/src/observability/event-log.ts +2 -2
- package/src/observability/event-query.ts +59 -291
- package/src/observability/log-sanitize.ts +1 -1
- package/src/observability/metrics.ts +4 -4
- package/src/observability/payload-capture.ts +6 -5
- package/src/observability/payload-store.ts +1 -1
- package/src/observability/runtime-metrics.ts +1 -1
- package/src/observability/telemetry-buffer.ts +12 -3
- package/src/observability/telemetry-reconciliation.ts +3 -3
- package/src/observability/token-speed.ts +1 -1
- package/src/persistence/connection-url.ts +1 -1
- package/src/persistence/db-handle.ts +1 -1
- package/src/persistence/db-pg.ts +2 -2
- package/src/persistence/db-sqlite.ts +3 -3
- package/src/persistence/dialect.ts +5 -1
- package/src/persistence/readiness.ts +1 -1
- package/src/persistence/redis.ts +1 -1
- package/src/persistence/schema.ts +113 -40
- package/src/persistence/shared-cache.ts +2 -2
- package/src/persistence/sort-order.ts +1 -1
- package/src/persistence/stores/api-key-store.ts +10 -1
- package/src/persistence/stores/share-store.ts +20 -8
- package/src/persistence/system-prompt-store.ts +63 -18
- package/src/persistence/tenant-preferences.ts +1 -1
- package/src/persistence/ttl-cache.ts +3 -3
- package/src/persistence/usage-flush.ts +7 -2
- package/src/protocol/canonical-model.ts +1 -1
- package/src/protocol/codecs.ts +6 -10
- package/src/protocol/dsml.ts +3 -49
- package/src/protocol/image-clamp.ts +2 -2
- package/src/protocol/reasoning-text.ts +1 -1
- package/src/protocol/reasoning.ts +7 -52
- package/src/protocol/registry.ts +50 -15
- package/src/protocol/request/chat.ts +46 -19
- package/src/protocol/request/codex.ts +1 -1
- package/src/protocol/request/messages.ts +46 -14
- package/src/protocol/request/responses.ts +19 -10
- package/src/protocol/response/chat.ts +25 -10
- package/src/protocol/response/codex.ts +1 -1
- package/src/protocol/response/messages.ts +1 -1
- package/src/protocol/response/omp-tool-call-markup.ts +1 -1
- package/src/protocol/response/responses.ts +1 -1
- package/src/protocol/sse-decoder.ts +50 -1
- package/src/protocol/stop-reason.ts +2 -2
- package/src/protocol/think-split.ts +347 -0
- package/src/protocol/translation/attachment-integrity.ts +3 -3
- package/src/protocol/translation/cache-controls.ts +8 -20
- package/src/protocol/translation/capabilities.ts +6 -6
- package/src/protocol/translation/dialect/deepseek.ts +10 -0
- package/src/protocol/translation/dialect/inband.ts +39 -0
- package/src/protocol/translation/dialect/model-thinking.ts +89 -0
- package/src/protocol/translation/dialect/qwen.ts +114 -0
- package/src/protocol/translation/dialect/resolver.ts +83 -0
- package/src/protocol/translation/dialect/rules.ts +93 -0
- package/src/protocol/translation/dialect/thinking-ladder.ts +245 -0
- package/src/protocol/translation/dialect/types.ts +58 -0
- package/src/protocol/translation/quirks.ts +18 -4
- package/src/protocol/translation/thinking.ts +12 -252
- package/src/protocol/translation/tool-id.ts +3 -3
- package/src/protocol/translation/tool-repair.ts +1 -1
- package/src/protocol/upstream/post-json.ts +6 -1
- package/src/providers/adapters/compatible-adapter.ts +42 -3
- package/src/providers/authentication/jwt-validator.ts +0 -5
- package/src/providers/authentication/oauth-client.ts +254 -253
- package/src/providers/authentication/oauth-flow-store.ts +42 -7
- package/src/providers/bundled-discovery-providers.ts +6 -30
- package/src/providers/configured-openai-providers.ts +82 -97
- package/src/providers/default-registry.ts +23 -35
- package/src/providers/discovery/catalog/catalog-format.ts +13 -2
- package/src/providers/discovery/discovery-types.ts +0 -1
- package/src/providers/discovery/openai-model-discovery.ts +2 -2
- package/src/providers/discovery/probe-phases.ts +48 -13
- package/src/providers/discovery/probing-service.ts +6 -8
- package/src/providers/integrations/agentrouter/agentrouter.ts +12 -2
- package/src/providers/integrations/antigravity/antigravity-oauth.ts +0 -1
- package/src/providers/integrations/antigravity/antigravity-protocol.ts +0 -14
- package/src/providers/integrations/antigravity/antigravity.ts +2 -2
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +1 -1
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +20 -4
- package/src/providers/integrations/buddy/buddy-cli-headers.ts +19 -52
- package/src/providers/integrations/buddy/buddy-identity.ts +86 -0
- package/src/providers/integrations/buddy/buddy-oauth-shared.ts +1 -1
- package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +1 -2
- package/src/providers/integrations/buddy/codebuddy/provider.ts +4 -15
- package/src/providers/integrations/buddy/codebuddy/shared.ts +30 -9
- package/src/providers/integrations/buddy/workbuddy/provider.ts +5 -9
- package/src/providers/integrations/buddy/workbuddy/shared.ts +21 -3
- package/src/providers/integrations/claude/claude-cch.ts +148 -148
- package/src/providers/integrations/claude/fallback-credit.ts +3 -7
- package/src/providers/integrations/cline/cline.ts +1 -1
- package/src/providers/integrations/codex/codex-device-code.ts +101 -101
- package/src/providers/integrations/codex/codex-oauth.ts +0 -1
- package/src/providers/integrations/commandcode/commandcode.ts +75 -115
- package/src/providers/integrations/commandcode/quota.ts +131 -51
- package/src/providers/integrations/cursor/cursor-http2.ts +0 -3
- package/src/providers/integrations/cursor/cursor-quota.ts +2 -6
- package/src/providers/integrations/cursor/cursor-request.ts +0 -87
- package/src/providers/integrations/cursor/cursor-shared.ts +0 -4
- package/src/providers/integrations/cursor/cursor.ts +38 -5
- package/src/providers/integrations/cursor/protocol/framing.ts +0 -56
- package/src/providers/integrations/cursor/protocol/messages.ts +0 -96
- package/src/providers/integrations/factory/factory.ts +9 -9
- package/src/providers/integrations/github/github-discovery.ts +55 -10
- package/src/providers/integrations/github/github-oauth.ts +6 -5
- package/src/providers/integrations/github/github.ts +41 -14
- package/src/providers/integrations/grok/grok-oauth.ts +261 -261
- package/src/providers/integrations/grok/grok-quota-frame.ts +1 -1
- package/src/providers/integrations/grok/grok-quota.ts +16 -7
- package/src/providers/integrations/grok/grok-ratelimit-store.ts +0 -5
- package/src/providers/integrations/grok/grok-ratelimit.ts +3 -0
- package/src/providers/integrations/grok/grok.ts +86 -36
- package/src/providers/integrations/kilo/kilo-oauth.ts +1 -1
- package/src/providers/integrations/kiro/kiro-cache.ts +31 -0
- package/src/providers/integrations/kiro/kiro-catalog.ts +31 -5
- package/src/providers/integrations/kiro/kiro-discovery.ts +47 -43
- package/src/providers/integrations/kiro/kiro-machine-id.ts +6 -3
- package/src/providers/integrations/kiro/kiro-oauth.ts +523 -255
- package/src/providers/integrations/kiro/kiro-quota.ts +35 -47
- package/src/providers/integrations/kiro/kiro-request.ts +8 -11
- package/src/providers/integrations/kiro/kiro-stream.ts +13 -0
- package/src/providers/integrations/kiro/kiro.ts +81 -68
- package/src/providers/integrations/muse/muse-oauth.ts +0 -1
- package/src/providers/integrations/muse/muse-quota.ts +0 -4
- package/src/providers/integrations/opencode/fingerprint.ts +7 -5
- package/src/providers/integrations/opencode/provider.ts +17 -24
- package/src/providers/integrations/qoder/qoder-catalog.ts +85 -8
- package/src/providers/integrations/qoder/qoder-oauth.ts +165 -25
- package/src/providers/integrations/qoder/qoder-quota.ts +48 -6
- package/src/providers/integrations/qoder/qoder-realm.ts +10 -31
- package/src/providers/integrations/qoder/qoder-sse.ts +159 -0
- package/src/providers/integrations/qoder/qoder-umid.ts +21 -25
- package/src/providers/integrations/qoder/qoder-virtual.ts +12 -0
- package/src/providers/integrations/qoder/qoder.ts +354 -62
- package/src/providers/integrations/shared/connect.ts +0 -54
- package/src/providers/integrations/shared/hash.ts +15 -0
- package/src/providers/integrations/shared/session-cache.ts +136 -0
- package/src/providers/integrations/trae/trae-cache.ts +7 -87
- package/src/providers/integrations/trae/trae-catalog.ts +1 -6
- package/src/providers/integrations/trae/trae-protocol.ts +17 -8
- package/src/providers/integrations/trae/trae-realm.ts +0 -7
- package/src/providers/integrations/trae/trae.ts +53 -10
- package/src/providers/integrations/xai/xai-oauth.ts +5 -5
- package/src/providers/integrations/zcode-start-plan/gifts.ts +265 -0
- package/src/providers/integrations/zcode-start-plan/oauth.ts +154 -0
- package/src/providers/integrations/zcode-start-plan/provider.ts +131 -0
- package/src/providers/integrations/zcode-start-plan/quota.ts +152 -0
- package/src/providers/integrations/zcode-start-plan/zcode_prompt.json +10 -0
- package/src/providers/operations/account-error-classification.ts +131 -116
- package/src/providers/operations/account-health-service.ts +31 -39
- package/src/providers/operations/account-reset-service.ts +58 -1
- package/src/providers/operations/cli-platform.ts +31 -5
- package/src/providers/operations/client-version-resolver.ts +4 -6
- package/src/providers/operations/client-versions.ts +10 -7
- package/src/providers/operations/provider-catalog-seeder.ts +2 -0
- package/src/providers/operations/provider-catalog-service.ts +18 -2
- package/src/providers/operations/provider-credential-service.ts +19 -2
- package/src/providers/provider-contracts.ts +18 -7
- package/src/providers/provider-metadata.ts +17 -2
- package/src/providers/provider-model-definition.ts +22 -1
- package/src/providers/provider-probe.ts +4 -2
- package/src/providers/provider-usage.ts +81 -16
- package/src/providers/quota/cache.ts +29 -0
- package/src/providers/quota/quota-contracts.ts +4 -0
- package/src/providers/quota/refresh.ts +27 -4
- package/src/providers/quota/snapshot.ts +94 -0
- package/src/providers/search/search-provider.ts +1 -3
- package/src/providers/search/search-providers.ts +2 -1
- package/src/security/abuse.ts +4 -4
- package/src/security/admission/service.ts +2 -2
- package/src/security/admission/ttl.ts +61 -61
- package/src/security/api-key-auth.ts +16 -4
- package/src/security/client-router-fingerprint.ts +4 -4
- package/src/security/credential-codec.ts +3 -3
- package/src/security/csrf.ts +2 -2
- package/src/security/ip-boundary.ts +16 -189
- package/src/security/model-access-rule.ts +1 -1
- package/src/security/outbound-headers.ts +18 -0
- package/src/shared/invoke-guard.ts +47 -0
- package/src/transport/contracts.ts +13 -4
- package/src/transport/dispatch/attempt-finalize.ts +1 -1
- package/src/transport/dispatch/capture-policy.ts +34 -37
- package/src/transport/dispatch/empty-stream.ts +23 -20
- package/src/transport/dispatch/generation.ts +25 -45
- package/src/transport/dispatch/native-shared.ts +127 -0
- package/src/transport/dispatch/proxy-request.ts +3 -1
- package/src/transport/dispatch/responses-compact.ts +25 -46
- package/src/transport/dispatch/streaming/encoder.ts +18 -72
- package/src/transport/dispatch/streaming/finalize.ts +2 -2
- package/src/transport/dispatch/streaming/stream.ts +7 -3
- package/src/transport/dispatch/streaming/thinking-loop.ts +1 -1
- package/src/transport/dispatch/systemone.ts +20 -48
- package/src/transport/dispatch/token-count.ts +41 -38
- package/src/transport/dispatch/websearch.ts +19 -45
- package/src/transport/drain-endpoint.ts +1 -1
- package/src/transport/failure-policy.ts +6 -0
- package/src/transport/guards/auth-guard.ts +0 -6
- package/src/transport/guards/body-policy.ts +3 -3
- package/src/transport/guards/headroom-guard.ts +1 -1
- package/src/transport/guards/pipeline.ts +1 -1
- package/src/transport/guards/request-context.ts +12 -17
- package/src/transport/request/preparer.ts +286 -7
- package/src/transport/request/rtk/compress-request.ts +3 -3
- package/src/transport/request/rtk/rtk-constants.ts +2 -2
- package/src/transport/request/rtk/rtk-filters.ts +8 -8
- package/src/transport/request/state.ts +1 -13
- package/src/transport/request/system-prompt-injection.ts +74 -11
- package/src/transport/request/tenant-preferences.ts +22 -0
- package/src/transport/routing/candidate-index.ts +2 -2
- package/src/transport/routing/round-robin.ts +1 -1
- package/src/transport/routing/route-catalog.ts +17 -18
- package/src/transport/routing/route-model.ts +126 -33
- package/src/transport/routing/router.ts +152 -37
- package/src/transport/shutdown-notice.ts +2 -2
- package/src/transport/surface/adapters.ts +3 -3
- package/src/transport/surface/chat/encode.ts +7 -7
- package/src/transport/surface/chat/parse.ts +7 -7
- package/src/transport/surface/completion.ts +2 -2
- package/src/transport/surface/content-parts.ts +1 -1
- package/src/transport/surface/dialects.ts +2 -2
- package/src/transport/surface/messages/parse.ts +3 -3
- package/src/transport/surface/responses/adapter.ts +1 -1
- package/src/transport/surface/responses/errors.ts +0 -9
- package/src/transport/vision-handoff-cache.ts +58 -0
- package/src/transport/vision-handoff.ts +376 -0
- package/src/workers/account-identity-sweep.ts +2 -2
- package/src/workers/buddy-growth-tasks.ts +392 -346
- package/src/workers/daily-checkin.ts +102 -49
- package/src/workers/maintenance-lease.ts +2 -35
- package/src/workers/oauth-refresh-sweep.ts +8 -1
- package/src/workers/quota-refresh-sweep.ts +120 -82
- package/src/workers/scheduler.ts +67 -4
- package/src/workers/sweep-runner.ts +24 -5
- package/src/workers/zcode-gift-claim.ts +108 -0
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js +0 -1
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js.gz +0 -0
- package/dist/dashboard/assets/BannedPage-ChG5svFb.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BIcWQun7.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-Bf2VelDe.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-DCgm5g6g.js +0 -1
- package/dist/dashboard/assets/CombosPage-DCgm5g6g.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-a8mD0QF1.js +0 -1
- package/dist/dashboard/assets/ConsoleLogPage-a8mD0QF1.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-ggeMSjte.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-DzSWzE_j.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-DzSWzE_j.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-U6AKaJcF.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-BMS2t8BA.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-D2D4IiHl.js +0 -1
- package/dist/dashboard/assets/OverviewPage-D2D4IiHl.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-CrNf7j_X.js +0 -5
- package/dist/dashboard/assets/ProviderDetailPage-CrNf7j_X.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js +0 -1
- package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BSDbquc1.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-BSDbquc1.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-lsrx7NYg.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-L0skzML8.js +0 -1
- package/dist/dashboard/assets/QuotaPage-L0skzML8.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-CmAbjRHW.js +0 -1
- package/dist/dashboard/assets/SettingsPage-CmAbjRHW.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-f0DE1h0-.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-ClzpwyET.js +0 -1
- package/dist/dashboard/assets/SortableList-ClzpwyET.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-Cq5tW7hW.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-Dfc9rWQn.js +0 -56
- package/dist/dashboard/assets/UsagePage-Dfc9rWQn.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-C38iXoO4.js +0 -1
- package/dist/dashboard/assets/api-keys-C38iXoO4.js.gz +0 -0
- package/dist/dashboard/assets/app-a159k0ub.css +0 -2
- package/dist/dashboard/assets/app-a159k0ub.css.gz +0 -0
- package/dist/dashboard/assets/assert-DbRA8EG2.js +0 -15
- package/dist/dashboard/assets/assert-DbRA8EG2.js.gz +0 -0
- package/dist/dashboard/assets/badge-D9CS6dZk.js.gz +0 -0
- package/dist/dashboard/assets/banner-DympBNq4.js.gz +0 -0
- package/dist/dashboard/assets/card-ibRWU_uT.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-63qBGaRw.js +0 -1
- package/dist/dashboard/assets/cli-tools-63qBGaRw.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-DJm-9pz7.js.gz +0 -0
- package/dist/dashboard/assets/dialog-8fiE6tec.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CqGYeOrd.js.gz +0 -0
- package/dist/dashboard/assets/entry-BSAsYsmV.js.gz +0 -0
- package/dist/dashboard/assets/entry-CiIQULZD.js +0 -4
- package/dist/dashboard/assets/entry-CiIQULZD.js.gz +0 -0
- package/dist/dashboard/assets/entry-Daz0lJ-W.js +0 -1
- package/dist/dashboard/assets/entry-Daz0lJ-W.js.gz +0 -0
- package/dist/dashboard/assets/formatters-D-MTJxMr.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-CPK47xQx.js.gz +0 -0
- package/dist/dashboard/assets/index-DBNPOfhV.js.gz +0 -0
- package/dist/dashboard/assets/inline-BT0zntEr.js.gz +0 -0
- package/dist/dashboard/assets/input-Da2ZViWg.js.gz +0 -0
- package/dist/dashboard/assets/layout-BXNeLw6M.js.gz +0 -0
- package/dist/dashboard/assets/list-row-BycOrrIV.js.gz +0 -0
- package/dist/dashboard/assets/live-DCQNZpF7.js +0 -1
- package/dist/dashboard/assets/live-DCQNZpF7.js.gz +0 -0
- package/dist/dashboard/assets/network-9Yj2ZyLo.js +0 -1
- package/dist/dashboard/assets/network-9Yj2ZyLo.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CEagj6ZZ.js +0 -2
- package/dist/dashboard/assets/numbers-CEagj6ZZ.js.gz +0 -0
- package/dist/dashboard/assets/quota-Caw7wqci.js +0 -1
- package/dist/dashboard/assets/quota-Caw7wqci.js.gz +0 -0
- package/dist/dashboard/assets/routing-CO9zCUus.js +0 -1
- package/dist/dashboard/assets/routing-CO9zCUus.js.gz +0 -0
- package/dist/dashboard/assets/select-BIYIBkMU.js.gz +0 -0
- package/dist/dashboard/assets/settings-jS3-PNSA.js +0 -1
- package/dist/dashboard/assets/settings-jS3-PNSA.js.gz +0 -0
- package/dist/dashboard/assets/stack-DfgnFDWY.js.gz +0 -0
- package/dist/dashboard/assets/state-CkfdYWel.js.gz +0 -0
- package/dist/dashboard/assets/stream-retry-5QnVuSSo.js +0 -1
- package/dist/dashboard/assets/stream-retry-5QnVuSSo.js.gz +0 -0
- package/dist/dashboard/assets/switch-SYm237HG.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-BQqCRNIi.js.gz +0 -0
- package/src/network/response-headers.ts +0 -39
- package/src/protocol/response/dsml.ts +0 -38
- package/src/providers/integrations/xiaomi-mimo/think-stream.ts +0 -229
- /package/dist/dashboard/assets/{app-BayTTy01.js → app-Bgd3zANQ.js} +0 -0
- /package/dist/dashboard/assets/{app-BayTTy01.js.gz → app-Bgd3zANQ.js.gz} +0 -0
- /package/dist/dashboard/assets/brand/{og_bansos.webp → og_bansos_initial.webp} +0 -0
- /package/dist/dashboard/assets/brand/{og_image.webp → og_image_initial.webp} +0 -0
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{D as u,E as d,S as f,T as p,a as m,h,k as g,l as _,s as v,u as y,w as b,y as x}from"./numbers-CEagj6ZZ.js";import{t as S}from"./circle-alert-CntYHV5v.js";import{t as C}from"./circle-check-BU3v_mFW.js";import{l as w,m as T}from"./formatters-D-MTJxMr.js";import{t as E}from"./eye-off-Bk5g2luF.js";import{t as D}from"./eye-C_hawfH4.js";import{t as O}from"./gauge-BbIMy7MB.js";import{t as k}from"./image-BPaouViG.js";import{n as A,r as j,t as M}from"./state-CkfdYWel.js";import{t as N}from"./key-round-UkavsGxp.js";import{t as ee}from"./layers-2-glBbjl.js";import{r as te}from"./use-modal-focus-By7oJoGd.js";import{n as P,t as F}from"./dialog-8fiE6tec.js";import{t as I}from"./pencil-768ysRAr.js";import{t as ne}from"./plus-DIdX_g-x.js";import{t as re}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as ae}from"./rotate-ccw-CufcqITi.js";import{t as oe}from"./search-JOKus9rb.js";import{t as se}from"./trash-Cppn5c3R.js";import{t as L}from"./wrench-B6E1oEuY.js";import{E as ce,v as le,w as ue}from"./assert-DbRA8EG2.js";import{i as de,l as fe,o as pe,t as R}from"./query-keys-BloKtaXJ.js";import{A as me,B as he,C as ge,D as _e,O as ve,S as ye,T as be,_ as xe,a as Se,b as Ce,c as we,d as z,f as Te,ft as Ee,g as De,h as Oe,k as ke,l as Ae,m as je,nt as Me,o as Ne,p as Pe,r as Fe,rt as Ie,t as Le,tt as Re,u as B,ut as ze,w as Be,x as Ve}from"./entry-CiIQULZD.js";import{n as V,r as He,t as H}from"./card-ibRWU_uT.js";import{n as Ue}from"./download-dRFo5_Wu.js";import{f as U,i as We,l as Ge,n as Ke,r as qe,s as Je,u as Ye}from"./tokens-COzario9.js";import{t as W}from"./switch-SYm237HG.js";import{t as G}from"./badge-D9CS6dZk.js";import{n as K}from"./input-Da2ZViWg.js";import{t as q}from"./select-BIYIBkMU.js";import{t as Xe}from"./ProviderIcon-FB6yS4v1.js";import{t as J}from"./stack-DfgnFDWY.js";import{n as Y,t as Ze}from"./inline-BT0zntEr.js";import{c as Qe,i as $e}from"./quota-Caw7wqci.js";import{t as X}from"./banner-DympBNq4.js";import{t as et}from"./list-row-BycOrrIV.js";import{c as tt,l as nt,m as rt}from"./routing-CO9zCUus.js";import{d as it,l as at,u as ot,y as st}from"./network-9Yj2ZyLo.js";import{o as ct,s as lt,t as ut}from"./HealthEventsModal-DzSWzE_j.js";import{r as dt}from"./privacy-mode-GM8bej85.js";import{n as ft,t as pt}from"./AccountCooldown-Bjo92Qat.js";import{t as mt}from"./use-timeout-BwcBBRrT.js";var ht=e(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),gt=e(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),_t=e(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),vt=e(`package-x`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`m16.5 14.5 5 5`,key:`ozpm51`}],[`path`,{d:`m16.5 19.5 5-5`,key:`syf6b9`}],[`path`,{d:`M21 10.5V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l.13-.074`,key:`isw6gs`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),yt=e(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),bt=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),xt=e(`shuffle`,[[`path`,{d:`m18 14 4 4-4 4`,key:`10pe0f`}],[`path`,{d:`m18 2 4 4-4 4`,key:`pucp1d`}],[`path`,{d:`M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22`,key:`1ailkh`}],[`path`,{d:`M2 6h1.972a4 4 0 0 1 3.6 2.2`,key:`km57vx`}],[`path`,{d:`M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45`,key:`os18l9`}]]),St=e(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),Ct=e(`waypoints`,[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]),wt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function Tt(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function Et({to:e,label:t}){let n=Re();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function Dt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(Et,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:h(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function Ot(e){return e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function kt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var At={fallback:`Failover`,roundRobin:`Round robin`},jt=new Set([`inferhub`,`cline`]);function Mt(e,t){let n=nt(e),r=rt(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=kt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=kt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=kt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=kt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v})},skipProxy:g,userAgent:v,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),x(e)},setMaxInflightPerProxy:e=>{d(e),S(e)},setUserAgent:e=>{y(e),w(e)},setSkipProxy:e=>{_(e),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),b({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})},rotateCount:o,setRotateCount:e=>{s(e),C(e)}}}var Nt=[{value:`least_loaded`,label:`Least loaded`},{value:`round_robin`,label:`Round robin`},{value:`random`,label:`Random`}],Pt=50,Ft=100;function It(e,t,n){return[{value:``,label:`None`},{value:`Cartethyia/${e}`,label:`Cartethyia ${e}`},{value:`codex_cli_rs/${t}`,label:`Codex`},{value:`claude-cli/${n} (external, cli)`,label:`Claude Code`}]}function Lt({children:e,action:t}){return(0,Q.jsx)(et,{actions:t,children:e})}function Rt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=Mt(e,r),a=it(),o=st(),[s,c]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),f=jt.has(e),p=It(Le,n.codex,n.claude),m=p.some(e=>e.value===i.userAgent)?p:[...p,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(j,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(A,{message:`Failed to load routing`,onRetry:i.refetch});let h=i.roundRobinEnabled?`${At.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:At.fallback,g=a.data,y=Nt.find(e=>e.value===g?.strategy),b=g===void 0?`…`:i.skipProxy?`Direct — proxy pools bypassed`:y?g.strategy===`round_robin`?`${y.label} · ${g.rotateCount} per rotation`:y.label:`Unset`,x=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Per-account and per-pool routing`,S=i.maxInflight===null,C=S?51:Math.min(51,Math.max(1,i.maxInflight)),w=S?`∞`:String(i.maxInflight),T=i.maxInflightPerProxy===null,E=T?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),D=T?`∞`:String(i.maxInflightPerProxy),k=i.skipProxy,M=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},N=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=m.find(t=>t.value===e)?.label??e;v.success(`Client identity updated`,t)},te=e=>{e!==g?.strategy&&o.mutate({strategy:e})},I=e=>{g&&o.mutate({rotateCount:Math.min(1e3,Math.max(1,g.rotateCount+e))})},re=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Routing Strategy`,subtitle:x,icon:(0,Q.jsx)(ee,{size:16})}),(0,Q.jsx)(V,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Provider accounts`}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,Q.jsx)(`span`,{className:`status-indicator-dot${i.roundRobinEnabled?` bg-accent`:` bg-text-tertiary`}`,"aria-hidden":`true`}),h]})]}),(0,Q.jsx)(Lt,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(P,{size:14}),onClick:()=>M(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(ne,{size:14}),onClick:()=>M(1)})]}):null,(0,Q.jsx)(W,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(yt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Rotate accounts`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(Lt,{action:(0,Q.jsx)(W,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ht,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Proxy pools`}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,Q.jsx)(`span`,{className:`status-indicator-dot${i.skipProxy?` bg-text-tertiary`:` bg-accent`}`,"aria-hidden":`true`}),b]}),(0,Q.jsx)(_,{variant:`ghost`,size:`sm`,className:`shrink-0 -my-1`,"aria-label":`How pool routing works`,onClick:()=>d(!0),children:`How it works`})]}),(0,Q.jsx)(Lt,{action:(0,Q.jsxs)(Y,{gap:`8px`,align:`center`,children:[g?.strategy===`round_robin`&&!i.skipProxy?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Pools per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Pools/rotation`}),(0,Q.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease pools per rotation`,disabled:o.isPending||g.rotateCount<=1,icon:(0,Q.jsx)(P,{size:14}),onClick:()=>I(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:g.rotateCount}),(0,Q.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase pools per rotation`,disabled:o.isPending||g.rotateCount>=1e3,icon:(0,Q.jsx)(ne,{size:14}),onClick:()=>I(1)})]}):null,(0,Q.jsx)(q,{id:`routing-pool-strategy`,"aria-label":`Pool selection mode`,value:g?.strategy??``,disabled:i.skipProxy||o.isPending,options:Nt,onValueChange:te})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-pool-strategy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(xt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-text-tertiary`:`text-accent`}`}),`Pool mode`]})}),(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`How proxy pools are chosen when this provider dials one.`,i.skipProxy?` Disabled while “Always direct” is on.`:``]})]})})]}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(q,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:m,onValueChange:N}):(0,Q.jsx)(q,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:re,options:[{value:re,label:re}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(O,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,Pt,` is unlimited.`]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":S?`true`:void 0,min:1,max:51,step:1,value:C,"aria-valuetext":S?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>Pt?null:Math.round(t))},style:{"--slider-pct":`${C/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:w,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflight(Math.min(Ft,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${S?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${k?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(Ct,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(_,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>c(!0),children:`How it works`})]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":T?`true`:void 0,min:1,max:51,step:1,disabled:k,value:E,"aria-valuetext":T?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>Pt?null:Math.round(t))},style:{"--slider-pct":`${E/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:k,value:D,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflightPerProxy(Math.min(Ft,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${T?`text-status-success`:``}`})]}),(0,Q.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:k?`Always direct is on, so this provider never dials a pool. The limit is kept for when a pool is used again.`:`One step past ${Pt} is unlimited.`})]}),(0,Q.jsx)(F,{open:s,onClose:()=>c(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),(0,Q.jsx)(F,{open:u,onClose:()=>d(!1),title:`How pool routing works`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`When a provider dials a proxy pool, the gateway picks the pool with one of three modes. All modes skip pools that are cooling down, full, or disabled — the pool's own gates always apply.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Least loaded`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Each request goes to the pool with the most headroom (weighted). The default — spreads load and prefers the fastest-available egress.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Round robin`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Requests rotate across pools in a fixed order, with a set number of successful requests per pool before moving on. Useful for even request counts across pools.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Random`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Each request picks from the eligible pools at random, so a burst does not gang up on the first pools in the order.`})]})]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Turning on “Always direct” bypasses pools entirely — this mode has no effect then.`})]})}),f&&(0,Q.jsxs)(Y,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(gt,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function zt(e){if(typeof e!=`object`||!e)throw{status:500,code:`invalid_response`,message:`Invalid InferHub summary`};let t=e;return{models:Array.isArray(t.models)?t.models:[],providers:Array.isArray(t.providers)?t.providers:[],pricingConfig:t.pricingConfig??null,meta:t.meta??{fetchedAt:0,ageSeconds:0,stale:!0},error:t.error??null}}function Bt(e=!0){return ue({queryKey:R.inferhub.summary,queryFn:e=>pe(`/inferhub/summary`,{signal:le(e)}).then(zt),enabled:e,...de,staleTime:6e4})}function Vt(e){return e===null?`—`:`$${e.toFixed(4)}`}function Ht(e){return e===null?`—`:`${e}%`}function Ut(e){return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}var Wt={provider:`Provider (A–Z)`,availability:`Highest availability`,sustainable:`Sustainable price`,price:`Lowest price`,discount:`Biggest discount`};function Gt(e,t){return(n,r)=>{let i=e(n),a=e(r);return i===null&&a===null?0:i===null?1:a===null?-1:t===`asc`?i-a:a-i}}function Kt(e){switch(e){case`provider`:return(e,t)=>e.family.localeCompare(t.family,void 0,{sensitivity:`base`})||e.prefix.localeCompare(t.prefix);case`availability`:return(e,t)=>t.providersLive-e.providersLive||Gt(e=>e.health.successRatePct,`desc`)(e,t);case`sustainable`:return Gt(e=>e.capacityPriceIn,`asc`);case`price`:return Gt(e=>e.minAskIn,`asc`);case`discount`:return Gt(e=>e.tiersIn[0]?.discountPct??null,`desc`)}}function qt(e){return e===`operational`?`ok`:e===`degraded`?`warn`:e===`major_outage`?`err`:`default`}function Jt(e,t){return e.providers.find(e=>e.prefix===t)}function Yt(e){return e.providersLive>0&&e.routable&&e.minAskIn!==null}function Xt(){let e=Bt(),t=e.data,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(`provider`),u=t?.models??[],d=u.filter(Yt),f=(0,Z.useMemo)(()=>{let e=[...i?u:d].sort(Kt(c)),t=new Map;for(let n of e){let e=t.get(n.prefix);e===void 0?t.set(n.prefix,[n]):e.push(n)}return[...t.entries()].map(([e,t])=>({prefix:e,family:t[0]?.family??e,models:t}))},[u,d,i,c]),p=(0,Q.jsxs)(_,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,Q.jsx)(ie,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,Q.jsx)(ie,{size:16})}),(0,Q.jsx)(V,{children:e.isError?(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`InferHub market`,icon:(0,Q.jsx)(ie,{size:16}),action:p}),(0,Q.jsx)(V,{children:(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let m=f,g=m.reduce((e,t)=>e+t.models.length,0),v=u.length-g;return(0,Q.jsxs)(H,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-start gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,Q.jsx)(Ee,{size:15,"aria-hidden":`true`,className:h(`mt-1 shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,Q.jsxs)(J,{gap:`1px`,children:[(0,Q.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,Q.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,Ut(t.meta.ageSeconds)]}):null]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:n?p:null})]}),n?(0,Q.jsxs)(V,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(Qt,{onSaved:()=>void e.refetch()}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,Q.jsx)(q,{value:c,onValueChange:e=>l(e),options:Object.keys(Wt).map(e=>({value:e,label:Wt[e]})),"aria-label":`Sort InferHub models`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,Q.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`InferHub did not answer. Showing the last snapshot that was read`,t.meta.fetchedAt>0?` (${Ut(t.meta.ageSeconds)})`:``,`.`]}):null,t.meta.stale&&t.error===null?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,Ut(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[g,` of `,u.length,` models`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,v>0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,v,` hidden)`]}):null]})]}),m.length===0?(0,Q.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:m.map(e=>(0,Q.jsx)(Zt,{group:e,showUpstreams:o,summary:t},e.prefix))})]}):null]})}function Zt({group:e,showUpstreams:t,summary:n}){let[r,i]=(0,Z.useState)(!0),a=Jt(n,e.prefix),o=a?.familyState??null,s=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,Q.jsx)(Ee,{size:14,"aria-hidden":`true`,className:h(`shrink-0 transition-transform`,!r&&`-rotate-90`)}),(0,Q.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,Q.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),o===null?null:(0,Q.jsx)(G,{tone:qt(o),dot:!0,children:o.replace(/_/g,` `)}),t&&a!==void 0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Ht(a.availability24hPct),` · 7d`,` `,Ht(a.availability7dPct)]}):null,(0,Q.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),r?(0,Q.jsxs)(`div`,{className:`px-3 pb-3`,children:[s===null?null:(0,Q.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:s}),(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,Q.jsx)(`tbody`,{children:e.models.map(e=>(0,Q.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,Q.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,Q.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Vt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,Q.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Vt(e.capacityPriceIn),` sustainable`]}):null]}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Vt(e.minAskOut)}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,Q.jsx)(G,{children:`none`}):e.providersLive}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Ht(t?a?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function Qt({onSaved:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await pe(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await pe(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,Q.jsx)(K,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,Q.jsx)(_,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,Q.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),s===null?null:(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function $t({providerId:e}){let t=Mt(e,!1),n=ct(),r=tt(e),i=(0,Z.useMemo)(()=>tn(n.data?.accounts??[],e),[n.data,e]),a=(0,Z.useRef)(null),o=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Z.useState)(`40`),[l,u]=(0,Z.useState)(`percent`),d=t.usageFloor!==null;(0,Z.useEffect)(()=>{t.usageFloor!==null&&c(String(t.usageFloor)),u(t.usageFloorUnit)},[t.usageFloor,t.usageFloorUnit]);let f=Number(s),p=Number.isInteger(f)&&f>=0&&f<=1e6,m=i===null||i.remaining<=0?`text-status-danger`:i.percent<=10?`text-status-warning`:`text-status-success`,h=(e,n)=>{(e===null||p)&&t.setUsageFloor(e,n)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(O,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,Q.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`}),i.inactiveAccounts>0?(0,Q.jsxs)(`span`,{className:`badge border border-warning-line text-status-warning normal-case tracking-normal`,title:`Disabled or cooled accounts hold credits this provider cannot route to. Enable or recover them to add their balance.`,children:[i.inactiveAccounts,` inactive`]}):null]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-caption font-semibold tabular-nums text-text-primary`,title:`Combined allowance across active accounts; the usage floor is evaluated per account`,children:[(0,Q.jsx)(`strong`,{className:`font-bold ${m}`,children:nn(i.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,nn(i.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${nn(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${nn(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value:d?s:``,placeholder:`40`,disabled:!d,"aria-label":`Usage floor amount`,className:`h-full w-24 border-0 bg-transparent px-3 text-right font-mono text-body font-semibold tabular-nums text-text-primary disabled:text-text-tertiary`,onChange:e=>c(e.target.value),onBlur:()=>{d&&h(f,l)}}),(0,Q.jsxs)(`select`,{value:l,disabled:!d,"aria-label":`Usage floor unit`,className:`h-full border-0 border-l border-inner-border bg-hover px-3 text-body font-semibold text-text-secondary disabled:cursor-default disabled:opacity-60`,onChange:e=>{let t=e.target.value===`credit`?`credit`:`percent`;u(t),d&&h(f,t)},children:[(0,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(W,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(en,{providerId:e})]})}function en({providerId:e}){let{enabled:t,setEnabled:n}=dt(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(E,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(W,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function tn(e,t){let n=0,r=0,i=0,a=0,o=!1;for(let s of e)if(s.provider===t){if(!s.active){a+=1;continue}if(i+=1,s.quota!==null)for(let e of s.quota.windows){if(e.accounting!==`pooled`)continue;let t=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null;if(t===null)continue;let i=typeof e.remaining==`number`&&Number.isFinite(e.remaining)?e.remaining:typeof e.used==`number`&&Number.isFinite(e.used)?t-e.used:null;i!==null&&(n+=Math.min(t,Math.max(0,i)),r+=t,o=!0)}}return i>0&&o?{accounts:i,inactiveAccounts:a,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function nn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function rn({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(H,{density:`compact`,children:(0,Q.jsx)(V,{children:(0,Q.jsxs)(Y,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:y({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(ze,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function an({provider:e}){let t=ke(),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.baseUrl??``);(0,Z.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,Q.jsx)(b,{size:16})}),(0,Q.jsx)(V,{children:(0,Q.jsxs)(J,{gap:`12px`,children:[n?(0,Q.jsx)(K,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,Q.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(bt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(te,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(I,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(N,{size:13}),onClick:()=>{let e=document.getElementById(`provider-accounts`);e?.scrollIntoView({behavior:`smooth`,block:`start`}),e?.focus({preventScroll:!0})},children:`Manage API keys`}):null]})]})})]})}async function on(e,t,n){let r=Array(e.length),i=Math.max(1,Math.min(t,e.length)),a=0;return await Promise.all(Array.from({length:i},async()=>{for(;;){let t=a;if(t>=e.length)return;a+=1;try{r[t]={status:`fulfilled`,value:await n(e[t],t)}}catch(e){r[t]={status:`rejected`,reason:e}}}})),r}var sn={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`,validation_required:`Verification required`},cn=new Set([`quota_fetch_failed`]);function ln(e){return e===void 0||e.length===0?!1:!cn.has(e)}function un(e){return e===`oauth`?`Re-login required`:`Replace API key`}function dn(e,t){return e===`auth_invalidated`?un(t):sn[e]??e}var fn=/https?:\/\/[^\s"'\\]+/;function pn(e){if(e)return fn.exec(e)?.[0]}function mn({cooldowns:e,reason:t}){if(!e)return null;let n=$e(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(G,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function hn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function gn(e){if(!ln(e.lastErrorCategory)||e.lastErrorCategory===`quota_exhausted`&&pt(e))return null;let t=dn(e.lastErrorCategory,e.credentialKind),n=e.lastError??e.lastErrorCategory;if(e.lastErrorCategory===`validation_required`){let r=pn(e.lastError);if(r!==void 0)return(0,Q.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,title:n,children:(0,Q.jsxs)(G,{tone:`warn`,children:[t,(0,Q.jsx)(ze,{size:12,className:`shrink-0`,"aria-hidden":`true`})]})})}return(0,Q.jsx)(G,{tone:`warn`,title:n,children:t})}function _n(e){return e.credentialKind===`oauth`?`blue`:`ok`}function vn({account:e}){let t=e.providerCooldowns;if(!t||t.length===0)return null;let n=Date.now(),r=t.filter(e=>new Date(e.until).getTime()>n);if(r.length===0)return null;let i=r.some(e=>e.blocked),a=r.reduce((e,t)=>{let n=new Date(t.until).getTime();return n<e?n:e},1/0),o=r.map(e=>`${e.providerId}: ${e.reason}${e.blocked?` (blocked)`:``}`).join(` · `);return(0,Q.jsx)(G,{tone:`warn`,title:`${o} — resets ${$e(new Date(a).toISOString())}`,children:i?`Egress blocked`:`Rate-limited`})}function yn({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=pt(e);if(e.status===`disabled`){let t=hn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(G,{tone:`warn`,title:e.lastError,children:un(e.credentialKind)}):gn(e),(0,Q.jsx)(mn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:_n(e),dot:!0,children:[`Active`,hn(e)?` - ${hn(e)}`:``]}),(0,Q.jsx)(vn,{account:e}),gn(e),(0,Q.jsx)(mn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:`warn`,dot:!0,children:[`Cooldown`,hn(e)?` - ${hn(e)}`:``,` `,e.cooldownUntil?`(${$e(e.cooldownUntil)})`:``]}),(0,Q.jsx)(vn,{account:e}),gn(e),(0,Q.jsx)(mn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(G,{tone:`disabled`,children:`Disabled`})}function bn(e){if(e===void 0)return;let t=new Date(e).getTime();if(Number.isFinite(t))return t<=Date.now()?`Expired ${new Date(e).toLocaleDateString()}`:$e(e,!1)}function xn({windows:e}){let t=Qe(e??[]);return t.text===null?null:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":t.low?`warn`:void 0,title:t.hasCredits?`${Sn(t.remaining)} credits available of ${Sn(t.total)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),t.text]})}function Sn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Cn({providerId:e,account:t,onClose:n}){let r=me(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{v.error(`Clipboard access denied`)}};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(_,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{v.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;v.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(Y,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function wn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=me(),l=Ce(),u=lt(t.id),d=ot(),m=t.kind===`pool`,h=t.networkPoolId,g=at(m?h:void 0),y=t.status===`disabled`,b=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,x=Number.isFinite(b)&&b>Date.now(),S=t.status===`cooldown`||x,[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[,k]=(0,Z.useState)(0),[ee,te]=(0,Z.useState)(!1),[P,ne]=(0,Z.useState)(``),ie=dt(e),oe=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),L=ie.enabled?`Mysterious accounts`:oe,ce=bn(t.tokenExpiresAt),le=ft(t),ue=Math.max(x&&t.cooldownUntil?b:0,le??0);(0,Z.useEffect)(()=>{if(ue<=Date.now())return;let e=setInterval(()=>k(e=>e+1),1e3);return()=>clearInterval(e)},[ue]);let de=()=>{let n=P.trim();te(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>v.success(`Account renamed`,n),onError:e=>v.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:y?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${L}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:ee?(0,Q.jsx)(K,{value:P,onChange:e=>ne(e.target.value),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&te(!1)},onBlur:de,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:L}),m?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 border border-inner-border rounded-tiny bg-surface-1 text-micro font-bold uppercase tracking-label text-text-secondary`,title:`Proxy pool routing as an account for this ip-scoped provider`,children:`Pool`}):null,(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${L}`,onClick:()=>{ne(t.label??``),te(!0)},children:(0,Q.jsx)(I,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(yn,{account:t}),ce?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:ce,children:ce}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(xn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[m?(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${L}`,onClick:()=>E(!0),title:`View pool health & error history`}):(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${L}`,onClick:()=>w(!0),title:`View Health & Error History`}),m?(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:d.isPending?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):(0,Q.jsx)(p,{size:12}),label:d.isPending?`Testing…`:`Test`,"aria-label":`Test ${L}`,disabled:d.isPending||h===void 0,onClick:()=>{h&&d.mutate({poolId:h,providerId:e},{onSuccess:e=>{e.status===`allowed`?v.success(`Pool probe passed`,L):e.status===`blocked`?v.error(`Pool blocked`,e.reason??`Upstream refused this egress`):e.status===`throttled`?v.error(`Pool rate-limited`,e.reason??`Address accepted; rate limit spent`):v.error(`Pool unreachable`,e.reason??`Probe could not complete`)},onError:e=>v.error(`Pool probe failed`,e.message??`Probe failed`)})},title:`Probe this pool against the provider`}):(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):(0,Q.jsx)(p,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${L}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?v.success(`Account test passed`,L):v.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>v.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),m?null:(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(N,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${L}`,onClick:()=>O(!0),title:`Replace API key`}),m?null:(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:y?(0,Q.jsx)(_t,{size:12}):(0,Q.jsx)(re,{size:12}),label:y?`Enable`:`Disable`,"aria-label":y?`Enable ${L}`:`Disable ${L}`,disabled:c.isPending,onClick:()=>{let n=y;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>v.success(n?`Account enabled`:`Account disabled`,L),onError:e=>v.error(`Update failed`,e.message??`Unable to update account`)})},title:y?`Enable account`:`Disable account`}),S?(0,Q.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(ae,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${L}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,m?null:(0,Q.jsx)(_,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),label:`Delete`,"aria-label":`Delete ${L}`,onClick:()=>s(t),title:`Delete account`})]})]}),C&&(0,Q.jsx)(ut,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode,jwtIssuer:t.jwtIssuer},onClose:()=>w(!1)}),D&&(0,Q.jsx)(Cn,{providerId:e,account:t,onClose:()=>O(!1)}),T&&(0,Q.jsx)(F,{open:!0,title:`Pool Health & Error History`,onClose:()=>E(!1),width:640,footer:(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>E(!1),children:`Close`}),children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-3 min-h-40`,children:g.isPending?(0,Q.jsx)(j,{label:`Loading pool health events…`}):g.isError?(0,Q.jsx)(A,{message:`Failed to load pool health events`,onRetry:()=>void g.refetch()}):(g.data??[]).length===0?(0,Q.jsx)(M,{compact:!0,title:`No health events recorded`,message:`Status transitions, rate limits, and auto-recoveries will appear here.`}):(0,Q.jsx)(`div`,{className:`scroll-region max-h-160 overflow-y-auto pr-1 flex flex-col gap-3`,children:(g.data??[]).map(e=>(0,Q.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-badge`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`span`,{className:`font-mono tabular-nums text-micro text-text-tertiary`,children:new Date(e.createdAt).toLocaleString()}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-text-tertiary text-micro uppercase tracking-label`,children:[e.fromStatus??`—`,` → `,e.toStatus]}),e.errorCategory?(0,Q.jsx)(`span`,{className:`rounded-pill border border-warning-line bg-surface-2 px-2.5 py-px font-mono text-micro text-status-warning`,children:e.errorCategory}):null]})]}),e.reason?(0,Q.jsx)(`p`,{className:`mt-2 text-micro text-text-secondary [overflow-wrap:anywhere] break-words`,children:e.reason}):null]},e.id))})})})]})}var Tn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],En=[`refresh`,`refreshToken`,`refresh_token`],Dn=[`credentialKind`,`providerId`,`accessToken`],On=[`accounts`,`items`,`connections`],kn=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function An(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function jn(e){for(let t of Tn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=An(e);if(t)for(let e of Tn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Mn(e){for(let t of kn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=An(e);if(t)for(let e of kn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Nn(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,En);if(n(e))return!0;let r=An(e);return r?n(r):!1}function Pn(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function Fn(e){let t=Pn(e)?.exp;if(typeof t!=`number`||!Number.isFinite(t))return;let n=new Date(t*1e3);return Number.isFinite(n.getTime())?n.toISOString():void 0}function In(e){let t={},n=0;for(let r of e.split(/\r?\n/)){let e=/^\s*([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(r),i=e?.[1],a=e?.[2];i!==void 0&&a!==void 0&&(t[i]=a.trim(),n+=1)}return n>0?t:void 0}function Ln(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var Rn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function zn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of Rn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function Bn(e){let t=e.trim(),n=$(Ln(t))??In(t);return n&&Nn(n)?`oauth`:Pn((n?jn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Vn(e){return e.length!==0&&!!(e.some(e=>Array.isArray(e.cookies)&&(typeof e.domain==`string`||typeof e.originalUrl==`string`))||e.every(e=>typeof e.name==`string`&&typeof e.value==`string`&&(e.domain!==void 0||e.path!==void 0||e.expirationDate!==void 0)))}function Hn(e,t){let n,r=!1,i=(e,t)=>{let i=e.toLowerCase();(i===`userid`||i===`uid`||i===`accountid`||i===`cuserid`)&&(n||=t.replace(/^"|"$/g,``).trim()),(i.includes(`token`)||i.includes(`ph`)||i.includes(`auth`)||i.includes(`session`))&&(r=!0)};for(let e of t)if(Array.isArray(e.cookies)){for(let t of e.cookies)if(t&&typeof t==`object`){let e=t;typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value)}}else typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value);return{value:e,kind:r?`oauth`:`api_key`,...n?{identity:n}:{}}}function Un(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&Dn.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&Nn(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=jn(e),r=Nn(e)?`oauth`:Bn(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Mn(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function Wn(e){for(let t of On){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function Gn(e){let t=e.trim();if(!t)return[];let n=Ln(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return Vn(e)?[Hn(t,e)]:e.map(Un)}else{let e=$(n);if(e){let t=Wn(e);return t?t.map(Un):[Un(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1){let e=In(r[0]);return e?[Un(e)]:Kn(r[0])}let i=In(t);return i&&(jn(i)||Object.keys(i).length===r.length)?[Un(i)]:r.flatMap(Kn)}function Kn(e){let t=$(Ln(e));if(t){let e=Wn(t);return e?e.map(Un):[Un(t)]}return[{value:e,kind:Bn(e)}]}function qn(e,t,n){let r=new Set(n),i=1;return e.map(e=>{let n=e.identity;if(!n){for(;r.has(`${t}-${i}`);)i+=1;n=`${t}-${i}`,i+=1}let a=n,o=2;for(;r.has(a);)a=`${n} (${o++})`;return r.add(a),a})}function Jn(e){let t=[];for(let n of e){let e=n.text.trim();if(!e)continue;let r=Ln(e);if(Array.isArray(r)){let n=r.filter(e=>$(e)!==void 0);if(n.length>0&&Vn(n)){t.push(e);continue}for(let e of r){let n=$(e);t.push(n===void 0?String(e):JSON.stringify(n))}continue}let i=$(r);if(i){let n=Wn(i);if(n!==void 0){for(let e of n)t.push(JSON.stringify(e));continue}t.push(e);continue}Gn(e).length<=1?t.push(e):t.push(...e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0))}let n=t.join(`
|
|
2
|
-
`);return{text:n,entries:Gn(n)}}function Yn(e,t=50){if(t<1)throw RangeError(`chunk size must be at least 1`);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}var Xn=2097152,Zn=Xn/1048576;function Qn({providerId:e,accounts:t,onClose:n}){let r=Se(),i=Ne(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(`auto`),[p,m]=(0,Z.useState)(void 0),[h,g]=(0,Z.useState)(!1),b=(0,Z.useRef)(null),x=Gn(s),S=x.length>1,C=x.length===1?x[0]:void 0,w=d===`auto`?C?.kind:d,T=C&&w===`jwt`?Fn(C.value):void 0,E=x.length>0?zn(e,s):void 0,D=E!==void 0&&p!==s,O=t.map(e=>e.label),k=S?qn(x,e,O):[],A=e=>{let t=d===`auto`?e.kind===`jwt`?`jwt`:`auto`:d;return{credentialKind:t===`auto`&&e.kind===`oauth`?`oauth`:`api_key`,credentialMode:t,secret:e.value}},j=r.isPending||l,M=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=Gn(e);if(t.length>1)v.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;v.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{v.error(`Clipboard access denied`)}},N=e=>{if(e.length===0)return;let t=e.find(e=>e.size>Xn);if(t){v.error(`File too large`,`${t.name} is over ${Zn} MB — credential files must be ${Zn} MB or smaller.`);return}let n=e.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(typeof r.result==`string`?r.result:``),r.onerror=()=>n(Error(`Could not read ${e.name}`)),r.readAsText(e)}));Promise.all(n).then(t=>{let n=Jn(e.map((e,n)=>({name:e.name,text:t[n]??``})));if(n.entries.length===0){v.error(`Nothing to import`,`None of the selected files held a credential the gateway recognises.`);return}c(n.text),v.success(`Imported ${e.length} file${e.length===1?``:`s`}`,n.entries.length>1?`Detected ${n.entries.length} credentials`:n.entries[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)}).catch(e=>v.error(`Could not read those files`,String(e)))},ee=async()=>{if(x.length!==0&&!D){if(x.length===1){let t=x[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...A(t)}},{onSuccess:()=>{v.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>v.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=Yn(x.map((e,t)=>({label:k[t],...A(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${k[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${fe(e,`request failed`)}`);break}let s=a.length;r>0&&v.success(`${r} account${r===1?``:`s`} added`,o?`stopped partway; ${s} failed`:s>0?`${s} skipped`:void 0),s>0&&v.error(`${s} account${s===1?``:`s`} skipped`,a.slice(0,5).join(`
|
|
3
|
-
`)+(s>5?`\n…and ${s-5} more`:``)),r>0&&n()}finally{u(!1)}}};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:j,children:`Cancel`}),(0,Q.jsx)(_,{size:`sm`,variant:`primary`,disabled:j||x.length===0,onClick:()=>void ee(),children:j?`Connecting...`:D?`Confirm below`:S?`Add ${x.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!S&&(0,Q.jsx)(K,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:C?.identity??`${e} account`}),(0,Q.jsx)(q,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),S?(0,Q.jsxs)(G,{tone:`accent`,children:[`Detected: `,x.length,` accounts`]}):C?(0,Q.jsxs)(G,{tone:w===`oauth`||w===`jwt`?`accent`:`default`,children:[`Detected:`,` `,w===`oauth`?`OAuth`:w===`jwt`?`Static JWT`:`API key`,C.identity?` · ${C.identity}`:``]}):null,C&&w===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,T?` · expires ${new Date(T).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-control border-2 border-dashed p-3 transition-colors`,"data-drag-active":h?`true`:void 0,onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:e=>{e.preventDefault(),g(!1);let t=[...e.dataTransfer.files].filter(e=>e.name.endsWith(`.json`)||e.name.endsWith(`.jsonl`)||e.name.endsWith(`.ndjson`)||e.name.endsWith(`.txt`)||e.type.startsWith(`application/json`)||e.type.startsWith(`text/plain`));if(t.length===0){v.error(`Unsupported file`,`Drop .json, .txt, .jsonl, or .ndjson credential files.`);return}N(t)},children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary text-center`,children:`Or drop credential files here — JSON, .txt, .jsonl, .ndjson — several at once, merged and detected together.`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>void M(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:y({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.jsx)(`input`,{ref:b,type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,multiple:!0,"aria-label":`Import credentials from files`,className:`hidden`,onChange:e=>{let t=[...e.target.files??[]];e.target.value=``,t.length>0&&N(t)}}),`Import files`]})]})]}),S&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,Q.jsx)(`span`,{className:`truncate min-w-0`,children:k[t]}),(0,Q.jsx)(G,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))}),E&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-control border border-warning-line bg-surface-2 px-4 py-5`,role:`alert`,children:[(0,Q.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,Q.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`Cross-channel credential`})}),(0,Q.jsxs)(`p`,{className:`text-caption text-text-primary`,children:[`This looks like a `,E.provider,` credential.`,` `,E.provider,` and `,E.counterpart,` tokens are interchangeable — one works in the other — but using a token on a channel it was not issued for can raise the risk of the account being banned, because it appears active somewhere it never authenticated. The same applies in reverse.`]}),D?(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>{c(``),n()},children:`Cancel`}),(0,Q.jsx)(_,{size:`sm`,variant:`primary`,onClick:()=>m(s),children:`Add anyway`})]}):(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:`Acknowledged — you can add this account now.`})]})]})})}function $n(e){return e===`active`?0:e===`cooldown`?2:3}var er=[{value:`added-asc`,label:`Added · oldest`},{value:`added-desc`,label:`Added · newest`},{value:`label-asc`,label:`Name · A–Z`},{value:`label-desc`,label:`Name · Z–A`},{value:`status-asc`,label:`Status · active first`},{value:`status-desc`,label:`Status · disabled first`},{value:`lastCheck-desc`,label:`Last check · newest`},{value:`lastCheck-asc`,label:`Last check · oldest`}];function tr(e,t,n){let r=(e,t)=>(e.label||e.id).localeCompare(t.label||t.id)||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`added`)return e.sortIndex-t.sortIndex||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`label`)return r(e,t);if(n===`status`){let n=$n(e.status)-$n(t.status);return n===0?r(e,t):n}let i=new Date(e.lastSuccessAt??e.createdAt).getTime();return new Date(t.lastSuccessAt??t.createdAt).getTime()-i||r(e,t)}function nr({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ce(),s=me(),c=Ce(),l=Ae(),u=tt(e).data??new Map,f=ct(),m=(0,Z.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[h,g]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(new Set),[x,S]=(0,Z.useState)(`added-asc`),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),k=h.trim().toLowerCase(),A=(0,Z.useMemo)(()=>k?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return k.split(/\s+/).every(e=>t.includes(e))}):t,[t,k]),j=(0,Z.useMemo)(()=>{let e=x.slice(0,x.lastIndexOf(`-`)),t=x.endsWith(`-desc`)?-1:1,n=[...A];return n.sort((n,r)=>t*tr(n,r,e)),n},[A,x]),N=(0,Z.useMemo)(()=>t.filter(e=>e.kind!==`pool`&&y.has(e.id)),[t,y]),ee=A.length>0&&A.every(e=>y.has(e.id)),P=N.some(e=>e.status===`disabled`),F=N.some(e=>e.status!==`disabled`),I=N.length===0,ne=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},ie=()=>{b(e=>{let t=new Set(e);if(ee)for(let e of A)t.delete(e.id);else for(let e of A)e.kind!==`pool`&&t.add(e.id);return t})},L=async(e,t)=>{if(N.length===0)return;w(!0);let n=await Promise.allSettled(N.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;w(!1),r===0?v.success(`${e} complete`,`${i} account${i===1?``:`s`}`):v.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},le=()=>L(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),ue=async()=>{let e=t.filter(e=>e.kind!==`pool`);e.length!==0&&(w(!0),E({done:0,total:e.length}),await on(e,3,async(e,n)=>{let r=await pe(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return E({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:R.quota.all}),o.invalidateQueries({queryKey:R.providers.all})]),w(!1),E(null),v.success(`Test complete`,`${e.length} account${e.length===1?``:`s`} tested`))},de=t=>L(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),fe=async()=>{if(N.length!==0){w(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:N.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Ue(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),v.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){v.error(`Export failed`,e.message??`Unable to export accounts`)}finally{w(!1)}}};return(0,Q.jsxs)(J,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative w-full`,children:[(0,Q.jsx)(oe,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,Q.jsx)(K,{id:`accounts-search`,value:h,onChange:e=>g(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Q.jsx)(_,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(p,{size:12}),disabled:C||t.length===0,onClick:ue,"aria-label":T===null?`Test all accounts`:`Testing accounts, ${T.done} of ${T.total} tested`,title:`Test every account, regardless of selection or filters`,children:T===null?`Test all`:`Tested ${T.done}/${T.total}`}),(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ae,{size:12}),disabled:C||I,title:I?`Select at least one account to recover it`:`Clear cooldowns and retry-wait states on the selected accounts`,onClick:()=>void le(),children:`Recover`}),(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(_t,{size:12}),disabled:C||!P,title:I?`Select at least one disabled account to enable it`:P?`Enable the selected accounts`:`No selected account is currently disabled`,onClick:()=>void de(!0),children:`Enable`}),(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(re,{size:12}),disabled:C||!F,title:I?`Select at least one enabled account to disable it`:F?`Disable the selected accounts`:`No selected account is currently enabled`,onClick:()=>void de(!1),children:`Disable`}),(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(d,{size:12}),disabled:C||I,title:I?`Select at least one account to export`:`Download the selected accounts as JSON`,onClick:()=>void fe(),children:`Export`}),(0,Q.jsx)(_,{size:`sm`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),disabled:C||I,title:I?`Select at least one account to delete`:`Delete ${N.length} selected account${N.length===1?``:`s`}`,onClick:()=>O(!0),children:`Delete`}),r?(0,Q.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(p,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null,(0,Q.jsx)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary [&_.radix-select-trigger]:font-semibold [&_.radix-select-trigger]:bg-hover [&_.radix-select-trigger]:text-text-primary`,children:(0,Q.jsx)(q,{size:`sm`,value:x,onValueChange:e=>S(e),options:er,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:ee,onChange:ie,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),I?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(new Set),className:`inline-flex h-15 shrink-0 items-center gap-1 rounded-control border border-inner-border px-3 text-badge font-semibold text-text-secondary hover:bg-hover`,title:`Clear selection`,children:[N.length,` selected`,(0,Q.jsx)(te,{size:11,"aria-hidden":`true`})]})]})]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:j.length===0?(0,Q.jsx)(M,{compact:!0,icon:(0,Q.jsx)(oe,{size:20}),title:`No matching accounts`,message:k?`Nothing matches “${k}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):j.map(t=>(0,Q.jsx)(wn,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:m.get(t.id),selected:y.has(t.id),onToggleSelect:ne,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,A.length,` account`,A.length===1?``:`s`,k?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(he,{open:D,onClose:()=>{C||O(!1)},onConfirm:async()=>{await L(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await pe(t,{method:`DELETE`}),o.removeQueries({queryKey:R.quota.account(e.id),exact:!0})}),b(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:R.providers.accounts(e)}),o.invalidateQueries({queryKey:R.providers.all}),o.invalidateQueries({queryKey:R.quota.all})])},title:`Delete ${N.length} account${N.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}function rr(e){let t=e.trim(),n=e=>{try{return new URL(e).searchParams}catch{return}},r=n(t)??new URLSearchParams(t.startsWith(`?`)?t.slice(1):t),i=r.get(`code`);if(i)return{code:i};let a=r.get(`error_description`)??r.get(`error`);return a?{error:`The provider refused the login: ${a}`}:r.has(`authCodeInfo`)||r.has(`refreshToken`)||r.has(`refresh_token`)?{code:r.toString()}:n(t)!==void 0||t.startsWith(`?`)?{error:`That redirect URL carries no authorization code — copy the full URL from the address bar.`}:{code:t}}function ir({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=Fe(),d=mt(),p=ce(),m=je(e),h=(0,Z.useRef)(null),y=(0,Z.useRef)(!1),[b,x]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{let t=setInterval(()=>{p.invalidateQueries({queryKey:R.providers.accounts(e)})},1500);return()=>clearInterval(t)},[p,e]),(0,Z.useEffect)(()=>{let t=!1;return p.invalidateQueries({queryKey:R.providers.accounts(e)}).finally(()=>{t||x(!1)}),()=>{t=!0}},[p,e]),(0,Z.useEffect)(()=>{if(b)return;let e=m.data?.map(e=>e.id)??null;if(e!==null){if(h.current===null){h.current=new Set(e);return}y.current||e.find(e=>!h.current.has(e))!==void 0&&(y.current=!0,r.close(),v.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[m.data,b,r,i]);let S=()=>{r.close(),i(!1)},[C,w]=(0,Z.useState)(!1),T=()=>{w(!0),p.invalidateQueries({queryKey:R.providers.accounts(e)}).finally(()=>w(!1))},E=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){v.error(`Clipboard is empty`);return}c(e),v.success(`Pasted redirect URL`)}catch{v.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(F,{open:!0,onClose:S,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:S,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:T,disabled:l.isPending||C,title:`You already approved in the popup — check now instead of waiting`,children:C?`Checking…`:`Complete`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=rr(s);if(`error`in t){v.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),v.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>v.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,Q.jsxs)(J,{gap:`14px`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(g,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),d(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,Q.jsx)(`span`,{children:`Or complete manually`}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-start`,children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>void E(),className:`shrink-0`,children:`Paste`})]})]})]})})}function ar(e){try{return new URL(e).host}catch{return e}}function or({providerId:e,parameters:t,onClose:n}){let r=Be(),i=z(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,d]=(0,Z.useState)(!1),p=mt();(0,Z.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(v.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let m=(0,Z.useRef)(null),[h,y]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?m.current=e:y(!0),()=>{let e=m.current;m.current=null,e&&!e.closed&&e.close()}},[a]),(0,Z.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),v.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=m.current;e&&!e.closed&&e.close(),v.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),v.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,Q.jsx)(F,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,Q.jsx)(J,{gap:`14px`,children:a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,Q.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(g,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),p(()=>d(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:ar(a.verificationUri)}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(ze,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(g,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),p(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:h?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function sr({providerId:e}){let[t,n]=(0,Z.useState)(!1),r=xe(e,t);return(0,Q.jsxs)(H,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-expanded":t,className:`card-header-bar w-full cursor-pointer list-none text-left`,children:[(0,Q.jsxs)(`div`,{className:`card-header-left`,children:[(0,Q.jsx)(`div`,{className:`card-header-icon`,children:(0,Q.jsx)(i,{size:16,"aria-hidden":`true`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`font-bold text-text-primary`,children:`Activity Matrix`}),(0,Q.jsxs)(`div`,{className:`text-caption text-text-secondary`,children:[`Daily token usage, last `,r.data?.days??30,` days · expand to load`]})]})]}),(0,Q.jsx)(`div`,{className:`card-header-right`,children:(0,Q.jsx)(Ee,{size:14,"aria-hidden":`true`,className:h(`transition-transform`,t&&`rotate-180`)})})]}),t?(0,Q.jsx)(yr,{matrix:r}):null]})}function cr(e){let t=new Map,n=new Map,r={requests:0,tokens:0,cachedTokens:0,costUsd:0};for(let i of e.rows){let e=t.get(i.day)??{tokens:0,models:new Map},a=i.inputTokens+i.outputTokens;e.tokens+=a;let o=i.model??`unknown`,s=e.models.get(o)??{tokens:0,requests:0};s.tokens+=a,s.requests+=i.requests,e.models.set(o,s),t.set(i.day,e);let c=n.get(o)??{tokens:0,requests:0};c.tokens+=a,c.requests+=i.requests,n.set(o,c),r.requests+=i.requests,r.tokens+=a,r.cachedTokens+=i.cachedInputTokens,r.costUsd+=i.costUsd}let i=Math.min(Math.max(e.days,1),366),a=new Date,o=Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate()),s=[],c=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],l=0;for(let e of t.values())l=Math.max(l,e.tokens);let u=new Date(o-(i-1)*864e5),d=(u.getUTCDay()+6)%7,f=u.getTime()-d*864e5,p=[];for(;;){if(f>o){if(p.length>0||s.length===0){for(;p.length<7;)p.push(null);s.push({cells:p})}break}let e=new Date(f),n=e.toISOString().slice(0,10),r=t.get(n),i=r?[...r.models.entries()].map(([e,t])=>({name:e,tokens:t.tokens,requests:t.requests,color:lr(e)})).sort((e,t)=>t.tokens-e.tokens):[],a=r?{day:n,label:`${c[(e.getUTCDay()+6)%7]} ${n.slice(5)}`,total:r.tokens,color:i[0]?.color??`var(--surface-2)`,models:i}:null;p.push(a),p.length===7&&(s.push({cells:p}),p=[]),f+=864e5}let m=[...n.entries()].map(([e,t])=>({name:e,tokens:t.tokens,requests:t.requests,color:lr(e)})).sort((e,t)=>t.tokens-e.tokens);return{weeks:s,maxDay:l,totals:r,models:m}}function lr(e){let t=5381;for(let n=0;n<e.length;n++)t=t*33^e.charCodeAt(n);let n=Math.abs(t)%360;return`hsl(${(n<60||n>110?n:n+130)%360} 65% 60%)`}function ur(e,t){if(e<=0||t<=0)return 0;let n=e/t,r=1;for(let e=1;e<dr.length;e++)n>e/(dr.length-1)&&(r=e);return Math.min(r,dr.length-1)}var dr=[0,.18,.38,.62,.9];function fr(e){return dr[Math.min(Math.max(Math.trunc(e),0),dr.length-1)]??0}function pr(e){let t=fr(e)*100;return t===0?`var(--surface-2)`:`color-mix(in srgb, var(--text-primary) ${t}%, transparent)`}function mr(e,t){if(t===0)return{backgroundColor:`var(--surface-2)`,borderColor:`var(--inner-border)`};let n=fr(t)*100;return{backgroundColor:`color-mix(in srgb, ${e.color} ${n}%, transparent)`,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}}function hr(e){return[`${e.label} — ${Ye(e.total)} tokens`,...e.models.map(t=>`• ${t.name}: ${Ye(t.tokens)} (${Math.round(t.tokens/e.total*100)}%) · ${t.requests} req`)].join(`
|
|
4
|
-
`)}var gr=`26px repeat(7, minmax(0, 1fr))`,_r=420,vr=360;function yr({matrix:e}){let t=(0,Z.useMemo)(()=>e.data?cr(e.data):void 0,[e.data]),n;return n=e.isPending?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`Loading activity…`}):e.isError?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-status-danger`,children:`Failed to load activity matrix.`}):!t||t.totals.requests===0?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`No usage recorded for this provider in the window.`}):(0,Q.jsx)(xr,{view:t}),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`border-t border-inner-border`,children:(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 p-4 max-small:p-3 min-[641px]:grid-cols-4`,children:[(0,Q.jsx)(br,{label:`Total tokens`,value:Ye(t?.totals.tokens)}),(0,Q.jsx)(br,{label:`Requests`,value:(t?.totals.requests??0).toLocaleString(`en-US`)}),(0,Q.jsx)(br,{label:`Cached`,value:Ye(t?.totals.cachedTokens)}),(0,Q.jsx)(br,{label:`Est. cost`,value:w(t?.totals.costUsd)})]})}),(0,Q.jsxs)(`div`,{className:`min-w-0 overflow-x-auto border-t border-inner-border p-4 max-small:p-3`,children:[n,t&&t.totals.requests>0?(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-1.5 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Less`}),[0,1,2,3,4].map(e=>(0,Q.jsx)(`span`,{className:`size-3 rounded-micro border border-inner-border`,style:{backgroundColor:pr(e)}},e)),(0,Q.jsx)(`span`,{children:`More`})]}):null,t&&t.totals.requests>0&&t.models.length>0?(0,Q.jsxs)(`details`,{className:`group mt-4 border-t border-inner-border pt-3`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 text-caption text-text-secondary [&::-webkit-details-marker]:hidden`,children:[(0,Q.jsxs)(`span`,{className:`font-semibold`,children:[`Usage by model (`,t.models.length,`) · sorted by tokens`]}),(0,Q.jsx)(Ee,{size:14,"aria-hidden":`true`,className:`shrink-0 transition-transform group-open:rotate-180`})]}),(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-2.5`,children:t.models.map(e=>{let n=t.totals.tokens>0?e.tokens/t.totals.tokens:0;return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 shrink truncate text-caption font-semibold`,style:{color:e.color},title:e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`h-2.5 min-w-0 flex-1 rounded-micro`,style:{backgroundColor:`var(--surface-2)`,backgroundImage:`linear-gradient(to right, ${e.color} ${Math.max(n*100,2)}%, transparent ${Math.max(n*100,2)}%)`}}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-caption text-text-secondary`,children:[Ye(e.tokens),` `,(0,Q.jsxs)(`span`,{className:`text-text-tertiary`,children:[Math.round(n*100),`%`]}),` ·`,` `,e.requests.toLocaleString(`en-US`),` req`]})]},e.name)})})]}):null]})]})}function br({label:e,value:t}){return(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:e}),(0,Q.jsx)(`div`,{className:`mt-0.5 font-mono text-lg font-bold text-text-primary`,children:t})]})}function xr({view:e}){return(0,Q.jsx)(`div`,{style:{minWidth:vr},children:(0,Q.jsxs)(`div`,{className:`grid gap-1`,style:{gridTemplateColumns:gr,maxWidth:_r},children:[(0,Q.jsx)(`div`,{}),[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`].map(e=>(0,Q.jsx)(`div`,{className:`text-center text-micro text-text-tertiary`,children:e},e)),e.weeks.map((t,n)=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center text-micro text-text-tertiary`,children:[`W`,n+1]}),t.cells.map((t,r)=>t===null?(0,Q.jsx)(`div`,{},`${n}-${r}`):(0,Q.jsx)(`div`,{className:`aspect-square cursor-pointer rounded-micro border border-inner-border transition-[outline-offset] hover:outline hover:outline-2 hover:outline-accent`,style:mr(t,ur(t.total,e.maxDay)),title:hr(t)},t.day))]},n))]})})}function Sr(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function Cr(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function wr({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,Q.jsx)(J,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,Q.jsx)(q,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,Q.jsx)(K,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function Tr({providerId:e,providerName:t,fields:n,onClose:r}){let i=B(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>Sr(n)),d=(0,Z.useMemo)(()=>Cr(n,l),[n,l]);return(0,Q.jsx)(F,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){v.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){v.error(`Missing required fields`,`Fill in: ${d.join(`, `)}`);return}i.mutate({providerId:e,credential:a.trim(),...Object.keys(l).length>0?{fields:l}:{},...s.trim().length>0?{accountLabel:s.trim()}:{}},{onSuccess:()=>{v.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>v.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(f,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,Q.jsx)(wr,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(K,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(K,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}function Er(e,t,n){let r=n?.trim()??``,i=r.indexOf(` — `),a=i>0?r.slice(0,i):``,o=i>0?r.slice(i+3):r;return{title:`${e}/${t} probe failed${a.length>0?` via ${a}`:``}`,detail:o.length>0?o:`Unknown error`}}function Dr(e,t,n){let{title:r,detail:i}=Er(e,t,n);return[r,i]}function Or(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function kr(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var Ar=[{key:`builtin`,label:`Built-in models`,hint:`Compiled catalog — can be disabled, not deleted`,matches:e=>e===null||e===`builtin`},{key:`auto_free`,label:`Free models (auto)`,hint:`Discovered from the provider's free tier`,matches:e=>e===`auto_free`},{key:`manual`,label:`Manually added`,hint:`Added by hand from the Add Model dialog`,matches:e=>e===`manual`},{key:`fetched`,label:`Fetched from provider`,hint:`Listed by the provider's /v1/models`,matches:e=>e!==null&&e!==`builtin`&&e!==`auto_free`&&e!==`manual`}],jr={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function Mr(){return wt.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function Nr({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,Q.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0`,children:(0,Q.jsx)(q,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:Mr()})})}function Pr({providerId:e,provider:t,onClose:n}){let r=Pe(),i=Ve(),[a,o]=(0,Z.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Z.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Z.useState)(c??`chat`),[m,h]=(0,Z.useState)(`auto`),[g,y]=(0,Z.useState)(`idle`),[b,x]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(Rr),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(y(`testing`),x(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:u,reasoningEffort:m,serviceKind:`llm`}},{onSuccess:e=>{e.ok?y(`passed`):(y(`failed`),x(e.error??`Model probe failed`))},onError:e=>{y(`failed`),x(e.message??`Model probe failed`)}}))};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=U(S.contextLimit),r=U(S.outputLimit);if(t===null||r===null){v.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:S.passthrough,image:S.passthrough?!0:S.image,reasoning:S.passthrough?!0:S.reasoning,toolCall:S.passthrough?!0:S.toolCall}},{onSuccess:()=>{v.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>v.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-end`,children:[(0,Q.jsx)(K,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),y(`idle`),x(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:g===`testing`?(0,Q.jsx)(f,{size:13,className:`animate-spin`}):(0,Q.jsx)(p,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:g===`testing`?`Testing...`:`Test`})]}),E&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,Q.jsx)(q,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),y(`idle`),x(``)},options:l.map(e=>({value:e,label:Wr(e)}))}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,Q.jsx)(Nr,{id:`add-model-thinking-effort`,value:m,onChange:e=>{h(e),y(`idle`),x(``)},disabled:r.isPending}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,Q.jsx)(zr,{draft:S,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:Wr(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),g===`passed`&&(0,Q.jsx)(X,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),g===`failed`&&(0,Q.jsx)(X,{tone:`danger`,live:`alert`,children:b||`Model test failed.`})]})})}function Fr(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var Ir=String(qe),Lr=String(We);function Rr(){return{...Fr(),contextLimit:Ir,outputLimit:Lr}}function zr({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(K,{label:`Context`,id:`${n}-context`,placeholder:Ir,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(K,{label:`Output`,id:`${n}-output`,placeholder:Lr,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===Ir&&e.outputLimit===Lr,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:Ir,outputLimit:Lr}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,Ge(qe),` ctx ·`,` `,Ge(We),` out`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,Q.jsx)(J,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function Br({providerId:e,model:t,onClose:n}){let r=ve(),[i,a]=(0,Z.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=U(i.contextLimit),o=U(i.outputLimit);if(a===null||o===null){v.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}r.mutate({providerId:e,modelId:t.modelId,route:t.route??``,metadata:{contextLimit:a??null,outputLimit:o??null,passthrough:i.passthrough,image:i.passthrough?!0:i.image,reasoning:i.passthrough?!0:i.reasoning,toolCall:i.passthrough?!0:i.toolCall}},{onSuccess:()=>n(),onError:e=>v.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,Q.jsx)(zr,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Vr({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let d=Pe(),h=ye(),[y,w]=(0,Z.useState)(!1),[E,O]=(0,Z.useState)(null),k=mt(),A=n===`llm`?Tt(t.modelId,i===`auto`?null:i):t.modelId,j=`${e}/${A}`,M=n===`websearch`?`Searching…`:`Thinking…`,N=()=>{d.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(O({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=Er(e,A,t.error);v.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;v.successRich(`${A} · END ${m(t.latencyMs)}`,(0,Q.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,Q.jsxs)(Y,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,Q.jsx)(T,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,Q.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
5
|
-
`)||`No sample text in the response.`)},onError:t=>{O({ok:!1,latencyMs:0}),v.error(...Dr(e,A,t.message))}})},ee=()=>{let n=!t.enabled;h.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>v.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>v.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,Q.jsx)(o,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,Q.jsx)(`div`,{title:j,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:A}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...Ur(t.wireFamily)},children:Wr(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:Or(t.source),className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-teal`,children:kr(t.source)}):null,t.proOnly===!0?(0,Q.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,Q.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,Q.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,Q.jsx)(_,{variant:`ghost`,size:`sm`,icon:y?(0,Q.jsx)(g,{size:12}):(0,Q.jsx)(u,{size:12}),"aria-label":`Copy ${j}`,title:`Copy ${j}`,onClick:()=>{navigator.clipboard?.writeText(j),w(!0),k(()=>w(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,Q.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,Q.jsx)(s,{size:12})}):null,t.vision?(0,Q.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,Q.jsx)(D,{size:12})}):null,t.toolCall?(0,Q.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,Q.jsx)(L,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(b,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:Ke,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,Q.jsx)(S,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${Ge(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Je,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${Ge(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Je,className:`cursor-help`,children:` · n/a out`})]}),c?(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,Q.jsx)(I,{size:11})}):null]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,disabled:d.isPending,onClick:N,"aria-label":`Test ${A}`,title:d.isPending?`Probing ${A}…`:E?.ok?`Last probe OK in ${m(E.latencyMs)} — click to re-test`:E?`Last probe failed — click to retry`:`Test ${A}`,className:`flex-1 justify-center`,icon:d.isPending?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):E?E.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(C,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(x,{size:12})}):(0,Q.jsx)(p,{size:12}),children:d.isPending?M:E?.ok?m(E.latencyMs):E?`Fail`:`Test`}),(0,Q.jsx)(_,{variant:`ghost`,size:`sm`,disabled:h.isPending,onClick:ee,icon:t.enabled?(0,Q.jsx)(re,{size:12}):(0,Q.jsx)(_t,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,Q.jsx)(_,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(se,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var Hr=(0,Z.memo)(Vr);function Ur(e){return e===`responses`?{color:`var(--purple)`,background:`var(--purple-soft)`}:e===`messages`?{color:`var(--orange)`,background:`color-mix(in srgb, var(--orange) 14%, transparent)`}:{color:`var(--teal)`,background:`var(--teal-soft)`}}function Wr(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function Gr({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=we(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),u=e=>e.enabled!==!1,d=Ar.map(e=>({...e,rows:t.filter(t=>u(t)&&e.matches(t.source))})).filter(e=>e.rows.length>0),f=t.filter(e=>!u(e)),p=t=>(0,Q.jsx)(Hr,{providerId:e,model:t,serviceKind:r,searchCapable:i,thinkingEffort:n,deletePending:a.isPending,onDeleteRequest:s,onEditRequest:t.source===`builtin`?void 0:l},`${t.modelId}::${t.route}`);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(J,{gap:`16px`,children:[d.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,Q.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:jr.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,Q.jsxs)(`span`,{title:jr.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,jr.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,Q.jsx)(he,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),v.success(`Model deleted`,`${e}/${o.modelId}`),s(null))},title:`Delete model?`,message:`Delete ${e}/${o?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),c===null?null:(0,Q.jsx)(Br,{providerId:e,model:c,onClose:()=>l(null)})]})}function Kr(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function qr(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function Jr(){let{providerId:e}=Me(),[t]=Ie(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=Oe(n),s=De(n),l=je(n),u=be(),f=be({silent:!0}),[p,m]=(0,Z.useState)(!1),h=Te(),g=_e(),y=ge(),x=ce(),[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),E=Pe(),[D,O]=(0,Z.useState)(``),[ee,te]=(0,Z.useState)(``),[P,I]=(0,Z.useState)(null),ae=e=>`cartethyia:provider:${e}:thinking-effort`,oe=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(ae(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return wt.includes(n)?n:`auto`},[L,le]=(0,Z.useState)(()=>oe(n));(0,Z.useEffect)(()=>{if(!n)return;let e=oe(n);e!==L&&le(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(ae(n),L)},[n,L]);let[ue,de]=(0,Z.useState)(!1),[fe,me]=(0,Z.useState)(!1),[ve,ye]=(0,Z.useState)(null),[xe,Se]=(0,Z.useState)({}),[Ce,we]=(0,Z.useState)({}),[z,Ee]=(0,Z.useState)(null),[ke,Ae]=(0,Z.useState)(!1),[Ne,Fe]=(0,Z.useState)(null),Le=(0,Z.useRef)(null),Re=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=Le.current;Le.current=null,e&&!e.closed&&e.close()},[]);let B=o.data,Be=n===`opencode`||n===`cline`,Ve=B===void 0?[`llm`]:qr(B),Ue=[];for(let e of Ve)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&Ue.push(e);(0,Z.useEffect)(()=>{if(B===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=Ue[0];if(e!==void 0&&Ue.includes(e)){i!==e&&a(e);return}!Ue.includes(i)&&t!==void 0&&a(t)},[B,r,i,Ue.join(`|`)]),(0,Z.useEffect)(()=>{Be&&B!==void 0&&B.supportsModelDiscovery!==!1&&Re.current!==n&&(Re.current=n,f.mutate(n))},[Be,f,n,B?.supportsModelDiscovery]);let U=l.data??[],We=s.data??[],Ge=(()=>{let e=new Map;for(let t of We){let n=`${t.serviceKind??`llm`}:${t.modelId}`,r=e.get(n);if(!r)e.set(n,t);else{let i=r.contextLimit??0;(t.contextLimit??0)>i&&e.set(n,t)}}return[...e.values()].sort((e,t)=>e.modelId.localeCompare(t.modelId))})(),Ke=Ge.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),qe=Ge.filter(e=>e.serviceKind===`websearch`),Je=Ge.filter(e=>e.serviceKind===`imageGeneration`),Ye=Ge.filter(e=>e.serviceKind===`videoGeneration`),W=Ue.includes(i)?i:Ue[0],G=ee||qe[0]?.modelId||``,K=()=>{let e=D.trim();G&&e&&(I(null),E.mutate({providerId:n,request:{modelId:G,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>I({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>I({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,Q.jsx)(j,{label:`Loading provider...`});if(o.isError)return(0,Q.jsx)(A,{title:`Unable to load providers`,message:`The provider details could not be read, so this page cannot resolve its endpoint settings.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,Q.jsx)(Et,{to:`/providers`,label:`Back to providers`})});if(!B)return(0,Q.jsx)(M,{icon:(0,Q.jsx)(vt,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,Q.jsx)(Et,{to:`/providers`,label:`Back to providers`})});let q=U.filter(e=>e.status===`active`).length,Qe=e=>{let t=e===`browser`?B?.oauthFlows?.browserLoginFields??[]:B?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?X():de(!0);return}Se(Sr(t)),ye(e)},$e=()=>{if(ve===null)return;let e=Cr(ve===`browser`?B?.oauthFlows?.browserLoginFields??[]:B?.oauthFlows?.deviceLoginFields??[],xe);if(e.length>0){v.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=ve;ye(null),t===`browser`?X(xe):(we(xe),de(!0))},X=e=>{let t=Le.current;t&&!t.closed&&t.close();let r=`cartethyia-oauth-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,i=window.open(`about:blank`,r,`popup,width=720,height=820`);i&&(i.opener=null,Le.current=i),y.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:t})=>{let n=null;if(i&&!i.closed?(i.location.href=e,n=i):(n=window.open(e,r,`popup,width=720,height=820`),n&&(n.opener=null,Le.current=n)),!n){v.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Fe({authorizeUrl:e,state:t,popup:n})},onError:e=>{i&&!i.closed&&i.close(),Le.current===i&&(Le.current=null),v.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(J,{gap:`16px`,children:[(0,Q.jsx)(Dt,{title:`${B.label||B.displayName}${W?` (${Kr(W)})`:``}`,description:`${B.providerId}/${B.baseUrl?` · ${B.baseUrl}`:``}`,icon:(0,Q.jsx)(Xe,{icon:B.providerId,name:B.label||B.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,Q.jsx)(Y,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:B.isBuiltIn?(0,Q.jsx)(_,{variant:B.enabled?`danger`:`secondary`,icon:B.enabled?(0,Q.jsx)(re,{size:13}):(0,Q.jsx)(_t,{size:13}),loading:g.isPending,onClick:()=>g.mutate({providerId:n,enabled:!B.enabled},{onSuccess:e=>v.success(e.enabled?`Provider enabled`:`Provider disabled`,B.label||B.displayName),onError:e=>v.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:B.enabled?`Disable provider globally`:`Enable provider globally`,children:B.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(rn,{provider:B}),B.isBuiltIn?null:(0,Q.jsx)(an,{provider:B}),W===`llm`?(0,Q.jsx)(Rt,{providerId:n,clientVersion:B.clientVersion,routeIdentityVersions:B.routeIdentityVersions,userAgentEditable:Ot(B)}):null,(0,Q.jsx)(sr,{providerId:n}),(0,Q.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:B.requiresAccount===!1&&U.length===0?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Accounts`,icon:(0,Q.jsx)(ht,{size:16})}),(0,Q.jsx)(V,{children:(0,Q.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Accounts`,subtitle:`${U.length} total · ${q} active · ${U.length-q} disabled`,icon:(0,Q.jsx)(ht,{size:16}),action:(0,Q.jsxs)(Ze,{children:[B.oauthFlows?.browser&&(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(ze,{size:13}),disabled:y.isPending,onClick:()=>Qe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:y.isPending?`Starting...`:`Login with browser`}),B.oauthFlows?.device&&(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(N,{size:13}),onClick:()=>Qe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),B.oauthFlows?.import&&(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(d,{size:13}),onClick:()=>me(!0),title:B.oauthFlows.browser||B.oauthFlows.device||B.oauthFlows.refreshable?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:B.oauthFlows.browser||B.oauthFlows.device||B.oauthFlows.refreshable?`Import credential`:`Add API key`}),B.requiresAccount?(0,Q.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(ne,{size:13}),onClick:()=>C(!0),children:`Add Account`}):null]})}),(0,Q.jsxs)(V,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)($t,{providerId:n}),l.isPending?(0,Q.jsx)(j,{label:`Loading accounts...`}):l.isError?(0,Q.jsx)(A,{message:`Failed to load accounts`,onRetry:()=>l.refetch()}):U.length===0?(0,Q.jsx)(M,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,Q.jsx)(nr,{providerId:n,accounts:U,onDelete:e=>Ee(e),showGrokProbe:W===`llm`&&n===`grok`,grokProbePending:h.isPending,onGrokProbe:()=>{h.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`reply my message with exact number 407`,stream:!0,serviceKind:`llm`}},{onSuccess:e=>{let t=e.results.filter(e=>e.ok).length,n=e.results.filter(e=>e.statusCode===202).length,r=e.results.length-t-n;v.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>v.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),W===`llm`?(0,Q.jsxs)(Q.Fragment,{children:[n===`inferhub`?(0,Q.jsx)(Xt,{}):null,(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Models`,subtitle:`${Ke.length} model${Ke.length===1?``:`s`} registered`,icon:(0,Q.jsx)(c,{size:16}),action:(0,Q.jsxs)(Y,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,Q.jsx)(Nr,{id:`models-section-thinking-effort`,value:L,onChange:le}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(ie,{size:13,className:u.isPending||f.isPending?`animate-spin`:``}),disabled:u.isPending||f.isPending,onClick:()=>u.mutate(n),children:u.isPending||f.isPending?`Fetching...`:`Fetch models`}),(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(se,{size:13,className:p?`animate-spin`:``}),disabled:u.isPending||f.isPending||p||Ke.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=Ke.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){m(!0);try{let t=await pe(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([x.invalidateQueries({queryKey:R.providers.models(n)}),x.invalidateQueries({queryKey:R.providers.all})]);let r=t.failures.length;v.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){v.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{m(!1)}}},children:p?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(ne,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,Q.jsx)(V,{className:`flex flex-col gap-8`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load models`,onRetry:()=>s.refetch()}):Ke.length===0?(0,Q.jsx)(M,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,Q.jsx)(Gr,{providerId:n,models:Ke,serviceKind:`llm`,thinkingEffort:L,searchCapable:B?.supportsWebSearch===!0})})]})]}):W===`websearch`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(b,{size:16})}),(0,Q.jsx)(V,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading search models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):qe.length===0?(0,Q.jsx)(M,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,Q.jsx)(`select`,{value:G,onChange:e=>{te(e.target.value),I(null)},className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`,children:qe.map(e=>(0,Q.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,Q.jsx)(`input`,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),K())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,Q.jsx)(_,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:K,children:`Test search`}),P?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:P.ok?`var(--green)`:`var(--red)`},children:P.ok?`Search ok · ${P.latencyMs}ms · ${P.count??0} result(s)`:P.error??`Search failed.`}):null]}),P&&P.results&&P.results.length>0?(0,Q.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:P.results.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,Q.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,Q.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):W===`imageGeneration`||W===`videoGeneration`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(He,{title:Kr(W),subtitle:W===`imageGeneration`?`Models that return an image rather than text.`:`Models that return a video. Wired and routable; not yet verified against a live account.`,icon:W===`imageGeneration`?(0,Q.jsx)(k,{size:16}):(0,Q.jsx)(St,{size:16})}),(0,Q.jsx)(V,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading ${Kr(W).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load ${Kr(W).toLowerCase()} models`,onRetry:()=>s.refetch()}):(W===`imageGeneration`?Je:Ye).length===0?(0,Q.jsx)(M,{title:`No ${Kr(W)} models found`,message:`This provider advertises ${Kr(W)}, but no ${W} model is registered yet.`}):(0,Q.jsx)(Gr,{providerId:n,models:W===`imageGeneration`?Je:Ye,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,Q.jsx)(H,{children:(0,Q.jsx)(V,{children:(0,Q.jsx)(M,{title:`Service not available`,message:`This provider advertises ${Ve.map(Kr).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),S&&(0,Q.jsx)(Qn,{providerId:n,accounts:U,onClose:()=>C(!1)}),W===`llm`&&w?(0,Q.jsx)(Pr,{providerId:n,provider:B,onClose:()=>T(!1)}):null,(0,Q.jsx)(he,{open:z!==null,onClose:()=>{ke||Ee(null)},onConfirm:async()=>{if(z){Ae(!0);try{let e=z.tenantId===null?`/global/accounts/${encodeURIComponent(z.id)}`:`/accounts/${encodeURIComponent(z.id)}`;await pe(e,{method:`DELETE`}),x.removeQueries({queryKey:R.quota.account(z.id),exact:!0}),await Promise.all([x.invalidateQueries({queryKey:R.providers.accounts(n)}),x.invalidateQueries({queryKey:R.providers.healthEvents(n,z.id)}),x.invalidateQueries({queryKey:R.providers.all}),x.invalidateQueries({queryKey:R.quota.all})]),v.success(`Account deleted`,z.label||z.id.slice(0,8)),Ee(null)}catch(e){throw v.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Ae(!1)}}},title:`Delete account?`,message:`Delete "${z?.label||z?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),ue&&(0,Q.jsx)(or,{providerId:n,parameters:Ce,onClose:()=>{de(!1),we({})}}),ve!==null&&(0,Q.jsx)(F,{open:!0,onClose:()=>ye(null),title:ve===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>ye(null),children:`Cancel`}),(0,Q.jsx)(_,{variant:`primary`,size:`sm`,onClick:$e,children:`Continue`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:ve===`browser`?`Choose how ${B.label||B.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(wr,{fields:ve===`browser`?B?.oauthFlows?.browserLoginFields??[]:B?.oauthFlows?.deviceLoginFields??[],values:xe,idPrefix:`flow-${ve}`,onChange:(e,t)=>Se(n=>({...n,[e]:t}))})]})}),fe&&B?.oauthFlows?.import===!0&&(0,Q.jsx)(Tr,{providerId:n,providerName:B.label||B.displayName,fields:B.oauthFlows.importFields,onClose:()=>me(!1)}),Ne&&(0,Q.jsx)(ir,{providerId:n,authorizeUrl:Ne.authorizeUrl,state:Ne.state,popup:Ne.popup,onClose:e=>{Le.current=null,Fe(null),e&&x.invalidateQueries({queryKey:R.providers.accounts(n)})}})]})}export{Jr as default};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";var r=e(t(),1),i=n(),a=new Set,o={claude:{file:`claude-code`,ext:`svg`},anthropic:{file:`anthropics`,ext:`webp`},openai:{file:`openai-light`,ext:`svg`},codex:{file:`codex`,ext:`webp`},opencode:{file:`opencode`,ext:`webp`},"opencode-zen":{file:`opencode`,ext:`webp`},"opencode-go":{file:`opencode-go`,ext:`webp`},"google-antigravity":{file:`antigravity`,ext:`svg`},antigravity:{file:`antigravity`,ext:`svg`},blackbox:{file:`blackbox`,ext:`svg`},blackboxai:{file:`blackbox`,ext:`svg`},grok:{file:`grok-build`,ext:`webp`},"grok-build":{file:`grok-build`,ext:`webp`},xai:{file:`grok-build`,ext:`webp`},inferhub:{file:`inferhub`,ext:`svg`},gemini:{file:`gemini`,ext:`webp`},alibaba:{file:`alibaba`,ext:`svg`},alibabacp:{file:`alibaba`,ext:`svg`},dashscope:{file:`alibaba`,ext:`svg`},fireworks:{file:`fireworks`,ext:`webp`},exa:{file:`exa`,ext:`svg`},perplexity:{file:`perplexity`,ext:`webp`},tokenharbor:{file:`tokenharbor`,ext:`svg`},aihubmix:{file:`aihubmix`,ext:`svg`},zcode:{file:`zai-coding-plan`,ext:`svg`},"kimi-code":{file:`kimi-code`,ext:`webp`},kimi:{file:`kimi-code`,ext:`webp`},github:{file:`github`,ext:`webp`},copilot:{file:`copilot`,ext:`webp`},xiaomipg:{file:`mimo`,ext:`webp`},xiaomitp:{file:`mimo`,ext:`webp`},mimo:{file:`mimo`,ext:`webp`},cb:{file:`codebuddy`,ext:`webp`},cbcn:{file:`codebuddy`,ext:`webp`},workbuddy:{file:`codebuddy`,ext:`webp`},workbuddycn:{file:`codebuddy`,ext:`webp`},agentrouter:{file:`agentrouter`,ext:`svg`},parallel:{file:`parallel`,ext:`svg`},gmi:{file:`gmi-cloud`,ext:`svg`},hermes:{file:`hermes`,ext:`webp`},nous:{file:`nous-research`,ext:`svg`},inception:{file:`inception`,ext:`svg`},bai:{file:`bai`,ext:`svg`},cline:{file:`cline`,ext:`webp`},cerebras:{file:`cerebras`,ext:`webp`},qoder:{file:`qoder`,ext:`webp`},qodercn:{file:`qoder`,ext:`webp`},mistral:{file:`mistral`,ext:`webp`},muse:{file:`muse`,ext:`svg`},meta:{file:`muse`,ext:`svg`},openrouter:{file:`openrouter`,ext:`webp`},ollama:{file:`ollama`,ext:`webp`},ollamacloud:{file:`ollama-cloud`,ext:`webp`},nvidia:{file:`nvidia`,ext:`webp`},deepseek:{file:`deepseek`,ext:`webp`},"deepseek-tui":{file:`deepseek-tui`,ext:`webp`},droid:{file:`droid`,ext:`webp`},jcode:{file:`jcode`,ext:`webp`},kilo:{file:`kilocode`,ext:`webp`},"kilo-gateway":{file:`kilocode-gateway`,ext:`webp`},openclaw:{file:`openclaw`,ext:`webp`},cowork:{file:`claude`,ext:`webp`},roo:{file:`roo`,ext:`webp`},continue:{file:`continue`,ext:`webp`},amp:{file:`amp`,ext:`webp`},qwen:{file:`qwen`,ext:`webp`},kiro:{file:`kiro`,ext:`webp`},kimchi:{file:`kimchi`,ext:`webp`},commandcode:{file:`commandcode`,ext:`webp`},cursor:{file:`cursor`,ext:`webp`},trae:{file:`trae`,ext:`webp`},traecn:{file:`trae`,ext:`webp`}};function s(e){let t=e.toLowerCase().trim();return o[t]??{file:t,ext:`webp`}}function c(e){let t=e.trim().split(/[\s-]+/).filter(Boolean);return t.length>=2?(t[0][0]+t[1][0]).toUpperCase():e.slice(0,2).toUpperCase()}var l=(0,r.memo)(function({icon:e,name:t,size:n=32,imageSize:o,style:l,className:u}){let[d,f]=(0,r.useState)(()=>a.has(e)),p=s(e),m=o??n;return(0,i.jsx)(`div`,{className:u,style:{width:`${n}px`,height:`${n}px`,borderRadius:`8px`,background:`var(--surface-2)`,display:`grid`,placeItems:`center`,flexShrink:0,overflow:`hidden`,border:`1px solid var(--inner-border)`,...l},role:`img`,"aria-label":`${t} provider`,children:d?(0,i.jsx)(`span`,{style:{fontSize:`${Math.max(10,Math.floor(n*.35))}px`,fontWeight:700,color:`var(--text-secondary)`},children:c(t)}):(0,i.jsx)(`img`,{src:`/assets/providers/${p.file}.${p.ext}`,alt:``,width:m,height:m,loading:`lazy`,decoding:`async`,style:{width:`${m}px`,height:`${m}px`,objectFit:`contain`,padding:p.ext===`svg`?`1px`:`2px`},onError:()=>{a.add(e),f(!0)}})})});export{l as t};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{h as r,l as i}from"./numbers-CEagj6ZZ.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-CkfdYWel.js";import{t as u}from"./dialog-8fiE6tec.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-BloKtaXJ.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{E as ee,T as h,a as g,et as _,ft as v,g as y,i as b,m as x,ot as S,rt as C,s as w,v as T}from"./entry-CiIQULZD.js";import{n as E,r as D,t as O}from"./card-ibRWU_uT.js";import{t as k}from"./switch-SYm237HG.js";import{t as A}from"./badge-D9CS6dZk.js";import{n as j}from"./input-Da2ZViWg.js";import{t as M}from"./select-BIYIBkMU.js";import{t as N}from"./ProviderIcon-FB6yS4v1.js";import{t as P}from"./stack-DfgnFDWY.js";import{n as F}from"./inline-BT0zntEr.js";import{t as te}from"./list-row-BycOrrIV.js";import{t as I}from"./privacy-mode-GM8bej85.js";import{t as L}from"./AccountCooldown-Bjo92Qat.js";var R=e(t(),1),z=n();function ne(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(j,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(j,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(f,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(d,{size:13}),` Add header`]})]})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var V=r(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),H=r(`block flex-1 p-6 no-underline text-inherit`),U=r(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function W(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var G=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ie(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return G.test(r)?n.origin:null}function K({variant:e,open:t,onClose:n}){let a=b(),o=g(),s=h(),c=ee(),[l,d]=(0,R.useState)(``),[f,m]=(0,R.useState)(``),[_,v]=(0,R.useState)(``),[y,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),[w,T]=(0,R.useState)(!0),[E,D]=(0,R.useState)([]),[O,A]=(0,R.useState)(null),[N,P]=(0,R.useState)(!1),[I,L]=(0,R.useState)(null),[B,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>ie(_),[_]);(0,R.useEffect)(()=>{t&&(d(``),x(``),G(U),v(``),C(!1),T(!0),D([]),A(null),L(null))},[t]);let q=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{A(`Clipboard access denied — paste manually instead.`)}},ae=async()=>{if(!_.trim()){L({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),L(null),A(null);try{let e=ne(E),t=await c.mutateAsync({baseUrl:_.trim(),apiKey:y.trim(),wireFamily:W,cliIdentity:w,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;L({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else L({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){L({ok:!1,message:p(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(u,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:N,children:N?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){A(`Display Name is required`);return}if(!f.trim()){A(`Provider ID (slug) is required`);return}if(!_.trim()){A(`Base URL is required`);return}let t=ne(E),r=f.trim().toLowerCase();P(!0),A(null);try{let e={providerId:r,label:l.trim(),baseUrl:_.trim(),wireFamily:W,compatibilityProfile:{cli_identity:w,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:y.trim()}}),S&&await s.mutateAsync(r),n()}catch(e){A(p(e,`Failed to create provider`))}finally{P(!1)}},className:`flex flex-col gap-6`,children:[O?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:O}):null,(0,z.jsx)(j,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(j,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:H?`ac-prod`:`oc-prod`,required:!0}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,z.jsx)(`span`,{children:`Base URL`}),(0,z.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,H?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,z.jsxs)(F,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(j,{id:`compat-url`,value:_,onChange:e=>v(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(v),children:`Paste`})]}),K===null?null:(0,z.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,z.jsx)(`code`,{className:`font-mono`,children:K}),` instead — Cartethyia appends the endpoint path itself.`]})]}),H?null:(0,z.jsx)(M,{id:`compat-wire`,label:`API format`,value:W,onValueChange:e=>G(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,z.jsx)(`span`,{children:`API Key`}),(0,z.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,z.jsxs)(F,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(j,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>x(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:B,onClick:()=>void ae(),children:B?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(x),children:`Paste`})]}),I?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:r(`mt-3 text-caption leading-[1.4] break-words`,I.ok?`text-green`:`text-red`),children:[I.ok?`✓ `:`✗ `,I.message]}),I.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,I.warning]}):null]}):null]}),(0,z.jsx)(te,{actions:(0,z.jsx)(k,{checked:S,onChange:C,id:`compat-autofetch`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,z.jsx)(te,{actions:(0,z.jsx)(k,{checked:w,onChange:T,id:`compat-cli-identity`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:H?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:H?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,z.jsx)(re,{pairs:E,onChange:D})]})})}function q({customProvider:e}){let t=w(),[n,a]=(0,R.useState)(!1),o=y(e.providerId),s=o.data?.length,c=x(e.providerId),l=c.data,d=Q(l??[]);return(0,z.jsxs)(O,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(_,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:r(H,`pr-20 min-h-38`),children:(0,z.jsxs)(F,{gap:`10px`,children:[(0,z.jsx)(N,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,z.jsx)(A,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(A,{children:`No connections`}):(0,z.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,z.jsx)(A,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,z.jsxs)(A,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,z.jsx)(A,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,z.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(P,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,z.jsxs)(m,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(v,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(F,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(o,{size:13}):(0,z.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(O,{children:(0,z.jsxs)(E,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,z.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,z.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,z.jsx)(B,{children:e.map(e=>(0,z.jsx)(q,{customProvider:e},e.providerId))}),(0,z.jsx)(K,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(K,{variant:`openai-compatible`,open:r,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`,`inception`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||L(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&L(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,z.jsxs)(z.Fragment,{children:[e.healthy>0?(0,z.jsxs)(A,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(A,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(A,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(A,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(A,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),i=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=x(e.providerId),c=s.data,l=Q(c??[]);return(0,z.jsxs)(O,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:r(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(_,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:H,children:(0,z.jsxs)(F,{gap:`10px`,children:[(0,z.jsx)(N,{icon:e.providerId,name:i,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:i}),(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,z.jsx)(A,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(A,{children:`No connections`}):(0,z.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,z.jsx)(A,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,z.jsxs)(A,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,z.jsx)(A,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,z.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=`text-body font-bold tracking-[-0.01em]`,me=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function he(){let[e,t]=(0,R.useState)(fe),n=T(),u=I(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,R.useMemo)(()=>n.data??[],[n.data]),ee=(0,R.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),h=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`websearch`)&&f(e)),[m,d]),g=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`llm`)&&f(e)),[m,d]),[_,y]=C(),b=_.get(`tab`),x=b===`search`||b===`media`?b:`llm`,w=e=>{y(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},k=(0,R.useMemo)(()=>m.filter(e=>(W(e).includes(`imageGeneration`)||W(e).includes(`videoGeneration`))&&f(e)),[m,d]),A=(0,R.useMemo)(()=>[...h].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[h]),j=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},M=(0,R.useMemo)(()=>{if(x===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:k}].filter(e=>e.providers.length>0);if(x===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:A}].filter(e=>e.providers.length>0);let e=g;return me.map(t=>({...t,providers:e.filter(t.filter).sort(j)})).filter(e=>e.providers.length>0)},[g,A,k,x]),N=n.isPending&&!n.data?(0,z.jsx)(c,{label:`Loading providers...`}):n.isError?(0,z.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return N?(0,z.jsxs)(O,{children:[(0,z.jsx)(D,{title:`Providers`,icon:(0,z.jsx)(S,{size:16})}),(0,z.jsx)(E,{className:`flex flex-1`,children:N})]}):(0,z.jsx)(P,{gap:`24px`,children:(0,z.jsxs)(O,{children:[(0,z.jsx)(D,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(S,{size:16})}),(0,z.jsxs)(E,{className:`flex flex-col gap-8`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,z.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,z.jsxs)(`button`,{onClick:()=>w(e),className:r(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,x===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${h.length})`:e===`media`?` (${k.length})`:` (${g.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(a,{size:12}):(0,z.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:x===`search`?`Fallback runs only when the model invokes Websearch`:x===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),x===`llm`?(0,z.jsx)(ae,{customProviders:ee}):null,M.length===0?(0,z.jsx)(O,{children:(0,z.jsx)(E,{children:(0,z.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):M.map(n=>{let i=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!i,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(v,{size:15,className:r(`mt-1 shrink-0 transition-transform`,i&&`-rotate-90`)}),(0,z.jsxs)(P,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:pe,children:[n.title,` (`,n.providers.length,`)`,i?` (Hidden)`:``]}),!i&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),i?null:(0,z.jsx)(B,{children:n.providers.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:x===`search`?`websearch`:x===`media`?W(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{he as default,Q as summarizeAccounts};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{S as a,k as o,l as s,s as c,y as l}from"./numbers-CEagj6ZZ.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-CkfdYWel.js";import{t as h}from"./dialog-8fiE6tec.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as v}from"./trash-Cppn5c3R.js";import{t as y}from"./zap-C4EeVW4q.js";import{l as b}from"./query-keys-BloKtaXJ.js";import{B as x}from"./entry-CiIQULZD.js";import{n as S,t as te}from"./card-ibRWU_uT.js";import{t as C}from"./switch-SYm237HG.js";import{t as w}from"./badge-D9CS6dZk.js";import{t as T}from"./select-BIYIBkMU.js";import{t as E}from"./ProviderIcon-FB6yS4v1.js";import{t as D}from"./stack-DfgnFDWY.js";import{n as O}from"./inline-BT0zntEr.js";import{t as k}from"./layout-BXNeLw6M.js";import{a as A,i as j,n as M,o as N,r as P,s as F,t as I}from"./quota-Caw7wqci.js";import{a as ne,c as L,d as R,f as z,i as B,l as re,n as V,o as H,p as U,r as W,s as G,t as K,u as q}from"./HealthEventsModal-DzSWzE_j.js";var J=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),Y=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=B(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,o=e=>e?new Date(e).toLocaleString():`—`,l=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(w,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(k,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=l(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(w,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[o(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(s,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?c.success(e.message??`Rate limit reset applied`):c.error(e.message??`Rate limit reset failed`)},onError:e=>{c.error(b(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(O,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(s,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!V(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,o=z(i),l=i.length===0||o.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(T,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(s,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:l,className:`shrink-0`,icon:o.isPending?(0,Z.jsx)(a,{size:13,className:`animate-spin`}):(0,Z.jsx)(J,{size:13}),onClick:()=>o.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?c.success(e.message):c.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>c.error(b(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:o}){let u=G(e.id),d=R(e.id),f=V(e.provider),p=W(e.provider),m=B(e.id,p),h=e.quota,[g,x]=(0,X.useState)(0),S=h?.windows??[],w=N(S,g),T=w.pageCount;(0,X.useEffect)(()=>{x(e=>Math.min(e,Math.max(0,T-1)))},[T]);let D=u.isPending||d.isPending,O=m.data?.availableCount??0,[k,ne]=(0,X.useState)(null),[L,z]=(0,X.useState)(!1),re=e.checkin?.attemptedToday??!1,H=`${k?k.state===`claimed`?`Checked in${k.credit===null?``:` +${k.credit}`}${k.streakDays===null?``:` · ${k.streakDays}d streak`}`:k.state===`already_claimed`?`Check-in attempted · already claimed`:k.state===`not_eligible`?`Check-in attempted · not eligible`:k.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:re?`Check-in attempted today`:`Check-in due`}${L?` · Reported today`:``}`,U=S.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),K=(u.error?b(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=A(K),Y=q===`Quota tracking is not supported for this provider`?null:q,Q=I(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(te,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":D,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(E,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:M(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:O>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[O,` rate-limit reset`,O===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:H}),S.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,U.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(s,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:O>0?`Saved rate-limit resets (${O} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:D,onClick:()=>o(e),children:(0,Z.jsx)(y,{size:14})}),f&&(0,Z.jsx)(s,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${H}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:D,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&ne({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&z(!0),e.ok?c.success(e.message):c.error(e.message)},onError:e=>{c.error(b(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(a,{size:14,className:`animate-spin`}):(0,Z.jsx)(J,{size:14})}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:D,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:D,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(a,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(v,{size:12})}),(0,Z.jsx)(C,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),Y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(l,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:Y})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),w.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=F(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=P(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:j(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),w.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,w.startIndex+1,`–`,w.startIndex+w.items.length,` of `,S.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:w.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>x(w.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:w.page>=w.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>x(w.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):Y?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:D||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,a]=(0,X.useState)(!1),{data:l,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:v}=H(),y=(0,X.useMemo)(()=>[...l?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[l?.providers]),b=(0,X.useMemo)(()=>l?.accounts??[],[l?.accounts]),C=l?.refreshing??0,w=L(),[E,O]=(0,X.useState)(null),k=U(),A=re(),j=ne(),[M,N]=(0,X.useState)(null);(0,X.useEffect)(()=>{w.isPending||O(null)},[w.isPending]);let[P,F]=(0,X.useState)(null),[I,R]=(0,X.useState)(null),z=(0,X.useMemo)(()=>{let t=b.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,b,i,e]),B=async(e,t)=>{try{await k.mutateAsync({id:e.id,active:t}),c.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){c.error(e instanceof Error?e.message:`Unable to update account`)}},V=async()=>{let e=b.filter(e=>e.active&&Q(e));await A.mutateAsync({ids:e.map(e=>e.id),active:!1}),c.success(`Disabled ${e.length} empty accounts`)},W=async()=>{let e=b.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await A.mutateAsync({ids:e.map(e=>e.id),active:!0}),c.success(`Enabled ${e.length} available accounts`)},G=async e=>{await j.mutateAsync(e.id),c.success(`${e.name} deleted`)},q=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,J=b.filter(Q).length;return(0,Z.jsxs)(D,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(te,{children:(0,Z.jsxs)(S,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(T,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...y.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(T,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(s,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>a(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(Y,{size:13}),children:`Expiring first`}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:J===0||h,onClick:()=>void V(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(s,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void W(),icon:(0,Z.jsx)(o,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[z.length,` shown`,J>0?` · ${J} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${q}`,(0,Z.jsx)(oe,{accounts:b}),(0,Z.jsx)(s,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||w.isPending||b.length===0,icon:(0,Z.jsx)(g,{size:13,className:w.isPending?`animate-spin`:void 0}),onClick:()=>w.mutate({accountIds:b.map(e=>e.id),onProgress:(e,t)=>O({done:e,total:t})},{onSuccess:e=>{c.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>c.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:E&&E.total>0?`Refresh ${E.done}/${E.total}`:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(s,{variant:`secondary`,onClick:()=>void v(),children:`Retry`})}):z.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:z.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void B(e,t),onDelete:e=>N(e),onShowHealth:e=>F(e),onShowResets:e=>R(e)},e.id))})}),P&&(0,Z.jsx)(K,{summary:{providerId:P.provider,accountId:P.id,title:P.name,status:P.health?.status??`unknown`,errorCategory:P.health?.lastErrorCategory??void 0,errorMessage:P.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>F(null)}),I&&(0,Z.jsx)(ae,{account:I,onClose:()=>R(null)}),(0,Z.jsx)(x,{open:M!==null,onClose:()=>N(null),onConfirm:async()=>{M&&await G(M)},title:`Delete account?`,message:`Delete "${M?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i,r as a}from"./terminal-0_IjPWTk.js";import{E as o,i as s,l as c,s as l,t as u}from"./numbers-CEagj6ZZ.js";import{t as d}from"./database-Dz9N3zGd.js";import{t as f}from"./eye-C_hawfH4.js";import{n as p,r as m}from"./state-CkfdYWel.js";import{t as h}from"./layers-2-glBbjl.js";import{t as g}from"./dialog-8fiE6tec.js";import{n as _,r as ee,t as v}from"./settings-jS3-PNSA.js";import{t as y}from"./trash-Cppn5c3R.js";import{t as b}from"./zap-C4EeVW4q.js";import{E as x,v as S,w as te}from"./assert-DbRA8EG2.js";import{a as C,i as w,l as T,o as E,s as D,t as O}from"./query-keys-BloKtaXJ.js";import{t as k}from"./useMutation-BQqCRNIi.js";import{ot as A}from"./entry-CiIQULZD.js";import{n as j,r as M,t as N}from"./card-ibRWU_uT.js";import{n as ne,t as re}from"./download-dRFo5_Wu.js";import{t as ie}from"./switch-SYm237HG.js";import{n as P}from"./input-Da2ZViWg.js";import{t as F}from"./select-BIYIBkMU.js";import{t as I}from"./stack-DfgnFDWY.js";import{t as L}from"./banner-DympBNq4.js";import{t as ae}from"./backup-file-gdKIlg8U.js";var R=e(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),oe=e(`file-braces`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),se=e(`file-clock`,[[`path`,{d:`M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85`,key:`ryk6xj`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 14v2.2l1.6 1`,key:`6m4bie`}],[`circle`,{cx:`8`,cy:`16`,r:`6`,key:`10v15b`}]]),ce=e(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),z=e(`hard-drive`,[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]),le=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),B=t(n(),1);function ue(){return k({mutationFn:async({password:e,sections:t,compressed:n,onProgress:r})=>{let i=new URLSearchParams({password:e});t!==void 0&&t.length>0&&i.set(`sections`,t),n===!0&&i.set(`compressed`,`1`);let a=`/backup/export?${i.toString()}`;if(n!==!0)return E(a);let o=await E(a),s=atob(o.bytes),c=Uint8Array.from(s,e=>e.charCodeAt(0));return r?.({loaded:c.byteLength,total:c.byteLength}),c}})}function de(){let e=x();return k({mutationFn:({password:e,scopes:t})=>E(`/backup/delete-all`,{method:`POST`,body:JSON.stringify({password:e,scopes:t})}),onSuccess:async()=>{await e.invalidateQueries()}})}function fe(){let e=x();return k({mutationFn:({password:e,backup:t,tables:n,onProgress:r})=>D(`/backup/import`,JSON.stringify({password:e,backup:t,...n===void 0||n.length===0?{}:{tables:[...n]}}),r),onSuccess:async()=>{await e.invalidateQueries()}})}function pe(){return k({mutationFn:({backup:e})=>E(`/backup/inspect`,{method:`POST`,body:JSON.stringify({backup:e})})})}var V=r();function me({title:e,description:t}){return(0,V.jsxs)(`div`,{className:`mb-6 min-w-0`,children:[(0,V.jsx)(`h3`,{className:`text-body-lg font-bold text-text-primary`,children:e}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-secondary`,children:t})]})}function H({icon:e,label:t,description:n,checked:r,onChange:i}){return(0,V.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:r,onChange:i}),(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{children:t}),(0,V.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:n})]})]})}function he(e){return e===`providers`?A:e===`proxies`?a:h}function ge({report:e}){let t=Object.entries(e.imported).filter(([,e])=>e>0);return(0,V.jsxs)(I,{gap:`8px`,children:[t.length>0?(0,V.jsxs)(`p`,{className:`text-caption`,children:[`Imported:`,` `,t.map(([e,t])=>`${t} ${e}`).join(`, `)]}):null,e.remapped.length>0?(0,V.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[`Remapped provider ids: `,e.remapped.join(`, `)]}):null,e.skipped.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`p`,{className:`text-caption text-yellow`,children:[`Skipped (`,e.skipped.length,`) — nothing was guessed:`]}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.skipped.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null,e.warnings.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`Warnings:`}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.warnings.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null]})}function _e({warnings:e}){return e.length===0?null:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsxs)(`strong`,{children:[`Restore completed with `,e.length,` warning`,e.length===1?``:`s`]}),(0,V.jsx)(`ul`,{className:`mt-2 ml-8`,children:e.map((e,t)=>(0,V.jsxs)(`li`,{children:[e.table?`${e.table}${e.column?`.${e.column}`:``}: `:``,e.reason]},`${e.table??`backup`}:${e.column??`general`}:${t}`))})]})}function U(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ve(e,t){if(e===null)return t;let n=Math.max((Date.now()-e.startedAt)/1e3,.1),r=U(e.loaded/n);return`${e.total===null?U(e.loaded):`${U(e.loaded)} / ${U(e.total)}`} · ${r}/s`}function W(){let[e,t]=(0,B.useState)(``),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(!0),[s,u]=(0,B.useState)(!1),[f,p]=(0,B.useState)(!0),[m,h]=(0,B.useState)(null),[_,ee]=(0,B.useState)(null),[v,b]=(0,B.useState)(null),[x,S]=(0,B.useState)(null),[te,C]=(0,B.useState)(null),[w,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(new Set),[k,A]=(0,B.useState)(null),[j,M]=(0,B.useState)(null),[N,F]=(0,B.useState)(new Set),[R,oe]=(0,B.useState)(null),ce=(0,B.useRef)(null),z=ue(),U=fe(),W=de(),ye=pe(),be=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},G=()=>{r(null),t(``)},xe=()=>{D.size!==0&&(t(``),r(`delete`))},Se=async()=>{if(e.length===0)return;let t=await W.mutateAsync({password:e,scopes:[...D]});O(new Set),G(),l.success(`Selected configuration deleted.`,Object.entries(t.deleted).map(([e,t])=>`${e}: ${t}`).join(` · `))},K=()=>{let t=[...i?[`config`]:[],...s?[`telemetry`]:[]].join(`,`);if(t.length===0){l.error(`Select at least one backup section.`);return}z.mutate({password:e,sections:t,compressed:f,onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))},{onSuccess:e=>{let t=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`);e instanceof Uint8Array?re(`cartethyia_backup_${t}.json.gz`,e,`application/gzip`):ne(`cartethyia_backup_${t}.json`,JSON.stringify(e,null,2),`application/json`),G(),l.success(`Backup downloaded.`)},onError:e=>l.error(T(e,`Backup export failed.`))})},q=async e=>{ee(null),b(null),S(null),C(null),E(null),oe(null),M(null),F(new Set),A(e);try{let t=await ae(e),n=await ye.mutateAsync({backup:t});M(n),F(new Set(n.rows.filter(e=>e.supported).map(e=>e.table)))}catch(e){A(null),l.error(`Could not read that backup`,T(e,`The file is not a readable backup.`))}},Ce=e=>{F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},J=()=>{M(null),A(null),oe(null)},we=()=>{k!==null&&N.size!==0&&(t(``),S(null),r(`restore`))},Te=async()=>{let t=k;if(t!==null){S(null);try{let n=await ae(t),r=await U.mutateAsync({password:e,backup:n,tables:[...N],onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))});ee(r.restored),b(r.warnings),C(r.report??null),E(r.format),G(),A(null),M(null),l.success(r.warnings.length===0?`Restore complete.`:`Restore completed with warnings.`,r.warnings.length===0?null:`${r.warnings.length} item(s) need attention. See the restore report below.`)}catch(e){let t=T(e,`Backup restore failed.`);S(t),l.error(`Backup restore failed`,t)}}},Ee=_===null?[]:Object.entries(_);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,V.jsxs)(`section`,{"aria-label":`Backup`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Export and restore`,description:`Download a JSON snapshot, or restore one you already trust.`}),(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-2 gap-5 min-w-0 border-0 m-0 p-0 max-medium:grid-cols-1`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Include in the download`}),(0,V.jsx)(H,{icon:d,label:`Account, proxy & settings`,description:`Credentials, API-key hashes, routing, and settings`,checked:i,onChange:()=>a(!i)}),(0,V.jsx)(H,{icon:se,label:`Telemetry history`,description:`Status, tokens, cost, latency — never prompt bodies`,checked:s,onChange:()=>u(!s)})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border px-6 py-5`,children:[(0,V.jsxs)(`span`,{children:[(0,V.jsx)(`strong`,{className:`block text-body`,children:`Highly Compress Backup`}),(0,V.jsx)(`small`,{className:`text-caption text-text-tertiary`,children:`Makes the download smaller.`})]}),(0,V.jsx)(ie,{checked:f,onChange:p,"aria-label":`Highly Compress Backup`})]}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:`The file contains provider credentials. Treat it like the database. Prompt and response bodies, health-event history, and console sessions are left out.`}),(0,V.jsxs)(`div`,{className:`mt-auto flex justify-end gap-4`,children:[(0,V.jsx)(c,{variant:`primary`,size:`sm`,onClick:()=>{t(``),r(`download`)},disabled:!i&&!s,icon:(0,V.jsx)(o,{size:13}),children:`Download backup`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:()=>ce.current?.click(),icon:(0,V.jsx)(le,{size:13}),children:`Restore from file`}),(0,V.jsx)(`input`,{ref:ce,type:`file`,accept:`application/json,.json,.gz,application/gzip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];t&&q(t),e.target.value=``}})]}),w===null?null:(0,V.jsxs)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:[`Detected format:`,` `,w===`nine_router`?`router export`:`Cartethyia backup`]}),_===null?null:(0,V.jsxs)(L,{tone:`success`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`Restore complete`}),Ee.length>0?(0,V.jsx)(`ul`,{children:Ee.map(([e,t])=>(0,V.jsxs)(`li`,{children:[e,`: `,t]},e))}):(0,V.jsx)(`p`,{children:`No rows were imported.`})]}),v===null?null:(0,V.jsx)(_e,{warnings:v}),te===null?null:(0,V.jsx)(ge,{report:te})]})]}),(0,V.jsxs)(`section`,{"aria-label":`Delete data`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Delete data`,description:`Removes the scopes you check. Console users, sessions, and audit history stay.`}),(0,V.jsxs)(I,{gap:`12px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-5 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Delete`}),[[`providers`,`Providers`,`Accounts, credentials, tenant models, routing, and account health`],[`proxies`,`Proxies`,`Network pools, pool settings, and pool health`],[`configuration`,`All configuration`,`Providers, proxies, aliases, combos, API keys, CLI tools, and settings`]].map(([e,t,n])=>(0,V.jsx)(H,{icon:he(e),label:t,description:n,checked:D.has(e),onChange:()=>be(e)},e))]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end gap-4 flex-wrap`,children:(0,V.jsx)(c,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),disabled:D.size===0,onClick:xe,children:`Delete selected`})})]})]})]}),(0,V.jsx)(g,{open:j!==null,onClose:J,title:`Restore from backup`,description:`Choose which parts of this file to restore, then confirm with your console password.`,size:`md`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:J,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,size:`sm`,disabled:N.size===0,onClick:we,children:`Restore now`})]}),children:(0,V.jsx)(I,{gap:`12px`,children:j===null?null:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:j.format===`nine_router`?`Router export — it is converted at restore time, so every table it produces is restored.`:`${j.total} rows · exported ${j.exportedAt||`unknown date`}`}),j.rows.length>0?(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-4 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-3 text-text-secondary text-caption font-semibold`,children:`Restore these tables`}),(0,V.jsxs)(`div`,{className:`flex justify-end gap-4`,children:[(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-accent hover:underline`,onClick:()=>F(new Set(j.rows.filter(e=>e.supported).map(e=>e.table))),children:`Select all`}),(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-text-secondary hover:underline`,onClick:()=>F(new Set),children:`Select none`})]}),j.rows.map(e=>(0,V.jsxs)(`label`,{className:`flex items-start gap-4 px-5 py-4 border border-inner-border rounded-control bg-surface-2 text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:N.has(e.table),disabled:!e.supported,onChange:()=>Ce(e.table)}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{className:`text-text-primary`,children:e.table}),(0,V.jsxs)(`small`,{className:`text-text-tertiary text-badge`,children:[e.count,` rows · `,e.section,e.supported?``:` · not in the current schema, will be skipped`]})]})]},`${e.section}:${e.table}`))]}):null,R===null?null:(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:R})]})})}),(0,V.jsx)(g,{open:n!==null,onClose:G,title:n===`delete`?`Confirm deletion`:n===`restore`?`Restore backup`:`Download backup`,description:`The console password is checked again before this runs.`,size:`sm`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:G,children:`Cancel`}),(0,V.jsx)(c,{variant:n===`delete`?`danger`:`primary`,size:`sm`,loading:z.isPending||U.isPending||W.isPending,disabled:e.length===0||z.isPending||U.isPending||W.isPending,onClick:()=>{h(null),n===`download`?K():n===`restore`?Te():Se()},children:z.isPending?ve(m,`Downloading…`):U.isPending?ve(m,`Uploading…`):W.isPending?`Working…`:n===`delete`?`Delete permanently`:n===`restore`?`Restore`:`Download`})]}),children:(0,V.jsxs)(I,{gap:`10px`,children:[n===`restore`&&x!==null?(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:x}):null,(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:n===`delete`?`This cannot be undone. The password is verified again before anything is removed.`:n===`restore`?`Restore replaces the tenant configuration in this file. Continue only if the file is trusted.`:`The export is plain JSON and contains provider credentials.`}),(0,V.jsx)(P,{label:`Console password`,type:`password`,value:e,onChange:e=>t(e.target.value),autoComplete:`current-password`,"data-autofocus":!0})]})})]})}function ye(){return te({queryKey:O.settings.diskUsage,queryFn:e=>E(`/data-management/usage`,{signal:S(e)}),...w,staleTime:C.status})}function be(){let e=x();return k({mutationFn:e=>E(`/data-management/reclaim`,{method:`POST`,body:JSON.stringify({action:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function G(){return k({mutationFn:()=>E(`/data-management/flush`,{method:`POST`})})}function xe(){let e=x();return k({mutationFn:()=>E(`/data-management/purge`,{method:`POST`,body:JSON.stringify({target:`health_events`})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function Se(){let e=ye(),t=be(),n=G(),r=xe(),[a,o]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1);if(e.isPending)return(0,V.jsx)(m,{label:`Measuring disk usage…`});if(e.isError||!e.data)return(0,V.jsx)(p,{message:T(e.error,`Failed to measure disk usage`),onRetry:()=>void e.refetch()});let h=e.data,g=e=>{e!==null&&(o(null),t.mutate(e,{onSuccess:e=>{if(e.deletedFiles===0){l.success(`Nothing to reclaim.`);return}l.success(`Reclaimed ${u(e.reclaimedBytes)} across ${s(e.deletedFiles)} file${e.deletedFiles===1?``:`s`}.`)},onError:e=>l.error(T(e,`Reclaim failed.`))}))},_=h.healthEventCount;return(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4 flex-wrap`,children:[(0,V.jsxs)(`span`,{className:`text-caption text-text-tertiary`,children:[u(h.totalBytes),` on disk across`,` `,s(h.buckets.reduce((e,t)=>e+t.files,0)),` files`]}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(z,{size:14}),onClick:()=>void e.refetch(),disabled:e.isFetching,children:e.isFetching?`Measuring…`:`Refresh`})]}),(0,V.jsxs)(`div`,{className:`settings-bucket-grid`,children:[h.buckets.map(e=>{let n=q(e);return(0,V.jsx)(J,{bucket:e,busy:t.isPending,confirming:n!==null&&a===n,onAsk:()=>o(n),onCancel:()=>o(null),onConfirm:()=>g(n)},e.id)}),(0,V.jsx)(K,{icon:i,title:`Health & Error Log`,note:_===void 0?`Purging is not offered in this deployment's console composition.`:`${s(_)} recorded transition${_===1?``:`s`} across accounts and pools. Purge clears only this audit trail — account statuses and cooldowns stay as they are, and this cannot be undone.`,testId:`health_events`,children:_===void 0?null:d?(0,V.jsx)(`span`,{className:`flex flex-col gap-3`,children:(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:()=>f(!1),disabled:r.isPending,children:`Cancel`}),(0,V.jsx)(c,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),disabled:r.isPending,onClick:()=>r.mutate(void 0,{onSuccess:e=>{f(!1),l.success(e.deleted===0?`Health & error log was already empty.`:`Purged ${s(e.deleted)} health event${e.deleted===1?``:`s`}.`)},onError:e=>l.error(T(e,`Purge failed.`))}),children:`Delete`})]})}):(0,V.jsx)(c,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),disabled:r.isPending||_===0,onClick:()=>f(!0),children:`Purge`})}),(0,V.jsx)(K,{icon:ce,title:`Flush pending writes`,note:`Write queued telemetry, usage, and health events now instead of waiting for the interval. Nothing is deleted.`,testId:`flush`,children:(0,V.jsx)(c,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(b,{size:14}),disabled:n.isPending,onClick:()=>n.mutate(void 0,{onSuccess:()=>l.success(`Buffers flushed.`),onError:e=>l.error(T(e,`Flush failed.`))}),children:n.isPending?`Flushing…`:`Flush`})})]}),t.isError?(0,V.jsx)(L,{tone:`danger`,surface:`raised`,live:`status`,children:T(t.error,`Reclaim failed.`)}):null]})}function K({icon:e,title:t,note:n,children:r,testId:i}){return(0,V.jsxs)(`div`,{"data-panel":i,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:t}),(0,V.jsx)(`span`,{className:`mt-1 block text-caption text-text-tertiary`,children:n})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:r})]})}function q(e){return e.id===`payload_frames`?`payload_frames`:e.id===`telemetry_events`?`telemetry_retention`:null}function Ce(e){return e.id===`payload_frames`?oe:se}function J({bucket:e,busy:t,confirming:n,onAsk:r,onCancel:i,onConfirm:a}){let o=q(e),l=e.reclaimableBytes!==null,d=e.reclaimableBytes??0,f=e.reclaimableFiles??0,p=l&&d===0,m=Ce(e);return(0,V.jsxs)(`div`,{"data-bucket":e.id,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(m,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:e.label}),(0,V.jsx)(`span`,{className:`mt-1 block text-lead font-semibold text-text-primary`,children:u(e.bytes)}),(0,V.jsxs)(`span`,{className:`block text-caption text-text-tertiary`,children:[s(e.files),` file`,e.files===1?``:`s`,` · `,e.note]})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:o===null?(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:`Kept — no other copy.`}):n?(0,V.jsxs)(`span`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-secondary`,children:l?`Delete ${s(f)} file${f===1?``:`s`}, ${u(d)}?`:`Delete raw event files past the retention window?`}),(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:i,disabled:t,children:`Cancel`}),(0,V.jsx)(c,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),onClick:a,disabled:t,children:`Delete`})]})]}):(0,V.jsxs)(`span`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-tertiary`,children:l?p?`Clean`:`${u(d)} free`:`Expired events only`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),onClick:r,disabled:t||p,children:`Reclaim`})]})})]})}function we(){return k({mutationFn:e=>E(`/auth/change-password`,{method:`POST`,body:JSON.stringify(e)})})}var Te=[5,15,30,60,120,300,600],Ee=[5,15,30,60,180,720,1440],De=[1,5,10,25,50,100];function Oe({name:e}){let t={size:16};return e===`privacy`?(0,V.jsx)(f,{...t}):e===`operations`?(0,V.jsx)(b,{...t}):e===`data`?(0,V.jsx)(R,{...t}):e===`data-management`?(0,V.jsx)(d,{...t}):(0,V.jsx)(ee,{...t})}function Y(e,t,n){return(t===null||e.includes(t)?[...e]:[...e,t].sort((e,t)=>e-t)).map(e=>({value:String(e),label:n(e)}))}var ke=[{id:`security`,title:`Security`,description:`Change the password used to sign in to this console.`},{id:`privacy`,title:`Privacy`,description:`What request telemetry stores, and how client addresses are shown.`},{id:`backup`,title:`Backup`,description:`Export or restore this tenant's configuration and history.`},{id:`operations`,title:`Operations`,description:`Routing, admission, request handling, and response shaping for this tenant.`},{id:`data-management`,title:`Data Management`,description:`See what the gateway keeps on disk, reclaim space, and flush queued writes.`}];function X(e){if(e%1440==0){let t=e/1440;return`${t} day${t===1?``:`s`}`}if(e%60==0){let t=e/60;return`${t} hour${t===1?``:`s`}`}return`${e} min`}function Z(e){return`Deployment default (${e})`}function Ae(e){return`${Math.round(e/1048576)} MB`}function Q({label:e,hint:t,labelFor:n,control:r}){return(0,V.jsxs)(`div`,{className:`settings-row`,children:[(0,V.jsxs)(`div`,{className:`settings-row-text`,children:[n?(0,V.jsx)(`label`,{className:`settings-row-label`,htmlFor:n,children:e}):(0,V.jsx)(`span`,{className:`settings-row-label`,children:e}),t?(0,V.jsx)(`p`,{className:`settings-row-hint`,children:t}):null]}),(0,V.jsx)(`div`,{className:`settings-row-control`,children:r})]})}function $({title:e}){return(0,V.jsx)(`p`,{className:`settings-group-head`,children:e})}function je({id:e,title:t,description:n,children:r}){return(0,V.jsxs)(N,{id:e,"aria-label":t,className:`min-w-0`,children:[(0,V.jsx)(M,{title:t,subtitle:n,icon:(0,V.jsx)(Oe,{name:e})}),(0,V.jsx)(j,{className:`flex flex-col gap-0`,children:r})]})}function Me(){let e=v(),t=_(),n=e.data;return e.isPending?(0,V.jsx)(m,{label:`Loading privacy settings…`}):e.isError||!n?(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Telemetry payloads`,labelFor:`privacy-payloads`,hint:`Request metadata is always kept. Bodies stay off until you turn them on, and anything captured is redacted and deleted when the Request detail window in Operations runs out.`,control:(0,V.jsx)(F,{"aria-label":`Telemetry payloads`,id:`privacy-payloads`,value:n.telemetryPayloads,onValueChange:e=>t.mutate({telemetryPayloads:e===`full`||e===`metadata`?e:`none`},{onSuccess:()=>l.success(`Payload capture updated`),onError:e=>l.error(T(e,`Could not update payload capture.`))}),options:[{value:`none`,label:`Off — no payload capture`},{value:`metadata`,label:`Metadata — method and headers only`},{value:`full`,label:`Full — redacted bodies`}]})}),n.telemetryPayloads===`full`?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Capture depth`,labelFor:`privacy-payload-depth`,hint:`Size cap for each captured body.`,control:(0,V.jsx)(F,{"aria-label":`Capture depth`,id:`privacy-payload-depth`,value:n.telemetryPayloadDepth,onValueChange:e=>t.mutate({telemetryPayloadDepth:e===`moderate`||e===`maximum`?e:`minimum`},{onSuccess:()=>l.success(`Capture depth updated`),onError:e=>l.error(T(e,`Could not update capture depth.`))}),options:[{value:`minimum`,label:`Minimum — 1 MiB cap`},{value:`moderate`,label:`Moderate — 8 MiB cap`},{value:`maximum`,label:`Maximum — 16 MiB cap`}]})}),n.telemetryPayloadDepth===`minimum`?null:(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,className:`text-text-secondary`,children:[(0,V.jsx)(`strong`,{children:`High CPU and memory while this is on.`}),` Use it to debug, then switch back to Metadata or Minimum.`]})})]}):null,(0,V.jsx)(Q,{label:`Client IP display`,labelFor:`privacy-ip`,hint:`Raw addresses stay stored and are still written to telemetry. This only changes how they are shown in the console.`,control:(0,V.jsx)(F,{"aria-label":`Client IP display`,id:`privacy-ip`,value:n.privacyMode,onValueChange:e=>t.mutate({privacyMode:e===`full`?`full`:`masked`},{onSuccess:()=>l.success(`IP display updated`),onError:e=>l.error(T(e,`Could not update IP display.`))}),options:[{value:`masked`,label:`Masked — recommended`},{value:`full`,label:`Show full IP`}]})})]})}function Ne(){let e=v(),t=_(),n=e.data;if(e.isPending)return(0,V.jsx)(m,{label:`Loading operational settings…`});if(e.isError||!n)return(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()});let r=(e,n)=>{t.mutate(e,{onSuccess:()=>l.success(n),onError:e=>l.error(T(e,`Could not update settings.`))})};return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{title:`Routing`}),(0,V.jsx)(Q,{label:`Ignore cooldowns`,labelFor:`ignore-cooldowns`,hint:`Route to accounts that are cooling down, including ones already parked. Off by default: a cooling account stays out of the rotation until it resets. On dials it anyway, which is what the warning below is about.`,control:(0,V.jsx)(F,{"aria-label":`Ignore cooldowns`,id:`ignore-cooldowns`,value:n.forceDisableCooldown?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({forceDisableCooldown:t},t?`Cooldowns are ignored.`:`Cooldowns are enforced again.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),n.forceDisableCooldown?(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`This may cause admission failure.`}),` A cooled-down account was parked because the upstream refused it, so dialing it anyway reproduces that refusal on every attempt — and if every candidate is cooling, the request fails instead of waiting for a reset. The cooldown is still recorded and still recovered by the sweep, so turning this back off needs no cleanup. Per-model cooldowns are still enforced.`]})}):null,(0,V.jsx)($,{title:`Admission`}),(0,V.jsx)(Q,{label:`Tenant concurrency limit`,labelFor:`tenant-concurrency-limit`,hint:`Ceiling on requests in flight across every key in this tenant at once. Empty means no tenant-wide ceiling — each key is then bounded only by its own limit.`,control:(0,V.jsx)(P,{id:`tenant-concurrency-limit`,"aria-label":`Tenant concurrency limit`,type:`number`,min:`1`,step:`1`,inputMode:`numeric`,placeholder:`No ceiling`,value:n.tenantConcurrencyLimit?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({tenantConcurrencyLimit:null},`Tenant ceiling removed.`);return}let n=Number(t);!Number.isInteger(n)||n<1||r({tenantConcurrencyLimit:n},`Tenant concurrency limit updated.`)}})}),(0,V.jsx)(Q,{label:`Concurrency tolerance`,labelFor:`concurrency-tolerance`,hint:`Slack added above a key's own concurrency limit. The effective ceiling is the key's limit plus this, so a run landing a few over is not refused at the number it was told.`,control:(0,V.jsx)(P,{id:`concurrency-tolerance`,"aria-label":`Concurrency tolerance`,type:`number`,min:`0`,max:`1024`,step:`1`,inputMode:`numeric`,placeholder:`None`,value:n.concurrencyTolerance?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({concurrencyTolerance:null},`Tolerance removed.`);return}let n=Number(t);!Number.isInteger(n)||n<0||n>1024||r({concurrencyTolerance:n},`Concurrency tolerance updated.`)}})}),(0,V.jsx)($,{title:`Request handling`}),(0,V.jsx)(Q,{label:`Upstream timeout`,labelFor:`upstream-timeout`,hint:`5–600 seconds, ${n.defaults.upstreamTimeoutSeconds}s when unset. Applied when the request is dispatched, so it can only shorten a deadline that has already started.`,control:(0,V.jsx)(F,{"aria-label":`Upstream timeout`,id:`upstream-timeout`,value:n.upstreamTimeoutSeconds?.toString()??``,placeholder:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`),onValueChange:e=>r({upstreamTimeoutSeconds:e===``?null:Number(e)},`Upstream timeout updated.`),options:[...Y(Te,n.upstreamTimeoutSeconds,e=>`${e} seconds`),{value:``,label:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`)}]})}),(0,V.jsx)(Q,{label:`Request detail window`,labelFor:`telemetry-window-minutes`,hint:`1–1440 minutes, ${X(n.defaults.telemetryWindowMinutes)} when unset. Controls how long captured payload frames are kept — the same number Data Management reports as what payload frames expire after. Raw request events follow the ${n.defaults.telemetryRetentionDays}-day server retention instead.`,control:(0,V.jsx)(F,{"aria-label":`Request detail window`,id:`telemetry-window-minutes`,value:n.telemetryWindowMinutes?.toString()??``,placeholder:Z(X(n.defaults.telemetryWindowMinutes)),onValueChange:e=>r({telemetryWindowMinutes:e===``?null:Number(e)},`Detail window updated.`),options:[...Y(Ee,n.telemetryWindowMinutes,X),{value:``,label:Z(X(n.defaults.telemetryWindowMinutes))}]})}),(0,V.jsx)(Q,{label:`Max attachment size`,labelFor:`image-clamp-max-bytes`,hint:`Per image, ${Ae(n.defaults.imageClampMaxBytes)} when unset. An oversized attachment is refused before send rather than after the upstream rejects it — a block too large poisons every retry and every replayed turn. Raising this asserts your upstreams accept more; lowering it is the safer direction. Applies to the Messages and Gemini wires.`,control:(0,V.jsx)(F,{"aria-label":`Max attachment size`,id:`image-clamp-max-bytes`,value:n.imageClampMaxBytes===null?``:String(Math.round(n.imageClampMaxBytes/1048576)),placeholder:Z(Ae(n.defaults.imageClampMaxBytes)),onValueChange:e=>r({imageClampMaxBytes:e===``?null:Number(e)*1024*1024},`Attachment size limit updated.`),options:[...Y(De,n.imageClampMaxBytes===null?null:Math.round(n.imageClampMaxBytes/1048576),e=>`${e} MB`),{value:``,label:Z(Ae(n.defaults.imageClampMaxBytes))}]})}),(0,V.jsx)($,{title:`Response shaping`}),(0,V.jsx)(Q,{label:`Thinking normalization`,labelFor:`thinking-normalization`,hint:`Rewrite a provider's native thinking config into the canonical shape on turns where the user is not the final reader. Off by default: the upstream's own config is passed through untouched.`,control:(0,V.jsx)(F,{"aria-label":`Thinking normalization`,id:`thinking-normalization`,value:n.thinkingNormalizationEnabled?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({thinkingNormalizationEnabled:t},t?`Thinking config will be normalized.`:`Upstream thinking config is left as sent.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),(0,V.jsx)(Q,{label:`Reasoning summary`,labelFor:`responses-reasoning-summary`,hint:`Verbosity of the reasoning summary on the Responses wire, forced even when a request carries no reasoning block. Applies when the routed model is Responses and the client called a Chat surface.`,control:(0,V.jsx)(F,{"aria-label":`Reasoning summary`,id:`responses-reasoning-summary`,value:n.responsesReasoningSummary,onValueChange:e=>r({responsesReasoningSummary:e===`concise`||e===`detailed`?e:`auto`},`Reasoning summary updated.`),options:[{value:`auto`,label:`Auto — follow the request`},{value:`concise`,label:`Concise`},{value:`detailed`,label:`Detailed — default`}]})})]})}function Pe(){let e=we(),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(``),[a,o]=(0,B.useState)(``),[s,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(!1);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Current password`,labelFor:`current-password`,hint:`This is the password for this console, not for any upstream provider. Provider credentials live on each provider in Providers.`,control:(0,V.jsx)(P,{id:`current-password`,"aria-label":`Current password`,type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:`current-password`})}),(0,V.jsx)(Q,{label:`New password`,labelFor:`new-password`,hint:`Minimum 8 characters. A passphrase is easier to remember and harder to guess.`,control:(0,V.jsx)(P,{id:`new-password`,"aria-label":`New password`,type:`password`,value:r,onChange:e=>i(e.target.value),autoComplete:`new-password`})}),(0,V.jsx)(Q,{label:`Confirm new password`,labelFor:`confirm-password`,control:(0,V.jsx)(P,{id:`confirm-password`,"aria-label":`Confirm new password`,type:`password`,value:a,onChange:e=>o(e.target.value),autoComplete:`new-password`})}),s?(0,V.jsx)(`p`,{role:`alert`,className:`settings-feedback`,"data-tone":`err`,children:s}):null,u?(0,V.jsx)(`p`,{role:`status`,className:`settings-feedback`,"data-tone":`ok`,children:`Password updated.`}):null,(0,V.jsx)(`div`,{className:`settings-actions`,children:(0,V.jsx)(c,{variant:`primary`,size:`sm`,onClick:()=>{if(d(!1),r.length<8){l(`New password must be at least 8 characters.`);return}if(r!==a){l(`New password and confirmation do not match.`);return}l(null),e.mutate({currentPassword:t,newPassword:r},{onSuccess:()=>{d(!0),n(``),i(``),o(``)},onError:e=>l(T(e,`Password change failed.`))})},disabled:e.isPending||!t||!r||!a,children:e.isPending?`Updating…`:`Update password`})})]})}var Fe={security:(0,V.jsx)(Pe,{}),privacy:(0,V.jsx)(Me,{}),operations:(0,V.jsx)(Ne,{}),backup:(0,V.jsx)(W,{}),"data-management":(0,V.jsx)(Se,{})},Ie=[`security`,`privacy`];function Le(){return(0,V.jsxs)(`div`,{className:`settings-page`,children:[(0,V.jsx)(`div`,{className:`settings-grid`,children:Ie.map(e=>{let t=ke.find(t=>t.id===e);return t?(0,V.jsx)(je,{id:t.id,title:t.title,description:t.description,children:Fe[t.id]},e):null})}),ke.filter(e=>!Ie.includes(e.id)).map(e=>(0,V.jsx)(je,{id:e.id,title:e.title,description:e.description,children:Fe[e.id]},e.id))]})}export{Y as boundedOptions,Le as default};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{h as i}from"./numbers-CEagj6ZZ.js";import{ft as a}from"./entry-CiIQULZD.js";import{n as o}from"./stack-DfgnFDWY.js";var s=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),c=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),l=t(n(),1),u=r();function d({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:d,label:f}){let[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(null),_=(0,l.useRef)(null),v=()=>{_.current=null,m(null),g(null)},y=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,u.jsx)(`div`,{role:`list`,"aria-label":f,className:i(`flex flex-col min-w-0`,o(r)??`gap-5`),children:e.map((r,o)=>{let l=p===r.id,f=h===r.id&&p!==null&&p!==r.id,b=r=>{let i=o+r;if(n||i<0||i>=e.length)return;let a=e.map(e=>e.id),[s]=a.splice(o,1);s!==void 0&&(a.splice(i,0,s),t(a))};return(0,u.jsxs)(`div`,{role:`listitem`,className:i(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,l&&`opacity-50`,f&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":l?`true`:void 0,"data-drop-target":f?`true`:void 0,onDragOver:e=>{n||_.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,h!==r.id&&g(r.id))},onDrop:e=>{e.preventDefault();let t=_.current;t!==null&&y(t,r.id),v()},children:[(0,u.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,u.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:o+1}),(0,u.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${o+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{_.current=r.id,m(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:v,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,u.jsx)(c,{size:14})})]}),(0,u.jsxs)(`div`,{className:`flex gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} up`,title:`Move up`,disabled:n||o===0,onClick:()=>b(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(s,{size:14})}),(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} down`,title:`Move down`,disabled:n||o===e.length-1,onClick:()=>b(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(a,{size:14})})]})]}),(0,u.jsx)(`div`,{className:`flex-auto min-w-0`,children:d(r,o)})]},r.id)})})}export{d as t};
|
|
Binary file
|
|
Binary file
|