@aidotnet/server-win32-x64 0.14.3104 → 0.14.3105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/bin/astra-server.exe +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-COC8lfKF.js +9 -0
  3. package/bin/wwwroot/assets/{KeyPage-ZWeDQdNy.js → KeyPage-usImCI1l.js} +1 -1
  4. package/bin/wwwroot/assets/McpPage-D_uvPjF5.js +9 -0
  5. package/bin/wwwroot/assets/{ModelDetailPage-D5CbTowj.js → ModelDetailPage-CSgyizzq.js} +1 -1
  6. package/bin/wwwroot/assets/{ModelsPage-DliA_aAa.js → ModelsPage-B13qOMuJ.js} +1 -1
  7. package/bin/wwwroot/assets/PluginsPage-BigxbbK6.js +2 -0
  8. package/bin/wwwroot/assets/PrivacyPage-CaUXn9Pj.js +1 -0
  9. package/bin/wwwroot/assets/ProviderDetailPage-bmjEJLMl.js +3 -0
  10. package/bin/wwwroot/assets/ProvidersPage-B1FxC5kV.js +3 -0
  11. package/bin/wwwroot/assets/SettingsPage-DKCf-Kn7.js +2 -0
  12. package/bin/wwwroot/assets/{SkillsPage-DPtnUi1q.js → SkillsPage-DEMkjIab.js} +1 -1
  13. package/bin/wwwroot/assets/SmartRoutingPage-udRjsK4H.js +2 -0
  14. package/bin/wwwroot/assets/{TokenDetailPage-0Wzk4x4v.js → TokenDetailPage-DmvgGiZM.js} +1 -1
  15. package/bin/wwwroot/assets/{TokenPoolEditor-BraT_TLt.js → TokenPoolEditor-thPAci_g.js} +1 -1
  16. package/bin/wwwroot/assets/TokensPage-BN1h_nhM.js +1 -0
  17. package/bin/wwwroot/assets/{TracesPage-Bmt8W71X.js → TracesPage-gKbBBrq3.js} +3 -3
  18. package/bin/wwwroot/assets/{TrayPanelPage-fAVZ51n1.js → TrayPanelPage-Cigljgtp.js} +1 -1
  19. package/bin/wwwroot/assets/{TrayPanelView-BvketT9p.js → TrayPanelView-CN6A6AKW.js} +1 -1
  20. package/bin/wwwroot/assets/TrayTitleSource-Vrhk5544.js +41 -0
  21. package/bin/wwwroot/assets/{checkbox-9uG7tefe.js → checkbox-DGDdtEgb.js} +1 -1
  22. package/bin/wwwroot/assets/confirm-morph-QxrTkHxo.js +1 -0
  23. package/bin/wwwroot/assets/format-xhi4nXQn.js +15 -0
  24. package/bin/wwwroot/assets/index-D74BlcEH.css +1 -0
  25. package/bin/wwwroot/assets/{index-BmgQHUbu.js → index-ug2mwIxe.js} +14 -14
  26. package/bin/wwwroot/assets/{radio-cards-S8R3bqNN.js → radio-cards-C8S87Euv.js} +1 -1
  27. package/bin/wwwroot/assets/{sortable.esm-Cuxc4P7e.js → sortable.esm-CgiwIVTR.js} +1 -1
  28. package/bin/wwwroot/assets/terminal-B-mEYDi0.js +1 -0
  29. package/bin/wwwroot/assets/use-transform-DZtiZX0A.js +1 -0
  30. package/bin/wwwroot/index.html +5 -5
  31. package/package.json +1 -1
  32. package/bin/wwwroot/assets/ClientsPage-liK3VnwH.js +0 -9
  33. package/bin/wwwroot/assets/McpPage-DYGSTB92.js +0 -3
  34. package/bin/wwwroot/assets/PluginsPage-CKbrq_82.js +0 -2
  35. package/bin/wwwroot/assets/PrivacyPage-C1EGVq_7.js +0 -1
  36. package/bin/wwwroot/assets/ProviderDetailPage-CirP5WN_.js +0 -3
  37. package/bin/wwwroot/assets/ProvidersPage-BdBnmpLG.js +0 -3
  38. package/bin/wwwroot/assets/SettingsPage-DoyHuHaN.js +0 -2
  39. package/bin/wwwroot/assets/SmartRoutingPage-BThub05E.js +0 -2
  40. package/bin/wwwroot/assets/TokensPage-DFVf1oRY.js +0 -1
  41. package/bin/wwwroot/assets/TrayTitleSource-CNflSYSn.js +0 -41
  42. package/bin/wwwroot/assets/confirm-morph-BKAgGoFC.js +0 -1
  43. package/bin/wwwroot/assets/format-ox0oJ51_.js +0 -15
  44. package/bin/wwwroot/assets/index-BIs3wfin.css +0 -1
  45. package/bin/wwwroot/assets/terminal-vbY4_lZv.js +0 -1
  46. package/bin/wwwroot/assets/use-transform-971qznsR.js +0 -1
@@ -1,2 +0,0 @@
1
- import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$t as n,A as r,Aa as i,At as a,Bi as o,C as s,D as c,Da as l,Di as u,Dr as d,E as f,Ea as p,Et as m,F as h,Ft as g,Gt as _,H as v,Hr as y,L as b,Ln as x,Mi as S,N as C,Nn as w,O as T,Oa as E,P as D,Qi as O,R as k,Ta as A,Tt as j,U as M,V as N,Vi as ee,X as te,Xi as P,Zt as ne,_o as F,a as re,ai as ie,ba as ae,ca as oe,da as se,ei as ce,ga as le,ht as ue,j as de,jt as fe,ki as pe,la as me,ln as he,ma as I,na as ge,oa as L,r as _e,ta as R,ti as ve,un as ye,va as be,vo as xe,wr as Se,wt as Ce,x as z,ya as B,zi as we}from"./format-ox0oJ51_.js";import{B as V,H,R as U,U as W,V as G,W as K,a as Te,c as Ee,dt as De,i as Oe,o as ke,r as Ae,s as je}from"./TrayTitleSource-CNflSYSn.js";import{t as Me}from"./use-transform-971qznsR.js";import{t as Ne}from"./bell-ring-kS9kGwcv.js";import{t as q}from"./bell-i0ZTNxjY.js";import{t as Pe}from"./book-open-W5VGeEf_.js";import{t as Fe}from"./copy-48gwhhDO.js";import{t as Ie}from"./ellipsis-CidyZaW2.js";import{t as Le}from"./external-link-D6jQM2CZ.js";import{t as Re}from"./flask-conical-P-TiuT25.js";import{t as ze}from"./folder-open-z1RXMZa1.js";import{t as Be}from"./globe-CFH0vwgV.js";import{t as Ve}from"./key-round-m9ps8ZDi.js";import{t as He}from"./list-checks-CStYtbur.js";import{t as Ue}from"./log-out-CgcpH2Q7.js";import{t as We}from"./minus-BxRsdlKm.js";import{t as Ge}from"./panel-top-dXjBAa0g.js";import{t as Ke}from"./pencil-CpF9MxGZ.js";import{t as qe}from"./plus-c3HzV6VX.js";import{t as Je}from"./refresh-cw-CoLAai2c.js";import{t as Ye}from"./rotate-ccw-fsXoCwyv.js";import{t as Xe}from"./sliders-horizontal-B2K_lfHz.js";import{t as J}from"./trash-BHBJn5GS.js";import{t as Ze}from"./webhook-BiqcD9Uv.js";import{B as Qe,D as $e,E as et,G as tt,O as nt,P as rt,W as it,k as at,n as ot,o as st,t as ct,u as lt,v as ut}from"./index-BmgQHUbu.js";import{t as dt}from"./radio-cards-S8R3bqNN.js";import{t as ft}from"./TrayPanelView-BvketT9p.js";var Y=e(t(),1),X=xe(),pt=`https://astra-gate.si/docs/guide/remote-access`,mt=`astra.remote.acknowledged`;function ht(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 gt(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 _t(){try{return localStorage.getItem(mt)===`1`}catch{return!1}}function vt(){try{localStorage.setItem(mt,`1`)}catch{}}function yt(){let{t:e}=s(),t=we(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(bt,{s:n}),(0,X.jsx)(xt,{s:n}),(0,X.jsx)(St,{s:n}),(0,X.jsx)(Tt,{s:n}),(0,X.jsx)(r,{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)(z,{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:W(t.error)}):(0,X.jsx)(v,{className:`mx-auto my-8`})})}function bt({s:e}){let{t,locale:n}=s(),{toast:r,confirm:i}=K(),o=pe(),l=a(),u=ht(e,t),d=async e=>{await U.copy(e)&&r(t(`common.copied`))},f=async e=>{if(e&&!_t()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;vt()}(e||!l.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&o.mutate(e,{onError:e=>r(W(e),`error`)})},p=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,m=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,h=e.state===`connected`&&m!==null?m<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:re(m,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),g=e.cloudflared,_=g.downloading||g.path?null:g.asset?t(`settings.remote.cloudflaredMissing`,{version:g.version??``}):t(`settings.remote.cloudflaredUnsupported`),v=e.enabled?e.error??g.error??null:null,y=v!==null&&(e.state!==`connected`||/origin service|origin server/i.test(v)),b=e.publicUrl;return(0,X.jsxs)(D,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(k,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?_e(e.connectedAt,n):void 0,children:[(0,X.jsx)(de,{tone:p}),h,g.downloading&&g.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(g.progress*100),`%`]})]}),children:(0,X.jsx)(M,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:o.isPending||!e.enabled&&u!==null,onChange:e=>void f(e)})}),!e.enabled&&u&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:u}),!e.enabled&&!u&&_&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:_}),e.enabled&&b&&(0,X.jsxs)(k,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${b}/v1`}),children:[(0,X.jsx)(V,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(Fe,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void d(`${b}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void d(b)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void d(`${b}/key`),separatorBefore:!0}]}),(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(b,`_blank`,`noopener`)})]}),e.enabled&&b&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),y&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(z,{tone:e.state===`connected`?`warning`:`danger`,title:gt(v,e,t),children:v})})]})}function xt({s:e}){let{t}=s(),{toast:n,confirm:r}=K(),i=R(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let l=async e=>{await U.copy(e)&&n(t(`common.copied`))},u=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(W(e),`error`)})},d=()=>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(W(e),`error`)}),f=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(D,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(k,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(N,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void u(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)(z,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(h,{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)(k,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(h,{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)(k,{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)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void l(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Pe,{className:`size-3.5`}),onClick:()=>window.open(pt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(c,{size:`sm`,disabled:!f||i.isPending,onClick:d,children:t(`common.save`)})]})]})]})}function St({s:e}){let{t}=s(),{toast:n,confirm:r}=K(),i=R(),o=a(),c=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!o.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(W(e),`error`)})};return(0,X.jsxs)(D,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(k,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(f,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(k,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(M,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void c(e)})}),(0,X.jsx)(Ct,{passwordSet:e.checks.passwordSet})]})}function Ct({passwordSet:e}){let{t}=s(),{toast:n}=K(),r=a(),i=ce(),[o,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!o&&!r.data?.required&&(0,X.jsx)(c,{size:`sm`,onClick:()=>l(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),o&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(h,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:u,onChange:e=>d(e.target.value)}),(0,X.jsx)(c,{size:`sm`,variant:`plain`,onClick:()=>l(!1),children:t(`common.cancel`)}),(0,X.jsx)(c,{size:`sm`,variant:`primary`,disabled:u.length<8,loading:i.isPending,onClick:()=>i.mutate(u,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),l(!1),d(``)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})]})}var wt=[`auto`,`github`,`astra`,`custom`];function Tt({s:e}){let{t}=s(),{toast:n}=K(),r=R(),i=ye(),o=a(),l=e.cloudflared,[u,d]=(0,Y.useState)(e.download.downloadBaseUrl??``),[f,p]=(0,Y.useState)(!1),[m,g]=(0,Y.useState)(``);(0,Y.useEffect)(()=>d(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[_,v]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>v(e.download.downloadSource),[e.download.downloadSource]);let y=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(W(e),`error`)}),b=t=>{v(t),(t!==`custom`||e.download.downloadBaseUrl)&&y({downloadSource:t})},x=()=>i.mutate(void 0,{onSuccess:e=>e.path?g(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(W(e),`error`)}),S=l.fromEnvironment?t(`settings.remote.cf.fromEnv`):l.installed?l.version?t(`settings.remote.cf.installedProgram`,{version:l.version}):t(`settings.remote.cf.installedUnknown`):l.path?t(`settings.remote.cf.downloaded`,{version:l.version??``}):l.asset?t(`settings.remote.cf.notDownloaded`,{version:l.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(D,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(k,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:l.path??void 0,children:S}),children:(0,X.jsx)(de,{tone:l.path?`green`:l.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!l.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${_}.hint`),children:(0,X.jsx)(G,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:_,onChange:b,options:wt.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),_===`custom`&&(0,X.jsxs)(k,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(h,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:u,onChange:e=>d(e.target.value)}),(0,X.jsx)(c,{size:`sm`,disabled:!u.trim()||r.isPending||u.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>y({downloadSource:`custom`,downloadBaseUrl:u.trim()}),children:t(`common.save`)})]})]}),!o.data?.remote&&!l.fromEnvironment&&(0,X.jsx)(k,{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)(c,{size:`sm`,disabled:r.isPending,onClick:()=>y({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!f&&(0,X.jsx)(c,{size:`sm`,onClick:()=>{p(!0),x()},children:t(`settings.remote.cf.choose`)})}),f&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(h,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:m,onChange:e=>g(e.target.value)}),(0,X.jsx)(c,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:x,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(c,{size:`sm`,variant:`plain`,onClick:()=>p(!1),children:t(`common.cancel`)}),(0,X.jsx)(c,{size:`sm`,variant:`primary`,disabled:!m.trim(),loading:r.isPending,onClick:()=>y({cloudflaredPath:m.trim()},()=>p(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Et=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Dt={local:`127.0.0.1`,lan:`0.0.0.0`},Ot=e=>Et.includes(e)?`local`:`lan`;function kt(){let{t:e}=s(),{toast:t,confirm:n}=K(),r=F(),i=w(),o=a(),l=ee(),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),m=i.data;if(!m)return(0,X.jsx)(k,{label:e(`settings.listen`),detail:i.isError?W(i.error):void 0,children:i.isPending&&(0,X.jsx)(v,{className:`size-3.5`})});let h=`${m.host}:${m.port}`,g=Ot(m.configuredHost),_=m.configuredHost!==m.host,y=!!o.data?.required,b=async n=>{await U.copy(n)&&t(e(`common.copied`))},x=n=>l.mutate(Dt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(W(e),`error`)}),S=async t=>{if(t!==g){if(t===`lan`){if(!m.passwordSet){d(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}x(t)}},C=async()=>{p(!0);let n=await U.restartService();if(p(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},T=m.hostFromEnvironment?e(`settings.listen.env`,{address:h}):y?e(`settings.listen.localOnly`,{address:h}):_?`${e(`settings.listen.pending`,{host:m.configuredHost})}${B?``:` · ${e(`settings.listen.restartHint`)}`}`:h;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:e(`settings.listen`),detail:T,children:!m.hostFromEnvironment&&!y&&(0,X.jsxs)(X.Fragment,{children:[_&&B&&(0,X.jsx)(c,{size:`sm`,loading:f,onClick:()=>void C(),children:e(`settings.listen.restart`)}),(0,X.jsx)(N,{ariaLabel:e(`settings.listen`),value:g,onChange:e=>void S(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),m.networkUrls.map(t=>(0,X.jsx)(k,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(`${t}/v1`)})},t)),(g===`lan`||m.networkUrls.length>0)&&(0,X.jsx)(Ct,{passwordSet:m.passwordSet}),(0,X.jsx)(At,{open:u,onOpenChange:d,onSaved:()=>x(`lan`)})]})}function At({open:e,onOpenChange:t,onSaved:n}){let{t:r}=s(),{toast:i}=K(),a=ce(),[o,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(``),f=u!==``&&u!==o,p=o.length>=8&&o===u,m=e=>{e||(l(``),d(``)),t(e)},g=()=>{p&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),m(!1),n()},onError:e=>i(W(e),`error`)})};return(0,X.jsx)(H,{open:e,onOpenChange:m,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{onClick:()=>m(!1),children:r(`common.cancel`)}),(0,X.jsx)(c,{variant:`primary`,disabled:!p,loading:a.isPending,onClick:g,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,X.jsx)(h,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>l(e.target.value)}),(0,X.jsx)(h,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:f,value:u,onChange:e=>d(e.target.value)}),f&&(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 jt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Mt={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/…`},Nt=e=>e===`feishu`||e===`dingtalk`,Pt=(e,t)=>e(`alerts.event.${t}`),Ft=(e,t)=>e(`alerts.event.${t}.hint`);function It(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Lt,{}),(0,X.jsx)(Rt,{}),(0,X.jsx)(Ut,{})]})}function Lt(){let{t:e,locale:t}=s(),n=m(!0);return(0,X.jsxs)(D,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(v,{}),n.data?.length===0&&(0,X.jsx)(k,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(k,{icon:(0,X.jsx)(Ne,{className:`size-4 text-[var(--danger)]`}),label:`${Pt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${_e(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Rt(){let{t:e}=s(),{toast:t,confirm:n}=K(),r=me(),i=he(),a=u(),o=y(),[l,d]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),_=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(W(e),`error`)}),b=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>g(e.secret??null),onError:e=>t(W(e),`error`)})},x=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(D,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(v,{}),r.data?.length===0&&(0,X.jsx)(k,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(k,{icon:(0,X.jsx)(Ze,{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)(f,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(f,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||Nt(t.format))&&(0,X.jsx)(f,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(c,{size:`sm`,icon:(0,X.jsx)(Re,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>_(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(V,{label:e(`common.more`),icon:(0,X.jsx)(Ie,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(Ke,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>m(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ve,{className:`size-3.5`}),onSelect:()=>void b(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(J,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void x(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(c,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>d(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(zt,{hook:l,onClose:()=>d(null),onSecret:g}),(0,X.jsx)(Vt,{hook:p,onClose:()=>m(null)}),(0,X.jsx)(Bt,{secret:h,onClose:()=>g(null)})]})}function zt({hook:e,onClose:t,onSecret:n}){let{t:r}=s(),{toast:i}=K(),a=ne(),o=ge(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(10),[g,_]=(0,Y.useState)(!0),[v,y]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(!0),[w,T]=(0,Y.useState)(`generic`),[E,D]=(0,Y.useState)(``),[O,A]=(0,Y.useState)([]),j=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;u(t?.name??``),f(t?.url??``),m(t?.timeoutSec??10),_(t?.useProxy??!0),y(t?.enabled??!0),S(!t||t.hasSecret),T(t?.format??`generic`),D(``),A((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(H,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(j?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(c,{variant:`primary`,disabled:!l.trim()||!d.trim(),loading:a.isPending||o.isPending,onClick:()=>{let s=Object.fromEntries(O.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),c={name:l.trim(),url:d.trim(),timeoutSec:p??10,useProxy:g,enabled:v,headers:Object.keys(s).length>0?s:null},u={onError:e=>i(W(e),`error`)},f=!j&&e!==null&&e.format!==w,m=Nt(w)?x?E.trim()||void 0:``:void 0;j?a.mutate({...c,format:w,...w===`generic`?{signed:x}:m?{secret:m}:{}},{...u,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...c,...f?{format:w}:{},...w===`generic`?x||!e.hasSecret||f?{}:{signed:!1}:m===void 0?{}:{secret:m}},{...u,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(C,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(h,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(C,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${w}.hint`),children:(0,X.jsx)(G,{ariaLabel:r(`alerts.webhooks.format`),value:w,onChange:t=>{T(t),S(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||Nt(t))},options:jt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(C,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(h,{mono:!0,value:d,placeholder:Mt[w],onChange:e=>f(e.target.value)})}),Nt(w)&&x&&(0,X.jsx)(C,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(h,{mono:!0,type:`password`,autoComplete:`off`,value:E,placeholder:e!==`new`&&e!==null&&e.format===w&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>D(e.target.value)})}),(0,X.jsx)(C,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(b,{value:p,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:m})}),(0,X.jsx)(C,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[O.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)(h,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>A(O.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(h,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>A(O.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(J,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>A(O.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(c,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>A([...O,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(k,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(M,{checked:v,label:r(`alerts.webhooks.enabled`),onChange:y})}),(0,X.jsx)(k,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(M,{checked:g,label:r(`alerts.webhooks.useProxy`),onChange:_})}),(w===`generic`?j||e!==null&&e.format===`generic`&&e.hasSecret:Nt(w))&&(0,X.jsx)(k,{label:r(`alerts.webhooks.signed`),detail:r(w===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(M,{checked:x,label:r(`alerts.webhooks.signed`),onChange:S})})]})]})})}function Bt({secret:e,onClose:t}){let{t:n}=s(),{toast:r}=K();return(0,X.jsx)(H,{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)(c,{onClick:async()=>e&&await U.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(c,{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 Vt({hook:e,onClose:t}){let{t:n,locale:r}=s(),{toast:i}=K(),a=oe(e?.id),o=d(),l={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(H,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(v,{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)(f,{tone:l[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Pt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:_e(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:_e(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)(T,{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)(T,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(c,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(W(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Ht(e){let t=Se(),n=S(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=De({queries:r.map(t=>({queryKey:ue.providerAccounts(t.id),queryFn:()=>se(`GET`,`/api/providers/${I(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(t.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(n.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?r.flatMap((e,t)=>(i[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Ut(){let{t:e}=s(),{toast:t,confirm:r}=K(),i=j(),a=me(),l=o(),u=n(),[d,p]=(0,Y.useState)(null),m=e=>a.data?.find(t=>t.id===e)?.name??e,h=async n=>{await r({title:e(`alerts.rules.deleteConfirm`,{name:n.name}),confirmLabel:e(`common.delete`),destructive:!0})&&u.mutate(n.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:n.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(D,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[i.isLoading&&(0,X.jsx)(v,{}),i.data?.length===0&&(0,X.jsx)(k,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),i.data?.map(n=>(0,X.jsxs)(k,{icon:(0,X.jsx)(Ne,{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)(f,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(f,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Pt(e,n.event)} → ${n.webhookIds.map(m).join(`, `)||`—`}`,children:[(0,X.jsx)(M,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>l.mutate({id:n.id,enabled:e},{onError:e=>t(W(e),`error`)})}),(0,X.jsx)(V,{label:e(`common.more`),icon:(0,X.jsx)(Ie,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(Ke,{className:`size-3.5`}),onSelect:()=>p(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(J,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void h(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(c,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>p(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Gt,{rule:d,onClose:()=>p(null)})]})}function Wt(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 Gt({rule:e,onClose:t}){let{t:n}=s(),{toast:r}=K(),i=Ce(),a=me(),l=_(),u=o(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[g,v]=(0,Y.useState)({}),[y,x]=(0,Y.useState)(`all`),[S,w]=(0,Y.useState)([]),[T,E]=(0,Y.useState)([]),[D,O]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(null),[ee,te]=(0,Y.useState)(60),P=i.data?.find(e=>e.id===p),ne=Ht(P?.subjectType),F=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=i.data?.[0];f(t?.name??``),m(t?.event??n?.id??``),v(t?{...Wt(i.data?.find(e=>e.id===t.event)),...t.condition}:Wt(n)),x(t?.subjects?`only`:`all`),w(t?.subjects??[]),E(t?.webhookIds??(a.data??[]).map(e=>e.id)),O(t?.notifyResolved??!1),j(t?.repeatMinutes??null),te(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(H,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(F?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(c,{variant:`primary`,disabled:!d.trim()||!p,loading:l.isPending||u.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(g).filter(([,e])=>e!==null&&e!==``)),a={name:d.trim(),event:p,condition:i,subjects:y===`all`?null:S,webhookIds:T,notifyResolved:D,repeatMinutes:A&&A>0?Math.floor(A):null,cooldownMinutes:Math.max(0,Math.floor(ee??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(W(e),`error`)};F?l.mutate(a,o):e&&u.mutate({id:e.id,...a},o)},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(C,{label:n(`alerts.rules.name`),children:(0,X.jsx)(h,{value:d,maxLength:64,onChange:e=>f(e.target.value)})}),(0,X.jsx)(C,{label:n(`alerts.rules.event`),hint:p?Ft(n,p):void 0,children:(0,X.jsx)(G,{ariaLabel:n(`alerts.rules.event`),value:p,onChange:e=>{m(e),v(Wt(i.data?.find(t=>t.id===e))),w([])},options:(i.data??[]).map(e=>({value:e.id,label:Pt(n,e.id)}))})}),P?.params.map(e=>(0,X.jsx)(C,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(b,{value:typeof g[e.name]==`number`?g[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>v({...g,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(G,{ariaLabel:n(`alerts.param.${e.name}`),value:String(g[e.name]??``),onChange:t=>v({...g,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(h,{mono:!0,value:String(g[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>v({...g,[e.name]:t.target.value})})},e.name)),P&&(0,X.jsx)(C,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${P.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(N,{ariaLabel:n(`alerts.rules.subjects`),value:y,onChange:x,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),y===`only`&&(0,X.jsx)(lt,{label:n(`alerts.rules.subjects`),value:S,onValueChange:w,options:[...ne,...S.filter(e=>!ne.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(C,{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)(lt,{label:n(`alerts.rules.webhooks`),value:T,onValueChange:E,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)(C,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(b,{value:A,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:j})}),(0,X.jsx)(C,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(b,{value:ee,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:te})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(k,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(M,{checked:D,label:n(`alerts.rules.notifyResolved`),onChange:O})})})]})})}function Kt(){let{t:e}=s(),t=fe(),n=be()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&ae;return(0,X.jsxs)(D,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)(qt,{loginItem:n}),(0,X.jsx)(Jt,{})]})}function qt({loginItem:e}){let{t}=s(),{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)(k,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(M,{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(W(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(v,{className:`size-3.5`})})}function Jt(){let{t:e}=s(),{toast:t}=K(),n=fe(),r=ve(),i=n.data;if(!i)return(0,X.jsx)(k,{label:e(`settings.startup.service`),detail:n.isError?W(n.error):void 0,children:n.isPending&&(0,X.jsx)(v,{className:`size-3.5`})});let a=!i.supported||i.mechanism===`none`?e(`settings.startup.unsupported.${i.unsupported??`platform`}`):i.canChange?i.enabled&&i.location?e(`settings.startup.entry`,{location:i.location}):e(`settings.startup.service.${i.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(k,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(M,{checked:i.enabled,disabled:!i.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(W(e),`error`)})})})}var Z={field:`_field_bzdr6_1`,head:`_head_bzdr6_11`,label:`_label_bzdr6_13`,limit:`_limit_bzdr6_17`,control:`_control_bzdr6_27`,step:`_step_bzdr6_43`,icon:`_icon_bzdr6_45`,valueWrap:`_valueWrap_bzdr6_67`,value:`_value_bzdr6_67`,affix:`_affix_bzdr6_75`,char:`_char_bzdr6_77`,number:`_number_bzdr6_83`,display:`_display_bzdr6_85`,mirror:`_mirror_bzdr6_89`,input:`_input_bzdr6_91`,column:`_column_bzdr6_103`,sizer:`_sizer_bzdr6_105`,glyph:`_glyph_bzdr6_107`,symbol:`_symbol_bzdr6_109`,messageSlot:`_messageSlot_bzdr6_113`,hint:`_hint_bzdr6_115`,words:`_words_bzdr6_119`,wordSlot:`_wordSlot_bzdr6_121`,wordSizer:`_wordSizer_bzdr6_123`,word:`_word_bzdr6_119`,srOnly:`_srOnly_bzdr6_127`},{spring:Q,duration:$,blur:Yt}=te,Xt=[...te.ease.enter],Zt=[...te.ease.standard],Qt=[0,1,2,3,4,5,6,7,8,9],$t=6,en=400,tn=40,nn=240,rn=1500,an=700,on=700,sn=.22,cn=4,ln=130,un=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),dn=e=>(String(e).split(`.`)[1]??``).length,fn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),pn=(e,t)=>typeof e==`function`?e(t):e??``,mn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function hn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var gn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Yt.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:Zt}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Yt.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Zt},opacity:{duration:$.instant},filter:{duration:$.instant}}})},_n=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),vn={enter:_n(0),center:{..._n(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},yn={enter:_n(1),center:{..._n(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function bn({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=Me(e,e=>`${n(e)*1.05}em`),i=Me(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=Me(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=Me(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*Yt.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(A.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function xn({digit:e,direction:t,instant:n}){let r=l(),i=E(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`}),Qt.map(e=>(0,X.jsx)(bn,{position:i,digit:e},e))]})}function Sn({value:e,format:t,direction:n,instant:r}){let a=l(),o=r?yn:a?vn:gn;return(0,X.jsx)(i,{initial:!1,custom:n,children:hn(e,t).map(e=>(0,X.jsx)(A.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:o,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(xn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function Cn({text:e,direction:t,className:n}){let r=l();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(i,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(A.span,{className:Z.char,custom:t,variants:r?vn:gn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var wn=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},Tn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=wn(n[t]),i=wn(e);return r!==null&&i!==null&&i<r?-1:1})},En={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Yt.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:Xt,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Yt.subtle}px)`,transition:{duration:.14,ease:Zt}})},Dn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function On({word:e,direction:t}){let n=l(),r=(0,Y.useRef)(null),a=E(`auto`),o=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!o.current||n?a.jump(e.offsetWidth):p(a,e.offsetWidth,Q.morph),o.current=!0});return t.observe(e),()=>t.disconnect()},[n,a]),(0,X.jsxs)(A.span,{className:Z.wordSlot,style:{width:a},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(i,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(A.span,{className:Z.word,custom:t,variants:n?Dn:En,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function kn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:Tn(t.text,e)});let r=t.text===e?t.directions:Tn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(On,{word:e,direction:r[t]??1})]},t))})]})}function An({id:e,text:t,className:n}){return(0,X.jsx)(i,{initial:!1,children:t?(0,X.jsx)(jn,{id:e,text:t,className:n},`message`):null})}function jn({id:e,text:t,className:n}){let r=l(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(A.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(A.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${Yt.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:Xt},children:(0,X.jsx)(kn,{text:t})})})}function Mn({id:e,edge:t,text:n}){let r=l();return(0,X.jsx)(i,{initial:!1,children:t!==0&&(0,X.jsx)(A.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${Yt.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:Zt}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function Nn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?qe:We;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Pn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:u,id:d,prefix:f,suffix:m,scrub:h=!1,locale:g=`en-US`,formatOptions:_,size:v=`md`,limitHint:y=!0}){let b=l(),x=(0,Y.useId)(),S=d??x,C=c?`${S}-description`:void 0,w=`${S}-limit`,T=o>0?o:1,[D,O]=(0,Y.useState)(n),k=t??D,[j,M]=(0,Y.useState)(``),[N,ee]=(0,Y.useState)(!1),[te,P]=(0,Y.useState)(0),[ne,F]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(``),[ae,oe]=(0,Y.useState)(0),[se,ce]=(0,Y.useState)(!1),le=(0,Y.useRef)(null),ue=(0,Y.useRef)(null),de=(0,Y.useRef)(null),fe=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(void 0),me=(0,Y.useRef)(void 0),he=(0,Y.useRef)({edge:0,count:0,at:0}),I=(0,Y.useRef)(null),ge=(0,Y.useRef)(null),L=(0,Y.useRef)(k),_e=(0,Y.useRef)(k),R=(0,Y.useRef)(void 0),ve=(0,Y.useRef)(null),ye=(0,Y.useRef)(!1),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),Se=(0,Y.useRef)(()=>!1),Ce=E(0),z=E(0),B=E(0),we=Me(()=>z.get()+B.get()),V=Number.isFinite(i)?i:0,H=Math.max(dn(T),dn(V)),U=_?.minimumFractionDigits??H,W=Math.max(U,_?.maximumFractionDigits??H),G=_?.useGrouping??!0,K=(0,Y.useMemo)(()=>new Intl.NumberFormat(g,{minimumFractionDigits:U,maximumFractionDigits:W,useGrouping:G,numberingSystem:`latn`}),[g,U,W,G]),Te=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(g).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[g]),Ee=e=>Number(e.toFixed(H))||0,De=e=>Math.min(a,Math.max(i,e)),Oe=e=>Ee(V+Math.round((e-V)/T)*T),ke=(e,t)=>{let n=(e-V)/T;return Ee(V+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*T)},Ae=e=>`${pn(f,e)}${K.format(e)}${pn(m,e)}`.trim();function je(e){let t=e.split(Te.group).join(``).replace(Te.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Ne=N?je(j):null,q=Ne??k,[Pe,Fe]=(0,Y.useState)({value:q,direction:1});Pe.value!==q&&Fe({value:q,direction:q>Pe.value?1:-1});let Ie=Pe.value===q?Pe.direction:q>Pe.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(R.current),window.clearTimeout(fe.current),window.clearTimeout(pe.current),window.clearTimeout(me.current)},[]);function Le(e,t){let n=performance.now(),r=he.current;r.count=r.edge===e&&n-r.at<on?r.count+1:1,r.edge=e,r.at=n;let i=le.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(me.current),me.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!b){p(Ce,0,{...un,velocity:-e*ln*(1+Math.min(r.count-1,cn)*sn)});let n=(e>0?de:ue).current;n&&(t===`button`||t===`key`)&&p(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}y&&(oe(e),window.clearTimeout(fe.current),fe.current=window.setTimeout(()=>oe(0),rn))}function Re(e,n){if(!Number.isFinite(e))return!1;let i=De(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Le(a>0?1:-1,n),ie(`${Ae(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==L.current&&ie(Ae(i)),i!==L.current&&(L.current=i,t===void 0&&O(i),r?.(i),!0)}let ze=(e,t,n)=>Re(ke(L.current,e*t),n);(0,Y.useLayoutEffect)(()=>{L.current=k,Se.current=ze});function Be(){let e=ge.current;e&&be.current===null&&(be.current=e.getBoundingClientRect().left-z.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=be.current,t=ge.current;if(be.current=null,xe.current){xe.current=!1;let e=I.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-z.get()-B.get());Math.abs(n)<.5||(B.set(B.get()+n),b?B.jump(0):p(B,0,Q.morph))});function Ve(){window.clearTimeout(pe.current),ce(!1)}function He(){if(!N)return;Be(),ee(!1),Ve();let e=je(j);e!==null&&Re(Oe(e),`type`)}function Ue(){window.clearTimeout(R.current),R.current=void 0,P(0)}function We(e,t,n){Ue(),He();let r=Math.max(1,Math.round(t/T));n===`button`&&P(e);let i=0,a=()=>{let t=Se.current(e,r,n);R.current=window.setTimeout(a,t?Math.max(tn,150*.86**++i):nn)};R.current=window.setTimeout(a,ze(e,r,n)?en:360)}function Ge(e){let t=s??T*10,n={ArrowUp:[1,e.shiftKey?t:T],ArrowDown:[-1,e.shiftKey?t:T],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||We(n[0],n[1],`key`);return}if(!N&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),Re(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),N?(xe.current=!0,He()):e.currentTarget.select()),e.key===`Escape`&&N&&(e.preventDefault(),Be(),ee(!1),Ve(),xe.current=!0,Re(_e.current,`type`))}function Ke(e){let t=RegExp(`[^0-9${fn(Te.group)}${H||W?fn(Te.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);N||(_e.current=k),Be(),M(n),ee(!0);let r=je(n);r!==null&&r>=i&&r<=a&&Oe(r)===r&&Re(r,`type`),Ve(),r!==null&&r<i&&(pe.current=window.setTimeout(()=>ce(!0),an))}function qe(e){ye.current=!1,h&&!u&&e.button===0&&(He(),ve.current={pointer:e.pointerId,x:e.clientX,from:L.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Je(e){let t=ve.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,F(!0)}let r=n/$t,o=Math.trunc(r);Re(o?ke(t.from,o):t.from,`scrub`);let s=t.from+r*T,c=s>a?(s-a)/T*$t:s<i?(s-i)/T*$t:0;z.set(b?0:mn(c))}function Ye(e){let t=ve.current;t&&t.pointer===e.pointerId&&(ve.current=null,t.active&&(ye.current=!0,F(!1),p(z,0,b?{duration:0}:Q.snappy),ie(Ae(L.current))))}let Xe=t=>({toward:t,label:e,disabled:u,controls:S,limit:t>0?q>=a:q<=i,pressed:te===t}),J=Ne===null?0:Ne>a?1:Ne<i&&se?-1:0,Ze=y?J||ae:0,Qe=Ze>0?a:i,$e=Ze?typeof y==`function`?y(Ze>0?`max`:`min`,Qe):`${Ze>0?`Max`:`Min`} ${Ae(Qe)}`:``,et=[C,J&&y?w:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":v,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:S,className:Z.label,"data-scrub":h&&!u||void 0,onPointerDown:qe,onPointerMove:Je,onPointerUp:Ye,onPointerCancel:Ye,onClick:e=>{ye.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Mn,{id:w,edge:Ze,text:$e})]}),(0,X.jsxs)(`div`,{ref:le,className:Z.control,"data-scrubbing":ne||void 0,"data-disabled":u||void 0,"data-warn":J?J>0?`max`:`min`:void 0,children:[(0,X.jsx)(Nn,{...Xe(-1),iconRef:ue,onPress:()=>We(-1,T,`button`),onRelease:Ue,onActivate:()=>{He(),ze(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==I.current&&e.preventDefault()},onClick:e=>{!u&&e.target!==I.current&&(I.current?.focus(),I.current?.select())},children:(0,X.jsxs)(A.span,{ref:ge,className:Z.value,style:{x:we,y:Ce},children:[(0,X.jsx)(Cn,{text:pn(f,q),direction:Ie,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":N||void 0,"aria-hidden":`true`,children:(0,X.jsx)(Sn,{value:q,format:K,direction:Ie,instant:N})}),N&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:j}),(0,X.jsx)(`input`,{ref:I,id:S,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:H||W?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:N?j:K.format(k),disabled:u,"aria-describedby":et,"aria-invalid":J?!0:void 0,"aria-valuenow":k,"aria-valuetext":Ae(k),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a:void 0,onChange:e=>Ke(e.currentTarget.value),onKeyDown:Ge,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ue()},onBlur:()=>{Ue(),He()}})]}),(0,X.jsx)(Cn,{text:pn(m,q),direction:Ie,className:Z.affix})]})}),(0,X.jsx)(Nn,{...Xe(1),iconRef:de,onPress:()=>We(1,T,`button`),onRelease:Ue,onActivate:()=>{He(),ze(1,1,`button`)}})]}),(0,X.jsx)(An,{id:C,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:re})]})}var Fn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function In(){let{t:e}=s(),t=F(),[n,r]=ke(),i=je(),a=Ae(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(k,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(M,{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)(Ln,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(dt,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:le.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Ln,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Fn.map(o)})}),(0,X.jsx)(Ln,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ye,{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)(Ln,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(ft,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Ln({title:e,hint:t,children:n}){let{t:r}=s();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Rn=[`general`,`notifications`,`remote`,`tray`],zn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Bn(){let{t:e}=s(),{tab:t}=tt(),n=it(),r=Te(),i=Rn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsxs)(ut,{title:e(`nav.settings`),children:[(0,X.jsxs)(et,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(nt,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(at,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Xe,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(at,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(q,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(at,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Be,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(at,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Ge,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)($e,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Vn,{})}),(0,X.jsx)($e,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(It,{})}),(0,X.jsx)($e,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(yt,{})}),r&&(0,X.jsx)($e,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(In,{})})]}),(0,X.jsx)(`div`,{className:`mt-6`,children:(0,X.jsx)(st,{name:`settings.sections`})})]})}function Vn(){let{t:e,locale:t,setLocale:n}=s(),r=ot(),i=ie(),o=P(),l=F(),u=L(),d=a(),f=x(),p=we(),{toast:m,confirm:h}=K(),g=i.data,_=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,y=e=>o.mutate(e,{onError:e=>m(W(e),`error`)}),b=e=>{n(e),y({locale:e})},S=async t=>{await U.copy(t)&&m(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(D,{title:e(`settings.appearance`),children:[(0,X.jsx)(k,{label:e(`settings.theme`),children:(0,X.jsx)(N,{ariaLabel:e(`settings.theme`),value:r.theme,onChange:r.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(k,{label:e(`settings.accent`),detail:r.accentChoice===`system`?r.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(G,{className:`w-40`,ariaLabel:e(`settings.accent`),value:r.accentChoice,onChange:r.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...ct.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(k,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(N,{ariaLabel:e(`settings.language`),value:t,onChange:b,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Kt,{}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(D,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(k,{label:e(`settings.gatewayUrl`),detail:`${g.gatewayBaseUrl}/v1`,children:(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(`${g.gatewayBaseUrl}/v1`)})}),_&&(0,X.jsx)(k,{label:e(`settings.remote.publicUrl`),detail:_,children:(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(_)})}),(0,X.jsx)(kt,{}),(0,X.jsx)(k,{label:e(`settings.dataDir`),detail:g.dataDir,children:U.canOpenPaths?(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void U.openPath(g.dataDir)}):(0,X.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Fe,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(g.dataDir)})}),(0,X.jsx)(k,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(M,{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}))&&y({requireGatewayKey:t})}})}),(0,X.jsx)(k,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(qn,{label:e(`settings.streamIdle`),value:g.streamIdleTimeoutSec,onCommit:e=>y({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(k,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(G,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:g.requestCompression,onChange:e=>y({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)(D,{footer:e(`settings.preventSleepHint`),children:(0,X.jsx)(k,{label:e(`settings.preventSleep`),children:(0,X.jsx)(M,{checked:g.preventSleep??!1,label:e(`settings.preventSleep`),onChange:e=>y({preventSleep:e})})})}),(0,X.jsx)(D,{footer:e(`settings.clientFailoverHint`),children:(0,X.jsx)(k,{label:e(`settings.clientFailover`),children:(0,X.jsx)(M,{checked:g.clientProviderFailover??!0,label:e(`settings.clientFailover`),onChange:e=>y({clientProviderFailover:e})})})}),(0,X.jsx)(Wn,{settings:g}),(0,X.jsx)(Gn,{settings:g}),(0,X.jsx)(Un,{settings:g}),(0,X.jsx)(Kn,{settings:g}),(0,X.jsxs)(D,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(k,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(qn,{label:e(`settings.quota.autoInterval`),value:g.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void l.invalidateQueries({queryKey:ue.providers}),onError:e=>m(W(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(k,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(qn,{label:e(`settings.quota.subscriptionInterval`),value:g.subscriptionQuotaIntervalMinutes,onCommit:e=>y({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(D,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(k,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(G,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:g.usageTimeZone??``,onChange:e=>y({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:g.effectiveUsageTimeZone})},...[...new Set([...zn,...g.usageTimeZone?[g.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(D,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(k,{label:e(`settings.debugBodies`),children:(0,X.jsx)(M,{checked:g.debugBodies,label:e(`settings.debugBodies`),onChange:e=>y({debugBodies:e})})}),(0,X.jsx)(k,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(qn,{label:e(`settings.bodyRetention`),value:g.bodyRetentionDays,onCommit:e=>y({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(k,{label:e(`settings.requestRetention`),detail:g.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(M,{checked:g.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>y({requestRetentionDays:e?90:null})}),g.requestRetentionDays!=null&&(0,X.jsx)(qn,{label:e(`settings.requestRetention`),value:g.requestRetentionDays,onCommit:e=>y({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(D,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(k,{label:e(`settings.traceContent`),children:(0,X.jsx)(M,{checked:g.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>y({traceContent:e})})})}),(0,X.jsx)(D,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(k,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(qn,{label:e(`settings.effort.${t}`),value:g.effortBudgets[t],onCommit:e=>y({effortBudgets:{...g.effortBudgets,[t]:e??g.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):i.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:W(i.error)}):(0,X.jsx)(v,{className:`mx-auto my-8`}),(0,X.jsxs)(D,{title:e(`settings.about`),children:[(0,X.jsx)(k,{label:e(`settings.serverVersion`),detail:u.data?`${u.data.version} · API ${u.data.apiVersion}`:`—`}),B&&(0,X.jsx)(k,{label:e(`settings.desktopVersion`),detail:be()?.version||`—`}),(0,X.jsx)(Hn,{}),B&&(0,X.jsx)(k,{label:e(`settings.logs`),onClick:()=>void U.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(k,{label:e(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Ue,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Hn(){let{t:e}=s(),{toast:t}=K(),n=F(),r=P(),i=ie(),a=O(),o=g(),l=a.data,u=i.data?.updateChannel??l?.channel,d=be()?.updates??null,[f,p]=(0,Y.useState)(!1),m=()=>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(W(e),`error`)}),h=()=>{d&&!f&&(p(!0),d.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:ue.version}),n.invalidateQueries({queryKey:ue.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(W(e),`error`)).finally(()=>p(!1)))},_=l?.lastCheckAt?new Date(l.lastCheckAt).toLocaleString():void 0,y=l?.available?d?e(`settings.updateAvailable`,{version:l.available}):`${e(`settings.updateAvailable`,{version:l.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:e(`settings.autoCheck`),detail:l&&!l.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(M,{checked:l?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(W(e),`error`)})})}),(0,X.jsx)(k,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(M,{checked:u===`preview`,label:e(`settings.previewUpdates`),disabled:!u||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:m,onError:e=>t(W(e),`error`)})})}),(0,X.jsxs)(k,{label:e(`settings.checkUpdates`),detail:o.isError?e(`settings.updateCheckFailed`,{error:W(o.error)}):l?.available?y:_?e(`settings.lastChecked`,{time:_}):void 0,children:[(0,X.jsx)(c,{size:`sm`,variant:`plain`,disabled:o.isPending,onClick:m,children:o.isPending?(0,X.jsx)(v,{className:`size-3.5`}):(0,X.jsx)(Je,{className:`size-3.5`})}),d&&l?.available&&(0,X.jsx)(c,{size:`sm`,variant:`plain`,disabled:f,"aria-label":e(`settings.updateApply`),onClick:h,children:f?(0,X.jsx)(v,{className:`size-3.5`}):(0,X.jsx)(Qe,{className:`size-3.5`})})]})]})}function Un({settings:e}){let{t}=s(),{toast:n}=K(),r=P(),[i,a]=(0,Y.useState)(e.proxyMode),[o,l]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>l({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let u=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(W(e),`error`)})},d=()=>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(W(e),`error`)}),f=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(D,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(k,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(N,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:u,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)(k,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(h,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>l({...o,url:e.target.value})})}),(0,X.jsx)(k,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(h,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>l({...o,username:e.target.value})})}),(0,X.jsx)(k,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(h,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>l({...o,password:e.target.value})})}),(0,X.jsx)(k,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(h,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>l({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(c,{size:`sm`,disabled:!f||!o.url.trim()||r.isPending,onClick:d,children:t(`common.save`)})})]})]})}function Wn({settings:e}){let{t}=s(),{toast:n}=K(),r=P(),i=e.providerQualifiedModels??!1,a=i?e.modelQualifyScope??`shared`:`off`,o=e.modelProviderSeparator??`@`,[c,l]=(0,Y.useState)(o);(0,Y.useEffect)(()=>l(o),[o]);let u=e=>r.mutate(e,{onError:e=>{l(o),n(W(e),`error`)}});return(0,X.jsxs)(D,{title:t(`settings.qualifiedModels`),footer:t(`settings.qualifiedModels.footer`),children:[(0,X.jsx)(k,{label:t(`settings.qualifiedModels.mode`),detail:t(`settings.qualifiedModels.modeHint`),children:(0,X.jsx)(G,{className:`w-56`,ariaLabel:t(`settings.qualifiedModels.mode`),value:a,onChange:e=>u(e===`off`?{providerQualifiedModels:!1}:{providerQualifiedModels:!0,modelQualifyScope:e}),options:[{value:`off`,label:t(`settings.qualifiedModels.mode.off`)},{value:`shared`,label:t(`settings.qualifiedModels.mode.shared`)},{value:`all`,label:t(`settings.qualifiedModels.mode.all`)}]})}),i&&(0,X.jsx)(k,{label:t(`settings.qualifiedModels.separator`),detail:t(`settings.qualifiedModels.separatorHint`),children:(0,X.jsx)(h,{className:`w-24`,mono:!0,maxLength:8,"aria-label":t(`settings.qualifiedModels.separator`),value:c,onChange:e=>l(e.target.value),onBlur:()=>c!==o&&u({modelProviderSeparator:c})})})]})}function Gn({settings:e}){let{t}=s(),{toast:n}=K(),r=P(),i=e.hiddenNav??[],a=rt.flatMap(e=>e.items).filter(e=>e.id!==`settings`),o=(e,t)=>r.mutate({hiddenNav:t?i.filter(t=>t!==e):[...i,e]},{onError:e=>n(W(e),`error`)});return(0,X.jsx)(D,{title:t(`settings.sidebar`),footer:t(`settings.sidebar.footer`),children:a.map(e=>(0,X.jsx)(k,{label:t(e.label),children:(0,X.jsx)(M,{checked:!i.includes(e.id),label:t(e.label),onChange:t=>o(e.id,t)})},e.id))})}function Kn({settings:e}){let{t}=s(),{toast:n}=K(),r=P(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let l=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(W(e),`error`)});return(0,X.jsxs)(D,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(k,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(M,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>l(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(h,{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)(c,{size:`sm`,disabled:r.isPending,onClick:()=>l(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(c,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>l(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function qn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Pn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Bn as SettingsPage};
@@ -1,2 +0,0 @@
1
- import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{A as n,C as r,D as i,E as a,F as o,H as s,L as c,P as l,R as u,T as d,Ti as f,U as p,V as m,W as h,Yr as g,Zi as _,j as v,l as y,li as b,ua as x,vo as S,x as C}from"./format-ox0oJ51_.js";import{R as w,U as T,V as E,W as D}from"./TrayTitleSource-CNflSYSn.js";import{t as O}from"./arrow-down-Def8Fl70.js";import{t as k}from"./arrow-up-DE65OgjV.js";import{t as A}from"./copy-48gwhhDO.js";import{t as j}from"./plus-c3HzV6VX.js";import{t as M}from"./trash-BHBJn5GS.js";import{T as N,v as P}from"./index-BmgQHUbu.js";var F=e(t(),1),I=S(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(u,{...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 d))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(e,t,n){if(e instanceof x){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>J(e,t,n))}return[T(e)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in d?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in d?t(n):e??``}function Q(){let{t:e}=r(),t=b();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)(C,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(s,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=r(),{toast:n}=D(),a=_(),[o,s]=(0,F.useState)(()=>W(e)),[c,l]=(0,F.useState)([]),u=e=>s(t=>({...t,...e})),d=JSON.stringify(o)!==JSON.stringify(W(e)),f=G(o),p=e=>a.mutate({...q(o),...e!==void 0&&{enabled:e}},{onSuccess:r=>{l([]),s(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>l(Y(e,o,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:a.isPending,canSave:f,onToggle:e=>p(e),problems:c}),(0,I.jsx)(ne,{saved:e,draft:o,patch:u}),(0,I.jsx)(ie,{draft:o,patch:u}),(0,I.jsx)(ae,{draft:o,patch:u}),!f&&(0,I.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[d&&(0,I.jsx)(i,{variant:`plain`,onClick:()=>s(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(i,{variant:`primary`,disabled:!d||!f,loading:a.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:a,problems:o}){let{t:s}=r(),{toast:c}=D(),{status:u}=e,d=async e=>{await w.copy(e)&&c(s(`common.copied`))},f=(0,F.useRef)(null);return(0,F.useEffect)(()=>{o.length>0&&f.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[o]),(0,I.jsxs)(l,{title:s(`smartRouting.status`),footer:s(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:s(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(v,{tone:e.enabled?u.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?u.breakerOpen?s(`smartRouting.state.breaker`):`${s(`smartRouting.state.on`)}${u.pins>0?` · ${s(`smartRouting.state.pins`,{count:u.pins})}`:``}`:s(`smartRouting.state.off`)]}),children:(0,I.jsx)(p,{checked:e.enabled,label:s(`smartRouting.enable`),disabled:t||!n,onChange:a})}),e.enabled&&(0,I.jsxs)(z,{label:s(`smartRouting.use`),detail:s(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(A,{className:`size-3.5`}),"aria-label":s(`common.copy`),onClick:()=>void d(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),o.length>0&&(0,I.jsx)(`div`,{ref:f,className:`px-3 py-2`,children:(0,I.jsx)(C,{tone:`danger`,title:s(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:o.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:e}){let{t,locale:n}=r(),i=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=i.outcomes.judge??0,c=Object.entries(i.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=i.total-s,u=[t(`smartRouting.recent.judged`,{count:s,total:i.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...i.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:i.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:i.total===0?t(`smartRouting.recent.none`):u}),l>=2&&l*2>i.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(C,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in d?f:`smartRouting.recent.hint.other`)}),i.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(i.lastFallback,t),time:y(i.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(C,{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),i={count:e.count,time:y(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:N(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`,{...i,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,i)]}),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:i}){let{t:a}=r(),s=H(t.protocol,t.baseUrl),u=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)(l,{title:a(`smartRouting.judge.title`),footer:a(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:a(`smartRouting.judge.protocol`),detail:a(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(m,{ariaLabel:a(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>i({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:a(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:a(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(C,{tone:`warning`,title:a(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:a(`smartRouting.judge.service`),children:(0,I.jsx)(E,{className:`w-52`,ariaLabel:a(`smartRouting.judge.service`),value:s,onChange:e=>{if(e===`custom`)return i({baseUrl:t.baseUrl||`https://`});let n=B[t.protocol].find(t=>t.id===e);n&&i({baseUrl:n.baseUrl,...n.model!==void 0&&{model:n.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:a(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:a(`smartRouting.preset.custom`)}]})}),s===`custom`&&(0,I.jsx)(z,{label:a(`smartRouting.judge.baseUrl`),detail:a(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(o,{className:`w-72`,mono:!0,"aria-label":a(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>i({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:a(`smartRouting.judge.apiKey`),detail:u?a(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?a(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):a(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(o,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":a(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!u?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>i({apiKey:e.target.value})})}),u&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(C,{tone:`warning`,title:a(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:a(`smartRouting.judge.model`),detail:a(`smartRouting.judge.modelHint`),children:(0,I.jsx)(o,{className:`w-72`,mono:!0,"aria-label":a(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>i({model:e.target.value})})}),(0,I.jsx)(z,{label:a(`smartRouting.judge.timeout`),detail:a(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(c,{className:`w-28`,label:a(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>i({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(C,{tone:`info`,title:a(`smartRouting.privacy.title`),children:a(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(C,{tone:`warning`,title:a(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(n,{title:a(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:a(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(h,{rows:4,"aria-label":a(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>i({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:e}){let{t}=r(),n=f(),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)([]),d=()=>{c(null),u([]),n.mutate({text:a,judge:K(e),grades:e.grades},{onSuccess:c,onError:n=>u(Y(n,e,t))})},p=s!==null&&s.latencyMs>s.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,I.jsx)(h,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:a,onChange:e=>o(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(i,{size:`sm`,disabled:a.trim()===``,loading:n.isPending,onClick:d,children:t(`smartRouting.test.run`)})}),l.length>0&&(0,I.jsx)(C,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:l.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),s&&(s.ok?(0,I.jsx)(C,{tone:s.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:s.gradeName??s.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:s.model?t(`smartRouting.test.model`,{model:s.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((s.confidence??0)*100)}),` ·`,` `,s.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:s.latencyMs,limit:s.limitMs}),s.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:s.latencyMs,input:s.inputTokens,output:s.outputTokens,model:s.judgeModel??``})})]})}):(0,I.jsxs)(C,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(s.failure,t)}),children:[s.message,s.failure===`timeout`&&s.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:t}){let{t:n}=r(),s=g(),c=e.grades,u=(n,r=e.fallbackGrade)=>t({grades:n,fallbackGrade:n.some(e=>e.id===r)?r:n[Math.floor(n.length/2)]?.id??``}),d=(e,t)=>u(c.map((n,r)=>r===e?{...n,...t}:n)),f=(e,t)=>{let n=[...c];[n[e],n[e+t]]=[n[e+t],n[e]],u(n)},p=()=>{let e=c.length+1;for(;c.some(t=>t.id===`grade-${e}`);)e++;u([...c,{id:`grade-${e}`,name:``,description:``,model:``}])},m=s.data??[],_=new Set(m.filter((e,t)=>m.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),v=m.map(e=>({value:V(e.providerId,e.id),label:_.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:_.has(e.id)?void 0:e.providerName})),y=e=>{let t=V(e.providerId,e.model);return e.model&&!v.some(e=>e.value===t)?[{value:t,label:n(`smartRouting.grade.unavailable`,{model:e.model})},...v]:v},b=(e,t)=>{let n=t.indexOf(`
2
- `);d(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(l,{title:n(`smartRouting.grades.title`),footer:n(`smartRouting.grades.footer`),children:[c.map((t,r)=>(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:r+1}),(0,I.jsx)(o,{className:`flex-1`,"aria-label":n(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>d(r,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,I.jsx)(a,{tone:`accent`,children:n(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":n(`smartRouting.grade.up`),disabled:r===0,onClick:()=>f(r,-1)}),(0,I.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(O,{className:`size-3.5`}),"aria-label":n(`smartRouting.grade.down`),disabled:r===c.length-1,onClick:()=>f(r,1)}),(0,I.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(M,{className:`size-3.5`}),"aria-label":n(`smartRouting.grade.remove`),disabled:c.length<=L,onClick:()=>u(c.filter((e,t)=>t!==r))})]}),(0,I.jsx)(h,{rows:2,"aria-label":n(`smartRouting.grade.description`),placeholder:n(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>d(r,{description:e.target.value})}),(0,I.jsx)(E,{ariaLabel:n(`smartRouting.grade.model`),placeholder:n(`smartRouting.grade.pickModel`),value:t.model?V(t.providerId,t.model):``,options:y(t),onChange:e=>b(r,e)})]},t.id)),s.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:n(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(i,{size:`sm`,icon:(0,I.jsx)(j,{className:`size-3.5`}),disabled:c.length>=R,onClick:p,children:n(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:i}=r();return(0,I.jsxs)(l,{title:i(`smartRouting.rules.title`),footer:i(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:i(`smartRouting.rules.mode`),detail:i(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(m,{ariaLabel:i(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:i(`smartRouting.rules.mode.session`)},{value:`turn`,label:i(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:i(`smartRouting.rules.ttl`),detail:i(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(c,{className:`w-28`,label:i(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:i(`smartRouting.rules.fallback`),detail:i(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(E,{className:`w-44`,ariaLabel:i(`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:i(`smartRouting.rules.minConfidence`),detail:i(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(c,{className:`w-28`,label:i(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:i(`smartRouting.rules.contextTurns`),detail:i(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(c,{className:`w-28`,label:i(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:i(`smartRouting.rules.maxChars`),detail:i(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(c,{className:`w-28`,label:i(`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)(n,{title:i(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:i(`smartRouting.rules.virtualModel`),detail:i(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(o,{className:`w-56`,mono:!0,"aria-label":i(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=r();return(0,I.jsx)(P,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{Bn as n,C as r,D as i,E as a,F as o,H as s,Kr as c,L as l,M as u,Mi as d,N as f,V as p,Vr as m,Xt as h,Yt as g,ai as _,c as v,cn as y,d as b,ea as ee,j as x,ji as S,l as C,p as w,qr as T,r as E,u as D,vo as O,wr as k,x as A,zi as j}from"./format-ox0oJ51_.js";import{B as te,H as M,R as N,U as P,V as F,W as I}from"./TrayTitleSource-CNflSYSn.js";import{t as ne}from"./chart-column-TQVFilUc.js";import{t as re}from"./chevron-right-Bgtn3ze-.js";import{t as ie}from"./copy-48gwhhDO.js";import{t as ae}from"./ellipsis-CidyZaW2.js";import{t as L}from"./key-round-m9ps8ZDi.js";import{t as R}from"./link-2-BtBtZbXv.js";import{t as oe}from"./pencil-CpF9MxGZ.js";import{t as z}from"./plus-c3HzV6VX.js";import{t as se}from"./power-BZC18Gj2.js";import{t as ce}from"./rotate-ccw-fsXoCwyv.js";import{t as le}from"./scroll-text-DjXe21uH.js";import{t as ue}from"./square-terminal-pyhtjn4S.js";import{t as B}from"./trash-BHBJn5GS.js";import{t as de}from"./user-plus-Bsk_v4UF.js";import{H as V,S as H,a as fe,b as U,u as W,v as G}from"./index-BmgQHUbu.js";import{a as pe,i as K,n as q,r as J,t as Y}from"./TokenPoolEditor-BraT_TLt.js";var X=e(t(),1),Z=O(),Q=[15,60,1440];function me({token:e,open:t,onOpenChange:n}){let{t:o,locale:s}=r(),{toast:c}=I(),[l,u]=(0,X.useState)(15),[d,f]=(0,X.useState)(null),m=S(e.id,t),g=h(e.id),_=T(e.id),v=e=>e<60?o(`tokens.invite.minutes`,{n:e}):o(`tokens.invite.hours`,{n:e/60}),y=()=>g.mutate(l,{onSuccess:async e=>{f(e.link),c(await N.copy(e.link)?o(`tokens.invite.copied`):o(`tokens.copyFailed`),`success`)},onError:e=>c(P(e),`error`)}),b=e=>e===`pending`?`accent`:e===`used`?`green`:`neutral`;return(0,Z.jsx)(M,{open:t,onOpenChange:e=>{e||f(null),n(e)},title:o(`tokens.invite.title`,{name:e.name}),description:o(`tokens.invite.description`),footer:(0,Z.jsx)(i,{variant:`primary`,icon:(0,Z.jsx)(R,{className:`size-3.5`}),loading:g.isPending,onClick:y,children:o(`tokens.invite.generate`)}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.invite.lifetime`)}),(0,Z.jsx)(p,{items:Q.map(e=>({value:String(e),label:v(e)})),value:String(l),onChange:e=>u(Number(e)),ariaLabel:o(`tokens.invite.lifetime`)})]}),d&&(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.invite.linkOnce`)}),(0,Z.jsx)(`code`,{className:`selectable break-all rounded-lg bg-[var(--surface-muted)] px-3 py-2 font-mono text-[11.5px]`,children:d})]}),(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.invite.recent`)}),(m.data??[]).length===0?(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.invite.none`)}):(0,Z.jsx)(`ul`,{className:`grid gap-1.5`,children:(m.data??[]).map(e=>(0,Z.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 rounded-lg border border-[var(--border)] px-3 py-2 text-[12px]`,children:[(0,Z.jsx)(a,{tone:b(e.status),children:o(`tokens.invite.status.${e.status}`)}),(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:e.status===`used`?o(`tokens.invite.usedAt`,{time:E(e.usedAt,s),ip:e.usedIp??`—`}):o(`tokens.invite.expires`,{time:E(e.expiresAt,s)})}),e.status===`pending`&&(0,Z.jsx)(i,{size:`sm`,variant:`plain`,className:`ml-auto`,loading:_.isPending&&_.variables===e.id,onClick:()=>_.mutate(e.id,{onError:e=>c(P(e),`error`)}),children:o(`tokens.invite.revoke`)})]},e.id))})]})]})})}function he(){let{t:e}=r(),t=d(),n=_(),a=j(),o=a.data?.state===`connected`?a.data.publicUrl:null,[c,l]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null);return(0,Z.jsxs)(G,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Z.jsx)(i,{variant:`primary`,icon:(0,Z.jsx)(z,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`tokens.add`)}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Z.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),o&&(0,Z.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${o}/v1`,key:`${o}/key`})})]}),t.isLoading&&(0,Z.jsx)(s,{lines:4}),t.isError&&(0,Z.jsx)(A,{tone:`danger`,title:e(`common.error`),children:P(t.error)}),t.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(u,{icon:(0,Z.jsx)(L,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Z.jsx)(ge,{token:e,defaultOpen:t.data.length===1,onEdit:()=>p(e)},e.id))})]}),(0,Z.jsx)(xe,{open:c,onOpenChange:l}),(0,Z.jsx)(Se,{token:f,onClose:()=>p(null)})]})}function ge({token:e,defaultOpen:t,onEdit:n}){let{t:o,locale:s}=r(),{toast:l,confirm:u}=I(),d=k(),f=_(),p=c(),h=ee(),g=m(),v=y(),[b,S]=(0,X.useState)(t),T=fe(`token.row`,{tokenId:e.id}),O=(d.data??[]).find(t=>t.id===e.providerId),A=pe(),j=`token-detail-${e.id}`,M=(e,t)=>{l(t,`success`),e.skipped.length>0&&l(o(`tokens.skipped`,{clients:e.skipped.map(e=>U[e]?.name??e).join(`, `)}),`error`)},F=()=>p.mutate(e.id,{onSuccess:async({token:e})=>{await N.copy(e)?l(o(`tokens.copied`)):l(o(`tokens.copyFailed`),`error`)},onError:e=>l(P(e),`error`)}),[L,z]=(0,X.useState)(!1),W=async()=>{let e=f.data?.gatewayBaseUrl;e&&(await N.copy(`${e}/v1`)?l(o(`tokens.urlCopied`)):l(o(`tokens.copyFailed`),`error`))},G=async()=>{let e=f.data?.gatewayBaseUrl;e&&(await N.copy(`npx @aidotnet/astra-connect join ${e}`)?l(o(`tokens.joinCopied`)):l(o(`tokens.copyFailed`),`error`))},K=async()=>{(!e.enabled||await u({title:o(`tokens.disableConfirm`,{name:e.name}),detail:o(`tokens.disableDetail`),confirmLabel:o(`tokens.disable`),destructive:!0}))&&h.mutate({id:e.id,enabled:!e.enabled},{onError:e=>l(P(e),`error`)})},J=async()=>{await u({title:o(`tokens.resetConfirm`,{name:e.name}),detail:o(`tokens.resetDetail`),confirmLabel:o(`tokens.reset`),destructive:!0})&&g.mutate(e.id,{onSuccess:e=>M(e,o(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>l(P(e),`error`)})},Y=async()=>{await u({title:o(`tokens.deleteConfirm`,{name:e.name}),detail:o(`tokens.deleteDetail`),confirmLabel:o(`common.delete`),destructive:!0})&&v.mutate(e.id,{onSuccess:t=>M(t,o(`tokens.deleted`,{name:e.name})),onError:e=>l(P(e),`error`)})},Q=e.lastUsedAt?E(e.lastUsedAt,s):o(`tokens.neverUsed`);return(0,Z.jsxs)(`article`,{children:[(0,Z.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>S(e=>!e),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":b,"aria-controls":j,"aria-label":o(`tokens.details`),onClick:e=>{e.stopPropagation(),S(e=>!e)},children:(0,Z.jsx)(re,{className:`size-4 transition-transform ${b?`rotate-90`:``}`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Z.jsx)(a,{tone:`accent`,children:o(`tokens.default`)}),!e.enabled&&(0,Z.jsx)(a,{tone:`orange`,children:o(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Z.jsx)(a,{tone:`orange`,children:o(`tokens.limitExhausted`)}),e.pool&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Z.jsx)(a,{children:o(`tokens.pool.summary`,{count:e.pool.members.length,strategy:o(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Z.jsx)(x,{tone:q(e.health.state)},e.providerId))]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Z.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ie,{className:`size-3.5`}),"aria-label":o(`tokens.copy`),title:o(`tokens.copy`),loading:p.isPending,onClick:F}),(0,Z.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(R,{className:`size-3.5`}),"aria-label":o(`tokens.copyUrl`),title:o(`tokens.copyUrl`),disabled:!f.data,onClick:()=>void W()}),(0,Z.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ue,{className:`size-3.5`}),"aria-label":o(`tokens.copyJoin`),title:o(`tokens.copyJoin`),disabled:!f.data,onClick:()=>void G()}),(0,Z.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(de,{className:`size-3.5`}),"aria-label":o(`tokens.invite.open`),title:o(`tokens.invite.open`),disabled:!e.enabled,onClick:()=>z(!0)}),(0,Z.jsx)(me,{token:e,open:L,onOpenChange:z})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>U[e]?.name??e).join(`, `)||o(`tokens.noClients`),children:e.clients.length===0?(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Z.jsx)(H,{kind:e,size:16},e))}),(0,Z.jsx)($,{label:o(`tokens.today`),value:w(e.today.costUsd),context:o(`tokens.requestsContext`,{count:D(e.today.requests)})}),(0,Z.jsx)($,{label:o(`tokens.total`),value:w(e.total.costUsd),context:`${D(e.total.totalTokens,!0)} Token`}),(0,Z.jsx)($,{label:o(`tokens.lastUsedTitle`),value:e.lastUsedAt?C(e.lastUsedAt,s):`—`,context:e.lastUsedAt?``:o(`tokens.neverUsed`),title:Q}),(0,Z.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(te,{label:o(`common.more`),icon:(0,Z.jsx)(ae,{className:`size-4`}),items:[{id:`settings`,label:o(`tokens.settings`),icon:(0,Z.jsx)(oe,{className:`size-3.5`}),onSelect:n},{id:`toggle`,label:e.enabled?o(`tokens.disable`):o(`tokens.enable`),icon:(0,Z.jsx)(se,{className:`size-3.5`}),onSelect:()=>void K()},{id:`reset`,label:o(`tokens.reset`),icon:(0,Z.jsx)(ce,{className:`size-3.5`}),onSelect:()=>void J()},...T,...e.isDefault?[]:[{id:`delete`,label:o(`tokens.delete`),icon:(0,Z.jsx)(B,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void Y()}]]})})]}),b&&(0,Z.jsxs)(`div`,{id:j,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Z.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.clients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?o(`tokens.noClients`):e.clients.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(H,{kind:e,size:14}),U[e]?.name??e]},e))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?o(`tokens.pool.title`):o(`tokens.directProvider`)}),e.pool?(0,Z.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:A(e.health),children:[(0,Z.jsx)(x,{tone:q(e.health.state)}),(d.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:O?.name??(e.providerId?e.providerId:o(`tokens.directNone`))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.allowedClients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?o(`tokens.allowedClientsAny`):e.allowedClients.length===0?o(`tokens.directOnly`):e.allowedClients.map(e=>U[e]?.name??e).join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:o(`tokens.lastUsedTitle`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:Q})]})]}),(0,Z.jsx)(_e,{token:e}),(0,Z.jsx)(ye,{today:e.today,total:e.total}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Z.jsx)(V,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(i,{size:`sm`,icon:(0,Z.jsx)(ne,{className:`size-3.5`}),children:o(`tokens.detail.open`)})}),(0,Z.jsx)(V,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(i,{size:`sm`,icon:(0,Z.jsx)(le,{className:`size-3.5`}),children:o(`tokens.detail.viewLogs`)})})]})]})]})}function _e({token:e}){let{t}=r(),n=e.limits?.rpm;return(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Z.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Z.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Z.jsx)(ve,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Z.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function ve({usage:e}){let{t,locale:n}=r(),i=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,a=t=>e.metric===`cost`?w(t):D(t,!0),o=Math.max(0,Math.min(100,Math.round(e.usedPercent))),s=o>=90?`var(--danger)`:o>=70?`var(--warning)`:`var(--accent)`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.limitUsed`,{used:a(e.used),limit:a(e.limit)})})]}),(0,Z.jsx)(`div`,{role:`progressbar`,"aria-valuenow":o,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${o}%`,background:s}})}),e.resetsAt&&(0,Z.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:t(`tokens.limitResets`,{time:E(e.resetsAt,n)})})]})}function $({label:e,value:t,context:n,title:r}){return(0,Z.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function ye({today:e,total:t}){let{t:n}=r(),i=[[n(`tokens.today`),e],[n(`tokens.total`),t]],a=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,o=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,Z.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Z.jsx)(`th`,{className:`${a} text-left`}),(0,Z.jsx)(`th`,{className:a,children:n(`tokens.cost`)}),(0,Z.jsx)(`th`,{className:a,children:n(`tokens.requests`)}),(0,Z.jsx)(`th`,{className:a,children:n(`tokens.tokens`)}),(0,Z.jsx)(`th`,{className:a,children:n(`tokens.inOut`)}),(0,Z.jsx)(`th`,{className:a,children:n(`tokens.cacheHit`)}),(0,Z.jsx)(`th`,{className:a,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Z.jsx)(`tbody`,{children:i.map(([e,t])=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`${o} font-semibold selectable`,children:w(t.costUsd)}),(0,Z.jsx)(`td`,{className:o,children:D(t.requests)}),(0,Z.jsx)(`td`,{className:o,children:D(t.totalTokens,!0)}),(0,Z.jsxs)(`td`,{className:`${o} text-[var(--text-secondary)]`,children:[D(t.inputTokens,!0),` / `,D(t.outputTokens,!0)]}),(0,Z.jsx)(`td`,{className:o,title:n(`usage.cacheAmounts`,{read:D(t.cacheReadTokens,!0),write:D(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:v(t.cacheHitRate)}),(0,Z.jsx)(`td`,{className:o,children:t.tps==null?`—`:b(t.tps)})]},e))})]})})}function be(){let{t:e}=r(),t=(k().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function xe({open:e,onOpenChange:t}){let{t:n}=r(),{toast:a}=I(),s=g(),{options:c}=be(),[l,u]=(0,X.useState)(``),[d,p]=(0,X.useState)(``);return(0,X.useEffect)(()=>{e&&(u(``),p(``))},[e]),(0,Z.jsx)(M,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(i,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Z.jsx)(i,{variant:`primary`,disabled:!l.trim(),loading:s.isPending,onClick:()=>s.mutate({name:l.trim(),providerId:d||null},{onSuccess:e=>{t(!1),a(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>a(P(e),`error`)}),children:n(`common.create`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(f,{label:n(`tokens.name`),children:(0,Z.jsx)(o,{value:l,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>u(e.target.value)})}),(0,Z.jsx)(f,{label:n(`tokens.directProvider`),children:(0,Z.jsx)(F,{value:d,onChange:p,options:c})})]})})}function Se({token:e,onClose:t}){let{t:a}=r(),{toast:s}=I(),c=ee(),u=k(),d=n(),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)([]),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)([]),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(`any`),[E,D]=(0,X.useState)([]),O=new Set(b.map(e=>`${e.metric}:${e.period}`)).size<b.length,A=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,X.useEffect)(()=>{e&&(h(e.name),y(J(e)),x(e.limits?.budgets.map(e=>({...e}))??[]),C(e.limits?.rpm??null),T(e.allowedClients==null?`any`:`only`),D(e.allowedClients??[]),_(e.mcpServers??[]))},[e]),(0,Z.jsx)(M,{open:e!==null,onOpenChange:e=>!e&&t(),title:a(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(i,{onClick:t,children:a(`common.cancel`)}),(0,Z.jsx)(i,{variant:`primary`,disabled:!m.trim()||O,loading:c.isPending,onClick:()=>{if(!e)return;let n=b.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),r=n.length>0||S!=null&&S>0?{budgets:n,rpm:S!=null&&S>0?Math.floor(S):null}:null;c.mutate({id:e.id,name:m.trim(),...v?{pool:K(v,u.data??[])}:{},limits:r,allowedClients:w===`any`?null:E,...d.data?{mcpServers:g.filter(e=>d.data.some(t=>t.id===e))}:{}},{onSuccess:()=>{t(),s(a(`common.saved`),`success`)},onError:e=>s(P(e),`error`)})},children:a(`common.save`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(f,{label:a(`tokens.name`),children:(0,Z.jsx)(o,{value:m,maxLength:64,onChange:e=>h(e.target.value)})}),(0,Z.jsx)(f,{label:a(`tokens.pool.title`),hint:a(`tokens.pool.hint`),children:v&&(0,Z.jsx)(Y,{draft:v,onChange:y,providers:u.data??[],health:A})}),(0,Z.jsx)(f,{label:a(`tokens.limits`),hint:a(`tokens.limitsHint`),error:O?a(`tokens.limitDuplicate`):void 0,children:(0,Z.jsx)(Te,{budgets:b,onChange:x})}),(0,Z.jsx)(f,{label:a(`tokens.rpm`),hint:a(`tokens.rpmHint`),children:(0,Z.jsx)(l,{value:S,min:1,step:1,label:a(`tokens.rpm`),placeholder:a(`tokens.unlimited`),onChange:C})}),(0,Z.jsx)(f,{label:a(`tokens.mcp`),hint:d.data&&d.data.length===0?a(`tokens.mcpNone`):a(`tokens.mcpHint`),children:d.data&&d.data.length>0&&(0,Z.jsx)(W,{label:a(`tokens.mcp`),options:d.data.map(e=>({value:e.id,label:e.name})),value:g.filter(e=>d.data.some(t=>t.id===e)),onValueChange:e=>_(e)})}),(0,Z.jsx)(f,{label:a(`tokens.allowedClients`),hint:a(`tokens.allowedClientsHint`),children:(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(p,{ariaLabel:a(`tokens.allowedClients`),value:w,onChange:T,items:[{value:`any`,label:a(`tokens.allowedClientsAny`)},{value:`only`,label:a(`tokens.allowedClientsOnly`)}]}),w===`only`&&(0,Z.jsx)(W,{label:a(`tokens.allowedClients`),options:[...new Set([...Object.keys(U),...E])].map(e=>({value:e,label:U[e]?.name??e})),value:E,onValueChange:e=>D(e)})]})})]})})}var Ce=[`cost`,`requests`,`tokens`],we=[`day`,`week`,`month`,`total`];function Te({budgets:e,onChange:t}){let{t:n}=r(),a=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),o=Ce.flatMap(e=>we.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((r,o)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:r.metric,onChange:e=>a(o,{metric:e}),options:Ce.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:r.period,onChange:e=>a(o,{period:e}),options:we.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Z.jsx)(l,{label:n(`tokens.limitValue`),value:r.limit,min:0,step:r.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>a(o,{limit:e})}),(0,Z.jsx)(i,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(B,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),o&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(i,{size:`sm`,icon:(0,Z.jsx)(z,{className:`size-3.5`}),onClick:()=>t([...e,{...o,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{he as TokensPage};