@aidotnet/server-darwin-arm64 0.9.3 → 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.
- package/bin/astra-server +2 -2
- package/bin/wwwroot/assets/ClientsPage-DEetiYfc.js +9 -0
- package/bin/wwwroot/assets/KeyPage-cq7HprCR.js +1 -0
- package/bin/wwwroot/assets/ModelDetailPage-Uj6p-r8V.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-B-l5oEGF.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-BH9KjyfC.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-C5XhVKZd.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-uLPHWm2i.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-CNU_ji4e.js +2 -0
- package/bin/wwwroot/assets/SettingsPage-B3tbYdLW.js +2 -0
- package/bin/wwwroot/assets/TokenDetailPage-BVyb_-ev.js +1 -0
- package/bin/wwwroot/assets/TokenPoolEditor-7LX143SO.js +1 -0
- package/bin/wwwroot/assets/TokensPage-vRrXvqkK.js +1 -0
- package/bin/wwwroot/assets/{TracesPage-BqnfGeL4.js → TracesPage-C9mYB_7E.js} +2 -2
- package/bin/wwwroot/assets/{TrayPanelPage-DsMvwR_T.js → TrayPanelPage-NIkRrLCt.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelView-DnvoVnvO.js → TrayPanelView-BpQQa0qi.js} +1 -1
- package/bin/wwwroot/assets/alert-CN1yWco4.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-V3oFXKF5.js → arrow-down-DP0xP3tk.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-BpBbd_q4.js → arrow-left-UUQiUGQ1.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-Bqwnblbu.js → checkbox-BEWRhO5r.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-Cp5R1kIH.js → cloud-download-DebyBXx2.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-DwiVsert.js +1 -0
- package/bin/wwwroot/assets/{download-EFZWCXNY.js → download-C4--ZCHf.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-vy0zfY6I.js → ellipsis-D250KISp.js} +1 -1
- package/bin/wwwroot/assets/{external-link-CyPNKHdV.js → external-link-Bnshhxip.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-CS5Nhpwl.js → folder-open-BzVuhS53.js} +1 -1
- package/bin/wwwroot/assets/{index-Dlj17okK.js → index-CBrXkG99.js} +12 -12
- package/bin/wwwroot/assets/index-DE_l9Wt4.css +1 -0
- package/bin/wwwroot/assets/{log-out-DfSRg6bm.js → log-out-DEZofPIg.js} +1 -1
- package/bin/wwwroot/assets/minus-BAoIEc33.js +1 -0
- package/bin/wwwroot/assets/overlays-D2pWmtov.js +41 -0
- package/bin/wwwroot/assets/{pencil-BRz--Mw5.js → pencil-DuD1bQje.js} +1 -1
- package/bin/wwwroot/assets/{power-DmWGnFp9.js → power-LE8gLJKc.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-D1yOuSfh.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-7CnaPCq0.js → rotate-ccw-Cx9vNOkF.js} +1 -1
- package/bin/wwwroot/assets/sortable.esm-B0eMzUNN.js +5 -0
- package/bin/wwwroot/index.html +4 -4
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-r2weTDWW.js +0 -11
- package/bin/wwwroot/assets/KeyPage-BGxPT6pS.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-B08VTnCn.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-tHjDQDXP.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-CK5z2M5T.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-m_YIMy3n.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-CyUE_jWW.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-Dfa9xYj8.js +0 -2
- package/bin/wwwroot/assets/SettingsPage-BJPTZJNd.js +0 -2
- package/bin/wwwroot/assets/TokensPage-BNSLQb2G.js +0 -1
- package/bin/wwwroot/assets/alert-RpMgB81n.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-B8RLpf1K.js +0 -1
- package/bin/wwwroot/assets/index-BXZibBui.css +0 -1
- package/bin/wwwroot/assets/minus-DWdqkwzQ.js +0 -1
- package/bin/wwwroot/assets/overlays-D_YawsYE.js +0 -41
- package/bin/wwwroot/assets/radio-cards-CxPVQvHV.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{At as e,Ci as t,Cr as n,E as r,Ei as i,Gr as a,Ir as o,Kr as s,Kt as c,Mt as l,Oi as u,Pt as d,Qn as f,Rr as p,Rt as m,Ti as h,U as g,V as _,Xt as v,Zt as y,_ as b,_a as x,_i as S,ai as C,an as ee,ba as w,bn as T,ci as E,d as D,di as O,ei as k,ft as te,ga as A,gi as ne,ha as re,i as ie,ii as ae,in as oe,jt as se,l as j,li as ce,m as M,mi as le,mr as ue,n as N,o as de,ot as P,p as fe,pi as pe,pt as F,qr as me,r as I,s as he,si as L,t as ge,ti as _e,tr as ve,u as R,v as z,vt as B,wi as ye,wn as be,xt as xe,y as V,yr as H,zr as Se}from"./alert-RpMgB81n.js";import{B as Ce,F as we,I as Te,L as Ee,R as De,a as U,gt as W,i as Oe,n as ke,o as G,r as K,vt as Ae,z as je}from"./overlays-D_YawsYE.js";import{t as Me}from"./TrayPanelView-DnvoVnvO.js";import{t as q}from"./download-EFZWCXNY.js";import{t as Ne}from"./ellipsis-vy0zfY6I.js";import{t as Pe}from"./external-link-CyPNKHdV.js";import{n as Fe,t as Ie}from"./radio-cards-CxPVQvHV.js";import{t as J}from"./folder-open-CS5Nhpwl.js";import{t as Le}from"./log-out-DfSRg6bm.js";import{t as Re}from"./minus-DWdqkwzQ.js";import{t as ze}from"./pencil-BRz--Mw5.js";import{t as Be}from"./rotate-ccw-7CnaPCq0.js";import{C as Ve,E as He,I as Ue,L as We,M as Ge,T as Ke,X as qe,Z as Je,et as Ye,h as Xe,n as Ze,s as Qe,t as $e,w as et,z as tt}from"./index-Dlj17okK.js";var nt={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`}]]};nt.node;var rt=B(nt),it={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`}]]};it.node;var at=B(it),ot={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`}]]};ot.node;var st=B(ot),ct={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`}]]};ct.node;var lt=B(ct),ut={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`}]]};ut.node;var dt=B(ut),ft={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`}]]};ft.node;var pt=B(ft),mt={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`}]]};mt.node;var ht=B(mt),Y=w(x(),1),X=A(),gt=`https://astra-gate.si/docs/guide/remote-access`,_t=`astra.remote.acknowledged`;function vt(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 yt(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 bt(){try{return localStorage.getItem(_t)===`1`}catch{return!1}}function xt(){try{localStorage.setItem(_t,`1`)}catch{}}function St(){let{t:e}=P(),t=a(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Ct,{s:n}),(0,X.jsx)(wt,{s:n}),(0,X.jsx)(Tt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(de,{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)(ge,{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)(z,{className:`mx-auto my-8`})})}function Ct({s:e}){let{t,locale:n}=P(),{toast:r,confirm:i}=G(),a=p(),o=d(),s=vt(e,t),c=async e=>{await W.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!bt()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;xt()}(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(U(e),`error`)})},u=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,f=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,m=e.state===`connected`&&f!==null?f<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:g(f,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,v=h.downloading||h.path?null:h.asset?t(`settings.remote.cloudflaredMissing`,{version:h.version??``}):t(`settings.remote.cloudflaredUnsupported`),y=e.enabled?e.error??h.error??null:null,b=y!==null&&(e.state!==`connected`||/origin service|origin server/i.test(y)),x=e.publicUrl;return(0,X.jsxs)(R,{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?_(e.connectedAt,n):void 0,children:[(0,X.jsx)(he,{tone:u}),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:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),!e.enabled&&!s&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:v}),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)(ke,{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 c(`${x}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(x)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${x}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Pe,{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)(ge,{tone:e.state===`connected`?`warning`:`danger`,title:yt(y,e,t),children:y})})]})}function wt({s:e}){let{t}=P(),{toast:n,confirm:r}=G(),i=ae(),[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)(R,{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)(b,{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)(ge,{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)(st,{className:`size-3.5`}),onClick:()=>window.open(gt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Tt({s:e}){let{t}=P(),{toast:n,confirm:r}=G(),i=ae(),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)(R,{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)(Et,{passwordSet:e.checks.passwordSet})]})}function Et({passwordSet:e}){let{t}=P(),{toast:n}=G(),r=d(),i=H(),[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 Dt=[`auto`,`github`,`astra`,`custom`];function Ot({s:e}){let{t}=P(),{toast:n}=G(),r=ae(),i=ee(),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)(R,{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)(he,{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)(K,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:_,options:Dt.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 kt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],At={local:`127.0.0.1`,lan:`0.0.0.0`},jt=e=>kt.includes(e)?`local`:`lan`;function Mt(){let{t:e}=P(),{toast:t,confirm:n}=G(),r=re(),i=T(),a=d(),o=me(),[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)(z,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=jt(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(At[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)}},x=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()}},C=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${S?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{label:e(`settings.listen`),detail:C,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&S&&(0,X.jsx)(I,{size:`sm`,loading:l,onClick:()=>void x(),children:e(`settings.listen.restart`)}),(0,X.jsx)(b,{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)(Et,{passwordSet:f.passwordSet}),(0,X.jsx)(Nt,{open:s,onOpenChange:c,onSaved:()=>v(`lan`)})]})}function Nt({open:e,onOpenChange:t,onSaved:n}){let{t:r}=P(),{toast:i}=G(),a=H(),[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)(Oe,{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 Pt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Ft={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/…`},It=e=>e===`feishu`||e===`dingtalk`,Lt=(e,t)=>e(`alerts.event.${t}`),Rt=(e,t)=>e(`alerts.event.${t}.hint`);function zt(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Bt,{}),(0,X.jsx)(Vt,{}),(0,X.jsx)(Kt,{})]})}function Bt(){let{t:e,locale:t}=P(),n=l(!0);return(0,X.jsxs)(R,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(z,{}),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)(rt,{className:`size-4 text-[var(--danger)]`}),label:`${Lt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${_(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Vt(){let{t:e}=P(),{toast:t,confirm:n}=G(),r=ce(),i=oe(),a=o(),s=ue(),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),m=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(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})&&s.mutate(r.id,{onSuccess:e=>p(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)(R,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(z,{}),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)(ht,{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`||It(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)(Fe,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(ke,{label:e(`common.more`),icon:(0,X.jsx)(Ne,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(ze,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(lt,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(tt,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Ge,{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)(We,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Ht,{hook:c,onClose:()=>l(null),onSecret:p}),(0,X.jsx)(Wt,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(Ut,{secret:f,onClose:()=>p(null)})]})}function Ht({hook:e,onClose:t,onSecret:n}){let{t:r}=P(),{toast:i}=G(),a=v(),o=C(),[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),[_,y]=(0,Y.useState)(!0),[b,x]=(0,Y.useState)(`generic`),[S,ee]=(0,Y.useState)(``),[w,T]=(0,Y.useState)([]),E=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),y(!t||t.hasSecret),x(t?.format??`generic`),ee(``),T((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Oe,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(E?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(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(w.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=!E&&e!==null&&e.format!==b,g=It(b)?_?S.trim()||void 0:``:void 0;E?a.mutate({...u,format:b,...b===`generic`?{signed:_}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:b}:{},...b===`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.${b}.hint`),children:(0,X.jsx)(K,{ariaLabel:r(`alerts.webhooks.format`),value:b,onChange:t=>{x(t),y(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||It(t))},options:Pt.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:Ft[b],onChange:e=>u(e.target.value)})}),It(b)&&_&&(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:S,placeholder:e!==`new`&&e!==null&&e.format===b&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>ee(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(fe,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[w.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(D,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>T(w.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(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=>T(w.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ge,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>T(w.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(We,{className:`size-3.5`}),onClick:()=>T([...w,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(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})}),(b===`generic`?E||e!==null&&e.format===`generic`&&e.hasSecret:It(b))&&(0,X.jsx)(M,{label:r(`alerts.webhooks.signed`),detail:r(b===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:y})})]})]})})}function Ut({secret:e,onClose:t}){let{t:n}=P(),{toast:r}=G();return(0,X.jsx)(Oe,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(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 Wt({hook:e,onClose:t}){let{t:n,locale:r}=P(),{toast:i}=G(),a=E(e?.id),o=ve(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Oe,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(z,{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`):Lt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:_(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:_(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)(ie,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(ie,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading: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 Gt(e){let t=f(),n=Se(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=Ae({queries:r.map(t=>({queryKey:xe.providerAccounts(t.id),queryFn:()=>O(`GET`,`/api/providers/${pe(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(t.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(n.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?r.flatMap((e,t)=>(i[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Kt(){let{t:e}=P(),{toast:t,confirm:n}=G(),r=se(),i=ce(),a=s(),o=y(),[c,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)(R,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(z,{}),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)(rt,{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:`${Lt(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)(ke,{label:e(`common.more`),icon:(0,X.jsx)(Ne,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(ze,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Ge,{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)(We,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Jt,{rule:c,onClose:()=>l(null)})]})}function qt(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 Jt({rule:t,onClose:n}){let{t:r}=P(),{toast:i}=G(),a=e(),o=ce(),l=c(),u=s(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)({}),[_,v]=(0,Y.useState)(`all`),[y,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)([]),[ee,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(60),te=a.data?.find(e=>e.id===p),A=Gt(te?.subjectType),ne=t===`new`;return(0,Y.useEffect)(()=>{if(t===null)return;let e=t===`new`?null:t,n=a.data?.[0];f(e?.name??``),m(e?.event??n?.id??``),g(e?{...qt(a.data?.find(t=>t.id===e.event)),...e.condition}:qt(n)),v(e?.subjects?`only`:`all`),x(e?.subjects??[]),C(e?.webhookIds??(o.data??[]).map(e=>e.id)),w(e?.notifyResolved??!1),E(e?.repeatMinutes??null),k(e?.cooldownMinutes??60)},[t]),(0,X.jsx)(Oe,{open:t!==null,onOpenChange:e=>!e&&n(),title:r(ne?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:n,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d.trim()||!p,loading:l.isPending||u.isPending,onClick:()=>{let e=Object.fromEntries(Object.entries(h).filter(([,e])=>e!==null&&e!==``)),a={name:d.trim(),event:p,condition:e,subjects:_===`all`?null:y,webhookIds:S,notifyResolved:ee,repeatMinutes:T&&T>0?Math.floor(T):null,cooldownMinutes:Math.max(0,Math.floor(O??0))},o={onSuccess:()=>{n(),i(r(`common.saved`),`success`)},onError:e=>i(U(e),`error`)};ne?l.mutate(a,o):t&&u.mutate({id:t.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:d,maxLength:64,onChange:e=>f(e.target.value)})}),(0,X.jsx)(j,{label:r(`alerts.rules.event`),hint:p?Rt(r,p):void 0,children:(0,X.jsx)(K,{ariaLabel:r(`alerts.rules.event`),value:p,onChange:e=>{m(e),g(qt(a.data?.find(t=>t.id===e))),x([])},options:(a.data??[]).map(e=>({value:e.id,label:Lt(r,e.id)}))})}),te?.params.map(e=>(0,X.jsx)(j,{label:r(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(fe,{value:typeof h[e.name]==`number`?h[e.name]:null,min:0,label:r(`alerts.param.${e.name}`),onChange:t=>g({...h,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(K,{ariaLabel:r(`alerts.param.${e.name}`),value:String(h[e.name]??``),onChange:t=>g({...h,[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(h[e.name]??``),"aria-label":r(`alerts.param.${e.name}`),placeholder:r(`alerts.param.${e.name}.placeholder`),onChange:t=>g({...h,[e.name]:t.target.value})})},e.name)),te&&(0,X.jsx)(j,{label:`${r(`alerts.rules.subjects`)} · ${r(`alerts.subject.${te.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(b,{ariaLabel:r(`alerts.rules.subjects`),value:_,onChange:v,items:[{value:`all`,label:r(`alerts.rules.subjectsAll`)},{value:`only`,label:r(`alerts.rules.subjectsOnly`)}]}),_===`only`&&(0,X.jsx)(Qe,{label:r(`alerts.rules.subjects`),value:y,onValueChange:x,options:[...A,...y.filter(e=>!A.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)(Qe,{label:r(`alerts.rules.webhooks`),value:S,onValueChange:C,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)(fe,{value:T,min:1,step:1,label:r(`alerts.rules.repeat`),onChange:E})}),(0,X.jsx)(j,{label:r(`alerts.rules.cooldown`),hint:r(`alerts.rules.cooldownHint`),children:(0,X.jsx)(fe,{value:O,min:0,step:1,label:r(`alerts.rules.cooldown`),onChange:k})})]}),(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:w})})})]})})}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:Yt}=r,Xt=[...r.ease.enter],Zt=[...r.ease.standard],Qt=[0,1,2,3,4,5,6,7,8,9],$t=6,en=400,tn=40,nn=240,rn=1500,an=700,on=700,sn=.22,cn=4,ln=130,un=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),dn=e=>(String(e).split(`.`)[1]??``).length,fn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),pn=(e,t)=>typeof e==`function`?e(t):e??``,mn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function hn(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 gn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Yt.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:Zt}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Yt.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Zt},opacity:{duration:$.instant},filter:{duration:$.instant}}})},_n=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),vn={enter:_n(0),center:{..._n(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},yn={enter:_n(1),center:{..._n(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function bn({position:e,digit:n}){let r=e=>((n-e)%10+15)%10-5,i=Ye(e,e=>`${r(e)*1.05}em`),a=Ye(e,e=>Math.max(0,1-Math.abs(r(e))**1.5*1.1)),o=Ye(e,e=>Math.abs(r(e))>=1?`hidden`:`visible`),s=Ye(e,e=>{let t=Math.abs(r(e));return t<.02||t>=1?`none`:`blur(${(t*Yt.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(t.span,{className:Z.glyph,style:{y:i,opacity:a,filter:s,visibility:o},children:n})}function xn({digit:e,direction:t,instant:n}){let r=h(),a=i(e),o=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let i=o.current;if(i.digit===e)return;let s=t>0?(e-i.digit+10)%10:-((i.digit-e+10)%10);Math.abs(s)>5&&(s-=Math.sign(s)*10),i.target+=s,i.digit=e,n||r?a.jump(i.target):ye(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`}),Qt.map(e=>(0,X.jsx)(bn,{position:a,digit:e},e))]})}function Sn({value:e,format:n,direction:r,instant:i}){let a=h(),o=i?yn:a?vn:gn;return(0,X.jsx)(u,{initial:!1,custom:r,children:hn(e,n).map(e=>(0,X.jsx)(t.span,{className:`digit`in e?Z.column:Z.symbol,custom:r,variants:o,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(xn,{digit:e.digit,direction:r,instant:i}):e.text},e.key))})}function Cn({text:e,direction:n,className:r}){let i=h();return(0,X.jsx)(`span`,{className:r,children:(0,X.jsx)(u,{initial:!1,custom:n,children:[...e].map((e,r)=>(0,X.jsx)(t.span,{className:Z.char,custom:n,variants:i?vn:gn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${r}:${e}`))})})}var wn=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},Tn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=wn(n[t]),i=wn(e);return r!==null&&i!==null&&i<r?-1:1})},En={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Yt.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:Xt,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Yt.subtle}px)`,transition:{duration:.14,ease:Zt}})},Dn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function On({word:e,direction:n}){let r=h(),a=(0,Y.useRef)(null),o=i(`auto`),s=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!s.current||r?o.jump(e.offsetWidth):ye(o,e.offsetWidth,Q.morph),s.current=!0});return t.observe(e),()=>t.disconnect()},[r,o]),(0,X.jsxs)(t.span,{className:Z.wordSlot,style:{width:o},children:[(0,X.jsx)(`span`,{ref:a,className:Z.wordSizer,children:e}),(0,X.jsx)(u,{initial:!1,mode:`popLayout`,custom:n,children:(0,X.jsx)(t.span,{className:Z.word,custom:n,variants:r?Dn:En,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function kn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:Tn(t.text,e)});let r=t.text===e?t.directions:Tn(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)(On,{word:e,direction:r[t]??1})]},t))})]})}function An({id:e,text:t,className:n}){return(0,X.jsx)(u,{initial:!1,children:t?(0,X.jsx)(jn,{id:e,text:t,className:n},`message`):null})}function jn({id:e,text:n,className:r}){let i=h(),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)(t.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:o,opacity:1},exit:{height:0,opacity:0,transition:i?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:i?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(t.span,{ref:a,id:e,className:r,initial:!i&&{y:`0.35em`,filter:`blur(${Yt.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:i?0:$.standard,ease:Xt},children:(0,X.jsx)(kn,{text:n})})})}function Mn({id:e,edge:n,text:r}){let i=h();return(0,X.jsx)(u,{initial:!1,children:n!==0&&(0,X.jsx)(t.span,{id:e,className:Z.limit,initial:i?{opacity:0}:{opacity:0,y:`${n*.45}em`,filter:`blur(${Yt.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:i?$.instant:$.standard,ease:Zt}},transition:i?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:r},`limit`)})}function Nn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?We:Re;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 Pn({label:e,value:n,defaultValue:r=0,onValueChange:a,min:o=0,max:s=2**53-1,step:c=1,largeStep:l,description:u,disabled:d,id:f,prefix:p,suffix:m,scrub:g=!1,locale:_=`en-US`,formatOptions:v,size:y=`md`,limitHint:b=!0}){let x=h(),S=(0,Y.useId)(),C=f??S,ee=u?`${C}-description`:void 0,w=`${C}-limit`,T=c>0?c:1,[E,D]=(0,Y.useState)(r),O=n??E,[k,te]=(0,Y.useState)(``),[A,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(0),[ae,oe]=(0,Y.useState)(!1),[se,j]=(0,Y.useState)(``),[ce,M]=(0,Y.useState)(0),[le,ue]=(0,Y.useState)(!1),N=(0,Y.useRef)(null),de=(0,Y.useRef)(null),P=(0,Y.useRef)(null),fe=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(void 0),F=(0,Y.useRef)(void 0),me=(0,Y.useRef)({edge:0,count:0,at:0}),I=(0,Y.useRef)(null),he=(0,Y.useRef)(null),L=(0,Y.useRef)(O),ge=(0,Y.useRef)(O),_e=(0,Y.useRef)(void 0),ve=(0,Y.useRef)(null),R=(0,Y.useRef)(!1),z=(0,Y.useRef)(null),B=(0,Y.useRef)(!1),be=(0,Y.useRef)(()=>!1),xe=i(0),V=i(0),H=i(0),Se=Ye(()=>V.get()+H.get()),Ce=Number.isFinite(o)?o:0,we=Math.max(dn(T),dn(Ce)),Te=v?.minimumFractionDigits??we,Ee=Math.max(Te,v?.maximumFractionDigits??we),De=v?.useGrouping??!0,U=(0,Y.useMemo)(()=>new Intl.NumberFormat(_,{minimumFractionDigits:Te,maximumFractionDigits:Ee,useGrouping:De,numberingSystem:`latn`}),[_,Te,Ee,De]),W=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(_).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[_]),Oe=e=>Number(e.toFixed(we))||0,ke=e=>Math.min(s,Math.max(o,e)),G=e=>Oe(Ce+Math.round((e-Ce)/T)*T),K=(e,t)=>{let n=(e-Ce)/T;return Oe(Ce+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*T)},Ae=e=>`${pn(p,e)}${U.format(e)}${pn(m,e)}`.trim();function je(e){let t=e.split(W.group).join(``).replace(W.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Me=A?je(k):null,q=Me??O,[Ne,Pe]=(0,Y.useState)({value:q,direction:1});Ne.value!==q&&Pe({value:q,direction:q>Ne.value?1:-1});let Fe=Ne.value===q?Ne.direction:q>Ne.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(_e.current),window.clearTimeout(fe.current),window.clearTimeout(pe.current),window.clearTimeout(F.current)},[]);function Ie(e,t){let n=performance.now(),r=me.current;r.count=r.edge===e&&n-r.at<on?r.count+1:1,r.edge=e,r.at=n;let i=N.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(F.current),F.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!x){ye(xe,0,{...un,velocity:-e*ln*(1+Math.min(r.count-1,cn)*sn)});let n=(e>0?P:de).current;n&&(t===`button`||t===`key`)&&ye(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}b&&(M(e),window.clearTimeout(fe.current),fe.current=window.setTimeout(()=>M(0),rn))}function J(e,t){if(!Number.isFinite(e))return!1;let r=ke(e),i=Math.sign(e-r);return i&&t!==`scrub`?(Ie(i>0?1:-1,t),j(`${Ae(r)}, ${i>0?`maximum`:`minimum`}`)):t===`button`&&r!==L.current&&j(Ae(r)),r!==L.current&&(L.current=r,n===void 0&&D(r),a?.(r),!0)}let Le=(e,t,n)=>J(K(L.current,e*t),n);(0,Y.useLayoutEffect)(()=>{L.current=O,be.current=Le});function Re(){let e=he.current;e&&z.current===null&&(z.current=e.getBoundingClientRect().left-V.get()-H.get())}(0,Y.useLayoutEffect)(()=>{let e=z.current,t=he.current;if(z.current=null,B.current){B.current=!1;let e=I.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-V.get()-H.get());Math.abs(n)<.5||(H.set(H.get()+n),x?H.jump(0):ye(H,0,Q.morph))});function ze(){window.clearTimeout(pe.current),ue(!1)}function Be(){if(!A)return;Re(),ne(!1),ze();let e=je(k);e!==null&&J(G(e),`type`)}function Ve(){window.clearTimeout(_e.current),_e.current=void 0,ie(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/T));n===`button`&&ie(e);let i=0,a=()=>{let t=be.current(e,r,n);_e.current=window.setTimeout(a,t?Math.max(tn,150*.86**++i):nn)};_e.current=window.setTimeout(a,Le(e,r,n)?en:360)}function Ue(e){let t=l??T*10,n={ArrowUp:[1,e.shiftKey?t:T],ArrowDown:[-1,e.shiftKey?t:T],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(o)||e.key===`End`&&s<2**53-1)){e.preventDefault(),J(e.key===`Home`?o:s,`key`);return}e.key===`Enter`&&(e.preventDefault(),A?(B.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&A&&(e.preventDefault(),Re(),ne(!1),ze(),B.current=!0,J(ge.current,`type`))}function We(e){let t=RegExp(`[^0-9${fn(W.group)}${we||Ee?fn(W.decimal):``}${o<0?`\\-`:``}]`,`g`),n=e.replace(t,``);A||(ge.current=O),Re(),te(n),ne(!0);let r=je(n);r!==null&&r>=o&&r<=s&&G(r)===r&&J(r,`type`),ze(),r!==null&&r<o&&(pe.current=window.setTimeout(()=>ue(!0),an))}function Ge(e){R.current=!1,g&&!d&&e.button===0&&(Be(),ve.current={pointer:e.pointerId,x:e.clientX,from:L.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=ve.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,oe(!0)}let r=n/$t,i=Math.trunc(r);J(i?K(t.from,i):t.from,`scrub`);let a=t.from+r*T,c=a>s?(a-s)/T*$t:a<o?(a-o)/T*$t:0;V.set(x?0:mn(c))}function qe(e){let t=ve.current;t&&t.pointer===e.pointerId&&(ve.current=null,t.active&&(R.current=!0,oe(!1),ye(V,0,x?{duration:0}:Q.snappy),j(Ae(L.current))))}let Je=t=>({toward:t,label:e,disabled:d,controls:C,limit:t>0?q>=s:q<=o,pressed:re===t}),Xe=Me===null?0:Me>s?1:Me<o&&le?-1:0,Ze=b?Xe||ce:0,Qe=Ze>0?s:o,$e=Ze?typeof b==`function`?b(Ze>0?`max`:`min`,Qe):`${Ze>0?`Max`:`Min`} ${Ae(Qe)}`:``,et=[ee,Xe&&b?w:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":y,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:C,className:Z.label,"data-scrub":g&&!d||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{R.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Mn,{id:w,edge:Ze,text:$e})]}),(0,X.jsxs)(`div`,{ref:N,className:Z.control,"data-scrubbing":ae||void 0,"data-disabled":d||void 0,"data-warn":Xe?Xe>0?`max`:`min`:void 0,children:[(0,X.jsx)(Nn,{...Je(-1),iconRef:de,onPress:()=>He(-1,T,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==I.current&&e.preventDefault()},onClick:e=>{!d&&e.target!==I.current&&(I.current?.focus(),I.current?.select())},children:(0,X.jsxs)(t.span,{ref:he,className:Z.value,style:{x:Se,y:xe},children:[(0,X.jsx)(Cn,{text:pn(p,q),direction:Fe,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)(Sn,{value:q,format:U,direction:Fe,instant:A})}),A&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:k}),(0,X.jsx)(`input`,{ref:I,id:C,className:Z.input,type:`text`,role:`spinbutton`,inputMode:o<0?`text`:we||Ee?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:A?k:U.format(O),disabled:d,"aria-describedby":et,"aria-invalid":Xe?!0:void 0,"aria-valuenow":O,"aria-valuetext":Ae(O),"aria-valuemin":Number.isFinite(o)?o: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)(Cn,{text:pn(m,q),direction:Fe,className:Z.affix})]})}),(0,X.jsx)(Nn,{...Je(1),iconRef:P,onPress:()=>He(1,T,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(An,{id:ee,text:u,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:se})]})}var Fn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function In(){let{t:e}=P(),t=re(),[n,r]=De(),i=je(),a=we(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(Ce(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)(Ln,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Ie,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:le.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Ln,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Fn.map(o)})}),(0,X.jsx)(Ln,{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)(Be,{className:`size-3.5`}),onClick:()=>r(Te),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Ln,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Me,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Ln({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 Rn=[`general`,`notifications`,`remote`,`tray`],zn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Bn(){let{t:e}=P(),{tab:t}=Je(),n=qe(),r=Ee(),i=Rn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)(Xe,{title:e(`nav.settings`),children:(0,X.jsxs)(Ve,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ke,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(He,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(pt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(He,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(at,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(He,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(te,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(He,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(dt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(et,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Vn,{})}),(0,X.jsx)(et,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(zt,{})}),(0,X.jsx)(et,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(St,{})}),r&&(0,X.jsx)(et,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(In,{})})]})})}function Vn(){let{t:e,locale:t,setLocale:r}=P(),i=Ze(),o=n(),s=k(),c=re(),l=L(),u=d(),f=be(),p=a(),{toast:m,confirm:h}=G(),g=o.data,_=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,v=e=>s.mutate(e,{onError:e=>m(U(e),`error`)}),y=e=>{r(e),v({locale:e})},x=async t=>{await W.copy(t)&&m(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(R,{title:e(`settings.appearance`),children:[(0,X.jsx)(M,{label:e(`settings.theme`),children:(0,X.jsx)(b,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(M,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(K,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...$e.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)(b,{ariaLabel:e(`settings.language`),value:t,onChange:y,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(R,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(M,{label:e(`settings.gatewayUrl`),detail:`${g.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 x(`${g.gatewayBaseUrl}/v1`)})}),_&&(0,X.jsx)(M,{label:e(`settings.remote.publicUrl`),detail:_,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 x(_)})}),(0,X.jsx)(Mt,{}),(0,X.jsx)(M,{label:e(`settings.dataDir`),detail:g.dataDir,children:W.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(J,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void W.openPath(g.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 x(g.dataDir)})}),(0,X.jsx)(M,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:g.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await h({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)(Gn,{label:e(`settings.streamIdle`),value:g.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)(K,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:g.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)(Un,{settings:g}),(0,X.jsx)(Wn,{settings:g}),(0,X.jsxs)(R,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(M,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Gn,{label:e(`settings.quota.autoInterval`),value:g.quotaAutoIntervalMinutes,onCommit:e=>s.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void c.invalidateQueries({queryKey:xe.providers}),onError:e=>m(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)(Gn,{label:e(`settings.quota.subscriptionInterval`),value:g.subscriptionQuotaIntervalMinutes,onCommit:e=>v({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(R,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(M,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(K,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:g.usageTimeZone??``,onChange:e=>v({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:g.effectiveUsageTimeZone})},...[...new Set([...zn,...g.usageTimeZone?[g.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(R,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(M,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:g.debugBodies,label:e(`settings.debugBodies`),onChange:e=>v({debugBodies:e})})}),(0,X.jsx)(M,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Gn,{label:e(`settings.bodyRetention`),value:g.bodyRetentionDays,onCommit:e=>v({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(M,{label:e(`settings.requestRetention`),detail:g.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:g.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>v({requestRetentionDays:e?90:null})}),g.requestRetentionDays!=null&&(0,X.jsx)(Gn,{label:e(`settings.requestRetention`),value:g.requestRetentionDays,onCommit:e=>v({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(R,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(M,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Gn,{label:e(`settings.effort.${t}`),value:g.effortBudgets[t],onCommit:e=>v({effortBudgets:{...g.effortBudgets,[t]:e??g.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):o.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(o.error)}):(0,X.jsx)(z,{className:`mx-auto my-8`}),(0,X.jsxs)(R,{title:e(`settings.about`),children:[(0,X.jsx)(M,{label:e(`settings.serverVersion`),detail:l.data?`${l.data.version} · API ${l.data.apiVersion}`:`—`}),S&&(0,X.jsx)(M,{label:e(`settings.desktopVersion`),detail:ne()?.version||`—`}),(0,X.jsx)(Hn,{}),S&&(0,X.jsx)(M,{label:e(`settings.logs`),onClick:()=>void W.revealLogs(),children:(0,X.jsx)(J,{className:`size-4 text-[var(--text-secondary)]`})}),u.data?.required&&(0,X.jsx)(M,{label:e(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Le,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Hn(){let{t:e}=P(),{toast:t}=G(),n=re(),r=k(),i=_e(),a=m(),o=i.data,s=ne()?.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:xe.version}),n.invalidateQueries({queryKey:xe.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)(z,{className:`size-3.5`}):(0,X.jsx)(Ue,{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)(z,{className:`size-3.5`}):(0,X.jsx)(q,{className:`size-3.5`})})]})]})}function Un({settings:e}){let{t}=P(),{toast:n}=G(),r=k(),[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)(R,{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)(b,{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 Wn({settings:e}){let{t}=P(),{toast:n}=G(),r=k(),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)(R,{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 Gn({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)(Pn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Bn as SettingsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cr as e,Gr as t,J as n,K as r,Qn as i,V as a,Xn as o,Y as s,Yt as c,Z as l,_ as u,_a as d,ba as f,c as p,d as m,ga as h,gr as g,l as _,n as v,ot as y,p as b,pr as x,pt as S,q as C,r as w,ri as T,rn as E,t as D,v as O,zr as k}from"./alert-RpMgB81n.js";import{a as A,gt as j,i as M,n as N,o as P,r as F}from"./overlays-D_YawsYE.js";import{t as I}from"./ellipsis-vy0zfY6I.js";import{t as L}from"./pencil-BRz--Mw5.js";import{t as ee}from"./power-DmWGnFp9.js";import{t as te}from"./rotate-ccw-7CnaPCq0.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-Dlj17okK.js";var W=f(d(),1),G=h();function K(){let{t:n}=y(),r=k(),i=e(),a=t(),o=a.data?.state===`connected`?a.data.publicUrl:null,[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(null);return(0,G.jsxs)(V,{title:n(`nav.tokens`),subtitle:n(`tokens.subtitle`),actions:(0,G.jsx)(w,{variant:`primary`,icon:(0,G.jsx)(R,{className:`size-3.5`}),onClick:()=>c(!0),children:n(`tokens.add`)}),children:[(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[i.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:n(`tokens.directHint`,{url:`${i.data.gatewayBaseUrl}/v1`})}),(0,G.jsx)(`p`,{className:`selectable`,children:n(`tokens.selfServiceHint`,{url:i.data.gatewayBaseUrl})}),o&&(0,G.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:n(`tokens.remoteHint`,{url:`${o}/v1`,key:`${o}/key`})})]}),r.isLoading&&(0,G.jsx)(O,{lines:4}),r.isError&&(0,G.jsx)(D,{tone:`danger`,title:n(`common.error`),children:A(r.error)}),r.data?.length===0&&(0,G.jsx)(`div`,{className:`card`,children:(0,G.jsx)(p,{icon:(0,G.jsx)(re,{className:`size-6`}),title:n(`tokens.empty`)})}),r.data&&r.data.length>0&&(0,G.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:r.data.map(e=>(0,G.jsx)(q,{token:e,defaultOpen:r.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:e,defaultOpen:t,onEdit:r}){let{t:o,locale:s}=y(),{toast:c,confirm:u}=P(),d=i(),f=g(),p=T(),m=x(),h=E(),[_,b]=(0,W.useState)(t),D=(d.data??[]).find(t=>t.id===e.providerId),O=`token-detail-${e.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=()=>f.mutate(e.id,{onSuccess:async({token:e})=>{await j.copy(e)&&c(o(`tokens.copied`))},onError:e=>c(A(e),`error`)}),F=async()=>{(!e.enabled||await u({title:o(`tokens.disableConfirm`,{name:e.name}),detail:o(`tokens.disableDetail`),confirmLabel:o(`tokens.disable`),destructive:!0}))&&p.mutate({id:e.id,enabled:!e.enabled},{onError:e=>c(A(e),`error`)})},R=async()=>{await u({title:o(`tokens.resetConfirm`,{name:e.name}),detail:o(`tokens.resetDetail`),confirmLabel:o(`tokens.reset`),destructive:!0})&&m.mutate(e.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:e.name}),detail:o(`tokens.deleteDetail`),confirmLabel:o(`common.delete`),destructive:!0})&&h.mutate(e.id,{onSuccess:t=>k(t,o(`tokens.deleted`,{name:e.name})),onError:e=>c(A(e),`error`)})},H=e.lastUsedAt?a(e.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:()=>b(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":_,"aria-controls":O,"aria-label":o(`tokens.details`),onClick:e=>{e.stopPropagation(),b(e=>!e)},children:(0,G.jsx)(ne,{className:`size-4 transition-transform ${_?`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 ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,G.jsx)(v,{tone:`accent`,children:o(`tokens.default`)}),!e.enabled&&(0,G.jsx)(v,{tone:`orange`,children:o(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,G.jsx)(v,{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:e.keyMasked}),(0,G.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,G.jsx)(S,{className:`size-3.5`}),"aria-label":o(`tokens.copy`),title:o(`tokens.copy`),loading:f.isPending,onClick:M})]})]})]}),(0,G.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>B[e]?.name??e).join(`, `)||o(`tokens.noClients`),children:e.clients.length===0?(0,G.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,G.jsx)(U,{kind:e,size:16},e))}),(0,G.jsx)(X,{label:o(`tokens.today`),value:l(e.today.costUsd),context:o(`tokens.requestsContext`,{count:n(e.today.requests)})}),(0,G.jsx)(X,{label:o(`tokens.total`),value:l(e.total.costUsd),context:`${n(e.total.totalTokens,!0)} Token`}),(0,G.jsx)(X,{label:o(`tokens.lastUsedTitle`),value:e.lastUsedAt?C(e.lastUsedAt,s):`—`,context:e.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:r},{id:`toggle`,label:e.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()},...e.isDefault?[]:[{id:`delete`,label:o(`tokens.delete`),icon:(0,G.jsx)(z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void V()}]]})})]}),_&&(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:e.clients.length===0?o(`tokens.noClients`):e.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??(e.providerId?e.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:e.allowedClients==null?o(`tokens.allowedClientsAny`):e.allowedClients.length===0?o(`tokens.directOnly`):e.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:e}),(0,G.jsx)(ie,{today:e.today,total:e.total})]})]})}function J({token:e}){let{t}=y(),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,locale:r}=y(),i=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,o=t=>e.metric===`cost`?l(t):n(t,!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:t(`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:t(`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:t}){let{t:i}=y(),a=[[i(`tokens.today`),e],[i(`tokens.total`),t]],o=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,c=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,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,t])=>(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:`${c} font-semibold selectable`,children:l(t.costUsd)}),(0,G.jsx)(`td`,{className:c,children:n(t.requests)}),(0,G.jsx)(`td`,{className:c,children:n(t.totalTokens,!0)}),(0,G.jsxs)(`td`,{className:`${c} text-[var(--text-secondary)]`,children:[n(t.inputTokens,!0),` / `,n(t.outputTokens,!0)]}),(0,G.jsx)(`td`,{className:c,title:i(`usage.cacheAmounts`,{read:n(t.cacheReadTokens,!0),write:n(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:r(t.cacheHitRate)}),(0,G.jsx)(`td`,{className:c,children:t.tps==null?`—`:s(t.tps)})]},e))})]})})}function Z(){let{t:e}=y(),t=(i().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function ae({open:e,onOpenChange:t}){let{t:n}=y(),{toast:r}=P(),i=c(),{options:a}=Z(),[o,s]=(0,W.useState)(``),[l,u]=(0,W.useState)(``);return(0,W.useEffect)(()=>{e&&(s(``),u(``))},[e]),(0,G.jsx)(M,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,G.jsx)(w,{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)(m,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(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}=y(),{toast:r}=P(),i=T(),{providers:a,options:s}=Z(),[c,l]=(0,W.useState)(``),[d,f]=(0,W.useState)(``),[p,h]=(0,W.useState)(``),[g,v]=(0,W.useState)([]),[x,S]=(0,W.useState)(null),[C,E]=(0,W.useState)(`any`),[D,O]=(0,W.useState)([]),k=a.find(e=>e.id===d),j=k?.authScheme===`oauth-subscription`||k?.authScheme===`plugin`,N=o(k?.id,j),I=new Set(g.map(e=>`${e.metric}:${e.period}`)).size<g.length;return(0,W.useEffect)(()=>{e&&(l(e.name),f(e.providerId??``),h(e.accountId??``),v(e.limits?.budgets.map(e=>({...e}))??[]),S(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)(w,{onClick:t,children:n(`common.cancel`)}),(0,G.jsx)(w,{variant:`primary`,disabled:!c.trim()||I,loading:i.isPending,onClick:()=>{if(!e)return;let a=g.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),o=a.length>0||x!=null&&x>0?{budgets:a,rpm:x!=null&&x>0?Math.floor(x):null}:null;i.mutate({id:e.id,name:c.trim(),providerId:d||null,accountId:j&&p||null,limits:o,allowedClients:C===`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)(m,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,G.jsx)(_,{label:n(`tokens.directProvider`),children:(0,G.jsx)(F,{value:d,onChange:e=>{f(e),h(``)},options:s})}),j&&(0,G.jsx)(_,{label:n(`tokens.directAccount`),children:(0,G.jsx)(F,{value:p,onChange:h,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:g,onChange:v})}),(0,G.jsx)(_,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,G.jsx)(b,{value:x,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:S})}),(0,G.jsx)(_,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(u,{ariaLabel:n(`tokens.allowedClients`),value:C,onChange:E,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),C===`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}=y(),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)(b,{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)(w,{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)(w,{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};
|