@aidotnet/server-linux-x64 0.14.3102 → 0.14.3103
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-CbisrdvY.js +9 -0
- package/bin/wwwroot/assets/KeyPage-BJkqoRws.js +1 -0
- package/bin/wwwroot/assets/McpPage-lDbAQFBD.js +3 -0
- package/bin/wwwroot/assets/ModelDetailPage-2SDue3md.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-Djwi1_69.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-Cr3_QueY.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-K20lHsrR.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-dCLgz9IA.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-B3UD_FXO.js +3 -0
- package/bin/wwwroot/assets/SettingsPage-BOv88_uQ.js +2 -0
- package/bin/wwwroot/assets/SmartRoutingPage-DUdAF-mO.js +2 -0
- package/bin/wwwroot/assets/TokenDetailPage-DAFuMypb.js +1 -0
- package/bin/wwwroot/assets/{TokenPoolEditor-BANCSW9l.js → TokenPoolEditor-CGc4q0xj.js} +1 -1
- package/bin/wwwroot/assets/TokensPage-BAszgNt-.js +1 -0
- package/bin/wwwroot/assets/TracesPage-zR4Nhppl.js +8 -0
- package/bin/wwwroot/assets/{TrayPanelPage-j67xTz4h.js → TrayPanelPage-BzWJbHrV.js} +1 -1
- package/bin/wwwroot/assets/TrayPanelView-C8TTq4KZ.js +1 -0
- package/bin/wwwroot/assets/alert-BKRTQ9va.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-BxJ88yaJ.js → arrow-down-4QyszMPK.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-B3Ql-3af.js → arrow-left-CgusYKe5.js} +1 -1
- package/bin/wwwroot/assets/{arrow-up-right-QVW-fAFr.js → arrow-up-right-CgKLuRMO.js} +1 -1
- package/bin/wwwroot/assets/{chart-column-D6AP76ve.js → chart-column-DrO0zSNb.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-3cbHcFXQ.js → checkbox-JghCvxwP.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-d2J3TjHp.js → cloud-download-Cq6X58YR.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-bdMiffHC.js +1 -0
- package/bin/wwwroot/assets/{ellipsis-2ewY1Pkj.js → ellipsis-C09AxsS6.js} +1 -1
- package/bin/wwwroot/assets/{external-link-Ba13ucfD.js → external-link-B54WZqyE.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-DTgeVtUv.js → folder-open-DbnPnrzj.js} +1 -1
- package/bin/wwwroot/assets/index-8z9hfQDF.css +1 -0
- package/bin/wwwroot/assets/index-Cj8lNw6g.js +120 -0
- package/bin/wwwroot/assets/{log-out-DOtmyFi6.js → log-out-ZnLW7wzx.js} +1 -1
- package/bin/wwwroot/assets/minus-DosBdkUl.js +1 -0
- package/bin/wwwroot/assets/overlays-CizKmvVN.js +41 -0
- package/bin/wwwroot/assets/{pencil-CFjPUH1Y.js → pencil-BuVygJ9-.js} +1 -1
- package/bin/wwwroot/assets/{power-10gcP_1M.js → power-CfEiSxDi.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-6WsHN05O.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-C3uEcj_6.js → rotate-ccw-BhDSBCvo.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-Vg9V11Ab.js → sortable.esm-4hCCGHPl.js} +1 -1
- package/bin/wwwroot/index.html +4 -4
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-CcRyNV5u.js +0 -9
- package/bin/wwwroot/assets/KeyPage-DBEozu4C.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-DsuE2gLp.js +0 -1
- package/bin/wwwroot/assets/ModelsPage--EjkhnLC.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-B4wswSWs.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-DtowG3QB.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-Cc5KTl0J.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-D4cQrTgo.js +0 -3
- package/bin/wwwroot/assets/SettingsPage-Ab6k-ndX.js +0 -2
- package/bin/wwwroot/assets/SmartRoutingPage-Ca6ZC-sk.js +0 -2
- package/bin/wwwroot/assets/TokenDetailPage-tNGeSuwb.js +0 -1
- package/bin/wwwroot/assets/TokensPage-Ak52kWw6.js +0 -1
- package/bin/wwwroot/assets/TracesPage-DgaPoaqm.js +0 -8
- package/bin/wwwroot/assets/TrayPanelView-Cl2xyavV.js +0 -1
- package/bin/wwwroot/assets/alert-DpRdHImb.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-Dpiz2iAT.js +0 -1
- package/bin/wwwroot/assets/download-BF1gj38s.js +0 -1
- package/bin/wwwroot/assets/index-CpGX4nAj.css +0 -1
- package/bin/wwwroot/assets/index-YcD3CI_o.js +0 -17
- package/bin/wwwroot/assets/minus-CSv_UD8H.js +0 -1
- package/bin/wwwroot/assets/overlays-Ca_JSpnI.js +0 -41
- package/bin/wwwroot/assets/radio-cards-CWs2Sjuq.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Bt as e,Cr as t,E as n,Er as r,Et as i,Ft as a,Gi as o,Gt as s,H as c,It as l,Ji as u,Lt as d,Mi as f,Ni as p,Pi as m,Qi as h,Si as g,Ti as _,Ui as v,Un as y,Vr as b,Vt as x,W as S,Xr as C,Yi as ee,Zr as w,_ as T,_a as E,aa as te,bi as ne,co as D,ct as O,d as k,da as re,ea as ie,ga as A,gt as j,ht as ae,i as oe,l as M,la as se,ln as ce,lo as le,m as N,n as P,o as ue,p as de,po as fe,r as F,ra as pe,s as I,sa as me,sn as L,t as he,ta as R,ti as ge,tn as _e,u as z,ua as B,uo as ve,v as V,va as ye,vn as be,xa as H,xt as U,y as W,ya as xe,yn as Se,zn as Ce}from"./alert-BKRTQ9va.js";import{A as we,D as Te,M as Ee,O as De,a as G,ct as K,dt as Oe,i as ke,j as Ae,k as je,n as Me,o as q,r as J}from"./overlays-CizKmvVN.js";import{t as Ne}from"./TrayPanelView-C8TTq4KZ.js";import{t as Pe}from"./ellipsis-C09AxsS6.js";import{t as Fe}from"./external-link-B54WZqyE.js";import{n as Ie,t as Le}from"./radio-cards-6WsHN05O.js";import{t as Re}from"./folder-open-DbnPnrzj.js";import{t as ze}from"./log-out-ZnLW7wzx.js";import{t as Be}from"./minus-DosBdkUl.js";import{t as Ve}from"./pencil-BuVygJ9-.js";import{t as He}from"./rotate-ccw-BhDSBCvo.js";import{A as Ue,B as We,C as Ge,E as Ke,P as qe,T as Je,U as Ye,W as Xe,at as Ze,h as Qe,n as $e,nt as et,s as tt,t as nt,tt as rt,w as it,z as at}from"./index-Cj8lNw6g.js";var ot={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`}]]};ot.node;var st=U(ot),ct={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`}]]};ct.node;var lt=U(ct),ut={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`}]]};ut.node;var dt=U(ut),ft={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`}]]};ft.node;var pt=U(ft),mt={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`}]]};mt.node;var ht=U(mt),gt={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`}]]};gt.node;var _t=U(gt),vt={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`}]]};vt.node;var yt=U(vt),Y=fe(ve(),1),X=le(),bt=`https://astra-gate.si/docs/guide/remote-access`,xt=`astra.remote.acknowledged`;function St(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 Ct(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 wt(){try{return localStorage.getItem(xt)===`1`}catch{return!1}}function Tt(){try{localStorage.setItem(xt,`1`)}catch{}}function Et(){let{t:e}=O(),t=f(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(kt,{s:n}),(0,X.jsx)(Mt,{s:n}),(0,X.jsx)(ue,{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)(he,{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:G(t.error)}):(0,X.jsx)(V,{className:`mx-auto my-8`})})}function Dt({s:t}){let{t:n,locale:r}=O(),{toast:i,confirm:a}=q(),o=g(),s=e(),l=St(t,n),u=async e=>{await K.copy(e)&&i(n(`common.copied`))},d=async e=>{if(e&&!wt()){if(!await a({title:n(`settings.remote.enableConfirm`),detail:n(`settings.remote.enableDetail`),confirmLabel:n(`settings.remote.enableAction`)}))return;Tt()}(e||!s.data?.remote||await a({title:n(`settings.remote.disableSelfConfirm`),detail:n(`settings.remote.disableSelfDetail`),confirmLabel:n(`settings.remote.disableAction`),destructive:!0}))&&o.mutate(e,{onError:e=>i(G(e),`error`)})},f=t.state===`connected`?`green`:t.state===`off`?`neutral`:`orange`,p=t.connectedAt?Date.now()-new Date(t.connectedAt).getTime():null,m=t.state===`connected`&&p!==null?p<6e4?n(`settings.remote.connectedJustNow`):n(`settings.remote.connectedFor`,{duration:S(p,r)}):t.state===`downloading`&&t.cloudflared.source?n(`settings.remote.state.downloadingFrom`,{source:t.cloudflared.source}):n(`settings.remote.state.${t.state}`),h=t.cloudflared,_=h.downloading||h.path?null:h.asset?n(`settings.remote.cloudflaredMissing`,{version:h.version??``}):n(`settings.remote.cloudflaredUnsupported`),v=t.enabled?t.error??h.error??null:null,y=v!==null&&(t.state!==`connected`||/origin service|origin server/i.test(v)),b=t.publicUrl;return(0,X.jsxs)(z,{title:n(`settings.remote.status`),footer:n(`settings.remote.statusFooter`),children:[(0,X.jsx)(N,{label:n(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:t.connectedAt?c(t.connectedAt,r):void 0,children:[(0,X.jsx)(I,{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)(W,{checked:t.enabled,label:n(`settings.remote.enable`),disabled:o.isPending||!t.enabled&&l!==null,onChange:e=>void d(e)})}),!t.enabled&&l&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:l}),!t.enabled&&!l&&_&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:_}),t.enabled&&b&&(0,X.jsxs)(N,{label:n(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${b}/v1`}),children:[(0,X.jsx)(Me,{label:n(`settings.remote.copyMenu`),icon:(0,X.jsx)(j,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:n(`settings.remote.copy.openai`),onSelect:()=>void u(`${b}/v1`)},{id:`anthropic`,label:n(`settings.remote.copy.anthropic`),onSelect:()=>void u(b)},{id:`key`,label:n(`settings.remote.copy.key`),onSelect:()=>void u(`${b}/key`),separatorBefore:!0}]}),(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":n(`settings.remote.openPage`),title:n(`settings.remote.openPage`),onClick:()=>window.open(b,`_blank`,`noopener`)})]}),t.enabled&&b&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`settings.remote.publicUrlHint`)}),y&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(he,{tone:t.state===`connected`?`warning`:`danger`,title:Ct(v,t,n),children:v})})]})}function Ot({s:e}){let{t}=O(),{toast:n,confirm:r}=q(),i=u(),[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 K.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(G(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(G(e),`error`)}),d=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(z,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(N,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(T,{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)(he,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(N,{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)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{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)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(dt,{className:`size-3.5`}),onClick:()=>window.open(bt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(F,{size:`sm`,disabled:!d||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function kt({s:t}){let{t:n}=O(),{toast:r,confirm:i}=q(),a=u(),o=e(),s=async e=>{(!e||await i({title:n(`settings.remote.adminConfirm`),detail:n(`settings.remote.adminDetail`),confirmLabel:n(`settings.remote.adminAction`),destructive:!0}))&&(e||!o.data?.remote||await i({title:n(`settings.remote.adminOffSelfConfirm`),detail:n(`settings.remote.adminOffSelfDetail`),confirmLabel:n(`settings.remote.disableAction`),destructive:!0}))&&a.mutate({allowAdmin:e},{onError:e=>r(G(e),`error`)})};return(0,X.jsxs)(z,{title:n(`settings.remote.scope`),footer:n(`settings.remote.scopeFooter`),children:[(0,X.jsx)(N,{label:n(`settings.remote.scope.gateway`),detail:n(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(P,{tone:`green`,children:n(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(N,{label:n(`settings.remote.scope.admin`),detail:t.checks.passwordSet?n(`settings.remote.scope.adminHint`):n(`settings.remote.block.password`),children:(0,X.jsx)(W,{checked:t.allowAdmin,label:n(`settings.remote.scope.admin`),disabled:a.isPending||!t.allowAdmin&&!t.checks.passwordSet,onChange:e=>void s(e)})}),(0,X.jsx)(At,{passwordSet:t.checks.passwordSet})]})}function At({passwordSet:t}){let{t:n}=O(),{toast:r}=q(),i=e(),a=C(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:n(`settings.remote.password`),detail:n(t?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!o&&!i.data?.required&&(0,X.jsx)(F,{size:`sm`,onClick:()=>s(!0),children:n(t?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),o&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":n(`settings.remote.passwordNew`),placeholder:n(`settings.remote.passwordNew`),value:c,onChange:e=>l(e.target.value)}),(0,X.jsx)(F,{size:`sm`,variant:`plain`,onClick:()=>s(!1),children:n(`common.cancel`)}),(0,X.jsx)(F,{size:`sm`,variant:`primary`,disabled:c.length<8,loading:a.isPending,onClick:()=>a.mutate(c,{onSuccess:()=>{r(n(`settings.remote.passwordSaved`)),s(!1),l(``)},onError:e=>r(G(e),`error`)}),children:n(`common.save`)})]})]})}var jt=[`auto`,`github`,`astra`,`custom`];function Mt({s:t}){let{t:n}=O(),{toast:r}=q(),i=u(),a=Se(),o=e(),s=t.cloudflared,[c,l]=(0,Y.useState)(t.download.downloadBaseUrl??``),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(``);(0,Y.useEffect)(()=>l(t.download.downloadBaseUrl??``),[t.download.downloadBaseUrl]);let[h,g]=(0,Y.useState)(t.download.downloadSource);(0,Y.useEffect)(()=>g(t.download.downloadSource),[t.download.downloadSource]);let _=(e,t)=>i.mutate(e,{onSuccess:()=>{r(n(`settings.remote.cf.saved`)),t?.()},onError:e=>r(G(e),`error`)}),v=e=>{g(e),(e!==`custom`||t.download.downloadBaseUrl)&&_({downloadSource:e})},y=()=>a.mutate(void 0,{onSuccess:e=>e.path?m(e.path):r(n(`settings.remote.cf.detectNone`)),onError:e=>r(G(e),`error`)}),b=s.fromEnvironment?n(`settings.remote.cf.fromEnv`):s.installed?s.version?n(`settings.remote.cf.installedProgram`,{version:s.version}):n(`settings.remote.cf.installedUnknown`):s.path?n(`settings.remote.cf.downloaded`,{version:s.version??``}):s.asset?n(`settings.remote.cf.notDownloaded`,{version:s.version??``}):n(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(z,{title:`cloudflared`,footer:n(`settings.remote.cf.footer`),children:[(0,X.jsx)(N,{label:n(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:s.path??void 0,children:b}),children:(0,X.jsx)(I,{tone:s.path?`green`:s.asset?`neutral`:`red`})}),!t.download.cloudflaredPath&&!s.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:n(`settings.remote.cf.source`),detail:n(`settings.remote.cf.source.${h}.hint`),children:(0,X.jsx)(J,{className:`w-44`,ariaLabel:n(`settings.remote.cf.source`),value:h,onChange:v,options:jt.map(e=>({value:e,label:n(`settings.remote.cf.source.${e}`)}))})}),h===`custom`&&(0,X.jsxs)(N,{label:n(`settings.remote.cf.baseUrl`),detail:n(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":n(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:c,onChange:e=>l(e.target.value)}),(0,X.jsx)(F,{size:`sm`,disabled:!c.trim()||i.isPending||c.trim()===(t.download.downloadBaseUrl??``)&&t.download.downloadSource===`custom`,onClick:()=>_({downloadSource:`custom`,downloadBaseUrl:c.trim()}),children:n(`common.save`)})]})]}),!o.data?.remote&&!s.fromEnvironment&&(0,X.jsx)(N,{label:n(`settings.remote.cf.installed`),detail:t.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.download.cloudflaredPath}):n(`settings.remote.cf.installedHint`),children:t.download.cloudflaredPath?(0,X.jsx)(F,{size:`sm`,disabled:i.isPending,onClick:()=>_({cloudflaredPath:``}),children:n(`settings.remote.cf.useDownloaded`)}):!d&&(0,X.jsx)(F,{size:`sm`,onClick:()=>{f(!0),y()},children:n(`settings.remote.cf.choose`)})}),d&&!t.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(k,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":n(`settings.remote.cf.installedPath`),placeholder:n(`settings.remote.cf.installedPath`),value:p,onChange:e=>m(e.target.value)}),(0,X.jsx)(F,{size:`sm`,variant:`plain`,loading:a.isPending,onClick:y,children:n(`settings.remote.cf.detect`)}),(0,X.jsx)(F,{size:`sm`,variant:`plain`,onClick:()=>f(!1),children:n(`common.cancel`)}),(0,X.jsx)(F,{size:`sm`,variant:`primary`,disabled:!p.trim(),loading:i.isPending,onClick:()=>_({cloudflaredPath:p.trim()},()=>f(!1)),children:n(`settings.remote.cf.use`)})]})]})}var Nt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Pt={local:`127.0.0.1`,lan:`0.0.0.0`},Ft=e=>Nt.includes(e)?`local`:`lan`;function It(){let{t}=O(),{toast:n,confirm:r}=q(),i=D(),a=Ce(),o=e(),s=m(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=a.data;if(!f)return(0,X.jsx)(N,{label:t(`settings.listen`),detail:a.isError?G(a.error):void 0,children:a.isPending&&(0,X.jsx)(V,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,h=Ft(f.configuredHost),g=f.configuredHost!==f.host,_=!!o.data?.required,v=async e=>{await K.copy(e)&&n(t(`common.copied`))},y=e=>s.mutate(Pt[e],{onSuccess:e=>e.configuredHost!==e.host&&n(t(`settings.listen.saved`)),onError:e=>n(G(e),`error`)}),b=async e=>{if(e!==h){if(e===`lan`){if(!f.passwordSet){l(!0);return}if(!await r({title:t(`settings.listen.lanConfirm`),detail:t(`settings.listen.lanDetail`),confirmLabel:t(`settings.listen.lanAction`)}))return}y(e)}},x=async()=>{d(!0);let e=await K.restartService();if(d(!1),e){if(!e.ok){n(e.error??t(`common.error`),`error`);return}n(t(`settings.listen.restarted`)),i.invalidateQueries()}},S=f.hostFromEnvironment?t(`settings.listen.env`,{address:p}):_?t(`settings.listen.localOnly`,{address:p}):g?`${t(`settings.listen.pending`,{host:f.configuredHost})}${B?``:` · ${t(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.listen`),detail:S,children:!f.hostFromEnvironment&&!_&&(0,X.jsxs)(X.Fragment,{children:[g&&B&&(0,X.jsx)(F,{size:`sm`,loading:u,onClick:()=>void x(),children:t(`settings.listen.restart`)}),(0,X.jsx)(T,{ariaLabel:t(`settings.listen`),value:h,onChange:e=>void b(e),items:[{value:`local`,label:t(`settings.listen.local`)},{value:`lan`,label:t(`settings.listen.lan`)}]})]})}),f.networkUrls.map(e=>(0,X.jsx)(N,{label:t(`settings.listen.networkUrl`),detail:`${e}/v1`,children:(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void v(`${e}/v1`)})},e)),(h===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(At,{passwordSet:f.passwordSet}),(0,X.jsx)(Lt,{open:c,onOpenChange:l,onSaved:()=>y(`lan`)})]})}function Lt({open:e,onOpenChange:t,onSaved:n}){let{t:r}=O(),{toast:i}=q(),a=C(),[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(G(e),`error`)})};return(0,X.jsx)(ke,{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)(F,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(F,{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)(k,{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)(k,{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 Rt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],zt={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/…`},Bt=e=>e===`feishu`||e===`dingtalk`,Vt=(e,t)=>e(`alerts.event.${t}`),Ht=(e,t)=>e(`alerts.event.${t}.hint`);function Ut(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Wt,{}),(0,X.jsx)(Gt,{}),(0,X.jsx)(Xt,{})]})}function Wt(){let{t:e,locale:t}=O(),n=d(!0);return(0,X.jsxs)(z,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(V,{}),n.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(N,{icon:(0,X.jsx)(st,{className:`size-4 text-[var(--danger)]`}),label:`${Vt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${c(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Gt(){let{t:e}=O(),{toast:t,confirm:n}=q(),r=R(),i=be(),a=ne(),o=b(),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),p=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(G(e),`error`)}),m=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(G(e),`error`)})},h=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(G(e),`error`)})};return(0,X.jsxs)(z,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(V,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(N,{icon:(0,X.jsx)(yt,{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)(P,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(P,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||Bt(t.format))&&(0,X.jsx)(P,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(F,{size:`sm`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>p(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(Me,{label:e(`common.more`),icon:(0,X.jsx)(Pe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(Ve,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(pt,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ye,{className:`size-3.5`}),onSelect:()=>void m(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void h(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(F,{size:`sm`,icon:(0,X.jsx)(We,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Kt,{hook:s,onClose:()=>c(null),onSecret:f}),(0,X.jsx)(Jt,{hook:l,onClose:()=>u(null)}),(0,X.jsx)(qt,{secret:d,onClose:()=>f(null)})]})}function Kt({hook:e,onClose:t,onSecret:n}){let{t:r}=O(),{toast:i}=q(),a=L(),o=ee(),[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)(ke,{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)(F,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(F,{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(G(e),`error`)},m=!T&&e!==null&&e.format!==y,g=Bt(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)(M,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(k,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${y}.hint`),children:(0,X.jsx)(J,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||Bt(t))},options:Rt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(k,{mono:!0,value:l,placeholder:zt[y],onChange:e=>u(e.target.value)})}),Bt(y)&&_&&(0,X.jsx)(M,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(k,{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)(M,{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)(M,{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)(k,{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)(k,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(qe,{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)(F,{size:`sm`,icon:(0,X.jsx)(We,{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)(N,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(W,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:g})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(W,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?T||e!==null&&e.format===`generic`&&e.hasSecret:Bt(y))&&(0,X.jsx)(N,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(W,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function qt({secret:e,onClose:t}){let{t:n}=O(),{toast:r}=q();return(0,X.jsx)(ke,{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)(F,{onClick:async()=>e&&await K.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(F,{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 Jt({hook:e,onClose:t}){let{t:n,locale:i}=O(),{toast:a}=q(),o=ie(e?.id),s=r(),l={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(ke,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[o.isLoading&&(0,X.jsx)(V,{lines:4}),o.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:o.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(P,{tone:l[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Vt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:c(e.createdAt,i)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:c(e.nextAttemptAt,i)}):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)(oe,{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)(oe,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(F,{size:`sm`,loading:s.isPending&&s.variables===e.id,onClick:()=>s.mutate(e.id,{onSuccess:()=>a(n(`alerts.delivery.redelivered`)),onError:e=>a(G(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Yt(e){let n=t(),r=_(),a=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),o=Oe({queries:a.map(t=>({queryKey:i.providerAccounts(t.id),queryFn:()=>pe(`GET`,`/api/providers/${te(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?a.flatMap((e,t)=>(o[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Xt(){let{t:e}=O(),{toast:t,confirm:n}=q(),r=l(),i=R(),a=p(),o=ce(),[s,c]=(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(G(e),`error`)})};return(0,X.jsxs)(z,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(V,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(N,{icon:(0,X.jsx)(st,{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)(P,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(P,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Vt(e,n.event)} → ${n.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(W,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(G(e),`error`)})}),(0,X.jsx)(Me,{label:e(`common.more`),icon:(0,X.jsx)(Pe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(Ve,{className:`size-3.5`}),onSelect:()=>c(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{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)(F,{size:`sm`,icon:(0,X.jsx)(We,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Qt,{rule:s,onClose:()=>c(null)})]})}function Zt(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 Qt({rule:e,onClose:t}){let{t:n}=O(),{toast:r}=q(),i=a(),o=R(),s=_e(),c=p(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[ee,w]=(0,Y.useState)(null),[E,te]=(0,Y.useState)(60),ne=i.data?.find(e=>e.id===d),D=Yt(ne?.subjectType),re=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=i.data?.[0];u(t?.name??``),f(t?.event??n?.id??``),h(t?{...Zt(i.data?.find(e=>e.id===t.event)),...t.condition}:Zt(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(o.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),w(t?.repeatMinutes??null),te(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(ke,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(re?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(F,{variant:`primary`,disabled:!l.trim()||!d,loading:s.isPending||c.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:d,condition:i,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:S,repeatMinutes:ee&&ee>0?Math.floor(ee):null,cooldownMinutes:Math.max(0,Math.floor(E??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(G(e),`error`)};re?s.mutate(a,o):e&&c.mutate({id:e.id,...a},o)},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(M,{label:n(`alerts.rules.name`),children:(0,X.jsx)(k,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(M,{label:n(`alerts.rules.event`),hint:d?Ht(n,d):void 0,children:(0,X.jsx)(J,{ariaLabel:n(`alerts.rules.event`),value:d,onChange:e=>{f(e),h(Zt(i.data?.find(t=>t.id===e))),y([])},options:(i.data??[]).map(e=>({value:e.id,label:Vt(n,e.id)}))})}),ne?.params.map(e=>(0,X.jsx)(M,{label:n(`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:n(`alerts.param.${e.name}`),onChange:t=>h({...m,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(J,{ariaLabel:n(`alerts.param.${e.name}`),value:String(m[e.name]??``),onChange:t=>h({...m,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(k,{mono:!0,value:String(m[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>h({...m,[e.name]:t.target.value})})},e.name)),ne&&(0,X.jsx)(M,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${ne.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(T,{ariaLabel:n(`alerts.rules.subjects`),value:g,onChange:_,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),g===`only`&&(0,X.jsx)(tt,{label:n(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...D,...v.filter(e=>!D.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(M,{label:n(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.rules.noWebhooks`)}):(0,X.jsx)(tt,{label:n(`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)(M,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(de,{value:ee,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:w})}),(0,X.jsx)(M,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(de,{value:E,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:te})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(N,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(W,{checked:S,label:n(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function $t(){let{t:e}=O(),t=x(),n=se()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&re;return(0,X.jsxs)(z,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)(en,{loginItem:n}),(0,X.jsx)(tn,{})]})}function en({loginItem:e}){let{t}=O(),{toast:n}=q(),[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)(N,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(W,{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(G(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(V,{className:`size-3.5`})})}function tn(){let{t:e}=O(),{toast:t}=q(),n=x(),r=w(),i=n.data;if(!i)return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:n.isError?G(n.error):void 0,children:n.isPending&&(0,X.jsx)(V,{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)(N,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(W,{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(G(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:nn}=n,rn=[...n.ease.enter],an=[...n.ease.standard],on=[0,1,2,3,4,5,6,7,8,9],sn=6,cn=400,ln=40,un=240,dn=1500,fn=700,pn=700,mn=.22,hn=4,gn=130,_n=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),vn=e=>(String(e).split(`.`)[1]??``).length,yn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),bn=(e,t)=>typeof e==`function`?e(t):e??``,xn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function Sn(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 Cn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${nn.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:an}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${nn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:an},opacity:{duration:$.instant},filter:{duration:$.instant}}})},wn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),Tn={enter:wn(0),center:{...wn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},En={enter:wn(1),center:{...wn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function Dn({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=Ze(e,e=>`${n(e)*1.05}em`),i=Ze(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=Ze(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=Ze(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*nn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(A.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function On({digit:e,direction:t,instant:n}){let r=ye(),i=xe(e),a=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let o=a.current;if(o.digit===e)return;let s=t>0?(e-o.digit+10)%10:-((o.digit-e+10)%10);Math.abs(s)>5&&(s-=Math.sign(s)*10),o.target+=s,o.digit=e,n||r?i.jump(o.target):E(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),on.map(e=>(0,X.jsx)(Dn,{position:i,digit:e},e))]})}function kn({value:e,format:t,direction:n,instant:r}){let i=ye(),a=r?En:i?Tn:Cn;return(0,X.jsx)(H,{initial:!1,custom:n,children:Sn(e,t).map(e=>(0,X.jsx)(A.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(On,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function An({text:e,direction:t,className:n}){let r=ye();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(H,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(A.span,{className:Z.char,custom:t,variants:r?Tn:Cn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var jn=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},Mn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=jn(n[t]),i=jn(e);return r!==null&&i!==null&&i<r?-1:1})},Nn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${nn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:rn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${nn.subtle}px)`,transition:{duration:.14,ease:an}})},Pn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Fn({word:e,direction:t}){let n=ye(),r=(0,Y.useRef)(null),i=xe(`auto`),a=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!a.current||n?i.jump(e.offsetWidth):E(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(A.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(H,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(A.span,{className:Z.word,custom:t,variants:n?Pn:Nn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function In({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:Mn(t.text,e)});let r=t.text===e?t.directions:Mn(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)(Fn,{word:e,direction:r[t]??1})]},t))})]})}function Ln({id:e,text:t,className:n}){return(0,X.jsx)(H,{initial:!1,children:t?(0,X.jsx)(Rn,{id:e,text:t,className:n},`message`):null})}function Rn({id:e,text:t,className:n}){let r=ye(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(A.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(A.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${nn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:rn},children:(0,X.jsx)(In,{text:t})})})}function zn({id:e,edge:t,text:n}){let r=ye();return(0,X.jsx)(H,{initial:!1,children:t!==0&&(0,X.jsx)(A.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${nn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:an}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function Bn({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:Be;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 Vn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:p=!1,locale:m=`en-US`,formatOptions:h,size:g=`md`,limitHint:_=!0}){let v=ye(),y=(0,Y.useId)(),b=u??y,x=c?`${b}-description`:void 0,S=`${b}-limit`,C=o>0?o:1,[ee,w]=(0,Y.useState)(n),T=t??ee,[te,ne]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,re]=(0,Y.useState)(0),[ie,j]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(``),[M,se]=(0,Y.useState)(0),[ce,le]=(0,Y.useState)(!1),N=(0,Y.useRef)(null),P=(0,Y.useRef)(null),ue=(0,Y.useRef)(null),de=(0,Y.useRef)(void 0),fe=(0,Y.useRef)(void 0),F=(0,Y.useRef)(void 0),pe=(0,Y.useRef)({edge:0,count:0,at:0}),I=(0,Y.useRef)(null),me=(0,Y.useRef)(null),L=(0,Y.useRef)(T),he=(0,Y.useRef)(T),R=(0,Y.useRef)(void 0),ge=(0,Y.useRef)(null),_e=(0,Y.useRef)(!1),z=(0,Y.useRef)(null),B=(0,Y.useRef)(!1),ve=(0,Y.useRef)(()=>!1),V=xe(0),be=xe(0),H=xe(0),U=Ze(()=>be.get()+H.get()),W=Number.isFinite(i)?i:0,Se=Math.max(vn(C),vn(W)),Ce=h?.minimumFractionDigits??Se,we=Math.max(Ce,h?.maximumFractionDigits??Se),Te=h?.useGrouping??!0,Ee=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:Ce,maximumFractionDigits:we,useGrouping:Te,numberingSystem:`latn`}),[m,Ce,we,Te]),De=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(m).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[m]),G=e=>Number(e.toFixed(Se))||0,K=e=>Math.min(a,Math.max(i,e)),Oe=e=>G(W+Math.round((e-W)/C)*C),ke=(e,t)=>{let n=(e-W)/C;return G(W+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*C)},Ae=e=>`${bn(d,e)}${Ee.format(e)}${bn(f,e)}`.trim();function je(e){let t=e.split(De.group).join(``).replace(De.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Me=D?je(te):null,q=Me??T,[J,Ne]=(0,Y.useState)({value:q,direction:1});J.value!==q&&Ne({value:q,direction:q>J.value?1:-1});let Pe=J.value===q?J.direction:q>J.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(R.current),window.clearTimeout(de.current),window.clearTimeout(fe.current),window.clearTimeout(F.current)},[]);function Fe(e,t){let n=performance.now(),r=pe.current;r.count=r.edge===e&&n-r.at<pn?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)),!v){E(V,0,{..._n,velocity:-e*gn*(1+Math.min(r.count-1,hn)*mn)});let n=(e>0?ue:P).current;n&&(t===`button`||t===`key`)&&E(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}_&&(se(e),window.clearTimeout(de.current),de.current=window.setTimeout(()=>se(0),dn))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=K(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),oe(`${Ae(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==L.current&&oe(Ae(i)),i!==L.current&&(L.current=i,t===void 0&&w(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(ke(L.current,e*t),n);(0,Y.useLayoutEffect)(()=>{L.current=T,ve.current=Le});function Re(){let e=me.current;e&&z.current===null&&(z.current=e.getBoundingClientRect().left-be.get()-H.get())}(0,Y.useLayoutEffect)(()=>{let e=z.current,t=me.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-be.get()-H.get());Math.abs(n)<.5||(H.set(H.get()+n),v?H.jump(0):E(H,0,Q.morph))});function ze(){window.clearTimeout(fe.current),le(!1)}function Be(){if(!D)return;Re(),O(!1),ze();let e=je(te);e!==null&&Ie(Oe(e),`type`)}function Ve(){window.clearTimeout(R.current),R.current=void 0,re(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/C));n===`button`&&re(e);let i=0,a=()=>{let t=ve.current(e,r,n);R.current=window.setTimeout(a,t?Math.max(ln,150*.86**++i):un)};R.current=window.setTimeout(a,Le(e,r,n)?cn:360)}function Ue(e){let t=s??C*10,n={ArrowUp:[1,e.shiftKey?t:C],ArrowDown:[-1,e.shiftKey?t:C],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!D&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),Ie(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),D?(B.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&D&&(e.preventDefault(),Re(),O(!1),ze(),B.current=!0,Ie(he.current,`type`))}function We(e){let t=RegExp(`[^0-9${yn(De.group)}${Se||we?yn(De.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);D||(he.current=T),Re(),ne(n),O(!0);let r=je(n);r!==null&&r>=i&&r<=a&&Oe(r)===r&&Ie(r,`type`),ze(),r!==null&&r<i&&(fe.current=window.setTimeout(()=>le(!0),fn))}function Ge(e){_e.current=!1,p&&!l&&e.button===0&&(Be(),ge.current={pointer:e.pointerId,x:e.clientX,from:L.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=ge.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,j(!0)}let r=n/sn,o=Math.trunc(r);Ie(o?ke(t.from,o):t.from,`scrub`);let s=t.from+r*C,c=s>a?(s-a)/C*sn:s<i?(s-i)/C*sn:0;be.set(v?0:xn(c))}function qe(e){let t=ge.current;t&&t.pointer===e.pointerId&&(ge.current=null,t.active&&(_e.current=!0,j(!1),E(be,0,v?{duration:0}:Q.snappy),oe(Ae(L.current))))}let Je=t=>({toward:t,label:e,disabled:l,controls:b,limit:t>0?q>=a:q<=i,pressed:k===t}),Ye=Me===null?0:Me>a?1:Me<i&&ce?-1:0,Xe=_?Ye||M:0,Qe=Xe>0?a:i,$e=Xe?typeof _==`function`?_(Xe>0?`max`:`min`,Qe):`${Xe>0?`Max`:`Min`} ${Ae(Qe)}`:``,et=[x,Ye&&_?S:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":g,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:b,className:Z.label,"data-scrub":p&&!l||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{_e.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(zn,{id:S,edge:Xe,text:$e})]}),(0,X.jsxs)(`div`,{ref:N,className:Z.control,"data-scrubbing":ie||void 0,"data-disabled":l||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(Bn,{...Je(-1),iconRef:P,onPress:()=>He(-1,C,`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=>{!l&&e.target!==I.current&&(I.current?.focus(),I.current?.select())},children:(0,X.jsxs)(A.span,{ref:me,className:Z.value,style:{x:U,y:V},children:[(0,X.jsx)(An,{text:bn(d,q),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":D||void 0,"aria-hidden":`true`,children:(0,X.jsx)(kn,{value:q,format:Ee,direction:Pe,instant:D})}),D&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:te}),(0,X.jsx)(`input`,{ref:I,id:b,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:Se||we?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:D?te:Ee.format(T),disabled:l,"aria-describedby":et,"aria-invalid":Ye?!0:void 0,"aria-valuenow":T,"aria-valuetext":Ae(T),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a: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)(An,{text:bn(f,q),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(Bn,{...Je(1),iconRef:ue,onPress:()=>He(1,C,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(Ln,{id:x,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:ae})]})}var Hn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Un(){let{t:e}=O(),t=D(),[n,r]=we(),i=Ae(),a=Te(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(N,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(W,{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)(Wn,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Le,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:me.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Wn,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Hn.map(o)})}),(0,X.jsx)(Wn,{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)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(He,{className:`size-3.5`}),onClick:()=>r(De),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Wn,{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 Wn({title:e,hint:t,children:n}){let{t:r}=O();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 Gn=[`general`,`notifications`,`remote`,`tray`],Kn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function qn(){let{t:e}=O(),{tab:t}=et(),n=rt(),r=je(),i=Gn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)(Qe,{title:e(`nav.settings`),children:(0,X.jsxs)(Ge,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Je,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Ke,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(_t,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Ke,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(lt,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Ke,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ae,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Ke,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ht,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(it,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Jn,{})}),(0,X.jsx)(it,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ut,{})}),(0,X.jsx)(it,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Et,{})}),r&&(0,X.jsx)(it,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Un,{})})]})})}function Jn(){let{t,locale:n,setLocale:r}=O(),a=$e(),o=ge(),s=v(),c=D(),l=h(),u=e(),d=y(),p=f(),{toast:m,confirm:g}=q(),_=o.data,b=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,x=e=>s.mutate(e,{onError:e=>m(G(e),`error`)}),S=e=>{r(e),x({locale:e})},C=async e=>{await K.copy(e)&&m(t(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(z,{title:t(`settings.appearance`),children:[(0,X.jsx)(N,{label:t(`settings.theme`),children:(0,X.jsx)(T,{ariaLabel:t(`settings.theme`),value:a.theme,onChange:a.setTheme,items:[{value:`system`,label:t(`settings.theme.system`)},{value:`light`,label:t(`settings.theme.light`)},{value:`dark`,label:t(`settings.theme.dark`)}]})}),(0,X.jsx)(N,{label:t(`settings.accent`),detail:a.accentChoice===`system`?a.systemAccent?t(`settings.accent.followingSystem`):t(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(J,{className:`w-40`,ariaLabel:t(`settings.accent`),value:a.accentChoice,onChange:a.setAccentChoice,options:[{value:`system`,label:t(`settings.accent.system`)},...nt.map(e=>({value:e.color,label:t(`settings.accent.${e.id}`)}))]})}),(0,X.jsx)(N,{label:t(`settings.language`),detail:t(`settings.languageHint`),children:(0,X.jsx)(T,{ariaLabel:t(`settings.language`),value:n,onChange:S,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)($t,{}),_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(z,{title:t(`settings.gateway`),footer:t(`settings.gatewayFooter`),children:[(0,X.jsx)(N,{label:t(`settings.gatewayUrl`),detail:`${_.gatewayBaseUrl}/v1`,children:(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void C(`${_.gatewayBaseUrl}/v1`)})}),b&&(0,X.jsx)(N,{label:t(`settings.remote.publicUrl`),detail:b,children:(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void C(b)})}),(0,X.jsx)(It,{}),(0,X.jsx)(N,{label:t(`settings.dataDir`),detail:_.dataDir,children:K.canOpenPaths?(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Re,{className:`size-3.5`}),"aria-label":t(`settings.openFolder`),onClick:()=>void K.openPath(_.dataDir)}):(0,X.jsx)(F,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void C(_.dataDir)})}),(0,X.jsx)(N,{label:t(`settings.requireKey`),detail:t(`settings.requireKeyHint`),children:(0,X.jsx)(W,{checked:_.requireGatewayKey,label:t(`settings.requireKey`),onChange:async e=>{(e||await g({title:t(`settings.requireKeyOffConfirm`),detail:t(`settings.requireKeyOffDetail`),confirmLabel:t(`settings.requireKeyOff`),destructive:!0}))&&x({requireGatewayKey:e})}})}),(0,X.jsx)(N,{label:t(`settings.streamIdle`),detail:t(`settings.streamIdleHint`),children:(0,X.jsx)(er,{label:t(`settings.streamIdle`),value:_.streamIdleTimeoutSec,onCommit:e=>x({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(N,{label:t(`settings.requestCompression`),detail:t(`settings.requestCompressionHint`),children:(0,X.jsx)(J,{className:`w-40`,ariaLabel:t(`settings.requestCompression`),value:_.requestCompression,onChange:e=>x({requestCompression:e}),options:[{value:`default`,label:t(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:t(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(z,{footer:t(`settings.preventSleepHint`),children:(0,X.jsx)(N,{label:t(`settings.preventSleep`),children:(0,X.jsx)(W,{checked:_.preventSleep??!1,label:t(`settings.preventSleep`),onChange:e=>x({preventSleep:e})})})}),(0,X.jsx)(z,{footer:t(`settings.clientFailoverHint`),children:(0,X.jsx)(N,{label:t(`settings.clientFailover`),children:(0,X.jsx)(W,{checked:_.clientProviderFailover??!0,label:t(`settings.clientFailover`),onChange:e=>x({clientProviderFailover:e})})})}),(0,X.jsx)(Zn,{settings:_}),(0,X.jsx)(Qn,{settings:_}),(0,X.jsx)(Xn,{settings:_}),(0,X.jsx)($n,{settings:_}),(0,X.jsxs)(z,{title:t(`settings.quota`),footer:t(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(N,{label:t(`settings.quota.autoInterval`),children:(0,X.jsx)(er,{label:t(`settings.quota.autoInterval`),value:_.quotaAutoIntervalMinutes,onCommit:e=>s.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void c.invalidateQueries({queryKey:i.providers}),onError:e=>m(G(e),`error`)}),suffix:` ${t(`settings.minutes`)}`})}),(0,X.jsx)(N,{label:t(`settings.quota.subscriptionInterval`),detail:t(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(er,{label:t(`settings.quota.subscriptionInterval`),value:_.subscriptionQuotaIntervalMinutes,onCommit:e=>x({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${t(`settings.minutes`)}`})})]}),(0,X.jsx)(z,{footer:t(`settings.usageTimeZone.hint`),children:(0,X.jsx)(N,{label:t(`settings.usageTimeZone`),children:(0,X.jsx)(J,{className:`w-56`,ariaLabel:t(`settings.usageTimeZone`),value:_.usageTimeZone??``,onChange:e=>x({usageTimeZone:e||null}),options:[{value:``,label:t(`settings.usageTimeZone.system`,{zone:_.effectiveUsageTimeZone})},...[...new Set([...Kn,..._.usageTimeZone?[_.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(z,{title:t(`settings.logging`),footer:t(`settings.debugBodiesHint`),children:[(0,X.jsx)(N,{label:t(`settings.debugBodies`),children:(0,X.jsx)(W,{checked:_.debugBodies,label:t(`settings.debugBodies`),onChange:e=>x({debugBodies:e})})}),(0,X.jsx)(N,{label:t(`settings.bodyRetention`),children:(0,X.jsx)(er,{label:t(`settings.bodyRetention`),value:_.bodyRetentionDays,onCommit:e=>x({bodyRetentionDays:e??7}),suffix:` ${t(`settings.days`)}`})}),(0,X.jsxs)(N,{label:t(`settings.requestRetention`),detail:_.requestRetentionDays==null?t(`settings.keepForever`):void 0,children:[(0,X.jsx)(W,{checked:_.requestRetentionDays!=null,label:t(`settings.requestRetention`),onChange:e=>x({requestRetentionDays:e?90:null})}),_.requestRetentionDays!=null&&(0,X.jsx)(er,{label:t(`settings.requestRetention`),value:_.requestRetentionDays,onCommit:e=>x({requestRetentionDays:e??90}),suffix:` ${t(`settings.days`)}`})]})]}),(0,X.jsx)(z,{footer:t(`settings.traceContentHint`),children:(0,X.jsx)(N,{label:t(`settings.traceContent`),children:(0,X.jsx)(W,{checked:_.traceContent??!1,label:t(`settings.traceContent`),onChange:e=>x({traceContent:e})})})}),(0,X.jsx)(z,{title:t(`settings.effort`),footer:t(`settings.effortHint`),children:[`low`,`medium`,`high`].map(e=>(0,X.jsx)(N,{label:t(`settings.effort.${e}`),children:(0,X.jsx)(er,{label:t(`settings.effort.${e}`),value:_.effortBudgets[e],onCommit:t=>x({effortBudgets:{..._.effortBudgets,[e]:t??_.effortBudgets[e]}}),suffix:` tokens`,step:1024})},e))})]}):o.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:G(o.error)}):(0,X.jsx)(V,{className:`mx-auto my-8`}),(0,X.jsxs)(z,{title:t(`settings.about`),children:[(0,X.jsx)(N,{label:t(`settings.serverVersion`),detail:l.data?`${l.data.version} · API ${l.data.apiVersion}`:`—`}),B&&(0,X.jsx)(N,{label:t(`settings.desktopVersion`),detail:se()?.version||`—`}),(0,X.jsx)(Yn,{}),B&&(0,X.jsx)(N,{label:t(`settings.logs`),onClick:()=>void K.revealLogs(),children:(0,X.jsx)(Re,{className:`size-4 text-[var(--text-secondary)]`})}),u.data?.required&&(0,X.jsx)(N,{label:t(`settings.logout`),onClick:()=>d.mutate(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Yn(){let{t:e}=O(),{toast:t}=q(),n=D(),r=v(),a=ge(),c=o(),l=s(),u=c.data,d=a.data?.updateChannel??u?.channel,f=se()?.updates??null,[p,m]=(0,Y.useState)(!1),h=()=>l.mutate(void 0,{onSuccess:n=>n.error?t(e(`settings.updateCheckFailed`,{error:n.error}),`error`):t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(G(e),`error`)}),g=()=>{f&&!p&&(m(!0),f.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:i.version}),n.invalidateQueries({queryKey:i.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(G(e),`error`)).finally(()=>m(!1)))},_=u?.lastCheckAt?new Date(u.lastCheckAt).toLocaleString():void 0,y=u?.available?f?e(`settings.updateAvailable`,{version:u.available}):`${e(`settings.updateAvailable`,{version:u.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.autoCheck`),detail:u&&!u.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(W,{checked:u?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(G(e),`error`)})})}),(0,X.jsx)(N,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(W,{checked:d===`preview`,label:e(`settings.previewUpdates`),disabled:!d||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:h,onError:e=>t(G(e),`error`)})})}),(0,X.jsxs)(N,{label:e(`settings.checkUpdates`),detail:l.isError?e(`settings.updateCheckFailed`,{error:G(l.error)}):u?.available?y:_?e(`settings.lastChecked`,{time:_}):void 0,children:[(0,X.jsx)(F,{size:`sm`,variant:`plain`,disabled:l.isPending,onClick:h,children:l.isPending?(0,X.jsx)(V,{className:`size-3.5`}):(0,X.jsx)(at,{className:`size-3.5`})}),f&&u?.available&&(0,X.jsx)(F,{size:`sm`,variant:`plain`,disabled:p,"aria-label":e(`settings.updateApply`),onClick:g,children:p?(0,X.jsx)(V,{className:`size-3.5`}):(0,X.jsx)(Xe,{className:`size-3.5`})})]})]})}function Xn({settings:e}){let{t}=O(),{toast:n}=q(),r=v(),[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(G(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(G(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(z,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(N,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(T,{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)(N,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value: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)(F,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Zn({settings:e}){let{t}=O(),{toast:n}=q(),r=v(),i=e.providerQualifiedModels??!1,a=i?e.modelQualifyScope??`shared`:`off`,o=e.modelProviderSeparator??`@`,[s,c]=(0,Y.useState)(o);(0,Y.useEffect)(()=>c(o),[o]);let l=e=>r.mutate(e,{onError:e=>{c(o),n(G(e),`error`)}});return(0,X.jsxs)(z,{title:t(`settings.qualifiedModels`),footer:t(`settings.qualifiedModels.footer`),children:[(0,X.jsx)(N,{label:t(`settings.qualifiedModels.mode`),detail:t(`settings.qualifiedModels.modeHint`),children:(0,X.jsx)(J,{className:`w-56`,ariaLabel:t(`settings.qualifiedModels.mode`),value:a,onChange:e=>l(e===`off`?{providerQualifiedModels:!1}:{providerQualifiedModels:!0,modelQualifyScope:e}),options:[{value:`off`,label:t(`settings.qualifiedModels.mode.off`)},{value:`shared`,label:t(`settings.qualifiedModels.mode.shared`)},{value:`all`,label:t(`settings.qualifiedModels.mode.all`)}]})}),i&&(0,X.jsx)(N,{label:t(`settings.qualifiedModels.separator`),detail:t(`settings.qualifiedModels.separatorHint`),children:(0,X.jsx)(k,{className:`w-24`,mono:!0,maxLength:8,"aria-label":t(`settings.qualifiedModels.separator`),value:s,onChange:e=>c(e.target.value),onBlur:()=>s!==o&&l({modelProviderSeparator:s})})})]})}function Qn({settings:e}){let{t}=O(),{toast:n}=q(),r=v(),i=e.hiddenNav??[],a=Ue.flatMap(e=>e.items).filter(e=>e.id!==`settings`),o=(e,t)=>r.mutate({hiddenNav:t?i.filter(t=>t!==e):[...i,e]},{onError:e=>n(G(e),`error`)});return(0,X.jsx)(z,{title:t(`settings.sidebar`),footer:t(`settings.sidebar.footer`),children:a.map(e=>(0,X.jsx)(N,{label:t(e.label),children:(0,X.jsx)(W,{checked:!i.includes(e.id),label:t(e.label),onChange:t=>o(e.id,t)})},e.id))})}function $n({settings:e}){let{t}=O(),{toast:n}=q(),r=v(),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(G(e),`error`)});return(0,X.jsxs)(z,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(W,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(k,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value: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)(F,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(F,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function er({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)(Vn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{qn as SettingsPage};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{J as e,Kr as t,Wi as n,_ as r,b as i,ct as a,d as o,gt as s,lo as c,m as l,n as u,na as d,o as f,p,po as m,r as h,ri as g,s as _,t as v,u as y,uo as b,ut as x,v as S,vi as C,y as w}from"./alert-BKRTQ9va.js";import{a as T,ct as E,o as D,r as O}from"./overlays-CizKmvVN.js";import{t as k}from"./arrow-down-4QyszMPK.js";import{B as A,P as j,S as M,Y as N,h as P}from"./index-Cj8lNw6g.js";var F=m(b(),1),I=c(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(l,{...t,detail:e==null?void 0:(0,I.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var B={typesafe:[{id:`typesafe`,baseUrl:``,model:`jev-latest`},{id:`openrouter`,baseUrl:`https://openrouter.ai/api`,model:`~typesafe/jev-latest`},{id:`vercel`,baseUrl:`https://ai-gateway.vercel.sh/typesafe`,model:`typesafe-ai/jev`}],openai:[{id:`openai`,baseUrl:``}]},V=(e,t)=>`${e??``}\n${t}`;function H(e,t){let n=t.trim().replace(/\/+$/,``);return B[e].find(e=>e.baseUrl===n)?.id??`custom`}function U(e,t,n){let r=e.trim()||(n.find(e=>e.id===t)?.defaultBaseUrl??``);try{return new URL(r).origin.toLowerCase()}catch{return r}}function W(e){return{virtualModel:e.virtualModel,protocol:e.judge.protocol,baseUrl:e.judge.baseUrl??``,apiKey:``,model:e.judge.model,instructions:e.judge.instructions??``,timeoutMs:e.judge.timeoutMs,grades:e.grades.map(e=>({...e})),mode:e.rules.mode,sessionTtlMinutes:e.rules.sessionTtlMinutes,fallbackGrade:e.rules.fallbackGrade,minConfidence:e.rules.minConfidence,contextTurns:e.rules.contextTurns,maxChars:e.rules.maxChars}}var G=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function K(e){return{protocol:e.protocol,baseUrl:e.baseUrl,model:e.model,instructions:e.instructions,...e.timeoutMs!==null&&{timeoutMs:e.timeoutMs},...e.apiKey!==``&&{apiKey:e.apiKey}}}function q(e){return{virtualModel:e.virtualModel,judge:K(e),grades:e.grades,rules:{mode:e.mode,fallbackGrade:e.fallbackGrade,...e.sessionTtlMinutes!==null&&{sessionTtlMinutes:e.sessionTtlMinutes},...e.minConfidence!==null&&{minConfidence:e.minConfidence},...e.contextTurns!==null&&{contextTurns:e.contextTurns},...e.maxChars!==null&&{maxChars:e.maxChars}}}}function J(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in x))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(e,t,n){if(e instanceof d){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>J(e,t,n))}return[T(e)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in x?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in x?t(n):e??``}function Q(){let{t:e}=a(),t=g();return t.data?(0,I.jsx)($,{saved:t.data}):(0,I.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,I.jsx)(v,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(S,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=a(),{toast:r}=D(),i=n(),[o,s]=(0,F.useState)(()=>W(e)),[c,l]=(0,F.useState)([]),u=e=>s(t=>({...t,...e})),d=JSON.stringify(o)!==JSON.stringify(W(e)),f=G(o),p=e=>i.mutate({...q(o),...e!==void 0&&{enabled:e}},{onSuccess:n=>{l([]),s(W(n)),r(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>l(Y(e,o,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:i.isPending,canSave:f,onToggle:e=>p(e),problems:c}),(0,I.jsx)(ne,{saved:e,draft:o,patch:u}),(0,I.jsx)(ie,{draft:o,patch:u}),(0,I.jsx)(ae,{draft:o,patch:u}),!f&&(0,I.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[d&&(0,I.jsx)(h,{variant:`plain`,onClick:()=>s(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(h,{variant:`primary`,disabled:!d||!f,loading:i.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:o}=a(),{toast:c}=D(),{status:l}=e,u=async e=>{await E.copy(e)&&c(o(`common.copied`))},d=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&d.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(y,{title:o(`smartRouting.status`),footer:o(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:o(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(_,{tone:e.enabled?l.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?l.breakerOpen?o(`smartRouting.state.breaker`):`${o(`smartRouting.state.on`)}${l.pins>0?` · ${o(`smartRouting.state.pins`,{count:l.pins})}`:``}`:o(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:o(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:o(`smartRouting.use`),detail:o(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(h,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(s,{className:`size-3.5`}),"aria-label":o(`common.copy`),onClick:()=>void u(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:d,className:`px-3 py-2`,children:(0,I.jsx)(v,{tone:`danger`,title:o(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:i.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:t}){let{t:n,locale:r}=a(),i=t.status.recent??{total:0,outcomes:{}},o=t.status.unreachable??[],s=e=>{let n=t.grades.find(t=>t.id===e);return n?n.name||n.id:e},c=i.outcomes.judge??0,l=Object.entries(i.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),u=i.total-c,d=[n(`smartRouting.recent.judged`,{count:c,total:i.total}),...l.map(([e,t])=>n(`smartRouting.recent.fallback`,{reason:Z(e,n),count:t})),...i.medianJudgeMs==null?[]:[n(`smartRouting.recent.median`,{ms:i.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${l[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:n(`smartRouting.recent`),detail:i.total===0?n(`smartRouting.recent.none`):d}),u>=2&&u*2>i.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(v,{tone:`warning`,title:n(`smartRouting.recent.failing`,{grade:s(t.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:n(f in x?f:`smartRouting.recent.hint.other`)}),i.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:n(`smartRouting.recent.last`,{reason:Z(i.lastFallback,n),time:e(i.lastFallbackAt,r)})})]})}),o.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(v,{tone:`warning`,title:n(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:o.map(t=>{let i=X(t.reason),a={count:t.count,time:e(t.lastAt,r)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[n(`smartRouting.unreachable.item`,{caller:M(t.caller),grade:s(t.grade),where:t.providerName?n(`smartRouting.unreachable.where`,{provider:t.providerName,model:t.model}):t.model,reason:n(i??`smartRouting.unusable.unknown`)}),` `,t.usedGrade?n(`smartRouting.unreachable.used`,{...a,used:s(t.usedGrade)}):n(`smartRouting.unreachable.none`,a)]}),i&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`${i}.fix`)})]},`${t.caller}\n${t.grade}`)})}),o.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:n(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:s}=a(),c=H(t.protocol,t.baseUrl),l=e.judge.hasApiKey&&t.apiKey===``&&U(t.baseUrl,t.protocol,e.protocols)!==U(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,I.jsxs)(y,{title:s(`smartRouting.judge.title`),footer:s(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:s(`smartRouting.judge.protocol`),detail:s(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(r,{ariaLabel:s(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>n({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:s(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:s(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(v,{tone:`warning`,title:s(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:s(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:s(`smartRouting.judge.service`),value:c,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=B[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:s(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:s(`smartRouting.preset.custom`)}]})}),c===`custom`&&(0,I.jsx)(z,{label:s(`smartRouting.judge.baseUrl`),detail:s(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(o,{className:`w-72`,mono:!0,"aria-label":s(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:s(`smartRouting.judge.apiKey`),detail:l?s(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?s(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):s(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(o,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":s(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!l?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),l&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(v,{tone:`warning`,title:s(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:s(`smartRouting.judge.model`),detail:s(`smartRouting.judge.modelHint`),children:(0,I.jsx)(o,{className:`w-72`,mono:!0,"aria-label":s(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>n({model:e.target.value})})}),(0,I.jsx)(z,{label:s(`smartRouting.judge.timeout`),detail:s(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(p,{className:`w-28`,label:s(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(v,{tone:`info`,title:s(`smartRouting.privacy.title`),children:s(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(v,{tone:`warning`,title:s(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(f,{title:s(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:s(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(i,{rows:4,"aria-label":s(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:e}){let{t}=a(),n=C(),[r,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)([]),d=()=>{c(null),u([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:c,onError:n=>u(Y(n,e,t))})},f=s!==null&&s.latencyMs>s.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,I.jsx)(i,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>o(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(h,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:d,children:t(`smartRouting.test.run`)})}),l.length>0&&(0,I.jsx)(v,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:l.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),s&&(s.ok?(0,I.jsx)(v,{tone:s.confident&&!f?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:s.gradeName??s.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:s.model?t(`smartRouting.test.model`,{model:s.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((s.confidence??0)*100)}),` ·`,` `,s.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),f&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:s.latencyMs,limit:s.limitMs}),s.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:s.latencyMs,input:s.inputTokens,output:s.outputTokens,model:s.judgeModel??``})})]})}):(0,I.jsxs)(v,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(s.failure,t)}),children:[s.message,s.failure===`timeout`&&s.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:n}){let{t:r}=a(),s=t(),c=e.grades,l=(t,r=e.fallbackGrade)=>n({grades:t,fallbackGrade:t.some(e=>e.id===r)?r:t[Math.floor(t.length/2)]?.id??``}),d=(e,t)=>l(c.map((n,r)=>r===e?{...n,...t}:n)),f=(e,t)=>{let n=[...c];[n[e],n[e+t]]=[n[e+t],n[e]],l(n)},p=()=>{let e=c.length+1;for(;c.some(t=>t.id===`grade-${e}`);)e++;l([...c,{id:`grade-${e}`,name:``,description:``,model:``}])},m=s.data??[],g=new Set(m.filter((e,t)=>m.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),_=m.map(e=>({value:V(e.providerId,e.id),label:g.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:g.has(e.id)?void 0:e.providerName})),v=e=>{let t=V(e.providerId,e.model);return e.model&&!_.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},..._]:_},b=(e,t)=>{let n=t.indexOf(`
|
|
2
|
+
`);d(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(y,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[c.map((t,n)=>(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,I.jsx)(o,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>d(n,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,I.jsx)(u,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(h,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(N,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>f(n,-1)}),(0,I.jsx)(h,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===c.length-1,onClick:()=>f(n,1)}),(0,I.jsx)(h,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:c.length<=L,onClick:()=>l(c.filter((e,t)=>t!==n))})]}),(0,I.jsx)(i,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>d(n,{description:e.target.value})}),(0,I.jsx)(O,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:t.model?V(t.providerId,t.model):``,options:v(t),onChange:e=>b(n,e)})]},t.id)),s.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(h,{size:`sm`,icon:(0,I.jsx)(A,{className:`size-3.5`}),disabled:c.length>=R,onClick:p,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=a();return(0,I.jsxs)(y,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(r,{ariaLabel:n(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:n(`smartRouting.rules.mode.session`)},{value:`turn`,label:n(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(p,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(O,{className:`w-44`,ariaLabel:n(`smartRouting.rules.fallback`),value:e.fallbackGrade,onChange:e=>t({fallbackGrade:e}),options:e.grades.map(e=>({value:e.id,label:e.name||e.id}))})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(p,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(p,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(p,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(f,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(o,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=a();return(0,I.jsx)(P,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Ci as e,Cr as t,Ei as n,G as r,J as i,Lr as a,Q as o,Y as s,_ as c,c as l,ci as u,ct as ee,lo as d,n as f,po as p,q as m,r as h,s as g,t as _,uo as v,v as y,xi as b,xr as x}from"./alert-BKRTQ9va.js";import{J as S,Q as te,X as ne,Y as re,Z as ie,a as ae}from"./overlays-CizKmvVN.js";import{t as oe}from"./arrow-left-CgusYKe5.js";import{$ as C,D as w,O as T,R as E,h as D,m as O,nt as k,tt as A}from"./index-Cj8lNw6g.js";import{a as j,n as M}from"./TokenPoolEditor-CGc4q0xj.js";var N=p(v(),1),P=d();function F(){let{id:d=``}=k(),{t:p,locale:v}=ee(),F=A(),[L,R]=(0,N.useState)(`7d`),z=e(d),B=t(),V=u(L,void 0,d),H=b(L,L===`today`?`hour`:`day`,`token`,void 0,d),U=n(L,void 0,20,d),W=x(L,d),G=a({token:d,page:1,pageSize:10},!1),K=j(),q=(0,P.jsx)(h,{variant:`glass`,icon:(0,P.jsx)(oe,{className:`size-4`}),"aria-label":p(`common.back`),onClick:()=>F(`/tokens`)}),J=p(`range.${L}`),se=(0,N.useMemo)(()=>ie(ne(H.data??[],`requests`),te(L)).map(e=>({key:e.bucket,label:re(e.bucket),axisLabel:S(e.bucket),value:Math.round(e.value)})),[H.data,L]),Y=new Map((B.data??[]).map(e=>[e.id,e.name])),X=(W.data??[]).reduce((e,t)=>e+t.requests,0),ce=(W.data??[]).map(e=>({id:e.providerId,name:Y.get(e.providerId)??e.name??e.providerId,requests:e.requests,share:X?e.requests/X:0,success:e.successRate,ttft:e.avgTtftMs??null,cost:e.costUsd,out:e.failoversOut,in:e.failoversIn})),Z=[{key:`name`,label:p(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:p(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`share`,label:p(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>m(e)},{key:`success`,label:p(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?m(e):`—`},{key:`ttft`,label:p(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>r(e)},{key:`cost`,label:p(`overview.cost`),sortable:!0,numeric:!0,render:e=>o(e)},{key:`out`,label:p(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:p(`tokens.detail.failoversIn`),sortable:!0,numeric:!0}],le=(U.data??[]).map(e=>({model:e.model,requests:e.requests,tokens:e.tokens,cost:e.costUsd})),ue=[{key:`model`,label:p(`tokens.detail.model`),sortable:!0},{key:`requests`,label:p(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`tokens`,label:p(`overview.tokens`),sortable:!0,numeric:!0,render:e=>s(e,!0)},{key:`cost`,label:p(`overview.cost`),sortable:!0,numeric:!0,render:e=>o(e)}],de=(G.data?.items??[]).map(e=>({id:e.id,time:new Date(e.startedAtUtc).getTime(),model:e.requestedModel??`—`,provider:e.providerName??e.providerId??`—`,status:e.status,cost:e.costNanoUsd/1e9,r:e})),fe=[{key:`time`,label:p(`tokens.detail.time`),render:(e,t)=>i(t.r.startedAtUtc,v)},{key:`model`,label:p(`tokens.detail.model`)},{key:`provider`,label:p(`tokens.detail.provider`)},{key:`status`,label:p(`tokens.detail.status`),render:e=>(0,P.jsx)(f,{tone:e===`success`?`green`:`red`,children:p(`status.${e}`)})},{key:`cost`,label:p(`overview.cost`),numeric:!0,render:e=>o(e)}];if(z.isError)return(0,P.jsx)(D,{title:p(`nav.tokens`),leading:q,children:(0,P.jsx)(_,{tone:`danger`,title:p(`common.error`),children:ae(z.error)})});let Q=z.data,$=V.data;return(0,P.jsx)(D,{title:Q?.name??``,subtitle:Q?(0,P.jsx)(`code`,{className:`font-mono`,children:Q.keyMasked}):void 0,leading:q,actions:(0,P.jsx)(C,{to:`/requests?token=${encodeURIComponent(d)}`,children:(0,P.jsx)(h,{icon:(0,P.jsx)(E,{className:`size-3.5`}),children:p(`tokens.detail.viewLogs`)})}),children:(0,P.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[(0,P.jsx)(`div`,{className:`flex justify-end`,children:(0,P.jsx)(c,{ariaLabel:p(`overview.range`),value:L,onChange:R,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:p(`range.${e}`)}))})}),$?(0,P.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-5`,children:[(0,P.jsx)(I,{label:p(`overview.totalCost`),value:o($.costUsd),context:J}),(0,P.jsx)(I,{label:p(`overview.totalRequests`),value:s($.requests),context:J}),(0,P.jsx)(I,{label:p(`overview.tokens`),value:s($.inputTokens+$.outputTokens,!0),context:p(`overview.tokensContext`,{input:s($.inputTokens,!0),output:s($.outputTokens,!0)})}),(0,P.jsx)(I,{label:p(`usage.hitRate`),value:m(O($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,P.jsx)(I,{label:p(`overview.successRate`),value:$.requests?m($.successRate):`—`,context:r($.avgTtftMs)})]}):(0,P.jsx)(y,{lines:3}),Q?.pool&&(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[p(`tokens.pool.title`),` · `,p(`tokens.strategy.${Q.pool.strategy}`)]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-[13px]`,children:Q.pool.members.map(e=>(0,P.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,P.jsx)(g,{tone:M(e.health.state)}),Y.get(e.providerId)??e.providerId,(0,P.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:K(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,P.jsx)(`div`,{className:`card`,children:(0,P.jsx)(l,{title:p(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:p(`overview.tokenEmpty.detail`,{range:J})})}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[p(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,P.jsx)(y,{lines:4}):(0,P.jsx)(T,{data:se,label:p(`overview.requests`),period:J,height:160,formatValue:e=>s(e),averageLabel:p(L===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:p(`overview.total`),categoryLabel:p(L===`today`?`overview.hour`:`overview.day`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-1 text-[13px] font-medium`,children:p(`tokens.detail.byProvider`)}),(0,P.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:p(`tokens.detail.byProviderHint`)}),(0,P.jsx)(w,{caption:p(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:p(`common.noData`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:p(`tokens.detail.byModel`)}),(0,P.jsx)(w,{caption:p(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:p(`common.noData`)})]})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsx)(`h2`,{className:`text-[13px] font-medium`,children:p(`tokens.detail.recent`)}),(0,P.jsx)(C,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(d)}`,children:p(`tokens.detail.viewLogs`)})]}),(0,P.jsx)(w,{caption:p(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:p(`common.noData`)})]})]})})}function I({label:e,value:t,context:n}){return(0,P.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,P.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,P.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,P.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{F as TokenDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{J as e,_ as t,
|
|
1
|
+
import{J as e,_ as t,ct as n,lo as r,n as i,ot as a,p as o,r as s,y as c,yr as l}from"./alert-BKRTQ9va.js";import{r as u}from"./overlays-CizKmvVN.js";import{a as d,c as f,d as p,f as m,i as h,l as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./sortable.esm-4hCCGHPl.js";import{P as w,x as T}from"./index-Cj8lNw6g.js";var E=r(),D=[`failover`,`round_robin`,`weighted`,`tiered`,`least_busy`];function O(e){return e.pool?{strategy:e.pool.strategy,sticky:e.pool.sticky,failover:e.pool.failover,maxAttempts:e.pool.maxAttempts,members:e.pool.members.map(e=>({providerId:e.providerId,accountId:e.accountId??null,weight:e.weight,tier:e.tier}))}:{strategy:`failover`,sticky:`session`,failover:!0,maxAttempts:3,members:e.providerId?[{providerId:e.providerId,accountId:e.accountId??null,weight:1,tier:1}]:[]}}function k(e,t){let n=new Set(t.map(e=>e.id));return{strategy:e.strategy,sticky:e.sticky,failover:e.failover,maxAttempts:Math.min(5,Math.max(1,Math.floor(e.maxAttempts||1))),members:e.members.filter(e=>n.has(e.providerId)).map(e=>({...e,weight:Math.max(1,Math.floor(e.weight||1))}))}}function A(e){let{members:t,strategy:n}=e;if(t.length===0)return[];let r=e=>e.reduce((e,t)=>e+Math.max(1,t.weight),0);switch(n){case`failover`:return t.map((e,t)=>+(t===0));case`weighted`:{let e=r(t);return t.map(t=>Math.max(1,t.weight)/e)}case`tiered`:{let e=Math.min(...t.map(e=>e.tier)),n=r(t.filter(t=>t.tier===e));return t.map(t=>t.tier===e?Math.max(1,t.weight)/n:0)}default:return t.map(()=>1/t.length)}}var j=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],M=new Set([`oauth-subscription`,`plugin`]);function N(e){return e===`healthy`?`green`:e===`cooling`||e===`open`||e===`half_open`?`orange`:`red`}function P(){let{t,locale:r}=n();return n=>n.state===`cooling`||n.state===`open`?t(`tokens.health.${n.state}`,{time:n.until?e(n.until,r):`—`}):t(`tokens.health.${n.state}`)}function F({draft:e,onChange:r,providers:i,health:a}){let{t:s}=n(),l=new Map(i.map(e=>[e.id,e])),m=e.members.length>1,h=p(C(f,{activationConstraint:{distance:4}}),C(x,{coordinateGetter:b})),y=t=>r({...e,members:t}),w=(t,n)=>y(e.members.map((e,r)=>r===t?{...e,...n}:e)),T=({active:t,over:n})=>{if(!n||t.id===n.id)return;let r=e.members.findIndex(e=>e.providerId===t.id),i=e.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&y(_(e.members,r,i))},O=i.filter(t=>t.enabled&&!e.members.some(e=>e.providerId===t.id)),k=A(e),M=e.members.flatMap(e=>{let t=l.get(e.providerId);return t&&t.modelCount===0?[t.name]:[]});return(0,E.jsxs)(`div`,{className:`grid gap-3`,children:[m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(t,{ariaLabel:s(`tokens.pool.strategy`),value:e.strategy,onChange:t=>r({...e,strategy:t}),items:D.map(e=>({value:e,label:s(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:s(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(v,{sensors:h,collisionDetection:g,onDragEnd:T,children:(0,E.jsx)(S,{items:e.members.map(e=>e.providerId),strategy:d,children:e.members.map((t,n)=>(0,E.jsx)(I,{member:t,index:n,draft:e,provider:l.get(t.providerId),health:a?.get(t.providerId),onChange:e=>w(n,e),onRemove:()=>y(e.members.filter((e,t)=>t!==n))},t.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:s(`tokens.pool.add`),placeholder:s(`tokens.pool.add`),value:null,onChange:t=>y([...e.members,{providerId:t,accountId:null,weight:1,tier:1}]),options:O.map(e=>({value:e.id,label:e.name}))}),M.length>0&&(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--warning)]`,children:s(`tokens.pool.noModels`,{providers:M.join(`, `)})}),m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2 text-[12px]`,children:[(0,E.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:s(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:s(`tokens.pool.shareHint`)})]}),(0,E.jsx)(`div`,{className:`flex h-2 gap-0.5 overflow-hidden rounded-full bg-[var(--fill-2)]`,"aria-hidden":`true`,children:e.members.map((e,t)=>k[t]>0?(0,E.jsx)(`span`,{style:{flex:k[t],background:j[t%j.length]}},e.providerId):null)}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:e.members.map((e,t)=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`inline-block size-2 rounded-sm`,style:{background:j[t%j.length]}}),l.get(e.providerId)?.name??e.providerId,(0,E.jsxs)(`b`,{className:`tabular-nums text-[var(--text-primary)]`,children:[Math.round(k[t]*100),`%`]}),k[t]===0&&(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:s(`tokens.pool.standby`)})]},e.providerId))})]}),m&&(0,E.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:s(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(c,{label:s(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:t=>r({...e,sticky:t?`session`:`off`})})]}),(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:s(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(c,{label:s(`tokens.pool.failover`),checked:e.failover,onChange:t=>r({...e,failover:t})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:s(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(o,{label:s(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:t=>r({...e,maxAttempts:t??1})})})]})]})]})}function I({member:e,index:t,draft:r,provider:c,health:d,onChange:f,onRemove:p}){let{t:g}=n(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!c&&M.has(c.authScheme),A=l(c?.id,k),j=c?.name??e.providerId,F=r.members.length>1,I=c?c.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:a(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,O&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,E.jsx)(`button`,{ref:S,type:`button`,"aria-label":g(`clients.dragToReorder`,{provider:j}),title:g(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...v,...b,children:(0,E.jsx)(y,{className:`size-4`})}),c&&(0,E.jsx)(T,{name:c.name,icon:c.icon,colorKey:c.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&r.strategy===`failover`&&(0,E.jsx)(i,{tone:t===0?`accent`:`neutral`,children:t===0?g(`tokens.pool.primary`):g(`tokens.pool.backup`,{n:t})}),I&&(0,E.jsx)(i,{tone:N(I.state),children:_(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(r.strategy===`weighted`||r.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(o,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&r.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:g(`tokens.pool.tier`),value:String(e.tier),onChange:e=>f({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:g(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:g(`tokens.directAccount`),value:e.accountId??``,onChange:e=>f({accountId:e||null}),options:[{value:``,label:g(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(s,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(w,{className:`size-3.5`}),"aria-label":g(`tokens.pool.remove`,{provider:j}),title:g(`tokens.pool.remove`,{provider:j}),onClick:p})]})]})}export{P as a,k as i,N as n,O as r,F as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Br as e,Cr as t,Gr as n,H as r,J as i,Kn as a,Mi as o,Q as s,Ti as c,Wr as l,X as u,Y as d,_ as f,_n as p,an as m,c as h,ct as g,d as _,gt as v,l as y,lo as b,n as x,on as S,p as C,po as w,q as T,qi as ee,r as E,s as D,t as O,ti as k,uo as A,v as j,wi as M,xt as N}from"./alert-BKRTQ9va.js";import{a as P,ct as F,i as I,n as te,o as L,r as R}from"./overlays-CizKmvVN.js";import{t as ne}from"./chart-column-DrO0zSNb.js";import{t as re}from"./ellipsis-C09AxsS6.js";import{t as ie}from"./pencil-BuVygJ9-.js";import{t as ae}from"./power-CfEiSxDi.js";import{t as oe}from"./rotate-ccw-BhDSBCvo.js";import{$ as z,B,F as se,G as ce,P as V,R as le,U as H,_ as U,h as W,s as G,y as K}from"./index-Cj8lNw6g.js";import{a as ue,i as q,n as J,r as Y,t as de}from"./TokenPoolEditor-CGc4q0xj.js";var X={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};X.node;var fe=N(X),pe={name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]};pe.node;var me=N(pe),Z=w(A(),1),Q=b(),he=[15,60,1440];function ge({token:e,open:t,onOpenChange:i}){let{t:a,locale:o}=g(),{toast:s}=L(),[c,l]=(0,Z.useState)(15),[u,d]=(0,Z.useState)(null),p=M(e.id,t),m=S(e.id),h=n(e.id),_=e=>e<60?a(`tokens.invite.minutes`,{n:e}):a(`tokens.invite.hours`,{n:e/60}),v=()=>m.mutate(c,{onSuccess:async e=>{d(e.link),s(await F.copy(e.link)?a(`tokens.invite.copied`):a(`tokens.copyFailed`),`success`)},onError:e=>s(P(e),`error`)}),y=e=>e===`pending`?`accent`:e===`used`?`green`:`neutral`;return(0,Q.jsx)(I,{open:t,onOpenChange:e=>{e||d(null),i(e)},title:a(`tokens.invite.title`,{name:e.name}),description:a(`tokens.invite.description`),footer:(0,Q.jsx)(E,{variant:`primary`,icon:(0,Q.jsx)(fe,{className:`size-3.5`}),loading:m.isPending,onClick:v,children:a(`tokens.invite.generate`)}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:a(`tokens.invite.lifetime`)}),(0,Q.jsx)(f,{items:he.map(e=>({value:String(e),label:_(e)})),value:String(c),onChange:e=>l(Number(e)),ariaLabel:a(`tokens.invite.lifetime`)})]}),u&&(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:a(`tokens.invite.linkOnce`)}),(0,Q.jsx)(`code`,{className:`selectable break-all rounded-lg bg-[var(--surface-muted)] px-3 py-2 font-mono text-[11.5px]`,children:u})]}),(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:a(`tokens.invite.recent`)}),(p.data??[]).length===0?(0,Q.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`tokens.invite.none`)}):(0,Q.jsx)(`ul`,{className:`grid gap-1.5`,children:(p.data??[]).map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 rounded-lg border border-[var(--border)] px-3 py-2 text-[12px]`,children:[(0,Q.jsx)(x,{tone:y(e.status),children:a(`tokens.invite.status.${e.status}`)}),(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:e.status===`used`?a(`tokens.invite.usedAt`,{time:r(e.usedAt,o),ip:e.usedIp??`—`}):a(`tokens.invite.expires`,{time:r(e.expiresAt,o)})}),e.status===`pending`&&(0,Q.jsx)(E,{size:`sm`,variant:`plain`,className:`ml-auto`,loading:h.isPending&&h.variables===e.id,onClick:()=>h.mutate(e.id,{onError:e=>s(P(e),`error`)}),children:a(`tokens.invite.revoke`)})]},e.id))})]})]})})}function _e(){let{t:e}=g(),t=c(),n=k(),r=o(),i=r.data?.state===`connected`?r.data.publicUrl:null,[a,s]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null);return(0,Q.jsxs)(W,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Q.jsx)(E,{variant:`primary`,icon:(0,Q.jsx)(B,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Q.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Q.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),i&&(0,Q.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${i}/v1`,key:`${i}/key`})})]}),t.isLoading&&(0,Q.jsx)(j,{lines:4}),t.isError&&(0,Q.jsx)(O,{tone:`danger`,title:e(`common.error`),children:P(t.error)}),t.data?.length===0&&(0,Q.jsx)(`div`,{className:`card`,children:(0,Q.jsx)(h,{icon:(0,Q.jsx)(H,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Q.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Q.jsx)(ve,{token:e,defaultOpen:t.data.length===1,onEdit:()=>u(e)},e.id))})]}),(0,Q.jsx)(Ce,{open:a,onOpenChange:s}),(0,Q.jsx)(we,{token:l,onClose:()=>u(null)})]})}function ve({token:n,defaultOpen:a,onEdit:o}){let{t:c,locale:u}=g(),{toast:f,confirm:m}=L(),h=t(),_=k(),y=l(),b=ee(),S=e(),C=p(),[w,T]=(0,Z.useState)(a),O=(h.data??[]).find(e=>e.id===n.providerId),A=ue(),j=`token-detail-${n.id}`,M=(e,t)=>{f(t,`success`),e.skipped.length>0&&f(c(`tokens.skipped`,{clients:e.skipped.map(e=>U[e]?.name??e).join(`, `)}),`error`)},N=()=>y.mutate(n.id,{onSuccess:async({token:e})=>{await F.copy(e)?f(c(`tokens.copied`)):f(c(`tokens.copyFailed`),`error`)},onError:e=>f(P(e),`error`)}),[I,R]=(0,Z.useState)(!1),B=async()=>{let e=_.data?.gatewayBaseUrl;e&&(await F.copy(`${e}/v1`)?f(c(`tokens.urlCopied`)):f(c(`tokens.copyFailed`),`error`))},H=async()=>{let e=_.data?.gatewayBaseUrl;e&&(await F.copy(`npx @aidotnet/astra-connect join ${e}`)?f(c(`tokens.joinCopied`)):f(c(`tokens.copyFailed`),`error`))},W=async()=>{(!n.enabled||await m({title:c(`tokens.disableConfirm`,{name:n.name}),detail:c(`tokens.disableDetail`),confirmLabel:c(`tokens.disable`),destructive:!0}))&&b.mutate({id:n.id,enabled:!n.enabled},{onError:e=>f(P(e),`error`)})},G=async()=>{await m({title:c(`tokens.resetConfirm`,{name:n.name}),detail:c(`tokens.resetDetail`),confirmLabel:c(`tokens.reset`),destructive:!0})&&S.mutate(n.id,{onSuccess:e=>M(e,c(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>f(P(e),`error`)})},q=async()=>{await m({title:c(`tokens.deleteConfirm`,{name:n.name}),detail:c(`tokens.deleteDetail`),confirmLabel:c(`common.delete`),destructive:!0})&&C.mutate(n.id,{onSuccess:e=>M(e,c(`tokens.deleted`,{name:n.name})),onError:e=>f(P(e),`error`)})},Y=n.lastUsedAt?r(n.lastUsedAt,u):c(`tokens.neverUsed`);return(0,Q.jsxs)(`article`,{children:[(0,Q.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:()=>T(e=>!e),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":w,"aria-controls":j,"aria-label":c(`tokens.details`),onClick:e=>{e.stopPropagation(),T(e=>!e)},children:(0,Q.jsx)(ce,{className:`size-4 transition-transform ${w?`rotate-90`:``}`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${n.enabled?``:`text-[var(--text-muted)]`}`,children:n.name}),n.isDefault&&(0,Q.jsx)(x,{tone:`accent`,children:c(`tokens.default`)}),!n.enabled&&(0,Q.jsx)(x,{tone:`orange`,children:c(`tokens.disabledBadge`)}),n.limitUsage.some(e=>e.exhausted)&&(0,Q.jsx)(x,{tone:`orange`,children:c(`tokens.limitExhausted`)}),n.pool&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:n.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Q.jsx)(x,{children:c(`tokens.pool.summary`,{count:n.pool.members.length,strategy:c(`tokens.strategy.${n.pool.strategy}`)})}),n.pool.members.map(e=>(0,Q.jsx)(D,{tone:J(e.health.state)},e.providerId))]})]}),(0,Q.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:n.keyMasked}),(0,Q.jsx)(E,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(v,{className:`size-3.5`}),"aria-label":c(`tokens.copy`),title:c(`tokens.copy`),loading:y.isPending,onClick:N}),(0,Q.jsx)(E,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(fe,{className:`size-3.5`}),"aria-label":c(`tokens.copyUrl`),title:c(`tokens.copyUrl`),disabled:!_.data,onClick:()=>void B()}),(0,Q.jsx)(E,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(se,{className:`size-3.5`}),"aria-label":c(`tokens.copyJoin`),title:c(`tokens.copyJoin`),disabled:!_.data,onClick:()=>void H()}),(0,Q.jsx)(E,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(me,{className:`size-3.5`}),"aria-label":c(`tokens.invite.open`),title:c(`tokens.invite.open`),disabled:!n.enabled,onClick:()=>R(!0)}),(0,Q.jsx)(ge,{token:n,open:I,onOpenChange:R})]})]})]}),(0,Q.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:n.clients.map(e=>U[e]?.name??e).join(`, `)||c(`tokens.noClients`),children:n.clients.length===0?(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):n.clients.map(e=>(0,Q.jsx)(K,{kind:e,size:16},e))}),(0,Q.jsx)($,{label:c(`tokens.today`),value:s(n.today.costUsd),context:c(`tokens.requestsContext`,{count:d(n.today.requests)})}),(0,Q.jsx)($,{label:c(`tokens.total`),value:s(n.total.costUsd),context:`${d(n.total.totalTokens,!0)} Token`}),(0,Q.jsx)($,{label:c(`tokens.lastUsedTitle`),value:n.lastUsedAt?i(n.lastUsedAt,u):`—`,context:n.lastUsedAt?``:c(`tokens.neverUsed`),title:Y}),(0,Q.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(te,{label:c(`common.more`),icon:(0,Q.jsx)(re,{className:`size-4`}),items:[{id:`settings`,label:c(`tokens.settings`),icon:(0,Q.jsx)(ie,{className:`size-3.5`}),onSelect:o},{id:`toggle`,label:n.enabled?c(`tokens.disable`):c(`tokens.enable`),icon:(0,Q.jsx)(ae,{className:`size-3.5`}),onSelect:()=>void W()},{id:`reset`,label:c(`tokens.reset`),icon:(0,Q.jsx)(oe,{className:`size-3.5`}),onSelect:()=>void G()},...n.isDefault?[]:[{id:`delete`,label:c(`tokens.delete`),icon:(0,Q.jsx)(V,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),w&&(0,Q.jsxs)(`div`,{id:j,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Q.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.clients`)}),(0,Q.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?c(`tokens.noClients`):n.clients.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Q.jsx)(K,{kind:e,size:14}),U[e]?.name??e]},e))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:n.pool?c(`tokens.pool.title`):c(`tokens.directProvider`)}),n.pool?(0,Q.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:n.pool.members.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:A(e.health),children:[(0,Q.jsx)(D,{tone:J(e.health.state)}),(h.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:O?.name??(n.providerId?n.providerId:c(`tokens.directNone`))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.allowedClients`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:n.allowedClients==null?c(`tokens.allowedClientsAny`):n.allowedClients.length===0?c(`tokens.directOnly`):n.allowedClients.map(e=>U[e]?.name??e).join(`, `)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.lastUsedTitle`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:Y})]})]}),(0,Q.jsx)(ye,{token:n}),(0,Q.jsx)(xe,{today:n.today,total:n.total}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Q.jsx)(z,{to:`/tokens/${encodeURIComponent(n.id)}`,children:(0,Q.jsx)(E,{size:`sm`,icon:(0,Q.jsx)(ne,{className:`size-3.5`}),children:c(`tokens.detail.open`)})}),(0,Q.jsx)(z,{to:`/requests?token=${encodeURIComponent(n.id)}`,children:(0,Q.jsx)(E,{size:`sm`,icon:(0,Q.jsx)(le,{className:`size-3.5`}),children:c(`tokens.detail.viewLogs`)})})]})]})]})}function ye({token:e}){let{t}=g(),n=e.limits?.rpm;return(0,Q.jsxs)(`div`,{className:`mt-3`,children:[(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Q.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Q.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Q.jsx)(be,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Q.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Q.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function be({usage:e}){let{t,locale:n}=g(),i=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,a=t=>e.metric===`cost`?s(t):d(t,!0),o=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=o>=90?`var(--danger)`:o>=70?`var(--warning)`:`var(--accent)`;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Q.jsx)(`span`,{className:`num`,children:t(`tokens.limitUsed`,{used:a(e.used),limit:a(e.limit)})})]}),(0,Q.jsx)(`div`,{role:`progressbar`,"aria-valuenow":o,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${o}%`,background:c}})}),e.resetsAt&&(0,Q.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:t(`tokens.limitResets`,{time:r(e.resetsAt,n)})})]})}function $({label:e,value:t,context:n,title:r}){return(0,Q.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Q.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function xe({today:e,total:t}){let{t:n}=g(),r=[[n(`tokens.today`),e],[n(`tokens.total`),t]],i=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,a=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,Q.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Q.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Q.jsx)(`th`,{className:`${i} text-left`}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Q.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Q.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Q.jsx)(`td`,{className:`${a} font-semibold selectable`,children:s(t.costUsd)}),(0,Q.jsx)(`td`,{className:a,children:d(t.requests)}),(0,Q.jsx)(`td`,{className:a,children:d(t.totalTokens,!0)}),(0,Q.jsxs)(`td`,{className:`${a} text-[var(--text-secondary)]`,children:[d(t.inputTokens,!0),` / `,d(t.outputTokens,!0)]}),(0,Q.jsx)(`td`,{className:a,title:n(`usage.cacheAmounts`,{read:d(t.cacheReadTokens,!0),write:d(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:T(t.cacheHitRate)}),(0,Q.jsx)(`td`,{className:a,children:t.tps==null?`—`:u(t.tps)})]},e))})]})})}function Se(){let{t:e}=g(),n=(t().data??[]).filter(e=>e.enabled);return{providers:n,options:[{value:``,label:e(`tokens.directNone`)},...n.map(e=>({value:e.id,label:e.name}))]}}function Ce({open:e,onOpenChange:t}){let{t:n}=g(),{toast:r}=L(),i=m(),{options:a}=Se(),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Q.jsx)(I,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(E,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Q.jsx)(E,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(P(e),`error`)}),children:n(`common.create`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(y,{label:n(`tokens.name`),children:(0,Q.jsx)(_,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Q.jsx)(y,{label:n(`tokens.directProvider`),children:(0,Q.jsx)(R,{value:c,onChange:l,options:a})})]})})}function we({token:e,onClose:n}){let{t:r}=g(),{toast:i}=L(),o=ee(),s=t(),c=a(),[l,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)([]),[m,h]=(0,Z.useState)(null),[v,b]=(0,Z.useState)([]),[x,S]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(`any`),[D,O]=(0,Z.useState)([]),k=new Set(v.map(e=>`${e.metric}:${e.period}`)).size<v.length,A=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,Z.useEffect)(()=>{e&&(u(e.name),h(Y(e)),b(e.limits?.budgets.map(e=>({...e}))??[]),S(e.limits?.rpm??null),T(e.allowedClients==null?`any`:`only`),O(e.allowedClients??[]),p(e.mcpServers??[]))},[e]),(0,Q.jsx)(I,{open:e!==null,onOpenChange:e=>!e&&n(),title:r(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(E,{onClick:n,children:r(`common.cancel`)}),(0,Q.jsx)(E,{variant:`primary`,disabled:!l.trim()||k,loading:o.isPending,onClick:()=>{if(!e)return;let t=v.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),a=t.length>0||x!=null&&x>0?{budgets:t,rpm:x!=null&&x>0?Math.floor(x):null}:null;o.mutate({id:e.id,name:l.trim(),...m?{pool:q(m,s.data??[])}:{},limits:a,allowedClients:w===`any`?null:D,...c.data?{mcpServers:d.filter(e=>c.data.some(t=>t.id===e))}:{}},{onSuccess:()=>{n(),i(r(`common.saved`),`success`)},onError:e=>i(P(e),`error`)})},children:r(`common.save`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(y,{label:r(`tokens.name`),children:(0,Q.jsx)(_,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,Q.jsx)(y,{label:r(`tokens.pool.title`),hint:r(`tokens.pool.hint`),children:m&&(0,Q.jsx)(de,{draft:m,onChange:h,providers:s.data??[],health:A})}),(0,Q.jsx)(y,{label:r(`tokens.limits`),hint:r(`tokens.limitsHint`),error:k?r(`tokens.limitDuplicate`):void 0,children:(0,Q.jsx)(De,{budgets:v,onChange:b})}),(0,Q.jsx)(y,{label:r(`tokens.rpm`),hint:r(`tokens.rpmHint`),children:(0,Q.jsx)(C,{value:x,min:1,step:1,label:r(`tokens.rpm`),placeholder:r(`tokens.unlimited`),onChange:S})}),(0,Q.jsx)(y,{label:r(`tokens.mcp`),hint:c.data&&c.data.length===0?r(`tokens.mcpNone`):r(`tokens.mcpHint`),children:c.data&&c.data.length>0&&(0,Q.jsx)(G,{label:r(`tokens.mcp`),options:c.data.map(e=>({value:e.id,label:e.name})),value:d.filter(e=>c.data.some(t=>t.id===e)),onValueChange:e=>p(e)})}),(0,Q.jsx)(y,{label:r(`tokens.allowedClients`),hint:r(`tokens.allowedClientsHint`),children:(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(f,{ariaLabel:r(`tokens.allowedClients`),value:w,onChange:T,items:[{value:`any`,label:r(`tokens.allowedClientsAny`)},{value:`only`,label:r(`tokens.allowedClientsOnly`)}]}),w===`only`&&(0,Q.jsx)(G,{label:r(`tokens.allowedClients`),options:[...new Set([...Object.keys(U),...D])].map(e=>({value:e,label:U[e]?.name??e})),value:D,onValueChange:e=>O(e)})]})})]})})}var Te=[`cost`,`requests`,`tokens`],Ee=[`day`,`week`,`month`,`total`];function De({budgets:e,onChange:t}){let{t:n}=g(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=Te.flatMap(e=>Ee.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Q.jsx)(R,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:Te.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Q.jsx)(R,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:Ee.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Q.jsx)(C,{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,Q.jsx)(E,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(V,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,Q.jsx)(`div`,{children:(0,Q.jsx)(E,{size:`sm`,icon:(0,Q.jsx)(B,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{_e as TokensPage};
|