cartethyia 2.5.9 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +15 -42
- package/README.md +11 -10
- package/dist/dashboard/assets/{BannedPage-Brvuj_Eb.js → BannedPage-l6XMnfr9.js} +1 -1
- package/dist/dashboard/assets/BannedPage-l6XMnfr9.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-CqfXtI3y.js → CliToolDetailPage-DwOzAW45.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-DwOzAW45.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-GQeS91bg.js → CliToolsPage-BT3Up3QA.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-BT3Up3QA.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-BDRsTXBB.js → CombosPage-6kYIUpzR.js} +1 -1
- package/dist/dashboard/assets/CombosPage-6kYIUpzR.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-zP8AFHX0.js → ConsoleLogPage-zRnj1mlR.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-zRnj1mlR.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-BmfrNZ14.js → CustomizationPage-C7m-H1Rz.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-C7m-H1Rz.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-C8MR_BdB.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-C8MR_BdB.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-DoreIgm8.js → LoginPage-CbphLvjg.js} +1 -1
- package/dist/dashboard/assets/LoginPage-CbphLvjg.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-C7pDb41R.js → ModelPicker-DVny4S5_.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-DVny4S5_.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-DABu2Wgt.js +1 -0
- package/dist/dashboard/assets/OverviewPage-DABu2Wgt.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-C15x9q13.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-C15x9q13.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-BnoPgA7w.js → ProvidersPage-Dfb2896L.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-Dfb2896L.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-Bq_TGgdb.js → ProxyPage-BaCIdAUt.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-BaCIdAUt.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BsdoCIw1.js +1 -0
- package/dist/dashboard/assets/QuotaPage-BsdoCIw1.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-KVJFh3Ip.js +1 -0
- package/dist/dashboard/assets/SettingsPage-KVJFh3Ip.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-Day3mCOn.js → SetupPage-D4g6vOGc.js} +1 -1
- package/dist/dashboard/assets/SetupPage-D4g6vOGc.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-DQxllnB5.js → SortableList-C93i14BD.js} +1 -1
- package/dist/dashboard/assets/SortableList-C93i14BD.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-uMExoWu1.js → StudioPage-SgQpymjm.js} +1 -1
- package/dist/dashboard/assets/{StudioPage-uMExoWu1.js.gz → StudioPage-SgQpymjm.js.gz} +0 -0
- package/dist/dashboard/assets/{UsagePage-DXa1oR-4.js → UsagePage-BFME-eba.js} +2 -2
- package/dist/dashboard/assets/UsagePage-BFME-eba.js.gz +0 -0
- package/dist/dashboard/assets/{api-keys-DQYLQxpW.js → api-keys-C23S9sgp.js} +1 -1
- package/dist/dashboard/assets/api-keys-C23S9sgp.js.gz +0 -0
- package/dist/dashboard/assets/{app-BIt446yE.js → app-2KhtHCv9.js} +1 -1
- package/dist/dashboard/assets/{app-BIt446yE.js.gz → app-2KhtHCv9.js.gz} +0 -0
- package/dist/dashboard/assets/app-CEeaMHOy.css +2 -0
- package/dist/dashboard/assets/app-CEeaMHOy.css.gz +0 -0
- package/dist/dashboard/assets/{assert-C9FD_JwJ.js → assert-DU6qrMA_.js} +1 -1
- package/dist/dashboard/assets/assert-DU6qrMA_.js.gz +0 -0
- package/dist/dashboard/assets/{badge-CR72dasT.js → badge-CKsF123d.js} +1 -1
- package/dist/dashboard/assets/badge-CKsF123d.js.gz +0 -0
- package/dist/dashboard/assets/{banner-CI9_eSfO.js → banner-8j7uChA9.js} +1 -1
- package/dist/dashboard/assets/banner-8j7uChA9.js.gz +0 -0
- package/dist/dashboard/assets/{card-DS7CQEsO.js → card-CdsSlWA3.js} +1 -1
- package/dist/dashboard/assets/card-CdsSlWA3.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-CNqzrfdb.js → cli-tools-BaFUuFFF.js} +1 -1
- package/dist/dashboard/assets/cli-tools-BaFUuFFF.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-611pSsaX.js → clipboard-button-uL5aYLfW.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-uL5aYLfW.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-k37exjNt.js → dialog-C07hr5_G.js} +1 -1
- package/dist/dashboard/assets/dialog-C07hr5_G.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-CX7N8ucR.js → drawer-BPO1TcKH.js} +1 -1
- package/dist/dashboard/assets/drawer-BPO1TcKH.js.gz +0 -0
- package/dist/dashboard/assets/{entry-CTP8AyiS.js → entry-Bz_CtDfC.js} +1 -1
- package/dist/dashboard/assets/entry-Bz_CtDfC.js.gz +0 -0
- package/dist/dashboard/assets/entry-CwPRKk0d.js +4 -0
- package/dist/dashboard/assets/entry-CwPRKk0d.js.gz +0 -0
- package/dist/dashboard/assets/entry-GJRbmrpA.js +1 -0
- package/dist/dashboard/assets/entry-GJRbmrpA.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-sltk1qUi.js → github-badge-DmQreSDd.js} +1 -1
- package/dist/dashboard/assets/github-badge-DmQreSDd.js.gz +0 -0
- package/dist/dashboard/assets/{index-z3zDOSMM.js → index-Bblu6erR.js} +2 -2
- package/dist/dashboard/assets/index-Bblu6erR.js.gz +0 -0
- package/dist/dashboard/assets/{inline-BhY2sSnO.js → inline-C9dCYaBZ.js} +1 -1
- package/dist/dashboard/assets/inline-C9dCYaBZ.js.gz +0 -0
- package/dist/dashboard/assets/{input-V1umFiBk.js → input-CjCnXweJ.js} +1 -1
- package/dist/dashboard/assets/input-CjCnXweJ.js.gz +0 -0
- package/dist/dashboard/assets/{layout-BBOYycyS.js → layout-V6y8DAkl.js} +1 -1
- package/dist/dashboard/assets/layout-V6y8DAkl.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-1zzZYM0B.js → list-row-CM1AaG_y.js} +1 -1
- package/dist/dashboard/assets/list-row-CM1AaG_y.js.gz +0 -0
- package/dist/dashboard/assets/{live-BivGfuUs.js → live-ta6GMb-8.js} +1 -1
- package/dist/dashboard/assets/live-ta6GMb-8.js.gz +0 -0
- package/dist/dashboard/assets/{model-bans-CmffjLuG.js → model-bans-BmYTmbAk.js} +1 -1
- package/dist/dashboard/assets/model-bans-BmYTmbAk.js.gz +0 -0
- package/dist/dashboard/assets/{mutation-46P0oWMe.js → mutation-g_fduiNw.js} +1 -1
- package/dist/dashboard/assets/mutation-g_fduiNw.js.gz +0 -0
- package/dist/dashboard/assets/{numbers-DkfMR5Qs.js → numbers-BOevJzdz.js} +1 -1
- package/dist/dashboard/assets/numbers-BOevJzdz.js.gz +0 -0
- package/dist/dashboard/assets/{query-keys-BFhGpwR1.js → query-keys-UETqfytp.js} +1 -1
- package/dist/dashboard/assets/query-keys-UETqfytp.js.gz +0 -0
- package/dist/dashboard/assets/{routing-CAb4F37R.js → routing-BPUo-W8d.js} +1 -1
- package/dist/dashboard/assets/routing-BPUo-W8d.js.gz +0 -0
- package/dist/dashboard/assets/{select-C6MMiaio.js → select-C980c4cz.js} +1 -1
- package/dist/dashboard/assets/select-C980c4cz.js.gz +0 -0
- package/dist/dashboard/assets/{settings-DNX9sydi.js → settings--3hxSyry.js} +1 -1
- package/dist/dashboard/assets/settings--3hxSyry.js.gz +0 -0
- package/dist/dashboard/assets/{stack-BHTfXdz_.js → stack-_gfTdLVB.js} +1 -1
- package/dist/dashboard/assets/stack-_gfTdLVB.js.gz +0 -0
- package/dist/dashboard/assets/{state-mPDRlQkl.js → state-2c5V4zo7.js} +1 -1
- package/dist/dashboard/assets/state-2c5V4zo7.js.gz +0 -0
- package/dist/dashboard/assets/{switch-DOmJxg7H.js → switch-Dkke7Naf.js} +1 -1
- package/dist/dashboard/assets/switch-Dkke7Naf.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-Dem0lXQj.js → useMutation-EDFRkn1i.js} +1 -1
- package/dist/dashboard/assets/useMutation-EDFRkn1i.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 -51
- package/migrations/README.md +52 -52
- package/migrations/full-postgres/0020_add_telemetry_event_analytics.sql +77 -0
- package/migrations/full-postgres/0021_add_api_key_concurrency_tolerance.sql +13 -0
- package/migrations/full-postgres/0022_add_inferhub_config_key.sql +17 -0
- package/migrations/full-postgres/0023_drop_api_key_concurrency_tolerance.sql +13 -0
- package/migrations/lite-sqlite3/0020_add_telemetry_event_analytics.sql +69 -0
- package/migrations/lite-sqlite3/0021_add_api_key_concurrency_tolerance.sql +13 -0
- package/migrations/lite-sqlite3/0022_add_inferhub_config_key.sql +17 -0
- package/migrations/lite-sqlite3/0023_drop_api_key_concurrency_tolerance.sql +13 -0
- package/package.json +96 -97
- package/scripts/cli/admin.ts +126 -125
- package/scripts/cli/autostart.ts +237 -237
- package/scripts/cli/background.ts +120 -110
- package/scripts/cli/bin/carte.cjs +8 -8
- package/scripts/cli/bin/cartethyia.cjs +167 -167
- package/scripts/cli/console-menu.ts +308 -275
- package/scripts/cli/controller.ts +145 -0
- package/scripts/cli/doctor.ts +1 -1
- package/scripts/cli/env.ts +99 -99
- package/scripts/cli/gateway.ts +264 -261
- package/scripts/{health.ts → cli/health.ts} +4 -4
- package/scripts/cli/instance.ts +234 -224
- package/scripts/cli/main.ts +188 -164
- package/scripts/cli/platform.ts +64 -64
- package/scripts/cli/prompt.ts +275 -107
- package/scripts/cli/services.ts +88 -88
- package/scripts/cli/setup.ts +445 -445
- package/scripts/cli/start.ts +85 -82
- package/scripts/cli/startup-signal.ts +23 -23
- package/scripts/cli/telemetry.ts +70 -0
- package/scripts/cli/tray/index.ts +263 -263
- package/scripts/cli/tray/windows.ps1 +107 -107
- package/scripts/cli/tray.ts +192 -208
- package/scripts/cli/update.ts +39 -39
- package/scripts/cli/version.ts +67 -67
- package/scripts/cli/wordmark.ts +58 -58
- package/src/boot/app.ts +16 -1
- package/src/boot/dependencies.ts +128 -25
- package/src/config/package-paths.ts +24 -0
- package/src/config/resources.ts +137 -0
- package/src/config/runtime.ts +133 -76
- package/src/config/spec.ts +30 -29
- package/src/config/telemetry.ts +0 -25
- package/src/console/api-keys/bucket-spend.ts +14 -17
- package/src/console/api-keys/contracts.ts +410 -410
- package/src/console/api-keys/routes.ts +12 -0
- package/src/console/audit/store.ts +2 -3
- package/src/console/auth/setup-service.ts +8 -1
- package/src/console/backup/routes.ts +7 -0
- package/src/console/backup/service.ts +463 -463
- package/src/console/backup/store.ts +16 -11
- package/src/console/backup/validate.ts +1 -4
- package/src/console/cli-tools/fs-ops.ts +18 -2
- package/src/console/data-management/contracts.ts +1 -8
- package/src/console/data-management/operations.ts +61 -48
- package/src/console/data-management/routes.ts +4 -2
- package/src/console/domain-registration.ts +25 -3
- package/src/console/inferhub/client.ts +139 -0
- package/src/console/inferhub/key-store.ts +129 -0
- package/src/console/inferhub/normalize.ts +347 -0
- package/src/console/inferhub/routes.ts +411 -0
- package/src/console/inferhub/store.ts +109 -0
- package/src/console/inferhub/types.ts +183 -0
- package/src/console/observability/contracts.ts +2 -41
- package/src/console/observability/store.ts +176 -371
- package/src/console/providers/catalog/public-model-store.ts +0 -0
- package/src/console/providers/catalog/store.ts +23 -36
- package/src/console/quota/account-quota-shared.ts +52 -52
- package/src/console/quota/account-quota-tenant.ts +16 -24
- package/src/console/quota/refresh.ts +441 -441
- package/src/console/remote-support/service.ts +270 -114
- package/src/console/routing/pools/import-parse.ts +206 -206
- package/src/console/routing/pools/operations.ts +543 -543
- package/src/console/routing/pools/probe-verdict.ts +132 -132
- package/src/console/routing/pools/routes.ts +181 -181
- package/src/console/routing/pools/store.ts +1 -1
- package/src/console/settings/contracts.ts +42 -40
- package/src/console/settings/store.ts +25 -25
- package/src/console/share/share-stats.ts +22 -4
- package/src/console/share/share-usage.ts +30 -4
- package/src/console/shared/cursor.ts +15 -0
- package/src/console/updates/repository-updates.ts +40 -39
- package/src/console/updates/routes.ts +12 -0
- package/src/main.ts +13 -5
- package/src/network/pool/resolver.ts +1104 -1104
- package/src/observability/client-name.ts +22 -0
- package/src/observability/event-log.ts +5 -29
- package/src/observability/event-query.ts +690 -0
- package/src/observability/log-ring.ts +26 -2
- package/src/observability/log-sanitize.ts +118 -0
- package/src/observability/logger.ts +17 -13
- package/src/observability/metrics.ts +35 -0
- package/src/observability/payload-capture.ts +114 -41
- package/src/observability/payload-store.ts +249 -24
- package/src/observability/raw-event-writer.ts +118 -0
- package/src/observability/runtime-metrics.ts +71 -1
- package/src/observability/telemetry-buffer.ts +100 -17
- package/src/observability/telemetry-reconciliation.ts +417 -0
- package/src/persistence/boot.ts +20 -9
- package/src/persistence/db-pg.ts +13 -0
- package/src/persistence/db-sqlite.ts +569 -497
- package/src/persistence/dialect.ts +3 -2
- package/src/persistence/migrate.ts +181 -181
- package/src/persistence/schema.ts +1496 -1406
- package/src/persistence/shared-cache.ts +5 -1
- package/src/persistence/stores/api-key-store.ts +581 -581
- package/src/persistence/stores/telemetry-store.ts +124 -63
- package/src/protocol/reasoning-text.ts +30 -0
- package/src/protocol/registry.ts +2 -0
- package/src/protocol/response/chat.ts +33 -7
- package/src/protocol/response/codex.ts +14 -2
- package/src/protocol/response/messages.ts +5 -2
- package/src/providers/authentication/oauth-flow-store.ts +3 -10
- package/src/providers/bundled-discovery-providers.ts +122 -122
- package/src/providers/default-registry.ts +14 -0
- package/src/providers/discovery/catalog/catalog-blob.ts +18 -18
- package/src/providers/discovery/models-dev-catalog.ts +354 -354
- package/src/providers/discovery/probe-phases.ts +43 -7
- package/src/providers/discovery/probing-service.ts +70 -32
- package/src/providers/integrations/antigravity/antigravity.ts +9 -2
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +85 -17
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +934 -934
- package/src/providers/integrations/buddy/buddy-checkin.ts +5 -9
- package/src/providers/integrations/buddy/buddy-discovery-shared.ts +3 -7
- package/src/providers/integrations/buddy/buddy-quota-shared.ts +3 -1
- package/src/providers/integrations/buddy/capabilities.ts +4 -0
- package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +57 -49
- package/src/providers/integrations/buddy/codebuddy/provider.ts +180 -180
- package/src/providers/integrations/buddy/workbuddy/provider.ts +206 -206
- package/src/providers/integrations/buddy/workbuddy/quota.ts +161 -161
- package/src/providers/integrations/claude/claude-quota.ts +2 -2
- package/src/providers/integrations/claude/claude-user-profiles.ts +3 -2
- package/src/providers/integrations/claude/claude.ts +3 -4
- package/src/providers/integrations/cline/cline.ts +94 -8
- package/src/providers/integrations/codex/codex.ts +61 -37
- package/src/providers/integrations/cursor/cursor-catalog.ts +368 -368
- package/src/providers/integrations/cursor/cursor-http2.ts +300 -300
- package/src/providers/integrations/cursor/cursor-identity.ts +2 -4
- package/src/providers/integrations/cursor/cursor-request.ts +11 -0
- package/src/providers/integrations/cursor/cursor.ts +29 -17
- package/src/providers/integrations/cursor/protocol/framing.ts +129 -129
- package/src/providers/integrations/cursor/protocol/messages.ts +2380 -2380
- package/src/providers/integrations/cursor/protocol/struct.ts +305 -305
- package/src/providers/integrations/cursor/protocol/tool-canonical.ts +275 -0
- package/src/providers/integrations/github/github.ts +3 -1
- package/src/providers/integrations/grok/grok-quota.ts +279 -279
- package/src/providers/integrations/grok/grok-ratelimit-store.ts +73 -73
- package/src/providers/integrations/grok/grok-ratelimit.ts +218 -218
- package/src/providers/integrations/hermes.ts +7 -1
- package/src/providers/integrations/inferhub.ts +201 -73
- package/src/providers/integrations/kilo/kilo.ts +152 -152
- package/src/providers/integrations/kiro/kiro-machine-id.ts +2 -4
- package/src/providers/integrations/opencode/provider.ts +2 -0
- package/src/providers/integrations/openrouter/provider.ts +129 -129
- package/src/providers/integrations/qoder/qoder-quota.ts +193 -192
- package/src/providers/integrations/qoder/qoder-realm.ts +106 -106
- package/src/providers/integrations/trae/trae-headers.ts +17 -48
- package/src/providers/integrations/trae/trae-oauth.ts +4 -26
- package/src/providers/integrations/trae/trae-quota.ts +389 -384
- package/src/providers/integrations/trae/trae-realm.ts +15 -2
- package/src/providers/integrations/trae/trae.ts +22 -24
- package/src/providers/integrations/xiaomi-mimo/think-stream.ts +100 -24
- package/src/providers/integrations/zcode/oauth.ts +1 -1
- package/src/providers/operations/account-health-service.ts +605 -279
- package/src/providers/provider-metadata.ts +12 -1
- package/src/providers/provider-model-definition.ts +373 -373
- package/src/providers/provider-probe.ts +3 -0
- package/src/providers/quota/quota-contracts.ts +3 -7
- package/src/providers/search/search-provider.ts +2 -6
- package/src/security/admission/contracts.ts +10 -0
- package/src/security/admission/in-memory-store.ts +89 -14
- package/src/security/admission/lua.ts +191 -182
- package/src/security/admission/redis-store.ts +30 -0
- package/src/security/admission/service.ts +18 -0
- package/src/security/api-key-auth-cache.ts +96 -0
- package/src/security/api-key-auth.ts +11 -100
- package/src/security/client-router-fingerprint.ts +3 -7
- package/src/security/ip-boundary.ts +7 -3
- package/src/shared/coerce.ts +67 -0
- package/src/shared/hash.ts +6 -0
- package/src/shared/time.ts +7 -0
- package/src/transport/dispatch/attempt-finalize.ts +26 -138
- package/src/transport/dispatch/attempt-loop.ts +103 -81
- package/src/transport/dispatch/capture-policy.ts +78 -0
- package/src/transport/dispatch/proxy-request.ts +4 -2
- package/src/transport/dispatch/streaming/encoder.ts +111 -5
- package/src/transport/dispatch/streaming/stream.ts +19 -2
- package/src/transport/dispatch/streaming/thinking-loop.ts +300 -0
- package/src/transport/failure-policy.ts +27 -0
- package/src/transport/guards/abuse-guard.ts +2 -2
- package/src/transport/guards/auth-guard.ts +17 -0
- package/src/transport/guards/body-policy.ts +3 -2
- package/src/transport/guards/concurrency-guard.ts +89 -13
- package/src/transport/guards/early-rejection-capture.ts +43 -3
- package/src/transport/guards/error-lifecycle.ts +10 -2
- package/src/transport/guards/guard-errors.ts +23 -0
- package/src/transport/guards/headroom-guard.ts +41 -7
- package/src/transport/guards/pipeline.ts +24 -0
- package/src/transport/guards/request-context.ts +2 -1
- package/src/transport/routing/admission.ts +51 -9
- package/src/transport/routing/bounded-lru.ts +49 -0
- package/src/transport/routing/candidate-index.ts +88 -0
- package/src/transport/routing/reservations.ts +121 -7
- package/src/transport/routing/round-robin.ts +10 -22
- package/src/transport/routing/route-catalog.ts +26 -13
- package/src/transport/routing/route-model.ts +22 -2
- package/src/transport/routing/router.ts +53 -31
- package/src/transport/surface/chat/encode.ts +2 -3
- package/src/transport/surface/chat/parse.ts +2 -1
- package/src/transport/surface/dialects.ts +11 -3
- package/src/transport/surface/messages/encode.ts +2 -1
- package/src/transport/surface/messages/parse.ts +3 -1
- package/src/transport/surface/messages/stream.ts +2 -6
- package/src/workers/maintenance-lease.ts +200 -0
- package/src/workers/scheduler.ts +101 -1
- package/dist/dashboard/assets/BannedPage-Brvuj_Eb.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-CqfXtI3y.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-GQeS91bg.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BDRsTXBB.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-zP8AFHX0.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-BmfrNZ14.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-Dn3M6WZc.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-Dn3M6WZc.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-DoreIgm8.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-C7pDb41R.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CvvD1Ugk.js +0 -1
- package/dist/dashboard/assets/OverviewPage-CvvD1Ugk.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-Clbn1gsW.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-Clbn1gsW.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BnoPgA7w.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Bq_TGgdb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-D9DHXvom.js +0 -1
- package/dist/dashboard/assets/QuotaPage-D9DHXvom.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-7xV8WkWL.js +0 -1
- package/dist/dashboard/assets/SettingsPage-7xV8WkWL.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-Day3mCOn.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DQxllnB5.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-DXa1oR-4.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-DQYLQxpW.js.gz +0 -0
- package/dist/dashboard/assets/app-CX_Z8cMs.css +0 -2
- package/dist/dashboard/assets/app-CX_Z8cMs.css.gz +0 -0
- package/dist/dashboard/assets/assert-C9FD_JwJ.js.gz +0 -0
- package/dist/dashboard/assets/badge-CR72dasT.js.gz +0 -0
- package/dist/dashboard/assets/banner-CI9_eSfO.js.gz +0 -0
- package/dist/dashboard/assets/card-DS7CQEsO.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-CNqzrfdb.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-611pSsaX.js.gz +0 -0
- package/dist/dashboard/assets/dialog-k37exjNt.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CX7N8ucR.js.gz +0 -0
- package/dist/dashboard/assets/entry-B9Xvtnfj.js +0 -1
- package/dist/dashboard/assets/entry-B9Xvtnfj.js.gz +0 -0
- package/dist/dashboard/assets/entry-ByMGkR3C.js +0 -4
- package/dist/dashboard/assets/entry-ByMGkR3C.js.gz +0 -0
- package/dist/dashboard/assets/entry-CTP8AyiS.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-sltk1qUi.js.gz +0 -0
- package/dist/dashboard/assets/index-z3zDOSMM.js.gz +0 -0
- package/dist/dashboard/assets/inline-BhY2sSnO.js.gz +0 -0
- package/dist/dashboard/assets/input-V1umFiBk.js.gz +0 -0
- package/dist/dashboard/assets/layout-BBOYycyS.js.gz +0 -0
- package/dist/dashboard/assets/list-row-1zzZYM0B.js.gz +0 -0
- package/dist/dashboard/assets/live-BivGfuUs.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-CmffjLuG.js.gz +0 -0
- package/dist/dashboard/assets/mutation-46P0oWMe.js.gz +0 -0
- package/dist/dashboard/assets/numbers-DkfMR5Qs.js.gz +0 -0
- package/dist/dashboard/assets/query-keys-BFhGpwR1.js.gz +0 -0
- package/dist/dashboard/assets/routing-CAb4F37R.js.gz +0 -0
- package/dist/dashboard/assets/select-C6MMiaio.js.gz +0 -0
- package/dist/dashboard/assets/settings-DNX9sydi.js.gz +0 -0
- package/dist/dashboard/assets/stack-BHTfXdz_.js.gz +0 -0
- package/dist/dashboard/assets/state-mPDRlQkl.js.gz +0 -0
- package/dist/dashboard/assets/switch-DOmJxg7H.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-Dem0lXQj.js.gz +0 -0
- package/scripts/build/aot.ts +0 -143
- package/scripts/build/build.ts +0 -24
- package/scripts/build/compile.ts +0 -88
- package/scripts/build/restart.ts +0 -120
- package/scripts/build/start.ts +0 -25
- package/src/observability/event-compaction.ts +0 -317
- package/src/observability/event-day-index.ts +0 -440
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{n as i}from"./terminal-0_IjPWTk.js";import{a,i as o,n as s,r as c}from"./model-bans-BmYTmbAk.js";import{n as l,r as u,t as d}from"./concurrency-BDF0ok7y.js";import{C as f,E as p,O as m,T as h,c as g,s as _,v,x as y}from"./numbers-BOevJzdz.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as b}from"./SortableList-C93i14BD.js";import{t as x}from"./database-Dz9N3zGd.js";import{t as S}from"./eye-off-Bk5g2luF.js";import{t as C}from"./eye-C_hawfH4.js";import{t as te}from"./gauge-BbIMy7MB.js";import{n as w,r as T,t as E}from"./state-2c5V4zo7.js";import{t as D}from"./key-round-UkavsGxp.js";import{n as ne,r as re,t as O}from"./clipboard-button-uL5aYLfW.js";import{t as k}from"./dialog-C07hr5_G.js";import{t as A}from"./pencil-768ysRAr.js";import{t as j}from"./plus-DIdX_g-x.js";import{t as M}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as N}from"./route-CNSNj9Zm.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./shield-check-DVS0Foqh.js";import{n as P,r as se,t as F}from"./settings--3hxSyry.js";import{t as ce}from"./trash-Cppn5c3R.js";import{C as le,T as ue,b as de,x as fe}from"./assert-DU6qrMA_.js";import{l as I,o as pe,t as L}from"./query-keys-UETqfytp.js";import{t as me}from"./useMutation-EDFRkn1i.js";import{it as he,j as ge,lt as _e,ot as ve,z as ye}from"./entry-CwPRKk0d.js";import{n as R,r as z,t as B}from"./card-CdsSlWA3.js";import{t as V}from"./use-clipboard-B0Sy03fE.js";import{n as be}from"./download-dRFo5_Wu.js";import{c as H,d as U}from"./tokens-COzario9.js";import{t as W}from"./badge-CKsF123d.js";import{n as G,t as xe}from"./input-CjCnXweJ.js";import{t as Se}from"./select-C980c4cz.js";import{t as Ce}from"./ModelPicker-DVny4S5_.js";import{t as K}from"./switch-Dkke7Naf.js";import{t as q}from"./stack-_gfTdLVB.js";import{n as J}from"./inline-C9dCYaBZ.js";import{a as we,c as Y,d as Te,f as Ee,i as X,l as Z,n as De,o as Oe,r as ke,s as Ae,t as je,u as Me}from"./api-keys-C23S9sgp.js";import{a as Ne,i as Pe,n as Fe,r as Ie}from"./cli-tools-BaFUuFFF.js";import{t as Le}from"./layout-V6y8DAkl.js";import{s as Re}from"./quota-DZGyp0N5.js";var ze=e(`lock-keyhole`,[[`circle`,{cx:`12`,cy:`16`,r:`1`,key:`1au0dj`}],[`rect`,{x:`3`,y:`10`,width:`18`,height:`12`,rx:`2`,key:`6s8ecr`}],[`path`,{d:`M7 10V7a5 5 0 0 1 10 0v3`,key:`1pqi11`}]]),Be=e(`radio-tower`,[[`path`,{d:`M4.9 16.1C1 12.2 1 5.8 4.9 1.9`,key:`s0qx1y`}],[`path`,{d:`M7.8 4.7a6.14 6.14 0 0 0-.8 7.5`,key:`1idnkw`}],[`circle`,{cx:`12`,cy:`9`,r:`2`,key:`1092wv`}],[`path`,{d:`M16.2 4.8c2 2 2.26 5.11.8 7.47`,key:`ojru2q`}],[`path`,{d:`M19.1 1.9a9.96 9.96 0 0 1 0 14.1`,key:`rhi7fg`}],[`path`,{d:`M9.5 18h5`,key:`mfy3pd`}],[`path`,{d:`m8 22 4-11 4 11`,key:`25yftu`}]]),Ve=e(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),He=e(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Ue=e(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),We=e(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Ge=e(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Ke=e(`shield-x`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]]),qe=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),Je=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Ye=e(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),Xe=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],Ze=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Qe={"routing:invoke":`Call /v1/* gateway routes within this tenant.`,"routing:cli_mapping":`Resolve persisted CLI source→target model mappings.`,"search:invoke":`Call POST /v1/search with exa.`,"dashboard:read":`Read this tenant's configuration and usage.`,"dashboard:write":`Modify this tenant's configuration.`,"providers:read":`Read provider rows, including accounts.`,"providers:write":`Add, modify, or delete provider rows and their credentials.`,"models:read":`Read catalog model rows.`,"models:write":`Add, modify, or delete catalog model rows.`},$e={"routing:invoke":N,"routing:cli_mapping":N,"search:invoke":ae,"dashboard:read":C,"dashboard:write":A,"providers:read":he,"providers:write":ze,"models:read":u,"models:write":x},et={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},tt=[{label:`1M`,amount:1e6,description:`1 million`},{label:`100M`,amount:1e8,description:`100 million`},{label:`1B`,amount:1e9,description:`1 billion`},{label:`1T`,amount:0xe8d4a51000,description:`1 trillion`}];function nt(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.match(/^([\d.]+)\s*([kmbt])?$/);if(!n)return;let r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return;let i=n[2]?et[n[2]]??1:1;return Math.round(r*i)}function rt(e){if(e==null)return``;let t=tt.find(t=>t.amount===e);return t?t.label:e>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function it(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function at(e){let t=it(e);return e.trim()===``?null:t}function ot({label:e,value:t,onChange:n,disabled:r}){let i=nt(t),a=tt.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{label:e,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. 1M, 500K`,disabled:r}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mt-2`,role:`group`,"aria-label":`${e} presets`,children:tt.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":a===e.label,"aria-label":`${e.label}, ${e.description} tokens`,onClick:()=>n(e.label),disabled:r,className:`py-0.5 px-3 rounded-chip text-micro font-semibold`,style:{cursor:r?`not-allowed`:`pointer`,border:`1px solid ${a===e.label?`var(--accent)`:`var(--inner-border)`}`,background:a===e.label?`var(--accent-soft)`:`transparent`,color:a===e.label?`var(--accent)`:`var(--text-tertiary)`},children:e.label},e.label))})]})}function st({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Ie(),s=Fe(),c=a.data?.enabled??!1,l=r&&c,u=a.data?.mappings.length??0,d=o.isPending||s.isPending;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:l?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(N,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(K,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>_.success(`Saved remote routing for ${e.name}.`),onError:e=>_.error(I(e,`Could not save remote routing.`))})}}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>_.success(`Cleared remote routes for ${e.name}.`),onError:e=>_.error(I(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function ct({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ne().data??[]).filter(e=>e.mappingSupported);return(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`remote-routing-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(N,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Remote routing`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Route this key's CLI model calls through persisted mappings and grant routing:cli_mapping. Applies immediately — no save needed.`})]}),e.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Save the key first to configure per-tool remote routing mappings.`}):a.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`No CLI tools with mapping support are currently registered.`}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(st,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function lt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ut(e,t){return e===`personal`?t??null:null}function dt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...Xe]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function ft({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:o}){let[s,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,m]=(0,Q.useState)(``),[h,v]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[y,ee]=(0,Q.useState)(rt(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(rt(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(rt(t?.lifetimeTokenBudget??null)),[w,T]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[E,re]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[O,k]=(0,Q.useState)(()=>dt(t)),[A,j]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[M,ie]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[ae,P]=(0,Q.useState)(!1),[F,ce]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(fe).filter(e=>e!==void 0))]:[]}),[le,ue]=(0,Q.useState)(()=>t?.notesTitle??``),[pe,L]=(0,Q.useState)(()=>t?.notesSubtitle??``),[me,he]=(0,Q.useState)(()=>t?.notesBody??``),[ge,ye]=(0,Q.useState)(t?.sharePopupEnabled??!0),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(!1),[be,H]=(0,Q.useState)(null),U=t?.sharePopupImageMime!==void 0,W=R??(U&&!B&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{U||R!==null||B||fetch(`/donation/qris-risun-marke.png`).then(e=>e.ok?e.blob():Promise.reject(e.status)).then(e=>{let{promise:t,resolve:n,reject:r}=Promise.withResolvers(),i=new FileReader;return i.onload=()=>n(i.result),i.onerror=r,i.readAsDataURL(e),t}).then(e=>z(e)).catch(()=>{})},[]);let[Se,q]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[J,we]=(0,Q.useState)(t?.sharePopupBody??`Scan the QR code above with any QRIS-compatible banking or e-wallet app to support this gateway's upkeep. Every contribution helps keep the service running — thank you! 🙏`),[Y,Te]=(0,Q.useState)(t?.keyMode??`personal`),X=w===`one-time`,Z=e===`edit`,De=Ee(),Oe=e=>k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:s.trim(),...lt(Y,p,d),scopes:O,modelAccessMode:A,modelList:M,clientRouterDenylist:F,requestsPerMinute:at(h),maxConcurrentRequests:at(E),dailyTokenLimit:X?null:nt(y)??null,monthlyTokenLimit:X?null:nt(b)??null,lifetimeTokenBudget:X?nt(S)??null:null,notesTitle:le.trim(),notesSubtitle:pe.trim(),notesBody:me.trim(),sharePopupEnabled:ge,...R===null?B?{sharePopupImage:null}:{}:{sharePopupImage:R},sharePopupTitle:Se.trim(),sharePopupBody:J.trim()})};return(0,Q.useEffect)(()=>{o?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!s.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(D,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Credential mode`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Credential mode`,className:`flex gap-4`,children:[`personal`,`share`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":Y===e,disabled:n||Z,onClick:()=>Te(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,style:{border:`1px solid var(--inner-border)`,color:Y===e?`var(--accent)`:`var(--text-secondary)`,background:Y===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Z?`not-allowed`:`pointer`,opacity:Z&&Y!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)(Je,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Ye,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Y===`share`?`A share template does not authenticate requests. Recipients generate their own child key from its public enrollment page.`:`A personal key authenticates requests directly; its secret is shown once when created or rotated.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 min-w-0 max-medium:grid-cols-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(G,{label:`Name`,value:s,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(G,{label:`Key prefix`,value:d,onChange:e=>f(e.target.value),placeholder:`pn-carte- (default)…`,disabled:n||p.trim().length>0})]}),Y===`personal`&&(0,$.jsx)(G,{label:`Custom API key value (optional)`,value:p,onChange:e=>m(e.target.value),placeholder:`Leave blank to generate…`,disabled:n})]}),e===`edit`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(G,{label:`Name`,value:s,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(ne,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share notes`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional copy shown on the public share page.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(G,{label:`Title`,value:le,onChange:e=>ue(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(G,{label:`Subtitle`,value:pe,onChange:e=>L(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(G,{label:`Body`,value:me,onChange:e=>he(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Limits`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Keep this credential predictable under load.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(G,{label:`Requests per minute`,type:`number`,min:`0`,value:h,onChange:e=>v(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(G,{label:`Max concurrent requests`,type:`number`,min:`0`,value:E,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:E===``?`No concurrency limit, so the tenant allowance does nothing.`:`Limit ${E} concurrent. Refusals name this number; the allowance above it is tenant-wide and set in Settings.`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-panel border border-inner-border px-4 py-3 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{size:14,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Token budget`]}),(0,$.jsx)(`p`,{className:`mt-1 text-text-tertiary text-micro`,children:X?`One-time cap; it does not reset.`:`Daily and monthly limits reset automatically.`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-inset border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>T(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:X?`transparent`:`var(--accent-soft)`,color:X?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>T(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:X?`var(--accent-soft)`:`transparent`,color:X?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(ze,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(ot,{label:`One-time token limit`,value:S,onChange:C,disabled:n}):(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(ot,{label:`Daily token limit`,value:y,onChange:ee,disabled:n}),(0,$.jsx)(ot,{label:`Monthly token limit`,value:b,onChange:x,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,"aria-labelledby":`share-popup-heading`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{id:`share-popup-heading`,className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(We,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(K,{checked:ge,onChange:e=>ye(e),disabled:n,label:`Enable popup`})]}),ge?(0,$.jsxs)(`div`,{className:`flex gap-7 items-start mt-2 min-w-0 max-medium:flex-col max-medium:items-stretch`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 w-100 shrink-0 max-medium:w-auto`,children:[W?(0,$.jsx)(`img`,{className:`block w-full h-66 object-cover border border-inner-border rounded-control bg-surface-1 max-medium:h-80`,src:W,alt:`Popup image preview`}):(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-66 object-cover border border-dashed border-inner-border rounded-control bg-surface-1 text-text-tertiary text-badge max-medium:h-80`,"aria-hidden":`true`,children:(0,$.jsx)(`span`,{children:`No image`})}),(0,$.jsx)(xe,{id:`share-popup-image`,accept:Ze.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(H(null),t.size>2097152){z(null),H(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{z(String(n.result)),V(!1)},n.onerror=()=>H(`Could not read that file.`),n.readAsDataURL(t)}}),W?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{z(null),V(!0),H(null)},children:`Remove image`}):null,be?(0,$.jsx)(`p`,{className:`form-error`,children:be}):null,(0,$.jsx)(`p`,{className:`m-0 text-text-tertiary text-badge leading-normal`,children:`PNG, JPEG, WebP, or GIF up to 2 MB.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 flex-1 [&_.form-group]:gap-2`,children:[(0,$.jsx)(G,{label:`Popup title`,value:Se,onChange:e=>q(e.target.value),maxLength:120,placeholder:`Support this gateway`,disabled:n}),(0,$.jsxs)(`div`,{className:`form-group`,children:[(0,$.jsx)(`label`,{className:`form-label`,htmlFor:`share-popup-copy`,children:`Message`}),(0,$.jsx)(`textarea`,{className:`form-textarea`,id:`share-popup-copy`,value:J,onChange:e=>we(e.target.value),maxLength:1200,rows:3,placeholder:`If this service helps you, consider supporting its upkeep…`,disabled:n})]})]})]}):null]}),(0,$.jsxs)(`details`,{className:`group min-w-0 col-span-full rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(se,{size:18,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-body font-bold text-text-primary`,children:`Access`}),(0,$.jsx)(`span`,{className:`mt-1 block text-badge text-text-tertiary`,children:t?.isDefault?`Default gateway key · all tenant permissions, including gateway routing and remote debugging.`:`Choose model, router, and dashboard permissions for this key.`})]})]}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 rounded-control border border-inner-border bg-surface-1 px-3 py-2 text-micro font-semibold text-text-secondary`,children:[O.length,`/`,Xe.length,` grants`,(0,$.jsx)(_e,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-inner-border p-4`,children:[t?.isDefault?(0,$.jsxs)(`div`,{className:`flex items-start gap-3 rounded-control border border-accent/30 bg-accent-soft p-4 text-badge text-text-secondary`,children:[(0,$.jsx)(oe,{size:16,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`m-0`,children:[`This default API key is provisioned with every tenant permission, including `,(0,$.jsx)(`code`,{children:`routing:invoke`}),` and`,` `,(0,$.jsx)(`code`,{children:`routing:cli_mapping`}),`. Those grant gateway access and authorization to use remote CLI mappings; each client's mapping toggle below still controls whether those routes are active. You can remove individual grants here.`]})]}):null,(0,$.jsxs)(`div`,{className:`grid grid-cols-access gap-5 min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`model-access-heading`,className:`flex flex-col gap-3 min-w-0 rounded-card border border-inner-border bg-surface-1 p-4`,children:[(0,$.jsxs)(`h4`,{id:`model-access-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-2`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":A===e,disabled:n,onClick:()=>j(e),title:e===`whitelist`?`Only the listed models may be used. An empty list allows every model.`:`The listed models are refused. Everything else is allowed.`,className:`flex-1 py-2 px-3 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${A===e?`var(--accent)`:`var(--inner-border)`}`,background:A===e?`var(--accent-soft)`:`var(--surface-2)`,color:A===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(oe,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ke,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:A===`whitelist`?`Only these models may be called. Empty = all allowed.`:`These models are refused. Everything else is allowed.`}),(0,$.jsx)(`div`,{className:`flex gap-1.5 flex-wrap min-h-6`,children:M.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:A===`whitelist`?`All models allowed`:`No models blocked`}):M.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-1.5 text-badge bg-accent-soft text-accent py-1 px-3 rounded-chip border border-accent`,children:[e,(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e} from the model list`,onClick:()=>ie(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>P(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(Ce,{open:ae,onClose:()=>P(!1),selected:M,onToggle:e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:A===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`routing-blocking-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,children:[(0,$.jsxs)(`h4`,{id:`routing-blocking-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(N,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing & Client Blocking`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Control which gateway routes this key can call and which client apps are blocked before routing.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col divide-y divide-inner-border`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Gateway routing`}),Xe.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(N,{size:14,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Blocked client apps`}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:F.includes(e.id)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(a,{size:14,className:`shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption font-semibold text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsx)(`p`,{className:`mt-0.5 mb-0 text-badge text-text-tertiary`,children:e.id===`9router`?`9router, Omniroute, and Baazar Probes`:`Fingerprint-based detection — best-effort; unrecognised clients are never matched`})]})]}),(0,$.jsx)(K,{checked:F.includes(e.id),onChange:t=>ce(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]})]}),(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(ct,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:O.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==O.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...O,`routing:cli_mapping`])]:O.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>_.error(I(e,`Could not update the key's routing scope.`))})}})})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,children:[(0,$.jsxs)(`h4`,{id:`dashboard-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(ve,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Grants read or write access to console data — providers, models, configuration, and usage stats. No routing is implied by these scopes.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2 p-4`,children:Xe.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=$e[e];return(0,$.jsx)(t,{size:14,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`})})(),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function pt({secret:e,onClose:t}){return(0,$.jsx)(k,{open:e!==null,onClose:t,title:`New API key`,description:`Copy it now, or reveal it again later from the key's Share button.`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(`p`,{className:`text-body text-text-secondary m-0 leading-normal`,children:`A personal key stays recoverable. Open the key's Share button and choose Reveal to see it again and copy it. Rotating the key replaces this secret, and any client still using it starts getting 401s.`}),(0,$.jsx)(`code`,{className:`block rounded-inset border border-inner-border bg-surface-1 py-5 px-6 text-caption text-text-primary break-all`,children:e}),(0,$.jsxs)(`div`,{className:`flex gap-4 flex-wrap`,children:[(0,$.jsx)(O,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(h,{size:13}),onClick:()=>{e!==null&&(be(`cartethyia-api-key.txt`,`Cartethyia API key\n\n${e}\n\nKeep this secret. Reveal it again from the key's Share button.\n`,`text/plain;charset=utf-8`),_.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function mt(e,t){if(t)return`Permanent — lift manually`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=e-Date.now(),i=n.toLocaleString();if(r<=0)return`${i} (lapsed)`;let a=Math.ceil(r/6e4);if(a<60)return`${i} (in ${a}m)`;let o=Math.floor(a/60);return o<24?`${i} (in ${o}h)`:`${i} (in ${Math.floor(o/24)}d)`}function ht({onClose:e}){let t=s(!0),n=c(),[r,i]=(0,Q.useState)(null),a=t.data??[];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{open:!0,onClose:e,title:`Banned Users`,description:`A caller is banned after repeated invalid-model requests. A ban is scoped to the API key that made them, so other keys used from the same address keep working — unless an operator banned the address outright.`,size:`lg`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h4`,{className:`text-caption font-semibold text-text-secondary mb-4`,children:[`Active bans (`,a.length,`)`]}),t.isPending?(0,$.jsx)(T,{compact:!0,label:`Loading banned users…`}):t.isError?(0,$.jsx)(w,{compact:!0,message:I(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(E,{compact:!0,title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ge,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Le,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`API key`,`Reason`,`Applies to`,`Lapses`,``],children:a.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.ip}),(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-secondary whitespace-nowrap`,children:e.apiKeyId?`${e.apiKeyId.slice(0,8)}…`:`—`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.reason===`repeated_invalid_model_requests`?`Repeated invalid-model requests`:e.reason}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:e.apiKeyId?`This key only`:`All keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:mt(e.expiresAt,e.permanent===!0)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.identity))})})]}),(0,$.jsx)(J,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(ye,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.identity),_.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}${r.apiKeyId?` for this API key`:``}? The caller can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var gt=e=>(e??0).toLocaleString(),_t=e=>e?new Date(e).toLocaleString():`—`;function vt({keyId:e}){let t=we(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(`code`,{title:i&&n?n:void 0,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:i&&n?n:`••••••••••••••••`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(S,{size:13}):(0,$.jsx)(C,{size:13}),loading:t.isPending,disabled:t.isPending,onClick:()=>{if(n!==null){a(e=>!e);return}t.mutate({keyId:e},{onSuccess:e=>{r(e.secret),a(!0)},onError:e=>_.error(I(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(O,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function yt({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:e}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:t==null?`Unlimited`:gt(t)})]})}function bt(e){return e?{title:`Regenerate this key?`,message:`This rotates the key credential. Any client still using the current secret starts getting 401s immediately, and the old secret cannot be recovered. The handoff link is re-pointed to reveal the new key.`,confirmLabel:`Regenerate key`}:{title:`Regenerate this link?`,message:`This replaces the link URL; the current URL stops resolving immediately. Recipients keep the keys they already generated and keep working — but no one can enroll through the old link again.`,confirmLabel:`Regenerate link`}}function xt({consumed:e,budget:t}){let n=t==null||t<=0,r=n?100:Math.min(100,e/t*100),i=!n&&e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Lifetime budget`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:n?`${H(e)} · Unlimited`:`${H(e)} / ${H(t)}`})]}),(0,$.jsx)(`div`,{className:`h-3 overflow-hidden rounded bg-inner-border`,role:`progressbar`,"aria-label":`Lifetime token budget consumed`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(r),"aria-valuetext":n?`${H(e)} tokens consumed, no lifetime budget set`:`${H(e)} of ${H(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}var St=6;function Ct(e){return e.filter(e=>e.revokedAt===null).length}function wt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function Tt({consumed:e,budget:t}){if(t==null)return(0,$.jsx)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota used`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:H(e)})]})});let n=t>0?Math.min(100,e/t*100):0,r=t>0?Math.max(0,100-e/t*100):100,i=Math.max(0,t-e),a=Re(e>=t?0:r),o=e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota`}),(0,$.jsxs)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:[H(e),` / `,H(t)]}),(0,$.jsx)(`span`,{className:`border rounded-chip px-4 py-0.5 text-caption font-bold whitespace-nowrap tabular-nums`,style:{color:a.text,borderColor:a.text},children:o?`Exhausted`:`${H(i)} left`})]}),(0,$.jsx)(`div`,{className:`h-3 overflow-hidden rounded bg-inner-border`,role:`progressbar`,"aria-label":`Total quota consumed`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(n),"aria-valuetext":`${H(e)} of ${H(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:o?`h-full rounded bg-status-danger`:`h-full rounded`,style:{width:`${n}%`,background:o?void 0:a.bar}})})]})}function Et({parentId:e,childId:t}){let n=Me(e,t);if(n.isPending)return(0,$.jsx)(T,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(w,{compact:!0,message:I(n.error,`Could not load activity.`),onRetry:()=>void n.refetch()});let r=n.data;return r?(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6 border-t border-inner-border bg-surface-1 px-6 py-5`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Top models`}),r.models.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Errors`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:r.models.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:e.modelId}),(0,$.jsx)(`td`,{children:gt(e.todayRequests)}),(0,$.jsx)(`td`,{children:gt(e.todayErrors)}),(0,$.jsx)(`td`,{children:H(e.todayTokens)})]},`${e.providerId??``}-${e.modelId}-${t}`))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No model activity yet.`})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Recent requests`}),r.requests.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`}),(0,$.jsx)(`th`,{scope:`col`,children:`Time`})]})}),(0,$.jsx)(`tbody`,{children:r.requests.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`td`,{children:[e.providerId??`Provider`,`/`,e.modelId??`Model`]}),(0,$.jsxs)(`td`,{children:[e.status,e.httpStatus?` · ${e.httpStatus}`:``]}),(0,$.jsx)(`td`,{children:H(e.totalTokens)}),(0,$.jsx)(`td`,{children:_t(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function Dt({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,o]=(0,Q.useState)(`active`),[s,c]=(0,Q.useState)(null),l=ue(),u=Y(),f=ke(),p=Ae(),m=Z(e.id),h=e.keyMode!==`share`,v=Te(h?null:e.id),y=v.data??[],b=i===`active`?y.filter(e=>e.revokedAt===null):y.filter(e=>e.revokedAt!==null),x=y.filter(e=>e.revokedAt===null&&e.allTime.totalTokens===0);(0,Q.useEffect)(()=>{r(null)},[e.id]);let S=async(t,n)=>{let r=(await d(t,St,t=>p.mutateAsync({parentKeyId:e.id,childKeyId:t.id,deferInvalidation:!0}))).filter(e=>e.status===`fulfilled`).length;await l.invalidateQueries({queryKey:L.apiKeys.sharedKeys(e.id)}),await l.invalidateQueries({queryKey:L.apiKeys.all}),await v.refetch();let i=t.length-r;i>0?_.error(`Revoked ${r} of ${t.length} ${n}; ${i} failed.`):_.success(`Revoked ${r} ${n}.`)},C=u.isPending||f.isPending,[te,D]=(0,Q.useState)(!1),ne=async()=>{if(h){let n=await f.mutateAsync({keyId:e.id});t?.(n.secret);return}await u.mutateAsync({keyId:e.id,regenerate:!0}),_.success(`Link regenerated; the previous URL no longer works.`)},k=()=>{u.mutate({keyId:e.id},{onError:e=>_.error(I(e,`Could not create link.`))})},A=m.data?.url??null,j=bt(h);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:m.isPending?(0,$.jsx)(T,{label:`Loading link…`,compact:!0}):m.isError?(0,$.jsx)(w,{compact:!0,message:I(m.error,`Could not load the link.`),onRetry:()=>void m.refetch()}):A?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(re,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:A,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:A}),(0,$.jsx)(O,{value:A,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),loading:C,disabled:C,onClick:()=>D(!0),children:`Regenerate`})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(re,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`span`,{className:`flex-auto text-caption text-text-tertiary`,children:`No link yet.`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,loading:C,disabled:C,onClick:k,children:`Create link`})]})}),h?(0,$.jsxs)(`section`,{"aria-label":`API key`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`API key`})}),(0,$.jsx)(vt,{keyId:e.id})]}):null,h?(0,$.jsxs)(`section`,{"aria-label":`Usage`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Usage`})}),(0,$.jsxs)(`dl`,{className:`m-0 flex flex-wrap gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:`Lifetime tokens`}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:H(e.tokensConsumed)})]}),(0,$.jsx)(yt,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(yt,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(yt,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(xt,{consumed:e.tokensConsumed,budget:e.lifetimeTokenBudget})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`section`,{"aria-label":`Total quota`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Total quota`})}),(0,$.jsx)(Tt,{consumed:wt(y),budget:e.lifetimeTokenBudget})]}),(0,$.jsxs)(`section`,{"aria-label":`Recipients`,className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`strong`,{className:`text-caption`,children:`Recipients`}),(0,$.jsxs)(`span`,{className:`mr-2 ml-auto text-caption text-text-tertiary tabular-nums`,children:[`Active users: `,Ct(y)]}),(0,$.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-chip border border-inner-border p-0.5`,role:`group`,"aria-label":`Filter recipients by status`,children:[`active`,`revoked`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":i===e,onClick:()=>o(e),className:`rounded-chip border-0 px-3 py-1 text-badge font-semibold capitalize cursor-pointer ${i===e?`bg-surface-1 text-text-primary`:`bg-transparent text-text-secondary hover:text-text-primary`}`,children:e},e))}),s===null?null:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-chip border border-danger-border bg-surface-2 px-3 py-1`,children:[(0,$.jsx)(`span`,{className:`text-badge text-text-secondary`,children:s===`all`?`Revoke ${b.length}?`:`Revoke ${x.length} unused?`}),(0,$.jsx)(g,{variant:`danger`,size:`sm`,loading:p.isPending,onClick:()=>{let e=s===`all`?b:x,t=s===`all`?`recipients`:`unused recipients`;c(null),S(e,t)},children:`Confirm`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:`Cancel`})]}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:x.length===0||p.isPending,title:x.length===0?`No active recipient has spent zero tokens`:`Revoke ${x.length} recipient${x.length===1?``:`s`} that never spent a token`,onClick:()=>c(`unused`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:b.length===0||p.isPending,title:b.length===0?`Nothing to revoke in this view`:`Revoke all ${b.length} listed recipient${b.length===1?``:`s`}`,onClick:()=>c(`all`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke all`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>void v.refetch(),icon:(0,$.jsx)(ie,{size:13,className:v.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),v.isPending&&!v.data?(0,$.jsx)(T,{label:`Loading recipients…`,compact:!0}):v.isError?(0,$.jsx)(w,{compact:!0,message:I(v.error,`Could not load recipients.`),onRetry:()=>void v.refetch()}):b.length===0?(0,$.jsx)(E,{compact:!0,title:i===`revoked`?`No revoked recipients`:`No active recipients`,message:i===`revoked`?`Revoked keys appear here once a recipient's key is revoked.`:`Keys generated through this link appear here with their masked client IP and token usage.`}):(0,$.jsx)(`div`,{className:`data-table-container max-h-[46vh]`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-12`,"aria-label":`Expand`}),(0,$.jsx)(`th`,{scope:`col`,children:`Key`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Lifetime`}),(0,$.jsx)(`th`,{scope:`col`,children:`Last activity`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:b.map(t=>{let i=n===t.id;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,className:`grid h-11 w-11 place-items-center rounded-chip border-0 bg-transparent p-0 text-text-secondary hover:bg-hover hover:text-text-primary`,"aria-expanded":i,"aria-label":i?`Collapse recipient`:`Expand recipient`,onClick:()=>r(i?null:t.id),children:i?(0,$.jsx)(_e,{size:14}):(0,$.jsx)(ee,{size:14})})}),(0,$.jsxs)(`td`,{children:[(0,$.jsxs)(`code`,{children:[t.label||t.keyPrefix||`key`,`…`]}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary wrap-anywhere`,children:t.issuedClientIp??`IP hidden`})]}),(0,$.jsx)(`td`,{children:t.revokedAt?`revoked`:`active`}),(0,$.jsx)(`td`,{children:H(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:H(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:_t(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`danger`,size:`sm`,disabled:p.isPending||!!t.revokedAt,onClick:()=>p.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>_.error(I(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(Et,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(ye,{open:te,onClose:()=>D(!1),onConfirm:ne,title:j.title,message:j.message,confirmLabel:j.confirmLabel,danger:!0})]})}function Ot({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(k,{open:!0,onClose:t,title:`Sharing — ${e.label||`API key`}`,description:r?`One stable handoff link for this key. Regenerating rotates the key itself.`:`One stable enrollment link. Regenerating replaces the URL; recipients keep the keys they already generated.`,size:`lg`,children:(0,$.jsx)(Dt,{parent:e,onSecretRevealed:n})})}function kt(){let e=je(),t=ge(),n=De(),r=Ee(),i=Oe(),a=ke(),o=we(),s=X(),{copy:c}=V(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[ee,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[re,O]=(0,Q.useState)(null),[M,ie]=(0,Q.useState)(null),N=e.data??[],ae=t.data?.isPlatformAdmin??!1,oe=e=>{x(null),C(e)},P=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?_.success(`API key copied`):_.error(`Clipboard unavailable on this origin`)}catch(e){_.error(I(e,`Could not reveal API key.`))}},se=bt(!0);return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(D,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[ae?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Ge,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(g,{variant:`primary`,size:`sm`,onClick:()=>{x(null),u(!0)},icon:(0,$.jsx)(j,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(R,{children:e.isPending&&!e.data?(0,$.jsx)(T,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(w,{message:I(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):N.length===0?(0,$.jsx)(E,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(D,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:N,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>_.error(I(e,`Could not save the new order.`))}),renderItem:e=>(0,$.jsxs)(`div`,{className:`api-key-card flex items-start justify-between gap-6 px-6 py-4 rounded-chip border border-inner-border bg-surface-2 max-medium:flex-col max-medium:items-stretch max-medium:gap-4 max-medium:p-5 [&>div:last-child]:flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`strong`,{className:`text-body`,children:e.label||`Unnamed credential`}),(0,$.jsx)(W,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(W,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(W,{tone:`warn`,title:`Required by the gateway. Rotate it; it cannot be deleted.`,children:`default · rotate only`}):null]}),(0,$.jsxs)(`div`,{className:`api-key-facts flex items-center flex-wrap gap-2 mt-3 min-w-0 max-medium:grid max-medium:grid-cols-3 max-medium:gap-2 max-medium:mt-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Created`}),new Date(e.createdAt).toLocaleDateString()]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.keyMode===`share`?`Total usage`:`Usage`}),H(e.tokensConsumed)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`RPM`}),U(e.requestsPerMinute)]})]}),(0,$.jsxs)(`div`,{className:`api-key-facts flex items-center flex-wrap gap-2 mt-3 min-w-0 max-medium:grid max-medium:grid-cols-3 max-medium:gap-2 max-medium:mt-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Daily`}),U(e.dailyTokenLimit)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Monthly`}),U(e.monthlyTokenLimit)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`One-time`}),U(e.lifetimeTokenBudget)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Concurrent`}),U(e.maxConcurrentRequests)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(K,{checked:e.enabled,disabled:r.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>r.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>_.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>_.error(I(e,`Could not update credential state.`))})}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(A,{size:13}),onClick:()=>{x(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(p,{size:13}),onClick:()=>void P(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(We,{size:13}),onClick:()=>oe(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),onClick:()=>{x(null),y(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(g,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(ce,{size:13}),onClick:()=>h(e),disabled:i.isPending,children:`Revoke`})]})]})})})}),(0,$.jsx)(k,{open:l,onClose:()=>u(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:re,children:(0,$.jsx)(ft,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:O,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),x(ut(e.keyMode,t.secret)),_.success(`API key created`)},onError:e=>_.error(I(e,`Could not create API key.`))})}})}),(0,$.jsx)(k,{open:d!==null,onClose:()=>f(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:M,children:(0,$.jsx)(ft,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:ie,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),x(ut(e.keyMode,t.secret)),_.success(`API key updated`)},onError:e=>_.error(I(e,`Could not update API key.`))})}})}),S?(0,$.jsx)(Ot,{parent:S,onClose:()=>C(null),onSecretRevealed:e=>{C(null),x(e)}}):null,(0,$.jsx)(ye,{open:v!==null,onClose:()=>y(null),onConfirm:async()=>{if(!v)return;let e=await a.mutateAsync({keyId:v.id});x(e.secret),_.success(`Rotated ${v.label||v.id}.`),y(null)},title:se.title,message:se.message,confirmLabel:se.confirmLabel,danger:!0}),(0,$.jsx)(ye,{open:m!==null,onClose:()=>h(null),onConfirm:async()=>{m&&(await i.mutateAsync(m.id),_.success(`Revoked ${m.label||m.id}.`),h(null))},title:`Revoke API key?`,message:m?`Revoke ${m.label||m.id}? Clients using it will be rejected.${m.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),te?(0,$.jsx)(ht,{onClose:()=>ne(!1)}):null,(0,$.jsx)(pt,{secret:ee,onClose:()=>x(null)})]})}function At(){let e=F(),t=P(),n=e.data;if(e.isPending)return(0,$.jsx)(T,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(w,{message:I(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(o,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`14px`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(Ue,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-rtk`,children:(0,$.jsx)(J,{gap:`6px`,className:`text-body font-semibold`,children:`Prune tool output (RTK)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Compact bulky tool results (diffs, grep dumps, listings) in the message history so a long conversation stops re-sending megabytes of raw output. Higher strength compresses more aggressively.`})]})]}),(0,$.jsxs)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{id:`compression-rtk-level`,"aria-label":`RTK strength`,value:n.rtkPruneLevel,onValueChange:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>_.error(I(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>_.error(I(e,`Could not update RTK prune.`))})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(i,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-ponytail`,children:(0,$.jsx)(J,{gap:`6px`,className:`text-body font-semibold`,children:`PonyTail (system directive)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Appends a minimal-code directive to the system content, biasing the model toward the smallest working change. Higher strength pushes harder toward deletion over addition.`})]})]}),(0,$.jsxs)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{id:`compression-ponytail-level`,"aria-label":`PonyTail strength`,value:n.ponyTailLevel,onValueChange:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>_.error(I(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:a,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>_.error(I(e,`Could not update PonyTail.`))})})]})]}),r||a?(0,$.jsxs)(`p`,{role:`note`,className:`flex gap-4 items-start m-0 py-4 px-5 rounded-inset border border-orange bg-orange-soft text-text-secondary text-badge`,children:[(0,$.jsx)(v,{size:14,className:`shrink-0 mt-0.5 text-orange`}),(0,$.jsx)(`span`,{children:`Your AI may produce degraded quality while compression is active: it sees a shortened history and a minimal-code directive, so fewer tokens but a chance of missing detail. Turn it off if answers get worse.`})]}):null]})})]})}function jt(){return le({queryKey:L.remoteSupport.status,queryFn:()=>pe(`/remote-support/status`)})}function Mt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}function Nt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}var Pt={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ft={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function It({tool:e}){return e===`cloudflared`?(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M16.5 18.4a4.6 4.6 0 0 1-3.2-1.3l-6-5.9a2.4 2.4 0 0 0-3.3 0 2.3 2.3 0 0 0 0 3.3l5.4 5.3a.9.9 0 0 1-1.3 1.3L2.7 15.8a4.1 4.1 0 0 1 0-5.8 4.2 4.2 0 0 1 5.8 0l6 5.9a2.4 2.4 0 0 0 3.3 0 2.3 2.3 0 0 0 0-3.3l-4.2-4.1a.9.9 0 0 1 1.3-1.3l4.2 4.1a4.1 4.1 0 0 1 0 5.8 4.2 4.2 0 0 1-2.6 1.3Z`}),(0,$.jsx)(`path`,{d:`M7.6 18.4a4.5 4.5 0 0 1-3-1.1 5.4 5.4 0 0 1-1.5-3.5 6 6 0 0 1 .4-2 .9.9 0 0 1 1.7.6 4.2 4.2 0 0 0-.3 1.4 3.6 3.6 0 0 0 1 2.3 2.7 2.7 0 0 0 1.8.7.9.9 0 0 1 0 1.8Z`})]}):(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M12 3.2a4.4 4.4 0 0 0-4.4 4.4v2.2H4.6a2.2 2.2 0 0 0 0 4.4h3v2.2a4.4 4.4 0 0 0 8.8 0v-2.2h1.1a3.3 3.3 0 0 0 0-6.6h-1.1V7.6A4.4 4.4 0 0 0 12 3.2Zm0 2.2a2.2 2.2 0 0 1 2.2 2.2v6.6a2.2 2.2 0 0 1-4.4 0V7.6A2.2 2.2 0 0 1 12 5.4Z`}),(0,$.jsx)(`path`,{d:`M6.6 11h4.2v2.2H6.6zM13.2 11h4.2v2.2h-4.2z`})]})}function Lt({tool:e}){let t=jt(),n=Mt(),r=Nt(),{copied:i,copy:a}=V(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&f(o)},[o,n.isPending,r.isPending]);let h=async t=>{f(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),_.error(i.message),f(!t);return}u(null),_.success(t?`${Pt[e]} started`:`${Pt[e]} stopped`)}catch{_.error(`Could not ${t?`start`:`stop`} ${Pt[e]}`),f(!t)}},v=async()=>{if(c!==null){if(await a(c)){_.success(`Remote URL copied`,c);return}_.error(`Clipboard unavailable on this origin`)}};return(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(It,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Pt[e]})]}),(0,$.jsx)(K,{checked:d,disabled:s,onChange:e=>void h(e),"aria-label":`Toggle ${Pt[e]} remote support`})]}),n.isPending?(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(y,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void h(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ft[e]}):(0,$.jsxs)(`div`,{className:`mt-2 rounded-control border border-warning/30 bg-warning/10 p-3 text-badge leading-normal text-text-secondary`,children:[(0,$.jsx)(`p`,{className:`font-medium text-warning`,children:`Setup needed`}),(0,$.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap break-words`,children:l}),(()=>{let e=l.match(/https:\/\/login\.tailscale\.com\/f\/serve\?[^\s]+/);return e?(0,$.jsx)(`a`,{href:e[0],target:`_blank`,rel:`noreferrer`,className:`mt-2 inline-block font-medium text-accent underline`,children:`Enable Tailscale Serve →`}):null})()]}):(0,$.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-badge text-text-primary`,title:c,children:c}),(0,$.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(m,{size:14}):(0,$.jsx)(p,{size:14}),i?`Copied`:`Copy`]})]})]})}function Rt(){let{copied:e,copy:t}=V(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){_.success(`Gateway endpoint copied`,n);return}_.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(f,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`nested-panel flex items-center gap-4 rounded-control border border-inner-border bg-code-surface px-7 py-5 font-mono text-body font-semibold tabular-nums`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate`,title:n,children:n}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(m,{size:13}):(0,$.jsx)(p,{size:13}),"aria-label":`Copy endpoint`,title:`Copy endpoint`,onClick:()=>void r(),className:`shrink-0`,children:e?`Copied`:`Copy`})]}),(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Point any SDK, CLI, or agent (e.g. OpenCode, Pi, OMP, Kilo, Cline, Droid and more clients) to this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`You may not put `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` on Claude Code — the CLI appends it itself.`]})]})]})})]})}function zt(){let e=F(),t=P(),n=e.data?.invokeDisabled===!0,r=e=>{t.mutate({invokeDisabled:!e},{onSuccess:()=>_.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every request now returns 503 and nothing upstream is dialed.`),onError:e=>_.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Invoke Switch`,subtitle:`Stop every request without deleting anything`,icon:(0,$.jsx)(M,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 text-caption leading-normal text-text-secondary`,children:[`Off refuses every `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1/*`}),` request with 503. Nothing is dispatched upstream, and no account, key, or model is changed — the dashboard stays reachable so you can turn it back on.`]}),(0,$.jsx)(K,{checked:!n,disabled:e.isLoading||t.isPending,onChange:e=>r(e),"aria-label":`Toggle invoke for every request`})]}),n?(0,$.jsxs)(`p`,{className:`flex items-start gap-2 text-caption leading-normal text-warning`,children:[(0,$.jsx)(v,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:`Invoke is off. Every API request is being refused, and any client pointed at this gateway will keep failing until you switch it back on.`})]}):null]})})]})}function Bt(){let e=jt();return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Be,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Lt,{tool:`cloudflared`}),(0,$.jsx)(Lt,{tool:`tailscale`})]}),e.data?.blocker!==null&&e.data?.message!==null?(0,$.jsx)(`p`,{className:`text-badge leading-normal text-red-primary`,children:e.data?.message}):null,(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Either way the gateway still sees the tunnel's address as the client, so set`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` to the edge that forwards to it — otherwise every remote caller is recorded as the loopback address.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`cloudflared and Tailscale are not installed by Cartethyia — install either one yourself first. The tunnel is launched detached from this process, so it survives a gateway restart.`})]})})]})}function Vt(){return(0,$.jsxs)(q,{gap:`16px`,children:[(0,$.jsx)(Rt,{}),(0,$.jsx)(zt,{}),(0,$.jsx)(Bt,{}),(0,$.jsx)(At,{}),(0,$.jsx)(kt,{})]})}export{Vt as default};
|
|
Binary file
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,r as l,t as u}from"./concurrency-BDF0ok7y.js";import{C as d,E as f,O as p,T as m,a as h,c as g,l as _,m as v,s as y,v as b,w as x,x as S}from"./numbers-BOevJzdz.js";import{t as C}from"./circle-alert-CntYHV5v.js";import{t as w}from"./circle-check-BU3v_mFW.js";import{t as T}from"./cog-CdWhsajs.js";import{t as E}from"./eye-off-Bk5g2luF.js";import{t as D}from"./eye-C_hawfH4.js";import{t as ee}from"./gauge-BbIMy7MB.js";import{t as te}from"./image-BPaouViG.js";import{n as O,r as k,t as A}from"./state-2c5V4zo7.js";import{t as ne}from"./key-round-UkavsGxp.js";import{t as j}from"./layers-2-glBbjl.js";import{r as M}from"./use-modal-focus-By7oJoGd.js";import{n as N,t as P}from"./dialog-C07hr5_G.js";import{t as F}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as ie}from"./power-off-Yjw9GMJh.js";import{t as ae}from"./refresh-cw-BqJFk4sU.js";import{t as oe}from"./rotate-ccw-CufcqITi.js";import{t as se}from"./search-JOKus9rb.js";import{t as ce}from"./trash-Cppn5c3R.js";import{t as I}from"./wrench-B6E1oEuY.js";import{C as le,T as ue,v as de}from"./assert-DU6qrMA_.js";import{i as fe,l as pe,o as me,t as L}from"./query-keys-UETqfytp.js";import{$ as he,C as R,D as ge,E as _e,O as ve,S as ye,a as be,b as xe,c as Se,ct as Ce,d as z,et as we,f as Te,g as Ee,h as De,k as Oe,l as ke,lt as Ae,m as je,o as Me,p as Ne,r as Pe,t as B,tt as Fe,u as Ie,w as Le,x as V,y as Re,z as ze}from"./entry-CwPRKk0d.js";import{n as H,r as U,t as W}from"./card-CdsSlWA3.js";import{n as Be}from"./download-dRFo5_Wu.js";import{f as G,i as K,l as Ve,n as He,r as Ue,s as We}from"./tokens-COzario9.js";import{t as q}from"./badge-CKsF123d.js";import{n as J}from"./input-CjCnXweJ.js";import{t as Y}from"./select-C980c4cz.js";import{t as Ge}from"./ProviderIcon-CmfzxpVM.js";import{t as Ke}from"./switch-Dkke7Naf.js";import{t as X}from"./stack-_gfTdLVB.js";import{n as Z,t as qe}from"./inline-C9dCYaBZ.js";import{i as Je}from"./quota-DZGyp0N5.js";import{t as Ye}from"./list-row-CM1AaG_y.js";import{c as Xe,l as Ze,m as Qe}from"./routing-BPUo-W8d.js";import{t as $e}from"./banner-8j7uChA9.js";import{o as et,s as tt,t as nt}from"./HealthEventsModal-C8MR_BdB.js";import{r as rt}from"./privacy-mode-GM8bej85.js";import{n as it,t as at}from"./AccountCooldown-Bjo92Qat.js";import{t as ot}from"./use-timeout-BwcBBRrT.js";var st=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`}]]),ct=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`}]]),lt=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`}]]),ut=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`}]]),dt=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`}]]),ft=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),pt=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`}]]),mt=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`}]]),ht=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function gt(e,t){return t===null?e:`${e}(${t})`}var Q=t(n(),1),$=r();function _t({to:e,label:t}){let n=he();return(0,$.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,$.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function vt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,$.jsx)(_t,{...a}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,$.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,$.jsx)(`div`,{className:v(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function yt(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function bt(e,t=600){let n=(0,Q.useRef)(void 0);return(0,Q.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var xt={fallback:`Failover`,roundRobin:`Round robin`},St=new Set([`inferhub`,`cline`]);function Ct(e,t){let n=Ze(e),r=Qe(),[i,a]=(0,Q.useState)(`fallback`),[o,s]=(0,Q.useState)(1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(`percent`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``);(0,Q.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=bt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=bt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=bt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=bt(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 wt=50,Tt=100;function Et(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 Dt({children:e,action:t}){return(0,$.jsx)(Ye,{actions:t,children:e})}function Ot({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=Ct(e,r),[a,o]=(0,Q.useState)(!1),s=St.has(e),l=Et(B,n.codex,n.claude),u=l.some(e=>e.value===i.userAgent)?l:[...l,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,$.jsx)(k,{label:`Loading routing...`});if(i.isError)return(0,$.jsx)(O,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${xt.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:xt.fallback,f=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,p=i.maxInflight===null,m=p?51:Math.min(51,Math.max(1,i.maxInflight)),h=p?`∞`:String(i.maxInflight),_=i.maxInflightPerProxy===null,v=_?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),b=_?`∞`:String(i.maxInflightPerProxy),x=i.skipProxy,S=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},C=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;y.success(`Client identity updated`,t)},w=t?`${t.client} ${t.version}`:`Provider default`;return(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Routing Strategy`,subtitle:f,icon:(0,$.jsx)(j,{size:16})}),(0,$.jsx)(H,{children:(0,$.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,$.jsx)(Dt,{action:(0,$.jsxs)($.Fragment,{children:[i.roundRobinEnabled?(0,$.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,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,$.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,$.jsx)(N,{size:14}),onClick:()=>S(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,$.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,$.jsx)(re,{size:14}),onClick:()=>S(1)})]}):null,(0,$.jsx)(Ke,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(dt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,$.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,$.jsx)(Dt,{action:(0,$.jsx)(Ke,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(st,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,$.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,$.jsx)(c,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,$.jsx)(Y,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:C}):(0,$.jsx)(Y,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:w,options:[{value:w,label:w}]}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(ee,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,$.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,wt,` is unlimited.`]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":p?`true`:void 0,min:1,max:51,step:1,value:m,"aria-valuetext":p?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>wt?null:Math.round(t))},style:{"--slider-pct":`${m/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:h,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(Tt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${p?`text-status-success`:``}`})]})]})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${x?` opacity-60`:``}`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(mt,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,$.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,$.jsx)(g,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.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:x,value:v,"aria-valuetext":_?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>wt?null:Math.round(t))},style:{"--slider-pct":`${v/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:x,value:b,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(Tt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${_?`text-status-success`:``}`})]}),(0,$.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:x?`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 ${wt} is unlimited.`})]}),(0,$.jsx)(P,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,$.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,$.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,$.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,$.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,$.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,$.jsxs)(Z,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,$.jsx)(ct,{size:12,className:`shrink-0 mt-0.5`}),(0,$.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 kt(e){if(typeof e!=`object`||!e)throw{status:500,code:`invalid_response`,message:`Invalid InferHub summary`};let t=e;return{models:Array.isArray(t.models)?t.models:[],providers:Array.isArray(t.providers)?t.providers:[],pricingConfig:t.pricingConfig??null,meta:t.meta??{fetchedAt:0,ageSeconds:0,stale:!0},error:t.error??null}}function At(e=!0){return le({queryKey:L.inferhub.summary,queryFn:e=>me(`/inferhub/summary`,{signal:de(e)}).then(kt),enabled:e,...fe,staleTime:6e4})}function jt(e){return e===null?`—`:`$${e.toFixed(4)}`}function Mt(e){return e===null?`—`:`${e}%`}function Nt(e){return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}var Pt={provider:`Provider (A–Z)`,availability:`Highest availability`,sustainable:`Sustainable price`,price:`Lowest price`,discount:`Biggest discount`};function Ft(e,t){return(n,r)=>{let i=e(n),a=e(r);return i===null&&a===null?0:i===null?1:a===null?-1:t===`asc`?i-a:a-i}}function It(e){switch(e){case`provider`:return(e,t)=>e.family.localeCompare(t.family,void 0,{sensitivity:`base`})||e.prefix.localeCompare(t.prefix);case`availability`:return(e,t)=>t.providersLive-e.providersLive||Ft(e=>e.health.successRatePct,`desc`)(e,t);case`sustainable`:return Ft(e=>e.capacityPriceIn,`asc`);case`price`:return Ft(e=>e.minAskIn,`asc`);case`discount`:return Ft(e=>e.tiersIn[0]?.discountPct??null,`desc`)}}function Lt(e){return e===`operational`?`ok`:e===`degraded`?`warn`:e===`major_outage`?`err`:`default`}function Rt(e,t){return e.providers.find(e=>e.prefix===t)}function zt(e){return e.providersLive>0&&e.routable&&e.minAskIn!==null}function Bt(){let e=At(),t=e.data,[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(`provider`),u=t?.models??[],d=u.filter(zt),f=(0,Q.useMemo)(()=>{let e=[...i?u:d].sort(It(c)),t=new Map;for(let n of e){let e=t.get(n.prefix);e===void 0?t.set(n.prefix,[n]):e.push(n)}return[...t.entries()].map(([e,t])=>({prefix:e,family:t[0]?.family??e,models:t}))},[u,d,i,c]),p=(0,$.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,$.jsx)(ae,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,$.jsx)(ae,{size:16})}),(0,$.jsx)(H,{children:e.isError?(0,$.jsx)($e,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`InferHub market`,icon:(0,$.jsx)(ae,{size:16}),action:p}),(0,$.jsx)(H,{children:(0,$.jsx)($e,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let m=f,h=m.reduce((e,t)=>e+t.models.length,0),_=u.length-h;return(0,$.jsxs)(W,{children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-start gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,$.jsx)(Ae,{size:15,"aria-hidden":`true`,className:v(`mt-1 shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,$.jsxs)(X,{gap:`1px`,children:[(0,$.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,Nt(t.meta.ageSeconds)]}):null]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:n?p:null})]}),n?(0,$.jsxs)(H,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(Ht,{onSaved:()=>void e.refetch()}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,$.jsx)(Y,{value:c,onValueChange:e=>l(e),options:Object.keys(Pt).map(e=>({value:e,label:Pt[e]})),"aria-label":`Sort InferHub models`})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,$.jsxs)($e,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,$.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,$.jsxs)($e,{tone:`warning`,surface:`raised`,live:`none`,children:[`InferHub did not answer. Showing the last snapshot that was read`,t.meta.fetchedAt>0?` (${Nt(t.meta.ageSeconds)})`:``,`.`]}):null,t.meta.stale&&t.error===null?(0,$.jsxs)($e,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,Nt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[h,` of `,u.length,` models`]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,_>0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,_,` hidden)`]}):null]})]}),m.length===0?(0,$.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:m.map(e=>(0,$.jsx)(Vt,{group:e,showUpstreams:o,summary:t},e.prefix))})]}):null]})}function Vt({group:e,showUpstreams:t,summary:n}){let[r,i]=(0,Q.useState)(!0),a=Rt(n,e.prefix),o=a?.familyState??null,s=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,$.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,$.jsx)(Ae,{size:14,"aria-hidden":`true`,className:v(`shrink-0 transition-transform`,!r&&`-rotate-90`)}),(0,$.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,$.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),o===null?null:(0,$.jsx)(q,{tone:Lt(o),dot:!0,children:o.replace(/_/g,` `)}),t&&a!==void 0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Mt(a.availability24hPct),` · 7d`,` `,Mt(a.availability7dPct)]}):null,(0,$.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),r?(0,$.jsxs)(`div`,{className:`px-3 pb-3`,children:[s===null?null:(0,$.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:s}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,$.jsx)(`tbody`,{children:e.models.map(e=>(0,$.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,$.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,$.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[jt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,$.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[jt(e.capacityPriceIn),` sustainable`]}):null]}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:jt(e.minAskOut)}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,$.jsx)(q,{children:`none`}):e.providersLive}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Mt(t?a?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function Ht({onSaved:e}){let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await me(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await me(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,$.jsx)(J,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,$.jsx)(g,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,$.jsx)(g,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,$.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),s===null?null:(0,$.jsx)($e,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function Ut({providerId:e}){let t=Ct(e,!1),n=et(),r=Xe(e),i=(0,Q.useMemo)(()=>Gt(n.data?.accounts??[],e),[n.data,e]),a=(0,Q.useRef)(null),o=(0,Q.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Q.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Q.useState)(`40`),[l,u]=(0,Q.useState)(`percent`),d=t.usageFloor!==null;(0,Q.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,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(ee,{size:14}),(0,$.jsx)(`span`,{children:`Usage floor`}),(0,$.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,$.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,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,$.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,$.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,$.jsx)(`span`,{children:`Pooled credits`}),(0,$.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,$.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`})]}),(0,$.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,$.jsx)(`strong`,{className:`font-bold ${m}`,children:Kt(i.remaining)}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,$.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,Kt(i.total)]}),(0,$.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Kt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,$.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,$.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,$.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Kt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,$.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,$.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,$.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,$.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,$.jsx)(`option`,{value:`percent`,children:`%`}),(0,$.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,$.jsx)(Ke,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,$.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,$.jsx)(Wt,{providerId:e})]})}function Wt({providerId:e}){let{enabled:t,setEnabled:n}=rt(e);return(0,$.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,$.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(E,{size:14}),(0,$.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,$.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,$.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,$.jsx)(Ke,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function Gt(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 Kt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function qt({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,$.jsx)(W,{density:`compact`,children:(0,$.jsx)(H,{children:(0,$.jsxs)(Z,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,$.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`br`,{}),r]}):null]}),t?(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:_({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,$.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,$.jsx)(Ce,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function Jt({provider:e}){let t=ve(),[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.baseUrl??``);(0,Q.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,$.jsx)(d,{size:16})}),(0,$.jsx)(H,{children:(0,$.jsxs)(X,{gap:`12px`,children:[n?(0,$.jsx)(J,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,$.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,$.jsxs)(Z,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(ft,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,$.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(M,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,$.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(F,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,$.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(ne,{size:13}),onClick:()=>{let e=document.getElementById(`provider-accounts`);e?.scrollIntoView({behavior:`smooth`,block:`start`}),e?.focus({preventScroll:!0})},children:`Manage API keys`}):null]})]})})]})}var Yt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Xt=new Set([`quota_fetch_failed`]);function Zt(e){return e===void 0||e.length===0?!1:!Xt.has(e)}function Qt(e){return e===`oauth`?`Re-login required`:`Replace API key`}function $t(e,t){return e===`auth_invalidated`?Qt(t):Yt[e]??e}var en=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],tn=[`refresh`,`refreshToken`,`refresh_token`],nn=[`credentialKind`,`providerId`,`accessToken`],rn=[`accounts`,`items`,`connections`],an=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function on(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function sn(e){let t=e.data;if(typeof t==`string`)try{return on(JSON.parse(t))}catch{return}return on(t)}function cn(e){for(let t of en){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=sn(e);if(t)for(let e of en){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function ln(e){for(let t of an){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=sn(e);if(t)for(let e of an){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function un(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,tn);if(n(e))return!0;let r=sn(e);return r?n(r):!1}function dn(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 on(JSON.parse(atob(n)))}catch{return}}function fn(e){let t=dn(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 pn(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 mn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}function hn(e){let t=e.trim(),n=on(mn(t))??pn(t);return n&&un(n)?`oauth`:dn((n?cn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function gn(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 _n(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 vn(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&nn.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`&&un(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=cn(e),r=un(e)?`oauth`:hn(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=ln(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function yn(e){for(let t of rn){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>on(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function bn(e){let t=e.trim();if(!t)return[];let n=mn(t);if(Array.isArray(n)){let e=n.map(e=>on(e)).filter(e=>e!==void 0);if(e.length>0)return gn(e)?[_n(t,e)]:e.map(vn)}else{let e=on(n);if(e){let t=yn(e);return t?t.map(vn):[vn(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1){let e=pn(r[0]);return e?[vn(e)]:xn(r[0])}let i=pn(t);return i&&(cn(i)||Object.keys(i).length===r.length)?[vn(i)]:r.flatMap(xn)}function xn(e){let t=on(mn(e));if(t){let e=yn(t);return e?e.map(vn):[vn(t)]}return[{value:e,kind:hn(e)}]}function Sn(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 Cn(e,t=50){if(t<1)throw RangeError(`chunk size must be at least 1`);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function wn(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()}`:Je(e,!1)}function En({cooldowns:e,reason:t}){if(!e)return null;let n=Je(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,$.jsxs)(q,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function Dn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function On(e){return e.credentialKind===`oauth`?`blue`:`ok`}function kn({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=at(e);if(e.status===`disabled`){let t=Dn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,$.jsx)(q,{tone:`warn`,title:e.lastError,children:Qt(e.credentialKind)}):Zt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(q,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:$t(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(En,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:On(e),dot:!0,children:[`Active`,Dn(e)?` - ${Dn(e)}`:``]}),Zt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(q,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:$t(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(En,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`warn`,dot:!0,children:[`Cooldown`,Dn(e)?` - ${Dn(e)}`:``,` `,e.cooldownUntil?`(${Je(e.cooldownUntil)})`:``]}),Zt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(q,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:$t(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(En,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,$.jsx)(q,{tone:`disabled`,children:`Disabled`})}function An({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=`${jn(t)} of ${jn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,$.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?`${jn(t)} credits available of ${jn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function jn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Mn({providerId:e,account:t,onClose:n}){let r=Oe(),[i,a]=(0,Q.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{y.error(`Clipboard access denied`)}};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,$.jsx)(g,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{y.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;y.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.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,$.jsxs)(X,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,$.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,$.jsx)(Z,{gap:`8px`,className:`justify-end`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Nn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=Oe(),l=Re(),u=tt(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,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(!1),[,C]=(0,Q.useState)(0),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(``),ee=rt(e),te=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),O=ee.enabled?`Mysterious accounts`:te,k=Tn(t.tokenExpiresAt),A=it(t),j=Math.max(p&&t.cooldownUntil?f:0,A??0);(0,Q.useEffect)(()=>{if(j<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[j]);let M=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>y.success(`Account renamed`,n),onError:e=>y.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(`div`,{className:`flex items-center`,children:(0,$.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${O}`,className:`cursor-pointer`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,$.jsx)(J,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&M(),e.key===`Escape`&&T(!1)},onBlur:M,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,$.jsxs)($.Fragment,{children:[(0,$.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:O}),(0,$.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 ${O}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,$.jsx)(F,{size:11})})]})}),(0,$.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,$.jsx)(kn,{account:t}),k?(0,$.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:k,children:k}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,$.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,$.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,$.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,$.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,$.jsx)(An,{windows:r}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,$.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,$.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${O}`,onClick:()=>_(!0),title:`View Health & Error History`}),(0,$.jsx)(g,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,$.jsx)(S,{size:12,className:`animate-spin`}):(0,$.jsx)(x,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${O}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?y.success(`Account test passed`,O):y.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>y.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,$.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(ne,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${O}`,onClick:()=>b(!0),title:`Replace API key`}),(0,$.jsx)(g,{size:`icon`,variant:`secondary`,icon:d?(0,$.jsx)(lt,{size:12}):(0,$.jsx)(ie,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${O}`:`Disable ${O}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>y.success(n?`Account enabled`:`Account disabled`,O),onError:e=>y.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,$.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(oe,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${O}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,(0,$.jsx)(g,{size:`icon`,variant:`danger`,icon:(0,$.jsx)(ce,{size:12}),label:`Delete`,"aria-label":`Delete ${O}`,onClick:()=>s(t),title:`Delete account`})]})]}),h&&(0,$.jsx)(nt,{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:()=>_(!1)}),v&&(0,$.jsx)(Mn,{providerId:e,account:t,onClose:()=>b(!1)})]})}var Pn=[{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=wn(e.status)-wn(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 In({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ue(),s=Oe(),c=Re(),l=ke(),d=Xe(e).data??new Map,f=et(),p=(0,Q.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[h,_]=(0,Q.useState)(``),[v,b]=(0,Q.useState)(new Set),[S,C]=(0,Q.useState)(`added-asc`),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),[ee,te]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),ne=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!O)return;let e=e=>{ne.current&&!ne.current.contains(e.target)&&k(!1)},t=e=>{e.key===`Escape`&&k(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[O]);let j=h.trim().toLowerCase(),M=(0,Q.useMemo)(()=>j?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return j.split(/\s+/).every(e=>t.includes(e))}):t,[t,j]),N=(0,Q.useMemo)(()=>{let e=S.slice(0,S.lastIndexOf(`-`)),t=S.endsWith(`-desc`)?-1:1,n=[...M];return n.sort((n,r)=>t*Fn(n,r,e)),n},[M,S]),P=(0,Q.useMemo)(()=>t.filter(e=>v.has(e.id)),[t,v]),F=M.length>0&&M.every(e=>v.has(e.id)),re=P.some(e=>e.status===`disabled`),ae=P.some(e=>e.status!==`disabled`),I=P.length===0,le=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},de=()=>{b(e=>{let t=new Set(e);if(F)for(let e of M)t.delete(e.id);else for(let e of M)t.add(e.id);return t})},fe=async(e,t)=>{if(P.length===0)return;T(!0);let n=await Promise.allSettled(P.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;T(!1),r===0?y.success(`${e} complete`,`${i} account${i===1?``:`s`}`):y.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},pe=()=>fe(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),he=async()=>{t.length!==0&&(T(!0),D({done:0,total:t.length}),await u(t,3,async(e,n)=>{let r=await me(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return D({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:L.quota.all}),o.invalidateQueries({queryKey:L.providers.all})]),T(!1),D(null),y.success(`Test complete`,`${t.length} account${t.length===1?``:`s`} tested`))},R=t=>fe(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),ge=async()=>{if(P.length!==0){T(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:P.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Be(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),y.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){y.error(`Export failed`,e.message??`Unable to export accounts`)}finally{T(!1)}}};return(0,$.jsxs)(X,{gap:`8px`,children:[(0,$.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,$.jsxs)(`label`,{className:`relative min-w-20 flex-[1_1_10rem]`,children:[(0,$.jsx)(se,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,$.jsx)(J,{id:`accounts-search`,value:h,onChange:e=>_(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,$.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(x,{size:12}),disabled:w||t.length===0,onClick:he,"aria-label":E===null?`Test all accounts`:`Testing accounts, ${E.done} of ${E.total} tested`,title:`Test every account, regardless of selection or filters`,children:E===null?`Test all`:`Tested ${E.done}/${E.total}`}),(0,$.jsxs)(`div`,{ref:ne,className:`relative`,children:[(0,$.jsxs)(g,{size:`sm`,variant:`secondary`,disabled:w||I,"aria-expanded":O,"aria-haspopup":`menu`,"aria-label":I?`Select accounts to enable bulk actions`:`Bulk actions for ${P.length} selected accounts`,onClick:()=>k(e=>!e),children:[`Actions`,I?``:` (${P.length})`,(0,$.jsx)(Ae,{size:12,"aria-hidden":`true`,className:`transition-transform ${O?`rotate-180`:``}`})]}),O&&!I?(0,$.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,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(oe,{size:12}),disabled:w,onClick:()=>{k(!1),pe()},children:`Recover`}),re?(0,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(lt,{size:12}),disabled:w,onClick:()=>{k(!1),R(!0)},children:`Enable`}):null,ae?(0,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(ie,{size:12}),disabled:w,onClick:()=>{k(!1),R(!1)},children:`Disable`}):null,(0,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(m,{size:12}),disabled:w,onClick:()=>{k(!1),ge()},children:`Export JSON`}),(0,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`danger`,className:`w-full justify-start`,icon:(0,$.jsx)(ce,{size:12}),disabled:w,onClick:()=>{k(!1),te(!0)},children:`Delete`}),(0,$.jsx)(g,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,disabled:w,onClick:()=>{b(new Set),k(!1)},children:`Clear selection`})]}):null]}),(0,$.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,$.jsx)(Y,{size:`sm`,value:S,onValueChange:e=>C(e),options:Pn,"aria-label":`Sort accounts by`})}),(0,$.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:F,onChange:de,"aria-label":`Select accounts`}),(0,$.jsx)(`span`,{children:`Select`})]}),r?(0,$.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,$.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,$.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:N.length===0?(0,$.jsx)(A,{compact:!0,icon:(0,$.jsx)(se,{size:20}),title:`No matching accounts`,message:j?`Nothing matches “${j}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):N.map(t=>(0,$.jsx)(Nn,{providerId:e,account:t,inflight:d.get(t.id)??t.inflight,quota:p.get(t.id),selected:v.has(t.id),onToggleSelect:le,onDelete:n},t.id))}),(0,$.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,$.jsxs)(`span`,{children:[`Showing `,M.length,` account`,M.length===1?``:`s`,j?` (filtered from ${t.length})`:``]})}),(0,$.jsx)(ze,{open:ee,onClose:()=>{w||te(!1)},onConfirm:async()=>{await fe(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await me(t,{method:`DELETE`}),o.removeQueries({queryKey:L.quota.account(e.id),exact:!0})}),b(new Set),te(!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 Ln=2097152,Rn=Ln/1048576;function zn({providerId:e,accounts:t,onClose:n}){let r=be(),i=Me(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(`auto`),p=bn(s),m=p.length>1,h=p.length===1?p[0]:void 0,v=d===`auto`?h?.kind:d,b=h&&v===`jwt`?fn(h.value):void 0,x=t.map(e=>e.label),S=m?Sn(p,e,x):[],C=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}},w=r.isPending||l,T=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=bn(e);if(t.length>1)y.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`;y.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{y.error(`Clipboard access denied`)}},E=e=>{if(e.size>Ln){y.error(`File too large`,`Credential files must be ${Rn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=bn(n);if(r.length===0){y.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}y.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>y.error(`Could not read that file`),t.readAsText(e)},D=async()=>{if(p.length!==0){if(p.length===1){let t=p[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...C(t)}},{onSuccess:()=>{y.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>y.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=Cn(p.map((e,t)=>({label:S[t],...C(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${S[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${pe(e,`request failed`)}`);break}let s=a.length;r>0&&y.success(`${r} account${r===1?``:`s`} added`,o?`stopped partway; ${s} failed`:s>0?`${s} skipped`:void 0),s>0&&y.error(`${s} account${s===1?``:`s`} skipped`,a.slice(0,5).join(`
|
|
2
|
+
`)+(s>5?`\n…and ${s-5} more`:``)),r>0&&n()}finally{u(!1)}}};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:w,children:`Cancel`}),(0,$.jsx)(g,{size:`sm`,variant:`primary`,disabled:w||p.length===0,onClick:()=>void D(),children:w?`Connecting...`:m?`Add ${p.length} Accounts`:`Add Account`})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!m&&(0,$.jsx)(J,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:h?.identity??`${e} account`}),(0,$.jsx)(Y,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,$.jsxs)(X,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),m?(0,$.jsxs)(q,{tone:`accent`,children:[`Detected: `,p.length,` accounts`]}):h?(0,$.jsxs)(q,{tone:v===`oauth`||v===`jwt`?`accent`:`default`,children:[`Detected:`,` `,v===`oauth`?`OAuth`:v===`jwt`?`Static JWT`:`API key`,h.identity?` · ${h.identity}`:``]}):null,h&&v===`jwt`?(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,b?` · expires ${new Date(b).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,$.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,$.jsxs)(Z,{gap:`8px`,className:`justify-end`,children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void T(),children:`Paste`}),(0,$.jsxs)(`label`,{className:_({size:`sm`,className:`cursor-pointer`}),children:[(0,$.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&&E(t)}}),`Import file`]})]})]}),m&&(0,$.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:p.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,$.jsx)(`span`,{className:`truncate min-w-0`,children:S[t]}),(0,$.jsx)(q,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))})]})})}function Bn(e){let t=e.trim(),n=e=>{try{return new URL(e).searchParams}catch{return}},r=n(t)??new URLSearchParams(t.startsWith(`?`)?t.slice(1):t),i=r.get(`code`);if(i)return{code:i};let a=r.get(`error_description`)??r.get(`error`);return a?{error:`The provider refused the login: ${a}`}:r.has(`authCodeInfo`)||r.has(`refreshToken`)||r.has(`refresh_token`)?{code:r.toString()}:n(t)!==void 0||t.startsWith(`?`)?{error:`That redirect URL carries no authorization code — copy the full URL from the address bar.`}:{code:t}}function Vn({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),l=Pe(),u=ot(),d=ue(),m=je(e),h=(0,Q.useRef)(null),_=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let t=setInterval(()=>{d.invalidateQueries({queryKey:L.providers.accounts(e)})},1500);return()=>clearInterval(t)},[d,e]),(0,Q.useEffect)(()=>{let e=m.data?.map(e=>e.id)??null;if(e!==null){if(h.current===null){h.current=new Set(e);return}_.current||e.find(e=>!h.current.has(e))!==void 0&&(_.current=!0,r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[m.data,r,i]);let v=()=>{r.close(),i(!1)},[b,x]=(0,Q.useState)(!1),C=()=>{x(!0),d.invalidateQueries({queryKey:L.providers.accounts(e)}).finally(()=>x(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){y.error(`Clipboard is empty`);return}c(e),y.success(`Pasted redirect URL`)}catch{y.error(`Clipboard unavailable on this origin`)}};return(0,$.jsx)(P,{open:!0,onClose:v,title:`Connect via OAuth`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:v,disabled:l.isPending,children:`Cancel`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:C,disabled:l.isPending||b,title:`You already approved in the popup — check now instead of waiting`,children:b?`Checking…`:`Complete`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=Bn(s);if(`error`in t){y.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>y.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,$.jsxs)(X,{gap:`14px`,children:[(0,$.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,$.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,$.jsxs)(Z,{gap:`8px`,children:[(0,$.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,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:a?(0,$.jsx)(p,{size:12}):(0,$.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),u(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,$.jsx)(`span`,{children:`Or complete manually`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,$.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,$.jsxs)(Z,{gap:`8px`,align:`flex-start`,children:[(0,$.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,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function Hn(e){try{return new URL(e).host}catch{return e}}function Un({providerId:e,parameters:t,onClose:n}){let r=R(),i=z(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=ot();(0,Q.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||(y.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let m=(0,Q.useRef)(null),[h,_]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?m.current=e:_(!0),()=>{let e=m.current;m.current=null,e&&!e.closed&&e.close()}},[a]),(0,Q.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(),y.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=m.current;e&&!e.closed&&e.close(),y.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),y.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,$.jsx)(P,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,$.jsx)(X,{gap:`14px`,children:a?(0,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,$.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,$.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,$.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:l?(0,$.jsx)(p,{size:12}):(0,$.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),u(!0),d(()=>u(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.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,$.jsxs)(Z,{gap:`8px`,children:[(0,$.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:Hn(a.verificationUri)}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(Ce,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:s?(0,$.jsx)(p,{size:12}):(0,$.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),d(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:h?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,$.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,$.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function Wn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function Gn(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Kn({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,$.jsx)(X,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,$.jsx)(Y,{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,$.jsx)(J,{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 qn({providerId:e,providerName:t,fields:n,onClose:r}){let i=Ie(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(()=>Wn(n)),d=(0,Q.useMemo)(()=>Gn(n,l),[n,l]);return(0,$.jsx)(P,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){y.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){y.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:()=>{y.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>y.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,$.jsx)(S,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,$.jsxs)(X,{gap:`12px`,children:[(0,$.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,$.jsx)(Kn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,$.jsx)(J,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,$.jsx)(J,{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 Jn(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 Yn(e,t,n){let{title:r,detail:i}=Jn(e,t,n);return[r,i]}function Xn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function Zn(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var Qn=[{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`}],$n={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function er(){return ht.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function tr({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,$.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,$.jsx)(Y,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:er()})})}function nr({providerId:e,provider:t,onClose:n}){let r=Ne(),i=xe(),[a,o]=(0,Q.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Q.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,Q.useState)(c??`chat`),[f,p]=(0,Q.useState)(`auto`),[m,h]=(0,Q.useState)(`idle`),[_,v]=(0,Q.useState)(``),[b,C]=(0,Q.useState)(or),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(h(`testing`),v(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:u,reasoningEffort:f,serviceKind:`llm`}},{onSuccess:e=>{e.ok?h(`passed`):(h(`failed`),v(e.error??`Model probe failed`))},onError:e=>{h(`failed`),v(e.message??`Model probe failed`)}}))};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=G(b.contextLimit),r=G(b.outputLimit);if(t===null||r===null){y.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:b.passthrough,image:b.passthrough?!0:b.image,reasoning:b.passthrough?!0:b.reasoning,toolCall:b.passthrough?!0:b.toolCall}},{onSuccess:()=>{y.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>y.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(Z,{gap:`8px`,align:`flex-end`,children:[(0,$.jsx)(J,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),h(`idle`),v(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:m===`testing`?(0,$.jsx)(S,{size:13,className:`animate-spin`}):(0,$.jsx)(x,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:m===`testing`?`Testing...`:`Test`})]}),E&&(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,$.jsx)(Y,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),h(`idle`),v(``)},options:l.map(e=>({value:e,label:fr(e)}))}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,$.jsx)(tr,{id:`add-model-thinking-effort`,value:f,onChange:e=>{p(e),h(`idle`),v(``)},disabled:r.isPending}),(0,$.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,$.jsx)(sr,{draft:b,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:fr(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),m===`passed`&&(0,$.jsx)($e,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),m===`failed`&&(0,$.jsx)($e,{tone:`danger`,live:`alert`,children:_||`Model test failed.`})]})})}function rr(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var ir=String(Ue),ar=String(K);function or(){return{...rr(),contextLimit:ir,outputLimit:ar}}function sr({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,$.jsxs)(Z,{gap:`8px`,children:[(0,$.jsx)(J,{label:`Context`,id:`${n}-context`,placeholder:ir,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,$.jsx)(J,{label:`Output`,id:`${n}-output`,placeholder:ar,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===ir&&e.outputLimit===ar,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:ir,outputLimit:ar}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,Ve(Ue),` ctx ·`,` `,Ve(K),` out`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,$.jsx)(X,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,$.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,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,$.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,$.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 cr({providerId:e,model:t,onClose:n}){let r=ge(),[i,a]=(0,Q.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,$.jsx)(P,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=G(i.contextLimit),o=G(i.outputLimit);if(a===null||o===null){y.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=>y.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,$.jsx)(sr,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function lr({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let u=Ne(),m=V(),[_,v]=(0,Q.useState)(!1),[E,ee]=(0,Q.useState)(null),te=ot(),O=n===`llm`?gt(t.modelId,i===`auto`?null:i):t.modelId,k=`${e}/${O}`,A=n===`websearch`?`Searching…`:`Thinking…`,ne=()=>{u.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(ee({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=Jn(e,O,t.error);y.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;y.successRich(`${O} · END ${h(t.latencyMs)}`,(0,$.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,$.jsxs)(Z,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,$.jsx)(T,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,$.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,$.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
3
|
+
`)||`No sample text in the response.`)},onError:t=>{ee({ok:!1,latencyMs:0}),y.error(...Yn(e,O,t.message))}})},j=()=>{let n=!t.enabled;m.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>y.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>y.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,$.jsx)($.Fragment,{children:(0,$.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,$.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,$.jsx)(o,{size:14})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{title:k,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:O}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,$.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...dr(t.wireFamily)},children:fr(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,$.jsx)(`span`,{title:Xn(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:Zn(t.source)}):null,t.proOnly===!0?(0,$.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,$.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,$.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,$.jsx)(g,{variant:`ghost`,size:`sm`,icon:_?(0,$.jsx)(p,{size:12}):(0,$.jsx)(f,{size:12}),"aria-label":`Copy ${k}`,title:`Copy ${k}`,onClick:()=>{navigator.clipboard?.writeText(k),v(!0),te(()=>v(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,$.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,$.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,$.jsx)(s,{size:12})}):null,t.vision?(0,$.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,$.jsx)(D,{size:12})}):null,t.toolCall?(0,$.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,$.jsx)(I,{size:12})}):null,r?(0,$.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,$.jsx)(d,{size:12})}):null]}),(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,$.jsx)(`span`,{title:He,"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,$.jsx)(C,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${Ve(t.contextLimit)} ctx`:(0,$.jsx)(`span`,{title:We,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${Ve(t.outputLimit)} out`:(0,$.jsx)(`span`,{title:We,className:`cursor-help`,children:` · n/a out`})]}),c?(0,$.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,$.jsx)(F,{size:11})}):null]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,disabled:u.isPending,onClick:ne,"aria-label":`Test ${O}`,title:u.isPending?`Probing ${O}…`:E?.ok?`Last probe OK in ${h(E.latencyMs)} — click to re-test`:E?`Last probe failed — click to retry`:`Test ${O}`,className:`flex-1 justify-center`,icon:u.isPending?(0,$.jsx)(S,{size:12,className:`animate-spin`}):E?E.ok?(0,$.jsx)(`span`,{className:`inline-flex text-green`,children:(0,$.jsx)(w,{size:12})}):(0,$.jsx)(`span`,{className:`inline-flex text-red`,children:(0,$.jsx)(b,{size:12})}):(0,$.jsx)(x,{size:12}),children:u.isPending?A:E?.ok?h(E.latencyMs):E?`Fail`:`Test`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:m.isPending,onClick:j,icon:t.enabled?(0,$.jsx)(ie,{size:12}):(0,$.jsx)(lt,{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,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,$.jsx)(ce,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var ur=(0,Q.memo)(lr);function dr(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 fr(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function pr({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=Se(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),u=e=>e.enabled!==!1,d=Qn.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,$.jsx)(ur,{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,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{gap:`16px`,children:[d.map(e=>(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,$.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,$.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:$n.label}),(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,$.jsxs)(`span`,{title:$n.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,$n.hint]})]}),(0,$.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,$.jsx)(ze,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),y.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,$.jsx)(cr,{providerId:e,model:c,onClose:()=>l(null)})]})}function mr(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function hr(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function gr(){let{providerId:e}=we(),[t]=Fe(),n=e??``,r=t.get(`service`),[i,a]=(0,Q.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=De(n),s=Ee(n),c=je(n),u=Le(),f=Le({silent:!0}),[p,h]=(0,Q.useState)(!1),_=Te(),v=_e(),b=ye(),x=ue(),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),E=Ne(),[D,ee]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(``),[N,F]=(0,Q.useState)(null),oe=e=>`cartethyia:provider:${e}:thinking-effort`,se=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(oe(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return ht.includes(n)?n:`auto`},[I,le]=(0,Q.useState)(()=>se(n));(0,Q.useEffect)(()=>{if(!n)return;let e=se(n);e!==I&&le(e)},[n]),(0,Q.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(oe(n),I)},[n,I]);let[de,fe]=(0,Q.useState)(!1),[pe,he]=(0,Q.useState)(!1),[R,ge]=(0,Q.useState)(null),[ve,be]=(0,Q.useState)({}),[xe,Se]=(0,Q.useState)({}),[z,Oe]=(0,Q.useState)(null),[ke,Ae]=(0,Q.useState)(!1),[Me,Pe]=(0,Q.useState)(null),B=(0,Q.useRef)(null),Ie=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{let e=B.current;B.current=null,e&&!e.closed&&e.close()},[]);let V=o.data,Re=n===`opencode`||n===`cline`,Be=V===void 0?[`llm`]:hr(V),G=[];for(let e of Be)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&G.push(e);(0,Q.useEffect)(()=>{if(V===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=G[0];if(e!==void 0&&G.includes(e)){i!==e&&a(e);return}!G.includes(i)&&t!==void 0&&a(t)},[V,r,i,G.join(`|`)]),(0,Q.useEffect)(()=>{Re&&V!==void 0&&V.supportsModelDiscovery!==!1&&Ie.current!==n&&(Ie.current=n,f.mutate(n))},[Re,f,n,V?.supportsModelDiscovery]);let K=c.data??[],Ve=s.data??[],He=(()=>{let e=new Map;for(let t of Ve){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`),q=He.filter(e=>e.serviceKind===`imageGeneration`),J=He.filter(e=>e.serviceKind===`videoGeneration`),Y=G.includes(i)?i:G[0],Ke=j||We[0]?.modelId||``,Je=()=>{let e=D.trim();Ke&&e&&(F(null),E.mutate({providerId:n,request:{modelId:Ke,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>F({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>F({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,$.jsx)(k,{label:`Loading provider...`});if(o.isError)return(0,$.jsx)(O,{title:`Unable to load providers`,message:`The provider details could not be read, so this page cannot resolve its endpoint settings.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,$.jsx)(_t,{to:`/providers`,label:`Back to providers`})});if(!V)return(0,$.jsx)(A,{icon:(0,$.jsx)(ut,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,$.jsx)(_t,{to:`/providers`,label:`Back to providers`})});let Ye=K.filter(e=>e.status===`active`).length,Xe=e=>{let t=e===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?Qe():fe(!0);return}be(Wn(t)),ge(e)},Ze=()=>{if(R===null)return;let e=Gn(R===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[],ve);if(e.length>0){y.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=R;ge(null),t===`browser`?Qe(ve):(Se(ve),fe(!0))},Qe=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,B.current=t),b.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,B.current=r)),!r){y.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Pe({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),B.current===t&&(B.current=null),y.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,$.jsxs)(X,{gap:`16px`,children:[(0,$.jsx)(vt,{title:`${V.label||V.displayName}${Y?` (${mr(Y)})`:``}`,description:`${V.providerId}/${V.baseUrl?` · ${V.baseUrl}`:``}`,icon:(0,$.jsx)(Ge,{icon:V.providerId,name:V.label||V.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,$.jsx)(Z,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:V.isBuiltIn?(0,$.jsx)(g,{variant:V.enabled?`danger`:`secondary`,icon:V.enabled?(0,$.jsx)(ie,{size:13}):(0,$.jsx)(lt,{size:13}),loading:v.isPending,onClick:()=>v.mutate({providerId:n,enabled:!V.enabled},{onSuccess:e=>y.success(e.enabled?`Provider enabled`:`Provider disabled`,V.label||V.displayName),onError:e=>y.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:V.enabled?`Disable provider globally`:`Enable provider globally`,children:V.enabled?`Disable`:`Enable`}):null})}),(0,$.jsx)(qt,{provider:V}),V.isBuiltIn?null:(0,$.jsx)(Jt,{provider:V}),Y===`llm`?(0,$.jsx)(Ot,{providerId:n,clientVersion:V.clientVersion,routeIdentityVersions:V.routeIdentityVersions,userAgentEditable:yt(V)}):null,(0,$.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:V.requiresAccount===!1?(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Accounts`,icon:(0,$.jsx)(st,{size:16})}),(0,$.jsx)(H,{children:(0,$.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,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Accounts`,subtitle:`${K.length} total · ${Ye} active · ${K.length-Ye} disabled`,icon:(0,$.jsx)(st,{size:16}),action:(0,$.jsxs)(qe,{children:[V.oauthFlows?.browser&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ce,{size:13}),disabled:b.isPending,onClick:()=>Xe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:b.isPending?`Starting...`:`Login with browser`}),V.oauthFlows?.device&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(ne,{size:13}),onClick:()=>Xe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),V.oauthFlows?.import&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(m,{size:13}),onClick:()=>he(!0),title:V.oauthFlows.browser||V.oauthFlows.device||V.oauthFlows.refreshable?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:V.oauthFlows.browser||V.oauthFlows.device||V.oauthFlows.refreshable?`Import credential`:`Add API key`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(re,{size:13}),onClick:()=>C(!0),children:`Add Account`})]})}),(0,$.jsxs)(H,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(Ut,{providerId:n}),c.isPending?(0,$.jsx)(k,{label:`Loading accounts...`}):c.isError?(0,$.jsx)(O,{message:`Failed to load accounts`,onRetry:()=>c.refetch()}):K.length===0?(0,$.jsx)(A,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,$.jsx)(In,{providerId:n,accounts:K,onDelete:e=>Oe(e),showGrokProbe:Y===`llm`&&n===`grok`,grokProbePending:_.isPending,onGrokProbe:()=>{_.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;y.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>y.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),Y===`llm`?(0,$.jsxs)($.Fragment,{children:[n===`inferhub`?(0,$.jsx)(Bt,{}):null,(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Models`,subtitle:`${Ue.length} model${Ue.length===1?``:`s`} registered`,icon:(0,$.jsx)(l,{size:16}),action:(0,$.jsxs)(Z,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,$.jsx)(tr,{id:`models-section-thinking-effort`,value:I,onChange:le}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(ae,{size:13,className:u.isPending||f.isPending?`animate-spin`:``}),disabled:u.isPending||f.isPending,onClick:()=>u.mutate(n),children:u.isPending||f.isPending?`Fetching...`:`Fetch models`}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(ce,{size:13,className:p?`animate-spin`:``}),disabled:u.isPending||f.isPending||p||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}?`)){h(!0);try{let t=await me(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([x.invalidateQueries({queryKey:L.providers.models(n)}),x.invalidateQueries({queryKey:L.providers.all})]);let r=t.failures.length;y.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){y.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{h(!1)}}},children:p?`Deleting…`:`Delete fetched`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(re,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,$.jsx)(H,{className:`flex flex-col gap-8`,children:s.isPending?(0,$.jsx)(k,{label:`Loading models...`}):s.isError?(0,$.jsx)(O,{message:`Failed to load models`,onRetry:()=>s.refetch()}):Ue.length===0?(0,$.jsx)(A,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,$.jsx)(pr,{providerId:n,models:Ue,serviceKind:`llm`,thinkingEffort:I,searchCapable:V?.supportsWebSearch===!0})})]})]}):Y===`websearch`?(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,$.jsx)(d,{size:16})}),(0,$.jsx)(H,{className:`flex flex-col gap-6`,children:s.isPending?(0,$.jsx)(k,{label:`Loading search models...`}):s.isError?(0,$.jsx)(O,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):We.length===0?(0,$.jsx)(A,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,$.jsx)(`select`,{value:Ke,onChange:e=>{M(e.target.value),F(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,$.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,$.jsx)(`input`,{value:D,onChange:e=>ee(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,$.jsxs)(Z,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:Je,children:`Test search`}),N?(0,$.jsx)(`span`,{className:`text-badge`,style:{color:N.ok?`var(--green)`:`var(--red)`},children:N.ok?`Search ok · ${N.latencyMs}ms · ${N.count??0} result(s)`:N.error??`Search failed.`}):null]}),N&&N.results&&N.results.length>0?(0,$.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:N.results.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,$.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):Y===`imageGeneration`||Y===`videoGeneration`?(0,$.jsxs)(W,{children:[(0,$.jsx)(U,{title:mr(Y),subtitle:Y===`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:Y===`imageGeneration`?(0,$.jsx)(te,{size:16}):(0,$.jsx)(pt,{size:16})}),(0,$.jsx)(H,{className:`flex flex-col gap-6`,children:s.isPending?(0,$.jsx)(k,{label:`Loading ${mr(Y).toLowerCase()} models...`}):s.isError?(0,$.jsx)(O,{message:`Failed to load ${mr(Y).toLowerCase()} models`,onRetry:()=>s.refetch()}):(Y===`imageGeneration`?q:J).length===0?(0,$.jsx)(A,{title:`No ${mr(Y)} models found`,message:`This provider advertises ${mr(Y)}, but no ${Y} model is registered yet.`}):(0,$.jsx)(pr,{providerId:n,models:Y===`imageGeneration`?q:J,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,$.jsx)(W,{children:(0,$.jsx)(H,{children:(0,$.jsx)(A,{title:`Service not available`,message:`This provider advertises ${Be.map(mr).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),S&&(0,$.jsx)(zn,{providerId:n,accounts:K,onClose:()=>C(!1)}),Y===`llm`&&w?(0,$.jsx)(nr,{providerId:n,provider:V,onClose:()=>T(!1)}):null,(0,$.jsx)(ze,{open:z!==null,onClose:()=>{ke||Oe(null)},onConfirm:async()=>{if(z){Ae(!0);try{let e=z.tenantId===null?`/global/accounts/${encodeURIComponent(z.id)}`:`/accounts/${encodeURIComponent(z.id)}`;await me(e,{method:`DELETE`}),x.removeQueries({queryKey:L.quota.account(z.id),exact:!0}),await Promise.all([x.invalidateQueries({queryKey:L.providers.accounts(n)}),x.invalidateQueries({queryKey:L.providers.healthEvents(n,z.id)}),x.invalidateQueries({queryKey:L.providers.all}),x.invalidateQueries({queryKey:L.quota.all})]),y.success(`Account deleted`,z.label||z.id.slice(0,8)),Oe(null)}catch(e){throw y.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Ae(!1)}}},title:`Delete account?`,message:`Delete "${z?.label||z?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),de&&(0,$.jsx)(Un,{providerId:n,parameters:xe,onClose:()=>{fe(!1),Se({})}}),R!==null&&(0,$.jsx)(P,{open:!0,onClose:()=>ge(null),title:R===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>ge(null),children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,onClick:Ze,children:`Continue`})]}),children:(0,$.jsxs)(X,{gap:`12px`,children:[(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:R===`browser`?`Choose how ${V.label||V.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,$.jsx)(Kn,{fields:R===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[],values:ve,idPrefix:`flow-${R}`,onChange:(e,t)=>be(n=>({...n,[e]:t}))})]})}),pe&&V?.oauthFlows?.import===!0&&(0,$.jsx)(qn,{providerId:n,providerName:V.label||V.displayName,fields:V.oauthFlows.importFields,onClose:()=>he(!1)}),Me&&(0,$.jsx)(Vn,{providerId:n,authorizeUrl:Me.authorizeUrl,state:Me.state,popup:Me.popup,onClose:e=>{B.current=null,Pe(null),e&&x.invalidateQueries({queryKey:L.providers.accounts(n)})}})]})}export{gr as default};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r,m as i}from"./numbers-DkfMR5Qs.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-mPDRlQkl.js";import{t as u}from"./dialog-k37exjNt.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-BFhGpwR1.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{Q as h,T as g,_,a as v,g as y,i as ee,it as b,lt as x,m as S,s as C,tt as w,w as te}from"./entry-ByMGkR3C.js";import{n as T,r as E,t as D}from"./card-DS7CQEsO.js";import{t as O}from"./badge-CR72dasT.js";import{n as k}from"./input-V1umFiBk.js";import{t as A}from"./select-C6MMiaio.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-DOmJxg7H.js";import{t as N}from"./stack-BHTfXdz_.js";import{n as P}from"./inline-BhY2sSnO.js";import{t as ne}from"./list-row-1zzZYM0B.js";import{t as F}from"./privacy-mode-GM8bej85.js";import{t as I}from"./AccountCooldown-Bjo92Qat.js";var L=e(t(),1),R=n();function re(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function ie({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),i=n=>t(e.filter((e,t)=>t!==n));return(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label block`,children:[(0,R.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,R.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,R.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,R.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(r,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>i(a),children:(0,R.jsx)(f,{size:13})})]},a)),(0,R.jsxs)(r,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,R.jsx)(d,{size:13}),` Add header`]})]})]})}function z({children:e}){return(0,R.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var B=i(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),V=i(`block flex-1 p-6 no-underline text-inherit`),H=i(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function U(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var W=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ae(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 W.test(r)?n.origin:null}function G({variant:e,open:t,onClose:n}){let a=ee(),o=v(),s=te(),c=g(),[l,d]=(0,L.useState)(``),[f,m]=(0,L.useState)(``),[h,_]=(0,L.useState)(``),[y,b]=(0,L.useState)(``),[x,S]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!0),[T,E]=(0,L.useState)([]),[D,O]=(0,L.useState)(null),[j,N]=(0,L.useState)(!1),[F,I]=(0,L.useState)(null),[z,B]=(0,L.useState)(!1),V=e===`anthropic-compatible`,H=V?`messages`:`chat`,[U,W]=(0,L.useState)(H),G=(0,L.useMemo)(()=>ae(h),[h]);(0,L.useEffect)(()=>{t&&(d(``),b(``),W(H),_(``),S(!1),w(!0),E([]),O(null),I(null))},[t]);let K=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},q=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}B(!0),I(null),O(null);try{let e=re(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:U,cliIdentity:C,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:p(e,`Connection test failed`)})}finally{B(!1)}};return(0,R.jsx)(u,{open:t,onClose:n,title:V?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(r,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,R.jsx)(r,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,R.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=re(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:U,compatibilityProfile:{cli_identity:C,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:y.trim()}}),x&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,R.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,R.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:V?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,R.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:V?`ac-prod`:`oc-prod`,required:!0}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,R.jsx)(`span`,{children:`Base URL`}),(0,R.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,V?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-url`,value:h,onChange:e=>_(e.target.value),placeholder:V?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(_),children:`Paste`})]}),G===null?null:(0,R.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:G}),` instead — Cartethyia appends the endpoint path itself.`]})]}),V?null:(0,R.jsx)(A,{id:`compat-wire`,label:`API format`,value:U,onValueChange:e=>W(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,R.jsx)(`span`,{children:`API Key`}),(0,R.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>b(e.target.value)})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,disabled:z,onClick:()=>void q(),children:z?`Testing...`:`Test connection`}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(b),children:`Paste`})]}),F?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:i(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,R.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:x,onChange:S,id:`compat-autofetch`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:C,onChange:w,id:`compat-cli-identity`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:V?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:V?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,R.jsx)(ie,{pairs:T,onChange:E})]})})}function K({customProvider:e}){let t=C(),[n,a]=(0,L.useState)(!1),o=y(e.providerId),s=o.data?.length,c=S(e.providerId),l=c.data,d=Q(l??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:i(V,`pr-20 min-h-38`),children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:e.label||e.providerId}),e.baseUrl?(0,R.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,R.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.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,R.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,R.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,R.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,R.jsxs)(N,{gap:`12px`,children:[(0,R.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,R.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,R.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,R.jsxs)(m,{children:[(0,R.jsx)(r,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,R.jsx)(r,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function q({customProviders:e}){let[t,n]=(0,L.useState)(!1),[i,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,R.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,R.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,R.jsx)(x,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(r,{size:`sm`,variant:`ghost`,icon:c?(0,R.jsx)(o,{size:13}):(0,R.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,R.jsx)(D,{children:(0,R.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,R.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,R.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,R.jsx)(z,{children:e.map(e=>(0,R.jsx)(K,{customProvider:e},e.providerId))}),(0,R.jsx)(G,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,R.jsx)(G,{variant:`openai-compatible`,open:i,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||I(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&I(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,R.jsxs)(R.Fragment,{children:[e.healthy>0?(0,R.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,R.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,R.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,R.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,R.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,L.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),r=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=S(e.providerId),c=s.data,l=Q(c??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,R.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,R.jsx)(`span`,{className:i(`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,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:V,children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:r}),(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.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,R.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,R.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function me(){let[e,t]=(0,L.useState)(fe),n=_(),u=F(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,L.useMemo)(()=>n.data??[],[n.data]),h=(0,L.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),g=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`websearch`)&&f(e)),[m,d]),v=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`llm`)&&f(e)),[m,d]),[y,ee]=w(),S=y.get(`tab`),C=S===`search`||S===`media`?S:`llm`,te=e=>{ee(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,L.useMemo)(()=>m.filter(e=>(U(e).includes(`imageGeneration`)||U(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,L.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,L.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=v;return pe.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[v,k,O,C]),M=n.isPending&&!n.data?(0,R.jsx)(c,{label:`Loading providers...`}):n.isError?(0,R.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,R.jsx)(N,{gap:`24px`,children:(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,R.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,R.jsxs)(`button`,{onClick:()=>te(e),className:i(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===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`?` (${g.length})`:e===`media`?` (${O.length})`:` (${v.length})`]},e))}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:d?(0,R.jsx)(a,{size:12}):(0,R.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,R.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,R.jsx)(q,{customProviders:h}):null,j.length===0?(0,R.jsx)(D,{children:(0,R.jsx)(T,{children:(0,R.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,R.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,R.jsx)(x,{size:15,className:i(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,R.jsxs)(N,{gap:`1px`,children:[(0,R.jsxs)(`h2`,{className:`text-body font-bold tracking-[-0.01em]`,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,R.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,R.jsx)(z,{children:n.providers.map(e=>(0,R.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?U(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{me as default,Q as summarizeAccounts};
|
|
1
|
+
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r,m as i}from"./numbers-BOevJzdz.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-2c5V4zo7.js";import{t as u}from"./dialog-C07hr5_G.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-UETqfytp.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{Q as h,T as g,_,a as v,g as y,i as ee,it as b,lt as x,m as S,s as C,tt as w,w as te}from"./entry-CwPRKk0d.js";import{n as T,r as E,t as D}from"./card-CdsSlWA3.js";import{t as O}from"./badge-CKsF123d.js";import{n as k}from"./input-CjCnXweJ.js";import{t as A}from"./select-C980c4cz.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-Dkke7Naf.js";import{t as N}from"./stack-_gfTdLVB.js";import{n as P}from"./inline-C9dCYaBZ.js";import{t as ne}from"./list-row-CM1AaG_y.js";import{t as F}from"./privacy-mode-GM8bej85.js";import{t as I}from"./AccountCooldown-Bjo92Qat.js";var L=e(t(),1),R=n();function re(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function ie({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),i=n=>t(e.filter((e,t)=>t!==n));return(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label block`,children:[(0,R.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,R.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,R.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,R.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(r,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>i(a),children:(0,R.jsx)(f,{size:13})})]},a)),(0,R.jsxs)(r,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,R.jsx)(d,{size:13}),` Add header`]})]})]})}function z({children:e}){return(0,R.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var B=i(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),V=i(`block flex-1 p-6 no-underline text-inherit`),H=i(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function U(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var W=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ae(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 W.test(r)?n.origin:null}function G({variant:e,open:t,onClose:n}){let a=ee(),o=v(),s=te(),c=g(),[l,d]=(0,L.useState)(``),[f,m]=(0,L.useState)(``),[h,_]=(0,L.useState)(``),[y,b]=(0,L.useState)(``),[x,S]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!0),[T,E]=(0,L.useState)([]),[D,O]=(0,L.useState)(null),[j,N]=(0,L.useState)(!1),[F,I]=(0,L.useState)(null),[z,B]=(0,L.useState)(!1),V=e===`anthropic-compatible`,H=V?`messages`:`chat`,[U,W]=(0,L.useState)(H),G=(0,L.useMemo)(()=>ae(h),[h]);(0,L.useEffect)(()=>{t&&(d(``),b(``),W(H),_(``),S(!1),w(!0),E([]),O(null),I(null))},[t]);let K=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},q=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}B(!0),I(null),O(null);try{let e=re(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:U,cliIdentity:C,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:p(e,`Connection test failed`)})}finally{B(!1)}};return(0,R.jsx)(u,{open:t,onClose:n,title:V?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(r,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,R.jsx)(r,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,R.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=re(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:U,compatibilityProfile:{cli_identity:C,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:y.trim()}}),x&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,R.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,R.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:V?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,R.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:V?`ac-prod`:`oc-prod`,required:!0}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,R.jsx)(`span`,{children:`Base URL`}),(0,R.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,V?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-url`,value:h,onChange:e=>_(e.target.value),placeholder:V?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(_),children:`Paste`})]}),G===null?null:(0,R.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:G}),` instead — Cartethyia appends the endpoint path itself.`]})]}),V?null:(0,R.jsx)(A,{id:`compat-wire`,label:`API format`,value:U,onValueChange:e=>W(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,R.jsx)(`span`,{children:`API Key`}),(0,R.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>b(e.target.value)})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,disabled:z,onClick:()=>void q(),children:z?`Testing...`:`Test connection`}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(b),children:`Paste`})]}),F?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:i(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,R.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:x,onChange:S,id:`compat-autofetch`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:C,onChange:w,id:`compat-cli-identity`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:V?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:V?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,R.jsx)(ie,{pairs:T,onChange:E})]})})}function K({customProvider:e}){let t=C(),[n,a]=(0,L.useState)(!1),o=y(e.providerId),s=o.data?.length,c=S(e.providerId),l=c.data,d=Q(l??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:i(V,`pr-20 min-h-38`),children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:e.label||e.providerId}),e.baseUrl?(0,R.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,R.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.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,R.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,R.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,R.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,R.jsxs)(N,{gap:`12px`,children:[(0,R.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,R.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,R.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,R.jsxs)(m,{children:[(0,R.jsx)(r,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,R.jsx)(r,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function q({customProviders:e}){let[t,n]=(0,L.useState)(!1),[i,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,R.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,R.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,R.jsx)(x,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(r,{size:`sm`,variant:`ghost`,icon:c?(0,R.jsx)(o,{size:13}):(0,R.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,R.jsx)(D,{children:(0,R.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,R.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,R.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,R.jsx)(z,{children:e.map(e=>(0,R.jsx)(K,{customProvider:e},e.providerId))}),(0,R.jsx)(G,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,R.jsx)(G,{variant:`openai-compatible`,open:i,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||I(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&I(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,R.jsxs)(R.Fragment,{children:[e.healthy>0?(0,R.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,R.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,R.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,R.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,R.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,L.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),r=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=S(e.providerId),c=s.data,l=Q(c??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,R.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,R.jsx)(`span`,{className:i(`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,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:V,children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:r}),(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.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,R.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,R.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=`text-body font-bold tracking-[-0.01em]`,me=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function he(){let[e,t]=(0,L.useState)(fe),n=_(),u=F(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,L.useMemo)(()=>n.data??[],[n.data]),h=(0,L.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),g=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`websearch`)&&f(e)),[m,d]),v=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`llm`)&&f(e)),[m,d]),[y,ee]=w(),S=y.get(`tab`),C=S===`search`||S===`media`?S:`llm`,te=e=>{ee(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,L.useMemo)(()=>m.filter(e=>(U(e).includes(`imageGeneration`)||U(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,L.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,L.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=v;return me.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[v,k,O,C]),M=n.isPending&&!n.data?(0,R.jsx)(c,{label:`Loading providers...`}):n.isError?(0,R.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,R.jsx)(N,{gap:`24px`,children:(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,R.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,R.jsxs)(`button`,{onClick:()=>te(e),className:i(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===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`?` (${g.length})`:e===`media`?` (${O.length})`:` (${v.length})`]},e))}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:d?(0,R.jsx)(a,{size:12}):(0,R.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,R.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,R.jsx)(q,{customProviders:h}):null,j.length===0?(0,R.jsx)(D,{children:(0,R.jsx)(T,{children:(0,R.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,R.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,R.jsx)(x,{size:15,className:i(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,R.jsxs)(N,{gap:`1px`,children:[(0,R.jsxs)(`h2`,{className:pe,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,R.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,R.jsx)(z,{children:n.providers.map(e=>(0,R.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?U(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{he as default,Q as summarizeAccounts};
|
|
Binary file
|