@aidotnet/server-linux-arm64 0.8.0 → 0.9.0
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-CT5PiqS3.js +11 -0
- package/bin/wwwroot/assets/KeyPage-DOVrI-UN.js +1 -0
- package/bin/wwwroot/assets/ModelDetailPage-Yu2oJf3R.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-QefK7LU5.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-Dl53KvHU.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-DmSrQ2Mk.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-BfK0We2G.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-dKrtvirQ.js +2 -0
- package/bin/wwwroot/assets/SettingsPage-4R3aVJB1.js +2 -0
- package/bin/wwwroot/assets/TokensPage-C1s3mguI.js +1 -0
- package/bin/wwwroot/assets/TrayPanelPage-INGZ1PbI.js +1 -0
- package/bin/wwwroot/assets/TrayPanelView-CQQDnzsO.js +1 -0
- package/bin/wwwroot/assets/alert-D4IPjxz3.js +15 -0
- package/bin/wwwroot/assets/{overlays-Cnf3vGpI.css → alert-DwSJjne8.css} +1 -1
- package/bin/wwwroot/assets/arrow-down-DLYI19GC.js +1 -0
- package/bin/wwwroot/assets/arrow-left-BEIa7s0v.js +1 -0
- package/bin/wwwroot/assets/checkbox-DJG4To3W.js +1 -0
- package/bin/wwwroot/assets/cloud-download-Dx8D0gGR.js +1 -0
- package/bin/wwwroot/assets/confirm-morph-BpM-aHP9.js +1 -0
- package/bin/wwwroot/assets/download-CKu95INa.js +1 -0
- package/bin/wwwroot/assets/ellipsis-D-uqKDgA.js +1 -0
- package/bin/wwwroot/assets/external-link-tQTMyil6.js +1 -0
- package/bin/wwwroot/assets/folder-open-CL6HwOra.js +1 -0
- package/bin/wwwroot/assets/index-CdtIrMPt.js +17 -0
- package/bin/wwwroot/assets/index-nu-lKbLD.css +1 -0
- package/bin/wwwroot/assets/log-out-CZYk_IyX.js +1 -0
- package/bin/wwwroot/assets/overlays-BJrN5PWt.css +1 -0
- package/bin/wwwroot/assets/overlays-BX48Gd4h.js +41 -0
- package/bin/wwwroot/assets/paseo-B9ieOk6E.png +0 -0
- package/bin/wwwroot/assets/pencil-CUO0GAyP.js +1 -0
- package/bin/wwwroot/assets/power-USlcjghz.js +1 -0
- package/bin/wwwroot/assets/radio-cards-CGtNS_WO.js +1 -0
- package/bin/wwwroot/assets/rotate-ccw-Daii8PQN.js +1 -0
- package/bin/wwwroot/index.html +6 -8
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-B89Sa7jz.js +0 -11
- package/bin/wwwroot/assets/ModelDetailPage-CIr2VLVH.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-DHoSwTY5.js +0 -1
- package/bin/wwwroot/assets/Page-CnSErb_N.js +0 -3
- package/bin/wwwroot/assets/Page-CsiaycmK.css +0 -1
- package/bin/wwwroot/assets/PluginsPage-54tF_bjG.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-D5paxuYA.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-DhxcWbc_.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-DfMcnoYT.js +0 -2
- package/bin/wwwroot/assets/SettingsPage-a1XhJ-l9.js +0 -1
- package/bin/wwwroot/assets/TokensPage-T2w5pi_o.js +0 -1
- package/bin/wwwroot/assets/TrayPanelPage-DOmKXJLy.js +0 -1
- package/bin/wwwroot/assets/TrayPanelView-BcmaqvCD.js +0 -1
- package/bin/wwwroot/assets/arrow-down-CXkFrvO0.js +0 -1
- package/bin/wwwroot/assets/arrow-up-BfREUNOR.js +0 -1
- package/bin/wwwroot/assets/checkbox-RGYPqY5w.js +0 -1
- package/bin/wwwroot/assets/cloud-download-D865MmmV.js +0 -1
- package/bin/wwwroot/assets/confirm-morph-DUNuG_Io.js +0 -1
- package/bin/wwwroot/assets/download-CMr38kbd.js +0 -1
- package/bin/wwwroot/assets/ellipsis-zTWIrsa4.js +0 -1
- package/bin/wwwroot/assets/external-link-BSHuW87X.js +0 -1
- package/bin/wwwroot/assets/folder-open-Ce_7X0wN.js +0 -1
- package/bin/wwwroot/assets/index-PfVyiY3J.js +0 -15
- package/bin/wwwroot/assets/index-uU60OHOr.css +0 -1
- package/bin/wwwroot/assets/log-out-CXVs8bJY.js +0 -1
- package/bin/wwwroot/assets/overlays-D1ZtG8Qn.js +0 -55
- package/bin/wwwroot/assets/pencil-DyidL-8l.js +0 -1
- package/bin/wwwroot/assets/power-CJZylS33.js +0 -1
- package/bin/wwwroot/assets/radio-cards-QHFaDooy.js +0 -1
- package/bin/wwwroot/assets/rotate-ccw-Dr0Xbikv.js +0 -1
- package/bin/wwwroot/assets/use-transform-DvOb1h9g.js +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{$n as e,$t as t,B as n,Cr as r,Dn as i,En as a,Er as o,Fn as s,Hr as c,In as l,Jn as u,Kn as d,Mn as f,Mt as p,On as m,Ot as h,Pn as g,Rn as _,Sr as v,St as y,Tr as ee,Tt as te,Ur as ne,Ut as re,V as b,Vn as ie,Wr as x,Wt as S,_ as ae,_t as C,a as w,an as oe,at as T,b as E,bt as se,c as ce,ca as le,d as D,da as ue,dn as O,dt as de,en as fe,er as pe,et as me,f as k,fn as he,ft as ge,h as _e,i as ve,kr as ye,l as A,m as j,n as M,oa as be,p as xe,pn as Se,qn as Ce,qr as we,r as N,rr as Te,rt as P,sa as F,sn as Ee,sr as De,st as I,t as L,ti as R,tn as Oe,tt as ke,u as z,v as B,vn as Ae,vr as je,wn as Me,wt as Ne,xt as Pe,y as V,yn as Fe}from"./alert-D4IPjxz3.js";import{a as H,i as U,n as Ie,o as W,r as G}from"./overlays-BX48Gd4h.js";import{t as Le}from"./arrow-down-DLYI19GC.js";import{t as K}from"./arrow-left-BEIa7s0v.js";import{t as Re}from"./cloud-download-Dx8D0gGR.js";import{t as ze}from"./download-CKu95INa.js";import{t as q}from"./ellipsis-D-uqKDgA.js";import{t as J}from"./external-link-tQTMyil6.js";import{n as Be}from"./radio-cards-CGtNS_WO.js";import{t as Ve}from"./log-out-CZYk_IyX.js";import{t as He}from"./power-USlcjghz.js";import{t as Ue}from"./rotate-ccw-Daii8PQN.js";import{B as We,D as Y,G as Ge,M as Ke,P as qe,W as Je,a as Ye,b as Xe,f as Ze,o as Qe,s as $e,u as X,v as et,x as tt,y as nt,z as Z}from"./index-CdtIrMPt.js";import{t as rt}from"./checkbox-DJG4To3W.js";import{t as it}from"./confirm-morph-BpM-aHP9.js";import{AUTH_OPTIONS as at,PROTOCOL_OPTIONS as ot,n as st,r as ct,t as lt}from"./ProvidersPage-dKrtvirQ.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=C(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=C(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=C(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=C(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=C(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=C(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=C(St),Q=ue(le(),1),$=F(),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}=T(),{toast:o}=W(),s=O(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)(U,{open:!1,onOpenChange:i,title:``});let h=n===`apiKey`,g=h?t.formats.filter(e=>e.endsWith(`-api-key`)):t.formats,_=!h&&t.formats.some(e=>e.includes(`refresh-token`)||e.endsWith(`-json`)),v=a(h?`providers.accounts.import.apiKeyLabel`:`providers.accounts.import.label`),y=e=>s.mutate({text:c,asApiKey:h||void 0,dryRun:e||void 0,httpProxy:u.trim()||void 0},{onSuccess:t=>{p({...t,dryRun:e}),!e&&(o(a(`providers.accounts.import.summary`,{ok:t.imported,dup:t.duplicates,fail:t.failed}),t.failed>0?`info`:`success`),!(t.failed>0)&&(n===`batch`?l(``):i()))},onError:e=>o(H(e),`error`)});return(0,$.jsx)(U,{open:!0,onOpenChange:e=>!e&&i(),title:a(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)(E,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(D,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:u,onChange:e=>d(e.target.value)}),_&&(0,$.jsx)(L,{tone:`info`,title:a(`providers.accounts.import.rotateWarning`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.import.count`,{n:m})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[n===`batch`&&(0,$.jsx)(N,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>y(!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:()=>y(!1),children:a(`providers.accounts.import.run`)})]})]}),f&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[12px] font-medium`,children:a(f.dryRun?`providers.accounts.import.previewSummary`:`providers.accounts.import.summary`,{ok:f.imported,dup:f.duplicates,fail:f.failed})}),(0,$.jsx)(`ul`,{className:`card max-h-72 divide-y divide-[var(--border)] overflow-auto`,children:f.items.map(e=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`w-6 shrink-0 text-[var(--text-muted)]`,children:e.index}),(0,$.jsx)(`span`,{className:`selectable w-28 shrink-0 truncate font-mono`,children:e.source}),(0,$.jsx)(M,{tone: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}=T(),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)(He,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:c(`providers.subscription.moveUp`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:c(`providers.subscription.moveDown`),icon:(0,$.jsx)(Le,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:c(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:u===`dead`,onSelect:()=>n.refreshQuota(e)},...f?[]:[{id:`refresh`,label:c(`providers.subscription.refreshToken`),icon:(0,$.jsx)(Ue,{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:P(`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:P(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rt,{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)(de,{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)(Ie,{iconOnly:!0,label:c(`common.more`),icon:(0,$.jsx)(q,{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}=T(),i=[];return e?.session?.usedPercent!=null&&i.push({key:`session`,label:e.session.windowMinutes?`${Math.round(e.session.windowMinutes/60)}h`:n(`providers.accounts.quotaShortSession`),percent:e.session.usedPercent,reset:e.session.resetsAtUtc}),e?.weekly?.usedPercent!=null&&i.push({key:`weekly`,label:n(`providers.accounts.quotaShortWeekly`),percent:e.weekly.usedPercent,reset:e.weekly.resetsAtUtc}),i.length<2&&e?.credits?.usedPercent!=null&&i.push({key:`credits`,label:n(e.entitlement==null?`providers.accounts.quotaShortCredits`:`providers.accounts.quotaShortPremium`),percent:e.credits.usedPercent,reset:e.credits.resetsAtUtc}),i.length===0?null:(0,$.jsx)(`div`,{className:P(`mt-auto flex flex-col gap-2 pt-2`,t&&`opacity-60`),children:i.slice(0,2).map(e=>{let t=Math.max(0,Math.min(100,Math.round(e.percent))),i=t>=90?`var(--danger)`:t>=70?`var(--warning)`:`var(--accent)`,a=Math.round(t/100*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}=T(),i=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:n(`providers.subscription.quotaResets`,{when:t.toLocaleString(r)})},a=[];e.session?.usedPercent!=null&&a.push({key:`session`,label:n(`providers.subscription.quotaWindowSession`),window:e.session}),e.weekly?.usedPercent!=null&&a.push({key:`weekly`,label:n(`providers.subscription.quotaWindowWeekly`),window:e.weekly}),e.credits?.usedPercent!=null&&a.push({key:`credits`,label:e.entitlement==null?n(`providers.subscription.quotaWindowCredits`):n(`providers.subscription.quotaWindowPremium`),window:{usedPercent:e.credits.usedPercent,resetsAtUtc:e.credits.resetsAtUtc??null}});let o=e.credits?.prepaidBalance==null?null:n(`providers.subscription.quotaBalance`,{balance:e.credits.prepaidBalance}),s=e.entitlement!=null&&e.entitlement>=0?[n(`providers.subscription.quotaPremiumCount`,{used:Math.max(0,(e.entitlement??0)-(e.remaining??0)),total:e.entitlement}),e.overageUsed?n(`providers.subscription.quotaOverage`,{count:e.overageUsed}):null,e.overagePermitted===!1?n(`providers.subscription.quotaOverageOff`):null].filter(Boolean).join(` · `):null,c=e.planLabel??(e.fetchedAtUtc?n(`providers.subscription.quotaFetchedAt`,{when:new Date(e.fetchedAtUtc).toLocaleString(r)}):null);return(0,$.jsx)(`div`,{className:P(`px-4 py-1`,t),children:(0,$.jsxs)(`div`,{className:`card flex flex-col gap-3 p-3`,children:[(c||o)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] text-[var(--text-secondary)]`,children:[c&&(0,$.jsx)(`span`,{children:c}),o&&(0,$.jsx)(`span`,{children:o})]}),a.length===0?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.subscription.quotaNoWindows`)}):a.map(e=>(0,$.jsx)(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}=T(),{toast:r,confirm:i}=W(),a=De(e.id,e.status===`active`),o=S(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 R&&e.status===409?H(e):`${n(`providers.subscription.credits.consumeFailed`)}:${H(e)}`,`error`)})};return(0,$.jsxs)(z,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(B,{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)(j,{className:P(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)(M,{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}=T(),{toast:s}=W(),c=ne(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)(U,{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(H(e),`error`)});return(0,$.jsx)(U,{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)(ct,{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)(Ue,{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)(L,{tone:`danger`,title:t.lastError}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:a(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(D,{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)(D,{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)(k,{label:a(`providers.accounts.detail.status`),children:(0,$.jsx)(M,{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)(k,{label:a(`providers.accounts.detail.source`),children:a(`providers.accounts.source.${t.source}`)}),m?(0,$.jsx)(k,{label:a(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:a(`providers.accounts.detail.expires`),children:_(t.expiresAtUtc)}),(0,$.jsx)(k,{label:a(`providers.accounts.detail.lastRefresh`),children:_(t.lastRefreshAtUtc)})]}),p===`cooling`&&(0,$.jsx)(k,{label:a(`providers.accounts.filter.cooling`),children:_(t.cooldownUntilUtc)}),(0,$.jsx)(k,{label:a(`providers.accounts.detail.order`),children:a(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(k,{label:a(`providers.accounts.detail.created`),children:_(t.createdAt)}),t.lastError&&p!==`dead`&&(0,$.jsx)(k,{label:a(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function Ut({provider:e}){let{t}=T(),{toast:n}=W(),r=e.authScheme===`oauth-subscription`,i=o(e.id,r),a=we(e.id);if(!r||!i.data)return null;let s=i.data,c=e=>a.mutate(e,{onError:e=>n(H(e),`error`)}),l=s.claudeSubscription||s.clientPolicy===`claude-code-only`;return!l&&!s.claudeSubscription?null:(0,$.jsxs)(z,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[l&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:s.clientPolicy===`claude-code-only`,disabled:a.isPending,onChange:e=>c({clientPolicy:e?`claude-code-only`:`any`})})}),s.claudeSubscription&&(0,$.jsx)(j,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.mimic`),checked:s.mimicClaudeCode,disabled:a.isPending,onChange:e=>c({mimicClaudeCode:e})})}),l&&s.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:s.mimicClaudeCode?(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(L,{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:t}){let{t:n}=T(),{toast:i,confirm:a}=W(),s=be(),c=t.authScheme===`oauth-subscription`,l=Ce(t.id,c),u=o(t.id,c),d=we(t.id),f=Ne(t.id,c),p=r(t.id),m=_(t.id),h=re(t.id),g=Ee(t.id),v=e(t.id),y=fe(t.id),ee=te(t.id),b=ne(t.id),ie=Te(t.id),x=t.templateId===`openai-subscription`,S=Ae(c&&x),ae=he(t.id),C=t.templateId===`github-copilot-subscription`,w=Fe(c&&C),oe=Se(t.id),[E,ce]=(0,Q.useState)(`all`),[le,ue]=(0,Q.useState)(``),[O,de]=(0,Q.useState)(new Set),[pe,me]=(0,Q.useState)(null),[k,ge]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(``),[M,xe]=(0,Q.useState)(!1),[F,De]=(0,Q.useState)(!1),[I,Oe]=(0,Q.useState)(null),[ke,z]=(0,Q.useState)(null),[je,Me]=(0,Q.useState)(!1),[Pe,V]=(0,Q.useState)(``),G=(0,Q.useRef)(new Set),Le=(0,Q.useRef)(new Set),K=(0,Q.useMemo)(()=>l.data??[],[l.data]);if((0,Q.useEffect)(()=>{if(c)for(let e of K){if(e.status!==`active`||Le.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<Gt||(Le.current.add(e.id),g.mutate(e.id,{onError:()=>{}}))}},[K,c]),(0,Q.useEffect)(()=>{let e=new Set(K.map(e=>e.id));de(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),pe&&!e.has(pe)&&me(null)},[K,pe]),(0,Q.useEffect)(()=>{if(!F||I?.mode!==`pkce`)return;let e=setInterval(()=>void l.refetch(),3e3);return()=>clearInterval(e)},[F,I,l]),(0,Q.useEffect)(()=>{if(!F||I?.mode!==`pkce`)return;let e=K.find(e=>!G.current.has(e.id));e&&q(!0,e.displayName||e.accountEmail||e.id)},[K,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 m.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 R&&(n.status===404||n.status===400)){q(!1,void 0,H(n));return}++t>=5&&q(!1,void 0,H(n))}},r=setInterval(()=>void n(),Math.max(I.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[F,I]),!c)return null;let Re=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,q=(e,r,a)=>{if(s.invalidateQueries({queryKey:se.providerAccounts(t.id)}),e){Oe(null),z(null),De(!1),i(n(`providers.subscription.loginOk`,{name:r??``}),`success`);return}a&&z(a)},J=(e,t)=>{G.current=new Set(K.map(e=>e.id)),z(null),p.mutate({accountId:e,httpProxy:t},{onSuccess:e=>{ye(!1),Oe(e),De(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof R&&e.details?.needsVerification?i(n(`providers.subscription.needsVerification`),`error`):i(H(e),`error`)}})},Be=async()=>{if(I){Me(!0);try{let e=await m.mutateAsync(I.state);e.status===`done`?q(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?i(n(`providers.subscription.stillWaiting`),`info`):q(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof R&&e.status===404){let t=((await l.refetch()).data??[]).find(e=>!G.current.has(e.id));t?q(!0,t.displayName||t.accountEmail||t.id):q(!1,void 0,H(e))}else q(!1,void 0,H(e))}finally{Me(!1)}}},Ve=async()=>{if(I&&I.mode===`paste`&&Pe.trim().length!==0){Me(!0);try{let e=await h.mutateAsync({state:I.state,code:Pe.trim()});e.status===`done`?(V(``),q(!0,e.account.displayName||e.account.accountEmail||e.account.id)):q(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){q(!1,void 0,H(e))}finally{Me(!1)}}},Ue=()=>ae.mutate(void 0,{onSuccess:e=>{i(n(`providers.subscription.importOk`,{name:Re(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`),S.refetch()},onError:e=>i(H(e),`error`)}),We=()=>oe.mutate(``,{onSuccess:e=>{i(n(`providers.subscription.importOk`,{name:Re(e.account)}),e.warning?`info`:`success`),e.warning&&i(e.warning,`error`)},onError:e=>i(H(e),`error`)}),Ge=(e,t)=>{let n=K.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],ie.mutate(n,{onError:e=>i(H(e),`error`)}))},Je=async e=>{let t=Re(e);await a({title:n(`providers.subscription.logoutConfirm`,{name:t}),destructive:!0,confirmLabel:n(`providers.subscription.logout`)})&&y.mutate(e.id,{onError:e=>i(H(e),`error`)})},Ye={open:e=>me(e.id),activate:e=>ee.mutate(e.id,{onSuccess:()=>i(n(`providers.subscription.activated`,{name:Re(e)}),`success`),onError:e=>i(H(e),`error`)}),toggleEnabled:e=>b.mutate({id:e.id,enabled:!e.enabled},{onError:e=>i(H(e),`error`)}),refreshQuota:e=>g.mutate(e.id,{onError:e=>{e instanceof R&&e.status===501?i(n(`providers.subscription.quotaUnsupported`),`error`):i(H(e),`error`)}}),refreshToken:e=>v.mutate(e.id,{onSuccess:()=>i(n(`providers.subscription.tokenRefreshed`),`success`),onError:e=>i(H(e),`error`)}),relogin:e=>J(e.id),remove:e=>void Je(e)},Xe=e=>de(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Ze=async e=>{let r=K.filter(e=>O.has(e.id));xe(!0);let a=0;for(let t of r)try{await e(t),a++}catch(e){i(`${Re(t)}: ${H(e)}`,`error`)}xe(!1),de(new Set),s.invalidateQueries({queryKey:se.providerAccounts(t.id)}),a>0&&i(n(`providers.accounts.bulkDone`,{n:a}),`success`)},Qe=async()=>{await a({title:n(`providers.accounts.bulkDeleteConfirm`,{n:O.size}),detail:n(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:n(`common.delete`)})&&await Ze(e=>y.mutateAsync(e.id))},$e=K.map(e=>At(e)),X=e=>e===`all`?K.length:$e.filter(t=>t===e).length,et=le.trim().toLowerCase(),tt=K.map((e,t)=>({a:e,index:t,state:$e[t]})).filter(({a:e,state:t})=>(E===`all`||t===E)&&(et.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes(et)))),nt=K.find(e=>e.id===pe)??null,Z=f.data,rt=O.size>0,it=[{id:`login`,label:n(`providers.accounts.addLogin`),icon:(0,$.jsx)(_t,{className:`size-3.5`}),onSelect:()=>J()},{id:`login-proxy`,label:n(`providers.accounts.addLoginProxy`),onSelect:()=>ye(!0)},...x&&S.data?.available?[{id:`codex`,separatorBefore:!0,label:n(`providers.subscription.importCodex`),icon:(0,$.jsx)(ze,{className:`size-3.5`}),onSelect:Ue}]:[],...C?[{id:`copilot`,separatorBefore:!0,label:n(`providers.subscription.importCopilot`),icon:(0,$.jsx)(ze,{className:`size-3.5`}),onSelect:We}]:[],...Z?.supported?[{id:`token`,separatorBefore:!(x&&S.data?.available)&&!C,label:n(`providers.accounts.addToken`),onSelect:()=>ge(`token`)}]:[],...Z?.apiKey?[{id:`apikey`,label:n(`providers.accounts.addApiKey`),icon:(0,$.jsx)(qe,{className:`size-3.5`}),onSelect:()=>ge(`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:n(`providers.accounts.statTotal`,{n:K.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:n(`providers.accounts.statUsable`,{n:X(`usable`)})}),X(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:n(`providers.accounts.statCooling`,{n:X(`cooling`)})}),X(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:n(`providers.accounts.statDead`,{n:X(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`providers.accounts.providerProxy`,{proxy:t.httpProxy||n(`providers.accounts.proxyFallbackSystem`)})})]}),u.data&&(0,$.jsx)(qt,{policy:u.data,onChange:e=>d.mutate({switchMode:e},{onError:e=>i(H(e),`error`)})})]}),u.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:n(u.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:u.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)(_e,{className:`w-52`,value:le,onChange:ue,placeholder:n(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":n(`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":E===e.value,onClick:()=>ce(e.value),className:P(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,E===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[n(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:()=>ge(`batch`),children:n(`providers.accounts.batchImport`)}),(0,$.jsx)(Ie,{label:n(`providers.accounts.add`),icon:(0,$.jsx)(Ke,{className:`size-3.5`}),items:it})]}),x&&S.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[n(`providers.subscription.localCodexFound`,{who:S.data.accountEmail??S.data.plan??n(`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:[w.data?.available?n(`providers.subscription.localCopilotFound`,{source:w.data.source??``}):n(`providers.subscription.localCopilotHint`),w.data?.detail?` · ${w.data.detail}`:``]}),l.isLoading?(0,$.jsx)(B,{className:`my-4`}):K.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>J(),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:n(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(Ke,{className:`size-3.5`}),` `,n(`providers.subscription.login`)]})]}):tt.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:tt.map(({a:e,index:t})=>(0,$.jsx)(Pt,{account:e,index:t,actions:Ye,selected:O.has(e.id),selecting:rt,onToggleSelect:Xe,quotaPending:g.isPending&&g.variables===e.id,onMove:K.length>1?{up:t>0?()=>Ge(t,-1):void 0,down:t<K.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:n(`providers.subscription.footer`)}),rt&&(0,$.jsxs)(`div`,{className:`card sticky bottom-3 z-10 mt-3 flex flex-wrap items-center gap-1.5 px-3 py-1.5 shadow-lg`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[12px] text-[var(--text-secondary)]`,children:n(`providers.accounts.selected`,{n:O.size})}),(0,$.jsx)(N,{size:`sm`,icon:(0,$.jsx)(He,{className:`size-3.5`}),disabled:M,onClick:()=>void Ze(e=>b.mutateAsync({id:e.id,enabled:!0})),children:n(`providers.subscription.enable`)}),(0,$.jsx)(N,{size:`sm`,disabled:M,onClick:()=>void Ze(e=>b.mutateAsync({id:e.id,enabled:!1})),children:n(`providers.subscription.disable`)}),(0,$.jsx)(N,{size:`sm`,disabled:M,onClick:()=>void Ze(e=>g.mutateAsync(e.id)),children:n(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(N,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),disabled:M,onClick:()=>void Qe(),children:n(`common.delete`)}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,onClick:()=>de(new Set),children:n(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(Ut,{provider:t})}),(0,$.jsx)(Ht,{provider:t,account:nt,index:nt?K.indexOf(nt):0,actions:Ye,onClose:()=>me(null)}),Z&&(0,$.jsx)(kt,{providerId:t.id,info:Z,mode:k,providerProxy:t.httpProxy,onClose:()=>ge(null)}),(0,$.jsx)(U,{open:ve,onOpenChange:ye,title:n(`providers.accounts.loginProxyTitle`),description:n(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(N,{variant:`primary`,loading:p.isPending,disabled:A.trim().length===0,onClick:()=>J(void 0,A),children:n(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(D,{mono:!0,label:n(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:A,onChange:e=>j(e.target.value)})}),(0,$.jsxs)(U,{open:F,onOpenChange:e=>{De(e),e||(Oe(null),z(null))},title:n(`providers.subscription.login`),description:n(`providers.subscription.loginDesc`),children:[ke&&(0,$.jsx)(L,{tone:`danger`,title:n(`providers.subscription.loginFailed`),children:ke}),I?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:n(`providers.subscription.pasteTitle`),children:n(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:n(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(D,{mono:!0,value:Pe,onChange:e=>V(e.target.value),placeholder:n(`providers.subscription.pastePlaceholder`),"aria-label":n(`providers.subscription.pasteCode`)}),(0,$.jsx)(N,{variant:`primary`,loading:je,onClick:()=>void Ve(),children:n(`providers.subscription.pasteSubmit`)})]}),I?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:n(`providers.subscription.waiting`),children:n(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:n(`providers.subscription.openAuthorize`)}),(0,$.jsx)(N,{variant:`primary`,onClick:()=>{s.invalidateQueries({queryKey:se.providerAccounts(t.id)}),l.refetch()},children:n(`providers.subscription.doneAuthorize`)})]})]}),I?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:n(`providers.subscription.waiting`),children:n(`providers.subscription.cliDetail`)}),(0,$.jsx)(N,{onClick:()=>window.open(I.authorizeUrl,`_blank`,`noopener`),children:n(`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:n(`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:n(`providers.subscription.visitPage`)}),(0,$.jsx)(N,{variant:`primary`,loading:je,onClick:()=>void Be(),children:n(`providers.subscription.checkNow`)})]}),(0,$.jsx)(L,{tone:`info`,title:n(`providers.subscription.waiting`),children:n(`providers.subscription.checkNowHint`)})]})]})]})}function qt({policy:e,onChange:t}){let{t:n}=T();return(0,$.jsx)(ae,{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}=T(),n=Ce(e.id),r=f(e.id),i=o(e.id,!0),a=we(e.id),{toast:s}=W(),[c,l]=(0,Q.useState)(null);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r.isLoading&&(0,$.jsx)(B,{lines:1}),r.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:H(r.error)}),r.data?.map(e=>(0,$.jsx)(N,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(qe,{className:`size-3.5`}):(0,$.jsx)(_t,{className:`size-3.5`}),onClick:()=>l(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(B,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ce,{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=>s(H(e),`error`)})})]}),n.data&&n.data.length>0&&(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(t=>(0,$.jsx)(Xt,{provider:e,account:t},t.id))}),(0,$.jsx)(Yt,{provider:e}),c&&(0,$.jsx)(Zt,{provider:e,method:c,onClose:()=>l(null)})]})}function Yt({provider:e}){let{t,locale:n}=T(),{toast:r}=W(),a=i(e.id),o=m(e.id);if(!a.data?.supported)return null;let s=e=>o.mutate(e,{onError:e=>r(H(e),`error`)}),c={claimed:`green`,done:`green`,ineligible:`neutral`,inactive:`neutral`,captcha:`orange`,failed:`red`};return(0,$.jsxs)(`section`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`pluginAccounts.checkin`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`pluginAccounts.checkinDetail`)})]}),(0,$.jsx)(V,{checked:a.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>s(e)}),(0,$.jsx)(N,{size:`sm`,loading:o.isPending,onClick:()=>s(),children:t(`pluginAccounts.checkinNow`)})]}),a.data.accounts.map(e=>{let r=[e.credit?t(`pluginAccounts.credit`,{credit:e.credit}):null,e.streak?t(`pluginAccounts.streak`,{days:e.streak}):null,e.message,e.at?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)(M,{tone:c[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(M,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function Xt({provider:e,account:t}){let{t:n,locale:r}=T(),{toast:i,confirm:a}=W(),o=s(e.id),[c,u]=(0,Q.useState)(!1),d=e.settings?.plugin?.usage===!0,f=l(e.id,t.id,c),p=async()=>{await a({title:n(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:n(`pluginAccounts.signOut`),destructive:!0})&&o.mutate(t.id,{onError:e=>i(H(e),`error`)})};return(0,$.jsxs)(`article`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-medium`,children:t.displayName}),t.isCurrent&&(0,$.jsx)(M,{tone:`accent`,children:n(`pluginAccounts.current`)}),(0,$.jsx)(M,{tone:t.status===`active`?`green`:`red`,children:n(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),d&&(0,$.jsx)(N,{size:`sm`,onClick:()=>u(e=>!e),children:n(`pluginAccounts.usage`)}),(0,$.jsx)(N,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(Ve,{className:`size-3.5`}),onClick:()=>void p(),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:[f.isLoading&&(0,$.jsx)(B,{lines:2}),f.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:H(f.error)}),f.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:f.data.error}),f.data?.plan&&(0,$.jsx)(k,{label:n(`pluginAccounts.plan`),children:f.data.plan}),f.data?.until&&(0,$.jsx)(k,{label:n(`pluginAccounts.until`),children:b(f.data.until,r)}),f.data?.windows?.map(e=>(0,$.jsxs)(k,{label:e.name,children:[e.display??(e.limit?`${e.amount??e.used??0} / ${e.limit} ${e.unit??``}`:`${e.used??0}%`),e.resetsAt?` · ${n(`pluginAccounts.resets`,{at:b(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),r)})}`:``]},e.name))]})]})}function Zt({provider:e,method:t,onClose:n}){let{t:r}=T(),{toast:i}=W(),[o,s]=(0,Q.useState)({}),[c,l]=(0,Q.useState)(void 0),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(``),[_,te]=(0,Q.useState)(``),[ne,re]=(0,Q.useState)(null),b=v(e.id),ie=a(e.id),x=ee(e.id),S=g(e.id,ne).data;(0,Q.useEffect)(()=>{let n=!0;return Pe(e.id,t.index,o).then(e=>{n&&(l(e.prompt),d(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&i(H(e),`error`)),()=>{n=!1}},[e.id,t.index,o,i]),(0,Q.useEffect)(()=>{S?.state===`done`&&(i(r(`pluginAccounts.signedIn`),`success`),n())},[S?.state,n,r,i]);let ae=async()=>{if(!c)return;let n=await y(e.id,t.index,c.key,u).catch(()=>({error:null}));if(n.error)return p(n.error);p(null),s(e=>({...e,[c.key]:u}))};return(0,$.jsxs)(U,{open:!0,onOpenChange:e=>!e&&n(),title:r(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[c===void 0&&(0,$.jsx)(B,{lines:2}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:c.message,error:f??void 0,children:c.type===`select`?(0,$.jsx)(G,{value:u,onChange:d,options:(c.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(D,{value:u,placeholder:c.placeholder??void 0,onChange:e=>d(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,onClick:()=>void ae(),children:r(`pluginAccounts.continue`)})})]}),c===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(A,{label:r(`pluginAccounts.key`),children:(0,$.jsx)(D,{mono:!0,type:`password`,value:m,placeholder:t.placeholder??void 0,onChange:e=>h(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,disabled:!m.trim()||ie.isPending,onClick:()=>ie.mutate({method:t.index,inputs:o,key:m},{onSuccess:()=>(i(r(`pluginAccounts.signedIn`),`success`),n()),onError:e=>i(H(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),c===null&&t.type!==`api`&&!S&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,icon:(0,$.jsx)(J,{className:`size-3.5`}),disabled:b.isPending,onClick:()=>b.mutate({method:t.index,inputs:o},{onSuccess:e=>{re(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>i(H(e),`error`)}),children:r(`pluginAccounts.openPage`)})}),S&&S.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[S.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:S.instructions}),S.deviceCode&&(0,$.jsx)(k,{label:r(`pluginAccounts.deviceCode`),mono:!0,children:S.deviceCode}),S.url&&(0,$.jsx)(N,{icon:(0,$.jsx)(J,{className:`size-3.5`}),onClick:()=>window.open(S.url,`_blank`,`noopener`),children:r(`pluginAccounts.openAgain`)}),S.state===`waiting`&&S.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:r(`pluginAccounts.code`),children:(0,$.jsx)(D,{mono:!0,value:_,onChange:e=>te(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(N,{variant:`primary`,disabled:!_.trim()||x.isPending,onClick:()=>x.mutate({flow:S.id,code:_.trim()},{onError:e=>i(H(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),S.state===`waiting`&&!S.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`pluginAccounts.waiting`)}),S.state===`failed`&&(0,$.jsx)(L,{tone:`danger`,title:r(`pluginAccounts.failed`),children:S.error})]})]})}function 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}=T(),{id:t=``}=Ge(),n=Je(),r=d(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=u(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(X,{title:e(`nav.providers`),leading:(0,$.jsx)(en,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(L,{tone:`danger`,title:e(`common.error`),children:H(r.error)})});let f=r.data;return(0,$.jsx)(X,{title:f?f.name:``,subtitle:f?[f.templateId,f.priceKey?e(`providers.priceKeyShort`,{key:f.priceKey}):null].filter(Boolean).join(` · `):void 0,leading:(0,$.jsx)(en,{onClick:()=>n(`/providers`)}),actions:f&&(0,$.jsx)(tn,{p:f}),children:f?(0,$.jsxs)(et,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(Xe,{"aria-label":f.name,children:[(0,$.jsx)(tt,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(tt,{value:`accounts`,children:e(f.authScheme===`oauth-subscription`||f.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(tt,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(nt,{value:`models`,className:`pt-4`,children:(0,$.jsx)(rn,{provider:f,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(nt,{value:`accounts`,className:`pt-4`,children:f.authScheme===`plugin`?(0,$.jsx)(Jt,{provider:f}):f.authScheme===`oauth-subscription`?(0,$.jsx)(Kt,{provider:f}):(0,$.jsx)(dn,{provider:f})}),(0,$.jsx)(nt,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(pn,{provider:f})}),(0,$.jsx)(un,{provider:f,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(B,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}function en({onClick:e}){let{t}=T();return(0,$.jsx)(N,{variant:`glass`,icon:(0,$.jsx)(K,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function tn({p:e}){let{t:n}=T(),r=Je(),{toast:i,confirm:a}=W(),o=oe(),s=t(),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=async()=>{await a({title:n(`providers.deleteConfirm`,{name:e.name}),detail:n(`providers.deleteDetail`),destructive:!0,confirmLabel:n(`common.delete`)})&&s.mutate(e.id,{onSuccess:()=>{i(n(`providers.deleted`)),r(`/providers`)},onError:e=>{let t=e instanceof R&&e.status===409?e.details?.boundClients??[]:[];i(t.length?n(`providers.deleteBound`,{clients:t.map(e=>Ze[e]?.name??e).join(`, `)}):H(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{icon:(0,$.jsx)(Be,{className:`size-3.5`}),onClick:()=>d(!0),children:n(`providers.test`)}),(0,$.jsx)(Ie,{label:n(`common.more`),icon:(0,$.jsx)(q,{className:`size-4`}),items:[{id:`dup`,label:n(`providers.duplicate`),icon:(0,$.jsx)(ge,{className:`size-3.5`}),onSelect:()=>o.mutate(e.id,{onSuccess:e=>r(`/providers/${e.id}`),onError:e=>i(H(e),`error`)})},{id:`tpl`,label:n(`providers.templateUpdate`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>l(!0)},{id:`del`,label:n(`common.delete`),icon:(0,$.jsx)(Y,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void f()}]}),(0,$.jsx)(nn,{open:c,onOpenChange:l,provider:e}),(0,$.jsx)(lt,{provider:e,open:u,onOpenChange:d})]})}function nn({open:e,onOpenChange:t,provider:n}){let{t:r}=T(),{toast:i}=W(),a=ye(n.id,e),o=p(n.id),s=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(U,{open:e,onOpenChange:t,title:r(`providers.templateUpdate`),description:a.data?r(`providers.templateVersions`,{current:a.data.currentVersion,latest:a.data.latestVersion}):void 0,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(N,{variant:`primary`,disabled:!a.data||s,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(H(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(B,{}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:H(a.error)}),s&&(0,$.jsx)(L,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!s&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function rn({provider:e,models:t,loading:r,selected:i,onSelect:a}){let{t:o}=T(),{toast:s}=W(),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=x(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)(_e,{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)(Ke,{className:`size-3.5`}),onClick:()=>p(!0),children:o(`providers.addModels`)}),(0,$.jsx)(N,{variant:`primary`,icon:(0,$.jsx)(Re,{className:`size-3.5`}),onClick:()=>d(!0),children:o(`providers.fetchRemote`)})]})]}),r&&(0,$.jsx)(B,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(ce,{title:o(`providers.noModels`),detail:o(`providers.noModelsDetail`)})}),h.length>0&&(0,$.jsx)(z,{footer:o(`providers.modelsFooter`),children:h.map(e=>(0,$.jsxs)(j,{selected:e.id===i,onClick:()=>a(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:P(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(M,{tone:`orange`,children:o(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?n(e.effective.contextWindow):null,ke(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(Ye,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(V,{checked:e.enabled,label:o(`common.enabled`),onChange:t=>m.mutate({pmId:e.id,enabled:t},{onError:e=>s(H(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}=T(),{toast:r}=W(),i=je(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(H(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(z,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(j,{label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2 font-mono text-[12.5px]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e}),(0,$.jsx)(We,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:P(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(M,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(I,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>u(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(j,{icon:(0,$.jsx)(Ke,{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}=T(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(U,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(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)(D,{autoFocus:!0,mono:!0,label:a(`providers.modelMap.from`),placeholder:`deepseek-v4.1`,spellCheck:!1,value:o,onChange:e=>s(e.target.value)}),(0,$.jsx)(G,{label:a(`providers.modelMap.to`),value:c,onChange:l,placeholder:a(`providers.modelMap.toPlaceholder`),options:n.map(e=>({value:e.modelId,label:e.modelId}))})]})})}function sn({open:e,onOpenChange:t,provider:n}){let{t:r}=T(),{toast:i}=W(),a=h(n.id),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&s(``)},[e]);let c=[...new Set(o.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];return(0,$.jsx)(U,{open:e,onOpenChange:t,title:r(`providers.addModels`),description:r(`providers.addModelsDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(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(H(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(E,{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}=T(),{toast:i}=W(),a=pe(n.id,e),o=h(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)(U,{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(H(e),`error`)}),children:r(`providers.addSelected`,{count:s.size})})]}),children:[(0,$.jsx)(_e,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(B,{lines:4}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:H(a.error)}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(j,{onClick:e.alreadyAdded?void 0:()=>f(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(M,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rt,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function ln({origin:e}){let{t}=T();return e===`overridden`?(0,$.jsx)(M,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(M,{children:t(`origin.inherited`)}):(0,$.jsx)(M,{tone:`red`,children:t(`origin.unset`)})}function un({provider:e,pm:t,onClose:n}){let{t:r}=T(),{toast:i}=W(),a=x(e.id),o=Oe(e.id),s=Me(),[c,l]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(l(t.overrides),d(t.systemModelId??``),p(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(U,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let m={...c,pricing:f?c.pricing??null:null},h=JSON.stringify(m)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||u!==(t.systemModelId??``),g=()=>a.mutate({pmId:t.id,overrides:m,systemModelId:u||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(H(e),`error`)}),_=(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)(Ue,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(U,{open:!0,onOpenChange:e=>!e&&n(),width:720,title:t.modelId,description:e.name,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mr-auto`,children:(0,$.jsx)(it,{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:g,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)(Ye,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(M,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(w,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(G,{className:`w-full`,ariaLabel:r(`providers.linkedModel`),value:u,onChange:d,options:[{value:``,label:r(`providers.noLink`)},...(s.data??[]).map(e=>({value:e.id,label:e.id,detail:e.displayName}))]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:r(`providers.linkedModelHint`)})]}),(0,$.jsx)(w,{title:r(`providers.overrides`),children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[_(`displayName`,r(`models.field.displayName`),(0,$.jsx)(D,{className:`w-full`,"aria-label":r(`models.field.displayName`),placeholder:t.effective.displayName,value:c.displayName??``,onChange:e=>l({...c,displayName:e.target.value||null})})),_(`contextWindow`,r(`models.field.contextWindow`),(0,$.jsx)(xe,{className:`w-full`,label:r(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:c.contextWindow,onChange:e=>l({...c,contextWindow:e})})),_(`maxOutputTokens`,r(`models.field.maxOutputTokens`),(0,$.jsx)(xe,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:c.maxOutputTokens,onChange:e=>l({...c,maxOutputTokens:e})}))]})}),(0,$.jsxs)(w,{title:r(`providers.price`),action:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[r(`providers.customPrice`),(0,$.jsx)(V,{checked:f,label:r(`providers.customPrice`),onChange:e=>{p(e),e&&c.pricing==null&&l({...c,pricing:t.effectivePricing??{currency:`USD`,unit:`per_1m_tokens`,base:{input:null,output:null}}})}})]}),children:[(0,$.jsx)(`p`,{className:`mb-3 text-[11px] text-[var(--text-muted)]`,children:r(f?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),f?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(Qe,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(ve,{maxHeight:220,children:me(t.effectivePricing)}):(0,$.jsx)(L,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function dn({provider:e}){let{t}=T(),{toast:n}=W(),r=c(e.id),[i,a]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:(0,$.jsx)(j,{label:t(`providers.apiKey`),detail:e.hasApiKey?e.apiKeyMasked??`••••`:t(`providers.noKey`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":t(`providers.apiKey`),placeholder:t(`providers.replaceKey`),value:i,onChange:e=>a(e.target.value)}),(0,$.jsx)(N,{variant:`primary`,disabled:i.trim().length===0,loading:r.isPending,onClick:()=>r.mutate({apiKey:i},{onSuccess:()=>{a(``),n(t(`common.saved`),`success`)},onError:e=>n(H(e),`error`)}),children:t(`common.save`)})]})})}),(0,$.jsx)(st,{provider:e})]})}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:e}){let{t}=T(),{toast:n}=W(),r=c(e.id),i=ie(),a=(0,Q.useMemo)(()=>fn(e),[e]),[o,s]=(0,Q.useState)(a),[l,u]=(0,Q.useState)(Object.entries(e.extraHeaders)),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{s(a),u(Object.entries(a.extraHeaders))},[a]);let h=e=>s(t=>({...t,...e})),g={...o,extraHeaders:Object.fromEntries(l.filter(([e])=>e.trim()))},_=JSON.stringify(g)!==JSON.stringify(a),v=()=>{let e={};for(let t of Object.keys(g))t!==`apiKey`&&JSON.stringify(g[t])!==JSON.stringify(a[t])&&(e[t]=g[t]);o.apiKey&&(e.apiKey=o.apiKey),r.mutate(e,{onSuccess:()=>n(t(`common.saved`),`success`),onError:e=>n(H(e),`error`)})},y=(e,t)=>h({endpoints:o.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(z,{title:t(`providers.section.basic`),children:[(0,$.jsx)(j,{label:t(`providers.name`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":t(`providers.name`),value:o.name,onChange:e=>h({name:e.target.value})})}),(0,$.jsx)(j,{label:t(`common.enabled`),children:(0,$.jsx)(V,{checked:o.enabled,label:t(`common.enabled`),onChange:e=>h({enabled:e})})}),(0,$.jsx)(j,{label:t(`providers.notes`),children:(0,$.jsx)(D,{className:`w-64`,"aria-label":t(`providers.notes`),value:o.notes??``,onChange:e=>h({notes:e.target.value||null})})})]}),(0,$.jsx)(z,{title:t(`providers.section.auth`),children:(0,$.jsx)(j,{label:t(`providers.authScheme`),children:(0,$.jsx)(G,{className:`w-48`,value:o.authScheme,onChange:e=>h({authScheme:e}),options:at})})}),(0,$.jsxs)(z,{title:t(`providers.section.endpoints`),footer:t(`providers.endpointsFooter`),children:[o.endpoints.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(G,{className:`w-48`,value:e.protocol,onChange:e=>y(n,{protocol:e}),options:ot}),(0,$.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.baseUrl`),value:e.baseUrl,onChange:e=>y(n,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:!!e.fullUrl,label:t(`providers.fullUrl`),onChange:e=>y(n,{fullUrl:e})}),t(`providers.fullUrl`)]}),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>h({endpoints:o.endpoints.filter((e,t)=>t!==n)})})]},n)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ke,{className:`size-3.5`}),onClick:()=>f(!0),children:t(`providers.addEndpoint`)})}),(0,$.jsx)(j,{label:t(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[t(`providers.preferredHint`),o.preferredUpstreamProtocols.filter(e=>!o.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:t(`providers.preferredMissing`,{protocol:ot.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)($e,{label:t(`providers.preferred`),options:ot.map(e=>{let t=o.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:o.preferredUpstreamProtocols,onValueChange:e=>{let t=o.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));h({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(z,{title:t(`providers.section.billing`),footer:t(`providers.billingFooter`),children:[(0,$.jsx)(j,{label:t(`providers.priceKey`),detail:t(`providers.priceKeyHint`),children:(0,$.jsx)(G,{className:`w-56`,value:o.priceKey==null?`inherit`:`price:${o.priceKey}`,onChange:e=>h({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:t(`providers.priceKeyDefault`,{id:e.templateId??`—`})},{value:`price:`,label:t(`providers.priceKeyNone`)},...(i.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(j,{label:t(`providers.multiplier`),detail:t(`providers.multiplierHint`),children:(0,$.jsx)(xe,{className:`w-28`,label:t(`providers.multiplier`),step:.01,min:0,value:o.priceMultiplier,onChange:e=>h({priceMultiplier:e??1})})})]}),(0,$.jsxs)(z,{title:t(`providers.section.advanced`),children:[(0,$.jsx)(j,{label:t(`providers.proxy`),detail:t(`providers.proxyHint`),children:(0,$.jsx)(D,{className:`w-64 font-mono`,"aria-label":t(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:o.httpProxy??``,onChange:e=>h({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:t(`providers.headers`)}),l.map(([e,n],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(D,{className:`w-48 font-mono`,"aria-label":t(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>u(l.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(D,{className:`flex-1 font-mono`,"aria-label":t(`providers.headerValue`),placeholder:`value`,value:n,onChange:e=>u(l.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":t(`common.delete`),onClick:()=>u(l.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ke,{className:`size-3.5`}),onClick:()=>m(!0),children:t(`providers.addHeader`)})]}),Object.keys(e.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(E,{label:t(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:me(o.settings),onBlur:e=>{try{h({settings:JSON.parse(e.target.value)})}catch{n(t(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(z,{title:t(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(k,{label:`ID`,children:e.id}),e.adapterId&&(0,$.jsx)(k,{label:t(`providers.adapter`),children:e.adapterId}),(0,$.jsx)(k,{label:t(`providers.boundClients`),children:e.boundClients.map(e=>Ze[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(mn,{open:d,onOpenChange:f,onAdd:e=>h({endpoints:[...o.endpoints,e]})}),(0,$.jsx)(hn,{open:p,onOpenChange:m,onAdd:e=>u([...l.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:_&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:t(`common.unsaved`)}),(0,$.jsx)(N,{size:`sm`,onClick:()=>{s(a),u(Object.entries(a.extraHeaders))},children:t(`common.revert`)}),(0,$.jsx)(N,{size:`sm`,variant:`primary`,loading:r.isPending,onClick:v,children:t(`common.save`)})]})})]})}function mn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=T(),[i,a]=(0,Q.useState)(`openai-chat`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(s(``),l(!1))},[e]);let u=/^https?:\/\/\S+$/.test(o.trim());return(0,$.jsx)(U,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(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)(A,{label:r(`providers.protocol`),children:(0,$.jsx)(G,{value:i,onChange:a,options:ot})}),(0,$.jsx)(A,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`https://api.example.com/v1`,value:o,invalid:o!==``&&!u,onChange:e=>s(e.target.value)})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function hn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=T(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(a(``),s(``))},[e]);let c=/^[A-Za-z0-9-]+$/.test(i.trim());return(0,$.jsx)(U,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(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)(A,{label:r(`providers.headerName`),children:(0,$.jsx)(D,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(A,{label:r(`providers.headerValue`),children:(0,$.jsx)(D,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{$t as ProviderDetailPage};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ar as e,Ct as t,E as n,Hr as r,Jn as i,Nr as a,U as o,Vn as s,X as c,Xn as l,Yn as u,_ as d,_i as f,_t as p,at as m,b as h,c as g,ca as _,cn as v,d as y,da as b,f as x,gi as S,gn as C,h as w,hi as T,hn as E,ht as D,i as O,jr as k,l as A,m as j,mi as M,n as N,oa as ee,p as P,pr as F,q as I,qt as L,r as R,rt as z,s as B,sa as V,st as te,t as H,ti as U,u as ne,v as re,vi as ie,w as W,y as G,yi as K}from"./alert-D4IPjxz3.js";import{A as ae,C as oe,D as se,E as ce,O as le,T as ue,X as de,a as q,ct as fe,dt as pe,ft as me,i as he,k as ge,mt as _e,o as ve,pt as ye,r as be,ut as xe,w as Se}from"./overlays-BX48Gd4h.js";import{t as Ce}from"./arrow-left-BEIa7s0v.js";import{t as we}from"./download-CKu95INa.js";import{n as Te,t as Ee}from"./radio-cards-CGtNS_WO.js";import{C as De,H as Oe,J as ke,K as Ae,M as je,T as Me,W as Ne,_ as Pe,d as Fe,f as Ie,g as Le,h as Re,j as ze,k as Be,q as Ve,u as He}from"./index-CdtIrMPt.js";import{t as Ue}from"./checkbox-DJG4To3W.js";var J=b(_(),1);function We(e,t,n){(0,J.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var Ge={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`]};Ge.node;var Ke=p(Ge),qe={name:`gauge`,size:24,node:[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]};qe.node;var Je=p(qe),Ye={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Ye.node;var Xe=p(Ye),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=V(),{blur:Ze,duration:Z,ease:Qe,spring:$e,stagger:et}=n,tt={...$e.smooth,visualDuration:.3},nt={...$e.smooth,visualDuration:.26},rt=300,it={duration:Z.instant},at=1.04,ot={duration:Z.considered*2,ease:[...Qe.standard]},st={duration:Z.considered,ease:[...Qe.standard]},ct={delay:Z.instant,duration:Z.standard,ease:[...Qe.enter]},lt={delay:Z.instant,duration:Z.fast,ease:[...Qe.enter]},ut={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${Ze.subtle}px)`,transition:{duration:Z.fast,ease:[...Qe.standard]}}},dt={enter:{opacity:0,y:`.3em`,filter:`blur(${Ze.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:Z.standard,ease:[...Qe.enter],delay:e*et.word}})};function ft({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)(K,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(M.span,{className:Y.line,variants:ut,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,X.jsx)(M.span,{className:Y.word,custom:t/2,variants:dt,children:e},t))},e)})})]})}function pt(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function mt({title:e,description:t,media:n,action:r,avatar:i,meta:a,status:o,details:s,open:c,defaultOpen:l=!1,onOpenChange:u,children:d,className:f,style:p,...m}){let h=S()??!1,g=(0,J.useId)(),_=(0,J.useRef)(null),v=(0,J.useRef)(null),[y,b]=(0,J.useState)(l),[x,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)({}),[E,D]=(0,J.useState)(null),O=s?c??y:!1,k=!!s&&!h,A=!O&&E!==null,j=!!t,N=(0,J.useCallback)(e=>{c===void 0&&b(e),u?.(e)},[c,u]);(0,J.useEffect)(()=>{let e=_.current,t=v.current;if(!k||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=pt(e,n.borderTopLeftRadius),i=pt(e,n.getPropertyValue(`--radius-surface`)),a=t?.offsetWidth||void 0;T(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()},[k,j]);let ee=(0,J.useRef)(O);(0,J.useLayoutEffect)(()=>{let e=ee.current&&!O;ee.current=O;let t=_.current;if(O)D(null);else if(e&&k&&t){let e=t.getBoundingClientRect();D({top:e.top,left:e.left,width:e.width,height:e.height})}},[O,k]),(0,J.useEffect)(()=>{if(!A)return;let e=window.setTimeout(()=>D(null),rt);return()=>window.clearTimeout(e)},[A]);let P=(e,t,n=!0)=>k?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?O:A?`return`:`panel`,transition:{layout:t===`card`?nt:tt}}:{},F=e=>i||a||o||r?(0,X.jsxs)(`div`,{className:Y.footer,children:[i||a||o?(0,X.jsxs)(M.div,{className:Y.byline,...P(`byline`,e,`position`),children:[i?(0,X.jsx)(`span`,{className:Y.avatar,children:i}):null,(0,X.jsxs)(`span`,{className:Y.bylineText,children:[a?(0,X.jsx)(`span`,{className:Y.meta,children:a}):null,o?(0,X.jsx)(ft,{text:o,reduced:h}):null]})]}):null,r?(0,X.jsx)(M.div,{className:Y.action,...P(`action`,e,`position`),children:r}):null]}):null,I=(0,X.jsxs)(M.article,{...m,ref:_,className:[Y.card,f].filter(Boolean).join(` `),style:{...p,borderRadius:w.card??p?.borderRadius},"data-hover":x||void 0,whileHover:h?void 0:{y:-2},onHoverStart:()=>C(!0),onHoverEnd:()=>C(!1),...P(`card`,`card`),transition:{default:$e.snappy,layout:nt},children:[n?(0,X.jsx)(M.div,{className:Y.media,...P(`media`,`card`),children:(0,X.jsx)(M.div,{className:Y.zoom,initial:!1,animate:{scale:x&&!h?at:1},transition:x?ot:st,children:n})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(M.h3,{className:Y.title,...P(`title`,`card`),children:s?(0,X.jsx)(ae,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:Y.trigger,children:e})}):e}),t?(0,X.jsx)(M.p,{ref:v,className:Y.description,...P(`description`,`card`,`position`),children:t}):null,d,F(`card`)]})]});return s?(0,X.jsx)(oe,{open:O,onOpenChange:N,children:(0,X.jsxs)(ie,{id:g,children:[I,(0,X.jsx)(K,{children:(O||A)&&(0,X.jsxs)(le,{forceMount:!0,children:[(0,X.jsx)(K,{children:O&&(0,X.jsx)(se,{asChild:!0,forceMount:!0,children:(0,X.jsx)(M.div,{className:Y.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:h?it:{duration:Z.exit,ease:[...Qe.standard]}},transition:h?it:{duration:Z.standard,ease:[...Qe.enter]}})},`overlay`)}),(0,X.jsx)(ue,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,X.jsxs)(M.div,{className:Y.panel,"data-framer-portal-id":g,"data-returning":A||void 0,layoutScroll:!0,style:{borderRadius:w.panel,"--card-measure":w.measure?`${w.measure}px`:void 0,...E&&A?{"--landing-top":`${E.top}px`,"--landing-left":`${E.left}px`,"--landing-width":`${E.width}px`,"--landing-height":`${E.height}px`}:{}},...k?{...P(`card`,`panel`),initial:!1,animate:w.card!==void 0&&w.panel!==void 0?{borderRadius:A?w.card:w.panel}:void 0,transition:{layout:A?nt:tt,borderRadius:A?nt:tt},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:it},transition:it},children:[n?(0,X.jsx)(M.div,{className:Y.media,...P(`media`,`panel`),children:(0,X.jsx)(M.div,{className:Y.zoom,initial:{scale:x&&!h?at:1},animate:{scale:1},transition:tt,children:n})}):null,(0,X.jsx)(M.span,{className:Y.closeSlot,initial:h?{opacity:0}:{opacity:0,scale:.9},animate:A?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:A||h?it:lt,children:(0,X.jsx)(Se,{asChild:!0,children:(0,X.jsx)(M.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:h?void 0:{scale:.94},transition:$e.snappy,children:(0,X.jsx)(te,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(ge,{asChild:!0,children:(0,X.jsx)(M.h2,{className:Y.title,...P(`title`,`panel`),children:e})}),t?(0,X.jsx)(ce,{asChild:!0,children:(0,X.jsx)(M.p,{className:Y.description,...P(`description`,`panel`,`position`),children:t})}):null,d,F(`panel`),(0,X.jsx)(M.div,{className:Y.details,initial:!h&&{opacity:0,y:6},animate:A?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:it},transition:A||h?it:ct,children:s})]})]})})]},`quick-look`)})]})}):I}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`},ht={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${n.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.standard,ease:[...n.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${n.blur.subtle}px)`,transition:{duration:n.duration.fast,ease:[...n.ease.standard]}})},gt={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}}},_t=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),vt=new Intl.NumberFormat(`en-US`),yt={duration:n.duration.considered*1.75,ease:[...n.ease.inOut]},bt={duration:n.duration.fast,ease:[...n.ease.standard]};function xt(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 St({text:e,direction:t,whole:r=!1,morph:i=!1,tone:a}){let o=!!S(),s=(0,J.useRef)(null),c=f(`auto`),[l,u]=(0,J.useState)({text:e,direction:1});l.text!==e&&u({text:e,direction:t??(_t(e)<_t(l.text)?-1:1)}),(0,J.useEffect)(()=>{let e=s.current;if(!e||typeof ResizeObserver>`u`)return;let t=null,r=new ResizeObserver(([r])=>{if(!r)return;let i=r.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;t!==null&&t!==e.textContent&&!o?T(c,i,n.spring.morph):c.jump(i),t=e.textContent});return r.observe(e),()=>r.disconnect()},[i,o,c]);let d=!r&&!/\p{L}/u.test(e),p=o?gt:ht,m=d?`right`:`left`;return(0,X.jsxs)(M.span,{className:Q.roll,"data-end":d||void 0,"data-whole":r||void 0,style:i?{width:c}:void 0,children:[i&&(0,X.jsx)(`span`,{ref:s,className:Q.sizer,"aria-hidden":`true`,children:e}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(K,{mode:`popLayout`,initial:!1,custom:l.direction,anchorX:m,children:xt(e,r).map(e=>(0,X.jsx)(M.span,{className:Q.slot,custom:l.direction,variants:p,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(K,{mode:`popLayout`,initial:!1,custom:l.direction,anchorX:m,children:(0,X.jsx)(M.span,{className:a?`${Q.glyph} ${a}`:Q.glyph,custom:l.direction,variants:p,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${a??``}${e.key}`)})},e.slot))})})]})}var Ct=5,wt=1.25,Tt=Array.from({length:161},(e,t)=>t/160);function Et(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 Dt(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 Ot(e,t,n,r){let i=e=>Ct+(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(Dt(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 kt(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 At({data:e,label:t,value:r,change:i,tone:a=`accent`,width:o=160,height:s=52,labels:c,formatValue:l,area:u=!0,interactive:d=!0}){let p=e.length>1?e:[e[0]??0,e[0]??0],m=p.length-1,h=p.join(`,`),g=(0,J.useMemo)(()=>Et(h.split(`,`).map(Number)),[h]),_=`${t}: ${r??p[m]}. ${i??``}`.trim(),v=`sparkline${(0,J.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,y=(0,J.useRef)(null),b=(0,J.useRef)(null),x=Ve(y,{once:!0,amount:.5}),C=!!S(),[w,E]=(0,J.useState)({w:o,h:s}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!1),j=D===null?null:Math.min(D,m),[N,ee]=(0,J.useState)({index:j,direction:1});N.index!==j&&ee({index:j,direction:j===null||N.index===null?1:Math.sign(j-N.index)||1});let[P]=(0,J.useState)(()=>Ot(g,o,s,1)),F=(0,J.useRef)(g),I=(0,J.useRef)(w),L=f(0),R=f(1),z=f(P.line),B=f(P.trail),V=f(P.fill),te=f(P.dot),H=f(P.cx),U=f(P.cx+wt+16),ne=f(P.cx+wt),re=f(0),ie=ke(L,e=>+(e>.001)),W=(0,J.useCallback)(()=>{let{w:e,h:t}=I.current,n=L.get(),r=Ot(F.current,e,t,R.get());z.set(r.line),B.set(r.trail),V.set(r.fill),te.set(r.dot),H.set(r.cx),U.set(r.cx+wt+16),ne.set(r.cx+wt),re.set(n>=1?e+32:kt(r.points,n)+16)},[R,H,ne,te,L,V,z,U,re,B]);We(R,`change`,W),We(L,`change`,W),(0,J.useLayoutEffect)(()=>{let e=b.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&E(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*s/o})});return t.observe(e),()=>t.disconnect()},[s,o]),(0,J.useLayoutEffect)(()=>{I.current=w,W()},[w,W]),(0,J.useEffect)(()=>{if(C){L.jump(1);let e=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(e)}if(!x)return;let e=T(L,1,{...yt,onComplete:()=>A(!0)});return()=>e.stop()},[L,x,C]),(0,J.useEffect)(()=>{let e=F.current;if(e===g)return;if(C){F.current=g,W();return}let t=[...new Set([...Tt,...g.map(([e])=>e)])].sort((e,t)=>e-t),r=t.map(t=>Dt(e,t)),i=t.map(e=>Dt(g,e)),a=T(0,1,{...n.spring.smooth,onUpdate:e=>{F.current=t.map((t,n)=>[t,r[n]+(i[n]-r[n])*e]),W()},onComplete:()=>{F.current=g,W()}});return()=>a.stop()},[W,C,g]),(0,J.useEffect)(()=>{let e=j===null?1:j/m;if(C){R.jump(e);return}let t=T(R,e,n.spring.snappy);return()=>t.stop()},[R,j,m,C]);let G=j!==null,K=(e=>l?l(p[e],e):vt.format(p[e]))(j??m),ae=c?.[j??m],oe=r===void 0?void 0:G?K:r,se=j===null?i??``:r===void 0?[K,ae].filter(Boolean).join(` · `):ae??`${j+1} of ${m+1}`,ce=e=>{let t=b.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(m,Math.round((e-t.left)/t.width*m))):m},le=d?{role:`slider`,tabIndex:0,"aria-label":`${t}, explore values`,"aria-valuemin":1,"aria-valuemax":m+1,"aria-valuenow":(j??m)+1,"aria-valuetext":`${ae??(j===null?`Latest`:`Point ${j+1} of ${m+1}`)}: ${K}`,onPointerDown:e=>O(ce(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&O(ce(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&O(null)},onPointerLeave:()=>O(null),onPointerCancel:()=>O(null),onBlur:()=>O(null),onKeyDown:e=>{if(e.key===`Escape`&&G){e.preventDefault(),O(null);return}let t=j??m,n=Math.max(1,Math.round((m+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:m}[e.key];r!==void 0&&(e.preventDefault(),O(Math.max(0,Math.min(m,r))))}}:{};return(0,X.jsxs)(`figure`,{ref:y,className:Q.figure,"aria-label":_,children:[(0,X.jsxs)(`figcaption`,{className:Q.caption,children:[(0,X.jsx)(`span`,{className:Q.label,children:(0,X.jsx)(St,{text:t,whole:!0})}),oe!==void 0&&(0,X.jsx)(`strong`,{children:(0,X.jsx)(St,{text:oe,morph:!0})}),(0,X.jsx)(`small`,{className:Q[a],children:(0,X.jsx)(St,{text:se,direction:G?N.direction:void 0,tone:G?Q.point:void 0,morph:!0})})]}),(0,X.jsx)(`div`,{ref:b,className:Q.plot,"data-interactive":d||void 0,...le,children:(0,X.jsxs)(`svg`,{className:Q.chart,viewBox:`0 0 ${w.w} ${w.h}`,"aria-hidden":`true`,focusable:`false`,children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsx)(`clipPath`,{id:`${v}-lit`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(M.rect,{x:-16,y:-16,width:U,height:w.h+32})}),(0,X.jsx)(`clipPath`,{id:`${v}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(M.rect,{x:ne,y:-16,width:w.w+32,height:w.h+32})}),(0,X.jsx)(`clipPath`,{id:`${v}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(M.rect,{x:-16,y:-16,width:re,height:w.h+32})})]}),u&&(0,X.jsx)(M.path,{className:`${Q.area} ${Q[a]}`,d:V,clipPath:`url(#${v}-fill)`}),(0,X.jsx)(`line`,{className:Q.baseline,x1:`0`,y1:w.h-.5,x2:w.w,y2:w.h-.5}),(0,X.jsx)(M.path,{className:Q.trail,d:B,clipPath:`url(#${v}-dim)`,initial:!1,animate:{opacity:G&&k?1:0},transition:C?{duration:0}:bt}),(0,X.jsx)(M.polyline,{className:[Q.line,Q[a]].join(` `),points:z,clipPath:`url(#${v}-lit)`,style:{pathLength:L,opacity:ie}}),(0,X.jsx)(M.line,{className:Q.cursor,x1:H,x2:H,y1:0,y2:w.h,initial:!1,animate:{opacity:+!!G},transition:C?{duration:0}:bt}),(0,X.jsx)(M.polyline,{className:[Q.end,Q[a]].join(` `),points:te,initial:!1,animate:{opacity:+!!k,strokeWidth:k?G?10:7:0},transition:C?{duration:0}:{opacity:bt,strokeWidth:n.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`},jt=e=>`blur(${e}px)`,Mt={duration:0},Nt={duration:n.duration.fast,ease:[...n.ease.standard]},Pt={duration:n.duration.standard,ease:[...n.ease.enter]},Ft={opacity:0,y:`0.3em`,filter:jt(n.blur.soft)},It={opacity:1,y:0,filter:jt(0)},Lt={opacity:0,y:`-0.3em`,filter:jt(n.blur.subtle)},Rt={opacity:0,scale:.5,filter:jt(n.blur.subtle)},zt={opacity:1,scale:1,filter:jt(0)};function Bt({text:e,className:t,reduced:r}){let i=(0,J.useRef)(null),a=(0,J.useRef)(0),o=f(`auto`);return(0,J.useLayoutEffect)(()=>{a.current=performance.now()+700},[e]),(0,J.useEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let s=!1,c=new ResizeObserver(()=>{let t=e.offsetHeight;if(!s||r||performance.now()>a.current){s=!0,o.jump(t);return}T(o,t,n.spring.smooth)});return c.observe(e),()=>c.disconnect()},[o,r]),(0,X.jsx)(M.span,{className:$.slot,style:{height:o},children:(0,X.jsx)(`span`,{ref:i,className:$.slotInner,children:(0,X.jsx)(K,{mode:`popLayout`,initial:!1,children:e?(0,X.jsx)(M.span,{className:t,initial:Ft,animate:It,exit:{...Lt,transition:r?Mt:Nt},transition:r?Mt:Pt,children:e},`${t}:${e}`):null})})})}function Vt({kind:e,number:t,delay:r,reduced:i}){let a=i?Mt:{scale:{...n.spring.snappy,delay:r},opacity:{duration:n.duration.fast,delay:r},filter:{duration:n.duration.fast,delay:r}},o={...Rt,transition:i?Mt:Nt},s=i?Mt:{duration:n.duration.standard,ease:n.ease.enter,delay:r+.04};return e===`number`?(0,X.jsx)(M.span,{className:$.glyph,initial:Rt,animate:zt,exit:o,transition:a,children:t}):(0,X.jsx)(M.svg,{className:`${$.glyph} ${$.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:Rt,animate:zt,exit:o,transition:a,children:e===`check`?(0,X.jsx)(M.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)(M.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(M.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Mt:{...n.spring.snappy,delay:r+.16}})]})})}function Ht({number:e,kind:t,current:r,glyphDelay:i,ringDelay:a,reduced:o}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(K,{initial:!1,children:r?(0,X.jsx)(M.span,{className:$.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?Mt:Nt},transition:o?Mt:{scale:{...n.spring.snappy,delay:a},opacity:{duration:n.duration.fast,delay:a}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(K,{initial:!1,children:(0,X.jsx)(Vt,{kind:t,number:e,delay:i,reduced:o},t)})})]})}var Ut={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Wt({steps:e,current:t,orientation:r=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let u=S()??!1,d=e.length,f=Math.min(Math.max(Math.round(t),0),d),[p,m]=(0,J.useState)({to:f,from:f});p.to!==f&&m({to:f,from:p.to});let h=p.from,g=n.stagger.line,_=e=>u?0:f>h?e>=h&&e<f?(e-h)*g:0:e>=f&&e<h?(h-1-e)*g:0,v=u?0:Math.max(0,Math.abs(f-h)-1)*g+.12,y=!!i,b=r===`vertical`,x=f>=d?void 0:e[f];function C(e){let t=!b&&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 w=y?`nav`:`div`,T=[$.root,b?$.vertical:$.horizontal,o?$.compact:``,l].filter(Boolean).join(` `);return(0,X.jsxs)(w,{className:T,"aria-label":s,role:y?void 0:`group`,children:[(0,X.jsx)(`ol`,{className:$.list,style:b?void 0:{gridTemplateColumns:d>1?`repeat(${d-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:y?C:void 0,children:e.map((e,t)=>{let o=t===f,s=e.error?`error`:t<f?`complete`:o?`current`:`upcoming`,c=y&&t<f,l=e.error??(a===`all`||o?e.description:void 0),p=e.error?`error`:t<f?`check`:`number`,m=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ht,{number:t+1,kind:p,current:o,glyphDelay:_(t),ringDelay:v,reduced:u}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:e.label}),Ut[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Ut[s]]}):null,(0,X.jsx)(Bt,{text:l,className:e.error?$.error:$.description,reduced:u})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[t<d-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(M.span,{className:$.fill,initial:!1,animate:b?{scaleY:+(t<f)}:{scaleX:+(t<f)},transition:u?Mt:{...n.spring.smooth,delay:_(t)}},r)}):null,y?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":t<=f||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>i?.(t):void 0,children:m}):(0,X.jsx)(`span`,{className:$.head,"aria-current":o?`step`:void 0,children:m})]},e.id)})}),b?null:(0,X.jsxs)(`span`,{className:$.caption,"aria-hidden":`true`,children:[(0,X.jsx)(Bt,{text:x?.label??c,className:$.captionLabel,reduced:u}),(0,X.jsx)(Bt,{text:x?.error??x?.description,className:x?.error?$.error:$.description,reduced:u})]}),(0,X.jsx)(`span`,{className:$.srOnly,"aria-live":`polite`,children:x?`Step ${f+1} of ${d}: ${x.label}`:c})]})}var Gt={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Kt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},qt=e=>`${e.source}\u0000${e.ref}`,Jt=e=>e.status!==`skip`&&e.status!==`same`;function Yt(e){try{return new URL(e).host}catch{return e}}function Xt({open:e,onOpenChange:t}){let{t:n}=m(),{toast:r}=ve(),i=C(e),a=E(),[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(qt)))},[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)),h=(0,J.useMemo)(()=>(i.data??[]).flatMap(e=>e.items).filter(e=>c.has(qt(e))&&Jt(e)),[i.data,c]),g=(e,t)=>l(n=>{let r=new Set(n);return t?r.add(qt(e)):r.delete(qt(e)),r});return(0,X.jsx)(he,{open:e,onOpenChange:t,width:680,title:n(`import.title`),description:n(`import.detail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{icon:(0,X.jsx)(ze,{className:`size-3.5`}),onClick:()=>void i.refetch(),disabled:i.isFetching||a.isPending,children:n(`import.rescan`)}),(0,X.jsx)(R,{variant:`primary`,disabled:h.length===0||a.isPending,onClick:()=>{d(null),a.mutate(h.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:h.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(w,{value:o,onChange:s,placeholder:n(`import.search`)}),u&&(0,X.jsx)(H,{tone:`danger`,title:n(`common.error`),children:u}),i.isLoading&&(0,X.jsx)(re,{lines:3}),i.isError&&(0,X.jsx)(H,{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)(Zt,{source:e,matches:p,selected:c,onToggle:g,filtering:f.length>0},e.id))}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`import.footnote`)})]})})}function Zt({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=m(),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)(H,{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)(Qt,{c:e,checked:n.has(qt(e)),onToggle:t=>r(e,t)},qt(e)))}):(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function Qt({c:e,checked:t,onToggle:n}){let{t:r}=m(),i=Jt(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=>`${Gt[e.protocol]??e.protocol} · ${Yt(e.baseUrl)}`).join(` / `);return(0,X.jsxs)(`li`,{className:z(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,X.jsx)(Ue,{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:Kt[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 $t=``,en=`custom`,tn=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],nn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},rn={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},an=e=>JSON.stringify(e??{},null,2);function on(e){return{enabled:e.enabled,template:e.template??$t,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:an(e.request?.headers),extract:e.extract?an(e.extract):``}}function sn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function cn({provider:e}){let{t}=m(),{toast:n}=ve(),r=l(),i=F(e.id),a=k(e.id),o=v(),s=e.quotaConfig,c=(0,J.useMemo)(()=>on(s),[s]),[u,d]=(0,J.useState)(c),[f,p]=(0,J.useState)(null);(0,J.useEffect)(()=>d(c),[c]);let g=r.data??[],_=g.find(e=>e.id===s.suggestedTemplate),b=u.template===$t?_:g.find(e=>e.id===u.template),S=u.template===en,C=S?tn:b?.params??[],w=e=>d(t=>({...t,...e})),T=JSON.stringify(u)!==JSON.stringify(c),E=e=>{if(e!==en||u.url)return w({template:e});let t=b??_;w({template:e,method:t?.request.method??nn.method,url:t?.request.url??nn.url,auth:t?.request.auth??nn.auth,headers:an(t?.request.headers??nn.headers),extract:an(t?.extract??rn)})},D=()=>{let e={enabled:u.enabled,template:u.template===$t?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(S){let r=sn(u.headers),i=sn(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},A=()=>{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`)})},M=()=>{let e=D();e&&a.mutate(e,{onSuccess:p,onError:e=>n(q(e),`error`)})},N=s.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:s.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),ee=[{value:$t,label:_?t(`providers.quota.templateAuto`,{name:_.name}):t(`providers.quota.templateNone`)},...g.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:en,label:t(`providers.quota.custom`)}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(ne,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,X.jsx)(j,{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=>w({enabled:e})})}),(0,X.jsx)(j,{label:t(`providers.quota.template`),children:(0,X.jsx)(be,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:u.template,onChange:E,options:ee})}),C.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=s.secrets.includes(e.name);return e.secret?(0,X.jsx)(j,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,X.jsx)(y,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:u.secrets[e.name]??``,onChange:t=>w({secrets:{...u.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(j,{label:n,children:(0,X.jsx)(y,{className:`w-64 font-mono`,"aria-label":n,value:u.params[e.name]??``,onChange:t=>w({params:{...u.params,[e.name]:t.target.value}})})},e.name)}),C.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),S&&(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)(be,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:u.method,onChange:e=>w({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(y,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:u.url,onChange:e=>w({url:e.target.value})}),(0,X.jsx)(be,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:u.auth,onChange:e=>w({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)(h,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:u.headers,onChange:e=>w({headers:e.target.value})}),(0,X.jsx)(h,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:u.extract,onChange:e=>w({extract:e.target.value})}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,X.jsx)(j,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:N}),children:(0,X.jsx)(P,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:u.intervalMinutes,onChange:e=>w({intervalMinutes:e})})}),(0,X.jsx)(j,{label:t(`providers.quota.timeout`),children:(0,X.jsx)(P,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:u.timeoutSec,onChange:e=>w({timeoutSec:e})})}),(0,X.jsx)(j,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(y,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:u.baseUrl,onChange:e=>w({baseUrl:e.target.value})})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,X.jsx)(R,{size:`sm`,variant:`primary`,disabled:!T,loading:i.isPending,onClick:A,children:t(`common.save`)}),(0,X.jsx)(R,{size:`sm`,icon:(0,X.jsx)(Te,{className:`size-3.5`}),loading:a.isPending,onClick:M,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(R,{size:`sm`,icon:(0,X.jsx)(Je,{className:`size-3.5`}),disabled:T,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)(ln,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,X.jsx)(he,{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)(H,{tone:f.ok?`success`:`danger`,title:f.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!f.ok&&fe({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)(x,{label:t(`providers.quota.requestUrl`),mono:!0,children:f.url}),f.httpStatus!=null&&(0,X.jsx)(x,{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)(ln,{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)(O,{children:an(f.raw)})]})]})})]})}function ln({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=m(),i=ye(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)(H,{tone:`warning`,title:n(`providers.quota.failed`,{error:fe(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)(H,{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:xe(e,n,r)??`—`}),pe(e,n,r)&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:pe(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:de(o,r,n(`tray.justNow`))??``})})]})]})}function un({provider:e}){let{t,locale:n}=m(),{toast:r}=ve(),i=v();if(!me(e))return null;let a=_e(e.quota,t,n),o=ye(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:fe(o,t)})}),!a&&!o&&(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,X.jsx)(R,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Je,{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 dn=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],fn=[{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 pn(){let{t:e}=m(),t=Ne(),[n,r]=Ae(),i=u(),[o,s]=(0,J.useState)(n.get(`new`)===`1`),[c,l]=(0,J.useState)(!1);(0,J.useEffect)(()=>{n.get(`new`)===`1`&&(s(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),Me(e=>{e===`new-provider`&&s(!0)});let d=a(`7d`,`day`,`provider`),[f,p]=(0,J.useState)(null),h=(0,J.useMemo)(()=>{let e=hn(mn),t=new Map;for(let n of d.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}},[d.data]);return(0,X.jsxs)(He,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{icon:(0,X.jsx)(we,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`providers.import`)}),(0,X.jsx)(R,{variant:`primary`,icon:(0,X.jsx)(je,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`providers.add`)})]}),children:[(0,X.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,X.jsx)(re,{lines:4}),i.isError&&(0,X.jsx)(H,{tone:`danger`,title:e(`common.error`),children:q(i.error)}),i.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(g,{icon:(0,X.jsx)(Be,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,X.jsx)(R,{variant:`primary`,icon:(0,X.jsx)(je,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`providers.add`)}),(0,X.jsx)(R,{icon:(0,X.jsx)(we,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,X.jsx)(vn,{p:e,days:h.days,usage:h.byProvider.get(e.name),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>p(e)},e.id))})]}),(0,X.jsx)(Xt,{open:c,onOpenChange:l}),(0,X.jsx)(xn,{open:o,onOpenChange:s,onCreated:e=>t(`/providers/${e.id}`)}),f&&(0,X.jsx)(kn,{provider:f,open:!0,onOpenChange:e=>!e&&p(null)})]})}var mn=7;function hn(e){let t=new Date;return Array.from({length:e},(n,r)=>{let i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(e-1-r));return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,`0`)}-${String(i.getDate()).padStart(2,`0`)}`})}function gn(e){if(!e)return null;try{return new URL(e).host}catch{return e}}var _n=e=>e.stopPropagation();function vn({p:e,days:t,usage:n,onOpen:i,onTest:a}){let{t:o}=m(),s=r(e.id),{toast:l}=ve(),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`),h=e.enabled?d?{tone:`orange`,label:o(`providers.noKey`)}:{tone:`green`,label:o(`providers.card.active`)}:{tone:`neutral`,label:o(`providers.card.disabled`)},g=n?.requests??t.map(()=>0),_=g.reduce((e,t)=>e+t,0),v=e.templateUpdateAvailable?5:8;return(0,X.jsxs)(mt,{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=>dn.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:z(`transition-[filter,opacity]`,!e.enabled&&`opacity-50 grayscale`),children:(0,X.jsx)(Le,{name:e.name,icon:e.icon,colorKey:e.templateId,size:28})}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-[var(--border)] bg-[color-mix(in_oklab,var(--surface)_80%,transparent)] px-2 py-0.5 text-[11px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(B,{tone:h.tone}),h.label]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:gn(e.endpoints[0]?.baseUrl)??`—`}),(0,X.jsx)(`span`,{className:`shrink-0`,children:o(`providers.modelCount`,{count:e.modelCount})})]})]}),meta:(0,X.jsx)(`span`,{className:z(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:_n,children:[(0,X.jsx)(R,{variant:`plain`,size:`sm`,icon:(0,X.jsx)(Te,{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 Ie?(0,X.jsx)(`span`,{title:Pe(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=>Ie[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:_n,children:(0,X.jsx)(un,{provider:e})}),(0,X.jsx)(`div`,{className:`mt-2`,onClick:_n,children:_>0?(0,X.jsx)(At,{label:o(`providers.card.requests7d`),data:g,labels:t.map(e=>e.slice(5)),value:I(_,!0),change:c(n?.costUsd??0),width:320,height:28,formatValue:e=>I(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 yn=`plugin:`,bn=[`recommended`,`official`,`subscription`,`cn`,`aggregator`,`local`,`custom`];function xn({open:t,onOpenChange:n,onCreated:r}){let{t:i}=m(),{toast:a}=ve(),o=e(),c=s(),l=L(),d=u(),f=(0,J.useMemo)(()=>new Set((d.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[d.data]),p=Ne(),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),[S,C]=(0,J.useState)(``),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(``),[k,j]=(0,J.useState)(``),[M,N]=(0,J.useState)(``),[ee,P]=(0,J.useState)(`openai-chat`),[F,I]=(0,J.useState)(`bearer`);(0,J.useEffect)(()=>{t||(v(null),x(null),g(``),C(``),E(``),O(``),j(``),N(``))},[t]);let z=(0,J.useMemo)(()=>{let e=h.trim().toLowerCase(),t=(o.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)},[o.data,h]),B=(0,J.useMemo)(()=>{let e=h.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,h]),V=e=>{v(e),e===`custom`?(C(``),j(``),O(``)):(C(e.name),j(e.priceKey??e.id),O(``),I(e.auth.scheme))},te=()=>{let e=_===`custom`;l.mutate({templateId:e?null:_.id,variantId:D||null,name:S.trim()||null,apiKey:T.trim()||null,priceKey:k,...e?{endpoints:[{protocol:ee,baseUrl:M.trim()}],authScheme:F}:{}},{onSuccess:e=>{n(!1),a(i(`providers.created`,{name:e.name}),`success`),r(e)},onError:e=>a(q(e),`error`)})},U=_&&_!==`custom`?_:null,ne=()=>{if(b===`custom`)V(`custom`);else if(b?.startsWith(yn)){let e=B.find(e=>yn+e.id===b);e&&(n(!1),r(e))}else{let e=(o.data??[]).find(e=>e.id===b);e&&!f.has(e.id)&&V(e)}},ie=_!==null&&(_===`custom`?/^https?:\/\//.test(M.trim())&&S.trim()!==``:!U.requiresApiKey||T.trim()!==``);return(0,X.jsxs)(he,{open:t,onOpenChange:n,width:640,title:i(_?`providers.addTitleDetails`:`providers.addTitle`),description:_?U?U.name:i(`providers.custom`):i(`providers.addDetail`),footer:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{className:`mr-auto`,variant:`plain`,onClick:()=>v(null),children:i(`common.back`)}),(0,X.jsx)(R,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,X.jsx)(R,{variant:`primary`,disabled:!ie,loading:l.isPending,onClick:te,children:i(`providers.create`)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,X.jsx)(R,{variant:`primary`,disabled:!b,onClick:ne,children:i(`common.continue`)})]}),children:[(0,X.jsx)(Wt,{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)(A,{label:i(`providers.name`),children:(0,X.jsx)(y,{value:S,onChange:e=>C(e.target.value)})}),U?.variants&&U.variants.length>0&&(0,X.jsx)(A,{label:i(`providers.variant`),children:(0,X.jsx)(be,{value:D,onChange:e=>{O(e);let t=U.variants?.find(t=>t.id===e);j(t?.priceKey??U.priceKey??U.id)},options:[{value:``,label:i(`providers.variantDefault`)},...U.variants.map(e=>({value:e.id,label:e.name}))]})}),_===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:i(`providers.baseUrl`),hint:i(`providers.baseUrlHint`),children:(0,X.jsx)(y,{value:M,onChange:e=>N(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)(A,{label:i(`providers.protocol`),children:(0,X.jsx)(be,{value:ee,onChange:P,options:dn})}),(0,X.jsx)(A,{label:i(`providers.authScheme`),children:(0,X.jsx)(be,{value:F,onChange:I,options:fn})})]})]}),U?.authScheme===`oauth-subscription`?(0,X.jsx)(H,{tone:`info`,title:i(`providers.subscriptionWizardHint`),children:i(`providers.subscriptionWizardDetail`)}):(0,X.jsxs)(`div`,{className:`font-mono`,children:[(0,X.jsx)(De,{label:i(`providers.apiKey`),description:i(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:T,onChange:e=>E(e.target.value)}),U?.apiKeyUrl&&(0,X.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:U.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:i(`providers.getKey`)})]}),(0,X.jsx)(A,{label:i(`providers.priceKey`),hint:i(`providers.priceKeyHint`),children:(0,X.jsx)(be,{value:k,onChange:j,options:[{value:``,label:i(`providers.priceKeyNone`)},...(c.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),U&&U.models.length>0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.templateModels`,{count:U.models.length})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,X.jsx)(w,{value:h,onChange:g,placeholder:i(`providers.searchTemplates`)}),o.isLoading&&(0,X.jsx)(re,{lines:4}),o.isError&&(0,X.jsx)(H,{tone:`danger`,title:i(`common.error`),children:q(o.error)}),z.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)(Ee,{name:`provider-template`,"aria-label":i(`providers.category.${e.category}`),minColumnWidth:170,value:e.items.some(e=>e.id===b)?b:null,onValueChange:x,options:e.items.map(e=>({value:e.id,label:e.name,description:[...new Set(e.endpoints.map(e=>e.protocol))].join(` · `),icon:(0,X.jsx)(Le,{name:e.name,icon:e.icon,colorKey:e.id,size:24}),disabled:f.has(e.id),disabledReason: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`)}),B.length>0?(0,X.jsx)(Ee,{name:`provider-template-plugin`,"aria-label":i(`providers.category.plugin`),minColumnWidth:170,value:b?.startsWith(yn)?b:null,onValueChange:x,options:B.map(e=>({value:yn+e.id,label:e.name,description:i(`providers.pluginProvided`),icon:(0,X.jsx)(Le,{name:e.name,icon:e.icon,colorKey:e.id,size:24})}))}):(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)(R,{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)(Ee,{name:`provider-template-custom`,"aria-label":i(`providers.custom`),layout:`list`,value:b===`custom`?`custom`:null,onValueChange:x,options:[{value:`custom`,label:i(`providers.custom`),description:i(`providers.customDetail`),icon:(0,X.jsx)(je,{className:`size-4`})}]})]})]})]})}var Sn=3,Cn=256,wn=4096,Tn={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 En(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var Dn=e=>typeof e==`number`?e:null,On=e=>typeof e==`string`?e:null;function kn({provider:e,open:t,onOpenChange:n}){let{t:r}=m(),a=ee(),o=i(t?e.id:void 0),s=e.endpoints.map(e=>e.protocol),[c,l]=(0,J.useState)(`single`),[u,f]=(0,J.useState)(()=>En(e)),[p,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(Cn),[b,x]=(0,J.useState)(``),[S,C]=(0,J.useState)(null),[w,T]=(0,J.useState)({}),[E,D]=(0,J.useState)([]),[O,k]=(0,J.useState)(new Set),[j,M]=(0,J.useState)([]),[N,P]=(0,J.useState)(``),[F,I]=(0,J.useState)(null),[L,z]=(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),ne=(0,J.useMemo)(()=>{let e=[...o.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...j.filter(t=>!e.includes(t))]},[o.data,j]);(0,J.useEffect)(()=>{if(t){x(e=>e||(o.data??[]).find(e=>e.enabled)?.modelId||(o.data??[])[0]?.modelId||``);return}U.current=!1,B.current?.abort();for(let e of V.current.values())e.abort();V.current.clear(),C(null),T({}),D([]),k(new Set),M([]),P(``),I(null)},[t,o.data]);let re=(0,J.useCallback)(e=>({modelId:e,protocol:u,stream:p,prompt:g.trim()||null,maxOutputTokens:v??Cn}),[u,p,g,v]),ie=(0,J.useCallback)((t,n,r)=>Rn(e.id,t,re(t),n,r),[e.id,re]),W=()=>{let e=b.trim();if(!e)return;B.current?.abort();let t=new AbortController;B.current=t,U.current=!0,I(null),C({modelId:e,status:`running`,text:``,reasoning:``}),ie(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&K(),C(e)})},G=e=>{if(e.length===0)return;U.current=!0,H.current=!1,I(null),D(e),T(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(Sn,e.length)},async()=>{for(;;){if(!U.current)return;let n=e[t++];if(n===void 0)return;if(H.current){T(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;V.current.set(n,r),await ie(n,r.signal,e=>T(t=>({...t,[n]:e}))),V.current.delete(n),K()}}))},K=()=>void a.invalidateQueries({queryKey:[`requests`]}),ae=()=>{H.current=!0,T(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},oe=S?.status===`running`||E.some(e=>w[e]?.status===`running`||w[e]?.status===`queued`&&!H.current),se=E.filter(e=>w[e]&&w[e].status!==`queued`&&w[e].status!==`running`).length,ce=E.filter(e=>w[e]?.status===`success`).length,le=E.filter(e=>w[e]?.status===`failed`).length,ue=(e,t)=>k(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),de=()=>{oe||n(!1)},q=e=>e.stopPropagation();return(0,X.jsx)(`span`,{onClick:q,onKeyDown:q,children:(0,X.jsxs)(he,{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)(R,{disabled:oe,onClick:()=>n(!1),icon:(0,X.jsx)(te,{className:`size-3.5`}),children:r(`common.close`)}),c===`single`?oe?(0,X.jsx)(R,{variant:`primary`,icon:(0,X.jsx)(Xe,{className:`size-3.5`}),onClick:()=>B.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(R,{variant:`primary`,disabled:b.trim()===``,icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:W,children:r(S?`providers.testDialog.retest`:`providers.testDialog.start`)}):oe?(0,X.jsx)(R,{variant:`primary`,icon:(0,X.jsx)(Xe,{className:`size-3.5`}),onClick:ae,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(R,{variant:`primary`,disabled:O.size===0,icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>G([...O]),children:r(`providers.testDialog.testN`,{count:O.size})})]}),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,X.jsx)(Le,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,X.jsx)(d,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:c,onChange:e=>{l(e),I(null)},ariaLabel:r(`providers.testDialog.config`)})]}),c===`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)(A,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(An,{value:b,models:ne,onChange:x})}),(0,X.jsx)(jn,{protocols:s,protocol:u,onProtocol:f,stream:p,onStream:h,maxTokens:v,onMaxTokens:y,prompt:g,onPrompt:_}),(0,X.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,X.jsx)(Mn,{run:S,onRetest:W})]}):F===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(In,{known:ne,selected:O,onToggle:ue,onSelectAll:e=>k(e?new Set(ne):new Set),onClear:()=>k(new Set),search:N,onSearch:P,onAdd:e=>{M(t=>t.includes(e)?t:[...t,e]),k(t=>new Set(t).add(e)),P(``)},configOpen:L,onConfigOpen:z,protocols:s,protocol:u,onProtocol:f,stream:p,onStream:h,maxTokens:v,onMaxTokens:y,prompt:g,onPrompt:_}),E.length>0?(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:oe?r(`providers.testDialog.progress`,{done:se,total:E.length,ok:ce,failed:le}):r(`providers.testDialog.progressDone`,{total:E.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/E.length*100}%`,background:`var(--accent)`}})})]}):null,E.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Ln,{order:E,runs:w,onView:I})}):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)(R,{variant:`plain`,icon:(0,X.jsx)(Ce,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>I(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:F})]}),(0,X.jsx)(Mn,{run:w[F]??null})]})]})})}function An({value:e,models:t,onChange:n}){let{t:r}=m(),[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)(y,{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:z(`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 jn({protocols:e,...t}){let{t:n}=m(),r=e.map(e=>({value:e,label:dn.find(t=>t.value===e)?.label??e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:n(`providers.testDialog.protocol`),children:(0,X.jsx)(be,{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)(A,{label:n(`providers.testDialog.maxTokens`),children:(0,X.jsx)(P,{value:t.maxTokens,min:1,placeholder:String(Cn),label:n(`providers.testDialog.maxTokens`),onChange:e=>t.onMaxTokens(e===null?null:Math.min(wn,Math.max(1,Math.round(e))))})}),(0,X.jsx)(A,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(h,{rows:4,value:t.prompt,placeholder:`Reply with OK.`,onChange:e=>t.onPrompt(e.target.value)})})]})}function Mn({run:e,onRetest:t}){let{t:n}=m(),[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)(R,{size:`sm`,icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:t,children:n(`providers.testDialog.retest`)}):null,(0,X.jsx)(Fe,{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)(Ke,{className:`size-4`})})}),(0,X.jsx)(Fn,{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)(Pn,{label:n(`providers.testDialog.metrics.http`),value:e?.httpMs}),(0,X.jsx)(Pn,{label:n(`providers.testDialog.metrics.firstWait`),value:c}),(0,X.jsx)(Pn,{label:n(`providers.testDialog.metrics.ttft`),value:e?.ttftMs}),(0,X.jsx)(Pn,{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)(d,{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)(Nn,{run:e}):e?.error?(0,X.jsx)(H,{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)(Nn,{run:e})})]})]})}function Nn({run:e}){let{t}=m();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(Tn[e.status])}):(0,X.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,X.jsx)(Oe,{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 Pn({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?`—`:o(t)})]})}function Fn({run:e}){let{t}=m(),n=e?.status??`idle`;return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(B,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(Tn[n])]})}function In({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:i,search:a,onSearch:o,onAdd:s,configOpen:c,onConfigOpen:l,...u}){let{t:d}=m(),f=a.trim(),p=f.toLowerCase(),h=p?e.filter(e=>e.toLowerCase().includes(p)):e,g=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)(w,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,X.jsx)(R,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(R,{icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>l(!0),children:d(`providers.testDialog.config`)})]}),(0,X.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:h.length===0&&!g?(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)(Ue,{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`)})]}),g?(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,h.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(Ue,{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)(he,{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)(jn,{...u})})})]})}function Ln({order:e,runs:t,onView:n}){let{t:r}=m();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)(Fn,{run:i??null})}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:o(i.ttftMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:o(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 Rn(e,n,r,i,a){let o={modelId:n,status:`running`,text:``,reasoning:``};a(o);let s=e=>{o={...o,...e},a(o)};try{await t(e,r,e=>{let t=e.data??{};switch(e.event){case`headers`:s({httpStatus:Dn(t.httpStatus),httpMs:Dn(t.httpMs),contentType:On(t.contentType),headers:zn(t.headers)});break;case`delta`:{let e=On(t.text)??``;On(t.kind)===`reasoning`?s({reasoning:o.reasoning+e}):s({text:o.text+e});break}case`done`:{let t=e.data;s({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,contentType:t.contentType??null,headers:zn(t.headers)});break}}},i)}catch(e){e?.name===`AbortError`?s({status:`cancelled`,error:null}):s({status:`failed`,error:e instanceof U?e.message:String(e)})}}function zn(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}export{fn as AUTH_OPTIONS,dn as PROTOCOL_OPTIONS,pn as ProvidersPage,cn as n,Je as r,kn as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$r as e,At as t,E as n,Fr as r,Gr as i,Gt as a,Kr as o,Lr as s,Lt as c,Mr as l,Nt as u,Pr as d,Qn as f,Qr as p,Rr as m,V as h,Xr as g,Xt as _,Yn as v,Yr as y,Yt as b,_ as x,_i as S,_t as C,ai as w,at as T,bt as E,ca as D,ci as O,d as k,da as A,dt as ee,ei as te,ft as j,gi as M,hi as ne,hr as re,i as ie,ii as ae,jt as oe,kt as se,l as N,m as P,mi as F,n as ce,ni as le,o as ue,oa as de,p as fe,r as I,rn as pe,s as me,sa as he,si as ge,t as L,u as R,ur as _e,v as z,xn as ve,y as B,yi as V,yr as ye}from"./alert-D4IPjxz3.js";import{B as be,F as xe,I as Se,L as Ce,R as we,a as H,gt as U,i as Te,n as Ee,o as W,r as G,vt as De,z as Oe}from"./overlays-BX48Gd4h.js";import{t as ke}from"./TrayPanelView-CQQDnzsO.js";import{t as Ae}from"./download-CKu95INa.js";import{t as je}from"./ellipsis-D-uqKDgA.js";import{t as Me}from"./external-link-tQTMyil6.js";import{n as Ne,t as K}from"./radio-cards-CGtNS_WO.js";import{t as Pe}from"./folder-open-CL6HwOra.js";import{t as Fe}from"./log-out-CZYk_IyX.js";import{t as Ie}from"./pencil-CUO0GAyP.js";import{t as Le}from"./rotate-ccw-Daii8PQN.js";import{D as q,G as Re,J as ze,M as Be,P as Ve,W as He,b as Ue,j as We,n as Ge,s as Ke,t as qe,u as Je,v as Ye,x as Xe,y as J}from"./index-CdtIrMPt.js";var Ze={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`}]]};Ze.node;var Qe=C(Ze),$e={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`}]]};$e.node;var et=C($e),tt={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`}]]};tt.node;var nt=C(tt),rt={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`}]]};rt.node;var it=C(rt),at={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};at.node;var ot=C(at),st={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`}]]};st.node;var ct=C(st),lt={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`}]]};lt.node;var ut=C(lt),dt={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`}]]};dt.node;var ft=C(dt),Y=A(D(),1),X=he(),pt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],mt={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/…`},ht=e=>e===`feishu`||e===`dingtalk`,gt=(e,t)=>e(`alerts.event.${t}`),_t=(e,t)=>e(`alerts.event.${t}.hint`);function vt(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(yt,{}),(0,X.jsx)(bt,{}),(0,X.jsx)(Tt,{})]})}function yt(){let{t:e,locale:t}=T(),n=oe(!0);return(0,X.jsxs)(R,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(z,{}),n.data?.length===0&&(0,X.jsx)(P,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(P,{icon:(0,X.jsx)(Qe,{className:`size-4 text-[var(--danger)]`}),label:`${gt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${h(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function bt(){let{t:e}=T(),{toast:t,confirm:n}=W(),r=te(),i=pe(),a=l(),o=_e(),[s,c]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(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(H(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=>p(e.secret??null),onError:e=>t(H(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(H(e),`error`)})};return(0,X.jsxs)(R,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(z,{}),r.data?.length===0&&(0,X.jsx)(P,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(P,{icon:(0,X.jsx)(ft,{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)(ce,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(ce,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||ht(t.format))&&(0,X.jsx)(ce,{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)(Ne,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(Ee,{label:e(`common.more`),icon:(0,X.jsx)(je,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(Ie,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(it,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ve,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(q,{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)(Be,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(xt,{hook:s,onClose:()=>c(null),onSecret:p}),(0,X.jsx)(Ct,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(St,{secret:f,onClose:()=>p(null)})]})}function xt({hook:e,onClose:t,onSecret:n}){let{t:r}=T(),{toast:i}=W(),a=b(),o=g(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(10),[p,m]=(0,Y.useState)(!0),[h,_]=(0,Y.useState)(!0),[v,y]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(`generic`),[C,w]=(0,Y.useState)(``),[E,D]=(0,Y.useState)([]),O=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),_(t?.enabled??!0),y(!t||t.hasSecret),S(t?.format??`generic`),w(``),D((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Te,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(O?`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(E.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(H(e),`error`)},m=!O&&e!==null&&e.format!==x,g=ht(x)?v?C.trim()||void 0:``:void 0;O?a.mutate({...u,format:x,...x===`generic`?{signed:v}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:x}:{},...x===`generic`?v||!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)(N,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(k,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${x}.hint`),children:(0,X.jsx)(G,{ariaLabel:r(`alerts.webhooks.format`),value:x,onChange:t=>{S(t),y(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||ht(t))},options:pt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(k,{mono:!0,value:l,placeholder:mt[x],onChange:e=>u(e.target.value)})}),ht(x)&&v&&(0,X.jsx)(N,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(k,{mono:!0,type:`password`,autoComplete:`off`,value:C,placeholder:e!==`new`&&e!==null&&e.format===x&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>w(e.target.value)})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(fe,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[E.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)(k,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>D(E.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(k,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>D(E.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(q,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>D(E.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Be,{className:`size-3.5`}),onClick:()=>D([...E,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(P,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(B,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:_})}),(0,X.jsx)(P,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(B,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(x===`generic`?O||e!==null&&e.format===`generic`&&e.hasSecret:ht(x))&&(0,X.jsx)(P,{label:r(`alerts.webhooks.signed`),detail:r(x===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(B,{checked:v,label:r(`alerts.webhooks.signed`),onChange:y})})]})]})})}function St({secret:e,onClose:t}){let{t:n}=T(),{toast:r}=W();return(0,X.jsx)(Te,{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 U.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 Ct({hook:t,onClose:n}){let{t:r,locale:i}=T(),{toast:a}=W(),o=e(t?.id),s=f(),c={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Te,{open:t!==null,onOpenChange:e=>!e&&n(),title:`${r(`alerts.webhooks.deliveries`)} · ${t?.name??``}`,width:640,children:[o.isLoading&&(0,X.jsx)(z,{lines:4}),o.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:o.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)(ce,{tone:c[e.status],children:r(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?r(`alerts.webhooks.test`):gt(r,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:h(e.createdAt,i)}),(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?r(`alerts.delivery.next`,{time:h(e.nextAttemptAt,i)}):r(`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:r(`alerts.delivery.payload`)}),(0,X.jsx)(ie,{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:r(`alerts.delivery.response`)}),(0,X.jsx)(ie,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:s.isPending&&s.variables===e.id,onClick:()=>s.mutate(e.id,{onSuccess:()=>a(r(`alerts.delivery.redelivered`)),onError:e=>a(H(e),`error`)}),children:r(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function wt(e){let t=v(),n=r(),i=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),a=De({queries:i.map(t=>({queryKey:E.providerAccounts(t.id),queryFn:()=>le(`GET`,`/api/providers/${ae(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(t.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(n.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Tt(){let{t:e}=T(),{toast:n,confirm:r}=W(),i=t(),a=te(),o=m(),s=_(),[c,l]=(0,Y.useState)(null),u=e=>a.data?.find(t=>t.id===e)?.name??e,d=async t=>{await r({title:e(`alerts.rules.deleteConfirm`,{name:t.name}),confirmLabel:e(`common.delete`),destructive:!0})&&s.mutate(t.id,{onSuccess:()=>n(e(`alerts.rules.deleted`,{name:t.name})),onError:e=>n(H(e),`error`)})};return(0,X.jsxs)(R,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[i.isLoading&&(0,X.jsx)(z,{}),i.data?.length===0&&(0,X.jsx)(P,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),i.data?.map(t=>(0,X.jsxs)(P,{icon:(0,X.jsx)(Qe,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,t.firing>0&&(0,X.jsx)(ce,{tone:`red`,children:e(`alerts.rules.firing`,{count:t.firing})}),!t.enabled&&(0,X.jsx)(ce,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${gt(e,t.event)} → ${t.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(B,{checked:t.enabled,label:e(`alerts.rules.enabled`),onChange:e=>o.mutate({id:t.id,enabled:e},{onError:e=>n(H(e),`error`)})}),(0,X.jsx)(Ee,{label:e(`common.more`),icon:(0,X.jsx)(je,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(Ie,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(q,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Be,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Dt,{rule:c,onClose:()=>l(null)})]})}function Et(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 Dt({rule:e,onClose:t}){let{t:n}=T(),{toast:r}=W(),i=se(),o=te(),s=a(),c=m(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,S]=(0,Y.useState)([]),[C,w]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[O,A]=(0,Y.useState)(60),ee=i.data?.find(e=>e.id===d),j=wt(ee?.subjectType),M=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=i.data?.[0];u(t?.name??``),f(t?.event??n?.id??``),h(t?{...Et(i.data?.find(e=>e.id===t.event)),...t.condition}:Et(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),S(t?.webhookIds??(o.data??[]).map(e=>e.id)),w(t?.notifyResolved??!1),D(t?.repeatMinutes??null),A(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(Te,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(M?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!l.trim()||!d,loading:s.isPending||c.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(p).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:d,condition:i,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:C,repeatMinutes:E&&E>0?Math.floor(E):null,cooldownMinutes:Math.max(0,Math.floor(O??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(H(e),`error`)};M?s.mutate(a,o):e&&c.mutate({id:e.id,...a},o)},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(N,{label:n(`alerts.rules.name`),children:(0,X.jsx)(k,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(N,{label:n(`alerts.rules.event`),hint:d?_t(n,d):void 0,children:(0,X.jsx)(G,{ariaLabel:n(`alerts.rules.event`),value:d,onChange:e=>{f(e),h(Et(i.data?.find(t=>t.id===e))),y([])},options:(i.data??[]).map(e=>({value:e.id,label:gt(n,e.id)}))})}),ee?.params.map(e=>(0,X.jsx)(N,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(fe,{value:typeof p[e.name]==`number`?p[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>h({...p,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(G,{ariaLabel:n(`alerts.param.${e.name}`),value:String(p[e.name]??``),onChange:t=>h({...p,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(k,{mono:!0,value:String(p[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>h({...p,[e.name]:t.target.value})})},e.name)),ee&&(0,X.jsx)(N,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${ee.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(x,{ariaLabel:n(`alerts.rules.subjects`),value:g,onChange:_,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),g===`only`&&(0,X.jsx)(Ke,{label:n(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...j,...v.filter(e=>!j.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(N,{label:n(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.rules.noWebhooks`)}):(0,X.jsx)(Ke,{label:n(`alerts.rules.webhooks`),value:b,onValueChange:S,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)(N,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(fe,{value:E,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:D})}),(0,X.jsx)(N,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(fe,{value:O,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:A})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(P,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(B,{checked:C,label:n(`alerts.rules.notifyResolved`),onChange:w})})})]})})}var Ot=`https://astra-gate.si/docs/guide/remote-access`;function kt(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 At(){let{t:e}=T(),t=s(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(jt,{s:n}),(0,X.jsx)(Mt,{s:n}),(0,X.jsx)(Nt,{s:n}),(0,X.jsx)(Pt,{s:n}),(0,X.jsx)(ue,{title: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)(L,{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:H(t.error)}):(0,X.jsx)(z,{className:`mx-auto my-8`})})}function jt({s:e}){let{t,locale:n}=T(),{toast:r,confirm:i}=W(),a=d(),o=u(),s=kt(e,t),c=async e=>{await U.copy(e)&&r(t(`common.copied`))},l=async e=>{(!e||await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))&&(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(H(e),`error`)})},f=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,p=e.state===`connected`&&e.connectedAt?t(`settings.remote.connectedSince`,{time:h(e.connectedAt,n)}):t(`settings.remote.state.${e.state}`),m=e.publicUrl?`${e.publicUrl}/v1`:null;return(0,X.jsxs)(R,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(P,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(me,{tone:f}),p]}),children:(0,X.jsx)(B,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),e.enabled&&m&&(0,X.jsxs)(P,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:m}),children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void c(m)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Me,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(e.publicUrl,`_blank`,`noopener`)})]}),e.enabled&&e.publicUrl&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),e.cloudflared.downloading&&(0,X.jsx)(P,{label:t(`settings.remote.download`),detail:e.cloudflared.progress==null?`…`:`${Math.round(e.cloudflared.progress*100)}%`}),e.enabled&&e.state!==`connected`&&(e.error||e.cloudflared.error)&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(L,{tone:`danger`,title:e.error??e.cloudflared.error??``})})]})}function Mt({s:e}){let{t}=T(),{toast:n}=W(),r=re(),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(``),c=e.cloudflared,l=c.path?c.version?t(`settings.remote.cloudflaredReady`,{version:c.version}):t(`settings.remote.cloudflaredCustom`):c.asset?t(`settings.remote.cloudflaredMissing`,{version:c.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(R,{title:t(`settings.remote.checks`),children:[(0,X.jsx)(P,{label:t(`settings.remote.cloudflared`),detail:l,children:(0,X.jsx)(me,{tone:c.path?`green`:c.asset?`neutral`:`red`})}),(0,X.jsx)(P,{label:t(`settings.remote.password`),detail:e.checks.passwordSet?t(`settings.remote.passwordSet`):t(`settings.remote.passwordMissing`),children:!i&&(0,X.jsx)(I,{size:`sm`,onClick:()=>a(!0),children:e.checks.passwordSet?t(`settings.remote.passwordChange`):t(`settings.remote.passwordSetAction`)})}),i&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>a(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:o.length<8,loading:r.isPending,onClick:()=>r.mutate(o,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),a(!1),s(``)},onError:e=>n(H(e),`error`)}),children:t(`common.save`)})]})]})}function Nt({s:e}){let{t}=T(),{toast:n}=W(),r=y(),[i,a]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>a(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let o=async e=>{await U.copy(e)&&n(t(`common.copied`))},s=e=>r.mutate({mode:e},{onError:e=>n(H(e),`error`)}),c=()=>r.mutate({hostname:i.hostname.trim()||null,...i.token.trim()?{token:i.token.trim()}:{}},{onSuccess:()=>{n(t(`settings.remote.saved`)),a(e=>({...e,token:``}))},onError:e=>n(H(e),`error`)}),l=i.token.trim()!==``||i.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(R,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(P,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(x,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:s,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)(L,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:i.token,onChange:e=>a({...i,token:e.target.value})})}),(0,X.jsx)(P,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:i.hostname,onChange:e=>a({...i,hostname:e.target.value})})}),(0,X.jsxs)(P,{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)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void o(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)(nt,{className:`size-3.5`}),onClick:()=>window.open(Ot,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!l||r.isPending,onClick:c,children:t(`common.save`)})]})]})]})}function Pt({s:e}){let{t}=T(),{toast:n,confirm:r}=W(),i=y(),a=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(H(e),`error`)})};return(0,X.jsxs)(R,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(P,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(ce,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(P,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(B,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void a(e)})})]})}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:Ft}=n,It=[...n.ease.enter],Lt=[...n.ease.standard],Rt=[0,1,2,3,4,5,6,7,8,9],zt=6,Bt=400,Vt=40,Ht=240,Ut=1500,Wt=700,Gt=700,Kt=.22,qt=4,Jt=130,Yt=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),Xt=e=>(String(e).split(`.`)[1]??``).length,Zt=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),Qt=(e,t)=>typeof e==`function`?e(t):e??``,$t=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function en(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 tn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Ft.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:Lt}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Ft.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Lt},opacity:{duration:$.instant},filter:{duration:$.instant}}})},nn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),rn={enter:nn(0),center:{...nn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},an={enter:nn(1),center:{...nn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function on({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=ze(e,e=>`${n(e)*1.05}em`),i=ze(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=ze(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=ze(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*Ft.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(F.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function sn({digit:e,direction:t,instant:n}){let r=M(),i=S(e),a=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let o=a.current;if(o.digit===e)return;let s=t>0?(e-o.digit+10)%10:-((o.digit-e+10)%10);Math.abs(s)>5&&(s-=Math.sign(s)*10),o.target+=s,o.digit=e,n||r?i.jump(o.target):ne(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),Rt.map(e=>(0,X.jsx)(on,{position:i,digit:e},e))]})}function cn({value:e,format:t,direction:n,instant:r}){let i=M(),a=r?an:i?rn:tn;return(0,X.jsx)(V,{initial:!1,custom:n,children:en(e,t).map(e=>(0,X.jsx)(F.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(sn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function ln({text:e,direction:t,className:n}){let r=M();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(V,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(F.span,{className:Z.char,custom:t,variants:r?rn:tn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var un=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},dn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=un(n[t]),i=un(e);return r!==null&&i!==null&&i<r?-1:1})},fn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Ft.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:It,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Ft.subtle}px)`,transition:{duration:.14,ease:Lt}})},pn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function mn({word:e,direction:t}){let n=M(),r=(0,Y.useRef)(null),i=S(`auto`),a=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!a.current||n?i.jump(e.offsetWidth):ne(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(F.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(V,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(F.span,{className:Z.word,custom:t,variants:n?pn:fn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function hn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:dn(t.text,e)});let r=t.text===e?t.directions:dn(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)(mn,{word:e,direction:r[t]??1})]},t))})]})}function gn({id:e,text:t,className:n}){return(0,X.jsx)(V,{initial:!1,children:t?(0,X.jsx)(_n,{id:e,text:t,className:n},`message`):null})}function _n({id:e,text:t,className:n}){let r=M(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(F.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,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)(F.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${Ft.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:It},children:(0,X.jsx)(hn,{text:t})})})}function vn({id:e,edge:t,text:n}){let r=M();return(0,X.jsx)(V,{initial:!1,children:t!==0&&(0,X.jsx)(F.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${Ft.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:Lt}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function yn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?Be:ot;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:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:p=!1,locale:m=`en-US`,formatOptions:h,size:g=`md`,limitHint:_=!0}){let v=M(),y=(0,Y.useId)(),b=u??y,x=c?`${b}-description`:void 0,C=`${b}-limit`,w=o>0?o:1,[T,E]=(0,Y.useState)(n),D=t??T,[O,k]=(0,Y.useState)(``),[A,ee]=(0,Y.useState)(!1),[te,j]=(0,Y.useState)(0),[re,ie]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(``),[se,N]=(0,Y.useState)(0),[P,ce]=(0,Y.useState)(!1),le=(0,Y.useRef)(null),ue=(0,Y.useRef)(null),de=(0,Y.useRef)(null),fe=(0,Y.useRef)(void 0),I=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(void 0),me=(0,Y.useRef)({edge:0,count:0,at:0}),he=(0,Y.useRef)(null),ge=(0,Y.useRef)(null),L=(0,Y.useRef)(D),R=(0,Y.useRef)(D),_e=(0,Y.useRef)(void 0),z=(0,Y.useRef)(null),ve=(0,Y.useRef)(!1),B=(0,Y.useRef)(null),V=(0,Y.useRef)(!1),ye=(0,Y.useRef)(()=>!1),be=S(0),xe=S(0),Se=S(0),Ce=ze(()=>xe.get()+Se.get()),we=Number.isFinite(i)?i:0,H=Math.max(Xt(w),Xt(we)),U=h?.minimumFractionDigits??H,Te=Math.max(U,h?.maximumFractionDigits??H),Ee=h?.useGrouping??!0,W=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:U,maximumFractionDigits:Te,useGrouping:Ee,numberingSystem:`latn`}),[m,U,Te,Ee]),G=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(m).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[m]),De=e=>Number(e.toFixed(H))||0,Oe=e=>Math.min(a,Math.max(i,e)),ke=e=>De(we+Math.round((e-we)/w)*w),Ae=(e,t)=>{let n=(e-we)/w;return De(we+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*w)},je=e=>`${Qt(d,e)}${W.format(e)}${Qt(f,e)}`.trim();function Me(e){let t=e.split(G.group).join(``).replace(G.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Ne=A?Me(O):null,K=Ne??D,[Pe,Fe]=(0,Y.useState)({value:K,direction:1});Pe.value!==K&&Fe({value:K,direction:K>Pe.value?1:-1});let Ie=Pe.value===K?Pe.direction:K>Pe.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(_e.current),window.clearTimeout(fe.current),window.clearTimeout(I.current),window.clearTimeout(pe.current)},[]);function Le(e,t){let n=performance.now(),r=me.current;r.count=r.edge===e&&n-r.at<Gt?r.count+1:1,r.edge=e,r.at=n;let i=le.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(pe.current),pe.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!v){ne(be,0,{...Yt,velocity:-e*Jt*(1+Math.min(r.count-1,qt)*Kt)});let n=(e>0?de:ue).current;n&&(t===`button`||t===`key`)&&ne(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}_&&(N(e),window.clearTimeout(fe.current),fe.current=window.setTimeout(()=>N(0),Ut))}function q(e,n){if(!Number.isFinite(e))return!1;let i=Oe(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Le(a>0?1:-1,n),oe(`${je(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==L.current&&oe(je(i)),i!==L.current&&(L.current=i,t===void 0&&E(i),r?.(i),!0)}let Re=(e,t,n)=>q(Ae(L.current,e*t),n);(0,Y.useLayoutEffect)(()=>{L.current=D,ye.current=Re});function Be(){let e=ge.current;e&&B.current===null&&(B.current=e.getBoundingClientRect().left-xe.get()-Se.get())}(0,Y.useLayoutEffect)(()=>{let e=B.current,t=ge.current;if(B.current=null,V.current){V.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-xe.get()-Se.get());Math.abs(n)<.5||(Se.set(Se.get()+n),v?Se.jump(0):ne(Se,0,Q.morph))});function Ve(){window.clearTimeout(I.current),ce(!1)}function He(){if(!A)return;Be(),ee(!1),Ve();let e=Me(O);e!==null&&q(ke(e),`type`)}function Ue(){window.clearTimeout(_e.current),_e.current=void 0,j(0)}function We(e,t,n){Ue(),He();let r=Math.max(1,Math.round(t/w));n===`button`&&j(e);let i=0,a=()=>{let t=ye.current(e,r,n);_e.current=window.setTimeout(a,t?Math.max(Vt,150*.86**++i):Ht)};_e.current=window.setTimeout(a,Re(e,r,n)?Bt:360)}function Ge(e){let t=s??w*10,n={ArrowUp:[1,e.shiftKey?t:w],ArrowDown:[-1,e.shiftKey?t:w],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||We(n[0],n[1],`key`);return}if(!A&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),q(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),A?(V.current=!0,He()):e.currentTarget.select()),e.key===`Escape`&&A&&(e.preventDefault(),Be(),ee(!1),Ve(),V.current=!0,q(R.current,`type`))}function Ke(e){let t=RegExp(`[^0-9${Zt(G.group)}${H||Te?Zt(G.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);A||(R.current=D),Be(),k(n),ee(!0);let r=Me(n);r!==null&&r>=i&&r<=a&&ke(r)===r&&q(r,`type`),Ve(),r!==null&&r<i&&(I.current=window.setTimeout(()=>ce(!0),Wt))}function qe(e){ve.current=!1,p&&!l&&e.button===0&&(He(),z.current={pointer:e.pointerId,x:e.clientX,from:L.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Je(e){let t=z.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,ie(!0)}let r=n/zt,o=Math.trunc(r);q(o?Ae(t.from,o):t.from,`scrub`);let s=t.from+r*w,c=s>a?(s-a)/w*zt:s<i?(s-i)/w*zt:0;xe.set(v?0:$t(c))}function Ye(e){let t=z.current;t&&t.pointer===e.pointerId&&(z.current=null,t.active&&(ve.current=!0,ie(!1),ne(xe,0,v?{duration:0}:Q.snappy),oe(je(L.current))))}let Xe=t=>({toward:t,label:e,disabled:l,controls:b,limit:t>0?K>=a:K<=i,pressed:te===t}),J=Ne===null?0:Ne>a?1:Ne<i&&P?-1:0,Ze=_?J||se:0,Qe=Ze>0?a:i,$e=Ze?typeof _==`function`?_(Ze>0?`max`:`min`,Qe):`${Ze>0?`Max`:`Min`} ${je(Qe)}`:``,et=[x,J&&_?C:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":g,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:b,className:Z.label,"data-scrub":p&&!l||void 0,onPointerDown:qe,onPointerMove:Je,onPointerUp:Ye,onPointerCancel:Ye,onClick:e=>{ve.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(vn,{id:C,edge:Ze,text:$e})]}),(0,X.jsxs)(`div`,{ref:le,className:Z.control,"data-scrubbing":re||void 0,"data-disabled":l||void 0,"data-warn":J?J>0?`max`:`min`:void 0,children:[(0,X.jsx)(yn,{...Xe(-1),iconRef:ue,onPress:()=>We(-1,w,`button`),onRelease:Ue,onActivate:()=>{He(),Re(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==he.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==he.current&&(he.current?.focus(),he.current?.select())},children:(0,X.jsxs)(F.span,{ref:ge,className:Z.value,style:{x:Ce,y:be},children:[(0,X.jsx)(ln,{text:Qt(d,K),direction:Ie,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)(cn,{value:K,format:W,direction:Ie,instant:A})}),A&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:O}),(0,X.jsx)(`input`,{ref:he,id:b,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:H||Te?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:A?O:W.format(D),disabled:l,"aria-describedby":et,"aria-invalid":J?!0:void 0,"aria-valuenow":D,"aria-valuetext":je(D),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a:void 0,onChange:e=>Ke(e.currentTarget.value),onKeyDown:Ge,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ue()},onBlur:()=>{Ue(),He()}})]}),(0,X.jsx)(ln,{text:Qt(f,K),direction:Ie,className:Z.affix})]})}),(0,X.jsx)(yn,{...Xe(1),iconRef:de,onPress:()=>We(1,w,`button`),onRelease:Ue,onActivate:()=>{He(),Re(1,1,`button`)}})]}),(0,X.jsx)(gn,{id:x,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:ae})]})}var xn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Sn(){let{t:e}=T(),t=de(),[n,r]=we(),i=Oe(),a=xe(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(P,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(B,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(be(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)(Cn,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(K,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:w.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Cn,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:xn.map(o)})}),(0,X.jsx)(Cn,{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)(Le,{className:`size-3.5`}),onClick:()=>r(Se),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Cn,{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)(ke,{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 Cn({title:e,hint:t,children:n}){let{t:r}=T();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`],Tn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function En(){let{t:e}=T(),{tab:t}=Re(),n=He(),r=Ce(),i=wn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)(Je,{title:e(`nav.settings`),children:(0,X.jsxs)(Ye,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ue,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Xe,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ut,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Xe,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(et,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Xe,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ee,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Xe,{value:`tray`,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.tray`)]})})]}),(0,X.jsx)(J,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Dn,{})}),(0,X.jsx)(J,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(vt,{})}),(0,X.jsx)(J,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(At,{})}),r&&(0,X.jsx)(J,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Sn,{})})]})})}function Dn(){let{t:e,locale:t,setLocale:n}=T(),r=Ge(),a=ye(),o=i(),c=de(),l=p(),d=u(),f=ve(),m=s(),{toast:h,confirm:g}=W(),_=a.data,v=m.data?.state===`connected`&&m.data.publicUrl?`${m.data.publicUrl}/v1`:null,y=e=>o.mutate(e,{onError:e=>h(H(e),`error`)}),b=e=>{n(e),y({locale:e})},S=async t=>{await U.copy(t)&&h(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(R,{title:e(`settings.appearance`),children:[(0,X.jsx)(P,{label:e(`settings.theme`),children:(0,X.jsx)(x,{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)(P,{label:e(`settings.accent`),detail:r.accentChoice===`system`?r.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(G,{className:`w-40`,ariaLabel:e(`settings.accent`),value:r.accentChoice,onChange:r.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...qe.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(P,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(x,{ariaLabel:e(`settings.language`),value:t,onChange:b,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(R,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(P,{label:e(`settings.gatewayUrl`),detail:`${_.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(`${_.gatewayBaseUrl}/v1`)})}),v&&(0,X.jsx)(P,{label:e(`settings.remote.publicUrl`),detail:v,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(v)})}),(0,X.jsx)(P,{label:e(`settings.listen`),detail:`${_.host}:${_.port}`}),(0,X.jsx)(P,{label:e(`settings.dataDir`),detail:_.dataDir,children:U.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Pe,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void U.openPath(_.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(_.dataDir)})}),(0,X.jsx)(P,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(B,{checked:_.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await g({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&y({requireGatewayKey:t})}})}),(0,X.jsx)(P,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(jn,{label:e(`settings.streamIdle`),value:_.streamIdleTimeoutSec,onCommit:e=>y({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(P,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(G,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:_.requestCompression,onChange:e=>y({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)(kn,{settings:_}),(0,X.jsx)(An,{settings:_}),(0,X.jsxs)(R,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(P,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(jn,{label:e(`settings.quota.autoInterval`),value:_.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void c.invalidateQueries({queryKey:E.providers}),onError:e=>h(H(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(P,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(jn,{label:e(`settings.quota.subscriptionInterval`),value:_.subscriptionQuotaIntervalMinutes,onCommit:e=>y({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(R,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(P,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(G,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:_.usageTimeZone??``,onChange:e=>y({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:_.effectiveUsageTimeZone})},...[...new Set([...Tn,..._.usageTimeZone?[_.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(R,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(P,{label:e(`settings.debugBodies`),children:(0,X.jsx)(B,{checked:_.debugBodies,label:e(`settings.debugBodies`),onChange:e=>y({debugBodies:e})})}),(0,X.jsx)(P,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(jn,{label:e(`settings.bodyRetention`),value:_.bodyRetentionDays,onCommit:e=>y({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(P,{label:e(`settings.requestRetention`),detail:_.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(B,{checked:_.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>y({requestRetentionDays:e?90:null})}),_.requestRetentionDays!=null&&(0,X.jsx)(jn,{label:e(`settings.requestRetention`),value:_.requestRetentionDays,onCommit:e=>y({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(R,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(P,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(jn,{label:e(`settings.effort.${t}`),value:_.effortBudgets[t],onCommit:e=>y({effortBudgets:{..._.effortBudgets,[t]:e??_.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:H(a.error)}):(0,X.jsx)(z,{className:`mx-auto my-8`}),(0,X.jsxs)(R,{title:e(`settings.about`),children:[(0,X.jsx)(P,{label:e(`settings.serverVersion`),detail:l.data?`${l.data.version} · API ${l.data.apiVersion}`:`—`}),O&&(0,X.jsx)(P,{label:e(`settings.desktopVersion`),detail:ge()?.version||`—`}),(0,X.jsx)(On,{}),O&&(0,X.jsx)(P,{label:e(`settings.logs`),onClick:()=>void U.revealLogs(),children:(0,X.jsx)(Pe,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(P,{label:e(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Fe,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function On(){let{t:e}=T(),{toast:t}=W(),n=de(),r=i(),a=o(),s=c(),l=a.data,u=ge()?.updates??null,[d,f]=(0,Y.useState)(!1),p=()=>s.mutate(void 0,{onSuccess:n=>t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(H(e),`error`)}),m=()=>{u&&!d&&(f(!0),u.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:E.version}),n.invalidateQueries({queryKey:E.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:`settings.upToDate`))}).catch(e=>t(H(e),`error`)).finally(()=>f(!1)))},h=l?.lastCheckAt?new Date(l.lastCheckAt).toLocaleString():void 0,g=l?.available?u?e(`settings.updateAvailable`,{version:l.available}):`${e(`settings.updateAvailable`,{version:l.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{label:e(`settings.autoCheck`),detail:l&&!l.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(B,{checked:l?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(H(e),`error`)})})}),(0,X.jsxs)(P,{label:e(`settings.checkUpdates`),detail:s.isError?e(`settings.updateCheckFailed`,{error:H(s.error)}):l?.available?g:h?e(`settings.lastChecked`,{time:h}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:s.isPending,onClick:p,children:s.isPending?(0,X.jsx)(z,{className:`size-3.5`}):(0,X.jsx)(We,{className:`size-3.5`})}),u&&l?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:d,"aria-label":e(`settings.updateApply`),onClick:m,children:d?(0,X.jsx)(z,{className:`size-3.5`}):(0,X.jsx)(Ae,{className:`size-3.5`})})]})]})}function kn({settings:e}){let{t}=T(),{toast:n}=W(),r=i(),[a,o]=(0,Y.useState)(e.proxyMode),[s,c]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>o(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>c({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let l=t=>{o(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(H(e),`error`)})},u=()=>r.mutate({proxyMode:`custom`,proxyUrl:s.url.trim()||null,proxyUsername:s.username.trim()||null,proxyBypass:s.bypass.trim()||null,...s.password?{proxyPassword:s.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(H(e),`error`)}),d=a!==e.proxyMode||s.url!==(e.proxyUrl??``)||s.username!==(e.proxyUsername??``)||s.password!==``||s.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(R,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(P,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${a}.hint`),children:(0,X.jsx)(x,{ariaLabel:t(`settings.proxy.mode`),value:a,onChange:l,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`)}]})}),a===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:s.url,onChange:e=>c({...s,url:e.target.value})})}),(0,X.jsx)(P,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:s.username,onChange:e=>c({...s,username:e.target.value})})}),(0,X.jsx)(P,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:s.password,onChange:e=>c({...s,password:e.target.value})})}),(0,X.jsx)(P,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:s.bypass,onChange:e=>c({...s,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!d||!s.url.trim()||r.isPending,onClick:u,children:t(`common.save`)})})]})]})}function An({settings:e}){let{t}=T(),{toast:n}=W(),r=i(),a=e.pluginMarketUrl===``,[o,s]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>s(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let c=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(H(e),`error`)});return(0,X.jsxs)(R,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(P,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(B,{checked:a,label:t(`settings.pluginMarket.offline`),onChange:e=>c(e?``:null)})}),!a&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(k,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:o,onChange:e=>s(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:()=>c(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||o.trim()===(e.pluginMarketUrl??``),onClick:()=>c(o.trim()||null,!0),children:t(`common.save`)})]})]})]})}function jn({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{En as SettingsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fr as e,G as t,J as n,Jr as r,Jt as i,K as a,V as o,X as s,Yn as c,_ as l,at as u,c as d,ca as f,d as p,da as m,fr as h,ft as g,l as _,lr as v,n as y,nn as b,p as x,q as S,qn as C,r as w,sa as T,t as E,v as D,yr as O}from"./alert-D4IPjxz3.js";import{a as k,gt as A,i as j,n as M,o as N,r as P}from"./overlays-BX48Gd4h.js";import{t as F}from"./ellipsis-D-uqKDgA.js";import{t as I}from"./pencil-CUO0GAyP.js";import{t as L}from"./power-USlcjghz.js";import{t as R}from"./rotate-ccw-Daii8PQN.js";import{D as z,F as B,M as V,P as H,f as U,m as W,s as G,u as K}from"./index-CdtIrMPt.js";var q=m(f(),1),J=T();function Y(){let{t}=u(),n=e(),r=O(),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null);return(0,J.jsxs)(K,{title:t(`nav.tokens`),subtitle:t(`tokens.subtitle`),actions:(0,J.jsx)(w,{variant:`primary`,icon:(0,J.jsx)(V,{className:`size-3.5`}),onClick:()=>a(!0),children:t(`tokens.add`)}),children:[(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[r.data&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,J.jsx)(`p`,{children:t(`tokens.directHint`,{url:`${r.data.gatewayBaseUrl}/v1`})}),(0,J.jsx)(`p`,{className:`selectable`,children:t(`tokens.selfServiceHint`,{url:r.data.gatewayBaseUrl})})]}),n.isLoading&&(0,J.jsx)(D,{lines:4}),n.isError&&(0,J.jsx)(E,{tone:`danger`,title:t(`common.error`),children:k(n.error)}),n.data?.length===0&&(0,J.jsx)(`div`,{className:`card`,children:(0,J.jsx)(d,{icon:(0,J.jsx)(H,{className:`size-6`}),title:t(`tokens.empty`)})}),n.data&&n.data.length>0&&(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(e=>(0,J.jsx)(ee,{token:e,defaultOpen:n.data.length===1,onEdit:()=>s(e)},e.id))})]}),(0,J.jsx)(ie,{open:i,onOpenChange:a}),(0,J.jsx)(ae,{token:o,onClose:()=>s(null)})]})}function ee({token:e,defaultOpen:t,onEdit:n}){let{t:i,locale:l}=u(),{toast:d,confirm:f}=N(),p=c(),m=h(),_=r(),x=v(),C=b(),[T,E]=(0,q.useState)(t),D=(p.data??[]).find(t=>t.id===e.providerId),O=`token-detail-${e.id}`,j=(e,t)=>{d(t,`success`),e.skipped.length>0&&d(i(`tokens.skipped`,{clients:e.skipped.map(e=>U[e]?.name??e).join(`, `)}),`error`)},P=()=>m.mutate(e.id,{onSuccess:async({token:e})=>{await A.copy(e)&&d(i(`tokens.copied`))},onError:e=>d(k(e),`error`)}),V=async()=>{(!e.enabled||await f({title:i(`tokens.disableConfirm`,{name:e.name}),detail:i(`tokens.disableDetail`),confirmLabel:i(`tokens.disable`),destructive:!0}))&&_.mutate({id:e.id,enabled:!e.enabled},{onError:e=>d(k(e),`error`)})},H=async()=>{await f({title:i(`tokens.resetConfirm`,{name:e.name}),detail:i(`tokens.resetDetail`),confirmLabel:i(`tokens.reset`),destructive:!0})&&x.mutate(e.id,{onSuccess:e=>j(e,i(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>d(k(e),`error`)})},G=async()=>{await f({title:i(`tokens.deleteConfirm`,{name:e.name}),detail:i(`tokens.deleteDetail`),confirmLabel:i(`common.delete`),destructive:!0})&&C.mutate(e.id,{onSuccess:t=>j(t,i(`tokens.deleted`,{name:e.name})),onError:e=>d(k(e),`error`)})},K=e.lastUsedAt?o(e.lastUsedAt,l):i(`tokens.neverUsed`);return(0,J.jsxs)(`article`,{children:[(0,J.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,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":T,"aria-controls":O,"aria-label":i(`tokens.details`),onClick:e=>{e.stopPropagation(),E(e=>!e)},children:(0,J.jsx)(B,{className:`size-4 transition-transform ${T?`rotate-90`:``}`})}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,J.jsx)(y,{tone:`accent`,children:i(`tokens.default`)}),!e.enabled&&(0,J.jsx)(y,{tone:`orange`,children:i(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,J.jsx)(y,{tone:`orange`,children:i(`tokens.limitExhausted`)})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,J.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,J.jsx)(g,{className:`size-3.5`}),"aria-label":i(`tokens.copy`),title:i(`tokens.copy`),loading:m.isPending,onClick:P})]})]})]}),(0,J.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>U[e]?.name??e).join(`, `)||i(`tokens.noClients`),children:e.clients.length===0?(0,J.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,J.jsx)(W,{kind:e,size:16},e))}),(0,J.jsx)(X,{label:i(`tokens.today`),value:s(e.today.costUsd),context:i(`tokens.requestsContext`,{count:S(e.today.requests)})}),(0,J.jsx)(X,{label:i(`tokens.total`),value:s(e.total.costUsd),context:`${S(e.total.totalTokens,!0)} Token`}),(0,J.jsx)(X,{label:i(`tokens.lastUsedTitle`),value:e.lastUsedAt?a(e.lastUsedAt,l):`—`,context:e.lastUsedAt?``:i(`tokens.neverUsed`),title:K}),(0,J.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,J.jsx)(M,{label:i(`common.more`),icon:(0,J.jsx)(F,{className:`size-4`}),items:[{id:`settings`,label:i(`tokens.settings`),icon:(0,J.jsx)(I,{className:`size-3.5`}),onSelect:n},{id:`toggle`,label:e.enabled?i(`tokens.disable`):i(`tokens.enable`),icon:(0,J.jsx)(L,{className:`size-3.5`}),onSelect:()=>void V()},{id:`reset`,label:i(`tokens.reset`),icon:(0,J.jsx)(R,{className:`size-3.5`}),onSelect:()=>void H()},...e.isDefault?[]:[{id:`delete`,label:i(`tokens.delete`),icon:(0,J.jsx)(z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void G()}]]})})]}),T&&(0,J.jsxs)(`div`,{id:O,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,J.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:i(`tokens.clients`)}),(0,J.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:e.clients.length===0?i(`tokens.noClients`):e.clients.map(e=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,J.jsx)(W,{kind:e,size:14}),U[e]?.name??e]},e))})]}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:i(`tokens.directProvider`)}),(0,J.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:D?.name??(e.providerId?e.providerId:i(`tokens.directNone`))})]}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:i(`tokens.allowedClients`)}),(0,J.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?i(`tokens.allowedClientsAny`):e.allowedClients.length===0?i(`tokens.directOnly`):e.allowedClients.map(e=>U[e]?.name??e).join(`, `)})]}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:i(`tokens.lastUsedTitle`)}),(0,J.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:K})]})]}),(0,J.jsx)(te,{token:e}),(0,J.jsx)(re,{today:e.today,total:e.total})]})]})}function te({token:e}){let{t}=u(),n=e.limits?.rpm;return(0,J.jsxs)(`div`,{className:`mt-3`,children:[(0,J.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,J.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,J.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,J.jsx)(ne,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,J.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,J.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function ne({usage:e}){let{t,locale:n}=u(),r=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,i=t=>e.metric===`cost`?s(t):S(t,!0),a=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=a>=90?`var(--danger)`:a>=70?`var(--warning)`:`var(--accent)`;return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,J.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:r}),(0,J.jsx)(`span`,{className:`num`,children:t(`tokens.limitUsed`,{used:i(e.used),limit:i(e.limit)})})]}),(0,J.jsx)(`div`,{role:`progressbar`,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${a}%`,background:c}})}),e.resetsAt&&(0,J.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:t(`tokens.limitResets`,{time:o(e.resetsAt,n)})})]})}function X({label:e,value:t,context:n,title:r}){return(0,J.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,J.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,J.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,J.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function re({today:e,total:r}){let{t:i}=u(),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)]`,c=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,J.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,J.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,J.jsx)(`th`,{className:`${o} text-left`}),(0,J.jsx)(`th`,{className:o,children:i(`tokens.cost`)}),(0,J.jsx)(`th`,{className:o,children:i(`tokens.requests`)}),(0,J.jsx)(`th`,{className:o,children:i(`tokens.tokens`)}),(0,J.jsx)(`th`,{className:o,children:i(`tokens.inOut`)}),(0,J.jsx)(`th`,{className:o,children:i(`tokens.cacheHit`)}),(0,J.jsx)(`th`,{className:o,title:i(`tokens.tpsContext`),children:i(`tokens.tps`)})]})}),(0,J.jsx)(`tbody`,{children:a.map(([e,r])=>(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,J.jsx)(`td`,{className:`${c} font-semibold selectable`,children:s(r.costUsd)}),(0,J.jsx)(`td`,{className:c,children:S(r.requests)}),(0,J.jsx)(`td`,{className:c,children:S(r.totalTokens,!0)}),(0,J.jsxs)(`td`,{className:`${c} text-[var(--text-secondary)]`,children:[S(r.inputTokens,!0),` / `,S(r.outputTokens,!0)]}),(0,J.jsx)(`td`,{className:c,title:i(`usage.cacheAmounts`,{read:S(r.cacheReadTokens,!0),write:S(r.cacheWriteTokens,!0)}),children:r.cacheHitRate==null?`—`:t(r.cacheHitRate)}),(0,J.jsx)(`td`,{className:c,children:r.tps==null?`—`:n(r.tps)})]},e))})]})})}function Z(){let{t:e}=u(),t=(c().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function ie({open:e,onOpenChange:t}){let{t:n}=u(),{toast:r}=N(),a=i(),{options:o}=Z(),[s,c]=(0,q.useState)(``),[l,d]=(0,q.useState)(``);return(0,q.useEffect)(()=>{e&&(c(``),d(``))},[e]),(0,J.jsx)(j,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,J.jsx)(w,{variant:`primary`,disabled:!s.trim(),loading:a.isPending,onClick:()=>a.mutate({name:s.trim(),providerId:l||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(k(e),`error`)}),children:n(`common.create`)})]}),children:(0,J.jsxs)(`div`,{className:`grid gap-4`,children:[(0,J.jsx)(_,{label:n(`tokens.name`),children:(0,J.jsx)(p,{value:s,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>c(e.target.value)})}),(0,J.jsx)(_,{label:n(`tokens.directProvider`),children:(0,J.jsx)(P,{value:l,onChange:d,options:o})})]})})}function ae({token:e,onClose:t}){let{t:n}=u(),{toast:i}=N(),a=r(),{providers:o,options:s}=Z(),[c,d]=(0,q.useState)(``),[f,m]=(0,q.useState)(``),[h,g]=(0,q.useState)(``),[v,y]=(0,q.useState)([]),[b,S]=(0,q.useState)(null),[T,E]=(0,q.useState)(`any`),[D,O]=(0,q.useState)([]),A=o.find(e=>e.id===f),M=A?.authScheme===`oauth-subscription`||A?.authScheme===`plugin`,F=C(A?.id,M),I=new Set(v.map(e=>`${e.metric}:${e.period}`)).size<v.length;return(0,q.useEffect)(()=>{e&&(d(e.name),m(e.providerId??``),g(e.accountId??``),y(e.limits?.budgets.map(e=>({...e}))??[]),S(e.limits?.rpm??null),E(e.allowedClients==null?`any`:`only`),O(e.allowedClients??[]))},[e]),(0,J.jsx)(j,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,J.jsx)(w,{variant:`primary`,disabled:!c.trim()||I,loading:a.isPending,onClick:()=>{if(!e)return;let r=v.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),o=r.length>0||b!=null&&b>0?{budgets:r,rpm:b!=null&&b>0?Math.floor(b):null}:null;a.mutate({id:e.id,name:c.trim(),providerId:f||null,accountId:M&&h||null,limits:o,allowedClients:T===`any`?null:D},{onSuccess:()=>{t(),i(n(`common.saved`),`success`)},onError:e=>i(k(e),`error`)})},children:n(`common.save`)})]}),children:(0,J.jsxs)(`div`,{className:`grid gap-4`,children:[(0,J.jsx)(_,{label:n(`tokens.name`),children:(0,J.jsx)(p,{value:c,maxLength:64,onChange:e=>d(e.target.value)})}),(0,J.jsx)(_,{label:n(`tokens.directProvider`),children:(0,J.jsx)(P,{value:f,onChange:e=>{m(e),g(``)},options:s})}),M&&(0,J.jsx)(_,{label:n(`tokens.directAccount`),children:(0,J.jsx)(P,{value:h,onChange:g,options:[{value:``,label:n(`clients.accountDefault`)},...(F.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]})}),(0,J.jsx)(_,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:I?n(`tokens.limitDuplicate`):void 0,children:(0,J.jsx)(oe,{budgets:v,onChange:y})}),(0,J.jsx)(_,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,J.jsx)(x,{value:b,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:S})}),(0,J.jsx)(_,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,J.jsxs)(`div`,{className:`grid gap-2`,children:[(0,J.jsx)(l,{ariaLabel:n(`tokens.allowedClients`),value:T,onChange:E,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),T===`only`&&(0,J.jsx)(G,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(U),...D])].map(e=>({value:e,label:U[e]?.name??e})),value:D,onValueChange:e=>O(e)})]})})]})})}var Q=[`cost`,`requests`,`tokens`],$=[`day`,`week`,`month`,`total`];function oe({budgets:e,onChange:t}){let{t:n}=u(),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,J.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,J.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,J.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,J.jsx)(P,{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,J.jsx)(P,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:$.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,J.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,J.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,J.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,J.jsx)(`div`,{children:(0,J.jsx)(w,{size:`sm`,icon:(0,J.jsx)(V,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{Y as TokensPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{at as e,bt as t,ca as n,da as r,gr as i,oa as a,sa as o,si as s}from"./alert-D4IPjxz3.js";import{F as c,P as l,R as u,a as d,gt as f,o as p,z as m}from"./overlays-BX48Gd4h.js";import{t as h}from"./TrayPanelView-CQQDnzsO.js";var g=r(n(),1),_=o(),v=new Set([`astra.theme`,`astra.accent`,`astra.locale`]);function y(){let{t:n}=e(),r=a(),{toast:o}=p(),y=s(),[b]=u(),x=m(),[S,C]=(0,g.useState)(!1),[w,T]=(0,g.useState)(`overview`),E=c(b,{enabled:x.running,background:!0,live:S}),D=i(),O=(0,g.useRef)(null);(0,g.useLayoutEffect)(()=>{let e=document.documentElement;e.dataset.view=`tray`,e.style.background=`transparent`,document.body.style.background=`transparent`},[]);let k=(0,g.useCallback)(()=>{r.invalidateQueries({queryKey:[`stats`]}),r.invalidateQueries({queryKey:t.providers}),r.invalidateQueries({queryKey:t.clients}),r.invalidateQueries({queryKey:[`provider-accounts`]})},[r]);(0,g.useEffect)(()=>y?.tray.onVisibilityChanged(e=>{C(e),e&&(T(`overview`),k())}),[y,k]),(0,g.useEffect)(()=>{x.running&&k()},[x.running,k]),(0,g.useEffect)(()=>{let e=e=>{e.key&&v.has(e.key)&&window.location.reload()};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&y?.tray.command(`hide`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y]),(0,g.useLayoutEffect)(()=>{let e=O.current;if(!e||!y)return;let t=[`header`,`tabs`,`body`,`footer`].map(t=>e.querySelector(`[data-tray-part="${t}"]`)),n=()=>{let n=e.offsetHeight-e.clientHeight,r=t.reduce((e,t)=>e+(t?.offsetHeight??0),0)+n;y.tray.resize(r)},r=new ResizeObserver(n);for(let e of t)e&&r.observe(e);return n(),()=>r.disconnect()},[y]),l(b,x,E.summary,E.plans);let A=e=>void y?.tray.command(e),j=async()=>{E.settings&&await f.copy(`${E.settings.gatewayBaseUrl}/v1`)&&o(n(`common.copied`))},M=async e=>{let t=E.providers;if(t.length===0)return;let r=await f.contextMenu(t.map(t=>({id:t.id,label:t.enabled?t.name:n(`tray.disabledProvider`,{name:t.name}),type:`checkbox`,checked:t.id===e.providerId})));r&&r!==e.providerId&&D.mutate({kind:e.kind,providerId:r},{onError:e=>o(d(e),`error`)})};return(0,_.jsx)(`div`,{className:`h-full`,children:(0,_.jsx)(h,{ref:O,className:`h-full`,prefs:b,state:x,data:E,tab:w,onTabChange:T,onCommand:A,onRefresh:k,onCopyAddress:()=>void j(),onSwitchClient:e=>void M(e)})})}export{y as TrayPanelPage};
|