@aidotnet/server-linux-x64 0.14.3101 → 0.14.3103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/astra-server +2 -2
- package/bin/wwwroot/assets/ClientsPage-CbisrdvY.js +9 -0
- package/bin/wwwroot/assets/KeyPage-BJkqoRws.js +1 -0
- package/bin/wwwroot/assets/McpPage-lDbAQFBD.js +3 -0
- package/bin/wwwroot/assets/ModelDetailPage-2SDue3md.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-Djwi1_69.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-Cr3_QueY.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-K20lHsrR.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-dCLgz9IA.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-B3UD_FXO.js +3 -0
- package/bin/wwwroot/assets/SettingsPage-BOv88_uQ.js +2 -0
- package/bin/wwwroot/assets/SmartRoutingPage-DUdAF-mO.js +2 -0
- package/bin/wwwroot/assets/TokenDetailPage-DAFuMypb.js +1 -0
- package/bin/wwwroot/assets/{TokenPoolEditor-DfmDnnxw.js → TokenPoolEditor-CGc4q0xj.js} +1 -1
- package/bin/wwwroot/assets/TokensPage-BAszgNt-.js +1 -0
- package/bin/wwwroot/assets/TracesPage-zR4Nhppl.js +8 -0
- package/bin/wwwroot/assets/{TrayPanelPage-xke1V9tu.js → TrayPanelPage-BzWJbHrV.js} +1 -1
- package/bin/wwwroot/assets/TrayPanelView-C8TTq4KZ.js +1 -0
- package/bin/wwwroot/assets/alert-BKRTQ9va.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-DeIGdMUk.js → arrow-down-4QyszMPK.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-DX1c-nYY.js → arrow-left-CgusYKe5.js} +1 -1
- package/bin/wwwroot/assets/{arrow-up-right-D--u8dK5.js → arrow-up-right-CgKLuRMO.js} +1 -1
- package/bin/wwwroot/assets/{chart-column-zt3ZRFLH.js → chart-column-DrO0zSNb.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-BJe8ekJy.js → checkbox-JghCvxwP.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-DWw6s5ag.js → cloud-download-Cq6X58YR.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-bdMiffHC.js +1 -0
- package/bin/wwwroot/assets/{ellipsis-BH_FL485.js → ellipsis-C09AxsS6.js} +1 -1
- package/bin/wwwroot/assets/{external-link-Bb6sx3jt.js → external-link-B54WZqyE.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-Bcx5mAII.js → folder-open-DbnPnrzj.js} +1 -1
- package/bin/wwwroot/assets/index-8z9hfQDF.css +1 -0
- package/bin/wwwroot/assets/index-Cj8lNw6g.js +120 -0
- package/bin/wwwroot/assets/{log-out-Ch09k2bC.js → log-out-ZnLW7wzx.js} +1 -1
- package/bin/wwwroot/assets/minus-DosBdkUl.js +1 -0
- package/bin/wwwroot/assets/overlays-CizKmvVN.js +41 -0
- package/bin/wwwroot/assets/{pencil-fY6CohHT.js → pencil-BuVygJ9-.js} +1 -1
- package/bin/wwwroot/assets/{power-B9MMcl6Y.js → power-CfEiSxDi.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-6WsHN05O.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-DsmSscuv.js → rotate-ccw-BhDSBCvo.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-CO34h2h7.js → sortable.esm-4hCCGHPl.js} +1 -1
- package/bin/wwwroot/index.html +4 -4
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-BsCvaS4d.js +0 -9
- package/bin/wwwroot/assets/KeyPage-bkK0B_mk.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-BEVSPYM6.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-BGij6zvC.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-dVUvE8Lf.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-B-YBfQ6J.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-CQQdpDSf.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-BwigLnKs.js +0 -3
- package/bin/wwwroot/assets/SettingsPage-CvpROKS2.js +0 -2
- package/bin/wwwroot/assets/SmartRoutingPage-CYh7mRot.js +0 -2
- package/bin/wwwroot/assets/TokenDetailPage-GwSz8QI6.js +0 -1
- package/bin/wwwroot/assets/TokensPage-0hOOzLVU.js +0 -1
- package/bin/wwwroot/assets/TracesPage-A45sREZP.js +0 -8
- package/bin/wwwroot/assets/TrayPanelView-CHh9-E76.js +0 -1
- package/bin/wwwroot/assets/alert-CuKAE1Sv.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-DGAHV4QP.js +0 -1
- package/bin/wwwroot/assets/download-DR9BLMVt.js +0 -1
- package/bin/wwwroot/assets/index-CKrvKDIJ.js +0 -17
- package/bin/wwwroot/assets/index-CpGX4nAj.css +0 -1
- package/bin/wwwroot/assets/minus-UfPYsFrp.js +0 -1
- package/bin/wwwroot/assets/overlays-DeHu6TU_.js +0 -41
- package/bin/wwwroot/assets/radio-cards-Rq9vGqnw.js +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{$n as e,Ba as t,Dn as n,E as r,En as i,G as a,Ha as o,Ji as s,Ki as c,Mi as l,Q as u,Ra as d,Ua as f,Y as p,Yi as m,Zi as h,Zr as g,_,b as v,c as y,ct as b,d as x,dt as S,h as C,kt as w,l as T,lr as ee,n as E,o as te,or as ne,ot as D,p as O,q as k,qi as re,qr as A,r as j,s as M,sr as N,t as P,ti as F,tn as ie,v as ae,vi as I,w as oe,xt as L,y as R,yt as z,za as B}from"./alert-CuKAE1Sv.js";import{a as V,at as H,et as se,i as ce,it as U,o as le,ot as ue,r as W,ut as de}from"./overlays-DeHu6TU_.js";import{t as fe}from"./arrow-left-DX1c-nYY.js";import{t as pe}from"./chart-column-zt3ZRFLH.js";import{t as G}from"./download-DR9BLMVt.js";import{n as K,t as me}from"./radio-cards-Rq9vGqnw.js";import{$ as he,B as q,D as ge,L as _e,M as J,P as ve,X as ye,g as be,h as xe,k as Se,s as Ce,tt as we,x as Te,z as Ee}from"./index-CKrvKDIJ.js";import{t as De}from"./checkbox-BJe8ekJy.js";var Oe={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};Oe.node;var ke=L(Oe),Ae={name:`image-plus`,size:24,node:[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]};Ae.node;var je=L(Ae),Me={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Me.node;var Ne=L(Me),Y={root:`_root_1cea8_1`,horizontal:`_horizontal_1cea8_3`,list:`_list_1cea8_4`,item:`_item_1cea8_5`,vertical:`_vertical_1cea8_7`,compact:`_compact_1cea8_8`,head:`_head_1cea8_11`,marker:`_marker_1cea8_20`,ring:`_ring_1cea8_21`,disc:`_disc_1cea8_22`,glyph:`_glyph_1cea8_23`,icon:`_icon_1cea8_24`,connector:`_connector_1cea8_31`,fill:`_fill_1cea8_35`,text:`_text_1cea8_40`,label:`_label_1cea8_43`,slot:`_slot_1cea8_47`,slotInner:`_slotInner_1cea8_48`,description:`_description_1cea8_49`,error:`_error_1cea8_49`,caption:`_caption_1cea8_53`,captionLabel:`_captionLabel_1cea8_54`,srOnly:`_srOnly_1cea8_63`},X=f(t(),1),Z=B(),Pe=e=>`blur(${e}px)`,Q={duration:0},Fe={duration:r.duration.fast,ease:[...r.ease.standard]},Ie={duration:r.duration.standard,ease:[...r.ease.enter]},Le={opacity:0,y:`0.3em`,filter:Pe(r.blur.soft)},Re={opacity:1,y:0,filter:Pe(0)},ze={opacity:0,y:`-0.3em`,filter:Pe(r.blur.subtle)},Be={opacity:0,scale:.5,filter:Pe(r.blur.subtle)},Ve={opacity:1,scale:1,filter:Pe(0)};function He({text:e,className:t,reduced:n}){let i=(0,X.useRef)(null),a=(0,X.useRef)(0),o=m(`auto`);return(0,X.useLayoutEffect)(()=>{a.current=performance.now()+700},[e]),(0,X.useEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let s=!1,c=new ResizeObserver(()=>{let t=e.offsetHeight;if(!s||n||performance.now()>a.current){s=!0,o.jump(t);return}re(o,t,r.spring.smooth)});return c.observe(e),()=>c.disconnect()},[o,n]),(0,Z.jsx)(c.span,{className:Y.slot,style:{height:o},children:(0,Z.jsx)(`span`,{ref:i,className:Y.slotInner,children:(0,Z.jsx)(h,{mode:`popLayout`,initial:!1,children:e?(0,Z.jsx)(c.span,{className:t,initial:Le,animate:Re,exit:{...ze,transition:n?Q:Fe},transition:n?Q:Ie,children:e},`${t}:${e}`):null})})})}function Ue({kind:e,number:t,delay:n,reduced:i}){let a=i?Q:{scale:{...r.spring.snappy,delay:n},opacity:{duration:r.duration.fast,delay:n},filter:{duration:r.duration.fast,delay:n}},o={...Be,transition:i?Q:Fe},s=i?Q:{duration:r.duration.standard,ease:r.ease.enter,delay:n+.04};return e===`number`?(0,Z.jsx)(c.span,{className:Y.glyph,initial:Be,animate:Ve,exit:o,transition:a,children:t}):(0,Z.jsx)(c.svg,{className:`${Y.glyph} ${Y.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:Be,animate:Ve,exit:o,transition:a,children:e===`check`?(0,Z.jsx)(c.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:s}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(c.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,Z.jsx)(c.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Q:{...r.spring.snappy,delay:n+.16}})]})})}function We({number:e,kind:t,current:n,glyphDelay:i,ringDelay:a,reduced:o}){return(0,Z.jsxs)(`span`,{className:Y.marker,"aria-hidden":`true`,children:[(0,Z.jsx)(h,{initial:!1,children:n?(0,Z.jsx)(c.span,{className:Y.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?Q:Fe},transition:o?Q:{scale:{...r.spring.snappy,delay:a},opacity:{duration:r.duration.fast,delay:a}}},`ring`):null}),(0,Z.jsx)(`span`,{className:Y.disc,children:(0,Z.jsx)(h,{initial:!1,children:(0,Z.jsx)(Ue,{kind:t,number:e,delay:i,reduced:o},t)})})]})}var Ge={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Ke({steps:e,current:t,orientation:n=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:l=`Progress`,completeLabel:u=`All steps complete`,className:d}){let f=s()??!1,p=e.length,m=Math.min(Math.max(Math.round(t),0),p),[h,g]=(0,X.useState)({to:m,from:m});h.to!==m&&g({to:m,from:h.to});let _=h.from,v=r.stagger.line,y=e=>f?0:m>_?e>=_&&e<m?(e-_)*v:0:e>=m&&e<_?(_-1-e)*v:0,b=f?0:Math.max(0,Math.abs(m-_)-1)*v+.12,x=!!i,S=n===`vertical`,C=m>=p?void 0:e[m];function w(e){let t=!S&&getComputedStyle(e.currentTarget).direction===`rtl`,n=[`ArrowUp`,t?`ArrowRight`:`ArrowLeft`],r=[`ArrowDown`,t?`ArrowLeft`:`ArrowRight`];if(![...n,...r,`Home`,`End`].includes(e.key))return;let i=Array.from(e.currentTarget.querySelectorAll(`button[data-reachable]`)),a=i.indexOf(e.target);a<0||(e.preventDefault(),i[e.key===`Home`?0:e.key===`End`?i.length-1:n.includes(e.key)?Math.max(0,a-1):Math.min(i.length-1,a+1)]?.focus())}let T=x?`nav`:`div`,ee=[Y.root,S?Y.vertical:Y.horizontal,o?Y.compact:``,d].filter(Boolean).join(` `);return(0,Z.jsxs)(T,{className:ee,"aria-label":l,role:x?void 0:`group`,children:[(0,Z.jsx)(`ol`,{className:Y.list,style:S?void 0:{gridTemplateColumns:p>1?`repeat(${p-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:x?w:void 0,children:e.map((e,t)=>{let o=t===m,s=e.error?`error`:t<m?`complete`:o?`current`:`upcoming`,l=x&&t<m,u=e.error??(a===`all`||o?e.description:void 0),d=e.error?`error`:t<m?`check`:`number`,h=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(We,{number:t+1,kind:d,current:o,glyphDelay:y(t),ringDelay:b,reduced:f}),(0,Z.jsxs)(`span`,{className:Y.text,children:[(0,Z.jsx)(`span`,{className:Y.label,children:e.label}),Ge[s]?(0,Z.jsxs)(`span`,{className:Y.srOnly,children:[`, `,Ge[s]]}):null,(0,Z.jsx)(He,{text:u,className:e.error?Y.error:Y.description,reduced:f})]})]});return(0,Z.jsxs)(`li`,{className:Y.item,"data-status":s,children:[t<p-1?(0,Z.jsx)(`span`,{className:Y.connector,"aria-hidden":`true`,children:(0,Z.jsx)(c.span,{className:Y.fill,initial:!1,animate:S?{scaleY:+(t<m)}:{scaleX:+(t<m)},transition:f?Q:{...r.spring.smooth,delay:y(t)}},n)}):null,x?(0,Z.jsx)(`button`,{type:`button`,className:Y.head,"data-clickable":l||void 0,"data-reachable":t<=m||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!l||void 0,tabIndex:l?void 0:-1,onClick:l?()=>i?.(t):void 0,children:h}):(0,Z.jsx)(`span`,{className:Y.head,"aria-current":o?`step`:void 0,children:h})]},e.id)})}),S?null:(0,Z.jsxs)(`span`,{className:Y.caption,"aria-hidden":`true`,children:[(0,Z.jsx)(He,{text:C?.label??u,className:Y.captionLabel,reduced:f}),(0,Z.jsx)(He,{text:C?.error??C?.description,className:C?.error?Y.error:Y.description,reduced:f})]}),(0,Z.jsx)(`span`,{className:Y.srOnly,"aria-live":`polite`,children:C?`Step ${m+1} of ${p}: ${C.label}`:u})]})}var qe={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Je={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},Ye=e=>`${e.source}\u0000${e.ref}`,Xe=e=>e.status!==`skip`&&e.status!==`same`;function Ze(e){try{return new URL(e).host}catch{return e}}function Qe({open:e,onOpenChange:t}){let{t:r}=b(),{toast:a}=le(),o=n(e),s=i(),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(new Set),[f,p]=(0,X.useState)(null);(0,X.useEffect)(()=>{o.data&&d(new Set(o.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Ye)))},[o.data]),(0,X.useEffect)(()=>{e&&(l(``),p(null))},[e]);let m=c.trim().toLowerCase(),h=e=>!m||e.name.toLowerCase().includes(m)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(m)),g=(0,X.useMemo)(()=>(o.data??[]).flatMap(e=>e.items).filter(e=>u.has(Ye(e))&&Xe(e)),[o.data,u]),_=(e,t)=>d(n=>{let r=new Set(n);return t?r.add(Ye(e)):r.delete(Ye(e)),r});return(0,Z.jsx)(ce,{open:e,onOpenChange:t,width:680,title:r(`import.title`),description:r(`import.detail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{icon:(0,Z.jsx)(Ee,{className:`size-3.5`}),onClick:()=>void o.refetch(),disabled:o.isFetching||s.isPending,children:r(`import.rescan`)}),(0,Z.jsx)(j,{variant:`primary`,disabled:g.length===0||s.isPending,onClick:()=>{p(null),s.mutate(g.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let n=e.skipped.length;a(n>0?r(`import.doneSkipped`,{count:e.added.length,skipped:n}):r(`import.done`,{count:e.added.length})),t(!1)},onError:e=>{p(V(e)),o.refetch()}})},children:r(`import.selected`,{count:g.length})})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(C,{value:c,onChange:l,placeholder:r(`import.search`)}),f&&(0,Z.jsx)(P,{tone:`danger`,title:r(`common.error`),children:f}),o.isLoading&&(0,Z.jsx)(ae,{lines:3}),o.isError&&(0,Z.jsx)(P,{tone:`danger`,title:r(`common.error`),children:V(o.error)}),(0,Z.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:o.data?.map(e=>(0,Z.jsx)($e,{source:e,matches:h,selected:u,onToggle:_,filtering:m.length>0},e.id))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`import.footnote`)})]})})}function $e({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=b(),o=e.items.filter(t);return(0,Z.jsxs)(`section`,{"aria-label":e.name,children:[(0,Z.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:a(`import.path`,{path:e.path}),children:e.path})]}),e.error?(0,Z.jsx)(P,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,Z.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,Z.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,Z.jsx)(et,{c:e,checked:n.has(Ye(e)),onToggle:t=>r(e,t)},Ye(e)))}):(0,Z.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function et({c:e,checked:t,onToggle:n}){let{t:r}=b(),i=Xe(e),a=e.status===`skip`&&e.skipReason?r(`import.skip.${e.skipReason}`):e.status===`same`&&e.existing?r(`import.existing`,{name:e.existing.name}):e.status===`sameHost`&&e.existing?r(`import.sameHostHint`,{name:e.existing.name}):null,o=e.endpoints.map(e=>`${qe[e.protocol]??e.protocol} · ${Ze(e.baseUrl)}`).join(` / `);return(0,Z.jsxs)(`li`,{className:D(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,Z.jsx)(De,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,Z.jsx)(E,{tone:Je[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),o&&(0,Z.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:o,children:o}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),e.models.length>0&&(0,Z.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,Z.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignoredFields.join(`, `)})})]})]})}var tt=`astra.providers.view`,nt=`astra.providers.charts`;function rt(e){try{return localStorage.getItem(e)}catch{return null}}function it(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function at(){let[e,t]=(0,X.useState)(()=>rt(tt)===`table`?`table`:`grid`);return[e,e=>{t(e),it(tt,e===`table`?`table`:null)}]}function ot(){let[e,t]=(0,X.useState)(()=>rt(nt)!==`0`);return[e,e=>{t(e),it(nt,e?null:`0`)}]}var st=5;function ct(e){return!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`}function lt(e,t){return e.enabled?ct(e)?`noKey`:t&&t.requests>=st&&t.successRate<.9?`lowSuccess`:`healthy`:`disabled`}var ut={healthy:`green`,noKey:`orange`,lowSuccess:`red`,disabled:`neutral`};function dt(e,t){return t(e===`disabled`?`providers.card.disabled`:e===`noKey`?`providers.noKey`:e===`lowSuccess`?`providers.card.lowSuccess`:`providers.card.active`)}var ft=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],pt=`var(--text-muted)`;function mt(e){return e>=.97?`var(--success)`:e>=.9?`var(--warning)`:`var(--danger)`}function ht({data:e,labels:t,max:n,className:r}){return(0,Z.jsx)(`span`,{className:D(`flex h-[22px] shrink-0 items-end gap-[2px]`,r),title:e.map((e,n)=>`${t[n]}: ${e}`).join(`
|
|
2
|
-
`),children:e.map((e,t)=>(0,Z.jsx)(`i`,{className:`block w-[6px] rounded-t-[2px]`,style:{height:e>0?`${Math.max(14,Math.sqrt(e/Math.max(1,n))*100)}%`:2,background:e>0?`var(--accent)`:`var(--border)`}},t))})}function gt(e,t,n,r){let i=e.filter(e=>n(e)>0).sort((e,t)=>n(t)-n(e)),a=i.slice(0,ft.length).map((e,r)=>({key:e.providerId,name:t.get(e.providerId)??e.name??e.providerId,value:n(e),color:ft[r]})),o=i.slice(ft.length).reduce((e,t)=>e+n(t),0);return o>0?[...a,{key:`__other`,name:r,value:o,color:pt}]:a}var _t=[`today`,`7d`,`30d`];function vt({providers:e,stats:t,stats7d:n,range:r,chartsOpen:i}){let{t:a}=b(),o=new Map(e.map(e=>[e.id,e.name])),s=t.reduce((e,t)=>e+t.requests,0),c=t.reduce((e,t)=>e+t.successRequests,0),l=t.reduce((e,t)=>e+t.costUsd,0),d=t.reduce((e,t)=>e+t.failoversOut,0),f=e.filter(e=>e.enabled).length,m=t.filter(e=>e.requests>0&&o.has(e.providerId)).length,h=gt(t,o,e=>e.requests,a(`providers.overview.others`)),g=gt(t,o,e=>e.costUsd,a(`providers.overview.others`)),_=h.filter(e=>e.key!==`__other`),v={healthy:0,noKey:0,lowSuccess:0,disabled:0};for(let t of e)v[lt(t,n.get(t.id))]++;let y=a(`range.${r}`);return(0,Z.jsxs)(`div`,{className:`mb-3 grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`card px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,Z.jsx)(yt,{label:a(`providers.overview.requests`),value:p(s,!0),hint:y}),(0,Z.jsx)(yt,{label:a(`providers.overview.cost`),value:u(l),hint:y}),(0,Z.jsx)(yt,{label:a(`providers.overview.successRate`),value:s>0?k(c/s):`—`,color:s>0?mt(c/s):void 0,hint:d>0?a(`providers.overview.failoverCount`,{count:d}):y}),(0,Z.jsx)(yt,{label:a(`providers.overview.enabled`),value:`${f} / ${e.length}`,hint:a(`providers.overview.withTraffic`,{count:m})})]}),i&&h.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`mt-3 flex h-2.5 overflow-hidden rounded-full bg-[var(--border)]`,"aria-label":a(`providers.overview.share`),children:h.map(e=>(0,Z.jsx)(`span`,{className:`h-full border-r border-[var(--surface)] last:border-r-0`,style:{width:`${e.value/s*100}%`,background:e.color},title:`${e.name}: ${e.value} (${k(e.value/s)})`},e.key))}),(0,Z.jsx)(St,{items:h,total:s})]})]}),i&&(0,Z.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1.3fr_1fr_1fr]`,children:[(0,Z.jsx)(bt,{title:a(`providers.overview.ranking`),hint:y,children:_.length===0?(0,Z.jsx)(xt,{text:a(`providers.overview.noData`)}):(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:_.map(e=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[96px_1fr_44px] items-center gap-2 text-[12px]`,children:[(0,Z.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,Z.jsx)(`span`,{className:`h-2 overflow-hidden rounded-full bg-[var(--border)]`,children:(0,Z.jsx)(`i`,{className:`block h-full rounded-full`,style:{width:`${e.value/_[0].value*100}%`,background:e.color}})}),(0,Z.jsx)(`span`,{className:`num text-right text-[var(--text-secondary)]`,children:p(e.value,!0)})]},e.key))})}),(0,Z.jsx)(bt,{title:a(`providers.overview.costShare`),hint:u(l),children:g.length===0?(0,Z.jsx)(xt,{text:a(`providers.overview.noCost`)}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(Ct,{items:g,total:l,label:u(l,{compact:!0})}),(0,Z.jsx)(St,{items:g,total:l,column:!0})]})}),(0,Z.jsx)(bt,{title:a(`providers.overview.health`),hint:a(`range.7d`),children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(wt,{tone:`green`,label:a(`providers.overview.healthy`),value:v.healthy}),(0,Z.jsx)(wt,{tone:`red`,label:a(`providers.overview.lowSuccess`),value:v.lowSuccess}),(0,Z.jsx)(wt,{tone:`orange`,label:a(`providers.noKey`),value:v.noKey}),(0,Z.jsx)(wt,{tone:`neutral`,label:a(`providers.card.disabled`),value:v.disabled})]})})]})]})}function yt({label:e,value:t,hint:n,color:r}){return(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[19px] font-semibold leading-tight`,style:r?{color:r}:void 0,children:t}),n&&(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n})]})}function bt({title:e,hint:t,children:n}){return(0,Z.jsxs)(`div`,{className:`card min-h-[164px] px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-2.5 flex items-center justify-between gap-2 text-[12px]`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:e}),t&&(0,Z.jsx)(`span`,{className:`num text-[var(--text-muted)]`,children:t})]}),n]})}function xt({text:e}){return(0,Z.jsx)(`div`,{className:`grid h-[110px] place-items-center text-[12px] text-[var(--text-muted)]`,children:e})}function St({items:e,total:t,column:n}){return(0,Z.jsx)(`div`,{className:D(`mt-2 flex min-w-0 gap-x-3.5 gap-y-1 text-[11px] text-[var(--text-secondary)]`,n?`mt-0 flex-col`:`flex-wrap`),children:e.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,title:e.name,children:[(0,Z.jsx)(`i`,{className:`size-2 shrink-0 rounded-[2px]`,style:{background:e.color}}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`num shrink-0 text-[var(--text-muted)]`,children:k(e.value/t)})]},e.key))})}function Ct({items:e,total:t,label:n}){let r=0,i=e.map(e=>{let n=r;return r+=e.value/t*360,`${e.color} ${n}deg ${r}deg`}).join(`, `);return(0,Z.jsx)(`div`,{className:`grid size-[104px] shrink-0 place-items-center rounded-full`,style:{background:`conic-gradient(${i})`},children:(0,Z.jsx)(`div`,{className:`num grid size-[70px] place-items-center rounded-full bg-[var(--surface)] text-[12px] font-semibold`,children:n})})}function wt({tone:e,label:t,value:n}){return(0,Z.jsxs)(`div`,{className:`rounded-lg bg-[color-mix(in_oklab,var(--text)_5%,transparent)] px-2.5 py-2`,children:[(0,Z.jsx)(`div`,{className:`num text-[18px] font-semibold leading-tight`,children:n}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(M,{tone:e}),t]})]})}var Tt={lowSuccess:0,noKey:1,healthy:2,disabled:3};function Et({providers:e,stats7d:t,usage:n,labels:r,max:i,onOpen:o}){let{t:s}=b(),c=e.map(e=>{let r=t.get(e.id),i=n(e);return{id:e.id,name:e.name,health:Tt[lt(e,r)],models:e.modelCount,requests:i.reduce((e,t)=>e+t,0),successRate:r&&r.requests>0?r.successRate:-1,ttft:r?.avgTtftMs??-1,tokens:r?r.inputTokens+r.outputTokens:0,cost:r?.costUsd??0,enabled:+!!e.enabled,p:e,stat:r,days:i}}),l=[{key:`name`,label:s(`providers.col.provider`),render:(e,t)=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex w-full min-w-0 items-center gap-2 text-left`,onClick:()=>o(t.p),children:[(0,Z.jsx)(`span`,{className:D(!t.p.enabled&&`opacity-50 grayscale`),children:(0,Z.jsx)(Te,{name:t.p.name,icon:t.p.icon,colorKey:t.p.templateId,size:22})}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:D(`block truncate font-medium hover:text-[var(--accent)]`,!t.p.enabled&&`text-[var(--text-muted)]`),children:t.name}),(0,Z.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-[var(--text-muted)]`,children:Ot(t.p.endpoints[0]?.baseUrl)??`—`})]})]})},{key:`health`,label:s(`providers.col.status`),width:112,render:(e,t)=>{let n=lt(t.p,t.stat);return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(M,{tone:ut[n]}),dt(n,s)]})}},{key:`models`,label:s(`providers.col.models`),numeric:!0,width:56},{key:`days`,label:s(`providers.col.trend`),sortable:!1,width:84,render:(e,t)=>(0,Z.jsx)(ht,{data:t.days,labels:r,max:i})},{key:`requests`,label:s(`providers.col.requests`),numeric:!0,width:80,render:(e,t)=>t.requests?p(t.requests,!0):`—`},{key:`successRate`,label:s(`providers.col.successRate`),width:124,render:(e,t)=>t.successRate<0?(0,Z.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`—`}):(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:[(0,Z.jsx)(`span`,{className:`h-[5px] w-10 overflow-hidden rounded-full bg-[var(--border)]`,children:(0,Z.jsx)(`i`,{className:`block h-full`,style:{width:`${t.successRate*100}%`,background:mt(t.successRate)}})}),(0,Z.jsx)(`span`,{className:`num text-[12px]`,children:k(t.successRate)})]})},{key:`ttft`,label:s(`providers.col.ttft`),numeric:!0,width:92,render:(e,t)=>(0,Z.jsx)(Dt,{children:t.ttft<0?`—`:a(t.ttft)})},{key:`tokens`,label:s(`providers.col.tokens`),numeric:!0,width:128,render:(e,t)=>(0,Z.jsx)(Dt,{children:t.stat&&t.tokens>0?`${p(t.stat.inputTokens,!0)} / ${p(t.stat.outputTokens,!0)}`:`—`})},{key:`cost`,label:s(`providers.col.cost`),numeric:!0,width:96,render:(e,t)=>(0,Z.jsx)(Dt,{children:t.cost>0?u(t.cost):`—`})},{key:`enabled`,label:s(`providers.col.enabled`),width:64,render:(e,t)=>(0,Z.jsx)(kt,{provider:t.p})}];return(0,Z.jsx)(ge,{caption:s(`nav.providers`),rowKey:`id`,rows:c,columns:l,defaultSort:{key:`requests`,direction:`desc`}})}var Dt=({children:e})=>(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:e});function Ot(e){if(!e)return null;try{return new URL(e).host}catch{return e}}function kt({provider:e}){let{t}=b(),n=I(e.id),{toast:r}=le();return(0,Z.jsx)(`span`,{className:`ml-1 inline-flex`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(R,{checked:e.enabled,label:t(`common.enabled`),onChange:e=>n.mutate({enabled:e},{onError:e=>r(V(e),`error`)})})})}var At=e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,jt=e=>e.category!==`subscription`&&e.category!==`custom`&&e.authScheme!==`oauth-subscription`;function Mt({open:e,onOpenChange:t,provider:n}){let{t:r}=b(),{toast:i}=le(),a=g(),o=A(n.id),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(``),d=(a.data??[]).filter(jt);(0,X.useEffect)(()=>{e&&(c(n.templateId??``),u(``))},[e,n.templateId]);let f=d.find(e=>e.id===s),p=f?f.variants?.find(e=>e.id===l)?.endpointsOverride??f.endpoints:[],m=s===n.templateId&&!l;return(0,Z.jsxs)(ce,{open:e,onOpenChange:t,title:r(`providers.templateSwitch`),description:r(`providers.templateSwitchDetail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Z.jsx)(j,{variant:`primary`,disabled:!f||m,loading:o.isPending,onClick:()=>f&&o.mutate({templateId:f.id,variantId:l||null},{onSuccess:()=>{t(!1),i(r(`providers.templateSwitched`,{name:f.name}),`success`)},onError:e=>i(V(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,Z.jsx)(ae,{}),a.isError&&(0,Z.jsx)(P,{tone:`danger`,title:r(`common.error`),children:V(a.error)}),(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(T,{label:r(`providers.templateSwitchTarget`),children:(0,Z.jsx)(W,{value:s,onChange:e=>{c(e),u(``)},options:d.map(e=>({value:e.id,label:e.id===n.templateId?r(`providers.templateSwitchCurrent`,{name:e.name}):e.name,detail:e.id}))})}),f?.variants&&f.variants.length>0&&(0,Z.jsx)(T,{label:r(`providers.variant`),children:(0,Z.jsx)(W,{value:l,onChange:u,options:[{value:``,label:r(`providers.variantDefault`)},...f.variants.map(e=>({value:e.id,label:e.name}))]})}),f&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:r(`providers.templateSwitchEndpoints`)}),(0,Z.jsx)(`ul`,{className:`grid gap-1 text-[12px]`,children:p.map(e=>(0,Z.jsxs)(`li`,{className:`flex gap-3`,children:[(0,Z.jsx)(`span`,{className:`w-36 shrink-0 text-[var(--text-secondary)]`,children:$.find(t=>t.value===e.protocol)?.label??e.protocol}),(0,Z.jsx)(`span`,{className:`min-w-0 font-mono break-all`,children:e.baseUrl})]},e.protocol))})]})]})]})}function Nt({provider:e,httpStatus:t,className:n}){return t!==401&&t!==403||!e.templateId||!At(e)?null:(0,Z.jsx)(Pt,{provider:e,className:n})}function Pt({provider:e,className:t}){let{t:n}=b(),{toast:r,confirm:i}=le(),a=g(),o=A(e.id),s=a.data?.find(t=>t.id===e.templateId),c=(s?.keyAlternatives??[]).flatMap(e=>a.data?.filter(t=>t.id===e)??[]);if(!s||c.length===0)return null;let l=async e=>{let t=[...new Set(e.endpoints.map(e=>e.baseUrl))].join(`, `);await i({title:n(`providers.templateSwitchConfirm`,{alt:e.name}),detail:n(`providers.templateSwitchConfirmDetail`,{urls:t}),confirmLabel:n(`providers.keyAlternative.switch`,{alt:e.name})})&&o.mutate({templateId:e.id},{onSuccess:()=>r(n(`providers.templateSwitched`,{name:e.name}),`success`),onError:e=>r(V(e),`error`)})};return(0,Z.jsxs)(P,{className:t,tone:`warning`,title:n(`providers.keyAlternative.title`),children:[n(`providers.keyAlternative.rejected`,{name:s.name,alt:c.map(e=>e.name).join(` / `)}),(0,Z.jsx)(`span`,{className:`mt-2 flex flex-wrap gap-2`,children:c.map(e=>(0,Z.jsx)(j,{size:`sm`,loading:o.isPending,onClick:()=>void l(e),children:n(`providers.keyAlternative.switch`,{alt:e.name})},e.id))})]})}var Ft=3,It=256,Lt=4096,Rt=`A small red circle on a white background.`,zt=`Change the red circle to blue. Keep everything else the same.`;function Bt(e){let t=e.slice(e.lastIndexOf(`/`)+1).toLowerCase();return t.startsWith(`gpt-image`)||t.startsWith(`chatgpt-image`)||t.startsWith(`dall-e`)}var Vt={idle:`providers.testDialog.status.idle`,queued:`providers.testDialog.status.queued`,running:`providers.testDialog.status.running`,success:`providers.testDialog.status.success`,failed:`providers.testDialog.status.failed`,cancelled:`providers.testDialog.status.cancelled`};function Ht(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var Ut=e=>typeof e==`number`?e:null,Wt=e=>typeof e==`string`?e:null;function Gt({provider:e,open:t,onOpenChange:n}){let{t:r}=b(),i=d(),a=ne(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,X.useState)(`single`),[l,u]=(0,X.useState)(()=>Ht(e)),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(``),[g,v]=(0,X.useState)(It),[y,x]=(0,X.useState)({size:``,quality:``,count:1,operation:`generate`,input:null}),[C,w]=(0,X.useState)(``),ee=(0,X.useRef)(C);ee.current=C;let[E,te]=(0,X.useState)(null),[D,O]=(0,X.useState)({}),[k,re]=(0,X.useState)([]),[A,M]=(0,X.useState)(new Set),[N,P]=(0,X.useState)([]),[F,ie]=(0,X.useState)(``),[ae,I]=(0,X.useState)(null),[oe,L]=(0,X.useState)(!1),R=(0,X.useRef)(null),z=(0,X.useRef)(new Map),B=(0,X.useRef)(!1),V=(0,X.useRef)(!1),H=(0,X.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...N.filter(t=>!e.includes(t))]},[a.data,N]);(0,X.useEffect)(()=>{if(t){let e=ee.current||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``;!ee.current&&e&&Bt(e)&&u(`openai-images`),w(e);return}V.current=!1,R.current?.abort();for(let e of z.current.values())e.abort();z.current.clear(),te(null),O({}),re([]),M(new Set),P([]),ie(``),I(null)},[t,a.data]);let se=(0,X.useCallback)((t,n=!1)=>Bt(t)||!n&&l===`openai-images`?{modelId:t,protocol:`openai-images`,prompt:m.trim()||null,imageOperation:y.operation,...y.operation===`edit`&&y.input?{imageInput:y.input.data}:{},imageSize:y.size.trim()||null,imageQuality:y.quality||null,imageCount:y.count,imagePreview:!n}:{modelId:t,protocol:l===`openai-images`?Ht(e):l,stream:f,prompt:m.trim()||null,maxOutputTokens:g??It},[l,f,m,g,y,e]),U=(0,X.useCallback)((t,n,r,i=!1)=>sn(e.id,t,se(t,i),n,r),[e.id,se]),le=t=>{w(t),Bt(t)?u(`openai-images`):l===`openai-images`&&u(Ht(e))},ue=()=>{let e=C.trim();if(!e)return;R.current?.abort();let t=new AbortController;R.current=t,V.current=!0,I(null),te({modelId:e,status:`running`,text:``,reasoning:``}),U(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&de(),te(e)})},W=e=>{if(e.length===0)return;V.current=!0,B.current=!1,I(null),re(e),O(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(Ft,e.length)},async()=>{for(;;){if(!V.current)return;let n=e[t++];if(n===void 0)return;if(B.current){O(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;z.current.set(n,r),await U(n,r.signal,e=>O(t=>({...t,[n]:e})),!0),z.current.delete(n),de()}}))},de=()=>void i.invalidateQueries({queryKey:[`requests`]}),pe=()=>{B.current=!0,O(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},G=E?.status===`running`||k.some(e=>D[e]?.status===`running`||D[e]?.status===`queued`&&!B.current),me=k.filter(e=>D[e]&&D[e].status!==`queued`&&D[e].status!==`running`).length,he=k.filter(e=>D[e]?.status===`success`).length,q=k.filter(e=>D[e]?.status===`failed`).length,ge=(e,t)=>M(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),_e=()=>{G||n(!1)},J=e=>e.stopPropagation();return(0,Z.jsx)(`span`,{onClick:J,onKeyDown:J,children:(0,Z.jsxs)(ce,{open:t,onOpenChange:e=>e?n(!0):_e(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,Z.jsx)(j,{disabled:G,onClick:()=>n(!1),icon:(0,Z.jsx)(S,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?G?(0,Z.jsx)(j,{variant:`primary`,icon:(0,Z.jsx)(Ne,{className:`size-3.5`}),onClick:()=>R.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,Z.jsx)(j,{variant:`primary`,disabled:C.trim()===``,icon:(0,Z.jsx)(K,{className:`size-3.5`}),onClick:ue,children:r(E?`providers.testDialog.retest`:`providers.testDialog.start`)}):G?(0,Z.jsx)(j,{variant:`primary`,icon:(0,Z.jsx)(Ne,{className:`size-3.5`}),onClick:pe,children:r(`providers.testDialog.stopRest`)}):(0,Z.jsx)(j,{variant:`primary`,disabled:A.size===0,icon:(0,Z.jsx)(K,{className:`size-3.5`}),onClick:()=>W([...A]),children:r(`providers.testDialog.testN`,{count:A.size})})]}),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,Z.jsx)(Te,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,Z.jsx)(_,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),I(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,Z.jsx)(T,{label:r(`providers.testDialog.model`),children:(0,Z.jsx)(Kt,{value:C,models:H,onChange:le})}),(0,Z.jsx)(Qt,{protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:v,prompt:m,onPrompt:h,image:y,onImage:x}),(0,Z.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,Z.jsx)(en,{provider:e,run:E,onRetest:ue})]}):ae===null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(an,{known:H,selected:A,onToggle:ge,onSelectAll:e=>M(e?new Set(H):new Set),onClear:()=>M(new Set),search:F,onSearch:ie,onAdd:e=>{P(t=>t.includes(e)?t:[...t,e]),M(t=>new Set(t).add(e)),ie(``)},configOpen:oe,onConfigOpen:L,protocols:o,protocol:l,onProtocol:u,stream:f,onStream:p,maxTokens:g,onMaxTokens:v,prompt:m,onPrompt:h,image:y,onImage:x,batch:!0,hasImageModels:H.some(Bt)}),k.length>0?(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:G?r(`providers.testDialog.progress`,{done:me,total:k.length,ok:he,failed:q}):r(`providers.testDialog.progressDone`,{total:k.length,ok:he,failed:q})}),(0,Z.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${me/k.length*100}%`,background:`var(--accent)`}})})]}):null,k.length>0?(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(on,{order:k,runs:D,onView:I})}):null]}):(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(j,{variant:`plain`,icon:(0,Z.jsx)(fe,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>I(null)}),(0,Z.jsx)(`span`,{className:`font-mono text-[13px]`,children:ae})]}),(0,Z.jsx)(en,{provider:e,run:D[ae]??null})]})]})})}function Kt({value:e,models:t,onChange:n}){let{t:r}=b(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(0),[c,l]=(0,X.useState)(null),u=c===null?t:t.filter(e=>e.toLowerCase().includes(c.trim().toLowerCase())),d=()=>{l(null),s(Math.max(0,t.indexOf(e))),a(!0)},f=e=>{n(e),l(null),a(!1)};return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(x,{className:`pr-9 font-mono`,value:e,placeholder:r(`providers.testDialog.modelPlaceholder`),"aria-expanded":i,role:`combobox`,onFocus:d,onClick:d,onChange:e=>{n(e.target.value),l(e.target.value),s(0),a(!0)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!i)return d();if(u.length===0)return;let t=e.key===`ArrowDown`?1:-1;s(e=>(e+t+u.length)%u.length)}else e.key===`Enter`&&i?(e.preventDefault(),u[o]&&f(u[o])):e.key===`Escape`&&a(!1)}}),(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-y-0 right-0 grid w-8 place-items-center text-[var(--text-muted)] hover:text-[var(--text)]`,"aria-label":r(`providers.testDialog.showModels`),onClick:()=>i?a(!1):d(),children:(0,Z.jsx)(z,{className:`size-4`})}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,Z.jsx)(`ul`,{className:`absolute inset-x-0 top-full z-50 mt-1 max-h-64 overflow-auto rounded-lg border border-[var(--border)] bg-[var(--surface-raised)] py-1 shadow-lg`,children:u.length===0?(0,Z.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`button`,{type:`button`,className:D(`block w-full truncate px-3 py-1.5 text-left font-mono text-[12px] hover:bg-[var(--surface-strong)]`,t===o&&`bg-[var(--surface-strong)]`),onMouseEnter:()=>s(t),onMouseDown:t=>{t.preventDefault(),f(e)},children:e})},e))})]})]})}var qt=4194304,Jt=[`image/png`,`image/jpeg`,`image/webp`],Yt=[`auto`,`1024x1024`,`1536x1024`,`1024x1536`,`512x512`,`256x256`],Xt=[`auto`,`low`,`medium`,`high`,`standard`,`hd`],Zt=4;function Qt({protocols:e,batch:t=!1,hasImageModels:n=!1,...r}){let{t:i}=b(),a=e.map(e=>({value:e,label:$.find(t=>t.value===e)?.label??e}));!t&&e.some(e=>e===`openai-chat`||e===`openai-responses`)&&a.push({value:`openai-images`,label:`OpenAI Images`});let o=!t&&r.protocol===`openai-images`,s=e=>r.onImage({...r.image,...e}),c=r.image.operation===`edit`,l=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(T,{label:i(`providers.testDialog.imageOperation`),hint:c?i(`providers.testDialog.imageEditHint`):void 0,children:(0,Z.jsx)(_,{items:[{value:`generate`,label:i(`providers.testDialog.imageGenerate`)},{value:`edit`,label:i(`providers.testDialog.imageEdit`)}],value:r.image.operation,onChange:e=>s({operation:e}),ariaLabel:i(`providers.testDialog.imageOperation`)})}),c?(0,Z.jsx)($t,{value:r.image.input,onChange:e=>s({input:e})}):null,(0,Z.jsxs)(T,{label:i(`providers.testDialog.imageSize`),hint:i(`providers.testDialog.imageSizeHint`),children:[(0,Z.jsx)(x,{className:`font-mono`,list:`provider-test-image-sizes`,value:r.image.size,placeholder:`1024x1024`,"aria-label":i(`providers.testDialog.imageSize`),onChange:e=>s({size:e.target.value})}),(0,Z.jsx)(`datalist`,{id:`provider-test-image-sizes`,children:Yt.map(e=>(0,Z.jsx)(`option`,{value:e},e))})]}),(0,Z.jsx)(T,{label:i(`providers.testDialog.imageQuality`),children:(0,Z.jsx)(W,{value:r.image.quality,onChange:e=>s({quality:e}),options:[{value:``,label:i(`providers.testDialog.imageDefault`)},...Xt.map(e=>({value:e,label:e}))]})}),(0,Z.jsx)(T,{label:i(`providers.testDialog.imageCount`),children:(0,Z.jsx)(O,{value:r.image.count,min:1,placeholder:`1`,label:i(`providers.testDialog.imageCount`),onChange:e=>s({count:e===null?1:Math.min(Zt,Math.max(1,Math.round(e)))})})})]}),u=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.testDialog.stream`)}),(0,Z.jsx)(R,{checked:r.stream,label:i(`providers.testDialog.stream`),onChange:r.onStream})]}),(0,Z.jsx)(T,{label:i(`providers.testDialog.maxTokens`),children:(0,Z.jsx)(O,{value:r.maxTokens,min:1,placeholder:String(It),label:i(`providers.testDialog.maxTokens`),onChange:e=>r.onMaxTokens(e===null?null:Math.min(Lt,Math.max(1,Math.round(e))))})})]});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(T,{label:i(`providers.testDialog.protocol`),hint:t&&n?i(`providers.testDialog.batchAutoHint`):void 0,children:(0,Z.jsx)(W,{value:r.protocol,onChange:r.onProtocol,options:a})}),t?(0,Z.jsxs)(Z.Fragment,{children:[u,n?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h4`,{className:`pt-1 text-[12px] font-medium`,children:i(`providers.testDialog.imageSection`)}),l]}):null]}):o?l:u,(0,Z.jsx)(T,{label:i(`providers.testDialog.prompt`),hint:i(`providers.testDialog.promptHint`),children:(0,Z.jsx)(v,{rows:4,value:r.prompt,placeholder:o?c?zt:Rt:`Reply with OK.`,onChange:e=>r.onPrompt(e.target.value)})})]})}function $t({value:e,onChange:t}){let{t:n}=b(),r=(0,X.useRef)(null),[i,a]=(0,X.useState)(null),o=e=>{if(!e)return;if(!Jt.includes(e.type))return a(n(`providers.testDialog.imageInputType`));if(e.size>qt)return a(n(`providers.testDialog.imageInputTooLarge`));let r=new FileReader;r.onerror=()=>a(n(`providers.testDialog.imageInputUnreadable`)),r.onload=()=>{let n=String(r.result);a(null),t({name:e.name,bytes:e.size,data:n.slice(n.indexOf(`,`)+1),preview:n})},r.readAsDataURL(e)};return(0,Z.jsxs)(T,{label:n(`providers.testDialog.imageInput`),hint:i??void 0,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e?(0,Z.jsx)(`img`,{src:e.preview,alt:``,className:`size-12 shrink-0 rounded-md border border-[var(--border)] object-cover`}):(0,Z.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center rounded-md border border-[var(--border)] bg-white`,children:(0,Z.jsx)(`span`,{className:`size-7 rounded-full bg-[#ff2020]`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[12px]`,title:e?.name,children:e?e.name:n(`providers.testDialog.imageInputDefault`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e?`${(e.bytes/1024).toFixed(+(e.bytes<10240))} KB`:n(`providers.testDialog.imageInputLimits`)})]}),(0,Z.jsx)(`input`,{ref:r,type:`file`,hidden:!0,accept:Jt.join(`,`),"aria-label":n(`providers.testDialog.imageInput`),onChange:e=>{o(e.target.files?.[0]),e.target.value=``}}),(0,Z.jsx)(j,{size:`sm`,icon:(0,Z.jsx)(je,{className:`size-3.5`}),onClick:()=>r.current?.click(),children:n(`providers.testDialog.imageInputPick`)}),e?(0,Z.jsx)(j,{size:`sm`,variant:`plain`,onClick:()=>(a(null),t(null)),children:n(`providers.testDialog.imageInputReset`)}):null]}),i?(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-[var(--danger)]`,children:i}):null]})}function en({provider:e,run:t,onRetest:n}){let{t:r}=b(),[i,a]=(0,X.useState)(`preview`),o=t?.text??``,s=t?.raw??``,c=Object.entries(t?.headers??{}),l=t?.ttftMs!=null&&t?.httpMs!=null?Math.max(0,t.ttftMs-t.httpMs):null,u=i===`raw`?s:i===`headers`?c.map(([e,t])=>`${e}: ${t}`).join(`
|
|
3
|
-
`):o;return(0,Z.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n&&t&&t.status!==`running`?(0,Z.jsx)(j,{size:`sm`,icon:(0,Z.jsx)(K,{className:`size-3.5`}),onClick:n,children:r(`providers.testDialog.retest`)}):null,(0,Z.jsx)(be,{content:r(`providers.testDialog.metricsHelp`),children:(0,Z.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center text-[var(--text-muted)]`,tabIndex:0,children:(0,Z.jsx)(ke,{className:`size-4`})})}),(0,Z.jsx)(rn,{run:t}),t?.httpStatus?(0,Z.jsxs)(E,{tone:`neutral`,children:[`HTTP `,t.httpStatus]}):null]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-px overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--border)] sm:grid-cols-4`,children:[(0,Z.jsx)(nn,{label:r(`providers.testDialog.metrics.http`),value:t?.httpMs}),(0,Z.jsx)(nn,{label:r(`providers.testDialog.metrics.firstWait`),value:l}),(0,Z.jsx)(nn,{label:r(`providers.testDialog.metrics.ttft`),value:t?.ttftMs}),(0,Z.jsx)(nn,{label:r(`providers.testDialog.metrics.total`),value:t?.totalMs})]}),(0,Z.jsxs)(`section`,{className:`card overflow-hidden`,children:[(0,Z.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-[var(--border)] px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[12px] font-medium`,children:r(`providers.testDialog.reply`)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,Z.jsx)(_,{items:[{value:`preview`,label:r(`providers.testDialog.preview`)},{value:`raw`,label:r(`providers.testDialog.raw`)},{value:`headers`,label:r(`providers.testDialog.headers`)}],value:i,onChange:a,ariaLabel:r(`providers.testDialog.reply`)}),(0,Z.jsx)(oe,{value:u,label:r(i===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,Z.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:i===`headers`?c.length===0?(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.headersEmpty`)}):(0,Z.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,Z.jsx)(`tbody`,{children:c.map(([e,t])=>(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0 align-top`,children:[(0,Z.jsx)(`th`,{className:`w-[220px] py-1.5 pr-4 text-left font-mono font-normal text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`py-1.5 font-mono break-all whitespace-pre-wrap selectable`,children:t})]},e))})}):i===`raw`?s?(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[r(`providers.testDialog.rawNote`),t?.contentType?` · ${t.contentType}`:``]}),(0,Z.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:s}),t?.rawTruncated?(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:r(`providers.testDialog.rawTruncated`)}):null]}):(0,Z.jsx)(tn,{run:t}):t?.error?(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsx)(P,{tone:`danger`,title:r(`providers.testDialog.status.failed`),children:t.error}),(0,Z.jsx)(Nt,{provider:e,httpStatus:t.httpStatus})]}):o||t?.reasoning||t?.images?.length?(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[t?.reasoning?(0,Z.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.reasoning`)}),(0,Z.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:t.reasoning})]}):null,o?(0,Z.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:o}):null,t?.images?.length?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:t.images.map((e,t)=>{let n=`data:${e.mime};base64,${e.data}`;return(0,Z.jsxs)(`figure`,{className:`grid gap-1.5`,children:[(0,Z.jsx)(`img`,{src:n,alt:r(`providers.testDialog.imageAlt`,{n:t+1}),className:`max-h-[420px] max-w-full self-start rounded-md border border-[var(--border)] object-contain`}),(0,Z.jsx)(`a`,{className:`self-start text-[11px] text-[var(--accent)]`,href:n,download:`astra-test-${t+1}.${e.mime===`image/jpeg`?`jpg`:e.mime===`image/webp`?`webp`:`png`}`,children:r(`providers.testDialog.imageSave`)})]},t)})}):null]}):t?.status===`success`?(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noText`)}):(0,Z.jsx)(tn,{run:t})})]})]})}function tn({run:e}){let{t}=b();return e?.status===`running`||e?.status===`queued`?(0,Z.jsx)(`div`,{className:`grid h-full place-items-center text-[12px] text-[var(--text-muted)]`,children:t(Vt[e.status])}):(0,Z.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,Z.jsx)(ye,{className:`mx-auto size-6 text-[var(--text-muted)]`}),(0,Z.jsx)(`div`,{className:`text-[13px]`,children:t(`providers.testDialog.emptyTitle`)}),(0,Z.jsx)(`p`,{className:`mx-auto max-w-[320px] text-[11px] text-[var(--text-muted)]`,children:t(`providers.testDialog.emptyDetail`)})]})}function nn({label:e,value:t}){return(0,Z.jsxs)(`div`,{className:`bg-[var(--surface)] px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[15px] tabular-nums`,children:t==null?`—`:a(t)})]})}function rn({run:e}){let{t}=b(),n=e?.status??`idle`;return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(M,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(Vt[n])]})}function an({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:i,search:a,onSearch:o,onAdd:s,configOpen:c,onConfigOpen:l,...u}){let{t:d}=b(),f=a.trim(),p=f.toLowerCase(),m=p?e.filter(e=>e.toLowerCase().includes(p)):e,h=f!==``&&!e.some(e=>e.toLowerCase()===p);return(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:d(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,Z.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,Z.jsx)(C,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,Z.jsx)(j,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(j,{icon:(0,Z.jsx)(K,{className:`size-3.5`}),onClick:()=>l(!0),children:d(`providers.testDialog.config`)})]}),(0,Z.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:m.length===0&&!h?(0,Z.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:d(`providers.testDialog.noModels`)}):(0,Z.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,Z.jsx)(De,{checked:t.size===e.length&&e.length>0||t.size!==0&&`indeterminate`,onCheckedChange:e=>r(e!==!1),"aria-label":d(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:d(`providers.testDialog.ownFilter`)})]}),h?(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Z.jsx)(q,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-left font-mono text-[12px] text-[var(--accent)]`,onClick:()=>s(f),children:d(`providers.testDialog.addModel`,{id:f})})]}):null,m.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Z.jsx)(De,{checked:t.has(e),onCheckedChange:t=>n(e,t!==!1),"aria-label":e}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,title:e,children:e})]},e))]})}),(0,Z.jsx)(ce,{open:c,onOpenChange:l,width:480,title:d(`providers.testDialog.config`),description:d(`providers.testDialog.savedCredentials`),children:(0,Z.jsx)(`div`,{className:`grid gap-4`,children:(0,Z.jsx)(Qt,{...u})})})]})}function on({order:e,runs:t,onView:n}){let{t:r}=b();return(0,Z.jsx)(`div`,{className:`card overflow-hidden`,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)] text-left text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.model`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.statusColumn`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.ttft`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.total`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.reply`)})]})}),(0,Z.jsx)(`tbody`,{children:e.map(e=>{let i=t[e];return(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0`,children:[(0,Z.jsxs)(`td`,{className:`px-4 py-2 font-mono`,children:[e,i?.imageOperation?(0,Z.jsx)(E,{tone:`neutral`,className:`ml-2 align-middle`,children:r(i.imageOperation===`edit`?`providers.testDialog.imageEdit`:`providers.testDialog.imageGenerate`)}):null]}),(0,Z.jsx)(`td`,{className:`px-4 py-2`,children:(0,Z.jsx)(rn,{run:i??null})}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:a(i.ttftMs)}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:a(i.totalMs)}),(0,Z.jsx)(`td`,{className:`px-4 py-2`,children:(0,Z.jsx)(`button`,{type:`button`,className:`text-[var(--accent)] disabled:text-[var(--text-muted)]`,disabled:!i,onClick:()=>n(e),children:r(`providers.testDialog.view`)})})]},e)})})]})})}async function sn(e,t,n,r,i){let a={modelId:t,status:`running`,text:``,reasoning:``,...n.protocol===`openai-images`?{imageOperation:n.imageOperation===`edit`?`edit`:`generate`}:{}};i(a);let o=e=>{a={...a,...e},i(a)};try{await w(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:o({httpStatus:Ut(t.httpStatus),httpMs:Ut(t.httpMs),contentType:Wt(t.contentType),headers:cn(t.headers)});break;case`delta`:{let e=Wt(t.text)??``;Wt(t.kind)===`reasoning`?o({reasoning:a.reasoning+e}):o({text:a.text+e});break}case`done`:{let t=e.data;o({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,images:t.images??[],contentType:t.contentType??null,headers:cn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?o({status:`cancelled`,error:null}):o({status:`failed`,error:e instanceof l?e.message:String(e)})}}function cn(e){if(typeof e!=`object`||!e)return{};let t={};for(let[n,r]of Object.entries(e))typeof r==`string`?t[n]=r:r!=null&&(t[n]=String(r));return t}var ln=o({AUTH_OPTIONS:()=>un,PROTOCOL_OPTIONS:()=>$,ProvidersPage:()=>dn}),$=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],un=[{value:`bearer`,label:`Authorization: Bearer`},{value:`x-api-key`,label:`x-api-key`},{value:`x-goog-api-key`,label:`x-goog-api-key`},{value:`query-key`,label:`?key=`},{value:`none`,label:`—`},{value:`oauth-subscription`,label:`OAuth 订阅`}];function dn(){let{t:e}=b(),t=he(),[n,r]=we(),i=ee(),[a,o]=(0,X.useState)(n.get(`new`)===`1`),[s,c]=(0,X.useState)(!1);(0,X.useEffect)(()=>{n.get(`new`)===`1`&&(o(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),J(e=>{e===`new-provider`&&o(!0)});let l=F(`7d`,`day`,`provider`),[u,d]=(0,X.useState)(`7d`),f=N(`7d`),p=N(u),[m,h]=at(),[g,v]=ot(),[x,S]=(0,X.useState)(null),C=(0,X.useMemo)(()=>{let e=pn(fn),t=new Map,n=0;for(let r of l.data??[]){let i=e.indexOf(r.bucket);if(i<0)continue;let a=t.get(r.key);a||t.set(r.key,a={requests:e.map(()=>0),costUsd:0}),a.requests[i]=(a.requests[i]??0)+r.requests,a.costUsd+=r.costUsd,n=Math.max(n,a.requests[i])}return{days:e,labels:e.map(e=>e.slice(5)),byProvider:t,max:n}},[l.data]),w=(0,X.useMemo)(()=>new Map((f.data??[]).map(e=>[e.providerId,e])),[f.data]),T=e=>C.byProvider.get(e.name)?.requests??C.days.map(()=>0);return(0,Z.jsxs)(xe,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{icon:(0,Z.jsx)(G,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,Z.jsx)(j,{variant:`primary`,icon:(0,Z.jsx)(q,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)})]}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,Z.jsx)(ae,{lines:4}),i.isError&&(0,Z.jsx)(P,{tone:`danger`,title:e(`common.error`),children:V(i.error)}),i.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(y,{icon:(0,Z.jsx)(_e,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,Z.jsx)(j,{variant:`primary`,icon:(0,Z.jsx)(q,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,Z.jsx)(j,{icon:(0,Z.jsx)(G,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,Z.jsx)(_,{ariaLabel:e(`providers.overview.range`),value:u,onChange:d,items:_t.map(t=>({value:t,label:e(`range.${t}`)}))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(j,{variant:`plain`,size:`sm`,icon:g?(0,Z.jsx)(de,{className:`size-3.5`}):(0,Z.jsx)(pe,{className:`size-3.5`}),onClick:()=>v(!g),children:e(g?`providers.overview.hideCharts`:`providers.overview.showCharts`)}),(0,Z.jsx)(_,{ariaLabel:e(`providers.view.label`),value:m,onChange:h,items:[{value:`grid`,label:e(`providers.view.grid`)},{value:`table`,label:e(`providers.view.table`)}]})]})]}),(0,Z.jsx)(vt,{providers:i.data,stats:p.data??[],stats7d:w,range:u,chartsOpen:g}),m===`table`?(0,Z.jsx)(Et,{providers:i.data,stats7d:w,usage:T,labels:C.labels,max:C.max,onOpen:e=>t(`/providers/${e.id}`)}):(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,Z.jsx)(hn,{p:e,labels:C.labels,max:C.max,requests:T(e),stat:w.get(e.id),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>S(e)},e.id))})]})]}),(0,Z.jsx)(Qe,{open:s,onOpenChange:c}),(0,Z.jsx)(Dn,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),x&&(0,Z.jsx)(Gt,{provider:x,open:!0,onOpenChange:e=>!e&&S(null)})]})}var fn=7;function pn(e){let t=new Date;return Array.from({length:e},(n,r)=>{let i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(e-1-r));return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,`0`)}-${String(i.getDate()).padStart(2,`0`)}`})}var mn=e=>e.stopPropagation();function hn({p:e,labels:t,max:n,requests:r,stat:i,onOpen:a,onTest:o}){let{t:s,locale:c}=b(),l=lt(e,i),d=e.authScheme===`plugin`?s(`providers.card.plugin`):e.authScheme===`oauth-subscription`?s(`providers.card.subscription`):e.authScheme===`none`?s(`providers.card.noAuth`):e.hasApiKey?e.apiKeyMasked??`••••`:s(`providers.noKey`),f=U(e)?ue(e.quota,s,c):null,m=U(e)?H(e.quota):null,h=r.reduce((e,t)=>e+t,0),g=Ot(e.endpoints[0]?.baseUrl);return(0,Z.jsxs)(`div`,{className:D(`card flex h-[116px] cursor-pointer flex-col gap-[7px] px-3 py-2.5 transition-colors hover:border-[var(--border-strong,var(--border))]`,!e.enabled&&`opacity-60`),role:`button`,tabIndex:0,"aria-label":e.name,title:e.name,onClick:a,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:D(`inline-flex shrink-0`,!e.enabled&&`grayscale`),children:(0,Z.jsx)(Te,{name:e.name,icon:e.icon,colorKey:e.templateId,size:24})}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[14px] font-semibold`,children:e.name}),(0,Z.jsx)(`span`,{title:dt(l,s),className:`inline-flex`,children:(0,Z.jsx)(M,{tone:ut[l]})}),e.templateUpdateAvailable&&(0,Z.jsx)(E,{tone:`accent`,children:s(`providers.templateUpdate`)}),(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[11.5px] text-[var(--text-muted)]`,children:s(`providers.modelCount`,{count:e.modelCount})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center`,onClick:mn,children:[(0,Z.jsx)(j,{variant:`plain`,size:`sm`,icon:(0,Z.jsx)(K,{className:`size-3.5`}),"aria-label":s(`providers.test`),title:s(`providers.test`),onClick:o}),(0,Z.jsx)(kt,{provider:e})]})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 gap-1.5 text-[11.5px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 shrink truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:g??`—`}),(0,Z.jsx)(`span`,{children:`·`}),m?(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[var(--warning)]`,title:m.message,children:s(`providers.quota.failed`,{error:se(m,s)})}):f?(0,Z.jsx)(`span`,{className:`num min-w-0 truncate text-[var(--text-secondary)]`,title:f,children:f}):(0,Z.jsx)(`span`,{className:D(`min-w-0 truncate`,e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:d})]}),(0,Z.jsxs)(`div`,{className:`mt-auto flex items-end justify-between gap-2.5`,onClick:mn,children:[(0,Z.jsx)(ht,{data:r,labels:t,max:n}),h>0?(0,Z.jsxs)(`span`,{className:`flex gap-2.5 whitespace-nowrap text-[11.5px] text-[var(--text-secondary)]`,title:s(`providers.card.requests7d`),children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`b`,{className:`num font-semibold text-[var(--text)]`,children:p(h,!0)}),` `,s(`providers.card.requestsUnit`)]}),i&&i.requests>0&&(0,Z.jsx)(`span`,{className:`num`,style:{color:mt(i.successRate)},title:s(`providers.col.successRate`),children:k(i.successRate)}),i&&i.costUsd>0&&(0,Z.jsx)(`span`,{className:`num`,children:u(i.costUsd)})]}):(0,Z.jsx)(`span`,{className:`text-[11.5px] text-[var(--text-muted)]`,children:s(`providers.card.noRequests7d`)})]})]})}var gn=`plugin:`,_n=[`recommended`,`official`,`subscription`,`coding`,`cn`,`aggregator`,`inference`,`local`,`custom`],vn={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},yn=e=>$.find(t=>t.value===e)?.label??e,bn=e=>(0,Z.jsx)(`span`,{title:e,children:e}),xn=e=>{let t=/^(.+?)\s*[((]([^()()]+)[))]$/.exec(e);return t?[t[1],t[2]]:[e,null]},Sn=/[\s,,]+/;function Cn(e,t,n){let r=new Set(t.map(e=>e.protocol)),i=n.map(e=>e.protocol);return[...e.filter(e=>i.includes(e)),...i.filter(t=>!r.has(t)&&!e.includes(t))]}function wn({label:e,hint:t,children:n}){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:e}),n,t&&(0,Z.jsx)(`div`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:t})]})}function Tn({value:e,onChange:t}){let{t:n}=b(),r=e.map(e=>e.protocol),i=$.filter(e=>!r.includes(e.value)),a=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.map((i,o)=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(W,{className:`w-44`,ariaLabel:n(`providers.protocol`),value:i.protocol,onChange:e=>a(o,{protocol:e}),options:$.filter(e=>e.value===i.protocol||!r.includes(e.value))}),(0,Z.jsx)(x,{className:`min-w-52 flex-1`,mono:!0,"aria-label":n(`providers.baseUrl`),placeholder:`https://api.example.com/v1`,value:i.baseUrl,onChange:e=>a(o,{baseUrl:e.target.value})}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,title:n(`providers.fullUrlHint`),children:[(0,Z.jsx)(R,{checked:!!i.fullUrl,label:n(`providers.fullUrl`),onChange:e=>a(o,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,Z.jsx)(j,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ve,{className:`size-3.5`}),"aria-label":n(`common.delete`),disabled:e.length===1,onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),i.length>0&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(j,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(q,{className:`size-3.5`}),onClick:()=>t([...e,{protocol:i[0].value,baseUrl:e[0]?.baseUrl??``}]),children:n(`providers.addEndpoint`)})})]})}function En({value:e,onChange:t}){let{t:n}=b(),r=(n,r)=>t(e.map((e,t)=>t===n?r:e));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.map(([i,a],o)=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(x,{className:`w-44`,mono:!0,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:i,onChange:e=>r(o,[e.target.value,a])}),(0,Z.jsx)(x,{className:`min-w-0 flex-1`,mono:!0,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:a,onChange:e=>r(o,[i,e.target.value])}),(0,Z.jsx)(j,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ve,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(j,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(q,{className:`size-3.5`}),onClick:()=>t([...e,[``,``]]),children:n(`providers.addHeader`)})})]})}function Dn({open:t,onOpenChange:n,onCreated:r}){let{t:i}=b(),{toast:a}=le(),o=g(),s=e(),c=ie(),l=ee(),u=(0,X.useMemo)(()=>new Set((l.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[l.data]),d=he(),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(null),[_,y]=(0,X.useState)(null),[S,w]=(0,X.useState)(``),[E,ne]=(0,X.useState)(``),[D,k]=(0,X.useState)(``),[re,A]=(0,X.useState)(``),[M,N]=(0,X.useState)(`bearer`),[F,I]=(0,X.useState)([]),[oe,L]=(0,X.useState)([]),[R,z]=(0,X.useState)([]),[B,H]=(0,X.useState)(``),[se,U]=(0,X.useState)(1),[ue,de]=(0,X.useState)(``),[fe,pe]=(0,X.useState)(``);(0,X.useEffect)(()=>{t||(h(null),y(null),p(``),w(``),ne(``),k(``),A(``))},[t]);let G=(0,X.useMemo)(()=>{let e=f.trim().toLowerCase(),t=(o.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return _n.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[o.data,f]),K=(0,X.useMemo)(()=>{let e=f.trim().toLowerCase();return(l.data??[]).filter(t=>t.authScheme===`plugin`&&!t.settings.plugin?.absent&&(!e||t.name.toLowerCase().includes(e)||t.id.includes(e)))},[l.data,f]),ge=e=>{h(e),k(``),H(``),de(``),pe(``),e===`custom`?(w(``),A(``),N(`bearer`),I([{protocol:`openai-chat`,baseUrl:``}]),L([`openai-chat`]),z([]),U(1)):(w(e.name),A(e.priceKey??e.id),N(e.auth.scheme),I(e.endpoints.map(e=>({...e}))),L([...e.preferredUpstreamProtocols]),z(Object.entries(e.defaultHeaders??{})),U(e.defaultPriceMultiplier??1))},_e=e=>{L(t=>Cn(t,F,e)),I(e)},J=m&&m!==`custom`?m:null,ve=J?.authScheme===`oauth-subscription`,ye=fe.split(Sn).map(e=>e.trim()).filter(Boolean),be=(J?.keyAlternatives??[]).flatMap(e=>(o.data??[]).filter(t=>t.id===e)),xe=()=>{let e=m===`custom`;c.mutate({templateId:e?null:m.id,variantId:D||null,name:S.trim()||null,apiKey:E.trim()||null,priceKey:re,...ve?{}:{endpoints:F.map(e=>({...e,baseUrl:e.baseUrl.trim()})),authScheme:M,preferredUpstreamProtocols:oe.filter(e=>F.some(t=>t.protocol===e)),extraHeaders:Object.fromEntries(R.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t])),httpProxy:B.trim()||null,priceMultiplier:se,notes:ue.trim()||null,...ye.length>0?{models:ye}:{}}},{onSuccess:e=>{n(!1),a(i(`providers.created`,{name:e.name}),`success`),r(e)},onError:e=>a(V(e),`error`)})},we=()=>{if(_===`custom`)ge(`custom`);else if(_?.startsWith(gn)){let e=K.find(e=>gn+e.id===_);e&&(n(!1),r(e))}else{let e=(o.data??[]).find(e=>e.id===_);e&&!u.has(e.id)&&ge(e)}},Ee=ve||F.length>0&&F.every(e=>/^https?:\/\//.test(e.baseUrl.trim())),De=m!==null&&Ee&&(m===`custom`?S.trim()!==``:!J.requiresApiKey||M===`none`||E.trim()!==``);return(0,Z.jsxs)(ce,{open:t,onOpenChange:n,width:640,title:i(m?`providers.addTitleDetails`:`providers.addTitle`),description:m?J?J.name:i(`providers.custom`):i(`providers.addDetail`),footer:m?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{className:`mr-auto`,variant:`plain`,onClick:()=>h(null),children:i(`common.back`)}),(0,Z.jsx)(j,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,Z.jsx)(j,{variant:`primary`,disabled:!De,loading:c.isPending,onClick:xe,children:i(`providers.create`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,Z.jsx)(j,{variant:`primary`,disabled:!_,onClick:we,children:i(`common.continue`)})]}),children:[(0,Z.jsx)(Ke,{className:`mb-6`,label:i(`providers.addTitle`),current:+!!m,steps:[{id:`template`,label:i(`providers.step.template`)},{id:`details`,label:i(`providers.step.details`)}]}),m?(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(T,{label:i(`providers.name`),children:(0,Z.jsx)(x,{value:S,onChange:e=>w(e.target.value)})}),J?.variants&&J.variants.length>0&&(0,Z.jsx)(T,{label:i(`providers.variant`),children:(0,Z.jsx)(W,{value:D,onChange:e=>{k(e);let t=J.variants?.find(t=>t.id===e);A(t?.priceKey??J.priceKey??J.id),_e((t?.endpointsOverride??J.endpoints).map(e=>({...e})))},options:[{value:``,label:i(`providers.variantDefault`)},...J.variants.map(e=>({value:e.id,label:e.name}))]})}),m===`custom`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(wn,{label:i(`providers.section.endpoints`),hint:i(`providers.baseUrlHint`),children:(0,Z.jsx)(Tn,{value:F,onChange:_e})}),(0,Z.jsx)(T,{label:i(`providers.authScheme`),children:(0,Z.jsx)(W,{value:M,onChange:N,options:un})})]}),ve?(0,Z.jsx)(P,{tone:`info`,title:i(`providers.subscriptionWizardHint`),children:i(`providers.subscriptionWizardDetail`)}):(0,Z.jsxs)(`div`,{className:`font-mono`,children:[(0,Z.jsx)(Se,{label:i(`providers.apiKey`),description:i(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:E,onChange:e=>ne(e.target.value)}),J?.apiKeyUrl&&(0,Z.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:J.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:i(`providers.getKey`)})]}),J&&be.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`span`,{children:i(`providers.keyAlternative.wizard`,{name:J.name,alt:be.map(e=>e.name).join(` / `)})}),be.map(e=>(0,Z.jsx)(j,{size:`sm`,variant:`plain`,onClick:()=>{y(e.id),ge(e)},children:i(`providers.keyAlternative.pick`,{alt:e.name})},e.id))]}),(0,Z.jsx)(T,{label:i(`providers.priceKey`),hint:i(`providers.priceKeyHint`),children:(0,Z.jsx)(W,{value:re,onChange:A,options:[{value:``,label:i(`providers.priceKeyNone`)},...(s.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),!ve&&(0,Z.jsx)(te,{title:i(`providers.moreOptions`),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[J&&(0,Z.jsx)(wn,{label:i(`providers.section.endpoints`),hint:i(`providers.endpointsFooter`),children:(0,Z.jsx)(Tn,{value:F,onChange:_e})}),new Set(F.map(e=>e.protocol)).size>1&&(0,Z.jsx)(wn,{label:i(`providers.preferred`),hint:i(`providers.preferredHint`),children:(0,Z.jsx)(Ce,{label:i(`providers.preferred`),options:$.filter(e=>F.some(t=>t.protocol===e.value)).map(e=>{let t=oe.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:oe,onValueChange:e=>{let t=oe.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));L([...t,...n])}})}),J&&(0,Z.jsx)(T,{label:i(`providers.authScheme`),children:(0,Z.jsx)(W,{value:M,onChange:N,options:un})}),(0,Z.jsx)(wn,{label:i(`providers.headers`),children:(0,Z.jsx)(En,{value:R,onChange:z})}),(0,Z.jsx)(T,{label:i(`providers.proxy`),hint:i(`providers.proxyHint`),children:(0,Z.jsx)(x,{mono:!0,placeholder:`http://127.0.0.1:7890`,value:B,onChange:e=>H(e.target.value)})}),(0,Z.jsx)(wn,{label:i(`providers.multiplier`),hint:i(`providers.multiplierHint`),children:(0,Z.jsx)(O,{className:`w-28`,label:i(`providers.multiplier`),step:.01,min:0,value:se,onChange:e=>U(e??1)})}),(0,Z.jsx)(T,{label:i(`providers.initialModels`),hint:J?i(`providers.initialModelsTemplateHint`,{count:J.models.length}):i(`providers.initialModelsCustomHint`),children:(0,Z.jsx)(v,{rows:3,mono:!0,value:fe,onChange:e=>pe(e.target.value)})}),(0,Z.jsx)(T,{label:i(`providers.notes`),children:(0,Z.jsx)(x,{value:ue,onChange:e=>de(e.target.value)})}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`providers.moreOptionsDetail`)})]})}),J&&J.models.length>0&&ye.length===0&&(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.templateModels`,{count:J.models.length})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsx)(C,{value:f,onChange:p,placeholder:i(`providers.searchTemplates`)}),o.isLoading&&(0,Z.jsx)(ae,{lines:4}),o.isError&&(0,Z.jsx)(P,{tone:`danger`,title:i(`common.error`),children:V(o.error)}),G.map(e=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.category.${e.category}`)}),(0,Z.jsx)(me,{name:`provider-template`,"aria-label":i(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===_)?_:null,onValueChange:y,options:e.items.map(e=>{let t=[...new Set(e.endpoints.map(e=>e.protocol))],[n,r]=xn(e.name);return{value:e.id,label:(0,Z.jsx)(`span`,{title:e.name,children:n}),description:(0,Z.jsx)(`span`,{title:t.map(yn).join(` · `),children:r??t.map(e=>vn[e]).join(` · `)}),icon:(0,Z.jsx)(Te,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:u.has(e.id),disabledReason:bn(i(`providers.subscriptionAdded`))}})})]},e.category)),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.category.plugin`)}),K.length>0?(0,Z.jsx)(me,{name:`provider-template-plugin`,"aria-label":i(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:_?.startsWith(gn)?_:null,onValueChange:y,options:K.map(e=>({value:gn+e.id,label:bn(e.name),description:bn(i(`providers.pluginProvided`)),icon:(0,Z.jsx)(Te,{name:e.name,icon:e.icon,colorKey:e.id,size:28})}))}):(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-[var(--radius-md)] border border-dashed border-[var(--border)] px-3 py-2.5`,children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:i(`providers.pluginHint`)}),(0,Z.jsx)(j,{size:`sm`,onClick:()=>{n(!1),d(`/plugins/market`)},children:i(`plugins.browseMarket`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.custom`)}),(0,Z.jsx)(me,{name:`provider-template-custom`,"aria-label":i(`providers.custom`),layout:`list`,density:`compact`,value:_===`custom`?`custom`:null,onValueChange:y,options:[{value:`custom`,label:i(`providers.custom`),description:i(`providers.customDetail`),icon:(0,Z.jsx)(`span`,{className:`inline-flex size-7 items-center justify-center rounded-[8px] border border-dashed border-[var(--border-strong)] text-[var(--text-secondary)]`,children:(0,Z.jsx)(q,{className:`size-4`})})}]})]})]})]})}export{Nt as a,Gt as i,$ as n,Mt as o,ln as r,At as s,un as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$t as e,Ai as t,Ba as n,Bi as r,Bt as i,Ci as a,Di as o,E as s,Ei as c,Er as l,Et as u,Fi as d,Ft as f,H as p,It as m,Ji as h,Ki as g,Li as _,Lt as v,Ni as y,Nn as b,Nr as x,Pr as S,Ra as C,Rr as w,Ua as T,Vi as E,W as ee,Wt as D,Yi as te,Zi as O,_ as ne,ai as k,an as re,ct as A,d as j,ei as ie,fi as ae,fn as oe,fr as se,gt as ce,ht as le,i as ue,in as de,ji as fe,ki as pe,kn as me,l as M,lr as he,m as N,mi as ge,n as P,ni as _e,o as F,p as ve,pi as ye,pn as be,qi as xe,r as I,s as Se,t as Ce,u as L,v as R,xi as z,xt as B,y as V,za as we,zi as H,zt as U}from"./alert-CuKAE1Sv.js";import{A as Te,D as Ee,M as De,O as Oe,a as W,ct as G,dt as ke,i as Ae,j as je,k as Me,n as Ne,o as K,r as q}from"./overlays-DeHu6TU_.js";import{t as Pe}from"./TrayPanelView-CHh9-E76.js";import{t as Fe}from"./download-DR9BLMVt.js";import{t as Ie}from"./ellipsis-BH_FL485.js";import{t as Le}from"./external-link-Bb6sx3jt.js";import{n as Re,t as ze}from"./radio-cards-Rq9vGqnw.js";import{t as Be}from"./folder-open-Bcx5mAII.js";import{t as Ve}from"./log-out-Ch09k2bC.js";import{t as He}from"./minus-UfPYsFrp.js";import{t as Ue}from"./pencil-fY6CohHT.js";import{t as We}from"./rotate-ccw-DsmSscuv.js";import{$ as Ge,A as Ke,B as qe,C as Je,E as Ye,H as Xe,P as J,T as Ze,et as Qe,h as $e,n as et,rt as tt,s as nt,t as rt,w as it,z as at}from"./index-CKrvKDIJ.js";var ot={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};ot.node;var st=B(ot),ct={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};ct.node;var lt=B(ct),ut={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};ut.node;var dt=B(ut),ft={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};ft.node;var pt=B(ft),mt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};mt.node;var ht=B(mt),gt={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};gt.node;var _t=B(gt),vt={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};vt.node;var yt=B(vt),Y=T(n(),1),X=we(),bt=`https://astra-gate.si/docs/guide/remote-access`,xt=`astra.remote.acknowledged`;function St(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function Ct(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function wt(){try{return localStorage.getItem(xt)===`1`}catch{return!1}}function Tt(){try{localStorage.setItem(xt,`1`)}catch{}}function Et(){let{t:e}=A(),t=ae(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(kt,{s:n}),(0,X.jsx)(Mt,{s:n}),(0,X.jsx)(F,{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)(Ce,{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)(R,{className:`mx-auto my-8`})})}function Dt({s:e}){let{t,locale:n}=A(),{toast:r,confirm:i}=K(),a=_e(),o=U(),s=St(e,t),c=async e=>{await G.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!wt()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;Tt()}(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(W(e),`error`)})},u=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,d=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,f=e.state===`connected`&&d!==null?d<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:ee(d,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),m=e.cloudflared,h=m.downloading||m.path?null:m.asset?t(`settings.remote.cloudflaredMissing`,{version:m.version??``}):t(`settings.remote.cloudflaredUnsupported`),g=e.enabled?e.error??m.error??null:null,_=g!==null&&(e.state!==`connected`||/origin service|origin server/i.test(g)),v=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?p(e.connectedAt,n):void 0,children:[(0,X.jsx)(Se,{tone:u}),f,m.downloading&&m.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(m.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),!e.enabled&&!s&&h&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:h}),e.enabled&&v&&(0,X.jsxs)(N,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${v}/v1`}),children:[(0,X.jsx)(Ne,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(ce,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void c(`${v}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(v)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${v}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(v,`_blank`,`noopener`)})]}),e.enabled&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),_&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Ce,{tone:e.state===`connected`?`warning`:`danger`,title:Ct(g,e,t),children:g})})]})}function Ot({s:e}){let{t}=A(),{toast:n,confirm:r}=K(),i=c(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await G.copy(e)&&n(t(`common.copied`))},l=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`)})},u=()=>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`)}),d=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(N,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(ne,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void l(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)(Ce,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(N,{label:t(`settings.remote.origin`),detail:t(`settings.remote.originHint`),children:[(0,X.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.originUrl}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void s(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(dt,{className:`size-3.5`}),onClick:()=>window.open(bt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!d||i.isPending,onClick:u,children:t(`common.save`)})]})]})]})}function kt({s:e}){let{t}=A(),{toast:n,confirm:r}=K(),i=c(),a=U(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(W(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(P,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(N,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(At,{passwordSet:e.checks.passwordSet})]})}function At({passwordSet:e}){let{t}=A(),{toast:n}=K(),r=U(),i=x(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})]})}var jt=[`auto`,`github`,`astra`,`custom`];function Mt({s:e}){let{t}=A(),{toast:n}=K(),r=c(),i=be(),a=U(),o=e.cloudflared,[s,l]=(0,Y.useState)(e.download.downloadBaseUrl??``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>l(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[m,h]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>h(e.download.downloadSource),[e.download.downloadSource]);let g=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(W(e),`error`)}),_=t=>{h(t),(t!==`custom`||e.download.downloadBaseUrl)&&g({downloadSource:t})},v=()=>i.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(W(e),`error`)}),y=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:y}),children:(0,X.jsx)(Se,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${m}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:_,options:jt.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),m===`custom`&&(0,X.jsxs)(N,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>l(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>g({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(N,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>g({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!u&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{d(!0),v()},children:t(`settings.remote.cf.choose`)})}),u&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(j,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:v,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>d(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>g({cloudflaredPath:f.trim()},()=>d(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Nt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Pt={local:`127.0.0.1`,lan:`0.0.0.0`},Ft=e=>Nt.includes(e)?`local`:`lan`;function It(){let{t:e}=A(),{toast:t,confirm:n}=K(),i=C(),a=me(),o=U(),s=ge(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=a.data;if(!f)return(0,X.jsx)(N,{label:e(`settings.listen`),detail:a.isError?W(a.error):void 0,children:a.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=Ft(f.configuredHost),h=f.configuredHost!==f.host,g=!!o.data?.required,_=async n=>{await G.copy(n)&&t(e(`common.copied`))},v=n=>s.mutate(Pt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(W(e),`error`)}),y=async t=>{if(t!==m){if(t===`lan`){if(!f.passwordSet){l(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}v(t)}},b=async()=>{d(!0);let n=await G.restartService();if(d(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),i.invalidateQueries()}},x=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${r?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.listen`),detail:x,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&r&&(0,X.jsx)(I,{size:`sm`,loading:u,onClick:()=>void b(),children:e(`settings.listen.restart`)}),(0,X.jsx)(ne,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void y(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(N,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(At,{passwordSet:f.passwordSet}),(0,X.jsx)(Lt,{open:c,onOpenChange:l,onSaved:()=>v(`lan`)})]})}function Lt({open:e,onOpenChange:t,onSaved:n}){let{t:r}=A(),{toast:i}=K(),a=x(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(W(e),`error`)})};return(0,X.jsx)(Ae,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(j,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(j,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Rt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],zt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},Bt=e=>e===`feishu`||e===`dingtalk`,Vt=(e,t)=>e(`alerts.event.${t}`),Ht=(e,t)=>e(`alerts.event.${t}.hint`);function Ut(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Wt,{}),(0,X.jsx)(Gt,{}),(0,X.jsx)(Xt,{})]})}function Wt(){let{t:e,locale:t}=A(),n=v(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),n.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(N,{icon:(0,X.jsx)(st,{className:`size-4 text-[var(--danger)]`}),label:`${Vt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${p(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Gt(){let{t:e}=A(),{toast:t,confirm:n}=K(),r=fe(),i=oe(),a=ie(),o=l(),[s,c]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),m=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(W(e),`error`)}),h=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>p(e.secret??null),onError:e=>t(W(e),`error`)})},g=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(N,{icon:(0,X.jsx)(yt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(P,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(P,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||Bt(t.format))&&(0,X.jsx)(P,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Re,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(Ne,{label:e(`common.more`),icon:(0,X.jsx)(Ie,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onSelect:()=>c(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(pt,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Xe,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(J,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void g(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Kt,{hook:s,onClose:()=>c(null),onSecret:p}),(0,X.jsx)(Jt,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(qt,{secret:f,onClose:()=>p(null)})]})}function Kt({hook:e,onClose:t,onSecret:n}){let{t:r}=A(),{toast:i}=K(),a=de(),s=o(),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(10),[m,h]=(0,Y.useState)(!0),[g,_]=(0,Y.useState)(!0),[v,y]=(0,Y.useState)(!0),[b,x]=(0,Y.useState)(`generic`),[S,C]=(0,Y.useState)(``),[w,T]=(0,Y.useState)([]),E=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;l(t?.name??``),d(t?.url??``),p(t?.timeoutSec??10),h(t?.useProxy??!0),_(t?.enabled??!0),y(!t||t.hasSecret),x(t?.format??`generic`),C(``),T((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Ae,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(E?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!c.trim()||!u.trim(),loading:a.isPending||s.isPending,onClick:()=>{let o=Object.fromEntries(w.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),l={name:c.trim(),url:u.trim(),timeoutSec:f??10,useProxy:m,enabled:g,headers:Object.keys(o).length>0?o:null},d={onError:e=>i(W(e),`error`)},p=!E&&e!==null&&e.format!==b,h=Bt(b)?v?S.trim()||void 0:``:void 0;E?a.mutate({...l,format:b,...b===`generic`?{signed:v}:h?{secret:h}:{}},{...d,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&s.mutate({id:e.id,...l,...p?{format:b}:{},...b===`generic`?v||!e.hasSecret||p?{}:{signed:!1}:h===void 0?{}:{secret:h}},{...d,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(M,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(j,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${b}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:b,onChange:t=>{x(t),y(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||Bt(t))},options:Rt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(j,{mono:!0,value:u,placeholder:zt[b],onChange:e=>d(e.target.value)})}),Bt(b)&&v&&(0,X.jsx)(M,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(j,{mono:!0,type:`password`,autoComplete:`off`,value:S,placeholder:e!==`new`&&e!==null&&e.format===b&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>C(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(ve,{value:f,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:p})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[w.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(j,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>T(w.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(j,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>T(w.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(J,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>T(w.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>T([...w,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(N,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(V,{checked:g,label:r(`alerts.webhooks.enabled`),onChange:_})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(V,{checked:m,label:r(`alerts.webhooks.useProxy`),onChange:h})}),(b===`generic`?E||e!==null&&e.format===`generic`&&e.hasSecret:Bt(b))&&(0,X.jsx)(N,{label:r(`alerts.webhooks.signed`),detail:r(b===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:v,label:r(`alerts.webhooks.signed`),onChange:y})})]})]})})}function qt({secret:e,onClose:t}){let{t:n}=A(),{toast:r}=K();return(0,X.jsx)(Ae,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await G.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function Jt({hook:e,onClose:n}){let{t:r,locale:i}=A(),{toast:a}=K(),o=t(e?.id),s=se(),c={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Ae,{open:e!==null,onOpenChange:e=>!e&&n(),title:`${r(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[o.isLoading&&(0,X.jsx)(R,{lines:4}),o.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:o.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(P,{tone:c[e.status],children:r(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?r(`alerts.webhooks.test`):Vt(r,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:p(e.createdAt,i)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?r(`alerts.delivery.next`,{time:p(e.nextAttemptAt,i)}):r(`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:r(`alerts.delivery.payload`)}),(0,X.jsx)(ue,{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:r(`alerts.delivery.response`)}),(0,X.jsx)(ue,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:s.isPending&&s.variables===e.id,onClick:()=>s.mutate(e.id,{onSuccess:()=>a(r(`alerts.delivery.redelivered`)),onError:e=>a(W(e),`error`)}),children:r(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Yt(e){let t=he(),n=k(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=ke({queries:r.map(t=>({queryKey:u.providerAccounts(t.id),queryFn:()=>y(`GET`,`/api/providers/${d(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 Xt(){let{t:e}=A(),{toast:t,confirm:n}=K(),r=m(),i=fe(),a=ye(),o=re(),[s,c]=(0,Y.useState)(null),l=e=>i.data?.find(t=>t.id===e)?.name??e,u=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(N,{icon:(0,X.jsx)(st,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(P,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(P,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Vt(e,n.event)} → ${n.webhookIds.map(l).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(W(e),`error`)})}),(0,X.jsx)(Ne,{label:e(`common.more`),icon:(0,X.jsx)(Ie,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onSelect:()=>c(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(J,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void u(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Qt,{rule:s,onClose:()=>c(null)})]})}function Zt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Qt({rule:t,onClose:n}){let{t:r}=A(),{toast:i}=K(),a=f(),o=fe(),s=e(),c=ye(),[l,u]=(0,Y.useState)(``),[d,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)({}),[g,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(null),[E,ee]=(0,Y.useState)(60),D=a.data?.find(e=>e.id===d),te=Yt(D?.subjectType),O=t===`new`;return(0,Y.useEffect)(()=>{if(t===null)return;let e=t===`new`?null:t,n=a.data?.[0];u(e?.name??``),p(e?.event??n?.id??``),h(e?{...Zt(a.data?.find(t=>t.id===e.event)),...e.condition}:Zt(n)),_(e?.subjects?`only`:`all`),y(e?.subjects??[]),x(e?.webhookIds??(o.data??[]).map(e=>e.id)),C(e?.notifyResolved??!1),T(e?.repeatMinutes??null),ee(e?.cooldownMinutes??60)},[t]),(0,X.jsx)(Ae,{open:t!==null,onOpenChange:e=>!e&&n(),title:r(O?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:n,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!l.trim()||!d,loading:s.isPending||c.isPending,onClick:()=>{let e=Object.fromEntries(Object.entries(m).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:d,condition:e,subjects:g===`all`?null:v,webhookIds:b,notifyResolved:S,repeatMinutes:w&&w>0?Math.floor(w):null,cooldownMinutes:Math.max(0,Math.floor(E??0))},o={onSuccess:()=>{n(),i(r(`common.saved`),`success`)},onError:e=>i(W(e),`error`)};O?s.mutate(a,o):t&&c.mutate({id:t.id,...a},o)},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(M,{label:r(`alerts.rules.name`),children:(0,X.jsx)(j,{value:l,maxLength:64,onChange:e=>u(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.rules.event`),hint:d?Ht(r,d):void 0,children:(0,X.jsx)(q,{ariaLabel:r(`alerts.rules.event`),value:d,onChange:e=>{p(e),h(Zt(a.data?.find(t=>t.id===e))),y([])},options:(a.data??[]).map(e=>({value:e.id,label:Vt(r,e.id)}))})}),D?.params.map(e=>(0,X.jsx)(M,{label:r(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(ve,{value:typeof m[e.name]==`number`?m[e.name]:null,min:0,label:r(`alerts.param.${e.name}`),onChange:t=>h({...m,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:r(`alerts.param.${e.name}`),value:String(m[e.name]??``),onChange:t=>h({...m,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:r(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(j,{mono:!0,value:String(m[e.name]??``),"aria-label":r(`alerts.param.${e.name}`),placeholder:r(`alerts.param.${e.name}.placeholder`),onChange:t=>h({...m,[e.name]:t.target.value})})},e.name)),D&&(0,X.jsx)(M,{label:`${r(`alerts.rules.subjects`)} · ${r(`alerts.subject.${D.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(ne,{ariaLabel:r(`alerts.rules.subjects`),value:g,onChange:_,items:[{value:`all`,label:r(`alerts.rules.subjectsAll`)},{value:`only`,label:r(`alerts.rules.subjectsOnly`)}]}),g===`only`&&(0,X.jsx)(nt,{label:r(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...te,...v.filter(e=>!te.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(M,{label:r(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.rules.noWebhooks`)}):(0,X.jsx)(nt,{label:r(`alerts.rules.webhooks`),value:b,onValueChange:x,options:(o.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(M,{label:r(`alerts.rules.repeat`),hint:r(`alerts.rules.repeatHint`),children:(0,X.jsx)(ve,{value:w,min:1,step:1,label:r(`alerts.rules.repeat`),onChange:T})}),(0,X.jsx)(M,{label:r(`alerts.rules.cooldown`),hint:r(`alerts.rules.cooldownHint`),children:(0,X.jsx)(ve,{value:E,min:0,step:1,label:r(`alerts.rules.cooldown`),onChange:ee})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(N,{label:r(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:S,label:r(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function $t(){let{t:e}=A(),t=i(),n=H()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&E;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)(en,{loginItem:n}),(0,X.jsx)(tn,{})]})}function en({loginItem:e}){let{t}=A(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(N,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(W(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function tn(){let{t:e}=A(),{toast:t}=K(),n=i(),r=S(),a=n.data;if(!a)return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:n.isError?W(n.error):void 0,children:n.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let o=!a.supported||a.mechanism===`none`?e(`settings.startup.unsupported.${a.unsupported??`platform`}`):a.canChange?a.enabled&&a.location?e(`settings.startup.entry`,{location:a.location}):e(`settings.startup.service.${a.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:o,children:a.supported&&(0,X.jsx)(V,{checked:a.enabled,disabled:!a.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_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:nn}=s,rn=[...s.ease.enter],an=[...s.ease.standard],on=[0,1,2,3,4,5,6,7,8,9],sn=6,cn=400,ln=40,un=240,dn=1500,fn=700,pn=700,mn=.22,hn=4,gn=130,_n=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),vn=e=>(String(e).split(`.`)[1]??``).length,yn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),bn=(e,t)=>typeof e==`function`?e(t):e??``,xn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function Sn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Cn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${nn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:an}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${nn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:an},opacity:{duration:$.instant},filter:{duration:$.instant}}})},wn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),Tn={enter:wn(0),center:{...wn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},En={enter:wn(1),center:{...wn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function Dn({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=tt(e,e=>`${n(e)*1.05}em`),i=tt(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=tt(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=tt(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*nn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(g.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function On({digit:e,direction:t,instant:n}){let r=h(),i=te(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):xe(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),on.map(e=>(0,X.jsx)(Dn,{position:i,digit:e},e))]})}function kn({value:e,format:t,direction:n,instant:r}){let i=h(),a=r?En:i?Tn:Cn;return(0,X.jsx)(O,{initial:!1,custom:n,children:Sn(e,t).map(e=>(0,X.jsx)(g.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(On,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function An({text:e,direction:t,className:n}){let r=h();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(O,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(g.span,{className:Z.char,custom:t,variants:r?Tn:Cn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var jn=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},Mn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=jn(n[t]),i=jn(e);return r!==null&&i!==null&&i<r?-1:1})},Nn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${nn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:rn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${nn.subtle}px)`,transition:{duration:.14,ease:an}})},Pn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Fn({word:e,direction:t}){let n=h(),r=(0,Y.useRef)(null),i=te(`auto`),a=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!a.current||n?i.jump(e.offsetWidth):xe(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(g.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(O,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(g.span,{className:Z.word,custom:t,variants:n?Pn:Nn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function In({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:Mn(t.text,e)});let r=t.text===e?t.directions:Mn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Fn,{word:e,direction:r[t]??1})]},t))})]})}function Ln({id:e,text:t,className:n}){return(0,X.jsx)(O,{initial:!1,children:t?(0,X.jsx)(Rn,{id:e,text:t,className:n},`message`):null})}function Rn({id:e,text:t,className:n}){let r=h(),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)(g.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)(g.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${nn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:rn},children:(0,X.jsx)(In,{text:t})})})}function zn({id:e,edge:t,text:n}){let r=h();return(0,X.jsx)(O,{initial:!1,children:t!==0&&(0,X.jsx)(g.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${nn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:an}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function Bn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?qe:He;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Vn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:p=!1,locale:m=`en-US`,formatOptions:_,size:v=`md`,limitHint:y=!0}){let b=h(),x=(0,Y.useId)(),S=u??x,C=c?`${S}-description`:void 0,w=`${S}-limit`,T=o>0?o:1,[E,ee]=(0,Y.useState)(n),D=t??E,[O,ne]=(0,Y.useState)(``),[k,re]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(0),[ie,ae]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(``),[ce,le]=(0,Y.useState)(0),[ue,de]=(0,Y.useState)(!1),fe=(0,Y.useRef)(null),pe=(0,Y.useRef)(null),me=(0,Y.useRef)(null),M=(0,Y.useRef)(void 0),he=(0,Y.useRef)(void 0),N=(0,Y.useRef)(void 0),ge=(0,Y.useRef)({edge:0,count:0,at:0}),P=(0,Y.useRef)(null),_e=(0,Y.useRef)(null),F=(0,Y.useRef)(D),ve=(0,Y.useRef)(D),ye=(0,Y.useRef)(void 0),be=(0,Y.useRef)(null),I=(0,Y.useRef)(!1),Se=(0,Y.useRef)(null),Ce=(0,Y.useRef)(!1),L=(0,Y.useRef)(()=>!1),R=te(0),z=te(0),B=te(0),V=tt(()=>z.get()+B.get()),we=Number.isFinite(i)?i:0,H=Math.max(vn(T),vn(we)),U=_?.minimumFractionDigits??H,Te=Math.max(U,_?.maximumFractionDigits??H),Ee=_?.useGrouping??!0,De=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:U,maximumFractionDigits:Te,useGrouping:Ee,numberingSystem:`latn`}),[m,U,Te,Ee]),Oe=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(m).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[m]),W=e=>Number(e.toFixed(H))||0,G=e=>Math.min(a,Math.max(i,e)),ke=e=>W(we+Math.round((e-we)/T)*T),Ae=(e,t)=>{let n=(e-we)/T;return W(we+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*T)},je=e=>`${bn(d,e)}${De.format(e)}${bn(f,e)}`.trim();function Me(e){let t=e.split(Oe.group).join(``).replace(Oe.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Ne=k?Me(O):null,K=Ne??D,[q,Pe]=(0,Y.useState)({value:K,direction:1});q.value!==K&&Pe({value:K,direction:K>q.value?1:-1});let Fe=q.value===K?q.direction:K>q.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(ye.current),window.clearTimeout(M.current),window.clearTimeout(he.current),window.clearTimeout(N.current)},[]);function Ie(e,t){let n=performance.now(),r=ge.current;r.count=r.edge===e&&n-r.at<pn?r.count+1:1,r.edge=e,r.at=n;let i=fe.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(N.current),N.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!b){xe(R,0,{..._n,velocity:-e*gn*(1+Math.min(r.count-1,hn)*mn)});let n=(e>0?me:pe).current;n&&(t===`button`||t===`key`)&&xe(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}y&&(le(e),window.clearTimeout(M.current),M.current=window.setTimeout(()=>le(0),dn))}function Le(e,n){if(!Number.isFinite(e))return!1;let i=G(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Ie(a>0?1:-1,n),se(`${je(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&se(je(i)),i!==F.current&&(F.current=i,t===void 0&&ee(i),r?.(i),!0)}let Re=(e,t,n)=>Le(Ae(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=D,L.current=Re});function ze(){let e=_e.current;e&&Se.current===null&&(Se.current=e.getBoundingClientRect().left-z.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=Se.current,t=_e.current;if(Se.current=null,Ce.current){Ce.current=!1;let e=P.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):xe(B,0,Q.morph))});function Be(){window.clearTimeout(he.current),de(!1)}function Ve(){if(!k)return;ze(),re(!1),Be();let e=Me(O);e!==null&&Le(ke(e),`type`)}function He(){window.clearTimeout(ye.current),ye.current=void 0,j(0)}function Ue(e,t,n){He(),Ve();let r=Math.max(1,Math.round(t/T));n===`button`&&j(e);let i=0,a=()=>{let t=L.current(e,r,n);ye.current=window.setTimeout(a,t?Math.max(ln,150*.86**++i):un)};ye.current=window.setTimeout(a,Re(e,r,n)?cn:360)}function We(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||Ue(n[0],n[1],`key`);return}if(!k&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),Le(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),k?(Ce.current=!0,Ve()):e.currentTarget.select()),e.key===`Escape`&&k&&(e.preventDefault(),ze(),re(!1),Be(),Ce.current=!0,Le(ve.current,`type`))}function Ge(e){let t=RegExp(`[^0-9${yn(Oe.group)}${H||Te?yn(Oe.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);k||(ve.current=D),ze(),ne(n),re(!0);let r=Me(n);r!==null&&r>=i&&r<=a&&ke(r)===r&&Le(r,`type`),Be(),r!==null&&r<i&&(he.current=window.setTimeout(()=>de(!0),fn))}function Ke(e){I.current=!1,p&&!l&&e.button===0&&(Ve(),be.current={pointer:e.pointerId,x:e.clientX,from:F.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function qe(e){let t=be.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,ae(!0)}let r=n/sn,o=Math.trunc(r);Le(o?Ae(t.from,o):t.from,`scrub`);let s=t.from+r*T,c=s>a?(s-a)/T*sn:s<i?(s-i)/T*sn:0;z.set(b?0:xn(c))}function Je(e){let t=be.current;t&&t.pointer===e.pointerId&&(be.current=null,t.active&&(I.current=!0,ae(!1),xe(z,0,b?{duration:0}:Q.snappy),se(je(F.current))))}let Ye=t=>({toward:t,label:e,disabled:l,controls:S,limit:t>0?K>=a:K<=i,pressed:A===t}),Xe=Ne===null?0:Ne>a?1:Ne<i&&ue?-1:0,J=y?Xe||ce:0,Ze=J>0?a:i,Qe=J?typeof y==`function`?y(J>0?`max`:`min`,Ze):`${J>0?`Max`:`Min`} ${je(Ze)}`:``,$e=[C,Xe&&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":p&&!l||void 0,onPointerDown:Ke,onPointerMove:qe,onPointerUp:Je,onPointerCancel:Je,onClick:e=>{I.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(zn,{id:w,edge:J,text:Qe})]}),(0,X.jsxs)(`div`,{ref:fe,className:Z.control,"data-scrubbing":ie||void 0,"data-disabled":l||void 0,"data-warn":Xe?Xe>0?`max`:`min`:void 0,children:[(0,X.jsx)(Bn,{...Ye(-1),iconRef:pe,onPress:()=>Ue(-1,T,`button`),onRelease:He,onActivate:()=>{Ve(),Re(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==P.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==P.current&&(P.current?.focus(),P.current?.select())},children:(0,X.jsxs)(g.span,{ref:_e,className:Z.value,style:{x:V,y:R},children:[(0,X.jsx)(An,{text:bn(d,K),direction:Fe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":k||void 0,"aria-hidden":`true`,children:(0,X.jsx)(kn,{value:K,format:De,direction:Fe,instant:k})}),k&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:O}),(0,X.jsx)(`input`,{ref:P,id:S,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:H||Te?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:k?O:De.format(D),disabled:l,"aria-describedby":$e,"aria-invalid":Xe?!0:void 0,"aria-valuenow":D,"aria-valuetext":je(D),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a:void 0,onChange:e=>Ge(e.currentTarget.value),onKeyDown:We,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&He()},onBlur:()=>{He(),Ve()}})]}),(0,X.jsx)(An,{text:bn(f,K),direction:Fe,className:Z.affix})]})}),(0,X.jsx)(Bn,{...Ye(1),iconRef:me,onPress:()=>Ue(1,T,`button`),onRelease:He,onActivate:()=>{Ve(),Re(1,1,`button`)}})]}),(0,X.jsx)(Ln,{id:C,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:oe})]})}var Hn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Un(){let{t:e}=A(),t=C(),[n,r]=Te(),i=je(),a=Ee(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(N,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(V,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(De(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Wn,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(ze,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:_.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Wn,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Hn.map(o)})}),(0,X.jsx)(Wn,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(We,{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)(Wn,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Pe,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Wn({title:e,hint:t,children:n}){let{t:r}=A();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Gn=[`general`,`notifications`,`remote`,`tray`],Kn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function qn(){let{t:e}=A(),{tab:t}=Qe(),n=Ge(),r=Me(),i=Gn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)($e,{title:e(`nav.settings`),children:(0,X.jsxs)(Je,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Ze,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Ye,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(_t,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Ye,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(lt,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Ye,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(le,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Ye,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ht,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(it,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Jn,{})}),(0,X.jsx)(it,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ut,{})}),(0,X.jsx)(it,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Et,{})}),r&&(0,X.jsx)(it,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Un,{})})]})})}function Jn(){let{t:e,locale:t,setLocale:n}=A(),i=et(),a=w(),o=z(),s=C(),c=pe(),l=U(),d=b(),f=ae(),{toast:p,confirm:m}=K(),h=a.data,g=f.data?.state===`connected`&&f.data.publicUrl?`${f.data.publicUrl}/v1`:null,_=e=>o.mutate(e,{onError:e=>p(W(e),`error`)}),v=e=>{n(e),_({locale:e})},y=async t=>{await G.copy(t)&&p(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(N,{label:e(`settings.theme`),children:(0,X.jsx)(ne,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(N,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...rt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(N,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(ne,{ariaLabel:e(`settings.language`),value:t,onChange:v,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)($t,{}),h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(N,{label:e(`settings.gatewayUrl`),detail:`${h.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void y(`${h.gatewayBaseUrl}/v1`)})}),g&&(0,X.jsx)(N,{label:e(`settings.remote.publicUrl`),detail:g,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void y(g)})}),(0,X.jsx)(It,{}),(0,X.jsx)(N,{label:e(`settings.dataDir`),detail:h.dataDir,children:G.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Be,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void G.openPath(h.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void y(h.dataDir)})}),(0,X.jsx)(N,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:h.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await m({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&_({requireGatewayKey:t})}})}),(0,X.jsx)(N,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(er,{label:e(`settings.streamIdle`),value:h.streamIdleTimeoutSec,onCommit:e=>_({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(N,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:h.requestCompression,onChange:e=>_({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(L,{footer:e(`settings.preventSleepHint`),children:(0,X.jsx)(N,{label:e(`settings.preventSleep`),children:(0,X.jsx)(V,{checked:h.preventSleep??!1,label:e(`settings.preventSleep`),onChange:e=>_({preventSleep:e})})})}),(0,X.jsx)(L,{footer:e(`settings.clientFailoverHint`),children:(0,X.jsx)(N,{label:e(`settings.clientFailover`),children:(0,X.jsx)(V,{checked:h.clientProviderFailover??!0,label:e(`settings.clientFailover`),onChange:e=>_({clientProviderFailover:e})})})}),(0,X.jsx)(Zn,{settings:h}),(0,X.jsx)(Qn,{settings:h}),(0,X.jsx)(Xn,{settings:h}),(0,X.jsx)($n,{settings:h}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(N,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(er,{label:e(`settings.quota.autoInterval`),value:h.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:u.providers}),onError:e=>p(W(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(N,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(er,{label:e(`settings.quota.subscriptionInterval`),value:h.subscriptionQuotaIntervalMinutes,onCommit:e=>_({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(N,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:h.usageTimeZone??``,onChange:e=>_({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:h.effectiveUsageTimeZone})},...[...new Set([...Kn,...h.usageTimeZone?[h.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(N,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:h.debugBodies,label:e(`settings.debugBodies`),onChange:e=>_({debugBodies:e})})}),(0,X.jsx)(N,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(er,{label:e(`settings.bodyRetention`),value:h.bodyRetentionDays,onCommit:e=>_({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(N,{label:e(`settings.requestRetention`),detail:h.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:h.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>_({requestRetentionDays:e?90:null})}),h.requestRetentionDays!=null&&(0,X.jsx)(er,{label:e(`settings.requestRetention`),value:h.requestRetentionDays,onCommit:e=>_({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(N,{label:e(`settings.traceContent`),children:(0,X.jsx)(V,{checked:h.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>_({traceContent:e})})})}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(N,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(er,{label:e(`settings.effort.${t}`),value:h.effortBudgets[t],onCommit:e=>_({effortBudgets:{...h.effortBudgets,[t]:e??h.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:W(a.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(N,{label:e(`settings.serverVersion`),detail:c.data?`${c.data.version} · API ${c.data.apiVersion}`:`—`}),r&&(0,X.jsx)(N,{label:e(`settings.desktopVersion`),detail:H()?.version||`—`}),(0,X.jsx)(Yn,{}),r&&(0,X.jsx)(N,{label:e(`settings.logs`),onClick:()=>void G.revealLogs(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})}),l.data?.required&&(0,X.jsx)(N,{label:e(`settings.logout`),onClick:()=>d.mutate(),children:(0,X.jsx)(Ve,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Yn(){let{t:e}=A(),{toast:t}=K(),n=C(),r=z(),i=w(),o=a(),s=D(),c=o.data,l=i.data?.updateChannel??c?.channel,d=H()?.updates??null,[f,p]=(0,Y.useState)(!1),m=()=>s.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:u.version}),n.invalidateQueries({queryKey:u.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)))},g=c?.lastCheckAt?new Date(c.lastCheckAt).toLocaleString():void 0,_=c?.available?d?e(`settings.updateAvailable`,{version:c.available}):`${e(`settings.updateAvailable`,{version:c.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.autoCheck`),detail:c&&!c.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:c?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(W(e),`error`)})})}),(0,X.jsx)(N,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(V,{checked:l===`preview`,label:e(`settings.previewUpdates`),disabled:!l||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:m,onError:e=>t(W(e),`error`)})})}),(0,X.jsxs)(N,{label:e(`settings.checkUpdates`),detail:s.isError?e(`settings.updateCheckFailed`,{error:W(s.error)}):c?.available?_:g?e(`settings.lastChecked`,{time:g}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:s.isPending,onClick:m,children:s.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(at,{className:`size-3.5`})}),d&&c?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:f,"aria-label":e(`settings.updateApply`),onClick:h,children:f?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Fe,{className:`size-3.5`})})]})]})}function Xn({settings:e}){let{t}=A(),{toast:n}=K(),r=z(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(W(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(W(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(N,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(ne,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:c,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),i===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(j,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Zn({settings:e}){let{t}=A(),{toast:n}=K(),r=z(),i=e.providerQualifiedModels??!1,a=i?e.modelQualifyScope??`shared`:`off`,o=e.modelProviderSeparator??`@`,[s,c]=(0,Y.useState)(o);(0,Y.useEffect)(()=>c(o),[o]);let l=e=>r.mutate(e,{onError:e=>{c(o),n(W(e),`error`)}});return(0,X.jsxs)(L,{title:t(`settings.qualifiedModels`),footer:t(`settings.qualifiedModels.footer`),children:[(0,X.jsx)(N,{label:t(`settings.qualifiedModels.mode`),detail:t(`settings.qualifiedModels.modeHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.qualifiedModels.mode`),value:a,onChange:e=>l(e===`off`?{providerQualifiedModels:!1}:{providerQualifiedModels:!0,modelQualifyScope:e}),options:[{value:`off`,label:t(`settings.qualifiedModels.mode.off`)},{value:`shared`,label:t(`settings.qualifiedModels.mode.shared`)},{value:`all`,label:t(`settings.qualifiedModels.mode.all`)}]})}),i&&(0,X.jsx)(N,{label:t(`settings.qualifiedModels.separator`),detail:t(`settings.qualifiedModels.separatorHint`),children:(0,X.jsx)(j,{className:`w-24`,mono:!0,maxLength:8,"aria-label":t(`settings.qualifiedModels.separator`),value:s,onChange:e=>c(e.target.value),onBlur:()=>s!==o&&l({modelProviderSeparator:s})})})]})}function Qn({settings:e}){let{t}=A(),{toast:n}=K(),r=z(),i=e.hiddenNav??[],a=Ke.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)(L,{title:t(`settings.sidebar`),footer:t(`settings.sidebar.footer`),children:a.map(e=>(0,X.jsx)(N,{label:t(e.label),children:(0,X.jsx)(V,{checked:!i.includes(e.id),label:t(e.label),onChange:t=>o(e.id,t)})},e.id))})}function $n({settings:e}){let{t}=A(),{toast:n}=K(),r=z(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(W(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(j,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function er({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Vn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{qn as SettingsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$r as e,Ar as t,Ba as n,Br as r,J as i,Mi as a,Si as o,Ua as s,_ as c,b as l,ct as u,d,gt as f,m as p,n as m,o as h,p as g,r as _,s as v,t as y,u as b,ut as x,v as S,y as C,za as w}from"./alert-CuKAE1Sv.js";import{a as T,ct as E,o as D,r as O}from"./overlays-DeHu6TU_.js";import{t as k}from"./arrow-down-DeIGdMUk.js";import{B as A,P as j,S as M,h as N,q as P}from"./index-CKrvKDIJ.js";var F=s(n(),1),I=w(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(p,{...t,detail:e==null?void 0:(0,I.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var B={typesafe:[{id:`typesafe`,baseUrl:``,model:`jev-latest`},{id:`openrouter`,baseUrl:`https://openrouter.ai/api`,model:`~typesafe/jev-latest`},{id:`vercel`,baseUrl:`https://ai-gateway.vercel.sh/typesafe`,model:`typesafe-ai/jev`}],openai:[{id:`openai`,baseUrl:``}]},V=(e,t)=>`${e??``}\n${t}`;function H(e,t){let n=t.trim().replace(/\/+$/,``);return B[e].find(e=>e.baseUrl===n)?.id??`custom`}function U(e,t,n){let r=e.trim()||(n.find(e=>e.id===t)?.defaultBaseUrl??``);try{return new URL(r).origin.toLowerCase()}catch{return r}}function W(e){return{virtualModel:e.virtualModel,protocol:e.judge.protocol,baseUrl:e.judge.baseUrl??``,apiKey:``,model:e.judge.model,instructions:e.judge.instructions??``,timeoutMs:e.judge.timeoutMs,grades:e.grades.map(e=>({...e})),mode:e.rules.mode,sessionTtlMinutes:e.rules.sessionTtlMinutes,fallbackGrade:e.rules.fallbackGrade,minConfidence:e.rules.minConfidence,contextTurns:e.rules.contextTurns,maxChars:e.rules.maxChars}}var G=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function K(e){return{protocol:e.protocol,baseUrl:e.baseUrl,model:e.model,instructions:e.instructions,...e.timeoutMs!==null&&{timeoutMs:e.timeoutMs},...e.apiKey!==``&&{apiKey:e.apiKey}}}function q(e){return{virtualModel:e.virtualModel,judge:K(e),grades:e.grades,rules:{mode:e.mode,fallbackGrade:e.fallbackGrade,...e.sessionTtlMinutes!==null&&{sessionTtlMinutes:e.sessionTtlMinutes},...e.minConfidence!==null&&{minConfidence:e.minConfidence},...e.contextTurns!==null&&{contextTurns:e.contextTurns},...e.maxChars!==null&&{maxChars:e.maxChars}}}}function J(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in x))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(e,t,n){if(e instanceof a){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>J(e,t,n))}return[T(e)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in x?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in x?t(n):e??``}function Q(){let{t:e}=u(),t=r();return t.data?(0,I.jsx)($,{saved:t.data}):(0,I.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,I.jsx)(y,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(S,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=u(),{toast:n}=D(),r=o(),[i,a]=(0,F.useState)(()=>W(e)),[s,c]=(0,F.useState)([]),l=e=>a(t=>({...t,...e})),d=JSON.stringify(i)!==JSON.stringify(W(e)),f=G(i),p=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{c([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>c(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:f,onToggle:e=>p(e),problems:s}),(0,I.jsx)(ne,{saved:e,draft:i,patch:l}),(0,I.jsx)(ie,{draft:i,patch:l}),(0,I.jsx)(ae,{draft:i,patch:l}),!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)(_,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(_,{variant:`primary`,disabled:!d||!f,loading:r.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=u(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(b,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(v,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(C,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(f,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(y,{tone:`danger`,title:a(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:i.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:e}){let{t,locale:n}=u(),r=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=r.outcomes.judge??0,c=Object.entries(r.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=r.total-s,d=[t(`smartRouting.recent.judged`,{count:s,total:r.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...r.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:r.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:r.total===0?t(`smartRouting.recent.none`):d}),l>=2&&l*2>r.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(y,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in x?f:`smartRouting.recent.hint.other`)}),r.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(r.lastFallback,t),time:i(r.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(y,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let r=X(e.reason),a={count:e.count,time:i(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(r??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),r&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${r}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=u(),i=H(t.protocol,t.baseUrl),a=e.judge.hasApiKey&&t.apiKey===``&&U(t.baseUrl,t.protocol,e.protocols)!==U(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,I.jsxs)(b,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>n({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(y,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=B[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(d,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(y,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>n({model:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(g,{className:`w-28`,label:r(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(y,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(y,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(h,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(l,{rows:4,"aria-label":r(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:t}){let{t:n}=u(),r=e(),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(null),[c,d]=(0,F.useState)([]),f=()=>{s(null),d([]),r.mutate({text:i,judge:K(t),grades:t.grades},{onSuccess:s,onError:e=>d(Y(e,t,n))})},p=o!==null&&o.latencyMs>o.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:n(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`smartRouting.test.hint`)}),(0,I.jsx)(l,{rows:3,"aria-label":n(`smartRouting.test.title`),placeholder:n(`smartRouting.test.placeholder`),value:i,onChange:e=>a(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(_,{size:`sm`,disabled:i.trim()===``,loading:r.isPending,onClick:f,children:n(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(y,{tone:`danger`,title:n(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),o&&(o.ok?(0,I.jsx)(y,{tone:o.confident&&!p?`success`:`warning`,title:n(`smartRouting.test.result`,{grade:o.gradeName??o.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:o.model?n(`smartRouting.test.model`,{model:o.model}):n(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[n(`smartRouting.test.confidence`,{percent:Math.round((o.confidence??0)*100)}),` ·`,` `,o.confident?n(`smartRouting.test.confident`):n(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[n(`smartRouting.test.slow`,{ms:o.latencyMs,limit:o.limitMs}),o.newConnection&&` ${n(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`smartRouting.test.meta`,{ms:o.latencyMs,input:o.inputTokens,output:o.outputTokens,model:o.judgeModel??``})})]})}):(0,I.jsxs)(y,{tone:`danger`,title:n(`smartRouting.test.failed`,{reason:Z(o.failure,n)}),children:[o.message,o.failure===`timeout`&&o.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:n(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:n}){let{t:r}=u(),i=t(),a=e.grades,o=(t,r=e.fallbackGrade)=>n({grades:t,fallbackGrade:t.some(e=>e.id===r)?r:t[Math.floor(t.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},f=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],h=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:h.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:h.has(e.id)?void 0:e.providerName})),v=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
|
|
2
|
-
`);s(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(b,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[a.map((t,n)=>(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,I.jsx)(d,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>s(n,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,I.jsx)(m,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(P,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>c(n,-1)}),(0,I.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===a.length-1,onClick:()=>c(n,1)}),(0,I.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:a.length<=L,onClick:()=>o(a.filter((e,t)=>t!==n))})]}),(0,I.jsx)(l,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>s(n,{description:e.target.value})}),(0,I.jsx)(O,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:t.model?V(t.providerId,t.model):``,options:v(t),onChange:e=>y(n,e)})]},t.id)),i.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(_,{size:`sm`,icon:(0,I.jsx)(A,{className:`size-3.5`}),disabled:a.length>=R,onClick:f,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=u();return(0,I.jsxs)(b,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(c,{ariaLabel:n(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:n(`smartRouting.rules.mode.session`)},{value:`turn`,label:n(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(g,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(O,{className:`w-44`,ariaLabel:n(`smartRouting.rules.fallback`),value:e.fallbackGrade,onChange:e=>t({fallbackGrade:e}),options:e.grades.map(e=>({value:e.id,label:e.name||e.id}))})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(g,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(g,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(g,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(h,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(d,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=u();return(0,I.jsx)(N,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ba as e,G as t,J as n,Q as r,Sr as i,Ua as a,Wr as o,Y as s,_ as c,c as ee,ct as l,lr as u,n as d,oi as f,q as p,r as m,ri as h,s as te,sr as g,t as _,ti as v,v as y,za as b}from"./alert-CuKAE1Sv.js";import{J as ne,Q as re,X as ie,Y as ae,Z as oe,a as x}from"./overlays-DeHu6TU_.js";import{t as S}from"./arrow-left-DX1c-nYY.js";import{$ as C,D as w,O as T,R as E,Z as D,et as O,h as k,m as A}from"./index-CKrvKDIJ.js";import{a as j,n as M}from"./TokenPoolEditor-DfmDnnxw.js";var N=a(e(),1),P=b();function F(){let{id:e=``}=O(),{t:a,locale:b}=l(),F=C(),[L,R]=(0,N.useState)(`7d`),z=h(e),B=u(),V=o(L,void 0,e),H=v(L,L===`today`?`hour`:`day`,`token`,void 0,e),U=f(L,void 0,20,e),W=g(L,e),G=i({token:e,page:1,pageSize:10},!1),K=j(),q=(0,P.jsx)(m,{variant:`glass`,icon:(0,P.jsx)(S,{className:`size-4`}),"aria-label":a(`common.back`),onClick:()=>F(`/tokens`)}),J=a(`range.${L}`),se=(0,N.useMemo)(()=>oe(ie(H.data??[],`requests`),re(L)).map(e=>({key:e.bucket,label:ae(e.bucket),axisLabel:ne(e.bucket),value:Math.round(e.value)})),[H.data,L]),Y=new Map((B.data??[]).map(e=>[e.id,e.name])),X=(W.data??[]).reduce((e,t)=>e+t.requests,0),ce=(W.data??[]).map(e=>({id:e.providerId,name:Y.get(e.providerId)??e.name??e.providerId,requests:e.requests,share:X?e.requests/X:0,success:e.successRate,ttft:e.avgTtftMs??null,cost:e.costUsd,out:e.failoversOut,in:e.failoversIn})),Z=[{key:`name`,label:a(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`share`,label:a(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>p(e)},{key:`success`,label:a(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?p(e):`—`},{key:`ttft`,label:a(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>t(e)},{key:`cost`,label:a(`overview.cost`),sortable:!0,numeric:!0,render:e=>r(e)},{key:`out`,label:a(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:a(`tokens.detail.failoversIn`),sortable:!0,numeric:!0}],le=(U.data??[]).map(e=>({model:e.model,requests:e.requests,tokens:e.tokens,cost:e.costUsd})),ue=[{key:`model`,label:a(`tokens.detail.model`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`tokens`,label:a(`overview.tokens`),sortable:!0,numeric:!0,render:e=>s(e,!0)},{key:`cost`,label:a(`overview.cost`),sortable:!0,numeric:!0,render:e=>r(e)}],de=(G.data?.items??[]).map(e=>({id:e.id,time:new Date(e.startedAtUtc).getTime(),model:e.requestedModel??`—`,provider:e.providerName??e.providerId??`—`,status:e.status,cost:e.costNanoUsd/1e9,r:e})),fe=[{key:`time`,label:a(`tokens.detail.time`),render:(e,t)=>n(t.r.startedAtUtc,b)},{key:`model`,label:a(`tokens.detail.model`)},{key:`provider`,label:a(`tokens.detail.provider`)},{key:`status`,label:a(`tokens.detail.status`),render:e=>(0,P.jsx)(d,{tone:e===`success`?`green`:`red`,children:a(`status.${e}`)})},{key:`cost`,label:a(`overview.cost`),numeric:!0,render:e=>r(e)}];if(z.isError)return(0,P.jsx)(k,{title:a(`nav.tokens`),leading:q,children:(0,P.jsx)(_,{tone:`danger`,title:a(`common.error`),children:x(z.error)})});let Q=z.data,$=V.data;return(0,P.jsx)(k,{title:Q?.name??``,subtitle:Q?(0,P.jsx)(`code`,{className:`font-mono`,children:Q.keyMasked}):void 0,leading:q,actions:(0,P.jsx)(D,{to:`/requests?token=${encodeURIComponent(e)}`,children:(0,P.jsx)(m,{icon:(0,P.jsx)(E,{className:`size-3.5`}),children:a(`tokens.detail.viewLogs`)})}),children:(0,P.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[(0,P.jsx)(`div`,{className:`flex justify-end`,children:(0,P.jsx)(c,{ariaLabel:a(`overview.range`),value:L,onChange:R,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:a(`range.${e}`)}))})}),$?(0,P.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-5`,children:[(0,P.jsx)(I,{label:a(`overview.totalCost`),value:r($.costUsd),context:J}),(0,P.jsx)(I,{label:a(`overview.totalRequests`),value:s($.requests),context:J}),(0,P.jsx)(I,{label:a(`overview.tokens`),value:s($.inputTokens+$.outputTokens,!0),context:a(`overview.tokensContext`,{input:s($.inputTokens,!0),output:s($.outputTokens,!0)})}),(0,P.jsx)(I,{label:a(`usage.hitRate`),value:p(A($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,P.jsx)(I,{label:a(`overview.successRate`),value:$.requests?p($.successRate):`—`,context:t($.avgTtftMs)})]}):(0,P.jsx)(y,{lines:3}),Q?.pool&&(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`tokens.pool.title`),` · `,a(`tokens.strategy.${Q.pool.strategy}`)]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-[13px]`,children:Q.pool.members.map(e=>(0,P.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,P.jsx)(te,{tone:M(e.health.state)}),Y.get(e.providerId)??e.providerId,(0,P.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:K(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,P.jsx)(`div`,{className:`card`,children:(0,P.jsx)(ee,{title:a(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:a(`overview.tokenEmpty.detail`,{range:J})})}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,P.jsx)(y,{lines:4}):(0,P.jsx)(T,{data:se,label:a(`overview.requests`),period:J,height:160,formatValue:e=>s(e),averageLabel:a(L===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:a(`overview.total`),categoryLabel:a(L===`today`?`overview.hour`:`overview.day`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-1 text-[13px] font-medium`,children:a(`tokens.detail.byProvider`)}),(0,P.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:a(`tokens.detail.byProviderHint`)}),(0,P.jsx)(w,{caption:a(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:a(`common.noData`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:a(`tokens.detail.byModel`)}),(0,P.jsx)(w,{caption:a(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:a(`common.noData`)})]})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsx)(`h2`,{className:`text-[13px] font-medium`,children:a(`tokens.detail.recent`)}),(0,P.jsx)(D,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(e)}`,children:a(`tokens.detail.viewLogs`)})]}),(0,P.jsx)(w,{caption:a(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:a(`common.noData`)})]})]})})}function I({label:e,value:t,context:n}){return(0,P.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,P.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,P.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,P.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{F as TokenDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ba as e,H as t,J as n,Or as r,Q as i,Rr as a,Ti as o,Tr as s,Ua as c,X as l,Y as u,_ as d,ai as f,c as p,ct as m,d as h,dn as g,fi as _,gt as v,ii as y,kr as b,l as x,lr as S,n as C,nn as w,p as T,q as E,r as D,rn as O,s as ee,t as te,v as k,xt as A,za as j}from"./alert-CuKAE1Sv.js";import{a as M,ct as N,i as P,n as ne,o as F,r as I}from"./overlays-DeHu6TU_.js";import{t as re}from"./chart-column-zt3ZRFLH.js";import{t as ie}from"./ellipsis-BH_FL485.js";import{t as ae}from"./pencil-fY6CohHT.js";import{t as oe}from"./power-B9MMcl6Y.js";import{t as se}from"./rotate-ccw-DsmSscuv.js";import{B as L,F as ce,H as R,P as z,R as le,U as ue,Z as B,_ as V,h as H,s as U,y as W}from"./index-CKrvKDIJ.js";import{a as de,i as G,n as K,r as q,t as J}from"./TokenPoolEditor-DfmDnnxw.js";var Y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Y.node;var X=A(Y),fe={name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]};fe.node;var pe=A(fe),Z=c(e(),1),Q=j(),me=[15,60,1440];function he({token:e,open:n,onOpenChange:r}){let{t:i,locale:a}=m(),{toast:o}=F(),[s,c]=(0,Z.useState)(15),[l,u]=(0,Z.useState)(null),f=y(e.id,n),p=O(e.id),h=b(e.id),g=e=>e<60?i(`tokens.invite.minutes`,{n:e}):i(`tokens.invite.hours`,{n:e/60}),_=()=>p.mutate(s,{onSuccess:async e=>{u(e.link),o(await N.copy(e.link)?i(`tokens.invite.copied`):i(`tokens.copyFailed`),`success`)},onError:e=>o(M(e),`error`)}),v=e=>e===`pending`?`accent`:e===`used`?`green`:`neutral`;return(0,Q.jsx)(P,{open:n,onOpenChange:e=>{e||u(null),r(e)},title:i(`tokens.invite.title`,{name:e.name}),description:i(`tokens.invite.description`),footer:(0,Q.jsx)(D,{variant:`primary`,icon:(0,Q.jsx)(X,{className:`size-3.5`}),loading:p.isPending,onClick:_,children:i(`tokens.invite.generate`)}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`tokens.invite.lifetime`)}),(0,Q.jsx)(d,{items:me.map(e=>({value:String(e),label:g(e)})),value:String(s),onChange:e=>c(Number(e)),ariaLabel:i(`tokens.invite.lifetime`)})]}),l&&(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`tokens.invite.linkOnce`)}),(0,Q.jsx)(`code`,{className:`selectable break-all rounded-lg bg-[var(--surface-muted)] px-3 py-2 font-mono text-[11.5px]`,children:l})]}),(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`tokens.invite.recent`)}),(f.data??[]).length===0?(0,Q.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`tokens.invite.none`)}):(0,Q.jsx)(`ul`,{className:`grid gap-1.5`,children:(f.data??[]).map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 rounded-lg border border-[var(--border)] px-3 py-2 text-[12px]`,children:[(0,Q.jsx)(C,{tone:v(e.status),children:i(`tokens.invite.status.${e.status}`)}),(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:e.status===`used`?i(`tokens.invite.usedAt`,{time:t(e.usedAt,a),ip:e.usedIp??`—`}):i(`tokens.invite.expires`,{time:t(e.expiresAt,a)})}),e.status===`pending`&&(0,Q.jsx)(D,{size:`sm`,variant:`plain`,className:`ml-auto`,loading:h.isPending&&h.variables===e.id,onClick:()=>h.mutate(e.id,{onError:e=>o(M(e),`error`)}),children:i(`tokens.invite.revoke`)})]},e.id))})]})]})})}function ge(){let{t:e}=m(),t=f(),n=a(),r=_(),i=r.data?.state===`connected`?r.data.publicUrl:null,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null);return(0,Q.jsxs)(H,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Q.jsx)(D,{variant:`primary`,icon:(0,Q.jsx)(L,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Q.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Q.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),i&&(0,Q.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${i}/v1`,key:`${i}/key`})})]}),t.isLoading&&(0,Q.jsx)(k,{lines:4}),t.isError&&(0,Q.jsx)(te,{tone:`danger`,title:e(`common.error`),children:M(t.error)}),t.data?.length===0&&(0,Q.jsx)(`div`,{className:`card`,children:(0,Q.jsx)(p,{icon:(0,Q.jsx)(R,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Q.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Q.jsx)(_e,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,Q.jsx)(Se,{open:o,onOpenChange:s}),(0,Q.jsx)(Ce,{token:c,onClose:()=>l(null)})]})}function _e({token:e,defaultOpen:c,onEdit:l}){let{t:d,locale:f}=m(),{toast:p,confirm:h}=F(),_=S(),y=a(),b=r(),x=o(),w=s(),T=g(),[E,O]=(0,Z.useState)(c),te=(_.data??[]).find(t=>t.id===e.providerId),k=de(),A=`token-detail-${e.id}`,j=(e,t)=>{p(t,`success`),e.skipped.length>0&&p(d(`tokens.skipped`,{clients:e.skipped.map(e=>V[e]?.name??e).join(`, `)}),`error`)},P=()=>b.mutate(e.id,{onSuccess:async({token:e})=>{await N.copy(e)?p(d(`tokens.copied`)):p(d(`tokens.copyFailed`),`error`)},onError:e=>p(M(e),`error`)}),[I,L]=(0,Z.useState)(!1),R=async()=>{let e=y.data?.gatewayBaseUrl;e&&(await N.copy(`${e}/v1`)?p(d(`tokens.urlCopied`)):p(d(`tokens.copyFailed`),`error`))},H=async()=>{let e=y.data?.gatewayBaseUrl;e&&(await N.copy(`npx @aidotnet/astra-connect join ${e}`)?p(d(`tokens.joinCopied`)):p(d(`tokens.copyFailed`),`error`))},U=async()=>{(!e.enabled||await h({title:d(`tokens.disableConfirm`,{name:e.name}),detail:d(`tokens.disableDetail`),confirmLabel:d(`tokens.disable`),destructive:!0}))&&x.mutate({id:e.id,enabled:!e.enabled},{onError:e=>p(M(e),`error`)})},G=async()=>{await h({title:d(`tokens.resetConfirm`,{name:e.name}),detail:d(`tokens.resetDetail`),confirmLabel:d(`tokens.reset`),destructive:!0})&&w.mutate(e.id,{onSuccess:e=>j(e,d(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>p(M(e),`error`)})},q=async()=>{await h({title:d(`tokens.deleteConfirm`,{name:e.name}),detail:d(`tokens.deleteDetail`),confirmLabel:d(`common.delete`),destructive:!0})&&T.mutate(e.id,{onSuccess:t=>j(t,d(`tokens.deleted`,{name:e.name})),onError:e=>p(M(e),`error`)})},J=e.lastUsedAt?t(e.lastUsedAt,f):d(`tokens.neverUsed`);return(0,Q.jsxs)(`article`,{children:[(0,Q.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>O(e=>!e),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":E,"aria-controls":A,"aria-label":d(`tokens.details`),onClick:e=>{e.stopPropagation(),O(e=>!e)},children:(0,Q.jsx)(ue,{className:`size-4 transition-transform ${E?`rotate-90`:``}`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Q.jsx)(C,{tone:`accent`,children:d(`tokens.default`)}),!e.enabled&&(0,Q.jsx)(C,{tone:`orange`,children:d(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Q.jsx)(C,{tone:`orange`,children:d(`tokens.limitExhausted`)}),e.pool&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Q.jsx)(C,{children:d(`tokens.pool.summary`,{count:e.pool.members.length,strategy:d(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Q.jsx)(ee,{tone:K(e.health.state)},e.providerId))]})]}),(0,Q.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Q.jsx)(D,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(v,{className:`size-3.5`}),"aria-label":d(`tokens.copy`),title:d(`tokens.copy`),loading:b.isPending,onClick:P}),(0,Q.jsx)(D,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(X,{className:`size-3.5`}),"aria-label":d(`tokens.copyUrl`),title:d(`tokens.copyUrl`),disabled:!y.data,onClick:()=>void R()}),(0,Q.jsx)(D,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(ce,{className:`size-3.5`}),"aria-label":d(`tokens.copyJoin`),title:d(`tokens.copyJoin`),disabled:!y.data,onClick:()=>void H()}),(0,Q.jsx)(D,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(pe,{className:`size-3.5`}),"aria-label":d(`tokens.invite.open`),title:d(`tokens.invite.open`),disabled:!e.enabled,onClick:()=>L(!0)}),(0,Q.jsx)(he,{token:e,open:I,onOpenChange:L})]})]})]}),(0,Q.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>V[e]?.name??e).join(`, `)||d(`tokens.noClients`),children:e.clients.length===0?(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Q.jsx)(W,{kind:e,size:16},e))}),(0,Q.jsx)($,{label:d(`tokens.today`),value:i(e.today.costUsd),context:d(`tokens.requestsContext`,{count:u(e.today.requests)})}),(0,Q.jsx)($,{label:d(`tokens.total`),value:i(e.total.costUsd),context:`${u(e.total.totalTokens,!0)} Token`}),(0,Q.jsx)($,{label:d(`tokens.lastUsedTitle`),value:e.lastUsedAt?n(e.lastUsedAt,f):`—`,context:e.lastUsedAt?``:d(`tokens.neverUsed`),title:J}),(0,Q.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(ne,{label:d(`common.more`),icon:(0,Q.jsx)(ie,{className:`size-4`}),items:[{id:`settings`,label:d(`tokens.settings`),icon:(0,Q.jsx)(ae,{className:`size-3.5`}),onSelect:l},{id:`toggle`,label:e.enabled?d(`tokens.disable`):d(`tokens.enable`),icon:(0,Q.jsx)(oe,{className:`size-3.5`}),onSelect:()=>void U()},{id:`reset`,label:d(`tokens.reset`),icon:(0,Q.jsx)(se,{className:`size-3.5`}),onSelect:()=>void G()},...e.isDefault?[]:[{id:`delete`,label:d(`tokens.delete`),icon:(0,Q.jsx)(z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),E&&(0,Q.jsxs)(`div`,{id:A,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Q.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:d(`tokens.clients`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?d(`tokens.noClients`):e.clients.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Q.jsx)(W,{kind:e,size:14}),V[e]?.name??e]},e))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?d(`tokens.pool.title`):d(`tokens.directProvider`)}),e.pool?(0,Q.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:k(e.health),children:[(0,Q.jsx)(ee,{tone:K(e.health.state)}),(_.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:te?.name??(e.providerId?e.providerId:d(`tokens.directNone`))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:d(`tokens.allowedClients`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?d(`tokens.allowedClientsAny`):e.allowedClients.length===0?d(`tokens.directOnly`):e.allowedClients.map(e=>V[e]?.name??e).join(`, `)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:d(`tokens.lastUsedTitle`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:J})]})]}),(0,Q.jsx)(ve,{token:e}),(0,Q.jsx)(be,{today:e.today,total:e.total}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Q.jsx)(B,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Q.jsx)(D,{size:`sm`,icon:(0,Q.jsx)(re,{className:`size-3.5`}),children:d(`tokens.detail.open`)})}),(0,Q.jsx)(B,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Q.jsx)(D,{size:`sm`,icon:(0,Q.jsx)(le,{className:`size-3.5`}),children:d(`tokens.detail.viewLogs`)})})]})]})]})}function ve({token:e}){let{t}=m(),n=e.limits?.rpm;return(0,Q.jsxs)(`div`,{className:`mt-3`,children:[(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Q.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Q.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Q.jsx)(ye,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Q.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Q.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function ye({usage:e}){let{t:n,locale:r}=m(),a=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,o=t=>e.metric===`cost`?i(t):u(t,!0),s=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:a}),(0,Q.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(e.used),limit:o(e.limit)})})]}),(0,Q.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":a,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,Q.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:t(e.resetsAt,r)})})]})}function $({label:e,value:t,context:n,title:r}){return(0,Q.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Q.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function be({today:e,total:t}){let{t:n}=m(),r=[[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,Q.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Q.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Q.jsx)(`th`,{className:`${a} text-left`}),(0,Q.jsx)(`th`,{className:a,children:n(`tokens.cost`)}),(0,Q.jsx)(`th`,{className:a,children:n(`tokens.requests`)}),(0,Q.jsx)(`th`,{className:a,children:n(`tokens.tokens`)}),(0,Q.jsx)(`th`,{className:a,children:n(`tokens.inOut`)}),(0,Q.jsx)(`th`,{className:a,children:n(`tokens.cacheHit`)}),(0,Q.jsx)(`th`,{className:a,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Q.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Q.jsx)(`td`,{className:`${o} font-semibold selectable`,children:i(t.costUsd)}),(0,Q.jsx)(`td`,{className:o,children:u(t.requests)}),(0,Q.jsx)(`td`,{className:o,children:u(t.totalTokens,!0)}),(0,Q.jsxs)(`td`,{className:`${o} text-[var(--text-secondary)]`,children:[u(t.inputTokens,!0),` / `,u(t.outputTokens,!0)]}),(0,Q.jsx)(`td`,{className:o,title:n(`usage.cacheAmounts`,{read:u(t.cacheReadTokens,!0),write:u(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:E(t.cacheHitRate)}),(0,Q.jsx)(`td`,{className:o,children:t.tps==null?`—`:l(t.tps)})]},e))})]})})}function xe(){let{t:e}=m(),t=(S().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function Se({open:e,onOpenChange:t}){let{t:n}=m(),{toast:r}=F(),i=w(),{options:a}=xe(),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Q.jsx)(P,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(D,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Q.jsx)(D,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(M(e),`error`)}),children:n(`common.create`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(x,{label:n(`tokens.name`),children:(0,Q.jsx)(h,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Q.jsx)(x,{label:n(`tokens.directProvider`),children:(0,Q.jsx)(I,{value:c,onChange:l,options:a})})]})})}function Ce({token:e,onClose:t}){let{t:n}=m(),{toast:r}=F(),i=o(),a=S(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(null),[f,p]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(`any`),[b,C]=(0,Z.useState)([]),w=new Set(f.map(e=>`${e.metric}:${e.period}`)).size<f.length,E=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,Z.useEffect)(()=>{e&&(c(e.name),u(q(e)),p(e.limits?.budgets.map(e=>({...e}))??[]),_(e.limits?.rpm??null),y(e.allowedClients==null?`any`:`only`),C(e.allowedClients??[]))},[e]),(0,Q.jsx)(P,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(D,{onClick:t,children:n(`common.cancel`)}),(0,Q.jsx)(D,{variant:`primary`,disabled:!s.trim()||w,loading:i.isPending,onClick:()=>{if(!e)return;let o=f.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),c=o.length>0||g!=null&&g>0?{budgets:o,rpm:g!=null&&g>0?Math.floor(g):null}:null;i.mutate({id:e.id,name:s.trim(),...l?{pool:G(l,a.data??[])}:{},limits:c,allowedClients:v===`any`?null:b},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(M(e),`error`)})},children:n(`common.save`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(x,{label:n(`tokens.name`),children:(0,Q.jsx)(h,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,Q.jsx)(x,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:l&&(0,Q.jsx)(J,{draft:l,onChange:u,providers:a.data??[],health:E})}),(0,Q.jsx)(x,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:w?n(`tokens.limitDuplicate`):void 0,children:(0,Q.jsx)(Ee,{budgets:f,onChange:p})}),(0,Q.jsx)(x,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Q.jsx)(T,{value:g,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:_})}),(0,Q.jsx)(x,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:v,onChange:y,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),v===`only`&&(0,Q.jsx)(U,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(V),...b])].map(e=>({value:e,label:V[e]?.name??e})),value:b,onValueChange:e=>C(e)})]})})]})})}var we=[`cost`,`requests`,`tokens`],Te=[`day`,`week`,`month`,`total`];function Ee({budgets:e,onChange:t}){let{t:n}=m(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=we.flatMap(e=>Te.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Q.jsx)(I,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:we.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Q.jsx)(I,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:Te.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Q.jsx)(T,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,Q.jsx)(D,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(z,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,Q.jsx)(`div`,{children:(0,Q.jsx)(D,{size:`sm`,icon:(0,Q.jsx)(L,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{ge as TokensPage};
|