cartethyia 2.5.2 → 2.5.3
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/dist/dashboard/assets/{BannedPage-MsQaeQTs.js → BannedPage-hfCzi-Ux.js} +1 -1
- package/dist/dashboard/assets/BannedPage-hfCzi-Ux.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-BO9nKg9w.js → CliToolDetailPage-DLGqYEwI.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-DLGqYEwI.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-DfWHTJ7v.js → CliToolsPage-DEDyKBlC.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DEDyKBlC.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-BrCBQDAc.js → CombosPage-CfuYiQ8Z.js} +1 -1
- package/dist/dashboard/assets/CombosPage-CfuYiQ8Z.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-C6Uh33er.js → ConsoleLogPage-bsLuZmYH.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-bsLuZmYH.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-8aS9hyJu.js → CustomizationPage-_UWhwziJ.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-_UWhwziJ.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-qomXThxX.js → HealthEventsModal-Cjfc5WFS.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-Cjfc5WFS.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-C8hKyXBe.js → LoginPage-DDVIfZGW.js} +1 -1
- package/dist/dashboard/assets/LoginPage-DDVIfZGW.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-C-ExCy1V.js → OverviewPage-B53YYMng.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-B53YYMng.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-BS9IEpvv.js → ProvidersPage-Dx31DgIO.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-Dx31DgIO.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-Rn_qXScb.js → ProxyPage-BpnR4kXT.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-BpnR4kXT.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-BihkgQSq.js → QuotaPage-BpOQCnun.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-BpOQCnun.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js +1 -0
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-CXjUlfqr.js → SetupPage-D6pmQ86L.js} +1 -1
- package/dist/dashboard/assets/SetupPage-D6pmQ86L.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-C-_oD3F2.js → SortableList-DWvKiuSl.js} +1 -1
- package/dist/dashboard/assets/SortableList-DWvKiuSl.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-u9IxmYOI.js → StudioPage-CmkUrgdj.js} +1 -1
- package/dist/dashboard/assets/StudioPage-CmkUrgdj.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-BEVLVrwP.js → UsagePage-B47uOydr.js} +1 -1
- package/dist/dashboard/assets/UsagePage-B47uOydr.js.gz +0 -0
- package/dist/dashboard/assets/{entry-Dj9AR0gY.js → entry-CkryrIea.js} +3 -3
- package/dist/dashboard/assets/entry-CkryrIea.js.gz +0 -0
- package/dist/dashboard/assets/{index-DCBtROoK.js → index-BydyKaDz.js} +2 -2
- package/dist/dashboard/assets/index-BydyKaDz.js.gz +0 -0
- package/dist/dashboard/assets/{select-DsX5QT8K.js → select-BO6h8yNv.js} +1 -1
- package/dist/dashboard/assets/select-BO6h8yNv.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 +21 -21
- package/package.json +1 -1
- package/scripts/cli/command/console-menu.ts +248 -246
- package/scripts/cli/command/tray.ts +208 -204
- package/src/config/spec.ts +26 -2
- package/src/console/backup/routes.ts +52 -1
- package/src/console/backup/service.ts +60 -4
- package/src/console/share/share-router.ts +6 -9
- package/src/observability/payload-capture.ts +366 -344
- package/src/observability/payload-store.ts +12 -2
- package/src/observability/telemetry-status.ts +28 -16
- package/src/persistence/stores/api-key-store.ts +6 -0
- package/src/persistence/stores/share-store.ts +583 -556
- package/src/persistence/stores/telemetry-store.ts +1 -1
- package/src/protocol/response/gemini.ts +18 -4
- package/src/providers/integrations/antigravity/antigravity-quota.ts +11 -3
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +4 -4
- package/src/providers/integrations/buddy/workbuddy/shared.ts +201 -200
- package/src/providers/integrations/cline/cline-quota.ts +8 -11
- package/src/providers/integrations/opencode/provider.ts +532 -532
- package/src/providers/integrations/tokenharbor.ts +2 -2
- package/src/providers/integrations/trae/trae-catalog.ts +5 -3
- package/src/providers/operations/account-health-service.ts +23 -0
- package/src/providers/operations/client-versions.ts +9 -2
- package/src/providers/provider-metadata.ts +7 -1
- package/src/transport/dispatch/attempt-finalize.ts +46 -5
- package/src/transport/dispatch/proxy-request.ts +9 -0
- package/src/transport/dispatch/streaming/stream.ts +16 -2
- package/src/transport/routing/route-catalog.ts +806 -799
- package/dist/dashboard/assets/BannedPage-MsQaeQTs.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-DfWHTJ7v.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js +0 -1
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-u9IxmYOI.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js.gz +0 -0
- package/dist/dashboard/assets/index-DCBtROoK.js.gz +0 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js.gz +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|