cartethyia 2.4.6 → 2.5.1
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/README.md +45 -13
- package/dist/dashboard/assets/BannedPage-ChqnTRpZ.js +1 -0
- package/dist/dashboard/assets/BannedPage-ChqnTRpZ.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-Bcy150Jo.js → CliToolDetailPage-Bb9CNuoh.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-Bb9CNuoh.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-DyNXefph.js → CliToolsPage-BXUaRCQQ.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-BXUaRCQQ.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CisNZOUt.js +1 -0
- package/dist/dashboard/assets/CombosPage-CisNZOUt.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-CATpAEOz.js → ConsoleLogPage-BOpI_LOH.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-BOpI_LOH.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-D6jEU7nL.js → CustomizationPage-DAkdvJ4k.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-DAkdvJ4k.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-CZkpn0a7.js → HealthEventsModal-DeT-VXHd.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-DeT-VXHd.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-BJlMVN4U.js → LoginPage-CytxSeGP.js} +1 -1
- package/dist/dashboard/assets/LoginPage-CytxSeGP.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-Br3CXEau.js → ModelPicker-oQ-SDXp8.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-oQ-SDXp8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CU7S1wJs.js +1 -0
- package/dist/dashboard/assets/OverviewPage-CU7S1wJs.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-DLm2baot.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-DLm2baot.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-CmfzxpVM.js +1 -0
- package/dist/dashboard/assets/ProviderIcon-CmfzxpVM.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-DOXfuzfL.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-DOXfuzfL.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-wvk0ciQN.js +7 -0
- package/dist/dashboard/assets/ProxyPage-wvk0ciQN.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-Cn_fcUHE.js +1 -0
- package/dist/dashboard/assets/QuotaPage-Cn_fcUHE.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-BHW4Zt06.js → SettingsPage-8-eVadhc.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-8-eVadhc.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-VOYC_lIa.js → SetupPage-uEIXPyGO.js} +1 -1
- package/dist/dashboard/assets/SetupPage-uEIXPyGO.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DCY0TPTZ.js +1 -0
- package/dist/dashboard/assets/SortableList-DCY0TPTZ.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-BNIDLiU6.js → StudioPage-DqK5E26W.js} +4 -4
- package/dist/dashboard/assets/StudioPage-DqK5E26W.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-38JfiZ0H.js +56 -0
- package/dist/dashboard/assets/UsagePage-38JfiZ0H.js.gz +0 -0
- package/dist/dashboard/assets/{api-keys-BETfaMYZ.js → api-keys-BmDbsior.js} +1 -1
- package/dist/dashboard/assets/api-keys-BmDbsior.js.gz +0 -0
- package/dist/dashboard/assets/app-BbpSarVV.css +2 -0
- package/dist/dashboard/assets/app-BbpSarVV.css.gz +0 -0
- package/dist/dashboard/assets/assert-BHfaei-X.js +1 -0
- package/dist/dashboard/assets/assert-BHfaei-X.js.gz +0 -0
- package/dist/dashboard/assets/{badge-BTyGk_DL.js → badge-DpXT4Ixt.js} +1 -1
- package/dist/dashboard/assets/badge-DpXT4Ixt.js.gz +0 -0
- package/dist/dashboard/assets/{banner-bujTWYM4.js → banner-CSAAWLJv.js} +1 -1
- package/dist/dashboard/assets/banner-CSAAWLJv.js.gz +0 -0
- package/dist/dashboard/assets/{card-B0Bnx5CA.js → card-DEhRXXw4.js} +1 -1
- package/dist/dashboard/assets/card-DEhRXXw4.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-DE2ug812.js → cli-tools-B0wBq-RL.js} +1 -1
- package/dist/dashboard/assets/cli-tools-B0wBq-RL.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-R_rArH8S.js → clipboard-button-DOo6EU8O.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-DOo6EU8O.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-BWIP_EvW.js → dialog-BvQeBMfP.js} +1 -1
- package/dist/dashboard/assets/dialog-BvQeBMfP.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-BKcgVugF.js → drawer-CMwPXwQB.js} +1 -1
- package/dist/dashboard/assets/drawer-CMwPXwQB.js.gz +0 -0
- package/dist/dashboard/assets/entry--yj84zk3.js +4 -0
- package/dist/dashboard/assets/entry--yj84zk3.js.gz +0 -0
- package/dist/dashboard/assets/{entry-CcWkGR4a.js → entry-D4O2229X.js} +1 -1
- package/dist/dashboard/assets/{entry-CcWkGR4a.js.gz → entry-D4O2229X.js.gz} +0 -0
- package/dist/dashboard/assets/{entry-kTiTFrvh.js → entry-DKvr5Q9K.js} +1 -1
- package/dist/dashboard/assets/entry-DKvr5Q9K.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-Booc5mNe.js → github-badge-zliLvBwr.js} +1 -1
- package/dist/dashboard/assets/github-badge-zliLvBwr.js.gz +0 -0
- package/dist/dashboard/assets/{index-D70pChfn.js → index-CcD1eSJ6.js} +2 -2
- package/dist/dashboard/assets/index-CcD1eSJ6.js.gz +0 -0
- package/dist/dashboard/assets/{inline-D1TCqM2D.js → inline-D1IlZZ8H.js} +1 -1
- package/dist/dashboard/assets/inline-D1IlZZ8H.js.gz +0 -0
- package/dist/dashboard/assets/{input-B9oyU93y.js → input-BpVZdrbc.js} +1 -1
- package/dist/dashboard/assets/input-BpVZdrbc.js.gz +0 -0
- package/dist/dashboard/assets/{layout-BArzXirQ.js → layout-BioLW7gN.js} +1 -1
- package/dist/dashboard/assets/layout-BioLW7gN.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-BVZzaoHF.js → list-row-CwVcGAIc.js} +1 -1
- package/dist/dashboard/assets/list-row-CwVcGAIc.js.gz +0 -0
- package/dist/dashboard/assets/{live-EmuIayqp.js → live-yfEJFF9T.js} +1 -1
- package/dist/dashboard/assets/live-yfEJFF9T.js.gz +0 -0
- package/dist/dashboard/assets/{model-bans-CSPQ9xB0.js → model-bans-CT-TxSNX.js} +1 -1
- package/dist/dashboard/assets/model-bans-CT-TxSNX.js.gz +0 -0
- package/dist/dashboard/assets/providers/cursor.webp +0 -0
- package/dist/dashboard/assets/providers/trae.webp +0 -0
- package/dist/dashboard/assets/{routing-BExgxxBU.js → routing-Cs6jl49L.js} +1 -1
- package/dist/dashboard/assets/routing-Cs6jl49L.js.gz +0 -0
- package/dist/dashboard/assets/select-XPJ-dIw3.js +41 -0
- package/dist/dashboard/assets/select-XPJ-dIw3.js.gz +0 -0
- package/dist/dashboard/assets/settings-CfcTcOyU.js +1 -0
- package/dist/dashboard/assets/settings-CfcTcOyU.js.gz +0 -0
- package/dist/dashboard/assets/{stack-Ca5HxI5i.js → stack-C9_uUjaA.js} +1 -1
- package/dist/dashboard/assets/stack-C9_uUjaA.js.gz +0 -0
- package/dist/dashboard/assets/{state-CzUPfLXo.js → state-DA0B95UQ.js} +1 -1
- package/dist/dashboard/assets/state-DA0B95UQ.js.gz +0 -0
- package/dist/dashboard/assets/{switch-DOUIky_i.js → switch-Cittxy-x.js} +1 -1
- package/dist/dashboard/assets/switch-Cittxy-x.js.gz +0 -0
- package/dist/dashboard/assets/{toast-C76WrMhc.js → toast-CNt_jzO4.js} +1 -1
- package/dist/dashboard/assets/toast-CNt_jzO4.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-D87FZwH0.js → useMutation-BQKMcJ1H.js} +1 -1
- package/dist/dashboard/assets/useMutation-BQKMcJ1H.js.gz +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +51 -52
- package/migrations/full-postgres/0015_add_payload_stages.sql +18 -0
- package/migrations/full-postgres/0016_add_share_link_slug.sql +20 -0
- package/migrations/full-postgres/0017_add_models_pro_only.sql +18 -0
- package/migrations/full-postgres/0018_add_accounts_quota_plan.sql +18 -0
- package/migrations/full-postgres/0019_add_models_free_tier.sql +15 -0
- package/migrations/lite-sqlite3/0015_add_payload_stages.sql +18 -0
- package/migrations/lite-sqlite3/0016_add_share_link_slug.sql +20 -0
- package/migrations/lite-sqlite3/0017_add_models_pro_only.sql +18 -0
- package/migrations/lite-sqlite3/0018_add_accounts_quota_plan.sql +18 -0
- package/migrations/lite-sqlite3/0019_add_models_free_tier.sql +15 -0
- package/package.json +3 -2
- package/scripts/cli/command/console-menu.ts +30 -11
- package/scripts/cli/command/start.ts +77 -13
- package/scripts/cli/command/tray.ts +47 -8
- package/scripts/cli/command/update.ts +1 -1
- package/scripts/cli/gateway/instance-lock.ts +105 -0
- package/scripts/cli/gateway/spawn.ts +173 -101
- package/scripts/cli/ui/background.ts +110 -49
- package/src/boot/app.ts +20 -6
- package/src/boot/dependencies.ts +19 -0
- package/src/boot/elysia-typebox-bridge.ts +37 -0
- package/src/boot/lifecycle.ts +2 -0
- package/src/config/cooldowns.ts +138 -138
- package/src/config/providers.ts +5 -5
- package/src/config/runtime.ts +19 -3
- package/src/config/spec.ts +9 -0
- package/src/console/api-keys/contracts.ts +414 -391
- package/src/console/api-keys/routes.ts +880 -870
- package/src/console/auth/account-reset-store.ts +14 -0
- package/src/console/auth/account-reset.ts +3 -2
- package/src/console/auth/setup-service.ts +6 -3
- package/src/console/domain-registration.ts +9 -2
- package/src/console/observability/contracts.ts +475 -455
- package/src/console/observability/store.ts +1015 -952
- package/src/console/providers/catalog/contracts.ts +31 -0
- package/src/console/providers/catalog/provider-operations.ts +8 -0
- package/src/console/providers/catalog/store.ts +1532 -1525
- package/src/console/providers/oauth/callback-listener.ts +18 -3
- package/src/console/providers/oauth/routes.ts +38 -15
- package/src/console/quota/refresh.ts +19 -0
- package/src/console/updates/routes.ts +162 -4
- package/src/main.ts +3 -0
- package/src/network/http2-bidi.ts +85 -0
- package/src/network/outbound-fetch.ts +1 -26
- package/src/network/pool/agent.ts +478 -460
- package/src/network/pool/resolver.ts +1104 -544
- package/src/network/pool-health-machine.ts +12 -5
- package/src/observability/payload-capture.ts +344 -324
- package/src/persistence/db-pg.ts +9 -3
- package/src/persistence/db-sqlite.ts +497 -495
- package/src/persistence/health-event-flush.ts +137 -0
- package/src/persistence/migrate.ts +181 -129
- package/src/persistence/schema.ts +1360 -1295
- package/src/persistence/settings-revision.ts +25 -0
- package/src/persistence/shared-cache.ts +217 -0
- package/src/persistence/stores/share-store.ts +556 -528
- package/src/persistence/usage-flush.ts +61 -1
- package/src/protocol/canonical-model.ts +23 -1
- package/src/protocol/response/chat.ts +143 -10
- package/src/protocol/response/omp-tool-call-markup.ts +221 -0
- package/src/providers/default-registry.ts +173 -1
- package/src/providers/discovery/openai-model-discovery.ts +39 -3
- package/src/providers/discovery/openrouter-free-roster.ts +98 -0
- package/src/providers/discovery/probing-service.ts +1022 -1001
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +39 -0
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +913 -914
- package/src/providers/integrations/buddy/buddy-conversation-headers.ts +18 -5
- package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +4 -0
- package/src/providers/integrations/buddy/codebuddy/provider.ts +180 -175
- package/src/providers/integrations/buddy/codebuddy/shared.ts +15 -6
- package/src/providers/integrations/buddy/workbuddy/provider.ts +206 -204
- package/src/providers/integrations/buddy/workbuddy/shared.ts +3 -3
- package/src/providers/integrations/claude/claude.ts +606 -582
- package/src/providers/integrations/cline/cline-quota.ts +18 -16
- package/src/providers/integrations/cline/cline.ts +539 -468
- package/src/providers/integrations/commandcode/commandcode.ts +675 -541
- package/src/providers/integrations/commandcode/discovery.ts +116 -0
- package/src/providers/integrations/commandcode/quota.ts +160 -0
- package/src/providers/integrations/cursor/cursor-auth.ts +418 -0
- package/src/providers/integrations/cursor/cursor-catalog.ts +368 -0
- package/src/providers/integrations/cursor/cursor-http2.ts +300 -0
- package/src/providers/integrations/cursor/cursor-identity.ts +92 -0
- package/src/providers/integrations/cursor/cursor-request.ts +471 -0
- package/src/providers/integrations/cursor/cursor-session-manager.ts +281 -0
- package/src/providers/integrations/cursor/cursor-shared.ts +108 -0
- package/src/providers/integrations/cursor/cursor.ts +960 -0
- package/src/providers/integrations/cursor/protocol/framing.ts +129 -0
- package/src/providers/integrations/cursor/protocol/messages.ts +2355 -0
- package/src/providers/integrations/cursor/protocol/struct.ts +305 -0
- package/src/providers/integrations/github/github.ts +4 -4
- package/src/providers/integrations/hermes.ts +79 -8
- package/src/providers/integrations/kilo/kilo-discovery.ts +10 -1
- package/src/providers/integrations/kilo/kilo.ts +153 -146
- package/src/providers/integrations/opencode/provider.ts +532 -538
- package/src/providers/integrations/openrouter/provider.ts +139 -281
- package/src/providers/integrations/qoder/qoder-catalog.ts +450 -0
- package/src/providers/integrations/qoder/qoder-oauth.ts +310 -257
- package/src/providers/integrations/qoder/qoder-realm.ts +106 -0
- package/src/providers/integrations/qoder/qoder-virtual.ts +77 -0
- package/src/providers/integrations/qoder/qoder.ts +865 -730
- package/src/providers/integrations/trae/trae-catalog.ts +190 -0
- package/src/providers/integrations/trae/trae-headers.ts +149 -0
- package/src/providers/integrations/trae/trae-oauth.ts +773 -0
- package/src/providers/integrations/trae/trae-protocol.ts +400 -0
- package/src/providers/integrations/trae/trae-realm.ts +220 -0
- package/src/providers/integrations/trae/trae.ts +458 -0
- package/src/providers/operations/account-health-service.ts +107 -10
- package/src/providers/operations/client-versions.ts +133 -6
- package/src/providers/operations/provider-catalog-seeder.ts +95 -86
- package/src/providers/operations/provider-credential-service.ts +46 -7
- package/src/providers/provider-contracts.ts +76 -0
- package/src/providers/provider-metadata.ts +78 -6
- package/src/providers/provider-model-definition.ts +373 -349
- package/src/security/api-key-auth.ts +126 -8
- package/src/transport/contracts.ts +3 -0
- package/src/transport/dispatch/attempt-finalize.ts +32 -1
- package/src/transport/dispatch/attempt-loop.ts +530 -515
- package/src/transport/dispatch/generation.ts +88 -21
- package/src/transport/dispatch/leases.ts +99 -2
- package/src/transport/dispatch/proxy-request.ts +60 -3
- package/src/transport/dispatch/streaming/finalize.ts +16 -1
- package/src/transport/dispatch/streaming/stream.ts +22 -2
- package/src/transport/dispatch/upstream.ts +19 -1
- package/src/transport/guards/auth-guard.ts +26 -1
- package/src/transport/guards/body-policy.ts +5 -4
- package/src/transport/request/preparer.ts +103 -0
- package/src/transport/request/state.ts +14 -0
- package/src/transport/routing/plan-gate.ts +45 -0
- package/src/transport/routing/route-catalog.ts +799 -777
- package/src/transport/routing/route-model.ts +52 -1
- package/src/transport/routing/router.ts +51 -0
- package/dist/dashboard/assets/BannedPage-QhvbJB9o.js +0 -1
- package/dist/dashboard/assets/BannedPage-QhvbJB9o.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-Bcy150Jo.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-DyNXefph.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-Cak0ljnO.js +0 -1
- package/dist/dashboard/assets/CombosPage-Cak0ljnO.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-CATpAEOz.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-D6jEU7nL.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-CZkpn0a7.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-BJlMVN4U.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-Br3CXEau.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CQxXbo2g.js +0 -1
- package/dist/dashboard/assets/OverviewPage-CQxXbo2g.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage--0RBNh99.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage--0RBNh99.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-paOCq8I0.js +0 -1
- package/dist/dashboard/assets/ProviderIcon-paOCq8I0.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-1M-C3mbu.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-1M-C3mbu.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-CXiumA53.js +0 -7
- package/dist/dashboard/assets/ProxyPage-CXiumA53.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BGDIfIYP.js +0 -1
- package/dist/dashboard/assets/QuotaPage-BGDIfIYP.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-BHW4Zt06.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-VOYC_lIa.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DpOTnGuH.js +0 -1
- package/dist/dashboard/assets/SortableList-DpOTnGuH.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-BNIDLiU6.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BAFaSDQV.js +0 -56
- package/dist/dashboard/assets/UsagePage-BAFaSDQV.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-BETfaMYZ.js.gz +0 -0
- package/dist/dashboard/assets/app-BLCvGdzb.css +0 -2
- package/dist/dashboard/assets/app-BLCvGdzb.css.gz +0 -0
- package/dist/dashboard/assets/assert-7J6_LVD3.js +0 -1
- package/dist/dashboard/assets/assert-7J6_LVD3.js.gz +0 -0
- package/dist/dashboard/assets/badge-BTyGk_DL.js.gz +0 -0
- package/dist/dashboard/assets/banner-bujTWYM4.js.gz +0 -0
- package/dist/dashboard/assets/card-B0Bnx5CA.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-DE2ug812.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-R_rArH8S.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BWIP_EvW.js.gz +0 -0
- package/dist/dashboard/assets/drawer-BKcgVugF.js.gz +0 -0
- package/dist/dashboard/assets/entry-7dpgvpJ3.js +0 -4
- package/dist/dashboard/assets/entry-7dpgvpJ3.js.gz +0 -0
- package/dist/dashboard/assets/entry-kTiTFrvh.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-Booc5mNe.js.gz +0 -0
- package/dist/dashboard/assets/index-D70pChfn.js.gz +0 -0
- package/dist/dashboard/assets/inline-D1TCqM2D.js.gz +0 -0
- package/dist/dashboard/assets/input-B9oyU93y.js.gz +0 -0
- package/dist/dashboard/assets/layout-BArzXirQ.js.gz +0 -0
- package/dist/dashboard/assets/list-row-BVZzaoHF.js.gz +0 -0
- package/dist/dashboard/assets/live-EmuIayqp.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-CSPQ9xB0.js.gz +0 -0
- package/dist/dashboard/assets/routing-BExgxxBU.js.gz +0 -0
- package/dist/dashboard/assets/select-C9mMoEpJ.js +0 -41
- package/dist/dashboard/assets/select-C9mMoEpJ.js.gz +0 -0
- package/dist/dashboard/assets/settings-C4_Gn_wq.js +0 -1
- package/dist/dashboard/assets/settings-C4_Gn_wq.js.gz +0 -0
- package/dist/dashboard/assets/sliders-horizontal-ClG7dBeJ.js +0 -1
- package/dist/dashboard/assets/sliders-horizontal-ClG7dBeJ.js.gz +0 -0
- package/dist/dashboard/assets/stack-Ca5HxI5i.js.gz +0 -0
- package/dist/dashboard/assets/state-CzUPfLXo.js.gz +0 -0
- package/dist/dashboard/assets/switch-DOUIky_i.js.gz +0 -0
- package/dist/dashboard/assets/toast-C76WrMhc.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-D87FZwH0.js.gz +0 -0
- package/src/network/tls/bun-client-hello.ts +0 -112
- /package/dist/dashboard/assets/{app-Cjq7nrwu.js → app-C-Y4oZT0.js} +0 -0
- /package/dist/dashboard/assets/{app-Cjq7nrwu.js.gz → app-C-Y4oZT0.js.gz} +0 -0
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.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{t as u}from"./check-D69FzdvC.js";import{n as d,t as f}from"./select-C9mMoEpJ.js";import{t as p}from"./circle-alert-CntYHV5v.js";import{t as m}from"./circle-check-BU3v_mFW.js";import{_ as h,a as g,g as _,i as v,r as y,t as b,v as x}from"./toast-C76WrMhc.js";import{t as S}from"./cog-CdWhsajs.js";import{t as C}from"./copy-ngmQ9zcZ.js";import{t as w}from"./download-A0SW9OCW.js";import{t as T}from"./eye-off-Bk5g2luF.js";import{t as E}from"./eye-C_hawfH4.js";import{t as D}from"./gauge-BbIMy7MB.js";import{t as O}from"./image-BPaouViG.js";import{a as k,n as A,r as j,t as M}from"./state-CzUPfLXo.js";import{t as N}from"./key-round-UkavsGxp.js";import{t as ee}from"./layers-2-glBbjl.js";import{n as P,t as F}from"./dialog-BWIP_EvW.js";import{t as I}from"./pencil-768ysRAr.js";import{t as te}from"./plus-DIdX_g-x.js";import{t as ne}from"./power-off-Yjw9GMJh.js";import{t as re}from"./refresh-cw-BqJFk4sU.js";import{t as ie}from"./rotate-ccw-CufcqITi.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./trash-Cppn5c3R.js";import{t as se}from"./wrench-B6E1oEuY.js";import{w as ce}from"./assert-7J6_LVD3.js";import{o as le,t as L}from"./query-keys-D7wX2vM5.js";import{E as R,F as ue,S as de,T as fe,X as pe,Y as me,Z as he,_ as ge,a as _e,b as ve,c as ye,d as z,f as be,g as xe,h as Se,l as Ce,m as we,o as Te,p as Ee,r as De,t as Oe,u as ke,v as B,w as Ae,x as je,y as Me}from"./entry-7dpgvpJ3.js";import{n as V,r as Ne,t as H}from"./card-B0Bnx5CA.js";import{n as Pe}from"./download-dRFo5_Wu.js";import{f as U,i as Fe,l as W,n as Ie,r as G,s as Le}from"./tokens-DDxMbSRL.js";import{a as Re}from"./numbers-CFL4_Dqc.js";import{t as K}from"./badge-BTyGk_DL.js";import{n as q}from"./input-B9oyU93y.js";import{t as ze}from"./ProviderIcon-paOCq8I0.js";import{t as Be}from"./switch-DOUIky_i.js";import{t as J}from"./stack-Ca5HxI5i.js";import{n as Y,t as Ve}from"./inline-D1TCqM2D.js";import{i as He}from"./quota-DZGyp0N5.js";import{t as Ue}from"./list-row-BVZzaoHF.js";import{c as We,l as Ge,m as Ke}from"./routing-BExgxxBU.js";import{o as X,s as qe,t as Je}from"./HealthEventsModal-CZkpn0a7.js";import{r as Ye}from"./privacy-mode-GM8bej85.js";import{n as Xe,t as Ze}from"./AccountCooldown-ChpdzxRH.js";import{t as Qe}from"./use-timeout-BwcBBRrT.js";import{t as $e}from"./banner-bujTWYM4.js";var et=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`}]]),tt=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),nt=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`}]]),rt=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`}]]),it=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`}]]),at=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`}]]),ot=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`}]]),st=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`}]]),ct=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function lt(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function ut({to:e,label:t}){let n=me();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)(ut,{...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:g(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function ft(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function pt(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 mt={fallback:`Failover`,roundRobin:`Round robin`},ht=new Set([`inferhub`,`cline`]);function gt(e,t){let n=Ge(e),r=Ke(),[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=pt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=pt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=pt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=pt(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 _t=50,vt=100;function yt(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 bt({children:e,action:t}){return(0,Q.jsx)(Ue,{actions:t,children:e})}function xt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=gt(e,r),[a,o]=(0,Z.useState)(!1),s=ht.has(e),c=yt(Oe,n.codex,n.claude),u=c.some(e=>e.value===i.userAgent)?c:[...c,{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 d=i.roundRobinEnabled?`${mt.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:mt.fallback,p=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,m=i.maxInflight===null,h=m?51:Math.min(51,Math.max(1,i.maxInflight)),g=m?`∞`:String(i.maxInflight),_=i.maxInflightPerProxy===null,v=_?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),x=_?`∞`:String(i.maxInflightPerProxy),S=i.skipProxy,C=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},w=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;b.success(`Client identity updated`,t)},T=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Routing Strategy`,subtitle:p,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.jsx)(bt,{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)(y,{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:()=>C(-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)(y,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(te,{size:14}),onClick:()=>C(1)})]}):null,(0,Q.jsx)(Be,{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)(at,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(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)(bt,{action:(0,Q.jsx)(Be,{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)(et,{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:`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)(f,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:w}):(0,Q.jsx)(f,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:T,options:[{value:T,label:T}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`Sent when the provider has no identity of its own.`:`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)(D,{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:[`Shared provider ceiling. One step past `,_t,` 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":m?`true`:void 0,min:1,max:51,step:1,value:h,"aria-valuetext":m?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>_t?null:Math.round(t))},style:{"--slider-pct":`${h/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:g,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(vt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${m?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${S?` 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)(st,{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)(y,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!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":_?`true`:void 0,min:1,max:51,step:1,disabled:S,value:v,"aria-valuetext":_?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>_t?null:Math.round(t))},style:{"--slider-pct":`${v/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:S,value:x,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(vt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${_?`text-status-success`:``}`})]}),(0,Q.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:S?`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 ${_t} is unlimited.`})]}),(0,Q.jsx)(F,{open:a,onClose:()=>o(!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.`})]})}),s&&(0,Q.jsxs)(Y,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(nt,{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 St({providerId:e}){let t=gt(e,!1),n=X(),r=We(e),i=(0,Z.useMemo)(()=>wt(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)(D,{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`})]}),(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:Tt(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 `,Tt(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 ${Tt(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 ${Tt(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)(Be,{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)(Ct,{providerId:e})]})}function Ct({providerId:e}){let{enabled:t,setEnabled:n}=Ye(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)(T,{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)(Be,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function wt(e,t){let n=0,r=0,i=0,a=!1;for(let o of e)if(o.provider===t&&o.active&&(i+=1,o.quota!==null))for(let e of o.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,a=!0)}return i>0&&a?{accounts:i,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function Tt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Et({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:v({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(tt,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}var Dt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Ot=new Set([`quota_fetch_failed`]);function kt(e){return e===void 0||e.length===0?!1:!Ot.has(e)}function At(e){return e===`oauth`?`Re-login required`:`Replace API key`}function jt(e,t){return e===`auth_invalidated`?At(t):Dt[e]??e}async function Mt(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 Nt=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Pt=[`refresh`,`refreshToken`,`refresh_token`],Ft=[`credentialKind`,`providerId`,`accessToken`],It=[`accounts`,`items`,`connections`],Lt=[`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 Rt(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function zt(e){for(let t of Nt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Rt(e);if(t)for(let e of Nt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Bt(e){for(let t of Lt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Rt(e);if(t)for(let e of Lt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Vt(e){let t=e=>Pt.some(t=>typeof e[t]==`string`||typeof e[t]==`number`);if(t(e))return!0;let n=Rt(e);return n?t(n):!1}function Ht(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 Ut(e){let t=Ht(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 Wt(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 Gt(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}function Kt(e){let t=e.trim(),n=$(Gt(t))??Wt(t);return n&&Vt(n)?`oauth`:Ht((n?zt(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function qt(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 Jt(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 Yt(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&Ft.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`&&Vt(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=zt(e),r=Vt(e)?`oauth`:Kt(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Bt(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function Xt(e){for(let t of It){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 Zt(e){let t=e.trim();if(!t)return[];let n=Gt(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return qt(e)?[Jt(t,e)]:e.map(Yt)}else{let e=$(n);if(e){let t=Xt(e);return t?t.map(Yt):[Yt(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)return Qt(r[0]);let i=Wt(t);return i&&(zt(i)||Object.keys(i).length===r.length)?[Yt(i)]:r.flatMap(Qt)}function Qt(e){let t=$(Gt(e));if(t){let e=Xt(t);return e?e.map(Yt):[Yt(t)]}return[{value:e,kind:Kt(e)}]}function $t(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 en(e){return e===`active`?0:e===`cooldown`?2:3}function tn(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()}`:He(e,!1)}function nn({cooldowns:e,reason:t}){if(!e)return null;let n=He(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(K,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function rn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function an(e){return e.credentialKind===`oauth`?`blue`:`ok`}function on({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=Ze(e);if(e.status===`disabled`){let t=rn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError,children:At(e.credentialKind)}):kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{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)(K,{tone:an(e),dot:!0,children:[`Active`,rn(e)?` - ${rn(e)}`:``]}),kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{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)(K,{tone:`warn`,dot:!0,children:[`Cooldown`,rn(e)?` - ${rn(e)}`:``,` `,e.cooldownUntil?`(${He(e.cooldownUntil)})`:``]}),kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(K,{tone:`disabled`,children:`Disabled`})}function sn({windows:e}){if(e===void 0||e.length===0)return null;let t=0,n=0,r=!1,i=null;for(let a of e){if(a.accounting!==`pooled`){typeof a.remainingPercent==`number`&&Number.isFinite(a.remainingPercent)&&(i=i===null?a.remainingPercent:Math.min(i,a.remainingPercent));continue}let e=typeof a.limit==`number`&&Number.isFinite(a.limit)?a.limit:null,o=typeof a.remaining==`number`&&Number.isFinite(a.remaining)?a.remaining:e!==null&&typeof a.used==`number`&&Number.isFinite(a.used)?e-a.used:null;o!==null&&e!==null&&(t+=Math.max(0,o),n+=e,r=!0)}let a=null;return r?a=`${cn(t)} of ${cn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===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":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${cn(t)} credits available of ${cn(n)}`:`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`}),a]})}function cn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function ln({providerId:e,account:t,onClose:n}){let r=R(),[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{b.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)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{b.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;b.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)(y,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function un({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=R(),l=ge(),u=qe(t.id),d=t.status===`disabled`,f=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,p=Number.isFinite(f)&&f>Date.now(),m=t.status===`cooldown`||p,[h,g]=(0,Z.useState)(!1),[v,S]=(0,Z.useState)(!1),[,C]=(0,Z.useState)(0),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(``),O=Ye(e),k=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),A=O.enabled?`Mysterious accounts`:k,j=tn(t.tokenExpiresAt),M=Xe(t),ee=Math.max(p&&t.cooldownUntil?f:0,M??0);(0,Z.useEffect)(()=>{if(ee<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[ee]);let P=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>b.success(`Account renamed`,n),onError:e=>b.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:d?.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 ${A}`,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:w?(0,Q.jsx)(q,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P(),e.key===`Escape`&&T(!1)},onBlur:P,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:A}),(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 ${A}`,onClick:()=>{D(t.label??``),T(!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)(on,{account:t}),j?(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:j,children:j}):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)(sn,{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 no longer carry 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:[(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${A}`,onClick:()=>g(!0),title:`View Health & Error History`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(_,{size:12,className:`animate-spin`}):(0,Q.jsx)(x,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${A}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?b.success(`Account test passed`,A):b.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>b.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(N,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${A}`,onClick:()=>S(!0),title:`Replace API key`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:d?(0,Q.jsx)(rt,{size:12}):(0,Q.jsx)(ne,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${A}`:`Disable ${A}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>b.success(n?`Account enabled`:`Account disabled`,A),onError:e=>b.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(ie,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${A}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,(0,Q.jsx)(y,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(oe,{size:12}),label:`Delete`,"aria-label":`Delete ${A}`,onClick:()=>s(t),title:`Delete account`})]})]}),h&&(0,Q.jsx)(Je,{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},onClose:()=>g(!1)}),v&&(0,Q.jsx)(ln,{providerId:e,account:t,onClose:()=>S(!1)})]})}var dn=[{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 fn(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=en(e.status)-en(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 pn({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ce(),s=R(),c=ge(),l=Ce(),u=We(e).data??new Map,p=X(),m=(0,Z.useMemo)(()=>{let t=new Map;for(let n of p.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[p.data,e]),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(new Set),[S,C]=(0,Z.useState)(`added-asc`),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),j=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!k)return;let e=e=>{j.current&&!j.current.contains(e.target)&&A(!1)},t=e=>{e.key===`Escape`&&A(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[k]);let M=h.trim().toLowerCase(),N=(0,Z.useMemo)(()=>M?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return M.split(/\s+/).every(e=>t.includes(e))}):t,[t,M]),ee=(0,Z.useMemo)(()=>{let e=S.slice(0,S.lastIndexOf(`-`)),t=S.endsWith(`-desc`)?-1:1,n=[...N];return n.sort((n,r)=>t*fn(n,r,e)),n},[N,S]),P=(0,Z.useMemo)(()=>t.filter(e=>_.has(e.id)),[t,_]),F=N.length>0&&N.every(e=>_.has(e.id)),I=P.some(e=>e.status===`disabled`),te=P.some(e=>e.status!==`disabled`),re=P.length===0,se=(e,t)=>{v(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},de=()=>{v(e=>{let t=new Set(e);if(F)for(let e of N)t.delete(e.id);else for(let e of N)t.add(e.id);return t})},fe=async(e,t)=>{if(P.length===0)return;E(!0);let n=await Promise.allSettled(P.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;E(!1),r===0?b.success(`${e} complete`,`${i} account${i===1?``:`s`}`):b.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},pe=()=>fe(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),me=async()=>{if(t.length===0)return;E(!0);let e=await Mt(t,3,e=>le(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`})),n=0,r=0;for(let t of e)t.status===`fulfilled`&&t.value?.ok?n+=1:r+=1;await Promise.all([o.invalidateQueries({queryKey:L.quota.all}),o.invalidateQueries({queryKey:L.providers.all})]),E(!1),r===0?b.success(`Test complete`,`${n} passed`):n===0?b.error(`Test failed`,`${r} account${r===1?``:`s`} failed`):b.error(`Test partially failed`,`${n} passed, ${r} failed`)},he=t=>fe(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),_e=async()=>{if(P.length!==0){E(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:P.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Pe(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),b.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){b.error(`Export failed`,e.message??`Unable to export accounts`)}finally{E(!1)}}};return(0,Q.jsxs)(J,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative min-w-20 flex-[1_1_10rem]`,children:[(0,Q.jsx)(ae,{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)(q,{id:`accounts-search`,value:h,onChange:e=>g(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(x,{size:12}),disabled:T||t.length===0,onClick:me,"aria-label":`Test all accounts`,title:`Test every account, regardless of selection or filters`,children:`Test all`}),(0,Q.jsxs)(`div`,{ref:j,className:`relative`,children:[(0,Q.jsxs)(y,{size:`sm`,variant:`secondary`,disabled:T||re,"aria-expanded":k,"aria-haspopup":`menu`,"aria-label":re?`Select accounts to enable bulk actions`:`Bulk actions for ${P.length} selected accounts`,onClick:()=>A(e=>!e),children:[`Actions`,re?``:` (${P.length})`,(0,Q.jsx)(d,{size:12,"aria-hidden":`true`,className:`transition-transform ${k?`rotate-180`:``}`})]}),k&&!re?(0,Q.jsxs)(`div`,{role:`menu`,"aria-label":`Selected account actions`,className:`absolute left-0 top-full z-50 mt-1 flex w-64 popover-max flex-col gap-1 rounded-control border border-inner-border bg-popover-bg p-2 shadow-popout sm:left-auto sm:right-0`,children:[(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(ie,{size:12}),disabled:T,onClick:()=>{A(!1),pe()},children:`Recover`}),I?(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(rt,{size:12}),disabled:T,onClick:()=>{A(!1),he(!0)},children:`Enable`}):null,te?(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(ne,{size:12}),disabled:T,onClick:()=>{A(!1),he(!1)},children:`Disable`}):null,(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(w,{size:12}),disabled:T,onClick:()=>{A(!1),_e()},children:`Export JSON`}),(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`danger`,className:`w-full justify-start`,icon:(0,Q.jsx)(oe,{size:12}),disabled:T,onClick:()=>{A(!1),O(!0)},children:`Delete`}),(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,disabled:T,onClick:()=>{v(new Set),A(!1)},children:`Clear selection`})]}):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)(f,{size:`sm`,value:S,onValueChange:e=>C(e),options:dn,"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:F,onChange:de,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),r?(0,Q.jsx)(y,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(x,{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)(`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:ee.map(t=>(0,Q.jsx)(un,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:m.get(t.id),selected:_.has(t.id),onToggleSelect:se,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 `,N.length,` account`,N.length===1?``:`s`,M?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(ue,{open:D,onClose:()=>{T||O(!1)},onConfirm:async()=>{await fe(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await le(t,{method:`DELETE`}),o.removeQueries({queryKey:L.quota.account(e.id),exact:!0})}),v(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:L.providers.accounts(e)}),o.invalidateQueries({queryKey:L.providers.all}),o.invalidateQueries({queryKey:L.quota.all})])},title:`Delete ${P.length} account${P.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var mn=2097152,hn=mn/1048576;function gn({providerId:e,accounts:t,onClose:n}){let r=_e(),i=Te(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,p]=(0,Z.useState)(`auto`),m=Zt(s),h=m.length>1,g=m.length===1?m[0]:void 0,_=d===`auto`?g?.kind:d,x=g&&_===`jwt`?Ut(g.value):void 0,S=t.map(e=>e.label),C=h?$t(m,e,S):[],w=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}},T=r.isPending||l,E=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=Zt(e);if(t.length>1)b.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`;b.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{b.error(`Clipboard access denied`)}},D=e=>{if(e.size>mn){b.error(`File too large`,`Credential files must be ${hn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=Zt(n);if(r.length===0){b.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}b.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>b.error(`Could not read that file`),t.readAsText(e)},O=async()=>{if(m.length!==0){if(m.length===1){let t=m[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...w(t)}},{onSuccess:()=>{b.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>b.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=await i.mutateAsync({providerId:e,accounts:m.map((e,t)=>({label:C[t],...w(e)}))}),r=t.results.filter(e=>!e.ok),a=t.created;if(a>0&&b.success(`${a} account${a===1?``:`s`} added`,r.length>0?`${r.length} skipped`:void 0),r.length>0){let e=r.slice(0,5).map(e=>`${C[e.index]??e.index}: ${e.error??`rejected`}`).join(`
|
|
2
|
-
`);b.error(`${r.length} account${r.length===1?``:`s`} skipped`,e+(r.length>5?`\n…and ${r.length-5} more`:``))}a>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)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:T,children:`Cancel`}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,disabled:T||m.length===0,onClick:()=>void O(),children:T?`Connecting...`:h?`Add ${m.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!h&&(0,Q.jsx)(q,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:g?.identity??`${e} account`}),(0,Q.jsx)(f,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>p(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`}),h?(0,Q.jsxs)(K,{tone:`accent`,children:[`Detected: `,m.length,` accounts`]}):g?(0,Q.jsxs)(K,{tone:_===`oauth`||_===`jwt`?`accent`:`default`,children:[`Detected:`,` `,_===`oauth`?`OAuth`:_===`jwt`?`Static JWT`:`API key`,g.identity?` · ${g.identity}`:``]}):null,g&&_===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,x?` · expires ${new Date(x).toLocaleString()}`:` · no expiry claim`]}):null]}),(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.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>void E(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:v({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.jsx)(`input`,{type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,"aria-label":`Import credentials from a file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&D(t)}}),`Import file`]})]})]}),h&&(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:m.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:C[t]}),(0,Q.jsx)(K,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))})]})})}function _n(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}`}: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 vn({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=De(),d=Qe(),f=ce(),p=we(e),m=(0,Z.useRef)(null),h=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let t=setInterval(()=>{f.invalidateQueries({queryKey:L.providers.accounts(e)})},1500);return()=>clearInterval(t)},[f,e]),(0,Z.useEffect)(()=>{let e=p.data?.map(e=>e.id)??null;if(e!==null){if(m.current===null){m.current=new Set(e);return}h.current||e.find(e=>!m.current.has(e))!==void 0&&(h.current=!0,r.close(),b.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[p.data,r,i]);let g=()=>{r.close(),i(!1)},[v,x]=(0,Z.useState)(!1),S=()=>{x(!0),f.invalidateQueries({queryKey:L.providers.accounts(e)}).finally(()=>x(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){b.error(`Clipboard is empty`);return}c(e),b.success(`Pasted redirect URL`)}catch{b.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(F,{open:!0,onClose:g,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:g,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:S,disabled:l.isPending||v,title:`You already approved in the popup — check now instead of waiting`,children:v?`Checking…`:`Complete`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=_n(s);if(`error`in t){b.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),b.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>b.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)(_,{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)(y,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{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)(y,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function yn(e){try{return new URL(e).host}catch{return e}}function bn({providerId:e,parameters:t,onClose:n}){let r=je(),i=z(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,d]=(0,Z.useState)(!1),f=Qe();(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||(b.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let p=(0,Z.useRef)(null),[m,h]=(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?p.current=e:h(!0),()=>{let e=p.current;p.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(),b.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=p.current;e&&!e.closed&&e.close(),b.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),b.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)(y,{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)(_,{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)(y,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),f(()=>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:yn(a.verificationUri)}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(tt,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),f(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:m?`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)(_,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function xn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function Sn(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Cn({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)(f,{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)(q,{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 wn({providerId:e,providerName:t,fields:n,onClose:r}){let i=ke(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>xn(n)),d=(0,Z.useMemo)(()=>Sn(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)(y,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){b.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){b.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:()=>{b.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>b.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(_,{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)(Cn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(q,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(q,{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 Tn(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 En(e,t,n){let{title:r,detail:i}=Tn(e,t,n);return[r,i]}function Dn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function On(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var kn=[{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`}],An={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function jn(){return ct.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function Mn({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)(f,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:jn()})})}function Nn({providerId:e,provider:t,onClose:n}){let r=Ee(),i=B(),[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`),[p,m]=(0,Z.useState)(`auto`),[h,g]=(0,Z.useState)(`idle`),[v,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(Ln),T=a.trim(),E=T.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&T.length>e.length+1?T.slice(e.length+1):T,D=E!==T,O=()=>{E&&(g(`testing`),S(``),r.mutate({providerId:e,request:{modelId:E,wireFamily:u,reasoningEffort:p,serviceKind:`llm`}},{onSuccess:e=>{e.ok?g(`passed`):(g(`failed`),S(e.error??`Model probe failed`))},onError:e=>{g(`failed`),S(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)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:i.isPending||E.length===0,onClick:()=>{if(!E)return;let t=U(C.contextLimit),r=U(C.outputLimit);if(t===null||r===null){b.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[E],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:C.passthrough,image:C.passthrough?!0:C.image,reasoning:C.passthrough?!0:C.reasoning,toolCall:C.passthrough?!0:C.toolCall}},{onSuccess:()=>{b.success(`Custom model added`,`Sent to ${e}/${E}`),n()},onError:e=>b.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)(q,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),g(`idle`),S(``)},onKeyDown:e=>{e.key===`Enter`&&E.length>0&&O()},className:`flex-1`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:h===`testing`?(0,Q.jsx)(_,{size:13,className:`animate-spin`}):(0,Q.jsx)(x,{size:13}),disabled:r.isPending||E.length===0,onClick:O,className:`shrink-0`,children:h===`testing`?`Testing...`:`Test`})]}),D&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:E}),` (provider prefix removed).`]}),(0,Q.jsx)(f,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),g(`idle`),S(``)},options:l.map(e=>({value:e,label:Un(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)(Mn,{id:`add-model-thinking-effort`,value:p,onChange:e=>{m(e),g(`idle`),S(``)},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)(Rn,{draft:C,onChange:w,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:Un(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),h===`passed`&&(0,Q.jsx)($e,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),h===`failed`&&(0,Q.jsx)($e,{tone:`danger`,live:`alert`,children:v||`Model test failed.`})]})})}function Pn(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var Fn=String(G),In=String(Fe);function Ln(){return{...Pn(),contextLimit:Fn,outputLimit:In}}function Rn({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)(q,{label:`Context`,id:`${n}-context`,placeholder:Fn,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(q,{label:`Output`,id:`${n}-output`,placeholder:In,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===Fn&&e.outputLimit===In,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:Fn,outputLimit:In}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,W(G),` ctx ·`,` `,W(Fe),` 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 zn({providerId:e,model:t,onClose:n}){let r=fe(),[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)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=U(i.contextLimit),o=U(i.outputLimit);if(a===null||o===null){b.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=>b.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)(Rn,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Bn({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let d=Ee(),f=Me(),[g,v]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(null),D=Qe(),O=n===`llm`?lt(t.modelId,i===`auto`?null:i):t.modelId,A=`${e}/${O}`,j=n===`websearch`?`Searching…`:`Thinking…`,M=()=>{d.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(T({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=Tn(e,O,t.error);b.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;b.successRich(`${O} · END ${Re(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)(S,{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(`
|
|
3
|
-
`)||`No sample text in the response.`)},onError:t=>{T({ok:!1,latencyMs:0}),b.error(...En(e,O,t.message))}})},N=()=>{let n=!t.enabled;f.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>b.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>b.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:A,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:O}),(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-pill px-3 py-0.5 text-micro font-bold tracking-[0.04em]`,style:{...Hn(t.wireFamily)},children:Un(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:Dn(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:On(t.source)}):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)(y,{variant:`ghost`,size:`sm`,icon:g?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),"aria-label":`Copy ${A}`,title:`Copy ${A}`,onClick:()=>{navigator.clipboard?.writeText(A),v(!0),D(()=>v(!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)(E,{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)(se,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(h,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:Ie,"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)(p,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${W(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Le,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${W(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Le,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)(y,{variant:`secondary`,size:`sm`,disabled:d.isPending,onClick:M,"aria-label":`Test ${O}`,title:d.isPending?`Probing ${O}…`:w?.ok?`Last probe OK in ${Re(w.latencyMs)} — click to re-test`:w?`Last probe failed — click to retry`:`Test ${O}`,className:`flex-1 justify-center`,icon:d.isPending?(0,Q.jsx)(_,{size:12,className:`animate-spin`}):w?w.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(m,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(k,{size:12})}):(0,Q.jsx)(x,{size:12}),children:d.isPending?j:w?.ok?Re(w.latencyMs):w?`Fail`:`Test`}),(0,Q.jsx)(y,{variant:`ghost`,size:`sm`,disabled:f.isPending,onClick:N,icon:t.enabled?(0,Q.jsx)(ne,{size:12}):(0,Q.jsx)(rt,{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)(y,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(oe,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var Vn=(0,Z.memo)(Bn);function Hn(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 Un(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function Wn({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=ye(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),u=e=>e.enabled!==!1,d=kn.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)(Vn,{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:An.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,Q.jsxs)(`span`,{title:An.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,An.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,Q.jsx)(ue,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),b.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)(zn,{providerId:e,model:c,onClose:()=>l(null)})]})}function Gn(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function Kn(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function qn(){let{providerId:e}=pe(),[t]=he(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=xe(),s=Se(n),l=we(n),u=de(),d=de({silent:!0}),[f,p]=(0,Z.useState)(!1),m=be(),g=Ae(),_=ve(),v=ce(),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(!1),E=Ee(),[D,k]=(0,Z.useState)(``),[ee,P]=(0,Z.useState)(``),[I,ie]=(0,Z.useState)(null),ae=e=>`cartethyia:provider:${e}:thinking-effort`,se=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 ct.includes(n)?n:`auto`},[R,fe]=(0,Z.useState)(()=>se(n));(0,Z.useEffect)(()=>{if(!n)return;let e=se(n);e!==R&&fe(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(ae(n),R)},[n,R]);let[me,ge]=(0,Z.useState)(!1),[_e,ye]=(0,Z.useState)(!1),[z,Ce]=(0,Z.useState)(null),[Te,De]=(0,Z.useState)({}),[Oe,ke]=(0,Z.useState)({}),[B,je]=(0,Z.useState)(null),[Me,Pe]=(0,Z.useState)(!1),[U,Fe]=(0,Z.useState)(null),W=(0,Z.useRef)(null),Ie=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=W.current;W.current=null,e&&!e.closed&&e.close()},[]);let G=(o.data??[]).find(e=>e.providerId===n),Le=n===`opencode`||n===`cline`,Re=G===void 0?[`llm`]:Kn(G),K=[];for(let e of Re)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&K.push(e);(0,Z.useEffect)(()=>{if(G===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=K[0];if(e!==void 0&&K.includes(e)){i!==e&&a(e);return}!K.includes(i)&&t!==void 0&&a(t)},[G,r,i,K.join(`|`)]),(0,Z.useEffect)(()=>{Le&&G!==void 0&&G.supportsModelDiscovery!==!1&&Ie.current!==n&&(Ie.current=n,d.mutate(n))},[Le,d,n,G?.supportsModelDiscovery]);let q=l.data??[],Be=s.data??[],He=(()=>{let e=new Map;for(let t of Be){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))})(),Ue=He.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),We=He.filter(e=>e.serviceKind===`websearch`),Ge=He.filter(e=>e.serviceKind===`imageGeneration`),Ke=He.filter(e=>e.serviceKind===`videoGeneration`),X=K.includes(i)?i:K[0],qe=ee||We[0]?.modelId||``,Je=()=>{let e=D.trim();qe&&e&&(ie(null),E.mutate({providerId:n,request:{modelId:qe,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>ie({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>ie({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 catalog could not be read, so this page cannot resolve its provider.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,Q.jsx)(ut,{to:`/providers`,label:`Back to providers`})});if(!G)return(0,Q.jsx)(M,{icon:(0,Q.jsx)(it,{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)(ut,{to:`/providers`,label:`Back to providers`})});let Ye=q.filter(e=>e.status===`active`).length,Xe=e=>{let t=e===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?Qe():ge(!0);return}De(xn(t)),Ce(e)},Ze=()=>{if(z===null)return;let e=Sn(z===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[],Te);if(e.length>0){b.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=z;Ce(null),t===`browser`?Qe(Te):(ke(Te),ge(!0))},Qe=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,W.current=t),_.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:n})=>{let r=null;if(t&&!t.closed?(t.location.href=e,r=t):(r=window.open(e,`cartethyia-oauth`,`popup,width=720,height=820`),r&&(r.opener=null,W.current=r)),!r){b.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Fe({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),W.current===t&&(W.current=null),b.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(J,{gap:`16px`,children:[(0,Q.jsx)(dt,{title:`${G.label||G.displayName}${X?` (${Gn(X)})`:``}`,description:`${G.providerId}/${G.baseUrl?` · ${G.baseUrl}`:``}`,icon:(0,Q.jsx)(ze,{icon:G.providerId,name:G.label||G.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:G.isBuiltIn?(0,Q.jsx)(y,{variant:G.enabled?`danger`:`secondary`,icon:G.enabled?(0,Q.jsx)(ne,{size:13}):(0,Q.jsx)(rt,{size:13}),loading:g.isPending,onClick:()=>g.mutate({providerId:n,enabled:!G.enabled},{onSuccess:e=>b.success(e.enabled?`Provider enabled`:`Provider disabled`,G.label||G.displayName),onError:e=>b.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:G.enabled?`Disable provider globally`:`Enable provider globally`,children:G.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(Et,{provider:G}),X===`llm`?(0,Q.jsx)(xt,{providerId:n,clientVersion:G.clientVersion,routeIdentityVersions:G.routeIdentityVersions,userAgentEditable:ft(G)}):null,G.requiresAccount===!1?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Accounts`,icon:(0,Q.jsx)(et,{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)(Ne,{title:`Accounts`,subtitle:`${q.length} total · ${Ye} active · ${q.length-Ye} disabled`,icon:(0,Q.jsx)(et,{size:16}),action:(0,Q.jsxs)(Ve,{children:[G.oauthFlows?.browser&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(tt,{size:13}),disabled:_.isPending,onClick:()=>Xe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:_.isPending?`Starting...`:`Login with browser`}),G.oauthFlows?.device&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(N,{size:13}),onClick:()=>Xe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),G.oauthFlows?.import&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(w,{size:13}),onClick:()=>ye(!0),title:G.oauthFlows.browser||G.oauthFlows.device?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:G.oauthFlows.browser||G.oauthFlows.device?`Import credential`:`Add API key`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(te,{size:13}),onClick:()=>S(!0),children:`Add Account`})]})}),(0,Q.jsxs)(V,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(St,{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()}):q.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)(pn,{providerId:n,accounts:q,onDelete:e=>je(e),showGrokProbe:X===`llm`&&n===`grok`,grokProbePending:m.isPending,onGrokProbe:()=>{m.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;b.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>b.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]}),X===`llm`?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Models`,subtitle:`${Ue.length} model${Ue.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)(Mn,{id:`models-section-thinking-effort`,value:R,onChange:fe}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(re,{size:13,className:u.isPending||d.isPending?`animate-spin`:``}),disabled:u.isPending||d.isPending,onClick:()=>u.mutate(n),children:u.isPending||d.isPending?`Fetching...`:`Fetch models`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(oe,{size:13,className:f?`animate-spin`:``}),disabled:u.isPending||d.isPending||f||Ue.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=Ue.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){p(!0);try{let t=await le(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([v.invalidateQueries({queryKey:L.providers.models(n)}),v.invalidateQueries({queryKey:L.providers.all})]);let r=t.failures.length;b.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){b.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{p(!1)}}},children:f?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(te,{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()}):Ue.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)(Wn,{providerId:n,models:Ue,serviceKind:`llm`,thinkingEffort:R,searchCapable:G?.supportsWebSearch===!0})})]})}):X===`websearch`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(h,{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()}):We.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:qe,onChange:e=>{P(e.target.value),ie(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:We.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=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())},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)(y,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:Je,children:`Test search`}),I?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:I.ok?`var(--green)`:`var(--red)`},children:I.ok?`Search ok · ${I.latencyMs}ms · ${I.count??0} result(s)`:I.error??`Search failed.`}):null]}),I&&I.results&&I.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:I.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]})})]}):X===`imageGeneration`||X===`videoGeneration`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:Gn(X),subtitle:X===`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:X===`imageGeneration`?(0,Q.jsx)(O,{size:16}):(0,Q.jsx)(ot,{size:16})}),(0,Q.jsx)(V,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading ${Gn(X).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load ${Gn(X).toLowerCase()} models`,onRetry:()=>s.refetch()}):(X===`imageGeneration`?Ge:Ke).length===0?(0,Q.jsx)(M,{title:`No ${Gn(X)} models found`,message:`This provider advertises ${Gn(X)}, but no ${X} model is registered yet.`}):(0,Q.jsx)(Wn,{providerId:n,models:X===`imageGeneration`?Ge:Ke,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 ${Re.map(Gn).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),x&&(0,Q.jsx)(gn,{providerId:n,accounts:q,onClose:()=>S(!1)}),X===`llm`&&C?(0,Q.jsx)(Nn,{providerId:n,provider:G,onClose:()=>T(!1)}):null,(0,Q.jsx)(ue,{open:B!==null,onClose:()=>{Me||je(null)},onConfirm:async()=>{if(B){Pe(!0);try{let e=B.tenantId===null?`/global/accounts/${encodeURIComponent(B.id)}`:`/accounts/${encodeURIComponent(B.id)}`;await le(e,{method:`DELETE`}),v.removeQueries({queryKey:L.quota.account(B.id),exact:!0}),await Promise.all([v.invalidateQueries({queryKey:L.providers.accounts(n)}),v.invalidateQueries({queryKey:L.providers.healthEvents(n,B.id)}),v.invalidateQueries({queryKey:L.providers.all}),v.invalidateQueries({queryKey:L.quota.all})]),b.success(`Account deleted`,B.label||B.id.slice(0,8)),je(null)}catch(e){throw b.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Pe(!1)}}},title:`Delete account?`,message:`Delete "${B?.label||B?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),me&&(0,Q.jsx)(bn,{providerId:n,parameters:Oe,onClose:()=>{ge(!1),ke({})}}),z!==null&&(0,Q.jsx)(F,{open:!0,onClose:()=>Ce(null),title:z===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>Ce(null),children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,onClick:Ze,children:`Continue`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:z===`browser`?`Choose how ${G.label||G.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(Cn,{fields:z===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[],values:Te,idPrefix:`flow-${z}`,onChange:(e,t)=>De(n=>({...n,[e]:t}))})]})}),_e&&G?.oauthFlows?.import===!0&&(0,Q.jsx)(wn,{providerId:n,providerName:G.label||G.displayName,fields:G.oauthFlows.importFields,onClose:()=>ye(!1)}),U&&(0,Q.jsx)(vn,{providerId:n,authorizeUrl:U.authorizeUrl,state:U.state,popup:U.popup,onClose:e=>{W.current=null,Fe(null),e&&v.invalidateQueries({queryKey:L.providers.accounts(n)})}})]})}export{qn 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`},bai:{file:`bai`,ext:`svg`},cline:{file:`cline`,ext:`webp`},cerebras:{file:`cerebras`,ext:`webp`},qoder:{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`}};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{n as r,t as i}from"./select-C9mMoEpJ.js";import{a,r as o}from"./toast-C76WrMhc.js";import{t as s}from"./eye-off-Bk5g2luF.js";import{t as c}from"./eye-C_hawfH4.js";import{n as l,r as u,t as d}from"./state-CzUPfLXo.js";import{t as f}from"./dialog-BWIP_EvW.js";import{t as p}from"./plus-DIdX_g-x.js";import{t as m}from"./trash-Cppn5c3R.js";import{l as h}from"./query-keys-D7wX2vM5.js";import{t as g}from"./dialog-actions-B1axpEg7.js";import{C as _,J as v,S as ee,Z as y,a as b,et as x,g as S,h as C,i as w,m as T,s as E}from"./entry-7dpgvpJ3.js";import{n as D,r as O,t as k}from"./card-B0Bnx5CA.js";import{t as A}from"./badge-BTyGk_DL.js";import{n as j}from"./input-B9oyU93y.js";import{t as M}from"./ProviderIcon-paOCq8I0.js";import{t as N}from"./switch-DOUIky_i.js";import{t as P}from"./stack-Ca5HxI5i.js";import{n as F}from"./inline-D1TCqM2D.js";import{t as te}from"./list-row-BVZzaoHF.js";import{t as I}from"./privacy-mode-GM8bej85.js";import{r as L}from"./AccountCooldown-ChpdzxRH.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],i)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(j,{placeholder:`Header-Name`,value:e,onChange:e=>n(i,[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(i,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(i),children:(0,z.jsx)(m,{size:13})})]},i)),(0,z.jsxs)(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(p,{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=a(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),H=a(`block flex-1 p-6 no-underline text-inherit`),U=a(`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 r=w(),s=b(),c=ee(),l=_(),[u,d]=(0,R.useState)(``),[p,m]=(0,R.useState)(``),[g,v]=(0,R.useState)(``),[y,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),[T,E]=(0,R.useState)(!0),[D,O]=(0,R.useState)([]),[k,A]=(0,R.useState)(null),[M,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(g),[g]);(0,R.useEffect)(()=>{t&&(d(``),x(``),G(U),v(``),C(!1),E(!0),O([]),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.`)}},J=async()=>{if(!g.trim()){L({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),L(null),A(null);try{let e=ne(D),t=await l.mutateAsync({baseUrl:g.trim(),apiKey:y.trim(),wireFamily:W,cliIdentity:T,...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:h(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(f,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(o,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(o,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:M,children:M?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!u.trim()){A(`Display Name is required`);return}if(!p.trim()){A(`Provider ID (slug) is required`);return}if(!g.trim()){A(`Base URL is required`);return}let t=ne(D),i=p.trim().toLowerCase();P(!0),A(null);try{let e={providerId:i,label:u.trim(),baseUrl:g.trim(),wireFamily:W,compatibilityProfile:{cli_identity:T,...Object.keys(t).length>0?{extra_headers:t}:{}}};await r.mutateAsync(e),y.trim()&&await s.mutateAsync({providerId:i,request:{credentialKind:`api_key`,secret:y.trim()}}),S&&await c.mutateAsync(i),n()}catch(e){A(h(e,`Failed to create provider`))}finally{P(!1)}},className:`flex flex-col gap-6`,children:[k?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:k}):null,(0,z.jsx)(j,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:u,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:p,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:g,onChange:e=>v(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(o,{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)(i,{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)(o,{type:`button`,variant:`secondary`,disabled:B,onClick:()=>void J(),children:B?`Testing...`:`Test connection`}),(0,z.jsx)(o,{type:`button`,variant:`secondary`,onClick:()=>q(x),children:`Paste`})]}),I?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:a(`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)(N,{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)(N,{checked:T,onChange:E,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:D,onChange:O})]})})}function q({customProvider:e}){let t=E(),[n,r]=(0,R.useState)(!1),i=C(e.providerId),s=i.data?.length,c=T(e.providerId),l=c.data,u=Q(l??[]);return(0,z.jsxs)(k,{className:V,children:[(0,z.jsx)(se,{clientVersion:e.clientVersion}),(0,z.jsx)(v,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:a(H,`pr-20 min-h-38`),children:(0,z.jsxs)(F,{gap:`10px`,children:[(0,z.jsx)(M,{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}),(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)(oe,{counts:u,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,i.isError?(0,z.jsx)(A,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,z.jsx)($,{kind:`models`,isPending:i.isPending,isError:!1,hasData:!1}):s===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(o,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(m,{size:12}),onClick:()=>r(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(f,{open:n,onClose:()=>r(!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:h(t.error,`Delete failed`)}):null,(0,z.jsxs)(g,{children:[(0,z.jsx)(o,{variant:`secondary`,onClick:()=>r(!1),children:`Cancel`}),(0,z.jsx)(o,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>r(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function J({customProviders:e}){let[t,n]=(0,R.useState)(!1),[i,a]=(0,R.useState)(!1),[l,u]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function d(){u(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:d,"aria-expanded":!l,title:l?`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)(r,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:l?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(F,{gap:`8px`,children:[(0,z.jsx)(o,{size:`sm`,variant:`ghost`,icon:l?(0,z.jsx)(c,{size:13}):(0,z.jsx)(s,{size:13}),onClick:d,title:l?`Show custom providers`:`Hide custom providers`,children:l?`Show`:`Hide`}),(0,z.jsx)(o,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(p,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(o,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(p,{size:13}),onClick:()=>a(!0),children:`Custom OpenAI`})]})]}),l?null:e.length===0?(0,z.jsx)(k,{children:(0,z.jsxs)(D,{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:i,onClose:()=>a(!1)})]})}var Y=new Set([`inferhub`]),X=new Set([`grok`,`opencode`,`cline`,`hermes`,`commandcode`,`kilo`]),ae=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`]);function Z(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Q(e){return{active:e.filter(e=>e.status===`active`).length,cooldown:e.filter(e=>e.status===`cooldown`).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:L(e)}}function oe({counts:e,total:t}){return e.active>0||e.cooldown>0||e.cooling>0||e.disabled>0?(0,z.jsxs)(z.Fragment,{children:[e.active>0?(0,z.jsxs)(A,{tone:`ok`,dot:!0,children:[e.active,` Healthy`]}):null,e.cooldown>0?(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[e.cooldown,` Cooldown`]}):null,e.cooling>0?(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[e.cooling,` Cooling`]}):null,e.disabled>0?(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]}):(0,z.jsxs)(A,{tone:`warn`,dot:!0,children:[t,` Connected`]})}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 se({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 ce=(0,R.memo)(function({provider:e,serviceKind:t}){let n=Y.has(e.providerId.toLowerCase()),r=e.label||e.displayName,i=C(e.providerId),o=i.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=T(e.providerId),c=s.data,l=Q(c??[]);return(0,z.jsxs)(k,{className:V,children:[(0,z.jsx)(se,{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:a(`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)(v,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:H,children:(0,z.jsxs)(F,{gap:`10px`,children:[(0,z.jsx)(M,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:r}),(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)(oe,{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,i.isError?(0,z.jsx)(A,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,z.jsx)($,{kind:`models`,isPending:i.isPending,isError:!1,hasData:!1}):o===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function le(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var ue=`cartethyia.providerSectionsCollapsed`;function de(){try{let e=window.localStorage.getItem(ue),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var fe=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>X.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>Z(e)&&!X.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&&ae.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!ae.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)}];function pe(){let[e,t]=(0,R.useState)(de),n=S(),i=I(),f=i.enabled,p=e=>!f||e.configured===!0||e.requiresAccount===!1,m=(0,R.useMemo)(()=>n.data??[],[n.data]),g=(0,R.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&p(e))].sort(le),[m,f]),_=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`websearch`)&&p(e)),[m,f]),v=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`llm`)&&p(e)),[m,f]),[ee,b]=y(),C=ee.get(`tab`),w=C===`search`||C===`media`?C:`llm`,T=e=>{b(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},E=(0,R.useMemo)(()=>m.filter(e=>(W(e).includes(`imageGeneration`)||W(e).includes(`videoGeneration`))&&p(e)),[m,f]),A=(0,R.useMemo)(()=>[..._].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[_]),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(w===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:E}].filter(e=>e.providers.length>0);if(w===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:A}].filter(e=>e.providers.length>0);let e=v;return fe.map(t=>({...t,providers:e.filter(t.filter).sort(j)})).filter(e=>e.providers.length>0)},[v,A,E,w]),N=n.isPending&&!n.data?(0,z.jsx)(u,{label:`Loading providers...`}):n.isError?(0,z.jsx)(l,{message:h(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return N?(0,z.jsxs)(k,{children:[(0,z.jsx)(O,{title:`Providers`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsx)(D,{className:`flex flex-1`,children:N})]}):(0,z.jsx)(P,{gap:`24px`,children:(0,z.jsxs)(k,{children:[(0,z.jsx)(O,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsxs)(D,{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:()=>T(e),className:a(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,w===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`?` (${_.length})`:e===`media`?` (${E.length})`:` (${v.length})`]},e))}),(0,z.jsx)(o,{variant:`ghost`,size:`sm`,icon:f?(0,z.jsx)(s,{size:12}):(0,z.jsx)(c,{size:12}),onClick:()=>i.setEnabled(!f),title:f?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:f?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:w===`search`?`Fallback runs only when the model invokes Websearch`:w===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),w===`llm`?(0,z.jsx)(J,{customProviders:g}):null,M.length===0?(0,z.jsx)(k,{children:(0,z.jsx)(D,{children:(0,z.jsx)(d,{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(ue,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(r,{size:15,className:a(`mt-1 shrink-0 transition-transform`,i&&`-rotate-90`)}),(0,z.jsxs)(P,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:`text-body font-bold tracking-[-0.01em]`,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)(ce,{provider:e,serviceKind:w===`search`?`websearch`:w===`media`?W(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{pe as default};
|
|
Binary file
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./select-C9mMoEpJ.js";import{g as o,r as s,t as c,v as l}from"./toast-C76WrMhc.js";import{t as u}from"./download-A0SW9OCW.js";import{t as d}from"./eye-off-Bk5g2luF.js";import{t as f}from"./eye-C_hawfH4.js";import{t as p}from"./gauge-BbIMy7MB.js";import{a as m,n as h,r as g,t as _}from"./state-CzUPfLXo.js";import{t as v}from"./dialog-BWIP_EvW.js";import{t as y}from"./pencil-768ysRAr.js";import{t as b}from"./plus-DIdX_g-x.js";import{t as ee}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{S as w,_ as T,c as E,v as D,w as O}from"./assert-7J6_LVD3.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-D7wX2vM5.js";import{t as P}from"./useMutation-D87FZwH0.js";import{F as te,et as F}from"./entry-7dpgvpJ3.js";import{n as ne,r as re,t as ie}from"./card-B0Bnx5CA.js";import{n as ae}from"./download-dRFo5_Wu.js";import{t as I}from"./numbers-CFL4_Dqc.js";import{t as L}from"./badge-BTyGk_DL.js";import{n as R}from"./input-B9oyU93y.js";import{t as z}from"./switch-DOUIky_i.js";import{t as oe}from"./stack-Ca5HxI5i.js";import{n as se}from"./inline-D1TCqM2D.js";import{r as B,t as ce}from"./layout-BArzXirQ.js";import{i as le,n as ue}from"./privacy-mode-GM8bej85.js";import{n as V}from"./live-EmuIayqp.js";var de=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),fe=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),pe=1e6,me=1e8,he=5e6,ge=`sin1`,_e=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function ve(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:T(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function ye(){let e=O();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),c.success(`Proxy pool created`)},onError:e=>{c.error(`Could not create the proxy pool.`,j(e))}})}function be(){let e=O();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function xe(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function Se(){let e=O();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),c.success(`Proxy updated`)},onError:e=>{c.error(`Could not update the proxy pool.`,j(e))}})}function Ce(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:T(t)}),enabled:!!e,...A,refetchInterval:k.status})}function we(){let e=O();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),c.success(`Proxy pool recovered`)},onError:e=>{c.error(`Could not recover the proxy pool.`,j(e))}})}function Te(){let e=O();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),c.success(`Proxy pool deleted`)},onError:e=>{c.error(`Could not delete the proxy pool.`,j(e))}})}function Ee(){let e=O();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function De(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function Oe(){let e=O();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),c.success(`Health check complete`)},onError:e=>{c.error(`Health check failed.`,j(e))}})}function ke(){let e=O();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Ae(){let e=O();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),c.success(`Provider cooldowns cleared`)},onError:e=>{c.error(`Could not clear provider cooldowns.`,j(e))}})}var H=t(n(),1),U=r(),W={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},je=_e.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Me({onClose:e}){let t=be(),[n,r]=(0,H.useState)(`cloudflare`),[i,o]=(0,H.useState)(ge),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(``),[p,h]=(0,H.useState)(``),[g,_]=(0,H.useState)(null),y=W[n],b=l.trim().length>0&&(!y.needsAccount||d.trim().length>0);return(0,U.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,U.jsxs)(oe,{gap:`12px`,children:[(0,U.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,U.jsx)(F,{size:13,className:`shrink-0 mt-0.5`}),(0,U.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,y.label,` account and registers its URL (`,(0,U.jsx)(`code`,{children:y.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,U.jsx)(a,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:D.map(e=>({value:e,label:W[e].label}))}),(0,U.jsx)(R,{label:y.tokenLabel,id:`relay-token`,type:`password`,value:l,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),y.needsAccount?(0,U.jsx)(R,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,U.jsx)(R,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>h(e.target.value)}),y.hasRegion?(0,U.jsx)(a,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>o(e),options:je}):null,y.hasRegion?(0,U.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,U.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,U.jsx)(s,{variant:`primary`,size:`sm`,onClick:()=>{b&&t.mutate({target:n,token:l.trim(),...y.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},...y.hasRegion?{region:i}:{}},{onSuccess:e=>{_(e.relayUrl),u(``),c.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>c.error(j(e,`Relay deploy failed.`))})},disabled:!b||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),g?(0,U.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,U.jsx)(`code`,{children:g})]}):null]}),t.isError?(0,U.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,U.jsx)(m,{size:13,className:`shrink-0 mt-0.5`}),(0,U.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Ne(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Pe(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Fe(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Pe(e,t,r(e)),o=Pe(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function G(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var K=[`http`,`https`,`socks5`];function q(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Ie(e,t){let n=e.trim();return t===null||q(n)?n:`${t}://${n}`}function J(e){return e.find(e=>e.trim()!==``)}function Y(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var Le=1024**3;function Re(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*Le))}function X(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var ze=4,Be=`cartethyia_proxy_test_payload`,Ve=`cartethyia_proxy_check_results`,He=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],Ue=`opencode`,We=4,Ge=`Mysterious Proxy`;function Z(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function Ke(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function Q(e){return e.label||Ke(e).name||e.id}var $=1024**3;function qe(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Je(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Ye=[{value:String(pe),label:`1 MB`},{value:String(he),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(me),label:`100 MB`}];function Xe({pool:e,onClose:t,actionsRef:n}){let r=Se(),i=De(),a=Oe(),[u,d]=(0,H.useState)(e.label??``),[f,p]=(0,H.useState)(e.family??``),[m,h]=(0,H.useState)(e.endpoint??``),[g,_]=(0,H.useState)(String(e.maxInflight??10)),[v,y]=(0,H.useState)(String(e.weight??100)),[b,ee]=(0,H.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/$*1e3)/1e3):``),[x,S]=(0,H.useState)(null),[C,w]=(0,H.useState)(!1),T=m.trim()===e.endpoint,E=async()=>{w(!0),S(null);try{if(T){let t=await a.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;S({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:m.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:Ue,targets:t}),r=n?.result;if(!r){S({ok:!1,message:`Probe returned no result`});return}let o=r.status===`allowed`||r.status===`throttled`;S({ok:o,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){S({ok:!1,message:j(e,`Connection failed`)})}finally{w(!1)}},D=Re(b),O=async()=>{await r.mutateAsync({poolId:e.id,request:{...u.trim()===e.label?{}:{label:u.trim()||void 0},...f.trim()===(e.family??``)?{}:{family:f.trim()||null},...m.trim()!==e.endpoint&&m.trim()!==``?{endpoint:m.trim()}:{},...Number(g)===e.maxInflight?{}:{maxInflight:Number(g)},...Number(v)===e.weight?{}:{weight:Number(v)},...D===(e.quotaBytes??null)?{}:{quotaBytes:D}}}),c.success(`Proxy updated`),t()};return(0,H.useEffect)(()=>{n?.((0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(s,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,U.jsx)(s,{variant:`primary`,size:`sm`,disabled:r.isPending||!m.trim(),onClick:()=>void O(),children:`Save`})]}))}),(0,U.jsxs)(oe,{gap:`12px`,children:[(0,U.jsx)(`div`,{children:(0,U.jsx)(R,{label:`Name`,value:u,onChange:e=>d(e.target.value)})}),(0,U.jsx)(`div`,{children:(0,U.jsx)(R,{label:`Family`,value:f,placeholder:`e.g. residential-id`,onChange:e=>p(e.target.value)})}),(0,U.jsx)(`div`,{children:(0,U.jsx)(R,{label:`Endpoint`,value:m,onChange:e=>h(e.target.value),className:`font-mono tabular-nums`})}),(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,U.jsx)(`div`,{children:(0,U.jsx)(R,{label:`Max concurrent`,type:`number`,min:1,value:g,onChange:e=>_(e.target.value)})}),(0,U.jsx)(`div`,{children:(0,U.jsx)(R,{label:`Weight`,type:`number`,min:1,value:v,onChange:e=>y(e.target.value)})})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(R,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>ee(e.target.value)}),(0,U.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:D===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${I(D)} is exceeded.`})]}),x&&(0,U.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${x.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:x.message}),(0,U.jsx)(`div`,{children:(0,U.jsx)(s,{variant:`secondary`,size:`sm`,disabled:C,icon:C?(0,U.jsx)(o,{size:13,className:`animate-spin`}):(0,U.jsx)(l,{size:13}),onClick:()=>void E(),children:C?`Testing…`:`Test connection`})})]})}function Ze({endpoint:e,chip:t,onChipChange:n}){return(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,U.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),K.map(r=>{let i=t===r;return(0,U.jsxs)(s,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,U.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Ie(e??``,t)]})]})}function Qe({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=ye(),a=xe(),o=De(),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(``),[p,m]=(0,H.useState)(``),[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)([]),[y,b]=(0,H.useState)({}),[ee,x]=(0,H.useState)({}),[S,C]=(0,H.useState)(!1),[w,T]=(0,H.useState)(null),E=l.split(`
|
|
2
|
-
`).map(e=>e.trim()).filter(Boolean),D=J(E),O=(0,H.useMemo)(()=>w===null||D===void 0?E:E.map((e,t)=>e===D&&t===0?Ie(e,w):e),[E,w,D]),k=E.length>100,A=Re(p),M=(0,H.useMemo)(()=>O.map(e=>({kind:Y(e),endpoint:e})),[O]),N=async()=>{try{let e=await navigator.clipboard.readText();e&&u(t=>t?`${t}\n${e}`:e)}catch{c.error(`Paste failed`,`Clipboard access denied`)}},P=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s)…`]);try{let e=await a.mutateAsync(M),t=e.map(e=>{let t=e.result.status===`healthy`||e.result.status===`reachable`,n=e.result.latencyMs===void 0?``:` · ${e.result.latencyMs}ms`,r=e.result.egressIp?` · ${e.result.egressIp}`:``,i=t?``:` · ${e.result.errorMessage??e.result.status}`;return`${t?`OK `:`FAIL`} ${e.endpoint}${n}${r}${i}`}),n=e.filter(e=>e.result.status===`healthy`||e.result.status===`reachable`).length;x(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n}),v([`${n}/${e.length} reachable`,...t]),n===e.length?c.success(`All ${e.length} proxies reachable`):c.error(`${e.length-n} of ${e.length} proxies failed`)}catch(e){v([`Test failed: ${j(e,`batch probe failed`)}`]),c.error(`Test failed`,j(e,`batch probe failed`))}}},te=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s) against OpenCode…`]);try{let e=await o.mutateAsync({providerId:Ue,targets:M}),t=e.map(e=>{let{status:t,latencyMs:n,reason:r}=e.result,i=n===void 0?``:` · ${n}ms`,a=r===void 0?``:` · ${r}`;return`${t===`allowed`?`OK `:t===`blocked`?`BLOCK`:`FAIL`} ${e.endpoint}${i}${a}`});b(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n});let n=e.filter(e=>e.result.status===`allowed`).length,r=e.filter(e=>e.result.status===`blocked`).length;v([`${n}/${e.length} allowed · ${r} blocked`,...t]),r===0&&n===e.length?c.success(`OpenCode accepted all ${e.length} proxies`):c.error(`OpenCode: ${n} allowed · ${r} blocked`)}catch(e){v([`Test failed: ${j(e,`provider probe failed`)}`]),c.error(`Test failed`,j(e,`provider probe failed`))}}};return(0,H.useEffect)(()=>{t?.((0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(s,{variant:`secondary`,type:`button`,onClick:e,children:`Cancel`}),(0,U.jsx)(s,{variant:`primary`,type:`submit`,form:`add-proxy-form`,disabled:S||E.length===0,children:S?`Adding…`:`Add ${E.length} Prox${E.length===1?`y`:`ies`}`})]}))},[t,S,E.length,e]),(0,U.jsxs)(`form`,{id:`add-proxy-form`,onSubmit:async t=>{if(t.preventDefault(),E.length!==0){g(null),C(!0);try{let t=A===null?new Map:X(A,d,O.length),a=Array(E.length),o=0,s=async()=>{for(;o<E.length;){let e=o++,s=O[e];try{let o=await i.mutateAsync({kind:Y(s),endpoint:s,...t.has(e)?{quotaBytes:t.get(e)}:{},...d.trim()===``?{}:{family:d.trim()}}),c=y[s],l=ee[s];o?.id&&(l!==void 0&&r?.(o.id,l),c!==void 0&&n?.(o.id,c)),a[e]={ok:!0}}catch(t){a[e]={ok:!1,error:j(t,`Proxy pool creation failed`)}}}};await Promise.all(Array.from({length:Math.min(ze,E.length)},()=>s()));let l=[],f=0;for(let[e,t]of a.entries())t.ok?f++:l.length<3&&l.push(`${E[e].slice(0,48)}…: ${t.error}`);let p=E.length-f,m=a.find(e=>!e.ok)?.error;f>0&&c.success(`Added ${f} proxy pool(s)`,p?`${p} failed: ${m??`see the import details`}`:void 0),p>0&&f===0&&c.error(`Failed to create pool`,m??`See the import details`),p>0&&g(l.join(`
|
|
3
|
-
`)),f>0&&(u(``),e())}finally{C(!1)}}},className:`flex flex-col gap-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`label`,{htmlFor:`proxy-endpoints`,className:`text-caption font-semibold text-text-primary`,children:`Proxy endpoints`}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:N,children:`Paste`})]}),(0,U.jsx)(`textarea`,{id:`proxy-endpoints`,value:l,onChange:e=>u(e.target.value),placeholder:`http://proxy.example:8080
|
|
4
|
-
https://proxy.example:8443
|
|
5
|
-
socks5://proxy.example:1080`,rows:5,"aria-describedby":`proxy-format-hint proxy-line-count`,"aria-invalid":!!h,className:`w-full min-h-32 max-h-64 resize-y overflow-y-auto rounded-control border border-inner-border bg-surface-1 p-3 font-mono text-caption text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),(0,U.jsx)(Ze,{endpoint:D,chip:w,onChipChange:T}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,U.jsx)(`p`,{id:`proxy-format-hint`,className:`m-0 text-badge leading-normal text-text-secondary`,children:`HTTP, HTTPS, or SOCKS5 | one per line | authentication optional`}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,U.jsxs)(`span`,{id:`proxy-line-count`,role:`status`,"aria-live":`polite`,className:`text-badge ${k?`text-red`:`text-text-tertiary`}`,children:[E.length===1?`1 proxy detected`:`${E.length} proxies detected`,k?` · max 100 per test`:``]}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>void P(),disabled:a.isPending||o.isPending||E.length===0||k,children:a.isPending?`Testing…`:`Test URL`}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>void te(),disabled:a.isPending||o.isPending||E.length===0||k,children:o.isPending?`Testing…`:`Test OpenCode`})]})]}),h&&(0,U.jsx)(`div`,{role:`alert`,className:`max-h-28 overflow-y-auto rounded-inset bg-red-soft px-4 py-3 text-badge text-red whitespace-pre-wrap break-words`,children:h}),_.length>0&&(0,U.jsx)(`div`,{role:`log`,"aria-label":`Proxy test results`,"aria-live":`polite`,className:`scroll-region max-h-40 overflow-y-auto whitespace-pre-wrap break-all rounded-inset border border-inner-border bg-surface-1 px-3 py-2 font-mono text-badge leading-[1.5] text-text-secondary`,children:_.join(`
|
|
6
|
-
`)}),(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,U.jsx)(R,{id:`proxy-family`,label:`Family`,hint:`Optional`,value:d,placeholder:`e.g. residential-id`,onChange:e=>f(e.target.value),className:`w-full`}),(0,U.jsx)(R,{id:`proxy-quota`,label:`Bandwidth quota (GB)`,hint:`Optional`,type:`number`,min:.001,step:`0.1`,value:p,onChange:e=>m(e.target.value),className:`w-full`})]})]})}function $e(e,t){if(t?.status===`healthy`||t?.status===`reachable`)return t.latencyMs;if(e.lastSuccessAt)return e.lastLatencyMs??void 0}function et(e){if(e===`proxy_payment_required`)return`HTTP 402 Payment Required`;if(e===`proxy_auth_required`)return`HTTP 407 Proxy Authentication Required`}var tt=(0,H.createContext)({byId:new Map,live:!1});function nt({children:e}){let t=V(),n=(0,H.useMemo)(()=>new Map((t.pools??[]).map(e=>[e.poolId,e])),[t.pools]),r=(0,H.useMemo)(()=>({byId:n,live:t.live&&t.pools!==null}),[n,t.live,t.pools]);return(0,U.jsx)(tt.Provider,{value:r,children:e})}function rt({pools:e}){let{byId:t,live:n}=(0,H.useContext)(tt),r=(0,H.useMemo)(()=>G(e,n?new Map([...t].map(([e,t])=>[e,t.currentInflight])):void 0),[e,t,n]),a=(0,H.useMemo)(()=>{let r=0,i=0;for(let a of e){let e=n?t.get(a.id):void 0,o=(a.bytesSentTotal??0)+(a.bytesReceivedTotal??0),s=(e?.bytesSent??0)+(e?.bytesReceived??0);r+=Math.max(o,s),a.quotaBytes&&(i+=a.quotaBytes)}return{used:r,allowance:i}},[e,t,n]);return(0,U.jsxs)(`div`,{className:`signal-grid grid gap-7 w-full min-w-0 mb-7`,children:[(0,U.jsx)(B,{label:`Enabled pool`,value:String(r.active),detail:`/ ${r.totalPools} total`,tone:`accent`,icon:(0,U.jsx)(S,{size:13})}),(0,U.jsx)(B,{label:`Route capacity`,value:String(r.totalMaxConcurrency),detail:`${r.usedInflight} inflight · ${r.availableCapacity} available`,tone:r.availableCapacity===0?`orange`:`teal`,icon:(0,U.jsx)(p,{size:13})}),(0,U.jsx)(B,{label:`Latency`,value:r.avgLatencyMs===null?`—`:`${r.avgLatencyMs}ms`,detail:Z(r),tone:r.avgLatencyMs===null?`accent`:r.avgLatencyMs>2e3?`orange`:`teal`,icon:(0,U.jsx)(i,{size:13})}),(0,U.jsx)(B,{label:`Quota usage`,value:I(a.used),detail:a.allowance>0?`of ${I(a.allowance)} allowance · ${e.length} pools`:`${e.length} pools · no allowance set`,tone:a.allowance>0&&a.used>a.allowance?`red`:a.allowance>0&&a.used/a.allowance>=.8?`orange`:`teal`,icon:(0,U.jsx)(de,{size:13})})]})}function it(e,t,n,r,i){let a=Ke(e),o=Q(e),s=e.status!==`disabled`,c=et(e.lastErrorCategory),l=e.status===`disabled`&&c!==void 0,u=e.lastSuccessAt?new Date(e.lastSuccessAt).getTime():0,d=e.lastErrorAt?new Date(e.lastErrorAt).getTime():0,f=!t&&(u>0||d>0)?u>=d:null,p=n?`default`:l?`warn`:t?t.status===`healthy`?`ok`:t.status===`reachable`?`warn`:`err`:f===!0?`ok`:f===!1?`err`:`default`,m=l?e.lastError??c:t?.errorMessage??(f===null?void 0:`last check ${(e.lastHealthCheckAt?new Date(e.lastHealthCheckAt):new Date).toLocaleString()}`),h=$e(e,t),g=r?.currentInflight??e.inflight,_=e.maxInflight>0?Math.min(1,g/e.maxInflight):1,v=e.providerCooldowns??[],y=v.filter(e=>e.blocked===!0),b=v.filter(e=>e.blocked!==!0),ee=v.slice(0,2).map(e=>e.blocked===!0?`${e.providerId} blocked: ${e.reason}`:`${e.providerId} until ${new Date(e.until).toLocaleTimeString()}: ${e.reason}`).join(` · `),x=n?`Testing…`:l?`Proxy reachable`:t?t.status===`healthy`?`Connected`:t.status===`reachable`?`Proxy reachable`:t.status===`timeout`?`Timeout`:`Unhealthy`:f===!0?`Connected`:f===!1?e.lastErrorCategory===`timeout`?`Timeout`:`Unhealthy`:`Untested`,S=(e.bytesSentTotal??0)+(e.bytesReceivedTotal??0),C=(r?.bytesSent??0)+(r?.bytesReceived??0);return{display:a,poolLabel:o,isEnabled:s,checkTone:p,checkTooltip:m,statusText:x,latency:h,inflight:g,load:_,cooldowns:v,blocked:y,cooldownOnly:b,cooldownText:ee,...i===void 0?{}:{probe:i},metered:S,session:C,used:Math.max(S,C),proxyFailureLabel:c}}function at({pool:e,view:t,maskValues:n}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`block text-caption font-semibold overflow-hidden truncate whitespace-nowrap`,title:n?Ge:t.poolLabel,children:n?Ge:t.poolLabel}),(0,U.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 min-w-0 flex-wrap`,children:[e.status===`disabled`?(0,U.jsxs)(L,{tone:`disabled`,title:e.lastError,children:[`Disabled`,t.proxyFailureLabel?` · ${t.proxyFailureLabel}`:``]}):(0,U.jsx)(L,{tone:t.checkTone,title:t.checkTooltip,children:t.latency===void 0?t.statusText:`${t.statusText} · ${t.latency}ms`}),t.blocked.length>0?(0,U.jsxs)(L,{tone:`disabled`,title:t.cooldownText,children:[t.blocked.length,` blocked`]}):null,t.probe?(0,U.jsx)(L,{tone:t.probe.status===`blocked`?`disabled`:t.probe.status===`allowed`?`ok`:`warn`,title:t.probe.reason??(t.probe.status===`allowed`?t.probe.httpStatus!==void 0&&t.probe.httpStatus>=400?`Reachable — upstream answered ${t.probe.httpStatus} for the probe body`:`OpenCode served a probe through this pool`:t.probe.status===`throttled`?`OpenCode accepted this egress; the rate is spent`:`The probe could not complete`),children:t.probe.status===`blocked`?`OpenCode blocked`:t.probe.status===`allowed`?t.probe.httpStatus!==void 0&&t.probe.httpStatus>=400?`OpenCode reachable`:`OpenCode OK`:t.probe.status===`throttled`?`OpenCode rate-limited`:`OpenCode unreachable`}):null,t.cooldownOnly.length>0?(0,U.jsxs)(L,{tone:`warn`,title:t.cooldownText,children:[t.cooldownOnly.length,` cooldown`,t.cooldownOnly.length>1?`s`:``]}):null]})]})}function ot({pool:e,view:t,speedResult:n,isSpeedTesting:r,maskIp:i}){return(0,U.jsxs)(U.Fragment,{children:[e.egressIp?(0,U.jsx)(`span`,{className:`font-mono tabular-nums block overflow-hidden text-ellipsis whitespace-nowrap text-badge`,title:i?`IP masked`:`egress ${e.egressIp} · ${t.display.endpoint}`,children:i?`IP masked`:e.egressIp}):(0,U.jsx)(`span`,{className:`text-badge text-text-tertiary`,title:`Test the pool to read its egress address`,children:`not probed`}),(r||n)&&(0,U.jsx)(`div`,{className:`mt-1.5`,children:(0,U.jsx)(L,{tone:r?`default`:n?.status===`ok`?`ok`:`err`,title:r?`Measuring download throughput`:n?.status===`ok`?`${I(n.bytes)} in ${n.durationMs}ms${n.measuredAt?` · last measured ${new Date(n.measuredAt).toLocaleString()}`:``}`:`${n?.errorMessage??`Speed test failed`}${n?.measuredAt?` · last measured ${new Date(n.measuredAt).toLocaleString()}`:``}`,children:r?`Speed…`:n?.status===`ok`?`${(n.megabitsPerSecond??0).toFixed(1)} Mbps`:`Speed failed`})})]})}function st({pool:e,view:t}){let n=e.quotaBytes,r=n&&n>0?Math.min(1,t.used/n):0,i=n!==void 0&&n>0&&t.used>n;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{title:`${t.inflight}/${e.maxInflight} inflight`,className:`flex items-center gap-3`,children:[(0,U.jsx)(`div`,{className:`flex-1 h-3 rounded-micro overflow-hidden`,children:(0,U.jsx)(`div`,{className:`h-full rounded-micro`,style:{width:`${Math.round(t.load*100)}%`,background:t.load>=.8?`var(--orange)`:`var(--green)`}})}),(0,U.jsxs)(`span`,{className:`font-mono tabular-nums text-micro text-text-secondary whitespace-nowrap`,children:[t.inflight,`/`,e.maxInflight]})]}),(0,U.jsxs)(`div`,{title:n?`${I(t.used)} of ${I(n)} used · ${I(t.metered)} metered lifetime`:`${I(t.used)} carried (no quota set) · ${I(t.session)} this session`,className:`flex items-center gap-3 mt-2`,children:[(0,U.jsx)(`div`,{className:`flex-1 h-3 rounded-micro overflow-hidden`,children:(0,U.jsx)(`div`,{className:`h-full rounded-micro`,style:{width:`${Math.round(r*100)}%`,background:i?`var(--red)`:r>=.8?`var(--orange)`:`var(--teal)`}})}),(0,U.jsxs)(`span`,{className:`font-mono tabular-nums whitespace-nowrap text-micro ${i?`text-red`:`text-text-secondary`}`,children:[I(t.used),n?` / ${I(n)}`:``]})]})]})}function ct({pool:e,view:t,isTesting:n,onDelete:r,onEdit:a,onHealthCheck:c,onActivity:u}){let d=Se(),f=Ae(),p=we();return(0,U.jsxs)(U.Fragment,{children:[t.cooldowns.length>0&&(0,U.jsx)(s,{size:`icon`,variant:`secondary`,disabled:f.isPending,icon:f.isPending?(0,U.jsx)(o,{size:12,className:`animate-spin`}):(0,U.jsx)(x,{size:12}),onClick:()=>f.mutate({poolId:e.id}),title:`Clear provider cooldowns — ${t.cooldownText}`,label:`Clear`}),(0,U.jsx)(s,{size:`icon`,variant:`secondary`,icon:(0,U.jsx)(i,{size:12}),onClick:()=>u(e),title:`Health and error activity`,label:`Activity`}),e.status===`cooldown`&&(0,U.jsx)(s,{size:`icon`,variant:`secondary`,disabled:p.isPending,icon:(0,U.jsx)(x,{size:12,className:p.isPending?`animate-spin`:``}),onClick:()=>p.mutate(e.id),title:`Recover pool`,children:`Recover`}),!(!t.isEnabled&&t.cooldowns.length>0)&&(0,U.jsx)(s,{size:`icon`,variant:`secondary`,disabled:n,icon:n?(0,U.jsx)(o,{size:12,className:`animate-spin`}):(0,U.jsx)(l,{size:12}),onClick:()=>c(e),title:t.checkTooltip??`Run health check`,label:`Test`}),(0,U.jsx)(s,{size:`icon`,variant:`secondary`,icon:(0,U.jsx)(y,{size:12}),onClick:()=>a(e),title:`Edit pool`,label:`Edit`}),(0,U.jsx)(s,{size:`icon`,variant:`secondary`,icon:(0,U.jsx)(C,{size:12}),onClick:()=>r(e.id),title:`Delete pool`,label:`Delete`}),(0,U.jsx)(z,{className:`ml-3`,checked:t.isEnabled,disabled:d.isPending,onChange:t=>d.mutate({poolId:e.id,request:{status:t?`active`:`disabled`}})})]})}var lt=(0,H.memo)(function({pool:e,isSelected:t,onToggleSelect:n,checkResult:r,isTesting:i,onDelete:a,onEdit:o,onHealthCheck:s,onActivity:c,speedResult:l,isSpeedTesting:u,maskValues:d,maskIp:f,probe:p}){let m=(0,H.useContext)(tt),h=it(e,r,i,(m.live?m.byId.get(e.id):void 0)??null,p);return(0,U.jsxs)(`tr`,{className:h.isEnabled?``:`opacity-60`,children:[(0,U.jsx)(`td`,{className:`w-13`,children:(0,U.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>n(e.id),"aria-label":`Select ${h.poolLabel}`})}),(0,U.jsx)(`td`,{className:`min-w-0 max-w-150`,children:(0,U.jsx)(at,{pool:e,view:h,maskValues:d})}),(0,U.jsx)(`td`,{className:`min-w-0 max-w-90`,children:e.family?(0,U.jsx)(`span`,{className:`truncate text-caption font-semibold text-text-secondary`,title:e.family,children:e.family}):(0,U.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:`—`})}),(0,U.jsx)(`td`,{className:`max-w-110`,children:(0,U.jsx)(ot,{pool:e,view:h,speedResult:l,isSpeedTesting:u,maskIp:f})}),(0,U.jsx)(`td`,{className:`min-w-55`,children:(0,U.jsx)(st,{pool:e,view:h})}),(0,U.jsx)(`td`,{className:`whitespace-nowrap pl-36 text-right`,children:(0,U.jsx)(se,{gap:`4px`,justify:`end`,children:(0,U.jsx)(ct,{pool:e,view:h,isTesting:i,onDelete:a,onEdit:o,onHealthCheck:s,onActivity:c})})})]})});function ut({pool:e,onClose:t}){let n=Ce(e.id),r=we(),i=n.data??[],a=et(e.lastErrorCategory),o=e.status===`disabled`&&a!==void 0,c=e.status===`active`?`ok`:e.status===`disabled`?`disabled`:`warn`;return(0,U.jsx)(v,{open:!0,onClose:t,title:`Health & Activity — ${Q(e)}`,children:(0,U.jsxs)(oe,{gap:`14px`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-8 rounded-panel border bg-surface-2 p-8 ${o?`border-orange`:`border-inner-border`}`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`div`,{className:`mb-2.5 text-text-tertiary text-micro font-bold tracking-label uppercase`,children:`Proxy health`}),(0,U.jsx)(`div`,{className:`text-title font-bold leading-[1.3]`,children:o?`Proxy reachable`:`Proxy ${e.status}`}),(0,U.jsx)(`p`,{className:`mt-3 mx-0 mb-0 text-text-secondary text-caption leading-normal wrap-anywhere`,children:o?`${a} · disabled from routing`:e.lastError??`No recent proxy errors.`})]}),(0,U.jsx)(L,{tone:c,dot:!0,children:e.status})]}),e.status===`cooldown`&&(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsx)(s,{size:`sm`,variant:`secondary`,disabled:r.isPending,onClick:()=>r.mutate(e.id),icon:(0,U.jsx)(x,{size:12,className:r.isPending?`animate-spin`:``}),children:`Recover Now`})}),n.isPending?(0,U.jsx)(g,{label:`Loading pool activity…`}):null,n.isError?(0,U.jsx)(h,{message:`Failed to load pool activity`,onRetry:()=>void n.refetch()}):null,!n.isPending&&!n.isError&&i.length===0?(0,U.jsx)(_,{title:`No pool activity`,message:`Proxy checks, disable events, and recoveries will appear here.`}):null,i.length>0?(0,U.jsx)(`div`,{className:`grid gap-4 max-h-190 overflow-y-auto pr-1`,children:i.map(e=>(0,U.jsxs)(`div`,{className:`p-6 border border-inner-border rounded-control bg-surface-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,U.jsxs)(se,{gap:`6px`,children:[(0,U.jsxs)(L,{tone:e.toStatus===`active`?`ok`:e.toStatus===`disabled`?`disabled`:`warn`,children:[e.fromStatus??`new`,` → `,e.toStatus]}),e.errorCategory?(0,U.jsx)(L,{tone:e.errorCategory.startsWith(`proxy_`)?`warn`:`err`,children:e.errorCategory}):null]}),(0,U.jsx)(`time`,{className:`text-text-tertiary text-badge tabular-nums`,children:new Date(e.createdAt).toLocaleString()})]}),(0,U.jsx)(`p`,{className:`mt-4 mx-0 mb-0 text-text-secondary text-caption leading-normal wrap-anywhere`,children:e.reason??`No additional details`})]},e.id))}):null]})})}function dt(){let e=ve(),t=Te(),n=Se(),r=Oe(),[i,m]=(0,H.useState)(!1),y=(0,H.useCallback)(()=>m(!1),[]),[x,w]=(0,H.useState)(null),[T,E]=(0,H.useState)(null),[D,O]=(0,H.useState)(!1),[k,A]=(0,H.useState)(null),[M,N]=(0,H.useState)(new Set),P=le(),F=P.enabled,I=ue(),R=I.enabled,[z,B]=(0,H.useState)(new Set),[V,pe]=(0,H.useState)(()=>{try{return localStorage.getItem(Be)===`opencode`?`opencode`:`url`}catch{return`url`}});(0,H.useEffect)(()=>{try{localStorage.setItem(Be,V)}catch{}},[V]);let[me,ge]=(0,H.useState)(new Set),[_e,ye]=(0,H.useState)({}),be=Ee(),xe=ke(),[Ce,we]=(0,H.useState)(he),[De,Ae]=(0,H.useState)(()=>{try{let e=localStorage.getItem(`cartethyia_proxy_speed_results`);return e?JSON.parse(e):{}}catch{return{}}}),[W,je]=(0,H.useState)(new Set),Pe=(0,H.useCallback)((e,t)=>{let n={...t,measuredAt:new Date().toISOString()};Ae(t=>{let r={...t,[e]:n};try{localStorage.setItem(`cartethyia_proxy_speed_results`,JSON.stringify(r))}catch{}return r})},[]),[G,K]=(0,H.useState)(()=>{try{let e=localStorage.getItem(Ve);return e?JSON.parse(e):{}}catch{return{}}}),[q,Ie]=(0,H.useState)({key:`name`,direction:`asc`}),[J,Y]=(0,H.useState)(null),[Le,Re]=(0,H.useState)(null),X=e.data??[],ze=(0,H.useMemo)(()=>Fe(X,q.key,q.direction,e=>$e(e,G[e.id])),[X,q,G]),Ge=(0,H.useCallback)(e=>{let t=e;Ie(e=>e.key===t?{key:t,direction:e.direction===`asc`?`desc`:`asc`}:{key:t,direction:`asc`})},[]),Z=e.isPending,$=e.isError,Ze=X.length>0&&X.every(e=>M.has(e.id)),et=()=>{N(Ze?new Set:new Set(X.map(e=>e.id)))},tt=(0,H.useCallback)(e=>{N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);(0,H.useEffect)(()=>{try{localStorage.setItem(Ve,JSON.stringify(G))}catch{}},[G]);let it=Object.values(G),at=it.length,ot=it.filter(e=>e.status===`healthy`||e.status===`reachable`).length,st=it.filter(e=>e.status!==`healthy`&&e.status!==`reachable`).length,ct=(0,H.useCallback)(e=>{B(t=>new Set(t).add(e.id)),r.mutate(e.id,{onSuccess:t=>{K(n=>({...n,[e.id]:t}));let n=Q(e);t.status===`healthy`?c.success(`${n}: connected`,`${t.latencyMs??0}ms`):t.status===`reachable`?c.error(`${n}: proxy reachable · disabled`,t.errorMessage):c.error(`${n}: ${t.status===`timeout`?`timeout`:`unhealthy`}`,t.errorMessage)},onError:t=>{let n=Q(e);c.error(`${n}: check failed`,j(t,`Health check failed`))},onSettled:()=>{B(t=>{let n=new Set(t);return n.delete(e.id),n})}})},[r]),dt=async()=>{let e=X;if(e.length===0)return;let t=0,n=0,i=0,a=async()=>{for(;;){let a=e[i++];if(!a)return;B(e=>new Set(e).add(a.id));try{let e=await r.mutateAsync(a.id);K(t=>({...t,[a.id]:e})),e.status===`healthy`?t+=1:n+=1}catch(e){n+=1;let t={poolId:a.id,status:`timeout`,errorMessage:j(e,`Health check failed`)};K(e=>({...e,[a.id]:t}))}finally{B(e=>{let t=new Set(e);return t.delete(a.id),t})}}};await Promise.all(Array.from({length:Math.min(8,e.length)},()=>a())),c.success(`Tested ${e.length} pools · ${t} healthy · ${n} failed`)},ft=async()=>{let e=X.filter(e=>M.has(e.id));if(e.length===0)return;let t=0,n=0,i=0,a=async()=>{for(;;){let a=e[i++];if(!a)return;B(e=>new Set(e).add(a.id));try{let e=await r.mutateAsync(a.id);K(t=>({...t,[a.id]:e})),e.status===`healthy`?t+=1:n+=1}catch(e){n+=1;let t={poolId:a.id,status:`timeout`,errorMessage:j(e,`Health check failed`)};K(e=>({...e,[a.id]:t}))}finally{B(e=>{let t=new Set(e);return t.delete(a.id),t})}}};await Promise.all(Array.from({length:Math.min(8,e.length)},()=>a())),c.success(`Tested ${e.length} pools · ${t} healthy · ${n} failed`)},pt=async()=>{let e=X.filter(e=>M.has(e.id));if(e.length===0)return;let t=0,n=0,r=0,i=0,a=0,o=async()=>{for(;;){let o=e[a++];if(!o)return;ge(e=>new Set(e).add(o.id));try{let e=await be.mutateAsync({poolId:o.id,providerId:Ue});ye(t=>({...t,[o.id]:{endpoint:o.endpoint??``,result:e}})),e.status===`allowed`?t+=1:e.status===`blocked`?n+=1:e.status===`throttled`?r+=1:i+=1}catch(e){i+=1,ye(t=>({...t,[o.id]:{endpoint:o.endpoint??``,result:{poolId:o.id,providerId:Ue,status:`unreachable`,reason:j(e,`Provider probe failed`)}}}))}finally{ge(e=>{let t=new Set(e);return t.delete(o.id),t})}}};await Promise.all(Array.from({length:Math.min(We,e.length)},()=>o())),c.success(`OpenCode: ${t} allowed · ${n} blocked`+(r>0?` · ${r} rate-limited`:``)+(i>0?` · ${i} unreachable`:``))},mt=async()=>{let e=X.filter(e=>M.has(e.id));if(e.length===0)return;let t=0;await(async()=>{for(;;){let n=e[t++];if(!n)return;je(e=>new Set(e).add(n.id));try{let e=await xe.mutateAsync({poolId:n.id,bytes:Ce});Pe(n.id,e)}catch(e){Pe(n.id,{poolId:n.id,status:`failed`,bytes:0,durationMs:0,errorMessage:j(e,`Speed test failed`)})}finally{je(e=>{let t=new Set(e);return t.delete(n.id),t})}}})(),c.success(`Speed tested ${e.length} pool(s)`)},ht=async()=>{let e=X.filter(e=>M.has(e.id));e.length!==0&&(await Promise.all(e.map(e=>n.mutateAsync({poolId:e.id,request:{status:`active`}}))),N(new Set),c.success(`Enabled ${e.length} pool(s)`))},gt=async()=>{let e=X.filter(e=>M.has(e.id));e.length!==0&&(await Promise.all(e.map(e=>n.mutateAsync({poolId:e.id,request:{status:`disabled`}}))),N(new Set),c.success(`Disabled ${e.length} pool(s)`))},_t=()=>{let e=M.size>0?X.filter(e=>M.has(e.id)):X;if(e.length===0)return;let t=e.map(e=>Ke(e).endpoint||e.endpoint).join(`
|
|
7
|
-
`);ae(`cartethyia-proxies.txt`,t,`text/plain;charset=utf-8`),c.success(`Exported ${e.length} pool(s)`)},vt=(0,H.useCallback)(e=>{let t=X.find(t=>t.id===e);t&&Y([t])},[X]);return(0,U.jsx)(nt,{children:(0,U.jsxs)(oe,{gap:`16px`,children:[(0,U.jsx)(v,{open:i,onClose:y,title:`Add Proxy`,footer:x,children:(0,U.jsx)(Qe,{onClose:y,actionsRef:w,onProbeResult:(e,t)=>{let n=X.find(t=>t.id===e);ye(r=>({...r,[e]:{endpoint:n?.endpoint??``,result:t}}))},onHealthResult:(e,t)=>{K(n=>({...n,[e]:t}))}})}),(0,U.jsx)(v,{open:k!==null,onClose:()=>A(null),title:`Edit pool`,footer:T,children:k&&(0,U.jsx)(Xe,{pool:k,onClose:()=>A(null),actionsRef:E},k.id)}),(0,U.jsxs)(ie,{style:X.length===0&&!Z&&!$?{minHeight:`min(78dvh, calc(100dvh - 160px))`,display:`flex`,flexDirection:`column`}:void 0,children:[(0,U.jsx)(re,{title:`Proxy Pool`,subtitle:`Outbound proxy servers — HTTP, HTTPS, and SOCKS5`,icon:(0,U.jsx)(S,{size:16}),action:(0,U.jsxs)(se,{gap:`8px`,children:[(0,U.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,U.jsx)(de,{size:13}),onClick:()=>O(!0),children:`Deploy relay`}),(0,U.jsx)(s,{variant:`primary`,size:`sm`,icon:(0,U.jsx)(b,{size:13}),onClick:()=>m(!0),children:`Add proxies`})]})}),(0,U.jsxs)(ne,{style:X.length===0&&!Z&&!$?{flex:1,display:`flex`,flexDirection:`column`,gap:`16px`}:void 0,children:[(0,U.jsx)(rt,{pools:X}),X.length>0&&(0,U.jsxs)(`div`,{className:`nested-panel flex flex-wrap items-center justify-start overflow-x-auto rounded-card border border-inner-border bg-surface-2 p-4 text-badge`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer text-text-secondary`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:Ze,onChange:et,"aria-label":`Select all proxies`}),`Select all`,M.size>0&&(0,U.jsxs)(`span`,{className:`text-text-tertiary`,children:[`(`,M.size,`)`]})]}),at>0&&(0,U.jsxs)(se,{gap:`6px`,children:[(0,U.jsxs)(`span`,{className:`text-text-tertiary`,children:[`Tested `,at,`/`,X.length]}),ot>0&&(0,U.jsxs)(L,{tone:`ok`,children:[ot,` success`]}),st>0&&(0,U.jsxs)(L,{tone:`err`,children:[st,` errors`]})]})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,U.jsx)(s,{variant:`ghost`,size:`sm`,icon:F?(0,U.jsx)(d,{size:12}):(0,U.jsx)(f,{size:12}),onClick:()=>P.setEnabled(!F),title:F?`Show proxy names and addresses`:`Hide proxy names and addresses`,children:F?`Unmask`:`Mask`}),(0,U.jsx)(s,{variant:`ghost`,size:`sm`,icon:R?(0,U.jsx)(d,{size:12}):(0,U.jsx)(f,{size:12}),onClick:()=>I.setEnabled(!R),title:R?`Show egress addresses`:`Hide egress addresses`,children:R?`Show IP`:`Mask IP`}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,disabled:z.size>0||X.length===0,icon:z.size>0?(0,U.jsx)(o,{size:12,className:`animate-spin`}):(0,U.jsx)(l,{size:12}),onClick:()=>void dt(),children:`Test all`}),(0,U.jsxs)(`div`,{className:`inline-flex items-stretch h-15`,children:[(0,U.jsx)(s,{variant:`secondary`,size:`sm`,className:`rounded-tr-none rounded-br-none`,disabled:z.size>0||me.size>0||M.size===0,icon:z.size>0||me.size>0?(0,U.jsx)(o,{size:12,className:`animate-spin`}):(0,U.jsx)(l,{size:12}),onClick:()=>void(V===`opencode`?pt():ft()),children:V===`opencode`?`Test OpenCode`:`Test URL`}),(0,U.jsx)(a,{"aria-label":`Test payload`,value:V,onValueChange:e=>pe(e),options:He,disabled:z.size>0||me.size>0,className:`w-auto min-w-38 h-15 rounded-tl-none rounded-bl-none -ml-0.5`})]}),(0,U.jsxs)(`div`,{className:`inline-flex items-stretch h-15`,children:[(0,U.jsx)(s,{variant:`secondary`,size:`sm`,className:`rounded-tr-none rounded-br-none`,disabled:M.size===0||W.size>0||xe.isPending,icon:W.size>0?(0,U.jsx)(o,{size:12,className:`animate-spin`}):(0,U.jsx)(p,{size:12}),onClick:()=>void mt(),children:`Speedtest selected`}),(0,U.jsx)(a,{"aria-label":`Speed test payload size`,value:String(Ce),onValueChange:e=>we(Number(e)),options:Ye,disabled:W.size>0||xe.isPending,className:`w-auto min-w-38 h-15 rounded-tl-none rounded-bl-none -ml-0.5`})]}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,disabled:X.length===0,icon:(0,U.jsx)(u,{size:12}),onClick:_t,children:`Export`}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,disabled:M.size===0||n.isPending,icon:(0,U.jsx)(fe,{size:12}),onClick:()=>void ht(),children:`Enable selected`}),(0,U.jsx)(s,{variant:`secondary`,size:`sm`,disabled:M.size===0||n.isPending,icon:(0,U.jsx)(ee,{size:12}),onClick:()=>void gt(),children:`Disable selected`}),(0,U.jsx)(s,{variant:`danger`,size:`sm`,disabled:M.size===0||t.isPending,icon:(0,U.jsx)(C,{size:12}),onClick:()=>{let e=X.filter(e=>M.has(e.id));e.length!==0&&Y(e)},children:`Delete selected`})]})]}),Z&&(0,U.jsx)(g,{}),$&&(0,U.jsx)(h,{title:`Error`,message:`Failed to load network pools`}),!Z&&!$&&X.length===0&&(0,U.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,U.jsx)(_,{title:`No proxy pools configured`,message:`The summary above is empty because nothing is routing yet. Use Add proxies or Deploy relay in the header to start one.`})}),!Z&&!$&&X.length>0&&(0,U.jsx)(`div`,{className:`proxy-table-scroll rounded-control border border-inner-border bg-surface-1`,children:(0,U.jsx)(ce,{maxHeight:460,scrollRegion:!0,headers:[``,{key:`name`,label:`Proxy`,sortable:!0},{key:`family`,label:`Family`,sortable:!0},{key:`address`,label:`Address`,sortable:!0},{key:`load`,label:`Load`,sortable:!0},`Actions`],sortKey:q.key,sortDirection:q.direction,onSort:Ge,children:ze.map(e=>(0,U.jsx)(lt,{pool:e,isSelected:M.has(e.id),onToggleSelect:tt,checkResult:G[e.id],probe:e.providerProbe===void 0?Ne(_e[e.id],e.endpoint):{poolId:e.id,providerId:e.providerProbe.providerId,status:e.providerProbe.status,...e.providerProbe.httpStatus===void 0?{}:{httpStatus:e.providerProbe.httpStatus},...e.providerProbe.reason===void 0?{}:{reason:e.providerProbe.reason},...e.providerProbe.latencyMs===void 0?{}:{latencyMs:e.providerProbe.latencyMs}},isTesting:z.has(e.id),onDelete:vt,onEdit:A,onHealthCheck:ct,onActivity:Re,speedResult:Je(De[e.id],qe(e)),isSpeedTesting:W.has(e.id),maskValues:F,maskIp:R},e.id))})})]})]}),(0,U.jsx)(te,{open:J!==null,onClose:()=>Y(null),onConfirm:async()=>{J&&(await Promise.all(J.map(e=>t.mutateAsync(e.id))),N(new Set),c.success(`Deleted ${J.length} pool(s)`),Y(null))},title:`Delete proxy pool?`,message:J&&J.length===1?`Delete "${Q(J[0])}"? This cannot be undone.`:J?`Delete ${J.length} proxy pools? This cannot be undone.`:`Delete this proxy pool? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),Le?(0,U.jsx)(ut,{pool:Le,onClose:()=>Re(null)}):null,D?(0,U.jsx)(Me,{onClose:()=>O(!1)}):null]})})}export{Qe as ProxyBulkForm,nt as ProxyLiveProvider,Ze as SchemeChipRow,dt 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{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./check-D69FzdvC.js";import{t as o}from"./select-C9mMoEpJ.js";import{t as s}from"./chevron-right-BXIy5l3h.js";import{g as c,r as l,t as u}from"./toast-C76WrMhc.js";import{t as d}from"./eye-off-Bk5g2luF.js";import{a as f,i as p,n as m,r as h,t as g}from"./state-CzUPfLXo.js";import{t as _}from"./dialog-BWIP_EvW.js";import{t as v}from"./refresh-cw-BqJFk4sU.js";import{t as y}from"./rotate-ccw-CufcqITi.js";import{t as b}from"./sliders-horizontal-ClG7dBeJ.js";import{t as x}from"./trash-Cppn5c3R.js";import{l as S}from"./query-keys-D7wX2vM5.js";import{F as C}from"./entry-7dpgvpJ3.js";import{n as w,r as T,t as E}from"./card-B0Bnx5CA.js";import{t as D}from"./badge-BTyGk_DL.js";import{t as O}from"./ProviderIcon-paOCq8I0.js";import{t as k}from"./switch-DOUIky_i.js";import{t as A}from"./stack-Ca5HxI5i.js";import{n as j}from"./inline-D1TCqM2D.js";import{t as M}from"./layout-BArzXirQ.js";import{a as ee,i as N,n as P,o as F,r as I,s as L,t as R}from"./quota-DZGyp0N5.js";import{a as te,c as z,d as B,f as V,i as H,l as U,n as W,o as ne,p as G,r as re,s as K,t as q,u as J}from"./HealthEventsModal-CZkpn0a7.js";var Y=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`}]]),X=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Z=e(`zap`,[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]),Q=t(n(),1),$=r();function ae(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function oe(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function se({account:e,onClose:t}){let n=H(e.id,!0),r=J(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,o=e=>e?new Date(e).toLocaleString():`—`,s=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,$.jsx)(_,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.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,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(Z,{size:14,className:`text-status-success`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,$.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,$.jsxs)(D,{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,$.jsx)(h,{label:`Reading saved resets…`}):n.isError?(0,$.jsx)(m,{message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,$.jsx)(g,{title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,$.jsx)(Z,{size:20})}):(0,$.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,$.jsx)(M,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=s(e.expiresAt);return(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,$.jsx)(D,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,$.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,$.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,$.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[o(e.expiresAt),n&&(0,$.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,$.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,$.jsx)(l,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?u.success(e.message??`Rate limit reset applied`):u.error(e.message??`Rate limit reset failed`)},onError:e=>{u.error(S(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,$.jsx)(j,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(l,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function ce({accounts:e}){let t=(0,Q.useMemo)(()=>{let t=new Map;for(let n of e){if(!W(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,Q.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,a=V(i),s=i.length===0||a.isPending||t.length===0;return(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,$.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,$.jsx)(o,{"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,$.jsx)(l,{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:s,className:`shrink-0`,icon:a.isPending?(0,$.jsx)(c,{size:13,className:`animate-spin`}):(0,$.jsx)(Y,{size:13}),onClick:()=>a.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?u.success(e.message):u.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>u.error(S(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function le({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:a}){let o=K(e.id),d=B(e.id),p=W(e.provider),m=re(e.provider),h=H(e.id,m),g=e.quota,[_,v]=(0,Q.useState)(0),b=g?.windows??[],C=F(b,_),w=C.pageCount;(0,Q.useEffect)(()=>{v(e=>Math.min(e,Math.max(0,w-1)))},[w]);let T=o.isPending||d.isPending,D=h.data?.availableCount??0,[A,j]=(0,Q.useState)(null),[M,te]=(0,Q.useState)(!1),z=e.checkin?.attemptedToday??!1,V=`${A?A.state===`claimed`?`Checked in${A.credit===null?``:` +${A.credit}`}${A.streakDays===null?``:` · ${A.streakDays}d streak`}`:A.state===`already_claimed`?`Check-in attempted · already claimed`:A.state===`not_eligible`?`Check-in attempted · not eligible`:A.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:z?`Check-in attempted today`:`Check-in due`}${M?` · Reported today`:``}`,U=b.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),ne=(o.error?S(o.error,`Unable to refresh this account`):null)??g?.refreshError??g?.error??e.health?.sanitizedMessage,G=ee(ne),q=G===`Quota tracking is not supported for this provider`?null:G,J=R(e.credentialHint,e.name),X=e.health?.status??`unknown`;return(0,$.jsxs)(E,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":T,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,$.jsx)(O,{icon:e.providerIcon,name:e.providerName,size:32}),(0,$.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,$.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),g?.plan&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:g.plan})]}),(0,$.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:J.primary}),J.secondary!==null&&(0,$.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:J.secondary}),g&&(0,$.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:P(g.lastSuccessAt??g.fetchedAt)}),m&&(0,$.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:h.isPending?`Checking saved resets…`:D>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`reset-credit-live`,children:[D,` rate-limit reset`,D===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.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…`:V}),b.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,$.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,U.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[m&&(0,$.jsx)(l,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:h.isPending?`Checking saved rate-limit resets…`:D>0?`Saved rate-limit resets (${D} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:T,onClick:()=>a(e),children:(0,$.jsx)(Z,{size:14})}),p&&(0,$.jsx)(l,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${V}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:T,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&j({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&te(!0),e.ok?u.success(e.message):u.error(e.message)},onError:e=>{u.error(S(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,$.jsx)(c,{size:14,className:`animate-spin`}):(0,$.jsx)(Y,{size:14})}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,title:X===`active`?`Health & Error Log`:`${X} — Inspect account health details`,"aria-label":X===`active`?`Health log for ${e.name}`:`Account is ${X} — inspect health details for ${e.name}`,disabled:T,onClick:()=>r(e),icon:(0,$.jsx)(i,{size:12})}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:T,onClick:()=>o.mutate(),icon:o.isPending?(0,$.jsx)(c,{size:12,className:`animate-spin`}):(0,$.jsx)(y,{size:12})}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,$.jsx)(x,{size:12})}),(0,$.jsx)(k,{checked:e.active,disabled:o.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),q&&(0,$.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,$.jsx)(f,{size:13,className:`shrink-0`}),(0,$.jsx)(`span`,{children:q})]}),g?.windows.length?(0,$.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,$.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),C.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=L(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=I(e.label);return(0,$.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,$.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,$.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,$.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,$.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,$.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,$.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,$.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,$.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:N(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),C.pageCount>1&&(0,$.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,$.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,C.startIndex+1,`–`,C.startIndex+C.items.length,` of `,b.length]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(l,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:C.page===0,icon:(0,$.jsx)(ie,{size:13}),onClick:()=>v(C.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:C.page>=C.pageCount-1,icon:(0,$.jsx)(s,{size:13}),onClick:()=>v(C.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):q?null:(0,$.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:T||e.pending?`Fetching quota…`:`No quota data`})]})}function ue(){let[e,t]=(0,Q.useState)(`all`),[n,r]=(0,Q.useState)(`all`),[i,s]=(0,Q.useState)(!1),{data:c,isLoading:f,isError:m,error:h,isFetching:_,dataUpdatedAt:y,refetch:x}=ne(),S=(0,Q.useMemo)(()=>[...c?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[c?.providers]),D=(0,Q.useMemo)(()=>c?.accounts??[],[c?.accounts]),O=c?.refreshing??0,k=z(),j=G(),M=U(),ee=te(),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),B=(0,Q.useMemo)(()=>{let t=D.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)=>oe(e)-oe(t)||r(e,t):r)},[n,D,i,e]),V=async(e,t)=>{try{await j.mutateAsync({id:e.id,active:t}),u.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){u.error(e instanceof Error?e.message:`Unable to update account`)}},H=async()=>{let e=D.filter(e=>e.active&&ae(e));await M.mutateAsync({ids:e.map(e=>e.id),active:!1}),u.success(`Disabled ${e.length} empty accounts`)},W=async()=>{let e=D.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await M.mutateAsync({ids:e.map(e=>e.id),active:!0}),u.success(`Enabled ${e.length} available accounts`)},re=async e=>{await ee.mutateAsync(e.id),u.success(`${e.name} deleted`)},K=y>0?new Date(y).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,J=D.filter(ae).length;return(0,$.jsxs)(A,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(T,{title:`Quota`,subtitle:`Provider account limits and what is left of them`,icon:(0,$.jsx)(b,{size:16})})}),(0,$.jsx)(E,{children:(0,$.jsxs)(w,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,$.jsx)(o,{"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`},...S.map(e=>({value:e.id,label:e.name}))]}),(0,$.jsx)(o,{"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,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,$.jsx)(l,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>s(e=>!e),"aria-pressed":i,icon:(0,$.jsx)(X,{size:13}),children:`Expiring first`}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:J===0||_,onClick:()=>void H(),icon:(0,$.jsx)(d,{size:13}),children:`Turn off Empty`}),(0,$.jsx)(l,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:_,onClick:()=>void W(),icon:(0,$.jsx)(a,{size:13}),children:`Turn on Available`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,$.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[B.length,` shown`,J>0?` · ${J} empty`:``]}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[O>0?`Refreshing ${O} account${O===1?``:`s`}…`:`Auto-refresh 60s · ${K}`,(0,$.jsx)(ce,{accounts:D}),(0,$.jsx)(l,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:_||k.isPending||D.length===0,icon:(0,$.jsx)(v,{size:13,className:k.isPending?`animate-spin`:void 0}),onClick:()=>k.mutate(D.map(e=>e.id),{onSuccess:e=>{u.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>u.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:`Refresh`})]})]})]})}),(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:f?(0,$.jsx)(p,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):m?(0,$.jsx)(p,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:h instanceof Error?h.message:`Check the console session and retry.`,action:(0,$.jsx)(l,{variant:`secondary`,onClick:()=>void x(),children:`Retry`})}):B.length===0?(0,$.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,$.jsx)(g,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,$.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:B.map(e=>(0,$.jsx)(le,{account:e,onToggle:(e,t)=>void V(e,t),onDelete:e=>P(e),onShowHealth:e=>I(e),onShowResets:e=>R(e)},e.id))})}),F&&(0,$.jsx)(q,{summary:{providerId:F.provider,accountId:F.id,title:F.name,status:F.health?.status??`unknown`,errorCategory:F.health?.lastErrorCategory??void 0,errorMessage:F.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>I(null)}),L&&(0,$.jsx)(se,{account:L,onClose:()=>R(null)}),(0,$.jsx)(C,{open:N!==null,onClose:()=>P(null),onConfirm:async()=>{N&&await re(N)},title:`Delete account?`,message:`Delete "${N?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ue as default};
|
|
Binary file
|
|
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{n as i}from"./select-C9mMoEpJ.js";import{a}from"./toast-C76WrMhc.js";import{n as o}from"./stack-Ca5HxI5i.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:a(`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:a(`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)(i,{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
|