cartethyia 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +5 -1
- package/dist/dashboard/assets/{AccountCooldown-ChpdzxRH.js → AccountCooldown-Bjo92Qat.js} +1 -1
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js.gz +0 -0
- package/dist/dashboard/assets/{BannedPage-9igfctfZ.js → BannedPage-MsQaeQTs.js} +1 -1
- package/dist/dashboard/assets/BannedPage-MsQaeQTs.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js +1 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-D3xqZbN-.js → CliToolsPage-DfWHTJ7v.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DfWHTJ7v.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js +1 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js +1 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js +1 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js +1 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js +1 -0
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js +1 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js +7 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js +1 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js +1 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js +1 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js +1 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-CbK3hXvU.js → StudioPage-u9IxmYOI.js} +3 -3
- package/dist/dashboard/assets/StudioPage-u9IxmYOI.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js +56 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js.gz +0 -0
- package/dist/dashboard/assets/{api-keys-BmDbsior.js → api-keys-uNywYlfv.js} +1 -1
- package/dist/dashboard/assets/api-keys-uNywYlfv.js.gz +0 -0
- package/dist/dashboard/assets/{app-C-Y4oZT0.js → app-CafWtVXA.js} +1 -1
- package/dist/dashboard/assets/{app-C-Y4oZT0.js.gz → app-CafWtVXA.js.gz} +0 -0
- package/dist/dashboard/assets/app-DxivpfYG.css +2 -0
- package/dist/dashboard/assets/app-DxivpfYG.css.gz +0 -0
- package/dist/dashboard/assets/{assert-BHfaei-X.js → assert-NHwYq95t.js} +1 -1
- package/dist/dashboard/assets/{assert-BHfaei-X.js.gz → assert-NHwYq95t.js.gz} +0 -0
- package/dist/dashboard/assets/badge-6uzDDvqs.js +1 -0
- package/dist/dashboard/assets/badge-6uzDDvqs.js.gz +0 -0
- package/dist/dashboard/assets/banner-4_WNg2WZ.js +1 -0
- package/dist/dashboard/assets/banner-4_WNg2WZ.js.gz +0 -0
- package/dist/dashboard/assets/card--AtFedAq.js +1 -0
- package/dist/dashboard/assets/card--AtFedAq.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-B0wBq-RL.js → cli-tools-B3e7dx3N.js} +1 -1
- package/dist/dashboard/assets/cli-tools-B3e7dx3N.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-NreUx6c8.js +1 -0
- package/dist/dashboard/assets/clipboard-button-NreUx6c8.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BtpsJU98.js +1 -0
- package/dist/dashboard/assets/dialog-BtpsJU98.js.gz +0 -0
- package/dist/dashboard/assets/drawer-WwwtzihF.js +1 -0
- package/dist/dashboard/assets/drawer-WwwtzihF.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js +4 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js.gz +0 -0
- package/dist/dashboard/assets/entry-TJIye_jT.js +1 -0
- package/dist/dashboard/assets/entry-TJIye_jT.js.gz +0 -0
- package/dist/dashboard/assets/{entry-D4O2229X.js → entry-jy9_4-Ke.js} +1 -1
- package/dist/dashboard/assets/entry-jy9_4-Ke.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-D_eM3IgG.js +1 -0
- package/dist/dashboard/assets/github-badge-D_eM3IgG.js.gz +0 -0
- package/dist/dashboard/assets/{index-CXm3FIyt.js → index-DCBtROoK.js} +2 -2
- package/dist/dashboard/assets/index-DCBtROoK.js.gz +0 -0
- package/dist/dashboard/assets/inline-BcNGF8Gr.js +1 -0
- package/dist/dashboard/assets/inline-BcNGF8Gr.js.gz +0 -0
- package/dist/dashboard/assets/input-BG41et9G.js +1 -0
- package/dist/dashboard/assets/input-BG41et9G.js.gz +0 -0
- package/dist/dashboard/assets/layout-C8mer_Ak.js +1 -0
- package/dist/dashboard/assets/layout-C8mer_Ak.js.gz +0 -0
- package/dist/dashboard/assets/list-row-Gh_W4OR_.js +1 -0
- package/dist/dashboard/assets/list-row-Gh_W4OR_.js.gz +0 -0
- package/dist/dashboard/assets/{live-yfEJFF9T.js → live-BJGYRBnR.js} +1 -1
- package/dist/dashboard/assets/live-BJGYRBnR.js.gz +0 -0
- package/dist/dashboard/assets/{model-bans-CT-TxSNX.js → model-bans-DeVLDA7I.js} +1 -1
- package/dist/dashboard/assets/model-bans-DeVLDA7I.js.gz +0 -0
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js +2 -0
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js.gz +0 -0
- package/dist/dashboard/assets/{routing-Cs6jl49L.js → routing-CcusqXA7.js} +1 -1
- package/dist/dashboard/assets/routing-CcusqXA7.js.gz +0 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js +41 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js.gz +0 -0
- package/dist/dashboard/assets/{settings-CfcTcOyU.js → settings-mpmXTgUa.js} +1 -1
- package/dist/dashboard/assets/settings-mpmXTgUa.js.gz +0 -0
- package/dist/dashboard/assets/stack-DwLmjUFK.js +1 -0
- package/dist/dashboard/assets/stack-DwLmjUFK.js.gz +0 -0
- package/dist/dashboard/assets/state-DYdQmdAl.js +1 -0
- package/dist/dashboard/assets/state-DYdQmdAl.js.gz +0 -0
- package/dist/dashboard/assets/switch-CidSfbG7.js +1 -0
- package/dist/dashboard/assets/switch-CidSfbG7.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-BQKMcJ1H.js → useMutation-w4u4CVue.js} +1 -1
- package/dist/dashboard/assets/useMutation-w4u4CVue.js.gz +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +51 -54
- package/package.json +1 -1
- package/scripts/cli/command/tray.ts +47 -8
- package/src/boot/app.ts +3 -2
- package/src/console/observability/contracts.ts +11 -1
- package/src/console/observability/store.ts +9 -6
- package/src/providers/discovery/openrouter-free-roster.ts +3 -11
- package/src/providers/discovery/probe-phases.ts +42 -5
- package/src/providers/discovery/probing-service.ts +25 -2
- package/src/providers/integrations/claude/claude.ts +3 -1
- package/src/providers/integrations/cloudflareai/cloudflareai-models.ts +3 -1
- package/src/providers/integrations/inferhub.ts +3 -1
- package/src/providers/integrations/kilo/kilo.ts +0 -1
- package/src/providers/integrations/kiro/kiro-catalog.ts +8 -2
- package/src/providers/integrations/openrouter/provider.ts +5 -15
- package/src/security/api-key-auth.ts +23 -0
- package/src/transport/guards/auth-guard.ts +2 -3
- package/dist/dashboard/assets/AccountCooldown-ChpdzxRH.js.gz +0 -0
- package/dist/dashboard/assets/BannedPage-9igfctfZ.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-ZRr2K2sF.js +0 -1
- package/dist/dashboard/assets/CliToolDetailPage-ZRr2K2sF.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-D3xqZbN-.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CVnQPBBz.js +0 -1
- package/dist/dashboard/assets/CombosPage-CVnQPBBz.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-u6W1UXSc.js +0 -1
- package/dist/dashboard/assets/ConsoleLogPage-u6W1UXSc.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-CTTpCb25.js +0 -1
- package/dist/dashboard/assets/CustomizationPage-CTTpCb25.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-C5XpWlvy.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-C5XpWlvy.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-DHoB3Agn.js +0 -1
- package/dist/dashboard/assets/LoginPage-DHoB3Agn.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-oQ-SDXp8.js +0 -1
- package/dist/dashboard/assets/ModelPicker-oQ-SDXp8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-BrY4SgIt.js +0 -1
- package/dist/dashboard/assets/OverviewPage-BrY4SgIt.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-D9VSt7T_.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-D9VSt7T_.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-Df77V5I5.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-Df77V5I5.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-CDfxP7AC.js +0 -7
- package/dist/dashboard/assets/ProxyPage-CDfxP7AC.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CY4o2t4p.js +0 -1
- package/dist/dashboard/assets/QuotaPage-CY4o2t4p.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-CvjZxHE4.js +0 -1
- package/dist/dashboard/assets/SettingsPage-CvjZxHE4.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-D3nza7LH.js +0 -1
- package/dist/dashboard/assets/SetupPage-D3nza7LH.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-Dtt12WT1.js +0 -1
- package/dist/dashboard/assets/SortableList-Dtt12WT1.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-CbK3hXvU.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BQlWbWg2.js +0 -56
- package/dist/dashboard/assets/UsagePage-BQlWbWg2.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-BmDbsior.js.gz +0 -0
- package/dist/dashboard/assets/app-BbpSarVV.css +0 -2
- package/dist/dashboard/assets/app-BbpSarVV.css.gz +0 -0
- package/dist/dashboard/assets/badge-DpXT4Ixt.js +0 -1
- package/dist/dashboard/assets/badge-DpXT4Ixt.js.gz +0 -0
- package/dist/dashboard/assets/banner-CSAAWLJv.js +0 -1
- package/dist/dashboard/assets/banner-CSAAWLJv.js.gz +0 -0
- package/dist/dashboard/assets/card-DEhRXXw4.js +0 -1
- package/dist/dashboard/assets/card-DEhRXXw4.js.gz +0 -0
- package/dist/dashboard/assets/check-D69FzdvC.js +0 -1
- package/dist/dashboard/assets/check-D69FzdvC.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-B0wBq-RL.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-DOo6EU8O.js +0 -1
- package/dist/dashboard/assets/clipboard-button-DOo6EU8O.js.gz +0 -0
- package/dist/dashboard/assets/copy-ngmQ9zcZ.js +0 -1
- package/dist/dashboard/assets/copy-ngmQ9zcZ.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BvQeBMfP.js +0 -1
- package/dist/dashboard/assets/dialog-BvQeBMfP.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CMwPXwQB.js +0 -1
- package/dist/dashboard/assets/drawer-CMwPXwQB.js.gz +0 -0
- package/dist/dashboard/assets/entry-D4O2229X.js.gz +0 -0
- package/dist/dashboard/assets/entry-DKvr5Q9K.js +0 -1
- package/dist/dashboard/assets/entry-DKvr5Q9K.js.gz +0 -0
- package/dist/dashboard/assets/entry-FQCejoDY.js +0 -4
- package/dist/dashboard/assets/entry-FQCejoDY.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-zliLvBwr.js +0 -1
- package/dist/dashboard/assets/github-badge-zliLvBwr.js.gz +0 -0
- package/dist/dashboard/assets/index-CXm3FIyt.js.gz +0 -0
- package/dist/dashboard/assets/inline-D1IlZZ8H.js +0 -1
- package/dist/dashboard/assets/inline-D1IlZZ8H.js.gz +0 -0
- package/dist/dashboard/assets/input-BpVZdrbc.js +0 -1
- package/dist/dashboard/assets/input-BpVZdrbc.js.gz +0 -0
- package/dist/dashboard/assets/layout-BioLW7gN.js +0 -1
- package/dist/dashboard/assets/layout-BioLW7gN.js.gz +0 -0
- package/dist/dashboard/assets/list-row-CwVcGAIc.js +0 -1
- package/dist/dashboard/assets/list-row-CwVcGAIc.js.gz +0 -0
- package/dist/dashboard/assets/live-yfEJFF9T.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-CT-TxSNX.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CFL4_Dqc.js +0 -1
- package/dist/dashboard/assets/numbers-CFL4_Dqc.js.gz +0 -0
- package/dist/dashboard/assets/routing-Cs6jl49L.js.gz +0 -0
- package/dist/dashboard/assets/select-C0Rer3gF.js +0 -41
- package/dist/dashboard/assets/select-C0Rer3gF.js.gz +0 -0
- package/dist/dashboard/assets/settings-CfcTcOyU.js.gz +0 -0
- package/dist/dashboard/assets/stack-C9_uUjaA.js +0 -1
- package/dist/dashboard/assets/stack-C9_uUjaA.js.gz +0 -0
- package/dist/dashboard/assets/state-DA0B95UQ.js +0 -1
- package/dist/dashboard/assets/state-DA0B95UQ.js.gz +0 -0
- package/dist/dashboard/assets/switch-Cittxy-x.js +0 -1
- package/dist/dashboard/assets/switch-Cittxy-x.js.gz +0 -0
- package/dist/dashboard/assets/toast-CNt_jzO4.js +0 -2
- package/dist/dashboard/assets/toast-CNt_jzO4.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-BQKMcJ1H.js.gz +0 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{C as u,E as d,O as f,T as p,a as m,b as h,d as g,l as _,s as v,u as y,w as b,y as x}from"./numbers-Bs4LOOuf.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"./cog-CdWhsajs.js";import{t as T}from"./download-A0SW9OCW.js";import{t as E}from"./eye-off-Bk5g2luF.js";import{t as D}from"./eye-C_hawfH4.js";import{t as O}from"./gauge-BbIMy7MB.js";import{t as ee}from"./image-BPaouViG.js";import{n as k,r as A,t as j}from"./state-DYdQmdAl.js";import{t as M}from"./key-round-UkavsGxp.js";import{t as N}from"./layers-2-glBbjl.js";import{n as te,t as P}from"./dialog-BtpsJU98.js";import{t as F}from"./pencil-768ysRAr.js";import{t as ne}from"./plus-DIdX_g-x.js";import{t as re}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as ae}from"./rotate-ccw-CufcqITi.js";import{t as oe}from"./search-JOKus9rb.js";import{t as se}from"./trash-Cppn5c3R.js";import{t as ce}from"./wrench-B6E1oEuY.js";import{T as le}from"./assert-NHwYq95t.js";import{o as ue,t as I}from"./query-keys-D7wX2vM5.js";import{$ as de,C as fe,D as L,E as pe,O as me,Q as he,R as ge,S as _e,T as ve,a as ye,b as R,c as be,d as xe,et as Se,f as Ce,g as we,h as Te,l as Ee,m as De,o as Oe,ot as ke,p as Ae,r as je,st as z,t as Me,u as Ne,v as Pe,x as Fe,y as Ie}from"./entry-Dj9AR0gY.js";import{n as B,r as Le,t as V}from"./card--AtFedAq.js";import{n as Re}from"./download-dRFo5_Wu.js";import{f as H,i as ze,l as U,n as Be,r as Ve,s as W}from"./tokens-DDxMbSRL.js";import{t as G}from"./badge-6uzDDvqs.js";import{n as K}from"./input-BG41et9G.js";import{t as q}from"./select-DsX5QT8K.js";import{t as He}from"./ProviderIcon-CmfzxpVM.js";import{t as J}from"./switch-CidSfbG7.js";import{t as Y}from"./stack-DwLmjUFK.js";import{n as X,t as Ue}from"./inline-BcNGF8Gr.js";import{i as We}from"./quota-DZGyp0N5.js";import{t as Ge}from"./list-row-Gh_W4OR_.js";import{c as Ke,l as Z,m as qe}from"./routing-CcusqXA7.js";import{o as Je,s as Ye,t as Xe}from"./HealthEventsModal-qomXThxX.js";import{r as Ze}from"./privacy-mode-GM8bej85.js";import{n as Qe,t as $e}from"./AccountCooldown-Bjo92Qat.js";import{t as et}from"./use-timeout-BwcBBRrT.js";import{t as tt}from"./banner-4_WNg2WZ.js";var nt=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`}]]),rt=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`}]]),it=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`}]]),at=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`}]]),ot=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`}]]),st=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`}]]),ct=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`}]]),lt=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`}]]),ut=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function dt(e,t){return t===null?e:`${e}(${t})`}var Q=t(n(),1),$=r();function ft({to:e,label:t}){let n=he();return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,$.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function pt({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)(ft,{...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:g(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function mt(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function ht(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 gt={fallback:`Failover`,roundRobin:`Round robin`},_t=new Set([`inferhub`,`cline`]);function vt(e,t){let n=Z(e),r=qe(),[i,a]=(0,Q.useState)(`fallback`),[o,s]=(0,Q.useState)(1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(`percent`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=ht(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=ht(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=ht(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=ht(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v})},skipProxy:g,userAgent:v,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),x(e)},setMaxInflightPerProxy:e=>{d(e),S(e)},setUserAgent:e=>{y(e),w(e)},setSkipProxy:e=>{_(e),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),b({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})},rotateCount:o,setRotateCount:e=>{s(e),C(e)}}}var yt=50,bt=100;function xt(e,t,n){return[{value:``,label:`None`},{value:`Cartethyia/${e}`,label:`Cartethyia ${e}`},{value:`codex_cli_rs/${t}`,label:`Codex`},{value:`claude-cli/${n} (external, cli)`,label:`Claude Code`}]}function St({children:e,action:t}){return(0,$.jsx)(Ge,{actions:t,children:e})}function Ct({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=vt(e,r),[a,o]=(0,Q.useState)(!1),s=_t.has(e),c=xt(Me,n.codex,n.claude),u=c.some(e=>e.value===i.userAgent)?c:[...c,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,$.jsx)(A,{label:`Loading routing...`});if(i.isError)return(0,$.jsx)(k,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${gt.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:gt.fallback,f=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,p=i.maxInflight===null,m=p?51:Math.min(51,Math.max(1,i.maxInflight)),h=p?`∞`:String(i.maxInflight),g=i.maxInflightPerProxy===null,y=g?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),b=g?`∞`:String(i.maxInflightPerProxy),x=i.skipProxy,S=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},C=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;v.success(`Client identity updated`,t)},w=t?`${t.client} ${t.version}`:`Provider default`;return(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:`Routing Strategy`,subtitle:f,icon:(0,$.jsx)(N,{size:16})}),(0,$.jsx)(B,{children:(0,$.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,$.jsx)(St,{action:(0,$.jsxs)($.Fragment,{children:[i.roundRobinEnabled?(0,$.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,$.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,$.jsx)(te,{size:14}),onClick:()=>S(-1)}),(0,$.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,$.jsx)(_,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,$.jsx)(ne,{size:14}),onClick:()=>S(1)})]}):null,(0,$.jsx)(J,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,$.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(ot,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,$.jsx)(St,{action:(0,$.jsx)(J,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,$.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(nt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,$.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsxs)(X,{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`]}),r?(0,$.jsx)(q,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:C}):(0,$.jsx)(q,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:w,options:[{value:w,label:w}]}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,$.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(O,{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:[`Shared provider ceiling. One step past `,yt,` is unlimited.`]}),(0,$.jsxs)(X,{gap:`10px`,className:`mt-3`,children:[(0,$.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":p?`true`:void 0,min:1,max:51,step:1,value:m,"aria-valuetext":p?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>yt?null:Math.round(t))},style:{"--slider-pct":`${m/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:h,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflight(Math.min(bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${p?`text-status-success`:``}`})]})]})]}),(0,$.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${x?` opacity-60`:``}`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,$.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,$.jsx)(lt,{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)(_,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,$.jsxs)(X,{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":g?`true`:void 0,min:1,max:51,step:1,disabled:x,value:y,"aria-valuetext":g?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>yt?null:Math.round(t))},style:{"--slider-pct":`${y/51*100}%`}}),(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:x,value:b,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflightPerProxy(Math.min(bt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${g?`text-status-success`:``}`})]}),(0,$.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:x?`Always direct is on, so this provider never dials a pool. The limit is kept for when a pool is used again.`:`One step past ${yt} is unlimited.`})]}),(0,$.jsx)(P,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,$.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,$.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,$.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,$.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,$.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,$.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,$.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,$.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),s&&(0,$.jsxs)(X,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,$.jsx)(rt,{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 wt({providerId:e}){let t=vt(e,!1),n=Je(),r=Ke(e),i=(0,Q.useMemo)(()=>Et(n.data?.accounts??[],e),[n.data,e]),a=(0,Q.useRef)(null),o=(0,Q.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Q.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Q.useState)(`40`),[l,u]=(0,Q.useState)(`percent`),d=t.usageFloor!==null;(0,Q.useEffect)(()=>{t.usageFloor!==null&&c(String(t.usageFloor)),u(t.usageFloorUnit)},[t.usageFloor,t.usageFloorUnit]);let f=Number(s),p=Number.isInteger(f)&&f>=0&&f<=1e6,m=i===null||i.remaining<=0?`text-status-danger`:i.percent<=10?`text-status-warning`:`text-status-success`,h=(e,n)=>{(e===null||p)&&t.setUsageFloor(e,n)};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(O,{size:14}),(0,$.jsx)(`span`,{children:`Usage floor`}),(0,$.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,$.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`Pooled credits`}),(0,$.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,$.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-caption font-semibold tabular-nums text-text-primary`,title:`Combined allowance across active accounts; the usage floor is evaluated per account`,children:[(0,$.jsx)(`strong`,{className:`font-bold ${m}`,children:Dt(i.remaining)}),(0,$.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,$.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,Dt(i.total)]}),(0,$.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Dt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,$.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,$.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,$.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Dt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,$.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,$.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,$.jsx)(`input`,{type:`number`,min:0,max:1e6,value:d?s:``,placeholder:`40`,disabled:!d,"aria-label":`Usage floor amount`,className:`h-full w-24 border-0 bg-transparent px-3 text-right font-mono text-body font-semibold tabular-nums text-text-primary disabled:text-text-tertiary`,onChange:e=>c(e.target.value),onBlur:()=>{d&&h(f,l)}}),(0,$.jsxs)(`select`,{value:l,disabled:!d,"aria-label":`Usage floor unit`,className:`h-full border-0 border-l border-inner-border bg-hover px-3 text-body font-semibold text-text-secondary disabled:cursor-default disabled:opacity-60`,onChange:e=>{let t=e.target.value===`credit`?`credit`:`percent`;u(t),d&&h(f,t)},children:[(0,$.jsx)(`option`,{value:`percent`,children:`%`}),(0,$.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,$.jsx)(J,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,$.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,$.jsx)(Tt,{providerId:e})]})}function Tt({providerId:e}){let{enabled:t,setEnabled:n}=Ze(e);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,$.jsx)(E,{size:14}),(0,$.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,$.jsx)(J,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function Et(e,t){let n=0,r=0,i=0,a=!1;for(let o of e)if(o.provider===t&&o.active&&(i+=1,o.quota!==null))for(let e of o.quota.windows){if(e.accounting!==`pooled`)continue;let t=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null;if(t===null)continue;let i=typeof e.remaining==`number`&&Number.isFinite(e.remaining)?e.remaining:typeof e.used==`number`&&Number.isFinite(e.used)?t-e.used:null;i!==null&&(n+=Math.min(t,Math.max(0,i)),r+=t,a=!0)}return i>0&&a?{accounts:i,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function Dt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Ot({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)(V,{density:`compact`,children:(0,$.jsx)(B,{children:(0,$.jsxs)(X,{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:y({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,$.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,$.jsx)(ke,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function kt({provider:e}){let t=L(),[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)(V,{children:[(0,$.jsx)(Le,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,$.jsx)(b,{size:16})}),(0,$.jsx)(B,{children:(0,$.jsxs)(Y,{gap:`12px`,children:[n?(0,$.jsx)(K,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,$.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)(X,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(st,{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)(_,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(x,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,$.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(F,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,$.jsx)(_,{size:`sm`,variant:`secondary`,icon:(0,$.jsx)(M,{size:13}),onClick:()=>{let e=document.getElementById(`provider-accounts`);e?.scrollIntoView({behavior:`smooth`,block:`start`}),e?.focus({preventScroll:!0})},children:`Manage API keys`}):null]})]})})]})}var At={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},jt=new Set([`quota_fetch_failed`]);function Mt(e){return e===void 0||e.length===0?!1:!jt.has(e)}function Nt(e){return e===`oauth`?`Re-login required`:`Replace API key`}function Pt(e,t){return e===`auth_invalidated`?Nt(t):At[e]??e}async function Ft(e,t,n){let r=Array(e.length),i=Math.max(1,Math.min(t,e.length)),a=0;return await Promise.all(Array.from({length:i},async()=>{for(;;){let t=a;if(t>=e.length)return;a+=1;try{r[t]={status:`fulfilled`,value:await n(e[t],t)}}catch(e){r[t]={status:`rejected`,reason:e}}}})),r}var It=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Lt=[`refresh`,`refreshToken`,`refresh_token`],Rt=[`credentialKind`,`providerId`,`accessToken`],zt=[`accounts`,`items`,`connections`],Bt=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function Vt(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Ht(e){let t=e.data;if(typeof t==`string`)try{return Vt(JSON.parse(t))}catch{return}return Vt(t)}function Ut(e){for(let t of It){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Ht(e);if(t)for(let e of It){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Wt(e){for(let t of Bt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Ht(e);if(t)for(let e of Bt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Gt(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,Lt);if(n(e))return!0;let r=Ht(e);return r?n(r):!1}function Kt(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 Vt(JSON.parse(atob(n)))}catch{return}}function qt(e){let t=Kt(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 Jt(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 Yt(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}function Xt(e){let t=e.trim(),n=Vt(Yt(t))??Jt(t);return n&&Gt(n)?`oauth`:Kt((n?Ut(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Zt(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 Qt(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 $t(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&Rt.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`&&Gt(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=Ut(e),r=Gt(e)?`oauth`:Xt(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Wt(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function en(e){for(let t of zt){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>Vt(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function tn(e){let t=e.trim();if(!t)return[];let n=Yt(t);if(Array.isArray(n)){let e=n.map(e=>Vt(e)).filter(e=>e!==void 0);if(e.length>0)return Zt(e)?[Qt(t,e)]:e.map($t)}else{let e=Vt(n);if(e){let t=en(e);return t?t.map($t):[$t(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=Jt(r[0]);return e?[$t(e)]:nn(r[0])}let i=Jt(t);return i&&(Ut(i)||Object.keys(i).length===r.length)?[$t(i)]:r.flatMap(nn)}function nn(e){let t=Vt(Yt(e));if(t){let e=en(t);return e?e.map($t):[$t(t)]}return[{value:e,kind:Xt(e)}]}function rn(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 an(e){return e===`active`?0:e===`cooldown`?2:3}function on(e){if(e===void 0)return;let t=new Date(e).getTime();if(Number.isFinite(t))return t<=Date.now()?`Expired ${new Date(e).toLocaleDateString()}`:We(e,!1)}function sn({cooldowns:e,reason:t}){if(!e)return null;let n=We(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,$.jsxs)(G,{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 ln(e){return e.credentialKind===`oauth`?`blue`:`ok`}function un({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=$e(e);if(e.status===`disabled`){let t=cn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,$.jsxs)(X,{gap:`4px`,children:[(0,$.jsxs)(G,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,$.jsx)(G,{tone:`warn`,title:e.lastError,children:Nt(e.credentialKind)}):Mt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(G,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Pt(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,$.jsxs)(X,{gap:`4px`,children:[(0,$.jsxs)(G,{tone:ln(e),dot:!0,children:[`Active`,cn(e)?` - ${cn(e)}`:``]}),Mt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(G,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Pt(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,$.jsxs)(X,{gap:`4px`,children:[(0,$.jsxs)(G,{tone:`warn`,dot:!0,children:[`Cooldown`,cn(e)?` - ${cn(e)}`:``,` `,e.cooldownUntil?`(${We(e.cooldownUntil)})`:``]}),Mt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,$.jsx)(G,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Pt(e.lastErrorCategory,e.credentialKind)}):null,(0,$.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,$.jsx)(G,{tone:`disabled`,children:`Disabled`})}function dn({windows:e}){if(e===void 0||e.length===0)return null;let t=0,n=0,r=!1,i=null;for(let a of e){if(a.accounting!==`pooled`){typeof a.remainingPercent==`number`&&Number.isFinite(a.remainingPercent)&&(i=i===null?a.remainingPercent:Math.min(i,a.remainingPercent));continue}let e=typeof a.limit==`number`&&Number.isFinite(a.limit)?a.limit:null,o=typeof a.remaining==`number`&&Number.isFinite(a.remaining)?a.remaining:e!==null&&typeof a.used==`number`&&Number.isFinite(a.used)?e-a.used:null;o!==null&&e!==null&&(t+=Math.max(0,o),n+=e,r=!0)}let a=null;return r?a=`${fn(t)} of ${fn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${fn(t)} credits available of ${fn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function fn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function pn({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{v.error(`Clipboard access denied`)}};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,$.jsx)(_,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{v.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;v.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,$.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)(Y,{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)(X,{gap:`8px`,className:`justify-end`,children:(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function mn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=me(),l=Pe(),d=Ye(t.id),f=t.status===`disabled`,m=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,h=Number.isFinite(m)&&m>Date.now(),g=t.status===`cooldown`||h,[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[,C]=(0,Q.useState)(0),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(``),O=Ze(e),ee=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),k=O.enabled?`Mysterious accounts`:ee,A=on(t.tokenExpiresAt),j=Qe(t),N=Math.max(h&&t.cooldownUntil?m:0,j??0);(0,Q.useEffect)(()=>{if(N<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[N]);let te=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>v.success(`Account renamed`,n),onError:e=>v.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,$.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:f?.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 ${k}`,className:`cursor-pointer`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,$.jsx)(K,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&te(),e.key===`Escape`&&T(!1)},onBlur:te,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:k}),(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 ${k}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,$.jsx)(F,{size:11})})]})}),(0,$.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,$.jsx)(un,{account:t}),A?(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:A,children:A}):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)(dn,{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 no longer carry manual ceilings.`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,$.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,$.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${k}`,onClick:()=>b(!0),title:`View Health & Error History`}),(0,$.jsx)(_,{size:`icon`,variant:`secondary`,icon:d.isPending?(0,$.jsx)(u,{size:12,className:`animate-spin`}):(0,$.jsx)(p,{size:12}),label:d.isPending?`Testing…`:`Test`,"aria-label":`Test ${k}`,disabled:d.isPending,onClick:()=>{d.mutate(void 0,{onSuccess:e=>{e?.ok?v.success(`Account test passed`,k):v.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>v.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,$.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(M,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${k}`,onClick:()=>S(!0),title:`Replace API key`}),(0,$.jsx)(_,{size:`icon`,variant:`secondary`,icon:f?(0,$.jsx)(it,{size:12}):(0,$.jsx)(re,{size:12}),label:f?`Enable`:`Disable`,"aria-label":f?`Enable ${k}`:`Disable ${k}`,disabled:c.isPending,onClick:()=>{let n=f;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>v.success(n?`Account enabled`:`Account disabled`,k),onError:e=>v.error(`Update failed`,e.message??`Unable to update account`)})},title:f?`Enable account`:`Disable account`}),g?(0,$.jsx)(_,{size:`icon`,variant:`secondary`,icon:(0,$.jsx)(ae,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${k}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,(0,$.jsx)(_,{size:`icon`,variant:`danger`,icon:(0,$.jsx)(se,{size:12}),label:`Delete`,"aria-label":`Delete ${k}`,onClick:()=>s(t),title:`Delete account`})]})]}),y&&(0,$.jsx)(Xe,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode},onClose:()=>b(!1)}),x&&(0,$.jsx)(pn,{providerId:e,account:t,onClose:()=>S(!1)})]})}var hn=[{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 gn(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=an(e.status)-an(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 _n({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=le(),s=me(),c=Pe(),l=Ee(),u=Ke(e).data??new Map,d=Je(),f=(0,Q.useMemo)(()=>{let t=new Map;for(let n of d.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[d.data,e]),[m,h]=(0,Q.useState)(``),[g,y]=(0,Q.useState)(new Set),[b,x]=(0,Q.useState)(`added-asc`),[S,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(!1),[ee,k]=(0,Q.useState)(!1),A=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!ee)return;let e=e=>{A.current&&!A.current.contains(e.target)&&k(!1)},t=e=>{e.key===`Escape`&&k(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[ee]);let M=m.trim().toLowerCase(),N=(0,Q.useMemo)(()=>M?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return M.split(/\s+/).every(e=>t.includes(e))}):t,[t,M]),te=(0,Q.useMemo)(()=>{let e=b.slice(0,b.lastIndexOf(`-`)),t=b.endsWith(`-desc`)?-1:1,n=[...N];return n.sort((n,r)=>t*gn(n,r,e)),n},[N,b]),P=(0,Q.useMemo)(()=>t.filter(e=>g.has(e.id)),[t,g]),F=N.length>0&&N.every(e=>g.has(e.id)),ne=P.some(e=>e.status===`disabled`),ie=P.some(e=>e.status!==`disabled`),ce=P.length===0,de=(e,t)=>{y(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},fe=()=>{y(e=>{let t=new Set(e);if(F)for(let e of N)t.delete(e.id);else for(let e of N)t.add(e.id);return t})},L=async(e,t)=>{if(P.length===0)return;C(!0);let n=await Promise.allSettled(P.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;C(!1),r===0?v.success(`${e} complete`,`${i} account${i===1?``:`s`}`):v.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},pe=()=>L(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),he=async()=>{t.length!==0&&(C(!0),E({done:0,total:t.length}),await Ft(t,3,async(e,n)=>{let r=await ue(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return E({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:I.quota.all}),o.invalidateQueries({queryKey:I.providers.all})]),C(!1),E(null),v.success(`Test complete`,`${t.length} account${t.length===1?``:`s`} tested`))},_e=t=>L(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),ve=async()=>{if(P.length!==0){C(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:P.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Re(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),v.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){v.error(`Export failed`,e.message??`Unable to export accounts`)}finally{C(!1)}}};return(0,$.jsxs)(Y,{gap:`8px`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,$.jsxs)(`label`,{className:`relative min-w-20 flex-[1_1_10rem]`,children:[(0,$.jsx)(oe,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,$.jsx)(K,{id:`accounts-search`,value:m,onChange:e=>h(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,$.jsx)(_,{size:`sm`,variant:`primary`,icon:(0,$.jsx)(p,{size:12}),disabled:S||t.length===0,onClick:he,"aria-label":w===null?`Test all accounts`:`Testing accounts, ${w.done} of ${w.total} tested`,title:`Test every account, regardless of selection or filters`,children:w===null?`Test all`:`Tested ${w.done}/${w.total}`}),(0,$.jsxs)(`div`,{ref:A,className:`relative`,children:[(0,$.jsxs)(_,{size:`sm`,variant:`secondary`,disabled:S||ce,"aria-expanded":ee,"aria-haspopup":`menu`,"aria-label":ce?`Select accounts to enable bulk actions`:`Bulk actions for ${P.length} selected accounts`,onClick:()=>k(e=>!e),children:[`Actions`,ce?``:` (${P.length})`,(0,$.jsx)(z,{size:12,"aria-hidden":`true`,className:`transition-transform ${ee?`rotate-180`:``}`})]}),ee&&!ce?(0,$.jsxs)(`div`,{role:`menu`,"aria-label":`Selected account actions`,className:`absolute left-0 top-full z-50 mt-1 flex w-64 popover-max flex-col gap-1 rounded-control border border-inner-border bg-popover-bg p-2 shadow-popout sm:left-auto sm:right-0`,children:[(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(ae,{size:12}),disabled:S,onClick:()=>{k(!1),pe()},children:`Recover`}),ne?(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(it,{size:12}),disabled:S,onClick:()=>{k(!1),_e(!0)},children:`Enable`}):null,ie?(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(re,{size:12}),disabled:S,onClick:()=>{k(!1),_e(!1)},children:`Disable`}):null,(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,$.jsx)(T,{size:12}),disabled:S,onClick:()=>{k(!1),ve()},children:`Export JSON`}),(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`danger`,className:`w-full justify-start`,icon:(0,$.jsx)(se,{size:12}),disabled:S,onClick:()=>{k(!1),O(!0)},children:`Delete`}),(0,$.jsx)(_,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,disabled:S,onClick:()=>{y(new Set),k(!1)},children:`Clear selection`})]}):null]}),(0,$.jsx)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary [&_.radix-select-trigger]:font-semibold [&_.radix-select-trigger]:bg-hover [&_.radix-select-trigger]:text-text-primary`,children:(0,$.jsx)(q,{size:`sm`,value:b,onValueChange:e=>x(e),options:hn,"aria-label":`Sort accounts by`})}),(0,$.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:F,onChange:fe,"aria-label":`Select accounts`}),(0,$.jsx)(`span`,{children:`Select`})]}),r?(0,$.jsx)(_,{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)(`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:te.length===0?(0,$.jsx)(j,{compact:!0,icon:(0,$.jsx)(oe,{size:20}),title:`No matching accounts`,message:M?`Nothing matches “${M}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):te.map(t=>(0,$.jsx)(mn,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:f.get(t.id),selected:g.has(t.id),onToggleSelect:de,onDelete:n},t.id))}),(0,$.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,$.jsxs)(`span`,{children:[`Showing `,N.length,` account`,N.length===1?``:`s`,M?` (filtered from ${t.length})`:``]})}),(0,$.jsx)(ge,{open:D,onClose:()=>{S||O(!1)},onConfirm:async()=>{await L(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await ue(t,{method:`DELETE`}),o.removeQueries({queryKey:I.quota.account(e.id),exact:!0})}),y(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:I.providers.accounts(e)}),o.invalidateQueries({queryKey:I.providers.all}),o.invalidateQueries({queryKey:I.quota.all})])},title:`Delete ${P.length} account${P.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var vn=2097152,yn=vn/1048576;function bn({providerId:e,accounts:t,onClose:n}){let r=ye(),i=Oe(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(`auto`),p=tn(s),m=p.length>1,h=p.length===1?p[0]:void 0,g=d===`auto`?h?.kind:d,b=h&&g===`jwt`?qt(h.value):void 0,x=t.map(e=>e.label),S=m?rn(p,e,x):[],C=e=>{let t=d===`auto`?e.kind===`jwt`?`jwt`:`auto`:d;return{credentialKind:t===`auto`&&e.kind===`oauth`?`oauth`:`api_key`,credentialMode:t,secret:e.value}},w=r.isPending||l,T=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=tn(e);if(t.length>1)v.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;v.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{v.error(`Clipboard access denied`)}},E=e=>{if(e.size>vn){v.error(`File too large`,`Credential files must be ${yn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=tn(n);if(r.length===0){v.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}v.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>v.error(`Could not read that file`),t.readAsText(e)},D=async()=>{if(p.length!==0){if(p.length===1){let t=p[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...C(t)}},{onSuccess:()=>{v.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>v.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=await i.mutateAsync({providerId:e,accounts:p.map((e,t)=>({label:S[t],...C(e)}))}),r=t.results.filter(e=>!e.ok),a=t.created;if(a>0&&v.success(`${a} account${a===1?``:`s`} added`,r.length>0?`${r.length} skipped`:void 0),r.length>0){let e=r.slice(0,5).map(e=>`${S[e.index]??e.index}: ${e.error??`rejected`}`).join(`
|
|
2
|
+
`);v.error(`${r.length} account${r.length===1?``:`s`} skipped`,e+(r.length>5?`\n…and ${r.length-5} more`:``))}a>0&&n()}finally{u(!1)}}};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:w,children:`Cancel`}),(0,$.jsx)(_,{size:`sm`,variant:`primary`,disabled:w||p.length===0,onClick:()=>void D(),children:w?`Connecting...`:m?`Add ${p.length} Accounts`:`Add Account`})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!m&&(0,$.jsx)(K,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:h?.identity??`${e} account`}),(0,$.jsx)(q,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,$.jsxs)(Y,{gap:`6px`,className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),m?(0,$.jsxs)(G,{tone:`accent`,children:[`Detected: `,p.length,` accounts`]}):h?(0,$.jsxs)(G,{tone:g===`oauth`||g===`jwt`?`accent`:`default`,children:[`Detected:`,` `,g===`oauth`?`OAuth`:g===`jwt`?`Static JWT`:`API key`,h.identity?` · ${h.identity}`:``]}):null,h&&g===`jwt`?(0,$.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,b?` · expires ${new Date(b).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,$.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,$.jsxs)(X,{gap:`8px`,className:`justify-end`,children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>void T(),children:`Paste`}),(0,$.jsxs)(`label`,{className:y({size:`sm`,className:`cursor-pointer`}),children:[(0,$.jsx)(`input`,{type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,"aria-label":`Import credentials from a file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&E(t)}}),`Import file`]})]})]}),m&&(0,$.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:p.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,$.jsx)(`span`,{className:`truncate min-w-0`,children:S[t]}),(0,$.jsx)(G,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))})]})})}function xn(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 Sn({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),l=je(),p=et(),m=le(),h=De(e),g=(0,Q.useRef)(null),y=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let t=setInterval(()=>{m.invalidateQueries({queryKey:I.providers.accounts(e)})},1500);return()=>clearInterval(t)},[m,e]),(0,Q.useEffect)(()=>{let e=h.data?.map(e=>e.id)??null;if(e!==null){if(g.current===null){g.current=new Set(e);return}y.current||e.find(e=>!g.current.has(e))!==void 0&&(y.current=!0,r.close(),v.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[h.data,r,i]);let b=()=>{r.close(),i(!1)},[x,S]=(0,Q.useState)(!1),C=()=>{S(!0),m.invalidateQueries({queryKey:I.providers.accounts(e)}).finally(()=>S(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){v.error(`Clipboard is empty`);return}c(e),v.success(`Pasted redirect URL`)}catch{v.error(`Clipboard unavailable on this origin`)}};return(0,$.jsx)(P,{open:!0,onClose:b,title:`Connect via OAuth`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:b,disabled:l.isPending,children:`Cancel`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:C,disabled:l.isPending||x,title:`You already approved in the popup — check now instead of waiting`,children:x?`Checking…`:`Complete`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=xn(s);if(`error`in t){v.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),v.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>v.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,$.jsxs)(Y,{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)(u,{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)(X,{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)(_,{variant:`secondary`,size:`sm`,icon:a?(0,$.jsx)(f,{size:12}):(0,$.jsx)(d,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),p(()=>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)(X,{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)(_,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function Cn(e){try{return new URL(e).host}catch{return e}}function wn({providerId:e,parameters:t,onClose:n}){let r=_e(),i=xe(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,p]=(0,Q.useState)(!1),m=et();(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||(v.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let h=(0,Q.useRef)(null),[g,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?h.current=e:y(!0),()=>{let e=h.current;h.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(),v.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=h.current;e&&!e.closed&&e.close(),v.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),v.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,$.jsx)(P,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,$.jsx)(Y,{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)(u,{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)(_,{variant:`secondary`,size:`sm`,icon:l?(0,$.jsx)(f,{size:12}):(0,$.jsx)(d,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),p(!0),m(()=>p(!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)(X,{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:Cn(a.verificationUri)}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(ke,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:s?(0,$.jsx)(f,{size:12}):(0,$.jsx)(d,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),m(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:g?`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)(u,{size:16,className:`animate-spin text-accent shrink-0`}),(0,$.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function Tn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function En(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Dn({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,$.jsx)(Y,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,$.jsx)(q,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,$.jsx)(K,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function On({providerId:e,providerName:t,fields:n,onClose:r}){let i=Ne(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,d]=(0,Q.useState)(()=>Tn(n)),f=(0,Q.useMemo)(()=>En(n,l),[n,l]);return(0,$.jsx)(P,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){v.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(f.length>0){v.error(`Missing required fields`,`Fill in: ${f.join(`, `)}`);return}i.mutate({providerId:e,credential:a.trim(),...Object.keys(l).length>0?{fields:l}:{},...s.trim().length>0?{accountLabel:s.trim()}:{}},{onSuccess:()=>{v.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>v.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,$.jsx)(u,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,$.jsxs)(Y,{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)(Dn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>d(n=>({...n,[e]:t}))}),(0,$.jsx)(K,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,$.jsx)(K,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}function kn(e,t,n){let r=n?.trim()??``,i=r.indexOf(` — `),a=i>0?r.slice(0,i):``,o=i>0?r.slice(i+3):r;return{title:`${e}/${t} probe failed${a.length>0?` via ${a}`:``}`,detail:o.length>0?o:`Unknown error`}}function An(e,t,n){let{title:r,detail:i}=kn(e,t,n);return[r,i]}function jn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function Mn(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var Nn=[{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`}],Pn={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function Fn(){return ut.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function In({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,$.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0`,children:(0,$.jsx)(q,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:Fn()})})}function Ln({providerId:e,provider:t,onClose:n}){let r=Ae(),i=Ie(),[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]),[d,f]=(0,Q.useState)(c??`chat`),[m,h]=(0,Q.useState)(`auto`),[g,y]=(0,Q.useState)(`idle`),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(Vn),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(y(`testing`),x(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:d,reasoningEffort:m,serviceKind:`llm`}},{onSuccess:e=>{e.ok?y(`passed`):(y(`failed`),x(e.error??`Model probe failed`))},onError:e=>{y(`failed`),x(e.message??`Model probe failed`)}}))};return(0,$.jsx)(P,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=H(S.contextLimit),r=H(S.outputLimit);if(t===null||r===null){v.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:d,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:S.passthrough,image:S.passthrough?!0:S.image,reasoning:S.passthrough?!0:S.reasoning,toolCall:S.passthrough?!0:S.toolCall}},{onSuccess:()=>{v.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>v.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,$.jsxs)(Y,{gap:`10px`,children:[(0,$.jsxs)(X,{gap:`8px`,align:`flex-end`,children:[(0,$.jsx)(K,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),y(`idle`),x(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:g===`testing`?(0,$.jsx)(u,{size:13,className:`animate-spin`}):(0,$.jsx)(p,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:g===`testing`?`Testing...`:`Test`})]}),E&&(0,$.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,$.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,$.jsx)(q,{label:`Wire family`,id:`add-model-wire-family`,value:d,onValueChange:e=>{f(e),y(`idle`),x(``)},options:l.map(e=>({value:e,label:qn(e)}))}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,$.jsx)(In,{id:`add-model-thinking-effort`,value:m,onChange:e=>{h(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)(Hn,{draft:S,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(d)&&(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:qn(d)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),g===`passed`&&(0,$.jsx)(tt,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),g===`failed`&&(0,$.jsx)(tt,{tone:`danger`,live:`alert`,children:b||`Model test failed.`})]})})}function Rn(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var zn=String(Ve),Bn=String(ze);function Vn(){return{...Rn(),contextLimit:zn,outputLimit:Bn}}function Hn({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,$.jsxs)(Y,{gap:`10px`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,$.jsxs)(X,{gap:`8px`,children:[(0,$.jsx)(K,{label:`Context`,id:`${n}-context`,placeholder:zn,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,$.jsx)(K,{label:`Output`,id:`${n}-output`,placeholder:Bn,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===zn&&e.outputLimit===Bn,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:zn,outputLimit:Bn}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,U(Ve),` ctx ·`,` `,U(ze),` out`]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,$.jsx)(Y,{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 Un({providerId:e,model:t,onClose:n}){let r=pe(),[i,a]=(0,Q.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,$.jsx)(P,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=H(i.contextLimit),o=H(i.outputLimit);if(a===null||o===null){v.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}r.mutate({providerId:e,modelId:t.modelId,route:t.route??``,metadata:{contextLimit:a??null,outputLimit:o??null,passthrough:i.passthrough,image:i.passthrough?!0:i.image,reasoning:i.passthrough?!0:i.reasoning,toolCall:i.passthrough?!0:i.toolCall}},{onSuccess:()=>n(),onError:e=>v.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,$.jsxs)(Y,{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)(Hn,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Wn({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let g=Ae(),y=R(),[x,T]=(0,Q.useState)(!1),[E,O]=(0,Q.useState)(null),ee=et(),k=n===`llm`?dt(t.modelId,i===`auto`?null:i):t.modelId,A=`${e}/${k}`,j=n===`websearch`?`Searching…`:`Thinking…`,M=()=>{g.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(O({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=kn(e,k,t.error);v.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;v.successRich(`${k} · END ${m(t.latencyMs)}`,(0,$.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,$.jsxs)(X,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,$.jsx)(w,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,$.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,$.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
3
|
+
`)||`No sample text in the response.`)},onError:t=>{O({ok:!1,latencyMs:0}),v.error(...An(e,k,t.message))}})},N=()=>{let n=!t.enabled;y.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>v.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>v.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,$.jsx)(o,{size:14})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{title:A,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:k}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,$.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...Kn(t.wireFamily)},children:qn(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,$.jsx)(`span`,{title:jn(t.source),className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-teal`,children:Mn(t.source)}):null,t.proOnly===!0?(0,$.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,$.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,$.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,$.jsx)(_,{variant:`ghost`,size:`sm`,icon:x?(0,$.jsx)(f,{size:12}):(0,$.jsx)(d,{size:12}),"aria-label":`Copy ${A}`,title:`Copy ${A}`,onClick:()=>{navigator.clipboard?.writeText(A),T(!0),ee(()=>T(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,$.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,$.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,$.jsx)(s,{size:12})}):null,t.vision?(0,$.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,$.jsx)(D,{size:12})}):null,t.toolCall?(0,$.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,$.jsx)(ce,{size:12})}):null,r?(0,$.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,$.jsx)(b,{size:12})}):null]}),(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,$.jsx)(`span`,{title:Be,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,$.jsx)(S,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${U(t.contextLimit)} ctx`:(0,$.jsx)(`span`,{title:W,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${U(t.outputLimit)} out`:(0,$.jsx)(`span`,{title:W,className:`cursor-help`,children:` · n/a out`})]}),c?(0,$.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,$.jsx)(F,{size:11})}):null]}),(0,$.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,disabled:g.isPending,onClick:M,"aria-label":`Test ${k}`,title:g.isPending?`Probing ${k}…`:E?.ok?`Last probe OK in ${m(E.latencyMs)} — click to re-test`:E?`Last probe failed — click to retry`:`Test ${k}`,className:`flex-1 justify-center`,icon:g.isPending?(0,$.jsx)(u,{size:12,className:`animate-spin`}):E?E.ok?(0,$.jsx)(`span`,{className:`inline-flex text-green`,children:(0,$.jsx)(C,{size:12})}):(0,$.jsx)(`span`,{className:`inline-flex text-red`,children:(0,$.jsx)(h,{size:12})}):(0,$.jsx)(p,{size:12}),children:g.isPending?j:E?.ok?m(E.latencyMs):E?`Fail`:`Test`}),(0,$.jsx)(_,{variant:`ghost`,size:`sm`,disabled:y.isPending,onClick:N,icon:t.enabled?(0,$.jsx)(re,{size:12}):(0,$.jsx)(it,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,$.jsx)(_,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,$.jsx)(se,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var Gn=(0,Q.memo)(Wn);function Kn(e){return e===`responses`?{color:`var(--purple)`,background:`var(--purple-soft)`}:e===`messages`?{color:`var(--orange)`,background:`color-mix(in srgb, var(--orange) 14%, transparent)`}:{color:`var(--teal)`,background:`var(--teal-soft)`}}function qn(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function Jn({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=be(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),u=e=>e.enabled!==!1,d=Nn.map(e=>({...e,rows:t.filter(t=>u(t)&&e.matches(t.source))})).filter(e=>e.rows.length>0),f=t.filter(e=>!u(e)),p=t=>(0,$.jsx)(Gn,{providerId:e,model:t,serviceKind:r,searchCapable:i,thinkingEffort:n,deletePending:a.isPending,onDeleteRequest:s,onEditRequest:t.source===`builtin`?void 0:l},`${t.modelId}::${t.route}`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Y,{gap:`16px`,children:[d.map(e=>(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,$.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,$.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:Pn.label}),(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,$.jsxs)(`span`,{title:Pn.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,Pn.hint]})]}),(0,$.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,$.jsx)(ge,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),v.success(`Model deleted`,`${e}/${o.modelId}`),s(null))},title:`Delete model?`,message:`Delete ${e}/${o?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),c===null?null:(0,$.jsx)(Un,{providerId:e,model:c,onClose:()=>l(null)})]})}function Yn(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function Xn(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function Zn(){let{providerId:e}=de(),[t]=Se(),n=e??``,r=t.get(`service`),[i,a]=(0,Q.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=Te(n),s=we(n),l=De(n),u=fe(),d=fe({silent:!0}),[f,p]=(0,Q.useState)(!1),m=Ce(),h=ve(),g=Fe(),y=le(),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),E=Ae(),[D,O]=(0,Q.useState)(``),[N,te]=(0,Q.useState)(``),[F,ae]=(0,Q.useState)(null),oe=e=>`cartethyia:provider:${e}:thinking-effort`,ce=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(oe(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return ut.includes(n)?n:`auto`},[L,pe]=(0,Q.useState)(()=>ce(n));(0,Q.useEffect)(()=>{if(!n)return;let e=ce(n);e!==L&&pe(e)},[n]),(0,Q.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(oe(n),L)},[n,L]);let[me,he]=(0,Q.useState)(!1),[_e,ye]=(0,Q.useState)(!1),[R,be]=(0,Q.useState)(null),[xe,Ee]=(0,Q.useState)({}),[Oe,je]=(0,Q.useState)({}),[z,Me]=(0,Q.useState)(null),[Ne,Pe]=(0,Q.useState)(!1),[Ie,Re]=(0,Q.useState)(null),H=(0,Q.useRef)(null),ze=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{let e=H.current;H.current=null,e&&!e.closed&&e.close()},[]);let U=o.data,Be=n===`opencode`||n===`cline`,Ve=U===void 0?[`llm`]:Xn(U),W=[];for(let e of Ve)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&W.push(e);(0,Q.useEffect)(()=>{if(U===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=W[0];if(e!==void 0&&W.includes(e)){i!==e&&a(e);return}!W.includes(i)&&t!==void 0&&a(t)},[U,r,i,W.join(`|`)]),(0,Q.useEffect)(()=>{Be&&U!==void 0&&U.supportsModelDiscovery!==!1&&ze.current!==n&&(ze.current=n,d.mutate(n))},[Be,d,n,U?.supportsModelDiscovery]);let G=l.data??[],K=s.data??[],q=(()=>{let e=new Map;for(let t of K){let n=`${t.serviceKind??`llm`}:${t.modelId}`,r=e.get(n);if(!r)e.set(n,t);else{let i=r.contextLimit??0;(t.contextLimit??0)>i&&e.set(n,t)}}return[...e.values()].sort((e,t)=>e.modelId.localeCompare(t.modelId))})(),J=q.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),We=q.filter(e=>e.serviceKind===`websearch`),Ge=q.filter(e=>e.serviceKind===`imageGeneration`),Ke=q.filter(e=>e.serviceKind===`videoGeneration`),Z=W.includes(i)?i:W[0],qe=N||We[0]?.modelId||``,Je=()=>{let e=D.trim();qe&&e&&(ae(null),E.mutate({providerId:n,request:{modelId:qe,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>ae({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>ae({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,$.jsx)(A,{label:`Loading provider...`});if(o.isError)return(0,$.jsx)(k,{title:`Unable to load providers`,message:`The provider details could not be read, so this page cannot resolve its endpoint settings.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,$.jsx)(ft,{to:`/providers`,label:`Back to providers`})});if(!U)return(0,$.jsx)(j,{icon:(0,$.jsx)(at,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,$.jsx)(ft,{to:`/providers`,label:`Back to providers`})});let Ye=G.filter(e=>e.status===`active`).length,Xe=e=>{let t=e===`browser`?U?.oauthFlows?.browserLoginFields??[]:U?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?Qe():he(!0);return}Ee(Tn(t)),be(e)},Ze=()=>{if(R===null)return;let e=En(R===`browser`?U?.oauthFlows?.browserLoginFields??[]:U?.oauthFlows?.deviceLoginFields??[],xe);if(e.length>0){v.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=R;be(null),t===`browser`?Qe(xe):(je(xe),he(!0))},Qe=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,H.current=t),g.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:n})=>{let r=null;if(t&&!t.closed?(t.location.href=e,r=t):(r=window.open(e,`cartethyia-oauth`,`popup,width=720,height=820`),r&&(r.opener=null,H.current=r)),!r){v.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Re({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),H.current===t&&(H.current=null),v.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,$.jsxs)(Y,{gap:`16px`,children:[(0,$.jsx)(pt,{title:`${U.label||U.displayName}${Z?` (${Yn(Z)})`:``}`,description:`${U.providerId}/${U.baseUrl?` · ${U.baseUrl}`:``}`,icon:(0,$.jsx)(He,{icon:U.providerId,name:U.label||U.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,$.jsx)(X,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:U.isBuiltIn?(0,$.jsx)(_,{variant:U.enabled?`danger`:`secondary`,icon:U.enabled?(0,$.jsx)(re,{size:13}):(0,$.jsx)(it,{size:13}),loading:h.isPending,onClick:()=>h.mutate({providerId:n,enabled:!U.enabled},{onSuccess:e=>v.success(e.enabled?`Provider enabled`:`Provider disabled`,U.label||U.displayName),onError:e=>v.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:U.enabled?`Disable provider globally`:`Enable provider globally`,children:U.enabled?`Disable`:`Enable`}):null})}),(0,$.jsx)(Ot,{provider:U}),U.isBuiltIn?null:(0,$.jsx)(kt,{provider:U}),Z===`llm`?(0,$.jsx)(Ct,{providerId:n,clientVersion:U.clientVersion,routeIdentityVersions:U.routeIdentityVersions,userAgentEditable:mt(U)}):null,(0,$.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:U.requiresAccount===!1?(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:`Accounts`,icon:(0,$.jsx)(nt,{size:16})}),(0,$.jsx)(B,{children:(0,$.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:`Accounts`,subtitle:`${G.length} total · ${Ye} active · ${G.length-Ye} disabled`,icon:(0,$.jsx)(nt,{size:16}),action:(0,$.jsxs)(Ue,{children:[U.oauthFlows?.browser&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(ke,{size:13}),disabled:g.isPending,onClick:()=>Xe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:g.isPending?`Starting...`:`Login with browser`}),U.oauthFlows?.device&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(M,{size:13}),onClick:()=>Xe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),U.oauthFlows?.import&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(T,{size:13}),onClick:()=>ye(!0),title:U.oauthFlows.browser||U.oauthFlows.device||U.oauthFlows.refreshable?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:U.oauthFlows.browser||U.oauthFlows.device||U.oauthFlows.refreshable?`Import credential`:`Add API key`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(ne,{size:13}),onClick:()=>S(!0),children:`Add Account`})]})}),(0,$.jsxs)(B,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(wt,{providerId:n}),l.isPending?(0,$.jsx)(A,{label:`Loading accounts...`}):l.isError?(0,$.jsx)(k,{message:`Failed to load accounts`,onRetry:()=>l.refetch()}):G.length===0?(0,$.jsx)(j,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,$.jsx)(_n,{providerId:n,accounts:G,onDelete:e=>Me(e),showGrokProbe:Z===`llm`&&n===`grok`,grokProbePending:m.isPending,onGrokProbe:()=>{m.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`reply my message with exact number 407`,stream:!0,serviceKind:`llm`}},{onSuccess:e=>{let t=e.results.filter(e=>e.ok).length,n=e.results.filter(e=>e.statusCode===202).length,r=e.results.length-t-n;v.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>v.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),Z===`llm`?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:`Models`,subtitle:`${J.length} model${J.length===1?``:`s`} registered`,icon:(0,$.jsx)(c,{size:16}),action:(0,$.jsxs)(X,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,$.jsx)(In,{id:`models-section-thinking-effort`,value:L,onChange:pe}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(ie,{size:13,className:u.isPending||d.isPending?`animate-spin`:``}),disabled:u.isPending||d.isPending,onClick:()=>u.mutate(n),children:u.isPending||d.isPending?`Fetching...`:`Fetch models`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(se,{size:13,className:f?`animate-spin`:``}),disabled:u.isPending||d.isPending||f||J.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=J.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){p(!0);try{let t=await ue(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([y.invalidateQueries({queryKey:I.providers.models(n)}),y.invalidateQueries({queryKey:I.providers.all})]);let r=t.failures.length;v.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){v.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{p(!1)}}},children:f?`Deleting…`:`Delete fetched`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,icon:(0,$.jsx)(ne,{size:13}),onClick:()=>w(!0),children:`Add Model`})]})}),(0,$.jsx)(B,{className:`flex flex-col gap-8`,children:s.isPending?(0,$.jsx)(A,{label:`Loading models...`}):s.isError?(0,$.jsx)(k,{message:`Failed to load models`,onRetry:()=>s.refetch()}):J.length===0?(0,$.jsx)(j,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,$.jsx)(Jn,{providerId:n,models:J,serviceKind:`llm`,thinkingEffort:L,searchCapable:U?.supportsWebSearch===!0})})]})}):Z===`websearch`?(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,$.jsx)(b,{size:16})}),(0,$.jsx)(B,{className:`flex flex-col gap-6`,children:s.isPending?(0,$.jsx)(A,{label:`Loading search models...`}):s.isError?(0,$.jsx)(k,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):We.length===0?(0,$.jsx)(j,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,$.jsx)(`select`,{value:qe,onChange:e=>{te(e.target.value),ae(null)},className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`,children:We.map(e=>(0,$.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,$.jsx)(`input`,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,$.jsxs)(X,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:Je,children:`Test search`}),F?(0,$.jsx)(`span`,{className:`text-badge`,style:{color:F.ok?`var(--green)`:`var(--red)`},children:F.ok?`Search ok · ${F.latencyMs}ms · ${F.count??0} result(s)`:F.error??`Search failed.`}):null]}),F&&F.results&&F.results.length>0?(0,$.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:F.results.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,$.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):Z===`imageGeneration`||Z===`videoGeneration`?(0,$.jsxs)(V,{children:[(0,$.jsx)(Le,{title:Yn(Z),subtitle:Z===`imageGeneration`?`Models that return an image rather than text.`:`Models that return a video. Wired and routable; not yet verified against a live account.`,icon:Z===`imageGeneration`?(0,$.jsx)(ee,{size:16}):(0,$.jsx)(ct,{size:16})}),(0,$.jsx)(B,{className:`flex flex-col gap-6`,children:s.isPending?(0,$.jsx)(A,{label:`Loading ${Yn(Z).toLowerCase()} models...`}):s.isError?(0,$.jsx)(k,{message:`Failed to load ${Yn(Z).toLowerCase()} models`,onRetry:()=>s.refetch()}):(Z===`imageGeneration`?Ge:Ke).length===0?(0,$.jsx)(j,{title:`No ${Yn(Z)} models found`,message:`This provider advertises ${Yn(Z)}, but no ${Z} model is registered yet.`}):(0,$.jsx)(Jn,{providerId:n,models:Z===`imageGeneration`?Ge:Ke,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,$.jsx)(V,{children:(0,$.jsx)(B,{children:(0,$.jsx)(j,{title:`Service not available`,message:`This provider advertises ${Ve.map(Yn).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),x&&(0,$.jsx)(bn,{providerId:n,accounts:G,onClose:()=>S(!1)}),Z===`llm`&&C?(0,$.jsx)(Ln,{providerId:n,provider:U,onClose:()=>w(!1)}):null,(0,$.jsx)(ge,{open:z!==null,onClose:()=>{Ne||Me(null)},onConfirm:async()=>{if(z){Pe(!0);try{let e=z.tenantId===null?`/global/accounts/${encodeURIComponent(z.id)}`:`/accounts/${encodeURIComponent(z.id)}`;await ue(e,{method:`DELETE`}),y.removeQueries({queryKey:I.quota.account(z.id),exact:!0}),await Promise.all([y.invalidateQueries({queryKey:I.providers.accounts(n)}),y.invalidateQueries({queryKey:I.providers.healthEvents(n,z.id)}),y.invalidateQueries({queryKey:I.providers.all}),y.invalidateQueries({queryKey:I.quota.all})]),v.success(`Account deleted`,z.label||z.id.slice(0,8)),Me(null)}catch(e){throw v.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Pe(!1)}}},title:`Delete account?`,message:`Delete "${z?.label||z?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),me&&(0,$.jsx)(wn,{providerId:n,parameters:Oe,onClose:()=>{he(!1),je({})}}),R!==null&&(0,$.jsx)(P,{open:!0,onClose:()=>be(null),title:R===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>be(null),children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,onClick:Ze,children:`Continue`})]}),children:(0,$.jsxs)(Y,{gap:`12px`,children:[(0,$.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:R===`browser`?`Choose how ${U.label||U.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,$.jsx)(Dn,{fields:R===`browser`?U?.oauthFlows?.browserLoginFields??[]:U?.oauthFlows?.deviceLoginFields??[],values:xe,idPrefix:`flow-${R}`,onChange:(e,t)=>Ee(n=>({...n,[e]:t}))})]})}),_e&&U?.oauthFlows?.import===!0&&(0,$.jsx)(On,{providerId:n,providerName:U.label||U.displayName,fields:U.oauthFlows.importFields,onClose:()=>ye(!1)}),Ie&&(0,$.jsx)(Sn,{providerId:n,authorizeUrl:Ie.authorizeUrl,state:Ie.state,popup:Ie.popup,onClose:e=>{H.current=null,Re(null),e&&y.invalidateQueries({queryKey:I.providers.accounts(n)})}})]})}export{Zn as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{d as r,l as i}from"./numbers-Bs4LOOuf.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-DYdQmdAl.js";import{t as u}from"./dialog-BtpsJU98.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-D7wX2vM5.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{C as ee,Z as h,_ as g,a as _,et as v,g as y,i as te,m as b,rt as x,s as S,st as C,w}from"./entry-Dj9AR0gY.js";import{n as T,r as E,t as D}from"./card--AtFedAq.js";import{t as O}from"./badge-6uzDDvqs.js";import{n as k}from"./input-BG41et9G.js";import{t as A}from"./select-DsX5QT8K.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-CidSfbG7.js";import{t as N}from"./stack-DwLmjUFK.js";import{n as P}from"./inline-BcNGF8Gr.js";import{t as F}from"./list-row-Gh_W4OR_.js";import{t as I}from"./privacy-mode-GM8bej85.js";import{t as L}from"./AccountCooldown-Bjo92Qat.js";var R=e(t(),1),z=n();function ne(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(f,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(d,{size:13}),` Add header`]})]})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var V=r(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),H=r(`block flex-1 p-6 no-underline text-inherit`),U=r(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function W(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var G=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ie(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return G.test(r)?n.origin:null}function K({variant:e,open:t,onClose:n}){let a=te(),o=_(),s=ee(),c=w(),[l,d]=(0,R.useState)(``),[f,m]=(0,R.useState)(``),[h,g]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),[b,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(!0),[T,E]=(0,R.useState)([]),[D,O]=(0,R.useState)(null),[j,N]=(0,R.useState)(!1),[I,L]=(0,R.useState)(null),[B,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>ie(h),[h]);(0,R.useEffect)(()=>{t&&(d(``),y(``),G(U),g(``),x(!1),C(!0),E([]),O(null),L(null))},[t]);let q=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},ae=async()=>{if(!h.trim()){L({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),L(null),O(null);try{let e=ne(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:v.trim(),wireFamily:W,cliIdentity:S,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;L({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else L({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){L({ok:!1,message:p(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(u,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=ne(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:W,compatibilityProfile:{cli_identity:S,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),v.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:v.trim()}}),b&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,z.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder: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)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-url`,value:h,onChange:e=>g(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(g),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)(A,{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)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:v,onChange:e=>y(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:B,onClick:()=>void ae(),children:B?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(y),children:`Paste`})]}),I?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:r(`mt-3 text-caption leading-[1.4] break-words`,I.ok?`text-green`:`text-red`),children:[I.ok?`✓ `:`✗ `,I.message]}),I.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,I.warning]}):null]}):null]}),(0,z.jsx)(F,{actions:(0,z.jsx)(M,{checked:b,onChange:x,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)(F,{actions:(0,z.jsx)(M,{checked:S,onChange:C,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:T,onChange:E})]})})}function q({customProvider:e}){let t=S(),[n,a]=(0,R.useState)(!1),o=y(e.providerId),s=o.data?.length,c=b(e.providerId),l=c.data,d=Q(l??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:r(H,`pr-20 min-h-38`),children:(0,z.jsxs)(P,{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:U,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,z.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,z.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(N,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,z.jsxs)(m,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(C,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(o,{size:13}):(0,z.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(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)(B,{children:e.map(e=>(0,z.jsx)(q,{customProvider:e},e.providerId))}),(0,z.jsx)(K,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(K,{variant:`openai-compatible`,open:r,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||L(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&L(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,z.jsxs)(z.Fragment,{children:[e.healthy>0?(0,z.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),i=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=b(e.providerId),c=s.data,l=Q(c??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:r(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:H,children:(0,z.jsxs)(P,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.providerId,name:i,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:i}),(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,z.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,z.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function me(){let[e,t]=(0,R.useState)(fe),n=g(),u=I(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,R.useMemo)(()=>n.data??[],[n.data]),ee=(0,R.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),h=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`websearch`)&&f(e)),[m,d]),_=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`llm`)&&f(e)),[m,d]),[y,te]=v(),b=y.get(`tab`),S=b===`search`||b===`media`?b:`llm`,w=e=>{te(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,R.useMemo)(()=>m.filter(e=>(W(e).includes(`imageGeneration`)||W(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,R.useMemo)(()=>[...h].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[h]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,R.useMemo)(()=>{if(S===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(S===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=_;return pe.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[_,k,O,S]),M=n.isPending&&!n.data?(0,z.jsx)(c,{label:`Loading providers...`}):n.isError?(0,z.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(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:M})]}):(0,z.jsx)(N,{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:()=>w(e),className:r(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,S===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${h.length})`:e===`media`?` (${O.length})`:` (${_.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(a,{size:12}):(0,z.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:S===`search`?`Fallback runs only when the model invokes Websearch`:S===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),S===`llm`?(0,z.jsx)(ae,{customProviders:ee}):null,j.length===0?(0,z.jsx)(D,{children:(0,z.jsx)(T,{children:(0,z.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let i=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!i,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(C,{size:15,className:r(`mt-1 shrink-0 transition-transform`,i&&`-rotate-90`)}),(0,z.jsxs)(N,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:`text-body font-bold tracking-[-0.01em]`,children:[n.title,` (`,n.providers.length,`)`,i?` (Hidden)`:``]}),!i&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),i?null:(0,z.jsx)(B,{children:n.providers.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:S===`search`?`websearch`:S===`media`?W(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{me as default,Q as summarizeAccounts};
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,T as o,b as s,l as c,s as l,t as u}from"./numbers-Bs4LOOuf.js";import{t as d}from"./download-A0SW9OCW.js";import{t as f}from"./eye-off-Bk5g2luF.js";import{t as p}from"./eye-C_hawfH4.js";import{t as m}from"./gauge-BbIMy7MB.js";import{n as h,r as g,t as _}from"./state-DYdQmdAl.js";import{t as v}from"./dialog-BtpsJU98.js";import{t as y}from"./pencil-768ysRAr.js";import{t as ee}from"./plus-DIdX_g-x.js";import{t as b}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{C as w,T,c as E,v as D,y as O}from"./assert-NHwYq95t.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-D7wX2vM5.js";import{t as P}from"./useMutation-w4u4CVue.js";import{R as te,rt as ne}from"./entry-Dj9AR0gY.js";import{n as re,r as ie,t as ae}from"./card--AtFedAq.js";import{n as oe}from"./download-dRFo5_Wu.js";import{t as F}from"./badge-6uzDDvqs.js";import{n as I}from"./input-BG41et9G.js";import{t as se}from"./select-DsX5QT8K.js";import{t as L}from"./switch-CidSfbG7.js";import{t as ce}from"./stack-DwLmjUFK.js";import{n as le}from"./inline-BcNGF8Gr.js";import{r as R,t as ue}from"./layout-C8mer_Ak.js";import{i as de,n as fe}from"./privacy-mode-GM8bej85.js";import{n as z}from"./live-BJGYRBnR.js";var pe=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),me=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),he=1e6,ge=1e8,_e=5e6,ve=`sin1`,ye=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function be(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:D(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function xe(){let e=T();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool created`)},onError:e=>{l.error(`Could not create the proxy pool.`,j(e))}})}function Se(){let e=T();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Ce(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function we(){let e=T();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy updated`)},onError:e=>{l.error(`Could not update the proxy pool.`,j(e))}})}function Te(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:D(t)}),enabled:!!e,...A,refetchInterval:k.status})}function Ee(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),l.success(`Proxy pool recovered`)},onError:e=>{l.error(`Could not recover the proxy pool.`,j(e))}})}function De(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool deleted`)},onError:e=>{l.error(`Could not delete the proxy pool.`,j(e))}})}function Oe(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function ke(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function Ae(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Health check complete`)},onError:e=>{l.error(`Health check failed.`,j(e))}})}function je(){let e=T();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Me(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Provider cooldowns cleared`)},onError:e=>{l.error(`Could not clear provider cooldowns.`,j(e))}})}var B=t(n(),1),V=r(),H={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},Ne=ye.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Pe({onClose:e}){let t=Se(),[n,r]=(0,B.useState)(`cloudflare`),[i,a]=(0,B.useState)(ve),[o,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),_=H[n],y=o.trim().length>0&&(!_.needsAccount||d.trim().length>0);return(0,V.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,V.jsx)(ne,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,_.label,` account and registers its URL (`,(0,V.jsx)(`code`,{children:_.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,V.jsx)(se,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:O.map(e=>({value:e,label:H[e].label}))}),(0,V.jsx)(I,{label:_.tokenLabel,id:`relay-token`,type:`password`,value:o,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),_.needsAccount?(0,V.jsx)(I,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,V.jsx)(I,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>m(e.target.value)}),_.hasRegion?(0,V.jsx)(se,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>a(e),options:Ne}):null,_.hasRegion?(0,V.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,V.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,V.jsx)(c,{variant:`primary`,size:`sm`,onClick:()=>{y&&t.mutate({target:n,token:o.trim(),..._.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},..._.hasRegion?{region:i}:{}},{onSuccess:e=>{g(e.relayUrl),u(``),l.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>l.error(j(e,`Relay deploy failed.`))})},disabled:!y||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),h?(0,V.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,V.jsx)(`code`,{children:h})]}):null]}),t.isError?(0,V.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,V.jsx)(s,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Fe(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Ie(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Le(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Ie(e,t,r(e)),o=Ie(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function U(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var W=[`http`,`https`,`socks5`];function G(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Re(e,t){let n=e.trim();return t===null||G(n)?n:`${t}://${n}`}function K(e){return e.find(e=>e.trim()!==``)}function q(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var ze=1024**3;function Be(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*ze))}function J(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var Ve=4,He=`cartethyia_proxy_test_payload`,Ue=`cartethyia_proxy_check_results`,We=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],Ge=`opencode`,Ke=4,qe=`Mysterious Proxy`;function Y(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function Je(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function X(e){return e.label||Je(e).name||e.id}var Z=1024**3;function Ye(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Xe(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Ze=[{value:String(he),label:`1 MB`},{value:String(_e),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(ge),label:`100 MB`}];function Qe({pool:e,onClose:t,actionsRef:n}){let r=we(),i=ke(),s=Ae(),[d,f]=(0,B.useState)(e.label??``),[p,m]=(0,B.useState)(e.family??``),[h,g]=(0,B.useState)(e.endpoint??``),[_,v]=(0,B.useState)(String(e.maxInflight??10)),[y,ee]=(0,B.useState)(String(e.weight??100)),[b,x]=(0,B.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/Z*1e3)/1e3):``),[S,C]=(0,B.useState)(null),[w,T]=(0,B.useState)(!1),E=h.trim()===e.endpoint,D=async()=>{T(!0),C(null);try{if(E){let t=await s.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;C({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:h.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:Ge,targets:t}),r=n?.result;if(!r){C({ok:!1,message:`Probe returned no result`});return}let a=r.status===`allowed`||r.status===`throttled`;C({ok:a,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){C({ok:!1,message:j(e,`Connection failed`)})}finally{T(!1)}},O=Be(b),k=async()=>{await r.mutateAsync({poolId:e.id,request:{...d.trim()===e.label?{}:{label:d.trim()||void 0},...p.trim()===(e.family??``)?{}:{family:p.trim()||null},...h.trim()!==e.endpoint&&h.trim()!==``?{endpoint:h.trim()}:{},...Number(_)===e.maxInflight?{}:{maxInflight:Number(_)},...Number(y)===e.weight?{}:{weight:Number(y)},...O===(e.quotaBytes??null)?{}:{quotaBytes:O}}}),l.success(`Proxy updated`),t()};return(0,B.useEffect)(()=>{n?.((0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,size:`sm`,disabled:r.isPending||!h.trim(),onClick:()=>void k(),children:`Save`})]}))}),(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Name`,value:d,onChange:e=>f(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Family`,value:p,placeholder:`e.g. residential-id`,onChange:e=>m(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Endpoint`,value:h,onChange:e=>g(e.target.value),className:`font-mono tabular-nums`})}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Max concurrent`,type:`number`,min:1,value:_,onChange:e=>v(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Weight`,type:`number`,min:1,value:y,onChange:e=>ee(e.target.value)})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(I,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>x(e.target.value)}),(0,V.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:O===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${u(O)} is exceeded.`})]}),S&&(0,V.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${S.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:S.message}),(0,V.jsx)(`div`,{children:(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:w,icon:w?(0,V.jsx)(a,{size:13,className:`animate-spin`}):(0,V.jsx)(o,{size:13}),onClick:()=>void D(),children:w?`Testing…`:`Test connection`})})]})}function $e({endpoint:e,chip:t,onChipChange:n}){return(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,V.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),W.map(r=>{let i=t===r;return(0,V.jsxs)(c,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,V.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Re(e??``,t)]})]})}function et({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=xe(),a=Ce(),o=ke(),[s,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)([]),[y,ee]=(0,B.useState)({}),[b,x]=(0,B.useState)({}),[S,C]=(0,B.useState)(!1),[w,T]=(0,B.useState)(null),E=s.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(Boolean),D=K(E),O=(0,B.useMemo)(()=>w===null||D===void 0?E:E.map((e,t)=>e===D&&t===0?Re(e,w):e),[E,w,D]),k=E.length>100,A=Be(p),M=(0,B.useMemo)(()=>O.map(e=>({kind:q(e),endpoint:e})),[O]),N=async()=>{try{let e=await navigator.clipboard.readText();e&&u(t=>t?`${t}\n${e}`:e)}catch{l.error(`Paste failed`,`Clipboard access denied`)}},P=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s)…`]);try{let e=await a.mutateAsync(M),t=e.map(e=>{let t=e.result.status===`healthy`||e.result.status===`reachable`,n=e.result.latencyMs===void 0?``:` · ${e.result.latencyMs}ms`,r=e.result.egressIp?` · ${e.result.egressIp}`:``,i=t?``:` · ${e.result.errorMessage??e.result.status}`;return`${t?`OK `:`FAIL`} ${e.endpoint}${n}${r}${i}`}),n=e.filter(e=>e.result.status===`healthy`||e.result.status===`reachable`).length;x(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n}),v([`${n}/${e.length} reachable`,...t]),n===e.length?l.success(`All ${e.length} proxies reachable`):l.error(`${e.length-n} of ${e.length} proxies failed`)}catch(e){v([`Test failed: ${j(e,`batch probe failed`)}`]),l.error(`Test failed`,j(e,`batch probe failed`))}}},te=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s) against OpenCode…`]);try{let e=await o.mutateAsync({providerId:Ge,targets:M}),t=e.map(e=>{let{status:t,latencyMs:n,reason:r}=e.result,i=n===void 0?``:` · ${n}ms`,a=r===void 0?``:` · ${r}`;return`${t===`allowed`?`OK `:t===`blocked`?`BLOCK`:`FAIL`} ${e.endpoint}${i}${a}`});ee(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n});let n=e.filter(e=>e.result.status===`allowed`).length,r=e.filter(e=>e.result.status===`blocked`).length;v([`${n}/${e.length} allowed · ${r} blocked`,...t]),r===0&&n===e.length?l.success(`OpenCode accepted all ${e.length} proxies`):l.error(`OpenCode: ${n} allowed · ${r} blocked`)}catch(e){v([`Test failed: ${j(e,`provider probe failed`)}`]),l.error(`Test failed`,j(e,`provider probe failed`))}}};return(0,B.useEffect)(()=>{t?.((0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,type:`button`,onClick:e,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,type:`submit`,form:`add-proxy-form`,disabled:S||E.length===0,children:S?`Adding…`:`Add ${E.length} Prox${E.length===1?`y`:`ies`}`})]}))},[t,S,E.length,e]),(0,V.jsxs)(`form`,{id:`add-proxy-form`,onSubmit:async t=>{if(t.preventDefault(),E.length!==0){g(null),C(!0);try{let t=A===null?new Map:J(A,d,O.length),a=Array(E.length),o=0,s=async()=>{for(;o<E.length;){let e=o++,s=O[e];try{let o=await i.mutateAsync({kind:q(s),endpoint:s,...t.has(e)?{quotaBytes:t.get(e)}:{},...d.trim()===``?{}:{family:d.trim()}}),c=y[s],l=b[s];o?.id&&(l!==void 0&&r?.(o.id,l),c!==void 0&&n?.(o.id,c)),a[e]={ok:!0}}catch(t){a[e]={ok:!1,error:j(t,`Proxy pool creation failed`)}}}};await Promise.all(Array.from({length:Math.min(Ve,E.length)},()=>s()));let c=[],f=0;for(let[e,t]of a.entries())t.ok?f++:c.length<3&&c.push(`${E[e].slice(0,48)}…: ${t.error}`);let p=E.length-f,m=a.find(e=>!e.ok)?.error;f>0&&l.success(`Added ${f} proxy pool(s)`,p?`${p} failed: ${m??`see the import details`}`:void 0),p>0&&f===0&&l.error(`Failed to create pool`,m??`See the import details`),p>0&&g(c.join(`
|
|
3
|
+
`)),f>0&&(u(``),e())}finally{C(!1)}}},className:`flex flex-col gap-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,V.jsx)(`label`,{htmlFor:`proxy-endpoints`,className:`text-caption font-semibold text-text-primary`,children:`Proxy endpoints`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,type:`button`,onClick:N,children:`Paste`})]}),(0,V.jsx)(`textarea`,{id:`proxy-endpoints`,value:s,onChange:e=>u(e.target.value),placeholder:`http://proxy.example:8080
|
|
4
|
+
https://proxy.example:8443
|
|
5
|
+
socks5://proxy.example:1080`,rows:5,"aria-describedby":`proxy-format-hint proxy-line-count`,"aria-invalid":!!h,className:`w-full min-h-32 max-h-64 resize-y overflow-y-auto rounded-control border border-inner-border bg-surface-1 p-3 font-mono text-caption text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),(0,V.jsx)($e,{endpoint:D,chip:w,onChipChange:T}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,V.jsx)(`p`,{id:`proxy-format-hint`,className:`m-0 text-badge leading-normal text-text-secondary`,children:`HTTP, HTTPS, or SOCKS5 | one per line | authentication optional`}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsxs)(`span`,{id:`proxy-line-count`,role:`status`,"aria-live":`polite`,className:`text-badge ${k?`text-red`:`text-text-tertiary`}`,children:[E.length===1?`1 proxy detected`:`${E.length} proxies detected`,k?` · max 100 per test`:``]}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>void P(),disabled:a.isPending||o.isPending||E.length===0||k,children:a.isPending?`Testing…`:`Test URL`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>void te(),disabled:a.isPending||o.isPending||E.length===0||k,children:o.isPending?`Testing…`:`Test OpenCode`})]})]}),h&&(0,V.jsx)(`div`,{role:`alert`,className:`max-h-28 overflow-y-auto rounded-inset bg-red-soft px-4 py-3 text-badge text-red whitespace-pre-wrap break-words`,children:h}),_.length>0&&(0,V.jsx)(`div`,{role:`log`,"aria-label":`Proxy test results`,"aria-live":`polite`,className:`scroll-region max-h-40 overflow-y-auto whitespace-pre-wrap break-all rounded-inset border border-inner-border bg-surface-1 px-3 py-2 font-mono text-badge leading-[1.5] text-text-secondary`,children:_.join(`
|
|
6
|
+
`)}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,V.jsx)(I,{id:`proxy-family`,label:`Family`,hint:`Optional`,value:d,placeholder:`e.g. residential-id`,onChange:e=>f(e.target.value),className:`w-full`}),(0,V.jsx)(I,{id:`proxy-quota`,label:`Bandwidth quota (GB)`,hint:`Optional`,type:`number`,min:.001,step:`0.1`,value:p,onChange:e=>m(e.target.value),className:`w-full`})]})]})}function tt(e,t){if(t?.status===`healthy`||t?.status===`reachable`)return t.latencyMs;if(e.lastSuccessAt)return e.lastLatencyMs??void 0}function nt(e){if(e===`proxy_payment_required`)return`HTTP 402 Payment Required`;if(e===`proxy_auth_required`)return`HTTP 407 Proxy Authentication Required`}var Q=(0,B.createContext)({byId:new Map,live:!1});function rt({children:e}){let t=z(),n=(0,B.useMemo)(()=>new Map((t.pools??[]).map(e=>[e.poolId,e])),[t.pools]),r=(0,B.useMemo)(()=>({byId:n,live:t.live&&t.pools!==null}),[n,t.live,t.pools]);return(0,V.jsx)(Q.Provider,{value:r,children:e})}function it({pools:e}){let{byId:t,live:n}=(0,B.useContext)(Q),r=(0,B.useMemo)(()=>U(e,n?new Map([...t].map(([e,t])=>[e,t.currentInflight])):void 0),[e,t,n]),a=(0,B.useMemo)(()=>{let r=0,i=0;for(let a of e){let e=n?t.get(a.id):void 0,o=(a.bytesSentTotal??0)+(a.bytesReceivedTotal??0),s=(e?.bytesSent??0)+(e?.bytesReceived??0);r+=Math.max(o,s),a.quotaBytes&&(i+=a.quotaBytes)}return{used:r,allowance:i}},[e,t,n]);return(0,V.jsxs)(`div`,{className:`signal-grid grid gap-7 w-full min-w-0 mb-7`,children:[(0,V.jsx)(R,{label:`Enabled pool`,value:String(r.active),detail:`/ ${r.totalPools} total`,tone:`accent`,icon:(0,V.jsx)(S,{size:13})}),(0,V.jsx)(R,{label:`Route capacity`,value:String(r.totalMaxConcurrency),detail:`${r.usedInflight} inflight · ${r.availableCapacity} available`,tone:r.availableCapacity===0?`orange`:`teal`,icon:(0,V.jsx)(m,{size:13})}),(0,V.jsx)(R,{label:`Latency`,value:r.avgLatencyMs===null?`—`:`${r.avgLatencyMs}ms`,detail:Y(r),tone:r.avgLatencyMs===null?`accent`:r.avgLatencyMs>2e3?`orange`:`teal`,icon:(0,V.jsx)(i,{size:13})}),(0,V.jsx)(R,{label:`Quota usage`,value:u(a.used),detail:a.allowance>0?`of ${u(a.allowance)} allowance · ${e.length} pools`:`${e.length} pools · no allowance set`,tone:a.allowance>0&&a.used>a.allowance?`red`:a.allowance>0&&a.used/a.allowance>=.8?`orange`:`teal`,icon:(0,V.jsx)(pe,{size:13})})]})}function $(e,t,n,r,i){let a=Je(e),o=X(e),s=e.status!==`disabled`,c=nt(e.lastErrorCategory),l=e.status===`disabled`&&c!==void 0,u=e.lastSuccessAt?new Date(e.lastSuccessAt).getTime():0,d=e.lastErrorAt?new Date(e.lastErrorAt).getTime():0,f=!t&&(u>0||d>0)?u>=d:null,p=n?`default`:l?`warn`:t?t.status===`healthy`?`ok`:t.status===`reachable`?`warn`:`err`:f===!0?`ok`:f===!1?`err`:`default`,m=l?e.lastError??c:t?.errorMessage??(f===null?void 0:`last check ${(e.lastHealthCheckAt?new Date(e.lastHealthCheckAt):new Date).toLocaleString()}`),h=tt(e,t),g=r?.currentInflight??e.inflight,_=e.maxInflight>0?Math.min(1,g/e.maxInflight):1,v=e.providerCooldowns??[],y=v.filter(e=>e.blocked===!0),ee=v.filter(e=>e.blocked!==!0),b=v.slice(0,2).map(e=>e.blocked===!0?`${e.providerId} blocked: ${e.reason}`:`${e.providerId} until ${new Date(e.until).toLocaleTimeString()}: ${e.reason}`).join(` · `),x=n?`Testing…`:l?`Proxy reachable`:t?t.status===`healthy`?`Connected`:t.status===`reachable`?`Proxy reachable`:t.status===`timeout`?`Timeout`:`Unhealthy`:f===!0?`Connected`:f===!1?e.lastErrorCategory===`timeout`?`Timeout`:`Unhealthy`:`Untested`,S=(e.bytesSentTotal??0)+(e.bytesReceivedTotal??0),C=(r?.bytesSent??0)+(r?.bytesReceived??0);return{display:a,poolLabel:o,isEnabled:s,checkTone:p,checkTooltip:m,statusText:x,latency:h,inflight:g,load:_,cooldowns:v,blocked:y,cooldownOnly:ee,cooldownText:b,...i===void 0?{}:{probe:i},metered:S,session:C,used:Math.max(S,C),proxyFailureLabel:c}}function at({pool:e,view:t,maskValues:n}){return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`block text-caption font-semibold overflow-hidden truncate whitespace-nowrap`,title:n?qe:t.poolLabel,children:n?qe:t.poolLabel}),(0,V.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 min-w-0 flex-wrap`,children:[e.status===`disabled`?(0,V.jsxs)(F,{tone:`disabled`,title:e.lastError,children:[`Disabled`,t.proxyFailureLabel?` · ${t.proxyFailureLabel}`:``]}):(0,V.jsx)(F,{tone:t.checkTone,title:t.checkTooltip,children:t.latency===void 0?t.statusText:`${t.statusText} · ${t.latency}ms`}),t.blocked.length>0?(0,V.jsxs)(F,{tone:`disabled`,title:t.cooldownText,children:[t.blocked.length,` blocked`]}):null,t.probe?(0,V.jsx)(F,{tone:t.probe.status===`blocked`?`disabled`:t.probe.status===`allowed`?`ok`:`warn`,title:t.probe.reason??(t.probe.status===`allowed`?t.probe.httpStatus!==void 0&&t.probe.httpStatus>=400?`Reachable — upstream answered ${t.probe.httpStatus} for the probe body`:`OpenCode served a probe through this pool`:t.probe.status===`throttled`?`OpenCode accepted this egress; the rate is spent`:`The probe could not complete`),children:t.probe.status===`blocked`?`OpenCode blocked`:t.probe.status===`allowed`?t.probe.httpStatus!==void 0&&t.probe.httpStatus>=400?`OpenCode reachable`:`OpenCode OK`:t.probe.status===`throttled`?`OpenCode rate-limited`:`OpenCode unreachable`}):null,t.cooldownOnly.length>0?(0,V.jsxs)(F,{tone:`warn`,title:t.cooldownText,children:[t.cooldownOnly.length,` cooldown`,t.cooldownOnly.length>1?`s`:``]}):null]})]})}function ot({pool:e,view:t,speedResult:n,isSpeedTesting:r,maskIp:i}){return(0,V.jsxs)(V.Fragment,{children:[e.egressIp?(0,V.jsx)(`span`,{className:`font-mono tabular-nums block overflow-hidden text-ellipsis whitespace-nowrap text-badge`,title:i?`IP masked`:`egress ${e.egressIp} · ${t.display.endpoint}`,children:i?`IP masked`:e.egressIp}):(0,V.jsx)(`span`,{className:`text-badge text-text-tertiary`,title:`Test the pool to read its egress address`,children:`not probed`}),(r||n)&&(0,V.jsx)(`div`,{className:`mt-1.5`,children:(0,V.jsx)(F,{tone:r?`default`:n?.status===`ok`?`ok`:`err`,title:r?`Measuring download throughput`:n?.status===`ok`?`${u(n.bytes)} in ${n.durationMs}ms${n.measuredAt?` · last measured ${new Date(n.measuredAt).toLocaleString()}`:``}`:`${n?.errorMessage??`Speed test failed`}${n?.measuredAt?` · last measured ${new Date(n.measuredAt).toLocaleString()}`:``}`,children:r?`Speed…`:n?.status===`ok`?`${(n.megabitsPerSecond??0).toFixed(1)} Mbps`:`Speed failed`})})]})}function st({pool:e,view:t}){let n=e.quotaBytes,r=n&&n>0?Math.min(1,t.used/n):0,i=n!==void 0&&n>0&&t.used>n;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{title:`${t.inflight}/${e.maxInflight} inflight`,className:`flex items-center gap-3`,children:[(0,V.jsx)(`div`,{className:`flex-1 h-3 rounded-micro overflow-hidden`,children:(0,V.jsx)(`div`,{className:`h-full rounded-micro`,style:{width:`${Math.round(t.load*100)}%`,background:t.load>=.8?`var(--orange)`:`var(--green)`}})}),(0,V.jsxs)(`span`,{className:`font-mono tabular-nums text-micro text-text-secondary whitespace-nowrap`,children:[t.inflight,`/`,e.maxInflight]})]}),(0,V.jsxs)(`div`,{title:n?`${u(t.used)} of ${u(n)} used · ${u(t.metered)} metered lifetime`:`${u(t.used)} carried (no quota set) · ${u(t.session)} this session`,className:`flex items-center gap-3 mt-2`,children:[(0,V.jsx)(`div`,{className:`flex-1 h-3 rounded-micro overflow-hidden`,children:(0,V.jsx)(`div`,{className:`h-full rounded-micro`,style:{width:`${Math.round(r*100)}%`,background:i?`var(--red)`:r>=.8?`var(--orange)`:`var(--teal)`}})}),(0,V.jsxs)(`span`,{className:`font-mono tabular-nums whitespace-nowrap text-micro ${i?`text-red`:`text-text-secondary`}`,children:[u(t.used),n?` / ${u(n)}`:``]})]})]})}function ct({pool:e,view:t,isTesting:n,onDelete:r,onEdit:s,onHealthCheck:l,onActivity:u}){let d=we(),f=Me(),p=Ee();return(0,V.jsxs)(V.Fragment,{children:[t.cooldowns.length>0&&(0,V.jsx)(c,{size:`icon`,variant:`secondary`,disabled:f.isPending,icon:f.isPending?(0,V.jsx)(a,{size:12,className:`animate-spin`}):(0,V.jsx)(x,{size:12}),onClick:()=>f.mutate({poolId:e.id}),title:`Clear provider cooldowns — ${t.cooldownText}`,label:`Clear`}),(0,V.jsx)(c,{size:`icon`,variant:`secondary`,icon:(0,V.jsx)(i,{size:12}),onClick:()=>u(e),title:`Health and error activity`,label:`Activity`}),e.status===`cooldown`&&(0,V.jsx)(c,{size:`icon`,variant:`secondary`,disabled:p.isPending,icon:(0,V.jsx)(x,{size:12,className:p.isPending?`animate-spin`:``}),onClick:()=>p.mutate(e.id),title:`Recover pool`,children:`Recover`}),!(!t.isEnabled&&t.cooldowns.length>0)&&(0,V.jsx)(c,{size:`icon`,variant:`secondary`,disabled:n,icon:n?(0,V.jsx)(a,{size:12,className:`animate-spin`}):(0,V.jsx)(o,{size:12}),onClick:()=>l(e),title:t.checkTooltip??`Run health check`,label:`Test`}),(0,V.jsx)(c,{size:`icon`,variant:`secondary`,icon:(0,V.jsx)(y,{size:12}),onClick:()=>s(e),title:`Edit pool`,label:`Edit`}),(0,V.jsx)(c,{size:`icon`,variant:`secondary`,icon:(0,V.jsx)(C,{size:12}),onClick:()=>r(e.id),title:`Delete pool`,label:`Delete`}),(0,V.jsx)(L,{className:`ml-3`,checked:t.isEnabled,disabled:d.isPending,onChange:t=>d.mutate({poolId:e.id,request:{status:t?`active`:`disabled`}})})]})}var lt=(0,B.memo)(function({pool:e,isSelected:t,onToggleSelect:n,checkResult:r,isTesting:i,onDelete:a,onEdit:o,onHealthCheck:s,onActivity:c,speedResult:l,isSpeedTesting:u,maskValues:d,maskIp:f,probe:p}){let m=(0,B.useContext)(Q),h=$(e,r,i,(m.live?m.byId.get(e.id):void 0)??null,p);return(0,V.jsxs)(`tr`,{className:h.isEnabled?``:`opacity-60`,children:[(0,V.jsx)(`td`,{className:`w-13`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>n(e.id),"aria-label":`Select ${h.poolLabel}`})}),(0,V.jsx)(`td`,{className:`min-w-0 max-w-150`,children:(0,V.jsx)(at,{pool:e,view:h,maskValues:d})}),(0,V.jsx)(`td`,{className:`min-w-0 max-w-90`,children:e.family?(0,V.jsx)(`span`,{className:`truncate text-caption font-semibold text-text-secondary`,title:e.family,children:e.family}):(0,V.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:`—`})}),(0,V.jsx)(`td`,{className:`max-w-110`,children:(0,V.jsx)(ot,{pool:e,view:h,speedResult:l,isSpeedTesting:u,maskIp:f})}),(0,V.jsx)(`td`,{className:`min-w-55`,children:(0,V.jsx)(st,{pool:e,view:h})}),(0,V.jsx)(`td`,{className:`whitespace-nowrap pl-36 text-right`,children:(0,V.jsx)(le,{gap:`4px`,justify:`end`,children:(0,V.jsx)(ct,{pool:e,view:h,isTesting:i,onDelete:a,onEdit:o,onHealthCheck:s,onActivity:c})})})]})});function ut({pool:e,onClose:t}){let n=Te(e.id),r=Ee(),i=n.data??[],a=nt(e.lastErrorCategory),o=e.status===`disabled`&&a!==void 0,s=e.status===`active`?`ok`:e.status===`disabled`?`disabled`:`warn`;return(0,V.jsx)(v,{open:!0,onClose:t,title:`Health & Activity — ${X(e)}`,children:(0,V.jsxs)(ce,{gap:`14px`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-8 rounded-panel border bg-surface-2 p-8 ${o?`border-orange`:`border-inner-border`}`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`mb-2.5 text-text-tertiary text-micro font-bold tracking-label uppercase`,children:`Proxy health`}),(0,V.jsx)(`div`,{className:`text-title font-bold leading-[1.3]`,children:o?`Proxy reachable`:`Proxy ${e.status}`}),(0,V.jsx)(`p`,{className:`mt-3 mx-0 mb-0 text-text-secondary text-caption leading-normal wrap-anywhere`,children:o?`${a} · disabled from routing`:e.lastError??`No recent proxy errors.`})]}),(0,V.jsx)(F,{tone:s,dot:!0,children:e.status})]}),e.status===`cooldown`&&(0,V.jsx)(`div`,{className:`flex justify-end`,children:(0,V.jsx)(c,{size:`sm`,variant:`secondary`,disabled:r.isPending,onClick:()=>r.mutate(e.id),icon:(0,V.jsx)(x,{size:12,className:r.isPending?`animate-spin`:``}),children:`Recover Now`})}),n.isPending?(0,V.jsx)(g,{compact:!0,label:`Loading pool activity…`}):null,n.isError?(0,V.jsx)(h,{compact:!0,message:`Failed to load pool activity`,onRetry:()=>void n.refetch()}):null,!n.isPending&&!n.isError&&i.length===0?(0,V.jsx)(_,{compact:!0,title:`No pool activity`,message:`Proxy checks, disable events, and recoveries will appear here.`}):null,i.length>0?(0,V.jsx)(`div`,{className:`grid gap-4 max-h-190 overflow-y-auto pr-1`,children:i.map(e=>(0,V.jsxs)(`div`,{className:`p-6 border border-inner-border rounded-control bg-surface-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,V.jsxs)(le,{gap:`6px`,children:[(0,V.jsxs)(F,{tone:e.toStatus===`active`?`ok`:e.toStatus===`disabled`?`disabled`:`warn`,children:[e.fromStatus??`new`,` → `,e.toStatus]}),e.errorCategory?(0,V.jsx)(F,{tone:e.errorCategory.startsWith(`proxy_`)?`warn`:`err`,children:e.errorCategory}):null]}),(0,V.jsx)(`time`,{className:`text-text-tertiary text-badge tabular-nums`,children:new Date(e.createdAt).toLocaleString()})]}),(0,V.jsx)(`p`,{className:`mt-4 mx-0 mb-0 text-text-secondary text-caption leading-normal wrap-anywhere`,children:e.reason??`No additional details`})]},e.id))}):null]})})}function dt(){let e=be(),t=De(),n=we(),r=Ae(),[i,s]=(0,B.useState)(!1),u=(0,B.useCallback)(()=>s(!1),[]),[y,x]=(0,B.useState)(null),[w,T]=(0,B.useState)(null),[E,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)(null),[A,M]=(0,B.useState)(new Set),N=de(),P=N.enabled,ne=fe(),I=ne.enabled,[L,R]=(0,B.useState)(new Set),[z,he]=(0,B.useState)(()=>{try{return localStorage.getItem(He)===`opencode`?`opencode`:`url`}catch{return`url`}});(0,B.useEffect)(()=>{try{localStorage.setItem(He,z)}catch{}},[z]);let[ge,ve]=(0,B.useState)(new Set),[ye,xe]=(0,B.useState)({}),Se=Oe(),Ce=je(),[Te,Ee]=(0,B.useState)(_e),[ke,Me]=(0,B.useState)(()=>{try{let e=localStorage.getItem(`cartethyia_proxy_speed_results`);return e?JSON.parse(e):{}}catch{return{}}}),[H,Ne]=(0,B.useState)(new Set),Ie=(0,B.useCallback)((e,t)=>{let n={...t,measuredAt:new Date().toISOString()};Me(t=>{let r={...t,[e]:n};try{localStorage.setItem(`cartethyia_proxy_speed_results`,JSON.stringify(r))}catch{}return r})},[]),[U,W]=(0,B.useState)(()=>{try{let e=localStorage.getItem(Ue);return e?JSON.parse(e):{}}catch{return{}}}),[G,Re]=(0,B.useState)({key:`name`,direction:`asc`}),[K,q]=(0,B.useState)(null),[ze,Be]=(0,B.useState)(null),J=e.data??[],Ve=(0,B.useMemo)(()=>Le(J,G.key,G.direction,e=>tt(e,U[e.id])),[J,G,U]),qe=(0,B.useCallback)(e=>{let t=e;Re(e=>e.key===t?{key:t,direction:e.direction===`asc`?`desc`:`asc`}:{key:t,direction:`asc`})},[]),Y=e.isPending,Z=e.isError,$e=J.length>0&&J.every(e=>A.has(e.id)),nt=()=>{M($e?new Set:new Set(J.map(e=>e.id)))},Q=(0,B.useCallback)(e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);(0,B.useEffect)(()=>{try{localStorage.setItem(Ue,JSON.stringify(U))}catch{}},[U]);let $=Object.values(U),at=$.length,ot=$.filter(e=>e.status===`healthy`||e.status===`reachable`).length,st=$.filter(e=>e.status!==`healthy`&&e.status!==`reachable`).length,ct=(0,B.useCallback)(e=>{R(t=>new Set(t).add(e.id)),r.mutate(e.id,{onSuccess:t=>{W(n=>({...n,[e.id]:t}));let n=X(e);t.status===`healthy`?l.success(`${n}: connected`,`${t.latencyMs??0}ms`):t.status===`reachable`?l.error(`${n}: proxy reachable · disabled`,t.errorMessage):l.error(`${n}: ${t.status===`timeout`?`timeout`:`unhealthy`}`,t.errorMessage)},onError:t=>{let n=X(e);l.error(`${n}: check failed`,j(t,`Health check failed`))},onSettled:()=>{R(t=>{let n=new Set(t);return n.delete(e.id),n})}})},[r]),dt=async()=>{let e=J;if(e.length===0)return;let t=0,n=0,i=0,a=async()=>{for(;;){let a=e[i++];if(!a)return;R(e=>new Set(e).add(a.id));try{let e=await r.mutateAsync(a.id);W(t=>({...t,[a.id]:e})),e.status===`healthy`?t+=1:n+=1}catch(e){n+=1;let t={poolId:a.id,status:`timeout`,errorMessage:j(e,`Health check failed`)};W(e=>({...e,[a.id]:t}))}finally{R(e=>{let t=new Set(e);return t.delete(a.id),t})}}};await Promise.all(Array.from({length:Math.min(8,e.length)},()=>a())),l.success(`Tested ${e.length} pools · ${t} healthy · ${n} failed`)},ft=async()=>{let e=J.filter(e=>A.has(e.id));if(e.length===0)return;let t=0,n=0,i=0,a=async()=>{for(;;){let a=e[i++];if(!a)return;R(e=>new Set(e).add(a.id));try{let e=await r.mutateAsync(a.id);W(t=>({...t,[a.id]:e})),e.status===`healthy`?t+=1:n+=1}catch(e){n+=1;let t={poolId:a.id,status:`timeout`,errorMessage:j(e,`Health check failed`)};W(e=>({...e,[a.id]:t}))}finally{R(e=>{let t=new Set(e);return t.delete(a.id),t})}}};await Promise.all(Array.from({length:Math.min(8,e.length)},()=>a())),l.success(`Tested ${e.length} pools · ${t} healthy · ${n} failed`)},pt=async()=>{let e=J.filter(e=>A.has(e.id));if(e.length===0)return;let t=0,n=0,r=0,i=0,a=0,o=async()=>{for(;;){let o=e[a++];if(!o)return;ve(e=>new Set(e).add(o.id));try{let e=await Se.mutateAsync({poolId:o.id,providerId:Ge});xe(t=>({...t,[o.id]:{endpoint:o.endpoint??``,result:e}})),e.status===`allowed`?t+=1:e.status===`blocked`?n+=1:e.status===`throttled`?r+=1:i+=1}catch(e){i+=1,xe(t=>({...t,[o.id]:{endpoint:o.endpoint??``,result:{poolId:o.id,providerId:Ge,status:`unreachable`,reason:j(e,`Provider probe failed`)}}}))}finally{ve(e=>{let t=new Set(e);return t.delete(o.id),t})}}};await Promise.all(Array.from({length:Math.min(Ke,e.length)},()=>o())),l.success(`OpenCode: ${t} allowed · ${n} blocked`+(r>0?` · ${r} rate-limited`:``)+(i>0?` · ${i} unreachable`:``))},mt=async()=>{let e=J.filter(e=>A.has(e.id));if(e.length===0)return;let t=0;await(async()=>{for(;;){let n=e[t++];if(!n)return;Ne(e=>new Set(e).add(n.id));try{let e=await Ce.mutateAsync({poolId:n.id,bytes:Te});Ie(n.id,e)}catch(e){Ie(n.id,{poolId:n.id,status:`failed`,bytes:0,durationMs:0,errorMessage:j(e,`Speed test failed`)})}finally{Ne(e=>{let t=new Set(e);return t.delete(n.id),t})}}})(),l.success(`Speed tested ${e.length} pool(s)`)},ht=async()=>{let e=J.filter(e=>A.has(e.id));e.length!==0&&(await Promise.all(e.map(e=>n.mutateAsync({poolId:e.id,request:{status:`active`}}))),M(new Set),l.success(`Enabled ${e.length} pool(s)`))},gt=async()=>{let e=J.filter(e=>A.has(e.id));e.length!==0&&(await Promise.all(e.map(e=>n.mutateAsync({poolId:e.id,request:{status:`disabled`}}))),M(new Set),l.success(`Disabled ${e.length} pool(s)`))},_t=()=>{let e=A.size>0?J.filter(e=>A.has(e.id)):J;if(e.length===0)return;let t=e.map(e=>Je(e).endpoint||e.endpoint).join(`
|
|
7
|
+
`);oe(`cartethyia-proxies.txt`,t,`text/plain;charset=utf-8`),l.success(`Exported ${e.length} pool(s)`)},vt=(0,B.useCallback)(e=>{let t=J.find(t=>t.id===e);t&&q([t])},[J]);return(0,V.jsx)(rt,{children:(0,V.jsxs)(ce,{gap:`16px`,children:[(0,V.jsx)(v,{open:i,onClose:u,title:`Add Proxy`,footer:y,children:(0,V.jsx)(et,{onClose:u,actionsRef:x,onProbeResult:(e,t)=>{let n=J.find(t=>t.id===e);xe(r=>({...r,[e]:{endpoint:n?.endpoint??``,result:t}}))},onHealthResult:(e,t)=>{W(n=>({...n,[e]:t}))}})}),(0,V.jsx)(v,{open:O!==null,onClose:()=>k(null),title:`Edit pool`,footer:w,children:O&&(0,V.jsx)(Qe,{pool:O,onClose:()=>k(null),actionsRef:T},O.id)}),(0,V.jsxs)(ae,{style:J.length===0&&!Y&&!Z?{minHeight:`min(78dvh, calc(100dvh - 160px))`,display:`flex`,flexDirection:`column`}:void 0,children:[(0,V.jsx)(ie,{title:`Proxy Pool`,subtitle:`Outbound proxy servers — HTTP, HTTPS, and SOCKS5`,icon:(0,V.jsx)(S,{size:16}),action:(0,V.jsxs)(le,{gap:`8px`,children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(pe,{size:13}),onClick:()=>D(!0),children:`Deploy relay`}),(0,V.jsx)(c,{variant:`primary`,size:`sm`,icon:(0,V.jsx)(ee,{size:13}),onClick:()=>s(!0),children:`Add proxies`})]})}),(0,V.jsxs)(re,{style:J.length===0&&!Y&&!Z?{flex:1,display:`flex`,flexDirection:`column`,gap:`16px`}:void 0,children:[(0,V.jsx)(it,{pools:J}),J.length>0&&(0,V.jsxs)(`div`,{className:`nested-panel flex flex-wrap items-center justify-start overflow-x-auto rounded-card border border-inner-border bg-surface-2 p-4 text-badge`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,V.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer text-text-secondary`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:$e,onChange:nt,"aria-label":`Select all proxies`}),`Select all`,A.size>0&&(0,V.jsxs)(`span`,{className:`text-text-tertiary`,children:[`(`,A.size,`)`]})]}),at>0&&(0,V.jsxs)(le,{gap:`6px`,children:[(0,V.jsxs)(`span`,{className:`text-text-tertiary`,children:[`Tested `,at,`/`,J.length]}),ot>0&&(0,V.jsxs)(F,{tone:`ok`,children:[ot,` success`]}),st>0&&(0,V.jsxs)(F,{tone:`err`,children:[st,` errors`]})]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(c,{variant:`ghost`,size:`sm`,icon:P?(0,V.jsx)(f,{size:12}):(0,V.jsx)(p,{size:12}),onClick:()=>N.setEnabled(!P),title:P?`Show proxy names and addresses`:`Hide proxy names and addresses`,children:P?`Unmask`:`Mask`}),(0,V.jsx)(c,{variant:`ghost`,size:`sm`,icon:I?(0,V.jsx)(f,{size:12}):(0,V.jsx)(p,{size:12}),onClick:()=>ne.setEnabled(!I),title:I?`Show egress addresses`:`Hide egress addresses`,children:I?`Show IP`:`Mask IP`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:L.size>0||J.length===0,icon:L.size>0?(0,V.jsx)(a,{size:12,className:`animate-spin`}):(0,V.jsx)(o,{size:12}),onClick:()=>void dt(),children:`Test all`}),(0,V.jsxs)(`div`,{className:`inline-flex items-stretch h-15`,children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,className:`rounded-tr-none rounded-br-none`,disabled:L.size>0||ge.size>0||A.size===0,icon:L.size>0||ge.size>0?(0,V.jsx)(a,{size:12,className:`animate-spin`}):(0,V.jsx)(o,{size:12}),onClick:()=>void(z===`opencode`?pt():ft()),children:z===`opencode`?`Test OpenCode`:`Test URL`}),(0,V.jsx)(se,{"aria-label":`Test payload`,value:z,onValueChange:e=>he(e),options:We,disabled:L.size>0||ge.size>0,className:`w-auto min-w-38 h-15 rounded-tl-none rounded-bl-none -ml-0.5`})]}),(0,V.jsxs)(`div`,{className:`inline-flex items-stretch h-15`,children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,className:`rounded-tr-none rounded-br-none`,disabled:A.size===0||H.size>0||Ce.isPending,icon:H.size>0?(0,V.jsx)(a,{size:12,className:`animate-spin`}):(0,V.jsx)(m,{size:12}),onClick:()=>void mt(),children:`Speedtest selected`}),(0,V.jsx)(se,{"aria-label":`Speed test payload size`,value:String(Te),onValueChange:e=>Ee(Number(e)),options:Ze,disabled:H.size>0||Ce.isPending,className:`w-auto min-w-38 h-15 rounded-tl-none rounded-bl-none -ml-0.5`})]}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:J.length===0,icon:(0,V.jsx)(d,{size:12}),onClick:_t,children:`Export`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:A.size===0||n.isPending,icon:(0,V.jsx)(me,{size:12}),onClick:()=>void ht(),children:`Enable selected`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:A.size===0||n.isPending,icon:(0,V.jsx)(b,{size:12}),onClick:()=>void gt(),children:`Disable selected`}),(0,V.jsx)(c,{variant:`danger`,size:`sm`,disabled:A.size===0||t.isPending,icon:(0,V.jsx)(C,{size:12}),onClick:()=>{let e=J.filter(e=>A.has(e.id));e.length!==0&&q(e)},children:`Delete selected`})]})]}),Y&&(0,V.jsx)(g,{}),Z&&(0,V.jsx)(h,{title:`Error`,message:`Failed to load network pools`}),!Y&&!Z&&J.length===0&&(0,V.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,V.jsx)(_,{title:`No proxy pools configured`,message:`The summary above is empty because nothing is routing yet. Use Add proxies or Deploy relay in the header to start one.`})}),!Y&&!Z&&J.length>0&&(0,V.jsx)(`div`,{className:`proxy-table-scroll rounded-control border border-inner-border bg-surface-1`,children:(0,V.jsx)(ue,{maxHeight:460,scrollRegion:!0,headers:[``,{key:`name`,label:`Proxy`,sortable:!0},{key:`family`,label:`Family`,sortable:!0},{key:`address`,label:`Address`,sortable:!0},{key:`load`,label:`Load`,sortable:!0},`Actions`],sortKey:G.key,sortDirection:G.direction,onSort:qe,children:Ve.map(e=>(0,V.jsx)(lt,{pool:e,isSelected:A.has(e.id),onToggleSelect:Q,checkResult:U[e.id],probe:e.providerProbe===void 0?Fe(ye[e.id],e.endpoint):{poolId:e.id,providerId:e.providerProbe.providerId,status:e.providerProbe.status,...e.providerProbe.httpStatus===void 0?{}:{httpStatus:e.providerProbe.httpStatus},...e.providerProbe.reason===void 0?{}:{reason:e.providerProbe.reason},...e.providerProbe.latencyMs===void 0?{}:{latencyMs:e.providerProbe.latencyMs}},isTesting:L.has(e.id),onDelete:vt,onEdit:k,onHealthCheck:ct,onActivity:Be,speedResult:Xe(ke[e.id],Ye(e)),isSpeedTesting:H.has(e.id),maskValues:P,maskIp:I},e.id))})})]})]}),(0,V.jsx)(te,{open:K!==null,onClose:()=>q(null),onConfirm:async()=>{K&&(await Promise.all(K.map(e=>t.mutateAsync(e.id))),M(new Set),l.success(`Deleted ${K.length} pool(s)`),q(null))},title:`Delete proxy pool?`,message:K&&K.length===1?`Delete "${X(K[0])}"? This cannot be undone.`:K?`Delete ${K.length} proxy pools? This cannot be undone.`:`Delete this proxy pool? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),ze?(0,V.jsx)(ut,{pool:ze,onClose:()=>Be(null)}):null,E?(0,V.jsx)(Pe,{onClose:()=>D(!1)}):null]})})}export{et as ProxyBulkForm,rt as ProxyLiveProvider,$e as SchemeChipRow,dt as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,O as o,b as s,l as c,s as l}from"./numbers-Bs4LOOuf.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-DYdQmdAl.js";import{t as h}from"./dialog-BtpsJU98.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as te}from"./trash-Cppn5c3R.js";import{l as v}from"./query-keys-D7wX2vM5.js";import{R as y}from"./entry-Dj9AR0gY.js";import{n as b,t as ne}from"./card--AtFedAq.js";import{t as x}from"./badge-6uzDDvqs.js";import{t as S}from"./select-DsX5QT8K.js";import{t as C}from"./ProviderIcon-CmfzxpVM.js";import{t as w}from"./switch-CidSfbG7.js";import{t as T}from"./stack-DwLmjUFK.js";import{n as E}from"./inline-BcNGF8Gr.js";import{t as D}from"./layout-C8mer_Ak.js";import{a as O,i as k,n as A,o as j,r as M,s as N,t as P}from"./quota-DZGyp0N5.js";import{a as F,c as I,d as L,f as R,i as z,l as B,n as V,o as H,p as U,r as W,s as G,t as K,u as q}from"./HealthEventsModal-qomXThxX.js";var re=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),J=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Y=e(`zap`,[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=z(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,o=e=>e?new Date(e).toLocaleString():`—`,s=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(Y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(x,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(Y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(D,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=s(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(x,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[o(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(c,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?l.success(e.message??`Rate limit reset applied`):l.error(e.message??`Rate limit reset failed`)},onError:e=>{l.error(v(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(E,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!V(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,o=R(i),s=i.length===0||o.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(S,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:s,className:`shrink-0`,icon:o.isPending?(0,Z.jsx)(a,{size:13,className:`animate-spin`}):(0,Z.jsx)(re,{size:13}),onClick:()=>o.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?l.success(e.message):l.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>l.error(v(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:o}){let u=G(e.id),d=L(e.id),f=V(e.provider),p=W(e.provider),m=z(e.id,p),h=e.quota,[g,y]=(0,X.useState)(0),b=h?.windows??[],x=j(b,g),S=x.pageCount;(0,X.useEffect)(()=>{y(e=>Math.min(e,Math.max(0,S-1)))},[S]);let T=u.isPending||d.isPending,E=m.data?.availableCount??0,[D,F]=(0,X.useState)(null),[I,R]=(0,X.useState)(!1),B=e.checkin?.attemptedToday??!1,H=`${D?D.state===`claimed`?`Checked in${D.credit===null?``:` +${D.credit}`}${D.streakDays===null?``:` · ${D.streakDays}d streak`}`:D.state===`already_claimed`?`Check-in attempted · already claimed`:D.state===`not_eligible`?`Check-in attempted · not eligible`:D.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:B?`Check-in attempted today`:`Check-in due`}${I?` · Reported today`:``}`,U=b.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),K=(u.error?v(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=O(K),J=q===`Quota tracking is not supported for this provider`?null:q,Q=P(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(ne,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":T,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(C,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:A(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:E>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[E,` rate-limit reset`,E===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:H}),b.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,U.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:E>0?`Saved rate-limit resets (${E} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:T,onClick:()=>o(e),children:(0,Z.jsx)(Y,{size:14})}),f&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${H}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:T,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&F({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&R(!0),e.ok?l.success(e.message):l.error(e.message)},onError:e=>{l.error(v(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(a,{size:14,className:`animate-spin`}):(0,Z.jsx)(re,{size:14})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:T,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:T,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(a,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(te,{size:12})}),(0,Z.jsx)(w,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),J&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(s,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:J})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),x.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=N(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=M(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:k(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),x.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,x.startIndex+1,`–`,x.startIndex+x.items.length,` of `,b.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:x.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>y(x.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:x.page>=x.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>y(x.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):J?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:T||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,a]=(0,X.useState)(!1),{data:s,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:te}=H(),v=(0,X.useMemo)(()=>[...s?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[s?.providers]),x=(0,X.useMemo)(()=>s?.accounts??[],[s?.accounts]),C=s?.refreshing??0,w=I(),E=U(),D=B(),O=F(),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),[N,P]=(0,X.useState)(null),L=(0,X.useMemo)(()=>{let t=x.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,x,i,e]),R=async(e,t)=>{try{await E.mutateAsync({id:e.id,active:t}),l.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){l.error(e instanceof Error?e.message:`Unable to update account`)}},z=async()=>{let e=x.filter(e=>e.active&&Q(e));await D.mutateAsync({ids:e.map(e=>e.id),active:!1}),l.success(`Disabled ${e.length} empty accounts`)},V=async()=>{let e=x.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await D.mutateAsync({ids:e.map(e=>e.id),active:!0}),l.success(`Enabled ${e.length} available accounts`)},W=async e=>{await O.mutateAsync(e.id),l.success(`${e.name} deleted`)},G=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,q=x.filter(Q).length;return(0,Z.jsxs)(T,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(ne,{children:(0,Z.jsxs)(b,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(S,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...v.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(S,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(c,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>a(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(J,{size:13}),children:`Expiring first`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:q===0||h,onClick:()=>void z(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void V(),icon:(0,Z.jsx)(o,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[L.length,` shown`,q>0?` · ${q} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${G}`,(0,Z.jsx)(oe,{accounts:x}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||w.isPending||x.length===0,icon:(0,Z.jsx)(g,{size:13,className:w.isPending?`animate-spin`:void 0}),onClick:()=>w.mutate(x.map(e=>e.id),{onSuccess:e=>{l.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>l.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(c,{variant:`secondary`,onClick:()=>void te(),children:`Retry`})}):L.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:L.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void R(e,t),onDelete:e=>A(e),onShowHealth:e=>M(e),onShowResets:e=>P(e)},e.id))})}),j&&(0,Z.jsx)(K,{summary:{providerId:j.provider,accountId:j.id,title:j.name,status:j.health?.status??`unknown`,errorCategory:j.health?.lastErrorCategory??void 0,errorMessage:j.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>M(null)}),N&&(0,Z.jsx)(ae,{account:N,onClose:()=>P(null)}),(0,Z.jsx)(y,{open:k!==null,onClose:()=>A(null),onConfirm:async()=>{k&&await W(k)},title:`Delete account?`,message:`Delete "${k?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{l as i,s as a}from"./numbers-Bs4LOOuf.js";import{t as o}from"./download-A0SW9OCW.js";import{t as s}from"./eye-C_hawfH4.js";import{n as c,r as l}from"./state-DYdQmdAl.js";import{t as u}from"./dialog-BtpsJU98.js";import{n as d,r as f,t as p}from"./settings-mpmXTgUa.js";import{t as m}from"./trash-Cppn5c3R.js";import{T as h}from"./assert-NHwYq95t.js";import{l as g,o as _,s as v}from"./query-keys-D7wX2vM5.js";import{t as y}from"./useMutation-w4u4CVue.js";import{n as b,r as x,t as S}from"./card--AtFedAq.js";import{n as C,t as w}from"./download-dRFo5_Wu.js";import{n as T}from"./input-BG41et9G.js";import{t as E}from"./select-DsX5QT8K.js";import{t as ee}from"./switch-CidSfbG7.js";import{t as D}from"./stack-DwLmjUFK.js";import{t as O}from"./banner-4_WNg2WZ.js";import{t as k}from"./backup-file-gdKIlg8U.js";var te=e(`database-backup`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 12a9 3 0 0 0 5 2.69`,key:`1ui2ym`}],[`path`,{d:`M21 9.3V5`,key:`6k6cib`}],[`path`,{d:`M3 5v14a9 3 0 0 0 6.47 2.88`,key:`i62tjy`}],[`path`,{d:`M12 12v4h4`,key:`1bxaet`}],[`path`,{d:`M13 20a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L12 16`,key:`1f4ei9`}]]),ne=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),A=t(n(),1);function re(){return y({mutationFn:async({password:e,sections:t,compressed:n,onProgress:r})=>{let i=new URLSearchParams({password:e});t!==void 0&&t.length>0&&i.set(`sections`,t),n===!0&&i.set(`compressed`,`1`);let a=`/backup/export?${i.toString()}`;if(n!==!0)return _(a);let o=await _(a),s=atob(o.bytes),c=Uint8Array.from(s,e=>e.charCodeAt(0));return r?.({loaded:c.byteLength,total:c.byteLength}),c}})}function ie(){let e=h();return y({mutationFn:({password:e,scopes:t})=>_(`/backup/delete-all`,{method:`POST`,body:JSON.stringify({password:e,scopes:t})}),onSuccess:async()=>{await e.invalidateQueries()}})}function j(){let e=h();return y({mutationFn:({password:e,backup:t,onProgress:n})=>v(`/backup/import`,JSON.stringify({password:e,backup:t}),n),onSuccess:async()=>{await e.invalidateQueries()}})}var M=r();function N({report:e}){let t=Object.entries(e.imported).filter(([,e])=>e>0);return(0,M.jsxs)(D,{gap:`8px`,children:[t.length>0?(0,M.jsxs)(`p`,{className:`text-caption`,children:[`Imported: `,t.map(([e,t])=>`${t} ${e}`).join(`, `)]}):null,e.remapped.length>0?(0,M.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[`Remapped provider ids: `,e.remapped.join(`, `)]}):null,e.skipped.length>0?(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`p`,{className:`text-caption text-yellow`,children:[`Skipped (`,e.skipped.length,`) — nothing was guessed:`]}),(0,M.jsx)(`ul`,{className:`text-badge text-text-tertiary mt-2 ml-8`,children:e.skipped.map(e=>(0,M.jsx)(`li`,{children:e},e))})]}):null,e.warnings.length>0?(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`Warnings:`}),(0,M.jsx)(`ul`,{className:`text-badge text-text-tertiary mt-2 ml-8`,children:e.warnings.map(e=>(0,M.jsx)(`li`,{children:e},e))})]}):null]})}function P({warnings:e}){return e.length===0?null:(0,M.jsxs)(O,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,M.jsxs)(`strong`,{children:[`Restore completed with `,e.length,` warning`,e.length===1?``:`s`]}),(0,M.jsx)(`ul`,{className:`mt-2 ml-8`,children:e.map((e,t)=>(0,M.jsxs)(`li`,{children:[e.table?`${e.table}${e.column?`.${e.column}`:``}: `:``,e.reason]},`${e.table??`backup`}:${e.column??`general`}:${t}`))})]})}function F(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function I(e,t){if(e===null)return t;let n=Math.max((Date.now()-e.startedAt)/1e3,.1),r=F(e.loaded/n);return`${e.total===null?F(e.loaded):`${F(e.loaded)} / ${F(e.total)}`} · ${r}/s`}function L(){let[e,t]=(0,A.useState)(``),[n,r]=(0,A.useState)(null),[s,c]=(0,A.useState)(!0),[l,d]=(0,A.useState)(!1),[f,p]=(0,A.useState)(!0),[h,_]=(0,A.useState)(null),[v,y]=(0,A.useState)(null),[E,F]=(0,A.useState)(null),[L,R]=(0,A.useState)(null),[z,B]=(0,A.useState)(null),[V,H]=(0,A.useState)(null),[U,W]=(0,A.useState)(new Set),[G,K]=(0,A.useState)(null),q=(0,A.useRef)(null),J=re(),Y=j(),X=ie(),ae=e=>{W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Z=()=>{r(null),t(``)},oe=()=>{U.size!==0&&(t(``),r(`delete`))},se=async()=>{if(e.length===0)return;let t=await X.mutateAsync({password:e,scopes:[...U]});W(new Set),Z(),a.success(`Selected configuration deleted.`,Object.entries(t.deleted).map(([e,t])=>`${e}: ${t}`).join(` · `))},Q=()=>{let t=[...s?[`config`]:[],...l?[`telemetry`]:[]].join(`,`);if(t.length===0){a.error(`Select at least one backup section.`);return}J.mutate({password:e,sections:t,compressed:f,onProgress:e=>_(t=>({...e,startedAt:t?.startedAt??Date.now()}))},{onSuccess:e=>{let t=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`);e instanceof Uint8Array?w(`cartethyia_backup_${t}.json.gz`,e,`application/gzip`):C(`cartethyia_backup_${t}.json`,JSON.stringify(e,null,2),`application/json`),Z(),a.success(`Backup downloaded.`)},onError:e=>a.error(g(e,`Backup export failed.`))})},ce=e=>{K(e),y(null),F(null),R(null),B(null),H(null),t(``),r(`restore`)},le=async()=>{let t=G;if(t!==null){R(null);try{let n=await k(t),r=await Y.mutateAsync({password:e,backup:n,onProgress:e=>_(t=>({...e,startedAt:t?.startedAt??Date.now()}))});y(r.restored),F(r.warnings),B(r.report??null),H(r.format),Z(),K(null),a.success(r.warnings.length===0?`Restore complete.`:`Restore completed with warnings.`,r.warnings.length===0?null:`${r.warnings.length} item(s) need attention. See the restore report below.`)}catch(e){let t=g(e,`Backup restore failed.`);R(t),a.error(`Backup restore failed`,t)}}},$=v===null?[]:Object.entries(v);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,M.jsxs)(S,{className:`h-full`,children:[(0,M.jsx)(x,{title:`Backup`,subtitle:`Download a JSON snapshot, or restore one you already trust`,icon:(0,M.jsx)(te,{size:16})}),(0,M.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,M.jsxs)(D,{gap:`14px`,className:`flex-1`,children:[(0,M.jsxs)(`fieldset`,{className:`grid grid-cols-2 gap-5 min-w-0 border-0 m-0 p-0 max-medium:grid-cols-1`,children:[(0,M.jsx)(`legend`,{className:`mb-4 text-text-secondary text-badge font-semibold`,children:`Include in the download`}),(0,M.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),(0,M.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,M.jsx)(`strong`,{children:`Account, proxy & settings`}),(0,M.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:`Credentials, API-key hashes, routing, and settings`})]})]}),(0,M.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>d(e.target.checked)}),(0,M.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,M.jsx)(`strong`,{children:`Telemetry history`}),(0,M.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:`Status, tokens, cost, latency — never prompt bodies`})]})]})]}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border px-6 py-5`,children:[(0,M.jsxs)(`span`,{children:[(0,M.jsx)(`strong`,{className:`block text-body`,children:`Highly Compress Backup`}),(0,M.jsx)(`small`,{className:`text-badge text-text-tertiary`,children:`Makes the download smaller.`})]}),(0,M.jsx)(ee,{checked:f,onChange:p,"aria-label":`Highly Compress Backup`})]}),(0,M.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`The file contains provider credentials. Treat it like the database. Prompt and response bodies, health-event history, and console sessions are left out.`}),(0,M.jsxs)(`div`,{className:`mt-auto flex justify-end gap-4`,children:[(0,M.jsx)(i,{variant:`primary`,size:`sm`,onClick:()=>{t(``),r(`download`)},disabled:!s&&!l,icon:(0,M.jsx)(o,{size:13}),children:`Download backup`}),(0,M.jsx)(i,{variant:`secondary`,size:`sm`,onClick:()=>q.current?.click(),icon:(0,M.jsx)(ne,{size:13}),children:`Restore from file`}),(0,M.jsx)(`input`,{ref:q,type:`file`,accept:`application/json,.json,.gz,application/gzip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];t&&ce(t),e.target.value=``}})]}),V===null?null:(0,M.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Detected format: `,V===`nine_router`?`router export`:`Cartethyia backup`]}),v===null?null:(0,M.jsxs)(O,{tone:`success`,surface:`raised`,live:`status`,children:[(0,M.jsx)(`strong`,{children:`Restore complete`}),$.length>0?(0,M.jsx)(`ul`,{children:$.map(([e,t])=>(0,M.jsxs)(`li`,{children:[e,`: `,t]},e))}):(0,M.jsx)(`p`,{children:`No rows were imported.`})]}),E===null?null:(0,M.jsx)(P,{warnings:E}),z===null?null:(0,M.jsx)(N,{report:z})]})})]}),(0,M.jsxs)(S,{className:`settings-danger h-full`,children:[(0,M.jsx)(x,{title:`Delete data`,subtitle:`Removes the scopes you check. Console users, sessions, and audit history stay.`,icon:(0,M.jsx)(m,{size:16})}),(0,M.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,M.jsxs)(D,{gap:`12px`,className:`flex-1`,children:[(0,M.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-5 min-w-0 border-0 m-0 p-0`,children:[(0,M.jsx)(`legend`,{className:`mb-4 text-text-secondary text-badge font-semibold`,children:`Delete`}),[[`providers`,`Providers`,`Accounts, credentials, tenant models, routing, and account health`],[`proxies`,`Proxies`,`Network pools, pool settings, and pool health`],[`configuration`,`All configuration`,`Providers, proxies, aliases, combos, API keys, CLI tools, and settings`]].map(([e,t,n])=>(0,M.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:U.has(e),onChange:()=>ae(e)}),(0,M.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,M.jsx)(`strong`,{children:t}),(0,M.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:n})]})]},e))]}),(0,M.jsx)(`div`,{className:`mt-auto flex justify-end`,children:(0,M.jsx)(i,{variant:`danger`,size:`sm`,icon:(0,M.jsx)(m,{size:14}),disabled:U.size===0,onClick:oe,children:`Delete selected`})})]})})]})]}),(0,M.jsx)(u,{open:n!==null,onClose:Z,title:n===`delete`?`Confirm deletion`:n===`restore`?`Restore backup`:`Download backup`,description:`The console password is checked again before this runs.`,size:`sm`,footer:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(i,{variant:`secondary`,size:`sm`,onClick:Z,children:`Cancel`}),(0,M.jsx)(i,{variant:n===`delete`?`danger`:`primary`,size:`sm`,loading:J.isPending||Y.isPending||X.isPending,disabled:e.length===0||J.isPending||Y.isPending||X.isPending,onClick:()=>{_(null),n===`download`?Q():n===`restore`?le():se()},children:J.isPending?I(h,`Downloading…`):Y.isPending?I(h,`Uploading…`):X.isPending?`Working…`:n===`delete`?`Delete permanently`:n===`restore`?`Restore`:`Download`})]}),children:(0,M.jsxs)(D,{gap:`10px`,children:[n===`restore`&&L!==null?(0,M.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:L}):null,(0,M.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n===`delete`?`This cannot be undone. The password is verified again before anything is removed.`:n===`restore`?`Restore replaces the tenant configuration in this file. Continue only if the file is trusted.`:`The export is plain JSON and contains provider credentials.`}),(0,M.jsx)(T,{label:`Console password`,type:`password`,value:e,onChange:e=>t(e.target.value),autoComplete:`current-password`,"data-autofocus":!0})]})})]})}function R(){return y({mutationFn:e=>_(`/auth/change-password`,{method:`POST`,body:JSON.stringify(e)})})}function z(){let e=p(),t=d(),n=e.data;return e.isPending?(0,M.jsx)(l,{label:`Loading privacy settings…`}):e.isError||!n?(0,M.jsx)(c,{message:g(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()}):(0,M.jsxs)(S,{className:`h-full`,children:[(0,M.jsx)(x,{title:`Privacy`,subtitle:`What request telemetry stores, and how client addresses are shown`,icon:(0,M.jsx)(s,{size:16})}),(0,M.jsx)(b,{children:(0,M.jsxs)(D,{gap:`16px`,children:[(0,M.jsxs)(`div`,{className:`settings-field`,children:[(0,M.jsx)(E,{label:`Telemetry payloads`,id:`privacy-payloads`,value:n.telemetryPayloads,onValueChange:e=>t.mutate({telemetryPayloads:e===`full`||e===`metadata`?e:`none`},{onSuccess:()=>a.success(`Payload capture updated`),onError:e=>a.error(g(e,`Could not update payload capture.`))}),options:[{value:`none`,label:`Off — no payload capture`},{value:`metadata`,label:`Metadata — method and headers, 15 minutes`},{value:`full`,label:`Full — redacted bodies, 15 minutes`}]}),(0,M.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Request metadata is always kept. Bodies stay off until you turn them on, and anything captured is redacted and deleted after 15 minutes.`})]}),n.telemetryPayloads===`full`?(0,M.jsxs)(`div`,{className:`settings-field`,children:[(0,M.jsx)(E,{label:`Capture depth`,id:`privacy-payload-depth`,value:n.telemetryPayloadDepth,onValueChange:e=>t.mutate({telemetryPayloadDepth:e===`moderate`||e===`maximum`?e:`minimum`},{onSuccess:()=>a.success(`Capture depth updated`),onError:e=>a.error(g(e,`Could not update capture depth.`))}),options:[{value:`minimum`,label:`Minimum — 1 MiB cap`},{value:`moderate`,label:`Moderate — 8 MiB cap`},{value:`maximum`,label:`Maximum — 16 MiB cap`}]}),n.telemetryPayloadDepth===`minimum`?null:(0,M.jsxs)(O,{tone:`warning`,surface:`raised`,className:`text-text-secondary`,children:[(0,M.jsx)(`strong`,{children:`High CPU and memory while this is on.`}),` Use it to debug, then switch back to Metadata or Minimum.`]})]}):null,(0,M.jsxs)(`div`,{className:`settings-field`,children:[(0,M.jsx)(E,{label:`Client IP display`,id:`privacy-ip`,value:n.privacyMode,onValueChange:e=>t.mutate({privacyMode:e===`full`?`full`:`masked`},{onSuccess:()=>a.success(`IP display updated`),onError:e=>a.error(g(e,`Could not update IP display.`))}),options:[{value:`masked`,label:`Masked — recommended`},{value:`full`,label:`Show full IP`}]}),(0,M.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Raw addresses stay stored. This only changes how they are shown.`})]})]})})]})}function B(){let e=R(),[t,n]=(0,A.useState)(``),[r,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(``),[c,l]=(0,A.useState)(null),[u,d]=(0,A.useState)(!1);return(0,M.jsxs)(D,{gap:`12px`,className:`flex-1`,children:[(0,M.jsx)(T,{id:`current-password`,label:`Current password`,type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:`current-password`}),(0,M.jsxs)(`div`,{className:`settings-pair settings-pair-tight`,children:[(0,M.jsx)(T,{id:`new-password`,label:`New password`,type:`password`,value:r,onChange:e=>a(e.target.value),autoComplete:`new-password`}),(0,M.jsx)(T,{id:`confirm-password`,label:`Confirm new password`,type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:`new-password`})]}),c?(0,M.jsx)(`p`,{role:`alert`,className:`settings-feedback`,"data-tone":`err`,children:c}):null,u?(0,M.jsx)(`p`,{role:`status`,className:`settings-feedback`,"data-tone":`ok`,children:`Password updated.`}):null,(0,M.jsx)(`div`,{className:`mt-auto flex justify-end`,children:(0,M.jsx)(i,{variant:`primary`,size:`sm`,onClick:()=>{if(d(!1),r.length<8){l(`New password must be at least 8 characters.`);return}if(r!==o){l(`New password and confirmation do not match.`);return}l(null),e.mutate({currentPassword:t,newPassword:r},{onSuccess:()=>{d(!0),n(``),a(``),s(``)},onError:e=>l(g(e,`Password change failed.`))})},disabled:e.isPending||!t||!r||!o,children:e.isPending?`Updating…`:`Update password`})})]})}function V(){return(0,M.jsxs)(S,{children:[(0,M.jsx)(x,{title:`Settings`,subtitle:`Account security, privacy, and tenant data`,icon:(0,M.jsx)(f,{size:16})}),(0,M.jsxs)(b,{className:`flex flex-col gap-10`,children:[(0,M.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,M.jsx)(`h2`,{className:`text-badge font-bold uppercase tracking-label text-text-tertiary`,children:`Account`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,M.jsxs)(S,{className:`h-full`,children:[(0,M.jsx)(x,{title:`Security`,subtitle:`Change the password used to sign in to this console`,icon:(0,M.jsx)(f,{size:16})}),(0,M.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,M.jsx)(B,{})})]}),(0,M.jsx)(z,{})]})]}),(0,M.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,M.jsx)(`h2`,{className:`text-badge font-bold uppercase tracking-label text-text-tertiary`,children:`Data`}),(0,M.jsx)(L,{})]})]})]})}export{V as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{l as i}from"./numbers-Bs4LOOuf.js";import{o as a,t as o}from"./query-keys-D7wX2vM5.js";import{I as s,Q as c,Z as l}from"./entry-Dj9AR0gY.js";import{n as u}from"./input-BG41et9G.js";import{t as d}from"./layout-C8mer_Ak.js";import{t as f}from"./backup-file-gdKIlg8U.js";var p=e(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),m=t(n(),1),h=r();function g(){let e=c(),[t,n]=(0,m.useState)(null),[r,d]=(0,m.useState)(`admin`),[g,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(`create`),[A,j]=(0,m.useState)(null),[M,N]=(0,m.useState)(null),P=(0,m.useRef)(null);(0,m.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(r=>{t&&(n(r.requires_setup),r.requires_setup||e(`/login`,{replace:!0}))}).catch(()=>{t&&n(!0)}),()=>{t=!1}},[e]);let F=async n=>{if(n.preventDefault(),t===!1){T(`This console already has an account. Sign in instead.`);return}if(!r.trim()){T(`Administrator username is required.`);return}if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}D(!0),T(null);try{let t=await a(`/auth/setup`,{method:`POST`,body:JSON.stringify({username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(t.status!==`success`){T(t.message??`Setup failed. Please try again.`);return}s.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){T(t);return}}T(`An unexpected network error occurred.`)}finally{D(!1)}},I=async t=>{D(!0),T(null);try{if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}let n=await f(t),i=await a(`/auth/setup/restore`,{method:`POST`,body:JSON.stringify({backup:n,username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(i.status!==`success`){T(i.message??`Restore failed. Please try again.`);return}s.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e instanceof Error){T(e.message);return}T(`An unexpected network error occurred.`)}finally{D(!1)}},L=e=>{if(j(e),T(null),e===null){N(null);return}f(e).then(async t=>{try{let n=await a(`/auth/setup/inspect`,{method:`POST`,body:JSON.stringify({backup:t})});if(n.status!==`success`){N(null),T(n.message??`Could not read that backup.`);return}N({fileName:e.name,version:n.version??0,exportedAt:n.exportedAt??``,rows:n.rows??[],total:n.total??0,warnings:n.warnings??[]})}catch{N(null)}}).catch(e=>{N(null),T(e instanceof Error?e.message:`That file is not a JSON backup.`)})};return t===!1?(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Account Already Registered`}),(0,h.jsx)(`p`,{className:`auth-desc`,children:`This console already has an administrator account, so setup is closed. Sign in with the account that was created.`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsx)(v,{message:`Setup is already finished. Creating a second administrator is not possible from here.`}),(0,h.jsx)(l,{to:`/login`,className:`no-underline`,children:(0,h.jsx)(i,{variant:`primary`,type:`button`,className:`w-full h-20`,children:`Go to sign in`})})]})]})}):(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console Setup`}),O===`create`?(0,h.jsx)(`p`,{className:`auth-desc`,children:`Configure the administrator account for Cartethyia AI Gateway`}):null]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-7`,children:[(0,h.jsx)(i,{type:`button`,variant:O===`create`?`primary`:`secondary`,onClick:()=>k(`create`),children:`New account`}),(0,h.jsx)(i,{type:`button`,variant:O===`restore`?`primary`:`secondary`,onClick:()=>k(`restore`),children:`Restore`})]}),O===`restore`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`text-text-secondary text-caption`,children:`Backup file`}),(0,h.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border-subtle px-3 py-2.5`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>P.current?.click(),disabled:E||t===null,children:`Choose file…`}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-caption text-text-secondary`,children:A?.name??`No file chosen`})]})]}),(0,h.jsx)(`input`,{ref:P,id:`setup-backup`,type:`file`,accept:`application/json,.json,.gz,application/gzip`,disabled:E,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;L(t),e.target.value=``}}),M?(0,h.jsx)(_,{preview:M}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`Backups carry settings only — no logins. Create the administrator for this install.`}),(0,h.jsx)(u,{label:`Administrator Username`,id:`restore-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`restore-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`restore-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`})]}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>k(`create`),disabled:E,children:`Cancel`}),(0,h.jsx)(i,{type:`button`,variant:`primary`,disabled:E||t===null||A===null,onClick:()=>{A&&I(A)},children:E?`Restoring…`:`Restore this backup`})]})]}):(0,h.jsxs)(`form`,{onSubmit:F,className:`flex flex-col gap-7`,children:[(0,h.jsx)(u,{label:`Administrator Username`,id:`setup-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`,placeholder:`e.g. admin, risun`}),(0,h.jsx)(u,{label:`Display Name`,hint:`(optional)`,id:`display-name`,value:g,onChange:e=>y(e.target.value),autoComplete:`name`,placeholder:`e.g. Administrator, risun`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`setup-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`setup-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsx)(i,{variant:`primary`,type:`submit`,disabled:E||t===null,className:`w-full mt-3 h-20`,icon:(0,h.jsx)(p,{size:15}),children:E?`Initializing…`:`Complete Setup`})]})]})})}function _({preview:e}){let t=e.rows.filter(e=>!e.supported),n=e.rows.filter(e=>e.supported),r=e.exportedAt?e.exportedAt.replace(`T`,` `).slice(0,19):`unknown`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center flex-wrap gap-1.5`,children:[(0,h.jsx)(`span`,{className:`min-w-0 overflow-hidden whitespace-nowrap text-ellipsis text-body font-semibold`,title:e.fileName,children:e.fileName}),(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border border-inner-border rounded-md bg-surface-2 text-text-secondary text-badge tabular-nums`,children:[`v`,e.version]}),t.length>0?(0,h.jsxs)(`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:[t.length,` unsupported`]}):null]}),(0,h.jsxs)(`p`,{className:`m-0 text-text-secondary text-caption`,children:[e.total,` rows across `,e.rows.length,` tables · exported `,r]}),t.length>0?(0,h.jsx)(`p`,{className:`m-0 text-caption text-status-warning`,children:t.length===e.rows.length?`None of these tables exist in this build, so nothing can be restored.`:`This build no longer has some of these tables. The rest still restores.`}):null,e.rows.length===0?(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`This backup is empty.`}):(0,h.jsx)(`div`,{className:`max-h-110 overflow-auto`,children:(0,h.jsx)(d,{headers:[`Table`,`Section`,`Rows`],dense:!0,children:[...n,...t].map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:e.table}),(0,h.jsx)(`td`,{children:e.section}),(0,h.jsx)(`td`,{className:`text-right`,children:e.supported?e.count:(0,h.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:`unsupported`})})]},`${e.section}/${e.table}`))})})]})}function v({message:e}){return(0,h.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:e})}export{g as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{d as i}from"./numbers-Bs4LOOuf.js";import{st as a}from"./entry-Dj9AR0gY.js";import{n as o}from"./stack-DwLmjUFK.js";var s=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),c=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),l=t(n(),1),u=r();function d({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:d,label:f}){let[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(null),_=(0,l.useRef)(null),v=()=>{_.current=null,m(null),g(null)},y=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,u.jsx)(`div`,{role:`list`,"aria-label":f,className:i(`flex flex-col min-w-0`,o(r)??`gap-5`),children:e.map((r,o)=>{let l=p===r.id,f=h===r.id&&p!==null&&p!==r.id,b=r=>{let i=o+r;if(n||i<0||i>=e.length)return;let a=e.map(e=>e.id),[s]=a.splice(o,1);s!==void 0&&(a.splice(i,0,s),t(a))};return(0,u.jsxs)(`div`,{role:`listitem`,className:i(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,l&&`opacity-50`,f&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":l?`true`:void 0,"data-drop-target":f?`true`:void 0,onDragOver:e=>{n||_.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,h!==r.id&&g(r.id))},onDrop:e=>{e.preventDefault();let t=_.current;t!==null&&y(t,r.id),v()},children:[(0,u.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,u.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:o+1}),(0,u.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${o+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{_.current=r.id,m(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:v,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,u.jsx)(c,{size:14})})]}),(0,u.jsxs)(`div`,{className:`flex gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} up`,title:`Move up`,disabled:n||o===0,onClick:()=>b(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(s,{size:14})}),(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} down`,title:`Move down`,disabled:n||o===e.length-1,onClick:()=>b(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(a,{size:14})})]})]}),(0,u.jsx)(`div`,{className:`flex-auto min-w-0`,children:d(r,o)})]},r.id)})})}export{d as t};
|
|
Binary file
|