@aidotnet/server-darwin-arm64 0.9.3 → 0.9.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.
- package/bin/astra-server +2 -2
- package/bin/wwwroot/assets/ClientsPage-DzZnCU7V.js +12 -0
- package/bin/wwwroot/assets/KeyPage-CtHw5I7A.js +1 -0
- package/bin/wwwroot/assets/ModelDetailPage-KY2k0x3l.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-Bo8oA3Zb.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-BMP78mVY.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-BgldsSQj.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-B6EfUhXb.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-DclHIvR2.js +2 -0
- package/bin/wwwroot/assets/SettingsPage-D29CZiaV.js +2 -0
- package/bin/wwwroot/assets/TokensPage-CaF-wXlr.js +1 -0
- package/bin/wwwroot/assets/{TracesPage-BqnfGeL4.js → TracesPage-Bzy2gUvV.js} +2 -2
- package/bin/wwwroot/assets/{TrayPanelPage-DsMvwR_T.js → TrayPanelPage-BZS_htv0.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelView-DnvoVnvO.js → TrayPanelView-CYoAUUiY.js} +1 -1
- package/bin/wwwroot/assets/alert-CGUFPyGb.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-V3oFXKF5.js → arrow-down-7oFM4dM3.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-BpBbd_q4.js → arrow-left-Dn6_YDkh.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-Bqwnblbu.js → checkbox-DzIMWhhw.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-Cp5R1kIH.js → cloud-download-Bvry8vmS.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-DnwMPT3r.js +1 -0
- package/bin/wwwroot/assets/{download-EFZWCXNY.js → download-5xAFYJ6Q.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-vy0zfY6I.js → ellipsis-Dxds5r72.js} +1 -1
- package/bin/wwwroot/assets/{external-link-CyPNKHdV.js → external-link-Bq_1v6I1.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-CS5Nhpwl.js → folder-open-BXsxEYtm.js} +1 -1
- package/bin/wwwroot/assets/{index-Dlj17okK.js → index-mlmGhWY4.js} +12 -12
- package/bin/wwwroot/assets/{log-out-DfSRg6bm.js → log-out-B9HHsF8m.js} +1 -1
- package/bin/wwwroot/assets/minus-BVd6Aw9t.js +1 -0
- package/bin/wwwroot/assets/overlays-B1a0OZYb.js +41 -0
- package/bin/wwwroot/assets/{pencil-BRz--Mw5.js → pencil-BAzRd1Ro.js} +1 -1
- package/bin/wwwroot/assets/{power-DmWGnFp9.js → power-DrpargJA.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-Cr0tP9In.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-7CnaPCq0.js → rotate-ccw-D6r7Boub.js} +1 -1
- package/bin/wwwroot/index.html +3 -3
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-r2weTDWW.js +0 -11
- package/bin/wwwroot/assets/KeyPage-BGxPT6pS.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-B08VTnCn.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-tHjDQDXP.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-CK5z2M5T.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-m_YIMy3n.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-CyUE_jWW.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-Dfa9xYj8.js +0 -2
- package/bin/wwwroot/assets/SettingsPage-BJPTZJNd.js +0 -2
- package/bin/wwwroot/assets/TokensPage-BNSLQb2G.js +0 -1
- package/bin/wwwroot/assets/alert-RpMgB81n.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-B8RLpf1K.js +0 -1
- package/bin/wwwroot/assets/minus-DWdqkwzQ.js +0 -1
- package/bin/wwwroot/assets/overlays-D_YawsYE.js +0 -41
- package/bin/wwwroot/assets/radio-cards-CxPVQvHV.js +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{$r as e,An as t,B as n,Bn as r,Cn as i,Ct as a,Et as o,Fr as s,Gn as c,Gt as l,Hn as u,In as d,Kt as f,Mn as p,Mr as m,Nt as h,On as g,Or as _,Qn as v,Rn as ee,Sa as y,Sn as te,St as ne,Tt as re,V as b,Xn as ie,Zn as ae,_ as x,_a as oe,a as S,b as se,c as C,cn as ce,ct as le,d as w,ei as ue,f as T,fi as E,fr as de,ft as fe,gn as pe,h as me,hn as he,i as ge,ii as _e,ir as D,it as O,jn as ve,jr as ye,kr as be,kt as xe,l as k,m as A,mn as Se,n as j,nn as Ce,nt as we,ot as M,p as Te,pt as Ee,r as N,rn as De,rr as Oe,sr as ke,t as P,ti as F,tn as Ae,tt as I,u as L,un as je,v as R,va as Me,vt as z,wr as Ne,xt as Pe,y as B,ya as Fe,zn as Ie}from"./alert-CGUFPyGb.js";import{a as V,i as H,n as Le,o as U,r as W}from"./overlays-B1a0OZYb.js";import{a as Re,i as G,n as K,o as q,t as ze}from"./ProvidersPage-DclHIvR2.js";import{t as Be}from"./arrow-down-7oFM4dM3.js";import{t as Ve}from"./arrow-left-Dn6_YDkh.js";import{t as He}from"./cloud-download-Bvry8vmS.js";import{t as Ue}from"./download-5xAFYJ6Q.js";import{t as We}from"./ellipsis-Dxds5r72.js";import{t as Ge}from"./external-link-Bq_1v6I1.js";import{n as Ke}from"./radio-cards-Cr0tP9In.js";import{t as qe}from"./log-out-B9HHsF8m.js";import{t as Je}from"./power-DrpargJA.js";import{t as Ye}from"./rotate-ccw-D6r7Boub.js";import{C as Xe,E as Ze,G as Qe,L as J,M as Y,T as X,W as $e,X as et,Z as tt,_ as Z,a as nt,h as rt,o as it,s as at,w as ot,z as st}from"./index-mlmGhWY4.js";import{t as ct}from"./checkbox-DzIMWhhw.js";import{t as lt}from"./confirm-morph-DnwMPT3r.js";var ut={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`}]]};ut.node;var dt=z(ut),ft={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`}]]};ft.node;var pt=z(ft),mt={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`}]]};mt.node;var ht=z(mt),gt={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`}]]};gt.node;var _t=z(gt),vt={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`}]]};vt.node;var yt=z(vt),bt={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};bt.node;var xt=z(bt),St={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`}]]};St.node;var Ct=z(St),Q=y(Fe(),1),$=Me(),wt={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`},Tt={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Et={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function Dt(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 Ot(e){let t=e.trim();if(t.length===0)return 0;if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e.filter(e=>typeof e==`object`&&!!e||typeof e==`string`&&e.trim().length>0).length;if(typeof e==`object`&&e)return 1}catch{}let n=0;for(let t of e.split(`
|
|
2
|
+
`)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:Dt(e))}return n}function kt({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=M(),{toast:o}=U(),s=Se(e),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),m=(0,Q.useMemo)(()=>Ot(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),p(null))},[n]),n===null)return(0,$.jsx)(H,{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`),ee=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(V(e),`error`)});return(0,$.jsx)(H,{open:!0,onOpenChange:e=>!e&&i(),title:a(Et[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)(se,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(w,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:u,onChange:e=>d(e.target.value)}),_&&(0,$.jsx)(P,{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)(N,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>ee(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(N,{variant:`primary`,disabled:m===0||m>t.maxBatch,loading:s.isPending&&!s.variables?.dryRun,onClick:()=>ee(!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)(j,{tone:Tt[e.status],children:a(wt[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 At(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var jt={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},Mt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Nt(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 Pt({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s}){let{t:c,locale:l}=M(),u=At(e),d=e.displayName||e.accountEmail||e.keyMasked||e.id,f=e.kind===`api_key`,p=e.plan?.trim(),m=u===`cooling`?{text:c(`providers.subscription.cooldown`,{when:b(e.cooldownUntilUtc,l)}),tone:`var(--warning)`}:u===`dead`?{text:e.lastError||c(Mt[e.status]),tone:`var(--danger)`}:f?{text:e.keyMasked??c(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:c(`providers.accounts.expiresAt`,{when:b(e.expiresAtUtc,l)}),tone:void 0}:null,h=[{id:`activate`,label:c(`providers.subscription.activate`),icon:(0,$.jsx)(dt,{className:`size-3.5`}),disabled:e.isCurrent||u===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:c(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(Je,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:c(`providers.subscription.moveUp`),icon:(0,$.jsx)($e,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:c(`providers.subscription.moveDown`),icon:(0,$.jsx)(Be,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:c(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(q,{className:`size-3.5`}),disabled:u===`dead`,onSelect:()=>n.refreshQuota(e)},...f?[]:[{id:`refresh`,label:c(`providers.subscription.refreshToken`),icon:(0,$.jsx)(Ye,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:c(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],{id:`remove`,label:c(`providers.subscription.logout`),icon:(0,$.jsx)(Y,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],g=c(u===`disabled`?`providers.subscription.disabled`:Mt[e.status]),_=c(f?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`),v=e.quota?.session?.usedPercent!=null||e.quota?.weekly?.usedPercent!=null||e.quota?.credits?.usedPercent!=null;return(0,$.jsxs)(`div`,{"data-testid":`account-card`,className:O(`group card relative flex aspect-square 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)]`,u===`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:Nt(p,f)},children:[(u===`cooling`||u===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:jt[u]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:O(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ct,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":c(`providers.accounts.select`,{name:d})})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{role:`img`,"aria-label":g,className:`size-1.5 shrink-0 rounded-full`,style:{background:jt[u]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:g})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${c(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(fe,{className:`size-3.5`,"aria-label":c(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Le,{iconOnly:!0,label:c(`common.more`),icon:(0,$.jsx)(We,{className:`size-4`}),items:h})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 truncate text-[17px] font-bold tracking-[.01em]`,title:p||_,children:p||_})]}),(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:d,onClick:t=>{t.stopPropagation(),i?a(e.id):n.open(e)},children:d}),(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:c(`providers.subscription.current`)})]}),e.isCurrent&&(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`shrink-0`,children:_}),e.source&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,children:c(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:c(`providers.accounts.order`,{n:t+1})})]}),m&&(u===`cooling`||u===`dead`||!v)&&(0,$.jsx)(`div`,{className:`mt-1.5 line-clamp-2 text-[11px] leading-snug`,style:{color:m.tone??`var(--text-muted)`},title:m.text,children:m.text}),u===`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:c(`providers.accounts.signedOut`)}),!f&&(0,$.jsx)(N,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:c(`providers.subscription.relogin`)})]}):(0,$.jsx)(It,{quota:e.quota??null,pending:s})]})]})}var Ft=10;function It({quota:e,pending:t}){let{t:n,locale:r}=M(),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:O(`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*Ft),o=e.reset?n(`providers.subscription.quotaResets`,{when:b(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:Ft},(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 Lt({quota:e,className:t}){let{t:n,locale:r}=M(),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:O(`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)(Rt,{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 Rt({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 zt={available:`green`,redeemed:`neutral`,expired:`orange`};function Bt({account:e,providerId:t}){let{t:n}=M(),{toast:r,confirm:i}=U(),a=de(e.id,e.status===`active`),o=f(t),s=a.data?.credits??[],c=a.data?.available_count??s.filter(e=>e.status===`available`).length,l=async t=>{await i({title:n(`providers.subscription.credits.consumeConfirm`,{title:t.title??t.reset_type??``}),detail:n(`providers.subscription.credits.consumeDetail`),confirmLabel:n(`providers.subscription.credits.consume`),destructive:!0})&&o.mutate({accountId:e.id,creditId:t.id},{onSuccess:()=>r(n(`providers.subscription.credits.consumed`),`success`),onError:e=>r(e instanceof E&&e.status===409?V(e):`${n(`providers.subscription.credits.consumeFailed`)}:${V(e)}`,`error`)})};return(0,$.jsxs)(L,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(R,{className:`my-4`}),a.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.unavailable`)}),a.data&&s.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.none`)}),s.map(e=>{let t=e.status!==`available`;return(0,$.jsxs)(A,{className:O(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pt,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?n(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?n(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?n(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(j,{tone:zt[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ct,{className:`size-3.5`}),disabled:t,loading:o.isPending&&o.variables?.creditId===e.id,onClick:()=>void l(e),children:n(`providers.subscription.credits.consume`)})]},e.id)}),a.data&&s.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`providers.subscription.credits.availableCount`,{count:c})})]})}var Vt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Ht({provider:e,account:t,index:n,actions:r,onClose:i}){let{t:a,locale:o}=M(),{toast:s}=U(),c=ue(e.id),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``);if((0,Q.useEffect)(()=>{u(t?.displayName??``),f(t?.httpProxy??``)},[t?.id,t?.displayName,t?.httpProxy]),!t)return(0,$.jsx)(H,{open:!1,onOpenChange:i,title:``});let p=At(t),m=t.kind===`api_key`,h=e.templateId===`openai-subscription`,g=e.httpProxy||a(`providers.accounts.proxyFallbackSystem`),_=e=>e?b(e,o):`—`,v=(e,n)=>c.mutate({id:t.id,...e},{onSuccess:()=>s(a(n),`success`),onError:e=>s(V(e),`error`)});return(0,$.jsx)(H,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,a(m?`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)(N,{size:`sm`,icon:(0,$.jsx)(dt,{className:`size-3.5`}),disabled:t.isCurrent||p===`dead`,onClick:()=>r.activate(t),children:a(`providers.subscription.activate`)}),(0,$.jsx)(N,{size:`sm`,icon:(0,$.jsx)(q,{className:`size-3.5`}),disabled:p===`dead`,onClick:()=>r.refreshQuota(t),children:a(`providers.subscription.quotaRefresh`)}),!m&&(0,$.jsx)(N,{size:`sm`,icon:(0,$.jsx)(Ye,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:a(`providers.subscription.refreshToken`)}),!m&&t.status!==`active`&&(0,$.jsx)(N,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:a(`providers.subscription.relogin`)}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),onClick:()=>r.remove(t),children:a(`providers.subscription.logout`)})]}),p===`dead`&&t.lastError&&(0,$.jsx)(P,{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:a(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(w,{className:`flex-1`,label:a(`providers.accounts.detail.name`),value:l,onChange:e=>u(e.target.value)}),(0,$.jsx)(N,{disabled:l.trim().length===0||l.trim()===t.displayName,loading:c.isPending&&c.variables?.displayName!==void 0,onClick:()=>v({displayName:l.trim()},`providers.accounts.renamed`),children:a(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(w,{className:`flex-1`,mono:!0,label:a(`providers.accounts.detail.proxy`),placeholder:g,value:d,onChange:e=>f(e.target.value)}),(0,$.jsx)(N,{disabled:d.trim()===(t.httpProxy??``),loading:c.isPending&&c.variables?.httpProxy!==void 0,onClick:()=>v({httpProxy:d.trim()},`providers.accounts.proxySaved`),children:a(`common.save`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.detail.proxyHint`,{fallback:g})})]}),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:a(`providers.accounts.detail.quota`)}),(0,$.jsx)(Lt,{quota:t.quota})]}),h&&p!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(Bt,{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:a(`providers.accounts.detail.credentials`)}),(0,$.jsxs)(`div`,{className:`card divide-y divide-[var(--border)] px-3`,children:[(0,$.jsx)(T,{label:a(`providers.accounts.detail.status`),children:(0,$.jsx)(j,{tone:p===`usable`?`green`:p===`cooling`?`orange`:p===`dead`?`red`:`neutral`,children:a(p===`disabled`?`providers.subscription.disabled`:Vt[t.status])})}),t.source&&(0,$.jsx)(T,{label:a(`providers.accounts.detail.source`),children:a(`providers.accounts.source.${t.source}`)}),m?(0,$.jsx)(T,{label:a(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(T,{label:a(`providers.accounts.detail.expires`),children:_(t.expiresAtUtc)}),(0,$.jsx)(T,{label:a(`providers.accounts.detail.lastRefresh`),children:_(t.lastRefreshAtUtc)})]}),p===`cooling`&&(0,$.jsx)(T,{label:a(`providers.accounts.filter.cooling`),children:_(t.cooldownUntilUtc)}),(0,$.jsx)(T,{label:a(`providers.accounts.detail.order`),children:a(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(T,{label:a(`providers.accounts.detail.created`),children:_(t.createdAt)}),t.lastError&&p!==`dead`&&(0,$.jsx)(T,{label:a(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function Ut({provider:e}){let{t}=M(),{toast:n}=U(),r=e.authScheme===`oauth-subscription`,i=m(e.id,r),a=_e(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(V(e),`error`)}),c=o.claudeSubscription||o.clientPolicy===`claude-code-only`;return!c&&!o.claudeSubscription?null:(0,$.jsxs)(L,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[c&&(0,$.jsx)(A,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(B,{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)(A,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(B,{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)(P,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(P,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Wt=[{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`}],Gt=3e5;function Kt({provider:e}){let{t}=M(),{toast:n,confirm:r}=U(),a=oe(),s=e.authScheme===`oauth-subscription`,c=ae(e.id,s),d=m(e.id,s),f=_e(e.id),p=re(e.id,s),h=be(e.id),g=u(e.id),_=l(e.id),v=je(e.id),ee=Oe(e.id),y=Ce(e.id),ne=o(e.id),b=ue(e.id),ie=ke(e.id),x=e.templateId===`openai-subscription`,S=te(s&&x),se=he(e.id),C=e.templateId===`github-copilot-subscription`,ce=i(s&&C),le=pe(e.id),[T,de]=(0,Q.useState)(`all`),[fe,ge]=(0,Q.useState)(``),[D,ve]=(0,Q.useState)(new Set),[ye,xe]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(null),[Se,j]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)(``),[Ee,De]=(0,Q.useState)(!1),[F,Ae]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(null),[Me,z]=(0,Q.useState)(null),[Ne,B]=(0,Q.useState)(!1),[Fe,Ie]=(0,Q.useState)(``),W=(0,Q.useRef)(new Set),Re=(0,Q.useRef)(new Set),G=(0,Q.useMemo)(()=>c.data??[],[c.data]);if((0,Q.useEffect)(()=>{if(s)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<Gt||(Re.current.add(e.id),v.mutate(e.id,{onError:()=>{}}))}},[G,s]),(0,Q.useEffect)(()=>{let e=new Set(G.map(e=>e.id));ve(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),ye&&!e.has(ye)&&xe(null)},[G,ye]),(0,Q.useEffect)(()=>{if(!F||I?.mode!==`pkce`)return;let e=setInterval(()=>void c.refetch(),3e3);return()=>clearInterval(e)},[F,I,c]),(0,Q.useEffect)(()=>{if(!F||I?.mode!==`pkce`)return;let e=G.find(e=>!W.current.has(e.id));e&&q(!0,e.displayName||e.accountEmail||e.id)},[G,F,I]),(0,Q.useEffect)(()=>{if(!F||I?.mode!==`device`&&I?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await g.mutateAsync(I.state);if(e)return;t=0,n.status===`done`?q(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&q(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof E&&(n.status===404||n.status===400)){q(!1,void 0,V(n));return}++t>=5&&q(!1,void 0,V(n))}},r=setInterval(()=>void n(),Math.max(I.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[F,I]),!s)return null;let K=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,q=(r,i,o)=>{if(a.invalidateQueries({queryKey:Pe.providerAccounts(e.id)}),r){L(null),z(null),Ae(!1),n(t(`providers.subscription.loginOk`,{name:i??``}),`success`);return}o&&z(o)},ze=(e,r)=>{W.current=new Set(G.map(e=>e.id)),z(null),h.mutate({accountId:e,httpProxy:r},{onSuccess:e=>{j(!1),L(e),Ae(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof E&&e.details?.needsVerification?n(t(`providers.subscription.needsVerification`),`error`):n(V(e),`error`)}})},Be=async()=>{if(I){B(!0);try{let e=await g.mutateAsync(I.state);e.status===`done`?q(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?n(t(`providers.subscription.stillWaiting`),`info`):q(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof E&&e.status===404){let t=((await c.refetch()).data??[]).find(e=>!W.current.has(e.id));t?q(!0,t.displayName||t.accountEmail||t.id):q(!1,void 0,V(e))}else q(!1,void 0,V(e))}finally{B(!1)}}},Ve=async()=>{if(I&&I.mode===`paste`&&Fe.trim().length!==0){B(!0);try{let e=await _.mutateAsync({state:I.state,code:Fe.trim()});e.status===`done`?(Ie(``),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,V(e))}finally{B(!1)}}},He=()=>se.mutate(void 0,{onSuccess:e=>{n(t(`providers.subscription.importOk`,{name:K(e.account)}),e.warning?`info`:`success`),e.warning&&n(e.warning,`error`),S.refetch()},onError:e=>n(V(e),`error`)}),We=()=>le.mutate(``,{onSuccess:e=>{n(t(`providers.subscription.importOk`,{name:K(e.account)}),e.warning?`info`:`success`),e.warning&&n(e.warning,`error`)},onError:e=>n(V(e),`error`)}),Ge=(e,t)=>{let r=G.map(e=>e.id),i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],ie.mutate(r,{onError:e=>n(V(e),`error`)}))},Ke=async e=>{let i=K(e);await r({title:t(`providers.subscription.logoutConfirm`,{name:i}),destructive:!0,confirmLabel:t(`providers.subscription.logout`)})&&y.mutate(e.id,{onError:e=>n(V(e),`error`)})},qe={open:e=>xe(e.id),activate:e=>ne.mutate(e.id,{onSuccess:()=>n(t(`providers.subscription.activated`,{name:K(e)}),`success`),onError:e=>n(V(e),`error`)}),toggleEnabled:e=>b.mutate({id:e.id,enabled:!e.enabled},{onError:e=>n(V(e),`error`)}),refreshQuota:e=>v.mutate(e.id,{onError:e=>{e instanceof E&&e.status===501?n(t(`providers.subscription.quotaUnsupported`),`error`):n(V(e),`error`)}}),refreshToken:e=>ee.mutate(e.id,{onSuccess:()=>n(t(`providers.subscription.tokenRefreshed`),`success`),onError:e=>n(V(e),`error`)}),relogin:e=>ze(e.id),remove:e=>void Ke(e)},Ye=e=>ve(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Xe=async r=>{let i=G.filter(e=>D.has(e.id));De(!0);let o=0;for(let e of i)try{await r(e),o++}catch(t){n(`${K(e)}: ${V(t)}`,`error`)}De(!1),ve(new Set),a.invalidateQueries({queryKey:Pe.providerAccounts(e.id)}),o>0&&n(t(`providers.accounts.bulkDone`,{n:o}),`success`)},Ze=async()=>{await r({title:t(`providers.accounts.bulkDeleteConfirm`,{n:D.size}),detail:t(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&await Xe(e=>y.mutateAsync(e.id))},Qe=G.map(e=>At(e)),X=e=>e===`all`?G.length:Qe.filter(t=>t===e).length,$e=fe.trim().toLowerCase(),et=G.map((e,t)=>({a:e,index:t,state:Qe[t]})).filter(({a:e,state:t})=>(T===`all`||t===T)&&($e.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes($e)))),tt=G.find(e=>e.id===ye)??null,Z=p.data,nt=D.size>0,rt=[{id:`login`,label:t(`providers.accounts.addLogin`),icon:(0,$.jsx)(_t,{className:`size-3.5`}),onSelect:()=>ze()},{id:`login-proxy`,label:t(`providers.accounts.addLoginProxy`),onSelect:()=>j(!0)},...x&&S.data?.available?[{id:`codex`,separatorBefore:!0,label:t(`providers.subscription.importCodex`),icon:(0,$.jsx)(Ue,{className:`size-3.5`}),onSelect:He}]:[],...C?[{id:`copilot`,separatorBefore:!0,label:t(`providers.subscription.importCopilot`),icon:(0,$.jsx)(Ue,{className:`size-3.5`}),onSelect:We}]:[],...Z?.supported?[{id:`token`,separatorBefore:!(x&&S.data?.available)&&!C,label:t(`providers.accounts.addToken`),onSelect:()=>A(`token`)}]:[],...Z?.apiKey?[{id:`apikey`,label:t(`providers.accounts.addApiKey`),icon:(0,$.jsx)(st,{className:`size-3.5`}),onSelect:()=>A(`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:t(`providers.accounts.statTotal`,{n:G.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:t(`providers.accounts.statUsable`,{n:X(`usable`)})}),X(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:t(`providers.accounts.statCooling`,{n:X(`cooling`)})}),X(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:t(`providers.accounts.statDead`,{n:X(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.accounts.providerProxy`,{proxy:e.httpProxy||t(`providers.accounts.proxyFallbackSystem`)})})]}),d.data&&(0,$.jsx)(qt,{policy:d.data,onChange:e=>f.mutate({switchMode:e},{onError:e=>n(V(e),`error`)})})]}),d.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:t(d.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:d.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)(me,{className:`w-52`,value:fe,onChange:ge,placeholder:t(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":t(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Wt.filter(e=>e.value===`all`||X(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":T===e.value,onClick:()=>de(e.value),className:O(`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:[t(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:X(e.value)})]},e.value))}),Z?.supported&&(0,$.jsx)(N,{size:`sm`,icon:(0,$.jsx)(ht,{className:`size-3.5`}),onClick:()=>A(`batch`),children:t(`providers.accounts.batchImport`)}),(0,$.jsx)(Le,{label:t(`providers.accounts.add`),icon:(0,$.jsx)(J,{className:`size-3.5`}),items:rt})]}),x&&S.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[t(`providers.subscription.localCodexFound`,{who:S.data.accountEmail??S.data.plan??t(`providers.subscription.unknownAccount`)}),S.data.detail?` · ${S.data.detail}`:``]}),C&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[ce.data?.available?t(`providers.subscription.localCopilotFound`,{source:ce.data.source??``}):t(`providers.subscription.localCopilotHint`),ce.data?.detail?` · ${ce.data.detail}`:``]}),c.isLoading?(0,$.jsx)(R,{className:`my-4`}):G.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ze(),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:t(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(J,{className:`size-3.5`}),` `,t(`providers.subscription.login`)]})]}):et.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:t(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:et.map(({a:e,index:t})=>(0,$.jsx)(Pt,{account:e,index:t,actions:qe,selected:D.has(e.id),selecting:nt,onToggleSelect:Ye,quotaPending:v.isPending&&v.variables===e.id,onMove:G.length>1?{up:t>0?()=>Ge(t,-1):void 0,down:t<G.length-1?()=>Ge(t,1):void 0}:void 0},e.id))}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:t(`providers.subscription.footer`)}),nt&&(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:t(`providers.accounts.selected`,{n:D.size})}),(0,$.jsx)(N,{size:`sm`,icon:(0,$.jsx)(Je,{className:`size-3.5`}),disabled:Ee,onClick:()=>void Xe(e=>b.mutateAsync({id:e.id,enabled:!0})),children:t(`providers.subscription.enable`)}),(0,$.jsx)(N,{size:`sm`,disabled:Ee,onClick:()=>void Xe(e=>b.mutateAsync({id:e.id,enabled:!1})),children:t(`providers.subscription.disable`)}),(0,$.jsx)(N,{size:`sm`,disabled:Ee,onClick:()=>void Xe(e=>v.mutateAsync(e.id)),children:t(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(N,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),disabled:Ee,onClick:()=>void Ze(),children:t(`common.delete`)}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,onClick:()=>ve(new Set),children:t(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(Ut,{provider:e})}),(0,$.jsx)(Ht,{provider:e,account:tt,index:tt?G.indexOf(tt):0,actions:qe,onClose:()=>xe(null)}),Z&&(0,$.jsx)(kt,{providerId:e.id,info:Z,mode:k,providerProxy:e.httpProxy,onClose:()=>A(null)}),(0,$.jsx)(H,{open:Se,onOpenChange:j,title:t(`providers.accounts.loginProxyTitle`),description:t(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(N,{variant:`primary`,loading:h.isPending,disabled:we.trim().length===0,onClick:()=>ze(void 0,we),children:t(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(w,{mono:!0,label:t(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:we,onChange:e=>Te(e.target.value)})}),(0,$.jsxs)(H,{open:F,onOpenChange:e=>{Ae(e),e||(L(null),z(null))},title:t(`providers.subscription.login`),description:t(`providers.subscription.loginDesc`),children:[Me&&(0,$.jsx)(P,{tone:`danger`,title:t(`providers.subscription.loginFailed`),children:Me}),I?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(P,{tone:`info`,title:t(`providers.subscription.pasteTitle`),children:t(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(w,{mono:!0,value:Fe,onChange:e=>Ie(e.target.value),placeholder:t(`providers.subscription.pastePlaceholder`),"aria-label":t(`providers.subscription.pasteCode`)}),(0,$.jsx)(N,{variant:`primary`,loading:Ne,onClick:()=>void Ve(),children:t(`providers.subscription.pasteSubmit`)})]}),I?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(P,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)}),(0,$.jsx)(N,{variant:`primary`,onClick:()=>{a.invalidateQueries({queryKey:Pe.providerAccounts(e.id)}),c.refetch()},children:t(`providers.subscription.doneAuthorize`)})]})]}),I?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(P,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.cliDetail`)}),(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})]}),I?.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:t(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:I.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[I.verificationUrl&&(0,$.jsx)(N,{onClick:()=>window.open(I.verificationUrl??void 0,`_blank`,`noopener`),children:t(`providers.subscription.visitPage`)}),(0,$.jsx)(N,{variant:`primary`,loading:Ne,onClick:()=>void Be(),children:t(`providers.subscription.checkNow`)})]}),(0,$.jsx)(P,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.checkNowHint`)})]})]})]})}function qt({policy:e,onChange:t}){let{t:n}=M();return(0,$.jsx)(x,{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 Jt({provider:e}){let{t}=M(),n=ae(e.id),r=d(e.id),i=m(e.id,!0),a=_e(e.id),{toast:o}=U(),[s,c]=(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:[r.isLoading&&(0,$.jsx)(R,{lines:1}),r.isError&&(0,$.jsx)(P,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:V(r.error)}),r.data?.map(e=>(0,$.jsx)(N,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(st,{className:`size-3.5`}):(0,$.jsx)(_t,{className:`size-3.5`}),onClick:()=>c(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(R,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(C,{icon:(0,$.jsx)(yt,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&i.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(i.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:i.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsx)(qt,{policy:i.data,onChange:e=>a.mutate({switchMode:e},{onError:e=>o(V(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)(Xt,{provider:e,account:t},t.id))}),(0,$.jsx)(Yt,{provider:e}),s&&(0,$.jsx)(Zt,{provider:e,method:s,onClose:()=>c(null)})]})}function Yt({provider:e}){let{t,locale:n}=M(),{toast:r}=U(),i=ve(e.id),a=p(e.id);if(!i.data?.supported)return null;let o=e=>a.mutate(e,{onError:e=>r(V(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)(B,{checked:i.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>o(e)}),(0,$.jsx)(N,{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?b(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)(j,{tone:s[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(j,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function Xt({provider:e,account:t}){let{t:n,locale:i}=M(),{toast:a,confirm:o}=U(),s=Ie(e.id),[c,l]=(0,Q.useState)(!1),u=e.settings?.plugin?.usage===!0,d=r(e.id,t.id,c),f=async()=>{await o({title:n(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:n(`pluginAccounts.signOut`),destructive:!0})&&s.mutate(t.id,{onError:e=>a(V(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)(j,{tone:`accent`,children:n(`pluginAccounts.current`)}),(0,$.jsx)(j,{tone:t.status===`active`?`green`:`red`,children:n(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),u&&(0,$.jsx)(N,{size:`sm`,onClick:()=>l(e=>!e),children:n(`pluginAccounts.usage`)}),(0,$.jsx)(N,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(qe,{className:`size-3.5`}),onClick:()=>void f(),children:n(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:n(`pluginAccounts.lapsedDetail`)}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[d.isLoading&&(0,$.jsx)(R,{lines:2}),d.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:V(d.error)}),d.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:d.data.error}),d.data?.plan&&(0,$.jsx)(T,{label:n(`pluginAccounts.plan`),children:d.data.plan}),d.data?.until&&(0,$.jsx)(T,{label:n(`pluginAccounts.until`),children:b(d.data.until,i)}),d.data?.windows?.map(e=>(0,$.jsxs)(T,{label:e.name,children:[e.display??(e.limit?`${e.amount??e.used??0} / ${e.limit} ${e.unit??``}`:`${e.used??0}%`),e.resetsAt?` · ${n(`pluginAccounts.resets`,{at:b(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function Zt({provider:e,method:n,onClose:r}){let{t:i}=M(),{toast:o}=U(),[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)(``),[te,re]=(0,Q.useState)(null),b=_(e.id),ie=t(e.id),ae=ye(e.id),x=ee(e.id,te).data;(0,Q.useEffect)(()=>{let t=!0;return ne(e.id,n.index,s).then(e=>{t&&(u(e.prompt),f(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>t&&o(V(e),`error`)),()=>{t=!1}},[e.id,n.index,s,o]),(0,Q.useEffect)(()=>{x?.state===`done`&&(o(i(`pluginAccounts.signedIn`),`success`),r())},[x?.state,r,i,o]);let oe=async()=>{if(!l)return;let t=await a(e.id,n.index,l.key,d).catch(()=>({error:null}));if(t.error)return m(t.error);m(null),c(e=>({...e,[l.key]:d}))};return(0,$.jsxs)(H,{open:!0,onOpenChange:e=>!e&&r(),title:i(`pluginAccounts.signInTitle`,{name:e.name}),description:n.label,width:520,children:[l===void 0&&(0,$.jsx)(R,{lines:2}),l&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:l.message,error:p??void 0,children:l.type===`select`?(0,$.jsx)(W,{value:d,onChange:f,options:(l.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(w,{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)(N,{variant:`primary`,onClick:()=>void oe(),children:i(`pluginAccounts.continue`)})})]}),l===null&&n.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:i(`pluginAccounts.key`),children:(0,$.jsx)(w,{mono:!0,type:`password`,value:h,placeholder:n.placeholder??void 0,onChange:e=>g(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,disabled:!h.trim()||ie.isPending,onClick:()=>ie.mutate({method:n.index,inputs:s,key:h},{onSuccess:()=>(o(i(`pluginAccounts.signedIn`),`success`),r()),onError:e=>o(V(e),`error`)}),children:i(`pluginAccounts.signIn`)})})]}),l===null&&n.type!==`api`&&!x&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,icon:(0,$.jsx)(Ge,{className:`size-3.5`}),disabled:b.isPending,onClick:()=>b.mutate({method:n.index,inputs:s},{onSuccess:e=>{re(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>o(V(e),`error`)}),children:i(`pluginAccounts.openPage`)})}),x&&x.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[x.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:x.instructions}),x.deviceCode&&(0,$.jsx)(T,{label:i(`pluginAccounts.deviceCode`),mono:!0,children:x.deviceCode}),x.url&&(0,$.jsx)(N,{icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onClick:()=>window.open(x.url,`_blank`,`noopener`),children:i(`pluginAccounts.openAgain`)}),x.state===`waiting`&&x.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:i(`pluginAccounts.code`),children:(0,$.jsx)(w,{mono:!0,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,disabled:!v.trim()||ae.isPending,onClick:()=>ae.mutate({flow:x.id,code:v.trim()},{onError:e=>o(V(e),`error`)}),children:i(`pluginAccounts.signIn`)})})]}),x.state===`waiting`&&!x.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`pluginAccounts.waiting`)}),x.state===`failed`&&(0,$.jsx)(P,{tone:`danger`,title:i(`pluginAccounts.failed`),children:x.error})]})]})}function Qt(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 $t(){let{t:e}=M(),{id:t=``}=tt(),n=et(),r=ie(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=v(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(rt,{title:e(`nav.providers`),leading:(0,$.jsx)(en,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(P,{tone:`danger`,title:e(`common.error`),children:V(r.error)})});let u=r.data;return(0,$.jsx)(rt,{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)(en,{onClick:()=>n(`/providers`)}),actions:u&&(0,$.jsx)(tn,{p:u}),children:u?(0,$.jsxs)(Xe,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(X,{"aria-label":u.name,children:[(0,$.jsx)(Ze,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(Ze,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(Ze,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(ot,{value:`models`,className:`pt-4`,children:(0,$.jsx)(rn,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(ot,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(Jt,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(Kt,{provider:u}):(0,$.jsx)(dn,{provider:u})}),(0,$.jsx)(ot,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(pn,{provider:u})}),(0,$.jsx)(un,{provider:u,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(R,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}function en({onClick:e}){let{t}=M();return(0,$.jsx)(N,{variant:`glass`,icon:(0,$.jsx)(Ve,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function tn({p:e}){let{t}=M(),n=et(),{toast:r,confirm:i}=U(),a=ce(),o=Ae(),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=async()=>{await i({title:t(`providers.deleteConfirm`,{name:e.name}),detail:t(`providers.deleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&o.mutate(e.id,{onSuccess:()=>{r(t(`providers.deleted`)),n(`/providers`)},onError:e=>{let n=e instanceof E&&e.status===409?e.details?.boundClients??[]:[];r(n.length?t(`providers.deleteBound`,{clients:n.map(e=>Z[e]?.name??e).join(`, `)}):V(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{icon:(0,$.jsx)(Ke,{className:`size-3.5`}),onClick:()=>u(!0),children:t(`providers.test`)}),(0,$.jsx)(Le,{label:t(`common.more`),icon:(0,$.jsx)(We,{className:`size-4`}),items:[{id:`dup`,label:t(`providers.duplicate`),icon:(0,$.jsx)(Ee,{className:`size-3.5`}),onSelect:()=>a.mutate(e.id,{onSuccess:e=>n(`/providers/${e.id}`),onError:e=>r(V(e),`error`)})},{id:`tpl`,label:t(`providers.templateUpdate`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>c(!0)},{id:`del`,label:t(`common.delete`),icon:(0,$.jsx)(Y,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d()}]}),(0,$.jsx)(nn,{open:s,onOpenChange:c,provider:e}),(0,$.jsx)(G,{provider:e,open:l,onOpenChange:u})]})}function nn({open:e,onOpenChange:t,provider:n}){let{t:r}=M(),{toast:i}=U(),a=s(n.id,e),o=h(n.id),c=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(H,{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)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{variant:`primary`,disabled:!a.data||c,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(V(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(R,{}),a.isError&&(0,$.jsx)(P,{tone:`danger`,title:r(`common.error`),children:V(a.error)}),c&&(0,$.jsx)(P,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!c&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function rn({provider:e,models:t,loading:r,selected:i,onSelect:a}){let{t:o}=M(),{toast:s}=U(),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=F(e.id),h=(t??[]).filter(e=>!c||e.modelId.toLowerCase().includes(c.toLowerCase())||e.effective.displayName.toLowerCase().includes(c.toLowerCase()));return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(me,{className:`w-56`,value:c,onChange:l,placeholder:o(`providers.searchModels`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(N,{icon:(0,$.jsx)(J,{className:`size-3.5`}),onClick:()=>p(!0),children:o(`providers.addModels`)}),(0,$.jsx)(N,{variant:`primary`,icon:(0,$.jsx)(He,{className:`size-3.5`}),onClick:()=>d(!0),children:o(`providers.fetchRemote`)})]})]}),r&&(0,$.jsx)(R,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(C,{title:o(`providers.noModels`),detail:o(`providers.noModelsDetail`)})}),h.length>0&&(0,$.jsx)(L,{footer:o(`providers.modelsFooter`),children:h.map(e=>(0,$.jsxs)(A,{selected:e.id===i,onClick:()=>a(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:O(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(j,{tone:`orange`,children:o(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?n(e.effective.contextWindow):null,we(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(nt,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(B,{checked:e.enabled,label:o(`common.enabled`),onChange:t=>m.mutate({pmId:e.id,enabled:t},{onError:e=>s(V(e),`error`)})})]},e.id))}),t&&(0,$.jsx)(an,{provider:e,models:t}),(0,$.jsx)(sn,{open:f,onOpenChange:p,provider:e}),(0,$.jsx)(cn,{open:u,onOpenChange:d,provider:e})]})}function an({provider:e,models:t}){let{t:n}=M(),{toast:r}=U(),i=Ne(e.id),[a,o]=(0,Q.useState)(!1),s=Qt(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(V(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(L,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(A,{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)(Qe,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:O(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(j,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(le,{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)(A,{icon:(0,$.jsx)(J,{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)(on,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function on({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=M(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(H,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(N,{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)(w,{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)(W,{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 sn({open:e,onOpenChange:t,provider:n}){let{t:r}=M(),{toast:i}=U(),a=xe(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)(H,{open:e,onOpenChange:t,title:r(`providers.addModels`),description:r(`providers.addModelsDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{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(V(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(se,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
|
|
3
|
+
claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function cn({open:e,onOpenChange:t,provider:n}){let{t:r}=M(),{toast:i}=U(),a=D(n.id,e),o=xe(n.id),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&c(new Set)},[e]);let d=(a.data??[]).filter(e=>!l||e.id.toLowerCase().includes(l.toLowerCase())),f=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(H,{open:e,onOpenChange:t,width:560,title:r(`providers.fetchRemote`),description:r(`providers.fetchRemoteDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{variant:`plain`,className:`mr-auto`,onClick:()=>c(new Set(d.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:d.length===0,children:r(`common.selectAll`)}),(0,$.jsx)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{variant:`primary`,disabled:s.size===0,loading:o.isPending,onClick:()=>o.mutate([...s],{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(V(e),`error`)}),children:r(`providers.addSelected`,{count:s.size})})]}),children:[(0,$.jsx)(me,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(R,{lines:4}),a.isError&&(0,$.jsx)(P,{tone:`danger`,title:r(`common.error`),children:V(a.error)}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(A,{onClick:e.alreadyAdded?void 0:()=>f(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(j,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ct,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function ln({origin:e}){let{t}=M();return e===`overridden`?(0,$.jsx)(j,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(j,{children:t(`origin.inherited`)}):(0,$.jsx)(j,{tone:`red`,children:t(`origin.unset`)})}function un({provider:e,pm:t,onClose:n}){let{t:r}=M(),{toast:i}=U(),a=F(e.id),o=De(e.id),s=g(),[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)(H,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let m={...c,pricing:f?c.pricing??null:null},h=JSON.stringify(m)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||u!==(t.systemModelId??``),_=()=>a.mutate({pmId:t.id,overrides:m,systemModelId:u||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(V(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)(ln,{origin:c[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),c[e]!=null&&(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ye,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(H,{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)(lt,{label:r(`providers.removeModelShort`),icon:(0,$.jsx)(Y,{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)(N,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(N,{variant:`primary`,disabled:!h,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)(nt,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(j,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(S,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(W,{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)(S,{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)(w,{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)(Te,{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)(Te,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:c.maxOutputTokens,onChange:e=>l({...c,maxOutputTokens:e})}))]})}),(0,$.jsxs)(S,{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)(B,{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)(it,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(ge,{maxHeight:220,children:I(t.effectivePricing)}):(0,$.jsx)(P,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function dn({provider:t}){let{t:n}=M(),{toast:r}=U(),i=e(t.id),[a,o]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(L,{title:n(`providers.section.auth`),footer:n(`providers.apiKeyStored`),children:(0,$.jsx)(A,{label:n(`providers.apiKey`),detail:t.hasApiKey?t.apiKeyMasked??`••••`:n(`providers.noKey`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(w,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n(`providers.apiKey`),placeholder:n(`providers.replaceKey`),value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(N,{variant:`primary`,disabled:a.trim().length===0,loading:i.isPending,onClick:()=>i.mutate({apiKey:a},{onSuccess:()=>{o(``),r(n(`common.saved`),`success`)},onError:e=>r(V(e),`error`)}),children:n(`common.save`)})]})})}),(0,$.jsx)(Re,{provider:t})]})}function fn(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 pn({provider:t}){let{t:n}=M(),{toast:r}=U(),i=e(t.id),a=c(),o=(0,Q.useMemo)(()=>fn(t),[t]),[s,l]=(0,Q.useState)(o),[u,d]=(0,Q.useState)(Object.entries(t.extraHeaders)),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{l(o),d(Object.entries(o.extraHeaders))},[o]);let g=e=>l(t=>({...t,...e})),_={...s,extraHeaders:Object.fromEntries(u.filter(([e])=>e.trim()))},v=JSON.stringify(_)!==JSON.stringify(o),ee=()=>{let e={};for(let t of Object.keys(_))t!==`apiKey`&&JSON.stringify(_[t])!==JSON.stringify(o[t])&&(e[t]=_[t]);s.apiKey&&(e.apiKey=s.apiKey),i.mutate(e,{onSuccess:()=>r(n(`common.saved`),`success`),onError:e=>r(V(e),`error`)})},y=(e,t)=>g({endpoints:s.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(L,{title:n(`providers.section.basic`),children:[(0,$.jsx)(A,{label:n(`providers.name`),children:(0,$.jsx)(w,{className:`w-64`,"aria-label":n(`providers.name`),value:s.name,onChange:e=>g({name:e.target.value})})}),(0,$.jsx)(A,{label:n(`common.enabled`),children:(0,$.jsx)(B,{checked:s.enabled,label:n(`common.enabled`),onChange:e=>g({enabled:e})})}),(0,$.jsx)(A,{label:n(`providers.notes`),children:(0,$.jsx)(w,{className:`w-64`,"aria-label":n(`providers.notes`),value:s.notes??``,onChange:e=>g({notes:e.target.value||null})})})]}),(0,$.jsx)(L,{title:n(`providers.section.auth`),children:(0,$.jsx)(A,{label:n(`providers.authScheme`),children:(0,$.jsx)(W,{className:`w-48`,value:s.authScheme,onChange:e=>g({authScheme:e}),options:ze})})}),(0,$.jsxs)(L,{title:n(`providers.section.endpoints`),footer:n(`providers.endpointsFooter`),children:[s.endpoints.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(W,{className:`w-48`,value:e.protocol,onChange:e=>y(t,{protocol:e}),options:K}),(0,$.jsx)(w,{className:`min-w-60 flex-1 font-mono`,"aria-label":n(`providers.baseUrl`),value:e.baseUrl,onChange:e=>y(t,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(B,{checked:!!e.fullUrl,label:n(`providers.fullUrl`),onChange:e=>y(t,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>g({endpoints:s.endpoints.filter((e,n)=>n!==t)})})]},t)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(J,{className:`size-3.5`}),onClick:()=>p(!0),children:n(`providers.addEndpoint`)})}),(0,$.jsx)(A,{label:n(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[n(`providers.preferredHint`),s.preferredUpstreamProtocols.filter(e=>!s.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:n(`providers.preferredMissing`,{protocol:K.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(at,{label:n(`providers.preferred`),options:K.map(e=>{let t=s.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:s.preferredUpstreamProtocols,onValueChange:e=>{let t=s.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));g({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(L,{title:n(`providers.section.billing`),footer:n(`providers.billingFooter`),children:[(0,$.jsx)(A,{label:n(`providers.priceKey`),detail:n(`providers.priceKeyHint`),children:(0,$.jsx)(W,{className:`w-56`,value:s.priceKey==null?`inherit`:`price:${s.priceKey}`,onChange:e=>g({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:n(`providers.priceKeyDefault`,{id:t.templateId??`—`})},{value:`price:`,label:n(`providers.priceKeyNone`)},...(a.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(A,{label:n(`providers.multiplier`),detail:n(`providers.multiplierHint`),children:(0,$.jsx)(Te,{className:`w-28`,label:n(`providers.multiplier`),step:.01,min:0,value:s.priceMultiplier,onChange:e=>g({priceMultiplier:e??1})})})]}),(0,$.jsxs)(L,{title:n(`providers.section.advanced`),children:[(0,$.jsx)(A,{label:n(`providers.proxy`),detail:n(`providers.proxyHint`),children:(0,$.jsx)(w,{className:`w-64 font-mono`,"aria-label":n(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:s.httpProxy??``,onChange:e=>g({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:n(`providers.headers`)}),u.map(([e,t],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(w,{className:`w-48 font-mono`,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>d(u.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(w,{className:`flex-1 font-mono`,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:t,onChange:e=>d(u.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>d(u.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(J,{className:`size-3.5`}),onClick:()=>h(!0),children:n(`providers.addHeader`)})]}),Object.keys(t.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(se,{label:n(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:I(s.settings),onBlur:e=>{try{g({settings:JSON.parse(e.target.value)})}catch{r(n(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(L,{title:n(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(T,{label:`ID`,children:t.id}),t.adapterId&&(0,$.jsx)(T,{label:n(`providers.adapter`),children:t.adapterId}),(0,$.jsx)(T,{label:n(`providers.boundClients`),children:t.boundClients.map(e=>Z[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(mn,{open:f,onOpenChange:p,onAdd:e=>g({endpoints:[...s.endpoints,e]})}),(0,$.jsx)(hn,{open:m,onOpenChange:h,onAdd:e=>d([...u.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:v&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:n(`common.unsaved`)}),(0,$.jsx)(N,{size:`sm`,onClick:()=>{l(o),d(Object.entries(o.extraHeaders))},children:n(`common.revert`)}),(0,$.jsx)(N,{size:`sm`,variant:`primary`,loading:i.isPending,onClick:ee,children:n(`common.save`)})]})})]})}function mn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=M(),[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)(H,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{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)(k,{label:r(`providers.protocol`),children:(0,$.jsx)(W,{value:i,onChange:a,options:K})}),(0,$.jsx)(k,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(w,{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)(B,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function hn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=M(),[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)(H,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{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)(k,{label:r(`providers.headerName`),children:(0,$.jsx)(w,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.headerValue`),children:(0,$.jsx)(w,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{$t as ProviderDetailPage};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$n as e,$r as t,Ai as n,Di as r,E as i,Ei as a,Gn as o,Ir as s,J as c,Lr as l,Oi as u,Qn as d,Sa as f,Ti as p,W as m,Yt as h,Z as g,_,_a as v,b as y,c as b,ct as x,d as S,dn as C,er as w,f as T,fi as E,gt as D,h as O,i as k,it as A,ki as ee,l as j,m as M,n as N,ot as P,p as F,r as I,s as L,t as R,u as z,v as te,va as B,vn as V,vr as H,vt as U,w as W,wt as ne,xa as re,y as G,ya as K,yn as ie,zr as ae}from"./alert-CGUFPyGb.js";import{A as oe,C as se,D as ce,E as le,O as ue,T as de,X as fe,a as q,ct as pe,dt as me,ft as he,i as ge,k as _e,mt as ve,o as ye,pt as be,r as xe,ut as Se,w as Ce}from"./overlays-B1a0OZYb.js";import{t as we}from"./arrow-left-Dn6_YDkh.js";import{t as Te}from"./download-5xAFYJ6Q.js";import{n as Ee,t as De}from"./radio-cards-Cr0tP9In.js";import{$ as Oe,A as ke,I as Ae,L as je,O as Me,P as Ne,Q as Pe,S as Fe,X as Ie,_ as Le,b as Re,et as ze,g as Be,h as Ve,q as He,x as Ue}from"./index-mlmGhWY4.js";import{t as We}from"./checkbox-DzIMWhhw.js";var J=f(K(),1);function Ge(e,t,n){(0,J.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var Ke={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`]};Ke.node;var qe=U(Ke),Je={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`}]]};Je.node;var Ye=U(Je),Xe={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Xe.node;var Ze=U(Xe),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=B(),{blur:Qe,duration:Z,ease:$e,spring:et,stagger:tt}=i,nt={...et.smooth,visualDuration:.3},rt={...et.smooth,visualDuration:.26},it=300,at={duration:Z.instant},ot=1.04,st={duration:Z.considered*2,ease:[...$e.standard]},ct={duration:Z.considered,ease:[...$e.standard]},lt={delay:Z.instant,duration:Z.standard,ease:[...$e.enter]},ut={delay:Z.instant,duration:Z.fast,ease:[...$e.enter]},dt={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${Qe.subtle}px)`,transition:{duration:Z.fast,ease:[...$e.standard]}}},ft={enter:{opacity:0,y:`.3em`,filter:`blur(${Qe.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:Z.standard,ease:[...$e.enter],delay:e*tt.word}})};function pt({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)(n,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(p.span,{className:Y.line,variants:dt,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,X.jsx)(p.span,{className:Y.word,custom:t/2,variants:ft,children:e},t))},e)})})]})}function mt(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function ht({title:e,description:t,media:i,action:a,avatar:o,meta:s,status:c,details:l,open:u,defaultOpen:d=!1,onOpenChange:f,children:m,className:h,style:g,..._}){let v=r()??!1,y=(0,J.useId)(),b=(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=l?u??C:!1,M=!!l&&!v,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=b.current,t=S.current;if(!M||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=mt(e,n.borderTopLeftRadius),i=mt(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 I=(0,J.useRef)(j);(0,J.useLayoutEffect)(()=>{let e=I.current&&!j;I.current=j;let t=b.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),it);return()=>window.clearTimeout(e)},[N]);let L=(e,t,n=!0)=>M?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?j:N?`return`:`panel`,transition:{layout:t===`card`?rt:nt}}:{},R=e=>o||s||c||a?(0,X.jsxs)(`div`,{className:Y.footer,children:[o||s||c?(0,X.jsxs)(p.div,{className:Y.byline,...L(`byline`,e,`position`),children:[o?(0,X.jsx)(`span`,{className:Y.avatar,children:o}):null,(0,X.jsxs)(`span`,{className:Y.bylineText,children:[s?(0,X.jsx)(`span`,{className:Y.meta,children:s}):null,c?(0,X.jsx)(pt,{text:c,reduced:v}):null]})]}):null,a?(0,X.jsx)(p.div,{className:Y.action,...L(`action`,e,`position`),children:a}):null]}):null,z=(0,X.jsxs)(p.article,{..._,ref:b,className:[Y.card,h].filter(Boolean).join(` `),style:{...g,borderRadius:D.card??g?.borderRadius},"data-hover":T||void 0,whileHover:v?void 0:{y:-2},onHoverStart:()=>E(!0),onHoverEnd:()=>E(!1),...L(`card`,`card`),transition:{default:et.snappy,layout:rt},children:[i?(0,X.jsx)(p.div,{className:Y.media,...L(`media`,`card`),children:(0,X.jsx)(p.div,{className:Y.zoom,initial:!1,animate:{scale:T&&!v?ot:1},transition:T?st:ct,children:i})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(p.h3,{className:Y.title,...L(`title`,`card`),children:l?(0,X.jsx)(oe,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:Y.trigger,children:e})}):e}),t?(0,X.jsx)(p.p,{ref:S,className:Y.description,...L(`description`,`card`,`position`),children:t}):null,m,R(`card`)]})]});return l?(0,X.jsx)(se,{open:j,onOpenChange:F,children:(0,X.jsxs)(ee,{id:y,children:[z,(0,X.jsx)(n,{children:(j||N)&&(0,X.jsxs)(ue,{forceMount:!0,children:[(0,X.jsx)(n,{children:j&&(0,X.jsx)(ce,{asChild:!0,forceMount:!0,children:(0,X.jsx)(p.div,{className:Y.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:v?at:{duration:Z.exit,ease:[...$e.standard]}},transition:v?at:{duration:Z.standard,ease:[...$e.enter]}})},`overlay`)}),(0,X.jsx)(de,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,X.jsxs)(p.div,{className:Y.panel,"data-framer-portal-id":y,"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?{...L(`card`,`panel`),initial:!1,animate:D.card!==void 0&&D.panel!==void 0?{borderRadius:N?D.card:D.panel}:void 0,transition:{layout:N?rt:nt,borderRadius:N?rt:nt},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:at},transition:at},children:[i?(0,X.jsx)(p.div,{className:Y.media,...L(`media`,`panel`),children:(0,X.jsx)(p.div,{className:Y.zoom,initial:{scale:T&&!v?ot:1},animate:{scale:1},transition:nt,children:i})}):null,(0,X.jsx)(p.span,{className:Y.closeSlot,initial:v?{opacity:0}:{opacity:0,scale:.9},animate:N?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:N||v?at:ut,children:(0,X.jsx)(Ce,{asChild:!0,children:(0,X.jsx)(p.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:v?void 0:{scale:.94},transition:et.snappy,children:(0,X.jsx)(x,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(_e,{asChild:!0,children:(0,X.jsx)(p.h2,{className:Y.title,...L(`title`,`panel`),children:e})}),t?(0,X.jsx)(le,{asChild:!0,children:(0,X.jsx)(p.p,{className:Y.description,...L(`description`,`panel`,`position`),children:t})}):null,m,R(`panel`),(0,X.jsx)(p.div,{className:Y.details,initial:!v&&{opacity:0,y:6},animate:N?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:at},transition:N||v?at:lt,children:l})]})]})})]},`quick-look`)})]})}):z}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`},gt={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${i.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:i.duration.standard,ease:[...i.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${i.blur.subtle}px)`,transition:{duration:i.duration.fast,ease:[...i.ease.standard]}})},_t={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:i.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:i.duration.instant}}},vt=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),yt=new Intl.NumberFormat(`en-US`),bt={duration:i.duration.considered*1.75,ease:[...i.ease.inOut]},xt={duration:i.duration.fast,ease:[...i.ease.standard]};function St(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 Ct({text:e,direction:t,whole:o=!1,morph:s=!1,tone:c}){let l=!!r(),d=(0,J.useRef)(null),f=u(`auto`),[m,h]=(0,J.useState)({text:e,direction:1});m.text!==e&&h({text:e,direction:t??(vt(e)<vt(m.text)?-1:1)}),(0,J.useEffect)(()=>{let e=d.current;if(!e||typeof ResizeObserver>`u`)return;let t=null,n=new ResizeObserver(([n])=>{if(!n)return;let r=n.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;t!==null&&t!==e.textContent&&!l?a(f,r,i.spring.morph):f.jump(r),t=e.textContent});return n.observe(e),()=>n.disconnect()},[s,l,f]);let g=!o&&!/\p{L}/u.test(e),_=l?_t:gt,v=g?`right`:`left`;return(0,X.jsxs)(p.span,{className:Q.roll,"data-end":g||void 0,"data-whole":o||void 0,style:s?{width:f}:void 0,children:[s&&(0,X.jsx)(`span`,{ref:d,className:Q.sizer,"aria-hidden":`true`,children:e}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(n,{mode:`popLayout`,initial:!1,custom:m.direction,anchorX:v,children:St(e,o).map(e=>(0,X.jsx)(p.span,{className:Q.slot,custom:m.direction,variants:_,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(n,{mode:`popLayout`,initial:!1,custom:m.direction,anchorX:v,children:(0,X.jsx)(p.span,{className:c?`${Q.glyph} ${c}`:Q.glyph,custom:m.direction,variants:_,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${c??``}${e.key}`)})},e.slot))})})]})}var wt=5,Tt=1.25,Et=Array.from({length:161},(e,t)=>t/160);function Dt(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 Ot(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 kt(e,t,n,r){let i=e=>wt+(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(Ot(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 At(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 jt({data:e,label:t,value:n,change:o,tone:s=`accent`,width:c=160,height:l=52,labels:d,formatValue:f,area:m=!0,interactive:h=!0}){let g=e.length>1?e:[e[0]??0,e[0]??0],_=g.length-1,v=g.join(`,`),y=(0,J.useMemo)(()=>Dt(v.split(`,`).map(Number)),[v]),b=`${t}: ${n??g[_]}. ${o??``}`.trim(),x=`sparkline${(0,J.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,S=(0,J.useRef)(null),C=(0,J.useRef)(null),w=Oe(S,{once:!0,amount:.5}),T=!!r(),[E,D]=(0,J.useState)({w:c,h:l}),[O,k]=(0,J.useState)(null),[A,ee]=(0,J.useState)(!1),j=O===null?null:Math.min(O,_),[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)(()=>kt(y,c,l,1)),F=(0,J.useRef)(y),I=(0,J.useRef)(E),L=u(0),R=u(1),z=u(P.line),te=u(P.trail),B=u(P.fill),V=u(P.dot),H=u(P.cx),U=u(P.cx+Tt+16),W=u(P.cx+Tt),ne=u(0),re=ze(L,e=>+(e>.001)),G=(0,J.useCallback)(()=>{let{w:e,h:t}=I.current,n=L.get(),r=kt(F.current,e,t,R.get());z.set(r.line),te.set(r.trail),B.set(r.fill),V.set(r.dot),H.set(r.cx),U.set(r.cx+Tt+16),W.set(r.cx+Tt),ne.set(n>=1?e+32:At(r.points,n)+16)},[R,H,W,V,L,B,z,U,ne,te]);Ge(R,`change`,G),Ge(L,`change`,G),(0,J.useLayoutEffect)(()=>{let e=C.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&D(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*l/c})});return t.observe(e),()=>t.disconnect()},[l,c]),(0,J.useLayoutEffect)(()=>{I.current=E,G()},[E,G]),(0,J.useEffect)(()=>{if(T){L.jump(1);let e=requestAnimationFrame(()=>ee(!0));return()=>cancelAnimationFrame(e)}if(!w)return;let e=a(L,1,{...bt,onComplete:()=>ee(!0)});return()=>e.stop()},[L,w,T]),(0,J.useEffect)(()=>{let e=F.current;if(e===y)return;if(T){F.current=y,G();return}let t=[...new Set([...Et,...y.map(([e])=>e)])].sort((e,t)=>e-t),n=t.map(t=>Ot(e,t)),r=t.map(e=>Ot(y,e)),o=a(0,1,{...i.spring.smooth,onUpdate:e=>{F.current=t.map((t,i)=>[t,n[i]+(r[i]-n[i])*e]),G()},onComplete:()=>{F.current=y,G()}});return()=>o.stop()},[G,T,y]),(0,J.useEffect)(()=>{let e=j===null?1:j/_;if(T){R.jump(e);return}let t=a(R,e,i.spring.snappy);return()=>t.stop()},[R,j,_,T]);let K=j!==null,ie=(e=>f?f(g[e],e):yt.format(g[e]))(j??_),ae=d?.[j??_],oe=n===void 0?void 0:K?ie:n,se=j===null?o??``:n===void 0?[ie,ae].filter(Boolean).join(` · `):ae??`${j+1} of ${_+1}`,ce=e=>{let t=C.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(_,Math.round((e-t.left)/t.width*_))):_},le=h?{role:`slider`,tabIndex:0,"aria-label":`${t}, explore values`,"aria-valuemin":1,"aria-valuemax":_+1,"aria-valuenow":(j??_)+1,"aria-valuetext":`${ae??(j===null?`Latest`:`Point ${j+1} of ${_+1}`)}: ${ie}`,onPointerDown:e=>k(ce(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&k(ce(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&k(null)},onPointerLeave:()=>k(null),onPointerCancel:()=>k(null),onBlur:()=>k(null),onKeyDown:e=>{if(e.key===`Escape`&&K){e.preventDefault(),k(null);return}let t=j??_,n=Math.max(1,Math.round((_+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:_}[e.key];r!==void 0&&(e.preventDefault(),k(Math.max(0,Math.min(_,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)(Ct,{text:t,whole:!0})}),oe!==void 0&&(0,X.jsx)(`strong`,{children:(0,X.jsx)(Ct,{text:oe,morph:!0})}),(0,X.jsx)(`small`,{className:Q[s],children:(0,X.jsx)(Ct,{text:se,direction:K?M.direction:void 0,tone:K?Q.point:void 0,morph:!0})})]}),(0,X.jsx)(`div`,{ref:C,className:Q.plot,"data-interactive":h||void 0,...le,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)(p.rect,{x:-16,y:-16,width:U,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(p.rect,{x:W,y:-16,width:E.w+32,height:E.h+32})}),(0,X.jsx)(`clipPath`,{id:`${x}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(p.rect,{x:-16,y:-16,width:ne,height:E.h+32})})]}),m&&(0,X.jsx)(p.path,{className:`${Q.area} ${Q[s]}`,d:B,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)(p.path,{className:Q.trail,d:te,clipPath:`url(#${x}-dim)`,initial:!1,animate:{opacity:K&&A?1:0},transition:T?{duration:0}:xt}),(0,X.jsx)(p.polyline,{className:[Q.line,Q[s]].join(` `),points:z,clipPath:`url(#${x}-lit)`,style:{pathLength:L,opacity:re}}),(0,X.jsx)(p.line,{className:Q.cursor,x1:H,x2:H,y1:0,y2:E.h,initial:!1,animate:{opacity:+!!K},transition:T?{duration:0}:xt}),(0,X.jsx)(p.polyline,{className:[Q.end,Q[s]].join(` `),points:V,initial:!1,animate:{opacity:+!!A,strokeWidth:A?K?10:7:0},transition:T?{duration:0}:{opacity:xt,strokeWidth:i.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`},Mt=e=>`blur(${e}px)`,Nt={duration:0},Pt={duration:i.duration.fast,ease:[...i.ease.standard]},Ft={duration:i.duration.standard,ease:[...i.ease.enter]},It={opacity:0,y:`0.3em`,filter:Mt(i.blur.soft)},Lt={opacity:1,y:0,filter:Mt(0)},Rt={opacity:0,y:`-0.3em`,filter:Mt(i.blur.subtle)},zt={opacity:0,scale:.5,filter:Mt(i.blur.subtle)},Bt={opacity:1,scale:1,filter:Mt(0)};function Vt({text:e,className:t,reduced:r}){let o=(0,J.useRef)(null),s=(0,J.useRef)(0),c=u(`auto`);return(0,J.useLayoutEffect)(()=>{s.current=performance.now()+700},[e]),(0,J.useEffect)(()=>{let e=o.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let n=!1,l=new ResizeObserver(()=>{let t=e.offsetHeight;if(!n||r||performance.now()>s.current){n=!0,c.jump(t);return}a(c,t,i.spring.smooth)});return l.observe(e),()=>l.disconnect()},[c,r]),(0,X.jsx)(p.span,{className:$.slot,style:{height:c},children:(0,X.jsx)(`span`,{ref:o,className:$.slotInner,children:(0,X.jsx)(n,{mode:`popLayout`,initial:!1,children:e?(0,X.jsx)(p.span,{className:t,initial:It,animate:Lt,exit:{...Rt,transition:r?Nt:Pt},transition:r?Nt:Ft,children:e},`${t}:${e}`):null})})})}function Ht({kind:e,number:t,delay:n,reduced:r}){let a=r?Nt:{scale:{...i.spring.snappy,delay:n},opacity:{duration:i.duration.fast,delay:n},filter:{duration:i.duration.fast,delay:n}},o={...zt,transition:r?Nt:Pt},s=r?Nt:{duration:i.duration.standard,ease:i.ease.enter,delay:n+.04};return e===`number`?(0,X.jsx)(p.span,{className:$.glyph,initial:zt,animate:Bt,exit:o,transition:a,children:t}):(0,X.jsx)(p.svg,{className:`${$.glyph} ${$.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:zt,animate:Bt,exit:o,transition:a,children:e===`check`?(0,X.jsx)(p.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)(p.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(p.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:r?Nt:{...i.spring.snappy,delay:n+.16}})]})})}function Ut({number:e,kind:t,current:r,glyphDelay:a,ringDelay:o,reduced:s}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(n,{initial:!1,children:r?(0,X.jsx)(p.span,{className:$.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:s?Nt:Pt},transition:s?Nt:{scale:{...i.spring.snappy,delay:o},opacity:{duration:i.duration.fast,delay:o}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(n,{initial:!1,children:(0,X.jsx)(Ht,{kind:t,number:e,delay:a,reduced:s},t)})})]})}var Wt={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Gt({steps:e,current:t,orientation:n=`horizontal`,onStepSelect:a,details:o=`all`,compact:s=!1,label:c=`Progress`,completeLabel:l=`All steps complete`,className:u}){let d=r()??!1,f=e.length,m=Math.min(Math.max(Math.round(t),0),f),[h,g]=(0,J.useState)({to:m,from:m});h.to!==m&&g({to:m,from:h.to});let _=h.from,v=i.stagger.line,y=e=>d?0:m>_?e>=_&&e<m?(e-_)*v:0:e>=m&&e<_?(_-1-e)*v:0,b=d?0:Math.max(0,Math.abs(m-_)-1)*v+.12,x=!!a,S=n===`vertical`,C=m>=f?void 0:e[m];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,s?$.compact:``,u].filter(Boolean).join(` `);return(0,X.jsxs)(T,{className:E,"aria-label":c,role:x?void 0:`group`,children:[(0,X.jsx)(`ol`,{className:$.list,style:S?void 0:{gridTemplateColumns:f>1?`repeat(${f-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:x?w:void 0,children:e.map((e,t)=>{let r=t===m,s=e.error?`error`:t<m?`complete`:r?`current`:`upcoming`,c=x&&t<m,l=e.error??(o===`all`||r?e.description:void 0),u=e.error?`error`:t<m?`check`:`number`,h=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ut,{number:t+1,kind:u,current:r,glyphDelay:y(t),ringDelay:b,reduced:d}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:e.label}),Wt[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Wt[s]]}):null,(0,X.jsx)(Vt,{text:l,className:e.error?$.error:$.description,reduced:d})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[t<f-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(p.span,{className:$.fill,initial:!1,animate:S?{scaleY:+(t<m)}:{scaleX:+(t<m)},transition:d?Nt:{...i.spring.smooth,delay:y(t)}},n)}):null,x?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":t<=m||void 0,"aria-current":r?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>a?.(t):void 0,children:h}):(0,X.jsx)(`span`,{className:$.head,"aria-current":r?`step`:void 0,children:h})]},e.id)})}),S?null:(0,X.jsxs)(`span`,{className:$.caption,"aria-hidden":`true`,children:[(0,X.jsx)(Vt,{text:C?.label??l,className:$.captionLabel,reduced:d}),(0,X.jsx)(Vt,{text:C?.error??C?.description,className:C?.error?$.error:$.description,reduced:d})]}),(0,X.jsx)(`span`,{className:$.srOnly,"aria-live":`polite`,children:C?`Step ${m+1} of ${f}: ${C.label}`:l})]})}var Kt={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},qt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},Jt=e=>`${e.source}\u0000${e.ref}`,Yt=e=>e.status!==`skip`&&e.status!==`same`;function Xt(e){try{return new URL(e).host}catch{return e}}function Zt({open:e,onOpenChange:t}){let{t:n}=P(),{toast:r}=ye(),i=ie(e),a=V(),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(new Set),[u,d]=(0,J.useState)(null);(0,J.useEffect)(()=>{i.data&&l(new Set(i.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Jt)))},[i.data]),(0,J.useEffect)(()=>{e&&(s(``),d(null))},[e]);let f=o.trim().toLowerCase(),p=e=>!f||e.name.toLowerCase().includes(f)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(f)),m=(0,J.useMemo)(()=>(i.data??[]).flatMap(e=>e.items).filter(e=>c.has(Jt(e))&&Yt(e)),[i.data,c]),h=(e,t)=>l(n=>{let r=new Set(n);return t?r.add(Jt(e)):r.delete(Jt(e)),r});return(0,X.jsx)(ge,{open:e,onOpenChange:t,width:680,title:n(`import.title`),description:n(`import.detail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{icon:(0,X.jsx)(Ae,{className:`size-3.5`}),onClick:()=>void i.refetch(),disabled:i.isFetching||a.isPending,children:n(`import.rescan`)}),(0,X.jsx)(I,{variant:`primary`,disabled:m.length===0||a.isPending,onClick:()=>{d(null),a.mutate(m.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let i=e.skipped.length;r(i>0?n(`import.doneSkipped`,{count:e.added.length,skipped:i}):n(`import.done`,{count:e.added.length})),t(!1)},onError:e=>{d(q(e)),i.refetch()}})},children:n(`import.selected`,{count:m.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(O,{value:o,onChange:s,placeholder:n(`import.search`)}),u&&(0,X.jsx)(R,{tone:`danger`,title:n(`common.error`),children:u}),i.isLoading&&(0,X.jsx)(te,{lines:3}),i.isError&&(0,X.jsx)(R,{tone:`danger`,title:n(`common.error`),children:q(i.error)}),(0,X.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:i.data?.map(e=>(0,X.jsx)(Qt,{source:e,matches:p,selected:c,onToggle:h,filtering:f.length>0},e.id))}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`import.footnote`)})]})})}function Qt({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=P(),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)(R,{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)($t,{c:e,checked:n.has(Jt(e)),onToggle:t=>r(e,t)},Jt(e)))}):(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function $t({c:e,checked:t,onToggle:n}){let{t:r}=P(),i=Yt(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=>`${Kt[e.protocol]??e.protocol} · ${Xt(e.baseUrl)}`).join(` / `);return(0,X.jsxs)(`li`,{className:A(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,X.jsx)(We,{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)(N,{tone:qt[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 en=``,tn=`custom`,nn=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],rn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},an={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},on=e=>JSON.stringify(e??{},null,2);function sn(e){return{enabled:e.enabled,template:e.template??en,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:on(e.request?.headers),extract:e.extract?on(e.extract):``}}function cn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function ln({provider:e}){let{t}=P(),{toast:n}=ye(),r=w(),i=H(e.id),a=l(e.id),o=C(),s=e.quotaConfig,c=(0,J.useMemo)(()=>sn(s),[s]),[u,d]=(0,J.useState)(c),[f,p]=(0,J.useState)(null);(0,J.useEffect)(()=>d(c),[c]);let m=r.data??[],h=m.find(e=>e.id===s.suggestedTemplate),g=u.template===en?h:m.find(e=>e.id===u.template),_=u.template===tn,v=_?nn:g?.params??[],b=e=>d(t=>({...t,...e})),x=JSON.stringify(u)!==JSON.stringify(c),E=e=>{if(e!==tn||u.url)return b({template:e});let t=g??h;b({template:e,method:t?.request.method??rn.method,url:t?.request.url??rn.url,auth:t?.request.auth??rn.auth,headers:on(t?.request.headers??rn.headers),extract:on(t?.extract??an)})},D=()=>{let e={enabled:u.enabled,template:u.template===en?null:u.template,intervalMinutes:u.intervalMinutes,timeoutSec:u.timeoutSec??10,baseUrl:u.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(u.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(u.secrets).filter(([,e])=>e.trim()!==``))};if(_){let r=cn(u.headers),i=cn(u.extract);if(!r||!i)return n(t(`providers.quota.invalidJson`,{field:t(r?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:u.method,url:u.url.trim(),auth:u.auth,headers:r},e.extract=i}return e},O=()=>{let r=D();if(!r)return;let a=r.enabled&&!s.enabled;i.mutate(r,{onSuccess:()=>{n(t(`common.saved`),`success`),a&&o.mutate(e.id,{onError:e=>n(q(e),`error`)})},onError:e=>n(q(e),`error`)})},A=()=>{let e=D();e&&a.mutate(e,{onSuccess:p,onError:e=>n(q(e),`error`)})},ee=s.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:s.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),j=[{value:en,label:h?t(`providers.quota.templateAuto`,{name:h.name}):t(`providers.quota.templateNone`)},...m.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:tn,label:t(`providers.quota.custom`)}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(z,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,X.jsx)(M,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,X.jsx)(G,{checked:u.enabled,label:t(`providers.quota.enable`),onChange:e=>b({enabled:e})})}),(0,X.jsx)(M,{label:t(`providers.quota.template`),children:(0,X.jsx)(xe,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:u.template,onChange:E,options:j})}),v.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=s.secrets.includes(e.name);return e.secret?(0,X.jsx)(M,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,X.jsx)(S,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:u.secrets[e.name]??``,onChange:t=>b({secrets:{...u.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(M,{label:n,children:(0,X.jsx)(S,{className:`w-64 font-mono`,"aria-label":n,value:u.params[e.name]??``,onChange:t=>b({params:{...u.params,[e.name]:t.target.value}})})},e.name)}),v.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),_&&(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)(xe,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:u.method,onChange:e=>b({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(S,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:u.url,onChange:e=>b({url:e.target.value})}),(0,X.jsx)(xe,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:u.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)(y,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:u.headers,onChange:e=>b({headers:e.target.value})}),(0,X.jsx)(y,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:u.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)(M,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:ee}),children:(0,X.jsx)(F,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:u.intervalMinutes,onChange:e=>b({intervalMinutes:e})})}),(0,X.jsx)(M,{label:t(`providers.quota.timeout`),children:(0,X.jsx)(F,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:u.timeoutSec,onChange:e=>b({timeoutSec:e})})}),(0,X.jsx)(M,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(S,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:u.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)(I,{size:`sm`,variant:`primary`,disabled:!x,loading:i.isPending,onClick:O,children:t(`common.save`)}),(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),loading:a.isPending,onClick:A,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Ye,{className:`size-3.5`}),disabled:x,loading:o.isPending,onClick:()=>o.mutate(e.id,{onError:e=>n(q(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(un,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,X.jsx)(ge,{open:f!==null,onOpenChange:e=>!e&&p(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:f&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(R,{tone:f.ok?`success`:`danger`,title:f.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!f.ok&&pe({code:f.errorCode??null,message:f.error??``},t),!f.ok&&f.error&&f.errorCode&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:f.error})]}),f.url&&(0,X.jsx)(T,{label:t(`providers.quota.requestUrl`),mono:!0,children:f.url}),f.httpStatus!=null&&(0,X.jsx)(T,{label:t(`providers.quota.httpStatus`),children:f.httpStatus}),f.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)(un,{snapshot:f.snapshot})]}),f.raw!==void 0&&f.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)(k,{children:on(f.raw)})]})]})})]})}function un({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=P(),i=be(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)(R,{tone:`warning`,title:n(`providers.quota.failed`,{error:pe(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)(R,{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)(N,{children:e.name}),(0,X.jsx)(`span`,{className:`num`,children:Se(e,n,r)??`—`}),me(e,n,r)&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:me(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)(N,{tone:`accent`,children:e.planLabel}),o>0&&(0,X.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:fe(o,r,n(`tray.justNow`))??``})})]})]})}function dn({provider:e}){let{t,locale:n}=P(),{toast:r}=ye(),i=C();if(!he(e))return null;let a=ve(e.quota,t,n),o=be(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:pe(o,t)})}),!a&&!o&&(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ye,{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(q(e),`error`)})})]})}var fn=3,pn=256,mn=4096,hn={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 gn(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var _n=e=>typeof e==`number`?e:null,vn=e=>typeof e==`string`?e:null;function yn({provider:e,open:t,onOpenChange:n}){let{t:r}=P(),i=v(),a=d(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,J.useState)(`single`),[l,u]=(0,J.useState)(()=>gn(e)),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(``),[g,y]=(0,J.useState)(pn),[b,S]=(0,J.useState)(``),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)({}),[D,O]=(0,J.useState)([]),[k,A]=(0,J.useState)(new Set),[ee,M]=(0,J.useState)([]),[N,F]=(0,J.useState)(``),[L,R]=(0,J.useState)(null),[z,te]=(0,J.useState)(!1),B=(0,J.useRef)(null),V=(0,J.useRef)(new Map),H=(0,J.useRef)(!1),U=(0,J.useRef)(!1),W=(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,...ee.filter(t=>!e.includes(t))]},[a.data,ee]);(0,J.useEffect)(()=>{if(t){S(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}U.current=!1,B.current?.abort();for(let e of V.current.values())e.abort();V.current.clear(),w(null),E({}),O([]),A(new Set),M([]),F(``),R(null)},[t,a.data]);let ne=(0,J.useCallback)(e=>({modelId:e,protocol:l,stream:f,prompt:m.trim()||null,maxOutputTokens:g??pn}),[l,f,m,g]),re=(0,J.useCallback)((t,n,r)=>On(e.id,t,ne(t),n,r),[e.id,ne]),G=()=>{let e=b.trim();if(!e)return;B.current?.abort();let t=new AbortController;B.current=t,U.current=!0,R(null),w({modelId:e,status:`running`,text:``,reasoning:``}),re(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&ie(),w(e)})},K=e=>{if(e.length===0)return;U.current=!0,H.current=!1,R(null),O(e),E(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(fn,e.length)},async()=>{for(;;){if(!U.current)return;let n=e[t++];if(n===void 0)return;if(H.current){E(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;V.current.set(n,r),await re(n,r.signal,e=>E(t=>({...t,[n]:e}))),V.current.delete(n),ie()}}))},ie=()=>void i.invalidateQueries({queryKey:[`requests`]}),ae=()=>{H.current=!0,E(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},oe=C?.status===`running`||D.some(e=>T[e]?.status===`running`||T[e]?.status===`queued`&&!H.current),se=D.filter(e=>T[e]&&T[e].status!==`queued`&&T[e].status!==`running`).length,ce=D.filter(e=>T[e]?.status===`success`).length,le=D.filter(e=>T[e]?.status===`failed`).length,ue=(e,t)=>A(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),de=()=>{oe||n(!1)},fe=e=>e.stopPropagation();return(0,X.jsx)(`span`,{onClick:fe,onKeyDown:fe,children:(0,X.jsxs)(ge,{open:t,onOpenChange:e=>e?n(!0):de(),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)(I,{disabled:oe,onClick:()=>n(!1),icon:(0,X.jsx)(x,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?oe?(0,X.jsx)(I,{variant:`primary`,icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onClick:()=>B.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(I,{variant:`primary`,disabled:b.trim()===``,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:G,children:r(C?`providers.testDialog.retest`:`providers.testDialog.start`)}):oe?(0,X.jsx)(I,{variant:`primary`,icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onClick:ae,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(I,{variant:`primary`,disabled:k.size===0,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:()=>K([...k]),children:r(`providers.testDialog.testN`,{count:k.size})})]}),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,X.jsx)(Ue,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,X.jsx)(_,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),R(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)(j,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(bn,{value:b,models:W,onChange:S})}),(0,X.jsx)(xn,{protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:y,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)(Sn,{run:C,onRetest:G})]}):L===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(En,{known:W,selected:k,onToggle:ue,onSelectAll:e=>A(e?new Set(W):new Set),onClear:()=>A(new Set),search:N,onSearch:F,onAdd:e=>{M(t=>t.includes(e)?t:[...t,e]),A(t=>new Set(t).add(e)),F(``)},configOpen:z,onConfigOpen:te,protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:y,prompt:m,onPrompt:h}),D.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:oe?r(`providers.testDialog.progress`,{done:se,total:D.length,ok:ce,failed:le}):r(`providers.testDialog.progressDone`,{total:D.length,ok:ce,failed:le})}),(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:`${se/D.length*100}%`,background:`var(--accent)`}})})]}):null,D.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Dn,{order:D,runs:T,onView:R})}):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)(I,{variant:`plain`,icon:(0,X.jsx)(we,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>R(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:L})]}),(0,X.jsx)(Sn,{run:T[L]??null})]})]})})}function bn({value:e,models:t,onChange:n}){let{t:r}=P(),[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)(S,{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)(D,{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:A(`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 xn({protocols:e,...t}){let{t:n}=P(),r=e.map(e=>({value:e,label:jn.find(t=>t.value===e)?.label??e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:n(`providers.testDialog.protocol`),children:(0,X.jsx)(xe,{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)(G,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,X.jsx)(j,{label:n(`providers.testDialog.maxTokens`),children:(0,X.jsx)(F,{value:t.maxTokens,min:1,placeholder:String(pn),label:n(`providers.testDialog.maxTokens`),onChange:e=>t.onMaxTokens(e===null?null:Math.min(mn,Math.max(1,Math.round(e))))})}),(0,X.jsx)(j,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(y,{rows:4,value:t.prompt,placeholder:`Reply with OK.`,onChange:e=>t.onPrompt(e.target.value)})})]})}function Sn({run:e,onRetest:t}){let{t:n}=P(),[r,i]=(0,J.useState)(`preview`),a=e?.text??``,o=e?.raw??``,s=Object.entries(e?.headers??{}),c=e?.ttftMs!=null&&e?.httpMs!=null?Math.max(0,e.ttftMs-e.httpMs):null,l=r===`raw`?o:r===`headers`?s.map(([e,t])=>`${e}: ${t}`).join(`
|
|
2
|
+
`):a;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:[t&&e&&e.status!==`running`?(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:t,children:n(`providers.testDialog.retest`)}):null,(0,X.jsx)(Be,{content:n(`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)(qe,{className:`size-4`})})}),(0,X.jsx)(Tn,{run:e}),e?.httpStatus?(0,X.jsxs)(N,{tone:`neutral`,children:[`HTTP `,e.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)(wn,{label:n(`providers.testDialog.metrics.http`),value:e?.httpMs}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.firstWait`),value:c}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.ttft`),value:e?.ttftMs}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.total`),value:e?.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:n(`providers.testDialog.reply`)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,X.jsx)(_,{items:[{value:`preview`,label:n(`providers.testDialog.preview`)},{value:`raw`,label:n(`providers.testDialog.raw`)},{value:`headers`,label:n(`providers.testDialog.headers`)}],value:r,onChange:i,ariaLabel:n(`providers.testDialog.reply`)}),(0,X.jsx)(W,{value:l,label:n(r===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,X.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:r===`headers`?s.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.headersEmpty`)}):(0,X.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,X.jsx)(`tbody`,{children:s.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))})}):r===`raw`?o?(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[n(`providers.testDialog.rawNote`),e?.contentType?` · ${e.contentType}`:``]}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:o}),e?.rawTruncated?(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:n(`providers.testDialog.rawTruncated`)}):null]}):(0,X.jsx)(Cn,{run:e}):e?.error?(0,X.jsx)(R,{tone:`danger`,title:n(`providers.testDialog.status.failed`),children:e.error}):a||e?.reasoning?(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[e?.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:n(`providers.testDialog.reasoning`)}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:e.reasoning})]}):null,a?(0,X.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:a}):null]}):e?.status===`success`?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.noText`)}):(0,X.jsx)(Cn,{run:e})})]})]})}function Cn({run:e}){let{t}=P();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(hn[e.status])}):(0,X.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,X.jsx)(He,{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 wn({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?`—`:m(t)})]})}function Tn({run:e}){let{t}=P(),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)(L,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(hn[n])]})}function En({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:i,search:a,onSearch:o,onAdd:s,configOpen:c,onConfigOpen:l,...u}){let{t:d}=P(),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)(O,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,X.jsx)(I,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(I,{icon:(0,X.jsx)(Ee,{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)(We,{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)(je,{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)(We,{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)(ge,{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)(xn,{...u})})})]})}function Dn({order:e,runs:t,onView:n}){let{t:r}=P();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)(Tn,{run:i??null})}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:m(i.ttftMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:m(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 On(e,t,n,r,i){let a={modelId:t,status:`running`,text:``,reasoning:``};i(a);let o=e=>{a={...a,...e},i(a)};try{await ne(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:o({httpStatus:_n(t.httpStatus),httpMs:_n(t.httpMs),contentType:vn(t.contentType),headers:kn(t.headers)});break;case`delta`:{let e=vn(t.text)??``;vn(t.kind)===`reasoning`?o({reasoning:a.reasoning+e}):o({text:a.text+e});break}case`done`:{let t=e.data;o({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:kn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?o({status:`cancelled`,error:null}):o({status:`failed`,error:e instanceof E?e.message:String(e)})}}function kn(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 An=re({AUTH_OPTIONS:()=>Mn,PROTOCOL_OPTIONS:()=>jn,ProvidersPage:()=>Nn}),jn=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],Mn=[{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 Nn(){let{t}=P(),n=Ie(),[r,i]=Pe(),a=e(),[o,s]=(0,J.useState)(r.get(`new`)===`1`),[c,l]=(0,J.useState)(!1);(0,J.useEffect)(()=>{r.get(`new`)===`1`&&(s(!0),r.delete(`new`),i(r,{replace:!0}))},[r,i]),ke(e=>{e===`new-provider`&&s(!0)});let u=ae(`7d`,`day`,`provider`),[d,f]=(0,J.useState)(null),p=(0,J.useMemo)(()=>{let e=Fn(Pn),t=new Map;for(let n of u.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}},[u.data]);return(0,X.jsxs)(Ve,{title:t(`nav.providers`),subtitle:a.data?t(`providers.count`,{count:a.data.length}):void 0,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>l(!0),children:t(`providers.import`)}),(0,X.jsx)(I,{variant:`primary`,icon:(0,X.jsx)(je,{className:`size-3.5`}),onClick:()=>s(!0),children:t(`providers.add`)})]}),children:[(0,X.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[a.isLoading&&(0,X.jsx)(te,{lines:4}),a.isError&&(0,X.jsx)(R,{tone:`danger`,title:t(`common.error`),children:q(a.error)}),a.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(b,{icon:(0,X.jsx)(Ne,{className:`size-6`}),title:t(`providers.empty`),detail:t(`providers.emptyDetail`),action:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,X.jsx)(I,{variant:`primary`,icon:(0,X.jsx)(je,{className:`size-3.5`}),onClick:()=>s(!0),children:t(`providers.add`)}),(0,X.jsx)(I,{icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>l(!0),children:t(`providers.import`)})]})})}),a.data&&a.data.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:a.data.map(e=>(0,X.jsx)(Rn,{p:e,days:p.days,usage:p.byProvider.get(e.name),onOpen:()=>n(`/providers/${e.id}`),onTest:()=>f(e)},e.id))})]}),(0,X.jsx)(Zt,{open:c,onOpenChange:l}),(0,X.jsx)(Gn,{open:o,onOpenChange:s,onCreated:e=>n(`/providers/${e.id}`)}),d&&(0,X.jsx)(yn,{provider:d,open:!0,onOpenChange:e=>!e&&f(null)})]})}var Pn=7;function Fn(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 In(e){if(!e)return null;try{return new URL(e).host}catch{return e}}var Ln=e=>e.stopPropagation();function Rn({p:e,days:n,usage:r,onOpen:i,onTest:a}){let{t:o}=P(),s=t(e.id),{toast:l}=ye(),u=[...new Set(e.endpoints.map(e=>e.protocol))],d=!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,f=[e.priceKey?o(`providers.priceKeyShort`,{key:e.priceKey}):null,e.priceMultiplier===1?null:`×${e.priceMultiplier}`].filter(Boolean).join(` · `),p=e.authScheme===`plugin`?o(`providers.card.plugin`):e.authScheme===`oauth-subscription`?o(`providers.card.subscription`):e.authScheme===`none`?o(`providers.card.noAuth`):e.hasApiKey?e.apiKeyMasked??`••••`:o(`providers.noKey`),m=e.enabled?d?{tone:`orange`,label:o(`providers.noKey`)}:{tone:`green`,label:o(`providers.card.active`)}:{tone:`neutral`,label:o(`providers.card.disabled`)},h=r?.requests??n.map(()=>0),_=h.reduce((e,t)=>e+t,0),v=e.templateUpdateAvailable?5:8;return(0,X.jsxs)(ht,{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:i,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())},style:{backgroundColor:`var(--surface)`},title:e.name,description:u.map(e=>jn.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:A(`transition-[filter,opacity]`,!e.enabled&&`opacity-50 grayscale`),children:(0,X.jsx)(Ue,{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)(L,{tone:m.tone}),m.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:In(e.endpoints[0]?.baseUrl)??`—`}),(0,X.jsx)(`span`,{className:`shrink-0`,children:o(`providers.modelCount`,{count:e.modelCount})})]})]}),meta:(0,X.jsx)(`span`,{className:A(e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:p}),status:f||void 0,action:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:Ln,children:[(0,X.jsx)(I,{variant:`plain`,size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),"aria-label":o(`providers.test`),title:o(`providers.test`),onClick:a}),(0,X.jsx)(`span`,{className:`ml-1 inline-flex`,children:(0,X.jsx)(G,{checked:e.enabled,label:o(`common.enabled`),onChange:e=>s.mutate({enabled:e},{onError:e=>l(q(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)(N,{tone:`accent`,children:o(`providers.templateUpdate`)}),e.boundClients.slice(0,v).map(e=>e in Le?(0,X.jsx)(`span`,{title:Fe(e),className:`inline-flex shrink-0`,children:(0,X.jsx)(Re,{kind:e,size:18})},e):(0,X.jsx)(N,{tone:`green`,children:e},e)),e.boundClients.length>v&&(0,X.jsxs)(`span`,{title:e.boundClients.slice(v).map(e=>Le[e]?.name??e).join(`, `),className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:[`+`,e.boundClients.length-v]})]}),(0,X.jsx)(`div`,{className:`min-h-[32px] [&>div]:mt-1`,onClick:Ln,children:(0,X.jsx)(dn,{provider:e})}),(0,X.jsx)(`div`,{className:`mt-2`,onClick:Ln,children:_>0?(0,X.jsx)(jt,{label:o(`providers.card.requests7d`),data:h,labels:n.map(e=>e.slice(5)),value:c(_,!0),change:g(r?.costUsd??0),width:320,height:28,formatValue:e=>c(e,!0)}):(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[13px] text-[var(--text-secondary)]`,children:o(`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:o(`providers.card.noRequests`)})]})})]})}var zn=`plugin:`,Bn=[`recommended`,`official`,`subscription`,`coding`,`cn`,`aggregator`,`inference`,`local`,`custom`],Vn={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Hn=e=>jn.find(t=>t.value===e)?.label??e,Un=e=>(0,X.jsx)(`span`,{title:e,children:e}),Wn=e=>{let t=/^(.+?)\s*[((]([^()()]+)[))]$/.exec(e);return t?[t[1],t[2]]:[e,null]};function Gn({open:t,onOpenChange:n,onCreated:r}){let{t:i}=P(),{toast:a}=ye(),c=s(),l=o(),u=h(),d=e(),f=(0,J.useMemo)(()=>new Set((d.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[d.data]),p=Ie(),[m,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[x,C]=(0,J.useState)(``),[w,T]=(0,J.useState)(``),[E,D]=(0,J.useState)(``),[k,A]=(0,J.useState)(``),[ee,M]=(0,J.useState)(``),[N,F]=(0,J.useState)(`openai-chat`),[L,z]=(0,J.useState)(`bearer`);(0,J.useEffect)(()=>{t||(v(null),b(null),g(``),C(``),T(``),D(``),A(``),M(``))},[t]);let B=(0,J.useMemo)(()=>{let e=m.trim().toLowerCase(),t=(c.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return Bn.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[c.data,m]),V=(0,J.useMemo)(()=>{let e=m.trim().toLowerCase();return(d.data??[]).filter(t=>t.authScheme===`plugin`&&!t.settings.plugin?.absent&&(!e||t.name.toLowerCase().includes(e)||t.id.includes(e)))},[d.data,m]),H=e=>{v(e),e===`custom`?(C(``),A(``),D(``)):(C(e.name),A(e.priceKey??e.id),D(``),z(e.auth.scheme))},U=()=>{let e=_===`custom`;u.mutate({templateId:e?null:_.id,variantId:E||null,name:x.trim()||null,apiKey:w.trim()||null,priceKey:k,...e?{endpoints:[{protocol:N,baseUrl:ee.trim()}],authScheme:L}:{}},{onSuccess:e=>{n(!1),a(i(`providers.created`,{name:e.name}),`success`),r(e)},onError:e=>a(q(e),`error`)})},W=_&&_!==`custom`?_:null,ne=()=>{if(y===`custom`)H(`custom`);else if(y?.startsWith(zn)){let e=V.find(e=>zn+e.id===y);e&&(n(!1),r(e))}else{let e=(c.data??[]).find(e=>e.id===y);e&&!f.has(e.id)&&H(e)}},re=_!==null&&(_===`custom`?/^https?:\/\//.test(ee.trim())&&x.trim()!==``:!W.requiresApiKey||w.trim()!==``);return(0,X.jsxs)(ge,{open:t,onOpenChange:n,width:640,title:i(_?`providers.addTitleDetails`:`providers.addTitle`),description:_?W?W.name:i(`providers.custom`):i(`providers.addDetail`),footer:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{className:`mr-auto`,variant:`plain`,onClick:()=>v(null),children:i(`common.back`)}),(0,X.jsx)(I,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!re,loading:u.isPending,onClick:U,children:i(`providers.create`)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!y,onClick:ne,children:i(`common.continue`)})]}),children:[(0,X.jsx)(Gt,{className:`mb-6`,label:i(`providers.addTitle`),current:+!!_,steps:[{id:`template`,label:i(`providers.step.template`)},{id:`details`,label:i(`providers.step.details`)}]}),_?(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(j,{label:i(`providers.name`),children:(0,X.jsx)(S,{value:x,onChange:e=>C(e.target.value)})}),W?.variants&&W.variants.length>0&&(0,X.jsx)(j,{label:i(`providers.variant`),children:(0,X.jsx)(xe,{value:E,onChange:e=>{D(e);let t=W.variants?.find(t=>t.id===e);A(t?.priceKey??W.priceKey??W.id)},options:[{value:``,label:i(`providers.variantDefault`)},...W.variants.map(e=>({value:e.id,label:e.name}))]})}),_===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:i(`providers.baseUrl`),hint:i(`providers.baseUrlHint`),children:(0,X.jsx)(S,{value:ee,onChange:e=>M(e.target.value),placeholder:`https://api.example.com/v1`,className:`font-mono`})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(j,{label:i(`providers.protocol`),children:(0,X.jsx)(xe,{value:N,onChange:F,options:jn})}),(0,X.jsx)(j,{label:i(`providers.authScheme`),children:(0,X.jsx)(xe,{value:L,onChange:z,options:Mn})})]})]}),W?.authScheme===`oauth-subscription`?(0,X.jsx)(R,{tone:`info`,title:i(`providers.subscriptionWizardHint`),children:i(`providers.subscriptionWizardDetail`)}):(0,X.jsxs)(`div`,{className:`font-mono`,children:[(0,X.jsx)(Me,{label:i(`providers.apiKey`),description:i(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:w,onChange:e=>T(e.target.value)}),W?.apiKeyUrl&&(0,X.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:W.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:i(`providers.getKey`)})]}),(0,X.jsx)(j,{label:i(`providers.priceKey`),hint:i(`providers.priceKeyHint`),children:(0,X.jsx)(xe,{value:k,onChange:A,options:[{value:``,label:i(`providers.priceKeyNone`)},...(l.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),W&&W.models.length>0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.templateModels`,{count:W.models.length})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(O,{value:m,onChange:g,placeholder:i(`providers.searchTemplates`)}),c.isLoading&&(0,X.jsx)(te,{lines:4}),c.isError&&(0,X.jsx)(R,{tone:`danger`,title:i(`common.error`),children:q(c.error)}),B.map(e=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.category.${e.category}`)}),(0,X.jsx)(De,{name:`provider-template`,"aria-label":i(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===y)?y:null,onValueChange:b,options:e.items.map(e=>{let t=[...new Set(e.endpoints.map(e=>e.protocol))],[n,r]=Wn(e.name);return{value:e.id,label:(0,X.jsx)(`span`,{title:e.name,children:n}),description:(0,X.jsx)(`span`,{title:t.map(Hn).join(` · `),children:r??t.map(e=>Vn[e]).join(` · `)}),icon:(0,X.jsx)(Ue,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:f.has(e.id),disabledReason:Un(i(`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:i(`providers.category.plugin`)}),V.length>0?(0,X.jsx)(De,{name:`provider-template-plugin`,"aria-label":i(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:y?.startsWith(zn)?y:null,onValueChange:b,options:V.map(e=>({value:zn+e.id,label:Un(e.name),description:Un(i(`providers.pluginProvided`)),icon:(0,X.jsx)(Ue,{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:i(`providers.pluginHint`)}),(0,X.jsx)(I,{size:`sm`,onClick:()=>{n(!1),p(`/plugins/market`)},children:i(`plugins.browseMarket`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.custom`)}),(0,X.jsx)(De,{name:`provider-template-custom`,"aria-label":i(`providers.custom`),layout:`list`,density:`compact`,value:y===`custom`?`custom`:null,onValueChange:b,options:[{value:`custom`,label:i(`providers.custom`),description:i(`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)(je,{className:`size-4`})})}]})]})]})]})}export{ln as a,yn as i,jn as n,Ye as o,An as r,Mn as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$n as e,Ai as t,At as n,Br as r,Di as i,E as a,Ei as o,Ft as s,Jr as c,Mt as l,Oi as u,Pt as d,Qt as f,Rr as p,Sa as m,Ti as h,Tn as g,Tr as _,U as v,V as y,Vr as b,Yr as x,Zt as ee,_ as S,_a as C,an as w,bi as T,br as E,d as D,di as te,ft as O,gi as k,hi as ne,hr as A,i as re,jt as ie,l as j,li as ae,m as M,n as N,ni as oe,nr as se,o as ce,oi as le,on as ue,ot as P,p as de,pi as fe,pt as F,qr as pe,qt as me,r as I,ri as he,s as ge,si as _e,t as ve,u as L,ui as ye,v as R,va as be,vi as xe,vt as z,xn as Se,xr as Ce,xt as B,y as V,ya as we,yi as H,zt as Te}from"./alert-CGUFPyGb.js";import{B as Ee,F as De,I as Oe,L as ke,R as Ae,a as U,gt as W,i as je,n as G,o as K,r as q,vt as J,z as Me}from"./overlays-B1a0OZYb.js";import{t as Ne}from"./TrayPanelView-CYoAUUiY.js";import{t as Pe}from"./download-5xAFYJ6Q.js";import{t as Fe}from"./ellipsis-Dxds5r72.js";import{t as Ie}from"./external-link-Bq_1v6I1.js";import{n as Le,t as Re}from"./radio-cards-Cr0tP9In.js";import{t as ze}from"./folder-open-BXsxEYtm.js";import{t as Be}from"./log-out-B9HHsF8m.js";import{t as Ve}from"./minus-BVd6Aw9t.js";import{t as He}from"./pencil-BAzRd1Ro.js";import{t as Ue}from"./rotate-ccw-D6r7Boub.js";import{C as We,E as Ge,I as Ke,L as qe,M as Je,T as Ye,X as Xe,Z as Ze,et as Qe,h as $e,n as et,s as tt,t as nt,w as rt,z as it}from"./index-mlmGhWY4.js";var at={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};at.node;var ot=z(at),st={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};st.node;var ct=z(st),lt={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};lt.node;var ut=z(lt),dt={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};dt.node;var ft=z(dt),pt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};pt.node;var mt=z(pt),ht={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};ht.node;var gt=z(ht),_t={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};_t.node;var vt=z(_t),Y=m(we(),1),X=be(),yt=`https://astra-gate.si/docs/guide/remote-access`,bt=`astra.remote.acknowledged`;function xt(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function St(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Ct(){try{return localStorage.getItem(bt)===`1`}catch{return!1}}function wt(){try{localStorage.setItem(bt,`1`)}catch{}}function Tt(){let{t:e}=P(),t=pe(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Et,{s:n}),(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(jt,{s:n}),(0,X.jsx)(ce,{title:n.cloudflared.path&&n.cloudflared.version?e(`settings.remote.logWithVersion`,{version:n.cloudflared.version}):e(`settings.remote.log`),children:n.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:e(`settings.remote.logEmpty`)}):(0,X.jsx)(`pre`,{className:`max-h-72 overflow-auto font-mono text-[10.5px] leading-relaxed whitespace-pre-wrap text-[var(--text-secondary)] selectable`,children:n.log.join(`
|
|
2
|
+
`)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(ve,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(t.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=P(),{toast:i,confirm:a}=K(),o=r(),s=d(),c=xt(e,t),l=async e=>{await W.copy(e)&&i(t(`common.copied`))},u=async e=>{if(e&&!Ct()){if(!await a({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;wt()}(e||!s.data?.remote||await a({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&o.mutate(e,{onError:e=>i(U(e),`error`)})},f=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,p=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,m=e.state===`connected`&&p!==null?p<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:v(p,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),h=e.cloudflared,g=h.downloading||h.path?null:h.asset?t(`settings.remote.cloudflaredMissing`,{version:h.version??``}):t(`settings.remote.cloudflaredUnsupported`),_=e.enabled?e.error??h.error??null:null,b=_!==null&&(e.state!==`connected`||/origin service|origin server/i.test(_)),x=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(M,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?y(e.connectedAt,n):void 0,children:[(0,X.jsx)(ge,{tone:f}),m,h.downloading&&h.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(h.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:o.isPending||!e.enabled&&c!==null,onChange:e=>void u(e)})}),!e.enabled&&c&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:c}),!e.enabled&&!c&&g&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:g}),e.enabled&&x&&(0,X.jsxs)(M,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${x}/v1`}),children:[(0,X.jsx)(G,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(F,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void l(`${x}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void l(x)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void l(`${x}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(x,`_blank`,`noopener`)})]}),e.enabled&&x&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),b&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(ve,{tone:e.state===`connected`?`warning`:`danger`,title:St(_,e,t),children:_})})]})}function Dt({s:e}){let{t}=P(),{toast:n,confirm:r}=K(),i=le(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await W.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(U(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(U(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(M,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(S,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void c(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(ve,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(M,{label:t(`settings.remote.origin`),detail:t(`settings.remote.originHint`),children:[(0,X.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.originUrl}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void s(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=P(),{toast:n,confirm:r}=K(),i=le(),a=d(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(U(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(M,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(N,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(M,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=P(),{toast:n}=K(),r=d(),i=E(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(U(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=P(),{toast:n}=K(),r=le(),i=ue(),a=d(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[m,h]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>h(e.download.downloadSource),[e.download.downloadSource]);let g=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(U(e),`error`)}),_=t=>{h(t),(t!==`custom`||e.download.downloadBaseUrl)&&g({downloadSource:t})},v=()=>i.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(U(e),`error`)}),y=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(M,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:y}),children:(0,X.jsx)(ge,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${m}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:_,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),m===`custom`&&(0,X.jsxs)(M,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>g({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(M,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>g({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{u(!0),v()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(D,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:v,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>g({cloudflaredPath:f.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=C(),i=Se(),a=d(),o=x(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),f=i.data;if(!f)return(0,X.jsx)(M,{label:e(`settings.listen`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=Pt(f.configuredHost),h=f.configuredHost!==f.host,g=!!a.data?.required,_=async n=>{await W.copy(n)&&t(e(`common.copied`))},v=n=>o.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(U(e),`error`)}),y=async t=>{if(t!==m){if(t===`lan`){if(!f.passwordSet){c(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}v(t)}},b=async()=>{u(!0);let n=await W.restartService();if(u(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},ee=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${H?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:e(`settings.listen`),detail:ee,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&H&&(0,X.jsx)(I,{size:`sm`,loading:l,onClick:()=>void b(),children:e(`settings.listen.restart`)}),(0,X.jsx)(S,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void y(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(M,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:f.passwordSet}),(0,X.jsx)(It,{open:s,onOpenChange:c,onSaved:()=>v(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=P(),{toast:i}=K(),a=E(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(U(e),`error`)})};return(0,X.jsx)(je,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(D,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(D,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Lt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Rt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},zt=e=>e===`feishu`||e===`dingtalk`,Bt=(e,t)=>e(`alerts.event.${t}`),Vt=(e,t)=>e(`alerts.event.${t}.hint`);function Ht(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Ut,{}),(0,X.jsx)(Wt,{}),(0,X.jsx)(Yt,{})]})}function Ut(){let{t:e,locale:t}=P(),n=l(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),n.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(M,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${y(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=te(),i=w(),a=p(),o=A(),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),m=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(U(e),`error`)}),h=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>f(e.secret??null),onError:e=>t(U(e),`error`)})},g=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(M,{icon:(0,X.jsx)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(N,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||zt(t.format))&&(0,X.jsx)(N,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(it,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Je,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void g(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:s,onClose:()=>c(null),onSecret:f}),(0,X.jsx)(qt,{hook:l,onClose:()=>u(null)}),(0,X.jsx)(Kt,{secret:d,onClose:()=>f(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=P(),{toast:i}=K(),a=ee(),o=_e(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(10),[p,m]=(0,Y.useState)(!0),[h,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(`generic`),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)([]),T=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),v(!t||t.hasSecret),b(t?.format??`generic`),S(``),w((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(T?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(U(e),`error`)},m=!T&&e!==null&&e.format!==y,g=zt(y)?_?x.trim()||void 0:``:void 0;T?a.mutate({...u,format:y,...y===`generic`?{signed:_}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:y}:{},...y===`generic`?_||!e.hasSecret||m?{}:{signed:!1}:g===void 0?{}:{secret:g}},{...f,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(D,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${y}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(D,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(j,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(D,{mono:!0,type:`password`,autoComplete:`off`,value:x,placeholder:e!==`new`&&e!==null&&e.format===y&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>S(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(de,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[C.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(D,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>w(C.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(D,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Je,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>w(C.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>w([...C,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(M,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(V,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:g})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(V,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?T||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(M,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=P(),{toast:r}=K();return(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await W.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=P(),{toast:i}=K(),a=ye(e?.id),o=se(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(N,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Bt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:y(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:y(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(re,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(re,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(U(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(t){let n=e(),r=b(),i=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),a=J({queries:i.map(e=>({queryKey:B.providerAccounts(e.id),queryFn:()=>fe(`GET`,`/api/providers/${ne(e.id)}/accounts`),enabled:t===`account`}))});return t===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):t===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):t===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Yt(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=ie(),i=te(),a=c(),o=f(),[s,l]=(0,Y.useState)(null),u=e=>i.data?.find(t=>t.id===e)?.name??e,d=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(M,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(N,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Bt(e,n.event)} → ${n.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(U(e),`error`)})}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Je,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Zt,{rule:s,onClose:()=>l(null)})]})}function Xt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Zt({rule:e,onClose:t}){let{t:r}=P(),{toast:i}=K(),a=n(),o=te(),s=me(),l=c(),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[ee,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(null),[E,O]=(0,Y.useState)(60),k=a.data?.find(e=>e.id===f),ne=Jt(k?.subjectType),A=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=a.data?.[0];d(t?.name??``),p(t?.event??n?.id??``),h(t?{...Xt(a.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(o.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),T(t?.repeatMinutes??null),O(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(A?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!u.trim()||!f,loading:s.isPending||l.isPending,onClick:()=>{let n=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:u.trim(),event:f,condition:n,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:ee,repeatMinutes:w&&w>0?Math.floor(w):null,cooldownMinutes:Math.max(0,Math.floor(E??0))},o={onSuccess:()=>{t(),i(r(`common.saved`),`success`)},onError:e=>i(U(e),`error`)};A?s.mutate(a,o):e&&l.mutate({id:e.id,...a},o)},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.rules.name`),children:(0,X.jsx)(D,{value:u,maxLength:64,onChange:e=>d(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.rules.event`),hint:f?Vt(r,f):void 0,children:(0,X.jsx)(q,{ariaLabel:r(`alerts.rules.event`),value:f,onChange:e=>{p(e),h(Xt(a.data?.find(t=>t.id===e))),y([])},options:(a.data??[]).map(e=>({value:e.id,label:Bt(r,e.id)}))})}),k?.params.map(e=>(0,X.jsx)(j,{label:r(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(de,{value:typeof m[e.name]==`number`?m[e.name]:null,min:0,label:r(`alerts.param.${e.name}`),onChange:t=>h({...m,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:r(`alerts.param.${e.name}`),value:String(m[e.name]??``),onChange:t=>h({...m,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:r(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(D,{mono:!0,value:String(m[e.name]??``),"aria-label":r(`alerts.param.${e.name}`),placeholder:r(`alerts.param.${e.name}.placeholder`),onChange:t=>h({...m,[e.name]:t.target.value})})},e.name)),k&&(0,X.jsx)(j,{label:`${r(`alerts.rules.subjects`)} · ${r(`alerts.subject.${k.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(S,{ariaLabel:r(`alerts.rules.subjects`),value:g,onChange:_,items:[{value:`all`,label:r(`alerts.rules.subjectsAll`)},{value:`only`,label:r(`alerts.rules.subjectsOnly`)}]}),g===`only`&&(0,X.jsx)(tt,{label:r(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...ne,...v.filter(e=>!ne.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(j,{label:r(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.rules.noWebhooks`)}):(0,X.jsx)(tt,{label:r(`alerts.rules.webhooks`),value:b,onValueChange:x,options:(o.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.rules.repeat`),hint:r(`alerts.rules.repeatHint`),children:(0,X.jsx)(de,{value:w,min:1,step:1,label:r(`alerts.rules.repeat`),onChange:T})}),(0,X.jsx)(j,{label:r(`alerts.rules.cooldown`),hint:r(`alerts.rules.cooldownHint`),children:(0,X.jsx)(de,{value:E,min:0,step:1,label:r(`alerts.rules.cooldown`),onChange:O})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(M,{label:r(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:ee,label:r(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function Qt(){let{t:e}=P(),t=s(),n=xe()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&T;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=P(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(M,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(U(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=P(),{toast:t}=K(),n=s(),r=Ce(),i=n.data;if(!i)return(0,X.jsx)(M,{label:e(`settings.startup.service`),detail:n.isError?U(n.error):void 0,children:n.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let a=!i.supported||i.mechanism===`none`?e(`settings.startup.unsupported.${i.unsupported??`platform`}`):i.canChange?i.enabled&&i.location?e(`settings.startup.entry`,{location:i.location}):e(`settings.startup.service.${i.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(M,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(V,{checked:i.enabled,disabled:!i.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(U(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=a,nn=[...a.ease.enter],rn=[...a.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=Qe(e,e=>`${n(e)*1.05}em`),i=Qe(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=Qe(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=Qe(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(h.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function Dn({digit:e,direction:t,instant:n}){let r=i(),a=u(e),s=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let i=s.current;if(i.digit===e)return;let c=t>0?(e-i.digit+10)%10:-((i.digit-e+10)%10);Math.abs(c)>5&&(c-=Math.sign(c)*10),i.target+=c,i.digit=e,n||r?a.jump(i.target):o(a,i.target,Q.snappy)},[e,t,n,a,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),an.map(e=>(0,X.jsx)(En,{position:a,digit:e},e))]})}function On({value:e,format:n,direction:r,instant:a}){let o=i(),s=a?Tn:o?wn:Sn;return(0,X.jsx)(t,{initial:!1,custom:r,children:xn(e,n).map(e=>(0,X.jsx)(h.span,{className:`digit`in e?Z.column:Z.symbol,custom:r,variants:s,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(Dn,{digit:e.digit,direction:r,instant:a}):e.text},e.key))})}function kn({text:e,direction:n,className:r}){let a=i();return(0,X.jsx)(`span`,{className:r,children:(0,X.jsx)(t,{initial:!1,custom:n,children:[...e].map((e,t)=>(0,X.jsx)(h.span,{className:Z.char,custom:n,variants:a?wn:Sn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${t}:${e}`))})})}var An=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},jn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=An(n[t]),i=An(e);return r!==null&&i!==null&&i<r?-1:1})},Mn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:nn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{duration:.14,ease:rn}})},Nn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Pn({word:e,direction:n}){let r=i(),a=(0,Y.useRef)(null),s=u(`auto`),c=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!c.current||r?s.jump(e.offsetWidth):o(s,e.offsetWidth,Q.morph),c.current=!0});return t.observe(e),()=>t.disconnect()},[r,s]),(0,X.jsxs)(h.span,{className:Z.wordSlot,style:{width:s},children:[(0,X.jsx)(`span`,{ref:a,className:Z.wordSizer,children:e}),(0,X.jsx)(t,{initial:!1,mode:`popLayout`,custom:n,children:(0,X.jsx)(h.span,{className:Z.word,custom:n,variants:r?Nn:Mn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Fn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:jn(t.text,e)});let r=t.text===e?t.directions:jn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Pn,{word:e,direction:r[t]??1})]},t))})]})}function In({id:e,text:n,className:r}){return(0,X.jsx)(t,{initial:!1,children:n?(0,X.jsx)(Ln,{id:e,text:n,className:r},`message`):null})}function Ln({id:e,text:t,className:n}){let r=i(),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>s(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(h.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:o,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(h.span,{ref:a,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${tn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:nn},children:(0,X.jsx)(Fn,{text:t})})})}function Rn({id:e,edge:n,text:r}){let a=i();return(0,X.jsx)(t,{initial:!1,children:n!==0&&(0,X.jsx)(h.span,{id:e,className:Z.limit,initial:a?{opacity:0}:{opacity:0,y:`${n*.45}em`,filter:`blur(${tn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:a?$.instant:$.standard,ease:rn}},transition:a?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:r},`limit`)})}function zn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?qe:Ve;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:a=0,max:s=2**53-1,step:c=1,largeStep:l,description:d,disabled:f,id:p,prefix:m,suffix:g,scrub:_=!1,locale:v=`en-US`,formatOptions:y,size:b=`md`,limitHint:x=!0}){let ee=i(),S=(0,Y.useId)(),C=p??S,w=d?`${C}-description`:void 0,T=`${C}-limit`,E=c>0?c:1,[D,te]=(0,Y.useState)(n),O=t??D,[k,ne]=(0,Y.useState)(``),[A,re]=(0,Y.useState)(!1),[ie,j]=(0,Y.useState)(0),[ae,M]=(0,Y.useState)(!1),[N,oe]=(0,Y.useState)(``),[se,ce]=(0,Y.useState)(0),[le,ue]=(0,Y.useState)(!1),P=(0,Y.useRef)(null),de=(0,Y.useRef)(null),fe=(0,Y.useRef)(null),F=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(void 0),me=(0,Y.useRef)(void 0),I=(0,Y.useRef)({edge:0,count:0,at:0}),he=(0,Y.useRef)(null),ge=(0,Y.useRef)(null),_e=(0,Y.useRef)(O),ve=(0,Y.useRef)(O),L=(0,Y.useRef)(void 0),ye=(0,Y.useRef)(null),R=(0,Y.useRef)(!1),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),z=(0,Y.useRef)(()=>!1),Se=u(0),Ce=u(0),B=u(0),V=Qe(()=>Ce.get()+B.get()),we=Number.isFinite(a)?a:0,H=Math.max(_n(E),_n(we)),Te=y?.minimumFractionDigits??H,Ee=Math.max(Te,y?.maximumFractionDigits??H),De=y?.useGrouping??!0,Oe=(0,Y.useMemo)(()=>new Intl.NumberFormat(v,{minimumFractionDigits:Te,maximumFractionDigits:Ee,useGrouping:De,numberingSystem:`latn`}),[v,Te,Ee,De]),ke=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(v).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[v]),Ae=e=>Number(e.toFixed(H))||0,U=e=>Math.min(s,Math.max(a,e)),W=e=>Ae(we+Math.round((e-we)/E)*E),je=(e,t)=>{let n=(e-we)/E;return Ae(we+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*E)},G=e=>`${yn(m,e)}${Oe.format(e)}${yn(g,e)}`.trim();function K(e){let t=e.split(ke.group).join(``).replace(ke.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let q=A?K(k):null,J=q??O,[Me,Ne]=(0,Y.useState)({value:J,direction:1});Me.value!==J&&Ne({value:J,direction:J>Me.value?1:-1});let Pe=Me.value===J?Me.direction:J>Me.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(L.current),window.clearTimeout(F.current),window.clearTimeout(pe.current),window.clearTimeout(me.current)},[]);function Fe(e,t){let n=performance.now(),r=I.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let i=P.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(me.current),me.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!ee){o(Se,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?fe:de).current;n&&(t===`button`||t===`key`)&&o(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}x&&(ce(e),window.clearTimeout(F.current),F.current=window.setTimeout(()=>ce(0),un))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=U(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),oe(`${G(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==_e.current&&oe(G(i)),i!==_e.current&&(_e.current=i,t===void 0&&te(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(je(_e.current,e*t),n);(0,Y.useLayoutEffect)(()=>{_e.current=O,z.current=Le});function Re(){let e=ge.current;e&&be.current===null&&(be.current=e.getBoundingClientRect().left-Ce.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=be.current,t=ge.current;if(be.current=null,xe.current){xe.current=!1;let e=he.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-Ce.get()-B.get());Math.abs(n)<.5||(B.set(B.get()+n),ee?B.jump(0):o(B,0,Q.morph))});function ze(){window.clearTimeout(pe.current),ue(!1)}function Be(){if(!A)return;Re(),re(!1),ze();let e=K(k);e!==null&&Ie(W(e),`type`)}function Ve(){window.clearTimeout(L.current),L.current=void 0,j(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/E));n===`button`&&j(e);let i=0,a=()=>{let t=z.current(e,r,n);L.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};L.current=window.setTimeout(a,Le(e,r,n)?sn:360)}function Ue(e){let t=l??E*10,n={ArrowUp:[1,e.shiftKey?t:E],ArrowDown:[-1,e.shiftKey?t:E],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!A&&(e.key===`Home`&&Number.isFinite(a)||e.key===`End`&&s<2**53-1)){e.preventDefault(),Ie(e.key===`Home`?a:s,`key`);return}e.key===`Enter`&&(e.preventDefault(),A?(xe.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&A&&(e.preventDefault(),Re(),re(!1),ze(),xe.current=!0,Ie(ve.current,`type`))}function We(e){let t=RegExp(`[^0-9${vn(ke.group)}${H||Ee?vn(ke.decimal):``}${a<0?`\\-`:``}]`,`g`),n=e.replace(t,``);A||(ve.current=O),Re(),ne(n),re(!0);let r=K(n);r!==null&&r>=a&&r<=s&&W(r)===r&&Ie(r,`type`),ze(),r!==null&&r<a&&(pe.current=window.setTimeout(()=>ue(!0),dn))}function Ge(e){R.current=!1,_&&!f&&e.button===0&&(Be(),ye.current={pointer:e.pointerId,x:e.clientX,from:_e.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=ye.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,M(!0)}let r=n/on,i=Math.trunc(r);Ie(i?je(t.from,i):t.from,`scrub`);let o=t.from+r*E,c=o>s?(o-s)/E*on:o<a?(o-a)/E*on:0;Ce.set(ee?0:bn(c))}function qe(e){let t=ye.current;t&&t.pointer===e.pointerId&&(ye.current=null,t.active&&(R.current=!0,M(!1),o(Ce,0,ee?{duration:0}:Q.snappy),oe(G(_e.current))))}let Je=t=>({toward:t,label:e,disabled:f,controls:C,limit:t>0?J>=s:J<=a,pressed:ie===t}),Ye=q===null?0:q>s?1:q<a&&le?-1:0,Xe=x?Ye||se:0,Ze=Xe>0?s:a,$e=Xe?typeof x==`function`?x(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${G(Ze)}`:``,et=[w,Ye&&x?T:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":b,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:C,className:Z.label,"data-scrub":_&&!f||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{R.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:T,edge:Xe,text:$e})]}),(0,X.jsxs)(`div`,{ref:P,className:Z.control,"data-scrubbing":ae||void 0,"data-disabled":f||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Je(-1),iconRef:de,onPress:()=>He(-1,E,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==he.current&&e.preventDefault()},onClick:e=>{!f&&e.target!==he.current&&(he.current?.focus(),he.current?.select())},children:(0,X.jsxs)(h.span,{ref:ge,className:Z.value,style:{x:V,y:Se},children:[(0,X.jsx)(kn,{text:yn(m,J),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":A||void 0,"aria-hidden":`true`,children:(0,X.jsx)(On,{value:J,format:Oe,direction:Pe,instant:A})}),A&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:k}),(0,X.jsx)(`input`,{ref:he,id:C,className:Z.input,type:`text`,role:`spinbutton`,inputMode:a<0?`text`:H||Ee?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:A?k:Oe.format(O),disabled:f,"aria-describedby":et,"aria-invalid":Ye?!0:void 0,"aria-valuenow":O,"aria-valuetext":G(O),"aria-valuemin":Number.isFinite(a)?a:void 0,"aria-valuemax":s<2**53-1?s:void 0,onChange:e=>We(e.currentTarget.value),onKeyDown:Ue,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ve()},onBlur:()=>{Ve(),Be()}})]}),(0,X.jsx)(kn,{text:yn(g,J),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Je(1),iconRef:fe,onPress:()=>He(1,E,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(In,{id:w,text:d,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:N})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=P(),t=C(),[n,r]=Ae(),i=Me(),a=De(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(M,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(V,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(Ee(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Un,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Re,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:k.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Un,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Vn.map(o)})}),(0,X.jsx)(Un,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>r(Oe),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Ne,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Un({title:e,hint:t,children:n}){let{t:r}=P();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Wn=[`general`,`notifications`,`remote`,`tray`],Gn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Kn(){let{t:e}=P(),{tab:t}=Ze(),n=Xe(),r=ke(),i=Wn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)($e,{title:e(`nav.settings`),children:(0,X.jsxs)(We,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ye,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Ge,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(gt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Ge,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ct,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Ge,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(O,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Ge,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(rt,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(rt,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(rt,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(rt,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:e,locale:t,setLocale:n}=P(),r=et(),i=_(),a=oe(),o=C(),s=ae(),c=d(),l=g(),u=pe(),{toast:f,confirm:p}=K(),m=i.data,h=u.data?.state===`connected`&&u.data.publicUrl?`${u.data.publicUrl}/v1`:null,v=e=>a.mutate(e,{onError:e=>f(U(e),`error`)}),y=e=>{n(e),v({locale:e})},b=async t=>{await W.copy(t)&&f(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(M,{label:e(`settings.theme`),children:(0,X.jsx)(S,{ariaLabel:e(`settings.theme`),value:r.theme,onChange:r.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(M,{label:e(`settings.accent`),detail:r.accentChoice===`system`?r.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:r.accentChoice,onChange:r.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...nt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(M,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(S,{ariaLabel:e(`settings.language`),value:t,onChange:y,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),m?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(M,{label:e(`settings.gatewayUrl`),detail:`${m.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(`${m.gatewayBaseUrl}/v1`)})}),h&&(0,X.jsx)(M,{label:e(`settings.remote.publicUrl`),detail:h,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(h)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(M,{label:e(`settings.dataDir`),detail:m.dataDir,children:W.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void W.openPath(m.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(m.dataDir)})}),(0,X.jsx)(M,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:m.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await p({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&v({requireGatewayKey:t})}})}),(0,X.jsx)(M,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:e(`settings.streamIdle`),value:m.streamIdleTimeoutSec,onCommit:e=>v({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(M,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:m.requestCompression,onChange:e=>v({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(Yn,{settings:m}),(0,X.jsx)(Xn,{settings:m}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(M,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.autoInterval`),value:m.quotaAutoIntervalMinutes,onCommit:e=>a.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void o.invalidateQueries({queryKey:B.providers}),onError:e=>f(U(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(M,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.subscriptionInterval`),value:m.subscriptionQuotaIntervalMinutes,onCommit:e=>v({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(M,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:m.usageTimeZone??``,onChange:e=>v({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:m.effectiveUsageTimeZone})},...[...new Set([...Gn,...m.usageTimeZone?[m.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(M,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:m.debugBodies,label:e(`settings.debugBodies`),onChange:e=>v({debugBodies:e})})}),(0,X.jsx)(M,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:e(`settings.bodyRetention`),value:m.bodyRetentionDays,onCommit:e=>v({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(M,{label:e(`settings.requestRetention`),detail:m.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:m.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>v({requestRetentionDays:e?90:null})}),m.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:e(`settings.requestRetention`),value:m.requestRetentionDays,onCommit:e=>v({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(M,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Zn,{label:e(`settings.effort.${t}`),value:m.effortBudgets[t],onCommit:e=>v({effortBudgets:{...m.effortBudgets,[t]:e??m.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):i.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(i.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(M,{label:e(`settings.serverVersion`),detail:s.data?`${s.data.version} · API ${s.data.apiVersion}`:`—`}),H&&(0,X.jsx)(M,{label:e(`settings.desktopVersion`),detail:xe()?.version||`—`}),(0,X.jsx)(Jn,{}),H&&(0,X.jsx)(M,{label:e(`settings.logs`),onClick:()=>void W.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),c.data?.required&&(0,X.jsx)(M,{label:e(`settings.logout`),onClick:()=>l.mutate(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=P(),{toast:t}=K(),n=C(),r=oe(),i=he(),a=Te(),o=i.data,s=xe()?.updates??null,[c,l]=(0,Y.useState)(!1),u=()=>a.mutate(void 0,{onSuccess:n=>t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(U(e),`error`)}),d=()=>{s&&!c&&(l(!0),s.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:B.version}),n.invalidateQueries({queryKey:B.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:`settings.upToDate`))}).catch(e=>t(U(e),`error`)).finally(()=>l(!1)))},f=o?.lastCheckAt?new Date(o.lastCheckAt).toLocaleString():void 0,p=o?.available?s?e(`settings.updateAvailable`,{version:o.available}):`${e(`settings.updateAvailable`,{version:o.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:e(`settings.autoCheck`),detail:o&&!o.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:o?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(U(e),`error`)})})}),(0,X.jsxs)(M,{label:e(`settings.checkUpdates`),detail:a.isError?e(`settings.updateCheckFailed`,{error:U(a.error)}):o?.available?p:f?e(`settings.lastChecked`,{time:f}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:a.isPending,onClick:u,children:a.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Ke,{className:`size-3.5`})}),s&&o?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:c,"aria-label":e(`settings.updateApply`),onClick:d,children:c?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=P(),{toast:n}=K(),r=oe(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(U(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(U(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(M,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(S,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:c,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),i===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(D,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=P(),{toast:n}=K(),r=oe(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(U(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(M,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(D,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Bn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Kn as SettingsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$n as e,J as t,K as n,Sa as r,Tr as i,V as a,Vr as o,Xt as s,Y as c,Z as l,Zn as u,_ as d,_r as f,ai as p,c as m,d as h,in as g,l as _,mr as v,n as y,ot as b,p as x,pt as S,q as C,qr as w,r as T,t as E,v as D,va as O,ya as k}from"./alert-CGUFPyGb.js";import{a as A,gt as j,i as M,n as N,o as P,r as F}from"./overlays-B1a0OZYb.js";import{t as I}from"./ellipsis-Dxds5r72.js";import{t as L}from"./pencil-BAzRd1Ro.js";import{t as ee}from"./power-DrpargJA.js";import{t as te}from"./rotate-ccw-D6r7Boub.js";import{B as ne,L as R,M as z,_ as B,h as V,s as H,y as U,z as re}from"./index-mlmGhWY4.js";var W=r(k(),1),G=O();function K(){let{t:e}=b(),t=o(),n=i(),r=w(),a=r.data?.state===`connected`?r.data.publicUrl:null,[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(null);return(0,G.jsxs)(V,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,G.jsx)(T,{variant:`primary`,icon:(0,G.jsx)(R,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`tokens.add`)}),children:[(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,G.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,G.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),a&&(0,G.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,G.jsx)(D,{lines:4}),t.isError&&(0,G.jsx)(E,{tone:`danger`,title:e(`common.error`),children:A(t.error)}),t.data?.length===0&&(0,G.jsx)(`div`,{className:`card`,children:(0,G.jsx)(m,{icon:(0,G.jsx)(re,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,G.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,G.jsx)(q,{token:e,defaultOpen:t.data.length===1,onEdit:()=>u(e)},e.id))})]}),(0,G.jsx)(ae,{open:s,onOpenChange:c}),(0,G.jsx)(oe,{token:l,onClose:()=>u(null)})]})}function q({token:n,defaultOpen:r,onEdit:i}){let{t:o,locale:s}=b(),{toast:c,confirm:u}=P(),d=e(),m=f(),h=p(),_=v(),x=g(),[w,E]=(0,W.useState)(r),D=(d.data??[]).find(e=>e.id===n.providerId),O=`token-detail-${n.id}`,k=(e,t)=>{c(t,`success`),e.skipped.length>0&&c(o(`tokens.skipped`,{clients:e.skipped.map(e=>B[e]?.name??e).join(`, `)}),`error`)},M=()=>m.mutate(n.id,{onSuccess:async({token:e})=>{await j.copy(e)&&c(o(`tokens.copied`))},onError:e=>c(A(e),`error`)}),F=async()=>{(!n.enabled||await u({title:o(`tokens.disableConfirm`,{name:n.name}),detail:o(`tokens.disableDetail`),confirmLabel:o(`tokens.disable`),destructive:!0}))&&h.mutate({id:n.id,enabled:!n.enabled},{onError:e=>c(A(e),`error`)})},R=async()=>{await u({title:o(`tokens.resetConfirm`,{name:n.name}),detail:o(`tokens.resetDetail`),confirmLabel:o(`tokens.reset`),destructive:!0})&&_.mutate(n.id,{onSuccess:e=>k(e,o(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>c(A(e),`error`)})},V=async()=>{await u({title:o(`tokens.deleteConfirm`,{name:n.name}),detail:o(`tokens.deleteDetail`),confirmLabel:o(`common.delete`),destructive:!0})&&x.mutate(n.id,{onSuccess:e=>k(e,o(`tokens.deleted`,{name:n.name})),onError:e=>c(A(e),`error`)})},H=n.lastUsedAt?a(n.lastUsedAt,s):o(`tokens.neverUsed`);return(0,G.jsxs)(`article`,{children:[(0,G.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>E(e=>!e),children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":w,"aria-controls":O,"aria-label":o(`tokens.details`),onClick:e=>{e.stopPropagation(),E(e=>!e)},children:(0,G.jsx)(ne,{className:`size-4 transition-transform ${w?`rotate-90`:``}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${n.enabled?``:`text-[var(--text-muted)]`}`,children:n.name}),n.isDefault&&(0,G.jsx)(y,{tone:`accent`,children:o(`tokens.default`)}),!n.enabled&&(0,G.jsx)(y,{tone:`orange`,children:o(`tokens.disabledBadge`)}),n.limitUsage.some(e=>e.exhausted)&&(0,G.jsx)(y,{tone:`orange`,children:o(`tokens.limitExhausted`)})]}),(0,G.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:n.keyMasked}),(0,G.jsx)(T,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(S,{className:`size-3.5`}),"aria-label":o(`tokens.copy`),title:o(`tokens.copy`),loading:m.isPending,onClick:M})]})]})]}),(0,G.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:n.clients.map(e=>B[e]?.name??e).join(`, `)||o(`tokens.noClients`),children:n.clients.length===0?(0,G.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):n.clients.map(e=>(0,G.jsx)(U,{kind:e,size:16},e))}),(0,G.jsx)(X,{label:o(`tokens.today`),value:l(n.today.costUsd),context:o(`tokens.requestsContext`,{count:t(n.today.requests)})}),(0,G.jsx)(X,{label:o(`tokens.total`),value:l(n.total.costUsd),context:`${t(n.total.totalTokens,!0)} Token`}),(0,G.jsx)(X,{label:o(`tokens.lastUsedTitle`),value:n.lastUsedAt?C(n.lastUsedAt,s):`—`,context:n.lastUsedAt?``:o(`tokens.neverUsed`),title:H}),(0,G.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,G.jsx)(N,{label:o(`common.more`),icon:(0,G.jsx)(I,{className:`size-4`}),items:[{id:`settings`,label:o(`tokens.settings`),icon:(0,G.jsx)(L,{className:`size-3.5`}),onSelect:i},{id:`toggle`,label:n.enabled?o(`tokens.disable`):o(`tokens.enable`),icon:(0,G.jsx)(ee,{className:`size-3.5`}),onSelect:()=>void F()},{id:`reset`,label:o(`tokens.reset`),icon:(0,G.jsx)(te,{className:`size-3.5`}),onSelect:()=>void R()},...n.isDefault?[]:[{id:`delete`,label:o(`tokens.delete`),icon:(0,G.jsx)(z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void V()}]]})})]}),w&&(0,G.jsxs)(`div`,{id:O,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,G.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.clients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:n.clients.length===0?o(`tokens.noClients`):n.clients.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(U,{kind:e,size:14}),B[e]?.name??e]},e))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.directProvider`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:D?.name??(n.providerId?n.providerId:o(`tokens.directNone`))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.allowedClients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:n.allowedClients==null?o(`tokens.allowedClientsAny`):n.allowedClients.length===0?o(`tokens.directOnly`):n.allowedClients.map(e=>B[e]?.name??e).join(`, `)})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.lastUsedTitle`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:H})]})]}),(0,G.jsx)(J,{token:n}),(0,G.jsx)(ie,{today:n.today,total:n.total})]})]})}function J({token:e}){let{t}=b(),n=e.limits?.rpm;return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,G.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,G.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,G.jsx)(Y,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,G.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,G.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function Y({usage:e}){let{t:n,locale:r}=b(),i=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,o=n=>e.metric===`cost`?l(n):t(n,!0),s=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,G.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,G.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(e.used),limit:o(e.limit)})})]}),(0,G.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,G.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:a(e.resetsAt,r)})})]})}function X({label:e,value:t,context:n,title:r}){return(0,G.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,G.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function ie({today:e,total:r}){let{t:i}=b(),a=[[i(`tokens.today`),e],[i(`tokens.total`),r]],o=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,s=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,G.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,G.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,G.jsx)(`th`,{className:`${o} text-left`}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.cost`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.requests`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.tokens`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.inOut`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.cacheHit`)}),(0,G.jsx)(`th`,{className:o,title:i(`tokens.tpsContext`),children:i(`tokens.tps`)})]})}),(0,G.jsx)(`tbody`,{children:a.map(([e,r])=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,G.jsx)(`td`,{className:`${s} font-semibold selectable`,children:l(r.costUsd)}),(0,G.jsx)(`td`,{className:s,children:t(r.requests)}),(0,G.jsx)(`td`,{className:s,children:t(r.totalTokens,!0)}),(0,G.jsxs)(`td`,{className:`${s} text-[var(--text-secondary)]`,children:[t(r.inputTokens,!0),` / `,t(r.outputTokens,!0)]}),(0,G.jsx)(`td`,{className:s,title:i(`usage.cacheAmounts`,{read:t(r.cacheReadTokens,!0),write:t(r.cacheWriteTokens,!0)}),children:r.cacheHitRate==null?`—`:n(r.cacheHitRate)}),(0,G.jsx)(`td`,{className:s,children:r.tps==null?`—`:c(r.tps)})]},e))})]})})}function Z(){let{t}=b(),n=(e().data??[]).filter(e=>e.enabled);return{providers:n,options:[{value:``,label:t(`tokens.directNone`)},...n.map(e=>({value:e.id,label:e.name}))]}}function ae({open:e,onOpenChange:t}){let{t:n}=b(),{toast:r}=P(),i=s(),{options:a}=Z(),[o,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``);return(0,W.useEffect)(()=>{e&&(c(``),u(``))},[e]),(0,G.jsx)(M,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,G.jsx)(T,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:l||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(A(e),`error`)}),children:n(`common.create`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(_,{label:n(`tokens.name`),children:(0,G.jsx)(h,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>c(e.target.value)})}),(0,G.jsx)(_,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:l,onChange:u,options:a})})]})})}function oe({token:e,onClose:t}){let{t:n}=b(),{toast:r}=P(),i=p(),{providers:a,options:o}=Z(),[s,c]=(0,W.useState)(``),[l,f]=(0,W.useState)(``),[m,g]=(0,W.useState)(``),[v,y]=(0,W.useState)([]),[S,C]=(0,W.useState)(null),[w,E]=(0,W.useState)(`any`),[D,O]=(0,W.useState)([]),k=a.find(e=>e.id===l),j=k?.authScheme===`oauth-subscription`||k?.authScheme===`plugin`,N=u(k?.id,j),I=new Set(v.map(e=>`${e.metric}:${e.period}`)).size<v.length;return(0,W.useEffect)(()=>{e&&(c(e.name),f(e.providerId??``),g(e.accountId??``),y(e.limits?.budgets.map(e=>({...e}))??[]),C(e.limits?.rpm??null),E(e.allowedClients==null?`any`:`only`),O(e.allowedClients??[]))},[e]),(0,G.jsx)(M,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{onClick:t,children:n(`common.cancel`)}),(0,G.jsx)(T,{variant:`primary`,disabled:!s.trim()||I,loading:i.isPending,onClick:()=>{if(!e)return;let a=v.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),o=a.length>0||S!=null&&S>0?{budgets:a,rpm:S!=null&&S>0?Math.floor(S):null}:null;i.mutate({id:e.id,name:s.trim(),providerId:l||null,accountId:j&&m||null,limits:o,allowedClients:w===`any`?null:D},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(A(e),`error`)})},children:n(`common.save`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(_,{label:n(`tokens.name`),children:(0,G.jsx)(h,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,G.jsx)(_,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:l,onChange:e=>{f(e),g(``)},options:o})}),j&&(0,G.jsx)(_,{label:n(`tokens.directAccount`),children:(0,G.jsx)(F,{value:m,onChange:g,options:[{value:``,label:n(`clients.accountDefault`)},...(N.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]})}),(0,G.jsx)(_,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:I?n(`tokens.limitDuplicate`):void 0,children:(0,G.jsx)(se,{budgets:v,onChange:y})}),(0,G.jsx)(_,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,G.jsx)(x,{value:S,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:C})}),(0,G.jsx)(_,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:w,onChange:E,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),w===`only`&&(0,G.jsx)(H,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(B),...D])].map(e=>({value:e,label:B[e]?.name??e})),value:D,onValueChange:e=>O(e)})]})})]})})}var Q=[`cost`,`requests`,`tokens`],$=[`day`,`week`,`month`,`total`];function se({budgets:e,onChange:t}){let{t:n}=b(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=Q.flatMap(e=>$.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,G.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:Q.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,G.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:$.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,G.jsx)(x,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,G.jsx)(T,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(z,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,G.jsx)(`div`,{children:(0,G.jsx)(T,{size:`sm`,icon:(0,G.jsx)(R,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{K as TokensPage};
|