@aidotnet/server-linux-x64 0.14.3101 → 0.14.3102
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/bin/astra-server +2 -2
- package/bin/wwwroot/assets/{ClientsPage-BsCvaS4d.js → ClientsPage-CcRyNV5u.js} +1 -1
- package/bin/wwwroot/assets/{KeyPage-bkK0B_mk.js → KeyPage-DBEozu4C.js} +1 -1
- package/bin/wwwroot/assets/{ModelDetailPage-BEVSPYM6.js → ModelDetailPage-DsuE2gLp.js} +1 -1
- package/bin/wwwroot/assets/{ModelsPage-BGij6zvC.js → ModelsPage--EjkhnLC.js} +1 -1
- package/bin/wwwroot/assets/{PluginsPage-dVUvE8Lf.js → PluginsPage-B4wswSWs.js} +1 -1
- package/bin/wwwroot/assets/{PrivacyPage-B-YBfQ6J.js → PrivacyPage-DtowG3QB.js} +1 -1
- package/bin/wwwroot/assets/{ProviderDetailPage-CQQdpDSf.js → ProviderDetailPage-Cc5KTl0J.js} +3 -3
- package/bin/wwwroot/assets/{ProvidersPage-BwigLnKs.js → ProvidersPage-D4cQrTgo.js} +1 -1
- package/bin/wwwroot/assets/{SettingsPage-CvpROKS2.js → SettingsPage-Ab6k-ndX.js} +1 -1
- package/bin/wwwroot/assets/{SmartRoutingPage-CYh7mRot.js → SmartRoutingPage-Ca6ZC-sk.js} +1 -1
- package/bin/wwwroot/assets/{TokenDetailPage-GwSz8QI6.js → TokenDetailPage-tNGeSuwb.js} +1 -1
- package/bin/wwwroot/assets/{TokenPoolEditor-DfmDnnxw.js → TokenPoolEditor-BANCSW9l.js} +1 -1
- package/bin/wwwroot/assets/{TokensPage-0hOOzLVU.js → TokensPage-Ak52kWw6.js} +1 -1
- package/bin/wwwroot/assets/{TracesPage-A45sREZP.js → TracesPage-DgaPoaqm.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelPage-xke1V9tu.js → TrayPanelPage-j67xTz4h.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelView-CHh9-E76.js → TrayPanelView-Cl2xyavV.js} +1 -1
- package/bin/wwwroot/assets/{alert-CuKAE1Sv.js → alert-DpRdHImb.js} +2 -2
- package/bin/wwwroot/assets/{arrow-down-DeIGdMUk.js → arrow-down-BxJ88yaJ.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-DX1c-nYY.js → arrow-left-B3Ql-3af.js} +1 -1
- package/bin/wwwroot/assets/{arrow-up-right-D--u8dK5.js → arrow-up-right-QVW-fAFr.js} +1 -1
- package/bin/wwwroot/assets/{chart-column-zt3ZRFLH.js → chart-column-D6AP76ve.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-BJe8ekJy.js → checkbox-3cbHcFXQ.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-DWw6s5ag.js → cloud-download-d2J3TjHp.js} +1 -1
- package/bin/wwwroot/assets/{confirm-morph-DGAHV4QP.js → confirm-morph-Dpiz2iAT.js} +1 -1
- package/bin/wwwroot/assets/{download-DR9BLMVt.js → download-BF1gj38s.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-BH_FL485.js → ellipsis-2ewY1Pkj.js} +1 -1
- package/bin/wwwroot/assets/{external-link-Bb6sx3jt.js → external-link-Ba13ucfD.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-Bcx5mAII.js → folder-open-DTgeVtUv.js} +1 -1
- package/bin/wwwroot/assets/{index-CKrvKDIJ.js → index-YcD3CI_o.js} +3 -3
- package/bin/wwwroot/assets/{log-out-Ch09k2bC.js → log-out-DOtmyFi6.js} +1 -1
- package/bin/wwwroot/assets/minus-CSv_UD8H.js +1 -0
- package/bin/wwwroot/assets/{overlays-DeHu6TU_.js → overlays-Ca_JSpnI.js} +1 -1
- package/bin/wwwroot/assets/{pencil-fY6CohHT.js → pencil-CFjPUH1Y.js} +1 -1
- package/bin/wwwroot/assets/{power-B9MMcl6Y.js → power-10gcP_1M.js} +1 -1
- package/bin/wwwroot/assets/{radio-cards-Rq9vGqnw.js → radio-cards-CWs2Sjuq.js} +1 -1
- package/bin/wwwroot/assets/{rotate-ccw-DsmSscuv.js → rotate-ccw-C3uEcj_6.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-CO34h2h7.js → sortable.esm-Vg9V11Ab.js} +1 -1
- package/bin/wwwroot/index.html +3 -3
- package/package.json +1 -1
- package/bin/wwwroot/assets/minus-UfPYsFrp.js +0 -1
package/bin/wwwroot/assets/{ProviderDetailPage-CQQdpDSf.js → ProviderDetailPage-Cc5KTl0J.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{$n as e,An as t,At as n,Ba as r,Bn as i,Cn as a,Cr as o,Dt as s,Et as c,Gr as l,H as u,Hr as d,In as f,Jn as p,Kn as m,Kr as h,Lr as g,Mi as _,Ot as v,Pt as y,Q as b,Qr as ee,Qt as te,Ra as ne,Rn as re,Rt as ie,Sn as x,Ua as ae,Ur as S,V as oe,Wn as C,Xn as se,Xr as ce,Y as w,Zt as le,_ as ue,_n as de,_r as fe,a as pe,ar as me,b as T,bi as he,c as ge,cn as _e,cr as ve,ct as E,d as D,dt as O,f as k,gt as ye,h as be,hn as xe,ht as Se,i as Ce,ir as we,it as Te,jn as Ee,jr as De,jt as Oe,l as A,ln as ke,m as j,mr as Ae,n as M,nt as je,or as N,ot as P,p as F,pr as Me,qn as Ne,r as I,rt as Pe,t as L,u as R,un as Fe,ur as Ie,v as z,vi as Le,vn as Re,wi as ze,wn as Be,xt as B,y as V,yi as Ve,yn as H,za as He,zn as U}from"./alert-CuKAE1Sv.js";import{H as Ue,a as W,at as We,ct as Ge,et as Ke,i as G,n as qe,nt as Je,o as K,r as q,rt as Ye}from"./overlays-DeHu6TU_.js";import{t as Xe}from"./arrow-down-DeIGdMUk.js";import{t as Ze}from"./arrow-left-DX1c-nYY.js";import{a as Qe,i as $e,n as J,o as et,s as tt,t as Y}from"./ProvidersPage-BwigLnKs.js";import{t as nt}from"./cloud-download-DWw6s5ag.js";import{t as rt}from"./download-DR9BLMVt.js";import{t as it}from"./ellipsis-BH_FL485.js";import{t as at}from"./external-link-Bb6sx3jt.js";import{n as X}from"./radio-cards-Rq9vGqnw.js";import{t as ot}from"./log-out-Ch09k2bC.js";import{t as st}from"./power-B9MMcl6Y.js";import{t as ct}from"./rotate-ccw-DsmSscuv.js";import{$ as lt,B as ut,C as dt,E as ft,H as pt,J as mt,P as Z,T as ht,_ as gt,a as _t,et as vt,h as yt,o as bt,q as xt,s as St,w as Ct}from"./index-CKrvKDIJ.js";import{t as wt}from"./checkbox-BJe8ekJy.js";import{t as Tt}from"./confirm-morph-DGAHV4QP.js";var Et={name:`arrow-left-right`,size:24,node:[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]};Et.node;var Dt=B(Et),Ot={name:`arrow-right-left`,size:24,node:[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]};Ot.node;var kt=B(Ot),At={name:`gauge`,size:24,node:[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]};At.node;var jt=B(At),Mt={name:`gift`,size:24,node:[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8`,key:`1sqzm4`}],[`path`,{d:`M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5`,key:`kc0143`}],[`rect`,{x:`3`,y:`7`,width:`18`,height:`4`,rx:`1`,key:`1hberx`}]]};Mt.node;var Nt=B(Mt),Pt={name:`list-plus`,size:24,node:[[`path`,{d:`M16 5H3`,key:`m91uny`}],[`path`,{d:`M11 12H3`,key:`51ecnj`}],[`path`,{d:`M16 19H3`,key:`zzsher`}],[`path`,{d:`M18 9v6`,key:`1twb98`}],[`path`,{d:`M21 12h-6`,key:`bt1uis`}]]};Pt.node;var Ft=B(Pt),It={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};It.node;var Lt=B(It),Rt={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};Rt.node;var zt=B(Rt),Bt={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};Bt.node;var Vt=B(Bt),Ht={name:`ticket`,size:24,node:[[`path`,{d:`M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z`,key:`qn84l0`}],[`path`,{d:`M13 5v2`,key:`dyzc3o`}],[`path`,{d:`M13 17v2`,key:`1ont0d`}],[`path`,{d:`M13 11v2`,key:`1wjjxi`}]]};Ht.node;var Ut=B(Ht),Wt={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]};Wt.node;var Gt=B(Wt),Q=ae(r(),1),$=He();function Kt({usage:e,compact:t=!1}){let{t:n}=E(),r=[{label:n(`providers.usage.requests`),values:[e?.today.requests,e?.total.requests],format:(e,n=t)=>w(e,n)},{label:n(`providers.usage.tokens`),values:[e?.today.tokens,e?.total.tokens],format:(e,n=t)=>w(e,n)},{label:n(`providers.usage.cost`),values:[e?.today.costNanoUsd,e?.total.costNanoUsd],format:(e,n=t)=>b(Te(e),{compact:n})}];return(0,$.jsxs)(`table`,{className:P(`w-full table-fixed text-right tabular-nums`,t?`text-[11px]`:`text-[12px]`),"aria-label":n(`providers.usage.title`),children:[(0,$.jsx)(`thead`,{className:`text-[var(--text-muted)]`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-[34%] pb-1 text-left font-normal`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:n(`providers.usage.title`)})}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.today`)}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.total`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`py-0.5 text-left font-normal text-[var(--text-secondary)]`,children:e.label}),e.values.map((t,n)=>(0,$.jsx)(`td`,{className:`truncate py-0.5 pl-1 font-mono`,title:t==null?void 0:e.format(t,!1),children:t==null?`—`:e.format(t)},n))]},e.label))})]})}function qt({timeZone:e}){let{t}=E();return(0,$.jsxs)(`p`,{className:`text-[11px] leading-relaxed text-[var(--text-muted)]`,children:[t(`providers.usage.hint`),e&&(0,$.jsxs)($.Fragment,{children:[` `,t(`providers.usage.dayHint`,{zone:e})]})]})}var Jt=``,Yt=`custom`,Xt=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],Zt={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},Qt={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},$t=e=>JSON.stringify(e??{},null,2);function en(e){return{enabled:e.enabled,template:e.template??Jt,intervalMinutes:e.intervalMinutes??null,timeoutSec:e.timeoutSec,baseUrl:e.baseUrl??``,params:{...e.params},secrets:{},method:e.request?.method??`GET`,url:e.request?.url??``,auth:e.request?.auth??`provider`,headers:$t(e.request?.headers),extract:e.extract?$t(e.extract):``}}function tn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function nn({provider:e}){let{t}=E(),{toast:n}=K(),r=Ie(),i=De(e.id),a=ee(e.id),o=H(),s=e.quotaConfig,c=(0,Q.useMemo)(()=>en(s),[s]),[l,u]=(0,Q.useState)(c),[d,f]=(0,Q.useState)(null);(0,Q.useEffect)(()=>u(c),[c]);let p=r.data??[],m=p.find(e=>e.id===s.suggestedTemplate),h=l.template===Jt?m:p.find(e=>e.id===l.template),g=l.template===Yt,_=g?Xt:h?.params??[],v=e=>u(t=>({...t,...e})),y=JSON.stringify(l)!==JSON.stringify(c),b=e=>{if(e!==Yt||l.url)return v({template:e});let t=h??m;v({template:e,method:t?.request.method??Zt.method,url:t?.request.url??Zt.url,auth:t?.request.auth??Zt.auth,headers:$t(t?.request.headers??Zt.headers),extract:$t(t?.extract??Qt)})},te=()=>{let e={enabled:l.enabled,template:l.template===Jt?null:l.template,intervalMinutes:l.intervalMinutes,timeoutSec:l.timeoutSec??10,baseUrl:l.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(l.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(l.secrets).filter(([,e])=>e.trim()!==``))};if(g){let r=tn(l.headers),i=tn(l.extract);if(!r||!i)return n(t(`providers.quota.invalidJson`,{field:t(r?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:l.method,url:l.url.trim(),auth:l.auth,headers:r},e.extract=i}return e},ne=()=>{let r=te();if(!r)return;let a=r.enabled&&!s.enabled;i.mutate(r,{onSuccess:()=>{n(t(`common.saved`),`success`),a&&o.mutate(e.id,{onError:e=>n(W(e),`error`)})},onError:e=>n(W(e),`error`)})},re=()=>{let e=te();e&&a.mutate(e,{onSuccess:f,onError:e=>n(W(e),`error`)})},ie=s.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:s.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),x=[{value:Jt,label:m?t(`providers.quota.templateAuto`,{name:m.name}):t(`providers.quota.templateNone`)},...p.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:Yt,label:t(`providers.quota.custom`)}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,$.jsx)(j,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,$.jsx)(V,{checked:l.enabled,label:t(`providers.quota.enable`),onChange:e=>v({enabled:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.template`),children:(0,$.jsx)(q,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:l.template,onChange:b,options:x})}),_.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=s.secrets.includes(e.name);return e.secret?(0,$.jsx)(j,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,$.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:l.secrets[e.name]??``,onChange:t=>v({secrets:{...l.secrets,[e.name]:t.target.value}})})},e.name):(0,$.jsx)(j,{label:n,children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":n,value:l.params[e.name]??``,onChange:t=>v({params:{...l.params,[e.name]:t.target.value}})})},e.name)}),_.length>0&&(0,$.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),g&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:l.method,onChange:e=>v({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:l.url,onChange:e=>v({url:e.target.value})}),(0,$.jsx)(q,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:l.auth,onChange:e=>v({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,$.jsx)(T,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:l.headers,onChange:e=>v({headers:e.target.value})}),(0,$.jsx)(T,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:l.extract,onChange:e=>v({extract:e.target.value})}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,$.jsx)(j,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:ie}),children:(0,$.jsx)(F,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:l.intervalMinutes,onChange:e=>v({intervalMinutes:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.timeout`),children:(0,$.jsx)(F,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:l.timeoutSec,onChange:e=>v({timeoutSec:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:l.baseUrl,onChange:e=>v({baseUrl:e.target.value})})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(I,{size:`sm`,variant:`primary`,disabled:!y,loading:i.isPending,onClick:ne,children:t(`common.save`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(X,{className:`size-3.5`}),loading:a.isPending,onClick:re,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:y,loading:o.isPending,onClick:()=>o.mutate(e.id,{onError:e=>n(W(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsx)(rn,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,$.jsx)(G,{open:d!==null,onOpenChange:e=>!e&&f(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:d&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(L,{tone:d.ok?`success`:`danger`,title:d.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!d.ok&&Ke({code:d.errorCode??null,message:d.error??``},t),!d.ok&&d.error&&d.errorCode&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:d.error})]}),d.url&&(0,$.jsx)(k,{label:t(`providers.quota.requestUrl`),mono:!0,children:d.url}),d.httpStatus!=null&&(0,$.jsx)(k,{label:t(`providers.quota.httpStatus`),children:d.httpStatus}),d.snapshot&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,$.jsx)(rn,{snapshot:d.snapshot})]}),d.raw!==void 0&&d.raw!==null&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,$.jsx)(Ce,{children:$t(d.raw)})]})]})})]})}function rn({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=E(),i=We(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,$.jsxs)(L,{tone:`warning`,title:n(`providers.quota.failed`,{error:Ke(i,n)}),children:[(0,$.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,$.jsx)(L,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,$.jsx)(M,{children:e.name}),(0,$.jsx)(`span`,{className:`num`,children:Je(e,n,r)??`—`}),Ye(e,n,r)&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:Ye(e,n,r)}),e.extra&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,$.jsx)(M,{tone:`accent`,children:e.planLabel}),o>0&&(0,$.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:Ue(o,r,n(`tray.justNow`))??``})})]})]})}var an={imported:`providers.subscription.importBatchStatus.imported`,updated:`providers.subscription.importBatchStatus.updated`,duplicate:`providers.subscription.importBatchStatus.duplicate`,invalid_format:`providers.subscription.importBatchStatus.invalid_format`,failed:`providers.subscription.importBatchStatus.failed`,ready:`providers.subscription.importBatchStatus.ready`},on={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},sn={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function cn(e){return e.split(/[,\s]+/).flatMap(e=>{let t=e.replace(/^["']+|["']+$/g,``);return t.startsWith(`tid=`)||t.startsWith(`exp=`)?[t]:t.split(`;`)}).filter(e=>e.replace(/^["']+|["']+$/g,``).length>0).length}function ln(e){let t=e.trim();if(t.length===0)return 0;if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e.filter(e=>typeof e==`object`&&!!e||typeof e==`string`&&e.trim().length>0).length;if(typeof e==`object`&&e)return 1}catch{}let n=0;for(let t of e.split(`
|
|
2
|
-
`)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:cn(e))}return n}function un({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=E(),{toast:o}=K(),s=x(e),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),m=(0,Q.useMemo)(()=>ln(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),p(null))},[n]),n===null)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let h=n===`apiKey`,g=h?t.formats.filter(e=>e.endsWith(`-api-key`)):t.formats,_=!h&&t.formats.some(e=>e.includes(`refresh-token`)||e.endsWith(`-json`)),v=a(h?`providers.accounts.import.apiKeyLabel`:`providers.accounts.import.label`),y=e=>s.mutate({text:c,asApiKey:h||void 0,dryRun:e||void 0,httpProxy:u.trim()||void 0},{onSuccess:t=>{p({...t,dryRun:e}),!e&&(o(a(`providers.accounts.import.summary`,{ok:t.imported,dup:t.duplicates,fail:t.failed}),t.failed>0?`info`:`success`),!(t.failed>0)&&(n===`batch`?l(``):i()))},onError:e=>o(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:a(sn[n]),description:a(`providers.accounts.import.desc`),width:560,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[g.length>0&&(0,$.jsx)(`p`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:a(`providers.accounts.import.formats`,{formats:g.map(e=>a(`providers.accounts.format.${e}`)).join(` · `)})}),(0,$.jsx)(T,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(D,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:u,onChange:e=>d(e.target.value)}),_&&(0,$.jsx)(L,{tone:`info`,title:a(`providers.accounts.import.rotateWarning`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.import.count`,{n:m})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[n===`batch`&&(0,$.jsx)(I,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>y(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(I,{variant:`primary`,disabled:m===0||m>t.maxBatch,loading:s.isPending&&!s.variables?.dryRun,onClick:()=>y(!1),children:a(`providers.accounts.import.run`)})]})]}),f&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[12px] font-medium`,children:a(f.dryRun?`providers.accounts.import.previewSummary`:`providers.accounts.import.summary`,{ok:f.imported,dup:f.duplicates,fail:f.failed})}),(0,$.jsx)(`ul`,{className:`card max-h-72 divide-y divide-[var(--border)] overflow-auto`,children:f.items.map(e=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`w-6 shrink-0 text-[var(--text-muted)]`,children:e.index}),(0,$.jsx)(`span`,{className:`selectable w-28 shrink-0 truncate font-mono`,children:e.source}),(0,$.jsx)(M,{tone:on[e.status],children:a(an[e.status])}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.credential.${e.kind}`)}),(0,$.jsx)(`span`,{className:`selectable min-w-0 flex-1 break-words text-[var(--text-secondary)]`,children:e.account?.displayName&&(e.status===`imported`||e.status===`updated`)?`${e.account.displayName}${e.message?` · ${e.message}`:``}`:e.message??``})]},e.index))})]})]})})}function dn(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var fn={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},pn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function mn(e,t){let n=(e??``).toLowerCase(),r=t?`110,115,135`:/max|ultra/.test(n)?`47,124,246`:/pro|plus|premium/.test(n)?`52,195,143`:/team|business|enterprise|allegro|vivace/.test(n)?`130,100,230`:`110,115,135`;return`linear-gradient(135deg, rgba(${r},.34), rgba(${r},.08))`}function hn({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s,usage:c}){let{t:l,locale:d}=E(),f=dn(e),p=e.displayName||e.accountEmail||e.keyMasked||e.id,m=e.kind===`api_key`,h=e.plan?.trim(),g=f===`cooling`?{text:l(`providers.subscription.cooldown`,{when:u(e.cooldownUntilUtc,d)}),tone:`var(--warning)`}:f===`dead`?{text:e.lastError||l(pn[e.status]),tone:`var(--danger)`}:m?{text:e.keyMasked??l(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:l(`providers.accounts.expiresAt`,{when:u(e.expiresAtUtc,d)}),tone:void 0}:null,_=[{id:`activate`,label:l(`providers.subscription.activate`),icon:(0,$.jsx)(kt,{className:`size-3.5`}),disabled:e.isCurrent||f===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:l(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(st,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:l(`providers.subscription.moveUp`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:l(`providers.subscription.moveDown`),icon:(0,$.jsx)(Xe,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:l(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:f===`dead`,onSelect:()=>n.refreshQuota(e)},...m?[]:[{id:`refresh`,label:l(`providers.subscription.refreshToken`),icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:l(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],{id:`remove`,label:l(`providers.subscription.logout`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],v=l(f===`disabled`?`providers.subscription.disabled`:pn[e.status]),y=l(m?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`),b=e.quota?.session?.usedPercent!=null||e.quota?.weekly?.usedPercent!=null||e.quota?.credits?.usedPercent!=null;return(0,$.jsxs)(`div`,{"data-testid":`account-card`,className:P(`group card relative flex min-h-[292px] min-w-0 cursor-pointer flex-col overflow-hidden transition-colors hover:bg-[var(--fill)]`,e.isCurrent&&`ring-1 ring-[var(--accent)]`,r&&`bg-[var(--accent-subtle)]`,f===`disabled`&&`opacity-55`),onClick:()=>i?a(e.id):n.open(e),children:[(0,$.jsxs)(`div`,{className:`relative shrink-0 px-3 pb-3 pt-2.5`,style:{background:mn(h,m)},children:[(f===`cooling`||f===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:fn[f]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:P(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(wt,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":l(`providers.accounts.select`,{name:p})})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{role:`img`,"aria-label":v,className:`size-1.5 shrink-0 rounded-full`,style:{background:fn[f]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:v})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${l(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(Se,{className:`size-3.5`,"aria-label":l(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(qe,{iconOnly:!0,label:l(`common.more`),icon:(0,$.jsx)(it,{className:`size-4`}),items:_})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 truncate text-[17px] font-bold tracking-[.01em]`,title:h||y,children:h||y})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col px-3 pb-3 pt-2.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-[13px] font-medium outline-none focus-visible:underline`,title:p,onClick:t=>{t.stopPropagation(),i?a(e.id):n.open(e)},children:p}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 items-center gap-1 whitespace-nowrap text-[11px] text-[var(--text-muted)]`,children:[e.isCurrent&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[var(--success)]`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`●`}),(0,$.jsx)(`span`,{children:l(`providers.subscription.current`)})]}),e.isCurrent&&(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`shrink-0`,children:y}),e.source&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,children:l(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:l(`providers.accounts.order`,{n:t+1})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 min-h-[28px]`,children:g&&(f===`cooling`||f===`dead`||!b)&&(0,$.jsx)(`div`,{className:`line-clamp-2 text-[11px] leading-snug`,style:{color:g.tone??`var(--text-muted)`},title:g.text,children:g.text})}),(0,$.jsx)(`div`,{className:`mt-3 shrink-0 border-t border-[var(--border-subtle)] pt-2`,children:(0,$.jsx)(Kt,{usage:c,compact:!0})}),f===`dead`?(0,$.jsxs)(`div`,{className:`mt-auto flex items-center gap-2 pt-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:l(`providers.accounts.signedOut`)}),!m&&(0,$.jsx)(I,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:l(`providers.subscription.relogin`)})]}):(0,$.jsx)(_n,{quota:e.quota??null,pending:s})]})]})}var gn=10;function _n({quota:e,pending:t}){let{t:n,locale:r}=E(),i=[];return e?.session?.usedPercent!=null&&i.push({key:`session`,label:e.session.windowMinutes?`${Math.round(e.session.windowMinutes/60)}h`:n(`providers.accounts.quotaShortSession`),percent:e.session.usedPercent,reset:e.session.resetsAtUtc}),e?.weekly?.usedPercent!=null&&i.push({key:`weekly`,label:n(`providers.accounts.quotaShortWeekly`),percent:e.weekly.usedPercent,reset:e.weekly.resetsAtUtc}),i.length<2&&e?.credits?.usedPercent!=null&&i.push({key:`credits`,label:n(e.entitlement==null?`providers.accounts.quotaShortCredits`:`providers.accounts.quotaShortPremium`),percent:e.credits.usedPercent,reset:e.credits.resetsAtUtc}),i.length===0?null:(0,$.jsx)(`div`,{className:P(`mt-auto flex flex-col gap-2 pt-2`,t&&`opacity-60`),children:i.slice(0,2).map(e=>{let t=Math.max(0,Math.min(100,Math.round(e.percent))),i=t>=90?`var(--danger)`:t>=70?`var(--warning)`:`var(--accent)`,a=Math.round(t/100*gn),o=e.reset?n(`providers.subscription.quotaResets`,{when:u(e.reset,r)}):void 0;return(0,$.jsxs)(`div`,{className:`min-w-0`,title:o,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[t,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-label":e.label,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,className:`mt-0.5 flex gap-[3px]`,children:Array.from({length:gn},(e,t)=>(0,$.jsx)(`i`,{className:`h-[5px] flex-1 rounded-[2px] bg-[var(--surface-muted)]`,style:t<a?{background:i}:void 0},t))})]},e.key)})})}function vn({quota:e,className:t}){let{t:n,locale:r}=E(),i=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:n(`providers.subscription.quotaResets`,{when:t.toLocaleString(r)})},a=[];e.session?.usedPercent!=null&&a.push({key:`session`,label:n(`providers.subscription.quotaWindowSession`),window:e.session}),e.weekly?.usedPercent!=null&&a.push({key:`weekly`,label:n(`providers.subscription.quotaWindowWeekly`),window:e.weekly}),e.credits?.usedPercent!=null&&a.push({key:`credits`,label:e.entitlement==null?n(`providers.subscription.quotaWindowCredits`):n(`providers.subscription.quotaWindowPremium`),window:{usedPercent:e.credits.usedPercent,resetsAtUtc:e.credits.resetsAtUtc??null}});let o=e.credits?.prepaidBalance==null?null:n(`providers.subscription.quotaBalance`,{balance:e.credits.prepaidBalance}),s=e.entitlement!=null&&e.entitlement>=0?[n(`providers.subscription.quotaPremiumCount`,{used:Math.max(0,(e.entitlement??0)-(e.remaining??0)),total:e.entitlement}),e.overageUsed?n(`providers.subscription.quotaOverage`,{count:e.overageUsed}):null,e.overagePermitted===!1?n(`providers.subscription.quotaOverageOff`):null].filter(Boolean).join(` · `):null,c=e.planLabel??(e.fetchedAtUtc?n(`providers.subscription.quotaFetchedAt`,{when:new Date(e.fetchedAtUtc).toLocaleString(r)}):null);return(0,$.jsx)(`div`,{className:P(`px-4 py-1`,t),children:(0,$.jsxs)(`div`,{className:`card flex flex-col gap-3 p-3`,children:[(c||o)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] text-[var(--text-secondary)]`,children:[c&&(0,$.jsx)(`span`,{children:c}),o&&(0,$.jsx)(`span`,{children:o})]}),a.length===0?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.subscription.quotaNoWindows`)}):a.map(e=>(0,$.jsx)(yn,{label:e.label,window:e.window,reset:i(e.window.resetsAtUtc)},e.key)),s&&(0,$.jsx)(`div`,{className:`text-[10.5px] text-[var(--text-muted)]`,children:s})]})})}function yn({label:e,window:t,reset:n}){let r=Math.max(0,Math.min(100,Math.round(t.usedPercent??0))),[i,a]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches){a(r);return}let e=requestAnimationFrame(()=>a(r));return()=>cancelAnimationFrame(e)},[r]);let o=r>=90?`var(--danger)`:r>=70?`var(--warning)`:`var(--accent)`,s=t.windowMinutes?Math.round(t.windowMinutes/60):null;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,$.jsxs)(`span`,{className:`text-[var(--text-secondary)]`,children:[e,s!=null&&(0,$.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[` · `,s,`h`]})]}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[r,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":e,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface-muted)]`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-[width] duration-500 ease-out`,style:{width:`${i}%`,background:o}})}),n&&(0,$.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n})]})}var bn={available:`green`,redeemed:`neutral`,expired:`orange`};function xn({account:e,providerId:t}){let{t:n}=E(),{toast:r,confirm:i}=K(),a=o(e.id,e.status===`active`),s=te(t),c=a.data?.credits??[],l=a.data?.available_count??c.filter(e=>e.status===`available`).length,u=async t=>{await i({title:n(`providers.subscription.credits.consumeConfirm`,{title:t.title??t.reset_type??``}),detail:n(`providers.subscription.credits.consumeDetail`),confirmLabel:n(`providers.subscription.credits.consume`),destructive:!0})&&s.mutate({accountId:e.id,creditId:t.id},{onSuccess:()=>r(n(`providers.subscription.credits.consumed`),`success`),onError:e=>r(e instanceof _&&e.status===409?W(e):`${n(`providers.subscription.credits.consumeFailed`)}:${W(e)}`,`error`)})};return(0,$.jsxs)(R,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(z,{className:`my-4`}),a.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.unavailable`)}),a.data&&c.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.none`)}),c.map(e=>{let t=e.status!==`available`;return(0,$.jsxs)(j,{className:P(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Nt,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?n(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?n(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?n(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(M,{tone:bn[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ut,{className:`size-3.5`}),disabled:t,loading:s.isPending&&s.variables?.creditId===e.id,onClick:()=>void u(e),children:n(`providers.subscription.credits.consume`)})]},e.id)}),a.data&&c.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`providers.subscription.credits.availableCount`,{count:l})})]})}var Sn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Cn({provider:e,account:t,index:n,actions:r,onClose:i,usage:a,usageTimeZone:o}){let{t:s,locale:c}=E(),{toast:l}=K(),d=Ve(e.id),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(``);if((0,Q.useEffect)(()=>{p(t?.displayName??``),h(t?.httpProxy??``)},[t?.id,t?.displayName,t?.httpProxy]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let g=dn(t),_=t.kind===`api_key`,v=e.templateId===`openai-subscription`,y=e.httpProxy||s(`providers.accounts.proxyFallbackSystem`),b=e=>e?u(e,c):`—`,ee=(e,n)=>d.mutate({id:t.id,...e},{onSuccess:()=>l(s(n),`success`),onError:e=>l(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,s(_?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`)].filter(Boolean).join(` · `),width:520,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(kt,{className:`size-3.5`}),disabled:t.isCurrent||g===`dead`,onClick:()=>r.activate(t),children:s(`providers.subscription.activate`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:g===`dead`,onClick:()=>r.refreshQuota(t),children:s(`providers.subscription.quotaRefresh`)}),!_&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:s(`providers.subscription.refreshToken`)}),!_&&t.status!==`active`&&(0,$.jsx)(I,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:s(`providers.subscription.relogin`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),onClick:()=>r.remove(t),children:s(`providers.subscription.logout`)})]}),g===`dead`&&t.lastError&&(0,$.jsx)(L,{tone:`danger`,title:t.lastError}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.usage.title`)}),(0,$.jsx)(`div`,{className:`card px-3 py-2`,children:(0,$.jsx)(Kt,{usage:a})}),(0,$.jsx)(qt,{timeZone:o})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(D,{className:`flex-1`,label:s(`providers.accounts.detail.name`),value:f,onChange:e=>p(e.target.value)}),(0,$.jsx)(I,{disabled:f.trim().length===0||f.trim()===t.displayName,loading:d.isPending&&d.variables?.displayName!==void 0,onClick:()=>ee({displayName:f.trim()},`providers.accounts.renamed`),children:s(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(D,{className:`flex-1`,mono:!0,label:s(`providers.accounts.detail.proxy`),placeholder:y,value:m,onChange:e=>h(e.target.value)}),(0,$.jsx)(I,{disabled:m.trim()===(t.httpProxy??``),loading:d.isPending&&d.variables?.httpProxy!==void 0,onClick:()=>ee({httpProxy:m.trim()},`providers.accounts.proxySaved`),children:s(`common.save`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:s(`providers.accounts.detail.proxyHint`,{fallback:y})})]}),t.quota&&(0,$.jsxs)(`section`,{className:`-mx-4 flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`px-4 text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.quota`)}),(0,$.jsx)(vn,{quota:t.quota})]}),v&&g!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(xn,{account:t,providerId:e.id})}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.credentials`)}),(0,$.jsxs)(`div`,{className:`card divide-y divide-[var(--border)] px-3`,children:[(0,$.jsx)(k,{label:s(`providers.accounts.detail.status`),children:(0,$.jsx)(M,{tone:g===`usable`?`green`:g===`cooling`?`orange`:g===`dead`?`red`:`neutral`,children:s(g===`disabled`?`providers.subscription.disabled`:Sn[t.status])})}),t.source&&(0,$.jsx)(k,{label:s(`providers.accounts.detail.source`),children:s(`providers.accounts.source.${t.source}`)}),_?(0,$.jsx)(k,{label:s(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:s(`providers.accounts.detail.expires`),children:b(t.expiresAtUtc)}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.lastRefresh`),children:b(t.lastRefreshAtUtc)})]}),g===`cooling`&&(0,$.jsx)(k,{label:s(`providers.accounts.filter.cooling`),children:b(t.cooldownUntilUtc)}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.order`),children:s(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.created`),children:b(t.createdAt)}),t.lastError&&g!==`dead`&&(0,$.jsx)(k,{label:s(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function wn({provider:e}){let{t}=E(),{toast:n}=K(),r=e.authScheme===`oauth-subscription`,i=h(e.id,r),a=ze(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(W(e),`error`)}),c=o.claudeSubscription||o.clientPolicy===`claude-code-only`;return!c&&!o.claudeSubscription?null:(0,$.jsxs)(R,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[c&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:o.clientPolicy===`claude-code-only`,disabled:a.isPending,onChange:e=>s({clientPolicy:e?`claude-code-only`:`any`})})}),o.claudeSubscription&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.mimic`),checked:o.mimicClaudeCode,disabled:a.isPending,onChange:e=>s({mimicClaudeCode:e})})}),c&&o.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:o.mimicClaudeCode?(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Tn=[{value:`all`,label:`providers.accounts.filter.all`},{value:`usable`,label:`providers.accounts.filter.usable`},{value:`cooling`,label:`providers.accounts.filter.cooling`},{value:`dead`,label:`providers.accounts.filter.dead`},{value:`disabled`,label:`providers.accounts.filter.disabled`}],En=3e5;function Dn({provider:e}){let{t:r}=E(),{toast:i,confirm:o}=K(),s=ne(),l=e.authScheme===`oauth-subscription`,u=me(e.id,l),d=ve(e.id,l),f=h(e.id,l),p=ze(e.id),m=n(e.id,l),g=S(e.id),v=se(e.id),y=le(e.id),b=Re(e.id),ee=Me(e.id),te=ke(e.id),re=de(e.id),ie=Oe(e.id),x=Ve(e.id),ae=fe(e.id),oe=e.templateId===`openai-subscription`,C=t(l&&oe),ce=a(e.id),w=e.templateId===`github-copilot-subscription`,ue=Ee(l&&w),pe=Be(e.id),[T,he]=(0,Q.useState)(`all`),[ge,_e]=(0,Q.useState)(``),[O,k]=(0,Q.useState)(new Set),[ye,xe]=(0,Q.useState)(null),[Se,Ce]=(0,Q.useState)(null),[we,Te]=(0,Q.useState)(!1),[De,A]=(0,Q.useState)(``),[j,Ae]=(0,Q.useState)(!1),[M,je]=(0,Q.useState)(!1),[N,F]=(0,Q.useState)(null),[Ne,Pe]=(0,Q.useState)(null),[R,Fe]=(0,Q.useState)(!1),[Ie,Le]=(0,Q.useState)(``),B=(0,Q.useRef)(new Set),V=(0,Q.useRef)(new Set),H=(0,Q.useMemo)(()=>u.data??[],[u.data]);if((0,Q.useEffect)(()=>{if(l)for(let e of H){if(e.status!==`active`||V.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<En||(V.current.add(e.id),b.mutate(e.id,{onError:()=>{}}))}},[H,l]),(0,Q.useEffect)(()=>{let e=new Set(H.map(e=>e.id));k(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),ye&&!e.has(ye)&&xe(null)},[H,ye]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`pkce`)return;let e=setInterval(()=>void u.refetch(),3e3);return()=>clearInterval(e)},[M,N,u]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`pkce`)return;let e=H.find(e=>!B.current.has(e.id));e&&U(!0,e.displayName||e.accountEmail||e.id)},[H,M,N]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`device`&&N?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await v.mutateAsync(N.state);if(e)return;t=0,n.status===`done`?U(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&U(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof _&&(n.status===404||n.status===400)){U(!1,void 0,W(n));return}++t>=5&&U(!1,void 0,W(n))}},r=setInterval(()=>void n(),Math.max(N.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[M,N]),!l)return null;let He=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,U=(t,n,a)=>{if(s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),t){F(null),Pe(null),je(!1),i(r(`providers.subscription.loginOk`,{name:n??``}),`success`);return}a&&Pe(a)},Ue=(e,t)=>{B.current=new Set(H.map(e=>e.id)),Pe(null),g.mutate({accountId:e,httpProxy:t},{onSuccess:e=>{Te(!1),F(e),je(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof _&&e.details?.needsVerification?i(r(`providers.subscription.needsVerification`),`error`):i(W(e),`error`)}})},We=async()=>{if(N){Fe(!0);try{let e=await v.mutateAsync(N.state);e.status===`done`?U(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?i(r(`providers.subscription.stillWaiting`),`info`):U(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof _&&e.status===404){let t=((await u.refetch()).data??[]).find(e=>!B.current.has(e.id));t?U(!0,t.displayName||t.accountEmail||t.id):U(!1,void 0,W(e))}else U(!1,void 0,W(e))}finally{Fe(!1)}}},Ke=async()=>{if(N&&N.mode===`paste`&&Ie.trim().length!==0){Fe(!0);try{let e=await y.mutateAsync({state:N.state,code:Ie.trim()});e.status===`done`?(Le(``),U(!0,e.account.displayName||e.account.accountEmail||e.account.id)):U(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){U(!1,void 0,W(e))}finally{Fe(!1)}}},Je=()=>ce.mutate(void 0,{onSuccess:e=>{i(r(`providers.subscription.importOk`,{name:He(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`),C.refetch()},onError:e=>i(W(e),`error`)}),q=()=>pe.mutate(``,{onSuccess:e=>{i(r(`providers.subscription.importOk`,{name:He(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`)},onError:e=>i(W(e),`error`)}),Ye=(e,t)=>{let n=H.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],ae.mutate(n,{onError:e=>i(W(e),`error`)}))},Xe=async()=>{if(await o({title:r(`providers.accounts.exportConfirm`),detail:r(`providers.accounts.exportDetail`),confirmLabel:r(`providers.accounts.export`)}))try{let e=await re.mutateAsync();if(e.count===0){i(r(`providers.accounts.exportNone`),`info`);return}if(!await Ge.copy(e.text)){i(r(`providers.accounts.exportCopyFailed`),`error`);return}i(r(`providers.accounts.exportDone`,{n:e.count})+(e.skipped>0?r(`providers.accounts.exportSkipped`,{n:e.skipped}):``),`success`)}catch(e){i(W(e),`error`)}},Ze=async e=>{let t=He(e);await o({title:r(`providers.subscription.logoutConfirm`,{name:t}),destructive:!0,confirmLabel:r(`providers.subscription.logout`)})&&te.mutate(e.id,{onError:e=>i(W(e),`error`)})},Qe={open:e=>xe(e.id),activate:e=>ie.mutate(e.id,{onSuccess:()=>i(r(`providers.subscription.activated`,{name:He(e)}),`success`),onError:e=>i(W(e),`error`)}),toggleEnabled:e=>x.mutate({id:e.id,enabled:!e.enabled},{onError:e=>i(W(e),`error`)}),refreshQuota:e=>b.mutate(e.id,{onError:e=>{e instanceof _&&e.status===501?i(r(`providers.subscription.quotaUnsupported`),`error`):i(W(e),`error`)}}),refreshToken:e=>ee.mutate(e.id,{onSuccess:()=>i(r(`providers.subscription.tokenRefreshed`),`success`),onError:e=>i(W(e),`error`)}),relogin:e=>Ue(e.id),remove:e=>void Ze(e)},$e=e=>k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),J=async t=>{let n=H.filter(e=>O.has(e.id));Ae(!0);let a=0;for(let e of n)try{await t(e),a++}catch(t){i(`${He(e)}: ${W(t)}`,`error`)}Ae(!1),k(new Set),s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),a>0&&i(r(`providers.accounts.bulkDone`,{n:a}),`success`)},et=async()=>{await o({title:r(`providers.accounts.bulkDeleteConfirm`,{n:O.size}),detail:r(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:r(`common.delete`)})&&await J(e=>te.mutateAsync(e.id))},tt=H.map(e=>dn(e)),Y=e=>e===`all`?H.length:tt.filter(t=>t===e).length,nt=ge.trim().toLowerCase(),it=H.map((e,t)=>({a:e,index:t,state:tt[t]})).filter(({a:e,state:t})=>(T===`all`||t===T)&&(nt.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes(nt)))),at=H.find(e=>e.id===ye)??null,X=m.data,ot=O.size>0,ct=[{id:`login`,label:r(`providers.accounts.addLogin`),icon:(0,$.jsx)(Lt,{className:`size-3.5`}),onSelect:()=>Ue()},{id:`login-proxy`,label:r(`providers.accounts.addLoginProxy`),onSelect:()=>Te(!0)},...oe&&C.data?.available?[{id:`codex`,separatorBefore:!0,label:r(`providers.subscription.importCodex`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),onSelect:Je}]:[],...w?[{id:`copilot`,separatorBefore:!0,label:r(`providers.subscription.importCopilot`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),onSelect:q}]:[],...X?.supported?[{id:`token`,separatorBefore:!(oe&&C.data?.available)&&!w,label:r(`providers.accounts.addToken`),onSelect:()=>Ce(`token`)}]:[],...X?.apiKey?[{id:`apikey`,label:r(`providers.accounts.addApiKey`),icon:(0,$.jsx)(pt,{className:`size-3.5`}),onSelect:()=>Ce(`apiKey`)}]:[]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`card mb-3 flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`mr-auto flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[var(--text)]`,children:r(`providers.accounts.statTotal`,{n:H.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:r(`providers.accounts.statUsable`,{n:Y(`usable`)})}),Y(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:r(`providers.accounts.statCooling`,{n:Y(`cooling`)})}),Y(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:r(`providers.accounts.statDead`,{n:Y(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`providers.accounts.providerProxy`,{proxy:e.httpProxy||r(`providers.accounts.proxyFallbackSystem`)})})]}),f.data&&(0,$.jsx)(On,{policy:f.data,onChange:e=>p.mutate({switchMode:e},{onError:e=>i(W(e),`error`)})})]}),f.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:r(f.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:f.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(be,{className:`w-52`,value:ge,onChange:_e,placeholder:r(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":r(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Tn.filter(e=>e.value===`all`||Y(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":T===e.value,onClick:()=>he(e.value),className:P(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,T===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[r(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:Y(e.value)})]},e.value))}),X?.supported&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(Ft,{className:`size-3.5`}),onClick:()=>Ce(`batch`),children:r(`providers.accounts.batchImport`)}),X?.supported&&H.length>0&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(Gt,{className:`size-3.5`}),disabled:re.isPending,onClick:()=>void Xe(),children:r(`providers.accounts.export`)}),(0,$.jsx)(qe,{label:r(`providers.accounts.add`),icon:(0,$.jsx)(ut,{className:`size-3.5`}),items:ct})]}),oe&&C.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[r(`providers.subscription.localCodexFound`,{who:C.data.accountEmail??C.data.plan??r(`providers.subscription.unknownAccount`)}),C.data.detail?` · ${C.data.detail}`:``]}),w&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[ue.data?.available?r(`providers.subscription.localCopilotFound`,{source:ue.data.source??``}):r(`providers.subscription.localCopilotHint`),ue.data?.detail?` · ${ue.data.detail}`:``]}),u.isLoading?(0,$.jsx)(z,{className:`my-4`}):H.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Ue(),className:`flex w-full flex-col items-center gap-1 rounded-[var(--radius-card,12px)] border border-dashed border-[var(--border)] px-4 py-6 text-[12px] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--text)]`,children:[(0,$.jsx)(`span`,{children:r(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(ut,{className:`size-3.5`}),` `,r(`providers.subscription.login`)]})]}):it.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:r(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:it.map(({a:e,index:t})=>(0,$.jsx)(hn,{account:e,usage:d.data?.accounts.find(t=>t.accountId===e.id),index:t,actions:Qe,selected:O.has(e.id),selecting:ot,onToggleSelect:$e,quotaPending:b.isPending&&b.variables===e.id,onMove:H.length>1?{up:t>0?()=>Ye(t,-1):void 0,down:t<H.length-1?()=>Ye(t,1):void 0}:void 0},e.id))}),d.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`providers.usage.error`),children:W(d.error)}),H.length>0&&(0,$.jsx)(qt,{timeZone:d.data?.timeZone}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:r(`providers.subscription.footer`)}),ot&&(0,$.jsxs)(`div`,{className:`card sticky bottom-3 z-10 mt-3 flex flex-wrap items-center gap-1.5 px-3 py-1.5 shadow-lg`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[12px] text-[var(--text-secondary)]`,children:r(`providers.accounts.selected`,{n:O.size})}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(st,{className:`size-3.5`}),disabled:j,onClick:()=>void J(e=>x.mutateAsync({id:e.id,enabled:!0})),children:r(`providers.subscription.enable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>x.mutateAsync({id:e.id,enabled:!1})),children:r(`providers.subscription.disable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>b.mutateAsync(e.id)),children:r(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(I,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:j,onClick:()=>void et(),children:r(`common.delete`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>k(new Set),children:r(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(wn,{provider:e})}),(0,$.jsx)(Cn,{provider:e,account:at,usage:d.data?.accounts.find(e=>e.accountId===at?.id),usageTimeZone:d.data?.timeZone,index:at?H.indexOf(at):0,actions:Qe,onClose:()=>xe(null)}),X&&(0,$.jsx)(un,{providerId:e.id,info:X,mode:Se,providerProxy:e.httpProxy,onClose:()=>Ce(null)}),(0,$.jsx)(G,{open:we,onOpenChange:Te,title:r(`providers.accounts.loginProxyTitle`),description:r(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(I,{variant:`primary`,loading:g.isPending,disabled:De.trim().length===0,onClick:()=>Ue(void 0,De),children:r(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(D,{mono:!0,label:r(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:De,onChange:e=>A(e.target.value)})}),(0,$.jsxs)(G,{open:M,onOpenChange:e=>{je(e),e||(F(null),Pe(null))},title:r(`providers.subscription.login`),description:r(`providers.subscription.loginDesc`),children:[Ne&&(0,$.jsx)(L,{tone:`danger`,title:r(`providers.subscription.loginFailed`),children:Ne}),N?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.pasteTitle`),children:r(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(D,{mono:!0,value:Ie,onChange:e=>Le(e.target.value),placeholder:r(`providers.subscription.pastePlaceholder`),"aria-label":r(`providers.subscription.pasteCode`)}),(0,$.jsx)(I,{variant:`primary`,loading:R,onClick:()=>void Ke(),children:r(`providers.subscription.pasteSubmit`)})]}),N?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)}),(0,$.jsx)(I,{variant:`primary`,onClick:()=>{s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),u.refetch()},children:r(`providers.subscription.doneAuthorize`)})]})]}),N?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.cliDetail`)}),(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)})]}),N?.mode===`device`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-secondary)]`,children:r(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:N.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[N.verificationUrl&&(0,$.jsx)(I,{onClick:()=>window.open(N.verificationUrl??void 0,`_blank`,`noopener`),children:r(`providers.subscription.visitPage`)}),(0,$.jsx)(I,{variant:`primary`,loading:R,onClick:()=>void We(),children:r(`providers.subscription.checkNow`)})]}),(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.checkNowHint`)})]})]})]})}function On({policy:e,onChange:t}){let{t:n}=E();return(0,$.jsx)(ue,{ariaLabel:n(`providers.subscription.policy.switchMode`),value:e.switchMode,onChange:t,items:[{value:`manual`,label:n(`providers.subscription.policy.manual`)},{value:`failover`,label:n(`providers.subscription.policy.failover`)},{value:`balanced`,label:n(`providers.subscription.policy.balanced`)}]})}function kn({provider:e}){let{t}=E(),n=me(e.id),r=ve(e.id),i=C(e.id),a=h(e.id,!0),o=ze(e.id),{toast:s}=K(),[c,l]=(0,Q.useState)(null);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i.isLoading&&(0,$.jsx)(z,{lines:1}),i.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:W(i.error)}),i.data?.map(e=>(0,$.jsx)(I,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(pt,{className:`size-3.5`}):(0,$.jsx)(Lt,{className:`size-3.5`}),onClick:()=>l(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(z,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ge,{icon:(0,$.jsx)(zt,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&a.data&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-1`,children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:t(a.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:a.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsx)(On,{policy:a.data,onChange:e=>o.mutate({switchMode:e},{onError:e=>s(W(e),`error`)})})]}),n.data&&n.data.length>0&&(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(t=>(0,$.jsx)(jn,{provider:e,account:t,gatewayUsage:r.data?.accounts.find(e=>e.accountId===t.id)},t.id))}),r.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`providers.usage.error`),children:W(r.error)}),n.data&&n.data.length>0&&(0,$.jsx)(qt,{timeZone:r.data?.timeZone}),(0,$.jsx)(An,{provider:e}),c&&(0,$.jsx)(Mn,{provider:e,method:c,onClose:()=>l(null)})]})}function An({provider:e}){let{t,locale:n}=E(),{toast:r}=K(),a=U(e.id),o=i(e.id);if(!a.data?.supported)return null;let s=e=>o.mutate(e,{onError:e=>r(W(e),`error`)}),c={claimed:`green`,done:`green`,ineligible:`neutral`,inactive:`neutral`,captcha:`orange`,failed:`red`};return(0,$.jsxs)(`section`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`pluginAccounts.checkin`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`pluginAccounts.checkinDetail`)})]}),(0,$.jsx)(V,{checked:a.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>s(e)}),(0,$.jsx)(I,{size:`sm`,loading:o.isPending,onClick:()=>s(),children:t(`pluginAccounts.checkinNow`)})]}),a.data.accounts.map(e=>{let r=[e.credit?t(`pluginAccounts.credit`,{credit:e.credit}):null,e.streak?t(`pluginAccounts.streak`,{days:e.streak}):null,e.message,e.at?u(e.at,n):null].filter(Boolean);return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px]`,children:e.account}),r.length>0&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-[var(--text-secondary)]`,children:r.join(` · `)}),e.outcome?(0,$.jsx)(M,{tone:c[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(M,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function jn({provider:e,account:t,gatewayUsage:n}){let{t:r,locale:i}=E(),{toast:a,confirm:o}=K(),s=Ne(e.id),[c,l]=(0,Q.useState)(!1),d=e.settings?.plugin?.usage===!0,f=p(e.id,t.id,c),m=async()=>{await o({title:r(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:r(`pluginAccounts.signOut`),destructive:!0})&&s.mutate(t.id,{onError:e=>a(W(e),`error`)})};return(0,$.jsxs)(`article`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-medium`,children:t.displayName}),t.isCurrent&&(0,$.jsx)(M,{tone:`accent`,children:r(`pluginAccounts.current`)}),(0,$.jsx)(M,{tone:t.status===`active`?`green`:`red`,children:r(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),d&&(0,$.jsx)(I,{size:`sm`,onClick:()=>l(e=>!e),children:r(`pluginAccounts.usage`)}),(0,$.jsx)(I,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(ot,{className:`size-3.5`}),onClick:()=>void m(),children:r(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:r(`pluginAccounts.lapsedDetail`)}),(0,$.jsx)(Kt,{usage:n}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[f.isLoading&&(0,$.jsx)(z,{lines:2}),f.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:W(f.error)}),f.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:f.data.error}),f.data?.plan&&(0,$.jsx)(k,{label:r(`pluginAccounts.plan`),children:f.data.plan}),f.data?.until&&(0,$.jsx)(k,{label:r(`pluginAccounts.until`),children:u(f.data.until,i)}),f.data?.windows?.map(e=>(0,$.jsxs)(k,{label:e.name,children:[e.display??(e.limit?`${e.amount??e.used??0} / ${e.limit} ${e.unit??``}`:`${e.used??0}%`),e.resetsAt?` · ${r(`pluginAccounts.resets`,{at:u(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function Mn({provider:e,method:t,onClose:n}){let{t:r}=E(),{toast:i}=K(),[a,o]=(0,Q.useState)({}),[c,u]=(0,Q.useState)(void 0),[f,p]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[_,y]=(0,Q.useState)(``),[b,ee]=(0,Q.useState)(``),[te,ne]=(0,Q.useState)(null),ie=d(e.id),x=re(e.id),ae=l(e.id),S=m(e.id,te).data;(0,Q.useEffect)(()=>{let n=!0;return s(e.id,t.index,a).then(e=>{n&&(u(e.prompt),p(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&i(W(e),`error`)),()=>{n=!1}},[e.id,t.index,a,i]),(0,Q.useEffect)(()=>{S?.state===`done`&&(i(r(`pluginAccounts.signedIn`),`success`),n())},[S?.state,n,r,i]);let oe=async()=>{if(!c)return;let n=await v(e.id,t.index,c.key,f).catch(()=>({error:null}));if(n.error)return g(n.error);g(null),o(e=>({...e,[c.key]:f}))};return(0,$.jsxs)(G,{open:!0,onOpenChange:e=>!e&&n(),title:r(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[c===void 0&&(0,$.jsx)(z,{lines:2}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:c.message,error:h??void 0,children:c.type===`select`?(0,$.jsx)(q,{value:f,onChange:p,options:(c.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(D,{value:f,placeholder:c.placeholder??void 0,onChange:e=>p(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,onClick:()=>void oe(),children:r(`pluginAccounts.continue`)})})]}),c===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:r(`pluginAccounts.key`),children:(0,$.jsx)(D,{mono:!0,type:`password`,value:_,placeholder:t.placeholder??void 0,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!_.trim()||x.isPending,onClick:()=>x.mutate({method:t.index,inputs:a,key:_},{onSuccess:()=>(i(r(`pluginAccounts.signedIn`),`success`),n()),onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),c===null&&t.type!==`api`&&!S&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(at,{className:`size-3.5`}),disabled:ie.isPending,onClick:()=>ie.mutate({method:t.index,inputs:a},{onSuccess:e=>{ne(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.openPage`)})}),S&&S.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[S.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:S.instructions}),S.deviceCode&&(0,$.jsx)(k,{label:r(`pluginAccounts.deviceCode`),mono:!0,children:S.deviceCode}),S.url&&(0,$.jsx)(I,{icon:(0,$.jsx)(at,{className:`size-3.5`}),onClick:()=>window.open(S.url,`_blank`,`noopener`),children:r(`pluginAccounts.openAgain`)}),S.state===`waiting`&&S.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:r(`pluginAccounts.code`),children:(0,$.jsx)(D,{mono:!0,value:b,onChange:e=>ee(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!b.trim()||ae.isPending,onClick:()=>ae.mutate({flow:S.id,code:b.trim()},{onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),S.state===`waiting`&&!S.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`pluginAccounts.waiting`)}),S.state===`failed`&&(0,$.jsx)(L,{tone:`danger`,title:r(`pluginAccounts.failed`),children:S.error})]})]})}function Nn(e){let t=e?.model_map,n={};if(!t||typeof t!=`object`||Array.isArray(t))return n;for(let[e,r]of Object.entries(t))e&&typeof r==`string`&&r&&(n[e]=r);return n}function Pn(){let{t:e}=E(),{id:t=``}=vt(),n=lt(),r=we(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=N(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(yt,{title:e(`nav.providers`),leading:(0,$.jsx)(Fn,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(L,{tone:`danger`,title:e(`common.error`),children:W(r.error)})});let u=r.data;return(0,$.jsx)(yt,{title:u?u.name:``,subtitle:u?[u.templateId,u.priceKey?e(`providers.priceKeyShort`,{key:u.priceKey}):null].filter(Boolean).join(` · `):void 0,leading:(0,$.jsx)(Fn,{onClick:()=>n(`/providers`)}),actions:u&&(0,$.jsx)(In,{p:u}),children:u?(0,$.jsxs)(dt,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(ht,{"aria-label":u.name,children:[(0,$.jsx)(ft,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(ft,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(ft,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(Ct,{value:`models`,className:`pt-4`,children:(0,$.jsx)(Rn,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(Ct,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(kn,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(Dn,{provider:u}):(0,$.jsx)(qn,{provider:u})}),(0,$.jsx)(Ct,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(Yn,{provider:u})}),(0,$.jsx)(Kn,{provider:u,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(z,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}function Fn({onClick:e}){let{t}=E();return(0,$.jsx)(I,{variant:`glass`,icon:(0,$.jsx)(Ze,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function In({p:e}){let{t}=E(),n=lt(),{toast:r,confirm:i}=K(),a=xe(),o=_e(),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=async()=>{await i({title:t(`providers.deleteConfirm`,{name:e.name}),detail:t(`providers.deleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&o.mutate(e.id,{onSuccess:()=>{r(t(`providers.deleted`)),n(`/providers`)},onError:e=>{let n=e instanceof _&&e.status===409?e.details?.boundClients??[]:[];r(n.length?t(`providers.deleteBound`,{clients:n.map(e=>gt[e]?.name??e).join(`, `)}):W(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>f(!0),children:t(`providers.test`)}),(0,$.jsx)(qe,{label:t(`common.more`),icon:(0,$.jsx)(it,{className:`size-4`}),items:[{id:`dup`,label:t(`providers.duplicate`),icon:(0,$.jsx)(ye,{className:`size-3.5`}),onSelect:()=>a.mutate(e.id,{onSuccess:e=>n(`/providers/${e.id}`),onError:e=>r(W(e),`error`)})},{id:`tpl`,label:t(`providers.templateUpdate`),icon:(0,$.jsx)(Vt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>c(!0)},{id:`switch`,label:t(`providers.templateSwitch`),icon:(0,$.jsx)(Dt,{className:`size-3.5`}),disabled:!tt(e),onSelect:()=>u(!0)},{id:`del`,label:t(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void p()}]}),(0,$.jsx)(Ln,{open:s,onOpenChange:c,provider:e}),(0,$.jsx)(et,{open:l,onOpenChange:u,provider:e}),(0,$.jsx)($e,{provider:e,open:d,onOpenChange:f})]})}function Ln({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=ce(n.id,e),o=ie(n.id),s=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(G,{open:e,onOpenChange:t,title:r(`providers.templateUpdate`),description:a.data?r(`providers.templateVersions`,{current:a.data.currentVersion,latest:a.data.latestVersion}):void 0,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!a.data||s,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(W(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(z,{}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),s&&(0,$.jsx)(L,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!s&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function Rn({provider:e,models:t,loading:n,selected:r,onSelect:i}){let{t:a}=E(),{toast:o}=K(),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=he(e.id),m=(t??[]).filter(e=>!s||e.modelId.toLowerCase().includes(s.toLowerCase())||e.effective.displayName.toLowerCase().includes(s.toLowerCase()));return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(be,{className:`w-56`,value:s,onChange:c,placeholder:a(`providers.searchModels`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(I,{icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>f(!0),children:a(`providers.addModels`)}),(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(nt,{className:`size-3.5`}),onClick:()=>u(!0),children:a(`providers.fetchRemote`)})]})]}),n&&(0,$.jsx)(z,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ge,{title:a(`providers.noModels`),detail:a(`providers.noModelsDetail`)})}),m.length>0&&(0,$.jsx)(R,{footer:a(`providers.modelsFooter`),children:m.map(e=>(0,$.jsxs)(j,{selected:e.id===r,onClick:()=>i(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:P(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(M,{tone:`orange`,children:a(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?oe(e.effective.contextWindow):null,Pe(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(_t,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(V,{checked:e.enabled,label:a(`common.enabled`),onChange:t=>p.mutate({pmId:e.id,enabled:t},{onError:e=>o(W(e),`error`)})})]},e.id))}),(0,$.jsx)(zn,{provider:e}),(0,$.jsx)(Bn,{provider:e}),t&&(0,$.jsx)(Vn,{provider:e,models:t}),(0,$.jsx)(Un,{open:d,onOpenChange:f,provider:e}),(0,$.jsx)(Wn,{open:l,onOpenChange:u,provider:e})]})}function zn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=typeof e.settings.alias==`string`?e.settings.alias:``,[a,o]=(0,Q.useState)(i);return(0,Q.useEffect)(()=>o(i),[i]),(0,$.jsx)(R,{title:t(`providers.alias.title`),footer:t(`providers.alias.footer`),children:(0,$.jsxs)(j,{label:t(`providers.alias.label`),detail:t(`providers.alias.hint`),children:[(0,$.jsx)(D,{className:`w-56`,mono:!0,maxLength:64,"aria-label":t(`providers.alias.label`),placeholder:e.name,value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===i,onClick:()=>{let i=a.trim(),o={...e.settings};i?o.alias=i:delete o.alias,r.mutate({settings:o},{onSuccess:()=>n(t(`providers.alias.saved`),`success`),onError:e=>n(W(e),`error`)})},children:t(`common.save`)})]})})}function Bn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=e.settings.first_byte_timeout_sec,a=typeof i==`number`&&i>0?String(i):``,[o,s]=(0,Q.useState)(a);return(0,Q.useEffect)(()=>s(a),[a]),(0,$.jsx)(R,{title:t(`providers.timeout.title`),footer:t(`providers.timeout.footer`),children:(0,$.jsxs)(j,{label:t(`providers.timeout.label`),detail:t(`providers.timeout.hint`),children:[(0,$.jsx)(D,{className:`w-28`,mono:!0,inputMode:`numeric`,"aria-label":t(`providers.timeout.label`),placeholder:`—`,value:o,onChange:e=>s(e.target.value.replace(/\D/g,``).slice(0,4))}),(0,$.jsx)(I,{size:`sm`,disabled:r.isPending||o===a,onClick:()=>{let i=Math.min(3600,Math.floor(Number(o))),a={...e.settings};o.trim()&&i>0?a.first_byte_timeout_sec=i:delete a.first_byte_timeout_sec,r.mutate({settings:a},{onSuccess:()=>n(t(`providers.timeout.saved`),`success`),onError:e=>n(W(e),`error`)})},children:t(`common.save`)})]})})}function Vn({provider:e,models:t}){let{t:n}=E(),{toast:r}=K(),i=g(e.id),[a,o]=(0,Q.useState)(!1),s=Nn(e.settings),c=Object.entries(s),l=new Set(t.map(e=>e.modelId)),u=(e,t)=>i.mutate(e,{onSuccess:()=>{t?.(),r(n(`providers.modelMap.saved`),`success`)},onError:e=>r(W(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(j,{label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2 font-mono text-[12.5px]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e}),(0,$.jsx)(mt,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:P(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(M,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(O,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>u(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(j,{icon:(0,$.jsx)(ut,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`providers.modelMap.add`),detail:t.length===0?n(`providers.modelMap.needModels`):void 0,onClick:t.length===0?void 0:()=>o(!0)})]}),(0,$.jsx)(Hn,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function Hn({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=E(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(G,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!u||!c||u===c,loading:r,onClick:()=>i(u,c),children:a(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(D,{autoFocus:!0,mono:!0,label:a(`providers.modelMap.from`),placeholder:`deepseek-v4.1`,spellCheck:!1,value:o,onChange:e=>s(e.target.value)}),(0,$.jsx)(q,{label:a(`providers.modelMap.to`),value:c,onChange:l,placeholder:a(`providers.modelMap.toPlaceholder`),options:n.map(e=>({value:e.modelId,label:e.modelId}))})]})})}function Un({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=y(n.id),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&s(``)},[e]);let c=[...new Set(o.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addModels`),description:r(`providers.addModelsDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:c.length===0,loading:a.isPending,onClick:()=>a.mutate(c,{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(W(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(T,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
|
|
3
|
-
claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function Wn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=Ae(n.id,e),o=y(n.id),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&c(new Set)},[e]);let d=(a.data??[]).filter(e=>!l||e.id.toLowerCase().includes(l.toLowerCase())),f=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(G,{open:e,onOpenChange:t,width:560,title:r(`providers.fetchRemote`),description:r(`providers.fetchRemoteDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{variant:`plain`,className:`mr-auto`,onClick:()=>c(new Set(d.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:d.length===0,children:r(`common.selectAll`)}),(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:s.size===0,loading:o.isPending,onClick:()=>o.mutate([...s],{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(W(e),`error`)}),children:r(`providers.addSelected`,{count:s.size})})]}),children:[(0,$.jsx)(be,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(z,{lines:4}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),a.error instanceof _&&(0,$.jsx)(Qe,{className:`mt-3`,provider:n,httpStatus:a.error.details?.httpStatus}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(j,{onClick:e.alreadyAdded?void 0:()=>f(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(M,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(wt,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function Gn({origin:e}){let{t}=E();return e===`overridden`?(0,$.jsx)(M,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(M,{children:t(`origin.inherited`)}):(0,$.jsx)(M,{tone:`red`,children:t(`origin.unset`)})}function Kn({provider:e,pm:t,onClose:n}){let{t:r}=E(),{toast:i}=K(),a=he(e.id),o=Fe(e.id),s=f(),[c,l]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(l(t.overrides),d(t.systemModelId??``),m(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let h={...c,pricing:p?c.pricing??null:null},g=JSON.stringify(h)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||u!==(t.systemModelId??``),_=()=>a.mutate({pmId:t.id,overrides:h,systemModelId:u||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(W(e),`error`)}),v=(e,n,i)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:n}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Gn,{origin:c[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),c[e]!=null&&(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ct,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&n(),width:720,title:t.modelId,description:e.name,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mr-auto`,children:(0,$.jsx)(Tt,{label:r(`providers.removeModelShort`),icon:(0,$.jsx)(Z,{className:`size-4`}),prompt:r(`providers.removeModel`,{id:t.modelId}),confirmLabel:r(`common.delete`),cancelLabel:r(`common.cancel`),pendingLabel:r(`common.deleting`),doneLabel:r(`common.deleted`),errorLabel:r(`common.error`),retryLabel:r(`common.retry`),onConfirm:async()=>{await o.mutateAsync(t.id),n()}})}),(0,$.jsx)(I,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!g,loading:a.isPending,onClick:_,children:r(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(_t,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(M,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(pe,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(q,{className:`w-full`,ariaLabel:r(`providers.linkedModel`),value:u,onChange:d,options:[{value:``,label:r(`providers.noLink`)},...(s.data??[]).map(e=>({value:e.id,label:e.id,detail:e.displayName}))]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:r(`providers.linkedModelHint`)})]}),(0,$.jsx)(pe,{title:r(`providers.overrides`),children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[v(`displayName`,r(`models.field.displayName`),(0,$.jsx)(D,{className:`w-full`,"aria-label":r(`models.field.displayName`),placeholder:t.effective.displayName,value:c.displayName??``,onChange:e=>l({...c,displayName:e.target.value||null})})),v(`contextWindow`,r(`models.field.contextWindow`),(0,$.jsx)(F,{className:`w-full`,label:r(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:c.contextWindow,onChange:e=>l({...c,contextWindow:e})})),v(`maxOutputTokens`,r(`models.field.maxOutputTokens`),(0,$.jsx)(F,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:c.maxOutputTokens,onChange:e=>l({...c,maxOutputTokens:e})}))]})}),(0,$.jsxs)(pe,{title:r(`providers.price`),action:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[r(`providers.customPrice`),(0,$.jsx)(V,{checked:p,label:r(`providers.customPrice`),onChange:e=>{m(e),e&&c.pricing==null&&l({...c,pricing:t.effectivePricing??{currency:`USD`,unit:`per_1m_tokens`,base:{input:null,output:null}}})}})]}),children:[(0,$.jsx)(`p`,{className:`mb-3 text-[11px] text-[var(--text-muted)]`,children:r(p?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),p?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(bt,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(Ce,{maxHeight:220,children:je(t.effectivePricing)}):(0,$.jsx)(L,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function qn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=ve(e.id),[a,o]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:(0,$.jsx)(j,{label:t(`providers.apiKey`),detail:e.hasApiKey?e.apiKeyMasked??`••••`:t(`providers.noKey`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":t(`providers.apiKey`),placeholder:t(`providers.replaceKey`),value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(I,{variant:`primary`,disabled:a.trim().length===0,loading:r.isPending,onClick:()=>r.mutate({apiKey:a},{onSuccess:()=>{o(``),n(t(`common.saved`),`success`)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})})}),(0,$.jsxs)(`section`,{className:`card my-4 flex flex-col gap-2 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`providers.usage.title`)}),i.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`providers.usage.error`),children:W(i.error)}),(0,$.jsx)(Kt,{usage:i.data?.accounts.find(e=>!e.accountId)}),(0,$.jsx)(qt,{timeZone:i.data?.timeZone})]}),(0,$.jsx)(nn,{provider:e})]})}function Jn(e){return{name:e.name,apiKey:``,endpoints:e.endpoints,preferredUpstreamProtocols:e.preferredUpstreamProtocols,authScheme:e.authScheme,extraHeaders:e.extraHeaders,httpProxy:e.httpProxy??null,priceMultiplier:e.priceMultiplier,priceKey:e.priceKey??null,settings:e.settings,enabled:e.enabled,notes:e.notes??null}}function Yn({provider:t}){let{t:n}=E(),{toast:r}=K(),i=Le(t.id),a=e(),o=(0,Q.useMemo)(()=>Jn(t),[t]),[s,c]=(0,Q.useState)(o),[l,u]=(0,Q.useState)(Object.entries(t.extraHeaders)),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{c(o),u(Object.entries(o.extraHeaders))},[o]);let h=e=>c(t=>({...t,...e})),g={...s,extraHeaders:Object.fromEntries(l.filter(([e])=>e.trim()))},_=JSON.stringify(g)!==JSON.stringify(o),v=()=>{let e={};for(let t of Object.keys(g))t!==`apiKey`&&JSON.stringify(g[t])!==JSON.stringify(o[t])&&(e[t]=g[t]);s.apiKey&&(e.apiKey=s.apiKey),i.mutate(e,{onSuccess:()=>r(n(`common.saved`),`success`),onError:e=>r(W(e),`error`)})},y=(e,t)=>h({endpoints:s.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:n(`providers.section.basic`),children:[(0,$.jsx)(j,{label:n(`providers.name`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":n(`providers.name`),value:s.name,onChange:e=>h({name:e.target.value})})}),(0,$.jsx)(j,{label:n(`common.enabled`),children:(0,$.jsx)(V,{checked:s.enabled,label:n(`common.enabled`),onChange:e=>h({enabled:e})})}),(0,$.jsx)(j,{label:n(`providers.notes`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":n(`providers.notes`),value:s.notes??``,onChange:e=>h({notes:e.target.value||null})})})]}),(0,$.jsx)(R,{title:n(`providers.section.auth`),children:(0,$.jsx)(j,{label:n(`providers.authScheme`),children:(0,$.jsx)(q,{className:`w-48`,value:s.authScheme,onChange:e=>h({authScheme:e}),options:Y})})}),(0,$.jsxs)(R,{title:n(`providers.section.endpoints`),footer:n(`providers.endpointsFooter`),children:[s.endpoints.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(q,{className:`w-48`,value:e.protocol,onChange:e=>y(t,{protocol:e}),options:J}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":n(`providers.baseUrl`),value:e.baseUrl,onChange:e=>y(t,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:!!e.fullUrl,label:n(`providers.fullUrl`),onChange:e=>y(t,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>h({endpoints:s.endpoints.filter((e,n)=>n!==t)})})]},t)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>f(!0),children:n(`providers.addEndpoint`)})}),(0,$.jsx)(j,{label:n(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[n(`providers.preferredHint`),s.preferredUpstreamProtocols.filter(e=>!s.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:n(`providers.preferredMissing`,{protocol:J.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(St,{label:n(`providers.preferred`),options:J.map(e=>{let t=s.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:s.preferredUpstreamProtocols,onValueChange:e=>{let t=s.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));h({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(R,{title:n(`providers.section.billing`),footer:n(`providers.billingFooter`),children:[(0,$.jsx)(j,{label:n(`providers.priceKey`),detail:n(`providers.priceKeyHint`),children:(0,$.jsx)(q,{className:`w-56`,value:s.priceKey==null?`inherit`:`price:${s.priceKey}`,onChange:e=>h({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:n(`providers.priceKeyDefault`,{id:t.templateId??`—`})},{value:`price:`,label:n(`providers.priceKeyNone`)},...(a.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(j,{label:n(`providers.multiplier`),detail:n(`providers.multiplierHint`),children:(0,$.jsx)(F,{className:`w-28`,label:n(`providers.multiplier`),step:.01,min:0,value:s.priceMultiplier,onChange:e=>h({priceMultiplier:e??1})})})]}),(0,$.jsxs)(R,{title:n(`providers.section.advanced`),children:[(0,$.jsx)(j,{label:n(`providers.proxy`),detail:n(`providers.proxyHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":n(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:s.httpProxy??``,onChange:e=>h({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:n(`providers.headers`)}),l.map(([e,t],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(D,{className:`w-48 font-mono`,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>u(l.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(D,{className:`flex-1 font-mono`,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:t,onChange:e=>u(l.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>u(l.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>m(!0),children:n(`providers.addHeader`)})]}),Object.keys(t.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(T,{label:n(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:je(s.settings),onBlur:e=>{try{h({settings:JSON.parse(e.target.value)})}catch{r(n(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(R,{title:n(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(k,{label:`ID`,children:t.id}),t.adapterId&&(0,$.jsx)(k,{label:n(`providers.adapter`),children:t.adapterId}),(0,$.jsx)(k,{label:n(`providers.boundClients`),children:t.boundClients.map(e=>gt[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(Xn,{open:d,onOpenChange:f,onAdd:e=>h({endpoints:[...s.endpoints,e]})}),(0,$.jsx)(Zn,{open:p,onOpenChange:m,onAdd:e=>u([...l.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:_&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:n(`common.unsaved`)}),(0,$.jsx)(I,{size:`sm`,onClick:()=>{c(o),u(Object.entries(o.extraHeaders))},children:n(`common.revert`)}),(0,$.jsx)(I,{size:`sm`,variant:`primary`,loading:i.isPending,onClick:v,children:n(`common.save`)})]})})]})}function Xn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=E(),[i,a]=(0,Q.useState)(`openai-chat`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(s(``),l(!1))},[e]);let u=/^https?:\/\/\S+$/.test(o.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!u,onClick:()=>{n({protocol:i,baseUrl:o.trim(),...c?{fullUrl:!0}:{}}),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(A,{label:r(`providers.protocol`),children:(0,$.jsx)(q,{value:i,onChange:a,options:J})}),(0,$.jsx)(A,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`https://api.example.com/v1`,value:o,invalid:o!==``&&!u,onChange:e=>s(e.target.value)})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function Zn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=E(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(a(``),s(``))},[e]);let c=/^[A-Za-z0-9-]+$/.test(i.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!c,onClick:()=>{n([i.trim(),o]),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(A,{label:r(`providers.headerName`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(A,{label:r(`providers.headerValue`),children:(0,$.jsx)(D,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{Pn as ProviderDetailPage};
|
|
1
|
+
import{$n as e,An as t,At as n,Ba as r,Bn as i,Cn as a,Cr as o,Dt as s,Et as c,Gr as l,H as u,Hr as d,In as f,Jn as p,Kn as m,Kr as h,Lr as g,Mi as _,Ot as v,Pt as y,Q as b,Qr as ee,Qt as te,Ra as ne,Rn as re,Rt as ie,Sn as x,Ua as ae,Ur as S,V as oe,Wn as C,Xn as se,Xr as ce,Y as w,Zt as le,_ as ue,_n as de,_r as fe,a as pe,ar as me,b as T,bi as he,c as ge,cn as _e,cr as ve,ct as E,d as D,dt as O,f as k,gt as ye,h as be,hn as xe,ht as Se,i as Ce,ir as we,it as Te,jn as Ee,jr as De,jt as Oe,l as A,ln as ke,m as j,mr as Ae,n as M,nt as je,or as N,ot as P,p as F,pr as Me,qn as Ne,r as I,rt as Pe,t as L,u as R,un as Fe,ur as Ie,v as z,vi as Le,vn as Re,wi as ze,wn as Be,xt as B,y as V,yi as Ve,yn as H,za as He,zn as U}from"./alert-DpRdHImb.js";import{H as Ue,a as W,at as We,ct as Ge,et as Ke,i as G,n as qe,nt as Je,o as K,r as q,rt as Ye}from"./overlays-Ca_JSpnI.js";import{t as Xe}from"./arrow-down-BxJ88yaJ.js";import{t as Ze}from"./arrow-left-B3Ql-3af.js";import{a as Qe,i as $e,n as J,o as et,s as tt,t as Y}from"./ProvidersPage-D4cQrTgo.js";import{t as nt}from"./cloud-download-d2J3TjHp.js";import{t as rt}from"./download-BF1gj38s.js";import{t as it}from"./ellipsis-2ewY1Pkj.js";import{t as at}from"./external-link-Ba13ucfD.js";import{n as X}from"./radio-cards-CWs2Sjuq.js";import{t as ot}from"./log-out-DOtmyFi6.js";import{t as st}from"./power-10gcP_1M.js";import{t as ct}from"./rotate-ccw-C3uEcj_6.js";import{$ as lt,B as ut,C as dt,E as ft,H as pt,J as mt,P as Z,T as ht,_ as gt,a as _t,et as vt,h as yt,o as bt,q as xt,s as St,w as Ct}from"./index-YcD3CI_o.js";import{t as wt}from"./checkbox-3cbHcFXQ.js";import{t as Tt}from"./confirm-morph-Dpiz2iAT.js";var Et={name:`arrow-left-right`,size:24,node:[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]};Et.node;var Dt=B(Et),Ot={name:`arrow-right-left`,size:24,node:[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]};Ot.node;var kt=B(Ot),At={name:`gauge`,size:24,node:[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]};At.node;var jt=B(At),Mt={name:`gift`,size:24,node:[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8`,key:`1sqzm4`}],[`path`,{d:`M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5`,key:`kc0143`}],[`rect`,{x:`3`,y:`7`,width:`18`,height:`4`,rx:`1`,key:`1hberx`}]]};Mt.node;var Nt=B(Mt),Pt={name:`list-plus`,size:24,node:[[`path`,{d:`M16 5H3`,key:`m91uny`}],[`path`,{d:`M11 12H3`,key:`51ecnj`}],[`path`,{d:`M16 19H3`,key:`zzsher`}],[`path`,{d:`M18 9v6`,key:`1twb98`}],[`path`,{d:`M21 12h-6`,key:`bt1uis`}]]};Pt.node;var Ft=B(Pt),It={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};It.node;var Lt=B(It),Rt={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};Rt.node;var zt=B(Rt),Bt={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};Bt.node;var Vt=B(Bt),Ht={name:`ticket`,size:24,node:[[`path`,{d:`M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z`,key:`qn84l0`}],[`path`,{d:`M13 5v2`,key:`dyzc3o`}],[`path`,{d:`M13 17v2`,key:`1ont0d`}],[`path`,{d:`M13 11v2`,key:`1wjjxi`}]]};Ht.node;var Ut=B(Ht),Wt={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]};Wt.node;var Gt=B(Wt),Q=ae(r(),1),$=He();function Kt({usage:e,compact:t=!1}){let{t:n}=E(),r=[{label:n(`providers.usage.requests`),values:[e?.today.requests,e?.total.requests],format:(e,n=t)=>w(e,n)},{label:n(`providers.usage.tokens`),values:[e?.today.tokens,e?.total.tokens],format:(e,n=t)=>w(e,n)},{label:n(`providers.usage.cost`),values:[e?.today.costNanoUsd,e?.total.costNanoUsd],format:(e,n=t)=>b(Te(e),{compact:n})}];return(0,$.jsxs)(`table`,{className:P(`w-full table-fixed text-right tabular-nums`,t?`text-[11px]`:`text-[12px]`),"aria-label":n(`providers.usage.title`),children:[(0,$.jsx)(`thead`,{className:`text-[var(--text-muted)]`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-[34%] pb-1 text-left font-normal`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:n(`providers.usage.title`)})}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.today`)}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.total`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`py-0.5 text-left font-normal text-[var(--text-secondary)]`,children:e.label}),e.values.map((t,n)=>(0,$.jsx)(`td`,{className:`truncate py-0.5 pl-1 font-mono`,title:t==null?void 0:e.format(t,!1),children:t==null?`—`:e.format(t)},n))]},e.label))})]})}function qt({timeZone:e}){let{t}=E();return(0,$.jsxs)(`p`,{className:`text-[11px] leading-relaxed text-[var(--text-muted)]`,children:[t(`providers.usage.hint`),e&&(0,$.jsxs)($.Fragment,{children:[` `,t(`providers.usage.dayHint`,{zone:e})]})]})}var Jt=``,Yt=`custom`,Xt=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],Zt={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},Qt={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},$t=e=>JSON.stringify(e??{},null,2);function en(e){return{enabled:e.enabled,template:e.template??Jt,intervalMinutes:e.intervalMinutes??null,timeoutSec:e.timeoutSec,baseUrl:e.baseUrl??``,params:{...e.params},secrets:{},method:e.request?.method??`GET`,url:e.request?.url??``,auth:e.request?.auth??`provider`,headers:$t(e.request?.headers),extract:e.extract?$t(e.extract):``}}function tn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function nn({provider:e}){let{t}=E(),{toast:n}=K(),r=Ie(),i=De(e.id),a=ee(e.id),o=H(),s=e.quotaConfig,c=(0,Q.useMemo)(()=>en(s),[s]),[l,u]=(0,Q.useState)(c),[d,f]=(0,Q.useState)(null);(0,Q.useEffect)(()=>u(c),[c]);let p=r.data??[],m=p.find(e=>e.id===s.suggestedTemplate),h=l.template===Jt?m:p.find(e=>e.id===l.template),g=l.template===Yt,_=g?Xt:h?.params??[],v=e=>u(t=>({...t,...e})),y=JSON.stringify(l)!==JSON.stringify(c),b=e=>{if(e!==Yt||l.url)return v({template:e});let t=h??m;v({template:e,method:t?.request.method??Zt.method,url:t?.request.url??Zt.url,auth:t?.request.auth??Zt.auth,headers:$t(t?.request.headers??Zt.headers),extract:$t(t?.extract??Qt)})},te=()=>{let e={enabled:l.enabled,template:l.template===Jt?null:l.template,intervalMinutes:l.intervalMinutes,timeoutSec:l.timeoutSec??10,baseUrl:l.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(l.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(l.secrets).filter(([,e])=>e.trim()!==``))};if(g){let r=tn(l.headers),i=tn(l.extract);if(!r||!i)return n(t(`providers.quota.invalidJson`,{field:t(r?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:l.method,url:l.url.trim(),auth:l.auth,headers:r},e.extract=i}return e},ne=()=>{let r=te();if(!r)return;let a=r.enabled&&!s.enabled;i.mutate(r,{onSuccess:()=>{n(t(`common.saved`),`success`),a&&o.mutate(e.id,{onError:e=>n(W(e),`error`)})},onError:e=>n(W(e),`error`)})},re=()=>{let e=te();e&&a.mutate(e,{onSuccess:f,onError:e=>n(W(e),`error`)})},ie=s.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:s.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),x=[{value:Jt,label:m?t(`providers.quota.templateAuto`,{name:m.name}):t(`providers.quota.templateNone`)},...p.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:Yt,label:t(`providers.quota.custom`)}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,$.jsx)(j,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,$.jsx)(V,{checked:l.enabled,label:t(`providers.quota.enable`),onChange:e=>v({enabled:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.template`),children:(0,$.jsx)(q,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:l.template,onChange:b,options:x})}),_.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=s.secrets.includes(e.name);return e.secret?(0,$.jsx)(j,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,$.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:l.secrets[e.name]??``,onChange:t=>v({secrets:{...l.secrets,[e.name]:t.target.value}})})},e.name):(0,$.jsx)(j,{label:n,children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":n,value:l.params[e.name]??``,onChange:t=>v({params:{...l.params,[e.name]:t.target.value}})})},e.name)}),_.length>0&&(0,$.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),g&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:l.method,onChange:e=>v({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:l.url,onChange:e=>v({url:e.target.value})}),(0,$.jsx)(q,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:l.auth,onChange:e=>v({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,$.jsx)(T,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:l.headers,onChange:e=>v({headers:e.target.value})}),(0,$.jsx)(T,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:l.extract,onChange:e=>v({extract:e.target.value})}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,$.jsx)(j,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:ie}),children:(0,$.jsx)(F,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:l.intervalMinutes,onChange:e=>v({intervalMinutes:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.timeout`),children:(0,$.jsx)(F,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:l.timeoutSec,onChange:e=>v({timeoutSec:e})})}),(0,$.jsx)(j,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:l.baseUrl,onChange:e=>v({baseUrl:e.target.value})})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(I,{size:`sm`,variant:`primary`,disabled:!y,loading:i.isPending,onClick:ne,children:t(`common.save`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(X,{className:`size-3.5`}),loading:a.isPending,onClick:re,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:y,loading:o.isPending,onClick:()=>o.mutate(e.id,{onError:e=>n(W(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsx)(rn,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,$.jsx)(G,{open:d!==null,onOpenChange:e=>!e&&f(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:d&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(L,{tone:d.ok?`success`:`danger`,title:d.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!d.ok&&Ke({code:d.errorCode??null,message:d.error??``},t),!d.ok&&d.error&&d.errorCode&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:d.error})]}),d.url&&(0,$.jsx)(k,{label:t(`providers.quota.requestUrl`),mono:!0,children:d.url}),d.httpStatus!=null&&(0,$.jsx)(k,{label:t(`providers.quota.httpStatus`),children:d.httpStatus}),d.snapshot&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,$.jsx)(rn,{snapshot:d.snapshot})]}),d.raw!==void 0&&d.raw!==null&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,$.jsx)(Ce,{children:$t(d.raw)})]})]})})]})}function rn({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=E(),i=We(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,$.jsxs)(L,{tone:`warning`,title:n(`providers.quota.failed`,{error:Ke(i,n)}),children:[(0,$.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,$.jsx)(L,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,$.jsx)(M,{children:e.name}),(0,$.jsx)(`span`,{className:`num`,children:Je(e,n,r)??`—`}),Ye(e,n,r)&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:Ye(e,n,r)}),e.extra&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,$.jsx)(M,{tone:`accent`,children:e.planLabel}),o>0&&(0,$.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:Ue(o,r,n(`tray.justNow`))??``})})]})]})}var an={imported:`providers.subscription.importBatchStatus.imported`,updated:`providers.subscription.importBatchStatus.updated`,duplicate:`providers.subscription.importBatchStatus.duplicate`,invalid_format:`providers.subscription.importBatchStatus.invalid_format`,failed:`providers.subscription.importBatchStatus.failed`,ready:`providers.subscription.importBatchStatus.ready`},on={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},sn={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function cn(e){return e.split(/[,\s]+/).flatMap(e=>{let t=e.replace(/^["']+|["']+$/g,``);return t.startsWith(`tid=`)||t.startsWith(`exp=`)?[t]:t.split(`;`)}).filter(e=>e.replace(/^["']+|["']+$/g,``).length>0).length}function ln(e){let t=e.trim();if(t.length===0)return 0;if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e.filter(e=>typeof e==`object`&&!!e||typeof e==`string`&&e.trim().length>0).length;if(typeof e==`object`&&e)return 1}catch{}let n=0;for(let t of e.split(`
|
|
2
|
+
`)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:cn(e))}return n}function un({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=E(),{toast:o}=K(),s=x(e),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),m=(0,Q.useMemo)(()=>ln(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),p(null))},[n]),n===null)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let h=n===`apiKey`,g=h?t.formats.filter(e=>e.endsWith(`-api-key`)):t.formats,_=!h&&t.formats.some(e=>e.includes(`refresh-token`)||e.endsWith(`-json`)),v=a(h?`providers.accounts.import.apiKeyLabel`:`providers.accounts.import.label`),y=e=>s.mutate({text:c,asApiKey:h||void 0,dryRun:e||void 0,httpProxy:u.trim()||void 0},{onSuccess:t=>{p({...t,dryRun:e}),!e&&(o(a(`providers.accounts.import.summary`,{ok:t.imported,dup:t.duplicates,fail:t.failed}),t.failed>0?`info`:`success`),!(t.failed>0)&&(n===`batch`?l(``):i()))},onError:e=>o(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:a(sn[n]),description:a(`providers.accounts.import.desc`),width:560,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[g.length>0&&(0,$.jsx)(`p`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:a(`providers.accounts.import.formats`,{formats:g.map(e=>a(`providers.accounts.format.${e}`)).join(` · `)})}),(0,$.jsx)(T,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(D,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:u,onChange:e=>d(e.target.value)}),_&&(0,$.jsx)(L,{tone:`info`,title:a(`providers.accounts.import.rotateWarning`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.import.count`,{n:m})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[n===`batch`&&(0,$.jsx)(I,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>y(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(I,{variant:`primary`,disabled:m===0||m>t.maxBatch,loading:s.isPending&&!s.variables?.dryRun,onClick:()=>y(!1),children:a(`providers.accounts.import.run`)})]})]}),f&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[12px] font-medium`,children:a(f.dryRun?`providers.accounts.import.previewSummary`:`providers.accounts.import.summary`,{ok:f.imported,dup:f.duplicates,fail:f.failed})}),(0,$.jsx)(`ul`,{className:`card max-h-72 divide-y divide-[var(--border)] overflow-auto`,children:f.items.map(e=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`w-6 shrink-0 text-[var(--text-muted)]`,children:e.index}),(0,$.jsx)(`span`,{className:`selectable w-28 shrink-0 truncate font-mono`,children:e.source}),(0,$.jsx)(M,{tone:on[e.status],children:a(an[e.status])}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.credential.${e.kind}`)}),(0,$.jsx)(`span`,{className:`selectable min-w-0 flex-1 break-words text-[var(--text-secondary)]`,children:e.account?.displayName&&(e.status===`imported`||e.status===`updated`)?`${e.account.displayName}${e.message?` · ${e.message}`:``}`:e.message??``})]},e.index))})]})]})})}function dn(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var fn={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},pn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function mn(e,t){let n=(e??``).toLowerCase(),r=t?`110,115,135`:/max|ultra/.test(n)?`47,124,246`:/pro|plus|premium/.test(n)?`52,195,143`:/team|business|enterprise|allegro|vivace/.test(n)?`130,100,230`:`110,115,135`;return`linear-gradient(135deg, rgba(${r},.34), rgba(${r},.08))`}function hn({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s,usage:c}){let{t:l,locale:d}=E(),f=dn(e),p=e.displayName||e.accountEmail||e.keyMasked||e.id,m=e.kind===`api_key`,h=e.plan?.trim(),g=f===`cooling`?{text:l(`providers.subscription.cooldown`,{when:u(e.cooldownUntilUtc,d)}),tone:`var(--warning)`}:f===`dead`?{text:e.lastError||l(pn[e.status]),tone:`var(--danger)`}:m?{text:e.keyMasked??l(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:l(`providers.accounts.expiresAt`,{when:u(e.expiresAtUtc,d)}),tone:void 0}:null,_=[{id:`activate`,label:l(`providers.subscription.activate`),icon:(0,$.jsx)(kt,{className:`size-3.5`}),disabled:e.isCurrent||f===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:l(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(st,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:l(`providers.subscription.moveUp`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:l(`providers.subscription.moveDown`),icon:(0,$.jsx)(Xe,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:l(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:f===`dead`,onSelect:()=>n.refreshQuota(e)},...m?[]:[{id:`refresh`,label:l(`providers.subscription.refreshToken`),icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:l(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],{id:`remove`,label:l(`providers.subscription.logout`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],v=l(f===`disabled`?`providers.subscription.disabled`:pn[e.status]),y=l(m?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`),b=e.quota?.session?.usedPercent!=null||e.quota?.weekly?.usedPercent!=null||e.quota?.credits?.usedPercent!=null;return(0,$.jsxs)(`div`,{"data-testid":`account-card`,className:P(`group card relative flex min-h-[292px] min-w-0 cursor-pointer flex-col overflow-hidden transition-colors hover:bg-[var(--fill)]`,e.isCurrent&&`ring-1 ring-[var(--accent)]`,r&&`bg-[var(--accent-subtle)]`,f===`disabled`&&`opacity-55`),onClick:()=>i?a(e.id):n.open(e),children:[(0,$.jsxs)(`div`,{className:`relative shrink-0 px-3 pb-3 pt-2.5`,style:{background:mn(h,m)},children:[(f===`cooling`||f===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:fn[f]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:P(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(wt,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":l(`providers.accounts.select`,{name:p})})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{role:`img`,"aria-label":v,className:`size-1.5 shrink-0 rounded-full`,style:{background:fn[f]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:v})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${l(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(Se,{className:`size-3.5`,"aria-label":l(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(qe,{iconOnly:!0,label:l(`common.more`),icon:(0,$.jsx)(it,{className:`size-4`}),items:_})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 truncate text-[17px] font-bold tracking-[.01em]`,title:h||y,children:h||y})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col px-3 pb-3 pt-2.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-[13px] font-medium outline-none focus-visible:underline`,title:p,onClick:t=>{t.stopPropagation(),i?a(e.id):n.open(e)},children:p}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 items-center gap-1 whitespace-nowrap text-[11px] text-[var(--text-muted)]`,children:[e.isCurrent&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[var(--success)]`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`●`}),(0,$.jsx)(`span`,{children:l(`providers.subscription.current`)})]}),e.isCurrent&&(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`shrink-0`,children:y}),e.source&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,children:l(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:l(`providers.accounts.order`,{n:t+1})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 min-h-[28px]`,children:g&&(f===`cooling`||f===`dead`||!b)&&(0,$.jsx)(`div`,{className:`line-clamp-2 text-[11px] leading-snug`,style:{color:g.tone??`var(--text-muted)`},title:g.text,children:g.text})}),(0,$.jsx)(`div`,{className:`mt-3 shrink-0 border-t border-[var(--border-subtle)] pt-2`,children:(0,$.jsx)(Kt,{usage:c,compact:!0})}),f===`dead`?(0,$.jsxs)(`div`,{className:`mt-auto flex items-center gap-2 pt-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:l(`providers.accounts.signedOut`)}),!m&&(0,$.jsx)(I,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:l(`providers.subscription.relogin`)})]}):(0,$.jsx)(_n,{quota:e.quota??null,pending:s})]})]})}var gn=10;function _n({quota:e,pending:t}){let{t:n,locale:r}=E(),i=[];return e?.session?.usedPercent!=null&&i.push({key:`session`,label:e.session.windowMinutes?`${Math.round(e.session.windowMinutes/60)}h`:n(`providers.accounts.quotaShortSession`),percent:e.session.usedPercent,reset:e.session.resetsAtUtc}),e?.weekly?.usedPercent!=null&&i.push({key:`weekly`,label:n(`providers.accounts.quotaShortWeekly`),percent:e.weekly.usedPercent,reset:e.weekly.resetsAtUtc}),i.length<2&&e?.credits?.usedPercent!=null&&i.push({key:`credits`,label:n(e.entitlement==null?`providers.accounts.quotaShortCredits`:`providers.accounts.quotaShortPremium`),percent:e.credits.usedPercent,reset:e.credits.resetsAtUtc}),i.length===0?null:(0,$.jsx)(`div`,{className:P(`mt-auto flex flex-col gap-2 pt-2`,t&&`opacity-60`),children:i.slice(0,2).map(e=>{let t=Math.max(0,Math.min(100,Math.round(e.percent))),i=t>=90?`var(--danger)`:t>=70?`var(--warning)`:`var(--accent)`,a=Math.round(t/100*gn),o=e.reset?n(`providers.subscription.quotaResets`,{when:u(e.reset,r)}):void 0;return(0,$.jsxs)(`div`,{className:`min-w-0`,title:o,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[t,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-label":e.label,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,className:`mt-0.5 flex gap-[3px]`,children:Array.from({length:gn},(e,t)=>(0,$.jsx)(`i`,{className:`h-[5px] flex-1 rounded-[2px] bg-[var(--surface-muted)]`,style:t<a?{background:i}:void 0},t))})]},e.key)})})}function vn({quota:e,className:t}){let{t:n,locale:r}=E(),i=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:n(`providers.subscription.quotaResets`,{when:t.toLocaleString(r)})},a=[];e.session?.usedPercent!=null&&a.push({key:`session`,label:n(`providers.subscription.quotaWindowSession`),window:e.session}),e.weekly?.usedPercent!=null&&a.push({key:`weekly`,label:n(`providers.subscription.quotaWindowWeekly`),window:e.weekly}),e.credits?.usedPercent!=null&&a.push({key:`credits`,label:e.entitlement==null?n(`providers.subscription.quotaWindowCredits`):n(`providers.subscription.quotaWindowPremium`),window:{usedPercent:e.credits.usedPercent,resetsAtUtc:e.credits.resetsAtUtc??null}});let o=e.credits?.prepaidBalance==null?null:n(`providers.subscription.quotaBalance`,{balance:e.credits.prepaidBalance}),s=e.entitlement!=null&&e.entitlement>=0?[n(`providers.subscription.quotaPremiumCount`,{used:Math.max(0,(e.entitlement??0)-(e.remaining??0)),total:e.entitlement}),e.overageUsed?n(`providers.subscription.quotaOverage`,{count:e.overageUsed}):null,e.overagePermitted===!1?n(`providers.subscription.quotaOverageOff`):null].filter(Boolean).join(` · `):null,c=e.planLabel??(e.fetchedAtUtc?n(`providers.subscription.quotaFetchedAt`,{when:new Date(e.fetchedAtUtc).toLocaleString(r)}):null);return(0,$.jsx)(`div`,{className:P(`px-4 py-1`,t),children:(0,$.jsxs)(`div`,{className:`card flex flex-col gap-3 p-3`,children:[(c||o)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] text-[var(--text-secondary)]`,children:[c&&(0,$.jsx)(`span`,{children:c}),o&&(0,$.jsx)(`span`,{children:o})]}),a.length===0?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.subscription.quotaNoWindows`)}):a.map(e=>(0,$.jsx)(yn,{label:e.label,window:e.window,reset:i(e.window.resetsAtUtc)},e.key)),s&&(0,$.jsx)(`div`,{className:`text-[10.5px] text-[var(--text-muted)]`,children:s})]})})}function yn({label:e,window:t,reset:n}){let r=Math.max(0,Math.min(100,Math.round(t.usedPercent??0))),[i,a]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches){a(r);return}let e=requestAnimationFrame(()=>a(r));return()=>cancelAnimationFrame(e)},[r]);let o=r>=90?`var(--danger)`:r>=70?`var(--warning)`:`var(--accent)`,s=t.windowMinutes?Math.round(t.windowMinutes/60):null;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,$.jsxs)(`span`,{className:`text-[var(--text-secondary)]`,children:[e,s!=null&&(0,$.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[` · `,s,`h`]})]}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[r,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":e,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface-muted)]`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-[width] duration-500 ease-out`,style:{width:`${i}%`,background:o}})}),n&&(0,$.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n})]})}var bn={available:`green`,redeemed:`neutral`,expired:`orange`};function xn({account:e,providerId:t}){let{t:n}=E(),{toast:r,confirm:i}=K(),a=o(e.id,e.status===`active`),s=te(t),c=a.data?.credits??[],l=a.data?.available_count??c.filter(e=>e.status===`available`).length,u=async t=>{await i({title:n(`providers.subscription.credits.consumeConfirm`,{title:t.title??t.reset_type??``}),detail:n(`providers.subscription.credits.consumeDetail`),confirmLabel:n(`providers.subscription.credits.consume`),destructive:!0})&&s.mutate({accountId:e.id,creditId:t.id},{onSuccess:()=>r(n(`providers.subscription.credits.consumed`),`success`),onError:e=>r(e instanceof _&&e.status===409?W(e):`${n(`providers.subscription.credits.consumeFailed`)}:${W(e)}`,`error`)})};return(0,$.jsxs)(R,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(z,{className:`my-4`}),a.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.unavailable`)}),a.data&&c.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.none`)}),c.map(e=>{let t=e.status!==`available`;return(0,$.jsxs)(j,{className:P(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Nt,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?n(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?n(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?n(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(M,{tone:bn[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ut,{className:`size-3.5`}),disabled:t,loading:s.isPending&&s.variables?.creditId===e.id,onClick:()=>void u(e),children:n(`providers.subscription.credits.consume`)})]},e.id)}),a.data&&c.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`providers.subscription.credits.availableCount`,{count:l})})]})}var Sn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Cn({provider:e,account:t,index:n,actions:r,onClose:i,usage:a,usageTimeZone:o}){let{t:s,locale:c}=E(),{toast:l}=K(),d=Ve(e.id),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(``);if((0,Q.useEffect)(()=>{p(t?.displayName??``),h(t?.httpProxy??``)},[t?.id,t?.displayName,t?.httpProxy]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let g=dn(t),_=t.kind===`api_key`,v=e.templateId===`openai-subscription`,y=e.httpProxy||s(`providers.accounts.proxyFallbackSystem`),b=e=>e?u(e,c):`—`,ee=(e,n)=>d.mutate({id:t.id,...e},{onSuccess:()=>l(s(n),`success`),onError:e=>l(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,s(_?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`)].filter(Boolean).join(` · `),width:520,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(kt,{className:`size-3.5`}),disabled:t.isCurrent||g===`dead`,onClick:()=>r.activate(t),children:s(`providers.subscription.activate`)}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(jt,{className:`size-3.5`}),disabled:g===`dead`,onClick:()=>r.refreshQuota(t),children:s(`providers.subscription.quotaRefresh`)}),!_&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:s(`providers.subscription.refreshToken`)}),!_&&t.status!==`active`&&(0,$.jsx)(I,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:s(`providers.subscription.relogin`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),onClick:()=>r.remove(t),children:s(`providers.subscription.logout`)})]}),g===`dead`&&t.lastError&&(0,$.jsx)(L,{tone:`danger`,title:t.lastError}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.usage.title`)}),(0,$.jsx)(`div`,{className:`card px-3 py-2`,children:(0,$.jsx)(Kt,{usage:a})}),(0,$.jsx)(qt,{timeZone:o})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(D,{className:`flex-1`,label:s(`providers.accounts.detail.name`),value:f,onChange:e=>p(e.target.value)}),(0,$.jsx)(I,{disabled:f.trim().length===0||f.trim()===t.displayName,loading:d.isPending&&d.variables?.displayName!==void 0,onClick:()=>ee({displayName:f.trim()},`providers.accounts.renamed`),children:s(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(D,{className:`flex-1`,mono:!0,label:s(`providers.accounts.detail.proxy`),placeholder:y,value:m,onChange:e=>h(e.target.value)}),(0,$.jsx)(I,{disabled:m.trim()===(t.httpProxy??``),loading:d.isPending&&d.variables?.httpProxy!==void 0,onClick:()=>ee({httpProxy:m.trim()},`providers.accounts.proxySaved`),children:s(`common.save`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:s(`providers.accounts.detail.proxyHint`,{fallback:y})})]}),t.quota&&(0,$.jsxs)(`section`,{className:`-mx-4 flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`px-4 text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.quota`)}),(0,$.jsx)(vn,{quota:t.quota})]}),v&&g!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(xn,{account:t,providerId:e.id})}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.credentials`)}),(0,$.jsxs)(`div`,{className:`card divide-y divide-[var(--border)] px-3`,children:[(0,$.jsx)(k,{label:s(`providers.accounts.detail.status`),children:(0,$.jsx)(M,{tone:g===`usable`?`green`:g===`cooling`?`orange`:g===`dead`?`red`:`neutral`,children:s(g===`disabled`?`providers.subscription.disabled`:Sn[t.status])})}),t.source&&(0,$.jsx)(k,{label:s(`providers.accounts.detail.source`),children:s(`providers.accounts.source.${t.source}`)}),_?(0,$.jsx)(k,{label:s(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:s(`providers.accounts.detail.expires`),children:b(t.expiresAtUtc)}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.lastRefresh`),children:b(t.lastRefreshAtUtc)})]}),g===`cooling`&&(0,$.jsx)(k,{label:s(`providers.accounts.filter.cooling`),children:b(t.cooldownUntilUtc)}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.order`),children:s(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(k,{label:s(`providers.accounts.detail.created`),children:b(t.createdAt)}),t.lastError&&g!==`dead`&&(0,$.jsx)(k,{label:s(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function wn({provider:e}){let{t}=E(),{toast:n}=K(),r=e.authScheme===`oauth-subscription`,i=h(e.id,r),a=ze(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(W(e),`error`)}),c=o.claudeSubscription||o.clientPolicy===`claude-code-only`;return!c&&!o.claudeSubscription?null:(0,$.jsxs)(R,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[c&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:o.clientPolicy===`claude-code-only`,disabled:a.isPending,onChange:e=>s({clientPolicy:e?`claude-code-only`:`any`})})}),o.claudeSubscription&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.mimic`),checked:o.mimicClaudeCode,disabled:a.isPending,onChange:e=>s({mimicClaudeCode:e})})}),c&&o.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:o.mimicClaudeCode?(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Tn=[{value:`all`,label:`providers.accounts.filter.all`},{value:`usable`,label:`providers.accounts.filter.usable`},{value:`cooling`,label:`providers.accounts.filter.cooling`},{value:`dead`,label:`providers.accounts.filter.dead`},{value:`disabled`,label:`providers.accounts.filter.disabled`}],En=3e5;function Dn({provider:e}){let{t:r}=E(),{toast:i,confirm:o}=K(),s=ne(),l=e.authScheme===`oauth-subscription`,u=me(e.id,l),d=ve(e.id,l),f=h(e.id,l),p=ze(e.id),m=n(e.id,l),g=S(e.id),v=se(e.id),y=le(e.id),b=Re(e.id),ee=Me(e.id),te=ke(e.id),re=de(e.id),ie=Oe(e.id),x=Ve(e.id),ae=fe(e.id),oe=e.templateId===`openai-subscription`,C=t(l&&oe),ce=a(e.id),w=e.templateId===`github-copilot-subscription`,ue=Ee(l&&w),pe=Be(e.id),[T,he]=(0,Q.useState)(`all`),[ge,_e]=(0,Q.useState)(``),[O,k]=(0,Q.useState)(new Set),[ye,xe]=(0,Q.useState)(null),[Se,Ce]=(0,Q.useState)(null),[we,Te]=(0,Q.useState)(!1),[De,A]=(0,Q.useState)(``),[j,Ae]=(0,Q.useState)(!1),[M,je]=(0,Q.useState)(!1),[N,F]=(0,Q.useState)(null),[Ne,Pe]=(0,Q.useState)(null),[R,Fe]=(0,Q.useState)(!1),[Ie,Le]=(0,Q.useState)(``),B=(0,Q.useRef)(new Set),V=(0,Q.useRef)(new Set),H=(0,Q.useMemo)(()=>u.data??[],[u.data]);if((0,Q.useEffect)(()=>{if(l)for(let e of H){if(e.status!==`active`||V.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<En||(V.current.add(e.id),b.mutate(e.id,{onError:()=>{}}))}},[H,l]),(0,Q.useEffect)(()=>{let e=new Set(H.map(e=>e.id));k(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),ye&&!e.has(ye)&&xe(null)},[H,ye]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`pkce`)return;let e=setInterval(()=>void u.refetch(),3e3);return()=>clearInterval(e)},[M,N,u]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`pkce`)return;let e=H.find(e=>!B.current.has(e.id));e&&U(!0,e.displayName||e.accountEmail||e.id)},[H,M,N]),(0,Q.useEffect)(()=>{if(!M||N?.mode!==`device`&&N?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await v.mutateAsync(N.state);if(e)return;t=0,n.status===`done`?U(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&U(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof _&&(n.status===404||n.status===400)){U(!1,void 0,W(n));return}++t>=5&&U(!1,void 0,W(n))}},r=setInterval(()=>void n(),Math.max(N.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[M,N]),!l)return null;let He=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,U=(t,n,a)=>{if(s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),t){F(null),Pe(null),je(!1),i(r(`providers.subscription.loginOk`,{name:n??``}),`success`);return}a&&Pe(a)},Ue=(e,t)=>{B.current=new Set(H.map(e=>e.id)),Pe(null),g.mutate({accountId:e,httpProxy:t},{onSuccess:e=>{Te(!1),F(e),je(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof _&&e.details?.needsVerification?i(r(`providers.subscription.needsVerification`),`error`):i(W(e),`error`)}})},We=async()=>{if(N){Fe(!0);try{let e=await v.mutateAsync(N.state);e.status===`done`?U(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?i(r(`providers.subscription.stillWaiting`),`info`):U(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof _&&e.status===404){let t=((await u.refetch()).data??[]).find(e=>!B.current.has(e.id));t?U(!0,t.displayName||t.accountEmail||t.id):U(!1,void 0,W(e))}else U(!1,void 0,W(e))}finally{Fe(!1)}}},Ke=async()=>{if(N&&N.mode===`paste`&&Ie.trim().length!==0){Fe(!0);try{let e=await y.mutateAsync({state:N.state,code:Ie.trim()});e.status===`done`?(Le(``),U(!0,e.account.displayName||e.account.accountEmail||e.account.id)):U(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){U(!1,void 0,W(e))}finally{Fe(!1)}}},Je=()=>ce.mutate(void 0,{onSuccess:e=>{i(r(`providers.subscription.importOk`,{name:He(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`),C.refetch()},onError:e=>i(W(e),`error`)}),q=()=>pe.mutate(``,{onSuccess:e=>{i(r(`providers.subscription.importOk`,{name:He(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`)},onError:e=>i(W(e),`error`)}),Ye=(e,t)=>{let n=H.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],ae.mutate(n,{onError:e=>i(W(e),`error`)}))},Xe=async()=>{if(await o({title:r(`providers.accounts.exportConfirm`),detail:r(`providers.accounts.exportDetail`),confirmLabel:r(`providers.accounts.export`)}))try{let e=await re.mutateAsync();if(e.count===0){i(r(`providers.accounts.exportNone`),`info`);return}if(!await Ge.copy(e.text)){i(r(`providers.accounts.exportCopyFailed`),`error`);return}i(r(`providers.accounts.exportDone`,{n:e.count})+(e.skipped>0?r(`providers.accounts.exportSkipped`,{n:e.skipped}):``),`success`)}catch(e){i(W(e),`error`)}},Ze=async e=>{let t=He(e);await o({title:r(`providers.subscription.logoutConfirm`,{name:t}),destructive:!0,confirmLabel:r(`providers.subscription.logout`)})&&te.mutate(e.id,{onError:e=>i(W(e),`error`)})},Qe={open:e=>xe(e.id),activate:e=>ie.mutate(e.id,{onSuccess:()=>i(r(`providers.subscription.activated`,{name:He(e)}),`success`),onError:e=>i(W(e),`error`)}),toggleEnabled:e=>x.mutate({id:e.id,enabled:!e.enabled},{onError:e=>i(W(e),`error`)}),refreshQuota:e=>b.mutate(e.id,{onError:e=>{e instanceof _&&e.status===501?i(r(`providers.subscription.quotaUnsupported`),`error`):i(W(e),`error`)}}),refreshToken:e=>ee.mutate(e.id,{onSuccess:()=>i(r(`providers.subscription.tokenRefreshed`),`success`),onError:e=>i(W(e),`error`)}),relogin:e=>Ue(e.id),remove:e=>void Ze(e)},$e=e=>k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),J=async t=>{let n=H.filter(e=>O.has(e.id));Ae(!0);let a=0;for(let e of n)try{await t(e),a++}catch(t){i(`${He(e)}: ${W(t)}`,`error`)}Ae(!1),k(new Set),s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),a>0&&i(r(`providers.accounts.bulkDone`,{n:a}),`success`)},et=async()=>{await o({title:r(`providers.accounts.bulkDeleteConfirm`,{n:O.size}),detail:r(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:r(`common.delete`)})&&await J(e=>te.mutateAsync(e.id))},tt=H.map(e=>dn(e)),Y=e=>e===`all`?H.length:tt.filter(t=>t===e).length,nt=ge.trim().toLowerCase(),it=H.map((e,t)=>({a:e,index:t,state:tt[t]})).filter(({a:e,state:t})=>(T===`all`||t===T)&&(nt.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes(nt)))),at=H.find(e=>e.id===ye)??null,X=m.data,ot=O.size>0,ct=[{id:`login`,label:r(`providers.accounts.addLogin`),icon:(0,$.jsx)(Lt,{className:`size-3.5`}),onSelect:()=>Ue()},{id:`login-proxy`,label:r(`providers.accounts.addLoginProxy`),onSelect:()=>Te(!0)},...oe&&C.data?.available?[{id:`codex`,separatorBefore:!0,label:r(`providers.subscription.importCodex`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),onSelect:Je}]:[],...w?[{id:`copilot`,separatorBefore:!0,label:r(`providers.subscription.importCopilot`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),onSelect:q}]:[],...X?.supported?[{id:`token`,separatorBefore:!(oe&&C.data?.available)&&!w,label:r(`providers.accounts.addToken`),onSelect:()=>Ce(`token`)}]:[],...X?.apiKey?[{id:`apikey`,label:r(`providers.accounts.addApiKey`),icon:(0,$.jsx)(pt,{className:`size-3.5`}),onSelect:()=>Ce(`apiKey`)}]:[]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`card mb-3 flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`mr-auto flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[var(--text)]`,children:r(`providers.accounts.statTotal`,{n:H.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:r(`providers.accounts.statUsable`,{n:Y(`usable`)})}),Y(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:r(`providers.accounts.statCooling`,{n:Y(`cooling`)})}),Y(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:r(`providers.accounts.statDead`,{n:Y(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`providers.accounts.providerProxy`,{proxy:e.httpProxy||r(`providers.accounts.proxyFallbackSystem`)})})]}),f.data&&(0,$.jsx)(On,{policy:f.data,onChange:e=>p.mutate({switchMode:e},{onError:e=>i(W(e),`error`)})})]}),f.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:r(f.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:f.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(be,{className:`w-52`,value:ge,onChange:_e,placeholder:r(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":r(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Tn.filter(e=>e.value===`all`||Y(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":T===e.value,onClick:()=>he(e.value),className:P(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,T===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[r(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:Y(e.value)})]},e.value))}),X?.supported&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(Ft,{className:`size-3.5`}),onClick:()=>Ce(`batch`),children:r(`providers.accounts.batchImport`)}),X?.supported&&H.length>0&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(Gt,{className:`size-3.5`}),disabled:re.isPending,onClick:()=>void Xe(),children:r(`providers.accounts.export`)}),(0,$.jsx)(qe,{label:r(`providers.accounts.add`),icon:(0,$.jsx)(ut,{className:`size-3.5`}),items:ct})]}),oe&&C.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[r(`providers.subscription.localCodexFound`,{who:C.data.accountEmail??C.data.plan??r(`providers.subscription.unknownAccount`)}),C.data.detail?` · ${C.data.detail}`:``]}),w&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[ue.data?.available?r(`providers.subscription.localCopilotFound`,{source:ue.data.source??``}):r(`providers.subscription.localCopilotHint`),ue.data?.detail?` · ${ue.data.detail}`:``]}),u.isLoading?(0,$.jsx)(z,{className:`my-4`}):H.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Ue(),className:`flex w-full flex-col items-center gap-1 rounded-[var(--radius-card,12px)] border border-dashed border-[var(--border)] px-4 py-6 text-[12px] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--text)]`,children:[(0,$.jsx)(`span`,{children:r(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(ut,{className:`size-3.5`}),` `,r(`providers.subscription.login`)]})]}):it.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:r(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:it.map(({a:e,index:t})=>(0,$.jsx)(hn,{account:e,usage:d.data?.accounts.find(t=>t.accountId===e.id),index:t,actions:Qe,selected:O.has(e.id),selecting:ot,onToggleSelect:$e,quotaPending:b.isPending&&b.variables===e.id,onMove:H.length>1?{up:t>0?()=>Ye(t,-1):void 0,down:t<H.length-1?()=>Ye(t,1):void 0}:void 0},e.id))}),d.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`providers.usage.error`),children:W(d.error)}),H.length>0&&(0,$.jsx)(qt,{timeZone:d.data?.timeZone}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:r(`providers.subscription.footer`)}),ot&&(0,$.jsxs)(`div`,{className:`card sticky bottom-3 z-10 mt-3 flex flex-wrap items-center gap-1.5 px-3 py-1.5 shadow-lg`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[12px] text-[var(--text-secondary)]`,children:r(`providers.accounts.selected`,{n:O.size})}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(st,{className:`size-3.5`}),disabled:j,onClick:()=>void J(e=>x.mutateAsync({id:e.id,enabled:!0})),children:r(`providers.subscription.enable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>x.mutateAsync({id:e.id,enabled:!1})),children:r(`providers.subscription.disable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>b.mutateAsync(e.id)),children:r(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(I,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:j,onClick:()=>void et(),children:r(`common.delete`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>k(new Set),children:r(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(wn,{provider:e})}),(0,$.jsx)(Cn,{provider:e,account:at,usage:d.data?.accounts.find(e=>e.accountId===at?.id),usageTimeZone:d.data?.timeZone,index:at?H.indexOf(at):0,actions:Qe,onClose:()=>xe(null)}),X&&(0,$.jsx)(un,{providerId:e.id,info:X,mode:Se,providerProxy:e.httpProxy,onClose:()=>Ce(null)}),(0,$.jsx)(G,{open:we,onOpenChange:Te,title:r(`providers.accounts.loginProxyTitle`),description:r(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(I,{variant:`primary`,loading:g.isPending,disabled:De.trim().length===0,onClick:()=>Ue(void 0,De),children:r(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(D,{mono:!0,label:r(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:De,onChange:e=>A(e.target.value)})}),(0,$.jsxs)(G,{open:M,onOpenChange:e=>{je(e),e||(F(null),Pe(null))},title:r(`providers.subscription.login`),description:r(`providers.subscription.loginDesc`),children:[Ne&&(0,$.jsx)(L,{tone:`danger`,title:r(`providers.subscription.loginFailed`),children:Ne}),N?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.pasteTitle`),children:r(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(D,{mono:!0,value:Ie,onChange:e=>Le(e.target.value),placeholder:r(`providers.subscription.pastePlaceholder`),"aria-label":r(`providers.subscription.pasteCode`)}),(0,$.jsx)(I,{variant:`primary`,loading:R,onClick:()=>void Ke(),children:r(`providers.subscription.pasteSubmit`)})]}),N?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)}),(0,$.jsx)(I,{variant:`primary`,onClick:()=>{s.invalidateQueries({queryKey:c.providerAccounts(e.id)}),u.refetch()},children:r(`providers.subscription.doneAuthorize`)})]})]}),N?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.cliDetail`)}),(0,$.jsx)(I,{onClick:()=>window.open(N.authorizeUrl,`_blank`,`noopener`),children:r(`providers.subscription.openAuthorize`)})]}),N?.mode===`device`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-secondary)]`,children:r(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:N.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[N.verificationUrl&&(0,$.jsx)(I,{onClick:()=>window.open(N.verificationUrl??void 0,`_blank`,`noopener`),children:r(`providers.subscription.visitPage`)}),(0,$.jsx)(I,{variant:`primary`,loading:R,onClick:()=>void We(),children:r(`providers.subscription.checkNow`)})]}),(0,$.jsx)(L,{tone:`info`,title:r(`providers.subscription.waiting`),children:r(`providers.subscription.checkNowHint`)})]})]})]})}function On({policy:e,onChange:t}){let{t:n}=E();return(0,$.jsx)(ue,{ariaLabel:n(`providers.subscription.policy.switchMode`),value:e.switchMode,onChange:t,items:[{value:`manual`,label:n(`providers.subscription.policy.manual`)},{value:`failover`,label:n(`providers.subscription.policy.failover`)},{value:`balanced`,label:n(`providers.subscription.policy.balanced`)}]})}function kn({provider:e}){let{t}=E(),n=me(e.id),r=ve(e.id),i=C(e.id),a=h(e.id,!0),o=ze(e.id),{toast:s}=K(),[c,l]=(0,Q.useState)(null);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i.isLoading&&(0,$.jsx)(z,{lines:1}),i.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:W(i.error)}),i.data?.map(e=>(0,$.jsx)(I,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(pt,{className:`size-3.5`}):(0,$.jsx)(Lt,{className:`size-3.5`}),onClick:()=>l(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(z,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ge,{icon:(0,$.jsx)(zt,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&a.data&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-1`,children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:t(a.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:a.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsx)(On,{policy:a.data,onChange:e=>o.mutate({switchMode:e},{onError:e=>s(W(e),`error`)})})]}),n.data&&n.data.length>0&&(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(t=>(0,$.jsx)(jn,{provider:e,account:t,gatewayUsage:r.data?.accounts.find(e=>e.accountId===t.id)},t.id))}),r.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`providers.usage.error`),children:W(r.error)}),n.data&&n.data.length>0&&(0,$.jsx)(qt,{timeZone:r.data?.timeZone}),(0,$.jsx)(An,{provider:e}),c&&(0,$.jsx)(Mn,{provider:e,method:c,onClose:()=>l(null)})]})}function An({provider:e}){let{t,locale:n}=E(),{toast:r}=K(),a=U(e.id),o=i(e.id);if(!a.data?.supported)return null;let s=e=>o.mutate(e,{onError:e=>r(W(e),`error`)}),c={claimed:`green`,done:`green`,ineligible:`neutral`,inactive:`neutral`,captcha:`orange`,failed:`red`};return(0,$.jsxs)(`section`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`pluginAccounts.checkin`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`pluginAccounts.checkinDetail`)})]}),(0,$.jsx)(V,{checked:a.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>s(e)}),(0,$.jsx)(I,{size:`sm`,loading:o.isPending,onClick:()=>s(),children:t(`pluginAccounts.checkinNow`)})]}),a.data.accounts.map(e=>{let r=[e.credit?t(`pluginAccounts.credit`,{credit:e.credit}):null,e.streak?t(`pluginAccounts.streak`,{days:e.streak}):null,e.message,e.at?u(e.at,n):null].filter(Boolean);return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px]`,children:e.account}),r.length>0&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-[var(--text-secondary)]`,children:r.join(` · `)}),e.outcome?(0,$.jsx)(M,{tone:c[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(M,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function jn({provider:e,account:t,gatewayUsage:n}){let{t:r,locale:i}=E(),{toast:a,confirm:o}=K(),s=Ne(e.id),[c,l]=(0,Q.useState)(!1),d=e.settings?.plugin?.usage===!0,f=p(e.id,t.id,c),m=async()=>{await o({title:r(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:r(`pluginAccounts.signOut`),destructive:!0})&&s.mutate(t.id,{onError:e=>a(W(e),`error`)})};return(0,$.jsxs)(`article`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-medium`,children:t.displayName}),t.isCurrent&&(0,$.jsx)(M,{tone:`accent`,children:r(`pluginAccounts.current`)}),(0,$.jsx)(M,{tone:t.status===`active`?`green`:`red`,children:r(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),d&&(0,$.jsx)(I,{size:`sm`,onClick:()=>l(e=>!e),children:r(`pluginAccounts.usage`)}),(0,$.jsx)(I,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(ot,{className:`size-3.5`}),onClick:()=>void m(),children:r(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:r(`pluginAccounts.lapsedDetail`)}),(0,$.jsx)(Kt,{usage:n}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[f.isLoading&&(0,$.jsx)(z,{lines:2}),f.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:W(f.error)}),f.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:f.data.error}),f.data?.plan&&(0,$.jsx)(k,{label:r(`pluginAccounts.plan`),children:f.data.plan}),f.data?.until&&(0,$.jsx)(k,{label:r(`pluginAccounts.until`),children:u(f.data.until,i)}),f.data?.windows?.map(e=>(0,$.jsxs)(k,{label:e.name,children:[e.display??(e.limit?`${e.amount??e.used??0} / ${e.limit} ${e.unit??``}`:`${e.used??0}%`),e.resetsAt?` · ${r(`pluginAccounts.resets`,{at:u(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function Mn({provider:e,method:t,onClose:n}){let{t:r}=E(),{toast:i}=K(),[a,o]=(0,Q.useState)({}),[c,u]=(0,Q.useState)(void 0),[f,p]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[_,y]=(0,Q.useState)(``),[b,ee]=(0,Q.useState)(``),[te,ne]=(0,Q.useState)(null),ie=d(e.id),x=re(e.id),ae=l(e.id),S=m(e.id,te).data;(0,Q.useEffect)(()=>{let n=!0;return s(e.id,t.index,a).then(e=>{n&&(u(e.prompt),p(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&i(W(e),`error`)),()=>{n=!1}},[e.id,t.index,a,i]),(0,Q.useEffect)(()=>{S?.state===`done`&&(i(r(`pluginAccounts.signedIn`),`success`),n())},[S?.state,n,r,i]);let oe=async()=>{if(!c)return;let n=await v(e.id,t.index,c.key,f).catch(()=>({error:null}));if(n.error)return g(n.error);g(null),o(e=>({...e,[c.key]:f}))};return(0,$.jsxs)(G,{open:!0,onOpenChange:e=>!e&&n(),title:r(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[c===void 0&&(0,$.jsx)(z,{lines:2}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:c.message,error:h??void 0,children:c.type===`select`?(0,$.jsx)(q,{value:f,onChange:p,options:(c.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(D,{value:f,placeholder:c.placeholder??void 0,onChange:e=>p(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,onClick:()=>void oe(),children:r(`pluginAccounts.continue`)})})]}),c===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:r(`pluginAccounts.key`),children:(0,$.jsx)(D,{mono:!0,type:`password`,value:_,placeholder:t.placeholder??void 0,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!_.trim()||x.isPending,onClick:()=>x.mutate({method:t.index,inputs:a,key:_},{onSuccess:()=>(i(r(`pluginAccounts.signedIn`),`success`),n()),onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),c===null&&t.type!==`api`&&!S&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(at,{className:`size-3.5`}),disabled:ie.isPending,onClick:()=>ie.mutate({method:t.index,inputs:a},{onSuccess:e=>{ne(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.openPage`)})}),S&&S.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[S.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:S.instructions}),S.deviceCode&&(0,$.jsx)(k,{label:r(`pluginAccounts.deviceCode`),mono:!0,children:S.deviceCode}),S.url&&(0,$.jsx)(I,{icon:(0,$.jsx)(at,{className:`size-3.5`}),onClick:()=>window.open(S.url,`_blank`,`noopener`),children:r(`pluginAccounts.openAgain`)}),S.state===`waiting`&&S.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:r(`pluginAccounts.code`),children:(0,$.jsx)(D,{mono:!0,value:b,onChange:e=>ee(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!b.trim()||ae.isPending,onClick:()=>ae.mutate({flow:S.id,code:b.trim()},{onError:e=>i(W(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),S.state===`waiting`&&!S.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`pluginAccounts.waiting`)}),S.state===`failed`&&(0,$.jsx)(L,{tone:`danger`,title:r(`pluginAccounts.failed`),children:S.error})]})]})}function Nn(e){let t=e?.model_map,n={};if(!t||typeof t!=`object`||Array.isArray(t))return n;for(let[e,r]of Object.entries(t))e&&typeof r==`string`&&r&&(n[e]=r);return n}function Pn(){let{t:e}=E(),{id:t=``}=vt(),n=lt(),r=we(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=N(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(yt,{title:e(`nav.providers`),leading:(0,$.jsx)(In,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(L,{tone:`danger`,title:e(`common.error`),children:W(r.error)})});let u=r.data;return(0,$.jsx)(yt,{title:u?u.name:``,subtitle:u?[u.templateId,u.priceKey?e(`providers.priceKeyShort`,{key:u.priceKey}):null].filter(Boolean).join(` · `):void 0,leading:(0,$.jsx)(In,{onClick:()=>n(`/providers`)}),actions:u&&(0,$.jsx)(Ln,{p:u}),children:u?(0,$.jsxs)(dt,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(ht,{"aria-label":u.name,children:[(0,$.jsx)(ft,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(ft,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(ft,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(Ct,{value:`models`,className:`pt-4`,children:(0,$.jsx)(zn,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(Ct,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(kn,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(Dn,{provider:u}):(0,$.jsx)(Jn,{provider:u})}),(0,$.jsx)(Ct,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(Xn,{provider:u})}),(0,$.jsx)(qn,{provider:u,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(z,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}var Fn=e=>e.subscription?.mimic_claude_code===!0;function In({onClick:e}){let{t}=E();return(0,$.jsx)(I,{variant:`glass`,icon:(0,$.jsx)(Ze,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function Ln({p:e}){let{t}=E(),n=lt(),{toast:r,confirm:i}=K(),a=xe(),o=_e(),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=async()=>{await i({title:t(`providers.deleteConfirm`,{name:e.name}),detail:t(`providers.deleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&o.mutate(e.id,{onSuccess:()=>{r(t(`providers.deleted`)),n(`/providers`)},onError:e=>{let n=e instanceof _&&e.status===409?e.details?.boundClients??[]:[];r(n.length?t(`providers.deleteBound`,{clients:n.map(e=>gt[e]?.name??e).join(`, `)}):W(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>f(!0),children:t(`providers.test`)}),(0,$.jsx)(qe,{label:t(`common.more`),icon:(0,$.jsx)(it,{className:`size-4`}),items:[{id:`dup`,label:t(`providers.duplicate`),icon:(0,$.jsx)(ye,{className:`size-3.5`}),onSelect:()=>a.mutate(e.id,{onSuccess:e=>n(`/providers/${e.id}`),onError:e=>r(W(e),`error`)})},{id:`tpl`,label:t(`providers.templateUpdate`),icon:(0,$.jsx)(Vt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>c(!0)},{id:`switch`,label:t(`providers.templateSwitch`),icon:(0,$.jsx)(Dt,{className:`size-3.5`}),disabled:!tt(e),onSelect:()=>u(!0)},{id:`del`,label:t(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void p()}]}),(0,$.jsx)(Rn,{open:s,onOpenChange:c,provider:e}),(0,$.jsx)(et,{open:l,onOpenChange:u,provider:e}),(0,$.jsx)($e,{provider:e,open:d,onOpenChange:f})]})}function Rn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=ce(n.id,e),o=ie(n.id),s=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(G,{open:e,onOpenChange:t,title:r(`providers.templateUpdate`),description:a.data?r(`providers.templateVersions`,{current:a.data.currentVersion,latest:a.data.latestVersion}):void 0,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!a.data||s,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(W(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(z,{}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),s&&(0,$.jsx)(L,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!s&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function zn({provider:e,models:t,loading:n,selected:r,onSelect:i}){let{t:a}=E(),{toast:o}=K(),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=he(e.id),m=(t??[]).filter(e=>!s||e.modelId.toLowerCase().includes(s.toLowerCase())||e.effective.displayName.toLowerCase().includes(s.toLowerCase()));return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(be,{className:`w-56`,value:s,onChange:c,placeholder:a(`providers.searchModels`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(I,{icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>f(!0),children:a(`providers.addModels`)}),(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(nt,{className:`size-3.5`}),onClick:()=>u(!0),children:a(`providers.fetchRemote`)})]})]}),n&&(0,$.jsx)(z,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ge,{title:a(`providers.noModels`),detail:a(`providers.noModelsDetail`)})}),m.length>0&&(0,$.jsx)(R,{footer:a(`providers.modelsFooter`),children:m.map(e=>(0,$.jsxs)(j,{selected:e.id===r,onClick:()=>i(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:P(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(M,{tone:`orange`,children:a(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?oe(e.effective.contextWindow):null,Pe(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(_t,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(V,{checked:e.enabled,label:a(`common.enabled`),onChange:t=>p.mutate({pmId:e.id,enabled:t},{onError:e=>o(W(e),`error`)})})]},e.id))}),(0,$.jsx)(Bn,{provider:e}),(0,$.jsx)(Vn,{provider:e}),t&&(0,$.jsx)(Hn,{provider:e,models:t}),(0,$.jsx)(Wn,{open:d,onOpenChange:f,provider:e}),(0,$.jsx)(Gn,{open:l,onOpenChange:u,provider:e})]})}function Bn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=typeof e.settings.alias==`string`?e.settings.alias:``,[a,o]=(0,Q.useState)(i);return(0,Q.useEffect)(()=>o(i),[i]),(0,$.jsx)(R,{title:t(`providers.alias.title`),footer:t(`providers.alias.footer`),children:(0,$.jsxs)(j,{label:t(`providers.alias.label`),detail:t(`providers.alias.hint`),children:[(0,$.jsx)(D,{className:`w-56`,mono:!0,maxLength:64,"aria-label":t(`providers.alias.label`),placeholder:e.name,value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===i,onClick:()=>{let i=a.trim(),o={...e.settings};i?o.alias=i:delete o.alias,r.mutate({settings:o},{onSuccess:()=>n(t(`providers.alias.saved`),`success`),onError:e=>n(W(e),`error`)})},children:t(`common.save`)})]})})}function Vn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=e.settings.first_byte_timeout_sec,a=typeof i==`number`&&i>0?String(i):``,[o,s]=(0,Q.useState)(a);return(0,Q.useEffect)(()=>s(a),[a]),(0,$.jsx)(R,{title:t(`providers.timeout.title`),footer:t(`providers.timeout.footer`),children:(0,$.jsxs)(j,{label:t(`providers.timeout.label`),detail:t(`providers.timeout.hint`),children:[(0,$.jsx)(D,{className:`w-28`,mono:!0,inputMode:`numeric`,"aria-label":t(`providers.timeout.label`),placeholder:`—`,value:o,onChange:e=>s(e.target.value.replace(/\D/g,``).slice(0,4))}),(0,$.jsx)(I,{size:`sm`,disabled:r.isPending||o===a,onClick:()=>{let i=Math.min(3600,Math.floor(Number(o))),a={...e.settings};o.trim()&&i>0?a.first_byte_timeout_sec=i:delete a.first_byte_timeout_sec,r.mutate({settings:a},{onSuccess:()=>n(t(`providers.timeout.saved`),`success`),onError:e=>n(W(e),`error`)})},children:t(`common.save`)})]})})}function Hn({provider:e,models:t}){let{t:n}=E(),{toast:r}=K(),i=g(e.id),[a,o]=(0,Q.useState)(!1),s=Nn(e.settings),c=Object.entries(s),l=new Set(t.map(e=>e.modelId)),u=(e,t)=>i.mutate(e,{onSuccess:()=>{t?.(),r(n(`providers.modelMap.saved`),`success`)},onError:e=>r(W(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(j,{label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2 font-mono text-[12.5px]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e}),(0,$.jsx)(mt,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:P(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(M,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(O,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>u(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(j,{icon:(0,$.jsx)(ut,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`providers.modelMap.add`),detail:t.length===0?n(`providers.modelMap.needModels`):void 0,onClick:t.length===0?void 0:()=>o(!0)})]}),(0,$.jsx)(Un,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function Un({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=E(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(G,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!u||!c||u===c,loading:r,onClick:()=>i(u,c),children:a(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(D,{autoFocus:!0,mono:!0,label:a(`providers.modelMap.from`),placeholder:`deepseek-v4.1`,spellCheck:!1,value:o,onChange:e=>s(e.target.value)}),(0,$.jsx)(q,{label:a(`providers.modelMap.to`),value:c,onChange:l,placeholder:a(`providers.modelMap.toPlaceholder`),options:n.map(e=>({value:e.modelId,label:e.modelId}))})]})})}function Wn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=y(n.id),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&s(``)},[e]);let c=[...new Set(o.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addModels`),description:r(`providers.addModelsDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:c.length===0,loading:a.isPending,onClick:()=>a.mutate(c,{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(W(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(T,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
|
|
3
|
+
claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function Gn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=K(),a=Ae(n.id,e),o=y(n.id),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&c(new Set)},[e]);let d=(a.data??[]).filter(e=>!l||e.id.toLowerCase().includes(l.toLowerCase())),f=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(G,{open:e,onOpenChange:t,width:560,title:r(`providers.fetchRemote`),description:r(`providers.fetchRemoteDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{variant:`plain`,className:`mr-auto`,onClick:()=>c(new Set(d.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:d.length===0,children:r(`common.selectAll`)}),(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:s.size===0,loading:o.isPending,onClick:()=>o.mutate([...s],{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(W(e),`error`)}),children:r(`providers.addSelected`,{count:s.size})})]}),children:[(0,$.jsx)(be,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(z,{lines:4}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),a.error instanceof _&&(0,$.jsx)(Qe,{className:`mt-3`,provider:n,httpStatus:a.error.details?.httpStatus}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(j,{onClick:e.alreadyAdded?void 0:()=>f(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(M,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(wt,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function Kn({origin:e}){let{t}=E();return e===`overridden`?(0,$.jsx)(M,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(M,{children:t(`origin.inherited`)}):(0,$.jsx)(M,{tone:`red`,children:t(`origin.unset`)})}function qn({provider:e,pm:t,onClose:n}){let{t:r}=E(),{toast:i}=K(),a=he(e.id),o=Fe(e.id),s=f(),[c,l]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(l(t.overrides),d(t.systemModelId??``),m(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let h={...c,pricing:p?c.pricing??null:null},g=JSON.stringify(h)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||u!==(t.systemModelId??``),_=()=>a.mutate({pmId:t.id,overrides:h,systemModelId:u||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(W(e),`error`)}),v=(e,n,i)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:n}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Kn,{origin:c[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),c[e]!=null&&(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ct,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&n(),width:720,title:t.modelId,description:e.name,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mr-auto`,children:(0,$.jsx)(Tt,{label:r(`providers.removeModelShort`),icon:(0,$.jsx)(Z,{className:`size-4`}),prompt:r(`providers.removeModel`,{id:t.modelId}),confirmLabel:r(`common.delete`),cancelLabel:r(`common.cancel`),pendingLabel:r(`common.deleting`),doneLabel:r(`common.deleted`),errorLabel:r(`common.error`),retryLabel:r(`common.retry`),onConfirm:async()=>{await o.mutateAsync(t.id),n()}})}),(0,$.jsx)(I,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!g,loading:a.isPending,onClick:_,children:r(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(_t,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(M,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(pe,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(q,{className:`w-full`,ariaLabel:r(`providers.linkedModel`),value:u,onChange:d,options:[{value:``,label:r(`providers.noLink`)},...(s.data??[]).map(e=>({value:e.id,label:e.id,detail:e.displayName}))]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:r(`providers.linkedModelHint`)})]}),(0,$.jsx)(pe,{title:r(`providers.overrides`),children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[v(`displayName`,r(`models.field.displayName`),(0,$.jsx)(D,{className:`w-full`,"aria-label":r(`models.field.displayName`),placeholder:t.effective.displayName,value:c.displayName??``,onChange:e=>l({...c,displayName:e.target.value||null})})),v(`contextWindow`,r(`models.field.contextWindow`),(0,$.jsx)(F,{className:`w-full`,label:r(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:c.contextWindow,onChange:e=>l({...c,contextWindow:e})})),v(`maxOutputTokens`,r(`models.field.maxOutputTokens`),(0,$.jsx)(F,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:c.maxOutputTokens,onChange:e=>l({...c,maxOutputTokens:e})}))]})}),(0,$.jsxs)(pe,{title:r(`providers.price`),action:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[r(`providers.customPrice`),(0,$.jsx)(V,{checked:p,label:r(`providers.customPrice`),onChange:e=>{m(e),e&&c.pricing==null&&l({...c,pricing:t.effectivePricing??{currency:`USD`,unit:`per_1m_tokens`,base:{input:null,output:null}}})}})]}),children:[(0,$.jsx)(`p`,{className:`mb-3 text-[11px] text-[var(--text-muted)]`,children:r(p?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),p?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(bt,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(Ce,{maxHeight:220,children:je(t.effectivePricing)}):(0,$.jsx)(L,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function Jn({provider:e}){let{t}=E(),{toast:n}=K(),r=Le(e.id),i=ve(e.id),[a,o]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:(0,$.jsx)(j,{label:t(`providers.apiKey`),detail:e.hasApiKey?e.apiKeyMasked??`••••`:t(`providers.noKey`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":t(`providers.apiKey`),placeholder:t(`providers.replaceKey`),value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(I,{variant:`primary`,disabled:a.trim().length===0,loading:r.isPending,onClick:()=>r.mutate({apiKey:a},{onSuccess:()=>{o(``),n(t(`common.saved`),`success`)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})})}),(0,$.jsxs)(`section`,{className:`card my-4 flex flex-col gap-2 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`providers.usage.title`)}),i.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`providers.usage.error`),children:W(i.error)}),(0,$.jsx)(Kt,{usage:i.data?.accounts.find(e=>!e.accountId)}),(0,$.jsx)(qt,{timeZone:i.data?.timeZone})]}),(0,$.jsx)(nn,{provider:e})]})}function Yn(e){return{name:e.name,apiKey:``,endpoints:e.endpoints,preferredUpstreamProtocols:e.preferredUpstreamProtocols,authScheme:e.authScheme,extraHeaders:e.extraHeaders,httpProxy:e.httpProxy??null,priceMultiplier:e.priceMultiplier,priceKey:e.priceKey??null,settings:e.settings,enabled:e.enabled,notes:e.notes??null}}function Xn({provider:t}){let{t:n}=E(),{toast:r}=K(),i=Le(t.id),a=e(),o=(0,Q.useMemo)(()=>Yn(t),[t]),[s,c]=(0,Q.useState)(o),[l,u]=(0,Q.useState)(Object.entries(t.extraHeaders)),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{c(o),u(Object.entries(o.extraHeaders))},[o]);let h=e=>c(t=>({...t,...e})),g={...s,extraHeaders:Object.fromEntries(l.filter(([e])=>e.trim()))},_=JSON.stringify(g)!==JSON.stringify(o),v=()=>{let e={};for(let t of Object.keys(g))t!==`apiKey`&&JSON.stringify(g[t])!==JSON.stringify(o[t])&&(e[t]=g[t]);s.apiKey&&(e.apiKey=s.apiKey),i.mutate(e,{onSuccess:()=>r(n(`common.saved`),`success`),onError:e=>r(W(e),`error`)})},y=(e,t)=>h({endpoints:s.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:n(`providers.section.basic`),children:[(0,$.jsx)(j,{label:n(`providers.name`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":n(`providers.name`),value:s.name,onChange:e=>h({name:e.target.value})})}),(0,$.jsx)(j,{label:n(`common.enabled`),children:(0,$.jsx)(V,{checked:s.enabled,label:n(`common.enabled`),onChange:e=>h({enabled:e})})}),(0,$.jsx)(j,{label:n(`providers.notes`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":n(`providers.notes`),value:s.notes??``,onChange:e=>h({notes:e.target.value||null})})})]}),(0,$.jsx)(R,{title:n(`providers.section.auth`),children:(0,$.jsx)(j,{label:n(`providers.authScheme`),children:(0,$.jsx)(q,{className:`w-48`,value:s.authScheme,onChange:e=>h({authScheme:e}),options:Y})})}),(0,$.jsxs)(R,{title:n(`providers.section.endpoints`),footer:n(`providers.endpointsFooter`),children:[s.endpoints.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(q,{className:`w-48`,value:e.protocol,onChange:e=>y(t,{protocol:e}),options:J}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":n(`providers.baseUrl`),value:e.baseUrl,onChange:e=>y(t,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:!!e.fullUrl,label:n(`providers.fullUrl`),onChange:e=>y(t,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>h({endpoints:s.endpoints.filter((e,n)=>n!==t)})})]},t)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>f(!0),children:n(`providers.addEndpoint`)})}),(0,$.jsx)(j,{label:n(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[n(`providers.preferredHint`),s.preferredUpstreamProtocols.filter(e=>!s.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:n(`providers.preferredMissing`,{protocol:J.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(St,{label:n(`providers.preferred`),options:J.map(e=>{let t=s.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:s.preferredUpstreamProtocols,onValueChange:e=>{let t=s.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));h({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(R,{title:n(`providers.section.billing`),footer:n(`providers.billingFooter`),children:[(0,$.jsx)(j,{label:n(`providers.priceKey`),detail:n(`providers.priceKeyHint`),children:(0,$.jsx)(q,{className:`w-56`,value:s.priceKey==null?`inherit`:`price:${s.priceKey}`,onChange:e=>h({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:n(`providers.priceKeyDefault`,{id:t.templateId??`—`})},{value:`price:`,label:n(`providers.priceKeyNone`)},...(a.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(j,{label:n(`providers.multiplier`),detail:n(`providers.multiplierHint`),children:(0,$.jsx)(F,{className:`w-28`,label:n(`providers.multiplier`),step:.01,min:0,value:s.priceMultiplier,onChange:e=>h({priceMultiplier:e??1})})})]}),(0,$.jsxs)(R,{title:n(`providers.section.advanced`),children:[(0,$.jsx)(j,{label:n(`providers.proxy`),detail:n(`providers.proxyHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":n(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:s.httpProxy??``,onChange:e=>h({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:n(`providers.headers`)}),l.map(([e,t],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(D,{className:`w-48 font-mono`,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>u(l.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(D,{className:`flex-1 font-mono`,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:t,onChange:e=>u(l.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>u(l.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ut,{className:`size-3.5`}),onClick:()=>m(!0),children:n(`providers.addHeader`)})]}),Object.keys(t.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(T,{label:n(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:je(s.settings),onBlur:e=>{try{h({settings:JSON.parse(e.target.value)})}catch{r(n(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(R,{title:n(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(k,{label:`ID`,children:t.id}),t.adapterId&&(0,$.jsx)(k,{label:n(`providers.adapter`),children:t.adapterId}),(0,$.jsx)(k,{label:n(`providers.boundClients`),children:t.boundClients.map(e=>gt[e]?.name??e).join(`, `)||`—`})]})}),s.authScheme!==`oauth-subscription`&&s.authScheme!==`plugin`&&s.endpoints.some(e=>e.protocol===`anthropic`)&&(0,$.jsx)(j,{label:n(`providers.mimicClaudeCode`),detail:n(`providers.mimicClaudeCode.hint`),children:(0,$.jsx)(V,{checked:Fn(s.settings),label:n(`providers.mimicClaudeCode`),onChange:e=>h({settings:{...s.settings,subscription:{...s.settings.subscription,mimic_claude_code:e}}})})}),(0,$.jsx)(Zn,{open:d,onOpenChange:f,onAdd:e=>h({endpoints:[...s.endpoints,e]})}),(0,$.jsx)(Qn,{open:p,onOpenChange:m,onAdd:e=>u([...l.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:_&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:n(`common.unsaved`)}),(0,$.jsx)(I,{size:`sm`,onClick:()=>{c(o),u(Object.entries(o.extraHeaders))},children:n(`common.revert`)}),(0,$.jsx)(I,{size:`sm`,variant:`primary`,loading:i.isPending,onClick:v,children:n(`common.save`)})]})})]})}function Zn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=E(),[i,a]=(0,Q.useState)(`openai-chat`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(s(``),l(!1))},[e]);let u=/^https?:\/\/\S+$/.test(o.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!u,onClick:()=>{n({protocol:i,baseUrl:o.trim(),...c?{fullUrl:!0}:{}}),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(A,{label:r(`providers.protocol`),children:(0,$.jsx)(q,{value:i,onChange:a,options:J})}),(0,$.jsx)(A,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`https://api.example.com/v1`,value:o,invalid:o!==``&&!u,onChange:e=>s(e.target.value)})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function Qn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=E(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(a(``),s(``))},[e]);let c=/^[A-Za-z0-9-]+$/.test(i.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:!c,onClick:()=>{n([i.trim(),o]),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(A,{label:r(`providers.headerName`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(A,{label:r(`providers.headerValue`),children:(0,$.jsx)(D,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{Pn as ProviderDetailPage};
|