cartethyia 2.7.7 → 2.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dashboard/assets/{BannedPage-B05aF8Dg.js → BannedPage-DeIbIiBU.js} +1 -1
- package/dist/dashboard/assets/BannedPage-DeIbIiBU.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-CLUhmjUy.js → CliToolDetailPage-BRWKPQPf.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-BRWKPQPf.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-CQmrqqrk.js → CliToolsPage-BP-Y5iHN.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-BP-Y5iHN.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-CHG_1Wr3.js → CombosPage-B7JHozVa.js} +1 -1
- package/dist/dashboard/assets/CombosPage-B7JHozVa.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-DPgbklad.js → ConsoleLogPage-GX7iGGcu.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-GX7iGGcu.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-pnfAqr_-.js → CustomizationPage-HVonbGEa.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-HVonbGEa.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-DGJuU2A6.js → HealthEventsModal-xaut4OJ9.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-xaut4OJ9.js.gz +0 -0
- package/dist/dashboard/assets/{InjectSystemPromptPanel-C-e2AMz6.js → InjectSystemPromptPanel-Cv-2Ol_K.js} +1 -1
- package/dist/dashboard/assets/InjectSystemPromptPanel-Cv-2Ol_K.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-J8wPbmfT.js → LoginPage-bKfz_b1K.js} +1 -1
- package/dist/dashboard/assets/LoginPage-bKfz_b1K.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-C6WlpU5E.js → ModelPicker-B-WQxx_H.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-B-WQxx_H.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-BSQnF2Lp.js → OverviewPage-Z9pJZFo8.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-Z9pJZFo8.js.gz +0 -0
- package/dist/dashboard/assets/{ProviderDetailPage-DK_e0FJz.js → ProviderDetailPage-CMeDBxR1.js} +1 -1
- package/dist/dashboard/assets/ProviderDetailPage-CMeDBxR1.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-D_a3r6Gc.js → ProvidersPage-BXPdOpG4.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-BXPdOpG4.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-BBTRBAQ3.js → ProxyPage-emlTuxz6.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-emlTuxz6.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-B2WqMSG1.js → QuotaPage-CMJKNYWb.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-CMJKNYWb.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-D7xp5Ij_.js → SettingsPage-BSy7EwGo.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-BSy7EwGo.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-LND6_Ss7.js → SetupPage-CUZrKs9r.js} +1 -1
- package/dist/dashboard/assets/SetupPage-CUZrKs9r.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-BzNnm6Bi.js → StudioPage-jWmUdDpy.js} +1 -1
- package/dist/dashboard/assets/StudioPage-jWmUdDpy.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-C1TbL24N.js → UsagePage-5F9tGVGG.js} +1 -1
- package/dist/dashboard/assets/UsagePage-5F9tGVGG.js.gz +0 -0
- package/dist/dashboard/assets/app-BEsU8hKs.css +2 -0
- package/dist/dashboard/assets/app-BEsU8hKs.css.gz +0 -0
- package/dist/dashboard/assets/{badge-BaX2GTrn.js → badge-DyI_mJfi.js} +1 -1
- package/dist/dashboard/assets/badge-DyI_mJfi.js.gz +0 -0
- package/dist/dashboard/assets/{banner-DFH4Bkte.js → banner-B-yXtCqb.js} +1 -1
- package/dist/dashboard/assets/banner-B-yXtCqb.js.gz +0 -0
- package/dist/dashboard/assets/{card-CxDw0lK6.js → card-_HwAEqFF.js} +1 -1
- package/dist/dashboard/assets/card-_HwAEqFF.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-DfS1ntiq.js → clipboard-button-ByjCk0o9.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-ByjCk0o9.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-BK-NRr5u.js → dialog-BZhOlfz-.js} +1 -1
- package/dist/dashboard/assets/dialog-BZhOlfz-.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-QqPul6sC.js → drawer-BADqIRYP.js} +1 -1
- package/dist/dashboard/assets/drawer-BADqIRYP.js.gz +0 -0
- package/dist/dashboard/assets/{entry-BMlYJVFj.js → entry-COaC-irN.js} +1 -1
- package/dist/dashboard/assets/entry-COaC-irN.js.gz +0 -0
- package/dist/dashboard/assets/{entry-vqGb8yVz.js → entry-Ca7LSCet.js} +3 -3
- package/dist/dashboard/assets/entry-Ca7LSCet.js.gz +0 -0
- package/dist/dashboard/assets/{entry-Dmx7gBiN.js → entry-PDd27uCd.js} +1 -1
- package/dist/dashboard/assets/entry-PDd27uCd.js.gz +0 -0
- package/dist/dashboard/assets/{formatters-DP-5E01-.js → formatters-DcHJyRiu.js} +1 -1
- package/dist/dashboard/assets/formatters-DcHJyRiu.js.gz +0 -0
- package/dist/dashboard/assets/{index-D36vCZht.js → index-CgKmFngv.js} +2 -2
- package/dist/dashboard/assets/index-CgKmFngv.js.gz +0 -0
- package/dist/dashboard/assets/{inline-CHJQwxLa.js → inline-B2BirKry.js} +1 -1
- package/dist/dashboard/assets/inline-B2BirKry.js.gz +0 -0
- package/dist/dashboard/assets/{input-BlmlizVV.js → input-D-qV9dKY.js} +1 -1
- package/dist/dashboard/assets/input-D-qV9dKY.js.gz +0 -0
- package/dist/dashboard/assets/{layout-Bz93I-yE.js → layout-B7tVWhtV.js} +1 -1
- package/dist/dashboard/assets/layout-B7tVWhtV.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-Ml16KCfu.js → list-row-CtkGE3bF.js} +1 -1
- package/dist/dashboard/assets/list-row-CtkGE3bF.js.gz +0 -0
- package/dist/dashboard/assets/{live-7_QpnYGu.js → live-DGizF06-.js} +1 -1
- package/dist/dashboard/assets/live-DGizF06-.js.gz +0 -0
- package/dist/dashboard/assets/{network-CuMDaTzT.js → network-C9UE-bOr.js} +1 -1
- package/dist/dashboard/assets/network-C9UE-bOr.js.gz +0 -0
- package/dist/dashboard/assets/{numbers-CoqpaDMx.js → numbers-BnAd22a_.js} +1 -1
- package/dist/dashboard/assets/numbers-BnAd22a_.js.gz +0 -0
- package/dist/dashboard/assets/{pagination-B5aOoweZ.js → pagination-BAywyMzS.js} +1 -1
- package/dist/dashboard/assets/pagination-BAywyMzS.js.gz +0 -0
- package/dist/dashboard/assets/{select-C9Ssle9b.js → select-BCOcv8WK.js} +1 -1
- package/dist/dashboard/assets/select-BCOcv8WK.js.gz +0 -0
- package/dist/dashboard/assets/{stack-j7cXjgYX.js → stack-ByKt3Q1g.js} +1 -1
- package/dist/dashboard/assets/stack-ByKt3Q1g.js.gz +0 -0
- package/dist/dashboard/assets/{state-DHmEnLa2.js → state-DXbGTx7N.js} +1 -1
- package/dist/dashboard/assets/state-DXbGTx7N.js.gz +0 -0
- package/dist/dashboard/assets/{switch-DmZcyTIC.js → switch-ZeTsW623.js} +1 -1
- package/dist/dashboard/assets/switch-ZeTsW623.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 +44 -44
- package/package.json +1 -1
- package/src/providers/integrations/qoder/qoder-grpc.ts +1 -1
- package/src/providers/operations/byok-wire-profile.ts +9 -12
- package/dist/dashboard/assets/BannedPage-B05aF8Dg.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-CLUhmjUy.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-CQmrqqrk.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CHG_1Wr3.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-DPgbklad.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-pnfAqr_-.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-DGJuU2A6.js.gz +0 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-C-e2AMz6.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-J8wPbmfT.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-C6WlpU5E.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-BSQnF2Lp.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-DK_e0FJz.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-D_a3r6Gc.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-BBTRBAQ3.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-B2WqMSG1.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-D7xp5Ij_.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-LND6_Ss7.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-BzNnm6Bi.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-C1TbL24N.js.gz +0 -0
- package/dist/dashboard/assets/app-mweRcsKp.css +0 -2
- package/dist/dashboard/assets/app-mweRcsKp.css.gz +0 -0
- package/dist/dashboard/assets/badge-BaX2GTrn.js.gz +0 -0
- package/dist/dashboard/assets/banner-DFH4Bkte.js.gz +0 -0
- package/dist/dashboard/assets/card-CxDw0lK6.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-DfS1ntiq.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BK-NRr5u.js.gz +0 -0
- package/dist/dashboard/assets/drawer-QqPul6sC.js.gz +0 -0
- package/dist/dashboard/assets/entry-BMlYJVFj.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dmx7gBiN.js.gz +0 -0
- package/dist/dashboard/assets/entry-vqGb8yVz.js.gz +0 -0
- package/dist/dashboard/assets/formatters-DP-5E01-.js.gz +0 -0
- package/dist/dashboard/assets/index-D36vCZht.js.gz +0 -0
- package/dist/dashboard/assets/inline-CHJQwxLa.js.gz +0 -0
- package/dist/dashboard/assets/input-BlmlizVV.js.gz +0 -0
- package/dist/dashboard/assets/layout-Bz93I-yE.js.gz +0 -0
- package/dist/dashboard/assets/list-row-Ml16KCfu.js.gz +0 -0
- package/dist/dashboard/assets/live-7_QpnYGu.js.gz +0 -0
- package/dist/dashboard/assets/network-CuMDaTzT.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CoqpaDMx.js.gz +0 -0
- package/dist/dashboard/assets/pagination-B5aOoweZ.js.gz +0 -0
- package/dist/dashboard/assets/select-C9Ssle9b.js.gz +0 -0
- package/dist/dashboard/assets/stack-j7cXjgYX.js.gz +0 -0
- package/dist/dashboard/assets/state-DHmEnLa2.js.gz +0 -0
- package/dist/dashboard/assets/switch-DmZcyTIC.js.gz +0 -0
- /package/dist/dashboard/assets/{app-DRnQLhsc.js → app-CTxoqyYB.js} +0 -0
- /package/dist/dashboard/assets/{app-DRnQLhsc.js.gz → app-CTxoqyYB.js.gz} +0 -0
package/dist/dashboard/assets/{ProviderDetailPage-DK_e0FJz.js → ProviderDetailPage-CMeDBxR1.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
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{h as T,l as E,m as D}from"./formatters-DP-5E01-.js";import{t as O}from"./eye-off-Bk5g2luF.js";import{t as k}from"./eye-C_hawfH4.js";import{t as A}from"./gauge-BbIMy7MB.js";import{t as j}from"./image-BPaouViG.js";import{n as M,r as N,t as P}from"./state-DHmEnLa2.js";import{t as F}from"./key-round-UkavsGxp.js";import{t as I}from"./layers-2-glBbjl.js";import{r as L}from"./use-modal-focus-By7oJoGd.js";import{r as R,t as z}from"./dialog-BK-NRr5u.js";import{t as ee}from"./pencil-768ysRAr.js";import{t as te}from"./plus-DIdX_g-x.js";import{t as ne}from"./power-off-Yjw9GMJh.js";import{t as B}from"./refresh-cw-BqJFk4sU.js";import{t as re}from"./rotate-ccw-CufcqITi.js";import{t as ie}from"./search-JOKus9rb.js";import{t as ae}from"./settings-2-Ds9DQp0t.js";import{t as oe}from"./trash-Cppn5c3R.js";import{t as se}from"./wrench-B6E1oEuY.js";import{C as ce,T as le,v as ue}from"./assert-CidQVoNo.js";import{i as de,l as fe,o as pe,t as V}from"./query-keys-YSoQOUh6.js";import{A as me,B as he,C as ge,D as _e,O as ve,S as ye,T as be,_ as xe,a as Se,b as Ce,c as we,d as Te,f as Ee,ft as De,g as Oe,h as ke,k as H,l as Ae,m as je,nt as Me,o as Ne,p as Pe,r as Fe,rt as Ie,tt as Le,u as Re,ut as ze,w as Be,x as Ve}from"./entry-vqGb8yVz.js";import{n as U,r as He,t as W}from"./card-CxDw0lK6.js";import{n as G}from"./download-dRFo5_Wu.js";import{f as Ue,i as We,l as K,n as Ge,r as Ke,s as qe,u as Je}from"./tokens-COzario9.js";import{t as Ye}from"./switch-DmZcyTIC.js";import{t as q}from"./badge-BaX2GTrn.js";import{n as J}from"./input-BlmlizVV.js";import{t as Y}from"./select-C9Ssle9b.js";import{t as Xe}from"./ProviderIcon-jjqXJDA3.js";import{t as X}from"./stack-j7cXjgYX.js";import{n as Z,t as Ze}from"./inline-CHJQwxLa.js";import{s as Qe,t as $e}from"./api-keys-KvX83mRe.js";import{a as et,l as tt,u as nt}from"./quota-DJ1QlAOq.js";import{t as rt}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,l as mt,o as ht,t as gt}from"./HealthEventsModal-DGJuU2A6.js";import{r as _t}from"./privacy-mode-GM8bej85.js";import{t as vt}from"./use-timeout-BwcBBRrT.js";var yt=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`}]]),bt=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`}]]),xt=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`}]]),St=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`}]]),Ct=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`}]]),wt=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`}]]),Tt=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`}]]),Et=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`}]]),Dt=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`}]]),Ot=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`}]]),kt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function At(e,t){return t===null?e:`${e}(${t})`}var Q=t(n(),1),$=r();function jt({to:e,label:t}){let n=Le();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,$.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function Mt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,$.jsx)(jt,{...a}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,$.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,$.jsx)(`div`,{className:y(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function Nt(e){return e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function Pt(e,t=600){let n=(0,Q.useRef)(void 0);return(0,Q.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var Ft={fallback:`Failover`,roundRobin:`Round robin`},It=new Set([`inferhub`,`cline`]);function Lt(e,t){let n=at(e),r=ot(),[i,a]=(0,Q.useState)(`fallback`),[o,s]=(0,Q.useState)(1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(`percent`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent),x(n.data.customUserAgent??null))},[n.data]);let S=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}:{},customUserAgent:i.customUserAgent}},{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(n.data.customUserAgent??null))}})},C=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),w=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),T=Pt(e=>S({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),E=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e,customUserAgent:b})),D=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v,customUserAgent:b})},skipProxy:g,userAgent:v,customUserAgent:b,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),C(e)},setMaxInflightPerProxy:e=>{d(e),w(e)},setUserAgent:e=>{y(e),E(e)},setCustomUserAgent:e=>{x(e),D(e)},setSkipProxy:e=>{_(e),S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v,customUserAgent:b})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),S({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})},rotateCount:o,setRotateCount:e=>{s(e),T(e)}}}var Rt=[{value:`least_loaded`,label:`Least loaded`},{value:`round_robin`,label:`Round robin`},{value:`random`,label:`Random`}],zt=50,Bt=100;function Vt({children:e,action:t}){return(0,$.jsx)(st,{actions:t,children:e})}function Ht({providerId:e,clientVersion:t,userAgentEditable:n}){let r=Lt(e,n),i=ct(),a=dt(),[o,s]=(0,Q.useState)(!1),[c,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=It.has(e);if(r.isLoading)return(0,$.jsx)(N,{label:`Loading routing...`});if(r.isError)return(0,$.jsx)(M,{message:`Failed to load routing`,onRetry:r.refetch});let m=r.roundRobinEnabled?`${Ft.roundRobin} · ${r.rotateCount} account${r.rotateCount===1?``:`s`} per rotation`:Ft.fallback,g=i.data,_=Rt.find(e=>e.value===g?.strategy),v=g===void 0?`…`:r.skipProxy?`Direct — proxy pools bypassed`:_?g.strategy===`round_robin`?`${_.label} · ${g.rotateCount} per rotation`:_.label:`Unset`,b=r.isSaving?`Saving...`:r.saveFailed?`Save failed — reverted to last saved value`:`Per-account and per-pool routing`,x=r.maxInflight===null,S=x?51:Math.min(51,Math.max(1,r.maxInflight)),C=x?`∞`:String(r.maxInflight),w=r.maxInflightPerProxy===null,T=w?51:Math.min(51,Math.max(1,r.maxInflightPerProxy)),E=w?`∞`:String(r.maxInflightPerProxy),D=r.skipProxy,O=e=>{r.setRotateCount(Math.min(1e3,Math.max(1,r.rotateCount+e)))},k=e=>{e!==g?.strategy&&a.mutate({strategy:e})},j=e=>{g&&a.mutate({rotateCount:Math.min(1e3,Math.max(1,g.rotateCount+e))})},P=t?`${t.client} ${t.version}`:`Provider default`;return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`Routing Strategy`,subtitle:b,icon:(0,$.jsx)(I,{size:16})}),(0,$.jsx)(U,{children:(0,$.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,$.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Provider accounts`}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(`span`,{className:`status-indicator-dot${r.roundRobinEnabled?` bg-accent`:` bg-text-tertiary`}`,"aria-hidden":`true`}),m]})]}),(0,$.jsx)(Vt,{action:(0,$.jsxs)($.Fragment,{children:[r.roundRobinEnabled?(0,$.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:r.rotateCount<=1,icon:(0,$.jsx)(R,{size:14}),onClick:()=>O(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:r.rotateCount}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:r.rotateCount>=1e3,icon:(0,$.jsx)(te,{size:14}),onClick:()=>O(1)})]}):null,(0,$.jsx)(Ye,{checked:r.roundRobinEnabled,onChange:r.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(wt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Rotate accounts`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,$.jsx)(Vt,{action:(0,$.jsx)(Ye,{checked:r.skipProxy,onChange:r.setSkipProxy,id:`routing-skip-proxy`}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(yt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,$.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Proxy pools`}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(`span`,{className:`status-indicator-dot${r.skipProxy?` bg-text-tertiary`:` bg-accent`}`,"aria-hidden":`true`}),v]}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0 -my-1`,"aria-label":`How pool routing works`,onClick:()=>u(!0),children:`How it works`})]}),(0,$.jsx)(Vt,{action:(0,$.jsxs)(Z,{gap:`8px`,align:`center`,children:[g?.strategy===`round_robin`&&!r.skipProxy?(0,$.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,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Pools/rotation`}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease pools per rotation`,disabled:a.isPending||g.rotateCount<=1,icon:(0,$.jsx)(R,{size:14}),onClick:()=>j(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:g.rotateCount}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase pools per rotation`,disabled:a.isPending||g.rotateCount>=1e3,icon:(0,$.jsx)(te,{size:14}),onClick:()=>j(1)})]}):null,(0,$.jsx)(Y,{id:`routing-pool-strategy`,"aria-label":`Pool selection mode`,value:g?.strategy??``,disabled:r.skipProxy||a.isPending,options:Rt,onValueChange:k})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-pool-strategy`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(Et,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.skipProxy?`text-text-tertiary`:`text-accent`}`}),`Pool mode`]})}),(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`How proxy pools are chosen when this provider dials one.`,r.skipProxy?` Disabled while “Always direct” is on.`:``]})]})})]}),(0,$.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${d?` opacity-60`:``}`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,$.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{id:`routing-user-agent-custom`,"aria-label":`Custom User-Agent override`,disabled:d,value:r.customUserAgent??``,placeholder:P,spellCheck:!1,onChange:e=>{let t=e.target.value;r.setCustomUserAgent(t.trim()===``?null:t)}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-micro text-text-tertiary`,children:`Custom User-Agent — leave empty to use the native identity below`}),r.customUserAgent===null?null:(0,$.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>r.setCustomUserAgent(null),title:`Reset to the provider's native identity`,children:`Reset`})]}),(0,$.jsxs)(`div`,{className:`text-micro text-text-tertiary`,children:[`Native identity: `,(0,$.jsx)(`code`,{className:`font-mono`,children:P}),`,`,` `,r.customUserAgent===null?`used as-is`:`overridden by the custom value above`]})]}):(0,$.jsx)(J,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:P}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-1`,children:d?`Locked while Advanced is open — collapse Advanced to edit.`:n?`Type a custom User-Agent to override the provider's identity (saved automatically); Reset clears it back to native.`:`Set by the provider. It cannot be changed.`})]})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(A,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,$.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,zt,` is unlimited.`]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":x?`true`:void 0,min:1,max:51,step:1,value:S,"aria-valuetext":x?`Unlimited`:String(r.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r.setMaxInflight(t>zt?null:Math.round(t))},style:{"--slider-pct":`${S/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:C,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){r.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&r.setMaxInflight(Math.min(Bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${x?`text-status-success`:``}`})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":d,"aria-label":d?`Collapse Advanced`:`Expand Advanced`,onClick:()=>f(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-4 py-3 text-left text-inherit`,children:[(0,$.jsx)(De,{size:15,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!d&&`-rotate-90`)}),(0,$.jsx)(ae,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Advanced`}),(0,$.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:`Max inflight / proxy`})]}),d?(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(Ot,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>s(!0),children:`How it works`})]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":w?`true`:void 0,min:1,max:51,step:1,disabled:D,value:T,"aria-valuetext":w?`Unlimited`:String(r.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r.setMaxInflightPerProxy(t>zt?null:Math.round(t))},style:{"--slider-pct":`${T/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:D,value:E,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){r.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&r.setMaxInflightPerProxy(Math.min(Bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${w?`text-status-success`:``}`})]}),(0,$.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:D?`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 ${zt} is unlimited.`})]})}):null]}),(0,$.jsx)(z,{open:o,onClose:()=>s(!1),title:`How concurrency limits stack`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,$.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`API key concurrency`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`The key's `,(0,$.jsx)(`em`,{children:`own`}),` limit (`,` `,(0,$.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,$.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,$.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),(0,$.jsx)(z,{open:c,onClose:()=>u(!1),title:`How pool routing works`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.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,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Least loaded`}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Round robin`}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Random`}),(0,$.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,$.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Turning on “Always direct” bypasses pools entirely — this mode has no effect then.`})]})}),p&&(0,$.jsxs)(Z,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,$.jsx)(xt,{size:12,className:`shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function 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 ce({queryKey:V.inferhub.summary,queryFn:e=>pe(`/inferhub/summary`,{signal:ue(e)}).then(Ut),enabled:e,...de,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,Q.useState)(!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(`provider`),[u,d]=(0,Q.useState)(!1),f=t?.models??[],p=f.filter($t),m=(0,Q.useMemo)(()=>{let e=[...i?f:p].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}))},[f,p,i,c]),g=(0,$.jsxs)(h,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,$.jsx)(B,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,$.jsx)(B,{size:16})}),(0,$.jsx)(U,{children:e.isError?(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`InferHub market`,icon:(0,$.jsx)(B,{size:16}),action:g}),(0,$.jsx)(U,{children:(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let _=m,v=_.reduce((e,t)=>e+t.models.length,0),b=f.length-v;return(0,$.jsxs)(W,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-center gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,$.jsx)(De,{size:15,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,$.jsxs)(X,{gap:`1px`,children:[(0,$.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,qt(t.meta.ageSeconds)]}):null]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:n?g:null})]}),n?(0,$.jsxs)(U,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(nn,{onSaved:()=>void e.refetch()}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,$.jsx)(Y,{value:c,onValueChange:e=>l(e),options:Object.keys(Jt).map(e=>({value:e,label:Jt[e]})),"aria-label":`Sort InferHub models`})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,$.jsxs)(rt,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,$.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,$.jsxs)(rt,{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,$.jsxs)(rt,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,qt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[v,` of `,f.length,` models`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(h,{size:`sm`,variant:`secondary`,onClick:()=>d(e=>!e),title:u?`Expand all provider groups`:`Collapse all provider groups`,children:u?`Expand all`:`Collapse all`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,b>0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,b,` hidden)`]}):null]})]})]}),_.length===0?(0,$.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:_.map(e=>(0,$.jsx)(tn,{group:e,showUpstreams:o,summary:t,collapsedAll:u},e.prefix))})]}):null]})}function tn({group:e,showUpstreams:t,summary:n,collapsedAll:r}){let[i,a]=(0,Q.useState)(!0),o=!r&&i,s=Qt(n,e.prefix),c=s?.familyState??null,l=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,$.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":o,"aria-label":`${o?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>a(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,$.jsx)(De,{size:14,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!o&&`-rotate-90`)}),(0,$.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,$.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),c===null?null:(0,$.jsx)(q,{tone:Zt(c),dot:!0,children:c.replace(/_/g,` `)}),t&&s!==void 0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Kt(s.availability24hPct),` · 7d`,` `,Kt(s.availability7dPct)]}):null,(0,$.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),o?(0,$.jsxs)(`div`,{className:`px-3 pb-3`,children:[l===null?null:(0,$.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:l}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,$.jsx)(`tbody`,{children:e.models.map(e=>(0,$.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,$.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,$.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Gt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,$.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Gt(e.capacityPriceIn),` sustainable`]}):null]}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Gt(e.minAskOut)}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,$.jsx)(q,{children:`none`}):e.providersLive}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Kt(t?s?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function nn({onSaved:e}){let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await pe(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await pe(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,$.jsx)(J,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,$.jsx)(h,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,$.jsx)(h,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,$.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),(0,$.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:(0,$.jsxs)(`a`,{href:`https://inferhub.dev/`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-accent hover:underline`,children:[(0,$.jsx)(ze,{size:12,"aria-hidden":`true`}),`inferhub.dev — create a `,(0,$.jsx)(`code`,{children:`config_read`}),` key`]})}),s===null?null:(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function rn({providerId:e}){let t=Lt(e,!1),n=pt(),r=it(e),[i,a]=(0,Q.useState)(!1),o=(0,Q.useMemo)(()=>on(n.data?.accounts??[],e),[n.data,e]),s=(0,Q.useRef)(null),c=(0,Q.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Q.useEffect)(()=>{if(s.current===null){s.current=c;return}s.current!==c&&(s.current=c,n.refetch())},[c,n]);let[l,u]=(0,Q.useState)(`40`),[d,f]=(0,Q.useState)(`percent`),p=t.usageFloor!==null;(0,Q.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,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(A,{size:14}),(0,$.jsx)(`span`,{children:`Usage floor`}),(0,$.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,icon:(0,$.jsx)(w,{size:14}),"aria-label":`How the usage floor works`,onClick:()=>a(!0),children:`How it works`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[o!==null&&(0,$.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`Pooled credits`}),(0,$.jsx)(`span`,{className:`text-text-primary`,children:o.accounts}),(0,$.jsx)(`span`,{children:o.accounts===1?`active account`:`active accounts`}),o.inactiveAccounts>0?(0,$.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,$.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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`strong`,{className:`font-bold ${_}`,children:sn(o.remaining)}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,$.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,sn(o.total)]}),(0,$.jsxs)(`span`,{className:`font-bold ${_}`,children:[o.percent,`%`]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`strong`,{className:`font-bold ${_}`,children:[o.percent,`% left`]}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`lowest independent window`})]})}),(0,$.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,$.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`No quota data is available for these accounts yet. Exhausted quota windows are still skipped.`}),(0,$.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,$.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,$.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,$.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,$.jsx)(`input`,{type:`number`,min:0,max:1e6,value: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,$.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,$.jsx)(`option`,{value:`percent`,children:`%`}),(0,$.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,$.jsx)(Ye,{checked:p,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>v(e?g?m:40:null,d)})]}),t.saveFailed?(0,$.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,$.jsx)(an,{providerId:e}),(0,$.jsx)(z,{open:i,onClose:()=>a(!1),title:`How the usage floor works`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 text-badge leading-relaxed text-text-secondary`,children:[(0,$.jsxs)(`p`,{children:[`The usage floor is a `,(0,$.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,$.jsxs)(`p`,{children:[(0,$.jsx)(`strong`,{children:`Credit mode`}),` sums absolute remaining credits across pooled windows. `,(0,$.jsx)(`strong`,{children:`Percent mode`}),` uses the aggregate credit percentage and the lowest independent percentage window. An account with `,(0,$.jsx)(`em`,{children:`unknown`}),` quota is never treated as below the floor.`]}),(0,$.jsxs)(`p`,{children:[(0,$.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,$.jsx)(`code`,{children:`0 left`}),`), it is skipped for free-tier models too.`]}),(0,$.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}=_t(e);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(O,{size:14}),(0,$.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,$.jsx)(Ye,{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,$.jsx)(W,{density:`compact`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(Z,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,$.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`br`,{}),r]}):null]}),t?(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:v({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,$.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,$.jsx)(ze,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function ln({provider:e}){let t=H(),[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.baseUrl??``);(0,Q.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,$.jsx)(b,{size:16})}),(0,$.jsx)(U,{children:(0,$.jsxs)(X,{gap:`12px`,children:[n?(0,$.jsx)(J,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,$.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,$.jsxs)(Z,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(Tt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(L,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(ee,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(F,{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=mt(e),i=n.isPending||r.isPending;return(0,$.jsx)(h,{size:`sm`,variant:`secondary`,title:`Manually claim available ZCode gift plans`,"aria-label":`Claim gifts for ${t}`,disabled:i,icon:i?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(bt,{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`,fe(e,`Refresh quota manually`))})},onError:e=>g.error(`Gift claim failed`,fe(e,`Unable to claim gift plans`))}),children:i?`Claiming…`:`Claim gifts`})}function mn({accountId:e,accountName:t}){let n=ht(e),r=n.isPending;return(0,$.jsx)(h,{size:`sm`,variant:`secondary`,title:`Manually claim the Qoder daily CREDITS campaign`,"aria-label":`Claim credits for ${t}`,disabled:r,icon:r?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(D,{size:12}),onClick:()=>n.mutate(void 0,{onSuccess:e=>{switch(e.state){case`claimed`:g.success(`Qoder credits claimed`,`+${e.amount} credits granted`);break;case`already_claimed`:g.success(`Qoder credits already claimed`,e.detail??void 0);break;case`nothing`:g.success(`No CREDITS campaign`,`No claimable CREDITS campaign is visible for this account right now.`);break;case`error`:g.error(`Qoder credit claim failed`,e.detail??`Claim failed`)}},onError:e=>g.error(`Qoder credit claim failed`,fe(e,`Unable to claim credits`))}),children:r?`Claiming…`:`Claim credits`})}var hn={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`},gn=new Set([`quota_fetch_failed`]);function _n(e){return e===void 0||e.length===0?!1:!gn.has(e)}function vn(e){return e===`oauth`?`Re-login required`:`Replace API key`}function yn(e,t,n){return e===`auth_invalidated`?vn(t):e===`policy_blocked_banned`&&n===`github`?`No Copilot access`:hn[e]??e}var bn=/https?:\/\/[^\s"'\\]+/;function xn(e){if(e)return bn.exec(e)?.[0]}function Sn({cooldowns:e,reason:t}){if(!e)return null;let n=et(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,$.jsxs)(q,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function Cn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function wn(e){if(!_n(e.lastErrorCategory)||e.lastErrorCategory===`quota_exhausted`&&dn(e))return null;let t=yn(e.lastErrorCategory,e.credentialKind,e.providerId),n=e.lastError??e.lastErrorCategory;if(e.lastErrorCategory===`policy_blocked_banned`&&e.providerId===`github`)return(0,$.jsx)(q,{tone:`err`,dot:!0,title:n,children:t});if(e.lastErrorCategory===`validation_required`){let r=xn(e.lastError);if(r!==void 0)return(0,$.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,title:n,children:(0,$.jsxs)(q,{tone:`warn`,children:[t,(0,$.jsx)(ze,{size:12,className:`shrink-0`,"aria-hidden":`true`})]})})}return(0,$.jsx)(q,{tone:`warn`,title:n,children:t})}function Tn(e){return e.credentialKind===`oauth`?`blue`:`ok`}function En({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,$.jsx)(q,{tone:`warn`,title:`${o} — resets ${et(new Date(a).toISOString())}`,children:i?`Egress blocked`:`Rate-limited`})}function Dn({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=Cn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,$.jsx)(q,{tone:`warn`,title:e.lastError,children:vn(e.credentialKind)}):wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:Tn(e),dot:!0,children:[`Active`,Cn(e)?` - ${Cn(e)}`:``]}),(0,$.jsx)(En,{account:e}),wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`warn`,dot:!0,children:[`Cooldown`,Cn(e)?` - ${Cn(e)}`:``,` `,e.cooldownUntil?`(${et(e.cooldownUntil)})`:``]}),(0,$.jsx)(En,{account:e}),wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,$.jsx)(q,{tone:`disabled`,children:`Disabled`})}function On(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 kn(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()}`:et(e,!1)}function An({windows:e}){let t=tt(e??[]),n=e?.filter(e=>nt(e)!==`current`)??[];return(0,$.jsxs)($.Fragment,{children:[t.text!==null&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":t.low?`warn`:void 0,title:t.hasCredits?`${jn(t.remaining)} credits available`:`Current model grants and account-wide quota limits`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),t.text]}),n.map((e,t)=>(0,$.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[e.label,e.modelIds?.length?` · ${e.modelIds.join(`, `)}`:``,` · `,nt(e)===`expired`?`Expired`:`Not started yet · Starts ${new Date(e.startsAt).toLocaleString()}`]},`${e.kind??e.label}:${e.startsAt}:${t}`))]})}function jn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Mn({providerId:e,account:t,onClose:n}){let r=me(),[i,a]=(0,Q.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{g.error(`Clipboard access denied`)}};return(0,$.jsx)(z,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,$.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,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,$.jsxs)(X,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,$.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,$.jsx)(Z,{gap:`8px`,className:`justify-end`,children:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Nn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=me(),l=Ce(),u=mt(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,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[,k]=(0,Q.useState)(0),[A,j]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(``),R=_t(e),te=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),B=R.enabled?`Mysterious accounts`:te,ie=kn(t.tokenExpiresAt),ae=fn(t),se=Math.max(x&&t.cooldownUntil?b:0,ae??0);(0,Q.useEffect)(()=>{if(se<=Date.now())return;let e=setInterval(()=>k(e=>e+1),1e3);return()=>clearInterval(e)},[se]);let ce=()=>{let n=I.trim();j(!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,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:y?.62:1},children:[(0,$.jsx)(`div`,{className:`flex items-center`,children:(0,$.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${B}`,className:`cursor-pointer`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:A?(0,$.jsx)(J,{value:I,onChange:e=>L(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&j(!1)},onBlur:ce,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:B}),m?(0,$.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=On(t.authMethod);return e===null?null:(0,$.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,$.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 ${B}`,onClick:()=>{L(t.label??``),j(!0)},children:(0,$.jsx)(ee,{size:11})})]})}),(0,$.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,$.jsx)(Dn,{account:t}),ie?(0,$.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:ie,children:ie}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,$.jsx)(An,{windows:r}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,$.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[e===`zcode-start`&&!m&&(0,$.jsx)(pn,{accountId:t.id,accountName:B}),(e===`qoder`||e===`qodercn`)&&!m&&(0,$.jsx)(mn,{accountId:t.id,accountName:B}),m?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${B}`,onClick:()=>E(!0),title:`View pool health & error history`}):(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${B}`,onClick:()=>w(!0),title:`View Health & Error History`}),m?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:d.isPending?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(p,{size:12}),label:d.isPending?`Testing…`:`Test`,"aria-label":`Test ${B}`,disabled:d.isPending||_===void 0,onClick:()=>{_&&d.mutate({poolId:_,providerId:e},{onSuccess:e=>{e.status===`allowed`?g.success(`Pool probe passed`,B):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,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(p,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${B}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?g.success(`Account test passed`,B):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,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(F,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${B}`,onClick:()=>O(!0),title:`Replace API key`}),m?null:(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:y?(0,$.jsx)(St,{size:12}):(0,$.jsx)(ne,{size:12}),label:y?`Enable`:`Disable`,"aria-label":y?`Enable ${B}`:`Disable ${B}`,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`,B),onError:e=>g.error(`Update failed`,e.message??`Unable to update account`)})},title:y?`Enable account`:`Disable account`}),S?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(re,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${B}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,m?null:(0,$.jsx)(h,{size:`icon`,variant:`danger`,icon:(0,$.jsx)(oe,{size:12}),label:`Delete`,"aria-label":`Delete ${B}`,onClick:()=>s(t),title:`Delete account`})]})]}),C&&(0,$.jsx)(gt,{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,$.jsx)(Mn,{providerId:e,account:t,onClose:()=>O(!1)}),T&&(0,$.jsx)(z,{open:!0,title:`Pool Health & Error History`,onClose:()=>E(!1),width:640,footer:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>E(!1),children:`Close`}),children:(0,$.jsx)(`div`,{className:`flex flex-col gap-3 min-h-40`,children:v.isPending?(0,$.jsx)(N,{label:`Loading pool health events…`}):v.isError?(0,$.jsx)(M,{message:`Failed to load pool health events`,onRetry:()=>void v.refetch()}):(v.data??[]).length===0?(0,$.jsx)(P,{compact:!0,title:`No health events recorded`,message:`Status transitions, rate limits, and auto-recoveries will appear here.`}):(0,$.jsx)(`div`,{className:`scroll-region max-h-160 overflow-y-auto pr-1 flex flex-col gap-3`,children:(v.data??[]).map(e=>(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-badge`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`span`,{className:`font-mono tabular-nums text-micro text-text-tertiary`,children:new Date(e.createdAt).toLocaleString()}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-text-tertiary text-micro uppercase tracking-label`,children:[e.fromStatus??`—`,` → `,e.toStatus]}),e.errorCategory?(0,$.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,$.jsx)(`p`,{className:`mt-2 text-micro text-text-secondary [overflow-wrap:anywhere] break-words`,children:e.reason}):null]},e.id))})})})]})}var Pn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Fn=[`refresh`,`refreshToken`,`refresh_token`],In=[`credentialKind`,`providerId`,`accessToken`],Ln=[`accounts`,`items`,`connections`],Rn=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function zn(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Bn(e){let t=e.data;if(typeof t==`string`)try{return zn(JSON.parse(t))}catch{return}return zn(t)}function Vn(e){for(let t of Pn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Bn(e);if(t)for(let e of Pn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Hn(e){for(let t of Rn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Bn(e);if(t)for(let e of Rn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Un(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,Fn);if(n(e))return!0;let r=Bn(e);return r?n(r):!1}function Wn(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 zn(JSON.parse(atob(n)))}catch{return}}function Gn(e){let t=Wn(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 Kn(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 qn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var Jn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function Yn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of Jn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function Xn(e){let t=e.trim(),n=zn(qn(t))??Kn(t);return n&&Un(n)?`oauth`:Wn((n?Vn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Zn(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 Qn(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 $n(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&In.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&Un(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=Vn(e),r=Un(e)?`oauth`:Xn(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Hn(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function er(e){for(let t of Ln){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>zn(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function tr(e){let t=e.trim();if(!t)return[];let n=qn(t);if(Array.isArray(n)){let e=n.map(e=>zn(e)).filter(e=>e!==void 0);if(e.length>0)return Zn(e)?[Qn(t,e)]:e.map($n)}else{let e=zn(n);if(e){let t=er(e);return t?t.map($n):[$n(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=Kn(r[0]);return e?[$n(e)]:nr(r[0])}let i=Kn(t);return i&&(Vn(i)||Object.keys(i).length===r.length)?[$n(i)]:r.flatMap(nr)}function nr(e){let t=zn(qn(e));if(t){let e=er(t);return e?e.map($n):[$n(t)]}let n=rr(e);return n.length>0?n:[{value:e,kind:Xn(e)}]}function rr(e){let t=e.indexOf(`|`);if(t<=0)return[];let n=e.slice(0,t).trim(),r=e.slice(t+1).trim();return!n||!r?[]:[{value:r,kind:Xn(r),identity:n}]}function ir(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 ar(e){let t=[];for(let n of e){let e=n.text.trim();if(!e)continue;let r=qn(e);if(Array.isArray(r)){let n=r.filter(e=>zn(e)!==void 0);if(n.length>0&&Zn(n)){t.push(e);continue}for(let e of r){let n=zn(e);t.push(n===void 0?String(e):JSON.stringify(n))}continue}let i=zn(r);if(i){let n=er(i);if(n!==void 0){for(let e of n)t.push(JSON.stringify(e));continue}t.push(e);continue}tr(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(`
|
|
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-BnAd22a_.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{h as T,l as E,m as D}from"./formatters-DcHJyRiu.js";import{t as O}from"./eye-off-Bk5g2luF.js";import{t as k}from"./eye-C_hawfH4.js";import{t as A}from"./gauge-BbIMy7MB.js";import{t as j}from"./image-BPaouViG.js";import{n as M,r as N,t as P}from"./state-DXbGTx7N.js";import{t as F}from"./key-round-UkavsGxp.js";import{t as I}from"./layers-2-glBbjl.js";import{r as L}from"./use-modal-focus-By7oJoGd.js";import{r as R,t as z}from"./dialog-BZhOlfz-.js";import{t as ee}from"./pencil-768ysRAr.js";import{t as te}from"./plus-DIdX_g-x.js";import{t as ne}from"./power-off-Yjw9GMJh.js";import{t as B}from"./refresh-cw-BqJFk4sU.js";import{t as re}from"./rotate-ccw-CufcqITi.js";import{t as ie}from"./search-JOKus9rb.js";import{t as ae}from"./settings-2-Ds9DQp0t.js";import{t as oe}from"./trash-Cppn5c3R.js";import{t as se}from"./wrench-B6E1oEuY.js";import{C as ce,T as le,v as ue}from"./assert-CidQVoNo.js";import{i as de,l as fe,o as pe,t as V}from"./query-keys-YSoQOUh6.js";import{A as me,B as he,C as ge,D as _e,O as ve,S as ye,T as be,_ as xe,a as Se,b as Ce,c as we,d as Te,f as Ee,ft as De,g as Oe,h as ke,k as H,l as Ae,m as je,nt as Me,o as Ne,p as Pe,r as Fe,rt as Ie,tt as Le,u as Re,ut as ze,w as Be,x as Ve}from"./entry-Ca7LSCet.js";import{n as U,r as He,t as W}from"./card-_HwAEqFF.js";import{n as G}from"./download-dRFo5_Wu.js";import{f as Ue,i as We,l as K,n as Ge,r as Ke,s as qe,u as Je}from"./tokens-COzario9.js";import{t as Ye}from"./switch-ZeTsW623.js";import{t as q}from"./badge-DyI_mJfi.js";import{n as J}from"./input-D-qV9dKY.js";import{t as Y}from"./select-BCOcv8WK.js";import{t as Xe}from"./ProviderIcon-jjqXJDA3.js";import{t as X}from"./stack-ByKt3Q1g.js";import{n as Z,t as Ze}from"./inline-B2BirKry.js";import{s as Qe,t as $e}from"./api-keys-KvX83mRe.js";import{a as et,l as tt,u as nt}from"./quota-DJ1QlAOq.js";import{t as rt}from"./banner-B-yXtCqb.js";import{c as it,l as at,m as ot}from"./routing-fnCsxgNO.js";import{t as st}from"./list-row-CtkGE3bF.js";import{d as ct,l as lt,u as ut,y as dt}from"./network-C9UE-bOr.js";import{a as ft,c as pt,l as mt,o as ht,t as gt}from"./HealthEventsModal-xaut4OJ9.js";import{r as _t}from"./privacy-mode-GM8bej85.js";import{t as vt}from"./use-timeout-BwcBBRrT.js";var yt=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`}]]),bt=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`}]]),xt=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`}]]),St=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`}]]),Ct=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`}]]),wt=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`}]]),Tt=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`}]]),Et=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`}]]),Dt=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`}]]),Ot=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`}]]),kt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function At(e,t){return t===null?e:`${e}(${t})`}var Q=t(n(),1),$=r();function jt({to:e,label:t}){let n=Le();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,$.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function Mt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,$.jsx)(jt,{...a}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,$.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,$.jsx)(`div`,{className:y(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function Nt(e){return e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function Pt(e,t=600){let n=(0,Q.useRef)(void 0);return(0,Q.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var Ft={fallback:`Failover`,roundRobin:`Round robin`},It=new Set([`inferhub`,`cline`]);function Lt(e,t){let n=at(e),r=ot(),[i,a]=(0,Q.useState)(`fallback`),[o,s]=(0,Q.useState)(1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(`percent`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent),x(n.data.customUserAgent??null))},[n.data]);let S=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}:{},customUserAgent:i.customUserAgent}},{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(n.data.customUserAgent??null))}})},C=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),w=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),T=Pt(e=>S({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})),E=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e,customUserAgent:b})),D=Pt(e=>S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v,customUserAgent:b})},skipProxy:g,userAgent:v,customUserAgent:b,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),C(e)},setMaxInflightPerProxy:e=>{d(e),w(e)},setUserAgent:e=>{y(e),E(e)},setCustomUserAgent:e=>{x(e),D(e)},setSkipProxy:e=>{_(e),S({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v,customUserAgent:b})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),S({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v,customUserAgent:b})},rotateCount:o,setRotateCount:e=>{s(e),T(e)}}}var Rt=[{value:`least_loaded`,label:`Least loaded`},{value:`round_robin`,label:`Round robin`},{value:`random`,label:`Random`}],zt=50,Bt=100;function Vt({children:e,action:t}){return(0,$.jsx)(st,{actions:t,children:e})}function Ht({providerId:e,clientVersion:t,userAgentEditable:n}){let r=Lt(e,n),i=ct(),a=dt(),[o,s]=(0,Q.useState)(!1),[c,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=It.has(e);if(r.isLoading)return(0,$.jsx)(N,{label:`Loading routing...`});if(r.isError)return(0,$.jsx)(M,{message:`Failed to load routing`,onRetry:r.refetch});let m=r.roundRobinEnabled?`${Ft.roundRobin} · ${r.rotateCount} account${r.rotateCount===1?``:`s`} per rotation`:Ft.fallback,g=i.data,_=Rt.find(e=>e.value===g?.strategy),v=g===void 0?`…`:r.skipProxy?`Direct — proxy pools bypassed`:_?g.strategy===`round_robin`?`${_.label} · ${g.rotateCount} per rotation`:_.label:`Unset`,b=r.isSaving?`Saving...`:r.saveFailed?`Save failed — reverted to last saved value`:`Per-account and per-pool routing`,x=r.maxInflight===null,S=x?51:Math.min(51,Math.max(1,r.maxInflight)),C=x?`∞`:String(r.maxInflight),w=r.maxInflightPerProxy===null,T=w?51:Math.min(51,Math.max(1,r.maxInflightPerProxy)),E=w?`∞`:String(r.maxInflightPerProxy),D=r.skipProxy,O=e=>{r.setRotateCount(Math.min(1e3,Math.max(1,r.rotateCount+e)))},k=e=>{e!==g?.strategy&&a.mutate({strategy:e})},j=e=>{g&&a.mutate({rotateCount:Math.min(1e3,Math.max(1,g.rotateCount+e))})},P=t?`${t.client} ${t.version}`:`Provider default`;return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`Routing Strategy`,subtitle:b,icon:(0,$.jsx)(I,{size:16})}),(0,$.jsx)(U,{children:(0,$.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,$.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Provider accounts`}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(`span`,{className:`status-indicator-dot${r.roundRobinEnabled?` bg-accent`:` bg-text-tertiary`}`,"aria-hidden":`true`}),m]})]}),(0,$.jsx)(Vt,{action:(0,$.jsxs)($.Fragment,{children:[r.roundRobinEnabled?(0,$.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:r.rotateCount<=1,icon:(0,$.jsx)(R,{size:14}),onClick:()=>O(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:r.rotateCount}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:r.rotateCount>=1e3,icon:(0,$.jsx)(te,{size:14}),onClick:()=>O(1)})]}):null,(0,$.jsx)(Ye,{checked:r.roundRobinEnabled,onChange:r.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(wt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Rotate accounts`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,$.jsx)(Vt,{action:(0,$.jsx)(Ye,{checked:r.skipProxy,onChange:r.setSkipProxy,id:`routing-skip-proxy`}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(yt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-inner-border pb-3`,children:[(0,$.jsx)(`span`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Proxy pools`}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(`span`,{className:`status-indicator-dot${r.skipProxy?` bg-text-tertiary`:` bg-accent`}`,"aria-hidden":`true`}),v]}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0 -my-1`,"aria-label":`How pool routing works`,onClick:()=>u(!0),children:`How it works`})]}),(0,$.jsx)(Vt,{action:(0,$.jsxs)(Z,{gap:`8px`,align:`center`,children:[g?.strategy===`round_robin`&&!r.skipProxy?(0,$.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,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Pools/rotation`}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease pools per rotation`,disabled:a.isPending||g.rotateCount<=1,icon:(0,$.jsx)(R,{size:14}),onClick:()=>j(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:g.rotateCount}),(0,$.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase pools per rotation`,disabled:a.isPending||g.rotateCount>=1e3,icon:(0,$.jsx)(te,{size:14}),onClick:()=>j(1)})]}):null,(0,$.jsx)(Y,{id:`routing-pool-strategy`,"aria-label":`Pool selection mode`,value:g?.strategy??``,disabled:r.skipProxy||a.isPending,options:Rt,onValueChange:k})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-pool-strategy`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(Et,{size:15,"aria-hidden":`true`,className:`shrink-0 ${r.skipProxy?`text-text-tertiary`:`text-accent`}`}),`Pool mode`]})}),(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`How proxy pools are chosen when this provider dials one.`,r.skipProxy?` Disabled while “Always direct” is on.`:``]})]})})]}),(0,$.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${d?` opacity-60`:``}`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,$.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{id:`routing-user-agent-custom`,"aria-label":`Custom User-Agent override`,disabled:d,value:r.customUserAgent??``,placeholder:P,spellCheck:!1,onChange:e=>{let t=e.target.value;r.setCustomUserAgent(t.trim()===``?null:t)}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-micro text-text-tertiary`,children:`Custom User-Agent — leave empty to use the native identity below`}),r.customUserAgent===null?null:(0,$.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>r.setCustomUserAgent(null),title:`Reset to the provider's native identity`,children:`Reset`})]}),(0,$.jsxs)(`div`,{className:`text-micro text-text-tertiary`,children:[`Native identity: `,(0,$.jsx)(`code`,{className:`font-mono`,children:P}),`,`,` `,r.customUserAgent===null?`used as-is`:`overridden by the custom value above`]})]}):(0,$.jsx)(J,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:P}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-1`,children:d?`Locked while Advanced is open — collapse Advanced to edit.`:n?`Type a custom User-Agent to override the provider's identity (saved automatically); Reset clears it back to native.`:`Set by the provider. It cannot be changed.`})]})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(A,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,$.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,zt,` is unlimited.`]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":x?`true`:void 0,min:1,max:51,step:1,value:S,"aria-valuetext":x?`Unlimited`:String(r.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r.setMaxInflight(t>zt?null:Math.round(t))},style:{"--slider-pct":`${S/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:C,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){r.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&r.setMaxInflight(Math.min(Bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${x?`text-status-success`:``}`})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":d,"aria-label":d?`Collapse Advanced`:`Expand Advanced`,onClick:()=>f(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-4 py-3 text-left text-inherit`,children:[(0,$.jsx)(De,{size:15,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!d&&`-rotate-90`)}),(0,$.jsx)(ae,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Advanced`}),(0,$.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:`Max inflight / proxy`})]}),d?(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,$.jsxs)(Z,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(Ot,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>s(!0),children:`How it works`})]}),(0,$.jsxs)(Z,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":w?`true`:void 0,min:1,max:51,step:1,disabled:D,value:T,"aria-valuetext":w?`Unlimited`:String(r.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r.setMaxInflightPerProxy(t>zt?null:Math.round(t))},style:{"--slider-pct":`${T/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:D,value:E,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){r.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&r.setMaxInflightPerProxy(Math.min(Bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${w?`text-status-success`:``}`})]}),(0,$.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:D?`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 ${zt} is unlimited.`})]})}):null]}),(0,$.jsx)(z,{open:o,onClose:()=>s(!1),title:`How concurrency limits stack`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,$.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`API key concurrency`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`The key's `,(0,$.jsx)(`em`,{children:`own`}),` limit (`,` `,(0,$.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,$.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,$.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),(0,$.jsx)(z,{open:c,onClose:()=>u(!1),title:`How pool routing works`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.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,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Least loaded`}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Round robin`}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Random`}),(0,$.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,$.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Turning on “Always direct” bypasses pools entirely — this mode has no effect then.`})]})}),p&&(0,$.jsxs)(Z,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,$.jsx)(xt,{size:12,className:`shrink-0 mt-0.5`}),(0,$.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function 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 ce({queryKey:V.inferhub.summary,queryFn:e=>pe(`/inferhub/summary`,{signal:ue(e)}).then(Ut),enabled:e,...de,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,Q.useState)(!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(`provider`),[u,d]=(0,Q.useState)(!1),f=t?.models??[],p=f.filter($t),m=(0,Q.useMemo)(()=>{let e=[...i?f:p].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}))},[f,p,i,c]),g=(0,$.jsxs)(h,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,$.jsx)(B,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,$.jsx)(B,{size:16})}),(0,$.jsx)(U,{children:e.isError?(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`InferHub market`,icon:(0,$.jsx)(B,{size:16}),action:g}),(0,$.jsx)(U,{children:(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let _=m,v=_.reduce((e,t)=>e+t.models.length,0),b=f.length-v;return(0,$.jsxs)(W,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-center gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,$.jsx)(De,{size:15,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,$.jsxs)(X,{gap:`1px`,children:[(0,$.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,qt(t.meta.ageSeconds)]}):null]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:n?g:null})]}),n?(0,$.jsxs)(U,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(nn,{onSaved:()=>void e.refetch()}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,$.jsx)(Y,{value:c,onValueChange:e=>l(e),options:Object.keys(Jt).map(e=>({value:e,label:Jt[e]})),"aria-label":`Sort InferHub models`})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,$.jsxs)(rt,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,$.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,$.jsxs)(rt,{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,$.jsxs)(rt,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,qt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[v,` of `,f.length,` models`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(h,{size:`sm`,variant:`secondary`,onClick:()=>d(e=>!e),title:u?`Expand all provider groups`:`Collapse all provider groups`,children:u?`Expand all`:`Collapse all`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,b>0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,b,` hidden)`]}):null]})]})]}),_.length===0?(0,$.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,$.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:_.map(e=>(0,$.jsx)(tn,{group:e,showUpstreams:o,summary:t,collapsedAll:u},e.prefix))})]}):null]})}function tn({group:e,showUpstreams:t,summary:n,collapsedAll:r}){let[i,a]=(0,Q.useState)(!0),o=!r&&i,s=Qt(n,e.prefix),c=s?.familyState??null,l=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,$.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":o,"aria-label":`${o?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>a(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,$.jsx)(De,{size:14,"aria-hidden":`true`,className:y(`shrink-0 transition-transform`,!o&&`-rotate-90`)}),(0,$.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,$.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),c===null?null:(0,$.jsx)(q,{tone:Zt(c),dot:!0,children:c.replace(/_/g,` `)}),t&&s!==void 0?(0,$.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Kt(s.availability24hPct),` · 7d`,` `,Kt(s.availability7dPct)]}):null,(0,$.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),o?(0,$.jsxs)(`div`,{className:`px-3 pb-3`,children:[l===null?null:(0,$.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:l}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,$.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,$.jsx)(`tbody`,{children:e.models.map(e=>(0,$.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,$.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,$.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Gt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,$.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Gt(e.capacityPriceIn),` sustainable`]}):null]}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Gt(e.minAskOut)}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,$.jsx)(q,{children:`none`}):e.providersLive}),(0,$.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Kt(t?s?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function nn({onSaved:e}){let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await pe(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await pe(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,$.jsx)(J,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,$.jsx)(h,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,$.jsx)(h,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,$.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),(0,$.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:(0,$.jsxs)(`a`,{href:`https://inferhub.dev/`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-accent hover:underline`,children:[(0,$.jsx)(ze,{size:12,"aria-hidden":`true`}),`inferhub.dev — create a `,(0,$.jsx)(`code`,{children:`config_read`}),` key`]})}),s===null?null:(0,$.jsx)(rt,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function rn({providerId:e}){let t=Lt(e,!1),n=pt(),r=it(e),[i,a]=(0,Q.useState)(!1),o=(0,Q.useMemo)(()=>on(n.data?.accounts??[],e),[n.data,e]),s=(0,Q.useRef)(null),c=(0,Q.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Q.useEffect)(()=>{if(s.current===null){s.current=c;return}s.current!==c&&(s.current=c,n.refetch())},[c,n]);let[l,u]=(0,Q.useState)(`40`),[d,f]=(0,Q.useState)(`percent`),p=t.usageFloor!==null;(0,Q.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,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(A,{size:14}),(0,$.jsx)(`span`,{children:`Usage floor`}),(0,$.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,icon:(0,$.jsx)(w,{size:14}),"aria-label":`How the usage floor works`,onClick:()=>a(!0),children:`How it works`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[o!==null&&(0,$.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`Pooled credits`}),(0,$.jsx)(`span`,{className:`text-text-primary`,children:o.accounts}),(0,$.jsx)(`span`,{children:o.accounts===1?`active account`:`active accounts`}),o.inactiveAccounts>0?(0,$.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,$.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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`strong`,{className:`font-bold ${_}`,children:sn(o.remaining)}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,$.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,sn(o.total)]}),(0,$.jsxs)(`span`,{className:`font-bold ${_}`,children:[o.percent,`%`]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`strong`,{className:`font-bold ${_}`,children:[o.percent,`% left`]}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`lowest independent window`})]})}),(0,$.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,$.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`No quota data is available for these accounts yet. Exhausted quota windows are still skipped.`}),(0,$.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,$.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,$.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,$.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,$.jsx)(`input`,{type:`number`,min:0,max:1e6,value: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,$.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,$.jsx)(`option`,{value:`percent`,children:`%`}),(0,$.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,$.jsx)(Ye,{checked:p,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>v(e?g?m:40:null,d)})]}),t.saveFailed?(0,$.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,$.jsx)(an,{providerId:e}),(0,$.jsx)(z,{open:i,onClose:()=>a(!1),title:`How the usage floor works`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 text-badge leading-relaxed text-text-secondary`,children:[(0,$.jsxs)(`p`,{children:[`The usage floor is a `,(0,$.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,$.jsxs)(`p`,{children:[(0,$.jsx)(`strong`,{children:`Credit mode`}),` sums absolute remaining credits across pooled windows. `,(0,$.jsx)(`strong`,{children:`Percent mode`}),` uses the aggregate credit percentage and the lowest independent percentage window. An account with `,(0,$.jsx)(`em`,{children:`unknown`}),` quota is never treated as below the floor.`]}),(0,$.jsxs)(`p`,{children:[(0,$.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,$.jsx)(`code`,{children:`0 left`}),`), it is skipped for free-tier models too.`]}),(0,$.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}=_t(e);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(O,{size:14}),(0,$.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,$.jsx)(Ye,{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,$.jsx)(W,{density:`compact`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(Z,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,$.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`br`,{}),r]}):null]}),t?(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:v({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,$.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,$.jsx)(ze,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function ln({provider:e}){let t=H(),[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.baseUrl??``);(0,Q.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,$.jsxs)(W,{children:[(0,$.jsx)(He,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,$.jsx)(b,{size:16})}),(0,$.jsx)(U,{children:(0,$.jsxs)(X,{gap:`12px`,children:[n?(0,$.jsx)(J,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,$.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,$.jsxs)(Z,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(Tt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(L,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(ee,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(F,{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=mt(e),i=n.isPending||r.isPending;return(0,$.jsx)(h,{size:`sm`,variant:`secondary`,title:`Manually claim available ZCode gift plans`,"aria-label":`Claim gifts for ${t}`,disabled:i,icon:i?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(bt,{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`,fe(e,`Refresh quota manually`))})},onError:e=>g.error(`Gift claim failed`,fe(e,`Unable to claim gift plans`))}),children:i?`Claiming…`:`Claim gifts`})}function mn({accountId:e,accountName:t}){let n=ht(e),r=n.isPending;return(0,$.jsx)(h,{size:`sm`,variant:`secondary`,title:`Manually claim the Qoder daily CREDITS campaign`,"aria-label":`Claim credits for ${t}`,disabled:r,icon:r?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(D,{size:12}),onClick:()=>n.mutate(void 0,{onSuccess:e=>{switch(e.state){case`claimed`:g.success(`Qoder credits claimed`,`+${e.amount} credits granted`);break;case`already_claimed`:g.success(`Qoder credits already claimed`,e.detail??void 0);break;case`nothing`:g.success(`No CREDITS campaign`,`No claimable CREDITS campaign is visible for this account right now.`);break;case`error`:g.error(`Qoder credit claim failed`,e.detail??`Claim failed`)}},onError:e=>g.error(`Qoder credit claim failed`,fe(e,`Unable to claim credits`))}),children:r?`Claiming…`:`Claim credits`})}var hn={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`},gn=new Set([`quota_fetch_failed`]);function _n(e){return e===void 0||e.length===0?!1:!gn.has(e)}function vn(e){return e===`oauth`?`Re-login required`:`Replace API key`}function yn(e,t,n){return e===`auth_invalidated`?vn(t):e===`policy_blocked_banned`&&n===`github`?`No Copilot access`:hn[e]??e}var bn=/https?:\/\/[^\s"'\\]+/;function xn(e){if(e)return bn.exec(e)?.[0]}function Sn({cooldowns:e,reason:t}){if(!e)return null;let n=et(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,$.jsxs)(q,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function Cn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function wn(e){if(!_n(e.lastErrorCategory)||e.lastErrorCategory===`quota_exhausted`&&dn(e))return null;let t=yn(e.lastErrorCategory,e.credentialKind,e.providerId),n=e.lastError??e.lastErrorCategory;if(e.lastErrorCategory===`policy_blocked_banned`&&e.providerId===`github`)return(0,$.jsx)(q,{tone:`err`,dot:!0,title:n,children:t});if(e.lastErrorCategory===`validation_required`){let r=xn(e.lastError);if(r!==void 0)return(0,$.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,title:n,children:(0,$.jsxs)(q,{tone:`warn`,children:[t,(0,$.jsx)(ze,{size:12,className:`shrink-0`,"aria-hidden":`true`})]})})}return(0,$.jsx)(q,{tone:`warn`,title:n,children:t})}function Tn(e){return e.credentialKind===`oauth`?`blue`:`ok`}function En({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,$.jsx)(q,{tone:`warn`,title:`${o} — resets ${et(new Date(a).toISOString())}`,children:i?`Egress blocked`:`Rate-limited`})}function Dn({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=Cn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,$.jsx)(q,{tone:`warn`,title:e.lastError,children:vn(e.credentialKind)}):wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:Tn(e),dot:!0,children:[`Active`,Cn(e)?` - ${Cn(e)}`:``]}),(0,$.jsx)(En,{account:e}),wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,$.jsxs)(Z,{gap:`4px`,children:[(0,$.jsxs)(q,{tone:`warn`,dot:!0,children:[`Cooldown`,Cn(e)?` - ${Cn(e)}`:``,` `,e.cooldownUntil?`(${et(e.cooldownUntil)})`:``]}),(0,$.jsx)(En,{account:e}),wn(e),(0,$.jsx)(Sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,$.jsx)(q,{tone:`disabled`,children:`Disabled`})}function On(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 kn(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()}`:et(e,!1)}function An({windows:e}){let t=tt(e??[]),n=e?.filter(e=>nt(e)!==`current`)??[];return(0,$.jsxs)($.Fragment,{children:[t.text!==null&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":t.low?`warn`:void 0,title:t.hasCredits?`${jn(t.remaining)} credits available`:`Current model grants and account-wide quota limits`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),t.text]}),n.map((e,t)=>(0,$.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[e.label,e.modelIds?.length?` · ${e.modelIds.join(`, `)}`:``,` · `,nt(e)===`expired`?`Expired`:`Not started yet · Starts ${new Date(e.startsAt).toLocaleString()}`]},`${e.kind??e.label}:${e.startsAt}:${t}`))]})}function jn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Mn({providerId:e,account:t,onClose:n}){let r=me(),[i,a]=(0,Q.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{g.error(`Clipboard access denied`)}};return(0,$.jsx)(z,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,$.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,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,$.jsxs)(X,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,$.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,$.jsx)(Z,{gap:`8px`,className:`justify-end`,children:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Nn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=me(),l=Ce(),u=mt(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,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[,k]=(0,Q.useState)(0),[A,j]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(``),R=_t(e),te=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),B=R.enabled?`Mysterious accounts`:te,ie=kn(t.tokenExpiresAt),ae=fn(t),se=Math.max(x&&t.cooldownUntil?b:0,ae??0);(0,Q.useEffect)(()=>{if(se<=Date.now())return;let e=setInterval(()=>k(e=>e+1),1e3);return()=>clearInterval(e)},[se]);let ce=()=>{let n=I.trim();j(!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,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:y?.62:1},children:[(0,$.jsx)(`div`,{className:`flex items-center`,children:(0,$.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${B}`,className:`cursor-pointer`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:A?(0,$.jsx)(J,{value:I,onChange:e=>L(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&j(!1)},onBlur:ce,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:B}),m?(0,$.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=On(t.authMethod);return e===null?null:(0,$.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,$.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 ${B}`,onClick:()=>{L(t.label??``),j(!0)},children:(0,$.jsx)(ee,{size:11})})]})}),(0,$.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,$.jsx)(Dn,{account:t}),ie?(0,$.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:ie,children:ie}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,$.jsx)(An,{windows:r}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,$.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[e===`zcode-start`&&!m&&(0,$.jsx)(pn,{accountId:t.id,accountName:B}),(e===`qoder`||e===`qodercn`)&&!m&&(0,$.jsx)(mn,{accountId:t.id,accountName:B}),m?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${B}`,onClick:()=>E(!0),title:`View pool health & error history`}):(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${B}`,onClick:()=>w(!0),title:`View Health & Error History`}),m?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:d.isPending?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(p,{size:12}),label:d.isPending?`Testing…`:`Test`,"aria-label":`Test ${B}`,disabled:d.isPending||_===void 0,onClick:()=>{_&&d.mutate({poolId:_,providerId:e},{onSuccess:e=>{e.status===`allowed`?g.success(`Pool probe passed`,B):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,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,$.jsx)(f,{size:12,className:`animate-spin`}):(0,$.jsx)(p,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${B}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?g.success(`Account test passed`,B):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,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(F,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${B}`,onClick:()=>O(!0),title:`Replace API key`}),m?null:(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:y?(0,$.jsx)(St,{size:12}):(0,$.jsx)(ne,{size:12}),label:y?`Enable`:`Disable`,"aria-label":y?`Enable ${B}`:`Disable ${B}`,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`,B),onError:e=>g.error(`Update failed`,e.message??`Unable to update account`)})},title:y?`Enable account`:`Disable account`}),S?(0,$.jsx)(h,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(re,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${B}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,m?null:(0,$.jsx)(h,{size:`icon`,variant:`danger`,icon:(0,$.jsx)(oe,{size:12}),label:`Delete`,"aria-label":`Delete ${B}`,onClick:()=>s(t),title:`Delete account`})]})]}),C&&(0,$.jsx)(gt,{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,$.jsx)(Mn,{providerId:e,account:t,onClose:()=>O(!1)}),T&&(0,$.jsx)(z,{open:!0,title:`Pool Health & Error History`,onClose:()=>E(!1),width:640,footer:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>E(!1),children:`Close`}),children:(0,$.jsx)(`div`,{className:`flex flex-col gap-3 min-h-40`,children:v.isPending?(0,$.jsx)(N,{label:`Loading pool health events…`}):v.isError?(0,$.jsx)(M,{message:`Failed to load pool health events`,onRetry:()=>void v.refetch()}):(v.data??[]).length===0?(0,$.jsx)(P,{compact:!0,title:`No health events recorded`,message:`Status transitions, rate limits, and auto-recoveries will appear here.`}):(0,$.jsx)(`div`,{className:`scroll-region max-h-160 overflow-y-auto pr-1 flex flex-col gap-3`,children:(v.data??[]).map(e=>(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-badge`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`span`,{className:`font-mono tabular-nums text-micro text-text-tertiary`,children:new Date(e.createdAt).toLocaleString()}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-text-tertiary text-micro uppercase tracking-label`,children:[e.fromStatus??`—`,` → `,e.toStatus]}),e.errorCategory?(0,$.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,$.jsx)(`p`,{className:`mt-2 text-micro text-text-secondary [overflow-wrap:anywhere] break-words`,children:e.reason}):null]},e.id))})})})]})}var Pn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Fn=[`refresh`,`refreshToken`,`refresh_token`],In=[`credentialKind`,`providerId`,`accessToken`],Ln=[`accounts`,`items`,`connections`],Rn=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function zn(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Bn(e){let t=e.data;if(typeof t==`string`)try{return zn(JSON.parse(t))}catch{return}return zn(t)}function Vn(e){for(let t of Pn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Bn(e);if(t)for(let e of Pn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Hn(e){for(let t of Rn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Bn(e);if(t)for(let e of Rn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Un(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,Fn);if(n(e))return!0;let r=Bn(e);return r?n(r):!1}function Wn(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 zn(JSON.parse(atob(n)))}catch{return}}function Gn(e){let t=Wn(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 Kn(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 qn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var Jn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function Yn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of Jn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function Xn(e){let t=e.trim(),n=zn(qn(t))??Kn(t);return n&&Un(n)?`oauth`:Wn((n?Vn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Zn(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 Qn(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 $n(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&In.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&Un(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=Vn(e),r=Un(e)?`oauth`:Xn(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Hn(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function er(e){for(let t of Ln){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>zn(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function tr(e){let t=e.trim();if(!t)return[];let n=qn(t);if(Array.isArray(n)){let e=n.map(e=>zn(e)).filter(e=>e!==void 0);if(e.length>0)return Zn(e)?[Qn(t,e)]:e.map($n)}else{let e=zn(n);if(e){let t=er(e);return t?t.map($n):[$n(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=Kn(r[0]);return e?[$n(e)]:nr(r[0])}let i=Kn(t);return i&&(Vn(i)||Object.keys(i).length===r.length)?[$n(i)]:r.flatMap(nr)}function nr(e){let t=zn(qn(e));if(t){let e=er(t);return e?e.map($n):[$n(t)]}let n=rr(e);return n.length>0?n:[{value:e,kind:Xn(e)}]}function rr(e){let t=e.indexOf(`|`);if(t<=0)return[];let n=e.slice(0,t).trim(),r=e.slice(t+1).trim();return!n||!r?[]:[{value:r,kind:Xn(r),identity:n}]}function ir(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 ar(e){let t=[];for(let n of e){let e=n.text.trim();if(!e)continue;let r=qn(e);if(Array.isArray(r)){let n=r.filter(e=>zn(e)!==void 0);if(n.length>0&&Zn(n)){t.push(e);continue}for(let e of r){let n=zn(e);t.push(n===void 0?String(e):JSON.stringify(n))}continue}let i=zn(r);if(i){let n=er(i);if(n!==void 0){for(let e of n)t.push(JSON.stringify(e));continue}t.push(e);continue}tr(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
2
|
`);return{text:n,entries:tr(n)}}function or(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 sr=2097152,cr=sr/1048576;function lr({providerId:e,accounts:t,onClose:n}){let r=Se(),i=Ne(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(`auto`),[p,m]=(0,Q.useState)(void 0),[_,y]=(0,Q.useState)(!1),b=(0,Q.useRef)(null),x=tr(s),S=x.length>1,C=x.length===1?x[0]:void 0,w=d===`auto`?C?.kind:d,T=C&&w===`jwt`?Gn(C.value):void 0,E=x.length>0?Yn(e,s):void 0,D=E!==void 0&&p!==s,O=t.map(e=>e.label),k=S?ir(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=tr(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>sr);if(t){g.error(`File too large`,`${t.name} is over ${cr} MB — credential files must be ${cr} 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=ar(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)))},P=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=or(x.map((e,t)=>({label:k[t],...A(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${k[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${fe(e,`request failed`)}`);break}let s=a.length;r>0&&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
3
|
`)+(s>5?`\n…and ${s-5} more`:``)),r>0&&n()}finally{u(!1)}}};return(0,$.jsx)(z,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:j,children:`Cancel`}),(0,$.jsx)(h,{size:`sm`,variant:`primary`,disabled:j||x.length===0,onClick:()=>void P(),children:j?`Connecting...`:D?`Confirm below`:S?`Add ${x.length} Accounts`:`Add Account`})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!S&&(0,$.jsx)(J,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:C?.identity??`${e} account`}),(0,$.jsx)(Y,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,$.jsxs)(X,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:[`API key, OAuth token, or exported JSON — one or many`,(0,$.jsxs)(`span`,{className:`font-normal text-text-tertiary`,children:[` `,`·`,` `,`also supports `,(0,$.jsx)(`code`,{className:`font-mono text-micro`,children:`name|credential`}),` per line`]})]}),S?(0,$.jsxs)(q,{tone:`accent`,children:[`Detected: `,x.length,` accounts`]}):C?(0,$.jsxs)(q,{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,$.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,$.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,$.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. Prefix a line with name| to name that account (e.g. onlybougieclan|pt-…). 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,$.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,$.jsxs)(Z,{gap:`8px`,className:`justify-end`,children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void M(),children:`Paste`}),(0,$.jsxs)(`label`,{className:v({size:`sm`,className:`cursor-pointer`}),children:[(0,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,$.jsx)(`span`,{className:`truncate min-w-0`,children:k[t]}),(0,$.jsx)(q,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))}),E&&(0,$.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,$.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,$.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,$.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,$.jsxs)(Z,{gap:`8px`,className:`justify-end`,children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>{c(``),n()},children:`Cancel`}),(0,$.jsx)(h,{size:`sm`,variant:`primary`,onClick:()=>m(s),children:`Add anyway`})]}):(0,$.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:`Acknowledged — you can add this account now.`})]})]})})}function ur(e){return e===`active`?0:e===`cooldown`?2:3}var dr=[{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 fr(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=ur(e.status)-ur(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 pr({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=le(),s=me(),c=Ce(),l=Ae(),u=it(e).data??new Map,f=pt(),m=(0,Q.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(new Set),[x,S]=(0,Q.useState)(`added-asc`),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(!1),k=_.trim().toLowerCase(),A=(0,Q.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,Q.useMemo)(()=>{let e=x.slice(0,x.lastIndexOf(`-`)),t=x.endsWith(`-desc`)?-1:1,n=[...A];return n.sort((n,r)=>t*fr(n,r,e)),n},[A,x]),M=(0,Q.useMemo)(()=>t.filter(e=>e.kind!==`pool`&&y.has(e.id)),[t,y]),N=A.length>0&&A.every(e=>y.has(e.id)),F=M.some(e=>e.status===`disabled`),I=M.some(e=>e.status!==`disabled`),R=M.length===0,z=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},ee=()=>{b(e=>{let t=new Set(e);if(N)for(let e of A)t.delete(e.id);else for(let e of A)e.kind!==`pool`&&t.add(e.id);return t})},te=async(e,t)=>{if(M.length===0)return;w(!0);let n=await un(M,ae,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`)},B=()=>te(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),ae=3,se=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 pe(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return E({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:V.quota.all}),o.invalidateQueries({queryKey:V.providers.all})]),w(!1),E(null),g.success(`Test complete`,`${e.length} account${e.length===1?``:`s`} tested`))},ce=t=>te(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),ue=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,`-`);G(`${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,$.jsxs)(X,{gap:`8px`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,$.jsxs)(`label`,{className:`relative w-full min-medium:w-56 shrink-0`,children:[(0,$.jsx)(ie,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,$.jsx)(J,{id:`accounts-search`,value:_,onChange:e=>v(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9 h-15 py-0`})]}),(0,$.jsx)(h,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(p,{size:12}),disabled:C||t.length===0,onClick:se,"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,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(re,{size:12}),disabled:C||R,title:R?`Select at least one account to recover it`:`Clear cooldowns and retry-wait states on the selected accounts`,onClick:()=>void B(),children:`Recover`}),(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(St,{size:12}),disabled:C||!F,title:R?`Select at least one disabled account to enable it`:F?`Enable the selected accounts`:`No selected account is currently disabled`,onClick:()=>void ce(!0),children:`Enable`}),(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(ne,{size:12}),disabled:C||!I,title:R?`Select at least one enabled account to disable it`:I?`Disable the selected accounts`:`No selected account is currently enabled`,onClick:()=>void ce(!1),children:`Disable`}),(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(d,{size:12}),disabled:C||R,title:R?`Select at least one account to export`:`Download the selected accounts as JSON`,onClick:()=>void ue(),children:`Export`}),(0,$.jsx)(h,{size:`sm`,variant:`danger`,icon:(0,$.jsx)(oe,{size:12}),disabled:C||R,title:R?`Select at least one account to delete`:`Delete ${M.length} selected account${M.length===1?``:`s`}`,onClick:()=>O(!0),children:`Delete`}),r?(0,$.jsx)(h,{size:`sm`,variant:`secondary`,icon:(0,$.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,$.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,$.jsx)(Y,{size:`sm`,value:x,onValueChange:e=>S(e),options:dr,"aria-label":`Sort accounts by`})}),(0,$.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:N,onChange:ee,"aria-label":`Select accounts`}),(0,$.jsx)(`span`,{children:`Select`})]}),R?null:(0,$.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,$.jsx)(L,{size:11,"aria-hidden":`true`})]})]}),(0,$.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:j.length===0?(0,$.jsx)(P,{compact:!0,icon:(0,$.jsx)(ie,{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,$.jsx)(Nn,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:m.get(t.id),selected:y.has(t.id),onToggleSelect:z,onDelete:n},t.id))}),(0,$.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,$.jsxs)(`span`,{children:[`Showing `,A.length,` account`,A.length===1?``:`s`,k?` (filtered from ${t.length})`:``]})}),(0,$.jsx)(he,{open:D,onClose:()=>{C||O(!1)},onConfirm:async()=>{await te(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await pe(t,{method:`DELETE`}),o.removeQueries({queryKey:V.quota.account(e.id),exact:!0})}),b(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:V.providers.accounts(e)}),o.invalidateQueries({queryKey:V.providers.all}),o.invalidateQueries({queryKey:V.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 mr(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 hr({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),l=Fe(),d=vt(),p=le(),m=je(e),v=(0,Q.useRef)(null),y=(0,Q.useRef)(!1),[b,x]=(0,Q.useState)(!0);(0,Q.useEffect)(()=>{let t=setInterval(()=>{p.invalidateQueries({queryKey:V.providers.accounts(e)})},1500);return()=>clearInterval(t)},[p,e]),(0,Q.useEffect)(()=>{let t=!1;return p.invalidateQueries({queryKey:V.providers.accounts(e)}).finally(()=>{t||x(!1)}),()=>{t=!0}},[p,e]),(0,Q.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,Q.useState)(!1),T=()=>{w(!0),p.invalidateQueries({queryKey:V.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,$.jsx)(z,{open:!0,onClose:S,title:`Connect via OAuth`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:S,disabled:l.isPending,children:`Cancel`}),(0,$.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,$.jsx)(h,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=mr(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,$.jsxs)(X,{gap:`14px`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,$.jsxs)(Z,{gap:`8px`,children:[(0,$.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:a?(0,$.jsx)(_,{size:12}):(0,$.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),d(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,$.jsx)(`span`,{children:`Or complete manually`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,$.jsxs)(Z,{gap:`8px`,align:`flex-start`,children:[(0,$.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>void E(),className:`shrink-0`,children:`Paste`})]})]})]})})}function gr(e){try{return new URL(e).host}catch{return e}}function _r({providerId:e,parameters:t,onClose:n}){let r=Be(),i=Te(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,d]=(0,Q.useState)(!1),p=vt();(0,Q.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(g.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let m=(0,Q.useRef)(null),[v,y]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?m.current=e:y(!0),()=>{let e=m.current;m.current=null,e&&!e.closed&&e.close()}},[a]),(0,Q.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),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,$.jsx)(z,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,$.jsx)(X,{gap:`14px`,children:a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,$.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,$.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,$.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:l?(0,$.jsx)(_,{size:12}):(0,$.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),p(()=>d(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,$.jsxs)(Z,{gap:`8px`,children:[(0,$.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:gr(a.verificationUri)}),(0,$.jsx)(h,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(ze,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:s?(0,$.jsx)(_,{size:12}):(0,$.jsx)(u,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),p(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsx)(f,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function vr({providerId:e}){let[t,n]=(0,Q.useState)(!1),r=xe(e,t);return(0,$.jsxs)(W,{children:[(0,$.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,$.jsxs)(`div`,{className:`card-header-left`,children:[(0,$.jsx)(`div`,{className:`card-header-icon`,children:(0,$.jsx)(i,{size:16,"aria-hidden":`true`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-bold text-text-primary`,children:`Activity Matrix`}),(0,$.jsxs)(`div`,{className:`text-caption text-text-secondary`,children:[`Daily token usage, last `,r.data?.days??30,` days · expand to load`]})]})]}),(0,$.jsx)(`div`,{className:`card-header-right`,children:(0,$.jsx)(De,{size:14,"aria-hidden":`true`,className:y(`transition-transform`,t&&`rotate-180`)})})]}),t?(0,$.jsx)(Ar,{matrix:r}):null]})}function yr(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:br(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:br(e)})).sort((e,t)=>t.tokens-e.tokens);return{weeks:s,maxDay:l,totals:r,models:m}}function br(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 xr(e,t){if(e<=0||t<=0)return 0;let n=e/t,r=1;for(let e=1;e<Sr.length;e++)n>e/(Sr.length-1)&&(r=e);return Math.min(r,Sr.length-1)}var Sr=[0,.18,.38,.62,.9];function Cr(e){return Sr[Math.min(Math.max(Math.trunc(e),0),Sr.length-1)]??0}function wr(e){let t=Cr(e)*100;return t===0?`var(--surface-2)`:`color-mix(in srgb, var(--text-primary) ${t}%, transparent)`}function Tr(e,t){if(t===0)return{backgroundColor:`var(--surface-2)`,borderColor:`var(--inner-border)`};let n=Cr(t)*100;return{backgroundColor:`color-mix(in srgb, ${e.color} ${n}%, transparent)`,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}}function Er(e){return[`${e.label} — ${Je(e.total)} tokens`,...e.models.map(t=>`• ${t.name}: ${Je(t.tokens)} (${Math.round(t.tokens/e.total*100)}%) · ${t.requests} req`)].join(`
|
|
4
4
|
`)}var Dr=`26px repeat(7, minmax(0, 1fr))`,Or=420,kr=360;function Ar({matrix:e}){let t=(0,Q.useMemo)(()=>e.data?yr(e.data):void 0,[e.data]),n;return n=e.isPending?(0,$.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`Loading activity…`}):e.isError?(0,$.jsx)(`p`,{className:`p-4 text-caption text-status-danger`,children:`Failed to load activity matrix.`}):!t||t.totals.requests===0?(0,$.jsx)(`p`,{className:`p-4 text-caption text-text-secondary`,children:`No usage recorded for this provider in the window.`}):(0,$.jsx)(Mr,{view:t}),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`border-t border-inner-border`,children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 p-4 max-small:p-3 min-[641px]:grid-cols-4`,children:[(0,$.jsx)(jr,{label:`Total tokens`,value:Je(t?.totals.tokens)}),(0,$.jsx)(jr,{label:`Requests`,value:(t?.totals.requests??0).toLocaleString(`en-US`)}),(0,$.jsx)(jr,{label:`Cached`,value:Je(t?.totals.cachedTokens)}),(0,$.jsx)(jr,{label:`Est. cost`,value:E(t?.totals.costUsd)})]})}),(0,$.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,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-1.5 text-micro text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`Less`}),[0,1,2,3,4].map(e=>(0,$.jsx)(`span`,{className:`size-3 rounded-micro border border-inner-border`,style:{backgroundColor:wr(e)}},e)),(0,$.jsx)(`span`,{children:`More`})]}):null,t&&t.totals.requests>0&&t.models.length>0?(0,$.jsxs)(`details`,{className:`group mt-4 border-t border-inner-border pt-3`,children:[(0,$.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,$.jsxs)(`span`,{className:`font-semibold`,children:[`Usage by model (`,t.models.length,`) · sorted by tokens`]}),(0,$.jsx)(De,{size:14,"aria-hidden":`true`,className:`shrink-0 transition-transform group-open:rotate-180`})]}),(0,$.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,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate text-caption font-semibold`,style:{color:e.color},title:e.name,children:e.name}),(0,$.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,$.jsxs)(`span`,{className:`shrink-0 font-mono text-caption text-text-secondary`,children:[Je(e.tokens),` `,(0,$.jsxs)(`span`,{className:`text-text-tertiary`,children:[Math.round(n*100),`%`]}),` ·`,` `,e.requests.toLocaleString(`en-US`),` req`]})]},e.name)})})]}):null]})]})}function jr({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:e}),(0,$.jsx)(`div`,{className:`mt-0.5 font-mono text-lg font-bold text-text-primary`,children:t})]})}function Mr({view:e}){return(0,$.jsx)(`div`,{style:{minWidth:kr},children:(0,$.jsxs)(`div`,{className:`grid gap-1`,style:{gridTemplateColumns:Dr,maxWidth:Or},children:[(0,$.jsx)(`div`,{}),[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`].map(e=>(0,$.jsx)(`div`,{className:`text-center text-micro text-text-tertiary`,children:e},e)),e.weeks.map((t,n)=>(0,$.jsxs)(`div`,{className:`contents`,children:[(0,$.jsxs)(`div`,{className:`flex items-center text-micro text-text-tertiary`,children:[`W`,n+1]}),t.cells.map((t,r)=>t===null?(0,$.jsx)(`div`,{},`${n}-${r}`):(0,$.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:Tr(t,xr(t.total,e.maxDay)),title:Er(t)},t.day))]},n))]})})}function Nr(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function Pr(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Fr({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,$.jsx)(X,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,$.jsx)(Y,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,$.jsx)(J,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function Ir({providerId:e,providerName:t,fields:n,onClose:r}){let i=Re(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(()=>Nr(n)),d=(0,Q.useMemo)(()=>Pr(n,l),[n,l]);return(0,$.jsx)(z,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,$.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,$.jsx)(f,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,$.jsxs)(X,{gap:`12px`,children:[(0,$.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,$.jsx)(Fr,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,$.jsx)(J,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,$.jsx)(J,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}var Lr=2e4,Rr=`What model are you, and what is your knowledge cutoff date? Answer in one sentence.`;function zr(){let e=$e(),t=Qe(),[n,r]=(0,Q.useState)(!1);return{test:(0,Q.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(),Lr),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:Rr}],...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 Br(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function Vr(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var Hr=[{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`}],Ur={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function Wr(){return kt.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function Gr({value:e,onChange:t,disabled:n,size:r=`md`,id:i=`probe-thinking-effort`}){return(0,$.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0 max-sm:min-w-56`,children:(0,$.jsx)(Y,{id:i,"aria-label":`Thinking effort`,value:e,disabled:n,size:r,onValueChange:e=>t(e),options:Wr()})})}function Kr(){return[{value:`all`,label:`All models`},{value:`free`,label:`Free tier`}]}function qr({value:e,onChange:t,disabled:n,size:r=`md`,id:i=`models-show-filter`}){return(0,$.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,$.jsx)(Y,{id:i,"aria-label":`Show models`,value:e,disabled:n,size:r,onValueChange:e=>t(e),options:Kr()})})}function Jr({providerId:e,provider:t,onClose:n}){let r=Pe(),i=Ve(),[a,o]=(0,Q.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Q.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Q.useState)(c??`chat`),[m,_]=(0,Q.useState)(`auto`),[v,y]=(0,Q.useState)(`idle`),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(Qr),E=a.trim(),D=E.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&E.length>e.length+1?E.slice(e.length+1):E,O=D!==E,k=()=>{if(!D)return;y(`testing`),x(``),C(null);let t=e===`qoder`||e===`qodercn`;r.mutate({providerId:e,request:{modelId:D,wireFamily:u,reasoningEffort:m,serviceKind:`llm`,...t?{surface:`ide`}:{}}},{onSuccess:e=>{e.ok?(y(`passed`),C(e.providerMetadata??null)):(y(`failed`),x(e.error??`Model probe failed`))},onError:e=>{y(`failed`),x(e.message??`Model probe failed`)}})};return(0,$.jsx)(z,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,$.jsx)(h,{variant:`primary`,size:`sm`,disabled:i.isPending||D.length===0,onClick:()=>{if(!D)return;let t=Ue(w.contextLimit),r=Ue(w.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:[D],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:w.passthrough,image:w.passthrough?!0:w.image,reasoning:w.passthrough?!0:w.reasoning,toolCall:w.passthrough?!0:w.toolCall}},{onSuccess:()=>{g.success(`Custom model added`,`Sent to ${e}/${D}`),n()},onError:e=>g.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(Z,{gap:`8px`,align:`flex-end`,children:[(0,$.jsx)(J,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),y(`idle`),x(``)},onKeyDown:e=>{e.key===`Enter`&&D.length>0&&k()},className:`flex-1`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:v===`testing`?(0,$.jsx)(f,{size:13,className:`animate-spin`}):(0,$.jsx)(p,{size:13}),disabled:r.isPending||D.length===0,onClick:k,className:`shrink-0`,children:v===`testing`?`Testing...`:`Test`})]}),O&&(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:D}),` (provider prefix removed).`]}),(0,$.jsx)(Y,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),y(`idle`),x(``)},options:l.map(e=>({value:e,label:ii(e)}))}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,$.jsx)(Gr,{id:`add-model-thinking-effort`,value:m,onChange:e=>{_(e),y(`idle`),x(``)},disabled:r.isPending}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,$.jsx)($r,{draft:w,onChange:T,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:ii(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),v===`passed`&&(0,$.jsxs)(rt,{tone:`success`,live:`status`,children:[`Model test passed — ready to add.`,S!==null&&(0,$.jsx)(`span`,{className:`grid gap-1 mt-2 min-w-0`,children:Object.entries(S).filter(([,e])=>e!=null&&e!==``).map(([e,t])=>(0,$.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`shrink-0 text-micro text-text-tertiary`,children:e}),(0,$.jsx)(`span`,{className:`truncate font-mono text-micro text-text-secondary`,title:String(t),children:String(t)})]},e))})]}),v===`failed`&&(0,$.jsx)(rt,{tone:`danger`,live:`alert`,children:b||`Model test failed.`})]})})}function Yr(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var Xr=String(Ke),Zr=String(We);function Qr(){return{...Yr(),contextLimit:Xr,outputLimit:Zr}}function $r({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,$.jsxs)(Z,{gap:`8px`,children:[(0,$.jsx)(J,{label:`Context`,id:`${n}-context`,placeholder:Xr,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,$.jsx)(J,{label:`Output`,id:`${n}-output`,placeholder:Zr,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===Xr&&e.outputLimit===Zr,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:Xr,outputLimit:Zr}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,K(Ke),` ctx ·`,` `,K(We),` out`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,$.jsx)(X,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function ei({providerId:e,model:t,onClose:n}){let r=ve(),[i,a]=(0,Q.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,$.jsx)(z,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,$.jsx)(h,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=Ue(i.contextLimit),o=Ue(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,$.jsxs)(X,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,$.jsx)($r,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function ti({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let d=zr(),v=Pe(),y=ye(),[w,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(!1),P=vt(),F=n===`llm`?At(t.modelId,i===`auto`?null:i):t.modelId,I=`${e}/${F}`,L=n===`websearch`?`Searching…`:`Thinking…`,R=()=>{if(N(!1),e===`qoder`||e===`qodercn`){v.mutate({providerId:e,request:{modelId:t.modelId,serviceKind:`llm`}},{onSuccess:t=>{if(O({ok:t.ok,latencyMs:t.latencyMs}),j(t.providerMetadata??null),!t.ok){g.error(`${e}/${F} test failed`,t.error??`Unknown error`);return}let n=t.sample??``,r=t.reportedModel?.trim()??``,i=t.providerMetadata,a=i?Object.entries(i).filter(([,e])=>e!=null&&e!==``):[];g.successRich(`${F} · END ${m(t.latencyMs)}`,(0,$.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,$.jsxs)(Z,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,$.jsx)(T,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,$.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,a.length>0?(0,$.jsx)(`span`,{className:`grid gap-1 min-w-0`,children:a.map(([e,t])=>(0,$.jsxs)(Z,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`shrink-0 text-micro text-text-tertiary`,children:e}),(0,$.jsx)(`span`,{className:`truncate font-mono text-micro text-text-secondary`,title:String(t),children:String(t)})]},e))}):null,(0,$.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i,m as a}from"./numbers-CoqpaDMx.js";import{t as o}from"./eye-off-Bk5g2luF.js";import{t as s}from"./eye-C_hawfH4.js";import{n as c,r as l,t as u}from"./state-DHmEnLa2.js";import{t as d}from"./dialog-BK-NRr5u.js";import{t as f}from"./plus-DIdX_g-x.js";import{t as p}from"./trash-Cppn5c3R.js";import{l as m}from"./query-keys-YSoQOUh6.js";import{t as h}from"./dialog-actions-B1axpEg7.js";import{E as g,T as _,a as ee,et as v,ft as y,i as b,ot as x,rt as S,s as C,v as w}from"./entry-vqGb8yVz.js";import{n as T,r as E,t as D}from"./card-CxDw0lK6.js";import{t as O}from"./switch-DmZcyTIC.js";import{t as k}from"./badge-BaX2GTrn.js";import{n as A}from"./input-BlmlizVV.js";import{t as te}from"./select-C9Ssle9b.js";import{t as j}from"./ProviderIcon-jjqXJDA3.js";import{t as M}from"./stack-j7cXjgYX.js";import{n as N}from"./inline-CHJQwxLa.js";import{t as ne}from"./pagination-B5aOoweZ.js";import{t as P}from"./list-row-Ml16KCfu.js";import{t as F}from"./privacy-mode-GM8bej85.js";var I=e(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),L=e(`rows-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),R=t(n(),1),z=r();function B(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(A,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(A,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(p,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(f,{size:13}),` Add header`]})]})]})}function V({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var H=a(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),U=a(`block flex-1 p-6 no-underline text-inherit`),W=a(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function G(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var K=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function q(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}let i=K.exec(r);if(i===null)return null;let a=r.slice(0,i.index);return`${n.origin}${a}`}function J({variant:e,open:t,onClose:n}){let r=b(),o=ee(),s=_(),c=g(),[l,u]=(0,R.useState)(``),[f,p]=(0,R.useState)(``),[h,v]=(0,R.useState)(``),[y,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),[w,T]=(0,R.useState)(!0),[E,D]=(0,R.useState)([]),[k,j]=(0,R.useState)(null),[M,ne]=(0,R.useState)(!1),[F,I]=(0,R.useState)(null),[L,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>q(h),[h]);(0,R.useEffect)(()=>{t&&(u(``),x(``),G(U),v(``),C(!1),T(!0),D([]),j(null),I(null))},[t]);let J=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{j(`Clipboard access denied — paste manually instead.`)}},ie=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),I(null),j(null);try{let e=B(E),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:W,cliIdentity:w,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:m(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(d,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:M,children:M?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){j(`Display Name is required`);return}if(!f.trim()){j(`Provider ID (slug) is required`);return}if(!h.trim()){j(`Base URL is required`);return}let t=B(E),i=f.trim().toLowerCase();ne(!0),j(null);try{let e={providerId:i,label:l.trim(),baseUrl:h.trim(),wireFamily:W,compatibilityProfile:{cli_identity:w,...Object.keys(t).length>0?{extra_headers:t}:{}}};await r.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:i,request:{credentialKind:`api_key`,secret:y.trim()}}),S&&await s.mutateAsync(i),n()}catch(e){j(m(e,`Failed to create provider`))}finally{ne(!1)}},className:`flex flex-col gap-6`,children:[k?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:k}):null,(0,z.jsx)(A,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>u(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(A,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>p(e.target.value),placeholder:H?`ac-prod`:`oc-prod`,required:!0}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,z.jsx)(`span`,{children:`Base URL`}),(0,z.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,H?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(A,{id:`compat-url`,value:h,onChange:e=>v(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>J(v),children:`Paste`})]}),K===null?null:(0,z.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,z.jsx)(`code`,{className:`font-mono`,children:K}),` instead — Cartethyia appends the endpoint path itself.`]})]}),H?null:(0,z.jsx)(te,{id:`compat-wire`,label:`API format`,value:W,onValueChange:e=>G(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,z.jsx)(`span`,{children:`API Key`}),(0,z.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(A,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>x(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:L,onClick:()=>void ie(),children:L?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>J(x),children:`Paste`})]}),F?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:a(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,z.jsx)(P,{actions:(0,z.jsx)(O,{checked:S,onChange:C,id:`compat-autofetch`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,z.jsx)(P,{actions:(0,z.jsx)(O,{checked:w,onChange:T,id:`compat-cli-identity`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:H?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:H?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,z.jsx)(re,{pairs:E,onChange:D})]})})}function ie({customProvider:e}){let t=C(),[n,r]=(0,R.useState)(!1);return(0,z.jsxs)(D,{className:H,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(v,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:a(U,`pr-20 min-h-38`),children:(0,z.jsxs)(N,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:W,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:e.accountCount===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:!1,isError:!1,hasData:!1}):e.accountCount===0?e.requiresAccount===!1?(0,z.jsx)(k,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(k,{children:`No connections`}):(0,z.jsx)(se,{activeCount:e.activeAccountCount,total:e.accountCount})})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),e.modelCount!==void 0&&e.modelCount>0?(0,z.jsxs)(k,{tone:`info`,children:[e.modelCount,` models`]}):null,e.modelCount===void 0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!1}):e.modelCount===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(p,{size:12}),onClick:()=>r(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(d,{open:n,onClose:()=>r(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(M,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:m(t.error,`Delete failed`)}):null,(0,z.jsxs)(h,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>r(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>r(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,a]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(y,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(s,{size:13}):(0,z.jsx)(o,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(f,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(f,{size:13}),onClick:()=>a(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(D,{children:(0,z.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,z.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,z.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,z.jsx)(V,{children:e.map(e=>(0,z.jsx)(ie,{customProvider:e},e.providerId))}),(0,z.jsx)(J,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(J,{variant:`openai-compatible`,open:r,onClose:()=>a(!1)})]})}var Y=new Set([`inferhub`]),X=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`,`inception`,`zcode-start`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function Z(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Q(e){return e.oauthFlows?.refreshable===!0}function se({activeCount:e,total:t}){return e===void 0?(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t,` Connected`]}):e===0?(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t,` Unhealthy`]}):e===t?(0,z.jsxs)(k,{tone:`ok`,dot:!0,children:[t,` Healthy`]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(k,{tone:`ok`,dot:!0,children:[e,` Healthy`]}),(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t-e,` Unhealthy`]})]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(k,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(k,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(k,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(k,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=Y.has(e.providerId.toLowerCase()),r=e.label||e.displayName;return(0,z.jsxs)(D,{className:H,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:a(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(v,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:U,children:(0,z.jsxs)(N,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:W,children:r}),(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:e.accountCount===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:!1,isError:!1,hasData:!1}):e.accountCount===0?e.requiresAccount===!1?(0,z.jsx)(k,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(k,{children:`No connections`}):(0,z.jsx)(se,{activeCount:e.activeAccountCount,total:e.accountCount})})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),e.modelCount!==void 0&&e.modelCount>0?(0,z.jsxs)(k,{tone:`info`,children:[e.modelCount,` models`]}):null,e.modelCount===void 0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!1}):e.modelCount===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`,fe=`cartethyia:providers:display-mode`;function pe(){try{if(typeof window>`u`)return null;let e=window.localStorage.getItem(fe);return e===`all`||e!==`paginated`&&null}catch{return null}}function me(e){try{window.localStorage.setItem(fe,e?`all`:`paginated`)}catch{}}var he=`Other API Key Providers`;function ge(){try{let e=window.localStorage.getItem(de);if(e===null)return new Set([he]);let t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set([he])}}var _e=`text-body font-bold tracking-[-0.01em]`,ve=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>X.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(Z(e)||Q(e))&&!X.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)&&!Q(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)&&!Q(e)}];function ye(){let[e,t]=(0,R.useState)(ge),n=w(),r=F(),d=r.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,p=(0,R.useMemo)(()=>n.data??[],[n.data]),h=(0,R.useMemo)(()=>[...p.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[p,d]),g=(0,R.useMemo)(()=>p.filter(e=>G(e).includes(`websearch`)&&f(e)),[p,d]),_=(0,R.useMemo)(()=>p.filter(e=>G(e).includes(`llm`)&&f(e)),[p,d]),[ee,v]=S(),b=ee.get(`tab`),C=b===`search`||b===`media`?b:`llm`,O=e=>{v(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},k=(0,R.useMemo)(()=>p.filter(e=>(G(e).includes(`imageGeneration`)||G(e).includes(`videoGeneration`))&&f(e)),[p,d]),A=(0,R.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),te=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,R.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:k}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:A}].filter(e=>e.providers.length>0);let e=_;return ve.map(t=>({...t,providers:e.filter(t.filter).sort(te)})).filter(e=>e.providers.length>0)},[_,A,k,C]),[N,P]=(0,R.useState)({}),[B,re]=(0,R.useState)(()=>pe()??!1),H=()=>{re(e=>{let t=!e;return me(t),t})},U=e=>N[e]??1,W=e=>t=>P(n=>({...n,[e]:t})),K=(e,t)=>{if(B)return{visible:e,pageCount:1,safePage:1};let n=U(t),r=Math.max(1,Math.ceil(e.length/8)),i=Math.min(n,r);return{visible:e.slice((i-1)*8,i*8),pageCount:r,safePage:i}},q=n.isPending&&!n.data?(0,z.jsx)(l,{label:`Loading providers...`}):n.isError?(0,z.jsx)(c,{message:m(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return q?(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsx)(T,{className:`flex flex-1`,children:q})]}):(0,z.jsx)(M,{gap:`24px`,children:(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,z.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,z.jsxs)(`button`,{onClick:()=>O(e),className:a(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${g.length})`:e===`media`?` (${k.length})`:` (${_.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(o,{size:12}):(0,z.jsx)(s,{size:12}),onClick:()=>r.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:B?(0,z.jsx)(L,{size:12}):(0,z.jsx)(I,{size:12}),onClick:H,title:B?`Paginate each section (8 per page)`:`Show every provider in each section at once`,children:B?`Paginated`:`Show All`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,z.jsx)(ae,{customProviders:h}):null,j.length===0?(0,z.jsx)(D,{children:(0,z.jsx)(T,{children:(0,z.jsx)(u,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(y,{size:15,className:a(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,z.jsxs)(M,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:_e,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,z.jsx)(V,{children:K(n.providers,n.title).visible.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?G(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))}),r?null:(()=>{let{pageCount:e,safePage:t}=K(n.providers,n.title);return e>1?(0,z.jsx)(ne,{page:t,pageCount:e,onPageChange:W(n.title),testId:`providers-section-pagination-${n.title}`}):null})()]},n.title)})]})]})})}export{ye as default};
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i,m as a}from"./numbers-BnAd22a_.js";import{t as o}from"./eye-off-Bk5g2luF.js";import{t as s}from"./eye-C_hawfH4.js";import{n as c,r as l,t as u}from"./state-DXbGTx7N.js";import{t as d}from"./dialog-BZhOlfz-.js";import{t as f}from"./plus-DIdX_g-x.js";import{t as p}from"./trash-Cppn5c3R.js";import{l as m}from"./query-keys-YSoQOUh6.js";import{t as h}from"./dialog-actions-B1axpEg7.js";import{E as g,T as _,a as ee,et as v,ft as y,i as b,ot as x,rt as S,s as C,v as w}from"./entry-Ca7LSCet.js";import{n as T,r as E,t as D}from"./card-_HwAEqFF.js";import{t as O}from"./switch-ZeTsW623.js";import{t as k}from"./badge-DyI_mJfi.js";import{n as A}from"./input-D-qV9dKY.js";import{t as te}from"./select-BCOcv8WK.js";import{t as j}from"./ProviderIcon-jjqXJDA3.js";import{t as M}from"./stack-ByKt3Q1g.js";import{n as N}from"./inline-B2BirKry.js";import{t as ne}from"./pagination-BAywyMzS.js";import{t as P}from"./list-row-CtkGE3bF.js";import{t as F}from"./privacy-mode-GM8bej85.js";var I=e(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),L=e(`rows-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),R=t(n(),1),z=r();function B(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(A,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(A,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(p,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(f,{size:13}),` Add header`]})]})]})}function V({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var H=a(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),U=a(`block flex-1 p-6 no-underline text-inherit`),W=a(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function G(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var K=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function q(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}let i=K.exec(r);if(i===null)return null;let a=r.slice(0,i.index);return`${n.origin}${a}`}function J({variant:e,open:t,onClose:n}){let r=b(),o=ee(),s=_(),c=g(),[l,u]=(0,R.useState)(``),[f,p]=(0,R.useState)(``),[h,v]=(0,R.useState)(``),[y,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),[w,T]=(0,R.useState)(!0),[E,D]=(0,R.useState)([]),[k,j]=(0,R.useState)(null),[M,ne]=(0,R.useState)(!1),[F,I]=(0,R.useState)(null),[L,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>q(h),[h]);(0,R.useEffect)(()=>{t&&(u(``),x(``),G(U),v(``),C(!1),T(!0),D([]),j(null),I(null))},[t]);let J=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{j(`Clipboard access denied — paste manually instead.`)}},ie=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),I(null),j(null);try{let e=B(E),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:W,cliIdentity:w,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:m(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(d,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:M,children:M?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){j(`Display Name is required`);return}if(!f.trim()){j(`Provider ID (slug) is required`);return}if(!h.trim()){j(`Base URL is required`);return}let t=B(E),i=f.trim().toLowerCase();ne(!0),j(null);try{let e={providerId:i,label:l.trim(),baseUrl:h.trim(),wireFamily:W,compatibilityProfile:{cli_identity:w,...Object.keys(t).length>0?{extra_headers:t}:{}}};await r.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:i,request:{credentialKind:`api_key`,secret:y.trim()}}),S&&await s.mutateAsync(i),n()}catch(e){j(m(e,`Failed to create provider`))}finally{ne(!1)}},className:`flex flex-col gap-6`,children:[k?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:k}):null,(0,z.jsx)(A,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>u(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(A,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>p(e.target.value),placeholder:H?`ac-prod`:`oc-prod`,required:!0}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,z.jsx)(`span`,{children:`Base URL`}),(0,z.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,H?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(A,{id:`compat-url`,value:h,onChange:e=>v(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>J(v),children:`Paste`})]}),K===null?null:(0,z.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,z.jsx)(`code`,{className:`font-mono`,children:K}),` instead — Cartethyia appends the endpoint path itself.`]})]}),H?null:(0,z.jsx)(te,{id:`compat-wire`,label:`API format`,value:W,onValueChange:e=>G(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,z.jsx)(`span`,{children:`API Key`}),(0,z.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(A,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>x(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:L,onClick:()=>void ie(),children:L?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>J(x),children:`Paste`})]}),F?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:a(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,z.jsx)(P,{actions:(0,z.jsx)(O,{checked:S,onChange:C,id:`compat-autofetch`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,z.jsx)(P,{actions:(0,z.jsx)(O,{checked:w,onChange:T,id:`compat-cli-identity`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:H?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:H?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,z.jsx)(re,{pairs:E,onChange:D})]})})}function ie({customProvider:e}){let t=C(),[n,r]=(0,R.useState)(!1);return(0,z.jsxs)(D,{className:H,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(v,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:a(U,`pr-20 min-h-38`),children:(0,z.jsxs)(N,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:W,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:e.accountCount===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:!1,isError:!1,hasData:!1}):e.accountCount===0?e.requiresAccount===!1?(0,z.jsx)(k,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(k,{children:`No connections`}):(0,z.jsx)(se,{activeCount:e.activeAccountCount,total:e.accountCount})})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),e.modelCount!==void 0&&e.modelCount>0?(0,z.jsxs)(k,{tone:`info`,children:[e.modelCount,` models`]}):null,e.modelCount===void 0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!1}):e.modelCount===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(p,{size:12}),onClick:()=>r(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(d,{open:n,onClose:()=>r(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(M,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:m(t.error,`Delete failed`)}):null,(0,z.jsxs)(h,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>r(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>r(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,a]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(y,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(N,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(s,{size:13}):(0,z.jsx)(o,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(f,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(f,{size:13}),onClick:()=>a(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(D,{children:(0,z.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,z.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,z.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,z.jsx)(V,{children:e.map(e=>(0,z.jsx)(ie,{customProvider:e},e.providerId))}),(0,z.jsx)(J,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(J,{variant:`openai-compatible`,open:r,onClose:()=>a(!1)})]})}var Y=new Set([`inferhub`]),X=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`,`inception`,`zcode-start`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function Z(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Q(e){return e.oauthFlows?.refreshable===!0}function se({activeCount:e,total:t}){return e===void 0?(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t,` Connected`]}):e===0?(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t,` Unhealthy`]}):e===t?(0,z.jsxs)(k,{tone:`ok`,dot:!0,children:[t,` Healthy`]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(k,{tone:`ok`,dot:!0,children:[e,` Healthy`]}),(0,z.jsxs)(k,{tone:`warn`,dot:!0,children:[t-e,` Unhealthy`]})]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(k,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(k,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(k,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(k,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=Y.has(e.providerId.toLowerCase()),r=e.label||e.displayName;return(0,z.jsxs)(D,{className:H,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:a(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(v,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:U,children:(0,z.jsxs)(N,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:W,children:r}),(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:e.accountCount===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:!1,isError:!1,hasData:!1}):e.accountCount===0?e.requiresAccount===!1?(0,z.jsx)(k,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(k,{children:`No connections`}):(0,z.jsx)(se,{activeCount:e.activeAccountCount,total:e.accountCount})})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),e.modelCount!==void 0&&e.modelCount>0?(0,z.jsxs)(k,{tone:`info`,children:[e.modelCount,` models`]}):null,e.modelCount===void 0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!1}):e.modelCount===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`,fe=`cartethyia:providers:display-mode`;function pe(){try{if(typeof window>`u`)return null;let e=window.localStorage.getItem(fe);return e===`all`||e!==`paginated`&&null}catch{return null}}function me(e){try{window.localStorage.setItem(fe,e?`all`:`paginated`)}catch{}}var he=`Other API Key Providers`;function ge(){try{let e=window.localStorage.getItem(de);if(e===null)return new Set([he]);let t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set([he])}}var _e=`text-body font-bold tracking-[-0.01em]`,ve=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>X.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(Z(e)||Q(e))&&!X.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)&&!Q(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X.has(e.providerId.toLowerCase())&&!Z(e)&&!Q(e)}];function ye(){let[e,t]=(0,R.useState)(ge),n=w(),r=F(),d=r.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,p=(0,R.useMemo)(()=>n.data??[],[n.data]),h=(0,R.useMemo)(()=>[...p.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[p,d]),g=(0,R.useMemo)(()=>p.filter(e=>G(e).includes(`websearch`)&&f(e)),[p,d]),_=(0,R.useMemo)(()=>p.filter(e=>G(e).includes(`llm`)&&f(e)),[p,d]),[ee,v]=S(),b=ee.get(`tab`),C=b===`search`||b===`media`?b:`llm`,O=e=>{v(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},k=(0,R.useMemo)(()=>p.filter(e=>(G(e).includes(`imageGeneration`)||G(e).includes(`videoGeneration`))&&f(e)),[p,d]),A=(0,R.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),te=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,R.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:k}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:A}].filter(e=>e.providers.length>0);let e=_;return ve.map(t=>({...t,providers:e.filter(t.filter).sort(te)})).filter(e=>e.providers.length>0)},[_,A,k,C]),[N,P]=(0,R.useState)({}),[B,re]=(0,R.useState)(()=>pe()??!1),H=()=>{re(e=>{let t=!e;return me(t),t})},U=e=>N[e]??1,W=e=>t=>P(n=>({...n,[e]:t})),K=(e,t)=>{if(B)return{visible:e,pageCount:1,safePage:1};let n=U(t),r=Math.max(1,Math.ceil(e.length/8)),i=Math.min(n,r);return{visible:e.slice((i-1)*8,i*8),pageCount:r,safePage:i}},q=n.isPending&&!n.data?(0,z.jsx)(l,{label:`Loading providers...`}):n.isError?(0,z.jsx)(c,{message:m(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return q?(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsx)(T,{className:`flex flex-1`,children:q})]}):(0,z.jsx)(M,{gap:`24px`,children:(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,z.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,z.jsxs)(`button`,{onClick:()=>O(e),className:a(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${g.length})`:e===`media`?` (${k.length})`:` (${_.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(o,{size:12}):(0,z.jsx)(s,{size:12}),onClick:()=>r.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:B?(0,z.jsx)(L,{size:12}):(0,z.jsx)(I,{size:12}),onClick:H,title:B?`Paginate each section (8 per page)`:`Show every provider in each section at once`,children:B?`Paginated`:`Show All`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,z.jsx)(ae,{customProviders:h}):null,j.length===0?(0,z.jsx)(D,{children:(0,z.jsx)(T,{children:(0,z.jsx)(u,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(y,{size:15,className:a(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,z.jsxs)(M,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:_e,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,z.jsx)(V,{children:K(n.providers,n.title).visible.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?G(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))}),r?null:(()=>{let{pageCount:e,safePage:t}=K(n.providers,n.title);return e>1?(0,z.jsx)(ne,{page:t,pageCount:e,onPageChange:W(n.title),testId:`providers-section-pagination-${n.title}`}):null})()]},n.title)})]})]})})}export{ye as default};
|
|
Binary file
|