@aidotnet/server-darwin-arm64 0.13.4 → 0.13.5
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-Tjb-Lk3j.js → ClientsPage-gRSh7_CV.js} +2 -2
- package/bin/wwwroot/assets/{KeyPage-Xj9r3Djk.js → KeyPage-D77qfw6X.js} +1 -1
- package/bin/wwwroot/assets/{ModelDetailPage-BanXH5PK.js → ModelDetailPage-9WGV08Ir.js} +1 -1
- package/bin/wwwroot/assets/{ModelsPage-E0tSsPts.js → ModelsPage-ONDK3J08.js} +1 -1
- package/bin/wwwroot/assets/{PluginsPage-CnstItW6.js → PluginsPage-nSzZ0q9J.js} +1 -1
- package/bin/wwwroot/assets/{PrivacyPage-CbBRFTMf.js → PrivacyPage-L2K6y0cS.js} +1 -1
- package/bin/wwwroot/assets/{ProviderDetailPage-AUDqLapy.js → ProviderDetailPage-Cb_AXwQV.js} +1 -1
- package/bin/wwwroot/assets/{ProvidersPage-DuVAa-Hz.js → ProvidersPage-D4CaD0A4.js} +1 -1
- package/bin/wwwroot/assets/{SettingsPage-a3uBRMV_.js → SettingsPage-DxaHksJO.js} +2 -2
- package/bin/wwwroot/assets/{SmartRoutingPage-DC5sD0bZ.js → SmartRoutingPage-CAcrEtoz.js} +1 -1
- package/bin/wwwroot/assets/{TokenDetailPage-D1ryElHF.js → TokenDetailPage-DQjS2Rfd.js} +1 -1
- package/bin/wwwroot/assets/{TokenPoolEditor-BhM2cgiC.js → TokenPoolEditor-B_Z5aPHq.js} +1 -1
- package/bin/wwwroot/assets/{TokensPage-Cp0oynev.js → TokensPage-DI5GW9jT.js} +1 -1
- package/bin/wwwroot/assets/{TracesPage-CuMO5elT.js → TracesPage-BLhnQx6x.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelPage-CwzGid44.js → TrayPanelPage-BVygPKsx.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelView-C5_GEcGF.js → TrayPanelView-CxRkRjNA.js} +1 -1
- package/bin/wwwroot/assets/{alert-VkCgBSEU.js → alert-BF0mCqUl.js} +3 -3
- package/bin/wwwroot/assets/{arrow-down-Bm13_VSy.js → arrow-down-DZLYQSjE.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-BpFef649.js → arrow-left-D_GXSlab.js} +1 -1
- package/bin/wwwroot/assets/{arrow-up-right-Dt19ixmG.js → arrow-up-right-6yJy6Xdl.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-YjWCwufO.js → checkbox-j5bCl2a6.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-0kOOrGs0.js → cloud-download-D02pcV_l.js} +1 -1
- package/bin/wwwroot/assets/{confirm-morph-Cxhcg5Af.js → confirm-morph-DanmNnVF.js} +1 -1
- package/bin/wwwroot/assets/{download-CVhnkMFM.js → download-DDp7Ezie.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-Cw0JIn8h.js → ellipsis-D10W7mYw.js} +1 -1
- package/bin/wwwroot/assets/{external-link-CoA1OFOi.js → external-link-DTLyxO14.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-vyiFD3ST.js → folder-open-VpvxiCWo.js} +1 -1
- package/bin/wwwroot/assets/{index-D2dNv2tH.js → index-CN0EAD0q.js} +3 -3
- package/bin/wwwroot/assets/{log-out-CfwP3cML.js → log-out-DOsFUSwe.js} +1 -1
- package/bin/wwwroot/assets/minus-CFFJg-m8.js +1 -0
- package/bin/wwwroot/assets/{overlays-DiAM_uxj.js → overlays-OPtjc9Yr.js} +1 -1
- package/bin/wwwroot/assets/{pencil-DhqvwNLm.js → pencil-Zf5QNEUX.js} +1 -1
- package/bin/wwwroot/assets/{power-CvCs4uOV.js → power-B2lC52A0.js} +1 -1
- package/bin/wwwroot/assets/{radio-cards-CiZ_t5iI.js → radio-cards-DAFCv1Xc.js} +1 -1
- package/bin/wwwroot/assets/{rotate-ccw-Ckutyipl.js → rotate-ccw-DwTwYkU2.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-DegG4iIY.js → sortable.esm-Btakc5-n.js} +1 -1
- package/bin/wwwroot/index.html +3 -3
- package/package.json +1 -1
- package/bin/wwwroot/assets/minus-C0K0VMJh.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Ai as e,An as t,Ar as n,Bt as r,Cr as i,E as a,Ei as o,En as s,Et as c,Fa as l,Fi as u,Ft as d,H as f,Hi as p,Ii as m,It as h,Ki as g,Lt as _,Mi as v,Na as y,Oi as b,Pa as x,Pi as S,Pr as C,Qr as w,Qt as ee,Ra as te,Si as T,Ti as ne,Ui as E,Vi as D,W as re,Wi as ie,Wt as O,Xr as ae,_ as oe,ci as se,ct as k,d as A,dn as ce,ei as le,gi as ue,gt as j,ht as de,i as fe,kr as pe,l as M,li as me,lr as he,m as N,n as P,nn as ge,o as _e,or as ve,p as F,r as I,rn as ye,s as be,si as xe,t as Se,u as L,un as Ce,v as R,vi as we,wi as z,xi as Te,xt as B,y as V,zt as H}from"./alert-
|
|
2
|
-
`)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(Se,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(t.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=k(),{toast:r,confirm:i}=K(),a=w(),o=H(),s=xt(e,t),c=async e=>{await W.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!Ct()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;wt()}(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(U(e),`error`)})},u=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,d=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,p=e.state===`connected`&&d!==null?d<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:re(d,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),m=e.cloudflared,h=m.downloading||m.path?null:m.asset?t(`settings.remote.cloudflaredMissing`,{version:m.version??``}):t(`settings.remote.cloudflaredUnsupported`),g=e.enabled?e.error??m.error??null:null,_=g!==null&&(e.state!==`connected`||/origin service|origin server/i.test(g)),v=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?f(e.connectedAt,n):void 0,children:[(0,X.jsx)(be,{tone:u}),p,m.downloading&&m.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(m.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),!e.enabled&&!s&&h&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:h}),e.enabled&&v&&(0,X.jsxs)(N,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${v}/v1`}),children:[(0,X.jsx)(G,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(j,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void c(`${v}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(v)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${v}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(v,`_blank`,`noopener`)})]}),e.enabled&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),_&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Se,{tone:e.state===`connected`?`warning`:`danger`,title:St(g,e,t),children:g})})]})}function Dt({s:e}){let{t}=k(),{toast:n,confirm:r}=K(),i=Te(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await W.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(U(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(U(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(N,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(oe,{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)(Se,{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)(A,{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)(A,{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)(I,{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)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=k(),{toast:n,confirm:r}=K(),i=Te(),a=H(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(U(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(P,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(N,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=k(),{toast:n}=K(),r=H(),i=pe(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(A,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(U(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=k(),{toast:n}=K(),r=Te(),i=ce(),a=H(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[p,m]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>m(e.download.downloadSource),[e.download.downloadSource]);let h=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(U(e),`error`)}),g=t=>{m(t),(t!==`custom`||e.download.downloadBaseUrl)&&h({downloadSource:t})},_=()=>i.mutate(void 0,{onSuccess:e=>e.path?f(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(U(e),`error`)}),v=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:v}),children:(0,X.jsx)(be,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${p}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:p,onChange:g,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),p===`custom`&&(0,X.jsxs)(N,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(A,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>h({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(N,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>h({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{u(!0),_()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(A,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:d,onChange:e=>f(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:_,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!d.trim(),loading:r.isPending,onClick:()=>h({cloudflaredPath:d.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=y(),i=s(),a=H(),o=me(),[c,l]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=i.data;if(!p)return(0,X.jsx)(N,{label:e(`settings.listen`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let m=`${p.host}:${p.port}`,h=Pt(p.configuredHost),g=p.configuredHost!==p.host,_=!!a.data?.required,v=async n=>{await W.copy(n)&&t(e(`common.copied`))},b=n=>o.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(U(e),`error`)}),x=async t=>{if(t!==h){if(t===`lan`){if(!p.passwordSet){l(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}b(t)}},S=async()=>{f(!0);let n=await W.restartService();if(f(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},C=p.hostFromEnvironment?e(`settings.listen.env`,{address:m}):_?e(`settings.listen.localOnly`,{address:m}):g?`${e(`settings.listen.pending`,{host:p.configuredHost})}${u?``:` · ${e(`settings.listen.restartHint`)}`}`:m;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.listen`),detail:C,children:!p.hostFromEnvironment&&!_&&(0,X.jsxs)(X.Fragment,{children:[g&&u&&(0,X.jsx)(I,{size:`sm`,loading:d,onClick:()=>void S(),children:e(`settings.listen.restart`)}),(0,X.jsx)(oe,{ariaLabel:e(`settings.listen`),value:h,onChange:e=>void x(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),p.networkUrls.map(t=>(0,X.jsx)(N,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void v(`${t}/v1`)})},t)),(h===`lan`||p.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:p.passwordSet}),(0,X.jsx)(It,{open:c,onOpenChange:l,onSaved:()=>b(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=k(),{toast:i}=K(),a=pe(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(U(e),`error`)})};return(0,X.jsx)(je,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(A,{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)(A,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Lt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Rt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},zt=e=>e===`feishu`||e===`dingtalk`,Bt=(e,t)=>e(`alerts.event.${t}`),Vt=(e,t)=>e(`alerts.event.${t}.hint`);function Ht(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Ut,{}),(0,X.jsx)(Wt,{}),(0,X.jsx)(Yt,{})]})}function Ut(){let{t:e,locale:t}=k(),n=_(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),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)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${f(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=o(),a=Ce(),s=ae(),c=i(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),h=n=>s.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(U(e),`error`)}),g=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&c.mutate(r.id,{onSuccess:e=>m(e.secret??null),onError:e=>t(U(e),`error`)})},_=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&a.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(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)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(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`||zt(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)(I,{size:`sm`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),loading:s.isPending&&s.variables===t.id,onClick:()=>h(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>f(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onSelect:()=>void g(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void _(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>u(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:l,onClose:()=>u(null),onSecret:m}),(0,X.jsx)(qt,{hook:d,onClose:()=>f(null)}),(0,X.jsx)(Kt,{secret:p,onClose:()=>m(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=k(),{toast:i}=K(),a=ge(),o=T(),[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)([]),ee=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),v(!t||t.hasSecret),b(t?.format??`generic`),S(``),w((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(ee?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(U(e),`error`)},m=!ee&&e!==null&&e.format!==y,g=zt(y)?_?x.trim()||void 0:``:void 0;ee?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)(A,{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)(q,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(A,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(M,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(A,{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)(F,{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)(A,{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)(A,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(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)(I,{size:`sm`,icon:(0,X.jsx)(it,{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)(V,{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)(V,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?ee||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(N,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=k(),{toast:r}=K();return(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await W.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=k(),{toast:i}=K(),a=ne(e?.id),o=he(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(P,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Bt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:f(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:f(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(fe,{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)(fe,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(U(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(t){let n=ve(),r=le(),i=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),a=J({queries:i.map(n=>({queryKey:c.providerAccounts(n.id),queryFn:()=>b(`GET`,`/api/providers/${e(n.id)}/accounts`),enabled:t===`account`}))});return t===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):t===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):t===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Yt(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=h(),i=o(),a=se(),s=ye(),[c,l]=(0,Y.useState)(null),u=e=>i.data?.find(t=>t.id===e)?.name??e,d=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&s.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(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)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(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:`${Bt(e,n.event)} → ${n.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(U(e),`error`)})}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(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)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Zt,{rule:c,onClose:()=>l(null)})]})}function Xt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Zt({rule:e,onClose:t}){let{t:n}=k(),{toast:r}=K(),i=d(),a=o(),s=ee(),c=se(),[l,u]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[w,te]=(0,Y.useState)(null),[T,ne]=(0,Y.useState)(60),E=i.data?.find(e=>e.id===f),D=Jt(E?.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??``),p(t?.event??n?.id??``),h(t?{...Xt(i.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(a.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),te(t?.repeatMinutes??null),ne(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(je,{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)(I,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!l.trim()||!f,loading:s.isPending||c.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:f,condition:i,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:S,repeatMinutes:w&&w>0?Math.floor(w):null,cooldownMinutes:Math.max(0,Math.floor(T??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(U(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)(A,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(M,{label:n(`alerts.rules.event`),hint:f?Vt(n,f):void 0,children:(0,X.jsx)(q,{ariaLabel:n(`alerts.rules.event`),value:f,onChange:e=>{p(e),h(Xt(i.data?.find(t=>t.id===e))),y([])},options:(i.data??[]).map(e=>({value:e.id,label:Bt(n,e.id)}))})}),E?.params.map(e=>(0,X.jsx)(M,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(F,{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)(q,{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)(A,{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)),E&&(0,X.jsx)(M,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${E.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(oe,{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:(a.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:(a.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)(F,{value:w,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:te})}),(0,X.jsx)(M,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(F,{value:T,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:ne})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(N,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:S,label:n(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function Qt(){let{t:e}=k(),t=r(),n=S()?.loginItem,i=t.data?.mechanism===`launchd`||!!n&&m;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:i?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=k(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(N,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(U(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=k(),{toast:t}=K(),i=r(),a=n(),o=i.data;if(!o)return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let s=!o.supported||o.mechanism===`none`?e(`settings.startup.unsupported.${o.unsupported??`platform`}`):o.canChange?o.enabled&&o.location?e(`settings.startup.entry`,{location:o.location}):e(`settings.startup.service.${o.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:s,children:o.supported&&(0,X.jsx)(V,{checked:o.enabled,disabled:!o.canChange||a.isPending,label:e(`settings.startup.service`),onChange:n=>a.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(U(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=a,nn=[...a.ease.enter],rn=[...a.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=et(e,e=>`${n(e)*1.05}em`),i=et(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=et(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=et(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(D.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function Dn({digit:e,direction:t,instant:n}){let r=E(),i=ie(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):p(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`}),an.map(e=>(0,X.jsx)(En,{position:i,digit:e},e))]})}function On({value:e,format:t,direction:n,instant:r}){let i=E(),a=r?Tn:i?wn:Sn;return(0,X.jsx)(g,{initial:!1,custom:n,children:xn(e,t).map(e=>(0,X.jsx)(D.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(Dn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function kn({text:e,direction:t,className:n}){let r=E();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(g,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(D.span,{className:Z.char,custom:t,variants:r?wn:Sn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var An=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},jn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=An(n[t]),i=An(e);return r!==null&&i!==null&&i<r?-1:1})},Mn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:nn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{duration:.14,ease:rn}})},Nn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Pn({word:e,direction:t}){let n=E(),r=(0,Y.useRef)(null),i=ie(`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):p(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(D.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(g,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(D.span,{className:Z.word,custom:t,variants:n?Nn:Mn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Fn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:jn(t.text,e)});let r=t.text===e?t.directions:jn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Pn,{word:e,direction:r[t]??1})]},t))})]})}function In({id:e,text:t,className:n}){return(0,X.jsx)(g,{initial:!1,children:t?(0,X.jsx)(Ln,{id:e,text:t,className:n},`message`):null})}function Ln({id:e,text:t,className:n}){let r=E(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(D.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(D.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${tn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:nn},children:(0,X.jsx)(Fn,{text:t})})})}function Rn({id:e,edge:t,text:n}){let r=E();return(0,X.jsx)(g,{initial:!1,children:t!==0&&(0,X.jsx)(D.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${tn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:rn}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function zn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?it:Ve;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:m=!1,locale:h=`en-US`,formatOptions:g,size:_=`md`,limitHint:v=!0}){let y=E(),b=(0,Y.useId)(),x=u??b,S=c?`${x}-description`:void 0,C=`${x}-limit`,w=o>0?o:1,[ee,te]=(0,Y.useState)(n),T=t??ee,[ne,re]=(0,Y.useState)(``),[O,ae]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(0),[k,A]=(0,Y.useState)(!1),[ce,le]=(0,Y.useState)(``),[ue,j]=(0,Y.useState)(0),[de,fe]=(0,Y.useState)(!1),pe=(0,Y.useRef)(null),M=(0,Y.useRef)(null),me=(0,Y.useRef)(null),he=(0,Y.useRef)(void 0),N=(0,Y.useRef)(void 0),P=(0,Y.useRef)(void 0),ge=(0,Y.useRef)({edge:0,count:0,at:0}),_e=(0,Y.useRef)(null),ve=(0,Y.useRef)(null),F=(0,Y.useRef)(T),I=(0,Y.useRef)(T),ye=(0,Y.useRef)(void 0),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),Se=(0,Y.useRef)(null),L=(0,Y.useRef)(!1),Ce=(0,Y.useRef)(()=>!1),R=ie(0),we=ie(0),z=ie(0),Te=et(()=>we.get()+z.get()),B=Number.isFinite(i)?i:0,V=Math.max(_n(w),_n(B)),H=g?.minimumFractionDigits??V,Ee=Math.max(H,g?.maximumFractionDigits??V),De=g?.useGrouping??!0,Oe=(0,Y.useMemo)(()=>new Intl.NumberFormat(h,{minimumFractionDigits:H,maximumFractionDigits:Ee,useGrouping:De,numberingSystem:`latn`}),[h,H,Ee,De]),ke=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(h).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[h]),Ae=e=>Number(e.toFixed(V))||0,U=e=>Math.min(a,Math.max(i,e)),W=e=>Ae(B+Math.round((e-B)/w)*w),je=(e,t)=>{let n=(e-B)/w;return Ae(B+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*w)},G=e=>`${yn(d,e)}${Oe.format(e)}${yn(f,e)}`.trim();function K(e){let t=e.split(ke.group).join(``).replace(ke.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let q=O?K(ne):null,J=q??T,[Me,Ne]=(0,Y.useState)({value:J,direction:1});Me.value!==J&&Ne({value:J,direction:J>Me.value?1:-1});let Pe=Me.value===J?Me.direction:J>Me.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(ye.current),window.clearTimeout(he.current),window.clearTimeout(N.current),window.clearTimeout(P.current)},[]);function Fe(e,t){let n=performance.now(),r=ge.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let i=pe.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(P.current),P.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!y){p(R,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?me:M).current;n&&(t===`button`||t===`key`)&&p(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}v&&(j(e),window.clearTimeout(he.current),he.current=window.setTimeout(()=>j(0),un))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=U(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),le(`${G(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&le(G(i)),i!==F.current&&(F.current=i,t===void 0&&te(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(je(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=T,Ce.current=Le});function Re(){let e=ve.current;e&&Se.current===null&&(Se.current=e.getBoundingClientRect().left-we.get()-z.get())}(0,Y.useLayoutEffect)(()=>{let e=Se.current,t=ve.current;if(Se.current=null,L.current){L.current=!1;let e=_e.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-we.get()-z.get());Math.abs(n)<.5||(z.set(z.get()+n),y?z.jump(0):p(z,0,Q.morph))});function ze(){window.clearTimeout(N.current),fe(!1)}function Be(){if(!O)return;Re(),ae(!1),ze();let e=K(ne);e!==null&&Ie(W(e),`type`)}function Ve(){window.clearTimeout(ye.current),ye.current=void 0,se(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/w));n===`button`&&se(e);let i=0,a=()=>{let t=Ce.current(e,r,n);ye.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};ye.current=window.setTimeout(a,Le(e,r,n)?sn:360)}function Ue(e){let t=s??w*10,n={ArrowUp:[1,e.shiftKey?t:w],ArrowDown:[-1,e.shiftKey?t:w],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!O&&(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(),O?(L.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&O&&(e.preventDefault(),Re(),ae(!1),ze(),L.current=!0,Ie(I.current,`type`))}function We(e){let t=RegExp(`[^0-9${vn(ke.group)}${V||Ee?vn(ke.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);O||(I.current=T),Re(),re(n),ae(!0);let r=K(n);r!==null&&r>=i&&r<=a&&W(r)===r&&Ie(r,`type`),ze(),r!==null&&r<i&&(N.current=window.setTimeout(()=>fe(!0),dn))}function Ge(e){xe.current=!1,m&&!l&&e.button===0&&(Be(),be.current={pointer:e.pointerId,x:e.clientX,from:F.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=be.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,A(!0)}let r=n/on,o=Math.trunc(r);Ie(o?je(t.from,o):t.from,`scrub`);let s=t.from+r*w,c=s>a?(s-a)/w*on:s<i?(s-i)/w*on:0;we.set(y?0:bn(c))}function qe(e){let t=be.current;t&&t.pointer===e.pointerId&&(be.current=null,t.active&&(xe.current=!0,A(!1),p(we,0,y?{duration:0}:Q.snappy),le(G(F.current))))}let Je=t=>({toward:t,label:e,disabled:l,controls:x,limit:t>0?J>=a:J<=i,pressed:oe===t}),Ye=q===null?0:q>a?1:q<i&&de?-1:0,Xe=v?Ye||ue:0,Ze=Xe>0?a:i,Qe=Xe?typeof v==`function`?v(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${G(Ze)}`:``,$e=[S,Ye&&v?C:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":_,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:x,className:Z.label,"data-scrub":m&&!l||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{xe.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:C,edge:Xe,text:Qe})]}),(0,X.jsxs)(`div`,{ref:pe,className:Z.control,"data-scrubbing":k||void 0,"data-disabled":l||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Je(-1),iconRef:M,onPress:()=>He(-1,w,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==_e.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==_e.current&&(_e.current?.focus(),_e.current?.select())},children:(0,X.jsxs)(D.span,{ref:ve,className:Z.value,style:{x:Te,y:R},children:[(0,X.jsx)(kn,{text:yn(d,J),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":O||void 0,"aria-hidden":`true`,children:(0,X.jsx)(On,{value:J,format:Oe,direction:Pe,instant:O})}),O&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:ne}),(0,X.jsx)(`input`,{ref:_e,id:x,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:V||Ee?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:O?ne:Oe.format(T),disabled:l,"aria-describedby":$e,"aria-invalid":Ye?!0:void 0,"aria-valuenow":T,"aria-valuetext":G(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)(kn,{text:yn(f,J),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Je(1),iconRef:me,onPress:()=>He(1,w,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(In,{id:S,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:ce})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=k(),t=y(),[n,r]=Ae(),i=Me(),a=De(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)(V,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(Ee(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Un,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Re,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:v.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Un,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Vn.map(o)})}),(0,X.jsx)(Un,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>r(Oe),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Ne,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Un({title:e,hint:t,children:n}){let{t:r}=k();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Wn=[`general`,`notifications`,`remote`,`tray`],Gn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Kn(){let{t:e}=k(),{tab:t}=We(),n=Je(),r=ke(),i=Wn.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)(Xe,{"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)(gt,{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)(ct,{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)(de,{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)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(rt,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(rt,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(rt,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(rt,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:e,locale:n,setLocale:r}=k(),i=$e(),a=C(),o=ue(),s=y(),l=z(),d=H(),f=t(),p=xe(),{toast:m,confirm:h}=K(),g=a.data,_=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,v=e=>o.mutate(e,{onError:e=>m(U(e),`error`)}),b=e=>{r(e),v({locale:e})},x=async t=>{await W.copy(t)&&m(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(N,{label:e(`settings.theme`),children:(0,X.jsx)(oe,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(N,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...nt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(N,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(oe,{ariaLabel:e(`settings.language`),value:n,onChange:b,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(N,{label:e(`settings.gatewayUrl`),detail:`${g.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(`${g.gatewayBaseUrl}/v1`)})}),_&&(0,X.jsx)(N,{label:e(`settings.remote.publicUrl`),detail:_,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(_)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(N,{label:e(`settings.dataDir`),detail:g.dataDir,children:W.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void W.openPath(g.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(g.dataDir)})}),(0,X.jsx)(N,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:g.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await h({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&v({requireGatewayKey:t})}})}),(0,X.jsx)(N,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:e(`settings.streamIdle`),value:g.streamIdleTimeoutSec,onCommit:e=>v({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(N,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:g.requestCompression,onChange:e=>v({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(Yn,{settings:g}),(0,X.jsx)(Xn,{settings:g}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(N,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.autoInterval`),value:g.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:c.providers}),onError:e=>m(U(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(N,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.subscriptionInterval`),value:g.subscriptionQuotaIntervalMinutes,onCommit:e=>v({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(N,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:g.usageTimeZone??``,onChange:e=>v({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:g.effectiveUsageTimeZone})},...[...new Set([...Gn,...g.usageTimeZone?[g.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(N,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:g.debugBodies,label:e(`settings.debugBodies`),onChange:e=>v({debugBodies:e})})}),(0,X.jsx)(N,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:e(`settings.bodyRetention`),value:g.bodyRetentionDays,onCommit:e=>v({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(N,{label:e(`settings.requestRetention`),detail:g.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:g.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>v({requestRetentionDays:e?90:null})}),g.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:e(`settings.requestRetention`),value:g.requestRetentionDays,onCommit:e=>v({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(N,{label:e(`settings.traceContent`),children:(0,X.jsx)(V,{checked:g.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>v({traceContent:e})})})}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(N,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Zn,{label:e(`settings.effort.${t}`),value:g.effortBudgets[t],onCommit:e=>v({effortBudgets:{...g.effortBudgets,[t]:e??g.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(a.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(N,{label:e(`settings.serverVersion`),detail:l.data?`${l.data.version} · API ${l.data.apiVersion}`:`—`}),u&&(0,X.jsx)(N,{label:e(`settings.desktopVersion`),detail:S()?.version||`—`}),(0,X.jsx)(Jn,{}),u&&(0,X.jsx)(N,{label:e(`settings.logs`),onClick:()=>void W.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(N,{label:e(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=k(),{toast:t}=K(),n=y(),r=ue(),i=C(),a=we(),o=O(),s=a.data,l=i.data?.updateChannel??s?.channel,u=S()?.updates??null,[d,f]=(0,Y.useState)(!1),p=()=>o.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(U(e),`error`)}),m=()=>{u&&!d&&(f(!0),u.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:c.version}),n.invalidateQueries({queryKey:c.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(U(e),`error`)).finally(()=>f(!1)))},h=s?.lastCheckAt?new Date(s.lastCheckAt).toLocaleString():void 0,g=s?.available?u?e(`settings.updateAvailable`,{version:s.available}):`${e(`settings.updateAvailable`,{version:s.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.autoCheck`),detail:s&&!s.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:s?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(U(e),`error`)})})}),(0,X.jsx)(N,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(V,{checked:l===`preview`,label:e(`settings.previewUpdates`),disabled:!l||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:p,onError:e=>t(U(e),`error`)})})}),(0,X.jsxs)(N,{label:e(`settings.checkUpdates`),detail:o.isError?e(`settings.updateCheckFailed`,{error:U(o.error)}):s?.available?g:h?e(`settings.lastChecked`,{time:h}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:o.isPending,onClick:p,children:o.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Ye,{className:`size-3.5`})}),u&&s?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:d,"aria-label":e(`settings.updateApply`),onClick:m,children:d?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=k(),{toast:n}=K(),r=ue(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(U(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(U(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(N,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(oe,{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)(A,{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)(A,{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)(A,{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)(A,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=k(),{toast:n}=K(),r=ue(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(U(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(A,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Bn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Kn as SettingsPage};
|
|
1
|
+
import{Ai as e,An as t,Ar as n,Bt as r,Cr as i,E as a,Ei as o,En as s,Et as c,Fa as l,Fi as u,Ft as d,H as f,Hi as p,Ii as m,It as h,Ki as g,Lt as _,Mi as v,Na as y,Oi as b,Pa as x,Pi as S,Pr as C,Qr as w,Qt as ee,Ra as te,Si as T,Ti as ne,Ui as E,Vi as D,W as re,Wi as ie,Wt as O,Xr as ae,_ as oe,ci as se,ct as k,d as A,dn as ce,ei as le,gi as ue,gt as j,ht as de,i as fe,kr as pe,l as M,li as me,lr as he,m as N,n as P,nn as ge,o as _e,or as ve,p as F,r as I,rn as ye,s as be,si as xe,t as Se,u as L,un as Ce,v as R,vi as we,wi as z,xi as Te,xt as B,y as V,zt as H}from"./alert-BF0mCqUl.js";import{B as Ee,F as De,I as Oe,L as ke,R as Ae,a as U,gt as W,i as je,n as G,o as K,r as q,vt as J,z as Me}from"./overlays-OPtjc9Yr.js";import{t as Ne}from"./TrayPanelView-CxRkRjNA.js";import{t as Pe}from"./download-DDp7Ezie.js";import{t as Fe}from"./ellipsis-D10W7mYw.js";import{t as Ie}from"./external-link-DTLyxO14.js";import{n as Le,t as Re}from"./radio-cards-DAFCv1Xc.js";import{t as ze}from"./folder-open-VpvxiCWo.js";import{t as Be}from"./log-out-DOsFUSwe.js";import{t as Ve}from"./minus-CFFJg-m8.js";import{t as He}from"./pencil-Zf5QNEUX.js";import{t as Ue}from"./rotate-ccw-DwTwYkU2.js";import{$ as We,C as Ge,E as Ke,N as qe,Q as Je,R as Ye,T as Xe,V as Ze,h as Qe,n as $e,nt as et,s as tt,t as nt,w as rt,z as it}from"./index-CN0EAD0q.js";var at={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};at.node;var ot=B(at),st={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};st.node;var ct=B(st),lt={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};lt.node;var ut=B(lt),dt={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};dt.node;var ft=B(dt),pt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};pt.node;var mt=B(pt),ht={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};ht.node;var gt=B(ht),_t={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};_t.node;var vt=B(_t),Y=te(l(),1),X=x(),yt=`https://astra-gate.si/docs/guide/remote-access`,bt=`astra.remote.acknowledged`;function xt(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function St(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Ct(){try{return localStorage.getItem(bt)===`1`}catch{return!1}}function wt(){try{localStorage.setItem(bt,`1`)}catch{}}function Tt(){let{t:e}=k(),t=xe(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Et,{s:n}),(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(jt,{s:n}),(0,X.jsx)(_e,{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)(Se,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(t.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=k(),{toast:r,confirm:i}=K(),a=w(),o=H(),s=xt(e,t),c=async e=>{await W.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!Ct()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;wt()}(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(U(e),`error`)})},u=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,d=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,p=e.state===`connected`&&d!==null?d<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:re(d,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),m=e.cloudflared,h=m.downloading||m.path?null:m.asset?t(`settings.remote.cloudflaredMissing`,{version:m.version??``}):t(`settings.remote.cloudflaredUnsupported`),g=e.enabled?e.error??m.error??null:null,_=g!==null&&(e.state!==`connected`||/origin service|origin server/i.test(g)),v=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?f(e.connectedAt,n):void 0,children:[(0,X.jsx)(be,{tone:u}),p,m.downloading&&m.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(m.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),!e.enabled&&!s&&h&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:h}),e.enabled&&v&&(0,X.jsxs)(N,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${v}/v1`}),children:[(0,X.jsx)(G,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(j,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void c(`${v}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(v)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${v}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(v,`_blank`,`noopener`)})]}),e.enabled&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),_&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Se,{tone:e.state===`connected`?`warning`:`danger`,title:St(g,e,t),children:g})})]})}function Dt({s:e}){let{t}=k(),{toast:n,confirm:r}=K(),i=Te(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await W.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(U(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(U(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(N,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(oe,{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)(Se,{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)(A,{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)(A,{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)(I,{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)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=k(),{toast:n,confirm:r}=K(),i=Te(),a=H(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(U(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(P,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(N,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=k(),{toast:n}=K(),r=H(),i=pe(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(A,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(U(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=k(),{toast:n}=K(),r=Te(),i=ce(),a=H(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[p,m]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>m(e.download.downloadSource),[e.download.downloadSource]);let h=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(U(e),`error`)}),g=t=>{m(t),(t!==`custom`||e.download.downloadBaseUrl)&&h({downloadSource:t})},_=()=>i.mutate(void 0,{onSuccess:e=>e.path?f(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(U(e),`error`)}),v=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:v}),children:(0,X.jsx)(be,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${p}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:p,onChange:g,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),p===`custom`&&(0,X.jsxs)(N,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(A,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>h({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(N,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>h({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{u(!0),_()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(A,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:d,onChange:e=>f(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:_,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!d.trim(),loading:r.isPending,onClick:()=>h({cloudflaredPath:d.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=y(),i=s(),a=H(),o=me(),[c,l]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=i.data;if(!p)return(0,X.jsx)(N,{label:e(`settings.listen`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let m=`${p.host}:${p.port}`,h=Pt(p.configuredHost),g=p.configuredHost!==p.host,_=!!a.data?.required,v=async n=>{await W.copy(n)&&t(e(`common.copied`))},b=n=>o.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(U(e),`error`)}),x=async t=>{if(t!==h){if(t===`lan`){if(!p.passwordSet){l(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}b(t)}},S=async()=>{f(!0);let n=await W.restartService();if(f(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},C=p.hostFromEnvironment?e(`settings.listen.env`,{address:m}):_?e(`settings.listen.localOnly`,{address:m}):g?`${e(`settings.listen.pending`,{host:p.configuredHost})}${u?``:` · ${e(`settings.listen.restartHint`)}`}`:m;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.listen`),detail:C,children:!p.hostFromEnvironment&&!_&&(0,X.jsxs)(X.Fragment,{children:[g&&u&&(0,X.jsx)(I,{size:`sm`,loading:d,onClick:()=>void S(),children:e(`settings.listen.restart`)}),(0,X.jsx)(oe,{ariaLabel:e(`settings.listen`),value:h,onChange:e=>void x(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),p.networkUrls.map(t=>(0,X.jsx)(N,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void v(`${t}/v1`)})},t)),(h===`lan`||p.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:p.passwordSet}),(0,X.jsx)(It,{open:c,onOpenChange:l,onSaved:()=>b(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=k(),{toast:i}=K(),a=pe(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(U(e),`error`)})};return(0,X.jsx)(je,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(A,{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)(A,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Lt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Rt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},zt=e=>e===`feishu`||e===`dingtalk`,Bt=(e,t)=>e(`alerts.event.${t}`),Vt=(e,t)=>e(`alerts.event.${t}.hint`);function Ht(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Ut,{}),(0,X.jsx)(Wt,{}),(0,X.jsx)(Yt,{})]})}function Ut(){let{t:e,locale:t}=k(),n=_(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),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)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${f(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=o(),a=Ce(),s=ae(),c=i(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),h=n=>s.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(U(e),`error`)}),g=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&c.mutate(r.id,{onSuccess:e=>m(e.secret??null),onError:e=>t(U(e),`error`)})},_=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&a.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(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)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(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`||zt(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)(I,{size:`sm`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),loading:s.isPending&&s.variables===t.id,onClick:()=>h(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>f(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onSelect:()=>void g(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void _(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>u(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:l,onClose:()=>u(null),onSecret:m}),(0,X.jsx)(qt,{hook:d,onClose:()=>f(null)}),(0,X.jsx)(Kt,{secret:p,onClose:()=>m(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=k(),{toast:i}=K(),a=ge(),o=T(),[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)([]),ee=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),v(!t||t.hasSecret),b(t?.format??`generic`),S(``),w((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(ee?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(U(e),`error`)},m=!ee&&e!==null&&e.format!==y,g=zt(y)?_?x.trim()||void 0:``:void 0;ee?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)(A,{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)(q,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(A,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(M,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(A,{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)(F,{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)(A,{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)(A,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(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)(I,{size:`sm`,icon:(0,X.jsx)(it,{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)(V,{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)(V,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?ee||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(N,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=k(),{toast:r}=K();return(0,X.jsx)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await W.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=k(),{toast:i}=K(),a=ne(e?.id),o=he(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(je,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(P,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Bt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:f(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:f(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(fe,{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)(fe,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(U(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(t){let n=ve(),r=le(),i=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),a=J({queries:i.map(n=>({queryKey:c.providerAccounts(n.id),queryFn:()=>b(`GET`,`/api/providers/${e(n.id)}/accounts`),enabled:t===`account`}))});return t===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):t===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):t===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Yt(){let{t:e}=k(),{toast:t,confirm:n}=K(),r=h(),i=o(),a=se(),s=ye(),[c,l]=(0,Y.useState)(null),u=e=>i.data?.find(t=>t.id===e)?.name??e,d=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&s.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(U(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(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)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(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:`${Bt(e,n.event)} → ${n.webhookIds.map(u).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(U(e),`error`)})}),(0,X.jsx)(G,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(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)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Zt,{rule:c,onClose:()=>l(null)})]})}function Xt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Zt({rule:e,onClose:t}){let{t:n}=k(),{toast:r}=K(),i=d(),a=o(),s=ee(),c=se(),[l,u]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[w,te]=(0,Y.useState)(null),[T,ne]=(0,Y.useState)(60),E=i.data?.find(e=>e.id===f),D=Jt(E?.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??``),p(t?.event??n?.id??``),h(t?{...Xt(i.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(a.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),te(t?.repeatMinutes??null),ne(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(je,{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)(I,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!l.trim()||!f,loading:s.isPending||c.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:f,condition:i,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:S,repeatMinutes:w&&w>0?Math.floor(w):null,cooldownMinutes:Math.max(0,Math.floor(T??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(U(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)(A,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(M,{label:n(`alerts.rules.event`),hint:f?Vt(n,f):void 0,children:(0,X.jsx)(q,{ariaLabel:n(`alerts.rules.event`),value:f,onChange:e=>{p(e),h(Xt(i.data?.find(t=>t.id===e))),y([])},options:(i.data??[]).map(e=>({value:e.id,label:Bt(n,e.id)}))})}),E?.params.map(e=>(0,X.jsx)(M,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(F,{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)(q,{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)(A,{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)),E&&(0,X.jsx)(M,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${E.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(oe,{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:(a.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:(a.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)(F,{value:w,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:te})}),(0,X.jsx)(M,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(F,{value:T,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:ne})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(N,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:S,label:n(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function Qt(){let{t:e}=k(),t=r(),n=S()?.loginItem,i=t.data?.mechanism===`launchd`||!!n&&m;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:i?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=k(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(N,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(U(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=k(),{toast:t}=K(),i=r(),a=n(),o=i.data;if(!o)return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:i.isError?U(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let s=!o.supported||o.mechanism===`none`?e(`settings.startup.unsupported.${o.unsupported??`platform`}`):o.canChange?o.enabled&&o.location?e(`settings.startup.entry`,{location:o.location}):e(`settings.startup.service.${o.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:s,children:o.supported&&(0,X.jsx)(V,{checked:o.enabled,disabled:!o.canChange||a.isPending,label:e(`settings.startup.service`),onChange:n=>a.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(U(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=a,nn=[...a.ease.enter],rn=[...a.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=et(e,e=>`${n(e)*1.05}em`),i=et(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=et(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=et(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(D.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function Dn({digit:e,direction:t,instant:n}){let r=E(),i=ie(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):p(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`}),an.map(e=>(0,X.jsx)(En,{position:i,digit:e},e))]})}function On({value:e,format:t,direction:n,instant:r}){let i=E(),a=r?Tn:i?wn:Sn;return(0,X.jsx)(g,{initial:!1,custom:n,children:xn(e,t).map(e=>(0,X.jsx)(D.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(Dn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function kn({text:e,direction:t,className:n}){let r=E();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(g,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(D.span,{className:Z.char,custom:t,variants:r?wn:Sn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var An=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},jn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=An(n[t]),i=An(e);return r!==null&&i!==null&&i<r?-1:1})},Mn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:nn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{duration:.14,ease:rn}})},Nn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Pn({word:e,direction:t}){let n=E(),r=(0,Y.useRef)(null),i=ie(`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):p(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(D.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(g,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(D.span,{className:Z.word,custom:t,variants:n?Nn:Mn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Fn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:jn(t.text,e)});let r=t.text===e?t.directions:jn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Pn,{word:e,direction:r[t]??1})]},t))})]})}function In({id:e,text:t,className:n}){return(0,X.jsx)(g,{initial:!1,children:t?(0,X.jsx)(Ln,{id:e,text:t,className:n},`message`):null})}function Ln({id:e,text:t,className:n}){let r=E(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(D.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(D.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${tn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:nn},children:(0,X.jsx)(Fn,{text:t})})})}function Rn({id:e,edge:t,text:n}){let r=E();return(0,X.jsx)(g,{initial:!1,children:t!==0&&(0,X.jsx)(D.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${tn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:rn}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function zn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?it:Ve;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:m=!1,locale:h=`en-US`,formatOptions:g,size:_=`md`,limitHint:v=!0}){let y=E(),b=(0,Y.useId)(),x=u??b,S=c?`${x}-description`:void 0,C=`${x}-limit`,w=o>0?o:1,[ee,te]=(0,Y.useState)(n),T=t??ee,[ne,re]=(0,Y.useState)(``),[O,ae]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(0),[k,A]=(0,Y.useState)(!1),[ce,le]=(0,Y.useState)(``),[ue,j]=(0,Y.useState)(0),[de,fe]=(0,Y.useState)(!1),pe=(0,Y.useRef)(null),M=(0,Y.useRef)(null),me=(0,Y.useRef)(null),he=(0,Y.useRef)(void 0),N=(0,Y.useRef)(void 0),P=(0,Y.useRef)(void 0),ge=(0,Y.useRef)({edge:0,count:0,at:0}),_e=(0,Y.useRef)(null),ve=(0,Y.useRef)(null),F=(0,Y.useRef)(T),I=(0,Y.useRef)(T),ye=(0,Y.useRef)(void 0),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),Se=(0,Y.useRef)(null),L=(0,Y.useRef)(!1),Ce=(0,Y.useRef)(()=>!1),R=ie(0),we=ie(0),z=ie(0),Te=et(()=>we.get()+z.get()),B=Number.isFinite(i)?i:0,V=Math.max(_n(w),_n(B)),H=g?.minimumFractionDigits??V,Ee=Math.max(H,g?.maximumFractionDigits??V),De=g?.useGrouping??!0,Oe=(0,Y.useMemo)(()=>new Intl.NumberFormat(h,{minimumFractionDigits:H,maximumFractionDigits:Ee,useGrouping:De,numberingSystem:`latn`}),[h,H,Ee,De]),ke=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(h).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[h]),Ae=e=>Number(e.toFixed(V))||0,U=e=>Math.min(a,Math.max(i,e)),W=e=>Ae(B+Math.round((e-B)/w)*w),je=(e,t)=>{let n=(e-B)/w;return Ae(B+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*w)},G=e=>`${yn(d,e)}${Oe.format(e)}${yn(f,e)}`.trim();function K(e){let t=e.split(ke.group).join(``).replace(ke.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let q=O?K(ne):null,J=q??T,[Me,Ne]=(0,Y.useState)({value:J,direction:1});Me.value!==J&&Ne({value:J,direction:J>Me.value?1:-1});let Pe=Me.value===J?Me.direction:J>Me.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(ye.current),window.clearTimeout(he.current),window.clearTimeout(N.current),window.clearTimeout(P.current)},[]);function Fe(e,t){let n=performance.now(),r=ge.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let i=pe.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(P.current),P.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!y){p(R,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?me:M).current;n&&(t===`button`||t===`key`)&&p(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}v&&(j(e),window.clearTimeout(he.current),he.current=window.setTimeout(()=>j(0),un))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=U(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),le(`${G(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&le(G(i)),i!==F.current&&(F.current=i,t===void 0&&te(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(je(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=T,Ce.current=Le});function Re(){let e=ve.current;e&&Se.current===null&&(Se.current=e.getBoundingClientRect().left-we.get()-z.get())}(0,Y.useLayoutEffect)(()=>{let e=Se.current,t=ve.current;if(Se.current=null,L.current){L.current=!1;let e=_e.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-we.get()-z.get());Math.abs(n)<.5||(z.set(z.get()+n),y?z.jump(0):p(z,0,Q.morph))});function ze(){window.clearTimeout(N.current),fe(!1)}function Be(){if(!O)return;Re(),ae(!1),ze();let e=K(ne);e!==null&&Ie(W(e),`type`)}function Ve(){window.clearTimeout(ye.current),ye.current=void 0,se(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/w));n===`button`&&se(e);let i=0,a=()=>{let t=Ce.current(e,r,n);ye.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};ye.current=window.setTimeout(a,Le(e,r,n)?sn:360)}function Ue(e){let t=s??w*10,n={ArrowUp:[1,e.shiftKey?t:w],ArrowDown:[-1,e.shiftKey?t:w],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!O&&(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(),O?(L.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&O&&(e.preventDefault(),Re(),ae(!1),ze(),L.current=!0,Ie(I.current,`type`))}function We(e){let t=RegExp(`[^0-9${vn(ke.group)}${V||Ee?vn(ke.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);O||(I.current=T),Re(),re(n),ae(!0);let r=K(n);r!==null&&r>=i&&r<=a&&W(r)===r&&Ie(r,`type`),ze(),r!==null&&r<i&&(N.current=window.setTimeout(()=>fe(!0),dn))}function Ge(e){xe.current=!1,m&&!l&&e.button===0&&(Be(),be.current={pointer:e.pointerId,x:e.clientX,from:F.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=be.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,A(!0)}let r=n/on,o=Math.trunc(r);Ie(o?je(t.from,o):t.from,`scrub`);let s=t.from+r*w,c=s>a?(s-a)/w*on:s<i?(s-i)/w*on:0;we.set(y?0:bn(c))}function qe(e){let t=be.current;t&&t.pointer===e.pointerId&&(be.current=null,t.active&&(xe.current=!0,A(!1),p(we,0,y?{duration:0}:Q.snappy),le(G(F.current))))}let Je=t=>({toward:t,label:e,disabled:l,controls:x,limit:t>0?J>=a:J<=i,pressed:oe===t}),Ye=q===null?0:q>a?1:q<i&&de?-1:0,Xe=v?Ye||ue:0,Ze=Xe>0?a:i,Qe=Xe?typeof v==`function`?v(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${G(Ze)}`:``,$e=[S,Ye&&v?C:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":_,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:x,className:Z.label,"data-scrub":m&&!l||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{xe.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:C,edge:Xe,text:Qe})]}),(0,X.jsxs)(`div`,{ref:pe,className:Z.control,"data-scrubbing":k||void 0,"data-disabled":l||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Je(-1),iconRef:M,onPress:()=>He(-1,w,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==_e.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==_e.current&&(_e.current?.focus(),_e.current?.select())},children:(0,X.jsxs)(D.span,{ref:ve,className:Z.value,style:{x:Te,y:R},children:[(0,X.jsx)(kn,{text:yn(d,J),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":O||void 0,"aria-hidden":`true`,children:(0,X.jsx)(On,{value:J,format:Oe,direction:Pe,instant:O})}),O&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:ne}),(0,X.jsx)(`input`,{ref:_e,id:x,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:V||Ee?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:O?ne:Oe.format(T),disabled:l,"aria-describedby":$e,"aria-invalid":Ye?!0:void 0,"aria-valuenow":T,"aria-valuetext":G(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)(kn,{text:yn(f,J),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Je(1),iconRef:me,onPress:()=>He(1,w,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(In,{id:S,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:ce})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=k(),t=y(),[n,r]=Ae(),i=Me(),a=De(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)(V,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(Ee(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Un,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Re,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:v.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Un,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Vn.map(o)})}),(0,X.jsx)(Un,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>r(Oe),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Ne,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Un({title:e,hint:t,children:n}){let{t:r}=k();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Wn=[`general`,`notifications`,`remote`,`tray`],Gn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Kn(){let{t:e}=k(),{tab:t}=We(),n=Je(),r=ke(),i=Wn.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)(Xe,{"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)(gt,{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)(ct,{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)(de,{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)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(rt,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(rt,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(rt,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(rt,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:e,locale:n,setLocale:r}=k(),i=$e(),a=C(),o=ue(),s=y(),l=z(),d=H(),f=t(),p=xe(),{toast:m,confirm:h}=K(),g=a.data,_=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,v=e=>o.mutate(e,{onError:e=>m(U(e),`error`)}),b=e=>{r(e),v({locale:e})},x=async t=>{await W.copy(t)&&m(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(N,{label:e(`settings.theme`),children:(0,X.jsx)(oe,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(N,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...nt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(N,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(oe,{ariaLabel:e(`settings.language`),value:n,onChange:b,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(N,{label:e(`settings.gatewayUrl`),detail:`${g.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(`${g.gatewayBaseUrl}/v1`)})}),_&&(0,X.jsx)(N,{label:e(`settings.remote.publicUrl`),detail:_,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(_)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(N,{label:e(`settings.dataDir`),detail:g.dataDir,children:W.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void W.openPath(g.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(j,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void x(g.dataDir)})}),(0,X.jsx)(N,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:g.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await h({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&v({requireGatewayKey:t})}})}),(0,X.jsx)(N,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:e(`settings.streamIdle`),value:g.streamIdleTimeoutSec,onCommit:e=>v({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(N,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:g.requestCompression,onChange:e=>v({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(L,{footer:e(`settings.preventSleepHint`),children:(0,X.jsx)(N,{label:e(`settings.preventSleep`),children:(0,X.jsx)(V,{checked:g.preventSleep??!1,label:e(`settings.preventSleep`),onChange:e=>v({preventSleep:e})})})}),(0,X.jsx)(Yn,{settings:g}),(0,X.jsx)(Xn,{settings:g}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(N,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.autoInterval`),value:g.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:c.providers}),onError:e=>m(U(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(N,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.subscriptionInterval`),value:g.subscriptionQuotaIntervalMinutes,onCommit:e=>v({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(N,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:g.usageTimeZone??``,onChange:e=>v({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:g.effectiveUsageTimeZone})},...[...new Set([...Gn,...g.usageTimeZone?[g.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(N,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:g.debugBodies,label:e(`settings.debugBodies`),onChange:e=>v({debugBodies:e})})}),(0,X.jsx)(N,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:e(`settings.bodyRetention`),value:g.bodyRetentionDays,onCommit:e=>v({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(N,{label:e(`settings.requestRetention`),detail:g.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:g.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>v({requestRetentionDays:e?90:null})}),g.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:e(`settings.requestRetention`),value:g.requestRetentionDays,onCommit:e=>v({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(N,{label:e(`settings.traceContent`),children:(0,X.jsx)(V,{checked:g.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>v({traceContent:e})})})}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(N,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Zn,{label:e(`settings.effort.${t}`),value:g.effortBudgets[t],onCommit:e=>v({effortBudgets:{...g.effortBudgets,[t]:e??g.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:U(a.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(N,{label:e(`settings.serverVersion`),detail:l.data?`${l.data.version} · API ${l.data.apiVersion}`:`—`}),u&&(0,X.jsx)(N,{label:e(`settings.desktopVersion`),detail:S()?.version||`—`}),(0,X.jsx)(Jn,{}),u&&(0,X.jsx)(N,{label:e(`settings.logs`),onClick:()=>void W.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(N,{label:e(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=k(),{toast:t}=K(),n=y(),r=ue(),i=C(),a=we(),o=O(),s=a.data,l=i.data?.updateChannel??s?.channel,u=S()?.updates??null,[d,f]=(0,Y.useState)(!1),p=()=>o.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(U(e),`error`)}),m=()=>{u&&!d&&(f(!0),u.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:c.version}),n.invalidateQueries({queryKey:c.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(U(e),`error`)).finally(()=>f(!1)))},h=s?.lastCheckAt?new Date(s.lastCheckAt).toLocaleString():void 0,g=s?.available?u?e(`settings.updateAvailable`,{version:s.available}):`${e(`settings.updateAvailable`,{version:s.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.autoCheck`),detail:s&&!s.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:s?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(U(e),`error`)})})}),(0,X.jsx)(N,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(V,{checked:l===`preview`,label:e(`settings.previewUpdates`),disabled:!l||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:p,onError:e=>t(U(e),`error`)})})}),(0,X.jsxs)(N,{label:e(`settings.checkUpdates`),detail:o.isError?e(`settings.updateCheckFailed`,{error:U(o.error)}):s?.available?g:h?e(`settings.lastChecked`,{time:h}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:o.isPending,onClick:p,children:o.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Ye,{className:`size-3.5`})}),u&&s?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:d,"aria-label":e(`settings.updateApply`),onClick:m,children:d?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=k(),{toast:n}=K(),r=ue(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(U(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(U(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(N,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(oe,{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)(A,{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)(A,{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)(A,{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)(A,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=k(),{toast:n}=K(),r=ue(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(U(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(A,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Bn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Kn as SettingsPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Di as e,Er as t,Fa as n,Ir as r,J as i,Pa as a,Ra as o,Yr as s,_ as c,_i as l,b as u,ct as d,d as f,gt as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,ut as S,v as C,y as w}from"./alert-VkCgBSEU.js";import{a as T,gt as E,o as D,r as O}from"./overlays-DiAM_uxj.js";import{t as k}from"./arrow-down-Bm13_VSy.js";import{K as A,N as j,S as M,h as N,z as P}from"./index-D2dNv2tH.js";var F=o(n(),1),I=a(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(m,{...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 S))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(t,n,r){if(t instanceof e){let e=t.details?.problems;if(Array.isArray(e)&&e.length>0)return e.map(e=>J(e,n,r))}return[T(t)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in S?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in S?t(n):e??``}function Q(){let{t:e}=d(),t=r();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)(b,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(C,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=d(),{toast:n}=D(),r=l(),[i,a]=(0,F.useState)(()=>W(e)),[o,s]=(0,F.useState)([]),c=e=>a(t=>({...t,...e})),u=JSON.stringify(i)!==JSON.stringify(W(e)),f=G(i),p=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:f,onToggle:e=>p(e),problems:o}),(0,I.jsx)(ne,{saved:e,draft:i,patch:c}),(0,I.jsx)(ie,{draft:i,patch:c}),(0,I.jsx)(ae,{draft:i,patch:c}),!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:[u&&(0,I.jsx)(v,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!u||!f,loading:r.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=d(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(x,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(y,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(p,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`danger`,title:a(`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:e}){let{t,locale:n}=d(),r=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=r.outcomes.judge??0,c=Object.entries(r.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=r.total-s,u=[t(`smartRouting.recent.judged`,{count:s,total:r.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...r.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:r.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:r.total===0?t(`smartRouting.recent.none`):u}),l>=2&&l*2>r.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in S?f:`smartRouting.recent.hint.other`)}),r.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(r.lastFallback,t),time:i(r.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let r=X(e.reason),a={count:e.count,time:i(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(r??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),r&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${r}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=d(),i=H(t.protocol,t.baseUrl),a=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)(x,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`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:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,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:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(f,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(f,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(f,{className:`w-72`,mono:!0,"aria-label":r(`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:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(_,{className:`w-28`,label:r(`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)(b,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(g,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(u,{rows:4,"aria-label":r(`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}=d(),n=s(),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),[c,l]=(0,F.useState)([]),f=()=>{o(null),l([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:o,onError:n=>l(Y(n,e,t))})},p=a!==null&&a.latencyMs>a.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)(u,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>i(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(v,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:f,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(b,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),a&&(a.ok?(0,I.jsx)(b,{tone:a.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:a.gradeName??a.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:a.model?t(`smartRouting.test.model`,{model:a.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((a.confidence??0)*100)}),` ·`,` `,a.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:a.latencyMs,limit:a.limitMs}),a.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:a.latencyMs,input:a.inputTokens,output:a.outputTokens,model:a.judgeModel??``})})]})}):(0,I.jsxs)(b,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(a.failure,t)}),children:[a.message,a.failure===`timeout`&&a.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:n}){let{t:r}=d(),i=t(),a=e.grades,o=(t,r=e.fallbackGrade)=>n({grades:t,fallbackGrade:t.some(e=>e.id===r)?r:t[Math.floor(t.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},l=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],m=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:m.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:m.has(e.id)?void 0:e.providerName})),_=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
|
|
1
|
+
import{Di as e,Er as t,Fa as n,Ir as r,J as i,Pa as a,Ra as o,Yr as s,_ as c,_i as l,b as u,ct as d,d as f,gt as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,ut as S,v as C,y as w}from"./alert-BF0mCqUl.js";import{a as T,gt as E,o as D,r as O}from"./overlays-OPtjc9Yr.js";import{t as k}from"./arrow-down-DZLYQSjE.js";import{K as A,N as j,S as M,h as N,z as P}from"./index-CN0EAD0q.js";var F=o(n(),1),I=a(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(m,{...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 S))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(t,n,r){if(t instanceof e){let e=t.details?.problems;if(Array.isArray(e)&&e.length>0)return e.map(e=>J(e,n,r))}return[T(t)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in S?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in S?t(n):e??``}function Q(){let{t:e}=d(),t=r();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)(b,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(C,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=d(),{toast:n}=D(),r=l(),[i,a]=(0,F.useState)(()=>W(e)),[o,s]=(0,F.useState)([]),c=e=>a(t=>({...t,...e})),u=JSON.stringify(i)!==JSON.stringify(W(e)),f=G(i),p=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:f,onToggle:e=>p(e),problems:o}),(0,I.jsx)(ne,{saved:e,draft:i,patch:c}),(0,I.jsx)(ie,{draft:i,patch:c}),(0,I.jsx)(ae,{draft:i,patch:c}),!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:[u&&(0,I.jsx)(v,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!u||!f,loading:r.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=d(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(x,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(y,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(p,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`danger`,title:a(`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:e}){let{t,locale:n}=d(),r=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=r.outcomes.judge??0,c=Object.entries(r.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=r.total-s,u=[t(`smartRouting.recent.judged`,{count:s,total:r.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...r.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:r.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:r.total===0?t(`smartRouting.recent.none`):u}),l>=2&&l*2>r.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in S?f:`smartRouting.recent.hint.other`)}),r.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(r.lastFallback,t),time:i(r.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let r=X(e.reason),a={count:e.count,time:i(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(r??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),r&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${r}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=d(),i=H(t.protocol,t.baseUrl),a=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)(x,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`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:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,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:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(f,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(f,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(f,{className:`w-72`,mono:!0,"aria-label":r(`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:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(_,{className:`w-28`,label:r(`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)(b,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(g,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(u,{rows:4,"aria-label":r(`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}=d(),n=s(),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),[c,l]=(0,F.useState)([]),f=()=>{o(null),l([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:o,onError:n=>l(Y(n,e,t))})},p=a!==null&&a.latencyMs>a.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)(u,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>i(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(v,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:f,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(b,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),a&&(a.ok?(0,I.jsx)(b,{tone:a.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:a.gradeName??a.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:a.model?t(`smartRouting.test.model`,{model:a.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((a.confidence??0)*100)}),` ·`,` `,a.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:a.latencyMs,limit:a.limitMs}),a.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:a.latencyMs,input:a.inputTokens,output:a.outputTokens,model:a.judgeModel??``})})]})}):(0,I.jsxs)(b,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(a.failure,t)}),children:[a.message,a.failure===`timeout`&&a.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:n}){let{t:r}=d(),i=t(),a=e.grades,o=(t,r=e.fallbackGrade)=>n({grades:t,fallbackGrade:t.some(e=>e.id===r)?r:t[Math.floor(t.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},l=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],m=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:m.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:m.has(e.id)?void 0:e.providerName})),_=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
|
|
2
2
|
`);s(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(x,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[a.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)(f,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>s(n,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,I.jsx)(h,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(A,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>c(n,-1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===a.length-1,onClick:()=>c(n,1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:a.length<=L,onClick:()=>o(a.filter((e,t)=>t!==n))})]}),(0,I.jsx)(u,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>s(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:_(t),onChange:e=>y(n,e)})]},t.id)),i.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)(v,{size:`sm`,icon:(0,I.jsx)(P,{className:`size-3.5`}),disabled:a.length>=R,onClick:l,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=d();return(0,I.jsxs)(x,{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)(c,{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)(_,{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)(_,{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)(_,{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)(_,{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)(g,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(f,{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}=d();return(0,I.jsx)(N,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$r as e,Br as t,Fa as n,G as r,J as i,Pa as a,Q as o,Ra as s,Y as c,Zr as l,_ as u,c as d,ct as f,ir as p,n as m,or as h,q as g,r as _,s as v,t as y,ti as b,v as x,yr as S}from"./alert-
|
|
1
|
+
import{$r as e,Br as t,Fa as n,G as r,J as i,Pa as a,Q as o,Ra as s,Y as c,Zr as l,_ as u,c as d,ct as f,ir as p,n as m,or as h,q as g,r as _,s as v,t as y,ti as b,v as x,yr as S}from"./alert-BF0mCqUl.js";import{a as ee,at as te,it as ne,nt as re,ot as ie,rt as ae}from"./overlays-OPtjc9Yr.js";import{t as C}from"./arrow-left-D_GXSlab.js";import{$ as w,D as T,L as E,O as D,Q as O,X as k,h as A,m as j}from"./index-CN0EAD0q.js";import{a as M,n as N}from"./TokenPoolEditor-B_Z5aPHq.js";var P=s(n(),1),F=a();function I(){let{id:n=``}=w(),{t:a,locale:s}=f(),I=O(),[R,oe]=(0,P.useState)(`7d`),z=e(n),B=h(),V=t(R,void 0,n),H=l(R,R===`today`?`hour`:`day`,`token`,void 0,n),U=b(R,void 0,20,n),W=p(R,n),G=S({token:n,page:1,pageSize:10},!1),K=M(),q=(0,F.jsx)(_,{variant:`glass`,icon:(0,F.jsx)(C,{className:`size-4`}),"aria-label":a(`common.back`),onClick:()=>I(`/tokens`)}),J=a(`range.${R}`),se=(0,P.useMemo)(()=>te(ne(H.data??[],`requests`),ie(R)).map(e=>({key:e.bucket,label:ae(e.bucket),axisLabel:re(e.bucket),value:Math.round(e.value)})),[H.data,R]),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:a(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`share`,label:a(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>g(e)},{key:`success`,label:a(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?g(e):`—`},{key:`ttft`,label:a(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>r(e)},{key:`cost`,label:a(`overview.cost`),sortable:!0,numeric:!0,render:e=>o(e)},{key:`out`,label:a(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:a(`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:a(`tokens.detail.model`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`tokens`,label:a(`overview.tokens`),sortable:!0,numeric:!0,render:e=>c(e,!0)},{key:`cost`,label:a(`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:a(`tokens.detail.time`),render:(e,t)=>i(t.r.startedAtUtc,s)},{key:`model`,label:a(`tokens.detail.model`)},{key:`provider`,label:a(`tokens.detail.provider`)},{key:`status`,label:a(`tokens.detail.status`),render:e=>(0,F.jsx)(m,{tone:e===`success`?`green`:`red`,children:a(`status.${e}`)})},{key:`cost`,label:a(`overview.cost`),numeric:!0,render:e=>o(e)}];if(z.isError)return(0,F.jsx)(A,{title:a(`nav.tokens`),leading:q,children:(0,F.jsx)(y,{tone:`danger`,title:a(`common.error`),children:ee(z.error)})});let Q=z.data,$=V.data;return(0,F.jsx)(A,{title:Q?.name??``,subtitle:Q?(0,F.jsx)(`code`,{className:`font-mono`,children:Q.keyMasked}):void 0,leading:q,actions:(0,F.jsx)(k,{to:`/requests?token=${encodeURIComponent(n)}`,children:(0,F.jsx)(_,{icon:(0,F.jsx)(E,{className:`size-3.5`}),children:a(`tokens.detail.viewLogs`)})}),children:(0,F.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsx)(u,{ariaLabel:a(`overview.range`),value:R,onChange:oe,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:a(`range.${e}`)}))})}),$?(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-5`,children:[(0,F.jsx)(L,{label:a(`overview.totalCost`),value:o($.costUsd),context:J}),(0,F.jsx)(L,{label:a(`overview.totalRequests`),value:c($.requests),context:J}),(0,F.jsx)(L,{label:a(`overview.tokens`),value:c($.inputTokens+$.outputTokens,!0),context:a(`overview.tokensContext`,{input:c($.inputTokens,!0),output:c($.outputTokens,!0)})}),(0,F.jsx)(L,{label:a(`usage.hitRate`),value:g(j($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,F.jsx)(L,{label:a(`overview.successRate`),value:$.requests?g($.successRate):`—`,context:r($.avgTtftMs)})]}):(0,F.jsx)(x,{lines:3}),Q?.pool&&(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`tokens.pool.title`),` · `,a(`tokens.strategy.${Q.pool.strategy}`)]}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-[13px]`,children:Q.pool.members.map(e=>(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(v,{tone:N(e.health.state)}),Y.get(e.providerId)??e.providerId,(0,F.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:K(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,F.jsx)(`div`,{className:`card`,children:(0,F.jsx)(d,{title:a(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:a(`overview.tokenEmpty.detail`,{range:J})})}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,F.jsx)(x,{lines:4}):(0,F.jsx)(D,{data:se,label:a(`overview.requests`),period:J,height:160,formatValue:e=>c(e),averageLabel:a(R===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:a(`overview.total`),categoryLabel:a(R===`today`?`overview.hour`:`overview.day`)})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsx)(`h2`,{className:`mb-1 text-[13px] font-medium`,children:a(`tokens.detail.byProvider`)}),(0,F.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:a(`tokens.detail.byProviderHint`)}),(0,F.jsx)(T,{caption:a(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:a(`common.noData`)})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:a(`tokens.detail.byModel`)}),(0,F.jsx)(T,{caption:a(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:a(`common.noData`)})]})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,F.jsx)(`h2`,{className:`text-[13px] font-medium`,children:a(`tokens.detail.recent`)}),(0,F.jsx)(k,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(n)}`,children:a(`tokens.detail.viewLogs`)})]}),(0,F.jsx)(T,{caption:a(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:a(`common.noData`)})]})]})})}function L({label:e,value:t,context:n}){return(0,F.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,F.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,F.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,F.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{I as TokenDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{J as e,Pa as t,_ as n,ct as r,n as i,nr as a,ot as o,p as s,r as c,y as l}from"./alert-
|
|
1
|
+
import{J as e,Pa as t,_ as n,ct as r,n as i,nr as a,ot as o,p as s,r as c,y as l}from"./alert-BF0mCqUl.js";import{r as u}from"./overlays-OPtjc9Yr.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-Btakc5-n.js";import{N as w,x as T}from"./index-CN0EAD0q.js";var E=t(),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:n}=r();return r=>r.state===`cooling`||r.state===`open`?t(`tokens.health.${r.state}`,{time:r.until?e(r.until,n):`—`}):t(`tokens.health.${r.state}`)}function F({draft:e,onChange:t,providers:i,health:a}){let{t:o}=r(),c=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=n=>t({...e,members:n}),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=c.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)(n,{ariaLabel:o(`tokens.pool.strategy`),value:e.strategy,onChange:n=>t({...e,strategy:n}),items:D.map(e=>({value:e,label:o(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`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:c.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:o(`tokens.pool.add`),placeholder:o(`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:o(`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:o(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`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]}}),c.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:o(`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:o(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:n=>t({...e,sticky:n?`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:o(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.failover`),checked:e.failover,onChange:n=>t({...e,failover:n})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:o(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:n=>t({...e,maxAttempts:n??1})})})]})]})]})}function I({member:e,index:t,draft:n,provider:l,health:d,onChange:f,onRemove:p}){let{t:g}=r(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!l&&M.has(l.authScheme),A=a(l?.id,k),j=l?.name??e.providerId,F=n.members.length>1,I=l?l.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:o(`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`})}),l&&(0,E.jsx)(T,{name:l.name,icon:l.icon,colorKey:l.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&n.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&&(n.strategy===`weighted`||n.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&n.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)(c,{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};
|