@aidotnet/server-linux-x64 0.9.4 → 0.9.6

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 (54) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-DEetiYfc.js +9 -0
  3. package/bin/wwwroot/assets/KeyPage-cq7HprCR.js +1 -0
  4. package/bin/wwwroot/assets/ModelDetailPage-Uj6p-r8V.js +1 -0
  5. package/bin/wwwroot/assets/ModelsPage-B-l5oEGF.js +1 -0
  6. package/bin/wwwroot/assets/PluginsPage-BH9KjyfC.js +2 -0
  7. package/bin/wwwroot/assets/PrivacyPage-C5XhVKZd.js +1 -0
  8. package/bin/wwwroot/assets/ProviderDetailPage-uLPHWm2i.js +3 -0
  9. package/bin/wwwroot/assets/ProvidersPage-CNU_ji4e.js +2 -0
  10. package/bin/wwwroot/assets/SettingsPage-B3tbYdLW.js +2 -0
  11. package/bin/wwwroot/assets/TokenDetailPage-BVyb_-ev.js +1 -0
  12. package/bin/wwwroot/assets/TokenPoolEditor-7LX143SO.js +1 -0
  13. package/bin/wwwroot/assets/TokensPage-vRrXvqkK.js +1 -0
  14. package/bin/wwwroot/assets/{TracesPage-Bzy2gUvV.js → TracesPage-C9mYB_7E.js} +2 -2
  15. package/bin/wwwroot/assets/{TrayPanelPage-BZS_htv0.js → TrayPanelPage-NIkRrLCt.js} +1 -1
  16. package/bin/wwwroot/assets/{TrayPanelView-CYoAUUiY.js → TrayPanelView-BpQQa0qi.js} +1 -1
  17. package/bin/wwwroot/assets/alert-CN1yWco4.js +15 -0
  18. package/bin/wwwroot/assets/{arrow-down-7oFM4dM3.js → arrow-down-DP0xP3tk.js} +1 -1
  19. package/bin/wwwroot/assets/{arrow-left-Dn6_YDkh.js → arrow-left-UUQiUGQ1.js} +1 -1
  20. package/bin/wwwroot/assets/{checkbox-DzIMWhhw.js → checkbox-BEWRhO5r.js} +1 -1
  21. package/bin/wwwroot/assets/{cloud-download-Bvry8vmS.js → cloud-download-DebyBXx2.js} +1 -1
  22. package/bin/wwwroot/assets/confirm-morph-DwiVsert.js +1 -0
  23. package/bin/wwwroot/assets/{download-5xAFYJ6Q.js → download-C4--ZCHf.js} +1 -1
  24. package/bin/wwwroot/assets/{ellipsis-Dxds5r72.js → ellipsis-D250KISp.js} +1 -1
  25. package/bin/wwwroot/assets/{external-link-Bq_1v6I1.js → external-link-Bnshhxip.js} +1 -1
  26. package/bin/wwwroot/assets/{folder-open-BXsxEYtm.js → folder-open-BzVuhS53.js} +1 -1
  27. package/bin/wwwroot/assets/{index-mlmGhWY4.js → index-CBrXkG99.js} +10 -10
  28. package/bin/wwwroot/assets/index-DE_l9Wt4.css +1 -0
  29. package/bin/wwwroot/assets/{log-out-B9HHsF8m.js → log-out-DEZofPIg.js} +1 -1
  30. package/bin/wwwroot/assets/minus-BAoIEc33.js +1 -0
  31. package/bin/wwwroot/assets/overlays-D2pWmtov.js +41 -0
  32. package/bin/wwwroot/assets/{pencil-BAzRd1Ro.js → pencil-DuD1bQje.js} +1 -1
  33. package/bin/wwwroot/assets/{power-DrpargJA.js → power-LE8gLJKc.js} +1 -1
  34. package/bin/wwwroot/assets/radio-cards-D1yOuSfh.js +1 -0
  35. package/bin/wwwroot/assets/{rotate-ccw-D6r7Boub.js → rotate-ccw-Cx9vNOkF.js} +1 -1
  36. package/bin/wwwroot/assets/sortable.esm-B0eMzUNN.js +5 -0
  37. package/bin/wwwroot/index.html +4 -4
  38. package/package.json +1 -1
  39. package/bin/wwwroot/assets/ClientsPage-DzZnCU7V.js +0 -12
  40. package/bin/wwwroot/assets/KeyPage-CtHw5I7A.js +0 -1
  41. package/bin/wwwroot/assets/ModelDetailPage-KY2k0x3l.js +0 -1
  42. package/bin/wwwroot/assets/ModelsPage-Bo8oA3Zb.js +0 -1
  43. package/bin/wwwroot/assets/PluginsPage-BMP78mVY.js +0 -2
  44. package/bin/wwwroot/assets/PrivacyPage-BgldsSQj.js +0 -1
  45. package/bin/wwwroot/assets/ProviderDetailPage-B6EfUhXb.js +0 -3
  46. package/bin/wwwroot/assets/ProvidersPage-DclHIvR2.js +0 -2
  47. package/bin/wwwroot/assets/SettingsPage-D29CZiaV.js +0 -2
  48. package/bin/wwwroot/assets/TokensPage-CaF-wXlr.js +0 -1
  49. package/bin/wwwroot/assets/alert-CGUFPyGb.js +0 -15
  50. package/bin/wwwroot/assets/confirm-morph-DnwMPT3r.js +0 -1
  51. package/bin/wwwroot/assets/index-BXZibBui.css +0 -1
  52. package/bin/wwwroot/assets/minus-BVd6Aw9t.js +0 -1
  53. package/bin/wwwroot/assets/overlays-B1a0OZYb.js +0 -41
  54. package/bin/wwwroot/assets/radio-cards-Cr0tP9In.js +0 -1
@@ -1,2 +0,0 @@
1
- import{$n as e,Ai as t,At as n,Br as r,Di as i,E as a,Ei as o,Ft as s,Jr as c,Mt as l,Oi as u,Pt as d,Qt as f,Rr as p,Sa as m,Ti as h,Tn as g,Tr as _,U as v,V as y,Vr as b,Yr as x,Zt as ee,_ as S,_a as C,an as w,bi as T,br as E,d as D,di as te,ft as O,gi as k,hi as ne,hr as A,i as re,jt as ie,l as j,li as ae,m as M,n as N,ni as oe,nr as se,o as ce,oi as le,on as ue,ot as P,p as de,pi as fe,pt as F,qr as pe,qt as me,r as I,ri as he,s as ge,si as _e,t as ve,u as L,ui as ye,v as R,va as be,vi as xe,vt as z,xn as Se,xr as Ce,xt as B,y as V,ya as we,yi as H,zt as Te}from"./alert-CGUFPyGb.js";import{B as Ee,F as De,I as Oe,L as ke,R as Ae,a as U,gt as W,i as je,n as G,o as K,r as q,vt as J,z as Me}from"./overlays-B1a0OZYb.js";import{t as Ne}from"./TrayPanelView-CYoAUUiY.js";import{t as Pe}from"./download-5xAFYJ6Q.js";import{t as Fe}from"./ellipsis-Dxds5r72.js";import{t as Ie}from"./external-link-Bq_1v6I1.js";import{n as Le,t as Re}from"./radio-cards-Cr0tP9In.js";import{t as ze}from"./folder-open-BXsxEYtm.js";import{t as Be}from"./log-out-B9HHsF8m.js";import{t as Ve}from"./minus-BVd6Aw9t.js";import{t as He}from"./pencil-BAzRd1Ro.js";import{t as Ue}from"./rotate-ccw-D6r7Boub.js";import{C as We,E as Ge,I as Ke,L as qe,M as Je,T as Ye,X as Xe,Z as Ze,et as Qe,h as $e,n as et,s as tt,t as nt,w as rt,z as it}from"./index-mlmGhWY4.js";var at={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};at.node;var ot=z(at),st={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};st.node;var ct=z(st),lt={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};lt.node;var ut=z(lt),dt={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};dt.node;var ft=z(dt),pt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};pt.node;var mt=z(pt),ht={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};ht.node;var gt=z(ht),_t={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};_t.node;var vt=z(_t),Y=m(we(),1),X=be(),yt=`https://astra-gate.si/docs/guide/remote-access`,bt=`astra.remote.acknowledged`;function xt(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function St(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Ct(){try{return localStorage.getItem(bt)===`1`}catch{return!1}}function wt(){try{localStorage.setItem(bt,`1`)}catch{}}function Tt(){let{t:e}=P(),t=pe(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Et,{s:n}),(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(jt,{s:n}),(0,X.jsx)(ce,{title:n.cloudflared.path&&n.cloudflared.version?e(`settings.remote.logWithVersion`,{version:n.cloudflared.version}):e(`settings.remote.log`),children:n.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:e(`settings.remote.logEmpty`)}):(0,X.jsx)(`pre`,{className:`max-h-72 overflow-auto font-mono text-[10.5px] leading-relaxed whitespace-pre-wrap text-[var(--text-secondary)] selectable`,children:n.log.join(`
2
- `)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(ve,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(t.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=P(),{toast:i,confirm:a}=K(),o=r(),s=d(),c=xt(e,t),l=async e=>{await W.copy(e)&&i(t(`common.copied`))},u=async e=>{if(e&&!Ct()){if(!await a({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;wt()}(e||!s.data?.remote||await a({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&o.mutate(e,{onError:e=>i(U(e),`error`)})},f=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,p=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,m=e.state===`connected`&&p!==null?p<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:v(p,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),h=e.cloudflared,g=h.downloading||h.path?null:h.asset?t(`settings.remote.cloudflaredMissing`,{version:h.version??``}):t(`settings.remote.cloudflaredUnsupported`),_=e.enabled?e.error??h.error??null:null,b=_!==null&&(e.state!==`connected`||/origin service|origin server/i.test(_)),x=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(M,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?y(e.connectedAt,n):void 0,children:[(0,X.jsx)(ge,{tone:f}),m,h.downloading&&h.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(h.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:o.isPending||!e.enabled&&c!==null,onChange:e=>void u(e)})}),!e.enabled&&c&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:c}),!e.enabled&&!c&&g&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:g}),e.enabled&&x&&(0,X.jsxs)(M,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${x}/v1`}),children:[(0,X.jsx)(G,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(F,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void l(`${x}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void l(x)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void l(`${x}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(x,`_blank`,`noopener`)})]}),e.enabled&&x&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),b&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(ve,{tone:e.state===`connected`?`warning`:`danger`,title:St(_,e,t),children:_})})]})}function Dt({s:e}){let{t}=P(),{toast:n,confirm:r}=K(),i=le(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await W.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(U(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(U(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(M,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(S,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void c(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(ve,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(M,{label:t(`settings.remote.origin`),detail:t(`settings.remote.originHint`),children:[(0,X.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.originUrl}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void s(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=P(),{toast:n,confirm:r}=K(),i=le(),a=d(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(U(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(M,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(N,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(M,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=P(),{toast:n}=K(),r=d(),i=E(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(U(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=P(),{toast:n}=K(),r=le(),i=ue(),a=d(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[m,h]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>h(e.download.downloadSource),[e.download.downloadSource]);let g=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(U(e),`error`)}),_=t=>{h(t),(t!==`custom`||e.download.downloadBaseUrl)&&g({downloadSource:t})},v=()=>i.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(U(e),`error`)}),y=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(M,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:y}),children:(0,X.jsx)(ge,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${m}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:_,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),m===`custom`&&(0,X.jsxs)(M,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>g({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(M,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>g({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{u(!0),v()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(D,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:v,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>g({cloudflaredPath:f.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=C(),i=Se(),a=d(),o=x(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),f=i.data;if(!f)return(0,X.jsx)(M,{label:e(`settings.listen`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=Pt(f.configuredHost),h=f.configuredHost!==f.host,g=!!a.data?.required,_=async n=>{await W.copy(n)&&t(e(`common.copied`))},v=n=>o.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(U(e),`error`)}),y=async t=>{if(t!==m){if(t===`lan`){if(!f.passwordSet){c(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}v(t)}},b=async()=>{u(!0);let n=await W.restartService();if(u(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},ee=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${H?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:e(`settings.listen`),detail:ee,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&H&&(0,X.jsx)(I,{size:`sm`,loading:l,onClick:()=>void b(),children:e(`settings.listen.restart`)}),(0,X.jsx)(S,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void y(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(M,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:f.passwordSet}),(0,X.jsx)(It,{open:s,onOpenChange:c,onSaved:()=>v(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=P(),{toast:i}=K(),a=E(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(U(e),`error`)})};return(0,X.jsx)(je,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(D,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(D,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Lt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Rt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},zt=e=>e===`feishu`||e===`dingtalk`,Bt=(e,t)=>e(`alerts.event.${t}`),Vt=(e,t)=>e(`alerts.event.${t}.hint`);function Ht(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Ut,{}),(0,X.jsx)(Wt,{}),(0,X.jsx)(Yt,{})]})}function Ut(){let{t:e,locale:t}=P(),n=l(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),n.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(M,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${y(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=te(),i=w(),a=p(),o=A(),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),m=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(U(e),`error`)}),h=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>f(e.secret??null),onError:e=>t(U(e),`error`)})},g=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(M,{icon:(0,X.jsx)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(N,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||zt(t.format))&&(0,X.jsx)(N,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(it,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Je,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void g(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:s,onClose:()=>c(null),onSecret:f}),(0,X.jsx)(qt,{hook:l,onClose:()=>u(null)}),(0,X.jsx)(Kt,{secret:d,onClose:()=>f(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=P(),{toast:i}=K(),a=ee(),o=_e(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(10),[p,m]=(0,Y.useState)(!0),[h,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(`generic`),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)([]),T=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),v(!t||t.hasSecret),b(t?.format??`generic`),S(``),w((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(T?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(U(e),`error`)},m=!T&&e!==null&&e.format!==y,g=zt(y)?_?x.trim()||void 0:``:void 0;T?a.mutate({...u,format:y,...y===`generic`?{signed:_}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:y}:{},...y===`generic`?_||!e.hasSecret||m?{}:{signed:!1}:g===void 0?{}:{secret:g}},{...f,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(D,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${y}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(D,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(j,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(D,{mono:!0,type:`password`,autoComplete:`off`,value:x,placeholder:e!==`new`&&e!==null&&e.format===y&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>S(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(de,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[C.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(D,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>w(C.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(D,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Je,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>w(C.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>w([...C,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(M,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(V,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:g})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(V,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?T||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(M,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=P(),{toast:r}=K();return(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await W.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=P(),{toast:i}=K(),a=ye(e?.id),o=se(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(N,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Bt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:y(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:y(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(re,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(re,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(U(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(t){let n=e(),r=b(),i=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),a=J({queries:i.map(e=>({queryKey:B.providerAccounts(e.id),queryFn:()=>fe(`GET`,`/api/providers/${ne(e.id)}/accounts`),enabled:t===`account`}))});return t===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):t===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):t===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Yt(){let{t:e}=P(),{toast:t,confirm:n}=K(),r=ie(),i=te(),a=c(),o=f(),[s,l]=(0,Y.useState)(null),u=e=>i.data?.find(t=>t.id===e)?.name??e,d=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(M,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(M,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(N,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Bt(e,n.event)} → ${n.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(U(e),`error`)})}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Je,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Zt,{rule:s,onClose:()=>l(null)})]})}function Xt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Zt({rule:e,onClose:t}){let{t:r}=P(),{toast:i}=K(),a=n(),o=te(),s=me(),l=c(),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[ee,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(null),[E,O]=(0,Y.useState)(60),k=a.data?.find(e=>e.id===f),ne=Jt(k?.subjectType),A=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=a.data?.[0];d(t?.name??``),p(t?.event??n?.id??``),h(t?{...Xt(a.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(o.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),T(t?.repeatMinutes??null),O(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(A?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!u.trim()||!f,loading:s.isPending||l.isPending,onClick:()=>{let n=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:u.trim(),event:f,condition:n,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:ee,repeatMinutes:w&&w>0?Math.floor(w):null,cooldownMinutes:Math.max(0,Math.floor(E??0))},o={onSuccess:()=>{t(),i(r(`common.saved`),`success`)},onError:e=>i(U(e),`error`)};A?s.mutate(a,o):e&&l.mutate({id:e.id,...a},o)},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.rules.name`),children:(0,X.jsx)(D,{value:u,maxLength:64,onChange:e=>d(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.rules.event`),hint:f?Vt(r,f):void 0,children:(0,X.jsx)(q,{ariaLabel:r(`alerts.rules.event`),value:f,onChange:e=>{p(e),h(Xt(a.data?.find(t=>t.id===e))),y([])},options:(a.data??[]).map(e=>({value:e.id,label:Bt(r,e.id)}))})}),k?.params.map(e=>(0,X.jsx)(j,{label:r(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(de,{value:typeof m[e.name]==`number`?m[e.name]:null,min:0,label:r(`alerts.param.${e.name}`),onChange:t=>h({...m,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:r(`alerts.param.${e.name}`),value:String(m[e.name]??``),onChange:t=>h({...m,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:r(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(D,{mono:!0,value:String(m[e.name]??``),"aria-label":r(`alerts.param.${e.name}`),placeholder:r(`alerts.param.${e.name}.placeholder`),onChange:t=>h({...m,[e.name]:t.target.value})})},e.name)),k&&(0,X.jsx)(j,{label:`${r(`alerts.rules.subjects`)} · ${r(`alerts.subject.${k.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(S,{ariaLabel:r(`alerts.rules.subjects`),value:g,onChange:_,items:[{value:`all`,label:r(`alerts.rules.subjectsAll`)},{value:`only`,label:r(`alerts.rules.subjectsOnly`)}]}),g===`only`&&(0,X.jsx)(tt,{label:r(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...ne,...v.filter(e=>!ne.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(j,{label:r(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.rules.noWebhooks`)}):(0,X.jsx)(tt,{label:r(`alerts.rules.webhooks`),value:b,onValueChange:x,options:(o.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(j,{label:r(`alerts.rules.repeat`),hint:r(`alerts.rules.repeatHint`),children:(0,X.jsx)(de,{value:w,min:1,step:1,label:r(`alerts.rules.repeat`),onChange:T})}),(0,X.jsx)(j,{label:r(`alerts.rules.cooldown`),hint:r(`alerts.rules.cooldownHint`),children:(0,X.jsx)(de,{value:E,min:0,step:1,label:r(`alerts.rules.cooldown`),onChange:O})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(M,{label:r(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:ee,label:r(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function Qt(){let{t:e}=P(),t=s(),n=xe()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&T;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=P(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(M,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(U(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=P(),{toast:t}=K(),n=s(),r=Ce(),i=n.data;if(!i)return(0,X.jsx)(M,{label:e(`settings.startup.service`),detail:n.isError?U(n.error):void 0,children:n.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let a=!i.supported||i.mechanism===`none`?e(`settings.startup.unsupported.${i.unsupported??`platform`}`):i.canChange?i.enabled&&i.location?e(`settings.startup.entry`,{location:i.location}):e(`settings.startup.service.${i.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(M,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(V,{checked:i.enabled,disabled:!i.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(U(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=a,nn=[...a.ease.enter],rn=[...a.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=Qe(e,e=>`${n(e)*1.05}em`),i=Qe(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=Qe(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=Qe(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(h.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function Dn({digit:e,direction:t,instant:n}){let r=i(),a=u(e),s=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let i=s.current;if(i.digit===e)return;let c=t>0?(e-i.digit+10)%10:-((i.digit-e+10)%10);Math.abs(c)>5&&(c-=Math.sign(c)*10),i.target+=c,i.digit=e,n||r?a.jump(i.target):o(a,i.target,Q.snappy)},[e,t,n,a,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),an.map(e=>(0,X.jsx)(En,{position:a,digit:e},e))]})}function On({value:e,format:n,direction:r,instant:a}){let o=i(),s=a?Tn:o?wn:Sn;return(0,X.jsx)(t,{initial:!1,custom:r,children:xn(e,n).map(e=>(0,X.jsx)(h.span,{className:`digit`in e?Z.column:Z.symbol,custom:r,variants:s,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(Dn,{digit:e.digit,direction:r,instant:a}):e.text},e.key))})}function kn({text:e,direction:n,className:r}){let a=i();return(0,X.jsx)(`span`,{className:r,children:(0,X.jsx)(t,{initial:!1,custom:n,children:[...e].map((e,t)=>(0,X.jsx)(h.span,{className:Z.char,custom:n,variants:a?wn:Sn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${t}:${e}`))})})}var An=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},jn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=An(n[t]),i=An(e);return r!==null&&i!==null&&i<r?-1:1})},Mn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:nn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{duration:.14,ease:rn}})},Nn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Pn({word:e,direction:n}){let r=i(),a=(0,Y.useRef)(null),s=u(`auto`),c=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!c.current||r?s.jump(e.offsetWidth):o(s,e.offsetWidth,Q.morph),c.current=!0});return t.observe(e),()=>t.disconnect()},[r,s]),(0,X.jsxs)(h.span,{className:Z.wordSlot,style:{width:s},children:[(0,X.jsx)(`span`,{ref:a,className:Z.wordSizer,children:e}),(0,X.jsx)(t,{initial:!1,mode:`popLayout`,custom:n,children:(0,X.jsx)(h.span,{className:Z.word,custom:n,variants:r?Nn:Mn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Fn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:jn(t.text,e)});let r=t.text===e?t.directions:jn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Pn,{word:e,direction:r[t]??1})]},t))})]})}function In({id:e,text:n,className:r}){return(0,X.jsx)(t,{initial:!1,children:n?(0,X.jsx)(Ln,{id:e,text:n,className:r},`message`):null})}function Ln({id:e,text:t,className:n}){let r=i(),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>s(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(h.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:o,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(h.span,{ref:a,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${tn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:nn},children:(0,X.jsx)(Fn,{text:t})})})}function Rn({id:e,edge:n,text:r}){let a=i();return(0,X.jsx)(t,{initial:!1,children:n!==0&&(0,X.jsx)(h.span,{id:e,className:Z.limit,initial:a?{opacity:0}:{opacity:0,y:`${n*.45}em`,filter:`blur(${tn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:a?$.instant:$.standard,ease:rn}},transition:a?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:r},`limit`)})}function zn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?qe:Ve;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:a=0,max:s=2**53-1,step:c=1,largeStep:l,description:d,disabled:f,id:p,prefix:m,suffix:g,scrub:_=!1,locale:v=`en-US`,formatOptions:y,size:b=`md`,limitHint:x=!0}){let ee=i(),S=(0,Y.useId)(),C=p??S,w=d?`${C}-description`:void 0,T=`${C}-limit`,E=c>0?c:1,[D,te]=(0,Y.useState)(n),O=t??D,[k,ne]=(0,Y.useState)(``),[A,re]=(0,Y.useState)(!1),[ie,j]=(0,Y.useState)(0),[ae,M]=(0,Y.useState)(!1),[N,oe]=(0,Y.useState)(``),[se,ce]=(0,Y.useState)(0),[le,ue]=(0,Y.useState)(!1),P=(0,Y.useRef)(null),de=(0,Y.useRef)(null),fe=(0,Y.useRef)(null),F=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(void 0),me=(0,Y.useRef)(void 0),I=(0,Y.useRef)({edge:0,count:0,at:0}),he=(0,Y.useRef)(null),ge=(0,Y.useRef)(null),_e=(0,Y.useRef)(O),ve=(0,Y.useRef)(O),L=(0,Y.useRef)(void 0),ye=(0,Y.useRef)(null),R=(0,Y.useRef)(!1),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),z=(0,Y.useRef)(()=>!1),Se=u(0),Ce=u(0),B=u(0),V=Qe(()=>Ce.get()+B.get()),we=Number.isFinite(a)?a:0,H=Math.max(_n(E),_n(we)),Te=y?.minimumFractionDigits??H,Ee=Math.max(Te,y?.maximumFractionDigits??H),De=y?.useGrouping??!0,Oe=(0,Y.useMemo)(()=>new Intl.NumberFormat(v,{minimumFractionDigits:Te,maximumFractionDigits:Ee,useGrouping:De,numberingSystem:`latn`}),[v,Te,Ee,De]),ke=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(v).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[v]),Ae=e=>Number(e.toFixed(H))||0,U=e=>Math.min(s,Math.max(a,e)),W=e=>Ae(we+Math.round((e-we)/E)*E),je=(e,t)=>{let n=(e-we)/E;return Ae(we+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*E)},G=e=>`${yn(m,e)}${Oe.format(e)}${yn(g,e)}`.trim();function K(e){let t=e.split(ke.group).join(``).replace(ke.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let q=A?K(k):null,J=q??O,[Me,Ne]=(0,Y.useState)({value:J,direction:1});Me.value!==J&&Ne({value:J,direction:J>Me.value?1:-1});let Pe=Me.value===J?Me.direction:J>Me.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(L.current),window.clearTimeout(F.current),window.clearTimeout(pe.current),window.clearTimeout(me.current)},[]);function Fe(e,t){let n=performance.now(),r=I.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let i=P.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(me.current),me.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!ee){o(Se,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?fe:de).current;n&&(t===`button`||t===`key`)&&o(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}x&&(ce(e),window.clearTimeout(F.current),F.current=window.setTimeout(()=>ce(0),un))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=U(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),oe(`${G(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==_e.current&&oe(G(i)),i!==_e.current&&(_e.current=i,t===void 0&&te(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(je(_e.current,e*t),n);(0,Y.useLayoutEffect)(()=>{_e.current=O,z.current=Le});function Re(){let e=ge.current;e&&be.current===null&&(be.current=e.getBoundingClientRect().left-Ce.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=be.current,t=ge.current;if(be.current=null,xe.current){xe.current=!1;let e=he.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-Ce.get()-B.get());Math.abs(n)<.5||(B.set(B.get()+n),ee?B.jump(0):o(B,0,Q.morph))});function ze(){window.clearTimeout(pe.current),ue(!1)}function Be(){if(!A)return;Re(),re(!1),ze();let e=K(k);e!==null&&Ie(W(e),`type`)}function Ve(){window.clearTimeout(L.current),L.current=void 0,j(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/E));n===`button`&&j(e);let i=0,a=()=>{let t=z.current(e,r,n);L.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};L.current=window.setTimeout(a,Le(e,r,n)?sn:360)}function Ue(e){let t=l??E*10,n={ArrowUp:[1,e.shiftKey?t:E],ArrowDown:[-1,e.shiftKey?t:E],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!A&&(e.key===`Home`&&Number.isFinite(a)||e.key===`End`&&s<2**53-1)){e.preventDefault(),Ie(e.key===`Home`?a:s,`key`);return}e.key===`Enter`&&(e.preventDefault(),A?(xe.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&A&&(e.preventDefault(),Re(),re(!1),ze(),xe.current=!0,Ie(ve.current,`type`))}function We(e){let t=RegExp(`[^0-9${vn(ke.group)}${H||Ee?vn(ke.decimal):``}${a<0?`\\-`:``}]`,`g`),n=e.replace(t,``);A||(ve.current=O),Re(),ne(n),re(!0);let r=K(n);r!==null&&r>=a&&r<=s&&W(r)===r&&Ie(r,`type`),ze(),r!==null&&r<a&&(pe.current=window.setTimeout(()=>ue(!0),dn))}function Ge(e){R.current=!1,_&&!f&&e.button===0&&(Be(),ye.current={pointer:e.pointerId,x:e.clientX,from:_e.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=ye.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,M(!0)}let r=n/on,i=Math.trunc(r);Ie(i?je(t.from,i):t.from,`scrub`);let o=t.from+r*E,c=o>s?(o-s)/E*on:o<a?(o-a)/E*on:0;Ce.set(ee?0:bn(c))}function qe(e){let t=ye.current;t&&t.pointer===e.pointerId&&(ye.current=null,t.active&&(R.current=!0,M(!1),o(Ce,0,ee?{duration:0}:Q.snappy),oe(G(_e.current))))}let Je=t=>({toward:t,label:e,disabled:f,controls:C,limit:t>0?J>=s:J<=a,pressed:ie===t}),Ye=q===null?0:q>s?1:q<a&&le?-1:0,Xe=x?Ye||se:0,Ze=Xe>0?s:a,$e=Xe?typeof x==`function`?x(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${G(Ze)}`:``,et=[w,Ye&&x?T:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":b,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:C,className:Z.label,"data-scrub":_&&!f||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{R.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:T,edge:Xe,text:$e})]}),(0,X.jsxs)(`div`,{ref:P,className:Z.control,"data-scrubbing":ae||void 0,"data-disabled":f||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Je(-1),iconRef:de,onPress:()=>He(-1,E,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==he.current&&e.preventDefault()},onClick:e=>{!f&&e.target!==he.current&&(he.current?.focus(),he.current?.select())},children:(0,X.jsxs)(h.span,{ref:ge,className:Z.value,style:{x:V,y:Se},children:[(0,X.jsx)(kn,{text:yn(m,J),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":A||void 0,"aria-hidden":`true`,children:(0,X.jsx)(On,{value:J,format:Oe,direction:Pe,instant:A})}),A&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:k}),(0,X.jsx)(`input`,{ref:he,id:C,className:Z.input,type:`text`,role:`spinbutton`,inputMode:a<0?`text`:H||Ee?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:A?k:Oe.format(O),disabled:f,"aria-describedby":et,"aria-invalid":Ye?!0:void 0,"aria-valuenow":O,"aria-valuetext":G(O),"aria-valuemin":Number.isFinite(a)?a:void 0,"aria-valuemax":s<2**53-1?s:void 0,onChange:e=>We(e.currentTarget.value),onKeyDown:Ue,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ve()},onBlur:()=>{Ve(),Be()}})]}),(0,X.jsx)(kn,{text:yn(g,J),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Je(1),iconRef:fe,onPress:()=>He(1,E,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(In,{id:w,text:d,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:N})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=P(),t=C(),[n,r]=Ae(),i=Me(),a=De(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(M,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(V,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(Ee(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Un,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Re,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:k.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Un,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Vn.map(o)})}),(0,X.jsx)(Un,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>r(Oe),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Ne,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Un({title:e,hint:t,children:n}){let{t:r}=P();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Wn=[`general`,`notifications`,`remote`,`tray`],Gn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Kn(){let{t:e}=P(),{tab:t}=Ze(),n=Xe(),r=ke(),i=Wn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)($e,{title:e(`nav.settings`),children:(0,X.jsxs)(We,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ye,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Ge,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(gt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Ge,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ct,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Ge,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(O,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Ge,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(rt,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(rt,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(rt,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(rt,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:e,locale:t,setLocale:n}=P(),r=et(),i=_(),a=oe(),o=C(),s=ae(),c=d(),l=g(),u=pe(),{toast:f,confirm:p}=K(),m=i.data,h=u.data?.state===`connected`&&u.data.publicUrl?`${u.data.publicUrl}/v1`:null,v=e=>a.mutate(e,{onError:e=>f(U(e),`error`)}),y=e=>{n(e),v({locale:e})},b=async t=>{await W.copy(t)&&f(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(M,{label:e(`settings.theme`),children:(0,X.jsx)(S,{ariaLabel:e(`settings.theme`),value:r.theme,onChange:r.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(M,{label:e(`settings.accent`),detail:r.accentChoice===`system`?r.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:r.accentChoice,onChange:r.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...nt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(M,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(S,{ariaLabel:e(`settings.language`),value:t,onChange:y,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),m?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(M,{label:e(`settings.gatewayUrl`),detail:`${m.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(`${m.gatewayBaseUrl}/v1`)})}),h&&(0,X.jsx)(M,{label:e(`settings.remote.publicUrl`),detail:h,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(h)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(M,{label:e(`settings.dataDir`),detail:m.dataDir,children:W.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void W.openPath(m.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(F,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(m.dataDir)})}),(0,X.jsx)(M,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:m.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await p({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&v({requireGatewayKey:t})}})}),(0,X.jsx)(M,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:e(`settings.streamIdle`),value:m.streamIdleTimeoutSec,onCommit:e=>v({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(M,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:m.requestCompression,onChange:e=>v({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(Yn,{settings:m}),(0,X.jsx)(Xn,{settings:m}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(M,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.autoInterval`),value:m.quotaAutoIntervalMinutes,onCommit:e=>a.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void o.invalidateQueries({queryKey:B.providers}),onError:e=>f(U(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(M,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.subscriptionInterval`),value:m.subscriptionQuotaIntervalMinutes,onCommit:e=>v({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(M,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:m.usageTimeZone??``,onChange:e=>v({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:m.effectiveUsageTimeZone})},...[...new Set([...Gn,...m.usageTimeZone?[m.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(M,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:m.debugBodies,label:e(`settings.debugBodies`),onChange:e=>v({debugBodies:e})})}),(0,X.jsx)(M,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:e(`settings.bodyRetention`),value:m.bodyRetentionDays,onCommit:e=>v({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(M,{label:e(`settings.requestRetention`),detail:m.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:m.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>v({requestRetentionDays:e?90:null})}),m.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:e(`settings.requestRetention`),value:m.requestRetentionDays,onCommit:e=>v({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(M,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Zn,{label:e(`settings.effort.${t}`),value:m.effortBudgets[t],onCommit:e=>v({effortBudgets:{...m.effortBudgets,[t]:e??m.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):i.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(i.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(M,{label:e(`settings.serverVersion`),detail:s.data?`${s.data.version} · API ${s.data.apiVersion}`:`—`}),H&&(0,X.jsx)(M,{label:e(`settings.desktopVersion`),detail:xe()?.version||`—`}),(0,X.jsx)(Jn,{}),H&&(0,X.jsx)(M,{label:e(`settings.logs`),onClick:()=>void W.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),c.data?.required&&(0,X.jsx)(M,{label:e(`settings.logout`),onClick:()=>l.mutate(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=P(),{toast:t}=K(),n=C(),r=oe(),i=he(),a=Te(),o=i.data,s=xe()?.updates??null,[c,l]=(0,Y.useState)(!1),u=()=>a.mutate(void 0,{onSuccess:n=>t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(U(e),`error`)}),d=()=>{s&&!c&&(l(!0),s.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:B.version}),n.invalidateQueries({queryKey:B.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:`settings.upToDate`))}).catch(e=>t(U(e),`error`)).finally(()=>l(!1)))},f=o?.lastCheckAt?new Date(o.lastCheckAt).toLocaleString():void 0,p=o?.available?s?e(`settings.updateAvailable`,{version:o.available}):`${e(`settings.updateAvailable`,{version:o.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:e(`settings.autoCheck`),detail:o&&!o.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:o?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(U(e),`error`)})})}),(0,X.jsxs)(M,{label:e(`settings.checkUpdates`),detail:a.isError?e(`settings.updateCheckFailed`,{error:U(a.error)}):o?.available?p:f?e(`settings.lastChecked`,{time:f}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:a.isPending,onClick:u,children:a.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Ke,{className:`size-3.5`})}),s&&o?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:c,"aria-label":e(`settings.updateApply`),onClick:d,children:c?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=P(),{toast:n}=K(),r=oe(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(U(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(U(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(M,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(S,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:c,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),i===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(D,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(D,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(M,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(D,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=P(),{toast:n}=K(),r=oe(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(U(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(M,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(D,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Bn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Kn as SettingsPage};
@@ -1 +0,0 @@
1
- import{$n as e,J as t,K as n,Sa as r,Tr as i,V as a,Vr as o,Xt as s,Y as c,Z as l,Zn as u,_ as d,_r as f,ai as p,c as m,d as h,in as g,l as _,mr as v,n as y,ot as b,p as x,pt as S,q as C,qr as w,r as T,t as E,v as D,va as O,ya as k}from"./alert-CGUFPyGb.js";import{a as A,gt as j,i as M,n as N,o as P,r as F}from"./overlays-B1a0OZYb.js";import{t as I}from"./ellipsis-Dxds5r72.js";import{t as L}from"./pencil-BAzRd1Ro.js";import{t as ee}from"./power-DrpargJA.js";import{t as te}from"./rotate-ccw-D6r7Boub.js";import{B as ne,L as R,M as z,_ as B,h as V,s as H,y as U,z as re}from"./index-mlmGhWY4.js";var W=r(k(),1),G=O();function K(){let{t:e}=b(),t=o(),n=i(),r=w(),a=r.data?.state===`connected`?r.data.publicUrl:null,[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(null);return(0,G.jsxs)(V,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,G.jsx)(T,{variant:`primary`,icon:(0,G.jsx)(R,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`tokens.add`)}),children:[(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,G.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,G.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),a&&(0,G.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,G.jsx)(D,{lines:4}),t.isError&&(0,G.jsx)(E,{tone:`danger`,title:e(`common.error`),children:A(t.error)}),t.data?.length===0&&(0,G.jsx)(`div`,{className:`card`,children:(0,G.jsx)(m,{icon:(0,G.jsx)(re,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,G.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,G.jsx)(q,{token:e,defaultOpen:t.data.length===1,onEdit:()=>u(e)},e.id))})]}),(0,G.jsx)(ae,{open:s,onOpenChange:c}),(0,G.jsx)(oe,{token:l,onClose:()=>u(null)})]})}function q({token:n,defaultOpen:r,onEdit:i}){let{t:o,locale:s}=b(),{toast:c,confirm:u}=P(),d=e(),m=f(),h=p(),_=v(),x=g(),[w,E]=(0,W.useState)(r),D=(d.data??[]).find(e=>e.id===n.providerId),O=`token-detail-${n.id}`,k=(e,t)=>{c(t,`success`),e.skipped.length>0&&c(o(`tokens.skipped`,{clients:e.skipped.map(e=>B[e]?.name??e).join(`, `)}),`error`)},M=()=>m.mutate(n.id,{onSuccess:async({token:e})=>{await j.copy(e)&&c(o(`tokens.copied`))},onError:e=>c(A(e),`error`)}),F=async()=>{(!n.enabled||await u({title:o(`tokens.disableConfirm`,{name:n.name}),detail:o(`tokens.disableDetail`),confirmLabel:o(`tokens.disable`),destructive:!0}))&&h.mutate({id:n.id,enabled:!n.enabled},{onError:e=>c(A(e),`error`)})},R=async()=>{await u({title:o(`tokens.resetConfirm`,{name:n.name}),detail:o(`tokens.resetDetail`),confirmLabel:o(`tokens.reset`),destructive:!0})&&_.mutate(n.id,{onSuccess:e=>k(e,o(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>c(A(e),`error`)})},V=async()=>{await u({title:o(`tokens.deleteConfirm`,{name:n.name}),detail:o(`tokens.deleteDetail`),confirmLabel:o(`common.delete`),destructive:!0})&&x.mutate(n.id,{onSuccess:e=>k(e,o(`tokens.deleted`,{name:n.name})),onError:e=>c(A(e),`error`)})},H=n.lastUsedAt?a(n.lastUsedAt,s):o(`tokens.neverUsed`);return(0,G.jsxs)(`article`,{children:[(0,G.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>E(e=>!e),children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":w,"aria-controls":O,"aria-label":o(`tokens.details`),onClick:e=>{e.stopPropagation(),E(e=>!e)},children:(0,G.jsx)(ne,{className:`size-4 transition-transform ${w?`rotate-90`:``}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${n.enabled?``:`text-[var(--text-muted)]`}`,children:n.name}),n.isDefault&&(0,G.jsx)(y,{tone:`accent`,children:o(`tokens.default`)}),!n.enabled&&(0,G.jsx)(y,{tone:`orange`,children:o(`tokens.disabledBadge`)}),n.limitUsage.some(e=>e.exhausted)&&(0,G.jsx)(y,{tone:`orange`,children:o(`tokens.limitExhausted`)})]}),(0,G.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:n.keyMasked}),(0,G.jsx)(T,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(S,{className:`size-3.5`}),"aria-label":o(`tokens.copy`),title:o(`tokens.copy`),loading:m.isPending,onClick:M})]})]})]}),(0,G.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:n.clients.map(e=>B[e]?.name??e).join(`, `)||o(`tokens.noClients`),children:n.clients.length===0?(0,G.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):n.clients.map(e=>(0,G.jsx)(U,{kind:e,size:16},e))}),(0,G.jsx)(X,{label:o(`tokens.today`),value:l(n.today.costUsd),context:o(`tokens.requestsContext`,{count:t(n.today.requests)})}),(0,G.jsx)(X,{label:o(`tokens.total`),value:l(n.total.costUsd),context:`${t(n.total.totalTokens,!0)} Token`}),(0,G.jsx)(X,{label:o(`tokens.lastUsedTitle`),value:n.lastUsedAt?C(n.lastUsedAt,s):`—`,context:n.lastUsedAt?``:o(`tokens.neverUsed`),title:H}),(0,G.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,G.jsx)(N,{label:o(`common.more`),icon:(0,G.jsx)(I,{className:`size-4`}),items:[{id:`settings`,label:o(`tokens.settings`),icon:(0,G.jsx)(L,{className:`size-3.5`}),onSelect:i},{id:`toggle`,label:n.enabled?o(`tokens.disable`):o(`tokens.enable`),icon:(0,G.jsx)(ee,{className:`size-3.5`}),onSelect:()=>void F()},{id:`reset`,label:o(`tokens.reset`),icon:(0,G.jsx)(te,{className:`size-3.5`}),onSelect:()=>void R()},...n.isDefault?[]:[{id:`delete`,label:o(`tokens.delete`),icon:(0,G.jsx)(z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void V()}]]})})]}),w&&(0,G.jsxs)(`div`,{id:O,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,G.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.clients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:n.clients.length===0?o(`tokens.noClients`):n.clients.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(U,{kind:e,size:14}),B[e]?.name??e]},e))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.directProvider`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:D?.name??(n.providerId?n.providerId:o(`tokens.directNone`))})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.allowedClients`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:n.allowedClients==null?o(`tokens.allowedClientsAny`):n.allowedClients.length===0?o(`tokens.directOnly`):n.allowedClients.map(e=>B[e]?.name??e).join(`, `)})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.lastUsedTitle`)}),(0,G.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:H})]})]}),(0,G.jsx)(J,{token:n}),(0,G.jsx)(ie,{today:n.today,total:n.total})]})]})}function J({token:e}){let{t}=b(),n=e.limits?.rpm;return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,G.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,G.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,G.jsx)(Y,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,G.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,G.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function Y({usage:e}){let{t:n,locale:r}=b(),i=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,o=n=>e.metric===`cost`?l(n):t(n,!0),s=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,G.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,G.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(e.used),limit:o(e.limit)})})]}),(0,G.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,G.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:a(e.resetsAt,r)})})]})}function X({label:e,value:t,context:n,title:r}){return(0,G.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,G.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,G.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function ie({today:e,total:r}){let{t:i}=b(),a=[[i(`tokens.today`),e],[i(`tokens.total`),r]],o=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,s=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,G.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,G.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,G.jsx)(`th`,{className:`${o} text-left`}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.cost`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.requests`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.tokens`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.inOut`)}),(0,G.jsx)(`th`,{className:o,children:i(`tokens.cacheHit`)}),(0,G.jsx)(`th`,{className:o,title:i(`tokens.tpsContext`),children:i(`tokens.tps`)})]})}),(0,G.jsx)(`tbody`,{children:a.map(([e,r])=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,G.jsx)(`td`,{className:`${s} font-semibold selectable`,children:l(r.costUsd)}),(0,G.jsx)(`td`,{className:s,children:t(r.requests)}),(0,G.jsx)(`td`,{className:s,children:t(r.totalTokens,!0)}),(0,G.jsxs)(`td`,{className:`${s} text-[var(--text-secondary)]`,children:[t(r.inputTokens,!0),` / `,t(r.outputTokens,!0)]}),(0,G.jsx)(`td`,{className:s,title:i(`usage.cacheAmounts`,{read:t(r.cacheReadTokens,!0),write:t(r.cacheWriteTokens,!0)}),children:r.cacheHitRate==null?`—`:n(r.cacheHitRate)}),(0,G.jsx)(`td`,{className:s,children:r.tps==null?`—`:c(r.tps)})]},e))})]})})}function Z(){let{t}=b(),n=(e().data??[]).filter(e=>e.enabled);return{providers:n,options:[{value:``,label:t(`tokens.directNone`)},...n.map(e=>({value:e.id,label:e.name}))]}}function ae({open:e,onOpenChange:t}){let{t:n}=b(),{toast:r}=P(),i=s(),{options:a}=Z(),[o,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``);return(0,W.useEffect)(()=>{e&&(c(``),u(``))},[e]),(0,G.jsx)(M,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,G.jsx)(T,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:l||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(A(e),`error`)}),children:n(`common.create`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(_,{label:n(`tokens.name`),children:(0,G.jsx)(h,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>c(e.target.value)})}),(0,G.jsx)(_,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:l,onChange:u,options:a})})]})})}function oe({token:e,onClose:t}){let{t:n}=b(),{toast:r}=P(),i=p(),{providers:a,options:o}=Z(),[s,c]=(0,W.useState)(``),[l,f]=(0,W.useState)(``),[m,g]=(0,W.useState)(``),[v,y]=(0,W.useState)([]),[S,C]=(0,W.useState)(null),[w,E]=(0,W.useState)(`any`),[D,O]=(0,W.useState)([]),k=a.find(e=>e.id===l),j=k?.authScheme===`oauth-subscription`||k?.authScheme===`plugin`,N=u(k?.id,j),I=new Set(v.map(e=>`${e.metric}:${e.period}`)).size<v.length;return(0,W.useEffect)(()=>{e&&(c(e.name),f(e.providerId??``),g(e.accountId??``),y(e.limits?.budgets.map(e=>({...e}))??[]),C(e.limits?.rpm??null),E(e.allowedClients==null?`any`:`only`),O(e.allowedClients??[]))},[e]),(0,G.jsx)(M,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{onClick:t,children:n(`common.cancel`)}),(0,G.jsx)(T,{variant:`primary`,disabled:!s.trim()||I,loading:i.isPending,onClick:()=>{if(!e)return;let a=v.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),o=a.length>0||S!=null&&S>0?{budgets:a,rpm:S!=null&&S>0?Math.floor(S):null}:null;i.mutate({id:e.id,name:s.trim(),providerId:l||null,accountId:j&&m||null,limits:o,allowedClients:w===`any`?null:D},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(A(e),`error`)})},children:n(`common.save`)})]}),children:(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsx)(_,{label:n(`tokens.name`),children:(0,G.jsx)(h,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,G.jsx)(_,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:l,onChange:e=>{f(e),g(``)},options:o})}),j&&(0,G.jsx)(_,{label:n(`tokens.directAccount`),children:(0,G.jsx)(F,{value:m,onChange:g,options:[{value:``,label:n(`clients.accountDefault`)},...(N.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]})}),(0,G.jsx)(_,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:I?n(`tokens.limitDuplicate`):void 0,children:(0,G.jsx)(se,{budgets:v,onChange:y})}),(0,G.jsx)(_,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,G.jsx)(x,{value:S,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:C})}),(0,G.jsx)(_,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:w,onChange:E,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),w===`only`&&(0,G.jsx)(H,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(B),...D])].map(e=>({value:e,label:B[e]?.name??e})),value:D,onValueChange:e=>O(e)})]})})]})})}var Q=[`cost`,`requests`,`tokens`],$=[`day`,`week`,`month`,`total`];function se({budgets:e,onChange:t}){let{t:n}=b(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=Q.flatMap(e=>$.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,G.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,G.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:Q.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,G.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:$.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,G.jsx)(x,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,G.jsx)(T,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(z,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,G.jsx)(`div`,{children:(0,G.jsx)(T,{size:`sm`,icon:(0,G.jsx)(R,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{K as TokensPage};