cartethyia 2.6.4 → 2.6.5
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-rvAOt5Ad.js → BannedPage-B7OjIxCp.js} +1 -1
- package/dist/dashboard/assets/BannedPage-B7OjIxCp.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-ZoKZDsob.js → CliToolDetailPage-Bt-6y24w.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-Bt-6y24w.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-1_a6Tw8Y.js → CliToolsPage-C6LunsuE.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-C6LunsuE.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-Czo7GLxL.js → CombosPage-CgyfN2Yy.js} +1 -1
- package/dist/dashboard/assets/CombosPage-CgyfN2Yy.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-BrlBFGtF.js → ConsoleLogPage-BHWU7y6j.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-BHWU7y6j.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-COvQuDTc.js → CustomizationPage-xIjU736m.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-xIjU736m.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-gTD1Qv_d.js → HealthEventsModal-DeT1zkYG.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-DeT1zkYG.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-BlGbMdYo.js → LoginPage-ChVqIAam.js} +1 -1
- package/dist/dashboard/assets/LoginPage-ChVqIAam.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-BhUFw9Qp.js → OverviewPage-BD4GkRtS.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-BD4GkRtS.js.gz +0 -0
- package/dist/dashboard/assets/{ProviderDetailPage-CrBfX_gj.js → ProviderDetailPage-BJXwqpKj.js} +1 -1
- package/dist/dashboard/assets/ProviderDetailPage-BJXwqpKj.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-CZ7sCKxk.js → ProvidersPage-Ck64riM5.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-Ck64riM5.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-PnJWpC9C.js → ProxyPage-Br_Leqq0.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-Br_Leqq0.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-CrGTXWjQ.js → QuotaPage-D2gyhfa8.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-D2gyhfa8.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-DXjUbFh_.js → SettingsPage-1dbYb8cM.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-1dbYb8cM.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-DCFo3R5_.js → SetupPage-DUTFy9wH.js} +1 -1
- package/dist/dashboard/assets/SetupPage-DUTFy9wH.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-lFdVPMo_.js → SortableList-BZEhfDpZ.js} +1 -1
- package/dist/dashboard/assets/SortableList-BZEhfDpZ.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-DPbSWHny.js → StudioPage-GBDtsJjh.js} +1 -1
- package/dist/dashboard/assets/StudioPage-GBDtsJjh.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-B-CTPrqB.js → UsagePage-CxidMvxq.js} +1 -1
- package/dist/dashboard/assets/UsagePage-CxidMvxq.js.gz +0 -0
- package/dist/dashboard/assets/{entry-BcfdW4C_.js → entry-BrksMru8.js} +3 -3
- package/dist/dashboard/assets/entry-BrksMru8.js.gz +0 -0
- package/dist/dashboard/assets/{index-_rbyCXD2.js → index-DU61iviS.js} +2 -2
- package/dist/dashboard/assets/index-DU61iviS.js.gz +0 -0
- package/dist/dashboard/assets/{select-BTEzH1iH.js → select-Ciq_KFQ1.js} +1 -1
- package/dist/dashboard/assets/select-Ciq_KFQ1.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/src/main.ts +6 -0
- package/dist/dashboard/assets/BannedPage-rvAOt5Ad.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-ZoKZDsob.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-1_a6Tw8Y.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-Czo7GLxL.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-BrlBFGtF.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-COvQuDTc.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-gTD1Qv_d.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-BlGbMdYo.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-BhUFw9Qp.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-CrBfX_gj.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-CZ7sCKxk.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-PnJWpC9C.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CrGTXWjQ.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DXjUbFh_.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-DCFo3R5_.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-lFdVPMo_.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-DPbSWHny.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-B-CTPrqB.js.gz +0 -0
- package/dist/dashboard/assets/entry-BcfdW4C_.js.gz +0 -0
- package/dist/dashboard/assets/index-_rbyCXD2.js.gz +0 -0
- package/dist/dashboard/assets/select-BTEzH1iH.js.gz +0 -0
package/dist/dashboard/assets/{ProviderDetailPage-CrBfX_gj.js → ProviderDetailPage-BJXwqpKj.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,r as l,t as u}from"./concurrency-BDF0ok7y.js";import{C as d,E as f,O as p,T as m,a as h,c as g,l as _,m as v,s as y,v as b,w as x,x as S}from"./numbers-Dulqgys5.js";import{t as C}from"./circle-alert-CntYHV5v.js";import{t as w}from"./circle-check-BU3v_mFW.js";import{t as T}from"./cog-CdWhsajs.js";import{t as E}from"./eye-off-Bk5g2luF.js";import{t as D}from"./eye-C_hawfH4.js";import{t as 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-DhZBfWgx.js";import{t as te}from"./key-round-UkavsGxp.js";import{t as M}from"./layers-2-glBbjl.js";import{r as ne}from"./use-modal-focus-By7oJoGd.js";import{n as N,t as P}from"./dialog-Iec_ywbD.js";import{t as F}from"./pencil-768ysRAr.js";import{t as I}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{C as le,T as ue,v as de}from"./assert-DU6qrMA_.js";import{i as fe,l as pe,o as me,t as L}from"./query-keys-UETqfytp.js";import{$ as he,C as R,D as ge,E as _e,O as ve,S as ye,a as be,b as xe,c as Se,ct as Ce,d as z,et as we,f as Te,g as Ee,h as De,k as Oe,l as ke,lt as Ae,m as je,o as Me,p as Ne,r as Pe,t as B,tt as Fe,u as Ie,w as Le,x as V,y as Re,z as ze}from"./entry-BcfdW4C_.js";import{n as H,r as U,t as W}from"./card-BOPBuBzD.js";import{n as Be}from"./download-dRFo5_Wu.js";import{f as G,i as Ve,l as He,n as Ue,r as We,s as Ge}from"./tokens-COzario9.js";import{t as K}from"./badge-Bkz_-RrM.js";import{n as q}from"./input-WlyHWeG2.js";import{t as J}from"./select-BTEzH1iH.js";import{t as Ke}from"./ProviderIcon-CmfzxpVM.js";import{t as qe}from"./switch-yD7D99Lg.js";import{t as Y}from"./stack-B1w5BM0u.js";import{n as X,t as Je}from"./inline-DToMICwl.js";import{i as Ye}from"./quota-DZGyp0N5.js";import{t as Xe}from"./list-row-B3oSK13z.js";import{c as Ze,l as Qe,m as $e}from"./routing-BPUo-W8d.js";import{t as et}from"./banner-C-7y3VKV.js";import{o as tt,s as nt,t as rt}from"./HealthEventsModal-gTD1Qv_d.js";import{r as it}from"./privacy-mode-GM8bej85.js";import{n as at,t as ot}from"./AccountCooldown-Bjo92Qat.js";import{t as st}from"./use-timeout-BwcBBRrT.js";var ct=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`}]]),lt=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`}]]),ut=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`}]]),dt=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`}]]),ft=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`}]]),pt=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`}]]),mt=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`}]]),ht=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`}]]),gt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function _t(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function vt({to:e,label:t}){let n=he();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function yt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(vt,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:v(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function bt(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function xt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var St={fallback:`Failover`,roundRobin:`Round robin`},Ct=new Set([`inferhub`,`cline`]);function wt(e,t){let n=Qe(e),r=$e(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=xt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=xt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=xt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=xt(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 Tt=50,Et=100;function Dt(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 Ot({children:e,action:t}){return(0,Q.jsx)(Xe,{actions:t,children:e})}function kt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=wt(e,r),[a,o]=(0,Z.useState)(!1),s=Ct.has(e),l=Dt(B,n.codex,n.claude),u=l.some(e=>e.value===i.userAgent)?l:[...l,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(A,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(k,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${St.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:St.fallback,f=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,p=i.maxInflight===null,m=p?51:Math.min(51,Math.max(1,i.maxInflight)),h=p?`∞`:String(i.maxInflight),_=i.maxInflightPerProxy===null,v=_?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),b=_?`∞`:String(i.maxInflightPerProxy),x=i.skipProxy,S=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},C=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;y.success(`Client identity updated`,t)},w=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Routing Strategy`,subtitle:f,icon:(0,Q.jsx)(M,{size:16})}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsx)(Ot,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(N,{size:14}),onClick:()=>S(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(I,{size:14}),onClick:()=>S(1)})]}):null,(0,Q.jsx)(qe,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ft,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(Ot,{action:(0,Q.jsx)(qe,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ct,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(c,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(J,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:C}):(0,Q.jsx)(J,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:w,options:[{value:w,label:w}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(O,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,Tt,` is unlimited.`]}),(0,Q.jsxs)(X,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":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>Tt?null:Math.round(t))},style:{"--slider-pct":`${m/51*100}%`}}),(0,Q.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(Et,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${p?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${x?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ht,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(g,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,Q.jsxs)(X,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":_?`true`:void 0,min:1,max:51,step:1,disabled:x,value:v,"aria-valuetext":_?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>Tt?null:Math.round(t))},style:{"--slider-pct":`${v/51*100}%`}}),(0,Q.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(Et,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${_?`text-status-success`:``}`})]}),(0,Q.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 ${Tt} is unlimited.`})]}),(0,Q.jsx)(P,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),s&&(0,Q.jsxs)(X,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(lt,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function At(e){if(typeof e!=`object`||!e)throw{status:500,code:`invalid_response`,message:`Invalid InferHub summary`};let t=e;return{models:Array.isArray(t.models)?t.models:[],providers:Array.isArray(t.providers)?t.providers:[],pricingConfig:t.pricingConfig??null,meta:t.meta??{fetchedAt:0,ageSeconds:0,stale:!0},error:t.error??null}}function jt(e=!0){return le({queryKey:L.inferhub.summary,queryFn:e=>me(`/inferhub/summary`,{signal:de(e)}).then(At),enabled:e,...fe,staleTime:6e4})}function Mt(e){return e===null?`—`:`$${e.toFixed(4)}`}function Nt(e){return e===null?`—`:`${e}%`}function Pt(e){return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}var Ft={provider:`Provider (A–Z)`,availability:`Highest availability`,sustainable:`Sustainable price`,price:`Lowest price`,discount:`Biggest discount`};function It(e,t){return(n,r)=>{let i=e(n),a=e(r);return i===null&&a===null?0:i===null?1:a===null?-1:t===`asc`?i-a:a-i}}function Lt(e){switch(e){case`provider`:return(e,t)=>e.family.localeCompare(t.family,void 0,{sensitivity:`base`})||e.prefix.localeCompare(t.prefix);case`availability`:return(e,t)=>t.providersLive-e.providersLive||It(e=>e.health.successRatePct,`desc`)(e,t);case`sustainable`:return It(e=>e.capacityPriceIn,`asc`);case`price`:return It(e=>e.minAskIn,`asc`);case`discount`:return It(e=>e.tiersIn[0]?.discountPct??null,`desc`)}}function Rt(e){return e===`operational`?`ok`:e===`degraded`?`warn`:e===`major_outage`?`err`:`default`}function zt(e,t){return e.providers.find(e=>e.prefix===t)}function Bt(e){return e.providersLive>0&&e.routable&&e.minAskIn!==null}function Vt(){let e=jt(),t=e.data,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(`provider`),u=t?.models??[],d=u.filter(Bt),f=(0,Z.useMemo)(()=>{let e=[...i?u:d].sort(Lt(c)),t=new Map;for(let n of e){let e=t.get(n.prefix);e===void 0?t.set(n.prefix,[n]):e.push(n)}return[...t.entries()].map(([e,t])=>({prefix:e,family:t[0]?.family??e,models:t}))},[u,d,i,c]),p=(0,Q.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,Q.jsx)(ie,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,Q.jsx)(ie,{size:16})}),(0,Q.jsx)(H,{children:e.isError?(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`InferHub market`,icon:(0,Q.jsx)(ie,{size:16}),action:p}),(0,Q.jsx)(H,{children:(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let m=f,h=m.reduce((e,t)=>e+t.models.length,0),_=u.length-h;return(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-start gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,Q.jsx)(Ae,{size:15,"aria-hidden":`true`,className:v(`mt-1 shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,Q.jsxs)(Y,{gap:`1px`,children:[(0,Q.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,Q.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,Pt(t.meta.ageSeconds)]}):null]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:n?p:null})]}),n?(0,Q.jsxs)(H,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(Ut,{onSaved:()=>void e.refetch()}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,Q.jsx)(J,{value:c,onValueChange:e=>l(e),options:Object.keys(Ft).map(e=>({value:e,label:Ft[e]})),"aria-label":`Sort InferHub models`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,Q.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`InferHub did not answer. Showing the last snapshot that was read`,t.meta.fetchedAt>0?` (${Pt(t.meta.ageSeconds)})`:``,`.`]}):null,t.meta.stale&&t.error===null?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,Pt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[h,` of `,u.length,` models`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,_>0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,_,` hidden)`]}):null]})]}),m.length===0?(0,Q.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:m.map(e=>(0,Q.jsx)(Ht,{group:e,showUpstreams:o,summary:t},e.prefix))})]}):null]})}function Ht({group:e,showUpstreams:t,summary:n}){let[r,i]=(0,Z.useState)(!0),a=zt(n,e.prefix),o=a?.familyState??null,s=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,Q.jsx)(Ae,{size:14,"aria-hidden":`true`,className:v(`shrink-0 transition-transform`,!r&&`-rotate-90`)}),(0,Q.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,Q.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),o===null?null:(0,Q.jsx)(K,{tone:Rt(o),dot:!0,children:o.replace(/_/g,` `)}),t&&a!==void 0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Nt(a.availability24hPct),` · 7d`,` `,Nt(a.availability7dPct)]}):null,(0,Q.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),r?(0,Q.jsxs)(`div`,{className:`px-3 pb-3`,children:[s===null?null:(0,Q.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:s}),(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,Q.jsx)(`tbody`,{children:e.models.map(e=>(0,Q.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,Q.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,Q.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Mt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,Q.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Mt(e.capacityPriceIn),` sustainable`]}):null]}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Mt(e.minAskOut)}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,Q.jsx)(K,{children:`none`}):e.providersLive}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Nt(t?a?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function Ut({onSaved:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await me(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await me(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,Q.jsx)(q,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,Q.jsx)(g,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,Q.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),s===null?null:(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function Wt({providerId:e}){let t=wt(e,!1),n=tt(),r=Ze(e),i=(0,Z.useMemo)(()=>Kt(n.data?.accounts??[],e),[n.data,e]),a=(0,Z.useRef)(null),o=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Z.useState)(`40`),[l,u]=(0,Z.useState)(`percent`),d=t.usageFloor!==null;(0,Z.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,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(O,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,Q.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`}),i.inactiveAccounts>0?(0,Q.jsxs)(`span`,{className:`badge border border-warning-line text-status-warning normal-case tracking-normal`,title:`Disabled or cooled accounts hold credits this provider cannot route to. Enable or recover them to add their balance.`,children:[i.inactiveAccounts,` inactive`]}):null]}),(0,Q.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,Q.jsx)(`strong`,{className:`font-bold ${m}`,children:qt(i.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,qt(i.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${qt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${qt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value: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,Q.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,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(qe,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(Gt,{providerId:e})]})}function Gt({providerId:e}){let{enabled:t,setEnabled:n}=it(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(E,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(qe,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function Kt(e,t){let n=0,r=0,i=0,a=0,o=!1;for(let s of e)if(s.provider===t){if(!s.active){a+=1;continue}if(i+=1,s.quota!==null)for(let e of s.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,o=!0)}}return i>0&&o?{accounts:i,inactiveAccounts:a,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function qt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Jt({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(W,{density:`compact`,children:(0,Q.jsx)(H,{children:(0,Q.jsxs)(X,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:_({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(Ce,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function Yt({provider:e}){let t=ve(),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.baseUrl??``);(0,Z.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,Q.jsx)(d,{size:16})}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(Y,{gap:`12px`,children:[n?(0,Q.jsx)(q,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,Q.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,Q.jsxs)(X,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(pt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ne,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(F,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(te,{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 Xt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Zt=new Set([`quota_fetch_failed`]);function Qt(e){return e===void 0||e.length===0?!1:!Zt.has(e)}function $t(e){return e===`oauth`?`Re-login required`:`Replace API key`}function en(e,t){return e===`auth_invalidated`?$t(t):Xt[e]??e}var tn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],nn=[`refresh`,`refreshToken`,`refresh_token`],rn=[`credentialKind`,`providerId`,`accessToken`],an=[`accounts`,`items`,`connections`],on=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function sn(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function cn(e){for(let t of tn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=sn(e);if(t)for(let e of tn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function ln(e){for(let t of on){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=sn(e);if(t)for(let e of on){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function un(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,nn);if(n(e))return!0;let r=sn(e);return r?n(r):!1}function dn(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function fn(e){let t=dn(e)?.exp;if(typeof t!=`number`||!Number.isFinite(t))return;let n=new Date(t*1e3);return Number.isFinite(n.getTime())?n.toISOString():void 0}function pn(e){let t={},n=0;for(let r of e.split(/\r?\n/)){let e=/^\s*([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(r),i=e?.[1],a=e?.[2];i!==void 0&&a!==void 0&&(t[i]=a.trim(),n+=1)}return n>0?t:void 0}function mn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var hn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function gn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of hn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function _n(e){let t=e.trim(),n=$(mn(t))??pn(t);return n&&un(n)?`oauth`:dn((n?cn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function vn(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 yn(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 bn(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&rn.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&un(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=cn(e),r=un(e)?`oauth`:_n(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=ln(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function xn(e){for(let t of an){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function Sn(e){let t=e.trim();if(!t)return[];let n=mn(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return vn(e)?[yn(t,e)]:e.map(bn)}else{let e=$(n);if(e){let t=xn(e);return t?t.map(bn):[bn(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1){let e=pn(r[0]);return e?[bn(e)]:Cn(r[0])}let i=pn(t);return i&&(cn(i)||Object.keys(i).length===r.length)?[bn(i)]:r.flatMap(Cn)}function Cn(e){let t=$(mn(e));if(t){let e=xn(t);return e?e.map(bn):[bn(t)]}return[{value:e,kind:_n(e)}]}function wn(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 Tn(e,t=50){if(t<1)throw RangeError(`chunk size must be at least 1`);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function En(e){return e===`active`?0:e===`cooldown`?2:3}function Dn(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()}`:Ye(e,!1)}function On({cooldowns:e,reason:t}){if(!e)return null;let n=Ye(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(K,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function kn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function An(e){return e.credentialKind===`oauth`?`blue`:`ok`}function jn({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=ot(e);if(e.status===`disabled`){let t=kn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError,children:$t(e.credentialKind)}):Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:An(e),dot:!0,children:[`Active`,kn(e)?` - ${kn(e)}`:``]}),Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`warn`,dot:!0,children:[`Cooldown`,kn(e)?` - ${kn(e)}`:``,` `,e.cooldownUntil?`(${Ye(e.cooldownUntil)})`:``]}),Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(K,{tone:`disabled`,children:`Disabled`})}function Mn({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=`${Nn(t)} of ${Nn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${Nn(t)} credits available of ${Nn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function Nn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Pn({providerId:e,account:t,onClose:n}){let r=Oe(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{y.error(`Clipboard access denied`)}};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(g,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{y.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;y.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(Y,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(X,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Fn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=Oe(),l=Re(),u=nt(t.id),d=t.status===`disabled`,f=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,p=Number.isFinite(f)&&f>Date.now(),m=t.status===`cooldown`||p,[h,_]=(0,Z.useState)(!1),[v,b]=(0,Z.useState)(!1),[,C]=(0,Z.useState)(0),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(``),O=it(e),ee=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),k=O.enabled?`Mysterious accounts`:ee,A=Dn(t.tokenExpiresAt),j=at(t),M=Math.max(p&&t.cooldownUntil?f:0,j??0);(0,Z.useEffect)(()=>{if(M<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[M]);let ne=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>y.success(`Account renamed`,n),onError:e=>y.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:d?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${k}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,Q.jsx)(q,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ne(),e.key===`Escape`&&T(!1)},onBlur:ne,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:k}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${k}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,Q.jsx)(F,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(jn,{account:t}),A?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:A,children:A}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(Mn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${k}`,onClick:()=>_(!0),title:`View Health & Error History`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(S,{size:12,className:`animate-spin`}):(0,Q.jsx)(x,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${k}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?y.success(`Account test passed`,k):y.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>y.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(te,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${k}`,onClick:()=>b(!0),title:`Replace API key`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:d?(0,Q.jsx)(ut,{size:12}):(0,Q.jsx)(re,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${k}`:`Disable ${k}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>y.success(n?`Account enabled`:`Account disabled`,k),onError:e=>y.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.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,Q.jsx)(g,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),label:`Delete`,"aria-label":`Delete ${k}`,onClick:()=>s(t),title:`Delete account`})]})]}),h&&(0,Q.jsx)(rt,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode,jwtIssuer:t.jwtIssuer},onClose:()=>_(!1)}),v&&(0,Q.jsx)(Pn,{providerId:e,account:t,onClose:()=>b(!1)})]})}var In=[{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 Ln(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=En(e.status)-En(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 Rn({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ue(),s=Oe(),c=Re(),l=ke(),d=Ze(e).data??new Map,f=tt(),p=(0,Z.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[h,_]=(0,Z.useState)(``),[v,b]=(0,Z.useState)(new Set),[S,C]=(0,Z.useState)(`added-asc`),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(null),[O,ee]=(0,Z.useState)(!1),k=h.trim().toLowerCase(),A=(0,Z.useMemo)(()=>k?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return k.split(/\s+/).every(e=>t.includes(e))}):t,[t,k]),te=(0,Z.useMemo)(()=>{let e=S.slice(0,S.lastIndexOf(`-`)),t=S.endsWith(`-desc`)?-1:1,n=[...A];return n.sort((n,r)=>t*Ln(n,r,e)),n},[A,S]),M=(0,Z.useMemo)(()=>t.filter(e=>v.has(e.id)),[t,v]),N=A.length>0&&A.every(e=>v.has(e.id)),P=M.some(e=>e.status===`disabled`),F=M.some(e=>e.status!==`disabled`),I=M.length===0,ie=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},ce=()=>{b(e=>{let t=new Set(e);if(N)for(let e of A)t.delete(e.id);else for(let e of A)t.add(e.id);return t})},le=async(e,t)=>{if(M.length===0)return;T(!0);let n=await Promise.allSettled(M.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;T(!1),r===0?y.success(`${e} complete`,`${i} account${i===1?``:`s`}`):y.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},de=()=>le(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),fe=async()=>{t.length!==0&&(T(!0),D({done:0,total:t.length}),await u(t,3,async(e,n)=>{let r=await me(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return D({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:L.quota.all}),o.invalidateQueries({queryKey:L.providers.all})]),T(!1),D(null),y.success(`Test complete`,`${t.length} account${t.length===1?``:`s`} tested`))},pe=t=>le(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),he=async()=>{if(M.length!==0){T(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:M.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Be(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),y.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){y.error(`Export failed`,e.message??`Unable to export accounts`)}finally{T(!1)}}};return(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative w-full`,children:[(0,Q.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,Q.jsx)(q,{id:`accounts-search`,value:h,onChange:e=>_(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Q.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(x,{size:12}),disabled:w||t.length===0,onClick:fe,"aria-label":E===null?`Test all accounts`:`Testing accounts, ${E.done} of ${E.total} tested`,title:`Test every account, regardless of selection or filters`,children:E===null?`Test all`:`Tested ${E.done}/${E.total}`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ae,{size:12}),disabled:w||I,title:I?`Select at least one account to recover it`:`Clear cooldowns and retry-wait states on the selected accounts`,onClick:()=>void de(),children:`Recover`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ut,{size:12}),disabled:w||!P,title:I?`Select at least one disabled account to enable it`:P?`Enable the selected accounts`:`No selected account is currently disabled`,onClick:()=>void pe(!0),children:`Enable`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(re,{size:12}),disabled:w||!F,title:I?`Select at least one enabled account to disable it`:F?`Disable the selected accounts`:`No selected account is currently enabled`,onClick:()=>void pe(!1),children:`Disable`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(m,{size:12}),disabled:w||I,title:I?`Select at least one account to export`:`Download the selected accounts as JSON`,onClick:()=>void he(),children:`Export`}),(0,Q.jsx)(g,{size:`sm`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),disabled:w||I,title:I?`Select at least one account to delete`:`Delete ${M.length} selected account${M.length===1?``:`s`}`,onClick:()=>ee(!0),children:`Delete`}),r?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(x,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null,(0,Q.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,Q.jsx)(J,{size:`sm`,value:S,onValueChange:e=>C(e),options:In,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:N,onChange:ce,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),I?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(new Set),className:`inline-flex h-15 shrink-0 items-center gap-1 rounded-control border border-inner-border px-3 text-badge font-semibold text-text-secondary hover:bg-hover`,title:`Clear selection`,children:[M.length,` selected`,(0,Q.jsx)(ne,{size:11,"aria-hidden":`true`})]})]})]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:te.length===0?(0,Q.jsx)(j,{compact:!0,icon:(0,Q.jsx)(oe,{size:20}),title:`No matching accounts`,message:k?`Nothing matches “${k}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):te.map(t=>(0,Q.jsx)(Fn,{providerId:e,account:t,inflight:d.get(t.id)??t.inflight,quota:p.get(t.id),selected:v.has(t.id),onToggleSelect:ie,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,A.length,` account`,A.length===1?``:`s`,k?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(ze,{open:O,onClose:()=>{w||ee(!1)},onConfirm:async()=>{await le(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await me(t,{method:`DELETE`}),o.removeQueries({queryKey:L.quota.account(e.id),exact:!0})}),b(new Set),ee(!1),await Promise.all([o.invalidateQueries({queryKey:L.providers.accounts(e)}),o.invalidateQueries({queryKey:L.providers.all}),o.invalidateQueries({queryKey:L.quota.all})])},title:`Delete ${M.length} account${M.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var zn=2097152,Bn=zn/1048576;function Vn({providerId:e,accounts:t,onClose:n}){let r=be(),i=Me(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(`auto`),[p,m]=(0,Z.useState)(void 0),h=Sn(s),v=h.length>1,b=h.length===1?h[0]:void 0,x=d===`auto`?b?.kind:d,S=b&&x===`jwt`?fn(b.value):void 0,C=h.length>0?gn(e,s):void 0,w=C!==void 0&&p!==s,T=t.map(e=>e.label),E=v?wn(h,e,T):[],D=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}},O=r.isPending||l,ee=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=Sn(e);if(t.length>1)y.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;y.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{y.error(`Clipboard access denied`)}},k=e=>{if(e.size>zn){y.error(`File too large`,`Credential files must be ${Bn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=Sn(n);if(r.length===0){y.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}y.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>y.error(`Could not read that file`),t.readAsText(e)},A=async()=>{if(h.length!==0&&!w){if(h.length===1){let t=h[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...D(t)}},{onSuccess:()=>{y.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>y.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=Tn(h.map((e,t)=>({label:E[t],...D(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${E[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${pe(e,`request failed`)}`);break}let s=a.length;r>0&&y.success(`${r} account${r===1?``:`s`} added`,o?`stopped partway; ${s} failed`:s>0?`${s} skipped`:void 0),s>0&&y.error(`${s} account${s===1?``:`s`} skipped`,a.slice(0,5).join(`
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,r as l,t as u}from"./concurrency-BDF0ok7y.js";import{C as d,E as f,O as p,T as m,a as h,c as g,l as _,m as v,s as y,v as b,w as x,x as S}from"./numbers-Dulqgys5.js";import{t as C}from"./circle-alert-CntYHV5v.js";import{t as w}from"./circle-check-BU3v_mFW.js";import{t as T}from"./cog-CdWhsajs.js";import{t as E}from"./eye-off-Bk5g2luF.js";import{t as D}from"./eye-C_hawfH4.js";import{t as 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-DhZBfWgx.js";import{t as te}from"./key-round-UkavsGxp.js";import{t as M}from"./layers-2-glBbjl.js";import{r as ne}from"./use-modal-focus-By7oJoGd.js";import{n as N,t as P}from"./dialog-Iec_ywbD.js";import{t as F}from"./pencil-768ysRAr.js";import{t as I}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{C as le,T as ue,v as de}from"./assert-DU6qrMA_.js";import{i as fe,l as pe,o as me,t as L}from"./query-keys-UETqfytp.js";import{$ as he,C as R,D as ge,E as _e,O as ve,S as ye,a as be,b as xe,c as Se,ct as Ce,d as z,et as we,f as Te,g as Ee,h as De,k as Oe,l as ke,lt as Ae,m as je,o as Me,p as Ne,r as Pe,t as B,tt as Fe,u as Ie,w as Le,x as V,y as Re,z as ze}from"./entry-BrksMru8.js";import{n as H,r as U,t as W}from"./card-BOPBuBzD.js";import{n as Be}from"./download-dRFo5_Wu.js";import{f as G,i as Ve,l as He,n as Ue,r as We,s as Ge}from"./tokens-COzario9.js";import{t as K}from"./badge-Bkz_-RrM.js";import{n as q}from"./input-WlyHWeG2.js";import{t as J}from"./select-Ciq_KFQ1.js";import{t as Ke}from"./ProviderIcon-CmfzxpVM.js";import{t as qe}from"./switch-yD7D99Lg.js";import{t as Y}from"./stack-B1w5BM0u.js";import{n as X,t as Je}from"./inline-DToMICwl.js";import{i as Ye}from"./quota-DZGyp0N5.js";import{t as Xe}from"./list-row-B3oSK13z.js";import{c as Ze,l as Qe,m as $e}from"./routing-BPUo-W8d.js";import{t as et}from"./banner-C-7y3VKV.js";import{o as tt,s as nt,t as rt}from"./HealthEventsModal-DeT1zkYG.js";import{r as it}from"./privacy-mode-GM8bej85.js";import{n as at,t as ot}from"./AccountCooldown-Bjo92Qat.js";import{t as st}from"./use-timeout-BwcBBRrT.js";var ct=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`}]]),lt=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`}]]),ut=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`}]]),dt=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`}]]),ft=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`}]]),pt=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`}]]),mt=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`}]]),ht=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`}]]),gt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function _t(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function vt({to:e,label:t}){let n=he();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function yt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(vt,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:v(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function bt(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function xt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var St={fallback:`Failover`,roundRobin:`Round robin`},Ct=new Set([`inferhub`,`cline`]);function wt(e,t){let n=Qe(e),r=$e(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=xt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=xt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=xt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=xt(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 Tt=50,Et=100;function Dt(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 Ot({children:e,action:t}){return(0,Q.jsx)(Xe,{actions:t,children:e})}function kt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=wt(e,r),[a,o]=(0,Z.useState)(!1),s=Ct.has(e),l=Dt(B,n.codex,n.claude),u=l.some(e=>e.value===i.userAgent)?l:[...l,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(A,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(k,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${St.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:St.fallback,f=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,p=i.maxInflight===null,m=p?51:Math.min(51,Math.max(1,i.maxInflight)),h=p?`∞`:String(i.maxInflight),_=i.maxInflightPerProxy===null,v=_?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),b=_?`∞`:String(i.maxInflightPerProxy),x=i.skipProxy,S=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},C=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;y.success(`Client identity updated`,t)},w=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Routing Strategy`,subtitle:f,icon:(0,Q.jsx)(M,{size:16})}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsx)(Ot,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(N,{size:14}),onClick:()=>S(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(g,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(I,{size:14}),onClick:()=>S(1)})]}):null,(0,Q.jsx)(qe,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ft,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(Ot,{action:(0,Q.jsx)(qe,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ct,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(c,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(J,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:C}):(0,Q.jsx)(J,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:w,options:[{value:w,label:w}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(O,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Per-account ceiling, not a provider-wide one: each account enforces its own limit, so a full account spills to the next. One step past `,Tt,` is unlimited.`]}),(0,Q.jsxs)(X,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":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>Tt?null:Math.round(t))},style:{"--slider-pct":`${m/51*100}%`}}),(0,Q.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(Et,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${p?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${x?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(X,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ht,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(g,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,Q.jsxs)(X,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":_?`true`:void 0,min:1,max:51,step:1,disabled:x,value:v,"aria-valuetext":_?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>Tt?null:Math.round(t))},style:{"--slider-pct":`${v/51*100}%`}}),(0,Q.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(Et,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${_?`text-status-success`:``}`})]}),(0,Q.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 ${Tt} is unlimited.`})]}),(0,Q.jsx)(P,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),s&&(0,Q.jsxs)(X,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(lt,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function At(e){if(typeof e!=`object`||!e)throw{status:500,code:`invalid_response`,message:`Invalid InferHub summary`};let t=e;return{models:Array.isArray(t.models)?t.models:[],providers:Array.isArray(t.providers)?t.providers:[],pricingConfig:t.pricingConfig??null,meta:t.meta??{fetchedAt:0,ageSeconds:0,stale:!0},error:t.error??null}}function jt(e=!0){return le({queryKey:L.inferhub.summary,queryFn:e=>me(`/inferhub/summary`,{signal:de(e)}).then(At),enabled:e,...fe,staleTime:6e4})}function Mt(e){return e===null?`—`:`$${e.toFixed(4)}`}function Nt(e){return e===null?`—`:`${e}%`}function Pt(e){return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}var Ft={provider:`Provider (A–Z)`,availability:`Highest availability`,sustainable:`Sustainable price`,price:`Lowest price`,discount:`Biggest discount`};function It(e,t){return(n,r)=>{let i=e(n),a=e(r);return i===null&&a===null?0:i===null?1:a===null?-1:t===`asc`?i-a:a-i}}function Lt(e){switch(e){case`provider`:return(e,t)=>e.family.localeCompare(t.family,void 0,{sensitivity:`base`})||e.prefix.localeCompare(t.prefix);case`availability`:return(e,t)=>t.providersLive-e.providersLive||It(e=>e.health.successRatePct,`desc`)(e,t);case`sustainable`:return It(e=>e.capacityPriceIn,`asc`);case`price`:return It(e=>e.minAskIn,`asc`);case`discount`:return It(e=>e.tiersIn[0]?.discountPct??null,`desc`)}}function Rt(e){return e===`operational`?`ok`:e===`degraded`?`warn`:e===`major_outage`?`err`:`default`}function zt(e,t){return e.providers.find(e=>e.prefix===t)}function Bt(e){return e.providersLive>0&&e.routable&&e.minAskIn!==null}function Vt(){let e=jt(),t=e.data,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(`provider`),u=t?.models??[],d=u.filter(Bt),f=(0,Z.useMemo)(()=>{let e=[...i?u:d].sort(Lt(c)),t=new Map;for(let n of e){let e=t.get(n.prefix);e===void 0?t.set(n.prefix,[n]):e.push(n)}return[...t.entries()].map(([e,t])=>({prefix:e,family:t[0]?.family??e,models:t}))},[u,d,i,c]),p=(0,Q.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void e.refetch(),disabled:e.isFetching,title:`Re-read InferHub market data now`,children:[(0,Q.jsx)(ie,{size:14}),e.isFetching?`Refreshing…`:`Refresh`]});if(t===void 0&&!e.isError)return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`InferHub market`,subtitle:e.isPending?`Reading market data…`:void 0,icon:(0,Q.jsx)(ie,{size:16})}),(0,Q.jsx)(H,{children:e.isError?(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`}):null})]});if(t===void 0)return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`InferHub market`,icon:(0,Q.jsx)(ie,{size:16}),action:p}),(0,Q.jsx)(H,{children:(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`none`,children:`InferHub market data could not be read.`})})]});let m=f,h=m.reduce((e,t)=>e+t.models.length,0),_=u.length-h;return(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-label":n?`Collapse InferHub market`:`Expand InferHub market`,onClick:()=>r(e=>!e),className:`flex min-w-0 flex-1 items-start gap-3 border-0 bg-transparent p-0 text-left text-inherit`,children:[(0,Q.jsx)(Ae,{size:15,"aria-hidden":`true`,className:v(`mt-1 shrink-0 transition-transform`,!n&&`-rotate-90`)}),(0,Q.jsxs)(Y,{gap:`1px`,children:[(0,Q.jsx)(`h2`,{className:`text-body font-bold`,children:`InferHub market`}),t.meta.fetchedAt>0?(0,Q.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Updated `,Pt(t.meta.ageSeconds)]}):null]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:n?p:null})]}),n?(0,Q.jsxs)(H,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(Ut,{onSaved:()=>void e.refetch()}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary`,children:[`Sort`,(0,Q.jsx)(J,{value:c,onValueChange:e=>l(e),options:Object.keys(Ft).map(e=>({value:e,label:Ft[e]})),"aria-label":`Sort InferHub models`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`cursor-pointer`}),`Show availability`]})]})]}),t.error===`no_config_key`?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`No InferHub `,(0,Q.jsx)(`code`,{children:`config_read`}),` key is configured, so the marketplace catalog cannot be read. Add one above.`]}):null,t.error===`upstream_unavailable`?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`InferHub did not answer. Showing the last snapshot that was read`,t.meta.fetchedAt>0?` (${Pt(t.meta.ageSeconds)})`:``,`.`]}):null,t.meta.stale&&t.error===null?(0,Q.jsxs)(et,{tone:`warning`,surface:`raised`,live:`none`,children:[`This snapshot is `,Pt(t.meta.ageSeconds),` — press Refresh for current prices.`]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[h,` of `,u.length,` models`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-caption text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`cursor-pointer`}),`Show all`,_>0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary`,children:[`(includes `,_,` hidden)`]}):null]})]}),m.length===0?(0,Q.jsx)(`p`,{className:`mt-3 text-caption text-text-secondary`,children:`No models to show.`}):(0,Q.jsx)(`div`,{className:`mt-3 flex flex-col gap-3`,children:m.map(e=>(0,Q.jsx)(Ht,{group:e,showUpstreams:o,summary:t},e.prefix))})]}):null]})}function Ht({group:e,showUpstreams:t,summary:n}){let[r,i]=(0,Z.useState)(!0),a=zt(n,e.prefix),o=a?.familyState??null,s=e.models.find(e=>e.systemPromptNote!==null)?.systemPromptNote??null;return(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${e.family} models`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit`,children:[(0,Q.jsx)(Ae,{size:14,"aria-hidden":`true`,className:v(`shrink-0 transition-transform`,!r&&`-rotate-90`)}),(0,Q.jsx)(`span`,{className:`text-caption font-bold`,children:e.family}),(0,Q.jsxs)(`span`,{className:`font-mono text-micro text-text-tertiary`,children:[e.prefix,`/`]}),o===null?null:(0,Q.jsx)(K,{tone:Rt(o),dot:!0,children:o.replace(/_/g,` `)}),t&&a!==void 0?(0,Q.jsxs)(`span`,{className:`text-micro text-text-tertiary tabular-nums`,children:[`24h `,Nt(a.availability24hPct),` · 7d`,` `,Nt(a.availability7dPct)]}):null,(0,Q.jsxs)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:[e.models.length,` model`,e.models.length===1?``:`s`]})]}),r?(0,Q.jsxs)(`div`,{className:`px-3 pb-3`,children:[s===null?null:(0,Q.jsx)(`p`,{className:`mb-2 text-micro text-text-secondary`,children:s}),(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-caption`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-text-secondary`,children:[(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Model`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Input`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Output`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Discount`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:`Live`}),(0,Q.jsx)(`th`,{className:`py-1 pr-3`,children:t?`24h`:`Success`})]})}),(0,Q.jsx)(`tbody`,{children:e.models.map(e=>(0,Q.jsxs)(`tr`,{className:`border-t border-inner-border`,children:[(0,Q.jsx)(`td`,{className:`py-1 pr-3 font-mono`,children:e.id}),(0,Q.jsxs)(`td`,{className:`py-1 pr-3 tabular-nums`,children:[Mt(e.minAskIn),e.capacityPriceIn!==null&&e.capacityPriceIn!==e.minAskIn?(0,Q.jsxs)(`div`,{className:`text-micro text-text-secondary`,children:[Mt(e.capacityPriceIn),` sustainable`]}):null]}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Mt(e.minAskOut)}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.tiersIn[0]?.discountPct===void 0||e.tiersIn[0]?.discountPct===null?`—`:`−${e.tiersIn[0].discountPct}%`}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:e.providersLive===0?(0,Q.jsx)(K,{children:`none`}):e.providersLive}),(0,Q.jsx)(`td`,{className:`py-1 pr-3 tabular-nums`,children:Nt(t?a?.availability24hPct??null:e.health.successRatePct)})]},e.id))})]})})]}):null]})}function Ut({onSaved:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{if(t.trim().length!==0){o(!0),c(null);try{await me(`/inferhub/key`,{method:`PUT`,body:JSON.stringify({key:t.trim()})}),n(``),i({configured:!0,last4:null}),e()}catch{c(`Could not save the key.`)}finally{o(!1)}}},u=async()=>{o(!0),c(null);try{await me(`/inferhub/key`,{method:`DELETE`}),i({configured:!1,last4:null}),e()}catch{c(`Could not remove the key.`)}finally{o(!1)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-64 flex-1`,children:(0,Q.jsx)(q,{type:`password`,value:t,onChange:e=>n(e.target.value),placeholder:`sk-airo-… (config_read key)`,"aria-label":`InferHub config_read key`,autoComplete:`off`})}),(0,Q.jsx)(g,{size:`sm`,onClick:()=>void l(),disabled:a||t.trim().length===0,children:a?`Saving…`:`Save key`}),r?.configured?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,onClick:()=>void u(),disabled:a,children:`Remove`}):null]}),(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Stored encrypted beside the market settings, never in this provider's accounts. Must be a`,` `,(0,Q.jsx)(`code`,{children:`config_read`}),` key — never an inference key.`]}),s===null?null:(0,Q.jsx)(et,{tone:`danger`,surface:`raised`,live:`alert`,children:s})]})}function Wt({providerId:e}){let t=wt(e,!1),n=tt(),r=Ze(e),i=(0,Z.useMemo)(()=>Kt(n.data?.accounts??[],e),[n.data,e]),a=(0,Z.useRef)(null),o=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Z.useState)(`40`),[l,u]=(0,Z.useState)(`percent`),d=t.usageFloor!==null;(0,Z.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,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(O,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,Q.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`}),i.inactiveAccounts>0?(0,Q.jsxs)(`span`,{className:`badge border border-warning-line text-status-warning normal-case tracking-normal`,title:`Disabled or cooled accounts hold credits this provider cannot route to. Enable or recover them to add their balance.`,children:[i.inactiveAccounts,` inactive`]}):null]}),(0,Q.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,Q.jsx)(`strong`,{className:`font-bold ${m}`,children:qt(i.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,qt(i.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${qt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${qt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value: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,Q.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,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(qe,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(Gt,{providerId:e})]})}function Gt({providerId:e}){let{enabled:t,setEnabled:n}=it(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(E,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(qe,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function Kt(e,t){let n=0,r=0,i=0,a=0,o=!1;for(let s of e)if(s.provider===t){if(!s.active){a+=1;continue}if(i+=1,s.quota!==null)for(let e of s.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,o=!0)}}return i>0&&o?{accounts:i,inactiveAccounts:a,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function qt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Jt({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(W,{density:`compact`,children:(0,Q.jsx)(H,{children:(0,Q.jsxs)(X,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:_({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(Ce,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function Yt({provider:e}){let t=ve(),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.baseUrl??``);(0,Z.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,Q.jsx)(d,{size:16})}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(Y,{gap:`12px`,children:[n?(0,Q.jsx)(q,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,Q.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,Q.jsxs)(X,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(pt,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ne,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(F,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(te,{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 Xt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Zt=new Set([`quota_fetch_failed`]);function Qt(e){return e===void 0||e.length===0?!1:!Zt.has(e)}function $t(e){return e===`oauth`?`Re-login required`:`Replace API key`}function en(e,t){return e===`auth_invalidated`?$t(t):Xt[e]??e}var tn=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],nn=[`refresh`,`refreshToken`,`refresh_token`],rn=[`credentialKind`,`providerId`,`accessToken`],an=[`accounts`,`items`,`connections`],on=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function sn(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function cn(e){for(let t of tn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=sn(e);if(t)for(let e of tn){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function ln(e){for(let t of on){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=sn(e);if(t)for(let e of on){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function un(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,nn);if(n(e))return!0;let r=sn(e);return r?n(r):!1}function dn(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function fn(e){let t=dn(e)?.exp;if(typeof t!=`number`||!Number.isFinite(t))return;let n=new Date(t*1e3);return Number.isFinite(n.getTime())?n.toISOString():void 0}function pn(e){let t={},n=0;for(let r of e.split(/\r?\n/)){let e=/^\s*([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(r),i=e?.[1],a=e?.[2];i!==void 0&&a!==void 0&&(t[i]=a.trim(),n+=1)}return n>0?t:void 0}function mn(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}var hn=[{id:`codebuddy`,counterpart:`WorkBuddy`},{id:`workbuddy`,counterpart:`CodeBuddy`}];function gn(e,t){let n=`${e} ${t}`.toLowerCase().replace(/[^a-z]/g,``);for(let e of hn)if(n.includes(e.id))return{provider:e.id,counterpart:e.counterpart}}function _n(e){let t=e.trim(),n=$(mn(t))??pn(t);return n&&un(n)?`oauth`:dn((n?cn(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function vn(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 yn(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 bn(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&rn.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&un(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=cn(e),r=un(e)?`oauth`:_n(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=ln(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function xn(e){for(let t of an){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function Sn(e){let t=e.trim();if(!t)return[];let n=mn(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return vn(e)?[yn(t,e)]:e.map(bn)}else{let e=$(n);if(e){let t=xn(e);return t?t.map(bn):[bn(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1){let e=pn(r[0]);return e?[bn(e)]:Cn(r[0])}let i=pn(t);return i&&(cn(i)||Object.keys(i).length===r.length)?[bn(i)]:r.flatMap(Cn)}function Cn(e){let t=$(mn(e));if(t){let e=xn(t);return e?e.map(bn):[bn(t)]}return[{value:e,kind:_n(e)}]}function wn(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 Tn(e,t=50){if(t<1)throw RangeError(`chunk size must be at least 1`);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function En(e){return e===`active`?0:e===`cooldown`?2:3}function Dn(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()}`:Ye(e,!1)}function On({cooldowns:e,reason:t}){if(!e)return null;let n=Ye(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(K,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function kn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function An(e){return e.credentialKind===`oauth`?`blue`:`ok`}function jn({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=ot(e);if(e.status===`disabled`){let t=kn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError,children:$t(e.credentialKind)}):Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:An(e),dot:!0,children:[`Active`,kn(e)?` - ${kn(e)}`:``]}),Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(X,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`warn`,dot:!0,children:[`Cooldown`,kn(e)?` - ${kn(e)}`:``,` `,e.cooldownUntil?`(${Ye(e.cooldownUntil)})`:``]}),Qt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:en(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(On,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(K,{tone:`disabled`,children:`Disabled`})}function Mn({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=`${Nn(t)} of ${Nn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${Nn(t)} credits available of ${Nn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function Nn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Pn({providerId:e,account:t,onClose:n}){let r=Oe(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{y.error(`Clipboard access denied`)}};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(g,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{y.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;y.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(Y,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(X,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function Fn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=Oe(),l=Re(),u=nt(t.id),d=t.status===`disabled`,f=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,p=Number.isFinite(f)&&f>Date.now(),m=t.status===`cooldown`||p,[h,_]=(0,Z.useState)(!1),[v,b]=(0,Z.useState)(!1),[,C]=(0,Z.useState)(0),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(``),O=it(e),ee=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),k=O.enabled?`Mysterious accounts`:ee,A=Dn(t.tokenExpiresAt),j=at(t),M=Math.max(p&&t.cooldownUntil?f:0,j??0);(0,Z.useEffect)(()=>{if(M<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[M]);let ne=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>y.success(`Account renamed`,n),onError:e=>y.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:d?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${k}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,Q.jsx)(q,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ne(),e.key===`Escape`&&T(!1)},onBlur:ne,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:k}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${k}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,Q.jsx)(F,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(jn,{account:t}),A?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:A,children:A}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(Mn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts carry no manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${k}`,onClick:()=>_(!0),title:`View Health & Error History`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(S,{size:12,className:`animate-spin`}):(0,Q.jsx)(x,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${k}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?y.success(`Account test passed`,k):y.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>y.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(te,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${k}`,onClick:()=>b(!0),title:`Replace API key`}),(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:d?(0,Q.jsx)(ut,{size:12}):(0,Q.jsx)(re,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${k}`:`Disable ${k}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>y.success(n?`Account enabled`:`Account disabled`,k),onError:e=>y.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,Q.jsx)(g,{size:`icon`,variant:`secondary`,icon:(0,Q.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,Q.jsx)(g,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),label:`Delete`,"aria-label":`Delete ${k}`,onClick:()=>s(t),title:`Delete account`})]})]}),h&&(0,Q.jsx)(rt,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode,jwtIssuer:t.jwtIssuer},onClose:()=>_(!1)}),v&&(0,Q.jsx)(Pn,{providerId:e,account:t,onClose:()=>b(!1)})]})}var In=[{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 Ln(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=En(e.status)-En(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 Rn({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ue(),s=Oe(),c=Re(),l=ke(),d=Ze(e).data??new Map,f=tt(),p=(0,Z.useMemo)(()=>{let t=new Map;for(let n of f.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[f.data,e]),[h,_]=(0,Z.useState)(``),[v,b]=(0,Z.useState)(new Set),[S,C]=(0,Z.useState)(`added-asc`),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(null),[O,ee]=(0,Z.useState)(!1),k=h.trim().toLowerCase(),A=(0,Z.useMemo)(()=>k?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return k.split(/\s+/).every(e=>t.includes(e))}):t,[t,k]),te=(0,Z.useMemo)(()=>{let e=S.slice(0,S.lastIndexOf(`-`)),t=S.endsWith(`-desc`)?-1:1,n=[...A];return n.sort((n,r)=>t*Ln(n,r,e)),n},[A,S]),M=(0,Z.useMemo)(()=>t.filter(e=>v.has(e.id)),[t,v]),N=A.length>0&&A.every(e=>v.has(e.id)),P=M.some(e=>e.status===`disabled`),F=M.some(e=>e.status!==`disabled`),I=M.length===0,ie=(e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},ce=()=>{b(e=>{let t=new Set(e);if(N)for(let e of A)t.delete(e.id);else for(let e of A)t.add(e.id);return t})},le=async(e,t)=>{if(M.length===0)return;T(!0);let n=await Promise.allSettled(M.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;T(!1),r===0?y.success(`${e} complete`,`${i} account${i===1?``:`s`}`):y.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},de=()=>le(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),fe=async()=>{t.length!==0&&(T(!0),D({done:0,total:t.length}),await u(t,3,async(e,n)=>{let r=await me(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return D({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:L.quota.all}),o.invalidateQueries({queryKey:L.providers.all})]),T(!1),D(null),y.success(`Test complete`,`${t.length} account${t.length===1?``:`s`} tested`))},pe=t=>le(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),he=async()=>{if(M.length!==0){T(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:M.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Be(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),y.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){y.error(`Export failed`,e.message??`Unable to export accounts`)}finally{T(!1)}}};return(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative w-full`,children:[(0,Q.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,Q.jsx)(q,{id:`accounts-search`,value:h,onChange:e=>_(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Q.jsx)(g,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(x,{size:12}),disabled:w||t.length===0,onClick:fe,"aria-label":E===null?`Test all accounts`:`Testing accounts, ${E.done} of ${E.total} tested`,title:`Test every account, regardless of selection or filters`,children:E===null?`Test all`:`Tested ${E.done}/${E.total}`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ae,{size:12}),disabled:w||I,title:I?`Select at least one account to recover it`:`Clear cooldowns and retry-wait states on the selected accounts`,onClick:()=>void de(),children:`Recover`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(ut,{size:12}),disabled:w||!P,title:I?`Select at least one disabled account to enable it`:P?`Enable the selected accounts`:`No selected account is currently disabled`,onClick:()=>void pe(!0),children:`Enable`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(re,{size:12}),disabled:w||!F,title:I?`Select at least one enabled account to disable it`:F?`Disable the selected accounts`:`No selected account is currently enabled`,onClick:()=>void pe(!1),children:`Disable`}),(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(m,{size:12}),disabled:w||I,title:I?`Select at least one account to export`:`Download the selected accounts as JSON`,onClick:()=>void he(),children:`Export`}),(0,Q.jsx)(g,{size:`sm`,variant:`danger`,icon:(0,Q.jsx)(se,{size:12}),disabled:w||I,title:I?`Select at least one account to delete`:`Delete ${M.length} selected account${M.length===1?``:`s`}`,onClick:()=>ee(!0),children:`Delete`}),r?(0,Q.jsx)(g,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(x,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null,(0,Q.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,Q.jsx)(J,{size:`sm`,value:S,onValueChange:e=>C(e),options:In,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:N,onChange:ce,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),I?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(new Set),className:`inline-flex h-15 shrink-0 items-center gap-1 rounded-control border border-inner-border px-3 text-badge font-semibold text-text-secondary hover:bg-hover`,title:`Clear selection`,children:[M.length,` selected`,(0,Q.jsx)(ne,{size:11,"aria-hidden":`true`})]})]})]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:te.length===0?(0,Q.jsx)(j,{compact:!0,icon:(0,Q.jsx)(oe,{size:20}),title:`No matching accounts`,message:k?`Nothing matches “${k}”. Clear the filter to see all ${t.length} account${t.length===1?``:`s`}.`:`This provider has no accounts yet.`}):te.map(t=>(0,Q.jsx)(Fn,{providerId:e,account:t,inflight:d.get(t.id)??t.inflight,quota:p.get(t.id),selected:v.has(t.id),onToggleSelect:ie,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,A.length,` account`,A.length===1?``:`s`,k?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(ze,{open:O,onClose:()=>{w||ee(!1)},onConfirm:async()=>{await le(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await me(t,{method:`DELETE`}),o.removeQueries({queryKey:L.quota.account(e.id),exact:!0})}),b(new Set),ee(!1),await Promise.all([o.invalidateQueries({queryKey:L.providers.accounts(e)}),o.invalidateQueries({queryKey:L.providers.all}),o.invalidateQueries({queryKey:L.quota.all})])},title:`Delete ${M.length} account${M.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var zn=2097152,Bn=zn/1048576;function Vn({providerId:e,accounts:t,onClose:n}){let r=be(),i=Me(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(`auto`),[p,m]=(0,Z.useState)(void 0),h=Sn(s),v=h.length>1,b=h.length===1?h[0]:void 0,x=d===`auto`?b?.kind:d,S=b&&x===`jwt`?fn(b.value):void 0,C=h.length>0?gn(e,s):void 0,w=C!==void 0&&p!==s,T=t.map(e=>e.label),E=v?wn(h,e,T):[],D=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}},O=r.isPending||l,ee=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=Sn(e);if(t.length>1)y.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;y.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{y.error(`Clipboard access denied`)}},k=e=>{if(e.size>zn){y.error(`File too large`,`Credential files must be ${Bn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=Sn(n);if(r.length===0){y.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}y.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>y.error(`Could not read that file`),t.readAsText(e)},A=async()=>{if(h.length!==0&&!w){if(h.length===1){let t=h[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...D(t)}},{onSuccess:()=>{y.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>y.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=Tn(h.map((e,t)=>({label:E[t],...D(e)}))),r=0,a=[],o=!1;for(let[n,s]of t.entries())try{let t=await i.mutateAsync({providerId:e,accounts:s});r+=t.created;let o=n*50;for(let e of t.results)e.ok||a.push(`${E[o+e.index]??o+e.index}: ${e.error??`rejected`}`)}catch(e){o=!0,a.push(`chunk ${n+1}/${t.length}: ${pe(e,`request failed`)}`);break}let s=a.length;r>0&&y.success(`${r} account${r===1?``:`s`} added`,o?`stopped partway; ${s} failed`:s>0?`${s} skipped`:void 0),s>0&&y.error(`${s} account${s===1?``:`s`} skipped`,a.slice(0,5).join(`
|
|
2
2
|
`)+(s>5?`\n…and ${s-5} more`:``)),r>0&&n()}finally{u(!1)}}};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:O,children:`Cancel`}),(0,Q.jsx)(g,{size:`sm`,variant:`primary`,disabled:O||h.length===0,onClick:()=>void A(),children:O?`Connecting...`:w?`Confirm below`:v?`Add ${h.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!v&&(0,Q.jsx)(q,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:b?.identity??`${e} account`}),(0,Q.jsx)(J,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,Q.jsxs)(Y,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),v?(0,Q.jsxs)(K,{tone:`accent`,children:[`Detected: `,h.length,` accounts`]}):b?(0,Q.jsxs)(K,{tone:x===`oauth`||x===`jwt`?`accent`:`default`,children:[`Detected:`,` `,x===`oauth`?`OAuth`:x===`jwt`?`Static JWT`:`API key`,b.identity?` · ${b.identity}`:``]}):null,b&&x===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,S?` · expires ${new Date(S).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsxs)(X,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void ee(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:_({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.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&&k(t)}}),`Import file`]})]})]}),v&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:h.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,Q.jsx)(`span`,{className:`truncate min-w-0`,children:E[t]}),(0,Q.jsx)(K,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))}),C&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-control border border-warning-line bg-surface-2 px-4 py-5`,role:`alert`,children:[(0,Q.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,Q.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`Cross-channel credential`})}),(0,Q.jsxs)(`p`,{className:`text-caption text-text-primary`,children:[`This looks like a `,C.provider,` credential.`,` `,C.provider,` and `,C.counterpart,` tokens are interchangeable — one works in the other — but using a token on a channel it was not issued for can raise the risk of the account being banned, because it appears active somewhere it never authenticated. The same applies in reverse.`]}),w?(0,Q.jsxs)(X,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>{c(``),n()},children:`Cancel`}),(0,Q.jsx)(g,{size:`sm`,variant:`primary`,onClick:()=>m(s),children:`Add anyway`})]}):(0,Q.jsx)(`p`,{className:`text-micro text-text-tertiary`,children:`Acknowledged — you can add this account now.`})]})]})})}function Hn(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 Un({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=Pe(),u=st(),d=ue(),m=je(e),h=(0,Z.useRef)(null),_=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let t=setInterval(()=>{d.invalidateQueries({queryKey:L.providers.accounts(e)})},1500);return()=>clearInterval(t)},[d,e]),(0,Z.useEffect)(()=>{let e=m.data?.map(e=>e.id)??null;if(e!==null){if(h.current===null){h.current=new Set(e);return}_.current||e.find(e=>!h.current.has(e))!==void 0&&(_.current=!0,r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[m.data,r,i]);let v=()=>{r.close(),i(!1)},[b,x]=(0,Z.useState)(!1),C=()=>{x(!0),d.invalidateQueries({queryKey:L.providers.accounts(e)}).finally(()=>x(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){y.error(`Clipboard is empty`);return}c(e),y.success(`Pasted redirect URL`)}catch{y.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(P,{open:!0,onClose:v,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:v,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:C,disabled:l.isPending||b,title:`You already approved in the popup — check now instead of waiting`,children:b?`Checking…`:`Complete`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=Hn(s);if(`error`in t){y.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>y.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,Q.jsxs)(Y,{gap:`14px`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,Q.jsxs)(X,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(p,{size:12}):(0,Q.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),u(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,Q.jsx)(`span`,{children:`Or complete manually`}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,Q.jsxs)(X,{gap:`8px`,align:`flex-start`,children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function Wn(e){try{return new URL(e).host}catch{return e}}function Gn({providerId:e,parameters:t,onClose:n}){let r=R(),i=z(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1),d=st();(0,Z.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(y.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let m=(0,Z.useRef)(null),[h,_]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?m.current=e:_(!0),()=>{let e=m.current;m.current=null,e&&!e.closed&&e.close()}},[a]),(0,Z.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),y.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=m.current;e&&!e.closed&&e.close(),y.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),y.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,Q.jsx)(P,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,Q.jsx)(Y,{gap:`14px`,children:a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,Q.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(p,{size:12}):(0,Q.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),u(!0),d(()=>u(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,Q.jsxs)(X,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:Wn(a.verificationUri)}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(Ce,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(p,{size:12}):(0,Q.jsx)(f,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),d(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:h?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(S,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function Kn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function qn(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Jn({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,Q.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,Q.jsx)(J,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,Q.jsx)(q,{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 Yn({providerId:e,providerName:t,fields:n,onClose:r}){let i=Ie(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>Kn(n)),d=(0,Z.useMemo)(()=>qn(n,l),[n,l]);return(0,Q.jsx)(P,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){y.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){y.error(`Missing required fields`,`Fill in: ${d.join(`, `)}`);return}i.mutate({providerId:e,credential:a.trim(),...Object.keys(l).length>0?{fields:l}:{},...s.trim().length>0?{accountLabel:s.trim()}:{}},{onSuccess:()=>{y.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>y.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(S,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,Q.jsxs)(Y,{gap:`12px`,children:[(0,Q.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,Q.jsx)(Jn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(q,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(q,{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 Xn(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 Zn(e,t,n){let{title:r,detail:i}=Xn(e,t,n);return[r,i]}function Qn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function $n(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var er=[{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`}],tr={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function nr(){return gt.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function rr({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,Q.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0`,children:(0,Q.jsx)(J,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:nr()})})}function ir({providerId:e,provider:t,onClose:n}){let r=Ne(),i=xe(),[a,o]=(0,Z.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Z.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Z.useState)(c??`chat`),[f,p]=(0,Z.useState)(`auto`),[m,h]=(0,Z.useState)(`idle`),[_,v]=(0,Z.useState)(``),[b,C]=(0,Z.useState)(cr),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(h(`testing`),v(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:u,reasoningEffort:f,serviceKind:`llm`}},{onSuccess:e=>{e.ok?h(`passed`):(h(`failed`),v(e.error??`Model probe failed`))},onError:e=>{h(`failed`),v(e.message??`Model probe failed`)}}))};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=G(b.contextLimit),r=G(b.outputLimit);if(t===null||r===null){y.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:b.passthrough,image:b.passthrough?!0:b.image,reasoning:b.passthrough?!0:b.reasoning,toolCall:b.passthrough?!0:b.toolCall}},{onSuccess:()=>{y.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>y.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,Q.jsxs)(Y,{gap:`10px`,children:[(0,Q.jsxs)(X,{gap:`8px`,align:`flex-end`,children:[(0,Q.jsx)(q,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),h(`idle`),v(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:m===`testing`?(0,Q.jsx)(S,{size:13,className:`animate-spin`}):(0,Q.jsx)(x,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:m===`testing`?`Testing...`:`Test`})]}),E&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,Q.jsx)(J,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),h(`idle`),v(``)},options:l.map(e=>({value:e,label:mr(e)}))}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,Q.jsx)(rr,{id:`add-model-thinking-effort`,value:f,onChange:e=>{p(e),h(`idle`),v(``)},disabled:r.isPending}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,Q.jsx)(lr,{draft:b,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:mr(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),m===`passed`&&(0,Q.jsx)(et,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),m===`failed`&&(0,Q.jsx)(et,{tone:`danger`,live:`alert`,children:_||`Model test failed.`})]})})}function ar(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var or=String(We),sr=String(Ve);function cr(){return{...ar(),contextLimit:or,outputLimit:sr}}function lr({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,Q.jsxs)(Y,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,Q.jsxs)(X,{gap:`8px`,children:[(0,Q.jsx)(q,{label:`Context`,id:`${n}-context`,placeholder:or,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(q,{label:`Output`,id:`${n}-output`,placeholder:sr,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===or&&e.outputLimit===sr,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:or,outputLimit:sr}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,He(We),` ctx ·`,` `,He(Ve),` out`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,Q.jsx)(Y,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function ur({providerId:e,model:t,onClose:n}){let r=ge(),[i,a]=(0,Z.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=G(i.contextLimit),o=G(i.outputLimit);if(a===null||o===null){y.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}r.mutate({providerId:e,modelId:t.modelId,route:t.route??``,metadata:{contextLimit:a??null,outputLimit:o??null,passthrough:i.passthrough,image:i.passthrough?!0:i.image,reasoning:i.passthrough?!0:i.reasoning,toolCall:i.passthrough?!0:i.toolCall}},{onSuccess:()=>n(),onError:e=>y.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,Q.jsxs)(Y,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,Q.jsx)(lr,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function dr({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let u=Ne(),m=V(),[_,v]=(0,Z.useState)(!1),[E,O]=(0,Z.useState)(null),ee=st(),k=n===`llm`?_t(t.modelId,i===`auto`?null:i):t.modelId,A=`${e}/${k}`,j=n===`websearch`?`Searching…`:`Thinking…`,te=()=>{u.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}=Xn(e,k,t.error);y.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;y.successRich(`${k} · END ${h(t.latencyMs)}`,(0,Q.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,Q.jsxs)(X,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,Q.jsx)(T,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,Q.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
3
3
|
`)||`No sample text in the response.`)},onError:t=>{O({ok:!1,latencyMs:0}),y.error(...Zn(e,k,t.message))}})},M=()=>{let n=!t.enabled;m.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>y.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>y.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,Q.jsx)(o,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,Q.jsx)(`div`,{title:A,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:k}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...pr(t.wireFamily)},children:mr(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:Qn(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:$n(t.source)}):null,t.proOnly===!0?(0,Q.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,Q.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,Q.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,Q.jsx)(g,{variant:`ghost`,size:`sm`,icon:_?(0,Q.jsx)(p,{size:12}):(0,Q.jsx)(f,{size:12}),"aria-label":`Copy ${A}`,title:`Copy ${A}`,onClick:()=>{navigator.clipboard?.writeText(A),v(!0),ee(()=>v(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,Q.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,Q.jsx)(s,{size:12})}):null,t.vision?(0,Q.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,Q.jsx)(D,{size:12})}):null,t.toolCall?(0,Q.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,Q.jsx)(ce,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(d,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:Ue,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,Q.jsx)(C,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${He(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Ge,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${He(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Ge,className:`cursor-help`,children:` · n/a out`})]}),c?(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,Q.jsx)(F,{size:11})}):null]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,disabled:u.isPending,onClick:te,"aria-label":`Test ${k}`,title:u.isPending?`Probing ${k}…`:E?.ok?`Last probe OK in ${h(E.latencyMs)} — click to re-test`:E?`Last probe failed — click to retry`:`Test ${k}`,className:`flex-1 justify-center`,icon:u.isPending?(0,Q.jsx)(S,{size:12,className:`animate-spin`}):E?E.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(w,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(b,{size:12})}):(0,Q.jsx)(x,{size:12}),children:u.isPending?j:E?.ok?h(E.latencyMs):E?`Fail`:`Test`}),(0,Q.jsx)(g,{variant:`ghost`,size:`sm`,disabled:m.isPending,onClick:M,icon:t.enabled?(0,Q.jsx)(re,{size:12}):(0,Q.jsx)(ut,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,Q.jsx)(g,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(se,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var fr=(0,Z.memo)(dr);function pr(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 mr(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function hr({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=Se(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),u=e=>e.enabled!==!1,d=er.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,Q.jsx)(fr,{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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Y,{gap:`16px`,children:[d.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,Q.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:tr.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,Q.jsxs)(`span`,{title:tr.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,tr.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,Q.jsx)(ze,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),y.success(`Model deleted`,`${e}/${o.modelId}`),s(null))},title:`Delete model?`,message:`Delete ${e}/${o?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),c===null?null:(0,Q.jsx)(ur,{providerId:e,model:c,onClose:()=>l(null)})]})}function gr(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function _r(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function vr(){let{providerId:e}=we(),[t]=Fe(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=De(n),s=Ee(n),c=je(n),u=Le(),f=Le({silent:!0}),[p,h]=(0,Z.useState)(!1),_=Te(),v=_e(),b=ye(),x=ue(),[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),E=Ne(),[D,O]=(0,Z.useState)(``),[M,ne]=(0,Z.useState)(``),[N,F]=(0,Z.useState)(null),ae=e=>`cartethyia:provider:${e}:thinking-effort`,oe=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(ae(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return gt.includes(n)?n:`auto`},[ce,le]=(0,Z.useState)(()=>oe(n));(0,Z.useEffect)(()=>{if(!n)return;let e=oe(n);e!==ce&&le(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(ae(n),ce)},[n,ce]);let[de,fe]=(0,Z.useState)(!1),[pe,he]=(0,Z.useState)(!1),[R,ge]=(0,Z.useState)(null),[ve,be]=(0,Z.useState)({}),[xe,Se]=(0,Z.useState)({}),[z,Oe]=(0,Z.useState)(null),[ke,Ae]=(0,Z.useState)(!1),[Me,Pe]=(0,Z.useState)(null),B=(0,Z.useRef)(null),Ie=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=B.current;B.current=null,e&&!e.closed&&e.close()},[]);let V=o.data,Re=n===`opencode`||n===`cline`,Be=V===void 0?[`llm`]:_r(V),G=[];for(let e of Be)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&G.push(e);(0,Z.useEffect)(()=>{if(V===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=G[0];if(e!==void 0&&G.includes(e)){i!==e&&a(e);return}!G.includes(i)&&t!==void 0&&a(t)},[V,r,i,G.join(`|`)]),(0,Z.useEffect)(()=>{Re&&V!==void 0&&V.supportsModelDiscovery!==!1&&Ie.current!==n&&(Ie.current=n,f.mutate(n))},[Re,f,n,V?.supportsModelDiscovery]);let Ve=c.data??[],He=s.data??[],Ue=(()=>{let e=new Map;for(let t of He){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))})(),We=Ue.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),Ge=Ue.filter(e=>e.serviceKind===`websearch`),K=Ue.filter(e=>e.serviceKind===`imageGeneration`),q=Ue.filter(e=>e.serviceKind===`videoGeneration`),J=G.includes(i)?i:G[0],qe=M||Ge[0]?.modelId||``,Ye=()=>{let e=D.trim();qe&&e&&(F(null),E.mutate({providerId:n,request:{modelId:qe,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>F({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>F({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,Q.jsx)(A,{label:`Loading provider...`});if(o.isError)return(0,Q.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,Q.jsx)(vt,{to:`/providers`,label:`Back to providers`})});if(!V)return(0,Q.jsx)(j,{icon:(0,Q.jsx)(dt,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,Q.jsx)(vt,{to:`/providers`,label:`Back to providers`})});let Xe=Ve.filter(e=>e.status===`active`).length,Ze=e=>{let t=e===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?$e():fe(!0);return}be(Kn(t)),ge(e)},Qe=()=>{if(R===null)return;let e=qn(R===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[],ve);if(e.length>0){y.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=R;ge(null),t===`browser`?$e(ve):(Se(ve),fe(!0))},$e=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,B.current=t),b.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:n})=>{let r=null;if(t&&!t.closed?(t.location.href=e,r=t):(r=window.open(e,`cartethyia-oauth`,`popup,width=720,height=820`),r&&(r.opener=null,B.current=r)),!r){y.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Pe({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),B.current===t&&(B.current=null),y.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(Y,{gap:`16px`,children:[(0,Q.jsx)(yt,{title:`${V.label||V.displayName}${J?` (${gr(J)})`:``}`,description:`${V.providerId}/${V.baseUrl?` · ${V.baseUrl}`:``}`,icon:(0,Q.jsx)(Ke,{icon:V.providerId,name:V.label||V.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,Q.jsx)(X,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:V.isBuiltIn?(0,Q.jsx)(g,{variant:V.enabled?`danger`:`secondary`,icon:V.enabled?(0,Q.jsx)(re,{size:13}):(0,Q.jsx)(ut,{size:13}),loading:v.isPending,onClick:()=>v.mutate({providerId:n,enabled:!V.enabled},{onSuccess:e=>y.success(e.enabled?`Provider enabled`:`Provider disabled`,V.label||V.displayName),onError:e=>y.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:V.enabled?`Disable provider globally`:`Enable provider globally`,children:V.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(Jt,{provider:V}),V.isBuiltIn?null:(0,Q.jsx)(Yt,{provider:V}),J===`llm`?(0,Q.jsx)(kt,{providerId:n,clientVersion:V.clientVersion,routeIdentityVersions:V.routeIdentityVersions,userAgentEditable:bt(V)}):null,(0,Q.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:V.requiresAccount===!1?(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Accounts`,icon:(0,Q.jsx)(ct,{size:16})}),(0,Q.jsx)(H,{children:(0,Q.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Accounts`,subtitle:`${Ve.length} total · ${Xe} active · ${Ve.length-Xe} disabled`,icon:(0,Q.jsx)(ct,{size:16}),action:(0,Q.jsxs)(Je,{children:[V.oauthFlows?.browser&&(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(Ce,{size:13}),disabled:b.isPending,onClick:()=>Ze(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:b.isPending?`Starting...`:`Login with browser`}),V.oauthFlows?.device&&(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(te,{size:13}),onClick:()=>Ze(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),V.oauthFlows?.import&&(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(m,{size:13}),onClick:()=>he(!0),title:V.oauthFlows.browser||V.oauthFlows.device||V.oauthFlows.refreshable?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:V.oauthFlows.browser||V.oauthFlows.device||V.oauthFlows.refreshable?`Import credential`:`Add API key`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(I,{size:13}),onClick:()=>C(!0),children:`Add Account`})]})}),(0,Q.jsxs)(H,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(Wt,{providerId:n}),c.isPending?(0,Q.jsx)(A,{label:`Loading accounts...`}):c.isError?(0,Q.jsx)(k,{message:`Failed to load accounts`,onRetry:()=>c.refetch()}):Ve.length===0?(0,Q.jsx)(j,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,Q.jsx)(Rn,{providerId:n,accounts:Ve,onDelete:e=>Oe(e),showGrokProbe:J===`llm`&&n===`grok`,grokProbePending:_.isPending,onGrokProbe:()=>{_.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`reply my message with exact number 407`,stream:!0,serviceKind:`llm`}},{onSuccess:e=>{let t=e.results.filter(e=>e.ok).length,n=e.results.filter(e=>e.statusCode===202).length,r=e.results.length-t-n;y.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>y.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),J===`llm`?(0,Q.jsxs)(Q.Fragment,{children:[n===`inferhub`?(0,Q.jsx)(Vt,{}):null,(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Models`,subtitle:`${We.length} model${We.length===1?``:`s`} registered`,icon:(0,Q.jsx)(l,{size:16}),action:(0,Q.jsxs)(X,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,Q.jsx)(rr,{id:`models-section-thinking-effort`,value:ce,onChange:le}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(ie,{size:13,className:u.isPending||f.isPending?`animate-spin`:``}),disabled:u.isPending||f.isPending,onClick:()=>u.mutate(n),children:u.isPending||f.isPending?`Fetching...`:`Fetch models`}),(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(se,{size:13,className:p?`animate-spin`:``}),disabled:u.isPending||f.isPending||p||We.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=We.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){h(!0);try{let t=await me(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([x.invalidateQueries({queryKey:L.providers.models(n)}),x.invalidateQueries({queryKey:L.providers.all})]);let r=t.failures.length;y.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){y.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{h(!1)}}},children:p?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(I,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,Q.jsx)(H,{className:`flex flex-col gap-8`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load models`,onRetry:()=>s.refetch()}):We.length===0?(0,Q.jsx)(j,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,Q.jsx)(hr,{providerId:n,models:We,serviceKind:`llm`,thinkingEffort:ce,searchCapable:V?.supportsWebSearch===!0})})]})]}):J===`websearch`?(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(d,{size:16})}),(0,Q.jsx)(H,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading search models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):Ge.length===0?(0,Q.jsx)(j,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,Q.jsx)(`select`,{value:qe,onChange:e=>{ne(e.target.value),F(null)},className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`,children:Ge.map(e=>(0,Q.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,Q.jsx)(`input`,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ye())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,Q.jsxs)(X,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,Q.jsx)(g,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:Ye,children:`Test search`}),N?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:N.ok?`var(--green)`:`var(--red)`},children:N.ok?`Search ok · ${N.latencyMs}ms · ${N.count??0} result(s)`:N.error??`Search failed.`}):null]}),N&&N.results&&N.results.length>0?(0,Q.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:N.results.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,Q.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,Q.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):J===`imageGeneration`||J===`videoGeneration`?(0,Q.jsxs)(W,{children:[(0,Q.jsx)(U,{title:gr(J),subtitle:J===`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:J===`imageGeneration`?(0,Q.jsx)(ee,{size:16}):(0,Q.jsx)(mt,{size:16})}),(0,Q.jsx)(H,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading ${gr(J).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load ${gr(J).toLowerCase()} models`,onRetry:()=>s.refetch()}):(J===`imageGeneration`?K:q).length===0?(0,Q.jsx)(j,{title:`No ${gr(J)} models found`,message:`This provider advertises ${gr(J)}, but no ${J} model is registered yet.`}):(0,Q.jsx)(hr,{providerId:n,models:J===`imageGeneration`?K:q,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,Q.jsx)(W,{children:(0,Q.jsx)(H,{children:(0,Q.jsx)(j,{title:`Service not available`,message:`This provider advertises ${Be.map(gr).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),S&&(0,Q.jsx)(Vn,{providerId:n,accounts:Ve,onClose:()=>C(!1)}),J===`llm`&&w?(0,Q.jsx)(ir,{providerId:n,provider:V,onClose:()=>T(!1)}):null,(0,Q.jsx)(ze,{open:z!==null,onClose:()=>{ke||Oe(null)},onConfirm:async()=>{if(z){Ae(!0);try{let e=z.tenantId===null?`/global/accounts/${encodeURIComponent(z.id)}`:`/accounts/${encodeURIComponent(z.id)}`;await me(e,{method:`DELETE`}),x.removeQueries({queryKey:L.quota.account(z.id),exact:!0}),await Promise.all([x.invalidateQueries({queryKey:L.providers.accounts(n)}),x.invalidateQueries({queryKey:L.providers.healthEvents(n,z.id)}),x.invalidateQueries({queryKey:L.providers.all}),x.invalidateQueries({queryKey:L.quota.all})]),y.success(`Account deleted`,z.label||z.id.slice(0,8)),Oe(null)}catch(e){throw y.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Ae(!1)}}},title:`Delete account?`,message:`Delete "${z?.label||z?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),de&&(0,Q.jsx)(Gn,{providerId:n,parameters:xe,onClose:()=>{fe(!1),Se({})}}),R!==null&&(0,Q.jsx)(P,{open:!0,onClose:()=>ge(null),title:R===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>ge(null),children:`Cancel`}),(0,Q.jsx)(g,{variant:`primary`,size:`sm`,onClick:Qe,children:`Continue`})]}),children:(0,Q.jsxs)(Y,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:R===`browser`?`Choose how ${V.label||V.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(Jn,{fields:R===`browser`?V?.oauthFlows?.browserLoginFields??[]:V?.oauthFlows?.deviceLoginFields??[],values:ve,idPrefix:`flow-${R}`,onChange:(e,t)=>be(n=>({...n,[e]:t}))})]})}),pe&&V?.oauthFlows?.import===!0&&(0,Q.jsx)(Yn,{providerId:n,providerName:V.label||V.displayName,fields:V.oauthFlows.importFields,onClose:()=>he(!1)}),Me&&(0,Q.jsx)(Un,{providerId:n,authorizeUrl:Me.authorizeUrl,state:Me.state,popup:Me.popup,onClose:e=>{B.current=null,Pe(null),e&&x.invalidateQueries({queryKey:L.providers.accounts(n)})}})]})}export{vr as default};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r,m as i}from"./numbers-Dulqgys5.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-DhZBfWgx.js";import{t as u}from"./dialog-Iec_ywbD.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-UETqfytp.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{Q as h,T as g,_,a as v,g as y,i as ee,it as b,lt as x,m as S,s as C,tt as w,w as te}from"./entry-BcfdW4C_.js";import{n as T,r as E,t as D}from"./card-BOPBuBzD.js";import{t as O}from"./badge-Bkz_-RrM.js";import{n as k}from"./input-WlyHWeG2.js";import{t as A}from"./select-BTEzH1iH.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-yD7D99Lg.js";import{t as N}from"./stack-B1w5BM0u.js";import{n as P}from"./inline-DToMICwl.js";import{t as ne}from"./list-row-B3oSK13z.js";import{t as F}from"./privacy-mode-GM8bej85.js";import{t as I}from"./AccountCooldown-Bjo92Qat.js";var L=e(t(),1),R=n();function re(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function ie({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),i=n=>t(e.filter((e,t)=>t!==n));return(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label block`,children:[(0,R.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,R.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,R.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,R.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(r,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>i(a),children:(0,R.jsx)(f,{size:13})})]},a)),(0,R.jsxs)(r,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,R.jsx)(d,{size:13}),` Add header`]})]})]})}function z({children:e}){return(0,R.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var B=i(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),V=i(`block flex-1 p-6 no-underline text-inherit`),H=i(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function U(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var W=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ae(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return W.test(r)?n.origin:null}function G({variant:e,open:t,onClose:n}){let a=ee(),o=v(),s=te(),c=g(),[l,d]=(0,L.useState)(``),[f,m]=(0,L.useState)(``),[h,_]=(0,L.useState)(``),[y,b]=(0,L.useState)(``),[x,S]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!0),[T,E]=(0,L.useState)([]),[D,O]=(0,L.useState)(null),[j,N]=(0,L.useState)(!1),[F,I]=(0,L.useState)(null),[z,B]=(0,L.useState)(!1),V=e===`anthropic-compatible`,H=V?`messages`:`chat`,[U,W]=(0,L.useState)(H),G=(0,L.useMemo)(()=>ae(h),[h]);(0,L.useEffect)(()=>{t&&(d(``),b(``),W(H),_(``),S(!1),w(!0),E([]),O(null),I(null))},[t]);let K=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},q=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}B(!0),I(null),O(null);try{let e=re(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:U,cliIdentity:C,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:p(e,`Connection test failed`)})}finally{B(!1)}};return(0,R.jsx)(u,{open:t,onClose:n,title:V?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(r,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,R.jsx)(r,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,R.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=re(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:U,compatibilityProfile:{cli_identity:C,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:y.trim()}}),x&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,R.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,R.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:V?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,R.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:V?`ac-prod`:`oc-prod`,required:!0}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,R.jsx)(`span`,{children:`Base URL`}),(0,R.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,V?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-url`,value:h,onChange:e=>_(e.target.value),placeholder:V?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(_),children:`Paste`})]}),G===null?null:(0,R.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:G}),` instead — Cartethyia appends the endpoint path itself.`]})]}),V?null:(0,R.jsx)(A,{id:`compat-wire`,label:`API format`,value:U,onValueChange:e=>W(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,R.jsx)(`span`,{children:`API Key`}),(0,R.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>b(e.target.value)})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,disabled:z,onClick:()=>void q(),children:z?`Testing...`:`Test connection`}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(b),children:`Paste`})]}),F?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:i(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,R.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:x,onChange:S,id:`compat-autofetch`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:C,onChange:w,id:`compat-cli-identity`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:V?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:V?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,R.jsx)(ie,{pairs:T,onChange:E})]})})}function K({customProvider:e}){let t=C(),[n,a]=(0,L.useState)(!1),o=y(e.providerId),s=o.data?.length,c=S(e.providerId),l=c.data,d=Q(l??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:i(V,`pr-20 min-h-38`),children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:e.label||e.providerId}),e.baseUrl?(0,R.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,R.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,R.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,R.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,R.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,R.jsxs)(N,{gap:`12px`,children:[(0,R.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,R.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,R.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,R.jsxs)(m,{children:[(0,R.jsx)(r,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,R.jsx)(r,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function q({customProviders:e}){let[t,n]=(0,L.useState)(!1),[i,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,R.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,R.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,R.jsx)(x,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(r,{size:`sm`,variant:`ghost`,icon:c?(0,R.jsx)(o,{size:13}):(0,R.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,R.jsx)(D,{children:(0,R.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,R.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,R.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,R.jsx)(z,{children:e.map(e=>(0,R.jsx)(K,{customProvider:e},e.providerId))}),(0,R.jsx)(G,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,R.jsx)(G,{variant:`openai-compatible`,open:i,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||I(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&I(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,R.jsxs)(R.Fragment,{children:[e.healthy>0?(0,R.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,R.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,R.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,R.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,R.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,L.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),r=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=S(e.providerId),c=s.data,l=Q(c??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,R.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,R.jsx)(`span`,{className:i(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:V,children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:r}),(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,R.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,R.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=`text-body font-bold tracking-[-0.01em]`,me=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function he(){let[e,t]=(0,L.useState)(fe),n=_(),u=F(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,L.useMemo)(()=>n.data??[],[n.data]),h=(0,L.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),g=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`websearch`)&&f(e)),[m,d]),v=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`llm`)&&f(e)),[m,d]),[y,ee]=w(),S=y.get(`tab`),C=S===`search`||S===`media`?S:`llm`,te=e=>{ee(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,L.useMemo)(()=>m.filter(e=>(U(e).includes(`imageGeneration`)||U(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,L.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,L.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=v;return me.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[v,k,O,C]),M=n.isPending&&!n.data?(0,R.jsx)(c,{label:`Loading providers...`}):n.isError?(0,R.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,R.jsx)(N,{gap:`24px`,children:(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,R.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,R.jsxs)(`button`,{onClick:()=>te(e),className:i(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${g.length})`:e===`media`?` (${O.length})`:` (${v.length})`]},e))}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:d?(0,R.jsx)(a,{size:12}):(0,R.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,R.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,R.jsx)(q,{customProviders:h}):null,j.length===0?(0,R.jsx)(D,{children:(0,R.jsx)(T,{children:(0,R.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,R.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,R.jsx)(x,{size:15,className:i(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,R.jsxs)(N,{gap:`1px`,children:[(0,R.jsxs)(`h2`,{className:pe,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,R.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,R.jsx)(z,{children:n.providers.map(e=>(0,R.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?U(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{he as default,Q as summarizeAccounts};
|
|
1
|
+
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r,m as i}from"./numbers-Dulqgys5.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-DhZBfWgx.js";import{t as u}from"./dialog-Iec_ywbD.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-UETqfytp.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{Q as h,T as g,_,a as v,g as y,i as ee,it as b,lt as x,m as S,s as C,tt as w,w as te}from"./entry-BrksMru8.js";import{n as T,r as E,t as D}from"./card-BOPBuBzD.js";import{t as O}from"./badge-Bkz_-RrM.js";import{n as k}from"./input-WlyHWeG2.js";import{t as A}from"./select-Ciq_KFQ1.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-yD7D99Lg.js";import{t as N}from"./stack-B1w5BM0u.js";import{n as P}from"./inline-DToMICwl.js";import{t as ne}from"./list-row-B3oSK13z.js";import{t as F}from"./privacy-mode-GM8bej85.js";import{t as I}from"./AccountCooldown-Bjo92Qat.js";var L=e(t(),1),R=n();function re(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function ie({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),i=n=>t(e.filter((e,t)=>t!==n));return(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label block`,children:[(0,R.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,R.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,R.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,R.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,R.jsx)(r,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>i(a),children:(0,R.jsx)(f,{size:13})})]},a)),(0,R.jsxs)(r,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,R.jsx)(d,{size:13}),` Add header`]})]})]})}function z({children:e}){return(0,R.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var B=i(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),V=i(`block flex-1 p-6 no-underline text-inherit`),H=i(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function U(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var W=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ae(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return W.test(r)?n.origin:null}function G({variant:e,open:t,onClose:n}){let a=ee(),o=v(),s=te(),c=g(),[l,d]=(0,L.useState)(``),[f,m]=(0,L.useState)(``),[h,_]=(0,L.useState)(``),[y,b]=(0,L.useState)(``),[x,S]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!0),[T,E]=(0,L.useState)([]),[D,O]=(0,L.useState)(null),[j,N]=(0,L.useState)(!1),[F,I]=(0,L.useState)(null),[z,B]=(0,L.useState)(!1),V=e===`anthropic-compatible`,H=V?`messages`:`chat`,[U,W]=(0,L.useState)(H),G=(0,L.useMemo)(()=>ae(h),[h]);(0,L.useEffect)(()=>{t&&(d(``),b(``),W(H),_(``),S(!1),w(!0),E([]),O(null),I(null))},[t]);let K=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},q=async()=>{if(!h.trim()){I({ok:!1,message:`Base URL is required to test the connection.`});return}B(!0),I(null),O(null);try{let e=re(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:y.trim(),wireFamily:U,cliIdentity:C,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;I({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else I({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){I({ok:!1,message:p(e,`Connection test failed`)})}finally{B(!1)}};return(0,R.jsx)(u,{open:t,onClose:n,title:V?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(r,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,R.jsx)(r,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,R.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=re(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:U,compatibilityProfile:{cli_identity:C,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),y.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:y.trim()}}),x&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,R.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,R.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:V?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,R.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:V?`ac-prod`:`oc-prod`,required:!0}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,R.jsx)(`span`,{children:`Base URL`}),(0,R.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,V?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-url`,value:h,onChange:e=>_(e.target.value),placeholder:V?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(_),children:`Paste`})]}),G===null?null:(0,R.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,R.jsx)(`code`,{className:`font-mono`,children:G}),` instead — Cartethyia appends the endpoint path itself.`]})]}),V?null:(0,R.jsx)(A,{id:`compat-wire`,label:`API format`,value:U,onValueChange:e=>W(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,R.jsxs)(`div`,{className:`form-group`,children:[(0,R.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,R.jsx)(`span`,{children:`API Key`}),(0,R.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,R.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:y,onChange:e=>b(e.target.value)})}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,disabled:z,onClick:()=>void q(),children:z?`Testing...`:`Test connection`}),(0,R.jsx)(r,{type:`button`,variant:`secondary`,onClick:()=>K(b),children:`Paste`})]}),F?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:i(`mt-3 text-caption leading-[1.4] break-words`,F.ok?`text-green`:`text-red`),children:[F.ok?`✓ `:`✗ `,F.message]}),F.warning?(0,R.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,F.warning]}):null]}):null]}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:x,onChange:S,id:`compat-autofetch`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,R.jsx)(ne,{actions:(0,R.jsx)(M,{checked:C,onChange:w,id:`compat-cli-identity`}),children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-body font-semibold`,children:V?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,R.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:V?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,R.jsx)(ie,{pairs:T,onChange:E})]})})}function K({customProvider:e}){let t=C(),[n,a]=(0,L.useState)(!1),o=y(e.providerId),s=o.data?.length,c=S(e.providerId),l=c.data,d=Q(l??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:i(V,`pr-20 min-h-38`),children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:e.label||e.providerId}),e.baseUrl?(0,R.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,R.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,R.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,R.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:(0,R.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,R.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,R.jsxs)(N,{gap:`12px`,children:[(0,R.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,R.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,R.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,R.jsxs)(m,{children:[(0,R.jsx)(r,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,R.jsx)(r,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function q({customProviders:e}){let[t,n]=(0,L.useState)(!1),[i,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,R.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,R.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,R.jsx)(x,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,R.jsxs)(P,{gap:`8px`,children:[(0,R.jsx)(r,{size:`sm`,variant:`ghost`,icon:c?(0,R.jsx)(o,{size:13}):(0,R.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,R.jsx)(r,{size:`sm`,variant:`secondary`,icon:(0,R.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,R.jsx)(D,{children:(0,R.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,R.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,R.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,R.jsx)(z,{children:e.map(e=>(0,R.jsx)(K,{customProvider:e},e.providerId))}),(0,R.jsx)(G,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,R.jsx)(G,{variant:`openai-compatible`,open:i,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||I(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&I(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,R.jsxs)(R.Fragment,{children:[e.healthy>0?(0,R.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,R.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,R.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,R.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,R.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,R.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,L.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),r=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=S(e.providerId),c=s.data,l=Q(c??[]);return(0,R.jsxs)(D,{className:B,children:[(0,R.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,R.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,R.jsx)(`span`,{className:i(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,R.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:V,children:(0,R.jsxs)(P,{gap:`10px`,children:[(0,R.jsx)(j,{icon:e.providerId,name:r,size:32,imageSize:24}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:H,children:r}),(0,R.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,R.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,R.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,R.jsx)(O,{children:`No connections`}):(0,R.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,R.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,R.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,R.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,R.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,R.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,R.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=`text-body font-bold tracking-[-0.01em]`,me=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function he(){let[e,t]=(0,L.useState)(fe),n=_(),u=F(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,L.useMemo)(()=>n.data??[],[n.data]),h=(0,L.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),g=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`websearch`)&&f(e)),[m,d]),v=(0,L.useMemo)(()=>m.filter(e=>U(e).includes(`llm`)&&f(e)),[m,d]),[y,ee]=w(),S=y.get(`tab`),C=S===`search`||S===`media`?S:`llm`,te=e=>{ee(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,L.useMemo)(()=>m.filter(e=>(U(e).includes(`imageGeneration`)||U(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,L.useMemo)(()=>[...g].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[g]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,L.useMemo)(()=>{if(C===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(C===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=v;return me.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[v,k,O,C]),M=n.isPending&&!n.data?(0,R.jsx)(c,{label:`Loading providers...`}):n.isError?(0,R.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,R.jsx)(N,{gap:`24px`,children:(0,R.jsxs)(D,{children:[(0,R.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,R.jsx)(b,{size:16})}),(0,R.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,R.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,R.jsxs)(`button`,{onClick:()=>te(e),className:i(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,C===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${g.length})`:e===`media`?` (${O.length})`:` (${v.length})`]},e))}),(0,R.jsx)(r,{variant:`ghost`,size:`sm`,icon:d?(0,R.jsx)(a,{size:12}):(0,R.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,R.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:C===`search`?`Fallback runs only when the model invokes Websearch`:C===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),C===`llm`?(0,R.jsx)(q,{customProviders:h}):null,j.length===0?(0,R.jsx)(D,{children:(0,R.jsx)(T,{children:(0,R.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let r=e.has(n.title);return(0,R.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!r,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,R.jsx)(x,{size:15,className:i(`mt-1 shrink-0 transition-transform`,r&&`-rotate-90`)}),(0,R.jsxs)(N,{gap:`1px`,children:[(0,R.jsxs)(`h2`,{className:pe,children:[n.title,` (`,n.providers.length,`)`,r?` (Hidden)`:``]}),!r&&n.subtitle?(0,R.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),r?null:(0,R.jsx)(z,{children:n.providers.map(e=>(0,R.jsx)(le,{provider:e,serviceKind:C===`search`?`websearch`:C===`media`?U(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{he as default,Q as summarizeAccounts};
|
|
Binary file
|