@aidotnet/server-linux-x64 0.13.3 → 0.13.4

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.
Files changed (40) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/{ClientsPage-CnHLR9_Q.js → ClientsPage-Tjb-Lk3j.js} +1 -1
  3. package/bin/wwwroot/assets/{KeyPage-zIb63Of5.js → KeyPage-Xj9r3Djk.js} +1 -1
  4. package/bin/wwwroot/assets/{ModelDetailPage-BcXehC4E.js → ModelDetailPage-BanXH5PK.js} +1 -1
  5. package/bin/wwwroot/assets/{ModelsPage-BWIb4L9N.js → ModelsPage-E0tSsPts.js} +1 -1
  6. package/bin/wwwroot/assets/{PluginsPage-BaoJMLzq.js → PluginsPage-CnstItW6.js} +1 -1
  7. package/bin/wwwroot/assets/{PrivacyPage-BmqVk2pi.js → PrivacyPage-CbBRFTMf.js} +1 -1
  8. package/bin/wwwroot/assets/{ProviderDetailPage-BLCMpahq.js → ProviderDetailPage-AUDqLapy.js} +1 -1
  9. package/bin/wwwroot/assets/{ProvidersPage-CnBPj_Jb.js → ProvidersPage-DuVAa-Hz.js} +1 -1
  10. package/bin/wwwroot/assets/{SettingsPage-CcEs-Ivi.js → SettingsPage-a3uBRMV_.js} +1 -1
  11. package/bin/wwwroot/assets/{SmartRoutingPage-BEf8F6eE.js → SmartRoutingPage-DC5sD0bZ.js} +1 -1
  12. package/bin/wwwroot/assets/{TokenDetailPage-CnwCepbj.js → TokenDetailPage-D1ryElHF.js} +1 -1
  13. package/bin/wwwroot/assets/{TokenPoolEditor-B5YYbTBI.js → TokenPoolEditor-BhM2cgiC.js} +1 -1
  14. package/bin/wwwroot/assets/{TokensPage-IYF5mfUz.js → TokensPage-Cp0oynev.js} +1 -1
  15. package/bin/wwwroot/assets/{TracesPage-RdQ1uzTo.js → TracesPage-CuMO5elT.js} +1 -1
  16. package/bin/wwwroot/assets/{TrayPanelPage-DF3TZ-Mi.js → TrayPanelPage-CwzGid44.js} +1 -1
  17. package/bin/wwwroot/assets/{TrayPanelView-ctysAPlQ.js → TrayPanelView-C5_GEcGF.js} +1 -1
  18. package/bin/wwwroot/assets/{alert-CMMOyMsp.js → alert-VkCgBSEU.js} +3 -3
  19. package/bin/wwwroot/assets/{arrow-down-rd1gJD55.js → arrow-down-Bm13_VSy.js} +1 -1
  20. package/bin/wwwroot/assets/{arrow-left-BYi8J86q.js → arrow-left-BpFef649.js} +1 -1
  21. package/bin/wwwroot/assets/{arrow-up-right-DNaPmTcJ.js → arrow-up-right-Dt19ixmG.js} +1 -1
  22. package/bin/wwwroot/assets/{checkbox--x0D0yfB.js → checkbox-YjWCwufO.js} +1 -1
  23. package/bin/wwwroot/assets/{cloud-download-BkOTPIzF.js → cloud-download-0kOOrGs0.js} +1 -1
  24. package/bin/wwwroot/assets/{confirm-morph-BLco2mdX.js → confirm-morph-Cxhcg5Af.js} +1 -1
  25. package/bin/wwwroot/assets/{download-CSRdoXEJ.js → download-CVhnkMFM.js} +1 -1
  26. package/bin/wwwroot/assets/{ellipsis-BI50R2Bc.js → ellipsis-Cw0JIn8h.js} +1 -1
  27. package/bin/wwwroot/assets/{external-link-Bzx5-ExU.js → external-link-CoA1OFOi.js} +1 -1
  28. package/bin/wwwroot/assets/{folder-open-BxXgq-F4.js → folder-open-vyiFD3ST.js} +1 -1
  29. package/bin/wwwroot/assets/{index-Ck4Qlg9B.js → index-D2dNv2tH.js} +3 -3
  30. package/bin/wwwroot/assets/{log-out-DzOM9UKH.js → log-out-CfwP3cML.js} +1 -1
  31. package/bin/wwwroot/assets/minus-C0K0VMJh.js +1 -0
  32. package/bin/wwwroot/assets/{overlays-BFrvqpMl.js → overlays-DiAM_uxj.js} +1 -1
  33. package/bin/wwwroot/assets/{pencil-BMnmsFVj.js → pencil-DhqvwNLm.js} +1 -1
  34. package/bin/wwwroot/assets/{power-CznSHqkx.js → power-CvCs4uOV.js} +1 -1
  35. package/bin/wwwroot/assets/{radio-cards-DNOgi4px.js → radio-cards-CiZ_t5iI.js} +1 -1
  36. package/bin/wwwroot/assets/{rotate-ccw-Bhx85LK2.js → rotate-ccw-Ckutyipl.js} +1 -1
  37. package/bin/wwwroot/assets/{sortable.esm-BY9yO4Eq.js → sortable.esm-DegG4iIY.js} +1 -1
  38. package/bin/wwwroot/index.html +3 -3
  39. package/package.json +1 -1
  40. package/bin/wwwroot/assets/minus-CYKTpU0K.js +0 -1
@@ -1,3 +1,3 @@
1
- import{At as e,Di as t,Dn as n,Dt as r,Et as i,Fa as a,Fn as o,Gn as s,H as c,Hr as l,In as u,Kr as d,Ln as f,Na as p,Nn as m,Nr as h,On as g,Ot as _,Pa as v,Pt as y,Q as b,Ra as x,Rr as ee,Rt as te,Un as ne,V as S,Vn as re,Vr as ie,Wn as C,Xn as ae,Xt as oe,Y as w,Zt as se,_ as ce,a as T,ar as le,b as ue,bn as de,br as fe,c as pe,cn as me,ct as E,d as D,dr as he,dt as ge,f as O,gt as _e,h as ve,hi as k,hn as ye,ht as be,i as xe,it as Se,jt as Ce,l as A,m as j,mi as we,mr as Te,n as M,nr as Ee,nt as N,on as De,ot as P,p as F,pi as Oe,pn as ke,qn as Ae,r as I,rr as je,rt as Me,sn as Ne,t as L,tr as Pe,u as R,ur as Fe,v as z,xn as Ie,xt as B,y as V,yi as Le,yn as Re,zr as ze}from"./alert-CMMOyMsp.js";import{a as H,i as U,n as Be,o as W,r as G}from"./overlays-BFrvqpMl.js";import{a as K,c as q,i as Ve,l as He,n as Ue,o as We,s as Ge,t as Ke}from"./ProvidersPage-CnBPj_Jb.js";import{t as qe}from"./arrow-down-rd1gJD55.js";import{t as Je}from"./arrow-left-BYi8J86q.js";import{t as Ye}from"./cloud-download-BkOTPIzF.js";import{t as Xe}from"./download-CSRdoXEJ.js";import{t as J}from"./ellipsis-BI50R2Bc.js";import{t as Ze}from"./external-link-Bzx5-ExU.js";import{n as Qe}from"./radio-cards-DNOgi4px.js";import{t as Y}from"./log-out-DzOM9UKH.js";import{t as $e}from"./power-CznSHqkx.js";import{t as et}from"./rotate-ccw-Bhx85LK2.js";import{$ as tt,C as nt,E as X,K as rt,N as Z,Q as it,T as at,V as ot,_ as st,a as ct,h as lt,o as ut,q as dt,s as ft,w as pt,z as mt}from"./index-Ck4Qlg9B.js";import{t as ht}from"./checkbox--x0D0yfB.js";import{t as gt}from"./confirm-morph-BLco2mdX.js";var _t={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`}]]};_t.node;var vt=B(_t),yt={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`}]]};yt.node;var bt=B(yt),xt={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`}]]};xt.node;var St=B(xt),Ct={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`}]]};Ct.node;var wt=B(Ct),Tt={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`}]]};Tt.node;var Et=B(Tt),Dt={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`}]]};Dt.node;var Ot=B(Dt),kt={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`]};kt.node;var At=B(kt),jt={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`}]]};jt.node;var Mt=B(jt),Q=x(a(),1),$=v();function Nt({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(Se(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 Pt({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 Ft={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`},It={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Lt={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function Rt(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 zt(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(`
1
+ import{At as e,Di as t,Dn as n,Dt as r,Et as i,Fa as a,Fn as o,Gn as s,H as c,Hr as l,In as u,Kr as d,Ln as f,Na as p,Nn as m,Nr as h,On as g,Ot as _,Pa as v,Pt as y,Q as b,Ra as x,Rr as ee,Rt as te,Un as ne,V as S,Vn as re,Vr as ie,Wn as C,Xn as ae,Xt as oe,Y as w,Zt as se,_ as ce,a as T,ar as le,b as ue,bn as de,br as fe,c as pe,cn as me,ct as E,d as D,dr as he,dt as ge,f as O,gt as _e,h as ve,hi as k,hn as ye,ht as be,i as xe,it as Se,jt as Ce,l as A,m as j,mi as we,mr as Te,n as M,nr as Ee,nt as N,on as De,ot as P,p as F,pi as Oe,pn as ke,qn as Ae,r as I,rr as je,rt as Me,sn as Ne,t as L,tr as Pe,u as R,ur as Fe,v as z,xn as Ie,xt as B,y as V,yi as Le,yn as Re,zr as ze}from"./alert-VkCgBSEU.js";import{a as H,i as U,n as Be,o as W,r as G}from"./overlays-DiAM_uxj.js";import{a as K,c as q,i as Ve,l as He,n as Ue,o as We,s as Ge,t as Ke}from"./ProvidersPage-DuVAa-Hz.js";import{t as qe}from"./arrow-down-Bm13_VSy.js";import{t as Je}from"./arrow-left-BpFef649.js";import{t as Ye}from"./cloud-download-0kOOrGs0.js";import{t as Xe}from"./download-CVhnkMFM.js";import{t as J}from"./ellipsis-Cw0JIn8h.js";import{t as Ze}from"./external-link-CoA1OFOi.js";import{n as Qe}from"./radio-cards-CiZ_t5iI.js";import{t as Y}from"./log-out-CfwP3cML.js";import{t as $e}from"./power-CvCs4uOV.js";import{t as et}from"./rotate-ccw-Ckutyipl.js";import{$ as tt,C as nt,E as X,K as rt,N as Z,Q as it,T as at,V as ot,_ as st,a as ct,h as lt,o as ut,q as dt,s as ft,w as pt,z as mt}from"./index-D2dNv2tH.js";import{t as ht}from"./checkbox-YjWCwufO.js";import{t as gt}from"./confirm-morph-Cxhcg5Af.js";var _t={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`}]]};_t.node;var vt=B(_t),yt={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`}]]};yt.node;var bt=B(yt),xt={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`}]]};xt.node;var St=B(xt),Ct={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`}]]};Ct.node;var wt=B(Ct),Tt={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`}]]};Tt.node;var Et=B(Tt),Dt={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`}]]};Dt.node;var Ot=B(Dt),kt={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`]};kt.node;var At=B(kt),jt={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`}]]};jt.node;var Mt=B(jt),Q=x(a(),1),$=v();function Nt({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(Se(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 Pt({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 Ft={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`},It={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Lt={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function Rt(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 zt(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
2
  `)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:Rt(e))}return n}function Bt({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=E(),{toast:o}=W(),s=Re(e),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),m=(0,Q.useMemo)(()=>zt(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),p(null))},[n]),n===null)return(0,$.jsx)(U,{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(H(e),`error`)});return(0,$.jsx)(U,{open:!0,onOpenChange:e=>!e&&i(),title:a(Lt[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)(ue,{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:It[e.status],children:a(Ft[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 Vt(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var Ht={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},Ut={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Wt(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 Gt({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s,usage:l}){let{t:u,locale:d}=E(),f=Vt(e),p=e.displayName||e.accountEmail||e.keyMasked||e.id,m=e.kind===`api_key`,h=e.plan?.trim(),g=f===`cooling`?{text:u(`providers.subscription.cooldown`,{when:c(e.cooldownUntilUtc,d)}),tone:`var(--warning)`}:f===`dead`?{text:e.lastError||u(Ut[e.status]),tone:`var(--danger)`}:m?{text:e.keyMasked??u(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:u(`providers.accounts.expiresAt`,{when:c(e.expiresAtUtc,d)}),tone:void 0}:null,_=[{id:`activate`,label:u(`providers.subscription.activate`),icon:(0,$.jsx)(bt,{className:`size-3.5`}),disabled:e.isCurrent||f===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:u(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)($e,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:u(`providers.subscription.moveUp`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:u(`providers.subscription.moveDown`),icon:(0,$.jsx)(qe,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:u(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(He,{className:`size-3.5`}),disabled:f===`dead`,onSelect:()=>n.refreshQuota(e)},...m?[]:[{id:`refresh`,label:u(`providers.subscription.refreshToken`),icon:(0,$.jsx)(et,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:u(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],{id:`remove`,label:u(`providers.subscription.logout`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],v=u(f===`disabled`?`providers.subscription.disabled`:Ut[e.status]),y=u(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:Wt(h,m)},children:[(f===`cooling`||f===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:Ht[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)(ht,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":u(`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:Ht[f]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:v})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${u(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(be,{className:`size-3.5`,"aria-label":u(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Be,{iconOnly:!0,label:u(`common.more`),icon:(0,$.jsx)(J,{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:u(`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:u(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:u(`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)(Nt,{usage:l,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:u(`providers.accounts.signedOut`)}),!m&&(0,$.jsx)(I,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:u(`providers.subscription.relogin`)})]}):(0,$.jsx)(qt,{quota:e.quota??null,pending:s})]})]})}var Kt=10;function qt({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*Kt),o=e.reset?n(`providers.subscription.quotaResets`,{when:c(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:Kt},(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 Jt({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)(Yt,{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 Yt({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 Xt={available:`green`,redeemed:`neutral`,expired:`orange`};function Zt({account:e,providerId:n}){let{t:r}=E(),{toast:i,confirm:a}=W(),o=fe(e.id,e.status===`active`),s=se(n),c=o.data?.credits??[],l=o.data?.available_count??c.filter(e=>e.status===`available`).length,u=async n=>{await a({title:r(`providers.subscription.credits.consumeConfirm`,{title:n.title??n.reset_type??``}),detail:r(`providers.subscription.credits.consumeDetail`),confirmLabel:r(`providers.subscription.credits.consume`),destructive:!0})&&s.mutate({accountId:e.id,creditId:n.id},{onSuccess:()=>i(r(`providers.subscription.credits.consumed`),`success`),onError:e=>i(e instanceof t&&e.status===409?H(e):`${r(`providers.subscription.credits.consumeFailed`)}:${H(e)}`,`error`)})};return(0,$.jsxs)(R,{title:r(`providers.subscription.credits.title`),footer:r(`providers.subscription.credits.footer`),children:[o.isLoading&&(0,$.jsx)(z,{className:`my-4`}),o.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:r(`providers.subscription.credits.unavailable`)}),o.data&&c.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:r(`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)(St,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?r(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?r(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?r(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(M,{tone:Xt[e.status]??`neutral`,children:r(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Mt,{className:`size-3.5`}),disabled:t,loading:s.isPending&&s.variables?.creditId===e.id,onClick:()=>void u(e),children:r(`providers.subscription.credits.consume`)})]},e.id)}),o.data&&c.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:r(`providers.subscription.credits.availableCount`,{count:l})})]})}var Qt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function $t({provider:e,account:t,index:n,actions:r,onClose:i,usage:a,usageTimeZone:o}){let{t:s,locale:l}=E(),{toast:u}=W(),d=we(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)(U,{open:!1,onOpenChange:i,title:``});let g=Vt(t),_=t.kind===`api_key`,v=e.templateId===`openai-subscription`,y=e.httpProxy||s(`providers.accounts.proxyFallbackSystem`),b=e=>e?c(e,l):`—`,x=(e,n)=>d.mutate({id:t.id,...e},{onSuccess:()=>u(s(n),`success`),onError:e=>u(H(e),`error`)});return(0,$.jsx)(U,{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)(bt,{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)(He,{className:`size-3.5`}),disabled:g===`dead`,onClick:()=>r.refreshQuota(t),children:s(`providers.subscription.quotaRefresh`)}),!_&&(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)(et,{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)(Nt,{usage:a})}),(0,$.jsx)(Pt,{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:()=>x({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:()=>x({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)(Jt,{quota:t.quota})]}),v&&g!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(Zt,{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)(O,{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`:Qt[t.status])})}),t.source&&(0,$.jsx)(O,{label:s(`providers.accounts.detail.source`),children:s(`providers.accounts.source.${t.source}`)}),_?(0,$.jsx)(O,{label:s(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{label:s(`providers.accounts.detail.expires`),children:b(t.expiresAtUtc)}),(0,$.jsx)(O,{label:s(`providers.accounts.detail.lastRefresh`),children:b(t.lastRefreshAtUtc)})]}),g===`cooling`&&(0,$.jsx)(O,{label:s(`providers.accounts.filter.cooling`),children:b(t.cooldownUntilUtc)}),(0,$.jsx)(O,{label:s(`providers.accounts.detail.order`),children:s(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(O,{label:s(`providers.accounts.detail.created`),children:b(t.createdAt)}),t.lastError&&g!==`dead`&&(0,$.jsx)(O,{label:s(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function en({provider:e}){let{t}=E(),{toast:n}=W(),r=e.authScheme===`oauth-subscription`,i=l(e.id,r),a=Le(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(H(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`}],nn=3e5;function rn({provider:r}){let{t:a}=E(),{toast:o,confirm:s}=W(),c=p(),u=r.authScheme===`oauth-subscription`,d=Ee(r.id,u),f=le(r.id,u),m=l(r.id,u),h=Le(r.id),_=e(r.id,u),v=ze(r.id),y=Ae(r.id),b=oe(r.id),x=ye(r.id),ee=Fe(r.id),te=Ne(r.id),ne=Ce(r.id),S=we(r.id),re=Te(r.id),ie=r.templateId===`openai-subscription`,C=n(u&&ie),ae=de(r.id),w=r.templateId===`github-copilot-subscription`,se=g(u&&w),ce=Ie(r.id),[T,ue]=(0,Q.useState)(`all`),[fe,pe]=(0,Q.useState)(``),[me,he]=(0,Q.useState)(new Set),[ge,O]=(0,Q.useState)(null),[_e,k]=(0,Q.useState)(null),[be,xe]=(0,Q.useState)(!1),[Se,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(!1),[N,De]=(0,Q.useState)(!1),[F,Oe]=(0,Q.useState)(null),[ke,je]=(0,Q.useState)(null),[Me,Pe]=(0,Q.useState)(!1),[R,B]=(0,Q.useState)(``),V=(0,Q.useRef)(new Set),Re=(0,Q.useRef)(new Set),G=(0,Q.useMemo)(()=>d.data??[],[d.data]);if((0,Q.useEffect)(()=>{if(u)for(let e of G){if(e.status!==`active`||Re.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<nn||(Re.current.add(e.id),x.mutate(e.id,{onError:()=>{}}))}},[G,u]),(0,Q.useEffect)(()=>{let e=new Set(G.map(e=>e.id));he(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),ge&&!e.has(ge)&&O(null)},[G,ge]),(0,Q.useEffect)(()=>{if(!N||F?.mode!==`pkce`)return;let e=setInterval(()=>void d.refetch(),3e3);return()=>clearInterval(e)},[N,F,d]),(0,Q.useEffect)(()=>{if(!N||F?.mode!==`pkce`)return;let e=G.find(e=>!V.current.has(e.id));e&&q(!0,e.displayName||e.accountEmail||e.id)},[G,N,F]),(0,Q.useEffect)(()=>{if(!N||F?.mode!==`device`&&F?.mode!==`cli`)return;let e=!1,n=0,r=async()=>{try{let t=await y.mutateAsync(F.state);if(e)return;n=0,t.status===`done`?q(!0,t.account.displayName||t.account.accountEmail||t.account.id):t.status!==`pending`&&t.status!==`slow_down`&&q(!1,void 0,`error`in t?t.error??t.status:t.status)}catch(r){if(e)return;if(r instanceof t&&(r.status===404||r.status===400)){q(!1,void 0,H(r));return}++n>=5&&q(!1,void 0,H(r))}},i=setInterval(()=>void r(),Math.max(F.interval||5,3)*1e3);return()=>{e=!0,clearInterval(i)}},[N,F]),!u)return null;let K=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,q=(e,t,n)=>{if(c.invalidateQueries({queryKey:i.providerAccounts(r.id)}),e){Oe(null),je(null),De(!1),o(a(`providers.subscription.loginOk`,{name:t??``}),`success`);return}n&&je(n)},Ve=(e,n)=>{V.current=new Set(G.map(e=>e.id)),je(null),v.mutate({accountId:e,httpProxy:n},{onSuccess:e=>{xe(!1),Oe(e),De(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof t&&e.details?.needsVerification?o(a(`providers.subscription.needsVerification`),`error`):o(H(e),`error`)}})},He=async()=>{if(F){Pe(!0);try{let e=await y.mutateAsync(F.state);e.status===`done`?q(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?o(a(`providers.subscription.stillWaiting`),`info`):q(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof t&&e.status===404){let t=((await d.refetch()).data??[]).find(e=>!V.current.has(e.id));t?q(!0,t.displayName||t.accountEmail||t.id):q(!1,void 0,H(e))}else q(!1,void 0,H(e))}finally{Pe(!1)}}},Ue=async()=>{if(F&&F.mode===`paste`&&R.trim().length!==0){Pe(!0);try{let e=await b.mutateAsync({state:F.state,code:R.trim()});e.status===`done`?(B(``),q(!0,e.account.displayName||e.account.accountEmail||e.account.id)):q(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){q(!1,void 0,H(e))}finally{Pe(!1)}}},We=()=>ae.mutate(void 0,{onSuccess:e=>{o(a(`providers.subscription.importOk`,{name:K(e.account)}),e.warning?`info`:`success`),e.warning&&o(e.warning,`error`),C.refetch()},onError:e=>o(H(e),`error`)}),Ge=()=>ce.mutate(``,{onSuccess:e=>{o(a(`providers.subscription.importOk`,{name:K(e.account)}),e.warning?`info`:`success`),e.warning&&o(e.warning,`error`)},onError:e=>o(H(e),`error`)}),Ke=(e,t)=>{let n=G.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],re.mutate(n,{onError:e=>o(H(e),`error`)}))},qe=async e=>{let t=K(e);await s({title:a(`providers.subscription.logoutConfirm`,{name:t}),destructive:!0,confirmLabel:a(`providers.subscription.logout`)})&&te.mutate(e.id,{onError:e=>o(H(e),`error`)})},Je={open:e=>O(e.id),activate:e=>ne.mutate(e.id,{onSuccess:()=>o(a(`providers.subscription.activated`,{name:K(e)}),`success`),onError:e=>o(H(e),`error`)}),toggleEnabled:e=>S.mutate({id:e.id,enabled:!e.enabled},{onError:e=>o(H(e),`error`)}),refreshQuota:e=>x.mutate(e.id,{onError:e=>{e instanceof t&&e.status===501?o(a(`providers.subscription.quotaUnsupported`),`error`):o(H(e),`error`)}}),refreshToken:e=>ee.mutate(e.id,{onSuccess:()=>o(a(`providers.subscription.tokenRefreshed`),`success`),onError:e=>o(H(e),`error`)}),relogin:e=>Ve(e.id),remove:e=>void qe(e)},Ye=e=>he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),J=async e=>{let t=G.filter(e=>me.has(e.id));M(!0);let n=0;for(let r of t)try{await e(r),n++}catch(e){o(`${K(r)}: ${H(e)}`,`error`)}M(!1),he(new Set),c.invalidateQueries({queryKey:i.providerAccounts(r.id)}),n>0&&o(a(`providers.accounts.bulkDone`,{n}),`success`)},Ze=async()=>{await s({title:a(`providers.accounts.bulkDeleteConfirm`,{n:me.size}),detail:a(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:a(`common.delete`)})&&await J(e=>te.mutateAsync(e.id))},Qe=G.map(e=>Vt(e)),Y=e=>e===`all`?G.length:Qe.filter(t=>t===e).length,et=fe.trim().toLowerCase(),tt=G.map((e,t)=>({a:e,index:t,state:Qe[t]})).filter(({a:e,state:t})=>(T===`all`||t===T)&&(et.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes(et)))),nt=G.find(e=>e.id===ge)??null,X=_.data,rt=me.size>0,it=[{id:`login`,label:a(`providers.accounts.addLogin`),icon:(0,$.jsx)(Et,{className:`size-3.5`}),onSelect:()=>Ve()},{id:`login-proxy`,label:a(`providers.accounts.addLoginProxy`),onSelect:()=>xe(!0)},...ie&&C.data?.available?[{id:`codex`,separatorBefore:!0,label:a(`providers.subscription.importCodex`),icon:(0,$.jsx)(Xe,{className:`size-3.5`}),onSelect:We}]:[],...w?[{id:`copilot`,separatorBefore:!0,label:a(`providers.subscription.importCopilot`),icon:(0,$.jsx)(Xe,{className:`size-3.5`}),onSelect:Ge}]:[],...X?.supported?[{id:`token`,separatorBefore:!(ie&&C.data?.available)&&!w,label:a(`providers.accounts.addToken`),onSelect:()=>k(`token`)}]:[],...X?.apiKey?[{id:`apikey`,label:a(`providers.accounts.addApiKey`),icon:(0,$.jsx)(ot,{className:`size-3.5`}),onSelect:()=>k(`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:a(`providers.accounts.statTotal`,{n:G.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:a(`providers.accounts.statUsable`,{n:Y(`usable`)})}),Y(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:a(`providers.accounts.statCooling`,{n:Y(`cooling`)})}),Y(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:a(`providers.accounts.statDead`,{n:Y(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.providerProxy`,{proxy:r.httpProxy||a(`providers.accounts.proxyFallbackSystem`)})})]}),m.data&&(0,$.jsx)(an,{policy:m.data,onChange:e=>h.mutate({switchMode:e},{onError:e=>o(H(e),`error`)})})]}),m.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:a(m.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:m.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)(ve,{className:`w-52`,value:fe,onChange:pe,placeholder:a(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":a(`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:()=>ue(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:[a(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)(wt,{className:`size-3.5`}),onClick:()=>k(`batch`),children:a(`providers.accounts.batchImport`)}),(0,$.jsx)(Be,{label:a(`providers.accounts.add`),icon:(0,$.jsx)(mt,{className:`size-3.5`}),items:it})]}),ie&&C.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[a(`providers.subscription.localCodexFound`,{who:C.data.accountEmail??C.data.plan??a(`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:[se.data?.available?a(`providers.subscription.localCopilotFound`,{source:se.data.source??``}):a(`providers.subscription.localCopilotHint`),se.data?.detail?` · ${se.data.detail}`:``]}),d.isLoading?(0,$.jsx)(z,{className:`my-4`}):G.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Ve(),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:a(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(mt,{className:`size-3.5`}),` `,a(`providers.subscription.login`)]})]}):tt.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:a(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:tt.map(({a:e,index:t})=>(0,$.jsx)(Gt,{account:e,usage:f.data?.accounts.find(t=>t.accountId===e.id),index:t,actions:Je,selected:me.has(e.id),selecting:rt,onToggleSelect:Ye,quotaPending:x.isPending&&x.variables===e.id,onMove:G.length>1?{up:t>0?()=>Ke(t,-1):void 0,down:t<G.length-1?()=>Ke(t,1):void 0}:void 0},e.id))}),f.isError&&(0,$.jsx)(L,{tone:`danger`,title:a(`providers.usage.error`),children:H(f.error)}),G.length>0&&(0,$.jsx)(Pt,{timeZone:f.data?.timeZone}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:a(`providers.subscription.footer`)}),rt&&(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:a(`providers.accounts.selected`,{n:me.size})}),(0,$.jsx)(I,{size:`sm`,icon:(0,$.jsx)($e,{className:`size-3.5`}),disabled:j,onClick:()=>void J(e=>S.mutateAsync({id:e.id,enabled:!0})),children:a(`providers.subscription.enable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>S.mutateAsync({id:e.id,enabled:!1})),children:a(`providers.subscription.disable`)}),(0,$.jsx)(I,{size:`sm`,disabled:j,onClick:()=>void J(e=>x.mutateAsync(e.id)),children:a(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(I,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:j,onClick:()=>void Ze(),children:a(`common.delete`)}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>he(new Set),children:a(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(en,{provider:r})}),(0,$.jsx)($t,{provider:r,account:nt,usage:f.data?.accounts.find(e=>e.accountId===nt?.id),usageTimeZone:f.data?.timeZone,index:nt?G.indexOf(nt):0,actions:Je,onClose:()=>O(null)}),X&&(0,$.jsx)(Bt,{providerId:r.id,info:X,mode:_e,providerProxy:r.httpProxy,onClose:()=>k(null)}),(0,$.jsx)(U,{open:be,onOpenChange:xe,title:a(`providers.accounts.loginProxyTitle`),description:a(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(I,{variant:`primary`,loading:v.isPending,disabled:Se.trim().length===0,onClick:()=>Ve(void 0,Se),children:a(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(D,{mono:!0,label:a(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:Se,onChange:e=>A(e.target.value)})}),(0,$.jsxs)(U,{open:N,onOpenChange:e=>{De(e),e||(Oe(null),je(null))},title:a(`providers.subscription.login`),description:a(`providers.subscription.loginDesc`),children:[ke&&(0,$.jsx)(L,{tone:`danger`,title:a(`providers.subscription.loginFailed`),children:ke}),F?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:a(`providers.subscription.pasteTitle`),children:a(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(I,{onClick:()=>window.open(F.authorizeUrl,`_blank`,`noopener`),children:a(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(D,{mono:!0,value:R,onChange:e=>B(e.target.value),placeholder:a(`providers.subscription.pastePlaceholder`),"aria-label":a(`providers.subscription.pasteCode`)}),(0,$.jsx)(I,{variant:`primary`,loading:Me,onClick:()=>void Ue(),children:a(`providers.subscription.pasteSubmit`)})]}),F?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:a(`providers.subscription.waiting`),children:a(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(I,{onClick:()=>window.open(F.authorizeUrl,`_blank`,`noopener`),children:a(`providers.subscription.openAuthorize`)}),(0,$.jsx)(I,{variant:`primary`,onClick:()=>{c.invalidateQueries({queryKey:i.providerAccounts(r.id)}),d.refetch()},children:a(`providers.subscription.doneAuthorize`)})]})]}),F?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:a(`providers.subscription.waiting`),children:a(`providers.subscription.cliDetail`)}),(0,$.jsx)(I,{onClick:()=>window.open(F.authorizeUrl,`_blank`,`noopener`),children:a(`providers.subscription.openAuthorize`)})]}),F?.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:a(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:F.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[F.verificationUrl&&(0,$.jsx)(I,{onClick:()=>window.open(F.verificationUrl??void 0,`_blank`,`noopener`),children:a(`providers.subscription.visitPage`)}),(0,$.jsx)(I,{variant:`primary`,loading:Me,onClick:()=>void He(),children:a(`providers.subscription.checkNow`)})]}),(0,$.jsx)(L,{tone:`info`,title:a(`providers.subscription.waiting`),children:a(`providers.subscription.checkNowHint`)})]})]})]})}function an({policy:e,onChange:t}){let{t:n}=E();return(0,$.jsx)(ce,{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 on({provider:e}){let{t}=E(),n=Ee(e.id),r=le(e.id),i=re(e.id),a=l(e.id,!0),o=Le(e.id),{toast:s}=W(),[c,u]=(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:H(i.error)}),i.data?.map(e=>(0,$.jsx)(I,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(ot,{className:`size-3.5`}):(0,$.jsx)(Et,{className:`size-3.5`}),onClick:()=>u(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)(pe,{icon:(0,$.jsx)(Ot,{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)(an,{policy:a.data,onChange:e=>o.mutate({switchMode:e},{onError:e=>s(H(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)(cn,{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:H(r.error)}),n.data&&n.data.length>0&&(0,$.jsx)(Pt,{timeZone:r.data?.timeZone}),(0,$.jsx)(sn,{provider:e}),c&&(0,$.jsx)(ln,{provider:e,method:c,onClose:()=>u(null)})]})}function sn({provider:e}){let{t,locale:n}=E(),{toast:r}=W(),i=u(e.id),a=f(e.id);if(!i.data?.supported)return null;let o=e=>a.mutate(e,{onError:e=>r(H(e),`error`)}),s={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:i.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>o(e)}),(0,$.jsx)(I,{size:`sm`,loading:a.isPending,onClick:()=>o(),children:t(`pluginAccounts.checkinNow`)})]}),i.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?c(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:s[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(M,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function cn({provider:e,account:t,gatewayUsage:n}){let{t:r,locale:i}=E(),{toast:a,confirm:o}=W(),l=C(e.id),[u,d]=(0,Q.useState)(!1),f=e.settings?.plugin?.usage===!0,p=s(e.id,t.id,u),m=async()=>{await o({title:r(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:r(`pluginAccounts.signOut`),destructive:!0})&&l.mutate(t.id,{onError:e=>a(H(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`)}),f&&(0,$.jsx)(I,{size:`sm`,onClick:()=>d(e=>!e),children:r(`pluginAccounts.usage`)}),(0,$.jsx)(I,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(Y,{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)(Nt,{usage:n}),u&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[p.isLoading&&(0,$.jsx)(z,{lines:2}),p.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:H(p.error)}),p.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:p.data.error}),p.data?.plan&&(0,$.jsx)(O,{label:r(`pluginAccounts.plan`),children:p.data.plan}),p.data?.until&&(0,$.jsx)(O,{label:r(`pluginAccounts.until`),children:c(p.data.until,i)}),p.data?.windows?.map(e=>(0,$.jsxs)(O,{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:c(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function ln({provider:e,method:t,onClose:n}){let{t:i}=E(),{toast:a}=W(),[s,c]=(0,Q.useState)({}),[l,u]=(0,Q.useState)(void 0),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),te=ee(e.id),S=o(e.id),re=ie(e.id),C=ne(e.id,b).data;(0,Q.useEffect)(()=>{let n=!0;return r(e.id,t.index,s).then(e=>{n&&(u(e.prompt),f(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&a(H(e),`error`)),()=>{n=!1}},[e.id,t.index,s,a]),(0,Q.useEffect)(()=>{C?.state===`done`&&(a(i(`pluginAccounts.signedIn`),`success`),n())},[C?.state,n,i,a]);let ae=async()=>{if(!l)return;let n=await _(e.id,t.index,l.key,d).catch(()=>({error:null}));if(n.error)return m(n.error);m(null),c(e=>({...e,[l.key]:d}))};return(0,$.jsxs)(U,{open:!0,onOpenChange:e=>!e&&n(),title:i(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[l===void 0&&(0,$.jsx)(z,{lines:2}),l&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:l.message,error:p??void 0,children:l.type===`select`?(0,$.jsx)(G,{value:d,onChange:f,options:(l.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(D,{value:d,placeholder:l.placeholder??void 0,onChange:e=>f(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,onClick:()=>void ae(),children:i(`pluginAccounts.continue`)})})]}),l===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:i(`pluginAccounts.key`),children:(0,$.jsx)(D,{mono:!0,type:`password`,value:h,placeholder:t.placeholder??void 0,onChange:e=>g(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!h.trim()||S.isPending,onClick:()=>S.mutate({method:t.index,inputs:s,key:h},{onSuccess:()=>(a(i(`pluginAccounts.signedIn`),`success`),n()),onError:e=>a(H(e),`error`)}),children:i(`pluginAccounts.signIn`)})})]}),l===null&&t.type!==`api`&&!C&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(Ze,{className:`size-3.5`}),disabled:te.isPending,onClick:()=>te.mutate({method:t.index,inputs:s},{onSuccess:e=>{x(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>a(H(e),`error`)}),children:i(`pluginAccounts.openPage`)})}),C&&C.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[C.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:C.instructions}),C.deviceCode&&(0,$.jsx)(O,{label:i(`pluginAccounts.deviceCode`),mono:!0,children:C.deviceCode}),C.url&&(0,$.jsx)(I,{icon:(0,$.jsx)(Ze,{className:`size-3.5`}),onClick:()=>window.open(C.url,`_blank`,`noopener`),children:i(`pluginAccounts.openAgain`)}),C.state===`waiting`&&C.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:i(`pluginAccounts.code`),children:(0,$.jsx)(D,{mono:!0,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(I,{variant:`primary`,disabled:!v.trim()||re.isPending,onClick:()=>re.mutate({flow:C.id,code:v.trim()},{onError:e=>a(H(e),`error`)}),children:i(`pluginAccounts.signIn`)})})]}),C.state===`waiting`&&!C.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`pluginAccounts.waiting`)}),C.state===`failed`&&(0,$.jsx)(L,{tone:`danger`,title:i(`pluginAccounts.failed`),children:C.error})]})]})}function un(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 dn(){let{t:e}=E(),{id:t=``}=tt(),n=it(),r=Pe(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=je(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(lt,{title:e(`nav.providers`),leading:(0,$.jsx)(fn,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(L,{tone:`danger`,title:e(`common.error`),children:H(r.error)})});let u=r.data;return(0,$.jsx)(lt,{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)(pn,{p:u}),children:u?(0,$.jsxs)(nt,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(at,{"aria-label":u.name,children:[(0,$.jsx)(X,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(X,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(X,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(pt,{value:`models`,className:`pt-4`,children:(0,$.jsx)(hn,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(pt,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(on,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(rn,{provider:u}):(0,$.jsx)(Sn,{provider:u})}),(0,$.jsx)(pt,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(wn,{provider:u})}),(0,$.jsx)(xn,{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)(Je,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function pn({p:e}){let{t:n}=E(),r=it(),{toast:i,confirm:a}=W(),o=ke(),s=De(),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=async()=>{await a({title:n(`providers.deleteConfirm`,{name:e.name}),detail:n(`providers.deleteDetail`),destructive:!0,confirmLabel:n(`common.delete`)})&&s.mutate(e.id,{onSuccess:()=>{i(n(`providers.deleted`)),r(`/providers`)},onError:e=>{let r=e instanceof t&&e.status===409?e.details?.boundClients??[]:[];i(r.length?n(`providers.deleteBound`,{clients:r.map(e=>st[e]?.name??e).join(`, `)}):H(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{icon:(0,$.jsx)(Qe,{className:`size-3.5`}),onClick:()=>p(!0),children:n(`providers.test`)}),(0,$.jsx)(Be,{label:n(`common.more`),icon:(0,$.jsx)(J,{className:`size-4`}),items:[{id:`dup`,label:n(`providers.duplicate`),icon:(0,$.jsx)(_e,{className:`size-3.5`}),onSelect:()=>o.mutate(e.id,{onSuccess:e=>r(`/providers/${e.id}`),onError:e=>i(H(e),`error`)})},{id:`tpl`,label:n(`providers.templateUpdate`),icon:(0,$.jsx)(At,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>l(!0)},{id:`switch`,label:n(`providers.templateSwitch`),icon:(0,$.jsx)(vt,{className:`size-3.5`}),disabled:!Ge(e),onSelect:()=>d(!0)},{id:`del`,label:n(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void m()}]}),(0,$.jsx)(mn,{open:c,onOpenChange:l,provider:e}),(0,$.jsx)(We,{open:u,onOpenChange:d,provider:e}),(0,$.jsx)(Ve,{provider:e,open:f,onOpenChange:p})]})}function mn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=W(),a=d(n.id,e),o=te(n.id),s=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(U,{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(H(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(z,{}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:H(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 hn({provider:e,models:t,loading:n,selected:r,onSelect:i}){let{t:a}=E(),{toast:o}=W(),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=k(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)(ve,{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)(mt,{className:`size-3.5`}),onClick:()=>f(!0),children:a(`providers.addModels`)}),(0,$.jsx)(I,{variant:`primary`,icon:(0,$.jsx)(Ye,{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)(pe,{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?S(e.effective.contextWindow):null,Me(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(ct,{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(H(e),`error`)})})]},e.id))}),t&&(0,$.jsx)(gn,{provider:e,models:t}),(0,$.jsx)(vn,{open:d,onOpenChange:f,provider:e}),(0,$.jsx)(yn,{open:l,onOpenChange:u,provider:e})]})}function gn({provider:e,models:t}){let{t:n}=E(),{toast:r}=W(),i=h(e.id),[a,o]=(0,Q.useState)(!1),s=un(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(H(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)(dt,{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)(ge,{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)(mt,{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)(_n,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function _n({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)(U,{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)(G,{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 vn({open:e,onOpenChange:t,provider:n}){let{t:r}=E(),{toast:i}=W(),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)(U,{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(H(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(ue,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
3
3
  claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function yn({open:e,onOpenChange:n,provider:r}){let{t:i}=E(),{toast:a}=W(),o=he(r.id,e),s=y(r.id),[c,l]=(0,Q.useState)(new Set),[u,d]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&l(new Set)},[e]);let f=(o.data??[]).filter(e=>!u||e.id.toLowerCase().includes(u.toLowerCase())),p=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(U,{open:e,onOpenChange:n,width:560,title:i(`providers.fetchRemote`),description:i(`providers.fetchRemoteDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{variant:`plain`,className:`mr-auto`,onClick:()=>l(new Set(f.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:f.length===0,children:i(`common.selectAll`)}),(0,$.jsx)(I,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,$.jsx)(I,{variant:`primary`,disabled:c.size===0,loading:s.isPending,onClick:()=>s.mutate([...c],{onSuccess:e=>{n(!1),a(i(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>a(H(e),`error`)}),children:i(`providers.addSelected`,{count:c.size})})]}),children:[(0,$.jsx)(ve,{className:`mb-3`,value:u,onChange:d,placeholder:i(`providers.searchModels`)}),o.isLoading&&(0,$.jsx)(z,{lines:4}),o.isError&&(0,$.jsx)(L,{tone:`danger`,title:i(`common.error`),children:H(o.error)}),o.error instanceof t&&(0,$.jsx)(K,{className:`mt-3`,provider:r,httpStatus:o.error.details?.httpStatus}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:f.map(e=>(0,$.jsx)(j,{onClick:e.alreadyAdded?void 0:()=>p(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?i(`providers.linksTo`,{id:e.linkedSystemModelId}):i(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(M,{children:i(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ht,{"aria-label":e.id,checked:c.has(e.id),onCheckedChange:()=>p(e.id)})})},e.id))})]})}function bn({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 xn({provider:e,pm:t,onClose:n}){let{t:r}=E(),{toast:i}=W(),a=k(e.id),o=me(e.id),s=m(),[c,l]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(l(t.overrides),d(t.systemModelId??``),p(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(U,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let h={...c,pricing:f?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(H(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)(bn,{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)(et,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(U,{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)(gt,{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)(ct,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(M,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(T,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(G,{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)(T,{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)(T,{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:f,label:r(`providers.customPrice`),onChange:e=>{p(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(f?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),f?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(ut,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(xe,{maxHeight:220,children:N(t.effectivePricing)}):(0,$.jsx)(L,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function Sn({provider:e}){let{t}=E(),{toast:n}=W(),r=Oe(e.id),i=le(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(H(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:H(i.error)}),(0,$.jsx)(Nt,{usage:i.data?.accounts.find(e=>!e.accountId)}),(0,$.jsx)(Pt,{timeZone:i.data?.timeZone})]}),(0,$.jsx)(q,{provider:e})]})}function Cn(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 wn({provider:e}){let{t}=E(),{toast:n}=W(),r=Oe(e.id),i=ae(),a=(0,Q.useMemo)(()=>Cn(e),[e]),[o,s]=(0,Q.useState)(a),[c,l]=(0,Q.useState)(Object.entries(e.extraHeaders)),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{s(a),l(Object.entries(a.extraHeaders))},[a]);let m=e=>s(t=>({...t,...e})),h={...o,extraHeaders:Object.fromEntries(c.filter(([e])=>e.trim()))},g=JSON.stringify(h)!==JSON.stringify(a),_=()=>{let e={};for(let t of Object.keys(h))t!==`apiKey`&&JSON.stringify(h[t])!==JSON.stringify(a[t])&&(e[t]=h[t]);o.apiKey&&(e.apiKey=o.apiKey),r.mutate(e,{onSuccess:()=>n(t(`common.saved`),`success`),onError:e=>n(H(e),`error`)})},v=(e,t)=>m({endpoints:o.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:t(`providers.section.basic`),children:[(0,$.jsx)(j,{label:t(`providers.name`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":t(`providers.name`),value:o.name,onChange:e=>m({name:e.target.value})})}),(0,$.jsx)(j,{label:t(`common.enabled`),children:(0,$.jsx)(V,{checked:o.enabled,label:t(`common.enabled`),onChange:e=>m({enabled:e})})}),(0,$.jsx)(j,{label:t(`providers.notes`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":t(`providers.notes`),value:o.notes??``,onChange:e=>m({notes:e.target.value||null})})})]}),(0,$.jsx)(R,{title:t(`providers.section.auth`),children:(0,$.jsx)(j,{label:t(`providers.authScheme`),children:(0,$.jsx)(G,{className:`w-48`,value:o.authScheme,onChange:e=>m({authScheme:e}),options:Ke})})}),(0,$.jsxs)(R,{title:t(`providers.section.endpoints`),footer:t(`providers.endpointsFooter`),children:[o.endpoints.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(G,{className:`w-48`,value:e.protocol,onChange:e=>v(n,{protocol:e}),options:Ue}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.baseUrl`),value:e.baseUrl,onChange:e=>v(n,{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:t(`providers.fullUrl`),onChange:e=>v(n,{fullUrl:e})}),t(`providers.fullUrl`)]}),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>m({endpoints:o.endpoints.filter((e,t)=>t!==n)})})]},n)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(mt,{className:`size-3.5`}),onClick:()=>d(!0),children:t(`providers.addEndpoint`)})}),(0,$.jsx)(j,{label:t(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[t(`providers.preferredHint`),o.preferredUpstreamProtocols.filter(e=>!o.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:t(`providers.preferredMissing`,{protocol:Ue.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(ft,{label:t(`providers.preferred`),options:Ue.map(e=>{let t=o.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:o.preferredUpstreamProtocols,onValueChange:e=>{let t=o.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));m({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(R,{title:t(`providers.section.billing`),footer:t(`providers.billingFooter`),children:[(0,$.jsx)(j,{label:t(`providers.priceKey`),detail:t(`providers.priceKeyHint`),children:(0,$.jsx)(G,{className:`w-56`,value:o.priceKey==null?`inherit`:`price:${o.priceKey}`,onChange:e=>m({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:t(`providers.priceKeyDefault`,{id:e.templateId??`—`})},{value:`price:`,label:t(`providers.priceKeyNone`)},...(i.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(j,{label:t(`providers.multiplier`),detail:t(`providers.multiplierHint`),children:(0,$.jsx)(F,{className:`w-28`,label:t(`providers.multiplier`),step:.01,min:0,value:o.priceMultiplier,onChange:e=>m({priceMultiplier:e??1})})})]}),(0,$.jsxs)(R,{title:t(`providers.section.advanced`),children:[(0,$.jsx)(j,{label:t(`providers.proxy`),detail:t(`providers.proxyHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":t(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:o.httpProxy??``,onChange:e=>m({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:t(`providers.headers`)}),c.map(([e,n],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(D,{className:`w-48 font-mono`,"aria-label":t(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>l(c.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(D,{className:`flex-1 font-mono`,"aria-label":t(`providers.headerValue`),placeholder:`value`,value:n,onChange:e=>l(c.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":t(`common.delete`),onClick:()=>l(c.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(mt,{className:`size-3.5`}),onClick:()=>p(!0),children:t(`providers.addHeader`)})]}),Object.keys(e.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(ue,{label:t(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:N(o.settings),onBlur:e=>{try{m({settings:JSON.parse(e.target.value)})}catch{n(t(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(R,{title:t(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(O,{label:`ID`,children:e.id}),e.adapterId&&(0,$.jsx)(O,{label:t(`providers.adapter`),children:e.adapterId}),(0,$.jsx)(O,{label:t(`providers.boundClients`),children:e.boundClients.map(e=>st[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(Tn,{open:u,onOpenChange:d,onAdd:e=>m({endpoints:[...o.endpoints,e]})}),(0,$.jsx)(En,{open:f,onOpenChange:p,onAdd:e=>l([...c.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:g&&(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:t(`common.unsaved`)}),(0,$.jsx)(I,{size:`sm`,onClick:()=>{s(a),l(Object.entries(a.extraHeaders))},children:t(`common.revert`)}),(0,$.jsx)(I,{size:`sm`,variant:`primary`,loading:r.isPending,onClick:_,children:t(`common.save`)})]})})]})}function Tn({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)(U,{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)(G,{value:i,onChange:a,options:Ue})}),(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 En({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)(U,{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{dn as ProviderDetailPage};
@@ -1,2 +1,2 @@
1
- import{Cn as e,Di as t,Dr as n,E as r,Fa as i,G as a,Gi as o,Hi as s,Jr as c,Ki as l,La as u,Na as d,Pa as f,Q as p,Ra as m,Ui as h,Ur as g,Vi as _,Wi as v,Xn as y,Y as b,Zr as x,_ as S,b as C,c as w,ct as T,d as E,dt as ee,en as D,f as O,gn as k,h as A,i as j,kt as M,l as N,m as P,n as F,o as te,or as I,ot as L,p as R,pi as ne,qr as re,r as z,rr as ie,s as B,sr as ae,t as V,u as oe,v as H,w as U,wn as se,xt as ce,y as W,yt as le}from"./alert-CMMOyMsp.js";import{A as ue,C as de,D as fe,E as pe,O as G,T as me,X as he,a as K,ct as ge,dt as _e,ft as ve,i as ye,k as be,mt as xe,o as Se,pt as Ce,r as q,ut as we,w as Te}from"./overlays-BFrvqpMl.js";import{t as Ee}from"./arrow-left-BYi8J86q.js";import{t as De}from"./download-CSRdoXEJ.js";import{n as Oe,t as ke}from"./radio-cards-DNOgi4px.js";import{I as Ae,N as je,Q as Me,R as Ne,S as Pe,Y as Fe,_ as Ie,b as Le,et as Re,g as ze,h as Be,j as Ve,k as He,nt as Ue,s as We,tt as Ge,x as Ke,z as qe}from"./index-Ck4Qlg9B.js";import{t as Je}from"./checkbox--x0D0yfB.js";var J=m(i(),1);function Ye(e,t,n){(0,J.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var Xe={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};Xe.node;var Ze=ce(Xe),Qe={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`}]]};Qe.node;var $e=ce(Qe),et={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};et.node;var tt=ce(et),Y={card:`_card_i7fo0_3`,trigger:`_trigger_i7fo0_6`,media:`_media_i7fo0_7`,zoom:`_zoom_i7fo0_8`,content:`_content_i7fo0_9`,description:`_description_i7fo0_12`,footer:`_footer_i7fo0_13`,title:`_title_i7fo0_15`,byline:`_byline_i7fo0_22`,avatar:`_avatar_i7fo0_23`,bylineText:`_bylineText_i7fo0_26`,meta:`_meta_i7fo0_27`,status:`_status_i7fo0_28`,roll:`_roll_i7fo0_30`,line:`_line_i7fo0_31`,word:`_word_i7fo0_32`,srOnly:`_srOnly_i7fo0_33`,action:`_action_i7fo0_34`,overlay:`_overlay_i7fo0_36`,panel:`_panel_i7fo0_38`,closeSlot:`_closeSlot_i7fo0_48`,close:`_close_i7fo0_48`,details:`_details_i7fo0_51`},X=f(),{blur:nt,duration:Z,ease:rt,spring:it,stagger:at}=r,ot={...it.smooth,visualDuration:.3},st={...it.smooth,visualDuration:.26},ct=300,lt={duration:Z.instant},ut=1.04,dt={duration:Z.considered*2,ease:[...rt.standard]},ft={duration:Z.considered,ease:[...rt.standard]},pt={delay:Z.instant,duration:Z.standard,ease:[...rt.enter]},mt={delay:Z.instant,duration:Z.fast,ease:[...rt.enter]},ht={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${nt.subtle}px)`,transition:{duration:Z.fast,ease:[...rt.standard]}}},gt={enter:{opacity:0,y:`.3em`,filter:`blur(${nt.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:Z.standard,ease:[...rt.enter],delay:e*at.word}})};function _t({text:e,reduced:t}){return(0,X.jsxs)(`span`,{className:Y.status,role:`status`,children:[(0,X.jsx)(`span`,{className:Y.srOnly,children:e}),(0,X.jsx)(`span`,{className:Y.roll,"aria-hidden":`true`,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(_.span,{className:Y.line,variants:ht,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,X.jsx)(_.span,{className:Y.word,custom:t/2,variants:gt,children:e},t))},e)})})]})}function vt(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function yt({title:e,description:t,media:n,action:r,avatar:i,meta:a,status:s,details:c,open:u,defaultOpen:d=!1,onOpenChange:f,children:p,className:m,style:g,...v}){let y=h()??!1,b=(0,J.useId)(),x=(0,J.useRef)(null),S=(0,J.useRef)(null),[C,w]=(0,J.useState)(d),[T,E]=(0,J.useState)(!1),[D,O]=(0,J.useState)({}),[k,A]=(0,J.useState)(null),j=c?u??C:!1,M=!!c&&!y,N=!j&&k!==null,P=!!t,F=(0,J.useCallback)(e=>{u===void 0&&w(e),f?.(e)},[u,f]);(0,J.useEffect)(()=>{let e=x.current,t=S.current;if(!M||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=vt(e,n.borderTopLeftRadius),i=vt(e,n.getPropertyValue(`--radius-surface`)),a=t?.offsetWidth||void 0;O(e=>e.card!==void 0&&e.measure===a?e:{card:e.card??r,panel:e.panel??i,measure:a})});return n.observe(e),t&&n.observe(t),()=>n.disconnect()},[M,P]);let te=(0,J.useRef)(j);(0,J.useLayoutEffect)(()=>{let e=te.current&&!j;te.current=j;let t=x.current;if(j)A(null);else if(e&&M&&t){let e=t.getBoundingClientRect();A({top:e.top,left:e.left,width:e.width,height:e.height})}},[j,M]),(0,J.useEffect)(()=>{if(!N)return;let e=window.setTimeout(()=>A(null),ct);return()=>window.clearTimeout(e)},[N]);let I=(e,t,n=!0)=>M?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?j:N?`return`:`panel`,transition:{layout:t===`card`?st:ot}}:{},L=e=>i||a||s||r?(0,X.jsxs)(`div`,{className:Y.footer,children:[i||a||s?(0,X.jsxs)(_.div,{className:Y.byline,...I(`byline`,e,`position`),children:[i?(0,X.jsx)(`span`,{className:Y.avatar,children:i}):null,(0,X.jsxs)(`span`,{className:Y.bylineText,children:[a?(0,X.jsx)(`span`,{className:Y.meta,children:a}):null,s?(0,X.jsx)(_t,{text:s,reduced:y}):null]})]}):null,r?(0,X.jsx)(_.div,{className:Y.action,...I(`action`,e,`position`),children:r}):null]}):null,R=(0,X.jsxs)(_.article,{...v,ref:x,className:[Y.card,m].filter(Boolean).join(` `),style:{...g,borderRadius:D.card??g?.borderRadius},"data-hover":T||void 0,whileHover:y?void 0:{y:-2},onHoverStart:()=>E(!0),onHoverEnd:()=>E(!1),...I(`card`,`card`),transition:{default:it.snappy,layout:st},children:[n?(0,X.jsx)(_.div,{className:Y.media,...I(`media`,`card`),children:(0,X.jsx)(_.div,{className:Y.zoom,initial:!1,animate:{scale:T&&!y?ut:1},transition:T?dt:ft,children:n})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(_.h3,{className:Y.title,...I(`title`,`card`),children:c?(0,X.jsx)(ue,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:Y.trigger,children:e})}):e}),t?(0,X.jsx)(_.p,{ref:S,className:Y.description,...I(`description`,`card`,`position`),children:t}):null,p,L(`card`)]})]});return c?(0,X.jsx)(de,{open:j,onOpenChange:F,children:(0,X.jsxs)(o,{id:b,children:[R,(0,X.jsx)(l,{children:(j||N)&&(0,X.jsxs)(G,{forceMount:!0,children:[(0,X.jsx)(l,{children:j&&(0,X.jsx)(fe,{asChild:!0,forceMount:!0,children:(0,X.jsx)(_.div,{className:Y.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:y?lt:{duration:Z.exit,ease:[...rt.standard]}},transition:y?lt:{duration:Z.standard,ease:[...rt.enter]}})},`overlay`)}),(0,X.jsx)(me,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,X.jsxs)(_.div,{className:Y.panel,"data-framer-portal-id":b,"data-returning":N||void 0,layoutScroll:!0,style:{borderRadius:D.panel,"--card-measure":D.measure?`${D.measure}px`:void 0,...k&&N?{"--landing-top":`${k.top}px`,"--landing-left":`${k.left}px`,"--landing-width":`${k.width}px`,"--landing-height":`${k.height}px`}:{}},...M?{...I(`card`,`panel`),initial:!1,animate:D.card!==void 0&&D.panel!==void 0?{borderRadius:N?D.card:D.panel}:void 0,transition:{layout:N?st:ot,borderRadius:N?st:ot},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:lt},transition:lt},children:[n?(0,X.jsx)(_.div,{className:Y.media,...I(`media`,`panel`),children:(0,X.jsx)(_.div,{className:Y.zoom,initial:{scale:T&&!y?ut:1},animate:{scale:1},transition:ot,children:n})}):null,(0,X.jsx)(_.span,{className:Y.closeSlot,initial:y?{opacity:0}:{opacity:0,scale:.9},animate:N?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:N||y?lt:mt,children:(0,X.jsx)(Te,{asChild:!0,children:(0,X.jsx)(_.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:y?void 0:{scale:.94},transition:it.snappy,children:(0,X.jsx)(ee,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(be,{asChild:!0,children:(0,X.jsx)(_.h2,{className:Y.title,...I(`title`,`panel`),children:e})}),t?(0,X.jsx)(pe,{asChild:!0,children:(0,X.jsx)(_.p,{className:Y.description,...I(`description`,`panel`,`position`),children:t})}):null,p,L(`panel`),(0,X.jsx)(_.div,{className:Y.details,initial:!y&&{opacity:0,y:6},animate:N?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:lt},transition:N||y?lt:pt,children:c})]})]})})]},`quick-look`)})]})}):R}var Q={figure:`_figure_1clu4_1`,caption:`_caption_1clu4_1`,label:`_label_1clu4_1`,accent:`_accent_1clu4_2`,success:`_success_1clu4_2`,warning:`_warning_1clu4_2`,danger:`_danger_1clu4_2`,point:`_point_1clu4_4`,roll:`_roll_1clu4_7`,track:`_track_1clu4_9`,slot:`_slot_1clu4_9`,glyph:`_glyph_1clu4_9`,sizer:`_sizer_1clu4_11`,plot:`_plot_1clu4_14`,chart:`_chart_1clu4_17`,baseline:`_baseline_1clu4_18`,area:`_area_1clu4_20`,line:`_line_1clu4_21`,trail:`_trail_1clu4_21`,cursor:`_cursor_1clu4_24`,end:`_end_1clu4_25`},bt={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${r.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.standard,ease:[...r.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${r.blur.subtle}px)`,transition:{duration:r.duration.fast,ease:[...r.ease.standard]}})},xt={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}}},St=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),Ct=new Intl.NumberFormat(`en-US`),wt={duration:r.duration.considered*1.75,ease:[...r.ease.inOut]},Tt={duration:r.duration.fast,ease:[...r.ease.standard]};function Et(e,t){if(!e)return[];if(t)return[{slot:`all`,key:e,text:e}];if(!/\p{L}/u.test(e))return[...e].map((e,t,n)=>({slot:`n${n.length-t}`,key:e,text:e}));let n=e.split(/(?<=\s)/);return n.map((e,t)=>({slot:`w${t}`,key:n.slice(0,t+1).join(``),text:e}))}function Dt({text:e,direction:t,whole:n=!1,morph:i=!1,tone:a}){let o=!!h(),c=(0,J.useRef)(null),u=v(`auto`),[d,f]=(0,J.useState)({text:e,direction:1});d.text!==e&&f({text:e,direction:t??(St(e)<St(d.text)?-1:1)}),(0,J.useEffect)(()=>{let e=c.current;if(!e||typeof ResizeObserver>`u`)return;let t=null,n=new ResizeObserver(([n])=>{if(!n)return;let i=n.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;t!==null&&t!==e.textContent&&!o?s(u,i,r.spring.morph):u.jump(i),t=e.textContent});return n.observe(e),()=>n.disconnect()},[i,o,u]);let p=!n&&!/\p{L}/u.test(e),m=o?xt:bt,g=p?`right`:`left`;return(0,X.jsxs)(_.span,{className:Q.roll,"data-end":p||void 0,"data-whole":n||void 0,style:i?{width:u}:void 0,children:[i&&(0,X.jsx)(`span`,{ref:c,className:Q.sizer,"aria-hidden":`true`,children:e}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:g,children:Et(e,n).map(e=>(0,X.jsx)(_.span,{className:Q.slot,custom:d.direction,variants:m,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:g,children:(0,X.jsx)(_.span,{className:a?`${Q.glyph} ${a}`:Q.glyph,custom:d.direction,variants:m,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${a??``}${e.key}`)})},e.slot))})})]})}var Ot=5,kt=1.25,At=Array.from({length:161},(e,t)=>t/160);function jt(e){let t=Math.min(...e),n=Math.max(...e)-t,r=e.map(e=>n?(e-t)/n:.5),i=r.length-1,a=1/i,o=r.slice(1).map((e,t)=>(e-r[t])/a),s=r.map((e,t)=>t===0||t===i?o[0]:(Math.sign(o[t-1])+Math.sign(o[t]))*Math.min(Math.abs(o[t-1]),Math.abs(o[t]),Math.abs(o[t-1]+o[t])/4)||0);i>1&&(s[0]=(3*o[0]-s[1])/2,s[i]=(3*o[i-1]-s[i-1])/2);let c=Math.max(1,Math.min(16,Math.round(128/i))),l=[];for(let e=0;e<i;e++)for(let t=0;t<c;t++){let n=t/c,i=n*n,o=i*n,u=(2*o-3*i+1)*r[e]+(o-2*i+n)*a*s[e]+(3*i-2*o)*r[e+1]+(o-i)*a*s[e+1];l.push([(e+n)*a,Math.min(1,Math.max(0,u))])}return l.push([1,r[i]]),l}function Mt(e,t){let n=0,r=e.length-1;if(t<=e[n][0])return e[n][1];if(t>=e[r][0])return e[r][1];for(;r-n>1;){let i=n+r>>1;e[i][0]<t?n=i:r=i}let[i,a]=e[n],[o,s]=e[r];return o===i?s:a+(s-a)*(t-i)/(o-i)}function Nt(e,t,n,r){let i=e=>Ot+(1-e)*(n-10),a=e.map(([e,n])=>[e*t,i(n)]),o=a.map(([e,t])=>`${e.toFixed(2)},${t.toFixed(2)}`),s=r*t,c=i(Mt(e,r));return{points:a,line:o.join(` `),trail:`M${o.join(`L`)}`,fill:`M${o.join(`L`)}L${t},${n}L0,${n}Z`,dot:`${s},${c} ${s},${c}`,cx:s}}function Pt(e,t){let n=e.slice(1).map(([t,n],r)=>Math.hypot(t-e[r][0],n-e[r][1])),r=t*n.reduce((e,t)=>e+t,0);for(let t=0;t<n.length;t++){let i=n[t],a=e[t][0];if(r<=i)return a+(e[t+1][0]-a)*(i?r/i:1);r-=i}return e[e.length-1][0]}function Ft({data:e,label:t,value:n,change:i,tone:a=`accent`,width:o=160,height:c=52,labels:l,formatValue:u,area:d=!0,interactive:f=!0}){let p=e.length>1?e:[e[0]??0,e[0]??0],m=p.length-1,g=p.join(`,`),y=(0,J.useMemo)(()=>jt(g.split(`,`).map(Number)),[g]),b=`${t}: ${n??p[m]}. ${i??``}`.trim(),x=`sparkline${(0,J.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,S=(0,J.useRef)(null),C=(0,J.useRef)(null),w=Ge(S,{once:!0,amount:.5}),T=!!h(),[E,ee]=(0,J.useState)({w:o,h:c}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!1),j=D===null?null:Math.min(D,m),[M,N]=(0,J.useState)({index:j,direction:1});M.index!==j&&N({index:j,direction:j===null||M.index===null?1:Math.sign(j-M.index)||1});let[P]=(0,J.useState)(()=>Nt(y,o,c,1)),F=(0,J.useRef)(y),te=(0,J.useRef)(E),I=v(0),L=v(1),R=v(P.line),ne=v(P.trail),re=v(P.fill),z=v(P.dot),ie=v(P.cx),B=v(P.cx+kt+16),ae=v(P.cx+kt),V=v(0),oe=Ue(I,e=>+(e>.001)),H=(0,J.useCallback)(()=>{let{w:e,h:t}=te.current,n=I.get(),r=Nt(F.current,e,t,L.get());R.set(r.line),ne.set(r.trail),re.set(r.fill),z.set(r.dot),ie.set(r.cx),B.set(r.cx+kt+16),ae.set(r.cx+kt),V.set(n>=1?e+32:Pt(r.points,n)+16)},[L,ie,ae,z,I,re,R,B,V,ne]);Ye(L,`change`,H),Ye(I,`change`,H),(0,J.useLayoutEffect)(()=>{let e=C.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&ee(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*c/o})});return t.observe(e),()=>t.disconnect()},[c,o]),(0,J.useLayoutEffect)(()=>{te.current=E,H()},[E,H]),(0,J.useEffect)(()=>{if(T){I.jump(1);let e=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(e)}if(!w)return;let e=s(I,1,{...wt,onComplete:()=>A(!0)});return()=>e.stop()},[I,w,T]),(0,J.useEffect)(()=>{let e=F.current;if(e===y)return;if(T){F.current=y,H();return}let t=[...new Set([...At,...y.map(([e])=>e)])].sort((e,t)=>e-t),n=t.map(t=>Mt(e,t)),i=t.map(e=>Mt(y,e)),a=s(0,1,{...r.spring.smooth,onUpdate:e=>{F.current=t.map((t,r)=>[t,n[r]+(i[r]-n[r])*e]),H()},onComplete:()=>{F.current=y,H()}});return()=>a.stop()},[H,T,y]),(0,J.useEffect)(()=>{let e=j===null?1:j/m;if(T){L.jump(e);return}let t=s(L,e,r.spring.snappy);return()=>t.stop()},[L,j,m,T]);let U=j!==null,se=(e=>u?u(p[e],e):Ct.format(p[e]))(j??m),ce=l?.[j??m],W=n===void 0?void 0:U?se:n,le=j===null?i??``:n===void 0?[se,ce].filter(Boolean).join(` · `):ce??`${j+1} of ${m+1}`,ue=e=>{let t=C.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(m,Math.round((e-t.left)/t.width*m))):m},de=f?{role:`slider`,tabIndex:0,"aria-label":`${t}, explore values`,"aria-valuemin":1,"aria-valuemax":m+1,"aria-valuenow":(j??m)+1,"aria-valuetext":`${ce??(j===null?`Latest`:`Point ${j+1} of ${m+1}`)}: ${se}`,onPointerDown:e=>O(ue(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&O(ue(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&O(null)},onPointerLeave:()=>O(null),onPointerCancel:()=>O(null),onBlur:()=>O(null),onKeyDown:e=>{if(e.key===`Escape`&&U){e.preventDefault(),O(null);return}let t=j??m,n=Math.max(1,Math.round((m+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:m}[e.key];r!==void 0&&(e.preventDefault(),O(Math.max(0,Math.min(m,r))))}}:{};return(0,X.jsxs)(`figure`,{ref:S,className:Q.figure,"aria-label":b,children:[(0,X.jsxs)(`figcaption`,{className:Q.caption,children:[(0,X.jsx)(`span`,{className:Q.label,children:(0,X.jsx)(Dt,{text:t,whole:!0})}),W!==void 0&&(0,X.jsx)(`strong`,{children:(0,X.jsx)(Dt,{text:W,morph:!0})}),(0,X.jsx)(`small`,{className:Q[a],children:(0,X.jsx)(Dt,{text:le,direction:U?M.direction:void 0,tone:U?Q.point:void 0,morph:!0})})]}),(0,X.jsx)(`div`,{ref:C,className:Q.plot,"data-interactive":f||void 0,...de,children:(0,X.jsxs)(`svg`,{className:Q.chart,viewBox:`0 0 ${E.w} ${E.h}`,"aria-hidden":`true`,focusable:`false`,children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsx)(`clipPath`,{id:`${x}-lit`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:-16,y:-16,width:B,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:ae,y:-16,width:E.w+32,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:-16,y:-16,width:V,height:E.h+32})})]}),d&&(0,X.jsx)(_.path,{className:`${Q.area} ${Q[a]}`,d:re,clipPath:`url(#${x}-fill)`}),(0,X.jsx)(`line`,{className:Q.baseline,x1:`0`,y1:E.h-.5,x2:E.w,y2:E.h-.5}),(0,X.jsx)(_.path,{className:Q.trail,d:ne,clipPath:`url(#${x}-dim)`,initial:!1,animate:{opacity:U&&k?1:0},transition:T?{duration:0}:Tt}),(0,X.jsx)(_.polyline,{className:[Q.line,Q[a]].join(` `),points:R,clipPath:`url(#${x}-lit)`,style:{pathLength:I,opacity:oe}}),(0,X.jsx)(_.line,{className:Q.cursor,x1:ie,x2:ie,y1:0,y2:E.h,initial:!1,animate:{opacity:+!!U},transition:T?{duration:0}:Tt}),(0,X.jsx)(_.polyline,{className:[Q.end,Q[a]].join(` `),points:z,initial:!1,animate:{opacity:+!!k,strokeWidth:k?U?10:7:0},transition:T?{duration:0}:{opacity:Tt,strokeWidth:r.spring.snappy},fill:`none`,strokeLinecap:`round`})]})})]})}var $={root:`_root_1cea8_1`,horizontal:`_horizontal_1cea8_3`,list:`_list_1cea8_4`,item:`_item_1cea8_5`,vertical:`_vertical_1cea8_7`,compact:`_compact_1cea8_8`,head:`_head_1cea8_11`,marker:`_marker_1cea8_20`,ring:`_ring_1cea8_21`,disc:`_disc_1cea8_22`,glyph:`_glyph_1cea8_23`,icon:`_icon_1cea8_24`,connector:`_connector_1cea8_31`,fill:`_fill_1cea8_35`,text:`_text_1cea8_40`,label:`_label_1cea8_43`,slot:`_slot_1cea8_47`,slotInner:`_slotInner_1cea8_48`,description:`_description_1cea8_49`,error:`_error_1cea8_49`,caption:`_caption_1cea8_53`,captionLabel:`_captionLabel_1cea8_54`,srOnly:`_srOnly_1cea8_63`},It=e=>`blur(${e}px)`,Lt={duration:0},Rt={duration:r.duration.fast,ease:[...r.ease.standard]},zt={duration:r.duration.standard,ease:[...r.ease.enter]},Bt={opacity:0,y:`0.3em`,filter:It(r.blur.soft)},Vt={opacity:1,y:0,filter:It(0)},Ht={opacity:0,y:`-0.3em`,filter:It(r.blur.subtle)},Ut={opacity:0,scale:.5,filter:It(r.blur.subtle)},Wt={opacity:1,scale:1,filter:It(0)};function Gt({text:e,className:t,reduced:n}){let i=(0,J.useRef)(null),a=(0,J.useRef)(0),o=v(`auto`);return(0,J.useLayoutEffect)(()=>{a.current=performance.now()+700},[e]),(0,J.useEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let c=!1,l=new ResizeObserver(()=>{let t=e.offsetHeight;if(!c||n||performance.now()>a.current){c=!0,o.jump(t);return}s(o,t,r.spring.smooth)});return l.observe(e),()=>l.disconnect()},[o,n]),(0,X.jsx)(_.span,{className:$.slot,style:{height:o},children:(0,X.jsx)(`span`,{ref:i,className:$.slotInner,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,children:e?(0,X.jsx)(_.span,{className:t,initial:Bt,animate:Vt,exit:{...Ht,transition:n?Lt:Rt},transition:n?Lt:zt,children:e},`${t}:${e}`):null})})})}function Kt({kind:e,number:t,delay:n,reduced:i}){let a=i?Lt:{scale:{...r.spring.snappy,delay:n},opacity:{duration:r.duration.fast,delay:n},filter:{duration:r.duration.fast,delay:n}},o={...Ut,transition:i?Lt:Rt},s=i?Lt:{duration:r.duration.standard,ease:r.ease.enter,delay:n+.04};return e===`number`?(0,X.jsx)(_.span,{className:$.glyph,initial:Ut,animate:Wt,exit:o,transition:a,children:t}):(0,X.jsx)(_.svg,{className:`${$.glyph} ${$.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:Ut,animate:Wt,exit:o,transition:a,children:e===`check`?(0,X.jsx)(_.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:s}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(_.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Lt:{...r.spring.snappy,delay:n+.16}})]})})}function qt({number:e,kind:t,current:n,glyphDelay:i,ringDelay:a,reduced:o}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(l,{initial:!1,children:n?(0,X.jsx)(_.span,{className:$.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?Lt:Rt},transition:o?Lt:{scale:{...r.spring.snappy,delay:a},opacity:{duration:r.duration.fast,delay:a}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(l,{initial:!1,children:(0,X.jsx)(Kt,{kind:t,number:e,delay:i,reduced:o},t)})})]})}var Jt={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Yt({steps:e,current:t,orientation:n=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let u=h()??!1,d=e.length,f=Math.min(Math.max(Math.round(t),0),d),[p,m]=(0,J.useState)({to:f,from:f});p.to!==f&&m({to:f,from:p.to});let g=p.from,v=r.stagger.line,y=e=>u?0:f>g?e>=g&&e<f?(e-g)*v:0:e>=f&&e<g?(g-1-e)*v:0,b=u?0:Math.max(0,Math.abs(f-g)-1)*v+.12,x=!!i,S=n===`vertical`,C=f>=d?void 0:e[f];function w(e){let t=!S&&getComputedStyle(e.currentTarget).direction===`rtl`,n=[`ArrowUp`,t?`ArrowRight`:`ArrowLeft`],r=[`ArrowDown`,t?`ArrowLeft`:`ArrowRight`];if(![...n,...r,`Home`,`End`].includes(e.key))return;let i=Array.from(e.currentTarget.querySelectorAll(`button[data-reachable]`)),a=i.indexOf(e.target);a<0||(e.preventDefault(),i[e.key===`Home`?0:e.key===`End`?i.length-1:n.includes(e.key)?Math.max(0,a-1):Math.min(i.length-1,a+1)]?.focus())}let T=x?`nav`:`div`,E=[$.root,S?$.vertical:$.horizontal,o?$.compact:``,l].filter(Boolean).join(` `);return(0,X.jsxs)(T,{className:E,"aria-label":s,role:x?void 0:`group`,children:[(0,X.jsx)(`ol`,{className:$.list,style:S?void 0:{gridTemplateColumns:d>1?`repeat(${d-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:x?w:void 0,children:e.map((e,t)=>{let o=t===f,s=e.error?`error`:t<f?`complete`:o?`current`:`upcoming`,c=x&&t<f,l=e.error??(a===`all`||o?e.description:void 0),p=e.error?`error`:t<f?`check`:`number`,m=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qt,{number:t+1,kind:p,current:o,glyphDelay:y(t),ringDelay:b,reduced:u}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:e.label}),Jt[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Jt[s]]}):null,(0,X.jsx)(Gt,{text:l,className:e.error?$.error:$.description,reduced:u})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[t<d-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(_.span,{className:$.fill,initial:!1,animate:S?{scaleY:+(t<f)}:{scaleX:+(t<f)},transition:u?Lt:{...r.spring.smooth,delay:y(t)}},n)}):null,x?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":t<=f||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>i?.(t):void 0,children:m}):(0,X.jsx)(`span`,{className:$.head,"aria-current":o?`step`:void 0,children:m})]},e.id)})}),S?null:(0,X.jsxs)(`span`,{className:$.caption,"aria-hidden":`true`,children:[(0,X.jsx)(Gt,{text:C?.label??c,className:$.captionLabel,reduced:u}),(0,X.jsx)(Gt,{text:C?.error??C?.description,className:C?.error?$.error:$.description,reduced:u})]}),(0,X.jsx)(`span`,{className:$.srOnly,"aria-live":`polite`,children:C?`Step ${f+1} of ${d}: ${C.label}`:c})]})}var Xt={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Zt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},Qt=e=>`${e.source}\u0000${e.ref}`,$t=e=>e.status!==`skip`&&e.status!==`same`;function en(e){try{return new URL(e).host}catch{return e}}function tn({open:t,onOpenChange:n}){let{t:r}=T(),{toast:i}=Se(),a=se(t),o=e(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(new Set),[d,f]=(0,J.useState)(null);(0,J.useEffect)(()=>{a.data&&u(new Set(a.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Qt)))},[a.data]),(0,J.useEffect)(()=>{t&&(c(``),f(null))},[t]);let p=s.trim().toLowerCase(),m=e=>!p||e.name.toLowerCase().includes(p)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(p)),h=(0,J.useMemo)(()=>(a.data??[]).flatMap(e=>e.items).filter(e=>l.has(Qt(e))&&$t(e)),[a.data,l]),g=(e,t)=>u(n=>{let r=new Set(n);return t?r.add(Qt(e)):r.delete(Qt(e)),r});return(0,X.jsx)(ye,{open:t,onOpenChange:n,width:680,title:r(`import.title`),description:r(`import.detail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{icon:(0,X.jsx)(Ne,{className:`size-3.5`}),onClick:()=>void a.refetch(),disabled:a.isFetching||o.isPending,children:r(`import.rescan`)}),(0,X.jsx)(z,{variant:`primary`,disabled:h.length===0||o.isPending,onClick:()=>{f(null),o.mutate(h.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let t=e.skipped.length;i(t>0?r(`import.doneSkipped`,{count:e.added.length,skipped:t}):r(`import.done`,{count:e.added.length})),n(!1)},onError:e=>{f(K(e)),a.refetch()}})},children:r(`import.selected`,{count:h.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(A,{value:s,onChange:c,placeholder:r(`import.search`)}),d&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:d}),a.isLoading&&(0,X.jsx)(H,{lines:3}),a.isError&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),(0,X.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:a.data?.map(e=>(0,X.jsx)(nn,{source:e,matches:m,selected:l,onToggle:g,filtering:p.length>0},e.id))}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`import.footnote`)})]})})}function nn({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=T(),o=e.items.filter(t);return(0,X.jsxs)(`section`,{"aria-label":e.name,children:[(0,X.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:a(`import.path`,{path:e.path}),children:e.path})]}),e.error?(0,X.jsx)(V,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,X.jsx)(rn,{c:e,checked:n.has(Qt(e)),onToggle:t=>r(e,t)},Qt(e)))}):(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function rn({c:e,checked:t,onToggle:n}){let{t:r}=T(),i=$t(e),a=e.status===`skip`&&e.skipReason?r(`import.skip.${e.skipReason}`):e.status===`same`&&e.existing?r(`import.existing`,{name:e.existing.name}):e.status===`sameHost`&&e.existing?r(`import.sameHostHint`,{name:e.existing.name}):null,o=e.endpoints.map(e=>`${Xt[e.protocol]??e.protocol} · ${en(e.baseUrl)}`).join(` / `);return(0,X.jsxs)(`li`,{className:L(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,X.jsx)(Je,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,X.jsx)(F,{tone:Zt[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),o&&(0,X.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:o,children:o}),(0,X.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),e.models.length>0&&(0,X.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,X.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignoredFields.join(`, `)})})]})]})}var an=``,on=`custom`,sn=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],cn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},ln={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},un=e=>JSON.stringify(e??{},null,2);function dn(e){return{enabled:e.enabled,template:e.template??an,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:un(e.request?.headers),extract:e.extract?un(e.extract):``}}function fn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function pn({provider:e}){let{t}=T(),{toast:r}=Se(),i=ae(),a=n(e.id),o=c(e.id),s=k(),l=e.quotaConfig,u=(0,J.useMemo)(()=>dn(l),[l]),[d,f]=(0,J.useState)(u),[p,m]=(0,J.useState)(null);(0,J.useEffect)(()=>f(u),[u]);let h=i.data??[],g=h.find(e=>e.id===l.suggestedTemplate),_=d.template===an?g:h.find(e=>e.id===d.template),v=d.template===on,y=v?sn:_?.params??[],b=e=>f(t=>({...t,...e})),x=JSON.stringify(d)!==JSON.stringify(u),S=e=>{if(e!==on||d.url)return b({template:e});let t=_??g;b({template:e,method:t?.request.method??cn.method,url:t?.request.url??cn.url,auth:t?.request.auth??cn.auth,headers:un(t?.request.headers??cn.headers),extract:un(t?.extract??ln)})},w=()=>{let e={enabled:d.enabled,template:d.template===an?null:d.template,intervalMinutes:d.intervalMinutes,timeoutSec:d.timeoutSec??10,baseUrl:d.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(d.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(d.secrets).filter(([,e])=>e.trim()!==``))};if(v){let n=fn(d.headers),i=fn(d.extract);if(!n||!i)return r(t(`providers.quota.invalidJson`,{field:t(n?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:d.method,url:d.url.trim(),auth:d.auth,headers:n},e.extract=i}return e},ee=()=>{let n=w();if(!n)return;let i=n.enabled&&!l.enabled;a.mutate(n,{onSuccess:()=>{r(t(`common.saved`),`success`),i&&s.mutate(e.id,{onError:e=>r(K(e),`error`)})},onError:e=>r(K(e),`error`)})},D=()=>{let e=w();e&&o.mutate(e,{onSuccess:m,onError:e=>r(K(e),`error`)})},A=l.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:l.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),M=[{value:an,label:g?t(`providers.quota.templateAuto`,{name:g.name}):t(`providers.quota.templateNone`)},...h.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:on,label:t(`providers.quota.custom`)}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(oe,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,X.jsx)(P,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,X.jsx)(W,{checked:d.enabled,label:t(`providers.quota.enable`),onChange:e=>b({enabled:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.template`),children:(0,X.jsx)(q,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:d.template,onChange:S,options:M})}),y.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=l.secrets.includes(e.name);return e.secret?(0,X.jsx)(P,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,X.jsx)(E,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:d.secrets[e.name]??``,onChange:t=>b({secrets:{...d.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(P,{label:n,children:(0,X.jsx)(E,{className:`w-64 font-mono`,"aria-label":n,value:d.params[e.name]??``,onChange:t=>b({params:{...d.params,[e.name]:t.target.value}})})},e.name)}),y.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),v&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(q,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:d.method,onChange:e=>b({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(E,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:d.url,onChange:e=>b({url:e.target.value})}),(0,X.jsx)(q,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:d.auth,onChange:e=>b({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,X.jsx)(C,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:d.headers,onChange:e=>b({headers:e.target.value})}),(0,X.jsx)(C,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:d.extract,onChange:e=>b({extract:e.target.value})}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,X.jsx)(P,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:A}),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:d.intervalMinutes,onChange:e=>b({intervalMinutes:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.timeout`),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:d.timeoutSec,onChange:e=>b({timeoutSec:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(E,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:d.baseUrl,onChange:e=>b({baseUrl:e.target.value})})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,X.jsx)(z,{size:`sm`,variant:`primary`,disabled:!x,loading:a.isPending,onClick:ee,children:t(`common.save`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),loading:o.isPending,onClick:D,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)($e,{className:`size-3.5`}),disabled:x,loading:s.isPending,onClick:()=>s.mutate(e.id,{onError:e=>r(K(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(mn,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,X.jsx)(ye,{open:p!==null,onOpenChange:e=>!e&&m(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:p&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(V,{tone:p.ok?`success`:`danger`,title:p.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!p.ok&&ge({code:p.errorCode??null,message:p.error??``},t),!p.ok&&p.error&&p.errorCode&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:p.error})]}),p.url&&(0,X.jsx)(O,{label:t(`providers.quota.requestUrl`),mono:!0,children:p.url}),p.httpStatus!=null&&(0,X.jsx)(O,{label:t(`providers.quota.httpStatus`),children:p.httpStatus}),p.snapshot&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,X.jsx)(mn,{snapshot:p.snapshot})]}),p.raw!==void 0&&p.raw!==null&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,X.jsx)(j,{children:un(p.raw)})]})]})})]})}function mn({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=T(),i=Ce(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,X.jsxs)(V,{tone:`warning`,title:n(`providers.quota.failed`,{error:ge(i,n)}),children:[(0,X.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,X.jsx)(V,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,X.jsx)(F,{children:e.name}),(0,X.jsx)(`span`,{className:`num`,children:we(e,n,r)??`—`}),_e(e,n,r)&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:_e(e,n,r)}),e.extra&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,X.jsx)(F,{tone:`accent`,children:e.planLabel}),o>0&&(0,X.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:he(o,r,n(`tray.justNow`))??``})})]})]})}function hn({provider:e}){let{t,locale:n}=T(),{toast:r}=Se(),i=k();if(!ve(e))return null;let a=xe(e.quota,t,n),o=Ce(e.quota);return(0,X.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-center gap-2 text-[12px]`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a&&(0,X.jsx)(`div`,{className:`num truncate text-[var(--text-secondary)]`,title:a,children:a}),o&&(0,X.jsx)(`div`,{className:`truncate text-[var(--warning)]`,title:o.message,children:t(`providers.quota.failed`,{error:ge(o,t)})}),!a&&!o&&(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)($e,{className:`size-3.5`}),"aria-label":t(`providers.quota.refresh`),title:t(`providers.quota.refresh`),loading:i.isPending,onClick:()=>i.mutate(e.id,{onError:e=>r(K(e),`error`)})})]})}var gn=e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,_n=e=>e.category!==`subscription`&&e.category!==`custom`&&e.authScheme!==`oauth-subscription`;function vn({open:e,onOpenChange:t,provider:n}){let{t:r}=T(),{toast:i}=Se(),a=re(),o=g(n.id),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),d=(a.data??[]).filter(_n);(0,J.useEffect)(()=>{e&&(c(n.templateId??``),u(``))},[e,n.templateId]);let f=d.find(e=>e.id===s),p=f?f.variants?.find(e=>e.id===l)?.endpointsOverride??f.endpoints:[],m=s===n.templateId&&!l;return(0,X.jsxs)(ye,{open:e,onOpenChange:t,title:r(`providers.templateSwitch`),description:r(`providers.templateSwitchDetail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!f||m,loading:o.isPending,onClick:()=>f&&o.mutate({templateId:f.id,variantId:l||null},{onSuccess:()=>{t(!1),i(r(`providers.templateSwitched`,{name:f.name}),`success`)},onError:e=>i(K(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,X.jsx)(H,{}),a.isError&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(N,{label:r(`providers.templateSwitchTarget`),children:(0,X.jsx)(q,{value:s,onChange:e=>{c(e),u(``)},options:d.map(e=>({value:e.id,label:e.id===n.templateId?r(`providers.templateSwitchCurrent`,{name:e.name}):e.name,detail:e.id}))})}),f?.variants&&f.variants.length>0&&(0,X.jsx)(N,{label:r(`providers.variant`),children:(0,X.jsx)(q,{value:l,onChange:u,options:[{value:``,label:r(`providers.variantDefault`)},...f.variants.map(e=>({value:e.id,label:e.name}))]})}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:r(`providers.templateSwitchEndpoints`)}),(0,X.jsx)(`ul`,{className:`grid gap-1 text-[12px]`,children:p.map(e=>(0,X.jsxs)(`li`,{className:`flex gap-3`,children:[(0,X.jsx)(`span`,{className:`w-36 shrink-0 text-[var(--text-secondary)]`,children:Bn.find(t=>t.value===e.protocol)?.label??e.protocol}),(0,X.jsx)(`span`,{className:`min-w-0 font-mono break-all`,children:e.baseUrl})]},e.protocol))})]})]})]})}function yn({provider:e,httpStatus:t,className:n}){return t!==401&&t!==403||!e.templateId||!gn(e)?null:(0,X.jsx)(bn,{provider:e,className:n})}function bn({provider:e,className:t}){let{t:n}=T(),{toast:r,confirm:i}=Se(),a=re(),o=g(e.id),s=a.data?.find(t=>t.id===e.templateId),c=(s?.keyAlternatives??[]).flatMap(e=>a.data?.filter(t=>t.id===e)??[]);if(!s||c.length===0)return null;let l=async e=>{let t=[...new Set(e.endpoints.map(e=>e.baseUrl))].join(`, `);await i({title:n(`providers.templateSwitchConfirm`,{alt:e.name}),detail:n(`providers.templateSwitchConfirmDetail`,{urls:t}),confirmLabel:n(`providers.keyAlternative.switch`,{alt:e.name})})&&o.mutate({templateId:e.id},{onSuccess:()=>r(n(`providers.templateSwitched`,{name:e.name}),`success`),onError:e=>r(K(e),`error`)})};return(0,X.jsxs)(V,{className:t,tone:`warning`,title:n(`providers.keyAlternative.title`),children:[n(`providers.keyAlternative.rejected`,{name:s.name,alt:c.map(e=>e.name).join(` / `)}),(0,X.jsx)(`span`,{className:`mt-2 flex flex-wrap gap-2`,children:c.map(e=>(0,X.jsx)(z,{size:`sm`,loading:o.isPending,onClick:()=>void l(e),children:n(`providers.keyAlternative.switch`,{alt:e.name})},e.id))})]})}var xn=3,Sn=256,Cn=4096,wn={idle:`providers.testDialog.status.idle`,queued:`providers.testDialog.status.queued`,running:`providers.testDialog.status.running`,success:`providers.testDialog.status.success`,failed:`providers.testDialog.status.failed`,cancelled:`providers.testDialog.status.cancelled`};function Tn(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var En=e=>typeof e==`number`?e:null,Dn=e=>typeof e==`string`?e:null;function On({provider:e,open:t,onOpenChange:n}){let{t:r}=T(),i=d(),a=ie(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,J.useState)(`single`),[l,u]=(0,J.useState)(()=>Tn(e)),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(Sn),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(null),[C,w]=(0,J.useState)({}),[E,D]=(0,J.useState)([]),[O,k]=(0,J.useState)(new Set),[A,j]=(0,J.useState)([]),[M,P]=(0,J.useState)(``),[F,te]=(0,J.useState)(null),[I,L]=(0,J.useState)(!1),R=(0,J.useRef)(null),ne=(0,J.useRef)(new Map),re=(0,J.useRef)(!1),B=(0,J.useRef)(!1),ae=(0,J.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...A.filter(t=>!e.includes(t))]},[a.data,A]);(0,J.useEffect)(()=>{if(t){y(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}B.current=!1,R.current?.abort();for(let e of ne.current.values())e.abort();ne.current.clear(),x(null),w({}),D([]),k(new Set),j([]),P(``),te(null)},[t,a.data]);let V=(0,J.useCallback)(e=>({modelId:e,protocol:l,stream:f,prompt:m.trim()||null,maxOutputTokens:g??Sn}),[l,f,m,g]),oe=(0,J.useCallback)((t,n,r)=>Ln(e.id,t,V(t),n,r),[e.id,V]),H=()=>{let e=v.trim();if(!e)return;R.current?.abort();let t=new AbortController;R.current=t,B.current=!0,te(null),x({modelId:e,status:`running`,text:``,reasoning:``}),oe(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&se(),x(e)})},U=e=>{if(e.length===0)return;B.current=!0,re.current=!1,te(null),D(e),w(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(xn,e.length)},async()=>{for(;;){if(!B.current)return;let n=e[t++];if(n===void 0)return;if(re.current){w(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;ne.current.set(n,r),await oe(n,r.signal,e=>w(t=>({...t,[n]:e}))),ne.current.delete(n),se()}}))},se=()=>void i.invalidateQueries({queryKey:[`requests`]}),ce=()=>{re.current=!0,w(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},W=b?.status===`running`||E.some(e=>C[e]?.status===`running`||C[e]?.status===`queued`&&!re.current),le=E.filter(e=>C[e]&&C[e].status!==`queued`&&C[e].status!==`running`).length,ue=E.filter(e=>C[e]?.status===`success`).length,de=E.filter(e=>C[e]?.status===`failed`).length,fe=(e,t)=>k(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),pe=()=>{W||n(!1)},G=e=>e.stopPropagation();return(0,X.jsx)(`span`,{onClick:G,onKeyDown:G,children:(0,X.jsxs)(ye,{open:t,onOpenChange:e=>e?n(!0):pe(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,X.jsx)(z,{disabled:W,onClick:()=>n(!1),icon:(0,X.jsx)(ee,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?W?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(tt,{className:`size-3.5`}),onClick:()=>R.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(z,{variant:`primary`,disabled:v.trim()===``,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:H,children:r(b?`providers.testDialog.retest`:`providers.testDialog.start`)}):W?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(tt,{className:`size-3.5`}),onClick:ce,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(z,{variant:`primary`,disabled:O.size===0,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:()=>U([...O]),children:r(`providers.testDialog.testN`,{count:O.size})})]}),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,X.jsx)(Ke,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,X.jsx)(S,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),te(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,X.jsx)(N,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(kn,{value:v,models:ae,onChange:y})}),(0,X.jsx)(An,{protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h}),(0,X.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,X.jsx)(jn,{provider:e,run:b,onRetest:H})]}):F===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fn,{known:ae,selected:O,onToggle:fe,onSelectAll:e=>k(e?new Set(ae):new Set),onClear:()=>k(new Set),search:M,onSearch:P,onAdd:e=>{j(t=>t.includes(e)?t:[...t,e]),k(t=>new Set(t).add(e)),P(``)},configOpen:I,onConfigOpen:L,protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h}),E.length>0?(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:W?r(`providers.testDialog.progress`,{done:le,total:E.length,ok:ue,failed:de}):r(`providers.testDialog.progressDone`,{total:E.length,ok:ue,failed:de})}),(0,X.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${le/E.length*100}%`,background:`var(--accent)`}})})]}):null,E.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(In,{order:E,runs:C,onView:te})}):null]}):(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(z,{variant:`plain`,icon:(0,X.jsx)(Ee,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>te(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:F})]}),(0,X.jsx)(jn,{provider:e,run:C[F]??null})]})]})})}function kn({value:e,models:t,onChange:n}){let{t:r}=T(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(0),[c,l]=(0,J.useState)(null),u=c===null?t:t.filter(e=>e.toLowerCase().includes(c.trim().toLowerCase())),d=()=>{l(null),s(Math.max(0,t.indexOf(e))),a(!0)},f=e=>{n(e),l(null),a(!1)};return(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(E,{className:`pr-9 font-mono`,value:e,placeholder:r(`providers.testDialog.modelPlaceholder`),"aria-expanded":i,role:`combobox`,onFocus:d,onClick:d,onChange:e=>{n(e.target.value),l(e.target.value),s(0),a(!0)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!i)return d();if(u.length===0)return;let t=e.key===`ArrowDown`?1:-1;s(e=>(e+t+u.length)%u.length)}else e.key===`Enter`&&i?(e.preventDefault(),u[o]&&f(u[o])):e.key===`Escape`&&a(!1)}}),(0,X.jsx)(`button`,{type:`button`,className:`absolute inset-y-0 right-0 grid w-8 place-items-center text-[var(--text-muted)] hover:text-[var(--text)]`,"aria-label":r(`providers.testDialog.showModels`),onClick:()=>i?a(!1):d(),children:(0,X.jsx)(le,{className:`size-4`})}),i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,X.jsx)(`ul`,{className:`absolute inset-x-0 top-full z-50 mt-1 max-h-64 overflow-auto rounded-lg border border-[var(--border)] bg-[var(--surface-raised)] py-1 shadow-lg`,children:u.length===0?(0,X.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{type:`button`,className:L(`block w-full truncate px-3 py-1.5 text-left font-mono text-[12px] hover:bg-[var(--surface-strong)]`,t===o&&`bg-[var(--surface-strong)]`),onMouseEnter:()=>s(t),onMouseDown:t=>{t.preventDefault(),f(e)},children:e})},e))})]})]})}function An({protocols:e,...t}){let{t:n}=T(),r=e.map(e=>({value:e,label:Bn.find(t=>t.value===e)?.label??e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:n(`providers.testDialog.protocol`),children:(0,X.jsx)(q,{value:t.protocol,onChange:t.onProtocol,options:r})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`providers.testDialog.stream`)}),(0,X.jsx)(W,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,X.jsx)(N,{label:n(`providers.testDialog.maxTokens`),children:(0,X.jsx)(R,{value:t.maxTokens,min:1,placeholder:String(Sn),label:n(`providers.testDialog.maxTokens`),onChange:e=>t.onMaxTokens(e===null?null:Math.min(Cn,Math.max(1,Math.round(e))))})}),(0,X.jsx)(N,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(C,{rows:4,value:t.prompt,placeholder:`Reply with OK.`,onChange:e=>t.onPrompt(e.target.value)})})]})}function jn({provider:e,run:t,onRetest:n}){let{t:r}=T(),[i,a]=(0,J.useState)(`preview`),o=t?.text??``,s=t?.raw??``,c=Object.entries(t?.headers??{}),l=t?.ttftMs!=null&&t?.httpMs!=null?Math.max(0,t.ttftMs-t.httpMs):null,u=i===`raw`?s:i===`headers`?c.map(([e,t])=>`${e}: ${t}`).join(`
1
+ import{Cn as e,Di as t,Dr as n,E as r,Fa as i,G as a,Gi as o,Hi as s,Jr as c,Ki as l,La as u,Na as d,Pa as f,Q as p,Ra as m,Ui as h,Ur as g,Vi as _,Wi as v,Xn as y,Y as b,Zr as x,_ as S,b as C,c as w,ct as T,d as E,dt as ee,en as D,f as O,gn as k,h as A,i as j,kt as M,l as N,m as P,n as F,o as te,or as I,ot as L,p as R,pi as ne,qr as re,r as z,rr as ie,s as B,sr as ae,t as V,u as oe,v as H,w as U,wn as se,xt as ce,y as W,yt as le}from"./alert-VkCgBSEU.js";import{A as ue,C as de,D as fe,E as pe,O as G,T as me,X as he,a as K,ct as ge,dt as _e,ft as ve,i as ye,k as be,mt as xe,o as Se,pt as Ce,r as q,ut as we,w as Te}from"./overlays-DiAM_uxj.js";import{t as Ee}from"./arrow-left-BpFef649.js";import{t as De}from"./download-CVhnkMFM.js";import{n as Oe,t as ke}from"./radio-cards-CiZ_t5iI.js";import{I as Ae,N as je,Q as Me,R as Ne,S as Pe,Y as Fe,_ as Ie,b as Le,et as Re,g as ze,h as Be,j as Ve,k as He,nt as Ue,s as We,tt as Ge,x as Ke,z as qe}from"./index-D2dNv2tH.js";import{t as Je}from"./checkbox-YjWCwufO.js";var J=m(i(),1);function Ye(e,t,n){(0,J.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var Xe={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};Xe.node;var Ze=ce(Xe),Qe={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`}]]};Qe.node;var $e=ce(Qe),et={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};et.node;var tt=ce(et),Y={card:`_card_i7fo0_3`,trigger:`_trigger_i7fo0_6`,media:`_media_i7fo0_7`,zoom:`_zoom_i7fo0_8`,content:`_content_i7fo0_9`,description:`_description_i7fo0_12`,footer:`_footer_i7fo0_13`,title:`_title_i7fo0_15`,byline:`_byline_i7fo0_22`,avatar:`_avatar_i7fo0_23`,bylineText:`_bylineText_i7fo0_26`,meta:`_meta_i7fo0_27`,status:`_status_i7fo0_28`,roll:`_roll_i7fo0_30`,line:`_line_i7fo0_31`,word:`_word_i7fo0_32`,srOnly:`_srOnly_i7fo0_33`,action:`_action_i7fo0_34`,overlay:`_overlay_i7fo0_36`,panel:`_panel_i7fo0_38`,closeSlot:`_closeSlot_i7fo0_48`,close:`_close_i7fo0_48`,details:`_details_i7fo0_51`},X=f(),{blur:nt,duration:Z,ease:rt,spring:it,stagger:at}=r,ot={...it.smooth,visualDuration:.3},st={...it.smooth,visualDuration:.26},ct=300,lt={duration:Z.instant},ut=1.04,dt={duration:Z.considered*2,ease:[...rt.standard]},ft={duration:Z.considered,ease:[...rt.standard]},pt={delay:Z.instant,duration:Z.standard,ease:[...rt.enter]},mt={delay:Z.instant,duration:Z.fast,ease:[...rt.enter]},ht={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${nt.subtle}px)`,transition:{duration:Z.fast,ease:[...rt.standard]}}},gt={enter:{opacity:0,y:`.3em`,filter:`blur(${nt.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:Z.standard,ease:[...rt.enter],delay:e*at.word}})};function _t({text:e,reduced:t}){return(0,X.jsxs)(`span`,{className:Y.status,role:`status`,children:[(0,X.jsx)(`span`,{className:Y.srOnly,children:e}),(0,X.jsx)(`span`,{className:Y.roll,"aria-hidden":`true`,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(_.span,{className:Y.line,variants:ht,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,X.jsx)(_.span,{className:Y.word,custom:t/2,variants:gt,children:e},t))},e)})})]})}function vt(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function yt({title:e,description:t,media:n,action:r,avatar:i,meta:a,status:s,details:c,open:u,defaultOpen:d=!1,onOpenChange:f,children:p,className:m,style:g,...v}){let y=h()??!1,b=(0,J.useId)(),x=(0,J.useRef)(null),S=(0,J.useRef)(null),[C,w]=(0,J.useState)(d),[T,E]=(0,J.useState)(!1),[D,O]=(0,J.useState)({}),[k,A]=(0,J.useState)(null),j=c?u??C:!1,M=!!c&&!y,N=!j&&k!==null,P=!!t,F=(0,J.useCallback)(e=>{u===void 0&&w(e),f?.(e)},[u,f]);(0,J.useEffect)(()=>{let e=x.current,t=S.current;if(!M||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=vt(e,n.borderTopLeftRadius),i=vt(e,n.getPropertyValue(`--radius-surface`)),a=t?.offsetWidth||void 0;O(e=>e.card!==void 0&&e.measure===a?e:{card:e.card??r,panel:e.panel??i,measure:a})});return n.observe(e),t&&n.observe(t),()=>n.disconnect()},[M,P]);let te=(0,J.useRef)(j);(0,J.useLayoutEffect)(()=>{let e=te.current&&!j;te.current=j;let t=x.current;if(j)A(null);else if(e&&M&&t){let e=t.getBoundingClientRect();A({top:e.top,left:e.left,width:e.width,height:e.height})}},[j,M]),(0,J.useEffect)(()=>{if(!N)return;let e=window.setTimeout(()=>A(null),ct);return()=>window.clearTimeout(e)},[N]);let I=(e,t,n=!0)=>M?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?j:N?`return`:`panel`,transition:{layout:t===`card`?st:ot}}:{},L=e=>i||a||s||r?(0,X.jsxs)(`div`,{className:Y.footer,children:[i||a||s?(0,X.jsxs)(_.div,{className:Y.byline,...I(`byline`,e,`position`),children:[i?(0,X.jsx)(`span`,{className:Y.avatar,children:i}):null,(0,X.jsxs)(`span`,{className:Y.bylineText,children:[a?(0,X.jsx)(`span`,{className:Y.meta,children:a}):null,s?(0,X.jsx)(_t,{text:s,reduced:y}):null]})]}):null,r?(0,X.jsx)(_.div,{className:Y.action,...I(`action`,e,`position`),children:r}):null]}):null,R=(0,X.jsxs)(_.article,{...v,ref:x,className:[Y.card,m].filter(Boolean).join(` `),style:{...g,borderRadius:D.card??g?.borderRadius},"data-hover":T||void 0,whileHover:y?void 0:{y:-2},onHoverStart:()=>E(!0),onHoverEnd:()=>E(!1),...I(`card`,`card`),transition:{default:it.snappy,layout:st},children:[n?(0,X.jsx)(_.div,{className:Y.media,...I(`media`,`card`),children:(0,X.jsx)(_.div,{className:Y.zoom,initial:!1,animate:{scale:T&&!y?ut:1},transition:T?dt:ft,children:n})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(_.h3,{className:Y.title,...I(`title`,`card`),children:c?(0,X.jsx)(ue,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:Y.trigger,children:e})}):e}),t?(0,X.jsx)(_.p,{ref:S,className:Y.description,...I(`description`,`card`,`position`),children:t}):null,p,L(`card`)]})]});return c?(0,X.jsx)(de,{open:j,onOpenChange:F,children:(0,X.jsxs)(o,{id:b,children:[R,(0,X.jsx)(l,{children:(j||N)&&(0,X.jsxs)(G,{forceMount:!0,children:[(0,X.jsx)(l,{children:j&&(0,X.jsx)(fe,{asChild:!0,forceMount:!0,children:(0,X.jsx)(_.div,{className:Y.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:y?lt:{duration:Z.exit,ease:[...rt.standard]}},transition:y?lt:{duration:Z.standard,ease:[...rt.enter]}})},`overlay`)}),(0,X.jsx)(me,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,X.jsxs)(_.div,{className:Y.panel,"data-framer-portal-id":b,"data-returning":N||void 0,layoutScroll:!0,style:{borderRadius:D.panel,"--card-measure":D.measure?`${D.measure}px`:void 0,...k&&N?{"--landing-top":`${k.top}px`,"--landing-left":`${k.left}px`,"--landing-width":`${k.width}px`,"--landing-height":`${k.height}px`}:{}},...M?{...I(`card`,`panel`),initial:!1,animate:D.card!==void 0&&D.panel!==void 0?{borderRadius:N?D.card:D.panel}:void 0,transition:{layout:N?st:ot,borderRadius:N?st:ot},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:lt},transition:lt},children:[n?(0,X.jsx)(_.div,{className:Y.media,...I(`media`,`panel`),children:(0,X.jsx)(_.div,{className:Y.zoom,initial:{scale:T&&!y?ut:1},animate:{scale:1},transition:ot,children:n})}):null,(0,X.jsx)(_.span,{className:Y.closeSlot,initial:y?{opacity:0}:{opacity:0,scale:.9},animate:N?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:N||y?lt:mt,children:(0,X.jsx)(Te,{asChild:!0,children:(0,X.jsx)(_.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:y?void 0:{scale:.94},transition:it.snappy,children:(0,X.jsx)(ee,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(be,{asChild:!0,children:(0,X.jsx)(_.h2,{className:Y.title,...I(`title`,`panel`),children:e})}),t?(0,X.jsx)(pe,{asChild:!0,children:(0,X.jsx)(_.p,{className:Y.description,...I(`description`,`panel`,`position`),children:t})}):null,p,L(`panel`),(0,X.jsx)(_.div,{className:Y.details,initial:!y&&{opacity:0,y:6},animate:N?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:lt},transition:N||y?lt:pt,children:c})]})]})})]},`quick-look`)})]})}):R}var Q={figure:`_figure_1clu4_1`,caption:`_caption_1clu4_1`,label:`_label_1clu4_1`,accent:`_accent_1clu4_2`,success:`_success_1clu4_2`,warning:`_warning_1clu4_2`,danger:`_danger_1clu4_2`,point:`_point_1clu4_4`,roll:`_roll_1clu4_7`,track:`_track_1clu4_9`,slot:`_slot_1clu4_9`,glyph:`_glyph_1clu4_9`,sizer:`_sizer_1clu4_11`,plot:`_plot_1clu4_14`,chart:`_chart_1clu4_17`,baseline:`_baseline_1clu4_18`,area:`_area_1clu4_20`,line:`_line_1clu4_21`,trail:`_trail_1clu4_21`,cursor:`_cursor_1clu4_24`,end:`_end_1clu4_25`},bt={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${r.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.standard,ease:[...r.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${r.blur.subtle}px)`,transition:{duration:r.duration.fast,ease:[...r.ease.standard]}})},xt={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}}},St=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),Ct=new Intl.NumberFormat(`en-US`),wt={duration:r.duration.considered*1.75,ease:[...r.ease.inOut]},Tt={duration:r.duration.fast,ease:[...r.ease.standard]};function Et(e,t){if(!e)return[];if(t)return[{slot:`all`,key:e,text:e}];if(!/\p{L}/u.test(e))return[...e].map((e,t,n)=>({slot:`n${n.length-t}`,key:e,text:e}));let n=e.split(/(?<=\s)/);return n.map((e,t)=>({slot:`w${t}`,key:n.slice(0,t+1).join(``),text:e}))}function Dt({text:e,direction:t,whole:n=!1,morph:i=!1,tone:a}){let o=!!h(),c=(0,J.useRef)(null),u=v(`auto`),[d,f]=(0,J.useState)({text:e,direction:1});d.text!==e&&f({text:e,direction:t??(St(e)<St(d.text)?-1:1)}),(0,J.useEffect)(()=>{let e=c.current;if(!e||typeof ResizeObserver>`u`)return;let t=null,n=new ResizeObserver(([n])=>{if(!n)return;let i=n.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;t!==null&&t!==e.textContent&&!o?s(u,i,r.spring.morph):u.jump(i),t=e.textContent});return n.observe(e),()=>n.disconnect()},[i,o,u]);let p=!n&&!/\p{L}/u.test(e),m=o?xt:bt,g=p?`right`:`left`;return(0,X.jsxs)(_.span,{className:Q.roll,"data-end":p||void 0,"data-whole":n||void 0,style:i?{width:u}:void 0,children:[i&&(0,X.jsx)(`span`,{ref:c,className:Q.sizer,"aria-hidden":`true`,children:e}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:g,children:Et(e,n).map(e=>(0,X.jsx)(_.span,{className:Q.slot,custom:d.direction,variants:m,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:g,children:(0,X.jsx)(_.span,{className:a?`${Q.glyph} ${a}`:Q.glyph,custom:d.direction,variants:m,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${a??``}${e.key}`)})},e.slot))})})]})}var Ot=5,kt=1.25,At=Array.from({length:161},(e,t)=>t/160);function jt(e){let t=Math.min(...e),n=Math.max(...e)-t,r=e.map(e=>n?(e-t)/n:.5),i=r.length-1,a=1/i,o=r.slice(1).map((e,t)=>(e-r[t])/a),s=r.map((e,t)=>t===0||t===i?o[0]:(Math.sign(o[t-1])+Math.sign(o[t]))*Math.min(Math.abs(o[t-1]),Math.abs(o[t]),Math.abs(o[t-1]+o[t])/4)||0);i>1&&(s[0]=(3*o[0]-s[1])/2,s[i]=(3*o[i-1]-s[i-1])/2);let c=Math.max(1,Math.min(16,Math.round(128/i))),l=[];for(let e=0;e<i;e++)for(let t=0;t<c;t++){let n=t/c,i=n*n,o=i*n,u=(2*o-3*i+1)*r[e]+(o-2*i+n)*a*s[e]+(3*i-2*o)*r[e+1]+(o-i)*a*s[e+1];l.push([(e+n)*a,Math.min(1,Math.max(0,u))])}return l.push([1,r[i]]),l}function Mt(e,t){let n=0,r=e.length-1;if(t<=e[n][0])return e[n][1];if(t>=e[r][0])return e[r][1];for(;r-n>1;){let i=n+r>>1;e[i][0]<t?n=i:r=i}let[i,a]=e[n],[o,s]=e[r];return o===i?s:a+(s-a)*(t-i)/(o-i)}function Nt(e,t,n,r){let i=e=>Ot+(1-e)*(n-10),a=e.map(([e,n])=>[e*t,i(n)]),o=a.map(([e,t])=>`${e.toFixed(2)},${t.toFixed(2)}`),s=r*t,c=i(Mt(e,r));return{points:a,line:o.join(` `),trail:`M${o.join(`L`)}`,fill:`M${o.join(`L`)}L${t},${n}L0,${n}Z`,dot:`${s},${c} ${s},${c}`,cx:s}}function Pt(e,t){let n=e.slice(1).map(([t,n],r)=>Math.hypot(t-e[r][0],n-e[r][1])),r=t*n.reduce((e,t)=>e+t,0);for(let t=0;t<n.length;t++){let i=n[t],a=e[t][0];if(r<=i)return a+(e[t+1][0]-a)*(i?r/i:1);r-=i}return e[e.length-1][0]}function Ft({data:e,label:t,value:n,change:i,tone:a=`accent`,width:o=160,height:c=52,labels:l,formatValue:u,area:d=!0,interactive:f=!0}){let p=e.length>1?e:[e[0]??0,e[0]??0],m=p.length-1,g=p.join(`,`),y=(0,J.useMemo)(()=>jt(g.split(`,`).map(Number)),[g]),b=`${t}: ${n??p[m]}. ${i??``}`.trim(),x=`sparkline${(0,J.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,S=(0,J.useRef)(null),C=(0,J.useRef)(null),w=Ge(S,{once:!0,amount:.5}),T=!!h(),[E,ee]=(0,J.useState)({w:o,h:c}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!1),j=D===null?null:Math.min(D,m),[M,N]=(0,J.useState)({index:j,direction:1});M.index!==j&&N({index:j,direction:j===null||M.index===null?1:Math.sign(j-M.index)||1});let[P]=(0,J.useState)(()=>Nt(y,o,c,1)),F=(0,J.useRef)(y),te=(0,J.useRef)(E),I=v(0),L=v(1),R=v(P.line),ne=v(P.trail),re=v(P.fill),z=v(P.dot),ie=v(P.cx),B=v(P.cx+kt+16),ae=v(P.cx+kt),V=v(0),oe=Ue(I,e=>+(e>.001)),H=(0,J.useCallback)(()=>{let{w:e,h:t}=te.current,n=I.get(),r=Nt(F.current,e,t,L.get());R.set(r.line),ne.set(r.trail),re.set(r.fill),z.set(r.dot),ie.set(r.cx),B.set(r.cx+kt+16),ae.set(r.cx+kt),V.set(n>=1?e+32:Pt(r.points,n)+16)},[L,ie,ae,z,I,re,R,B,V,ne]);Ye(L,`change`,H),Ye(I,`change`,H),(0,J.useLayoutEffect)(()=>{let e=C.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&ee(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*c/o})});return t.observe(e),()=>t.disconnect()},[c,o]),(0,J.useLayoutEffect)(()=>{te.current=E,H()},[E,H]),(0,J.useEffect)(()=>{if(T){I.jump(1);let e=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(e)}if(!w)return;let e=s(I,1,{...wt,onComplete:()=>A(!0)});return()=>e.stop()},[I,w,T]),(0,J.useEffect)(()=>{let e=F.current;if(e===y)return;if(T){F.current=y,H();return}let t=[...new Set([...At,...y.map(([e])=>e)])].sort((e,t)=>e-t),n=t.map(t=>Mt(e,t)),i=t.map(e=>Mt(y,e)),a=s(0,1,{...r.spring.smooth,onUpdate:e=>{F.current=t.map((t,r)=>[t,n[r]+(i[r]-n[r])*e]),H()},onComplete:()=>{F.current=y,H()}});return()=>a.stop()},[H,T,y]),(0,J.useEffect)(()=>{let e=j===null?1:j/m;if(T){L.jump(e);return}let t=s(L,e,r.spring.snappy);return()=>t.stop()},[L,j,m,T]);let U=j!==null,se=(e=>u?u(p[e],e):Ct.format(p[e]))(j??m),ce=l?.[j??m],W=n===void 0?void 0:U?se:n,le=j===null?i??``:n===void 0?[se,ce].filter(Boolean).join(` · `):ce??`${j+1} of ${m+1}`,ue=e=>{let t=C.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(m,Math.round((e-t.left)/t.width*m))):m},de=f?{role:`slider`,tabIndex:0,"aria-label":`${t}, explore values`,"aria-valuemin":1,"aria-valuemax":m+1,"aria-valuenow":(j??m)+1,"aria-valuetext":`${ce??(j===null?`Latest`:`Point ${j+1} of ${m+1}`)}: ${se}`,onPointerDown:e=>O(ue(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&O(ue(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&O(null)},onPointerLeave:()=>O(null),onPointerCancel:()=>O(null),onBlur:()=>O(null),onKeyDown:e=>{if(e.key===`Escape`&&U){e.preventDefault(),O(null);return}let t=j??m,n=Math.max(1,Math.round((m+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:m}[e.key];r!==void 0&&(e.preventDefault(),O(Math.max(0,Math.min(m,r))))}}:{};return(0,X.jsxs)(`figure`,{ref:S,className:Q.figure,"aria-label":b,children:[(0,X.jsxs)(`figcaption`,{className:Q.caption,children:[(0,X.jsx)(`span`,{className:Q.label,children:(0,X.jsx)(Dt,{text:t,whole:!0})}),W!==void 0&&(0,X.jsx)(`strong`,{children:(0,X.jsx)(Dt,{text:W,morph:!0})}),(0,X.jsx)(`small`,{className:Q[a],children:(0,X.jsx)(Dt,{text:le,direction:U?M.direction:void 0,tone:U?Q.point:void 0,morph:!0})})]}),(0,X.jsx)(`div`,{ref:C,className:Q.plot,"data-interactive":f||void 0,...de,children:(0,X.jsxs)(`svg`,{className:Q.chart,viewBox:`0 0 ${E.w} ${E.h}`,"aria-hidden":`true`,focusable:`false`,children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsx)(`clipPath`,{id:`${x}-lit`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:-16,y:-16,width:B,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:ae,y:-16,width:E.w+32,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(_.rect,{x:-16,y:-16,width:V,height:E.h+32})})]}),d&&(0,X.jsx)(_.path,{className:`${Q.area} ${Q[a]}`,d:re,clipPath:`url(#${x}-fill)`}),(0,X.jsx)(`line`,{className:Q.baseline,x1:`0`,y1:E.h-.5,x2:E.w,y2:E.h-.5}),(0,X.jsx)(_.path,{className:Q.trail,d:ne,clipPath:`url(#${x}-dim)`,initial:!1,animate:{opacity:U&&k?1:0},transition:T?{duration:0}:Tt}),(0,X.jsx)(_.polyline,{className:[Q.line,Q[a]].join(` `),points:R,clipPath:`url(#${x}-lit)`,style:{pathLength:I,opacity:oe}}),(0,X.jsx)(_.line,{className:Q.cursor,x1:ie,x2:ie,y1:0,y2:E.h,initial:!1,animate:{opacity:+!!U},transition:T?{duration:0}:Tt}),(0,X.jsx)(_.polyline,{className:[Q.end,Q[a]].join(` `),points:z,initial:!1,animate:{opacity:+!!k,strokeWidth:k?U?10:7:0},transition:T?{duration:0}:{opacity:Tt,strokeWidth:r.spring.snappy},fill:`none`,strokeLinecap:`round`})]})})]})}var $={root:`_root_1cea8_1`,horizontal:`_horizontal_1cea8_3`,list:`_list_1cea8_4`,item:`_item_1cea8_5`,vertical:`_vertical_1cea8_7`,compact:`_compact_1cea8_8`,head:`_head_1cea8_11`,marker:`_marker_1cea8_20`,ring:`_ring_1cea8_21`,disc:`_disc_1cea8_22`,glyph:`_glyph_1cea8_23`,icon:`_icon_1cea8_24`,connector:`_connector_1cea8_31`,fill:`_fill_1cea8_35`,text:`_text_1cea8_40`,label:`_label_1cea8_43`,slot:`_slot_1cea8_47`,slotInner:`_slotInner_1cea8_48`,description:`_description_1cea8_49`,error:`_error_1cea8_49`,caption:`_caption_1cea8_53`,captionLabel:`_captionLabel_1cea8_54`,srOnly:`_srOnly_1cea8_63`},It=e=>`blur(${e}px)`,Lt={duration:0},Rt={duration:r.duration.fast,ease:[...r.ease.standard]},zt={duration:r.duration.standard,ease:[...r.ease.enter]},Bt={opacity:0,y:`0.3em`,filter:It(r.blur.soft)},Vt={opacity:1,y:0,filter:It(0)},Ht={opacity:0,y:`-0.3em`,filter:It(r.blur.subtle)},Ut={opacity:0,scale:.5,filter:It(r.blur.subtle)},Wt={opacity:1,scale:1,filter:It(0)};function Gt({text:e,className:t,reduced:n}){let i=(0,J.useRef)(null),a=(0,J.useRef)(0),o=v(`auto`);return(0,J.useLayoutEffect)(()=>{a.current=performance.now()+700},[e]),(0,J.useEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let c=!1,l=new ResizeObserver(()=>{let t=e.offsetHeight;if(!c||n||performance.now()>a.current){c=!0,o.jump(t);return}s(o,t,r.spring.smooth)});return l.observe(e),()=>l.disconnect()},[o,n]),(0,X.jsx)(_.span,{className:$.slot,style:{height:o},children:(0,X.jsx)(`span`,{ref:i,className:$.slotInner,children:(0,X.jsx)(l,{mode:`popLayout`,initial:!1,children:e?(0,X.jsx)(_.span,{className:t,initial:Bt,animate:Vt,exit:{...Ht,transition:n?Lt:Rt},transition:n?Lt:zt,children:e},`${t}:${e}`):null})})})}function Kt({kind:e,number:t,delay:n,reduced:i}){let a=i?Lt:{scale:{...r.spring.snappy,delay:n},opacity:{duration:r.duration.fast,delay:n},filter:{duration:r.duration.fast,delay:n}},o={...Ut,transition:i?Lt:Rt},s=i?Lt:{duration:r.duration.standard,ease:r.ease.enter,delay:n+.04};return e===`number`?(0,X.jsx)(_.span,{className:$.glyph,initial:Ut,animate:Wt,exit:o,transition:a,children:t}):(0,X.jsx)(_.svg,{className:`${$.glyph} ${$.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:Ut,animate:Wt,exit:o,transition:a,children:e===`check`?(0,X.jsx)(_.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:s}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(_.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Lt:{...r.spring.snappy,delay:n+.16}})]})})}function qt({number:e,kind:t,current:n,glyphDelay:i,ringDelay:a,reduced:o}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(l,{initial:!1,children:n?(0,X.jsx)(_.span,{className:$.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?Lt:Rt},transition:o?Lt:{scale:{...r.spring.snappy,delay:a},opacity:{duration:r.duration.fast,delay:a}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(l,{initial:!1,children:(0,X.jsx)(Kt,{kind:t,number:e,delay:i,reduced:o},t)})})]})}var Jt={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Yt({steps:e,current:t,orientation:n=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let u=h()??!1,d=e.length,f=Math.min(Math.max(Math.round(t),0),d),[p,m]=(0,J.useState)({to:f,from:f});p.to!==f&&m({to:f,from:p.to});let g=p.from,v=r.stagger.line,y=e=>u?0:f>g?e>=g&&e<f?(e-g)*v:0:e>=f&&e<g?(g-1-e)*v:0,b=u?0:Math.max(0,Math.abs(f-g)-1)*v+.12,x=!!i,S=n===`vertical`,C=f>=d?void 0:e[f];function w(e){let t=!S&&getComputedStyle(e.currentTarget).direction===`rtl`,n=[`ArrowUp`,t?`ArrowRight`:`ArrowLeft`],r=[`ArrowDown`,t?`ArrowLeft`:`ArrowRight`];if(![...n,...r,`Home`,`End`].includes(e.key))return;let i=Array.from(e.currentTarget.querySelectorAll(`button[data-reachable]`)),a=i.indexOf(e.target);a<0||(e.preventDefault(),i[e.key===`Home`?0:e.key===`End`?i.length-1:n.includes(e.key)?Math.max(0,a-1):Math.min(i.length-1,a+1)]?.focus())}let T=x?`nav`:`div`,E=[$.root,S?$.vertical:$.horizontal,o?$.compact:``,l].filter(Boolean).join(` `);return(0,X.jsxs)(T,{className:E,"aria-label":s,role:x?void 0:`group`,children:[(0,X.jsx)(`ol`,{className:$.list,style:S?void 0:{gridTemplateColumns:d>1?`repeat(${d-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:x?w:void 0,children:e.map((e,t)=>{let o=t===f,s=e.error?`error`:t<f?`complete`:o?`current`:`upcoming`,c=x&&t<f,l=e.error??(a===`all`||o?e.description:void 0),p=e.error?`error`:t<f?`check`:`number`,m=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qt,{number:t+1,kind:p,current:o,glyphDelay:y(t),ringDelay:b,reduced:u}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:e.label}),Jt[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Jt[s]]}):null,(0,X.jsx)(Gt,{text:l,className:e.error?$.error:$.description,reduced:u})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[t<d-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(_.span,{className:$.fill,initial:!1,animate:S?{scaleY:+(t<f)}:{scaleX:+(t<f)},transition:u?Lt:{...r.spring.smooth,delay:y(t)}},n)}):null,x?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":t<=f||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>i?.(t):void 0,children:m}):(0,X.jsx)(`span`,{className:$.head,"aria-current":o?`step`:void 0,children:m})]},e.id)})}),S?null:(0,X.jsxs)(`span`,{className:$.caption,"aria-hidden":`true`,children:[(0,X.jsx)(Gt,{text:C?.label??c,className:$.captionLabel,reduced:u}),(0,X.jsx)(Gt,{text:C?.error??C?.description,className:C?.error?$.error:$.description,reduced:u})]}),(0,X.jsx)(`span`,{className:$.srOnly,"aria-live":`polite`,children:C?`Step ${f+1} of ${d}: ${C.label}`:c})]})}var Xt={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Zt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},Qt=e=>`${e.source}\u0000${e.ref}`,$t=e=>e.status!==`skip`&&e.status!==`same`;function en(e){try{return new URL(e).host}catch{return e}}function tn({open:t,onOpenChange:n}){let{t:r}=T(),{toast:i}=Se(),a=se(t),o=e(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(new Set),[d,f]=(0,J.useState)(null);(0,J.useEffect)(()=>{a.data&&u(new Set(a.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Qt)))},[a.data]),(0,J.useEffect)(()=>{t&&(c(``),f(null))},[t]);let p=s.trim().toLowerCase(),m=e=>!p||e.name.toLowerCase().includes(p)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(p)),h=(0,J.useMemo)(()=>(a.data??[]).flatMap(e=>e.items).filter(e=>l.has(Qt(e))&&$t(e)),[a.data,l]),g=(e,t)=>u(n=>{let r=new Set(n);return t?r.add(Qt(e)):r.delete(Qt(e)),r});return(0,X.jsx)(ye,{open:t,onOpenChange:n,width:680,title:r(`import.title`),description:r(`import.detail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{icon:(0,X.jsx)(Ne,{className:`size-3.5`}),onClick:()=>void a.refetch(),disabled:a.isFetching||o.isPending,children:r(`import.rescan`)}),(0,X.jsx)(z,{variant:`primary`,disabled:h.length===0||o.isPending,onClick:()=>{f(null),o.mutate(h.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let t=e.skipped.length;i(t>0?r(`import.doneSkipped`,{count:e.added.length,skipped:t}):r(`import.done`,{count:e.added.length})),n(!1)},onError:e=>{f(K(e)),a.refetch()}})},children:r(`import.selected`,{count:h.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(A,{value:s,onChange:c,placeholder:r(`import.search`)}),d&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:d}),a.isLoading&&(0,X.jsx)(H,{lines:3}),a.isError&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),(0,X.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:a.data?.map(e=>(0,X.jsx)(nn,{source:e,matches:m,selected:l,onToggle:g,filtering:p.length>0},e.id))}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`import.footnote`)})]})})}function nn({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=T(),o=e.items.filter(t);return(0,X.jsxs)(`section`,{"aria-label":e.name,children:[(0,X.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:a(`import.path`,{path:e.path}),children:e.path})]}),e.error?(0,X.jsx)(V,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,X.jsx)(rn,{c:e,checked:n.has(Qt(e)),onToggle:t=>r(e,t)},Qt(e)))}):(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function rn({c:e,checked:t,onToggle:n}){let{t:r}=T(),i=$t(e),a=e.status===`skip`&&e.skipReason?r(`import.skip.${e.skipReason}`):e.status===`same`&&e.existing?r(`import.existing`,{name:e.existing.name}):e.status===`sameHost`&&e.existing?r(`import.sameHostHint`,{name:e.existing.name}):null,o=e.endpoints.map(e=>`${Xt[e.protocol]??e.protocol} · ${en(e.baseUrl)}`).join(` / `);return(0,X.jsxs)(`li`,{className:L(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,X.jsx)(Je,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,X.jsx)(F,{tone:Zt[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),o&&(0,X.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:o,children:o}),(0,X.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),e.models.length>0&&(0,X.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,X.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignoredFields.join(`, `)})})]})]})}var an=``,on=`custom`,sn=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],cn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},ln={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},un=e=>JSON.stringify(e??{},null,2);function dn(e){return{enabled:e.enabled,template:e.template??an,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:un(e.request?.headers),extract:e.extract?un(e.extract):``}}function fn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function pn({provider:e}){let{t}=T(),{toast:r}=Se(),i=ae(),a=n(e.id),o=c(e.id),s=k(),l=e.quotaConfig,u=(0,J.useMemo)(()=>dn(l),[l]),[d,f]=(0,J.useState)(u),[p,m]=(0,J.useState)(null);(0,J.useEffect)(()=>f(u),[u]);let h=i.data??[],g=h.find(e=>e.id===l.suggestedTemplate),_=d.template===an?g:h.find(e=>e.id===d.template),v=d.template===on,y=v?sn:_?.params??[],b=e=>f(t=>({...t,...e})),x=JSON.stringify(d)!==JSON.stringify(u),S=e=>{if(e!==on||d.url)return b({template:e});let t=_??g;b({template:e,method:t?.request.method??cn.method,url:t?.request.url??cn.url,auth:t?.request.auth??cn.auth,headers:un(t?.request.headers??cn.headers),extract:un(t?.extract??ln)})},w=()=>{let e={enabled:d.enabled,template:d.template===an?null:d.template,intervalMinutes:d.intervalMinutes,timeoutSec:d.timeoutSec??10,baseUrl:d.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(d.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(d.secrets).filter(([,e])=>e.trim()!==``))};if(v){let n=fn(d.headers),i=fn(d.extract);if(!n||!i)return r(t(`providers.quota.invalidJson`,{field:t(n?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:d.method,url:d.url.trim(),auth:d.auth,headers:n},e.extract=i}return e},ee=()=>{let n=w();if(!n)return;let i=n.enabled&&!l.enabled;a.mutate(n,{onSuccess:()=>{r(t(`common.saved`),`success`),i&&s.mutate(e.id,{onError:e=>r(K(e),`error`)})},onError:e=>r(K(e),`error`)})},D=()=>{let e=w();e&&o.mutate(e,{onSuccess:m,onError:e=>r(K(e),`error`)})},A=l.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:l.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),M=[{value:an,label:g?t(`providers.quota.templateAuto`,{name:g.name}):t(`providers.quota.templateNone`)},...h.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:on,label:t(`providers.quota.custom`)}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(oe,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,X.jsx)(P,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,X.jsx)(W,{checked:d.enabled,label:t(`providers.quota.enable`),onChange:e=>b({enabled:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.template`),children:(0,X.jsx)(q,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:d.template,onChange:S,options:M})}),y.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=l.secrets.includes(e.name);return e.secret?(0,X.jsx)(P,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,X.jsx)(E,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:d.secrets[e.name]??``,onChange:t=>b({secrets:{...d.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(P,{label:n,children:(0,X.jsx)(E,{className:`w-64 font-mono`,"aria-label":n,value:d.params[e.name]??``,onChange:t=>b({params:{...d.params,[e.name]:t.target.value}})})},e.name)}),y.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),v&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(q,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:d.method,onChange:e=>b({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(E,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:d.url,onChange:e=>b({url:e.target.value})}),(0,X.jsx)(q,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:d.auth,onChange:e=>b({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,X.jsx)(C,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:d.headers,onChange:e=>b({headers:e.target.value})}),(0,X.jsx)(C,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:d.extract,onChange:e=>b({extract:e.target.value})}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,X.jsx)(P,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:A}),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:d.intervalMinutes,onChange:e=>b({intervalMinutes:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.timeout`),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:d.timeoutSec,onChange:e=>b({timeoutSec:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(E,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:d.baseUrl,onChange:e=>b({baseUrl:e.target.value})})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,X.jsx)(z,{size:`sm`,variant:`primary`,disabled:!x,loading:a.isPending,onClick:ee,children:t(`common.save`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),loading:o.isPending,onClick:D,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)($e,{className:`size-3.5`}),disabled:x,loading:s.isPending,onClick:()=>s.mutate(e.id,{onError:e=>r(K(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(mn,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,X.jsx)(ye,{open:p!==null,onOpenChange:e=>!e&&m(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:p&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(V,{tone:p.ok?`success`:`danger`,title:p.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!p.ok&&ge({code:p.errorCode??null,message:p.error??``},t),!p.ok&&p.error&&p.errorCode&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:p.error})]}),p.url&&(0,X.jsx)(O,{label:t(`providers.quota.requestUrl`),mono:!0,children:p.url}),p.httpStatus!=null&&(0,X.jsx)(O,{label:t(`providers.quota.httpStatus`),children:p.httpStatus}),p.snapshot&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,X.jsx)(mn,{snapshot:p.snapshot})]}),p.raw!==void 0&&p.raw!==null&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,X.jsx)(j,{children:un(p.raw)})]})]})})]})}function mn({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=T(),i=Ce(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,X.jsxs)(V,{tone:`warning`,title:n(`providers.quota.failed`,{error:ge(i,n)}),children:[(0,X.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,X.jsx)(V,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,X.jsx)(F,{children:e.name}),(0,X.jsx)(`span`,{className:`num`,children:we(e,n,r)??`—`}),_e(e,n,r)&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:_e(e,n,r)}),e.extra&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,X.jsx)(F,{tone:`accent`,children:e.planLabel}),o>0&&(0,X.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:he(o,r,n(`tray.justNow`))??``})})]})]})}function hn({provider:e}){let{t,locale:n}=T(),{toast:r}=Se(),i=k();if(!ve(e))return null;let a=xe(e.quota,t,n),o=Ce(e.quota);return(0,X.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-center gap-2 text-[12px]`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a&&(0,X.jsx)(`div`,{className:`num truncate text-[var(--text-secondary)]`,title:a,children:a}),o&&(0,X.jsx)(`div`,{className:`truncate text-[var(--warning)]`,title:o.message,children:t(`providers.quota.failed`,{error:ge(o,t)})}),!a&&!o&&(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)($e,{className:`size-3.5`}),"aria-label":t(`providers.quota.refresh`),title:t(`providers.quota.refresh`),loading:i.isPending,onClick:()=>i.mutate(e.id,{onError:e=>r(K(e),`error`)})})]})}var gn=e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,_n=e=>e.category!==`subscription`&&e.category!==`custom`&&e.authScheme!==`oauth-subscription`;function vn({open:e,onOpenChange:t,provider:n}){let{t:r}=T(),{toast:i}=Se(),a=re(),o=g(n.id),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),d=(a.data??[]).filter(_n);(0,J.useEffect)(()=>{e&&(c(n.templateId??``),u(``))},[e,n.templateId]);let f=d.find(e=>e.id===s),p=f?f.variants?.find(e=>e.id===l)?.endpointsOverride??f.endpoints:[],m=s===n.templateId&&!l;return(0,X.jsxs)(ye,{open:e,onOpenChange:t,title:r(`providers.templateSwitch`),description:r(`providers.templateSwitchDetail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!f||m,loading:o.isPending,onClick:()=>f&&o.mutate({templateId:f.id,variantId:l||null},{onSuccess:()=>{t(!1),i(r(`providers.templateSwitched`,{name:f.name}),`success`)},onError:e=>i(K(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,X.jsx)(H,{}),a.isError&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(N,{label:r(`providers.templateSwitchTarget`),children:(0,X.jsx)(q,{value:s,onChange:e=>{c(e),u(``)},options:d.map(e=>({value:e.id,label:e.id===n.templateId?r(`providers.templateSwitchCurrent`,{name:e.name}):e.name,detail:e.id}))})}),f?.variants&&f.variants.length>0&&(0,X.jsx)(N,{label:r(`providers.variant`),children:(0,X.jsx)(q,{value:l,onChange:u,options:[{value:``,label:r(`providers.variantDefault`)},...f.variants.map(e=>({value:e.id,label:e.name}))]})}),f&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:r(`providers.templateSwitchEndpoints`)}),(0,X.jsx)(`ul`,{className:`grid gap-1 text-[12px]`,children:p.map(e=>(0,X.jsxs)(`li`,{className:`flex gap-3`,children:[(0,X.jsx)(`span`,{className:`w-36 shrink-0 text-[var(--text-secondary)]`,children:Bn.find(t=>t.value===e.protocol)?.label??e.protocol}),(0,X.jsx)(`span`,{className:`min-w-0 font-mono break-all`,children:e.baseUrl})]},e.protocol))})]})]})]})}function yn({provider:e,httpStatus:t,className:n}){return t!==401&&t!==403||!e.templateId||!gn(e)?null:(0,X.jsx)(bn,{provider:e,className:n})}function bn({provider:e,className:t}){let{t:n}=T(),{toast:r,confirm:i}=Se(),a=re(),o=g(e.id),s=a.data?.find(t=>t.id===e.templateId),c=(s?.keyAlternatives??[]).flatMap(e=>a.data?.filter(t=>t.id===e)??[]);if(!s||c.length===0)return null;let l=async e=>{let t=[...new Set(e.endpoints.map(e=>e.baseUrl))].join(`, `);await i({title:n(`providers.templateSwitchConfirm`,{alt:e.name}),detail:n(`providers.templateSwitchConfirmDetail`,{urls:t}),confirmLabel:n(`providers.keyAlternative.switch`,{alt:e.name})})&&o.mutate({templateId:e.id},{onSuccess:()=>r(n(`providers.templateSwitched`,{name:e.name}),`success`),onError:e=>r(K(e),`error`)})};return(0,X.jsxs)(V,{className:t,tone:`warning`,title:n(`providers.keyAlternative.title`),children:[n(`providers.keyAlternative.rejected`,{name:s.name,alt:c.map(e=>e.name).join(` / `)}),(0,X.jsx)(`span`,{className:`mt-2 flex flex-wrap gap-2`,children:c.map(e=>(0,X.jsx)(z,{size:`sm`,loading:o.isPending,onClick:()=>void l(e),children:n(`providers.keyAlternative.switch`,{alt:e.name})},e.id))})]})}var xn=3,Sn=256,Cn=4096,wn={idle:`providers.testDialog.status.idle`,queued:`providers.testDialog.status.queued`,running:`providers.testDialog.status.running`,success:`providers.testDialog.status.success`,failed:`providers.testDialog.status.failed`,cancelled:`providers.testDialog.status.cancelled`};function Tn(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var En=e=>typeof e==`number`?e:null,Dn=e=>typeof e==`string`?e:null;function On({provider:e,open:t,onOpenChange:n}){let{t:r}=T(),i=d(),a=ie(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,J.useState)(`single`),[l,u]=(0,J.useState)(()=>Tn(e)),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(Sn),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(null),[C,w]=(0,J.useState)({}),[E,D]=(0,J.useState)([]),[O,k]=(0,J.useState)(new Set),[A,j]=(0,J.useState)([]),[M,P]=(0,J.useState)(``),[F,te]=(0,J.useState)(null),[I,L]=(0,J.useState)(!1),R=(0,J.useRef)(null),ne=(0,J.useRef)(new Map),re=(0,J.useRef)(!1),B=(0,J.useRef)(!1),ae=(0,J.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...A.filter(t=>!e.includes(t))]},[a.data,A]);(0,J.useEffect)(()=>{if(t){y(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}B.current=!1,R.current?.abort();for(let e of ne.current.values())e.abort();ne.current.clear(),x(null),w({}),D([]),k(new Set),j([]),P(``),te(null)},[t,a.data]);let V=(0,J.useCallback)(e=>({modelId:e,protocol:l,stream:f,prompt:m.trim()||null,maxOutputTokens:g??Sn}),[l,f,m,g]),oe=(0,J.useCallback)((t,n,r)=>Ln(e.id,t,V(t),n,r),[e.id,V]),H=()=>{let e=v.trim();if(!e)return;R.current?.abort();let t=new AbortController;R.current=t,B.current=!0,te(null),x({modelId:e,status:`running`,text:``,reasoning:``}),oe(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&se(),x(e)})},U=e=>{if(e.length===0)return;B.current=!0,re.current=!1,te(null),D(e),w(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(xn,e.length)},async()=>{for(;;){if(!B.current)return;let n=e[t++];if(n===void 0)return;if(re.current){w(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;ne.current.set(n,r),await oe(n,r.signal,e=>w(t=>({...t,[n]:e}))),ne.current.delete(n),se()}}))},se=()=>void i.invalidateQueries({queryKey:[`requests`]}),ce=()=>{re.current=!0,w(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},W=b?.status===`running`||E.some(e=>C[e]?.status===`running`||C[e]?.status===`queued`&&!re.current),le=E.filter(e=>C[e]&&C[e].status!==`queued`&&C[e].status!==`running`).length,ue=E.filter(e=>C[e]?.status===`success`).length,de=E.filter(e=>C[e]?.status===`failed`).length,fe=(e,t)=>k(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),pe=()=>{W||n(!1)},G=e=>e.stopPropagation();return(0,X.jsx)(`span`,{onClick:G,onKeyDown:G,children:(0,X.jsxs)(ye,{open:t,onOpenChange:e=>e?n(!0):pe(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,X.jsx)(z,{disabled:W,onClick:()=>n(!1),icon:(0,X.jsx)(ee,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?W?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(tt,{className:`size-3.5`}),onClick:()=>R.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(z,{variant:`primary`,disabled:v.trim()===``,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:H,children:r(b?`providers.testDialog.retest`:`providers.testDialog.start`)}):W?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(tt,{className:`size-3.5`}),onClick:ce,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(z,{variant:`primary`,disabled:O.size===0,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:()=>U([...O]),children:r(`providers.testDialog.testN`,{count:O.size})})]}),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,X.jsx)(Ke,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,X.jsx)(S,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),te(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,X.jsx)(N,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(kn,{value:v,models:ae,onChange:y})}),(0,X.jsx)(An,{protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h}),(0,X.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,X.jsx)(jn,{provider:e,run:b,onRetest:H})]}):F===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fn,{known:ae,selected:O,onToggle:fe,onSelectAll:e=>k(e?new Set(ae):new Set),onClear:()=>k(new Set),search:M,onSearch:P,onAdd:e=>{j(t=>t.includes(e)?t:[...t,e]),k(t=>new Set(t).add(e)),P(``)},configOpen:I,onConfigOpen:L,protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h}),E.length>0?(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:W?r(`providers.testDialog.progress`,{done:le,total:E.length,ok:ue,failed:de}):r(`providers.testDialog.progressDone`,{total:E.length,ok:ue,failed:de})}),(0,X.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${le/E.length*100}%`,background:`var(--accent)`}})})]}):null,E.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(In,{order:E,runs:C,onView:te})}):null]}):(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(z,{variant:`plain`,icon:(0,X.jsx)(Ee,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>te(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:F})]}),(0,X.jsx)(jn,{provider:e,run:C[F]??null})]})]})})}function kn({value:e,models:t,onChange:n}){let{t:r}=T(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(0),[c,l]=(0,J.useState)(null),u=c===null?t:t.filter(e=>e.toLowerCase().includes(c.trim().toLowerCase())),d=()=>{l(null),s(Math.max(0,t.indexOf(e))),a(!0)},f=e=>{n(e),l(null),a(!1)};return(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(E,{className:`pr-9 font-mono`,value:e,placeholder:r(`providers.testDialog.modelPlaceholder`),"aria-expanded":i,role:`combobox`,onFocus:d,onClick:d,onChange:e=>{n(e.target.value),l(e.target.value),s(0),a(!0)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!i)return d();if(u.length===0)return;let t=e.key===`ArrowDown`?1:-1;s(e=>(e+t+u.length)%u.length)}else e.key===`Enter`&&i?(e.preventDefault(),u[o]&&f(u[o])):e.key===`Escape`&&a(!1)}}),(0,X.jsx)(`button`,{type:`button`,className:`absolute inset-y-0 right-0 grid w-8 place-items-center text-[var(--text-muted)] hover:text-[var(--text)]`,"aria-label":r(`providers.testDialog.showModels`),onClick:()=>i?a(!1):d(),children:(0,X.jsx)(le,{className:`size-4`})}),i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,X.jsx)(`ul`,{className:`absolute inset-x-0 top-full z-50 mt-1 max-h-64 overflow-auto rounded-lg border border-[var(--border)] bg-[var(--surface-raised)] py-1 shadow-lg`,children:u.length===0?(0,X.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{type:`button`,className:L(`block w-full truncate px-3 py-1.5 text-left font-mono text-[12px] hover:bg-[var(--surface-strong)]`,t===o&&`bg-[var(--surface-strong)]`),onMouseEnter:()=>s(t),onMouseDown:t=>{t.preventDefault(),f(e)},children:e})},e))})]})]})}function An({protocols:e,...t}){let{t:n}=T(),r=e.map(e=>({value:e,label:Bn.find(t=>t.value===e)?.label??e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:n(`providers.testDialog.protocol`),children:(0,X.jsx)(q,{value:t.protocol,onChange:t.onProtocol,options:r})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`providers.testDialog.stream`)}),(0,X.jsx)(W,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,X.jsx)(N,{label:n(`providers.testDialog.maxTokens`),children:(0,X.jsx)(R,{value:t.maxTokens,min:1,placeholder:String(Sn),label:n(`providers.testDialog.maxTokens`),onChange:e=>t.onMaxTokens(e===null?null:Math.min(Cn,Math.max(1,Math.round(e))))})}),(0,X.jsx)(N,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(C,{rows:4,value:t.prompt,placeholder:`Reply with OK.`,onChange:e=>t.onPrompt(e.target.value)})})]})}function jn({provider:e,run:t,onRetest:n}){let{t:r}=T(),[i,a]=(0,J.useState)(`preview`),o=t?.text??``,s=t?.raw??``,c=Object.entries(t?.headers??{}),l=t?.ttftMs!=null&&t?.httpMs!=null?Math.max(0,t.ttftMs-t.httpMs):null,u=i===`raw`?s:i===`headers`?c.map(([e,t])=>`${e}: ${t}`).join(`
2
2
  `):o;return(0,X.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n&&t&&t.status!==`running`?(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:n,children:r(`providers.testDialog.retest`)}):null,(0,X.jsx)(ze,{content:r(`providers.testDialog.metricsHelp`),children:(0,X.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center text-[var(--text-muted)]`,tabIndex:0,children:(0,X.jsx)(Ze,{className:`size-4`})})}),(0,X.jsx)(Pn,{run:t}),t?.httpStatus?(0,X.jsxs)(F,{tone:`neutral`,children:[`HTTP `,t.httpStatus]}):null]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-px overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--border)] sm:grid-cols-4`,children:[(0,X.jsx)(Nn,{label:r(`providers.testDialog.metrics.http`),value:t?.httpMs}),(0,X.jsx)(Nn,{label:r(`providers.testDialog.metrics.firstWait`),value:l}),(0,X.jsx)(Nn,{label:r(`providers.testDialog.metrics.ttft`),value:t?.ttftMs}),(0,X.jsx)(Nn,{label:r(`providers.testDialog.metrics.total`),value:t?.totalMs})]}),(0,X.jsxs)(`section`,{className:`card overflow-hidden`,children:[(0,X.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-[var(--border)] px-4 py-2.5`,children:[(0,X.jsx)(`h3`,{className:`text-[12px] font-medium`,children:r(`providers.testDialog.reply`)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,X.jsx)(S,{items:[{value:`preview`,label:r(`providers.testDialog.preview`)},{value:`raw`,label:r(`providers.testDialog.raw`)},{value:`headers`,label:r(`providers.testDialog.headers`)}],value:i,onChange:a,ariaLabel:r(`providers.testDialog.reply`)}),(0,X.jsx)(U,{value:u,label:r(i===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,X.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:i===`headers`?c.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.headersEmpty`)}):(0,X.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,X.jsx)(`tbody`,{children:c.map(([e,t])=>(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0 align-top`,children:[(0,X.jsx)(`th`,{className:`w-[220px] py-1.5 pr-4 text-left font-mono font-normal text-[var(--text-secondary)]`,children:e}),(0,X.jsx)(`td`,{className:`py-1.5 font-mono break-all whitespace-pre-wrap selectable`,children:t})]},e))})}):i===`raw`?s?(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[r(`providers.testDialog.rawNote`),t?.contentType?` · ${t.contentType}`:``]}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:s}),t?.rawTruncated?(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:r(`providers.testDialog.rawTruncated`)}):null]}):(0,X.jsx)(Mn,{run:t}):t?.error?(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsx)(V,{tone:`danger`,title:r(`providers.testDialog.status.failed`),children:t.error}),(0,X.jsx)(yn,{provider:e,httpStatus:t.httpStatus})]}):o||t?.reasoning?(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[t?.reasoning?(0,X.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,X.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.reasoning`)}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:t.reasoning})]}):null,o?(0,X.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:o}):null]}):t?.status===`success`?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noText`)}):(0,X.jsx)(Mn,{run:t})})]})]})}function Mn({run:e}){let{t}=T();return e?.status===`running`||e?.status===`queued`?(0,X.jsx)(`div`,{className:`grid h-full place-items-center text-[12px] text-[var(--text-muted)]`,children:t(wn[e.status])}):(0,X.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,X.jsx)(Fe,{className:`mx-auto size-6 text-[var(--text-muted)]`}),(0,X.jsx)(`div`,{className:`text-[13px]`,children:t(`providers.testDialog.emptyTitle`)}),(0,X.jsx)(`p`,{className:`mx-auto max-w-[320px] text-[11px] text-[var(--text-muted)]`,children:t(`providers.testDialog.emptyDetail`)})]})}function Nn({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`bg-[var(--surface)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e}),(0,X.jsx)(`div`,{className:`mt-1 font-mono text-[15px] tabular-nums`,children:t==null?`—`:a(t)})]})}function Pn({run:e}){let{t}=T(),n=e?.status??`idle`;return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(B,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(wn[n])]})}function Fn({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:i,search:a,onSearch:o,onAdd:s,configOpen:c,onConfigOpen:l,...u}){let{t:d}=T(),f=a.trim(),p=f.toLowerCase(),m=p?e.filter(e=>e.toLowerCase().includes(p)):e,h=f!==``&&!e.some(e=>e.toLowerCase()===p);return(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:d(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,X.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,X.jsx)(A,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,X.jsx)(z,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(z,{icon:(0,X.jsx)(Oe,{className:`size-3.5`}),onClick:()=>l(!0),children:d(`providers.testDialog.config`)})]}),(0,X.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:m.length===0&&!h?(0,X.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:d(`providers.testDialog.noModels`)}):(0,X.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,X.jsx)(Je,{checked:t.size===e.length&&e.length>0||t.size!==0&&`indeterminate`,onCheckedChange:e=>r(e!==!1),"aria-label":d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:d(`providers.testDialog.ownFilter`)})]}),h?(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(qe,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,X.jsx)(`button`,{type:`button`,className:`text-left font-mono text-[12px] text-[var(--accent)]`,onClick:()=>s(f),children:d(`providers.testDialog.addModel`,{id:f})})]}):null,m.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(Je,{checked:t.has(e),onCheckedChange:t=>n(e,t!==!1),"aria-label":e}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,title:e,children:e})]},e))]})}),(0,X.jsx)(ye,{open:c,onOpenChange:l,width:480,title:d(`providers.testDialog.config`),description:d(`providers.testDialog.savedCredentials`),children:(0,X.jsx)(`div`,{className:`grid gap-4`,children:(0,X.jsx)(An,{...u})})})]})}function In({order:e,runs:t,onView:n}){let{t:r}=T();return(0,X.jsx)(`div`,{className:`card overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border)] text-left text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.model`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.statusColumn`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.ttft`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.total`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.reply`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let i=t[e];return(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0`,children:[(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono`,children:e}),(0,X.jsx)(`td`,{className:`px-4 py-2`,children:(0,X.jsx)(Pn,{run:i??null})}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:a(i.ttftMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:a(i.totalMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2`,children:(0,X.jsx)(`button`,{type:`button`,className:`text-[var(--accent)] disabled:text-[var(--text-muted)]`,disabled:!i,onClick:()=>n(e),children:r(`providers.testDialog.view`)})})]},e)})})]})})}async function Ln(e,n,r,i,a){let o={modelId:n,status:`running`,text:``,reasoning:``};a(o);let s=e=>{o={...o,...e},a(o)};try{await M(e,r,e=>{let t=e.data??{};switch(e.event){case`headers`:s({httpStatus:En(t.httpStatus),httpMs:En(t.httpMs),contentType:Dn(t.contentType),headers:Rn(t.headers)});break;case`delta`:{let e=Dn(t.text)??``;Dn(t.kind)===`reasoning`?s({reasoning:o.reasoning+e}):s({text:o.text+e});break}case`done`:{let t=e.data;s({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,contentType:t.contentType??null,headers:Rn(t.headers)});break}}},i)}catch(e){e?.name===`AbortError`?s({status:`cancelled`,error:null}):s({status:`failed`,error:e instanceof t?e.message:String(e)})}}function Rn(e){if(typeof e!=`object`||!e)return{};let t={};for(let[n,r]of Object.entries(e))typeof r==`string`?t[n]=r:r!=null&&(t[n]=String(r));return t}var zn=u({AUTH_OPTIONS:()=>Vn,PROTOCOL_OPTIONS:()=>Bn,ProvidersPage:()=>Hn}),Bn=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],Vn=[{value:`bearer`,label:`Authorization: Bearer`},{value:`x-api-key`,label:`x-api-key`},{value:`x-goog-api-key`,label:`x-goog-api-key`},{value:`query-key`,label:`?key=`},{value:`none`,label:`—`},{value:`oauth-subscription`,label:`OAuth 订阅`}];function Hn(){let{t:e}=T(),t=Me(),[n,r]=Re(),i=I(),[a,o]=(0,J.useState)(n.get(`new`)===`1`),[s,c]=(0,J.useState)(!1);(0,J.useEffect)(()=>{n.get(`new`)===`1`&&(o(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),Ve(e=>{e===`new-provider`&&o(!0)});let l=x(`7d`,`day`,`provider`),[u,d]=(0,J.useState)(null),f=(0,J.useMemo)(()=>{let e=Wn(Un),t=new Map;for(let n of l.data??[]){let r=e.indexOf(n.bucket);if(r<0)continue;let i=t.get(n.key);i||t.set(n.key,i={requests:e.map(()=>0),costUsd:0}),i.requests[r]=(i.requests[r]??0)+n.requests,i.costUsd+=n.costUsd}return{days:e,byProvider:t}},[l.data]);return(0,X.jsxs)(Be,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{icon:(0,X.jsx)(De,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)})]}),children:[(0,X.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,X.jsx)(H,{lines:4}),i.isError&&(0,X.jsx)(V,{tone:`danger`,title:e(`common.error`),children:K(i.error)}),i.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(w,{icon:(0,X.jsx)(Ae,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,X.jsx)(z,{icon:(0,X.jsx)(De,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,X.jsx)(qn,{p:e,days:f.days,usage:f.byProvider.get(e.name),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>d(e)},e.id))})]}),(0,X.jsx)(tn,{open:s,onOpenChange:c}),(0,X.jsx)(ar,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),u&&(0,X.jsx)(On,{provider:u,open:!0,onOpenChange:e=>!e&&d(null)})]})}var Un=7;function Wn(e){let t=new Date;return Array.from({length:e},(n,r)=>{let i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(e-1-r));return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,`0`)}-${String(i.getDate()).padStart(2,`0`)}`})}function Gn(e){if(!e)return null;try{return new URL(e).host}catch{return e}}var Kn=e=>e.stopPropagation();function qn({p:e,days:t,usage:n,onOpen:r,onTest:i}){let{t:a}=T(),o=ne(e.id),{toast:s}=Se(),c=[...new Set(e.endpoints.map(e=>e.protocol))],l=!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,u=[e.priceKey?a(`providers.priceKeyShort`,{key:e.priceKey}):null,e.priceMultiplier===1?null:`×${e.priceMultiplier}`].filter(Boolean).join(` · `),d=e.authScheme===`plugin`?a(`providers.card.plugin`):e.authScheme===`oauth-subscription`?a(`providers.card.subscription`):e.authScheme===`none`?a(`providers.card.noAuth`):e.hasApiKey?e.apiKeyMasked??`••••`:a(`providers.noKey`),f=e.enabled?l?{tone:`orange`,label:a(`providers.noKey`)}:{tone:`green`,label:a(`providers.card.active`)}:{tone:`neutral`,label:a(`providers.card.disabled`)},m=n?.requests??t.map(()=>0),h=m.reduce((e,t)=>e+t,0),g=e.templateUpdateAvailable?5:8;return(0,X.jsxs)(yt,{className:`flex flex-col [&>div:first-child>div]:min-h-0! [&>div:last-child]:flex [&>div:last-child]:flex-1 [&>div:last-child]:flex-col [&>div:last-child]:p-3 [&>div:last-child>:last-child]:mt-auto! [&>div:last-child>:last-child]:min-h-[44px] [&>div:last-child>:last-child]:pt-2 [&>div:last-child>h3]:line-clamp-1 [&>div:last-child>h3]:text-[15px] [&>div:last-child>p]:line-clamp-2 [&>div:last-child>p]:min-h-[2lh] [&>div:last-child>p]:text-[12px]`,"data-density":`compact`,role:`button`,tabIndex:0,"aria-label":e.name,onClick:r,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},style:{backgroundColor:`var(--surface)`},title:e.name,description:c.map(e=>Bn.find(t=>t.value===e)?.label??e).join(` / `),media:(0,X.jsxs)(`div`,{className:`flex flex-col justify-between gap-1.5 self-stretch justify-self-stretch px-3 py-2.5`,style:{background:`linear-gradient(135deg, color-mix(in oklab, var(--accent) 12%, transparent), transparent 70%)`},children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:L(`transition-[filter,opacity]`,!e.enabled&&`opacity-50 grayscale`),children:(0,X.jsx)(Ke,{name:e.name,icon:e.icon,colorKey:e.templateId,size:28})}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-[var(--border)] bg-[color-mix(in_oklab,var(--surface)_80%,transparent)] px-2 py-0.5 text-[11px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(B,{tone:f.tone}),f.label]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:Gn(e.endpoints[0]?.baseUrl)??`—`}),(0,X.jsx)(`span`,{className:`shrink-0`,children:a(`providers.modelCount`,{count:e.modelCount})})]})]}),meta:(0,X.jsx)(`span`,{className:L(e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:d}),status:u||void 0,action:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:Kn,children:[(0,X.jsx)(z,{variant:`plain`,size:`sm`,icon:(0,X.jsx)(Oe,{className:`size-3.5`}),"aria-label":a(`providers.test`),title:a(`providers.test`),onClick:i}),(0,X.jsx)(`span`,{className:`ml-1 inline-flex`,children:(0,X.jsx)(W,{checked:e.enabled,label:a(`common.enabled`),onChange:e=>o.mutate({enabled:e},{onError:e=>s(K(e),`error`)})})})]}),children:[(0,X.jsxs)(`div`,{className:`mt-1.5 flex h-5 flex-nowrap items-center gap-1 overflow-hidden`,children:[e.templateUpdateAvailable&&(0,X.jsx)(F,{tone:`accent`,children:a(`providers.templateUpdate`)}),e.boundClients.slice(0,g).map(e=>e in Ie?(0,X.jsx)(`span`,{title:Pe(e),className:`inline-flex shrink-0`,children:(0,X.jsx)(Le,{kind:e,size:18})},e):(0,X.jsx)(F,{tone:`green`,children:e},e)),e.boundClients.length>g&&(0,X.jsxs)(`span`,{title:e.boundClients.slice(g).map(e=>Ie[e]?.name??e).join(`, `),className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:[`+`,e.boundClients.length-g]})]}),(0,X.jsx)(`div`,{className:`min-h-[32px] [&>div]:mt-1`,onClick:Kn,children:(0,X.jsx)(hn,{provider:e})}),(0,X.jsx)(`div`,{className:`mt-2`,onClick:Kn,children:h>0?(0,X.jsx)(Ft,{label:a(`providers.card.requests7d`),data:m,labels:t.map(e=>e.slice(5)),value:b(h,!0),change:p(n?.costUsd??0),width:320,height:28,formatValue:e=>b(e,!0)}):(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[13px] text-[var(--text-secondary)]`,children:a(`providers.card.requests7d`)}),(0,X.jsx)(`div`,{className:`grid aspect-[320/28] place-items-center border-b border-dashed border-[var(--border)] text-[11px] text-[var(--text-muted)]`,children:a(`providers.card.noRequests`)})]})})]})}var Jn=`plugin:`,Yn=[`recommended`,`official`,`subscription`,`coding`,`cn`,`aggregator`,`inference`,`local`,`custom`],Xn={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Zn=e=>Bn.find(t=>t.value===e)?.label??e,Qn=e=>(0,X.jsx)(`span`,{title:e,children:e}),$n=e=>{let t=/^(.+?)\s*[((]([^()()]+)[))]$/.exec(e);return t?[t[1],t[2]]:[e,null]},er=/[\s,,]+/;function tr(e,t,n){let r=new Set(t.map(e=>e.protocol)),i=n.map(e=>e.protocol);return[...e.filter(e=>i.includes(e)),...i.filter(t=>!r.has(t)&&!e.includes(t))]}function nr({label:e,hint:t,children:n}){return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,X.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:e}),n,t&&(0,X.jsx)(`div`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:t})]})}function rr({value:e,onChange:t}){let{t:n}=T(),r=e.map(e=>e.protocol),i=Bn.filter(e=>!r.includes(e.value)),a=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[e.map((i,o)=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(q,{className:`w-44`,ariaLabel:n(`providers.protocol`),value:i.protocol,onChange:e=>a(o,{protocol:e}),options:Bn.filter(e=>e.value===i.protocol||!r.includes(e.value))}),(0,X.jsx)(E,{className:`min-w-52 flex-1`,mono:!0,"aria-label":n(`providers.baseUrl`),placeholder:`https://api.example.com/v1`,value:i.baseUrl,onChange:e=>a(o,{baseUrl:e.target.value})}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,title:n(`providers.fullUrlHint`),children:[(0,X.jsx)(W,{checked:!!i.fullUrl,label:n(`providers.fullUrl`),onChange:e=>a(o,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(je,{className:`size-3.5`}),"aria-label":n(`common.delete`),disabled:e.length===1,onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),i.length>0&&(0,X.jsx)(`div`,{children:(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>t([...e,{protocol:i[0].value,baseUrl:e[0]?.baseUrl??``}]),children:n(`providers.addEndpoint`)})})]})}function ir({value:e,onChange:t}){let{t:n}=T(),r=(n,r)=>t(e.map((e,t)=>t===n?r:e));return(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[e.map(([i,a],o)=>(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(E,{className:`w-44`,mono:!0,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:i,onChange:e=>r(o,[e.target.value,a])}),(0,X.jsx)(E,{className:`min-w-0 flex-1`,mono:!0,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:a,onChange:e=>r(o,[i,e.target.value])}),(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(je,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),(0,X.jsx)(`div`,{children:(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>t([...e,[``,``]]),children:n(`providers.addHeader`)})})]})}function ar({open:e,onOpenChange:t,onCreated:n}){let{t:r}=T(),{toast:i}=Se(),a=re(),o=y(),s=D(),c=I(),l=(0,J.useMemo)(()=>new Set((c.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[c.data]),u=Me(),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(``),[b,x]=(0,J.useState)(``),[S,w]=(0,J.useState)(``),[ee,O]=(0,J.useState)(``),[k,j]=(0,J.useState)(`bearer`),[M,P]=(0,J.useState)([]),[F,L]=(0,J.useState)([]),[ne,ie]=(0,J.useState)([]),[B,ae]=(0,J.useState)(``),[oe,U]=(0,J.useState)(1),[se,ce]=(0,J.useState)(``),[W,le]=(0,J.useState)(``);(0,J.useEffect)(()=>{e||(m(null),g(null),f(``),v(``),x(``),w(``),O(``))},[e]);let ue=(0,J.useMemo)(()=>{let e=d.trim().toLowerCase(),t=(a.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return Yn.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[a.data,d]),de=(0,J.useMemo)(()=>{let e=d.trim().toLowerCase();return(c.data??[]).filter(t=>t.authScheme===`plugin`&&!t.settings.plugin?.absent&&(!e||t.name.toLowerCase().includes(e)||t.id.includes(e)))},[c.data,d]),fe=e=>{m(e),w(``),ae(``),ce(``),le(``),e===`custom`?(v(``),O(``),j(`bearer`),P([{protocol:`openai-chat`,baseUrl:``}]),L([`openai-chat`]),ie([]),U(1)):(v(e.name),O(e.priceKey??e.id),j(e.auth.scheme),P(e.endpoints.map(e=>({...e}))),L([...e.preferredUpstreamProtocols]),ie(Object.entries(e.defaultHeaders??{})),U(e.defaultPriceMultiplier??1))},pe=e=>{L(t=>tr(t,M,e)),P(e)},G=p&&p!==`custom`?p:null,me=G?.authScheme===`oauth-subscription`,he=W.split(er).map(e=>e.trim()).filter(Boolean),ge=(G?.keyAlternatives??[]).flatMap(e=>(a.data??[]).filter(t=>t.id===e)),_e=()=>{let e=p===`custom`;s.mutate({templateId:e?null:p.id,variantId:S||null,name:_.trim()||null,apiKey:b.trim()||null,priceKey:ee,...me?{}:{endpoints:M.map(e=>({...e,baseUrl:e.baseUrl.trim()})),authScheme:k,preferredUpstreamProtocols:F.filter(e=>M.some(t=>t.protocol===e)),extraHeaders:Object.fromEntries(ne.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t])),httpProxy:B.trim()||null,priceMultiplier:oe,notes:se.trim()||null,...he.length>0?{models:he}:{}}},{onSuccess:e=>{t(!1),i(r(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>i(K(e),`error`)})},ve=()=>{if(h===`custom`)fe(`custom`);else if(h?.startsWith(Jn)){let e=de.find(e=>Jn+e.id===h);e&&(t(!1),n(e))}else{let e=(a.data??[]).find(e=>e.id===h);e&&!l.has(e.id)&&fe(e)}},be=me||M.length>0&&M.every(e=>/^https?:\/\//.test(e.baseUrl.trim())),xe=p!==null&&be&&(p===`custom`?_.trim()!==``:!G.requiresApiKey||k===`none`||b.trim()!==``);return(0,X.jsxs)(ye,{open:e,onOpenChange:t,width:640,title:r(p?`providers.addTitleDetails`:`providers.addTitle`),description:p?G?G.name:r(`providers.custom`):r(`providers.addDetail`),footer:p?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{className:`mr-auto`,variant:`plain`,onClick:()=>m(null),children:r(`common.back`)}),(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!xe,loading:s.isPending,onClick:_e,children:r(`providers.create`)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!h,onClick:ve,children:r(`common.continue`)})]}),children:[(0,X.jsx)(Yt,{className:`mb-6`,label:r(`providers.addTitle`),current:+!!p,steps:[{id:`template`,label:r(`providers.step.template`)},{id:`details`,label:r(`providers.step.details`)}]}),p?(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(N,{label:r(`providers.name`),children:(0,X.jsx)(E,{value:_,onChange:e=>v(e.target.value)})}),G?.variants&&G.variants.length>0&&(0,X.jsx)(N,{label:r(`providers.variant`),children:(0,X.jsx)(q,{value:S,onChange:e=>{w(e);let t=G.variants?.find(t=>t.id===e);O(t?.priceKey??G.priceKey??G.id),pe((t?.endpointsOverride??G.endpoints).map(e=>({...e})))},options:[{value:``,label:r(`providers.variantDefault`)},...G.variants.map(e=>({value:e.id,label:e.name}))]})}),p===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(nr,{label:r(`providers.section.endpoints`),hint:r(`providers.baseUrlHint`),children:(0,X.jsx)(rr,{value:M,onChange:pe})}),(0,X.jsx)(N,{label:r(`providers.authScheme`),children:(0,X.jsx)(q,{value:k,onChange:j,options:Vn})})]}),me?(0,X.jsx)(V,{tone:`info`,title:r(`providers.subscriptionWizardHint`),children:r(`providers.subscriptionWizardDetail`)}):(0,X.jsxs)(`div`,{className:`font-mono`,children:[(0,X.jsx)(He,{label:r(`providers.apiKey`),description:r(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:b,onChange:e=>x(e.target.value)}),G?.apiKeyUrl&&(0,X.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:G.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:r(`providers.getKey`)})]}),G&&ge.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(`span`,{children:r(`providers.keyAlternative.wizard`,{name:G.name,alt:ge.map(e=>e.name).join(` / `)})}),ge.map(e=>(0,X.jsx)(z,{size:`sm`,variant:`plain`,onClick:()=>{g(e.id),fe(e)},children:r(`providers.keyAlternative.pick`,{alt:e.name})},e.id))]}),(0,X.jsx)(N,{label:r(`providers.priceKey`),hint:r(`providers.priceKeyHint`),children:(0,X.jsx)(q,{value:ee,onChange:O,options:[{value:``,label:r(`providers.priceKeyNone`)},...(o.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),!me&&(0,X.jsx)(te,{title:r(`providers.moreOptions`),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[G&&(0,X.jsx)(nr,{label:r(`providers.section.endpoints`),hint:r(`providers.endpointsFooter`),children:(0,X.jsx)(rr,{value:M,onChange:pe})}),new Set(M.map(e=>e.protocol)).size>1&&(0,X.jsx)(nr,{label:r(`providers.preferred`),hint:r(`providers.preferredHint`),children:(0,X.jsx)(We,{label:r(`providers.preferred`),options:Bn.filter(e=>M.some(t=>t.protocol===e.value)).map(e=>{let t=F.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:F,onValueChange:e=>{let t=F.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));L([...t,...n])}})}),G&&(0,X.jsx)(N,{label:r(`providers.authScheme`),children:(0,X.jsx)(q,{value:k,onChange:j,options:Vn})}),(0,X.jsx)(nr,{label:r(`providers.headers`),children:(0,X.jsx)(ir,{value:ne,onChange:ie})}),(0,X.jsx)(N,{label:r(`providers.proxy`),hint:r(`providers.proxyHint`),children:(0,X.jsx)(E,{mono:!0,placeholder:`http://127.0.0.1:7890`,value:B,onChange:e=>ae(e.target.value)})}),(0,X.jsx)(nr,{label:r(`providers.multiplier`),hint:r(`providers.multiplierHint`),children:(0,X.jsx)(R,{className:`w-28`,label:r(`providers.multiplier`),step:.01,min:0,value:oe,onChange:e=>U(e??1)})}),(0,X.jsx)(N,{label:r(`providers.initialModels`),hint:G?r(`providers.initialModelsTemplateHint`,{count:G.models.length}):r(`providers.initialModelsCustomHint`),children:(0,X.jsx)(C,{rows:3,mono:!0,value:W,onChange:e=>le(e.target.value)})}),(0,X.jsx)(N,{label:r(`providers.notes`),children:(0,X.jsx)(E,{value:se,onChange:e=>ce(e.target.value)})}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`providers.moreOptionsDetail`)})]})}),G&&G.models.length>0&&he.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`providers.templateModels`,{count:G.models.length})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(A,{value:d,onChange:f,placeholder:r(`providers.searchTemplates`)}),a.isLoading&&(0,X.jsx)(H,{lines:4}),a.isError&&(0,X.jsx)(V,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),ue.map(e=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.${e.category}`)}),(0,X.jsx)(ke,{name:`provider-template`,"aria-label":r(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===h)?h:null,onValueChange:g,options:e.items.map(e=>{let t=[...new Set(e.endpoints.map(e=>e.protocol))],[n,i]=$n(e.name);return{value:e.id,label:(0,X.jsx)(`span`,{title:e.name,children:n}),description:(0,X.jsx)(`span`,{title:t.map(Zn).join(` · `),children:i??t.map(e=>Xn[e]).join(` · `)}),icon:(0,X.jsx)(Ke,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:l.has(e.id),disabledReason:Qn(r(`providers.subscriptionAdded`))}})})]},e.category)),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.plugin`)}),de.length>0?(0,X.jsx)(ke,{name:`provider-template-plugin`,"aria-label":r(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:h?.startsWith(Jn)?h:null,onValueChange:g,options:de.map(e=>({value:Jn+e.id,label:Qn(e.name),description:Qn(r(`providers.pluginProvided`)),icon:(0,X.jsx)(Ke,{name:e.name,icon:e.icon,colorKey:e.id,size:28})}))}):(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-[var(--radius-md)] border border-dashed border-[var(--border)] px-3 py-2.5`,children:[(0,X.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:r(`providers.pluginHint`)}),(0,X.jsx)(z,{size:`sm`,onClick:()=>{t(!1),u(`/plugins/market`)},children:r(`plugins.browseMarket`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.custom`)}),(0,X.jsx)(ke,{name:`provider-template-custom`,"aria-label":r(`providers.custom`),layout:`list`,density:`compact`,value:h===`custom`?`custom`:null,onValueChange:g,options:[{value:`custom`,label:r(`providers.custom`),description:r(`providers.customDetail`),icon:(0,X.jsx)(`span`,{className:`inline-flex size-7 items-center justify-center rounded-[8px] border border-dashed border-[var(--border-strong)] text-[var(--text-secondary)]`,children:(0,X.jsx)(qe,{className:`size-4`})})}]})]})]})]})}export{yn as a,pn as c,On as i,$e as l,Bn as n,vn as o,zn as r,gn as s,Vn as t};