cartethyia 2.7.5 → 2.7.6
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 +4 -1
- package/README.md +1 -1
- package/dist/dashboard/assets/BannedPage-B1N603cM.js +1 -0
- package/dist/dashboard/assets/BannedPage-B1N603cM.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-9q4_4NoK.js +3 -0
- package/dist/dashboard/assets/CliToolDetailPage-9q4_4NoK.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-DwshGtK-.js +1 -0
- package/dist/dashboard/assets/CliToolsPage-DwshGtK-.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-D762MIkp.js +1 -0
- package/dist/dashboard/assets/CombosPage-D762MIkp.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-D5rol2j2.js → ConsoleLogPage-KRYjHZsX.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-KRYjHZsX.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js +1 -0
- package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js.gz +0 -0
- package/dist/dashboard/assets/{InjectSystemPromptPanel-B5nZvmf0.js → InjectSystemPromptPanel-d5v3K_Yc.js} +245 -2
- package/dist/dashboard/assets/InjectSystemPromptPanel-d5v3K_Yc.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-Ccv4tjNS.js +1 -0
- package/dist/dashboard/assets/LoginPage-Ccv4tjNS.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-DnQPSIA8.js → ModelPicker-C6WlpU5E.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-C6WlpU5E.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-DN9fYNWA.js +1 -0
- package/dist/dashboard/assets/OverviewPage-DN9fYNWA.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js +5 -0
- package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js +1 -0
- package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-5SnUSy3j.js → ProxyPage-DxjvUzSD.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-DxjvUzSD.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-OaHScjpX.js +1 -0
- package/dist/dashboard/assets/QuotaPage-OaHScjpX.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-BJtRZ4qD.js → SettingsPage-BW4AKj2H.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-BW4AKj2H.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-44BZrxFC.js +1 -0
- package/dist/dashboard/assets/SetupPage-44BZrxFC.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-BfAb5-o_.js → StudioPage-DRPavCdU.js} +4 -4
- package/dist/dashboard/assets/StudioPage-DRPavCdU.js.gz +0 -0
- package/dist/dashboard/assets/ToolIcon-CfeLA-Z_.js +1 -0
- package/dist/dashboard/assets/ToolIcon-CfeLA-Z_.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-BNzeZ2Vk.js → UsagePage-B7M7LvMM.js} +13 -13
- package/dist/dashboard/assets/UsagePage-B7M7LvMM.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-KvX83mRe.js +1 -0
- package/dist/dashboard/assets/api-keys-KvX83mRe.js.gz +0 -0
- package/dist/dashboard/assets/app-DRnQLhsc.js +9 -0
- package/dist/dashboard/assets/app-DRnQLhsc.js.gz +0 -0
- package/dist/dashboard/assets/app-mweRcsKp.css +2 -0
- package/dist/dashboard/assets/app-mweRcsKp.css.gz +0 -0
- package/dist/dashboard/assets/{assert-C0K-c4eo.js → assert-CidQVoNo.js} +1 -1
- package/dist/dashboard/assets/assert-CidQVoNo.js.gz +0 -0
- package/dist/dashboard/assets/{badge-DfbhQU4k.js → badge-BaX2GTrn.js} +1 -1
- package/dist/dashboard/assets/badge-BaX2GTrn.js.gz +0 -0
- package/dist/dashboard/assets/{banner-BllT4LcF.js → banner-DFH4Bkte.js} +1 -1
- package/dist/dashboard/assets/banner-DFH4Bkte.js.gz +0 -0
- package/dist/dashboard/assets/{card-CtkX66Wd.js → card-CxDw0lK6.js} +1 -1
- package/dist/dashboard/assets/card-CxDw0lK6.js.gz +0 -0
- package/dist/dashboard/assets/circle-question-mark-Cz4un8sH.js +1 -0
- package/dist/dashboard/assets/circle-question-mark-Cz4un8sH.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-CQXVMn4P.js → cli-tools-Bwv5-zGZ.js} +1 -1
- package/dist/dashboard/assets/cli-tools-Bwv5-zGZ.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-BQqBQd2n.js → clipboard-button-DfS1ntiq.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-DfS1ntiq.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BK-NRr5u.js +1 -0
- package/dist/dashboard/assets/dialog-BK-NRr5u.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-BrTEZ8zu.js → drawer-QqPul6sC.js} +1 -1
- package/dist/dashboard/assets/drawer-QqPul6sC.js.gz +0 -0
- package/dist/dashboard/assets/entry-BMlYJVFj.js +1 -0
- package/dist/dashboard/assets/entry-BMlYJVFj.js.gz +0 -0
- package/dist/dashboard/assets/entry-D6WvojeD.js +4 -0
- package/dist/dashboard/assets/entry-D6WvojeD.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dmx7gBiN.js +1 -0
- package/dist/dashboard/assets/entry-Dmx7gBiN.js.gz +0 -0
- package/dist/dashboard/assets/{formatters-BAACA727.js → formatters-u7JPB5BX.js} +1 -1
- package/dist/dashboard/assets/formatters-u7JPB5BX.js.gz +0 -0
- package/dist/dashboard/assets/house-h9AZlJuT.js +1 -0
- package/dist/dashboard/assets/house-h9AZlJuT.js.gz +0 -0
- package/dist/dashboard/assets/{index-FQlj0HUT.js → index-Ko4dLRnV.js} +2 -2
- package/dist/dashboard/assets/index-Ko4dLRnV.js.gz +0 -0
- package/dist/dashboard/assets/{inline-C4gU5iOL.js → inline-CHJQwxLa.js} +1 -1
- package/dist/dashboard/assets/inline-CHJQwxLa.js.gz +0 -0
- package/dist/dashboard/assets/{input-BHHX_Tmm.js → input-BlmlizVV.js} +1 -1
- package/dist/dashboard/assets/input-BlmlizVV.js.gz +0 -0
- package/dist/dashboard/assets/{layout-CajrYUnD.js → layout-Bz93I-yE.js} +1 -1
- package/dist/dashboard/assets/layout-Bz93I-yE.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-Bx2I7XUe.js → list-row-Ml16KCfu.js} +1 -1
- package/dist/dashboard/assets/list-row-Ml16KCfu.js.gz +0 -0
- package/dist/dashboard/assets/{live-DNNqRbj2.js → live-7_QpnYGu.js} +1 -1
- package/dist/dashboard/assets/live-7_QpnYGu.js.gz +0 -0
- package/dist/dashboard/assets/{mutation-Rr0TIvcj.js → mutation-GU7XdEjz.js} +1 -1
- package/dist/dashboard/assets/mutation-GU7XdEjz.js.gz +0 -0
- package/dist/dashboard/assets/{network-C5UBACrJ.js → network-CuMDaTzT.js} +1 -1
- package/dist/dashboard/assets/network-CuMDaTzT.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CoqpaDMx.js +2 -0
- package/dist/dashboard/assets/numbers-CoqpaDMx.js.gz +0 -0
- package/dist/dashboard/assets/{pagination-Xsi9Qx04.js → pagination-B5aOoweZ.js} +1 -1
- package/dist/dashboard/assets/pagination-B5aOoweZ.js.gz +0 -0
- package/dist/dashboard/assets/providers/zai.webp +0 -0
- package/dist/dashboard/assets/providers/zcode.webp +0 -0
- package/dist/dashboard/assets/{query-keys-BloKtaXJ.js → query-keys-YSoQOUh6.js} +1 -1
- package/dist/dashboard/assets/{query-keys-BloKtaXJ.js.gz → query-keys-YSoQOUh6.js.gz} +0 -0
- package/dist/dashboard/assets/quota-DJ1QlAOq.js +1 -0
- package/dist/dashboard/assets/quota-DJ1QlAOq.js.gz +0 -0
- package/dist/dashboard/assets/{routing-in0f_IfK.js → routing-fnCsxgNO.js} +1 -1
- package/dist/dashboard/assets/routing-fnCsxgNO.js.gz +0 -0
- package/dist/dashboard/assets/{select-BLULNqTp.js → select-BHqpd-bg.js} +2 -2
- package/dist/dashboard/assets/select-BHqpd-bg.js.gz +0 -0
- package/dist/dashboard/assets/{settings-CcGczj6I.js → settings-BxslsErn.js} +1 -1
- package/dist/dashboard/assets/settings-BxslsErn.js.gz +0 -0
- package/dist/dashboard/assets/{stack-D2lIR0tg.js → stack-j7cXjgYX.js} +1 -1
- package/dist/dashboard/assets/stack-j7cXjgYX.js.gz +0 -0
- package/dist/dashboard/assets/{state-DTARjfiW.js → state-DHmEnLa2.js} +1 -1
- package/dist/dashboard/assets/state-DHmEnLa2.js.gz +0 -0
- package/dist/dashboard/assets/{switch-c0oPSnqW.js → switch-DmZcyTIC.js} +1 -1
- package/dist/dashboard/assets/switch-DmZcyTIC.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-m8WGNPrz.js → useMutation-CbCP4w1o.js} +1 -1
- package/dist/dashboard/assets/useMutation-CbCP4w1o.js.gz +0 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +57 -57
- package/migrations/full-postgres/0042_add_telemetry_degenerate_stop.sql +14 -0
- package/migrations/lite-sqlite3/0042_add_telemetry_degenerate_stop.sql +12 -0
- package/package.json +1 -1
- package/src/boot/dependencies.ts +10 -2
- package/src/config/providers.ts +13 -7
- package/src/config/spec.ts +18 -11
- package/src/config/usage.ts +27 -0
- package/src/console/api-keys/routes.ts +19 -23
- package/src/console/cli-tools/contracts.ts +39 -295
- package/src/console/cli-tools/fs-ops.ts +29 -0
- package/src/console/cli-tools/injectors/claude.ts +3 -3
- package/src/console/cli-tools/injectors/codex.ts +6 -6
- package/src/console/cli-tools/injectors/driver.ts +8 -105
- package/src/console/cli-tools/injectors/kilo.ts +146 -21
- package/src/console/cli-tools/injectors/opencode.ts +28 -5
- package/src/console/cli-tools/routes.ts +6 -0
- package/src/console/cli-tools/service.ts +7 -6
- package/src/console/observability/contracts.ts +6 -0
- package/src/console/observability/store.ts +3 -0
- package/src/console/share/share-stats.ts +7 -9
- package/src/observability/event-log.ts +7 -0
- package/src/observability/event-query.ts +2 -0
- package/src/observability/telemetry-buffer.ts +7 -0
- package/src/persistence/schema.ts +8 -0
- package/src/persistence/stores/api-key-store.ts +19 -1
- package/src/protocol/dsml.ts +5 -76
- package/src/providers/adapters/compatible-adapter.ts +29 -1
- package/src/providers/default-registry.ts +12 -2
- package/src/providers/integrations/antigravity/antigravity-protocol.ts +88 -14
- package/src/providers/integrations/antigravity/antigravity-quota.ts +18 -6
- package/src/providers/integrations/antigravity/antigravity.ts +20 -11
- package/src/providers/integrations/cursor/cursor.ts +2 -3
- package/src/providers/integrations/github/github-discovery.ts +15 -2
- package/src/providers/integrations/github/github-oauth.ts +178 -9
- package/src/providers/integrations/github/github.ts +95 -14
- package/src/providers/integrations/kiro/kiro.ts +1 -2
- package/src/providers/integrations/qoder/qoder-catalog.ts +9 -3
- package/src/providers/integrations/qoder/qoder.ts +147 -88
- package/src/providers/integrations/trae/trae.ts +2 -2
- package/src/providers/operations/account-error-classification.ts +67 -17
- package/src/providers/operations/byok-wire-profile.ts +19 -15
- package/src/providers/provider-usage.ts +15 -49
- package/src/security/admission/service.ts +11 -4
- package/src/security/api-key-auth.ts +5 -3
- package/src/transport/dispatch/attempt-finalize.ts +69 -21
- package/src/transport/dispatch/attempt-loop.ts +22 -0
- package/src/transport/failure-policy.ts +15 -1
- package/src/transport/guards/error-lifecycle.ts +4 -0
- package/src/transport/request/state.ts +6 -0
- package/src/transport/routing/router.ts +7 -0
- package/src/transport/surface/reasoning-summary.ts +9 -14
- package/src/transport/vision-handoff.ts +83 -28
- package/dist/dashboard/assets/BannedPage-Cj15GsMp.js +0 -1
- package/dist/dashboard/assets/BannedPage-Cj15GsMp.js.gz +0 -0
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js +0 -1
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-DZKmVuJN.js +0 -1
- package/dist/dashboard/assets/CliToolDetailPage-DZKmVuJN.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-BIccZmeL.js +0 -1
- package/dist/dashboard/assets/CliToolsPage-BIccZmeL.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js +0 -1
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-D5rol2j2.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-BKj_r0rp.js +0 -1
- package/dist/dashboard/assets/CustomizationPage-BKj_r0rp.js.gz +0 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-B5nZvmf0.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-DkXb6dx-.js +0 -1
- package/dist/dashboard/assets/LoginPage-DkXb6dx-.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-DnQPSIA8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js +0 -1
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js +0 -5
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js +0 -1
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-5SnUSy3j.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js +0 -1
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-BJtRZ4qD.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-WTa0sktC.js +0 -1
- package/dist/dashboard/assets/SetupPage-WTa0sktC.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-BfAb5-o_.js.gz +0 -0
- package/dist/dashboard/assets/ToolIcon-K1ckcDKg.js +0 -1
- package/dist/dashboard/assets/ToolIcon-K1ckcDKg.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BNzeZ2Vk.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-l29JROPv.js +0 -1
- package/dist/dashboard/assets/api-keys-l29JROPv.js.gz +0 -0
- package/dist/dashboard/assets/app--PJWq8_C.css +0 -2
- package/dist/dashboard/assets/app--PJWq8_C.css.gz +0 -0
- package/dist/dashboard/assets/app-Bgd3zANQ.js +0 -9
- package/dist/dashboard/assets/app-Bgd3zANQ.js.gz +0 -0
- package/dist/dashboard/assets/assert-C0K-c4eo.js.gz +0 -0
- package/dist/dashboard/assets/badge-DfbhQU4k.js.gz +0 -0
- package/dist/dashboard/assets/banner-BllT4LcF.js.gz +0 -0
- package/dist/dashboard/assets/card-CtkX66Wd.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-CQXVMn4P.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-BQqBQd2n.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BEK7KP0H.js +0 -1
- package/dist/dashboard/assets/dialog-BEK7KP0H.js.gz +0 -0
- package/dist/dashboard/assets/drawer-BrTEZ8zu.js.gz +0 -0
- package/dist/dashboard/assets/entry-CHWxbS56.js +0 -1
- package/dist/dashboard/assets/entry-CHWxbS56.js.gz +0 -0
- package/dist/dashboard/assets/entry-EBHJ3DrE.js +0 -1
- package/dist/dashboard/assets/entry-EBHJ3DrE.js.gz +0 -0
- package/dist/dashboard/assets/entry-LCS85hiq.js +0 -4
- package/dist/dashboard/assets/entry-LCS85hiq.js.gz +0 -0
- package/dist/dashboard/assets/formatters-BAACA727.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-YSCE4UC2.js +0 -1
- package/dist/dashboard/assets/github-badge-YSCE4UC2.js.gz +0 -0
- package/dist/dashboard/assets/index-FQlj0HUT.js.gz +0 -0
- package/dist/dashboard/assets/inline-C4gU5iOL.js.gz +0 -0
- package/dist/dashboard/assets/input-BHHX_Tmm.js.gz +0 -0
- package/dist/dashboard/assets/layout-CajrYUnD.js.gz +0 -0
- package/dist/dashboard/assets/list-row-Bx2I7XUe.js.gz +0 -0
- package/dist/dashboard/assets/live-DNNqRbj2.js.gz +0 -0
- package/dist/dashboard/assets/mutation-Rr0TIvcj.js.gz +0 -0
- package/dist/dashboard/assets/network-C5UBACrJ.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CUWAZK4J.js +0 -2
- package/dist/dashboard/assets/numbers-CUWAZK4J.js.gz +0 -0
- package/dist/dashboard/assets/pagination-Xsi9Qx04.js.gz +0 -0
- package/dist/dashboard/assets/providers/zai-coding-plan.svg +0 -6
- package/dist/dashboard/assets/providers/zai-coding-plan.svg.gz +0 -0
- package/dist/dashboard/assets/quota-DvQbD_sr.js +0 -1
- package/dist/dashboard/assets/quota-DvQbD_sr.js.gz +0 -0
- package/dist/dashboard/assets/routing-in0f_IfK.js.gz +0 -0
- package/dist/dashboard/assets/select-BLULNqTp.js.gz +0 -0
- package/dist/dashboard/assets/settings-CcGczj6I.js.gz +0 -0
- package/dist/dashboard/assets/stack-D2lIR0tg.js.gz +0 -0
- package/dist/dashboard/assets/state-DTARjfiW.js.gz +0 -0
- package/dist/dashboard/assets/switch-c0oPSnqW.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-m8WGNPrz.js.gz +0 -0
- package/src/console/cli-tools/injectors/cline.ts +0 -110
- package/src/console/cli-tools/injectors/copilot.ts +0 -108
- package/src/console/cli-tools/injectors/cowork.ts +0 -64
- package/src/console/cli-tools/injectors/deepseek-tui.ts +0 -85
- package/src/console/cli-tools/injectors/droid.ts +0 -96
- package/src/console/cli-tools/injectors/grok-build.ts +0 -70
- package/src/console/cli-tools/injectors/hermes.ts +0 -101
- package/src/console/cli-tools/injectors/jcode.ts +0 -115
- package/src/console/cli-tools/injectors/openclaw.ts +0 -161
|
@@ -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{n as a,t as o}from"./arrow-up-59ms1iiT.js";import{n as s,t as c}from"./minimize-2-BTmMTK4o.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{D as d,E as f,S as p,c as m,g as h,k as ee,w as g,y as _}from"./numbers-CoqpaDMx.js";import{t as v}from"./chevron-right-BXIy5l3h.js";import{n as y,o as b}from"./InjectSystemPromptPanel-d5v3K_Yc.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 w}from"./gauge-BbIMy7MB.js";import{n as T,r as E,t as D}from"./state-DHmEnLa2.js";import{t as O}from"./key-round-UkavsGxp.js";import{n as te,r as ne,t as k}from"./clipboard-button-DfS1ntiq.js";import{n as A,t as j}from"./dialog-BK-NRr5u.js";import{t as M}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as N}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as P}from"./route-CNSNj9Zm.js";import{t as F}from"./search-JOKus9rb.js";import{t as I}from"./shield-check-DVS0Foqh.js";import{t as ae}from"./shield-BMQNxORh.js";import{t as oe}from"./trash-Cppn5c3R.js";import{C as L,T as se,b as ce,x as le}from"./assert-CidQVoNo.js";import{l as R,o as z,t as ue}from"./query-keys-YSoQOUh6.js";import{t as B}from"./useMutation-CbCP4w1o.js";import{V as de,lt as fe,pt as pe,st as V}from"./entry-D6WvojeD.js";import{n as me,r as H,t as he}from"./card-CxDw0lK6.js";import{t as U}from"./use-clipboard-B0Sy03fE.js";import{n as ge}from"./download-dRFo5_Wu.js";import{c as W,d as _e}from"./tokens-COzario9.js";import{t as G}from"./switch-DmZcyTIC.js";import{t as K}from"./badge-BaX2GTrn.js";import{n as q,t as ve}from"./input-BlmlizVV.js";import{t as ye}from"./select-BHqpd-bg.js";import{t as be}from"./ModelPicker-C6WlpU5E.js";import{t as J}from"./stack-j7cXjgYX.js";import{n as Y}from"./inline-CHJQwxLa.js";import{a as xe,c as Se,d as Ce,f as we,g as Te,h as Ee,i as De,l as Oe,m as ke,o as Ae,p as X,r as je,s as Z,t as Me,u as Ne}from"./api-keys-KvX83mRe.js";import{a as Pe,i as Fe,o as Ie,r as Le}from"./cli-tools-Bwv5-zGZ.js";import{t as Re}from"./layout-Bz93I-yE.js";import{c as ze}from"./quota-DJ1QlAOq.js";import{n as Be,t as Ve}from"./settings-BxslsErn.js";import{t as He}from"./banner-DFH4Bkte.js";var Ue=e(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=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`}]]),Ye=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`}]]),Xe=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`}]]),Ze=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`}]]),$e=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),et=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`}]]),tt=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],nt=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),rt={"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.`},it={"routing:invoke":P,"routing:cli_mapping":P,"search:invoke":F,"dashboard:read":C,"dashboard:write":M,"providers:read":V,"providers:write":We,"models:read":l,"models:write":x},at={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},ot=[{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 st(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]?at[n[2]]??1:1;return Math.round(r*i)}function ct(e){if(e==null)return``;let t=ot.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 lt(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function ut(e){let t=lt(e);return e.trim()===``?null:t}function dt({label:e,value:t,onChange:n,disabled:r}){let i=st(t),a=ot.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(q,{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:ot.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 ft({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Fe(),s=Le(),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)(P,{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)(G,{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:()=>h.success(`Saved remote routing for ${e.name}.`),onError:e=>h.error(R(e,`Could not save remote routing.`))})}}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>h.success(`Cleared remote routes for ${e.name}.`),onError:e=>h.error(R(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function pt({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ie().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)(P,{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)(ft,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function mt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ht(e,t){return e===`personal`?t??null:null}function gt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...tt]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function _t({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,ee]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[v,y]=(0,Q.useState)(ct(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(ct(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(ct(t?.lifetimeTokenBudget??null)),[T,E]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[D,ne]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[k,j]=(0,Q.useState)(t?.concurrencyScope??`family`),[M,re]=(0,Q.useState)(t?.maxChildren?.toString()??``),[N,ie]=(0,Q.useState)(()=>gt(t)),[F,oe]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[L,se]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[z,ue]=(0,Q.useState)(!1),[B,de]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(le).filter(e=>e!==void 0))]:[]}),[V,me]=(0,Q.useState)(()=>t?.notesTitle??``),[H,he]=(0,Q.useState)(()=>t?.notesSubtitle??``),[U,ge]=(0,Q.useState)(()=>t?.notesBody??``),[W,_e]=(0,Q.useState)(t?.sharePopupEnabled??!0),[K,J]=(0,Q.useState)(null),[Y,xe]=(0,Q.useState)(!1),[Se,Ce]=(0,Q.useState)(null),we=t?.sharePopupImageMime!==void 0,Ee=K??(we&&!Y&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{we||K!==null||Y||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=>J(e)).catch(()=>{})},[]);let[De,Oe]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[ke,Ae]=(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! 🙏`),[X,je]=(0,Q.useState)(t?.keyMode??`personal`),Z=T===`one-time`,Me=e===`edit`,Ne=(0,Q.useMemo)(()=>{if(e===`create`)return o.trim().length>0||p.trim().length>0||d.trim().length>0||g.trim().length>0||v.trim().length>0||b.trim().length>0||S.trim().length>0||D.trim().length>0||M.trim().length>0||V.trim().length>0||H.trim().length>0||U.trim().length>0||N.length>0||L.length>0||B.length>0||K!==null||Y;let n=t;return n===null?!1:o.trim()!==(n.label??``)||g.trim()!==(n.requestsPerMinute?.toString()??``)||v.trim()!==ct(n?.dailyTokenLimit??null)||b.trim()!==ct(n?.monthlyTokenLimit??null)||S.trim()!==ct(n?.lifetimeTokenBudget??null)||T!==(n?.lifetimeTokenBudget==null?`recurring`:`one-time`)||D.trim()!==(n.maxConcurrentRequests?.toString()??``)||k!==(n.concurrencyScope??`family`)||M.trim()!==(n?.maxChildren?.toString()??``)||V.trim()!==(n?.notesTitle??``)||H.trim()!==(n?.notesSubtitle??``)||U.trim()!==(n?.notesBody??``)||N.join(`,`)!==gt(n).join(`,`)||F!==(n?.modelAccessMode??`whitelist`)||L.join(`,`)!==(n.modelList??[]).join(`,`)||B.join(`,`)!==(n?.clientRouterDenylist??[]).join(`,`)||W!==(n.sharePopupEnabled??!0)||K!==null||Y||De.trim()!==(n.sharePopupTitle??`Support via QRIS`)||ke.trim()!==(n.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! 🙏`)},[e,t,o,p,d,g,v,b,S,T,D,k,M,N,F,L,B,V,H,U,W,K,Y,De,ke]);A(Ne);let Pe=Te(),Fe=e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),Ie=()=>{r({label:o.trim(),...mt(X,p,d),scopes:N,modelAccessMode:F,modelList:L,clientRouterDenylist:B,requestsPerMinute:ut(g),maxConcurrentRequests:ut(D),concurrencyScope:X===`share`?k:void 0,maxChildren:X===`share`?ut(M):null,dailyTokenLimit:Z?null:st(v)??null,monthlyTokenLimit:Z?null:st(b)??null,lifetimeTokenBudget:Z?st(S)??null:null,notesTitle:V.trim(),notesSubtitle:H.trim(),notesBody:U.trim(),sharePopupEnabled:W,...K===null?Y?{sharePopupImage:null}:{}:{sharePopupImage:K},sharePopupTitle:De.trim(),sharePopupBody:ke.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:Ie,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)(O,{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":X===e,disabled:n||Me,onClick:()=>je(e),title:Me?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,style:{border:`1px solid var(--inner-border)`,color:X===e?`var(--accent)`:`var(--text-secondary)`,background:X===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Me?`not-allowed`:`pointer`,opacity:Me&&X!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)($e,{size:14,"aria-hidden":`true`}):(0,$.jsx)(et,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:X===`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)(u,{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)(q,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(q,{label:`Key prefix`,value:d,onChange:e=>f(e.target.value),placeholder:`pn-carte- (default)…`,disabled:n||p.trim().length>0})]}),X===`personal`&&(0,$.jsx)(q,{label:`Custom API key value (optional)`,value:p,onChange:e=>ee(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)(u,{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)(q,{label:`Name`,value:o,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)(te,{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)(q,{label:`Title`,value:V,onChange:e=>me(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(q,{label:`Subtitle`,value:H,onChange:e=>he(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(q,{label:`Body`,value:U,onChange:e=>ge(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)(w,{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)(q,{label:`Requests per minute`,type:`number`,min:`0`,value:g,onChange:e=>_(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(q,{label:`Max concurrent requests`,type:`number`,min:`0`,value:D,onChange:e=>ne(e.target.value),placeholder:`Unlimited…`,disabled:n}),X===`share`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`api-key-concurrency-scope`,className:`form-label text-caption font-semibold text-text-primary`,children:`Concurrency scope`}),(0,$.jsx)(ye,{id:`api-key-concurrency-scope`,"aria-label":`Concurrency scope`,value:k,onValueChange:e=>j(e),options:[{value:`family`,label:`Whole share family (all recipients together)`},{value:`per_key`,label:`Per recipient key (each has its own cap)`}],size:`md`})]}):null,X===`share`?(0,$.jsx)(q,{label:`Recipient slots (max children)`,type:`number`,min:`0`,value:M,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n}):null]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:D===``?`No concurrency limit, so the tenant allowance does nothing.`:X===`share`?k===`family`?`Limit ${D} concurrent across the whole share family — all recipients share this one cap.`:`Limit ${D} concurrent per recipient key — each key gets its own independent cap.`:`Limit ${D} concurrent for this key. 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)(w,{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:Z?`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:()=>E(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`transparent`:`var(--accent-soft)`,color:Z?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Ke,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`var(--accent-soft)`:`transparent`,color:Z?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(We,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),Z?(0,$.jsx)(dt,{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)(dt,{label:`Daily token limit`,value:v,onChange:y,disabled:n}),(0,$.jsx)(dt,{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)(Ye,{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)(G,{checked:W,onChange:e=>_e(e),disabled:n,label:`Enable popup`})]}),W?(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:[Ee?(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:Ee,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)(ve,{id:`share-popup-image`,accept:nt.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(Ce(null),t.size>2097152){J(null),Ce(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{J(String(n.result)),xe(!1)},n.onerror=()=>Ce(`Could not read that file.`),n.readAsDataURL(t)}}),Ee?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{J(null),xe(!0),Ce(null)},children:`Remove image`}):null,Se?(0,$.jsx)(`p`,{className:`form-error`,children:Se}):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)(q,{label:`Popup title`,value:De,onChange:e=>Oe(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:ke,onChange:e=>Ae(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)(ae,{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:[N.length,`/`,tt.length,` grants`,(0,$.jsx)(pe,{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)(I,{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)(l,{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":F===e,disabled:n,onClick:()=>oe(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 ${F===e?`var(--accent)`:`var(--inner-border)`}`,background:F===e?`var(--accent-soft)`:`var(--surface-2)`,color:F===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(I,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ze,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:F===`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:L.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:F===`whitelist`?`All models allowed`:`No models blocked`}):L.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:()=>se(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>ue(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(be,{open:z,onClose:()=>ue(!1),selected:L,onToggle:e=>se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:F===`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)(P,{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`}),tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(P,{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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(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:ce.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:B.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)(s,{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)(G,{checked:B.includes(e.id),onChange:t=>de(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)(pt,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:N.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==N.includes(`routing:cli_mapping`)&&Fe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...N,`routing:cli_mapping`])]:N.filter(e=>e!==`routing:cli_mapping`);Pe.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>h.error(R(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)(fe,{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:tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=it[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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function vt({secret:e,onClose:t}){return(0,$.jsx)(j,{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)(k,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(f,{size:13}),onClick:()=>{e!==null&&(ge(`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`),h.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}var yt=e=>(e??0).toLocaleString(),bt=e=>e?new Date(e).toLocaleString():`—`;function xt({keyId:e}){let t=Z(),[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)(m,{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=>h.error(R(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(k,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function St({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`:yt(t)})]})}function Ct(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 wt({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?`${W(e)} · Unlimited`:`${W(e)} / ${W(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?`${W(e)} tokens consumed, no lifetime budget set`:`${W(e)} of ${W(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 Tt=25,Et=25,Dt=500;function Ot({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:W(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=ze(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:[W(e),` / `,W(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`:`${W(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":`${W(e)} of ${W(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 kt({parentId:e,childId:t}){let n=X(e,t);if(n.isPending)return(0,$.jsx)(E,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(T,{compact:!0,message:R(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:yt(e.todayRequests)}),(0,$.jsx)(`td`,{children:yt(e.todayErrors)}),(0,$.jsx)(`td`,{children:W(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:W(e.totalTokens)}),(0,$.jsx)(`td`,{children:bt(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function At({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,c]=(0,Q.useState)(`active`),[l,u]=(0,Q.useState)(Tt),[d,f]=(0,Q.useState)(`createdAt`),[p,ee]=(0,Q.useState)(`desc`),[g,_]=(0,Q.useState)(null),y=Ce(),b=xe(),x=Oe(),S=Ne(),C=we(e.id),w=e.keyMode!==`share`,O=ke(w?null:e.id,{limit:l,offset:0,sortBy:d,order:p,status:i}),te=O.data,A=te?.rows??[],j=te?.active??0,M=A,re=()=>{r(null),u(Tt)},N=e=>{d===e?ee(e=>e===`asc`?`desc`:`asc`):(f(e),ee(`asc`)),re()},P=e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<40&&!O.isFetching&&A.length>=l&&l<Dt&&u(e=>Math.min(e+Et,Dt))},F=({column:e,children:t})=>{let n=d===e;return(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>N(e),className:`inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-inherit text-inherit hover:text-text-primary`,"aria-label":`Sort by ${String(e)}`,children:[t,n?p===`asc`?(0,$.jsx)(o,{size:12,"aria-hidden":`true`}):(0,$.jsx)(a,{size:12,"aria-hidden":`true`}):(0,$.jsx)(Ue,{size:12,"aria-hidden":`true`,className:`text-text-tertiary`})]})})};(0,Q.useEffect)(()=>{r(null)},[e.id]);let I=async t=>{try{let n=await S.mutateAsync({parentKeyId:e.id,scope:t});u(Tt),h.success(`Revoked ${n.deleted.toLocaleString()} recipient${n.deleted===1?``:`s`}.`)}catch(e){h.error(R(e,`Could not revoke recipients.`))}},ae=y.isPending||b.isPending,[oe,L]=(0,Q.useState)(!1),se=async()=>{if(w){let n=await b.mutateAsync({keyId:e.id});t?.(n.secret);return}await y.mutateAsync({keyId:e.id,regenerate:!0}),h.success(`Link regenerated; the previous URL no longer works.`)},ce=()=>{y.mutate({keyId:e.id},{onError:e=>h.error(R(e,`Could not create link.`))})},le=C.data?.url??null,z=Ct(w);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:C.isPending?(0,$.jsx)(E,{label:`Loading link…`,compact:!0}):C.isError?(0,$.jsx)(T,{compact:!0,message:R(C.error,`Could not load the link.`),onRetry:()=>void C.refetch()}):le?(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)(ne,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:le,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:le}),(0,$.jsx)(k,{value:le,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),loading:ae,disabled:ae,onClick:()=>L(!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)(ne,{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)(m,{variant:`primary`,size:`sm`,loading:ae,disabled:ae,onClick:ce,children:`Create link`})]})}),w?(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)(xt,{keyId:e.id})]}):null,w?(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:W(e.tokensConsumed)})]}),(0,$.jsx)(St,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(St,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(St,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(wt,{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)(Ot,{consumed:te?.consumed??0,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: `,j.toLocaleString()]}),(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:()=>{re(),c(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))}),g===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:g===`all`?`Revoke all active recipients?`:`Revoke all active recipients that never spent a token?`}),(0,$.jsx)(m,{variant:`danger`,size:`sm`,loading:S.isPending,onClick:()=>{let e=g===`all`?`active`:`unused`;_(null),I(e)},children:`Confirm`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>_(null),children:`Cancel`})]}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke every active recipient (${j.toLocaleString()})`,onClick:()=>_(`unused`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke all active recipients (${j.toLocaleString()})`,onClick:()=>_(`all`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke all`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>void O.refetch(),icon:(0,$.jsx)(ie,{size:13,className:O.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),O.isPending&&!O.data?(0,$.jsx)(E,{label:`Loading recipients…`,compact:!0}):O.isError?(0,$.jsx)(T,{compact:!0,message:R(O.error,`Could not load recipients.`),onRetry:()=>void O.refetch()}):M.length===0?(0,$.jsx)(D,{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,$.jsxs)(`div`,{className:`data-table-container max-h-[46vh]`,onScroll:P,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)(F,{column:`label`,children:`Key`}),(0,$.jsx)(F,{column:`revokedAt`,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)(F,{column:`createdAt`,children:`Created`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:M.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)(pe,{size:14}):(0,$.jsx)(v,{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:W(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:W(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:bt(t.lastUsedAt)}),(0,$.jsx)(`td`,{children:bt(t.createdAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`danger`,size:`sm`,disabled:x.isPending||!!t.revokedAt,onClick:()=>x.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>h.error(R(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:8,className:`p-0`,children:(0,$.jsx)(kt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]}),O.isFetching&&A.length>0?(0,$.jsx)(`div`,{className:`border-t border-inner-border py-2 text-center text-badge text-text-tertiary`,children:`Loading more…`}):null,A.length>0&&A.length>=l&&l<Dt?(0,$.jsx)(`div`,{className:`py-2 text-center text-badge text-text-tertiary`,children:`Scroll for more`}):null]})]})]}),(0,$.jsx)(de,{open:oe,onClose:()=>L(!1),onConfirm:se,title:z.title,message:z.message,confirmLabel:z.confirmLabel,danger:!0})]})}function jt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(j,{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)(At,{parent:e,onSecretRevealed:n})})}function Mt(e){if(!e.bannedUntil)return`Permanent — lift manually`;let t=new Date(e.bannedUntil).getTime();if(!Number.isFinite(t))return`—`;let n=t-Date.now(),r=new Date(e.bannedUntil).toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function Nt({onClose:e}){let t=je(),n=Ee(),[r,i]=(0,Q.useState)(null),a=Date.now(),o=(t.data??[]).filter(e=>e.bannedAt?!e.bannedUntil||new Date(e.bannedUntil).getTime()>a:!1);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(j,{open:!0,onClose:e,title:`Banned Users`,description:`API keys that have been banned. A timed ban lapses on its own; lifting one early is the escape hatch for a mistake.`,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 (`,o.length,`)`]}),t.isPending&&!t.data?(0,$.jsx)(E,{label:`Loading active bans…`}):t.isError&&!t.data?(0,$.jsx)(T,{message:R(t.error,`Could not load active bans.`),onRetry:()=>void t.refetch()}):o.length===0?(0,$.jsx)(D,{compact:!0,title:`No banned keys`,message:`No API key is currently banned.`,icon:(0,$.jsx)(Xe,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Re,{maxHeight:480,scrollRegion:!0,headers:[`API key`,`Reason`,`Lapses`,``],children:o.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.label||e.id.slice(0,8)}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.banReason??`—`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:Mt(e)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.id))})})]}),(0,$.jsx)(Y,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(de,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{if(r)try{await n.mutateAsync({keyId:r.id}),h.success(`Unbanned ${r.label||r.id.slice(0,8)}.`),i(null)}catch(e){h.error(R(e,`Could not unban key.`))}},title:`Lift this ban?`,message:`Lift the ban on ${r?.label||`this key`}? The caller can reach the gateway again immediately.`,confirmLabel:`Unban`,danger:!0})]})}function Pt(){let e=Me(),t=De(),n=Te(),r=Se(),i=Ee(),a=xe(),o=Z(),s=Ae(),{copy:c}=U(),l=Ve(),u=Be(),f=l.data?.invokeDisabled===!0,[p,ee]=(0,Q.useState)(!1),[g,v]=(0,Q.useState)(!1),[y,x]=(0,Q.useState)(null),[S,w]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),[ie,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[ae,L]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(null),[le,z]=(0,Q.useState)(null),ue=e.data??[],B=e=>{I(null),L(e)},fe=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?h.success(`API key copied`):h.error(`Clipboard unavailable on this origin`)}catch(e){h.error(R(e,`Could not reveal API key.`))}},pe=Ct(!0),V=e=>{u.mutate({invokeDisabled:!e},{onSuccess:()=>h.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every API key is now refused (503).`),onError:e=>h.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(O,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(m,{variant:f?`primary`:`secondary`,size:`sm`,loading:l.isLoading||u.isPending,onClick:()=>ee(!0),icon:(0,$.jsx)(N,{size:13}),children:f?`Enable Invoke`:`Disable Invoke`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Xe,{size:13}),children:`Banned Users`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,onClick:()=>{I(null),v(!0)},icon:(0,$.jsx)(re,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(me,{children:e.isPending&&!e.data?(0,$.jsx)(E,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(T,{message:R(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ue.length===0?(0,$.jsx)(D,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(O,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:ue,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>h.error(R(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)(K,{tone:e.revokedAt||e.bannedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.bannedAt?`banned`:e.enabled?`enabled`:`disabled`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(K,{tone:`err`,title:e.banReason??`Banned`,children:(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 cursor-pointer bg-transparent border-0 p-0 text-inherit`,onClick:()=>A(e),children:[(0,$.jsx)(C,{size:11,"aria-hidden":`true`}),`See reason`]})}):null,(0,$.jsx)(K,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(K,{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`}),W(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`}),_e(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`}),_e(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`}),_e(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`}),_e(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`}),_e(e.maxConcurrentRequests),e.keyMode===`share`?(0,$.jsx)(`span`,{className:`font-semibold text-text-tertiary`,title:e.concurrencyScope===`per_key`?`Each recipient key has its own concurrency cap and counter.`:`All recipients share one concurrency cap and counter.`,children:e.concurrencyScope===`per_key`?`· per key`:`· family`}):null]}),(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)(G,{checked:e.enabled,disabled:n.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>n.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>h.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>h.error(R(e,`Could not update credential state.`))})}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(M,{size:13}),onClick:()=>{I(null),x(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(d,{size:13}),onClick:()=>void fe(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ye,{size:13}),onClick:()=>B(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),onClick:()=>{I(null),P(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(m,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(oe,{size:13}),onClick:()=>w(e),disabled:r.isPending,children:`Revoke`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(_,{size:13}),onClick:()=>{i.mutate({keyId:e.id},{onSuccess:()=>h.success(`Unbanned ${e.label||e.id}.`),onError:e=>h.error(R(e,`Could not unban key.`))})},disabled:i.isPending,children:`Unban`}):null]})]})})})}),(0,$.jsx)(j,{open:g,onClose:()=>v(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:se,children:(0,$.jsx)(_t,{mode:`create`,record:null,busy:t.isPending,onClose:()=>v(!1),actionsRef:ce,onDone:e=>{t.mutate(e,{onSuccess:t=>{v(!1),I(ht(e.keyMode,t.secret)),h.success(`API key created`)},onError:e=>h.error(R(e,`Could not create API key.`))})}})}),(0,$.jsx)(j,{open:y!==null,onClose:()=>x(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:le,children:(0,$.jsx)(_t,{mode:`edit`,record:y,busy:n.isPending,onClose:()=>x(null),actionsRef:z,onDone:e=>{y&&n.mutate({keyId:y.id,request:e},{onSuccess:t=>{x(null),I(ht(e.keyMode,t.secret)),h.success(`API key updated`)},onError:e=>h.error(R(e,`Could not update API key.`))})}})}),ae?(0,$.jsx)(jt,{parent:ae,onClose:()=>L(null),onSecretRevealed:e=>{L(null),I(e)}}):null,(0,$.jsx)(de,{open:ie!==null,onClose:()=>P(null),onConfirm:async()=>{if(!ie)return;let e=await a.mutateAsync({keyId:ie.id});I(e.secret),h.success(`Rotated ${ie.label||ie.id}.`),P(null)},title:pe.title,message:pe.message,confirmLabel:pe.confirmLabel,danger:!0}),(0,$.jsx)(de,{open:S!==null,onClose:()=>w(null),onConfirm:async()=>{S&&(await r.mutateAsync(S.id),h.success(`Revoked ${S.label||S.id}.`),w(null))},title:`Revoke API key?`,message:S?`Revoke ${S.label||S.id}? Clients using it will be rejected.${S.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),(0,$.jsx)(de,{open:p,onClose:()=>ee(!1),onConfirm:async()=>{V(f)},title:f?`Enable Invoke?`:`Disable Invoke?`,message:f?`Allow this tenant's API keys to invoke /v1/* routes again. Traffic resumes immediately.`:`Disable invocation for every API key in this tenant? All /v1/* requests will be refused with 503, and nothing upstream is dialed. No keys, accounts, or models are deleted — the dashboard stays reachable so you can re-enable.`,confirmLabel:f?`Enable Invoke`:`Disable Invoke`,danger:!f}),(0,$.jsx)(vt,{secret:F,onClose:()=>I(null)}),te?(0,$.jsx)(Nt,{onClose:()=>ne(!1)}):null,(0,$.jsx)(j,{open:k!==null,onClose:()=>A(null),title:`Ban reason`,size:`sm`,footer:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>A(null),children:`Close`}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[k?.label||`API key`,` was banned.`]}),(0,$.jsx)(`div`,{className:`rounded-control border border-warning-line bg-surface-2 px-4 py-5 text-caption text-text-primary`,children:k?.banReason??`No reason recorded.`})]})})]})}var Ft=[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}],It={lite:`Lite`,full:`Full`,ultra:`Ultra`};function Lt({id:e,label:t,description:n,icon:r,enabled:i,strength:a,strengthSelectId:o,onToggle:s,onStrength:c}){return(0,$.jsx)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,$.jsx)(`label`,{htmlFor:e,children:(0,$.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[r,t]})}),(0,$.jsx)(K,{tone:i?`ok`:`default`,dot:!0,children:i?`Active · ${It[a]??a}`:`Off`})]}),(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:n})]}),(0,$.jsxs)(Y,{gap:`8px`,className:`shrink-0 items-center`,children:[(0,$.jsx)(ye,{id:o,"aria-label":`${t} strength`,value:a,onValueChange:c,options:Ft}),(0,$.jsx)(G,{id:e,"aria-label":`Enable ${t}`,checked:i,onChange:s})]})]})})}function Rt(){let e=Ve(),t=Be(),n=e.data;if(e.isPending)return(0,$.jsx)(E,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(T,{message:R(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(c,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`14px`,children:[r||a?(0,$.jsx)(He,{tone:`warning`,surface:`raised`,live:`status`,children:(0,$.jsxs)(`span`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(_,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(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,(0,$.jsx)(Lt,{id:`compression-rtk`,label:`Prune tool output (RTK)`,description:`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.`,icon:(0,$.jsx)(Je,{size:16,className:`shrink-0 text-text-secondary`}),enabled:r,strength:n.rtkPruneLevel,strengthSelectId:`compression-rtk-level`,onToggle:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>h.error(R(e,`Could not update RTK prune.`))}),onStrength:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update RTK strength.`))})}),(0,$.jsx)(Lt,{id:`compression-ponytail`,label:`PonyTail (system directive)`,description:`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.`,icon:(0,$.jsx)(i,{size:16,className:`shrink-0 text-text-secondary`}),enabled:a,strength:n.ponyTailLevel,strengthSelectId:`compression-ponytail-level`,onToggle:e=>t.mutate({ponyTailEnabled:e},{onError:e=>h.error(R(e,`Could not update PonyTail.`))}),onStrength:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update PonyTail strength.`))})})]})})]})}function zt(){return L({queryKey:ue.remoteSupport.status,queryFn:()=>z(`/remote-support/status`)})}function Bt(){let e=se();return B({mutationFn:e=>z(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}function Vt(){let e=se();return B({mutationFn:e=>z(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}var Ht={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ut={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function Wt({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 Gt({tool:e}){let t=zt(),n=Bt(),r=Vt(),{copied:i,copy:a}=U(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[f,g]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&g(o)},[o,n.isPending,r.isPending]);let _=async t=>{g(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),h.error(i.message),g(!t);return}u(null),h.success(t?`${Ht[e]} started`:`${Ht[e]} stopped`)}catch{h.error(`Could not ${t?`start`:`stop`} ${Ht[e]}`),g(!t)}},v=async()=>{if(c!==null){if(await a(c)){h.success(`Remote URL copied`,c);return}h.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)(Wt,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Ht[e]})]}),(0,$.jsx)(G,{checked:f,disabled:s,onChange:e=>void _(e),"aria-label":`Toggle ${Ht[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)(p,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>void _(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ut[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)(m,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(ee,{size:14}):(0,$.jsx)(d,{size:14}),i?`Copied`:`Copy`]})]})]})}function Kt(){let{copied:e,copy:t}=U(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){h.success(`Gateway endpoint copied`,n);return}h.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(g,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{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)(m,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(ee,{size:13}):(0,$.jsx)(d,{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 coding agent — OpenCode, Pi, OMP, Kilo, Cline, Droid, and more — at this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`For Claude Code, leave off `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` — its CLI appends it automatically.`]})]})]})})]})}function qt(){let e=zt();return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Ge,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Gt,{tool:`cloudflared`}),(0,$.jsx)(Gt,{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:[`No matter which tunnel you pick, the gateway sees the tunnel's address as the client. Add the forwarding edge to`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` so remote callers aren't recorded as loopback.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Cartethyia doesn't install cloudflared or Tailscale for you — set up either one yourself. Tunnels run detached from the gateway, so they keep working across restarts.`})]})})]})}function Jt(){return(0,$.jsxs)(J,{gap:`16px`,children:[(0,$.jsx)(Kt,{}),(0,$.jsx)(qt,{}),(0,$.jsx)(Rt,{}),(0,$.jsx)(y,{}),(0,$.jsx)(Pt,{})]})}export{Jt as default};
|
|
Binary file
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{D as u,E as d,S as f,T as p,a as m,c as h,g,k as _,l as v,m as y,w as b,y as x}from"./numbers-CoqpaDMx.js";import{t as S}from"./circle-alert-CntYHV5v.js";import{t as C}from"./circle-check-BU3v_mFW.js";import{t as w}from"./circle-question-mark-Cz4un8sH.js";import{l as T,m as E}from"./formatters-u7JPB5BX.js";import{t as D}from"./eye-off-Bk5g2luF.js";import{t as O}from"./eye-C_hawfH4.js";import{t as k}from"./gauge-BbIMy7MB.js";import{t as A}from"./image-BPaouViG.js";import{n as j,r as M,t as N}from"./state-DHmEnLa2.js";import{t as ee}from"./key-round-UkavsGxp.js";import{t as te}from"./layers-2-glBbjl.js";import{r as P}from"./use-modal-focus-By7oJoGd.js";import{r as F,t as I}from"./dialog-BK-NRr5u.js";import{t as ne}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 L}from"./search-JOKus9rb.js";import{t as se}from"./trash-Cppn5c3R.js";import{t as ce}from"./wrench-B6E1oEuY.js";import{C as le,T as ue,v as de}from"./assert-CidQVoNo.js";import{i as fe,l as pe,o as me,t as R}from"./query-keys-YSoQOUh6.js";import{A as he,C as ge,E as _e,O as ve,S as ye,T as be,V as xe,_ as Se,d as Ce,dt as we,f as Te,g as Ee,h as De,i as Oe,it as ke,j as Ae,k as je,l as Me,m as Ne,n as z,nt as Pe,o as Fe,p as Ie,pt as Le,rt as Re,s as ze,u as Be,v as Ve,w as He,x as Ue}from"./entry-D6WvojeD.js";import{n as B,r as We,t as V}from"./card-CxDw0lK6.js";import{n as H}from"./download-dRFo5_Wu.js";import{f as Ge,i as Ke,l as U,n as qe,r as Je,s as Ye,u as W}from"./tokens-COzario9.js";import{t as Xe}from"./switch-DmZcyTIC.js";import{t as G}from"./badge-BaX2GTrn.js";import{n as K}from"./input-BlmlizVV.js";import{t as q}from"./select-BHqpd-bg.js";import{t as Ze}from"./ProviderIcon-jjqXJDA3.js";import{t as J}from"./stack-j7cXjgYX.js";import{n as Y,t as Qe}from"./inline-CHJQwxLa.js";import{s as $e,t as et}from"./api-keys-KvX83mRe.js";import{a as tt,l as nt,u as rt}from"./quota-DJ1QlAOq.js";import{t as X}from"./banner-DFH4Bkte.js";import{c as it,l as at,m as ot}from"./routing-fnCsxgNO.js";import{t as st}from"./list-row-Ml16KCfu.js";import{d as ct,l as lt,u as ut,y as dt}from"./network-CuMDaTzT.js";import{a as ft,c as pt,s as mt,t as ht}from"./HealthEventsModal-BEjAjD4F.js";import{r as gt}from"./privacy-mode-GM8bej85.js";import{t as _t}from"./use-timeout-BwcBBRrT.js";var vt=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`}]]),yt=e(`gift`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8`,key:`1sqzm4`}],[`path`,{d:`M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5`,key:`kc0143`}],[`rect`,{x:`3`,y:`7`,width:`18`,height:`4`,rx:`1`,key:`1hberx`}]]),bt=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`}]]),xt=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`}]]),St=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`}]]),Ct=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`}]]),wt=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`}]]),Tt=e(`shuffle`,[[`path`,{d:`m18 14 4 4-4 4`,key:`10pe0f`}],[`path`,{d:`m18 2 4 4-4 4`,key:`pucp1d`}],[`path`,{d:`M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22`,key:`1ailkh`}],[`path`,{d:`M2 6h1.972a4 4 0 0 1 3.6 2.2`,key:`km57vx`}],[`path`,{d:`M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45`,key:`os18l9`}]]),Et=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`}]]),Dt=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`}]]),Ot=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function kt(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function At({to:e,label:t}){let n=Pe();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function jt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(At,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:y(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function Mt(e){return e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function Nt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var Pt={fallback:`Failover`,roundRobin:`Round robin`},Ft=new Set([`inferhub`,`cline`]);function It(e,t){let n=at(e),r=ot(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=Nt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=Nt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=Nt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=Nt(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 Lt=[{value:`least_loaded`,label:`Least loaded`},{value:`round_robin`,label:`Round robin`},{value:`random`,label:`Random`}],Rt=50,zt=100;function Bt(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 Vt({children:e,action:t}){return(0,Q.jsx)(st,{actions:t,children:e})}function Ht({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=It(e,r),a=ct(),o=dt(),[s,c]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),f=Ft.has(e),p=Bt(z,n.codex,n.claude),m=p.some(e=>e.value===i.userAgent)?p:[...p,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(M,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(j,{message:`Failed to load routing`,onRetry:i.refetch});let _=i.roundRobinEnabled?`${Pt.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:Pt.fallback,v=a.data,y=Lt.find(e=>e.value===v?.strategy),b=v===void 0?`…`:i.skipProxy?`Direct — proxy pools bypassed`:y?v.strategy===`round_robin`?`${y.label} · ${v.rotateCount} per rotation`:y.label:`Unset`,x=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Per-account and per-pool routing`,S=i.maxInflight===null,C=S?51:Math.min(51,Math.max(1,i.maxInflight)),w=S?`∞`:String(i.maxInflight),T=i.maxInflightPerProxy===null,E=T?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),D=T?`∞`:String(i.maxInflightPerProxy),O=i.skipProxy,A=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},N=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=m.find(t=>t.value===e)?.label??e;g.success(`Client identity updated`,t)},ee=e=>{e!==v?.strategy&&o.mutate({strategy:e})},P=e=>{v&&o.mutate({rotateCount:Math.min(1e3,Math.max(1,v.rotateCount+e))})},ne=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Routing Strategy`,subtitle:x,icon:(0,Q.jsx)(te,{size:16})}),(0,Q.jsx)(B,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Provider accounts`}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,Q.jsx)(`span`,{className:`status-indicator-dot${i.roundRobinEnabled?` bg-accent`:` bg-text-tertiary`}`,"aria-hidden":`true`}),_]})]}),(0,Q.jsx)(Vt,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(F,{size:14}),onClick:()=>A(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(re,{size:14}),onClick:()=>A(1)})]}):null,(0,Q.jsx)(Xe,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(Ct,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Rotate accounts`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(Vt,{action:(0,Q.jsx)(Xe,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(vt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Proxy pools`}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,Q.jsx)(`span`,{className:`status-indicator-dot${i.skipProxy?` bg-text-tertiary`:` bg-accent`}`,"aria-hidden":`true`}),b]}),(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0 -my-1`,"aria-label":`How pool routing works`,onClick:()=>d(!0),children:`How it works`})]}),(0,Q.jsx)(Vt,{action:(0,Q.jsxs)(Y,{gap:`8px`,align:`center`,children:[v?.strategy===`round_robin`&&!i.skipProxy?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Pools per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Pools/rotation`}),(0,Q.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease pools per rotation`,disabled:o.isPending||v.rotateCount<=1,icon:(0,Q.jsx)(F,{size:14}),onClick:()=>P(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:v.rotateCount}),(0,Q.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase pools per rotation`,disabled:o.isPending||v.rotateCount>=1e3,icon:(0,Q.jsx)(re,{size:14}),onClick:()=>P(1)})]}):null,(0,Q.jsx)(q,{id:`routing-pool-strategy`,"aria-label":`Pool selection mode`,value:v?.strategy??``,disabled:i.skipProxy||o.isPending,options:Lt,onValueChange:ee})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-pool-strategy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(Tt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-text-tertiary`:`text-accent`}`}),`Pool mode`]})}),(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`How proxy pools are chosen when this provider dials one.`,i.skipProxy?` Disabled while “Always direct” is on.`:``]})]})})]}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(q,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:m,onValueChange:N}):(0,Q.jsx)(q,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:ne,options:[{value:ne,label:ne}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(k,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,Rt,` is unlimited.`]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":S?`true`:void 0,min:1,max:51,step:1,value:C,"aria-valuetext":S?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>Rt?null:Math.round(t))},style:{"--slider-pct":`${C/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:w,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflight(Math.min(zt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${S?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${O?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(Dt,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>c(!0),children:`How it works`})]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":T?`true`:void 0,min:1,max:51,step:1,disabled:O,value:E,"aria-valuetext":T?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>Rt?null:Math.round(t))},style:{"--slider-pct":`${E/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:O,value:D,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflightPerProxy(Math.min(zt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${T?`text-status-success`:``}`})]}),(0,Q.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:O?`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 ${Rt} is unlimited.`})]}),(0,Q.jsx)(I,{open:s,onClose:()=>c(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`API key concurrency`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`The key's `,(0,Q.jsx)(`em`,{children:`own`}),` limit (`,` `,(0,Q.jsx)(`code`,{children:`max_concurrent`}),`, set on the key), which counts every request this key sends across all providers. It is separate from the two limits above: raising this provider's max-inflight does not raise the key's ceiling, and a rejection message that says “This API key is already serving its maximum number of concurrent requests” refers to this number, not to any setting here.`]})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),(0,Q.jsx)(I,{open:u,onClose:()=>d(!1),title:`How pool routing works`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`When a provider dials a proxy pool, the gateway picks the pool with one of three modes. All modes skip pools that are cooling down, full, or disabled — the pool's own gates always apply.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Least loaded`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Each request goes to the pool with the most headroom (weighted). The default — spreads load and prefers the fastest-available egress.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Round robin`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Requests rotate across pools in a fixed order, with a set number of successful requests per pool before moving on. Useful for even request counts across pools.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Random`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Each request picks from the eligible pools at random, so a burst does not gang up on the first pools in the order.`})]})]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Turning on “Always direct” bypasses pools entirely — this mode has no effect then.`})]})}),f&&(0,Q.jsxs)(Y,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(bt,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function Ut(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 Wt(e=!0){return le({queryKey:R.inferhub.summary,queryFn:e=>me(`/inferhub/summary`,{signal:de(e)}).then(Ut),enabled:e,...fe,staleTime:6e4})}function Gt(e){return e===null?`—`:`$${e.toFixed(4)}`}function Kt(e){return e===null?`—`:`${e}%`}function qt(e){return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}var Jt={provider:`Provider (A–Z)`,availability:`Highest availability`,sustainable:`Sustainable price`,price:`Lowest price`,discount:`Biggest discount`};function Yt(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 Xt(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||Yt(e=>e.health.successRatePct,`desc`)(e,t);case`sustainable`:return Yt(e=>e.capacityPriceIn,`asc`);case`price`:return Yt(e=>e.minAskIn,`asc`);case`discount`:return Yt(e=>e.tiersIn[0]?.discountPct??null,`desc`)}}function Zt(e){return e===`operational`?`ok`:e===`degraded`?`warn`:e===`major_outage`?`err`:`default`}function Qt(e,t){return e.providers.find(e=>e.prefix===t)}function $t(e){return e.providersLive>0&&e.routable&&e.minAskIn!==null}function en(){let e=Wt(),t=e.data,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(`provider`),u=t?.models??[],d=u.filter($t),f=(0,Z.useMemo)(()=>{let e=[...i?u:d].sort(Xt(c)),t=new Map;for(let n of e){let e=t.get(n.prefix);e===void 0?t.set(n.prefix,[n]):e.push(n)}return[...t.entries()].map(([e,t])=>({prefix:e,family:t[0]?.family??e,models:t}))},[u,d,i,c]),p=(0,Q.jsxs)(h,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,Q.jsx)(ae,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,Q.jsx)(ae,{size:16})}),(0,Q.jsx)(B,{children:e.isError?(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`InferHub market`,icon:(0,Q.jsx)(ae,{size:16}),action:p}),(0,Q.jsx)(B,{children:(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let m=f,g=m.reduce((e,t)=>e+t.models.length,0),_=u.length-g;return(0,Q.jsxs)(V,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-start gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,Q.jsx)(Le,{size:15,"aria-hidden":`true`,className:y(`mt-1 shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,Q.jsxs)(J,{gap:`1px`,children:[(0,Q.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,Q.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,qt(t.meta.ageSeconds)]}):null]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:n?p:null})]}),n?(0,Q.jsxs)(B,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(nn,{onSaved:()=>void e.refetch()}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,Q.jsx)(q,{value:c,onValueChange:e=>l(e),options:Object.keys(Jt).map(e=>({value:e,label:Jt[e]})),"aria-label":`Sort InferHub models`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,Q.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`InferHub did not answer. Showing the last snapshot that was read`,t.meta.fetchedAt>0?` (${qt(t.meta.ageSeconds)})`:``,`.`]}):null,t.meta.stale&&t.error===null?(0,Q.jsxs)(X,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,qt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[g,` of `,u.length,` models`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,_>0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,_,` hidden)`]}):null]})]}),m.length===0?(0,Q.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:m.map(e=>(0,Q.jsx)(tn,{group:e,showUpstreams:o,summary:t},e.prefix))})]}):null]})}function tn({group:e,showUpstreams:t,summary:n}){let[r,i]=(0,Z.useState)(!0),a=Qt(n,e.prefix),o=a?.familyState??null,s=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,Q.jsx)(Le,{size:14,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!r&&`-rotate-90`)}),(0,Q.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,Q.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),o===null?null:(0,Q.jsx)(G,{tone:Zt(o),dot:!0,children:o.replace(/_/g,` `)}),t&&a!==void 0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Kt(a.availability24hPct),` · 7d`,` `,Kt(a.availability7dPct)]}):null,(0,Q.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),r?(0,Q.jsxs)(`div`,{className:`px-3 pb-3`,children:[s===null?null:(0,Q.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:s}),(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,Q.jsx)(`tbody`,{children:e.models.map(e=>(0,Q.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,Q.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,Q.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Gt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,Q.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Gt(e.capacityPriceIn),` sustainable`]}):null]}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Gt(e.minAskOut)}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,Q.jsx)(G,{children:`none`}):e.providersLive}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Kt(t?a?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function nn({onSaved:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await 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,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,Q.jsx)(K,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,Q.jsx)(h,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,Q.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),s===null?null:(0,Q.jsx)(X,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function rn({providerId:e}){let t=It(e,!1),n=mt(),r=it(e),[i,a]=(0,Z.useState)(!1),o=(0,Z.useMemo)(()=>on(n.data?.accounts??[],e),[n.data,e]),s=(0,Z.useRef)(null),c=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(s.current===null){s.current=c;return}s.current!==c&&(s.current=c,n.refetch())},[c,n]);let[l,u]=(0,Z.useState)(`40`),[d,f]=(0,Z.useState)(`percent`),p=t.usageFloor!==null;(0,Z.useEffect)(()=>{t.usageFloor!==null&&u(String(t.usageFloor)),f(t.usageFloorUnit)},[t.usageFloor,t.usageFloorUnit]);let m=Number(l),g=Number.isInteger(m)&&m>=0&&m<=1e6,_=o===null||o.pooled&&o.remaining<=0?`text-status-danger`:o.percent<=10?`text-status-warning`:`text-status-success`,v=(e,n)=>{(e===null||g)&&t.setUsageFloor(e,n)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(k,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`}),(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,icon:(0,Q.jsx)(w,{size:14}),"aria-label":`How the usage floor works`,onClick:()=>a(!0),children:`How it works`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[o!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:o.accounts}),(0,Q.jsx)(`span`,{children:o.accounts===1?`active account`:`active accounts`}),o.inactiveAccounts>0?(0,Q.jsxs)(`span`,{className:`badge border border-warning-line text-status-warning normal-case tracking-normal`,title:`Disabled or cooled accounts hold credits this provider cannot route to. Enable or recover them to add their balance.`,children:[o.inactiveAccounts,` inactive`]}):null]}),(0,Q.jsx)(`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:o.pooled?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`strong`,{className:`font-bold ${_}`,children:sn(o.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,sn(o.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${_}`,children:[o.percent,`%`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`strong`,{className:`font-bold ${_}`,children:[o.percent,`% left`]}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`lowest independent window`})]})}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${sn(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),o===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No quota data is available for these accounts yet. Exhausted quota windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${sn(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value:p?l:``,placeholder:`40`,disabled:!p,"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=>u(e.target.value),onBlur:()=>{p&&v(m,d)}}),(0,Q.jsxs)(`select`,{value:d,disabled:!p,"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`;f(t),p&&v(m,t)},children:[(0,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(Xe,{checked:p,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>v(e?g?m:40:null,d)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(an,{providerId:e}),(0,Q.jsx)(I,{open:i,onClose:()=>a(!1),title:`How the usage floor works`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 text-badge leading-relaxed text-text-secondary`,children:[(0,Q.jsxs)(`p`,{children:[`The usage floor is a `,(0,Q.jsx)(`strong`,{children:`per-account`}),` guard: when an account's remaining allowance drops to or below the threshold, that account is skipped and the request fails over to the next one. It prevents a spent account from being dialed and erroring upstream.`]}),(0,Q.jsxs)(`p`,{children:[(0,Q.jsx)(`strong`,{children:`Credit mode`}),` sums absolute remaining credits across pooled windows. `,(0,Q.jsx)(`strong`,{children:`Percent mode`}),` uses the aggregate credit percentage and the lowest independent percentage window. An account with `,(0,Q.jsx)(`em`,{children:`unknown`}),` quota is never treated as below the floor.`]}),(0,Q.jsxs)(`p`,{children:[(0,Q.jsx)(`strong`,{children:`Free-tier models ignore the operator's floor threshold.`}),` `,`Their upstream service is not credit-funded, so the configurable floor does not gate them — an account below the threshold can still serve a free-tier model. Exhausted quota windows still exclude the account: if the provider's own free limit is spent (`,(0,Q.jsx)(`code`,{children:`0 left`}),`), it is skipped for free-tier models too.`]}),(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:`Turning the floor off disables the threshold for all models; exhausted quota windows are still skipped.`})]})})]})}function an({providerId:e}){let{enabled:t,setEnabled:n}=gt(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(D,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(Xe,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function on(e,t){let n=0,r=0,i=0,a=0,o=!1,s=!1,c=null;for(let l of e)if(l.provider===t){if(!l.active){a+=1;continue}if(i+=1,l.quota!==null)for(let e of l.quota.windows){if(e.accounting===`pooled`){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;if(i===null)continue;n+=Math.min(t,Math.max(0,i)),r+=t,o=!0;continue}if(s=!0,typeof e.remainingPercent==`number`&&Number.isFinite(e.remainingPercent)){let t=Math.min(100,Math.max(0,e.remainingPercent));c=c===null?t:Math.min(c,t)}}}return i===0?null:o?{accounts:i,inactiveAccounts:a,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0,pooled:!0}:s&&c!==null?{accounts:i,inactiveAccounts:a,remaining:0,total:0,percent:Math.round(c),pooled:!1}:null}function sn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function cn({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(V,{density:`compact`,children:(0,Q.jsx)(B,{children:(0,Q.jsxs)(Y,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:v({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(we,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function ln({provider:e}){let t=he(),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.baseUrl??``);(0,Z.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,Q.jsx)(b,{size:16})}),(0,Q.jsx)(B,{children:(0,Q.jsxs)(J,{gap:`12px`,children:[n?(0,Q.jsx)(K,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,Q.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(wt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(P,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ne,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ee,{size:13}),onClick:()=>{let e=document.getElementById(`provider-accounts`);e?.scrollIntoView({behavior:`smooth`,block:`start`}),e?.focus({preventScroll:!0})},children:`Manage API keys`}):null]})]})})]})}async function un(e,t,n){let r=Array(e.length),i=Math.max(1,Math.min(t,e.length)),a=0;return await Promise.all(Array.from({length:i},async()=>{for(;;){let t=a;if(t>=e.length)return;a+=1;try{r[t]={status:`fulfilled`,value:await n(e[t],t)}}catch(e){r[t]={status:`rejected`,reason:e}}}})),r}function dn(e){let t=Object.entries(e.modelCooldowns??{}).filter(([,e])=>Number.isFinite(new Date(e).getTime())&&new Date(e).getTime()>Date.now()),n;for(let e of t)(n===void 0||new Date(e[1]).getTime()<new Date(n[1]).getTime())&&(n=e);return n===void 0?void 0:{count:t.length,modelId:n[0],until:n[1]}}function fn(e){let t=Object.values(e.modelCooldowns??{}).map(e=>new Date(e).getTime()).filter(e=>Number.isFinite(e));return t.length===0?null:Math.max(...t)}function pn({accountId:e,accountName:t}){let n=ft(e),r=pt(e),i=n.isPending||r.isPending;return(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,title:`Manually claim available ZCode gift plans`,"aria-label":`Claim gifts for ${t}`,disabled:i,icon:i?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):(0,Q.jsx)(yt,{size:12}),onClick:()=>n.mutate(void 0,{onSuccess:e=>{let t=[e.claimed.length>0?`Claimed: ${e.claimed.join(`, `)}`:null,e.detail].filter(Boolean).join(` · `);switch(e.state){case`claimed`:g.success(`Gift plans claimed`,t);break;case`already_claimed`:g.success(`Gift plans already claimed`,t);break;case`nothing`:g.success(`No gift plans to claim`,t);break;case`captcha`:g.warning(`CAPTCHA required — open the ZCode app`,t);break;case`partial`:g.warning(`Gift claim only partially completed`,t);break;case`error`:g.error(`Gift claim failed`,t)}e.claimed.length>0&&r.mutate(void 0,{onSuccess:e=>{e.ok||g.warning(`Gifts claimed; quota refresh failed`,e.message)},onError:e=>g.warning(`Gifts claimed; quota refresh failed`,pe(e,`Refresh quota manually`))})},onError:e=>g.error(`Gift claim failed`,pe(e,`Unable to claim gift plans`))}),children:i?`Claiming…`:`Claim gifts`})}var mn={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,policy_blocked_banned:`Account banned`,policy_blocked_invalid_request:`Request refused`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`,validation_required:`Verification required`,model_unreachable:`Model unavailable`},hn=new Set([`quota_fetch_failed`]);function gn(e){return e===void 0||e.length===0?!1:!hn.has(e)}function _n(e){return e===`oauth`?`Re-login required`:`Replace API key`}function vn(e,t,n){return e===`auth_invalidated`?_n(t):e===`policy_blocked_banned`&&n===`github`?`No Copilot access`:mn[e]??e}var yn=/https?:\/\/[^\s"'\\]+/;function bn(e){if(e)return yn.exec(e)?.[0]}function xn({cooldowns:e,reason:t}){if(!e)return null;let n=tt(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(G,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function Sn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function Cn(e){if(!gn(e.lastErrorCategory)||e.lastErrorCategory===`quota_exhausted`&&dn(e))return null;let t=vn(e.lastErrorCategory,e.credentialKind,e.providerId),n=e.lastError??e.lastErrorCategory;if(e.lastErrorCategory===`policy_blocked_banned`&&e.providerId===`github`)return(0,Q.jsx)(G,{tone:`err`,dot:!0,title:n,children:t});if(e.lastErrorCategory===`validation_required`){let r=bn(e.lastError);if(r!==void 0)return(0,Q.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,title:n,children:(0,Q.jsxs)(G,{tone:`warn`,children:[t,(0,Q.jsx)(we,{size:12,className:`shrink-0`,"aria-hidden":`true`})]})})}return(0,Q.jsx)(G,{tone:`warn`,title:n,children:t})}function wn(e){return e.credentialKind===`oauth`?`blue`:`ok`}function Tn({account:e}){let t=e.providerCooldowns;if(!t||t.length===0)return null;let n=Date.now(),r=t.filter(e=>new Date(e.until).getTime()>n);if(r.length===0)return null;let i=r.some(e=>e.blocked),a=r.reduce((e,t)=>{let n=new Date(t.until).getTime();return n<e?n:e},1/0),o=r.map(e=>`${e.providerId}: ${e.reason}${e.blocked?` (blocked)`:``}`).join(` · `);return(0,Q.jsx)(G,{tone:`warn`,title:`${o} — resets ${tt(new Date(a).toISOString())}`,children:i?`Egress blocked`:`Rate-limited`})}function En({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=dn(e);if(e.status===`disabled`){let t=Sn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(G,{tone:`warn`,title:e.lastError,children:_n(e.credentialKind)}):Cn(e),(0,Q.jsx)(xn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:wn(e),dot:!0,children:[`Active`,Sn(e)?` - ${Sn(e)}`:``]}),(0,Q.jsx)(Tn,{account:e}),Cn(e),(0,Q.jsx)(xn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(G,{tone:`warn`,dot:!0,children:[`Cooldown`,Sn(e)?` - ${Sn(e)}`:``,` `,e.cooldownUntil?`(${tt(e.cooldownUntil)})`:``]}),(0,Q.jsx)(Tn,{account:e}),Cn(e),(0,Q.jsx)(xn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(G,{tone:`disabled`,children:`Disabled`})}function Dn(e){switch(e){case`google`:case`github`:return{label:`Social`,tone:`accent`};case`builder-id`:case`idc`:return{label:`OIDC`,tone:`default`};case`external_idp`:return{label:`Enterprise IdP`,tone:`default`};case`api_key`:return{label:`API key`,tone:`default`};case`imported`:return{label:`Imported`,tone:`default`};default:return null}}function On(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()}`:tt(e,!1)}function kn({windows:e}){let t=nt(e??[]),n=e?.filter(e=>rt(e)!==`current`)??[];return(0,Q.jsxs)(Q.Fragment,{children:[t.text!==null&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":t.low?`warn`:void 0,title:t.hasCredits?`${An(t.remaining)} credits available`:`Current model grants and account-wide quota limits`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),t.text]}),n.map((e,t)=>(0,Q.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[e.label,e.modelIds?.length?` · ${e.modelIds.join(`, `)}`:``,` · `,rt(e)===`expired`?`Expired`:`Not started yet · Starts ${new Date(e.startsAt).toLocaleString()}`]},`${e.kind??e.label}:${e.startsAt}:${t}`))]})}function An(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function jn({providerId:e,account:t,onClose:n}){let r=Ae(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{g.error(`Clipboard access denied`)}};return(0,Q.jsx)(I,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(h,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{g.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;g.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(Y,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Mn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=Ae(),l=Ue(),u=pt(t.id),d=ut(),m=t.kind===`pool`,_=t.networkPoolId,v=lt(m?_:void 0),y=t.status===`disabled`,b=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,x=Number.isFinite(b)&&b>Date.now(),S=t.status===`cooldown`||x,[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[,k]=(0,Z.useState)(0),[A,te]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)(``),re=gt(e),ae=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),L=re.enabled?`Mysterious accounts`:ae,ce=On(t.tokenExpiresAt),le=fn(t),ue=Math.max(x&&t.cooldownUntil?b:0,le??0);(0,Z.useEffect)(()=>{if(ue<=Date.now())return;let e=setInterval(()=>k(e=>e+1),1e3);return()=>clearInterval(e)},[ue]);let de=()=>{let n=P.trim();te(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>g.success(`Account renamed`,n),onError:e=>g.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:y?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${L}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:A?(0,Q.jsx)(K,{value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&te(!1)},onBlur:de,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:L}),m?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 border border-inner-border rounded-tiny bg-surface-1 text-micro font-bold uppercase tracking-label text-text-secondary`,title:`Proxy pool routing as an account for this ip-scoped provider`,children:`Pool`}):null,(()=>{let e=Dn(t.authMethod);return e===null?null:(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 border rounded-tiny text-micro font-bold uppercase tracking-label ${e.tone===`accent`?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`}`,title:`Signed in via ${e.label}`,children:e.label})})(),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${L}`,onClick:()=>{F(t.label??``),te(!0)},children:(0,Q.jsx)(ne,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(En,{account:t}),ce?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:ce,children:ce}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(kn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[e===`zcode-start`&&!m&&(0,Q.jsx)(pn,{accountId:t.id,accountName:L}),m?(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${L}`,onClick:()=>E(!0),title:`View pool health & error history`}):(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${L}`,onClick:()=>w(!0),title:`View Health & Error History`}),m?(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:d.isPending?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):(0,Q.jsx)(p,{size:12}),label:d.isPending?`Testing…`:`Test`,"aria-label":`Test ${L}`,disabled:d.isPending||_===void 0,onClick:()=>{_&&d.mutate({poolId:_,providerId:e},{onSuccess:e=>{e.status===`allowed`?g.success(`Pool probe passed`,L):e.status===`blocked`?g.error(`Pool blocked`,e.reason??`Upstream refused this egress`):e.status===`throttled`?g.error(`Pool rate-limited`,e.reason??`Address accepted; rate limit spent`):g.error(`Pool unreachable`,e.reason??`Probe could not complete`)},onError:e=>g.error(`Pool probe failed`,e.message??`Probe failed`)})},title:`Probe this pool against the provider`}):(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):(0,Q.jsx)(p,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${L}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?g.success(`Account test passed`,L):g.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>g.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),m?null:(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(ee,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${L}`,onClick:()=>O(!0),title:`Replace API key`}),m?null:(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:y?(0,Q.jsx)(xt,{size:12}):(0,Q.jsx)(ie,{size:12}),label:y?`Enable`:`Disable`,"aria-label":y?`Enable ${L}`:`Disable ${L}`,disabled:c.isPending,onClick:()=>{let n=y;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>g.success(n?`Account enabled`:`Account disabled`,L),onError:e=>g.error(`Update failed`,e.message??`Unable to update account`)})},title:y?`Enable account`:`Disable account`}),S?(0,Q.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(oe,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${L}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,m?null:(0,Q.jsx)(h,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),label:`Delete`,"aria-label":`Delete ${L}`,onClick:()=>s(t),title:`Delete account`})]})]}),C&&(0,Q.jsx)(ht,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode,jwtIssuer:t.jwtIssuer},onClose:()=>w(!1)}),D&&(0,Q.jsx)(jn,{providerId:e,account:t,onClose:()=>O(!1)}),T&&(0,Q.jsx)(I,{open:!0,title:`Pool Health & Error History`,onClose:()=>E(!1),width:640,footer:(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>E(!1),children:`Close`}),children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-3 min-h-40`,children:v.isPending?(0,Q.jsx)(M,{label:`Loading pool health events…`}):v.isError?(0,Q.jsx)(j,{message:`Failed to load pool health events`,onRetry:()=>void v.refetch()}):(v.data??[]).length===0?(0,Q.jsx)(N,{compact:!0,title:`No health events recorded`,message:`Status transitions, rate limits, and auto-recoveries will appear here.`}):(0,Q.jsx)(`div`,{className:`scroll-region max-h-160 overflow-y-auto pr-1 flex flex-col gap-3`,children:(v.data??[]).map(e=>(0,Q.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-badge`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`span`,{className:`font-mono tabular-nums text-micro text-text-tertiary`,children:new Date(e.createdAt).toLocaleString()}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-text-tertiary text-micro uppercase tracking-label`,children:[e.fromStatus??`—`,` → `,e.toStatus]}),e.errorCategory?(0,Q.jsx)(`span`,{className:`rounded-pill border border-warning-line bg-surface-2 px-2.5 py-px font-mono text-micro text-status-warning`,children:e.errorCategory}):null]})]}),e.reason?(0,Q.jsx)(`p`,{className:`mt-2 text-micro text-text-secondary [overflow-wrap:anywhere] break-words`,children:e.reason}):null]},e.id))})})})]})}var Nn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Pn=[`refresh`,`refreshToken`,`refresh_token`],Fn=[`credentialKind`,`providerId`,`accessToken`],In=[`accounts`,`items`,`connections`],Ln=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Rn(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function zn(e){for(let t of Nn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Rn(e);if(t)for(let e of Nn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Bn(e){for(let t of Ln){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Rn(e);if(t)for(let e of Ln){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Vn(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,Pn);if(n(e))return!0;let r=Rn(e);return r?n(r):!1}function Hn(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function Un(e){let t=Hn(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 Wn(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 Gn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var Kn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function qn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of Kn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function Jn(e){let t=e.trim(),n=$(Gn(t))??Wn(t);return n&&Vn(n)?`oauth`:Hn((n?zn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Yn(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 Xn(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 Zn(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&Fn.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`&&Vn(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=zn(e),r=Vn(e)?`oauth`:Jn(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Bn(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function Qn(e){for(let t of In){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function $n(e){let t=e.trim();if(!t)return[];let n=Gn(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return Yn(e)?[Xn(t,e)]:e.map(Zn)}else{let e=$(n);if(e){let t=Qn(e);return t?t.map(Zn):[Zn(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=Wn(r[0]);return e?[Zn(e)]:er(r[0])}let i=Wn(t);return i&&(zn(i)||Object.keys(i).length===r.length)?[Zn(i)]:r.flatMap(er)}function er(e){let t=$(Gn(e));if(t){let e=Qn(t);return e?e.map(Zn):[Zn(t)]}return[{value:e,kind:Jn(e)}]}function tr(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 nr(e){let t=[];for(let n of e){let e=n.text.trim();if(!e)continue;let r=Gn(e);if(Array.isArray(r)){let n=r.filter(e=>$(e)!==void 0);if(n.length>0&&Yn(n)){t.push(e);continue}for(let e of r){let n=$(e);t.push(n===void 0?String(e):JSON.stringify(n))}continue}let i=$(r);if(i){let n=Qn(i);if(n!==void 0){for(let e of n)t.push(JSON.stringify(e));continue}t.push(e);continue}$n(e).length<=1?t.push(e):t.push(...e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0))}let n=t.join(`
|
|
2
|
+
`);return{text:n,entries:$n(n)}}function rr(e,t=50){if(t<1)throw RangeError(`chunk size must be at least 1`);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}var ir=2097152,ar=ir/1048576;function or({providerId:e,accounts:t,onClose:n}){let r=Fe(),i=ze(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(`auto`),[p,m]=(0,Z.useState)(void 0),[_,y]=(0,Z.useState)(!1),b=(0,Z.useRef)(null),x=$n(s),S=x.length>1,C=x.length===1?x[0]:void 0,w=d===`auto`?C?.kind:d,T=C&&w===`jwt`?Un(C.value):void 0,E=x.length>0?qn(e,s):void 0,D=E!==void 0&&p!==s,O=t.map(e=>e.label),k=S?tr(x,e,O):[],A=e=>{let t=d===`auto`?e.kind===`jwt`?`jwt`:`auto`:d;return{credentialKind:t===`auto`&&e.kind===`oauth`?`oauth`:`api_key`,credentialMode:t,secret:e.value}},j=r.isPending||l,M=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=$n(e);if(t.length>1)g.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`;g.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{g.error(`Clipboard access denied`)}},N=e=>{if(e.length===0)return;let t=e.find(e=>e.size>ir);if(t){g.error(`File too large`,`${t.name} is over ${ar} MB — credential files must be ${ar} MB or smaller.`);return}let n=e.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(typeof r.result==`string`?r.result:``),r.onerror=()=>n(Error(`Could not read ${e.name}`)),r.readAsText(e)}));Promise.all(n).then(t=>{let n=nr(e.map((e,n)=>({name:e.name,text:t[n]??``})));if(n.entries.length===0){g.error(`Nothing to import`,`None of the selected files held a credential the gateway recognises.`);return}c(n.text),g.success(`Imported ${e.length} file${e.length===1?``:`s`}`,n.entries.length>1?`Detected ${n.entries.length} credentials`:n.entries[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)}).catch(e=>g.error(`Could not read those files`,String(e)))},ee=async()=>{if(x.length!==0&&!D){if(x.length===1){let t=x[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...A(t)}},{onSuccess:()=>{g.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>g.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=rr(x.map((e,t)=>({label:k[t],...A(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${k[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${pe(e,`request failed`)}`);break}let s=a.length;r>0&&g.success(`${r} account${r===1?``:`s`} added`,o?`stopped partway; ${s} failed`:s>0?`${s} skipped`:void 0),s>0&&g.error(`${s} account${s===1?``:`s`} skipped`,a.slice(0,5).join(`
|
|
3
|
+
`)+(s>5?`\n…and ${s-5} more`:``)),r>0&&n()}finally{u(!1)}}};return(0,Q.jsx)(I,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:j,children:`Cancel`}),(0,Q.jsx)(h,{size:`sm`,variant:`primary`,disabled:j||x.length===0,onClick:()=>void ee(),children:j?`Connecting...`:D?`Confirm below`:S?`Add ${x.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!S&&(0,Q.jsx)(K,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:C?.identity??`${e} account`}),(0,Q.jsx)(q,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),S?(0,Q.jsxs)(G,{tone:`accent`,children:[`Detected: `,x.length,` accounts`]}):C?(0,Q.jsxs)(G,{tone:w===`oauth`||w===`jwt`?`accent`:`default`,children:[`Detected:`,` `,w===`oauth`?`OAuth`:w===`jwt`?`Static JWT`:`API key`,C.identity?` · ${C.identity}`:``]}):null,C&&w===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,T?` · expires ${new Date(T).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-control border-2 border-dashed p-3 transition-colors`,"data-drag-active":_?`true`:void 0,onDragOver:e=>{e.preventDefault(),y(!0)},onDragLeave:()=>y(!1),onDrop:e=>{e.preventDefault(),y(!1);let t=[...e.dataTransfer.files].filter(e=>e.name.endsWith(`.json`)||e.name.endsWith(`.jsonl`)||e.name.endsWith(`.ndjson`)||e.name.endsWith(`.txt`)||e.type.startsWith(`application/json`)||e.type.startsWith(`text/plain`));if(t.length===0){g.error(`Unsupported file`,`Drop .json, .txt, .jsonl, or .ndjson credential files.`);return}N(t)},children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary text-center`,children:`Or drop credential files here — JSON, .txt, .jsonl, .ndjson — several at once, merged and detected together.`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void M(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:v({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.jsx)(`input`,{ref:b,type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,multiple:!0,"aria-label":`Import credentials from files`,className:`hidden`,onChange:e=>{let t=[...e.target.files??[]];e.target.value=``,t.length>0&&N(t)}}),`Import files`]})]})]}),S&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,Q.jsx)(`span`,{className:`truncate min-w-0`,children:k[t]}),(0,Q.jsx)(G,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))}),E&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-control border border-warning-line bg-surface-2 px-4 py-5`,role:`alert`,children:[(0,Q.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,Q.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`Cross-channel credential`})}),(0,Q.jsxs)(`p`,{className:`text-caption text-text-primary`,children:[`This looks like a `,E.provider,` credential.`,` `,E.provider,` and `,E.counterpart,` tokens are interchangeable — one works in the other — but using a token on a channel it was not issued for can raise the risk of the account being banned, because it appears active somewhere it never authenticated. The same applies in reverse.`]}),D?(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>{c(``),n()},children:`Cancel`}),(0,Q.jsx)(h,{size:`sm`,variant:`primary`,onClick:()=>m(s),children:`Add anyway`})]}):(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:`Acknowledged — you can add this account now.`})]})]})})}function sr(e){return e===`active`?0:e===`cooldown`?2:3}var cr=[{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 lr(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=sr(e.status)-sr(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 ur({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ue(),s=Ae(),c=Ue(),l=Be(),u=it(e).data??new Map,f=mt(),m=(0,Z.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[_,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(new Set),[x,S]=(0,Z.useState)(`added-asc`),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),k=_.trim().toLowerCase(),A=(0,Z.useMemo)(()=>k?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return k.split(/\s+/).every(e=>t.includes(e))}):t,[t,k]),j=(0,Z.useMemo)(()=>{let e=x.slice(0,x.lastIndexOf(`-`)),t=x.endsWith(`-desc`)?-1:1,n=[...A];return n.sort((n,r)=>t*lr(n,r,e)),n},[A,x]),M=(0,Z.useMemo)(()=>t.filter(e=>e.kind!==`pool`&&y.has(e.id)),[t,y]),ee=A.length>0&&A.every(e=>y.has(e.id)),te=M.some(e=>e.status===`disabled`),F=M.some(e=>e.status!==`disabled`),I=M.length===0,ne=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},re=()=>{b(e=>{let t=new Set(e);if(ee)for(let e of A)t.delete(e.id);else for(let e of A)e.kind!==`pool`&&t.add(e.id);return t})},ae=async(e,t)=>{if(M.length===0)return;w(!0);let n=await un(M,le,t),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;w(!1),r===0?g.success(`${e} complete`,`${i} account${i===1?``:`s`}`):g.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},ce=()=>ae(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),le=3,de=async()=>{let e=t.filter(e=>e.kind!==`pool`);e.length!==0&&(w(!0),E({done:0,total:e.length}),await un(e,3,async(e,n)=>{let r=await me(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return E({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:R.quota.all}),o.invalidateQueries({queryKey:R.providers.all})]),w(!1),E(null),g.success(`Test complete`,`${e.length} account${e.length===1?``:`s`} tested`))},fe=t=>ae(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),pe=async()=>{if(M.length!==0){w(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:M.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);H(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),g.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){g.error(`Export failed`,e.message??`Unable to export accounts`)}finally{w(!1)}}};return(0,Q.jsxs)(J,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative w-full min-medium:w-56 shrink-0`,children:[(0,Q.jsx)(L,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,Q.jsx)(K,{id:`accounts-search`,value:_,onChange:e=>v(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9 h-15 py-0`})]}),(0,Q.jsx)(h,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(p,{size:12}),disabled:C||t.length===0,onClick:de,"aria-label":T===null?`Test all accounts`:`Testing accounts, ${T.done} of ${T.total} tested`,title:`Test every account, regardless of selection or filters`,children:T===null?`Test all`:`Tested ${T.done}/${T.total}`}),(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(oe,{size:12}),disabled:C||I,title:I?`Select at least one account to recover it`:`Clear cooldowns and retry-wait states on the selected accounts`,onClick:()=>void ce(),children:`Recover`}),(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(xt,{size:12}),disabled:C||!te,title:I?`Select at least one disabled account to enable it`:te?`Enable the selected accounts`:`No selected account is currently disabled`,onClick:()=>void fe(!0),children:`Enable`}),(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ie,{size:12}),disabled:C||!F,title:I?`Select at least one enabled account to disable it`:F?`Disable the selected accounts`:`No selected account is currently enabled`,onClick:()=>void fe(!1),children:`Disable`}),(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(d,{size:12}),disabled:C||I,title:I?`Select at least one account to export`:`Download the selected accounts as JSON`,onClick:()=>void pe(),children:`Export`}),(0,Q.jsx)(h,{size:`sm`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),disabled:C||I,title:I?`Select at least one account to delete`:`Delete ${M.length} selected account${M.length===1?``:`s`}`,onClick:()=>O(!0),children:`Delete`}),r?(0,Q.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(p,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null,(0,Q.jsx)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary ml-auto max-small:ml-0 [&_.radix-select-trigger]:font-semibold [&_.radix-select-trigger]:bg-hover [&_.radix-select-trigger]:text-text-primary`,children:(0,Q.jsx)(q,{size:`sm`,value:x,onValueChange:e=>S(e),options:cr,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:ee,onChange:re,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),I?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(new Set),className:`inline-flex h-15 shrink-0 items-center gap-1 rounded-control border border-inner-border px-3 text-badge font-semibold text-text-secondary hover:bg-hover`,title:`Clear selection`,children:[M.length,` selected`,(0,Q.jsx)(P,{size:11,"aria-hidden":`true`})]})]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:j.length===0?(0,Q.jsx)(N,{compact:!0,icon:(0,Q.jsx)(L,{size:20}),title:`No matching accounts`,message:k?`Nothing matches “${k}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):j.map(t=>(0,Q.jsx)(Mn,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:m.get(t.id),selected:y.has(t.id),onToggleSelect:ne,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,A.length,` account`,A.length===1?``:`s`,k?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(xe,{open:D,onClose:()=>{C||O(!1)},onConfirm:async()=>{await ae(`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:R.quota.account(e.id),exact:!0})}),b(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:R.providers.accounts(e)}),o.invalidateQueries({queryKey:R.providers.all}),o.invalidateQueries({queryKey:R.quota.all})])},title:`Delete ${M.length} account${M.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}function dr(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 fr({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=Oe(),d=_t(),p=ue(),m=De(e),v=(0,Z.useRef)(null),y=(0,Z.useRef)(!1),[b,x]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{let t=setInterval(()=>{p.invalidateQueries({queryKey:R.providers.accounts(e)})},1500);return()=>clearInterval(t)},[p,e]),(0,Z.useEffect)(()=>{let t=!1;return p.invalidateQueries({queryKey:R.providers.accounts(e)}).finally(()=>{t||x(!1)}),()=>{t=!0}},[p,e]),(0,Z.useEffect)(()=>{if(b)return;let e=m.data?.map(e=>e.id)??null;if(e!==null){if(v.current===null){v.current=new Set(e);return}y.current||e.find(e=>!v.current.has(e))!==void 0&&(y.current=!0,r.close(),g.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[m.data,b,r,i]);let S=()=>{r.close(),i(!1)},[C,w]=(0,Z.useState)(!1),T=()=>{w(!0),p.invalidateQueries({queryKey:R.providers.accounts(e)}).finally(()=>w(!1))},E=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){g.error(`Clipboard is empty`);return}c(e),g.success(`Pasted redirect URL`)}catch{g.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(I,{open:!0,onClose:S,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:S,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:T,disabled:l.isPending||C,title:`You already approved in the popup — check now instead of waiting`,children:C?`Checking…`:`Complete`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=dr(s);if(`error`in t){g.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),g.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>g.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,Q.jsxs)(J,{gap:`14px`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(_,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),d(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,Q.jsx)(`span`,{children:`Or complete manually`}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-start`,children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void E(),className:`shrink-0`,children:`Paste`})]})]})]})})}function pr(e){try{return new URL(e).host}catch{return e}}function mr({providerId:e,parameters:t,onClose:n}){let r=be(),i=Te(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,d]=(0,Z.useState)(!1),p=_t();(0,Z.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(g.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let m=(0,Z.useRef)(null),[v,y]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?m.current=e:y(!0),()=>{let e=m.current;m.current=null,e&&!e.closed&&e.close()}},[a]),(0,Z.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),g.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(),g.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),g.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,Q.jsx)(I,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,Q.jsx)(J,{gap:`14px`,children:a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,Q.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(_,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),p(()=>d(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:pr(a.verificationUri)}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(we,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(_,{size:12}):(0,Q.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),p(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:v?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function hr({providerId:e}){let[t,n]=(0,Z.useState)(!1),r=Ve(e,t);return(0,Q.jsxs)(V,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-expanded":t,className:`card-header-bar w-full cursor-pointer list-none text-left`,children:[(0,Q.jsxs)(`div`,{className:`card-header-left`,children:[(0,Q.jsx)(`div`,{className:`card-header-icon`,children:(0,Q.jsx)(i,{size:16,"aria-hidden":`true`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`font-bold text-text-primary`,children:`Activity Matrix`}),(0,Q.jsxs)(`div`,{className:`text-caption text-text-secondary`,children:[`Daily token usage, last `,r.data?.days??30,` days · expand to load`]})]})]}),(0,Q.jsx)(`div`,{className:`card-header-right`,children:(0,Q.jsx)(Le,{size:14,"aria-hidden":`true`,className:y(`transition-transform`,t&&`rotate-180`)})})]}),t?(0,Q.jsx)(Dr,{matrix:r}):null]})}function gr(e){let t=new Map,n=new Map,r={requests:0,tokens:0,cachedTokens:0,costUsd:0};for(let i of e.rows){let e=t.get(i.day)??{tokens:0,models:new Map},a=i.inputTokens+i.outputTokens;e.tokens+=a;let o=i.model??`unknown`,s=e.models.get(o)??{tokens:0,requests:0};s.tokens+=a,s.requests+=i.requests,e.models.set(o,s),t.set(i.day,e);let c=n.get(o)??{tokens:0,requests:0};c.tokens+=a,c.requests+=i.requests,n.set(o,c),r.requests+=i.requests,r.tokens+=a,r.cachedTokens+=i.cachedInputTokens,r.costUsd+=i.costUsd}let i=Math.min(Math.max(e.days,1),366),a=new Date,o=Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate()),s=[],c=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],l=0;for(let e of t.values())l=Math.max(l,e.tokens);let u=new Date(o-(i-1)*864e5),d=(u.getUTCDay()+6)%7,f=u.getTime()-d*864e5,p=[];for(;;){if(f>o){if(p.length>0||s.length===0){for(;p.length<7;)p.push(null);s.push({cells:p})}break}let e=new Date(f),n=e.toISOString().slice(0,10),r=t.get(n),i=r?[...r.models.entries()].map(([e,t])=>({name:e,tokens:t.tokens,requests:t.requests,color:_r(e)})).sort((e,t)=>t.tokens-e.tokens):[],a=r?{day:n,label:`${c[(e.getUTCDay()+6)%7]} ${n.slice(5)}`,total:r.tokens,color:i[0]?.color??`var(--surface-2)`,models:i}:null;p.push(a),p.length===7&&(s.push({cells:p}),p=[]),f+=864e5}let m=[...n.entries()].map(([e,t])=>({name:e,tokens:t.tokens,requests:t.requests,color:_r(e)})).sort((e,t)=>t.tokens-e.tokens);return{weeks:s,maxDay:l,totals:r,models:m}}function _r(e){let t=5381;for(let n=0;n<e.length;n++)t=t*33^e.charCodeAt(n);let n=Math.abs(t)%360;return`hsl(${(n<60||n>110?n:n+130)%360} 65% 60%)`}function vr(e,t){if(e<=0||t<=0)return 0;let n=e/t,r=1;for(let e=1;e<yr.length;e++)n>e/(yr.length-1)&&(r=e);return Math.min(r,yr.length-1)}var yr=[0,.18,.38,.62,.9];function br(e){return yr[Math.min(Math.max(Math.trunc(e),0),yr.length-1)]??0}function xr(e){let t=br(e)*100;return t===0?`var(--surface-2)`:`color-mix(in srgb, var(--text-primary) ${t}%, transparent)`}function Sr(e,t){if(t===0)return{backgroundColor:`var(--surface-2)`,borderColor:`var(--inner-border)`};let n=br(t)*100;return{backgroundColor:`color-mix(in srgb, ${e.color} ${n}%, transparent)`,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}}function Cr(e){return[`${e.label} — ${W(e.total)} tokens`,...e.models.map(t=>`• ${t.name}: ${W(t.tokens)} (${Math.round(t.tokens/e.total*100)}%) · ${t.requests} req`)].join(`
|
|
4
|
+
`)}var wr=`26px repeat(7, minmax(0, 1fr))`,Tr=420,Er=360;function Dr({matrix:e}){let t=(0,Z.useMemo)(()=>e.data?gr(e.data):void 0,[e.data]),n;return n=e.isPending?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`Loading activity…`}):e.isError?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-status-danger`,children:`Failed to load activity matrix.`}):!t||t.totals.requests===0?(0,Q.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`No usage recorded for this provider in the window.`}):(0,Q.jsx)(kr,{view:t}),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`border-t border-inner-border`,children:(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 p-4 max-small:p-3 min-[641px]:grid-cols-4`,children:[(0,Q.jsx)(Or,{label:`Total tokens`,value:W(t?.totals.tokens)}),(0,Q.jsx)(Or,{label:`Requests`,value:(t?.totals.requests??0).toLocaleString(`en-US`)}),(0,Q.jsx)(Or,{label:`Cached`,value:W(t?.totals.cachedTokens)}),(0,Q.jsx)(Or,{label:`Est. cost`,value:T(t?.totals.costUsd)})]})}),(0,Q.jsxs)(`div`,{className:`min-w-0 overflow-x-auto border-t border-inner-border p-4 max-small:p-3`,children:[n,t&&t.totals.requests>0?(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-1.5 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Less`}),[0,1,2,3,4].map(e=>(0,Q.jsx)(`span`,{className:`size-3 rounded-micro border border-inner-border`,style:{backgroundColor:xr(e)}},e)),(0,Q.jsx)(`span`,{children:`More`})]}):null,t&&t.totals.requests>0&&t.models.length>0?(0,Q.jsxs)(`details`,{className:`group mt-4 border-t border-inner-border pt-3`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 text-caption text-text-secondary [&::-webkit-details-marker]:hidden`,children:[(0,Q.jsxs)(`span`,{className:`font-semibold`,children:[`Usage by model (`,t.models.length,`) · sorted by tokens`]}),(0,Q.jsx)(Le,{size:14,"aria-hidden":`true`,className:`shrink-0 transition-transform group-open:rotate-180`})]}),(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-2.5`,children:t.models.map(e=>{let n=t.totals.tokens>0?e.tokens/t.totals.tokens:0;return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 shrink truncate text-caption font-semibold`,style:{color:e.color},title:e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`h-2.5 min-w-0 flex-1 rounded-micro`,style:{backgroundColor:`var(--surface-2)`,backgroundImage:`linear-gradient(to right, ${e.color} ${Math.max(n*100,2)}%, transparent ${Math.max(n*100,2)}%)`}}),(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-caption text-text-secondary`,children:[W(e.tokens),` `,(0,Q.jsxs)(`span`,{className:`text-text-tertiary`,children:[Math.round(n*100),`%`]}),` ·`,` `,e.requests.toLocaleString(`en-US`),` req`]})]},e.name)})})]}):null]})]})}function Or({label:e,value:t}){return(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:e}),(0,Q.jsx)(`div`,{className:`mt-0.5 font-mono text-lg font-bold text-text-primary`,children:t})]})}function kr({view:e}){return(0,Q.jsx)(`div`,{style:{minWidth:Er},children:(0,Q.jsxs)(`div`,{className:`grid gap-1`,style:{gridTemplateColumns:wr,maxWidth:Tr},children:[(0,Q.jsx)(`div`,{}),[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`].map(e=>(0,Q.jsx)(`div`,{className:`text-center text-micro text-text-tertiary`,children:e},e)),e.weeks.map((t,n)=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center text-micro text-text-tertiary`,children:[`W`,n+1]}),t.cells.map((t,r)=>t===null?(0,Q.jsx)(`div`,{},`${n}-${r}`):(0,Q.jsx)(`div`,{className:`aspect-square cursor-pointer rounded-micro border border-inner-border transition-[outline-offset] hover:outline hover:outline-2 hover:outline-accent`,style:Sr(t,vr(t.total,e.maxDay)),title:Cr(t)},t.day))]},n))]})})}function Ar(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function jr(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Mr({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,Q.jsx)(J,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,Q.jsx)(q,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,Q.jsx)(K,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function Nr({providerId:e,providerName:t,fields:n,onClose:r}){let i=Ce(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>Ar(n)),d=(0,Z.useMemo)(()=>jr(n,l),[n,l]);return(0,Q.jsx)(I,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){g.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){g.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:()=>{g.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>g.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(f,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,Q.jsx)(Mr,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(K,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(K,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}var Pr=2e4,Fr=`What model are you, and what is your knowledge cutoff date? Answer in one sentence.`;function Ir(){let e=et(),t=$e(),[n,r]=(0,Z.useState)(!1);return{test:(0,Z.useCallback)(async(n,i)=>{let a=(e.data??[]).find(e=>e.enabled&&e.revokedAt===void 0&&e.isDefault);if(a===void 0)return{ok:!1,latencyMs:0,error:`The default gateway API key is unavailable.`};let o;try{({secret:o}=await t.mutateAsync({keyId:a.id}))}catch(e){return{ok:!1,latencyMs:0,error:e.message??`Failed to reveal the default API key.`}}let s=new AbortController,c=setTimeout(()=>s.abort(),Pr),l=performance.now();r(!0);try{let e=await fetch(`/v1/chat/completions`,{method:`POST`,credentials:`same-origin`,signal:s.signal,headers:{Accept:`application/json`,"Content-Type":`application/json`,Authorization:`Bearer ${o}`},body:JSON.stringify({model:n,messages:[{role:`user`,content:Fr}],...i===void 0?{}:{max_tokens:i},stream:!1})}),t=await e.text(),r=null;try{r=JSON.parse(t)}catch{r=null}let a=Math.round(performance.now()-l);if(!e.ok){let t=r?.error;return{ok:!1,latencyMs:a,error:typeof t?.message==`string`?t.message:`Gateway responded with HTTP ${e.status}`}}let c=(Array.isArray(r?.choices)?r?.choices:[])[0]?.message,u=typeof c?.content==`string`?c.content.trim():``,d=typeof r?.model==`string`?r.model:void 0;return{ok:!0,latencyMs:a,...u.length>0?{sample:u}:{},...d===void 0?{}:{reportedModel:d}}}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`;return{ok:!1,latencyMs:Math.round(performance.now()-l),error:t?`The model test timed out.`:e.message??`Network error during model test.`}}finally{clearTimeout(c),r(!1)}},[e.data,t]),testing:n}}function Lr(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function Rr(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var zr=[{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`}],Br={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function Vr(){return Ot.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function Hr({value:e,onChange:t,disabled:n,size:r=`md`,id:i=`probe-thinking-effort`}){return(0,Q.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0 max-sm:min-w-56`,children:(0,Q.jsx)(q,{id:i,"aria-label":`Thinking effort`,value:e,disabled:n,size:r,onValueChange:e=>t(e),options:Vr()})})}function Ur(){return[{value:`all`,label:`All models`},{value:`free`,label:`Free tier`}]}function Wr({value:e,onChange:t,disabled:n,size:r=`md`,id:i=`models-show-filter`}){return(0,Q.jsx)(`div`,{title:`Which models to show. Free tier hides every row the provider does not publish as free.`,className:`min-w-46 shrink-0 max-sm:min-w-40`,children:(0,Q.jsx)(q,{id:i,"aria-label":`Show models`,value:e,disabled:n,size:r,onValueChange:e=>t(e),options:Ur()})})}function Gr({providerId:e,provider:t,onClose:n}){let r=Ne(),i=ye(),[a,o]=(0,Z.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Z.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Z.useState)(c??`chat`),[m,_]=(0,Z.useState)(`auto`),[v,y]=(0,Z.useState)(`idle`),[b,x]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(Yr),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(y(`testing`),x(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:u,reasoningEffort:m,serviceKind:`llm`}},{onSuccess:e=>{e.ok?y(`passed`):(y(`failed`),x(e.error??`Model probe failed`))},onError:e=>{y(`failed`),x(e.message??`Model probe failed`)}}))};return(0,Q.jsx)(I,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=Ge(S.contextLimit),r=Ge(S.outputLimit);if(t===null||r===null){g.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:S.passthrough,image:S.passthrough?!0:S.image,reasoning:S.passthrough?!0:S.reasoning,toolCall:S.passthrough?!0:S.toolCall}},{onSuccess:()=>{g.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>g.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-end`,children:[(0,Q.jsx)(K,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),y(`idle`),x(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:v===`testing`?(0,Q.jsx)(f,{size:13,className:`animate-spin`}):(0,Q.jsx)(p,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:v===`testing`?`Testing...`:`Test`})]}),E&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,Q.jsx)(q,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),y(`idle`),x(``)},options:l.map(e=>({value:e,label:ti(e)}))}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,Q.jsx)(Hr,{id:`add-model-thinking-effort`,value:m,onChange:e=>{_(e),y(`idle`),x(``)},disabled:r.isPending}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,Q.jsx)(Xr,{draft:S,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:ti(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),v===`passed`&&(0,Q.jsx)(X,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),v===`failed`&&(0,Q.jsx)(X,{tone:`danger`,live:`alert`,children:b||`Model test failed.`})]})})}function Kr(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var qr=String(Je),Jr=String(Ke);function Yr(){return{...Kr(),contextLimit:qr,outputLimit:Jr}}function Xr({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(K,{label:`Context`,id:`${n}-context`,placeholder:qr,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(K,{label:`Output`,id:`${n}-output`,placeholder:Jr,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===qr&&e.outputLimit===Jr,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:qr,outputLimit:Jr}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,U(Je),` ctx ·`,` `,U(Ke),` out`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,Q.jsx)(J,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function Zr({providerId:e,model:t,onClose:n}){let r=je(),[i,a]=(0,Z.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,Q.jsx)(I,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=Ge(i.contextLimit),o=Ge(i.outputLimit);if(a===null||o===null){g.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=>g.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,Q.jsx)(Xr,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Qr({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let d=Ir(),v=ge(),[y,w]=(0,Z.useState)(!1),[T,D]=(0,Z.useState)(null),k=_t(),A=n===`llm`?kt(t.modelId,i===`auto`?null:i):t.modelId,j=`${e}/${A}`,M=n===`websearch`?`Searching…`:`Thinking…`,N=()=>{d.test(j,t.outputLimit??void 0).then(t=>{if(D({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){g.error(`${e}/${A} test failed`,t.error??`Unknown error`);return}let n=t.sample??``,r=t.reportedModel?.trim()??``;g.successRich(`${A} · END ${m(t.latencyMs)}`,(0,Q.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,Q.jsxs)(Y,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,Q.jsx)(E,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,Q.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
5
|
+
`)||`No sample text in the response.`)})},ee=()=>{let n=!t.enabled;v.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>g.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>g.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,Q.jsx)(o,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,Q.jsx)(`div`,{title:j,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:A}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...ei(t.wireFamily)},children:ti(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:Lr(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:Rr(t.source)}):null,t.proOnly===!0?(0,Q.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,Q.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,Q.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,icon:y?(0,Q.jsx)(_,{size:12}):(0,Q.jsx)(u,{size:12}),"aria-label":`Copy ${j}`,title:`Copy ${j}`,onClick:()=>{navigator.clipboard?.writeText(j),w(!0),k(()=>w(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,Q.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,Q.jsx)(s,{size:12})}):null,t.vision?(0,Q.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,Q.jsx)(O,{size:12})}):null,t.toolCall?(0,Q.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,Q.jsx)(ce,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(b,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:qe,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,Q.jsx)(S,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${U(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Ye,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${U(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Ye,className:`cursor-help`,children:` · n/a out`})]}),c?(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,Q.jsx)(ne,{size:11})}):null]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,disabled:d.testing,onClick:N,"aria-label":`Test ${A}`,title:d.testing?`Probing ${A}…`:T?.ok?`Last probe OK in ${m(T.latencyMs)} — click to re-test`:T?`Last probe failed — click to retry`:`Test ${A}`,className:`flex-1 justify-center`,icon:d.testing?(0,Q.jsx)(f,{size:12,className:`animate-spin`}):T?T.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(C,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(x,{size:12})}):(0,Q.jsx)(p,{size:12}),children:d.testing?M:T?.ok?m(T.latencyMs):T?`Fail`:`Test`}),(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,disabled:v.isPending,onClick:ee,icon:t.enabled?(0,Q.jsx)(ie,{size:12}):(0,Q.jsx)(xt,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,Q.jsx)(h,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(se,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var $r=(0,Z.memo)(Qr);function ei(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 ti(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function ni({providerId:e,models:t,thinkingEffort:n,showFilter:r=`all`,serviceKind:i=`llm`,searchCapable:a=!1}){let o=Me(),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),d=e=>e.enabled!==!1,f=r===`free`?t.filter(e=>e.freeTier===!0):t,p=zr.map(e=>({...e,rows:f.filter(t=>d(t)&&e.matches(t.source))})).filter(e=>e.rows.length>0),m=f.filter(e=>!d(e)),h=t=>(0,Q.jsx)($r,{providerId:e,model:t,serviceKind:i,searchCapable:a,thinkingEffort:n,deletePending:o.isPending,onDeleteRequest:c,onEditRequest:t.source===`builtin`?void 0:u},`${t.modelId}::${t.route}`);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(J,{gap:`16px`,children:[p.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,Q.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(h)})]},e.key)),m.length===0?null:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:Br.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:m.length}),(0,Q.jsxs)(`span`,{title:Br.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,Br.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:m.map(h)})]})]}),(0,Q.jsx)(xe,{open:s!==null,onClose:()=>{o.isPending||c(null)},onConfirm:async()=>{s!==null&&(await o.mutateAsync({providerId:e,request:{modelId:s.modelId,route:s.route}}),g.success(`Model deleted`,`${e}/${s.modelId}`),c(null))},title:`Delete model?`,message:`Delete ${e}/${s?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),l===null?null:(0,Q.jsx)(Zr,{providerId:e,model:l,onClose:()=>u(null)})]})}function ri(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function ii(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function ai(){let{providerId:e}=Re(),[t]=ke(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=Ee(n),s=Se(n),l=De(n),u=_e(),f=_e({silent:!0}),[p,m]=(0,Z.useState)(!1),_=Ie(),v=ve(),y=He(),x=ue(),[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),E=Ne(),[D,O]=(0,Z.useState)(``),[k,te]=(0,Z.useState)(``),[P,F]=(0,Z.useState)(null),ne=e=>`cartethyia:provider:${e}:thinking-effort`,oe=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(ne(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return Ot.includes(n)?n:`auto`},[L,ce]=(0,Z.useState)(()=>oe(n));(0,Z.useEffect)(()=>{if(!n)return;let e=oe(n);e!==L&&ce(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(ne(n),L)},[n,L]);let le=e=>`cartethyia:provider:${e}:show-filter`,de=e=>typeof window>`u`||!window.localStorage?`all`:window.localStorage.getItem(le(e))===`free`?`free`:`all`,[fe,pe]=(0,Z.useState)(()=>de(n));(0,Z.useEffect)(()=>{if(!n)return;let e=de(n);e!==fe&&pe(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(le(n),fe)},[n,fe]);let[he,ge]=(0,Z.useState)(!1),[ye,be]=(0,Z.useState)(!1),[Ce,Te]=(0,Z.useState)(null),[Oe,Ae]=(0,Z.useState)({}),[je,Me]=(0,Z.useState)({}),[z,Pe]=(0,Z.useState)(null),[Fe,Le]=(0,Z.useState)(!1),[ze,Be]=(0,Z.useState)(null),Ve=(0,Z.useRef)(null),Ue=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=Ve.current;Ve.current=null,e&&!e.closed&&e.close()},[]);let H=o.data,Ge=n===`opencode`||n===`cline`,Ke=H===void 0?[`llm`]:ii(H),U=[];for(let e of Ke)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&U.push(e);(0,Z.useEffect)(()=>{if(H===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=U[0];if(e!==void 0&&U.includes(e)){i!==e&&a(e);return}!U.includes(i)&&t!==void 0&&a(t)},[H,r,i,U.join(`|`)]),(0,Z.useEffect)(()=>{Ge&&H!==void 0&&H.supportsModelDiscovery!==!1&&Ue.current!==n&&(Ue.current=n,f.mutate(n))},[Ge,f,n,H?.supportsModelDiscovery]);let qe=l.data??[],Je=s.data??[],Ye=(()=>{let e=new Map;for(let t of Je){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))})(),W=Ye.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),Xe=Ye.filter(e=>e.serviceKind===`websearch`),G=Ye.filter(e=>e.serviceKind===`imageGeneration`),K=Ye.filter(e=>e.serviceKind===`videoGeneration`),q=U.includes(i)?i:U[0],$e=k||Xe[0]?.modelId||``,et=()=>{let e=D.trim();$e&&e&&(F(null),E.mutate({providerId:n,request:{modelId:$e,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,Q.jsx)(M,{label:`Loading provider...`});if(o.isError)return(0,Q.jsx)(j,{title:`Unable to load providers`,message:`The provider details could not be read, so this page cannot resolve its endpoint settings.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,Q.jsx)(At,{to:`/providers`,label:`Back to providers`})});if(!H)return(0,Q.jsx)(N,{icon:(0,Q.jsx)(St,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,Q.jsx)(At,{to:`/providers`,label:`Back to providers`})});let tt=qe.filter(e=>e.status===`active`).length,nt=e=>{let t=e===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?X():ge(!0);return}Ae(Ar(t)),Te(e)},rt=()=>{if(Ce===null)return;let e=jr(Ce===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[],Oe);if(e.length>0){g.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=Ce;Te(null),t===`browser`?X(Oe):(Me(Oe),ge(!0))},X=e=>{let t=Ve.current;t&&!t.closed&&t.close();let r=`cartethyia-oauth-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,i=window.open(`about:blank`,r,`popup,width=720,height=820`);i&&(i.opener=null,Ve.current=i),y.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:t})=>{let n=null;if(i&&!i.closed?(i.location.href=e,n=i):(n=window.open(e,r,`popup,width=720,height=820`),n&&(n.opener=null,Ve.current=n)),!n){g.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Be({authorizeUrl:e,state:t,popup:n})},onError:e=>{i&&!i.closed&&i.close(),Ve.current===i&&(Ve.current=null),g.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(J,{gap:`16px`,children:[(0,Q.jsx)(jt,{title:`${H.label||H.displayName}${q?` (${ri(q)})`:``}`,description:`${H.providerId}/${H.baseUrl?` · ${H.baseUrl}`:``}`,icon:(0,Q.jsx)(Ze,{icon:H.providerId,name:H.label||H.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,Q.jsx)(Y,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:H.isBuiltIn?(0,Q.jsx)(h,{variant:H.enabled?`danger`:`secondary`,icon:H.enabled?(0,Q.jsx)(ie,{size:13}):(0,Q.jsx)(xt,{size:13}),loading:v.isPending,onClick:()=>v.mutate({providerId:n,enabled:!H.enabled},{onSuccess:e=>g.success(e.enabled?`Provider enabled`:`Provider disabled`,H.label||H.displayName),onError:e=>g.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:H.enabled?`Disable provider globally`:`Enable provider globally`,children:H.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(cn,{provider:H}),H.isBuiltIn?null:(0,Q.jsx)(ln,{provider:H}),q===`llm`?(0,Q.jsx)(Ht,{providerId:n,clientVersion:H.clientVersion,routeIdentityVersions:H.routeIdentityVersions,userAgentEditable:Mt(H)}):null,(0,Q.jsx)(hr,{providerId:n}),(0,Q.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:H.requiresAccount===!1&&qe.length===0?(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Accounts`,icon:(0,Q.jsx)(vt,{size:16})}),(0,Q.jsx)(B,{children:(0,Q.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Accounts`,subtitle:`${qe.length} total · ${tt} active · ${qe.length-tt} disabled`,icon:(0,Q.jsx)(vt,{size:16}),action:(0,Q.jsxs)(Qe,{children:[H.oauthFlows?.browser&&(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(we,{size:13}),disabled:y.isPending,onClick:()=>X(),title:`Social login — Google / GitHub / OIDC via the provider's sign-in portal`,children:y.isPending?`Starting...`:`Social login`}),H.oauthFlows?.device&&(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(ee,{size:13}),onClick:()=>nt(`device`),title:`Device Code — enter the shown code on the provider site`,children:`Device Code`}),H.oauthFlows?.import&&(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(d,{size:13}),onClick:()=>be(!0),title:H.oauthFlows.browser||H.oauthFlows.device||H.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:H.oauthFlows.browser||H.oauthFlows.device||H.oauthFlows.refreshable?`Import credential`:`Add API key`}),H.requiresAccount?(0,Q.jsx)(h,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(re,{size:13}),onClick:()=>C(!0),children:`Add Account`}):null]})}),(0,Q.jsxs)(B,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(rn,{providerId:n}),l.isPending?(0,Q.jsx)(M,{label:`Loading accounts...`}):l.isError?(0,Q.jsx)(j,{message:`Failed to load accounts`,onRetry:()=>l.refetch()}):qe.length===0?(0,Q.jsx)(N,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,Q.jsx)(ur,{providerId:n,accounts:qe,onDelete:e=>Pe(e),showGrokProbe:q===`llm`&&n===`grok`,grokProbePending:_.isPending,onGrokProbe:()=>{_.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`Type the 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;g.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>g.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),q===`llm`?(0,Q.jsxs)(Q.Fragment,{children:[n===`inferhub`?(0,Q.jsx)(en,{}):null,(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Models`,subtitle:`${W.length} model${W.length===1?``:`s`} registered`,icon:(0,Q.jsx)(c,{size:16}),action:(0,Q.jsxs)(Y,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,Q.jsx)(Wr,{id:`models-section-show-filter`,value:fe,onChange:pe,size:`sm`}),(0,Q.jsx)(Hr,{id:`models-section-thinking-effort`,value:L,onChange:ce,size:`sm`}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,Q.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,Q.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(se,{size:13,className:p?`animate-spin`:``}),disabled:u.isPending||f.isPending||p||W.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=W.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){m(!0);try{let t=await 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:R.providers.models(n)}),x.invalidateQueries({queryKey:R.providers.all})]);let r=t.failures.length;g.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){g.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{m(!1)}}},children:p?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(re,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,Q.jsx)(B,{className:`flex flex-col gap-8`,children:s.isPending?(0,Q.jsx)(M,{label:`Loading models...`}):s.isError?(0,Q.jsx)(j,{message:`Failed to load models`,onRetry:()=>s.refetch()}):W.length===0?(0,Q.jsx)(N,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,Q.jsx)(ni,{providerId:n,models:W,serviceKind:`llm`,thinkingEffort:L,showFilter:fe,searchCapable:H?.supportsWebSearch===!0})})]})]}):q===`websearch`?(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(b,{size:16})}),(0,Q.jsx)(B,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(M,{label:`Loading search models...`}):s.isError?(0,Q.jsx)(j,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):Xe.length===0?(0,Q.jsx)(N,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,Q.jsx)(`select`,{value:$e,onChange:e=>{te(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:Xe.map(e=>(0,Q.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,Q.jsx)(`input`,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),et())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,Q.jsx)(h,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:et,children:`Test search`}),P?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:P.ok?`var(--green)`:`var(--red)`},children:P.ok?`Search ok · ${P.latencyMs}ms · ${P.count??0} result(s)`:P.error??`Search failed.`}):null]}),P&&P.results&&P.results.length>0?(0,Q.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:P.results.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,Q.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,Q.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):q===`imageGeneration`||q===`videoGeneration`?(0,Q.jsxs)(V,{children:[(0,Q.jsx)(We,{title:ri(q),subtitle:q===`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:q===`imageGeneration`?(0,Q.jsx)(A,{size:16}):(0,Q.jsx)(Et,{size:16})}),(0,Q.jsx)(B,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(M,{label:`Loading ${ri(q).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(j,{message:`Failed to load ${ri(q).toLowerCase()} models`,onRetry:()=>s.refetch()}):(q===`imageGeneration`?G:K).length===0?(0,Q.jsx)(N,{title:`No ${ri(q)} models found`,message:`This provider advertises ${ri(q)}, but no ${q} model is registered yet.`}):(0,Q.jsx)(ni,{providerId:n,models:q===`imageGeneration`?G:K,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,Q.jsx)(V,{children:(0,Q.jsx)(B,{children:(0,Q.jsx)(N,{title:`Service not available`,message:`This provider advertises ${Ke.map(ri).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),S&&(0,Q.jsx)(or,{providerId:n,accounts:qe,onClose:()=>C(!1)}),q===`llm`&&w?(0,Q.jsx)(Gr,{providerId:n,provider:H,onClose:()=>T(!1)}):null,(0,Q.jsx)(xe,{open:z!==null,onClose:()=>{Fe||Pe(null)},onConfirm:async()=>{if(z){Le(!0);try{let e=z.tenantId===null?`/global/accounts/${encodeURIComponent(z.id)}`:`/accounts/${encodeURIComponent(z.id)}`;await me(e,{method:`DELETE`}),x.removeQueries({queryKey:R.quota.account(z.id),exact:!0}),await Promise.all([x.invalidateQueries({queryKey:R.providers.accounts(n)}),x.invalidateQueries({queryKey:R.providers.healthEvents(n,z.id)}),x.invalidateQueries({queryKey:R.providers.all}),x.invalidateQueries({queryKey:R.quota.all})]),g.success(`Account deleted`,z.label||z.id.slice(0,8)),Pe(null)}catch(e){throw g.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Le(!1)}}},title:`Delete account?`,message:`Delete "${z?.label||z?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),he&&(0,Q.jsx)(mr,{providerId:n,parameters:je,onClose:()=>{ge(!1),Me({})}}),Ce!==null&&(0,Q.jsx)(I,{open:!0,onClose:()=>Te(null),title:Ce===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>Te(null),children:`Cancel`}),(0,Q.jsx)(h,{variant:`primary`,size:`sm`,onClick:rt,children:`Continue`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:Ce===`browser`?`Choose how ${H.label||H.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(Mr,{fields:Ce===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[],values:Oe,idPrefix:`flow-${Ce}`,onChange:(e,t)=>Ae(n=>({...n,[e]:t}))})]})}),ye&&H?.oauthFlows?.import===!0&&(0,Q.jsx)(Nr,{providerId:n,providerName:H.label||H.displayName,fields:H.oauthFlows.importFields,onClose:()=>be(!1)}),ze&&(0,Q.jsx)(fr,{providerId:n,authorizeUrl:ze.authorizeUrl,state:ze.state,popup:ze.popup,onClose:e=>{Ve.current=null,Be(null),e&&x.invalidateQueries({queryKey:R.providers.accounts(n)})}})]})}export{ai as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";var r=e(t(),1),i=n(),a=new Set,o={claude:{file:`claude-code`,ext:`svg`},anthropic:{file:`anthropics`,ext:`webp`},openai:{file:`openai-light`,ext:`svg`},codex:{file:`codex`,ext:`webp`},opencode:{file:`opencode`,ext:`webp`},"opencode-zen":{file:`opencode`,ext:`webp`},"opencode-go":{file:`opencode-go`,ext:`webp`},"google-antigravity":{file:`antigravity`,ext:`svg`},antigravity:{file:`antigravity`,ext:`svg`},blackbox:{file:`blackbox`,ext:`svg`},blackboxai:{file:`blackbox`,ext:`svg`},grok:{file:`grok-build`,ext:`webp`},"grok-build":{file:`grok-build`,ext:`webp`},xai:{file:`grok-build`,ext:`webp`},inferhub:{file:`inferhub`,ext:`svg`},gemini:{file:`gemini`,ext:`webp`},alibaba:{file:`alibaba`,ext:`svg`},alibabacp:{file:`alibaba`,ext:`svg`},dashscope:{file:`alibaba`,ext:`svg`},fireworks:{file:`fireworks`,ext:`webp`},exa:{file:`exa`,ext:`svg`},perplexity:{file:`perplexity`,ext:`webp`},tokenharbor:{file:`tokenharbor`,ext:`svg`},aihubmix:{file:`aihubmix`,ext:`svg`},zcode:{file:`zcode`,ext:`webp`},"zcode-start":{file:`zcode`,ext:`webp`},zai:{file:`zai`,ext:`webp`},"zai-plan":{file:`zai`,ext:`webp`},"zai-start":{file:`zai`,ext:`webp`},"kimi-code":{file:`kimi-code`,ext:`webp`},kimi:{file:`kimi-code`,ext:`webp`},github:{file:`github`,ext:`webp`},copilot:{file:`copilot`,ext:`webp`},xiaomipg:{file:`mimo`,ext:`webp`},xiaomitp:{file:`mimo`,ext:`webp`},mimo:{file:`mimo`,ext:`webp`},cb:{file:`codebuddy`,ext:`webp`},cbcn:{file:`codebuddy`,ext:`webp`},workbuddy:{file:`codebuddy`,ext:`webp`},workbuddycn:{file:`codebuddy`,ext:`webp`},agentrouter:{file:`agentrouter`,ext:`svg`},parallel:{file:`parallel`,ext:`svg`},gmi:{file:`gmi-cloud`,ext:`svg`},hermes:{file:`hermes`,ext:`webp`},nous:{file:`nous-research`,ext:`svg`},inception:{file:`inception`,ext:`svg`},bai:{file:`bai`,ext:`svg`},cline:{file:`cline`,ext:`webp`},cerebras:{file:`cerebras`,ext:`webp`},qoder:{file:`qoder`,ext:`webp`},qodercn:{file:`qoder`,ext:`webp`},mistral:{file:`mistral`,ext:`webp`},muse:{file:`muse`,ext:`svg`},meta:{file:`muse`,ext:`svg`},openrouter:{file:`openrouter`,ext:`webp`},ollama:{file:`ollama`,ext:`webp`},ollamacloud:{file:`ollama-cloud`,ext:`webp`},nvidia:{file:`nvidia`,ext:`webp`},deepseek:{file:`deepseek`,ext:`webp`},"deepseek-tui":{file:`deepseek-tui`,ext:`webp`},droid:{file:`droid`,ext:`webp`},jcode:{file:`jcode`,ext:`webp`},kilo:{file:`kilocode`,ext:`webp`},"kilo-gateway":{file:`kilocode-gateway`,ext:`webp`},openclaw:{file:`openclaw`,ext:`webp`},cowork:{file:`claude`,ext:`webp`},roo:{file:`roo`,ext:`webp`},continue:{file:`continue`,ext:`webp`},amp:{file:`amp`,ext:`webp`},qwen:{file:`qwen`,ext:`webp`},kiro:{file:`kiro`,ext:`webp`},kimchi:{file:`kimchi`,ext:`webp`},commandcode:{file:`commandcode`,ext:`webp`},cursor:{file:`cursor`,ext:`webp`},trae:{file:`trae`,ext:`webp`},traecn:{file:`trae`,ext:`webp`}};function s(e){let t=e.toLowerCase().trim();return o[t]??{file:t,ext:`webp`}}function c(e){let t=e.trim().split(/[\s-]+/).filter(Boolean);return t.length>=2?(t[0][0]+t[1][0]).toUpperCase():e.slice(0,2).toUpperCase()}var l=(0,r.memo)(function({icon:e,name:t,size:n=32,imageSize:o,style:l,className:u}){let[d,f]=(0,r.useState)(()=>a.has(e)),p=s(e),m=o??n;return(0,i.jsx)(`div`,{className:u,style:{width:`${n}px`,height:`${n}px`,borderRadius:`8px`,background:`var(--surface-2)`,display:`grid`,placeItems:`center`,flexShrink:0,overflow:`hidden`,border:`1px solid var(--inner-border)`,...l},role:`img`,"aria-label":`${t} provider`,children:d?(0,i.jsx)(`span`,{style:{fontSize:`${Math.max(10,Math.floor(n*.35))}px`,fontWeight:700,color:`var(--text-secondary)`},children:c(t)}):(0,i.jsx)(`img`,{src:`/assets/providers/${p.file}.${p.ext}`,alt:``,width:m,height:m,loading:`lazy`,decoding:`async`,style:{width:`${m}px`,height:`${m}px`,objectFit:`contain`,padding:p.ext===`svg`?`1px`:`2px`},onError:()=>{a.add(e),f(!0)}})})});export{l as t};
|
|
Binary file
|