@aidotnet/server-linux-arm64 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-Cwjn83RD.js +11 -0
  3. package/bin/wwwroot/assets/KeyPage-IsBY88jG.js +1 -0
  4. package/bin/wwwroot/assets/ModelDetailPage-BT8_QmLF.js +1 -0
  5. package/bin/wwwroot/assets/ModelsPage-a3SNBXwe.js +1 -0
  6. package/bin/wwwroot/assets/PluginsPage-CXRMCp_F.js +2 -0
  7. package/bin/wwwroot/assets/PrivacyPage-BfdLDJ63.js +1 -0
  8. package/bin/wwwroot/assets/ProviderDetailPage-C9eabWwn.js +3 -0
  9. package/bin/wwwroot/assets/ProvidersPage-CPw-h0Uz.js +2 -0
  10. package/bin/wwwroot/assets/SettingsPage-CTnL166S.js +2 -0
  11. package/bin/wwwroot/assets/TokensPage-TPaxzBMY.js +1 -0
  12. package/bin/wwwroot/assets/TrayPanelPage-BGDBeJs0.js +1 -0
  13. package/bin/wwwroot/assets/TrayPanelView-DP-m1Cui.js +1 -0
  14. package/bin/wwwroot/assets/alert-C-zJo-Vf.js +15 -0
  15. package/bin/wwwroot/assets/{overlays-Cnf3vGpI.css → alert-DwSJjne8.css} +1 -1
  16. package/bin/wwwroot/assets/arrow-down-DTsCyVhl.js +1 -0
  17. package/bin/wwwroot/assets/arrow-left-BlStTg-u.js +1 -0
  18. package/bin/wwwroot/assets/checkbox-B8UTLROZ.js +1 -0
  19. package/bin/wwwroot/assets/cloud-download-DoCH2MAL.js +1 -0
  20. package/bin/wwwroot/assets/confirm-morph-BZdvZ-wI.js +1 -0
  21. package/bin/wwwroot/assets/download-zacBMjpe.js +1 -0
  22. package/bin/wwwroot/assets/ellipsis-Dwk6_QlF.js +1 -0
  23. package/bin/wwwroot/assets/external-link-D-L32_ye.js +1 -0
  24. package/bin/wwwroot/assets/folder-open-ex39110T.js +1 -0
  25. package/bin/wwwroot/assets/index-CNdW2eN9.js +17 -0
  26. package/bin/wwwroot/assets/index-DSv7xAxU.css +1 -0
  27. package/bin/wwwroot/assets/log-out-CZSB5kqp.js +1 -0
  28. package/bin/wwwroot/assets/overlays-BBHZHl4R.js +41 -0
  29. package/bin/wwwroot/assets/overlays-BJrN5PWt.css +1 -0
  30. package/bin/wwwroot/assets/paseo-B9ieOk6E.png +0 -0
  31. package/bin/wwwroot/assets/pencil-C7HWLb95.js +1 -0
  32. package/bin/wwwroot/assets/power-BggG52OJ.js +1 -0
  33. package/bin/wwwroot/assets/radio-cards-BWCaBwfU.js +1 -0
  34. package/bin/wwwroot/assets/rotate-ccw-Xx5_g9bd.js +1 -0
  35. package/bin/wwwroot/index.html +6 -8
  36. package/package.json +1 -1
  37. package/bin/wwwroot/assets/ClientsPage-B89Sa7jz.js +0 -11
  38. package/bin/wwwroot/assets/ModelDetailPage-CIr2VLVH.js +0 -1
  39. package/bin/wwwroot/assets/ModelsPage-DHoSwTY5.js +0 -1
  40. package/bin/wwwroot/assets/Page-CnSErb_N.js +0 -3
  41. package/bin/wwwroot/assets/Page-CsiaycmK.css +0 -1
  42. package/bin/wwwroot/assets/PluginsPage-54tF_bjG.js +0 -2
  43. package/bin/wwwroot/assets/PrivacyPage-D5paxuYA.js +0 -1
  44. package/bin/wwwroot/assets/ProviderDetailPage-DhxcWbc_.js +0 -3
  45. package/bin/wwwroot/assets/ProvidersPage-DfMcnoYT.js +0 -2
  46. package/bin/wwwroot/assets/SettingsPage-a1XhJ-l9.js +0 -1
  47. package/bin/wwwroot/assets/TokensPage-T2w5pi_o.js +0 -1
  48. package/bin/wwwroot/assets/TrayPanelPage-DOmKXJLy.js +0 -1
  49. package/bin/wwwroot/assets/TrayPanelView-BcmaqvCD.js +0 -1
  50. package/bin/wwwroot/assets/arrow-down-CXkFrvO0.js +0 -1
  51. package/bin/wwwroot/assets/arrow-up-BfREUNOR.js +0 -1
  52. package/bin/wwwroot/assets/checkbox-RGYPqY5w.js +0 -1
  53. package/bin/wwwroot/assets/cloud-download-D865MmmV.js +0 -1
  54. package/bin/wwwroot/assets/confirm-morph-DUNuG_Io.js +0 -1
  55. package/bin/wwwroot/assets/download-CMr38kbd.js +0 -1
  56. package/bin/wwwroot/assets/ellipsis-zTWIrsa4.js +0 -1
  57. package/bin/wwwroot/assets/external-link-BSHuW87X.js +0 -1
  58. package/bin/wwwroot/assets/folder-open-Ce_7X0wN.js +0 -1
  59. package/bin/wwwroot/assets/index-PfVyiY3J.js +0 -15
  60. package/bin/wwwroot/assets/index-uU60OHOr.css +0 -1
  61. package/bin/wwwroot/assets/log-out-CXVs8bJY.js +0 -1
  62. package/bin/wwwroot/assets/overlays-D1ZtG8Qn.js +0 -55
  63. package/bin/wwwroot/assets/pencil-DyidL-8l.js +0 -1
  64. package/bin/wwwroot/assets/power-CJZylS33.js +0 -1
  65. package/bin/wwwroot/assets/radio-cards-QHFaDooy.js +0 -1
  66. package/bin/wwwroot/assets/rotate-ccw-Dr0Xbikv.js +0 -1
  67. package/bin/wwwroot/assets/use-transform-DvOb1h9g.js +0 -1
@@ -0,0 +1,3 @@
1
+ import{An as e,B as t,Bn as n,Ct as r,Dr as i,En as a,Et as o,Gr as s,Gt as c,In as l,Jn as u,Kr as d,Ln as f,Nt as p,On as m,Or as h,Pn as g,Rn as _,St as v,Tr as y,Tt as ee,Un as te,V as b,Wr as x,Wt as ne,Xn as re,Yn as ie,Yr as S,_ as C,a as w,ar as ae,b as oe,bn as se,br as ce,c as T,ca as le,ct as ue,d as E,en as de,f as D,ft as fe,h as pe,hn as me,i as he,it as O,jr as ge,kn as _e,kt as ve,l as k,la as ye,ln as be,lr as xe,m as A,mn as Se,n as j,nn as Ce,nr as we,nt as Te,ot as M,p as Ee,pa as N,pn as De,pt as P,r as F,ri as I,sn as Oe,t as L,tn as ke,tr as Ae,tt as je,u as R,ua as Me,v as z,vt as B,wr as Ne,xn as Pe,xt as Fe,y as V}from"./alert-C-zJo-Vf.js";import{a as H,i as U,n as Ie,o as W,r as G}from"./overlays-BBHZHl4R.js";import{t as Le}from"./arrow-down-DTsCyVhl.js";import{t as K}from"./arrow-left-BlStTg-u.js";import{t as q}from"./cloud-download-DoCH2MAL.js";import{t as Re}from"./download-zacBMjpe.js";import{t as J}from"./ellipsis-Dwk6_QlF.js";import{t as Y}from"./external-link-D-L32_ye.js";import{n as ze}from"./radio-cards-BWCaBwfU.js";import{t as Be}from"./log-out-CZSB5kqp.js";import{t as Ve}from"./power-BggG52OJ.js";import{t as He}from"./rotate-ccw-Xx5_g9bd.js";import{B as Ue,D as X,G as We,M as Ge,P as Ke,W as qe,a as Je,b as Ye,f as Xe,o as Ze,s as Qe,u as Z,v as $e,x as et,y as tt,z as nt}from"./index-CNdW2eN9.js";import{t as rt}from"./checkbox-B8UTLROZ.js";import{t as it}from"./confirm-morph-BZdvZ-wI.js";import{AUTH_OPTIONS as at,PROTOCOL_OPTIONS as ot,n as st,r as ct,t as lt}from"./ProvidersPage-CPw-h0Uz.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=B(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=B(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=B(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=B(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=B(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=B(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=B(St),Q=N(Me(),1),$=ye(),wt={imported:`providers.subscription.importBatchStatus.imported`,updated:`providers.subscription.importBatchStatus.updated`,duplicate:`providers.subscription.importBatchStatus.duplicate`,invalid_format:`providers.subscription.importBatchStatus.invalid_format`,failed:`providers.subscription.importBatchStatus.failed`,ready:`providers.subscription.importBatchStatus.ready`},Tt={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Et={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function Dt(e){return e.split(/[,\s]+/).flatMap(e=>{let t=e.replace(/^["']+|["']+$/g,``);return t.startsWith(`tid=`)||t.startsWith(`exp=`)?[t]:t.split(`;`)}).filter(e=>e.replace(/^["']+|["']+$/g,``).length>0).length}function Ot(e){let t=e.trim();if(t.length===0)return 0;if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e.filter(e=>typeof e==`object`&&!!e||typeof e==`string`&&e.trim().length>0).length;if(typeof e==`object`&&e)return 1}catch{}let n=0;for(let t of e.split(`
2
+ `)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:Dt(e))}return n}function kt({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=M(),{toast:o}=W(),s=De(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)(oe,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(E,{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)(F,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>y(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(F,{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)(j,{tone:Tt[e.status],children:a(wt[e.status])}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.credential.${e.kind}`)}),(0,$.jsx)(`span`,{className:`selectable min-w-0 flex-1 break-words text-[var(--text-secondary)]`,children:e.account?.displayName&&(e.status===`imported`||e.status===`updated`)?`${e.account.displayName}${e.message?` · ${e.message}`:``}`:e.message??``})]},e.index))})]})]})})}function At(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var jt={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},Mt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Nt(e,t){let n=(e??``).toLowerCase(),r=t?`110,115,135`:/max|ultra/.test(n)?`47,124,246`:/pro|plus|premium/.test(n)?`52,195,143`:/team|business|enterprise|allegro|vivace/.test(n)?`130,100,230`:`110,115,135`;return`linear-gradient(135deg, rgba(${r},.34), rgba(${r},.08))`}function Pt({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s}){let{t:c,locale:l}=M(),u=At(e),d=e.displayName||e.accountEmail||e.keyMasked||e.id,f=e.kind===`api_key`,p=e.plan?.trim(),m=u===`cooling`?{text:c(`providers.subscription.cooldown`,{when:b(e.cooldownUntilUtc,l)}),tone:`var(--warning)`}:u===`dead`?{text:e.lastError||c(Mt[e.status]),tone:`var(--danger)`}:f?{text:e.keyMasked??c(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:c(`providers.accounts.expiresAt`,{when:b(e.expiresAtUtc,l)}),tone:void 0}:null,h=[{id:`activate`,label:c(`providers.subscription.activate`),icon:(0,$.jsx)(dt,{className:`size-3.5`}),disabled:e.isCurrent||u===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:c(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(Ve,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:c(`providers.subscription.moveUp`),icon:(0,$.jsx)(nt,{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)(He,{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)(X,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],g=c(u===`disabled`?`providers.subscription.disabled`:Mt[e.status]),_=c(f?`providers.accounts.kind.api_key`:`providers.accounts.kind.oauth`),v=e.quota?.session?.usedPercent!=null||e.quota?.weekly?.usedPercent!=null||e.quota?.credits?.usedPercent!=null;return(0,$.jsxs)(`div`,{"data-testid":`account-card`,className:O(`group card relative flex aspect-square min-w-0 cursor-pointer flex-col overflow-hidden transition-colors hover:bg-[var(--fill)]`,e.isCurrent&&`ring-1 ring-[var(--accent)]`,r&&`bg-[var(--accent-subtle)]`,u===`disabled`&&`opacity-55`),onClick:()=>i?a(e.id):n.open(e),children:[(0,$.jsxs)(`div`,{className:`relative shrink-0 px-3 pb-3 pt-2.5`,style:{background:Nt(p,f)},children:[(u===`cooling`||u===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:jt[u]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:O(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(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)(fe,{className:`size-3.5`,"aria-label":c(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Ie,{iconOnly:!0,label:c(`common.more`),icon:(0,$.jsx)(J,{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)(F,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:c(`providers.subscription.relogin`)})]}):(0,$.jsx)(It,{quota:e.quota??null,pending:s})]})]})}var Ft=10;function It({quota:e,pending:t}){let{t:n,locale:r}=M(),i=[];return e?.session?.usedPercent!=null&&i.push({key:`session`,label:e.session.windowMinutes?`${Math.round(e.session.windowMinutes/60)}h`:n(`providers.accounts.quotaShortSession`),percent:e.session.usedPercent,reset:e.session.resetsAtUtc}),e?.weekly?.usedPercent!=null&&i.push({key:`weekly`,label:n(`providers.accounts.quotaShortWeekly`),percent:e.weekly.usedPercent,reset:e.weekly.resetsAtUtc}),i.length<2&&e?.credits?.usedPercent!=null&&i.push({key:`credits`,label:n(e.entitlement==null?`providers.accounts.quotaShortCredits`:`providers.accounts.quotaShortPremium`),percent:e.credits.usedPercent,reset:e.credits.resetsAtUtc}),i.length===0?null:(0,$.jsx)(`div`,{className:O(`mt-auto flex flex-col gap-2 pt-2`,t&&`opacity-60`),children:i.slice(0,2).map(e=>{let t=Math.max(0,Math.min(100,Math.round(e.percent))),i=t>=90?`var(--danger)`:t>=70?`var(--warning)`:`var(--accent)`,a=Math.round(t/100*Ft),o=e.reset?n(`providers.subscription.quotaResets`,{when:b(e.reset,r)}):void 0;return(0,$.jsxs)(`div`,{className:`min-w-0`,title:o,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[t,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-label":e.label,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,className:`mt-0.5 flex gap-[3px]`,children:Array.from({length:Ft},(e,t)=>(0,$.jsx)(`i`,{className:`h-[5px] flex-1 rounded-[2px] bg-[var(--surface-muted)]`,style:t<a?{background:i}:void 0},t))})]},e.key)})})}function Lt({quota:e,className:t}){let{t:n,locale:r}=M(),i=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:n(`providers.subscription.quotaResets`,{when:t.toLocaleString(r)})},a=[];e.session?.usedPercent!=null&&a.push({key:`session`,label:n(`providers.subscription.quotaWindowSession`),window:e.session}),e.weekly?.usedPercent!=null&&a.push({key:`weekly`,label:n(`providers.subscription.quotaWindowWeekly`),window:e.weekly}),e.credits?.usedPercent!=null&&a.push({key:`credits`,label:e.entitlement==null?n(`providers.subscription.quotaWindowCredits`):n(`providers.subscription.quotaWindowPremium`),window:{usedPercent:e.credits.usedPercent,resetsAtUtc:e.credits.resetsAtUtc??null}});let o=e.credits?.prepaidBalance==null?null:n(`providers.subscription.quotaBalance`,{balance:e.credits.prepaidBalance}),s=e.entitlement!=null&&e.entitlement>=0?[n(`providers.subscription.quotaPremiumCount`,{used:Math.max(0,(e.entitlement??0)-(e.remaining??0)),total:e.entitlement}),e.overageUsed?n(`providers.subscription.quotaOverage`,{count:e.overageUsed}):null,e.overagePermitted===!1?n(`providers.subscription.quotaOverageOff`):null].filter(Boolean).join(` · `):null,c=e.planLabel??(e.fetchedAtUtc?n(`providers.subscription.quotaFetchedAt`,{when:new Date(e.fetchedAtUtc).toLocaleString(r)}):null);return(0,$.jsx)(`div`,{className:O(`px-4 py-1`,t),children:(0,$.jsxs)(`div`,{className:`card flex flex-col gap-3 p-3`,children:[(c||o)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] text-[var(--text-secondary)]`,children:[c&&(0,$.jsx)(`span`,{children:c}),o&&(0,$.jsx)(`span`,{children:o})]}),a.length===0?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.subscription.quotaNoWindows`)}):a.map(e=>(0,$.jsx)(Rt,{label:e.label,window:e.window,reset:i(e.window.resetsAtUtc)},e.key)),s&&(0,$.jsx)(`div`,{className:`text-[10.5px] text-[var(--text-muted)]`,children:s})]})})}function Rt({label:e,window:t,reset:n}){let r=Math.max(0,Math.min(100,Math.round(t.usedPercent??0))),[i,a]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches){a(r);return}let e=requestAnimationFrame(()=>a(r));return()=>cancelAnimationFrame(e)},[r]);let o=r>=90?`var(--danger)`:r>=70?`var(--warning)`:`var(--accent)`,s=t.windowMinutes?Math.round(t.windowMinutes/60):null;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,$.jsxs)(`span`,{className:`text-[var(--text-secondary)]`,children:[e,s!=null&&(0,$.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[` · `,s,`h`]})]}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[r,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":e,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface-muted)]`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-[width] duration-500 ease-out`,style:{width:`${i}%`,background:o}})}),n&&(0,$.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n})]})}var zt={available:`green`,redeemed:`neutral`,expired:`orange`};function Bt({account:e,providerId:t}){let{t:n}=M(),{toast:r,confirm:i}=W(),a=xe(e.id,e.status===`active`),o=c(t),s=a.data?.credits??[],l=a.data?.available_count??s.filter(e=>e.status===`available`).length,u=async t=>{await i({title:n(`providers.subscription.credits.consumeConfirm`,{title:t.title??t.reset_type??``}),detail:n(`providers.subscription.credits.consumeDetail`),confirmLabel:n(`providers.subscription.credits.consume`),destructive:!0})&&o.mutate({accountId:e.id,creditId:t.id},{onSuccess:()=>r(n(`providers.subscription.credits.consumed`),`success`),onError:e=>r(e instanceof I&&e.status===409?H(e):`${n(`providers.subscription.credits.consumeFailed`)}:${H(e)}`,`error`)})};return(0,$.jsxs)(R,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(z,{className:`my-4`}),a.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.unavailable`)}),a.data&&s.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.none`)}),s.map(e=>{let t=e.status!==`available`;return(0,$.jsxs)(A,{className:O(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pt,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?n(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?n(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?n(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(j,{tone:zt[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ct,{className:`size-3.5`}),disabled:t,loading:o.isPending&&o.variables?.creditId===e.id,onClick:()=>void u(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:l})})]})}var Vt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Ht({provider:e,account:t,index:n,actions:r,onClose:i}){let{t:a,locale:o}=M(),{toast:c}=W(),l=s(e.id),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``);if((0,Q.useEffect)(()=>{d(t?.displayName??``),p(t?.httpProxy??``)},[t?.id,t?.displayName,t?.httpProxy]),!t)return(0,$.jsx)(U,{open:!1,onOpenChange:i,title:``});let m=At(t),h=t.kind===`api_key`,g=e.templateId===`openai-subscription`,_=e.httpProxy||a(`providers.accounts.proxyFallbackSystem`),v=e=>e?b(e,o):`—`,y=(e,n)=>l.mutate({id:t.id,...e},{onSuccess:()=>c(a(n),`success`),onError:e=>c(H(e),`error`)});return(0,$.jsx)(U,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,a(h?`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)(F,{size:`sm`,icon:(0,$.jsx)(dt,{className:`size-3.5`}),disabled:t.isCurrent||m===`dead`,onClick:()=>r.activate(t),children:a(`providers.subscription.activate`)}),(0,$.jsx)(F,{size:`sm`,icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:m===`dead`,onClick:()=>r.refreshQuota(t),children:a(`providers.subscription.quotaRefresh`)}),!h&&(0,$.jsx)(F,{size:`sm`,icon:(0,$.jsx)(He,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:a(`providers.subscription.refreshToken`)}),!h&&t.status!==`active`&&(0,$.jsx)(F,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:a(`providers.subscription.relogin`)}),(0,$.jsx)(F,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>r.remove(t),children:a(`providers.subscription.logout`)})]}),m===`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)(E,{className:`flex-1`,label:a(`providers.accounts.detail.name`),value:u,onChange:e=>d(e.target.value)}),(0,$.jsx)(F,{disabled:u.trim().length===0||u.trim()===t.displayName,loading:l.isPending&&l.variables?.displayName!==void 0,onClick:()=>y({displayName:u.trim()},`providers.accounts.renamed`),children:a(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(E,{className:`flex-1`,mono:!0,label:a(`providers.accounts.detail.proxy`),placeholder:_,value:f,onChange:e=>p(e.target.value)}),(0,$.jsx)(F,{disabled:f.trim()===(t.httpProxy??``),loading:l.isPending&&l.variables?.httpProxy!==void 0,onClick:()=>y({httpProxy:f.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:_})})]}),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})]}),g&&m!==`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)(D,{label:a(`providers.accounts.detail.status`),children:(0,$.jsx)(j,{tone:m===`usable`?`green`:m===`cooling`?`orange`:m===`dead`?`red`:`neutral`,children:a(m===`disabled`?`providers.subscription.disabled`:Vt[t.status])})}),t.source&&(0,$.jsx)(D,{label:a(`providers.accounts.detail.source`),children:a(`providers.accounts.source.${t.source}`)}),h?(0,$.jsx)(D,{label:a(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(D,{label:a(`providers.accounts.detail.expires`),children:v(t.expiresAtUtc)}),(0,$.jsx)(D,{label:a(`providers.accounts.detail.lastRefresh`),children:v(t.lastRefreshAtUtc)})]}),m===`cooling`&&(0,$.jsx)(D,{label:a(`providers.accounts.filter.cooling`),children:v(t.cooldownUntilUtc)}),(0,$.jsx)(D,{label:a(`providers.accounts.detail.order`),children:a(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(D,{label:a(`providers.accounts.detail.created`),children:v(t.createdAt)}),t.lastError&&m!==`dead`&&(0,$.jsx)(D,{label:a(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function Ut({provider:e}){let{t}=M(),{toast:n}=W(),r=e.authScheme===`oauth-subscription`,i=h(e.id,r),a=S(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(H(e),`error`)}),c=o.claudeSubscription||o.clientPolicy===`claude-code-only`;return!c&&!o.claudeSubscription?null:(0,$.jsxs)(R,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[c&&(0,$.jsx)(A,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:o.clientPolicy===`claude-code-only`,disabled:a.isPending,onChange:e=>s({clientPolicy:e?`claude-code-only`:`any`})})}),o.claudeSubscription&&(0,$.jsx)(A,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(V,{label:t(`providers.subscription.policy.mimic`),checked:o.mimicClaudeCode,disabled:a.isPending,onChange:e=>s({mimicClaudeCode:e})})}),c&&o.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:o.mimicClaudeCode?(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(L,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Wt=[{value:`all`,label:`providers.accounts.filter.all`},{value:`usable`,label:`providers.accounts.filter.usable`},{value:`cooling`,label:`providers.accounts.filter.cooling`},{value:`dead`,label:`providers.accounts.filter.dead`},{value:`disabled`,label:`providers.accounts.filter.disabled`}],Gt=3e5;function Kt({provider:e}){let{t}=M(),{toast:r,confirm:i}=W(),a=le(),c=e.authScheme===`oauth-subscription`,l=ie(e.id,c),u=h(e.id,c),d=S(e.id),f=ee(e.id,c),p=y(e.id),m=n(e.id),g=ne(e.id),_=be(e.id),v=Ae(e.id),te=ke(e.id),b=o(e.id),x=s(e.id),re=ae(e.id),C=e.templateId===`openai-subscription`,w=se(c&&C),oe=Se(e.id),ce=e.templateId===`github-copilot-subscription`,T=Pe(c&&ce),ue=me(e.id),[de,D]=(0,Q.useState)(`all`),[fe,he]=(0,Q.useState)(``),[ge,_e]=(0,Q.useState)(new Set),[ve,k]=(0,Q.useState)(null),[ye,xe]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(!1),[Ce,we]=(0,Q.useState)(``),[Te,Ee]=(0,Q.useState)(!1),[N,De]=(0,Q.useState)(!1),[P,Oe]=(0,Q.useState)(null),[je,R]=(0,Q.useState)(null),[Me,B]=(0,Q.useState)(!1),[Ne,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),_.mutate(e.id,{onError:()=>{}}))}},[K,c]),(0,Q.useEffect)(()=>{let e=new Set(K.map(e=>e.id));_e(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),ve&&!e.has(ve)&&k(null)},[K,ve]),(0,Q.useEffect)(()=>{if(!N||P?.mode!==`pkce`)return;let e=setInterval(()=>void l.refetch(),3e3);return()=>clearInterval(e)},[N,P,l]),(0,Q.useEffect)(()=>{if(!N||P?.mode!==`pkce`)return;let e=K.find(e=>!G.current.has(e.id));e&&J(!0,e.displayName||e.accountEmail||e.id)},[K,N,P]),(0,Q.useEffect)(()=>{if(!N||P?.mode!==`device`&&P?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await m.mutateAsync(P.state);if(e)return;t=0,n.status===`done`?J(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&J(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof I&&(n.status===404||n.status===400)){J(!1,void 0,H(n));return}++t>=5&&J(!1,void 0,H(n))}},r=setInterval(()=>void n(),Math.max(P.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[N,P]),!c)return null;let q=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,J=(n,i,o)=>{if(a.invalidateQueries({queryKey:Fe.providerAccounts(e.id)}),n){Oe(null),R(null),De(!1),r(t(`providers.subscription.loginOk`,{name:i??``}),`success`);return}o&&R(o)},Y=(e,n)=>{G.current=new Set(K.map(e=>e.id)),R(null),p.mutate({accountId:e,httpProxy:n},{onSuccess:e=>{j(!1),Oe(e),De(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof I&&e.details?.needsVerification?r(t(`providers.subscription.needsVerification`),`error`):r(H(e),`error`)}})},ze=async()=>{if(P){B(!0);try{let e=await m.mutateAsync(P.state);e.status===`done`?J(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?r(t(`providers.subscription.stillWaiting`),`info`):J(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof I&&e.status===404){let t=((await l.refetch()).data??[]).find(e=>!G.current.has(e.id));t?J(!0,t.displayName||t.accountEmail||t.id):J(!1,void 0,H(e))}else J(!1,void 0,H(e))}finally{B(!1)}}},Be=async()=>{if(P&&P.mode===`paste`&&Ne.trim().length!==0){B(!0);try{let e=await g.mutateAsync({state:P.state,code:Ne.trim()});e.status===`done`?(V(``),J(!0,e.account.displayName||e.account.accountEmail||e.account.id)):J(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){J(!1,void 0,H(e))}finally{B(!1)}}},He=()=>oe.mutate(void 0,{onSuccess:e=>{r(t(`providers.subscription.importOk`,{name:q(e.account)}),e.warning?`info`:`success`),e.warning&&r(e.warning,`error`),w.refetch()},onError:e=>r(H(e),`error`)}),Ue=()=>ue.mutate(``,{onSuccess:e=>{r(t(`providers.subscription.importOk`,{name:q(e.account)}),e.warning?`info`:`success`),e.warning&&r(e.warning,`error`)},onError:e=>r(H(e),`error`)}),We=(e,t)=>{let n=K.map(e=>e.id),i=e+t;i<0||i>=n.length||([n[e],n[i]]=[n[i],n[e]],re.mutate(n,{onError:e=>r(H(e),`error`)}))},qe=async e=>{let n=q(e);await i({title:t(`providers.subscription.logoutConfirm`,{name:n}),destructive:!0,confirmLabel:t(`providers.subscription.logout`)})&&te.mutate(e.id,{onError:e=>r(H(e),`error`)})},Je={open:e=>k(e.id),activate:e=>b.mutate(e.id,{onSuccess:()=>r(t(`providers.subscription.activated`,{name:q(e)}),`success`),onError:e=>r(H(e),`error`)}),toggleEnabled:e=>x.mutate({id:e.id,enabled:!e.enabled},{onError:e=>r(H(e),`error`)}),refreshQuota:e=>_.mutate(e.id,{onError:e=>{e instanceof I&&e.status===501?r(t(`providers.subscription.quotaUnsupported`),`error`):r(H(e),`error`)}}),refreshToken:e=>v.mutate(e.id,{onSuccess:()=>r(t(`providers.subscription.tokenRefreshed`),`success`),onError:e=>r(H(e),`error`)}),relogin:e=>Y(e.id),remove:e=>void qe(e)},Ye=e=>_e(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Xe=async n=>{let i=K.filter(e=>ge.has(e.id));Ee(!0);let o=0;for(let e of i)try{await n(e),o++}catch(t){r(`${q(e)}: ${H(t)}`,`error`)}Ee(!1),_e(new Set),a.invalidateQueries({queryKey:Fe.providerAccounts(e.id)}),o>0&&r(t(`providers.accounts.bulkDone`,{n:o}),`success`)},Ze=async()=>{await i({title:t(`providers.accounts.bulkDeleteConfirm`,{n:ge.size}),detail:t(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&await Xe(e=>te.mutateAsync(e.id))},Qe=K.map(e=>At(e)),Z=e=>e===`all`?K.length:Qe.filter(t=>t===e).length,$e=fe.trim().toLowerCase(),et=K.map((e,t)=>({a:e,index:t,state:Qe[t]})).filter(({a:e,state:t})=>(de===`all`||t===de)&&($e.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes($e)))),tt=K.find(e=>e.id===ve)??null,nt=f.data,rt=ge.size>0,it=[{id:`login`,label:t(`providers.accounts.addLogin`),icon:(0,$.jsx)(_t,{className:`size-3.5`}),onSelect:()=>Y()},{id:`login-proxy`,label:t(`providers.accounts.addLoginProxy`),onSelect:()=>j(!0)},...C&&w.data?.available?[{id:`codex`,separatorBefore:!0,label:t(`providers.subscription.importCodex`),icon:(0,$.jsx)(Re,{className:`size-3.5`}),onSelect:He}]:[],...ce?[{id:`copilot`,separatorBefore:!0,label:t(`providers.subscription.importCopilot`),icon:(0,$.jsx)(Re,{className:`size-3.5`}),onSelect:Ue}]:[],...nt?.supported?[{id:`token`,separatorBefore:!(C&&w.data?.available)&&!ce,label:t(`providers.accounts.addToken`),onSelect:()=>xe(`token`)}]:[],...nt?.apiKey?[{id:`apikey`,label:t(`providers.accounts.addApiKey`),icon:(0,$.jsx)(Ke,{className:`size-3.5`}),onSelect:()=>xe(`apiKey`)}]:[]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`card mb-3 flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`mr-auto flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[var(--text)]`,children:t(`providers.accounts.statTotal`,{n:K.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:t(`providers.accounts.statUsable`,{n:Z(`usable`)})}),Z(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:t(`providers.accounts.statCooling`,{n:Z(`cooling`)})}),Z(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:t(`providers.accounts.statDead`,{n:Z(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.accounts.providerProxy`,{proxy:e.httpProxy||t(`providers.accounts.proxyFallbackSystem`)})})]}),u.data&&(0,$.jsx)(qt,{policy:u.data,onChange:e=>d.mutate({switchMode:e},{onError:e=>r(H(e),`error`)})})]}),u.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:t(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)(pe,{className:`w-52`,value:fe,onChange:he,placeholder:t(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":t(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Wt.filter(e=>e.value===`all`||Z(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":de===e.value,onClick:()=>D(e.value),className:O(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,de===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[t(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:Z(e.value)})]},e.value))}),nt?.supported&&(0,$.jsx)(F,{size:`sm`,icon:(0,$.jsx)(ht,{className:`size-3.5`}),onClick:()=>xe(`batch`),children:t(`providers.accounts.batchImport`)}),(0,$.jsx)(Ie,{label:t(`providers.accounts.add`),icon:(0,$.jsx)(Ge,{className:`size-3.5`}),items:it})]}),C&&w.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[t(`providers.subscription.localCodexFound`,{who:w.data.accountEmail??w.data.plan??t(`providers.subscription.unknownAccount`)}),w.data.detail?` · ${w.data.detail}`:``]}),ce&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[T.data?.available?t(`providers.subscription.localCopilotFound`,{source:T.data.source??``}):t(`providers.subscription.localCopilotHint`),T.data?.detail?` · ${T.data.detail}`:``]}),l.isLoading?(0,$.jsx)(z,{className:`my-4`}):K.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Y(),className:`flex w-full flex-col items-center gap-1 rounded-[var(--radius-card,12px)] border border-dashed border-[var(--border)] px-4 py-6 text-[12px] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--text)]`,children:[(0,$.jsx)(`span`,{children:t(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(Ge,{className:`size-3.5`}),` `,t(`providers.subscription.login`)]})]}):et.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:t(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:et.map(({a:e,index:t})=>(0,$.jsx)(Pt,{account:e,index:t,actions:Je,selected:ge.has(e.id),selecting:rt,onToggleSelect:Ye,quotaPending:_.isPending&&_.variables===e.id,onMove:K.length>1?{up:t>0?()=>We(t,-1):void 0,down:t<K.length-1?()=>We(t,1):void 0}:void 0},e.id))}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:t(`providers.subscription.footer`)}),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:t(`providers.accounts.selected`,{n:ge.size})}),(0,$.jsx)(F,{size:`sm`,icon:(0,$.jsx)(Ve,{className:`size-3.5`}),disabled:Te,onClick:()=>void Xe(e=>x.mutateAsync({id:e.id,enabled:!0})),children:t(`providers.subscription.enable`)}),(0,$.jsx)(F,{size:`sm`,disabled:Te,onClick:()=>void Xe(e=>x.mutateAsync({id:e.id,enabled:!1})),children:t(`providers.subscription.disable`)}),(0,$.jsx)(F,{size:`sm`,disabled:Te,onClick:()=>void Xe(e=>_.mutateAsync(e.id)),children:t(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(F,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(X,{className:`size-3.5`}),disabled:Te,onClick:()=>void Ze(),children:t(`common.delete`)}),(0,$.jsx)(F,{size:`sm`,variant:`plain`,onClick:()=>_e(new Set),children:t(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(Ut,{provider:e})}),(0,$.jsx)(Ht,{provider:e,account:tt,index:tt?K.indexOf(tt):0,actions:Je,onClose:()=>k(null)}),nt&&(0,$.jsx)(kt,{providerId:e.id,info:nt,mode:ye,providerProxy:e.httpProxy,onClose:()=>xe(null)}),(0,$.jsx)(U,{open:A,onOpenChange:j,title:t(`providers.accounts.loginProxyTitle`),description:t(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(F,{variant:`primary`,loading:p.isPending,disabled:Ce.trim().length===0,onClick:()=>Y(void 0,Ce),children:t(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(E,{mono:!0,label:t(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:Ce,onChange:e=>we(e.target.value)})}),(0,$.jsxs)(U,{open:N,onOpenChange:e=>{De(e),e||(Oe(null),R(null))},title:t(`providers.subscription.login`),description:t(`providers.subscription.loginDesc`),children:[je&&(0,$.jsx)(L,{tone:`danger`,title:t(`providers.subscription.loginFailed`),children:je}),P?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:t(`providers.subscription.pasteTitle`),children:t(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(F,{onClick:()=>window.open(P.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(E,{mono:!0,value:Ne,onChange:e=>V(e.target.value),placeholder:t(`providers.subscription.pastePlaceholder`),"aria-label":t(`providers.subscription.pasteCode`)}),(0,$.jsx)(F,{variant:`primary`,loading:Me,onClick:()=>void Be(),children:t(`providers.subscription.pasteSubmit`)})]}),P?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(F,{onClick:()=>window.open(P.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)}),(0,$.jsx)(F,{variant:`primary`,onClick:()=>{a.invalidateQueries({queryKey:Fe.providerAccounts(e.id)}),l.refetch()},children:t(`providers.subscription.doneAuthorize`)})]})]}),P?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(L,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.cliDetail`)}),(0,$.jsx)(F,{onClick:()=>window.open(P.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})]}),P?.mode===`device`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-secondary)]`,children:t(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:P.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[P.verificationUrl&&(0,$.jsx)(F,{onClick:()=>window.open(P.verificationUrl??void 0,`_blank`,`noopener`),children:t(`providers.subscription.visitPage`)}),(0,$.jsx)(F,{variant:`primary`,loading:Me,onClick:()=>void ze(),children:t(`providers.subscription.checkNow`)})]}),(0,$.jsx)(L,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.checkNowHint`)})]})]})]})}function qt({policy:e,onChange:t}){let{t:n}=M();return(0,$.jsx)(C,{ariaLabel:n(`providers.subscription.policy.switchMode`),value:e.switchMode,onChange:t,items:[{value:`manual`,label:n(`providers.subscription.policy.manual`)},{value:`failover`,label:n(`providers.subscription.policy.failover`)},{value:`balanced`,label:n(`providers.subscription.policy.balanced`)}]})}function Jt({provider:e}){let{t}=M(),n=ie(e.id),r=g(e.id),i=h(e.id,!0),a=S(e.id),{toast:o}=W(),[s,c]=(0,Q.useState)(null);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r.isLoading&&(0,$.jsx)(z,{lines:1}),r.isError&&(0,$.jsx)(L,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:H(r.error)}),r.data?.map(e=>(0,$.jsx)(F,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(Ke,{className:`size-3.5`}):(0,$.jsx)(_t,{className:`size-3.5`}),onClick:()=>c(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(z,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(T,{icon:(0,$.jsx)(yt,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&i.data&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-1`,children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:t(i.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:i.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsx)(qt,{policy:i.data,onChange:e=>a.mutate({switchMode:e},{onError:e=>o(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}),s&&(0,$.jsx)(Zt,{provider:e,method:s,onClose:()=>c(null)})]})}function Yt({provider:t}){let{t:n,locale:r}=M(),{toast:i}=W(),a=_e(t.id),o=e(t.id);if(!a.data?.supported)return null;let s=e=>o.mutate(e,{onError:e=>i(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:n(`pluginAccounts.checkin`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:n(`pluginAccounts.checkinDetail`)})]}),(0,$.jsx)(V,{checked:a.data.on,label:n(`pluginAccounts.checkinOn`),onChange:e=>s(e)}),(0,$.jsx)(F,{size:`sm`,loading:o.isPending,onClick:()=>s(),children:n(`pluginAccounts.checkinNow`)})]}),a.data.accounts.map(e=>{let t=[e.credit?n(`pluginAccounts.credit`,{credit:e.credit}):null,e.streak?n(`pluginAccounts.streak`,{days:e.streak}):null,e.message,e.at?b(e.at,r):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}),t.length>0&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-[var(--text-secondary)]`,children:t.join(` · `)}),e.outcome?(0,$.jsx)(j,{tone:c[e.outcome]??`neutral`,children:n(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(j,{children:n(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function Xt({provider:e,account:t}){let{t:n,locale:r}=M(),{toast:i,confirm:a}=W(),o=f(e.id),[s,c]=(0,Q.useState)(!1),l=e.settings?.plugin?.usage===!0,u=_(e.id,t.id,s),d=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)(j,{tone:`accent`,children:n(`pluginAccounts.current`)}),(0,$.jsx)(j,{tone:t.status===`active`?`green`:`red`,children:n(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),l&&(0,$.jsx)(F,{size:`sm`,onClick:()=>c(e=>!e),children:n(`pluginAccounts.usage`)}),(0,$.jsx)(F,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(Be,{className:`size-3.5`}),onClick:()=>void d(),children:n(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:n(`pluginAccounts.lapsedDetail`)}),s&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[u.isLoading&&(0,$.jsx)(z,{lines:2}),u.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:H(u.error)}),u.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:u.data.error}),u.data?.plan&&(0,$.jsx)(D,{label:n(`pluginAccounts.plan`),children:u.data.plan}),u.data?.until&&(0,$.jsx)(D,{label:n(`pluginAccounts.until`),children:b(u.data.until,r)}),u.data?.windows?.map(e=>(0,$.jsxs)(D,{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:a}=M(),{toast:o}=W(),[s,c]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(void 0),[f,p]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[_,y]=(0,Q.useState)(``),[ee,te]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),ne=Ne(e.id),re=m(e.id),ie=i(e.id),S=l(e.id,b).data;(0,Q.useEffect)(()=>{let n=!0;return v(e.id,t.index,s).then(e=>{n&&(d(e.prompt),p(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&o(H(e),`error`)),()=>{n=!1}},[e.id,t.index,s,o]),(0,Q.useEffect)(()=>{S?.state===`done`&&(o(a(`pluginAccounts.signedIn`),`success`),n())},[S?.state,n,a,o]);let C=async()=>{if(!u)return;let n=await r(e.id,t.index,u.key,f).catch(()=>({error:null}));if(n.error)return g(n.error);g(null),c(e=>({...e,[u.key]:f}))};return(0,$.jsxs)(U,{open:!0,onOpenChange:e=>!e&&n(),title:a(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[u===void 0&&(0,$.jsx)(z,{lines:2}),u&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:u.message,error:h??void 0,children:u.type===`select`?(0,$.jsx)(G,{value:f,onChange:p,options:(u.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(E,{value:f,placeholder:u.placeholder??void 0,onChange:e=>p(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(F,{variant:`primary`,onClick:()=>void C(),children:a(`pluginAccounts.continue`)})})]}),u===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:a(`pluginAccounts.key`),children:(0,$.jsx)(E,{mono:!0,type:`password`,value:_,placeholder:t.placeholder??void 0,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(F,{variant:`primary`,disabled:!_.trim()||re.isPending,onClick:()=>re.mutate({method:t.index,inputs:s,key:_},{onSuccess:()=>(o(a(`pluginAccounts.signedIn`),`success`),n()),onError:e=>o(H(e),`error`)}),children:a(`pluginAccounts.signIn`)})})]}),u===null&&t.type!==`api`&&!S&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(F,{variant:`primary`,icon:(0,$.jsx)(Y,{className:`size-3.5`}),disabled:ne.isPending,onClick:()=>ne.mutate({method:t.index,inputs:s},{onSuccess:e=>{x(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>o(H(e),`error`)}),children:a(`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)(D,{label:a(`pluginAccounts.deviceCode`),mono:!0,children:S.deviceCode}),S.url&&(0,$.jsx)(F,{icon:(0,$.jsx)(Y,{className:`size-3.5`}),onClick:()=>window.open(S.url,`_blank`,`noopener`),children:a(`pluginAccounts.openAgain`)}),S.state===`waiting`&&S.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:a(`pluginAccounts.code`),children:(0,$.jsx)(E,{mono:!0,value:ee,onChange:e=>te(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(F,{variant:`primary`,disabled:!ee.trim()||ie.isPending,onClick:()=>ie.mutate({flow:S.id,code:ee.trim()},{onError:e=>o(H(e),`error`)}),children:a(`pluginAccounts.signIn`)})})]}),S.state===`waiting`&&!S.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`pluginAccounts.waiting`)}),S.state===`failed`&&(0,$.jsx)(L,{tone:`danger`,title:a(`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}=M(),{id:t=``}=We(),n=qe(),r=u(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=re(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(Z,{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 d=r.data;return(0,$.jsx)(Z,{title:d?d.name:``,subtitle:d?[d.templateId,d.priceKey?e(`providers.priceKeyShort`,{key:d.priceKey}):null].filter(Boolean).join(` · `):void 0,leading:(0,$.jsx)(en,{onClick:()=>n(`/providers`)}),actions:d&&(0,$.jsx)(tn,{p:d}),children:d?(0,$.jsxs)($e,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(Ye,{"aria-label":d.name,children:[(0,$.jsx)(et,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(et,{value:`accounts`,children:e(d.authScheme===`oauth-subscription`||d.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(et,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(tt,{value:`models`,className:`pt-4`,children:(0,$.jsx)(rn,{provider:d,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(tt,{value:`accounts`,className:`pt-4`,children:d.authScheme===`plugin`?(0,$.jsx)(Jt,{provider:d}):d.authScheme===`oauth-subscription`?(0,$.jsx)(Kt,{provider:d}):(0,$.jsx)(dn,{provider:d})}),(0,$.jsx)(tt,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(pn,{provider:d})}),(0,$.jsx)(un,{provider:d,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(z,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}function en({onClick:e}){let{t}=M();return(0,$.jsx)(F,{variant:`glass`,icon:(0,$.jsx)(K,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function tn({p:e}){let{t}=M(),n=qe(),{toast:r,confirm:i}=W(),a=Oe(),o=de(),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=async()=>{await i({title:t(`providers.deleteConfirm`,{name:e.name}),detail:t(`providers.deleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&o.mutate(e.id,{onSuccess:()=>{r(t(`providers.deleted`)),n(`/providers`)},onError:e=>{let n=e instanceof I&&e.status===409?e.details?.boundClients??[]:[];r(n.length?t(`providers.deleteBound`,{clients:n.map(e=>Xe[e]?.name??e).join(`, `)}):H(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{icon:(0,$.jsx)(ze,{className:`size-3.5`}),onClick:()=>u(!0),children:t(`providers.test`)}),(0,$.jsx)(Ie,{label:t(`common.more`),icon:(0,$.jsx)(J,{className:`size-4`}),items:[{id:`dup`,label:t(`providers.duplicate`),icon:(0,$.jsx)(P,{className:`size-3.5`}),onSelect:()=>a.mutate(e.id,{onSuccess:e=>n(`/providers/${e.id}`),onError:e=>r(H(e),`error`)})},{id:`tpl`,label:t(`providers.templateUpdate`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>c(!0)},{id:`del`,label:t(`common.delete`),icon:(0,$.jsx)(X,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d()}]}),(0,$.jsx)(nn,{open:s,onOpenChange:c,provider:e}),(0,$.jsx)(lt,{provider:e,open:l,onOpenChange:u})]})}function nn({open:e,onOpenChange:t,provider:n}){let{t:r}=M(),{toast:i}=W(),a=ge(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)(F,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(F,{variant:`primary`,disabled:!a.data||s,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(H(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(z,{}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:H(a.error)}),s&&(0,$.jsx)(L,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!s&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function rn({provider:e,models:n,loading:r,selected:i,onSelect:a}){let{t:o}=M(),{toast:s}=W(),[c,l]=(0,Q.useState)(``),[u,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),h=d(e.id),g=(n??[]).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)(pe,{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)(F,{icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onClick:()=>m(!0),children:o(`providers.addModels`)}),(0,$.jsx)(F,{variant:`primary`,icon:(0,$.jsx)(q,{className:`size-3.5`}),onClick:()=>f(!0),children:o(`providers.fetchRemote`)})]})]}),r&&(0,$.jsx)(z,{lines:4}),n?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(T,{title:o(`providers.noModels`),detail:o(`providers.noModelsDetail`)})}),g.length>0&&(0,$.jsx)(R,{footer:o(`providers.modelsFooter`),children:g.map(e=>(0,$.jsxs)(A,{selected:e.id===i,onClick:()=>a(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:O(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(j,{tone:`orange`,children:o(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?t(e.effective.contextWindow):null,Te(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(Je,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(V,{checked:e.enabled,label:o(`common.enabled`),onChange:t=>h.mutate({pmId:e.id,enabled:t},{onError:e=>s(H(e),`error`)})})]},e.id))}),n&&(0,$.jsx)(an,{provider:e,models:n}),(0,$.jsx)(sn,{open:p,onOpenChange:m,provider:e}),(0,$.jsx)(cn,{open:u,onOpenChange:f,provider:e})]})}function an({provider:e,models:t}){let{t:n}=M(),{toast:r}=W(),i=ce(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)(R,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(A,{label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2 font-mono text-[12.5px]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e}),(0,$.jsx)(Ue,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:O(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(j,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(ue,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>u(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(A,{icon:(0,$.jsx)(Ge,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`providers.modelMap.add`),detail:t.length===0?n(`providers.modelMap.needModels`):void 0,onClick:t.length===0?void 0:()=>o(!0)})]}),(0,$.jsx)(on,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function on({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=M(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(U,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(F,{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)(E,{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}=M(),{toast:i}=W(),a=ve(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)(F,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(F,{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)(oe,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
3
+ claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function cn({open:e,onOpenChange:t,provider:n}){let{t:r}=M(),{toast:i}=W(),a=we(n.id,e),o=ve(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)(F,{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)(F,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(F,{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)(pe,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(z,{lines:4}),a.isError&&(0,$.jsx)(L,{tone:`danger`,title:r(`common.error`),children:H(a.error)}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(A,{onClick:e.alreadyAdded?void 0:()=>f(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(j,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rt,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function ln({origin:e}){let{t}=M();return e===`overridden`?(0,$.jsx)(j,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(j,{children:t(`origin.inherited`)}):(0,$.jsx)(j,{tone:`red`,children:t(`origin.unset`)})}function un({provider:e,pm:t,onClose:n}){let{t:r}=M(),{toast:i}=W(),o=d(e.id),s=Ce(e.id),c=a(),[l,u]=(0,Q.useState)({}),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(u(t.overrides),p(t.systemModelId??``),h(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(U,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let g={...l,pricing:m?l.pricing??null:null},_=JSON.stringify(g)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||f!==(t.systemModelId??``),v=()=>o.mutate({pmId:t.id,overrides:g,systemModelId:f||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(H(e),`error`)}),y=(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:l[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),l[e]!=null&&(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(He,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>u({...l,[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)(X,{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 s.mutateAsync(t.id),n()}})}),(0,$.jsx)(F,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(F,{variant:`primary`,disabled:!_,loading:o.isPending,onClick:v,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)(Je,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(j,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(w,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(G,{className:`w-full`,ariaLabel:r(`providers.linkedModel`),value:f,onChange:p,options:[{value:``,label:r(`providers.noLink`)},...(c.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:[y(`displayName`,r(`models.field.displayName`),(0,$.jsx)(E,{className:`w-full`,"aria-label":r(`models.field.displayName`),placeholder:t.effective.displayName,value:l.displayName??``,onChange:e=>u({...l,displayName:e.target.value||null})})),y(`contextWindow`,r(`models.field.contextWindow`),(0,$.jsx)(Ee,{className:`w-full`,label:r(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:l.contextWindow,onChange:e=>u({...l,contextWindow:e})})),y(`maxOutputTokens`,r(`models.field.maxOutputTokens`),(0,$.jsx)(Ee,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:l.maxOutputTokens,onChange:e=>u({...l,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:m,label:r(`providers.customPrice`),onChange:e=>{h(e),e&&l.pricing==null&&u({...l,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(m?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),m?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(Ze,{value:l.pricing??null,onChange:e=>u({...l,pricing:e})})}):t.effectivePricing?(0,$.jsx)(he,{maxHeight:220,children:je(t.effectivePricing)}):(0,$.jsx)(L,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function dn({provider:e}){let{t}=M(),{toast:n}=W(),r=x(e.id),[i,a]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:(0,$.jsx)(A,{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)(E,{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)(F,{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}=M(),{toast:n}=W(),r=x(e.id),i=te(),a=(0,Q.useMemo)(()=>fn(e),[e]),[o,s]=(0,Q.useState)(a),[c,l]=(0,Q.useState)(Object.entries(e.extraHeaders)),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{s(a),l(Object.entries(a.extraHeaders))},[a]);let m=e=>s(t=>({...t,...e})),h={...o,extraHeaders:Object.fromEntries(c.filter(([e])=>e.trim()))},g=JSON.stringify(h)!==JSON.stringify(a),_=()=>{let e={};for(let t of Object.keys(h))t!==`apiKey`&&JSON.stringify(h[t])!==JSON.stringify(a[t])&&(e[t]=h[t]);o.apiKey&&(e.apiKey=o.apiKey),r.mutate(e,{onSuccess:()=>n(t(`common.saved`),`success`),onError:e=>n(H(e),`error`)})},v=(e,t)=>m({endpoints:o.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(R,{title:t(`providers.section.basic`),children:[(0,$.jsx)(A,{label:t(`providers.name`),children:(0,$.jsx)(E,{className:`w-64`,"aria-label":t(`providers.name`),value:o.name,onChange:e=>m({name:e.target.value})})}),(0,$.jsx)(A,{label:t(`common.enabled`),children:(0,$.jsx)(V,{checked:o.enabled,label:t(`common.enabled`),onChange:e=>m({enabled:e})})}),(0,$.jsx)(A,{label:t(`providers.notes`),children:(0,$.jsx)(E,{className:`w-64`,"aria-label":t(`providers.notes`),value:o.notes??``,onChange:e=>m({notes:e.target.value||null})})})]}),(0,$.jsx)(R,{title:t(`providers.section.auth`),children:(0,$.jsx)(A,{label:t(`providers.authScheme`),children:(0,$.jsx)(G,{className:`w-48`,value:o.authScheme,onChange:e=>m({authScheme:e}),options:at})})}),(0,$.jsxs)(R,{title:t(`providers.section.endpoints`),footer:t(`providers.endpointsFooter`),children:[o.endpoints.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(G,{className:`w-48`,value:e.protocol,onChange:e=>v(n,{protocol:e}),options:ot}),(0,$.jsx)(E,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.baseUrl`),value:e.baseUrl,onChange:e=>v(n,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(V,{checked:!!e.fullUrl,label:t(`providers.fullUrl`),onChange:e=>v(n,{fullUrl:e})}),t(`providers.fullUrl`)]}),(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(X,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>m({endpoints:o.endpoints.filter((e,t)=>t!==n)})})]},n)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onClick:()=>d(!0),children:t(`providers.addEndpoint`)})}),(0,$.jsx)(A,{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)(Qe,{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));m({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(R,{title:t(`providers.section.billing`),footer:t(`providers.billingFooter`),children:[(0,$.jsx)(A,{label:t(`providers.priceKey`),detail:t(`providers.priceKeyHint`),children:(0,$.jsx)(G,{className:`w-56`,value:o.priceKey==null?`inherit`:`price:${o.priceKey}`,onChange:e=>m({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:t(`providers.priceKeyDefault`,{id:e.templateId??`—`})},{value:`price:`,label:t(`providers.priceKeyNone`)},...(i.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(A,{label:t(`providers.multiplier`),detail:t(`providers.multiplierHint`),children:(0,$.jsx)(Ee,{className:`w-28`,label:t(`providers.multiplier`),step:.01,min:0,value:o.priceMultiplier,onChange:e=>m({priceMultiplier:e??1})})})]}),(0,$.jsxs)(R,{title:t(`providers.section.advanced`),children:[(0,$.jsx)(A,{label:t(`providers.proxy`),detail:t(`providers.proxyHint`),children:(0,$.jsx)(E,{className:`w-64 font-mono`,"aria-label":t(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:o.httpProxy??``,onChange:e=>m({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:t(`providers.headers`)}),c.map(([e,n],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(E,{className:`w-48 font-mono`,"aria-label":t(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>l(c.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(E,{className:`flex-1 font-mono`,"aria-label":t(`providers.headerValue`),placeholder:`value`,value:n,onChange:e=>l(c.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(X,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>l(c.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onClick:()=>p(!0),children:t(`providers.addHeader`)})]}),Object.keys(e.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(oe,{label:t(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:je(o.settings),onBlur:e=>{try{m({settings:JSON.parse(e.target.value)})}catch{n(t(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(R,{title:t(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(D,{label:`ID`,children:e.id}),e.adapterId&&(0,$.jsx)(D,{label:t(`providers.adapter`),children:e.adapterId}),(0,$.jsx)(D,{label:t(`providers.boundClients`),children:e.boundClients.map(e=>Xe[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(mn,{open:u,onOpenChange:d,onAdd:e=>m({endpoints:[...o.endpoints,e]})}),(0,$.jsx)(hn,{open:f,onOpenChange:p,onAdd:e=>l([...c.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:g&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:t(`common.unsaved`)}),(0,$.jsx)(F,{size:`sm`,onClick:()=>{s(a),l(Object.entries(a.extraHeaders))},children:t(`common.revert`)}),(0,$.jsx)(F,{size:`sm`,variant:`primary`,loading:r.isPending,onClick:_,children:t(`common.save`)})]})})]})}function mn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=M(),[i,a]=(0,Q.useState)(`openai-chat`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(s(``),l(!1))},[e]);let u=/^https?:\/\/\S+$/.test(o.trim());return(0,$.jsx)(U,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(F,{variant:`primary`,disabled:!u,onClick:()=>{n({protocol:i,baseUrl:o.trim(),...c?{fullUrl:!0}:{}}),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(k,{label:r(`providers.protocol`),children:(0,$.jsx)(G,{value:i,onChange:a,options:ot})}),(0,$.jsx)(k,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(E,{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}=M(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(a(``),s(``))},[e]);let c=/^[A-Za-z0-9-]+$/.test(i.trim());return(0,$.jsx)(U,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(F,{variant:`primary`,disabled:!c,onClick:()=>{n([i.trim(),o]),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(k,{label:r(`providers.headerName`),children:(0,$.jsx)(E,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.headerValue`),children:(0,$.jsx)(E,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{$t as ProviderDetailPage};
@@ -0,0 +1,2 @@
1
+ import{E as e,Fr as t,J as n,Jt as r,Mr as i,Nr as a,Qn as o,Un as s,W as c,Wr as l,Xn as u,Z as d,Zn as f,_ as p,_i as m,_n as h,b as g,bi as _,c as v,ca as y,ct as b,d as x,f as S,gi as C,gt as w,h as T,hr as E,i as D,it as O,l as k,la as A,m as j,n as M,ot as N,p as P,pa as ee,r as F,ri as I,s as L,t as R,u as te,ua as ne,un as z,v as B,vi as V,vn as H,vt as U,w as re,wt as W,xi as G,y as ie,yi as K}from"./alert-C-zJo-Vf.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-BBHZHl4R.js";import{t as Ce}from"./arrow-left-BlStTg-u.js";import{t as we}from"./download-zacBMjpe.js";import{n as Te,t as Ee}from"./radio-cards-BWCaBwfU.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-CNdW2eN9.js";import{t as Ue}from"./checkbox-B8UTLROZ.js";var J=ee(ne(),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=U(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=U(qe),Ye={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Ye.node;var Xe=U(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=A(),{blur:Ze,duration:Z,ease:Qe,spring:$e,stagger:et}=e,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)(G,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(C.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)(C.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=V()??!1,g=(0,J.useId)(),v=(0,J.useRef)(null),y=(0,J.useRef)(null),[x,S]=(0,J.useState)(l),[w,T]=(0,J.useState)(!1),[E,D]=(0,J.useState)({}),[O,k]=(0,J.useState)(null),A=s?c??x:!1,j=!!s&&!h,M=!A&&O!==null,N=!!t,P=(0,J.useCallback)(e=>{c===void 0&&S(e),u?.(e)},[c,u]);(0,J.useEffect)(()=>{let e=v.current,t=y.current;if(!j||!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;D(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()},[j,N]);let ee=(0,J.useRef)(A);(0,J.useLayoutEffect)(()=>{let e=ee.current&&!A;ee.current=A;let t=v.current;if(A)k(null);else if(e&&j&&t){let e=t.getBoundingClientRect();k({top:e.top,left:e.left,width:e.width,height:e.height})}},[A,j]),(0,J.useEffect)(()=>{if(!M)return;let e=window.setTimeout(()=>k(null),rt);return()=>window.clearTimeout(e)},[M]);let F=(e,t,n=!0)=>j?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?A:M?`return`:`panel`,transition:{layout:t===`card`?nt:tt}}:{},I=e=>i||a||o||r?(0,X.jsxs)(`div`,{className:Y.footer,children:[i||a||o?(0,X.jsxs)(C.div,{className:Y.byline,...F(`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)(C.div,{className:Y.action,...F(`action`,e,`position`),children:r}):null]}):null,L=(0,X.jsxs)(C.article,{...m,ref:v,className:[Y.card,f].filter(Boolean).join(` `),style:{...p,borderRadius:E.card??p?.borderRadius},"data-hover":w||void 0,whileHover:h?void 0:{y:-2},onHoverStart:()=>T(!0),onHoverEnd:()=>T(!1),...F(`card`,`card`),transition:{default:$e.snappy,layout:nt},children:[n?(0,X.jsx)(C.div,{className:Y.media,...F(`media`,`card`),children:(0,X.jsx)(C.div,{className:Y.zoom,initial:!1,animate:{scale:w&&!h?at:1},transition:w?ot:st,children:n})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(C.h3,{className:Y.title,...F(`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)(C.p,{ref:y,className:Y.description,...F(`description`,`card`,`position`),children:t}):null,d,I(`card`)]})]});return s?(0,X.jsx)(oe,{open:A,onOpenChange:P,children:(0,X.jsxs)(_,{id:g,children:[L,(0,X.jsx)(G,{children:(A||M)&&(0,X.jsxs)(le,{forceMount:!0,children:[(0,X.jsx)(G,{children:A&&(0,X.jsx)(se,{asChild:!0,forceMount:!0,children:(0,X.jsx)(C.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)(C.div,{className:Y.panel,"data-framer-portal-id":g,"data-returning":M||void 0,layoutScroll:!0,style:{borderRadius:E.panel,"--card-measure":E.measure?`${E.measure}px`:void 0,...O&&M?{"--landing-top":`${O.top}px`,"--landing-left":`${O.left}px`,"--landing-width":`${O.width}px`,"--landing-height":`${O.height}px`}:{}},...j?{...F(`card`,`panel`),initial:!1,animate:E.card!==void 0&&E.panel!==void 0?{borderRadius:M?E.card:E.panel}:void 0,transition:{layout:M?nt:tt,borderRadius:M?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)(C.div,{className:Y.media,...F(`media`,`panel`),children:(0,X.jsx)(C.div,{className:Y.zoom,initial:{scale:w&&!h?at:1},animate:{scale:1},transition:tt,children:n})}):null,(0,X.jsx)(C.span,{className:Y.closeSlot,initial:h?{opacity:0}:{opacity:0,scale:.9},animate:M?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:M||h?it:lt,children:(0,X.jsx)(Se,{asChild:!0,children:(0,X.jsx)(C.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:h?void 0:{scale:.94},transition:$e.snappy,children:(0,X.jsx)(b,{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)(C.h2,{className:Y.title,...F(`title`,`panel`),children:e})}),t?(0,X.jsx)(ce,{asChild:!0,children:(0,X.jsx)(C.p,{className:Y.description,...F(`description`,`panel`,`position`),children:t})}):null,d,I(`panel`),(0,X.jsx)(C.div,{className:Y.details,initial:!h&&{opacity:0,y:6},animate:M?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:it},transition:M||h?it:ct,children:s})]})]})})]},`quick-look`)})]})}):L}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:t=>({opacity:0,y:`${.3*t}em`,filter:`blur(${e.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:e.duration.standard,ease:[...e.ease.enter]}},gone:t=>({opacity:0,y:`${-.3*t}em`,filter:`blur(${e.blur.subtle}px)`,transition:{duration:e.duration.fast,ease:[...e.ease.standard]}})},gt={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:e.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:e.duration.instant}}},_t=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),vt=new Intl.NumberFormat(`en-US`),yt={duration:e.duration.considered*1.75,ease:[...e.ease.inOut]},bt={duration:e.duration.fast,ease:[...e.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:t,direction:n,whole:r=!1,morph:i=!1,tone:a}){let o=!!V(),s=(0,J.useRef)(null),c=K(`auto`),[l,u]=(0,J.useState)({text:t,direction:1});l.text!==t&&u({text:t,direction:n??(_t(t)<_t(l.text)?-1:1)}),(0,J.useEffect)(()=>{let t=s.current;if(!t||typeof ResizeObserver>`u`)return;let n=null,r=new ResizeObserver(([r])=>{if(!r)return;let i=r.borderBoxSize?.[0]?.inlineSize??t.offsetWidth;n!==null&&n!==t.textContent&&!o?m(c,i,e.spring.morph):c.jump(i),n=t.textContent});return r.observe(t),()=>r.disconnect()},[i,o,c]);let d=!r&&!/\p{L}/u.test(t),f=o?gt:ht,p=d?`right`:`left`;return(0,X.jsxs)(C.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:t}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(G,{mode:`popLayout`,initial:!1,custom:l.direction,anchorX:p,children:xt(t,r).map(e=>(0,X.jsx)(C.span,{className:Q.slot,custom:l.direction,variants:f,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(G,{mode:`popLayout`,initial:!1,custom:l.direction,anchorX:p,children:(0,X.jsx)(C.span,{className:a?`${Q.glyph} ${a}`:Q.glyph,custom:l.direction,variants:f,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:t,label:n,value:r,change:i,tone:a=`accent`,width:o=160,height:s=52,labels:c,formatValue:l,area:u=!0,interactive:d=!0}){let f=t.length>1?t:[t[0]??0,t[0]??0],p=f.length-1,h=f.join(`,`),g=(0,J.useMemo)(()=>Et(h.split(`,`).map(Number)),[h]),_=`${n}: ${r??f[p]}. ${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}),S=!!V(),[w,T]=(0,J.useState)({w:o,h:s}),[E,D]=(0,J.useState)(null),[O,k]=(0,J.useState)(!1),A=E===null?null:Math.min(E,p),[j,M]=(0,J.useState)({index:A,direction:1});j.index!==A&&M({index:A,direction:A===null||j.index===null?1:Math.sign(A-j.index)||1});let[N]=(0,J.useState)(()=>Ot(g,o,s,1)),P=(0,J.useRef)(g),ee=(0,J.useRef)(w),F=K(0),I=K(1),L=K(N.line),R=K(N.trail),te=K(N.fill),ne=K(N.dot),z=K(N.cx),B=K(N.cx+wt+16),H=K(N.cx+wt),U=K(0),re=ke(F,e=>+(e>.001)),W=(0,J.useCallback)(()=>{let{w:e,h:t}=ee.current,n=F.get(),r=Ot(P.current,e,t,I.get());L.set(r.line),R.set(r.trail),te.set(r.fill),ne.set(r.dot),z.set(r.cx),B.set(r.cx+wt+16),H.set(r.cx+wt),U.set(n>=1?e+32:kt(r.points,n)+16)},[I,z,H,ne,F,te,L,B,U,R]);We(I,`change`,W),We(F,`change`,W),(0,J.useLayoutEffect)(()=>{let e=b.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&T(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)(()=>{ee.current=w,W()},[w,W]),(0,J.useEffect)(()=>{if(S){F.jump(1);let e=requestAnimationFrame(()=>k(!0));return()=>cancelAnimationFrame(e)}if(!x)return;let e=m(F,1,{...yt,onComplete:()=>k(!0)});return()=>e.stop()},[F,x,S]),(0,J.useEffect)(()=>{let t=P.current;if(t===g)return;if(S){P.current=g,W();return}let n=[...new Set([...Tt,...g.map(([e])=>e)])].sort((e,t)=>e-t),r=n.map(e=>Dt(t,e)),i=n.map(e=>Dt(g,e)),a=m(0,1,{...e.spring.smooth,onUpdate:e=>{P.current=n.map((t,n)=>[t,r[n]+(i[n]-r[n])*e]),W()},onComplete:()=>{P.current=g,W()}});return()=>a.stop()},[W,S,g]),(0,J.useEffect)(()=>{let t=A===null?1:A/p;if(S){I.jump(t);return}let n=m(I,t,e.spring.snappy);return()=>n.stop()},[I,A,p,S]);let G=A!==null,ie=(e=>l?l(f[e],e):vt.format(f[e]))(A??p),ae=c?.[A??p],oe=r===void 0?void 0:G?ie:r,se=A===null?i??``:r===void 0?[ie,ae].filter(Boolean).join(` · `):ae??`${A+1} of ${p+1}`,ce=e=>{let t=b.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(p,Math.round((e-t.left)/t.width*p))):p},le=d?{role:`slider`,tabIndex:0,"aria-label":`${n}, explore values`,"aria-valuemin":1,"aria-valuemax":p+1,"aria-valuenow":(A??p)+1,"aria-valuetext":`${ae??(A===null?`Latest`:`Point ${A+1} of ${p+1}`)}: ${ie}`,onPointerDown:e=>D(ce(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&D(ce(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&D(null)},onPointerLeave:()=>D(null),onPointerCancel:()=>D(null),onBlur:()=>D(null),onKeyDown:e=>{if(e.key===`Escape`&&G){e.preventDefault(),D(null);return}let t=A??p,n=Math.max(1,Math.round((p+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:p}[e.key];r!==void 0&&(e.preventDefault(),D(Math.max(0,Math.min(p,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:n,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?j.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)(C.rect,{x:-16,y:-16,width:B,height:w.h+32})}),(0,X.jsx)(`clipPath`,{id:`${v}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(C.rect,{x:H,y:-16,width:w.w+32,height:w.h+32})}),(0,X.jsx)(`clipPath`,{id:`${v}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(C.rect,{x:-16,y:-16,width:U,height:w.h+32})})]}),u&&(0,X.jsx)(C.path,{className:`${Q.area} ${Q[a]}`,d:te,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)(C.path,{className:Q.trail,d:R,clipPath:`url(#${v}-dim)`,initial:!1,animate:{opacity:G&&O?1:0},transition:S?{duration:0}:bt}),(0,X.jsx)(C.polyline,{className:[Q.line,Q[a]].join(` `),points:L,clipPath:`url(#${v}-lit)`,style:{pathLength:F,opacity:re}}),(0,X.jsx)(C.line,{className:Q.cursor,x1:z,x2:z,y1:0,y2:w.h,initial:!1,animate:{opacity:+!!G},transition:S?{duration:0}:bt}),(0,X.jsx)(C.polyline,{className:[Q.end,Q[a]].join(` `),points:ne,initial:!1,animate:{opacity:+!!O,strokeWidth:O?G?10:7:0},transition:S?{duration:0}:{opacity:bt,strokeWidth:e.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:e.duration.fast,ease:[...e.ease.standard]},Pt={duration:e.duration.standard,ease:[...e.ease.enter]},Ft={opacity:0,y:`0.3em`,filter:jt(e.blur.soft)},It={opacity:1,y:0,filter:jt(0)},Lt={opacity:0,y:`-0.3em`,filter:jt(e.blur.subtle)},Rt={opacity:0,scale:.5,filter:jt(e.blur.subtle)},zt={opacity:1,scale:1,filter:jt(0)};function Bt({text:t,className:n,reduced:r}){let i=(0,J.useRef)(null),a=(0,J.useRef)(0),o=K(`auto`);return(0,J.useLayoutEffect)(()=>{a.current=performance.now()+700},[t]),(0,J.useEffect)(()=>{let t=i.current,n=t?.parentElement;if(!t||!n||typeof ResizeObserver>`u`)return;let s=!1,c=new ResizeObserver(()=>{let n=t.offsetHeight;if(!s||r||performance.now()>a.current){s=!0,o.jump(n);return}m(o,n,e.spring.smooth)});return c.observe(t),()=>c.disconnect()},[o,r]),(0,X.jsx)(C.span,{className:$.slot,style:{height:o},children:(0,X.jsx)(`span`,{ref:i,className:$.slotInner,children:(0,X.jsx)(G,{mode:`popLayout`,initial:!1,children:t?(0,X.jsx)(C.span,{className:n,initial:Ft,animate:It,exit:{...Lt,transition:r?Mt:Nt},transition:r?Mt:Pt,children:t},`${n}:${t}`):null})})})}function Vt({kind:t,number:n,delay:r,reduced:i}){let a=i?Mt:{scale:{...e.spring.snappy,delay:r},opacity:{duration:e.duration.fast,delay:r},filter:{duration:e.duration.fast,delay:r}},o={...Rt,transition:i?Mt:Nt},s=i?Mt:{duration:e.duration.standard,ease:e.ease.enter,delay:r+.04};return t===`number`?(0,X.jsx)(C.span,{className:$.glyph,initial:Rt,animate:zt,exit:o,transition:a,children:n}):(0,X.jsx)(C.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:t===`check`?(0,X.jsx)(C.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)(C.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(C.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Mt:{...e.spring.snappy,delay:r+.16}})]})})}function Ht({number:t,kind:n,current:r,glyphDelay:i,ringDelay:a,reduced:o}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(G,{initial:!1,children:r?(0,X.jsx)(C.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:{...e.spring.snappy,delay:a},opacity:{duration:e.duration.fast,delay:a}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(G,{initial:!1,children:(0,X.jsx)(Vt,{kind:n,number:t,delay:i,reduced:o},n)})})]})}var Ut={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Wt({steps:t,current:n,orientation:r=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let u=V()??!1,d=t.length,f=Math.min(Math.max(Math.round(n),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=e.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:t[f];function S(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?S:void 0,children:t.map((t,n)=>{let o=n===f,s=t.error?`error`:n<f?`complete`:o?`current`:`upcoming`,c=y&&n<f,l=t.error??(a===`all`||o?t.description:void 0),p=t.error?`error`:n<f?`check`:`number`,m=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ht,{number:n+1,kind:p,current:o,glyphDelay:_(n),ringDelay:v,reduced:u}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:t.label}),Ut[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Ut[s]]}):null,(0,X.jsx)(Bt,{text:l,className:t.error?$.error:$.description,reduced:u})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[n<d-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(C.span,{className:$.fill,initial:!1,animate:b?{scaleY:+(n<f)}:{scaleX:+(n<f)},transition:u?Mt:{...e.spring.smooth,delay:_(n)}},r)}):null,y?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":n<=f||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>i?.(n):void 0,children:m}):(0,X.jsx)(`span`,{className:$.head,"aria-current":o?`step`:void 0,children:m})]},t.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}=N(),{toast:r}=ve(),i=H(e),a=h(),[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)),m=(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)(F,{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)(F,{variant:`primary`,disabled:m.length===0||a.isPending,onClick:()=>{d(null),a.mutate(m.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let i=e.skipped.length;r(i>0?n(`import.doneSkipped`,{count:e.added.length,skipped:i}):n(`import.done`,{count:e.added.length})),t(!1)},onError:e=>{d(q(e)),i.refetch()}})},children:n(`import.selected`,{count:m.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(T,{value:o,onChange:s,placeholder:n(`import.search`)}),u&&(0,X.jsx)(R,{tone:`danger`,title:n(`common.error`),children:u}),i.isLoading&&(0,X.jsx)(B,{lines:3}),i.isError&&(0,X.jsx)(R,{tone:`danger`,title:n(`common.error`),children:q(i.error)}),(0,X.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:i.data?.map(e=>(0,X.jsx)(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}=N(),o=e.items.filter(t);return(0,X.jsxs)(`section`,{"aria-label":e.name,children:[(0,X.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:a(`import.path`,{path:e.path}),children:e.path})]}),e.error?(0,X.jsx)(R,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,X.jsx)(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}=N(),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:O(`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)(M,{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}=N(),{toast:n}=ve(),r=o(),i=E(e.id),s=a(e.id),c=z(),l=e.quotaConfig,u=(0,J.useMemo)(()=>on(l),[l]),[d,f]=(0,J.useState)(u),[p,m]=(0,J.useState)(null);(0,J.useEffect)(()=>f(u),[u]);let h=r.data??[],_=h.find(e=>e.id===l.suggestedTemplate),v=d.template===$t?_:h.find(e=>e.id===d.template),y=d.template===en,b=y?tn:v?.params??[],C=e=>f(t=>({...t,...e})),w=JSON.stringify(d)!==JSON.stringify(u),T=e=>{if(e!==en||d.url)return C({template:e});let t=v??_;C({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)})},O=()=>{let e={enabled:d.enabled,template:d.template===$t?null:d.template,intervalMinutes:d.intervalMinutes,timeoutSec:d.timeoutSec??10,baseUrl:d.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(d.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(d.secrets).filter(([,e])=>e.trim()!==``))};if(y){let r=sn(d.headers),i=sn(d.extract);if(!r||!i)return n(t(`providers.quota.invalidJson`,{field:t(r?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:d.method,url:d.url.trim(),auth:d.auth,headers:r},e.extract=i}return e},k=()=>{let r=O();if(!r)return;let a=r.enabled&&!l.enabled;i.mutate(r,{onSuccess:()=>{n(t(`common.saved`),`success`),a&&c.mutate(e.id,{onError:e=>n(q(e),`error`)})},onError:e=>n(q(e),`error`)})},A=()=>{let e=O();e&&s.mutate(e,{onSuccess:m,onError:e=>n(q(e),`error`)})},M=l.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:l.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),ee=[{value:$t,label:_?t(`providers.quota.templateAuto`,{name:_.name}):t(`providers.quota.templateNone`)},...h.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)(te,{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)(ie,{checked:d.enabled,label:t(`providers.quota.enable`),onChange:e=>C({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:d.template,onChange:T,options:ee})}),b.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=l.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)(x,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:d.secrets[e.name]??``,onChange:t=>C({secrets:{...d.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(j,{label:n,children:(0,X.jsx)(x,{className:`w-64 font-mono`,"aria-label":n,value:d.params[e.name]??``,onChange:t=>C({params:{...d.params,[e.name]:t.target.value}})})},e.name)}),b.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),y&&(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:d.method,onChange:e=>C({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(x,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:d.url,onChange:e=>C({url:e.target.value})}),(0,X.jsx)(be,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:d.auth,onChange:e=>C({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)(g,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:d.headers,onChange:e=>C({headers:e.target.value})}),(0,X.jsx)(g,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:d.extract,onChange:e=>C({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:M}),children:(0,X.jsx)(P,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:d.intervalMinutes,onChange:e=>C({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:d.timeoutSec,onChange:e=>C({timeoutSec:e})})}),(0,X.jsx)(j,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(x,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:d.baseUrl,onChange:e=>C({baseUrl:e.target.value})})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,X.jsx)(F,{size:`sm`,variant:`primary`,disabled:!w,loading:i.isPending,onClick:k,children:t(`common.save`)}),(0,X.jsx)(F,{size:`sm`,icon:(0,X.jsx)(Te,{className:`size-3.5`}),loading:s.isPending,onClick:A,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(F,{size:`sm`,icon:(0,X.jsx)(Je,{className:`size-3.5`}),disabled:w,loading:c.isPending,onClick:()=>c.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:p!==null,onOpenChange:e=>!e&&m(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:p&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(R,{tone:p.ok?`success`:`danger`,title:p.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!p.ok&&fe({code:p.errorCode??null,message:p.error??``},t),!p.ok&&p.error&&p.errorCode&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:p.error})]}),p.url&&(0,X.jsx)(S,{label:t(`providers.quota.requestUrl`),mono:!0,children:p.url}),p.httpStatus!=null&&(0,X.jsx)(S,{label:t(`providers.quota.httpStatus`),children:p.httpStatus}),p.snapshot&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,X.jsx)(ln,{snapshot:p.snapshot})]}),p.raw!==void 0&&p.raw!==null&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,X.jsx)(D,{children:an(p.raw)})]})]})})]})}function ln({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=N(),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)(R,{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)(R,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,X.jsx)(M,{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)(M,{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}=N(),{toast:r}=ve(),i=z();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)(F,{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}=N(),n=Ne(),[r,i]=Ae(),a=f(),[o,s]=(0,J.useState)(r.get(`new`)===`1`),[c,l]=(0,J.useState)(!1);(0,J.useEffect)(()=>{r.get(`new`)===`1`&&(s(!0),r.delete(`new`),i(r,{replace:!0}))},[r,i]),Me(e=>{e===`new-provider`&&s(!0)});let u=t(`7d`,`day`,`provider`),[d,p]=(0,J.useState)(null),m=(0,J.useMemo)(()=>{let e=hn(mn),t=new Map;for(let n of u.data??[]){let r=e.indexOf(n.bucket);if(r<0)continue;let i=t.get(n.key);i||t.set(n.key,i={requests:e.map(()=>0),costUsd:0}),i.requests[r]=(i.requests[r]??0)+n.requests,i.costUsd+=n.costUsd}return{days:e,byProvider:t}},[u.data]);return(0,X.jsxs)(He,{title:e(`nav.providers`),subtitle:a.data?e(`providers.count`,{count:a.data.length}):void 0,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{icon:(0,X.jsx)(we,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`providers.import`)}),(0,X.jsx)(F,{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:[a.isLoading&&(0,X.jsx)(B,{lines:4}),a.isError&&(0,X.jsx)(R,{tone:`danger`,title:e(`common.error`),children:q(a.error)}),a.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(v,{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)(F,{variant:`primary`,icon:(0,X.jsx)(je,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`providers.add`)}),(0,X.jsx)(F,{icon:(0,X.jsx)(we,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`providers.import`)})]})})}),a.data&&a.data.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:a.data.map(e=>(0,X.jsx)(vn,{p:e,days:m.days,usage:m.byProvider.get(e.name),onOpen:()=>n(`/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=>n(`/providers/${e.id}`)}),d&&(0,X.jsx)(kn,{provider:d,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:r,onOpen:i,onTest:a}){let{t:o}=N(),s=l(e.id),{toast:c}=ve(),u=[...new Set(e.endpoints.map(e=>e.protocol))],f=!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,p=[e.priceKey?o(`providers.priceKeyShort`,{key:e.priceKey}):null,e.priceMultiplier===1?null:`×${e.priceMultiplier}`].filter(Boolean).join(` · `),m=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?f?{tone:`orange`,label:o(`providers.noKey`)}:{tone:`green`,label:o(`providers.card.active`)}:{tone:`neutral`,label:o(`providers.card.disabled`)},g=r?.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:O(`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)(L,{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:O(e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:m}),status:p||void 0,action:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:_n,children:[(0,X.jsx)(F,{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)(ie,{checked:e.enabled,label:o(`common.enabled`),onChange:e=>s.mutate({enabled:e},{onError:e=>c(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)(M,{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)(M,{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:n(_,!0),change:d(r?.costUsd??0),width:320,height:28,formatValue:e=>n(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:e,onOpenChange:t,onCreated:n}){let{t:a}=N(),{toast:o}=ve(),c=i(),l=s(),u=r(),d=f(),p=(0,J.useMemo)(()=>new Set((d.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[d.data]),m=Ne(),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[S,C]=(0,J.useState)(``),[w,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(``),[A,j]=(0,J.useState)(``),[M,P]=(0,J.useState)(``),[ee,I]=(0,J.useState)(`openai-chat`),[L,te]=(0,J.useState)(`bearer`);(0,J.useEffect)(()=>{e||(v(null),b(null),g(``),C(``),E(``),O(``),j(``),P(``))},[e]);let ne=(0,J.useMemo)(()=>{let e=h.trim().toLowerCase(),t=(c.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return bn.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[c.data,h]),z=(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(``),te(e.auth.scheme))},H=()=>{let e=_===`custom`;u.mutate({templateId:e?null:_.id,variantId:D||null,name:S.trim()||null,apiKey:w.trim()||null,priceKey:A,...e?{endpoints:[{protocol:ee,baseUrl:M.trim()}],authScheme:L}:{}},{onSuccess:e=>{t(!1),o(a(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>o(q(e),`error`)})},U=_&&_!==`custom`?_:null,re=()=>{if(y===`custom`)V(`custom`);else if(y?.startsWith(yn)){let e=z.find(e=>yn+e.id===y);e&&(t(!1),n(e))}else{let e=(c.data??[]).find(e=>e.id===y);e&&!p.has(e.id)&&V(e)}},W=_!==null&&(_===`custom`?/^https?:\/\//.test(M.trim())&&S.trim()!==``:!U.requiresApiKey||w.trim()!==``);return(0,X.jsxs)(he,{open:e,onOpenChange:t,width:640,title:a(_?`providers.addTitleDetails`:`providers.addTitle`),description:_?U?U.name:a(`providers.custom`):a(`providers.addDetail`),footer:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{className:`mr-auto`,variant:`plain`,onClick:()=>v(null),children:a(`common.back`)}),(0,X.jsx)(F,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,X.jsx)(F,{variant:`primary`,disabled:!W,loading:u.isPending,onClick:H,children:a(`providers.create`)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,X.jsx)(F,{variant:`primary`,disabled:!y,onClick:re,children:a(`common.continue`)})]}),children:[(0,X.jsx)(Wt,{className:`mb-6`,label:a(`providers.addTitle`),current:+!!_,steps:[{id:`template`,label:a(`providers.step.template`)},{id:`details`,label:a(`providers.step.details`)}]}),_?(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(k,{label:a(`providers.name`),children:(0,X.jsx)(x,{value:S,onChange:e=>C(e.target.value)})}),U?.variants&&U.variants.length>0&&(0,X.jsx)(k,{label:a(`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:a(`providers.variantDefault`)},...U.variants.map(e=>({value:e.id,label:e.name}))]})}),_===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:a(`providers.baseUrl`),hint:a(`providers.baseUrlHint`),children:(0,X.jsx)(x,{value:M,onChange:e=>P(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)(k,{label:a(`providers.protocol`),children:(0,X.jsx)(be,{value:ee,onChange:I,options:dn})}),(0,X.jsx)(k,{label:a(`providers.authScheme`),children:(0,X.jsx)(be,{value:L,onChange:te,options:fn})})]})]}),U?.authScheme===`oauth-subscription`?(0,X.jsx)(R,{tone:`info`,title:a(`providers.subscriptionWizardHint`),children:a(`providers.subscriptionWizardDetail`)}):(0,X.jsxs)(`div`,{className:`font-mono`,children:[(0,X.jsx)(De,{label:a(`providers.apiKey`),description:a(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:w,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:a(`providers.getKey`)})]}),(0,X.jsx)(k,{label:a(`providers.priceKey`),hint:a(`providers.priceKeyHint`),children:(0,X.jsx)(be,{value:A,onChange:j,options:[{value:``,label:a(`providers.priceKeyNone`)},...(l.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:a(`providers.templateModels`,{count:U.models.length})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,X.jsx)(T,{value:h,onChange:g,placeholder:a(`providers.searchTemplates`)}),c.isLoading&&(0,X.jsx)(B,{lines:4}),c.isError&&(0,X.jsx)(R,{tone:`danger`,title:a(`common.error`),children:q(c.error)}),ne.map(e=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:a(`providers.category.${e.category}`)}),(0,X.jsx)(Ee,{name:`provider-template`,"aria-label":a(`providers.category.${e.category}`),minColumnWidth:170,value:e.items.some(e=>e.id===y)?y:null,onValueChange:b,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:p.has(e.id),disabledReason:a(`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:a(`providers.category.plugin`)}),z.length>0?(0,X.jsx)(Ee,{name:`provider-template-plugin`,"aria-label":a(`providers.category.plugin`),minColumnWidth:170,value:y?.startsWith(yn)?y:null,onValueChange:b,options:z.map(e=>({value:yn+e.id,label:e.name,description:a(`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:a(`providers.pluginHint`)}),(0,X.jsx)(F,{size:`sm`,onClick:()=>{t(!1),m(`/plugins/market`)},children:a(`plugins.browseMarket`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:a(`providers.custom`)}),(0,X.jsx)(Ee,{name:`provider-template-custom`,"aria-label":a(`providers.custom`),layout:`list`,value:y===`custom`?`custom`:null,onValueChange:b,options:[{value:`custom`,label:a(`providers.custom`),description:a(`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}=N(),i=y(),a=u(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,J.useState)(`single`),[l,d]=(0,J.useState)(()=>En(e)),[f,m]=(0,J.useState)(!0),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(Cn),[x,S]=(0,J.useState)(``),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)({}),[D,O]=(0,J.useState)([]),[A,j]=(0,J.useState)(new Set),[M,P]=(0,J.useState)([]),[ee,I]=(0,J.useState)(``),[L,R]=(0,J.useState)(null),[te,ne]=(0,J.useState)(!1),z=(0,J.useRef)(null),B=(0,J.useRef)(new Map),V=(0,J.useRef)(!1),H=(0,J.useRef)(!1),U=(0,J.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...M.filter(t=>!e.includes(t))]},[a.data,M]);(0,J.useEffect)(()=>{if(t){S(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}H.current=!1,z.current?.abort();for(let e of B.current.values())e.abort();B.current.clear(),w(null),E({}),O([]),j(new Set),P([]),I(``),R(null)},[t,a.data]);let re=(0,J.useCallback)(e=>({modelId:e,protocol:l,stream:f,prompt:h.trim()||null,maxOutputTokens:_??Cn}),[l,f,h,_]),W=(0,J.useCallback)((t,n,r)=>Rn(e.id,t,re(t),n,r),[e.id,re]),G=()=>{let e=x.trim();if(!e)return;z.current?.abort();let t=new AbortController;z.current=t,H.current=!0,R(null),w({modelId:e,status:`running`,text:``,reasoning:``}),W(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&K(),w(e)})},ie=e=>{if(e.length===0)return;H.current=!0,V.current=!1,R(null),O(e),E(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(Sn,e.length)},async()=>{for(;;){if(!H.current)return;let n=e[t++];if(n===void 0)return;if(V.current){E(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;B.current.set(n,r),await W(n,r.signal,e=>E(t=>({...t,[n]:e}))),B.current.delete(n),K()}}))},K=()=>void i.invalidateQueries({queryKey:[`requests`]}),ae=()=>{V.current=!0,E(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},oe=C?.status===`running`||D.some(e=>T[e]?.status===`running`||T[e]?.status===`queued`&&!V.current),se=D.filter(e=>T[e]&&T[e].status!==`queued`&&T[e].status!==`running`).length,ce=D.filter(e=>T[e]?.status===`success`).length,le=D.filter(e=>T[e]?.status===`failed`).length,ue=(e,t)=>j(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)(F,{disabled:oe,onClick:()=>n(!1),icon:(0,X.jsx)(b,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?oe?(0,X.jsx)(F,{variant:`primary`,icon:(0,X.jsx)(Xe,{className:`size-3.5`}),onClick:()=>z.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(F,{variant:`primary`,disabled:x.trim()===``,icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:G,children:r(C?`providers.testDialog.retest`:`providers.testDialog.start`)}):oe?(0,X.jsx)(F,{variant:`primary`,icon:(0,X.jsx)(Xe,{className:`size-3.5`}),onClick:ae,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(F,{variant:`primary`,disabled:A.size===0,icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>ie([...A]),children:r(`providers.testDialog.testN`,{count:A.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)(p,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),R(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,X.jsx)(k,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(An,{value:x,models:U,onChange:S})}),(0,X.jsx)(jn,{protocols:o,protocol:l,onProtocol:d,stream:f,onStream:m,maxTokens:_,onMaxTokens:v,prompt:h,onPrompt:g}),(0,X.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,X.jsx)(Mn,{run:C,onRetest:G})]}):L===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(In,{known:U,selected:A,onToggle:ue,onSelectAll:e=>j(e?new Set(U):new Set),onClear:()=>j(new Set),search:ee,onSearch:I,onAdd:e=>{P(t=>t.includes(e)?t:[...t,e]),j(t=>new Set(t).add(e)),I(``)},configOpen:te,onConfigOpen:ne,protocols:o,protocol:l,onProtocol:d,stream:f,onStream:m,maxTokens:_,onMaxTokens:v,prompt:h,onPrompt:g}),D.length>0?(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:oe?r(`providers.testDialog.progress`,{done:se,total:D.length,ok:ce,failed:le}):r(`providers.testDialog.progressDone`,{total:D.length,ok:ce,failed:le})}),(0,X.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${se/D.length*100}%`,background:`var(--accent)`}})})]}):null,D.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Ln,{order:D,runs:T,onView:R})}):null]}):(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(F,{variant:`plain`,icon:(0,X.jsx)(Ce,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>R(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:L})]}),(0,X.jsx)(Mn,{run:T[L]??null})]})]})})}function An({value:e,models:t,onChange:n}){let{t:r}=N(),[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)(x,{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)(w,{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:O(`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}=N(),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)(k,{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)(ie,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,X.jsx)(k,{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)(k,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(g,{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}=N(),[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)(F,{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)(M,{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)(p,{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)(re,{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)(R,{tone:`danger`,title:n(`providers.testDialog.status.failed`),children:e.error}):a||e?.reasoning?(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[e?.reasoning?(0,X.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,X.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:n(`providers.testDialog.reasoning`)}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:e.reasoning})]}):null,a?(0,X.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:a}):null]}):e?.status===`success`?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.noText`)}):(0,X.jsx)(Nn,{run:e})})]})]})}function Nn({run:e}){let{t}=N();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?`—`:c(t)})]})}function Fn({run:e}){let{t}=N(),n=e?.status??`idle`;return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(L,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(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}=N(),f=a.trim(),p=f.toLowerCase(),m=p?e.filter(e=>e.toLowerCase().includes(p)):e,h=f!==``&&!e.some(e=>e.toLowerCase()===p);return(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:d(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,X.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,X.jsx)(T,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,X.jsx)(F,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(F,{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:m.length===0&&!h?(0,X.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:d(`providers.testDialog.noModels`)}):(0,X.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,X.jsx)(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`)})]}),h?(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(je,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,X.jsx)(`button`,{type:`button`,className:`text-left font-mono text-[12px] text-[var(--accent)]`,onClick:()=>s(f),children:d(`providers.testDialog.addModel`,{id:f})})]}):null,m.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(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}=N();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?`—`:c(i.ttftMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:c(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,t,n,r,i){let a={modelId:t,status:`running`,text:``,reasoning:``};i(a);let o=e=>{a={...a,...e},i(a)};try{await W(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:o({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`?o({reasoning:a.reasoning+e}):o({text:a.text+e});break}case`done`:{let t=e.data;o({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,contentType:t.contentType??null,headers:zn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?o({status:`cancelled`,error:null}):o({status:`failed`,error:e instanceof I?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{At as e,Br as t,Cn as n,E as r,Ir as i,Jr as a,Kt as o,Lr as s,Mt as c,Pr as l,Pt as u,Qr as d,Rt as f,U as p,V as m,Xt as h,Zn as g,Zr as _,Zt as v,_ as y,_i as b,_r as x,an as ee,ca as S,d as C,ei as te,er as w,fr as T,ft as E,gi as D,i as ne,ii as O,in as re,jt as ie,l as k,la as ae,li as oe,m as A,n as j,ni as se,o as ce,oi as le,ot as M,p as ue,pa as de,pt as fe,qr as pe,r as N,s as me,si as he,t as P,ti as ge,u as F,ua as _e,ui as ve,v as I,vi as ye,vt as L,xi as R,xr as be,xt as xe,y as z,yi as Se,zr as Ce}from"./alert-C-zJo-Vf.js";import{B,F as we,I as Te,L as Ee,R as De,a as V,gt as H,i as Oe,n as ke,o as U,r as W,vt as Ae,z as je}from"./overlays-BBHZHl4R.js";import{t as Me}from"./TrayPanelView-DP-m1Cui.js";import{t as Ne}from"./download-zacBMjpe.js";import{t as Pe}from"./ellipsis-Dwk6_QlF.js";import{t as G}from"./external-link-D-L32_ye.js";import{n as Fe,t as Ie}from"./radio-cards-BWCaBwfU.js";import{t as Le}from"./folder-open-ex39110T.js";import{t as Re}from"./log-out-CZSB5kqp.js";import{t as K}from"./pencil-C7HWLb95.js";import{t as ze}from"./rotate-ccw-Xx5_g9bd.js";import{D as Be,G as Ve,J as He,M as q,P as Ue,W as We,b as Ge,j as Ke,n as qe,s as Je,t as Ye,u as Xe,v as Ze,x as J,y as Qe}from"./index-CNdW2eN9.js";var $e={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`}]]};$e.node;var et=L($e),tt={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`}]]};tt.node;var nt=L(tt),rt={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`}]]};rt.node;var it=L(rt),at={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`}]]};at.node;var ot=L(at),st={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};st.node;var ct=L(st),lt={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`}]]};lt.node;var ut=L(lt),dt={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`}]]};dt.node;var ft=L(dt),pt={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`}]]};pt.node;var mt=L(pt),Y=de(_e(),1),X=ae(),ht=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],gt={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/…`},_t=e=>e===`feishu`||e===`dingtalk`,vt=(e,t)=>e(`alerts.event.${t}`),yt=(e,t)=>e(`alerts.event.${t}.hint`);function bt(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(xt,{}),(0,X.jsx)(St,{}),(0,X.jsx)(Dt,{})]})}function xt(){let{t:e,locale:t}=M(),n=c(!0);return(0,X.jsxs)(F,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(I,{}),n.data?.length===0&&(0,X.jsx)(A,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(A,{icon:(0,X.jsx)(et,{className:`size-4 text-[var(--danger)]`}),label:`${vt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${m(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function St(){let{t:e}=M(),{toast:t,confirm:n}=U(),r=se(),i=re(),a=l(),o=T(),[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(V(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(V(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(V(e),`error`)})};return(0,X.jsxs)(F,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(I,{}),r.data?.length===0&&(0,X.jsx)(A,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(A,{icon:(0,X.jsx)(mt,{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)(j,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(j,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||_t(t.format))&&(0,X.jsx)(j,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(N,{size:`sm`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(ke,{label:e(`common.more`),icon:(0,X.jsx)(Pe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(K,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ot,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Be,{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)(N,{size:`sm`,icon:(0,X.jsx)(q,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Ct,{hook:s,onClose:()=>c(null),onSecret:p}),(0,X.jsx)(Tt,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(wt,{secret:f,onClose:()=>p(null)})]})}function Ct({hook:e,onClose:t,onSecret:n}){let{t:r}=M(),{toast:i}=U(),a=h(),o=d(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(10),[m,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(!0),[x,ee]=(0,Y.useState)(`generic`),[S,te]=(0,Y.useState)(``),[w,T]=(0,Y.useState)([]),E=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),p(t?.timeoutSec??10),g(t?.useProxy??!0),v(t?.enabled??!0),b(!t||t.hasSecret),ee(t?.format??`generic`),te(``),T((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Oe,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(E?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(N,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(w.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:f??10,useProxy:m,enabled:_,headers:Object.keys(c).length>0?c:null},d={onError:e=>i(V(e),`error`)},p=!E&&e!==null&&e.format!==x,h=_t(x)?y?S.trim()||void 0:``:void 0;E?a.mutate({...u,format:x,...x===`generic`?{signed:y}:h?{secret:h}:{}},{...d,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...p?{format:x}:{},...x===`generic`?y||!e.hasSecret||p?{}:{signed:!1}:h===void 0?{}:{secret:h}},{...d,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(k,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(C,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(k,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${x}.hint`),children:(0,X.jsx)(W,{ariaLabel:r(`alerts.webhooks.format`),value:x,onChange:t=>{ee(t),b(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||_t(t))},options:ht.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(k,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(C,{mono:!0,value:l,placeholder:gt[x],onChange:e=>u(e.target.value)})}),_t(x)&&y&&(0,X.jsx)(k,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(C,{mono:!0,type:`password`,autoComplete:`off`,value:S,placeholder:e!==`new`&&e!==null&&e.format===x&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>te(e.target.value)})}),(0,X.jsx)(k,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(ue,{value:f,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:p})}),(0,X.jsx)(k,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[w.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)(C,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>T(w.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(C,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>T(w.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Be,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>T(w.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(N,{size:`sm`,icon:(0,X.jsx)(q,{className:`size-3.5`}),onClick:()=>T([...w,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(A,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(z,{checked:_,label:r(`alerts.webhooks.enabled`),onChange:v})}),(0,X.jsx)(A,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(z,{checked:m,label:r(`alerts.webhooks.useProxy`),onChange:g})}),(x===`generic`?E||e!==null&&e.format===`generic`&&e.hasSecret:_t(x))&&(0,X.jsx)(A,{label:r(`alerts.webhooks.signed`),detail:r(x===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(z,{checked:y,label:r(`alerts.webhooks.signed`),onChange:b})})]})]})})}function wt({secret:e,onClose:t}){let{t:n}=M(),{toast:r}=U();return(0,X.jsx)(Oe,{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)(N,{onClick:async()=>e&&await H.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(N,{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 Tt({hook:e,onClose:t}){let{t:n,locale:r}=M(),{toast:i}=U(),a=ge(e?.id),o=w(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Oe,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(I,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(j,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):vt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:m(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:m(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(ne,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(ne,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(N,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(V(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Et(e){let t=g(),n=s(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=Ae({queries:r.map(t=>({queryKey:xe.providerAccounts(t.id),queryFn:()=>O(`GET`,`/api/providers/${le(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`?r.flatMap((e,t)=>(i[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Dt(){let{t:e}=M(),{toast:n,confirm:r}=U(),i=ie(),a=se(),o=t(),s=v(),[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(V(e),`error`)})};return(0,X.jsxs)(F,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[i.isLoading&&(0,X.jsx)(I,{}),i.data?.length===0&&(0,X.jsx)(A,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),i.data?.map(t=>(0,X.jsxs)(A,{icon:(0,X.jsx)(et,{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)(j,{tone:`red`,children:e(`alerts.rules.firing`,{count:t.firing})}),!t.enabled&&(0,X.jsx)(j,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${vt(e,t.event)} → ${t.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(z,{checked:t.enabled,label:e(`alerts.rules.enabled`),onChange:e=>o.mutate({id:t.id,enabled:e},{onError:e=>n(V(e),`error`)})}),(0,X.jsx)(ke,{label:e(`common.more`),icon:(0,X.jsx)(Pe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(K,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Be,{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)(N,{size:`sm`,icon:(0,X.jsx)(q,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(kt,{rule:c,onClose:()=>l(null)})]})}function Ot(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 kt({rule:n,onClose:r}){let{t:i}=M(),{toast:a}=U(),s=e(),c=se(),l=o(),u=t(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)({}),[_,v]=(0,Y.useState)(`all`),[b,x]=(0,Y.useState)([]),[ee,S]=(0,Y.useState)([]),[te,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(null),[D,ne]=(0,Y.useState)(60),O=s.data?.find(e=>e.id===p),re=Et(O?.subjectType),ie=n===`new`;return(0,Y.useEffect)(()=>{if(n===null)return;let e=n===`new`?null:n,t=s.data?.[0];f(e?.name??``),m(e?.event??t?.id??``),g(e?{...Ot(s.data?.find(t=>t.id===e.event)),...e.condition}:Ot(t)),v(e?.subjects?`only`:`all`),x(e?.subjects??[]),S(e?.webhookIds??(c.data??[]).map(e=>e.id)),w(e?.notifyResolved??!1),E(e?.repeatMinutes??null),ne(e?.cooldownMinutes??60)},[n]),(0,X.jsx)(Oe,{open:n!==null,onOpenChange:e=>!e&&r(),title:i(ie?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{onClick:r,children:i(`common.cancel`)}),(0,X.jsx)(N,{variant:`primary`,disabled:!d.trim()||!p,loading:l.isPending||u.isPending,onClick:()=>{let e=Object.fromEntries(Object.entries(h).filter(([,e])=>e!==null&&e!==``)),t={name:d.trim(),event:p,condition:e,subjects:_===`all`?null:b,webhookIds:ee,notifyResolved:te,repeatMinutes:T&&T>0?Math.floor(T):null,cooldownMinutes:Math.max(0,Math.floor(D??0))},o={onSuccess:()=>{r(),a(i(`common.saved`),`success`)},onError:e=>a(V(e),`error`)};ie?l.mutate(t,o):n&&u.mutate({id:n.id,...t},o)},children:i(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(k,{label:i(`alerts.rules.name`),children:(0,X.jsx)(C,{value:d,maxLength:64,onChange:e=>f(e.target.value)})}),(0,X.jsx)(k,{label:i(`alerts.rules.event`),hint:p?yt(i,p):void 0,children:(0,X.jsx)(W,{ariaLabel:i(`alerts.rules.event`),value:p,onChange:e=>{m(e),g(Ot(s.data?.find(t=>t.id===e))),x([])},options:(s.data??[]).map(e=>({value:e.id,label:vt(i,e.id)}))})}),O?.params.map(e=>(0,X.jsx)(k,{label:i(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(ue,{value:typeof h[e.name]==`number`?h[e.name]:null,min:0,label:i(`alerts.param.${e.name}`),onChange:t=>g({...h,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(W,{ariaLabel:i(`alerts.param.${e.name}`),value:String(h[e.name]??``),onChange:t=>g({...h,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:i(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(C,{mono:!0,value:String(h[e.name]??``),"aria-label":i(`alerts.param.${e.name}`),placeholder:i(`alerts.param.${e.name}.placeholder`),onChange:t=>g({...h,[e.name]:t.target.value})})},e.name)),O&&(0,X.jsx)(k,{label:`${i(`alerts.rules.subjects`)} · ${i(`alerts.subject.${O.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(y,{ariaLabel:i(`alerts.rules.subjects`),value:_,onChange:v,items:[{value:`all`,label:i(`alerts.rules.subjectsAll`)},{value:`only`,label:i(`alerts.rules.subjectsOnly`)}]}),_===`only`&&(0,X.jsx)(Je,{label:i(`alerts.rules.subjects`),value:b,onValueChange:x,options:[...re,...b.filter(e=>!re.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(k,{label:i(`alerts.rules.webhooks`),children:(c.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`alerts.rules.noWebhooks`)}):(0,X.jsx)(Je,{label:i(`alerts.rules.webhooks`),value:ee,onValueChange:S,options:(c.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(k,{label:i(`alerts.rules.repeat`),hint:i(`alerts.rules.repeatHint`),children:(0,X.jsx)(ue,{value:T,min:1,step:1,label:i(`alerts.rules.repeat`),onChange:E})}),(0,X.jsx)(k,{label:i(`alerts.rules.cooldown`),hint:i(`alerts.rules.cooldownHint`),children:(0,X.jsx)(ue,{value:D,min:0,step:1,label:i(`alerts.rules.cooldown`),onChange:ne})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(A,{label:i(`alerts.rules.notifyResolved`),children:(0,X.jsx)(z,{checked:te,label:i(`alerts.rules.notifyResolved`),onChange:w})})})]})})}var At=`https://astra-gate.si/docs/guide/remote-access`,jt=`astra.remote.acknowledged`;function Mt(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 Nt(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Pt(){try{return localStorage.getItem(jt)===`1`}catch{return!1}}function Ft(){try{localStorage.setItem(jt,`1`)}catch{}}function It(){let{t:e}=M(),t=Ce(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Lt,{s:n}),(0,X.jsx)(Rt,{s:n}),(0,X.jsx)(zt,{s:n}),(0,X.jsx)(Ht,{s:n}),(0,X.jsx)(ce,{title:n.cloudflared.path&&n.cloudflared.version?e(`settings.remote.logWithVersion`,{version:n.cloudflared.version}):e(`settings.remote.log`),children:n.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:e(`settings.remote.logEmpty`)}):(0,X.jsx)(`pre`,{className:`max-h-72 overflow-auto font-mono text-[10.5px] leading-relaxed whitespace-pre-wrap text-[var(--text-secondary)] selectable`,children:n.log.join(`
2
+ `)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(P,{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:V(t.error)}):(0,X.jsx)(I,{className:`mx-auto my-8`})})}function Lt({s:e}){let{t,locale:n}=M(),{toast:r,confirm:a}=U(),o=i(),s=u(),c=Mt(e,t),l=async e=>{await H.copy(e)&&r(t(`common.copied`))},d=async e=>{if(e&&!Pt()){if(!await a({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;Ft()}(e||!s.data?.remote||await a({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&o.mutate(e,{onError:e=>r(V(e),`error`)})},f=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,h=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,g=e.state===`connected`&&h!==null?h<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:p(h,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),_=e.cloudflared,v=_.downloading||_.path?null:_.asset?t(`settings.remote.cloudflaredMissing`,{version:_.version??``}):t(`settings.remote.cloudflaredUnsupported`),y=e.enabled?e.error??_.error??null:null,b=y!==null&&(e.state!==`connected`||/origin service|origin server/i.test(y)),x=e.publicUrl;return(0,X.jsxs)(F,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(A,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?m(e.connectedAt,n):void 0,children:[(0,X.jsx)(me,{tone:f}),g,_.downloading&&_.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(_.progress*100),`%`]})]}),children:(0,X.jsx)(z,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:o.isPending||!e.enabled&&c!==null,onChange:e=>void d(e)})}),!e.enabled&&c&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:c}),!e.enabled&&!c&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:v}),e.enabled&&x&&(0,X.jsxs)(A,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${x}/v1`}),children:[(0,X.jsx)(ke,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(fe,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void l(`${x}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void l(x)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void l(`${x}/key`),separatorBefore:!0}]}),(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(G,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(x,`_blank`,`noopener`)})]}),e.enabled&&x&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),b&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(P,{tone:e.state===`connected`?`warning`:`danger`,title:Nt(y,e,t),children:y})})]})}function Rt({s:e}){let{t}=M(),{toast:n,confirm:r}=U(),i=_(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await H.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(V(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(V(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(F,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(A,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(y,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void c(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(P,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(C,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(A,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(C,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(A,{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)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(fe,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void s(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>window.open(At,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(N,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function zt({s:e}){let{t}=M(),{toast:n,confirm:r}=U(),i=_(),a=u(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(V(e),`error`)})};return(0,X.jsxs)(F,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(A,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(j,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(A,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(z,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(Bt,{passwordSet:e.checks.passwordSet})]})}function Bt({passwordSet:e}){let{t}=M(),{toast:n}=U(),r=u(),i=x(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.remote&&(0,X.jsx)(N,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(C,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(N,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(N,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(V(e),`error`)}),children:t(`common.save`)})]})]})}var Vt=[`auto`,`github`,`astra`,`custom`];function Ht({s:e}){let{t}=M(),{toast:n}=U(),r=_(),i=ee(),a=u(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[m,h]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>h(e.download.downloadSource),[e.download.downloadSource]);let g=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(V(e),`error`)}),v=t=>{h(t),(t!==`custom`||e.download.downloadBaseUrl)&&g({downloadSource:t})},y=()=>i.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(V(e),`error`)}),b=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(F,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(A,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:b}),children:(0,X.jsx)(me,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${m}.hint`),children:(0,X.jsx)(W,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:v,options:Vt.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),m===`custom`&&(0,X.jsxs)(A,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(C,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(N,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>g({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(A,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(N,{size:`sm`,disabled:r.isPending,onClick:()=>g({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(N,{size:`sm`,onClick:()=>{d(!0),y()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(C,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(N,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:y,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(N,{size:`sm`,variant:`plain`,onClick:()=>d(!1),children:t(`common.cancel`)}),(0,X.jsx)(N,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>g({cloudflaredPath:f.trim()},()=>d(!1)),children:t(`settings.remote.cf.use`)})]})]})}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:Ut}=r,Wt=[...r.ease.enter],Gt=[...r.ease.standard],Kt=[0,1,2,3,4,5,6,7,8,9],qt=6,Jt=400,Yt=40,Xt=240,Zt=1500,Qt=700,$t=700,en=.22,tn=4,nn=130,rn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),an=e=>(String(e).split(`.`)[1]??``).length,on=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),sn=(e,t)=>typeof e==`function`?e(t):e??``,cn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function ln(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 un={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Ut.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:Gt}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Ut.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Gt},opacity:{duration:$.instant},filter:{duration:$.instant}}})},dn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),fn={enter:dn(0),center:{...dn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},pn={enter:dn(1),center:{...dn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function mn({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=He(e,e=>`${n(e)*1.05}em`),i=He(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=He(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=He(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*Ut.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(D.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function hn({digit:e,direction:t,instant:n}){let r=ye(),i=Se(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):b(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`}),Kt.map(e=>(0,X.jsx)(mn,{position:i,digit:e},e))]})}function gn({value:e,format:t,direction:n,instant:r}){let i=ye(),a=r?pn:i?fn:un;return(0,X.jsx)(R,{initial:!1,custom:n,children:ln(e,t).map(e=>(0,X.jsx)(D.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)(hn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function _n({text:e,direction:t,className:n}){let r=ye();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(R,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(D.span,{className:Z.char,custom:t,variants:r?fn:un,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var vn=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},yn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=vn(n[t]),i=vn(e);return r!==null&&i!==null&&i<r?-1:1})},bn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Ut.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:Wt,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Ut.subtle}px)`,transition:{duration:.14,ease:Gt}})},xn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Sn({word:e,direction:t}){let n=ye(),r=(0,Y.useRef)(null),i=Se(`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):b(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(D.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(R,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(D.span,{className:Z.word,custom:t,variants:n?xn:bn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Cn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:yn(t.text,e)});let r=t.text===e?t.directions:yn(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)(Sn,{word:e,direction:r[t]??1})]},t))})]})}function wn({id:e,text:t,className:n}){return(0,X.jsx)(R,{initial:!1,children:t?(0,X.jsx)(Tn,{id:e,text:t,className:n},`message`):null})}function Tn({id:e,text:t,className:n}){let r=ye(),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)(D.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)(D.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${Ut.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:Wt},children:(0,X.jsx)(Cn,{text:t})})})}function En({id:e,edge:t,text:n}){let r=ye();return(0,X.jsx)(R,{initial:!1,children:t!==0&&(0,X.jsx)(D.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${Ut.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:Gt}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function Dn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?q:ct;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 On({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=ye(),y=(0,Y.useId)(),x=u??y,ee=c?`${x}-description`:void 0,S=`${x}-limit`,C=o>0?o:1,[te,w]=(0,Y.useState)(n),T=t??te,[E,ne]=(0,Y.useState)(``),[O,re]=(0,Y.useState)(!1),[ie,k]=(0,Y.useState)(0),[ae,oe]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(``),[se,ce]=(0,Y.useState)(0),[le,M]=(0,Y.useState)(!1),ue=(0,Y.useRef)(null),de=(0,Y.useRef)(null),fe=(0,Y.useRef)(null),pe=(0,Y.useRef)(void 0),N=(0,Y.useRef)(void 0),me=(0,Y.useRef)(void 0),he=(0,Y.useRef)({edge:0,count:0,at:0}),P=(0,Y.useRef)(null),ge=(0,Y.useRef)(null),F=(0,Y.useRef)(T),_e=(0,Y.useRef)(T),ve=(0,Y.useRef)(void 0),I=(0,Y.useRef)(null),L=(0,Y.useRef)(!1),R=(0,Y.useRef)(null),be=(0,Y.useRef)(!1),xe=(0,Y.useRef)(()=>!1),z=Se(0),Ce=Se(0),B=Se(0),we=He(()=>Ce.get()+B.get()),Te=Number.isFinite(i)?i:0,Ee=Math.max(an(C),an(Te)),De=h?.minimumFractionDigits??Ee,V=Math.max(De,h?.maximumFractionDigits??Ee),H=h?.useGrouping??!0,Oe=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:De,maximumFractionDigits:V,useGrouping:H,numberingSystem:`latn`}),[m,De,V,H]),ke=(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]),U=e=>Number(e.toFixed(Ee))||0,W=e=>Math.min(a,Math.max(i,e)),Ae=e=>U(Te+Math.round((e-Te)/C)*C),je=(e,t)=>{let n=(e-Te)/C;return U(Te+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*C)},Me=e=>`${sn(d,e)}${Oe.format(e)}${sn(f,e)}`.trim();function Ne(e){let t=e.split(ke.group).join(``).replace(ke.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Pe=O?Ne(E):null,G=Pe??T,[Fe,Ie]=(0,Y.useState)({value:G,direction:1});Fe.value!==G&&Ie({value:G,direction:G>Fe.value?1:-1});let Le=Fe.value===G?Fe.direction:G>Fe.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(ve.current),window.clearTimeout(pe.current),window.clearTimeout(N.current),window.clearTimeout(me.current)},[]);function Re(e,t){let n=performance.now(),r=he.current;r.count=r.edge===e&&n-r.at<$t?r.count+1:1,r.edge=e,r.at=n;let i=ue.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(me.current),me.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!v){b(z,0,{...rn,velocity:-e*nn*(1+Math.min(r.count-1,tn)*en)});let n=(e>0?fe:de).current;n&&(t===`button`||t===`key`)&&b(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}_&&(ce(e),window.clearTimeout(pe.current),pe.current=window.setTimeout(()=>ce(0),Zt))}function K(e,n){if(!Number.isFinite(e))return!1;let i=W(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Re(a>0?1:-1,n),j(`${Me(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&j(Me(i)),i!==F.current&&(F.current=i,t===void 0&&w(i),r?.(i),!0)}let ze=(e,t,n)=>K(je(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=T,xe.current=ze});function Be(){let e=ge.current;e&&R.current===null&&(R.current=e.getBoundingClientRect().left-Ce.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=R.current,t=ge.current;if(R.current=null,be.current){be.current=!1;let e=P.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-Ce.get()-B.get());Math.abs(n)<.5||(B.set(B.get()+n),v?B.jump(0):b(B,0,Q.morph))});function Ve(){window.clearTimeout(N.current),M(!1)}function q(){if(!O)return;Be(),re(!1),Ve();let e=Ne(E);e!==null&&K(Ae(e),`type`)}function Ue(){window.clearTimeout(ve.current),ve.current=void 0,k(0)}function We(e,t,n){Ue(),q();let r=Math.max(1,Math.round(t/C));n===`button`&&k(e);let i=0,a=()=>{let t=xe.current(e,r,n);ve.current=window.setTimeout(a,t?Math.max(Yt,150*.86**++i):Xt)};ve.current=window.setTimeout(a,ze(e,r,n)?Jt:360)}function Ge(e){let t=s??C*10,n={ArrowUp:[1,e.shiftKey?t:C],ArrowDown:[-1,e.shiftKey?t:C],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||We(n[0],n[1],`key`);return}if(!O&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),K(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),O?(be.current=!0,q()):e.currentTarget.select()),e.key===`Escape`&&O&&(e.preventDefault(),Be(),re(!1),Ve(),be.current=!0,K(_e.current,`type`))}function Ke(e){let t=RegExp(`[^0-9${on(ke.group)}${Ee||V?on(ke.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);O||(_e.current=T),Be(),ne(n),re(!0);let r=Ne(n);r!==null&&r>=i&&r<=a&&Ae(r)===r&&K(r,`type`),Ve(),r!==null&&r<i&&(N.current=window.setTimeout(()=>M(!0),Qt))}function qe(e){L.current=!1,p&&!l&&e.button===0&&(q(),I.current={pointer:e.pointerId,x:e.clientX,from:F.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Je(e){let t=I.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,oe(!0)}let r=n/qt,o=Math.trunc(r);K(o?je(t.from,o):t.from,`scrub`);let s=t.from+r*C,c=s>a?(s-a)/C*qt:s<i?(s-i)/C*qt:0;Ce.set(v?0:cn(c))}function Ye(e){let t=I.current;t&&t.pointer===e.pointerId&&(I.current=null,t.active&&(L.current=!0,oe(!1),b(Ce,0,v?{duration:0}:Q.snappy),j(Me(F.current))))}let Xe=t=>({toward:t,label:e,disabled:l,controls:x,limit:t>0?G>=a:G<=i,pressed:ie===t}),Ze=Pe===null?0:Pe>a?1:Pe<i&&le?-1:0,J=_?Ze||se:0,Qe=J>0?a:i,$e=J?typeof _==`function`?_(J>0?`max`:`min`,Qe):`${J>0?`Max`:`Min`} ${Me(Qe)}`:``,et=[ee,Ze&&_?S: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:x,className:Z.label,"data-scrub":p&&!l||void 0,onPointerDown:qe,onPointerMove:Je,onPointerUp:Ye,onPointerCancel:Ye,onClick:e=>{L.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(En,{id:S,edge:J,text:$e})]}),(0,X.jsxs)(`div`,{ref:ue,className:Z.control,"data-scrubbing":ae||void 0,"data-disabled":l||void 0,"data-warn":Ze?Ze>0?`max`:`min`:void 0,children:[(0,X.jsx)(Dn,{...Xe(-1),iconRef:de,onPress:()=>We(-1,C,`button`),onRelease:Ue,onActivate:()=>{q(),ze(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==P.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==P.current&&(P.current?.focus(),P.current?.select())},children:(0,X.jsxs)(D.span,{ref:ge,className:Z.value,style:{x:we,y:z},children:[(0,X.jsx)(_n,{text:sn(d,G),direction:Le,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":O||void 0,"aria-hidden":`true`,children:(0,X.jsx)(gn,{value:G,format:Oe,direction:Le,instant:O})}),O&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:E}),(0,X.jsx)(`input`,{ref:P,id:x,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:Ee||V?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:O?E:Oe.format(T),disabled:l,"aria-describedby":et,"aria-invalid":Ze?!0:void 0,"aria-valuenow":T,"aria-valuetext":Me(T),"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(),q()}})]}),(0,X.jsx)(_n,{text:sn(f,G),direction:Le,className:Z.affix})]})}),(0,X.jsx)(Dn,{...Xe(1),iconRef:fe,onPress:()=>We(1,C,`button`),onRelease:Ue,onActivate:()=>{q(),ze(1,1,`button`)}})]}),(0,X.jsx)(wn,{id:ee,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:A})]})}var kn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function An(){let{t:e}=M(),t=S(),[n,r]=De(),i=je(),a=we(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(A,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(z,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(B(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)(jn,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Ie,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:he.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(jn,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:kn.map(o)})}),(0,X.jsx)(jn,{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)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),onClick:()=>r(Te),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(jn,{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)(Me,{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 jn({title:e,hint:t,children:n}){let{t:r}=M();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 Mn=[`general`,`notifications`,`remote`,`tray`],Nn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Pn(){let{t:e}=M(),{tab:t}=Ve(),n=We(),r=Ee(),i=Mn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)(Xe,{title:e(`nav.settings`),children:(0,X.jsxs)(Ze,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ge,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(J,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ft,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(J,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(nt,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(J,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(E,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(J,{value:`tray`,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.tray`)]})})]}),(0,X.jsx)(Qe,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Fn,{})}),(0,X.jsx)(Qe,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(bt,{})}),(0,X.jsx)(Qe,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(It,{})}),r&&(0,X.jsx)(Qe,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(An,{})})]})})}function Fn(){let{t:e,locale:t,setLocale:r}=M(),i=qe(),a=be(),o=pe(),s=S(),c=te(),l=u(),d=n(),f=Ce(),{toast:p,confirm:m}=U(),h=a.data,g=f.data?.state===`connected`&&f.data.publicUrl?`${f.data.publicUrl}/v1`:null,_=e=>o.mutate(e,{onError:e=>p(V(e),`error`)}),v=e=>{r(e),_({locale:e})},b=async t=>{await H.copy(t)&&p(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(F,{title:e(`settings.appearance`),children:[(0,X.jsx)(A,{label:e(`settings.theme`),children:(0,X.jsx)(y,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.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)(A,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(W,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...Ye.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(A,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(y,{ariaLabel:e(`settings.language`),value:t,onChange:v,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(F,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(A,{label:e(`settings.gatewayUrl`),detail:`${h.gatewayBaseUrl}/v1`,children:(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(`${h.gatewayBaseUrl}/v1`)})}),g&&(0,X.jsx)(A,{label:e(`settings.remote.publicUrl`),detail:g,children:(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(g)})}),(0,X.jsx)(A,{label:e(`settings.listen`),detail:`${h.host}:${h.port}`}),(0,X.jsx)(A,{label:e(`settings.dataDir`),detail:h.dataDir,children:H.canOpenPaths?(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void H.openPath(h.dataDir)}):(0,X.jsx)(N,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(h.dataDir)})}),(0,X.jsx)(A,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(z,{checked:h.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await m({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&_({requireGatewayKey:t})}})}),(0,X.jsx)(A,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(zn,{label:e(`settings.streamIdle`),value:h.streamIdleTimeoutSec,onCommit:e=>_({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(A,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(W,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:h.requestCompression,onChange:e=>_({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)(Ln,{settings:h}),(0,X.jsx)(Rn,{settings:h}),(0,X.jsxs)(F,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(A,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(zn,{label:e(`settings.quota.autoInterval`),value:h.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:xe.providers}),onError:e=>p(V(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(A,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(zn,{label:e(`settings.quota.subscriptionInterval`),value:h.subscriptionQuotaIntervalMinutes,onCommit:e=>_({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(F,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(A,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(W,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:h.usageTimeZone??``,onChange:e=>_({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:h.effectiveUsageTimeZone})},...[...new Set([...Nn,...h.usageTimeZone?[h.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(F,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(A,{label:e(`settings.debugBodies`),children:(0,X.jsx)(z,{checked:h.debugBodies,label:e(`settings.debugBodies`),onChange:e=>_({debugBodies:e})})}),(0,X.jsx)(A,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(zn,{label:e(`settings.bodyRetention`),value:h.bodyRetentionDays,onCommit:e=>_({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(A,{label:e(`settings.requestRetention`),detail:h.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(z,{checked:h.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>_({requestRetentionDays:e?90:null})}),h.requestRetentionDays!=null&&(0,X.jsx)(zn,{label:e(`settings.requestRetention`),value:h.requestRetentionDays,onCommit:e=>_({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(F,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(A,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(zn,{label:e(`settings.effort.${t}`),value:h.effortBudgets[t],onCommit:e=>_({effortBudgets:{...h.effortBudgets,[t]:e??h.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:V(a.error)}):(0,X.jsx)(I,{className:`mx-auto my-8`}),(0,X.jsxs)(F,{title:e(`settings.about`),children:[(0,X.jsx)(A,{label:e(`settings.serverVersion`),detail:c.data?`${c.data.version} · API ${c.data.apiVersion}`:`—`}),ve&&(0,X.jsx)(A,{label:e(`settings.desktopVersion`),detail:oe()?.version||`—`}),(0,X.jsx)(In,{}),ve&&(0,X.jsx)(A,{label:e(`settings.logs`),onClick:()=>void H.revealLogs(),children:(0,X.jsx)(Le,{className:`size-4 text-[var(--text-secondary)]`})}),l.data?.required&&(0,X.jsx)(A,{label:e(`settings.logout`),onClick:()=>d.mutate(),children:(0,X.jsx)(Re,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function In(){let{t:e}=M(),{toast:t}=U(),n=S(),r=pe(),i=a(),o=f(),s=i.data,c=oe()?.updates??null,[l,u]=(0,Y.useState)(!1),d=()=>o.mutate(void 0,{onSuccess:n=>t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(V(e),`error`)}),p=()=>{c&&!l&&(u(!0),c.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:xe.version}),n.invalidateQueries({queryKey:xe.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:`settings.upToDate`))}).catch(e=>t(V(e),`error`)).finally(()=>u(!1)))},m=s?.lastCheckAt?new Date(s.lastCheckAt).toLocaleString():void 0,h=s?.available?c?e(`settings.updateAvailable`,{version:s.available}):`${e(`settings.updateAvailable`,{version:s.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:e(`settings.autoCheck`),detail:s&&!s.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(z,{checked:s?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(V(e),`error`)})})}),(0,X.jsxs)(A,{label:e(`settings.checkUpdates`),detail:o.isError?e(`settings.updateCheckFailed`,{error:V(o.error)}):s?.available?h:m?e(`settings.lastChecked`,{time:m}):void 0,children:[(0,X.jsx)(N,{size:`sm`,variant:`plain`,disabled:o.isPending,onClick:d,children:o.isPending?(0,X.jsx)(I,{className:`size-3.5`}):(0,X.jsx)(Ke,{className:`size-3.5`})}),c&&s?.available&&(0,X.jsx)(N,{size:`sm`,variant:`plain`,disabled:l,"aria-label":e(`settings.updateApply`),onClick:p,children:l?(0,X.jsx)(I,{className:`size-3.5`}):(0,X.jsx)(Ne,{className:`size-3.5`})})]})]})}function Ln({settings:e}){let{t}=M(),{toast:n}=U(),r=pe(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(V(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(V(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(F,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(A,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(y,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:c,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),i===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(C,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(A,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(C,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(A,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(C,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(A,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(C,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(N,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Rn({settings:e}){let{t}=M(),{toast:n}=U(),r=pe(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(V(e),`error`)});return(0,X.jsxs)(F,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(A,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(z,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(C,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(N,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(N,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(On,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Pn as SettingsPage};
@@ -0,0 +1 @@
1
+ import{J as e,K as t,Lr as n,V as r,Xr as i,Y as a,Yn as o,Yt as s,Z as c,Zn as l,_ as u,c as d,d as f,dr as p,l as m,la as h,mr as g,n as _,ot as v,p as y,pa as b,pt as x,q as S,r as C,rn as w,t as T,ua as E,v as D,xr as O,zr as k}from"./alert-C-zJo-Vf.js";import{a as A,gt as j,i as M,n as N,o as P,r as F}from"./overlays-BBHZHl4R.js";import{t as I}from"./ellipsis-Dwk6_QlF.js";import{t as ee}from"./pencil-C7HWLb95.js";import{t as te}from"./power-BggG52OJ.js";import{t as ne}from"./rotate-ccw-Xx5_g9bd.js";import{D as L,F as R,M as z,P as B,f as V,m as H,s as U,u as re}from"./index-CNdW2eN9.js";var W=b(E(),1),G=h();function K(){let{t:e}=v(),t=n(),r=O(),i=k(),a=i.data?.state===`connected`?i.data.publicUrl:null,[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(null);return(0,G.jsxs)(re,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,G.jsx)(C,{variant:`primary`,icon:(0,G.jsx)(z,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[r.data&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,G.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${r.data.gatewayBaseUrl}/v1`})}),(0,G.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:r.data.gatewayBaseUrl})}),a&&(0,G.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,G.jsx)(D,{lines:4}),t.isError&&(0,G.jsx)(T,{tone:`danger`,title:e(`common.error`),children:A(t.error)}),t.data?.length===0&&(0,G.jsx)(`div`,{className:`card`,children:(0,G.jsx)(d,{icon:(0,G.jsx)(B,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,G.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,G.jsx)(q,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,G.jsx)(ae,{open:o,onOpenChange:s}),(0,G.jsx)(oe,{token:c,onClose:()=>l(null)})]})}function q({token:t,defaultOpen:n,onEdit:a}){let{t:o,locale:s}=v(),{toast:u,confirm:d}=P(),f=l(),m=g(),h=i(),y=p(),b=w(),[T,E]=(0,W.useState)(n),D=(f.data??[]).find(e=>e.id===t.providerId),O=`token-detail-${t.id}`,k=(e,t)=>{u(t,`success`),e.skipped.length>0&&u(o(`tokens.skipped`,{clients:e.skipped.map(e=>V[e]?.name??e).join(`, `)}),`error`)},M=()=>m.mutate(t.id,{onSuccess:async({token:e})=>{await j.copy(e)&&u(o(`tokens.copied`))},onError:e=>u(A(e),`error`)}),F=async()=>{(!t.enabled||await d({title:o(`tokens.disableConfirm`,{name:t.name}),detail:o(`tokens.disableDetail`),confirmLabel:o(`tokens.disable`),destructive:!0}))&&h.mutate({id:t.id,enabled:!t.enabled},{onError:e=>u(A(e),`error`)})},z=async()=>{await d({title:o(`tokens.resetConfirm`,{name:t.name}),detail:o(`tokens.resetDetail`),confirmLabel:o(`tokens.reset`),destructive:!0})&&y.mutate(t.id,{onSuccess:e=>k(e,o(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>u(A(e),`error`)})},B=async()=>{await d({title:o(`tokens.deleteConfirm`,{name:t.name}),detail:o(`tokens.deleteDetail`),confirmLabel:o(`common.delete`),destructive:!0})&&b.mutate(t.id,{onSuccess:e=>k(e,o(`tokens.deleted`,{name:t.name})),onError:e=>u(A(e),`error`)})},U=t.lastUsedAt?r(t.lastUsedAt,s):o(`tokens.neverUsed`);return(0,G.jsxs)(`article`,{children:[(0,G.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>E(e=>!e),children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":T,"aria-controls":O,"aria-label":o(`tokens.details`),onClick:e=>{e.stopPropagation(),E(e=>!e)},children:(0,G.jsx)(R,{className:`size-4 transition-transform ${T?`rotate-90`:``}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${t.enabled?``:`text-[var(--text-muted)]`}`,children:t.name}),t.isDefault&&(0,G.jsx)(_,{tone:`accent`,children:o(`tokens.default`)}),!t.enabled&&(0,G.jsx)(_,{tone:`orange`,children:o(`tokens.disabledBadge`)}),t.limitUsage.some(e=>e.exhausted)&&(0,G.jsx)(_,{tone:`orange`,children:o(`tokens.limitExhausted`)})]}),(0,G.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:t.keyMasked}),(0,G.jsx)(C,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(x,{className:`size-3.5`}),"aria-label":o(`tokens.copy`),title:o(`tokens.copy`),loading:m.isPending,onClick:M})]})]})]}),(0,G.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:t.clients.map(e=>V[e]?.name??e).join(`, `)||o(`tokens.noClients`),children:t.clients.length===0?(0,G.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):t.clients.map(e=>(0,G.jsx)(H,{kind:e,size:16},e))}),(0,G.jsx)(X,{label:o(`tokens.today`),value:c(t.today.costUsd),context:o(`tokens.requestsContext`,{count:e(t.today.requests)})}),(0,G.jsx)(X,{label:o(`tokens.total`),value:c(t.total.costUsd),context:`${e(t.total.totalTokens,!0)} Token`}),(0,G.jsx)(X,{label:o(`tokens.lastUsedTitle`),value:t.lastUsedAt?S(t.lastUsedAt,s):`—`,context:t.lastUsedAt?``:o(`tokens.neverUsed`),title:U}),(0,G.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,G.jsx)(N,{label:o(`common.more`),icon:(0,G.jsx)(I,{className:`size-4`}),items:[{id:`settings`,label:o(`tokens.settings`),icon:(0,G.jsx)(ee,{className:`size-3.5`}),onSelect:a},{id:`toggle`,label:t.enabled?o(`tokens.disable`):o(`tokens.enable`),icon:(0,G.jsx)(te,{className:`size-3.5`}),onSelect:()=>void F()},{id:`reset`,label:o(`tokens.reset`),icon:(0,G.jsx)(ne,{className:`size-3.5`}),onSelect:()=>void z()},...t.isDefault?[]:[{id:`delete`,label:o(`tokens.delete`),icon:(0,G.jsx)(L,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void B()}]]})})]}),T&&(0,G.jsxs)(`div`,{id:O,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,G.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.clients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:t.clients.length===0?o(`tokens.noClients`):t.clients.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(H,{kind:e,size:14}),V[e]?.name??e]},e))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.directProvider`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:D?.name??(t.providerId?t.providerId:o(`tokens.directNone`))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.allowedClients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:t.allowedClients==null?o(`tokens.allowedClientsAny`):t.allowedClients.length===0?o(`tokens.directOnly`):t.allowedClients.map(e=>V[e]?.name??e).join(`, `)})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.lastUsedTitle`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:U})]})]}),(0,G.jsx)(J,{token:t}),(0,G.jsx)(ie,{today:t.today,total:t.total})]})]})}function J({token:e}){let{t}=v(),n=e.limits?.rpm;return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,G.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,G.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,G.jsx)(Y,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,G.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,G.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function Y({usage:t}){let{t:n,locale:i}=v(),a=`${n(`tokens.period.${t.period}`)} · ${n(`tokens.metric.${t.metric}`)}`,o=n=>t.metric===`cost`?c(n):e(n,!0),s=Math.max(0,Math.min(100,Math.round(t.usedPercent))),l=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,G.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:a}),(0,G.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(t.used),limit:o(t.limit)})})]}),(0,G.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":a,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:l}})}),t.resetsAt&&(0,G.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:r(t.resetsAt,i)})})]})}function X({label:e,value:t,context:n,title:r}){return(0,G.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,G.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function ie({today:n,total:r}){let{t:i}=v(),o=[[i(`tokens.today`),n],[i(`tokens.total`),r]],s=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,l=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,G.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,G.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,G.jsx)(`th`,{className:`${s} text-left`}),(0,G.jsx)(`th`,{className:s,children:i(`tokens.cost`)}),(0,G.jsx)(`th`,{className:s,children:i(`tokens.requests`)}),(0,G.jsx)(`th`,{className:s,children:i(`tokens.tokens`)}),(0,G.jsx)(`th`,{className:s,children:i(`tokens.inOut`)}),(0,G.jsx)(`th`,{className:s,children:i(`tokens.cacheHit`)}),(0,G.jsx)(`th`,{className:s,title:i(`tokens.tpsContext`),children:i(`tokens.tps`)})]})}),(0,G.jsx)(`tbody`,{children:o.map(([n,r])=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:n}),(0,G.jsx)(`td`,{className:`${l} font-semibold selectable`,children:c(r.costUsd)}),(0,G.jsx)(`td`,{className:l,children:e(r.requests)}),(0,G.jsx)(`td`,{className:l,children:e(r.totalTokens,!0)}),(0,G.jsxs)(`td`,{className:`${l} text-[var(--text-secondary)]`,children:[e(r.inputTokens,!0),` / `,e(r.outputTokens,!0)]}),(0,G.jsx)(`td`,{className:l,title:i(`usage.cacheAmounts`,{read:e(r.cacheReadTokens,!0),write:e(r.cacheWriteTokens,!0)}),children:r.cacheHitRate==null?`—`:t(r.cacheHitRate)}),(0,G.jsx)(`td`,{className:l,children:r.tps==null?`—`:a(r.tps)})]},n))})]})})}function Z(){let{t:e}=v(),t=(l().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function ae({open:e,onOpenChange:t}){let{t:n}=v(),{toast:r}=P(),i=s(),{options:a}=Z(),[o,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``);return(0,W.useEffect)(()=>{e&&(c(``),u(``))},[e]),(0,G.jsx)(M,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(C,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,G.jsx)(C,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:l||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(A(e),`error`)}),children:n(`common.create`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(m,{label:n(`tokens.name`),children:(0,G.jsx)(f,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>c(e.target.value)})}),(0,G.jsx)(m,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:l,onChange:u,options:a})})]})})}function oe({token:e,onClose:t}){let{t:n}=v(),{toast:r}=P(),a=i(),{providers:s,options:c}=Z(),[l,d]=(0,W.useState)(``),[p,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(``),[b,x]=(0,W.useState)([]),[S,w]=(0,W.useState)(null),[T,E]=(0,W.useState)(`any`),[D,O]=(0,W.useState)([]),k=s.find(e=>e.id===p),j=k?.authScheme===`oauth-subscription`||k?.authScheme===`plugin`,N=o(k?.id,j),I=new Set(b.map(e=>`${e.metric}:${e.period}`)).size<b.length;return(0,W.useEffect)(()=>{e&&(d(e.name),h(e.providerId??``),_(e.accountId??``),x(e.limits?.budgets.map(e=>({...e}))??[]),w(e.limits?.rpm??null),E(e.allowedClients==null?`any`:`only`),O(e.allowedClients??[]))},[e]),(0,G.jsx)(M,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(C,{onClick:t,children:n(`common.cancel`)}),(0,G.jsx)(C,{variant:`primary`,disabled:!l.trim()||I,loading:a.isPending,onClick:()=>{if(!e)return;let i=b.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),o=i.length>0||S!=null&&S>0?{budgets:i,rpm:S!=null&&S>0?Math.floor(S):null}:null;a.mutate({id:e.id,name:l.trim(),providerId:p||null,accountId:j&&g||null,limits:o,allowedClients:T===`any`?null:D},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(A(e),`error`)})},children:n(`common.save`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(m,{label:n(`tokens.name`),children:(0,G.jsx)(f,{value:l,maxLength:64,onChange:e=>d(e.target.value)})}),(0,G.jsx)(m,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:p,onChange:e=>{h(e),_(``)},options:c})}),j&&(0,G.jsx)(m,{label:n(`tokens.directAccount`),children:(0,G.jsx)(F,{value:g,onChange:_,options:[{value:``,label:n(`clients.accountDefault`)},...(N.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]})}),(0,G.jsx)(m,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:I?n(`tokens.limitDuplicate`):void 0,children:(0,G.jsx)(se,{budgets:b,onChange:x})}),(0,G.jsx)(m,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,G.jsx)(y,{value:S,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:w})}),(0,G.jsx)(m,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(u,{ariaLabel:n(`tokens.allowedClients`),value:T,onChange:E,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),T===`only`&&(0,G.jsx)(U,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(V),...D])].map(e=>({value:e,label:V[e]?.name??e})),value:D,onValueChange:e=>O(e)})]})})]})})}var Q=[`cost`,`requests`,`tokens`],$=[`day`,`week`,`month`,`total`];function se({budgets:e,onChange:t}){let{t:n}=v(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=Q.flatMap(e=>$.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,G.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:Q.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,G.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:$.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,G.jsx)(y,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,G.jsx)(C,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(L,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,G.jsx)(`div`,{children:(0,G.jsx)(C,{size:`sm`,icon:(0,G.jsx)(z,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{K as TokensPage};
@@ -0,0 +1 @@
1
+ import{ca as e,la as t,li as n,ot as r,pa as i,ua as a,vr as o,xt as s}from"./alert-C-zJo-Vf.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-BBHZHl4R.js";import{t as h}from"./TrayPanelView-DP-m1Cui.js";var g=i(a(),1),_=t(),v=new Set([`astra.theme`,`astra.accent`,`astra.locale`]);function y(){let{t}=r(),i=e(),{toast:a}=p(),y=n(),[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=o(),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)(()=>{i.invalidateQueries({queryKey:[`stats`]}),i.invalidateQueries({queryKey:s.providers}),i.invalidateQueries({queryKey:s.clients}),i.invalidateQueries({queryKey:[`provider-accounts`]})},[i]);(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`)&&a(t(`common.copied`))},M=async e=>{let n=E.providers;if(n.length===0)return;let r=await f.contextMenu(n.map(n=>({id:n.id,label:n.enabled?n.name:t(`tray.disabledProvider`,{name:n.name}),type:`checkbox`,checked:n.id===e.providerId})));r&&r!==e.providerId&&D.mutate({kind:e.kind,providerId:r},{onError:e=>a(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};