@aidotnet/server-linux-x64 0.9.7 → 0.10.0
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-C-x5kPpG.js +9 -0
- package/bin/wwwroot/assets/KeyPage-CxvUUC6Z.js +1 -0
- package/bin/wwwroot/assets/ModelDetailPage-CQol60ci.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-Bp1-Rhad.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-YPDqytJ6.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-Co1ffmVU.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-CacRreeZ.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-DSwvae35.js +2 -0
- package/bin/wwwroot/assets/SettingsPage-CvIE8pBq.js +2 -0
- package/bin/wwwroot/assets/TokenDetailPage-w1XONN5-.js +1 -0
- package/bin/wwwroot/assets/TokenPoolEditor-BITgITLH.js +1 -0
- package/bin/wwwroot/assets/TokensPage-CiL0dLkj.js +1 -0
- package/bin/wwwroot/assets/{TracesPage-C9mYB_7E.js → TracesPage-zcvvDcj3.js} +2 -2
- package/bin/wwwroot/assets/TrayPanelPage-BwaSGRbR.js +1 -0
- package/bin/wwwroot/assets/{TrayPanelView-BpQQa0qi.js → TrayPanelView-CAF6qwfK.js} +1 -1
- package/bin/wwwroot/assets/alert-BhYHbQ5M.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-DP0xP3tk.js → arrow-down-CHVkKqVB.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-UUQiUGQ1.js → arrow-left-ByzgpjKh.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-BEWRhO5r.js → checkbox-B_oHm90b.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-DebyBXx2.js → cloud-download-DEv0Zu87.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-RDk31i1j.js +1 -0
- package/bin/wwwroot/assets/{download-C4--ZCHf.js → download-DXwZa8b6.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-D250KISp.js → ellipsis-DhvUvMq3.js} +1 -1
- package/bin/wwwroot/assets/{external-link-Bnshhxip.js → external-link-D9cY56rt.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-BzVuhS53.js → folder-open-Dt-7Rdbw.js} +1 -1
- package/bin/wwwroot/assets/{index-DE_l9Wt4.css → index-Dt3DJ3Cx.css} +1 -1
- package/bin/wwwroot/assets/index-XVK9epgF.js +17 -0
- package/bin/wwwroot/assets/{log-out-DEZofPIg.js → log-out-wpGBd0OK.js} +1 -1
- package/bin/wwwroot/assets/minus-3JX68qL9.js +1 -0
- package/bin/wwwroot/assets/overlays-CF55BHOs.js +41 -0
- package/bin/wwwroot/assets/{pencil-DuD1bQje.js → pencil-BjMGSY_u.js} +1 -1
- package/bin/wwwroot/assets/{power-LE8gLJKc.js → power-zBXM8vYz.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-BVdDbnT-.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-Cx9vNOkF.js → rotate-ccw-Omdd6cJU.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-B0eMzUNN.js → sortable.esm-CTCQ-9IR.js} +1 -1
- package/bin/wwwroot/index.html +4 -4
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-DEetiYfc.js +0 -9
- package/bin/wwwroot/assets/KeyPage-cq7HprCR.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-Uj6p-r8V.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-B-l5oEGF.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-BH9KjyfC.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-C5XhVKZd.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-uLPHWm2i.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-CNU_ji4e.js +0 -2
- package/bin/wwwroot/assets/SettingsPage-B3tbYdLW.js +0 -2
- package/bin/wwwroot/assets/TokenDetailPage-BVyb_-ev.js +0 -1
- package/bin/wwwroot/assets/TokenPoolEditor-7LX143SO.js +0 -1
- package/bin/wwwroot/assets/TokensPage-vRrXvqkK.js +0 -1
- package/bin/wwwroot/assets/TrayPanelPage-NIkRrLCt.js +0 -1
- package/bin/wwwroot/assets/alert-CN1yWco4.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-DwiVsert.js +0 -1
- package/bin/wwwroot/assets/index-CBrXkG99.js +0 -17
- package/bin/wwwroot/assets/minus-BAoIEc33.js +0 -1
- package/bin/wwwroot/assets/overlays-D2pWmtov.js +0 -41
- package/bin/wwwroot/assets/radio-cards-D1yOuSfh.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Cr as e,Dt as t,E as n,Ea as r,Fi as i,G as a,Hr as o,Ii as s,Jn as c,Li as l,Mi as u,Ni as d,Oa as f,Pi as p,Q as m,Qt as h,Sn as g,Ta as _,Vr as v,Wr as y,Y as b,_ as x,_t as S,ai as C,at as w,b as T,c as E,d as D,f as O,h as k,i as A,ir as j,ka as M,l as N,lt as ee,m as P,mn as F,n as I,p as L,r as R,rr as z,s as B,st as V,t as H,tr as te,u as U,v as ne,vi as re,w as ie,wa as W,xn as G,y as ae,yt as oe}from"./alert-BhYHbQ5M.js";import{A as se,C as ce,D as le,E as ue,O as de,T as fe,X as pe,a as K,ct as me,dt as he,ft as ge,i as _e,k as ve,mt as ye,o as be,pt as xe,r as Se,ut as Ce,w as we}from"./overlays-CF55BHOs.js";import{t as Te}from"./arrow-left-ByzgpjKh.js";import{t as Ee}from"./download-DXwZa8b6.js";import{n as De,t as Oe}from"./radio-cards-BVdDbnT-.js";import{$ as ke,F as Ae,J as je,L as Me,R as Ne,S as Pe,Z as Fe,_ as Ie,b as Le,et as Re,g as ze,h as Be,j as Ve,k as He,tt as Ue,x as We}from"./index-XVK9epgF.js";import{t as Ge}from"./checkbox-B_oHm90b.js";var q=M(r(),1);function Ke(e,t,n){(0,q.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var qe={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`]};qe.node;var Je=oe(qe),Ye={name:`gauge`,size:24,node:[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]};Ye.node;var Xe=oe(Ye),Ze={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Ze.node;var Qe=oe(Ze),J={card:`_card_i7fo0_3`,trigger:`_trigger_i7fo0_6`,media:`_media_i7fo0_7`,zoom:`_zoom_i7fo0_8`,content:`_content_i7fo0_9`,description:`_description_i7fo0_12`,footer:`_footer_i7fo0_13`,title:`_title_i7fo0_15`,byline:`_byline_i7fo0_22`,avatar:`_avatar_i7fo0_23`,bylineText:`_bylineText_i7fo0_26`,meta:`_meta_i7fo0_27`,status:`_status_i7fo0_28`,roll:`_roll_i7fo0_30`,line:`_line_i7fo0_31`,word:`_word_i7fo0_32`,srOnly:`_srOnly_i7fo0_33`,action:`_action_i7fo0_34`,overlay:`_overlay_i7fo0_36`,panel:`_panel_i7fo0_38`,closeSlot:`_closeSlot_i7fo0_48`,close:`_close_i7fo0_48`,details:`_details_i7fo0_51`},Y=_(),{blur:$e,duration:X,ease:et,spring:tt,stagger:nt}=n,rt={...tt.smooth,visualDuration:.3},it={...tt.smooth,visualDuration:.26},at=300,ot={duration:X.instant},st=1.04,ct={duration:X.considered*2,ease:[...et.standard]},lt={duration:X.considered,ease:[...et.standard]},ut={delay:X.instant,duration:X.standard,ease:[...et.enter]},dt={delay:X.instant,duration:X.fast,ease:[...et.enter]},ft={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${$e.subtle}px)`,transition:{duration:X.fast,ease:[...et.standard]}}},pt={enter:{opacity:0,y:`.3em`,filter:`blur(${$e.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:X.standard,ease:[...et.enter],delay:e*nt.word}})};function mt({text:e,reduced:t}){return(0,Y.jsxs)(`span`,{className:J.status,role:`status`,children:[(0,Y.jsx)(`span`,{className:J.srOnly,children:e}),(0,Y.jsx)(`span`,{className:J.roll,"aria-hidden":`true`,children:(0,Y.jsx)(l,{mode:`popLayout`,initial:!1,children:(0,Y.jsx)(u.span,{className:J.line,variants:ft,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,Y.jsx)(u.span,{className:J.word,custom:t/2,variants:pt,children:e},t))},e)})})]})}function ht(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function gt({title:e,description:t,media:n,action:r,avatar:i,meta:a,status:o,details:c,open:d,defaultOpen:f=!1,onOpenChange:m,children:h,className:g,style:_,...v}){let y=p()??!1,b=(0,q.useId)(),x=(0,q.useRef)(null),S=(0,q.useRef)(null),[C,w]=(0,q.useState)(f),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)({}),[k,A]=(0,q.useState)(null),j=c?d??C:!1,M=!!c&&!y,N=!j&&k!==null,P=!!t,F=(0,q.useCallback)(e=>{d===void 0&&w(e),m?.(e)},[d,m]);(0,q.useEffect)(()=>{let e=x.current,t=S.current;if(!M||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=ht(e,n.borderTopLeftRadius),i=ht(e,n.getPropertyValue(`--radius-surface`)),a=t?.offsetWidth||void 0;O(e=>e.card!==void 0&&e.measure===a?e:{card:e.card??r,panel:e.panel??i,measure:a})});return n.observe(e),t&&n.observe(t),()=>n.disconnect()},[M,P]);let I=(0,q.useRef)(j);(0,q.useLayoutEffect)(()=>{let e=I.current&&!j;I.current=j;let t=x.current;if(j)A(null);else if(e&&M&&t){let e=t.getBoundingClientRect();A({top:e.top,left:e.left,width:e.width,height:e.height})}},[j,M]),(0,q.useEffect)(()=>{if(!N)return;let e=window.setTimeout(()=>A(null),at);return()=>window.clearTimeout(e)},[N]);let L=(e,t,n=!0)=>M?{layoutId:e,layout:n,layoutCrossfade:!1,layoutDependency:t===`card`?j:N?`return`:`panel`,transition:{layout:t===`card`?it:rt}}:{},R=e=>i||a||o||r?(0,Y.jsxs)(`div`,{className:J.footer,children:[i||a||o?(0,Y.jsxs)(u.div,{className:J.byline,...L(`byline`,e,`position`),children:[i?(0,Y.jsx)(`span`,{className:J.avatar,children:i}):null,(0,Y.jsxs)(`span`,{className:J.bylineText,children:[a?(0,Y.jsx)(`span`,{className:J.meta,children:a}):null,o?(0,Y.jsx)(mt,{text:o,reduced:y}):null]})]}):null,r?(0,Y.jsx)(u.div,{className:J.action,...L(`action`,e,`position`),children:r}):null]}):null,z=(0,Y.jsxs)(u.article,{...v,ref:x,className:[J.card,g].filter(Boolean).join(` `),style:{..._,borderRadius:D.card??_?.borderRadius},"data-hover":T||void 0,whileHover:y?void 0:{y:-2},onHoverStart:()=>E(!0),onHoverEnd:()=>E(!1),...L(`card`,`card`),transition:{default:tt.snappy,layout:it},children:[n?(0,Y.jsx)(u.div,{className:J.media,...L(`media`,`card`),children:(0,Y.jsx)(u.div,{className:J.zoom,initial:!1,animate:{scale:T&&!y?st:1},transition:T?ct:lt,children:n})}):null,(0,Y.jsxs)(`div`,{className:J.content,children:[(0,Y.jsx)(u.h3,{className:J.title,...L(`title`,`card`),children:c?(0,Y.jsx)(se,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:J.trigger,children:e})}):e}),t?(0,Y.jsx)(u.p,{ref:S,className:J.description,...L(`description`,`card`,`position`),children:t}):null,h,R(`card`)]})]});return c?(0,Y.jsx)(ce,{open:j,onOpenChange:F,children:(0,Y.jsxs)(s,{id:b,children:[z,(0,Y.jsx)(l,{children:(j||N)&&(0,Y.jsxs)(de,{forceMount:!0,children:[(0,Y.jsx)(l,{children:j&&(0,Y.jsx)(le,{asChild:!0,forceMount:!0,children:(0,Y.jsx)(u.div,{className:J.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:y?ot:{duration:X.exit,ease:[...et.standard]}},transition:y?ot:{duration:X.standard,ease:[...et.enter]}})},`overlay`)}),(0,Y.jsx)(fe,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,Y.jsxs)(u.div,{className:J.panel,"data-framer-portal-id":b,"data-returning":N||void 0,layoutScroll:!0,style:{borderRadius:D.panel,"--card-measure":D.measure?`${D.measure}px`:void 0,...k&&N?{"--landing-top":`${k.top}px`,"--landing-left":`${k.left}px`,"--landing-width":`${k.width}px`,"--landing-height":`${k.height}px`}:{}},...M?{...L(`card`,`panel`),initial:!1,animate:D.card!==void 0&&D.panel!==void 0?{borderRadius:N?D.card:D.panel}:void 0,transition:{layout:N?it:rt,borderRadius:N?it:rt},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:ot},transition:ot},children:[n?(0,Y.jsx)(u.div,{className:J.media,...L(`media`,`panel`),children:(0,Y.jsx)(u.div,{className:J.zoom,initial:{scale:T&&!y?st:1},animate:{scale:1},transition:rt,children:n})}):null,(0,Y.jsx)(u.span,{className:J.closeSlot,initial:y?{opacity:0}:{opacity:0,scale:.9},animate:N?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:N||y?ot:dt,children:(0,Y.jsx)(we,{asChild:!0,children:(0,Y.jsx)(u.button,{type:`button`,className:J.close,"aria-label":`Close quick look`,whileTap:y?void 0:{scale:.94},transition:tt.snappy,children:(0,Y.jsx)(ee,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,Y.jsxs)(`div`,{className:J.content,children:[(0,Y.jsx)(ve,{asChild:!0,children:(0,Y.jsx)(u.h2,{className:J.title,...L(`title`,`panel`),children:e})}),t?(0,Y.jsx)(ue,{asChild:!0,children:(0,Y.jsx)(u.p,{className:J.description,...L(`description`,`panel`,`position`),children:t})}):null,h,R(`panel`),(0,Y.jsx)(u.div,{className:J.details,initial:!y&&{opacity:0,y:6},animate:N?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:ot},transition:N||y?ot:ut,children:c})]})]})})]},`quick-look`)})]})}):z}var Z={figure:`_figure_1clu4_1`,caption:`_caption_1clu4_1`,label:`_label_1clu4_1`,accent:`_accent_1clu4_2`,success:`_success_1clu4_2`,warning:`_warning_1clu4_2`,danger:`_danger_1clu4_2`,point:`_point_1clu4_4`,roll:`_roll_1clu4_7`,track:`_track_1clu4_9`,slot:`_slot_1clu4_9`,glyph:`_glyph_1clu4_9`,sizer:`_sizer_1clu4_11`,plot:`_plot_1clu4_14`,chart:`_chart_1clu4_17`,baseline:`_baseline_1clu4_18`,area:`_area_1clu4_20`,line:`_line_1clu4_21`,trail:`_trail_1clu4_21`,cursor:`_cursor_1clu4_24`,end:`_end_1clu4_25`},_t={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${n.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.standard,ease:[...n.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${n.blur.subtle}px)`,transition:{duration:n.duration.fast,ease:[...n.ease.standard]}})},vt={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}}},yt=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),bt=new Intl.NumberFormat(`en-US`),xt={duration:n.duration.considered*1.75,ease:[...n.ease.inOut]},St={duration:n.duration.fast,ease:[...n.ease.standard]};function Ct(e,t){if(!e)return[];if(t)return[{slot:`all`,key:e,text:e}];if(!/\p{L}/u.test(e))return[...e].map((e,t,n)=>({slot:`n${n.length-t}`,key:e,text:e}));let n=e.split(/(?<=\s)/);return n.map((e,t)=>({slot:`w${t}`,key:n.slice(0,t+1).join(``),text:e}))}function wt({text:e,direction:t,whole:r=!1,morph:a=!1,tone:o}){let s=!!p(),c=(0,q.useRef)(null),f=i(`auto`),[m,h]=(0,q.useState)({text:e,direction:1});m.text!==e&&h({text:e,direction:t??(yt(e)<yt(m.text)?-1:1)}),(0,q.useEffect)(()=>{let e=c.current;if(!e||typeof ResizeObserver>`u`)return;let t=null,r=new ResizeObserver(([r])=>{if(!r)return;let i=r.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;t!==null&&t!==e.textContent&&!s?d(f,i,n.spring.morph):f.jump(i),t=e.textContent});return r.observe(e),()=>r.disconnect()},[a,s,f]);let g=!r&&!/\p{L}/u.test(e),_=s?vt:_t,v=g?`right`:`left`;return(0,Y.jsxs)(u.span,{className:Z.roll,"data-end":g||void 0,"data-whole":r||void 0,style:a?{width:f}:void 0,children:[a&&(0,Y.jsx)(`span`,{ref:c,className:Z.sizer,"aria-hidden":`true`,children:e}),(0,Y.jsx)(`span`,{className:Z.track,children:(0,Y.jsx)(l,{mode:`popLayout`,initial:!1,custom:m.direction,anchorX:v,children:Ct(e,r).map(e=>(0,Y.jsx)(u.span,{className:Z.slot,custom:m.direction,variants:_,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,Y.jsx)(l,{mode:`popLayout`,initial:!1,custom:m.direction,anchorX:v,children:(0,Y.jsx)(u.span,{className:o?`${Z.glyph} ${o}`:Z.glyph,custom:m.direction,variants:_,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${o??``}${e.key}`)})},e.slot))})})]})}var Tt=5,Et=1.25,Dt=Array.from({length:161},(e,t)=>t/160);function Ot(e){let t=Math.min(...e),n=Math.max(...e)-t,r=e.map(e=>n?(e-t)/n:.5),i=r.length-1,a=1/i,o=r.slice(1).map((e,t)=>(e-r[t])/a),s=r.map((e,t)=>t===0||t===i?o[0]:(Math.sign(o[t-1])+Math.sign(o[t]))*Math.min(Math.abs(o[t-1]),Math.abs(o[t]),Math.abs(o[t-1]+o[t])/4)||0);i>1&&(s[0]=(3*o[0]-s[1])/2,s[i]=(3*o[i-1]-s[i-1])/2);let c=Math.max(1,Math.min(16,Math.round(128/i))),l=[];for(let e=0;e<i;e++)for(let t=0;t<c;t++){let n=t/c,i=n*n,o=i*n,u=(2*o-3*i+1)*r[e]+(o-2*i+n)*a*s[e]+(3*i-2*o)*r[e+1]+(o-i)*a*s[e+1];l.push([(e+n)*a,Math.min(1,Math.max(0,u))])}return l.push([1,r[i]]),l}function kt(e,t){let n=0,r=e.length-1;if(t<=e[n][0])return e[n][1];if(t>=e[r][0])return e[r][1];for(;r-n>1;){let i=n+r>>1;e[i][0]<t?n=i:r=i}let[i,a]=e[n],[o,s]=e[r];return o===i?s:a+(s-a)*(t-i)/(o-i)}function At(e,t,n,r){let i=e=>Tt+(1-e)*(n-10),a=e.map(([e,n])=>[e*t,i(n)]),o=a.map(([e,t])=>`${e.toFixed(2)},${t.toFixed(2)}`),s=r*t,c=i(kt(e,r));return{points:a,line:o.join(` `),trail:`M${o.join(`L`)}`,fill:`M${o.join(`L`)}L${t},${n}L0,${n}Z`,dot:`${s},${c} ${s},${c}`,cx:s}}function jt(e,t){let n=e.slice(1).map(([t,n],r)=>Math.hypot(t-e[r][0],n-e[r][1])),r=t*n.reduce((e,t)=>e+t,0);for(let t=0;t<n.length;t++){let i=n[t],a=e[t][0];if(r<=i)return a+(e[t+1][0]-a)*(i?r/i:1);r-=i}return e[e.length-1][0]}function Mt({data:e,label:t,value:r,change:a,tone:o=`accent`,width:s=160,height:c=52,labels:l,formatValue:f,area:m=!0,interactive:h=!0}){let g=e.length>1?e:[e[0]??0,e[0]??0],_=g.length-1,v=g.join(`,`),y=(0,q.useMemo)(()=>Ot(v.split(`,`).map(Number)),[v]),b=`${t}: ${r??g[_]}. ${a??``}`.trim(),x=`sparkline${(0,q.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,S=(0,q.useRef)(null),C=(0,q.useRef)(null),w=Re(S,{once:!0,amount:.5}),T=!!p(),[E,D]=(0,q.useState)({w:s,h:c}),[O,k]=(0,q.useState)(null),[A,j]=(0,q.useState)(!1),M=O===null?null:Math.min(O,_),[N,ee]=(0,q.useState)({index:M,direction:1});N.index!==M&&ee({index:M,direction:M===null||N.index===null?1:Math.sign(M-N.index)||1});let[P]=(0,q.useState)(()=>At(y,s,c,1)),F=(0,q.useRef)(y),I=(0,q.useRef)(E),L=i(0),R=i(1),z=i(P.line),B=i(P.trail),V=i(P.fill),H=i(P.dot),te=i(P.cx),U=i(P.cx+Et+16),ne=i(P.cx+Et),re=i(0),ie=Ue(L,e=>+(e>.001)),W=(0,q.useCallback)(()=>{let{w:e,h:t}=I.current,n=L.get(),r=At(F.current,e,t,R.get());z.set(r.line),B.set(r.trail),V.set(r.fill),H.set(r.dot),te.set(r.cx),U.set(r.cx+Et+16),ne.set(r.cx+Et),re.set(n>=1?e+32:jt(r.points,n)+16)},[R,te,ne,H,L,V,z,U,re,B]);Ke(R,`change`,W),Ke(L,`change`,W),(0,q.useLayoutEffect)(()=>{let e=C.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&D(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*c/s})});return t.observe(e),()=>t.disconnect()},[c,s]),(0,q.useLayoutEffect)(()=>{I.current=E,W()},[E,W]),(0,q.useEffect)(()=>{if(T){L.jump(1);let e=requestAnimationFrame(()=>j(!0));return()=>cancelAnimationFrame(e)}if(!w)return;let e=d(L,1,{...xt,onComplete:()=>j(!0)});return()=>e.stop()},[L,w,T]),(0,q.useEffect)(()=>{let e=F.current;if(e===y)return;if(T){F.current=y,W();return}let t=[...new Set([...Dt,...y.map(([e])=>e)])].sort((e,t)=>e-t),r=t.map(t=>kt(e,t)),i=t.map(e=>kt(y,e)),a=d(0,1,{...n.spring.smooth,onUpdate:e=>{F.current=t.map((t,n)=>[t,r[n]+(i[n]-r[n])*e]),W()},onComplete:()=>{F.current=y,W()}});return()=>a.stop()},[W,T,y]),(0,q.useEffect)(()=>{let e=M===null?1:M/_;if(T){R.jump(e);return}let t=d(R,e,n.spring.snappy);return()=>t.stop()},[R,M,_,T]);let G=M!==null,ae=(e=>f?f(g[e],e):bt.format(g[e]))(M??_),oe=l?.[M??_],se=r===void 0?void 0:G?ae:r,ce=M===null?a??``:r===void 0?[ae,oe].filter(Boolean).join(` · `):oe??`${M+1} of ${_+1}`,le=e=>{let t=C.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(_,Math.round((e-t.left)/t.width*_))):_},ue=h?{role:`slider`,tabIndex:0,"aria-label":`${t}, explore values`,"aria-valuemin":1,"aria-valuemax":_+1,"aria-valuenow":(M??_)+1,"aria-valuetext":`${oe??(M===null?`Latest`:`Point ${M+1} of ${_+1}`)}: ${ae}`,onPointerDown:e=>k(le(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&k(le(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&k(null)},onPointerLeave:()=>k(null),onPointerCancel:()=>k(null),onBlur:()=>k(null),onKeyDown:e=>{if(e.key===`Escape`&&G){e.preventDefault(),k(null);return}let t=M??_,n=Math.max(1,Math.round((_+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:_}[e.key];r!==void 0&&(e.preventDefault(),k(Math.max(0,Math.min(_,r))))}}:{};return(0,Y.jsxs)(`figure`,{ref:S,className:Z.figure,"aria-label":b,children:[(0,Y.jsxs)(`figcaption`,{className:Z.caption,children:[(0,Y.jsx)(`span`,{className:Z.label,children:(0,Y.jsx)(wt,{text:t,whole:!0})}),se!==void 0&&(0,Y.jsx)(`strong`,{children:(0,Y.jsx)(wt,{text:se,morph:!0})}),(0,Y.jsx)(`small`,{className:Z[o],children:(0,Y.jsx)(wt,{text:ce,direction:G?N.direction:void 0,tone:G?Z.point:void 0,morph:!0})})]}),(0,Y.jsx)(`div`,{ref:C,className:Z.plot,"data-interactive":h||void 0,...ue,children:(0,Y.jsxs)(`svg`,{className:Z.chart,viewBox:`0 0 ${E.w} ${E.h}`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(`clipPath`,{id:`${x}-lit`,clipPathUnits:`userSpaceOnUse`,children:(0,Y.jsx)(u.rect,{x:-16,y:-16,width:U,height:E.h+32})}),(0,Y.jsx)(`clipPath`,{id:`${x}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,Y.jsx)(u.rect,{x:ne,y:-16,width:E.w+32,height:E.h+32})}),(0,Y.jsx)(`clipPath`,{id:`${x}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,Y.jsx)(u.rect,{x:-16,y:-16,width:re,height:E.h+32})})]}),m&&(0,Y.jsx)(u.path,{className:`${Z.area} ${Z[o]}`,d:V,clipPath:`url(#${x}-fill)`}),(0,Y.jsx)(`line`,{className:Z.baseline,x1:`0`,y1:E.h-.5,x2:E.w,y2:E.h-.5}),(0,Y.jsx)(u.path,{className:Z.trail,d:B,clipPath:`url(#${x}-dim)`,initial:!1,animate:{opacity:G&&A?1:0},transition:T?{duration:0}:St}),(0,Y.jsx)(u.polyline,{className:[Z.line,Z[o]].join(` `),points:z,clipPath:`url(#${x}-lit)`,style:{pathLength:L,opacity:ie}}),(0,Y.jsx)(u.line,{className:Z.cursor,x1:te,x2:te,y1:0,y2:E.h,initial:!1,animate:{opacity:+!!G},transition:T?{duration:0}:St}),(0,Y.jsx)(u.polyline,{className:[Z.end,Z[o]].join(` `),points:H,initial:!1,animate:{opacity:+!!A,strokeWidth:A?G?10:7:0},transition:T?{duration:0}:{opacity:St,strokeWidth:n.spring.snappy},fill:`none`,strokeLinecap:`round`})]})})]})}var Q={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`},Nt=e=>`blur(${e}px)`,$={duration:0},Pt={duration:n.duration.fast,ease:[...n.ease.standard]},Ft={duration:n.duration.standard,ease:[...n.ease.enter]},It={opacity:0,y:`0.3em`,filter:Nt(n.blur.soft)},Lt={opacity:1,y:0,filter:Nt(0)},Rt={opacity:0,y:`-0.3em`,filter:Nt(n.blur.subtle)},zt={opacity:0,scale:.5,filter:Nt(n.blur.subtle)},Bt={opacity:1,scale:1,filter:Nt(0)};function Vt({text:e,className:t,reduced:r}){let a=(0,q.useRef)(null),o=(0,q.useRef)(0),s=i(`auto`);return(0,q.useLayoutEffect)(()=>{o.current=performance.now()+700},[e]),(0,q.useEffect)(()=>{let e=a.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let i=!1,c=new ResizeObserver(()=>{let t=e.offsetHeight;if(!i||r||performance.now()>o.current){i=!0,s.jump(t);return}d(s,t,n.spring.smooth)});return c.observe(e),()=>c.disconnect()},[s,r]),(0,Y.jsx)(u.span,{className:Q.slot,style:{height:s},children:(0,Y.jsx)(`span`,{ref:a,className:Q.slotInner,children:(0,Y.jsx)(l,{mode:`popLayout`,initial:!1,children:e?(0,Y.jsx)(u.span,{className:t,initial:It,animate:Lt,exit:{...Rt,transition:r?$:Pt},transition:r?$:Ft,children:e},`${t}:${e}`):null})})})}function Ht({kind:e,number:t,delay:r,reduced:i}){let a=i?$:{scale:{...n.spring.snappy,delay:r},opacity:{duration:n.duration.fast,delay:r},filter:{duration:n.duration.fast,delay:r}},o={...zt,transition:i?$:Pt},s=i?$:{duration:n.duration.standard,ease:n.ease.enter,delay:r+.04};return e===`number`?(0,Y.jsx)(u.span,{className:Q.glyph,initial:zt,animate:Bt,exit:o,transition:a,children:t}):(0,Y.jsx)(u.svg,{className:`${Q.glyph} ${Q.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:zt,animate:Bt,exit:o,transition:a,children:e===`check`?(0,Y.jsx)(u.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:s}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(u.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,Y.jsx)(u.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?$:{...n.spring.snappy,delay:r+.16}})]})})}function Ut({number:e,kind:t,current:r,glyphDelay:i,ringDelay:a,reduced:o}){return(0,Y.jsxs)(`span`,{className:Q.marker,"aria-hidden":`true`,children:[(0,Y.jsx)(l,{initial:!1,children:r?(0,Y.jsx)(u.span,{className:Q.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?$:Pt},transition:o?$:{scale:{...n.spring.snappy,delay:a},opacity:{duration:n.duration.fast,delay:a}}},`ring`):null}),(0,Y.jsx)(`span`,{className:Q.disc,children:(0,Y.jsx)(l,{initial:!1,children:(0,Y.jsx)(Ht,{kind:t,number:e,delay:i,reduced:o},t)})})]})}var Wt={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function Gt({steps:e,current:t,orientation:r=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let d=p()??!1,f=e.length,m=Math.min(Math.max(Math.round(t),0),f),[h,g]=(0,q.useState)({to:m,from:m});h.to!==m&&g({to:m,from:h.to});let _=h.from,v=n.stagger.line,y=e=>d?0:m>_?e>=_&&e<m?(e-_)*v:0:e>=m&&e<_?(_-1-e)*v:0,b=d?0:Math.max(0,Math.abs(m-_)-1)*v+.12,x=!!i,S=r===`vertical`,C=m>=f?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`,E=[Q.root,S?Q.vertical:Q.horizontal,o?Q.compact:``,l].filter(Boolean).join(` `);return(0,Y.jsxs)(T,{className:E,"aria-label":s,role:x?void 0:`group`,children:[(0,Y.jsx)(`ol`,{className:Q.list,style:S?void 0:{gridTemplateColumns:f>1?`repeat(${f-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`,c=x&&t<m,l=e.error??(a===`all`||o?e.description:void 0),p=e.error?`error`:t<m?`check`:`number`,h=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ut,{number:t+1,kind:p,current:o,glyphDelay:y(t),ringDelay:b,reduced:d}),(0,Y.jsxs)(`span`,{className:Q.text,children:[(0,Y.jsx)(`span`,{className:Q.label,children:e.label}),Wt[s]?(0,Y.jsxs)(`span`,{className:Q.srOnly,children:[`, `,Wt[s]]}):null,(0,Y.jsx)(Vt,{text:l,className:e.error?Q.error:Q.description,reduced:d})]})]});return(0,Y.jsxs)(`li`,{className:Q.item,"data-status":s,children:[t<f-1?(0,Y.jsx)(`span`,{className:Q.connector,"aria-hidden":`true`,children:(0,Y.jsx)(u.span,{className:Q.fill,initial:!1,animate:S?{scaleY:+(t<m)}:{scaleX:+(t<m)},transition:d?$:{...n.spring.smooth,delay:y(t)}},r)}):null,x?(0,Y.jsx)(`button`,{type:`button`,className:Q.head,"data-clickable":c||void 0,"data-reachable":t<=m||void 0,"aria-current":o?`step`:void 0,"aria-disabled":!c||void 0,tabIndex:c?void 0:-1,onClick:c?()=>i?.(t):void 0,children:h}):(0,Y.jsx)(`span`,{className:Q.head,"aria-current":o?`step`:void 0,children:h})]},e.id)})}),S?null:(0,Y.jsxs)(`span`,{className:Q.caption,"aria-hidden":`true`,children:[(0,Y.jsx)(Vt,{text:C?.label??c,className:Q.captionLabel,reduced:d}),(0,Y.jsx)(Vt,{text:C?.error??C?.description,className:C?.error?Q.error:Q.description,reduced:d})]}),(0,Y.jsx)(`span`,{className:Q.srOnly,"aria-live":`polite`,children:C?`Step ${m+1} of ${f}: ${C.label}`:c})]})}var Kt={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},qt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},Jt=e=>`${e.source}\u0000${e.ref}`,Yt=e=>e.status!==`skip`&&e.status!==`same`;function Xt(e){try{return new URL(e).host}catch{return e}}function Zt({open:e,onOpenChange:t}){let{t:n}=V(),{toast:r}=be(),i=g(e),a=G(),[o,s]=(0,q.useState)(``),[c,l]=(0,q.useState)(new Set),[u,d]=(0,q.useState)(null);(0,q.useEffect)(()=>{i.data&&l(new Set(i.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Jt)))},[i.data]),(0,q.useEffect)(()=>{e&&(s(``),d(null))},[e]);let f=o.trim().toLowerCase(),p=e=>!f||e.name.toLowerCase().includes(f)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(f)),m=(0,q.useMemo)(()=>(i.data??[]).flatMap(e=>e.items).filter(e=>c.has(Jt(e))&&Yt(e)),[i.data,c]),h=(e,t)=>l(n=>{let r=new Set(n);return t?r.add(Jt(e)):r.delete(Jt(e)),r});return(0,Y.jsx)(_e,{open:e,onOpenChange:t,width:680,title:n(`import.title`),description:n(`import.detail`),footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{icon:(0,Y.jsx)(Me,{className:`size-3.5`}),onClick:()=>void i.refetch(),disabled:i.isFetching||a.isPending,children:n(`import.rescan`)}),(0,Y.jsx)(R,{variant:`primary`,disabled:m.length===0||a.isPending,onClick:()=>{d(null),a.mutate(m.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let i=e.skipped.length;r(i>0?n(`import.doneSkipped`,{count:e.added.length,skipped:i}):n(`import.done`,{count:e.added.length})),t(!1)},onError:e=>{d(K(e)),i.refetch()}})},children:n(`import.selected`,{count:m.length})})]}),children:(0,Y.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Y.jsx)(k,{value:o,onChange:s,placeholder:n(`import.search`)}),u&&(0,Y.jsx)(H,{tone:`danger`,title:n(`common.error`),children:u}),i.isLoading&&(0,Y.jsx)(ne,{lines:3}),i.isError&&(0,Y.jsx)(H,{tone:`danger`,title:n(`common.error`),children:K(i.error)}),(0,Y.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:i.data?.map(e=>(0,Y.jsx)(Qt,{source:e,matches:p,selected:c,onToggle:h,filtering:f.length>0},e.id))}),(0,Y.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`import.footnote`)})]})})}function Qt({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=V(),o=e.items.filter(t);return(0,Y.jsxs)(`section`,{"aria-label":e.name,children:[(0,Y.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,Y.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,Y.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,Y.jsx)(H,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,Y.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,Y.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,Y.jsx)($t,{c:e,checked:n.has(Jt(e)),onToggle:t=>r(e,t)},Jt(e)))}):(0,Y.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function $t({c:e,checked:t,onToggle:n}){let{t:r}=V(),i=Yt(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=>`${Kt[e.protocol]??e.protocol} · ${Xt(e.baseUrl)}`).join(` / `);return(0,Y.jsxs)(`li`,{className:w(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,Y.jsx)(Ge,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,Y.jsx)(I,{tone:qt[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,Y.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),o&&(0,Y.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:o,children:o}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),e.models.length>0&&(0,Y.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,Y.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignoredFields.join(`, `)})})]})]})}var en=``,tn=`custom`,nn=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],rn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},an={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},on=e=>JSON.stringify(e??{},null,2);function sn(e){return{enabled:e.enabled,template:e.template??en,intervalMinutes:e.intervalMinutes??null,timeoutSec:e.timeoutSec,baseUrl:e.baseUrl??``,params:{...e.params},secrets:{},method:e.request?.method??`GET`,url:e.request?.url??``,auth:e.request?.auth??`provider`,headers:on(e.request?.headers),extract:e.extract?on(e.extract):``}}function cn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function ln({provider:t}){let{t:n}=V(),{toast:r}=be(),i=j(),a=e(t.id),s=o(t.id),c=F(),l=t.quotaConfig,u=(0,q.useMemo)(()=>sn(l),[l]),[d,f]=(0,q.useState)(u),[p,m]=(0,q.useState)(null);(0,q.useEffect)(()=>f(u),[u]);let h=i.data??[],g=h.find(e=>e.id===l.suggestedTemplate),_=d.template===en?g:h.find(e=>e.id===d.template),v=d.template===tn,y=v?nn:_?.params??[],b=e=>f(t=>({...t,...e})),x=JSON.stringify(d)!==JSON.stringify(u),S=e=>{if(e!==tn||d.url)return b({template:e});let t=_??g;b({template:e,method:t?.request.method??rn.method,url:t?.request.url??rn.url,auth:t?.request.auth??rn.auth,headers:on(t?.request.headers??rn.headers),extract:on(t?.extract??an)})},C=()=>{let e={enabled:d.enabled,template:d.template===en?null:d.template,intervalMinutes:d.intervalMinutes,timeoutSec:d.timeoutSec??10,baseUrl:d.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(d.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(d.secrets).filter(([,e])=>e.trim()!==``))};if(v){let t=cn(d.headers),i=cn(d.extract);if(!t||!i)return r(n(`providers.quota.invalidJson`,{field:n(t?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:d.method,url:d.url.trim(),auth:d.auth,headers:t},e.extract=i}return e},w=()=>{let e=C();if(!e)return;let i=e.enabled&&!l.enabled;a.mutate(e,{onSuccess:()=>{r(n(`common.saved`),`success`),i&&c.mutate(t.id,{onError:e=>r(K(e),`error`)})},onError:e=>r(K(e),`error`)})},E=()=>{let e=C();e&&s.mutate(e,{onSuccess:m,onError:e=>r(K(e),`error`)})},k=l.effectiveIntervalMinutes>0?n(`providers.quota.intervalEvery`,{minutes:l.effectiveIntervalMinutes}):n(`providers.quota.intervalOff`),M=[{value:en,label:g?n(`providers.quota.templateAuto`,{name:g.name}):n(`providers.quota.templateNone`)},...h.map(e=>({value:e.id,label:e.name,detail:n(`providers.quota.kind.${e.kind}`)})),{value:tn,label:n(`providers.quota.custom`)}];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(U,{title:n(`providers.quota.title`),footer:n(`providers.quota.footer`),children:[(0,Y.jsx)(P,{label:n(`providers.quota.enable`),detail:n(`providers.quota.enableHint`),children:(0,Y.jsx)(ae,{checked:d.enabled,label:n(`providers.quota.enable`),onChange:e=>b({enabled:e})})}),(0,Y.jsx)(P,{label:n(`providers.quota.template`),children:(0,Y.jsx)(Se,{className:`w-64`,ariaLabel:n(`providers.quota.template`),value:d.template,onChange:S,options:M})}),y.map(e=>{let t=n(`providers.quota.param.${e.name}`),r=l.secrets.includes(e.name);return e.secret?(0,Y.jsx)(P,{label:t,detail:r?n(`providers.quota.secretStored`):void 0,children:(0,Y.jsx)(D,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":t,placeholder:r?`••••••••`:``,value:d.secrets[e.name]??``,onChange:t=>b({secrets:{...d.secrets,[e.name]:t.target.value}})})},e.name):(0,Y.jsx)(P,{label:t,children:(0,Y.jsx)(D,{className:`w-64 font-mono`,"aria-label":t,value:d.params[e.name]??``,onChange:t=>b({params:{...d.params,[e.name]:t.target.value}})})},e.name)}),y.length>0&&(0,Y.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:n(`providers.quota.paramsHint`)}),v&&(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(Se,{className:`w-28`,ariaLabel:n(`providers.quota.method`),value:d.method,onChange:e=>b({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,Y.jsx)(D,{className:`min-w-60 flex-1 font-mono`,"aria-label":n(`providers.quota.url`),value:d.url,onChange:e=>b({url:e.target.value})}),(0,Y.jsx)(Se,{className:`w-52`,ariaLabel:n(`providers.quota.auth`),value:d.auth,onChange:e=>b({auth:e}),options:[{value:`provider`,label:n(`providers.quota.auth.provider`)},{value:`none`,label:n(`providers.quota.auth.none`)}]})]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`providers.quota.urlHint`)}),(0,Y.jsx)(T,{label:n(`providers.quota.headers`),mono:!0,rows:3,value:d.headers,onChange:e=>b({headers:e.target.value})}),(0,Y.jsx)(T,{label:n(`providers.quota.extract`),mono:!0,rows:8,value:d.extract,onChange:e=>b({extract:e.target.value})}),(0,Y.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`providers.quota.extractHint`)})]}),(0,Y.jsx)(P,{label:n(`providers.quota.interval`),detail:n(`providers.quota.intervalHint`,{value:k}),children:(0,Y.jsx)(L,{className:`w-28`,label:n(`providers.quota.interval`),min:0,step:1,value:d.intervalMinutes,onChange:e=>b({intervalMinutes:e})})}),(0,Y.jsx)(P,{label:n(`providers.quota.timeout`),children:(0,Y.jsx)(L,{className:`w-28`,label:n(`providers.quota.timeout`),min:1,step:1,value:d.timeoutSec,onChange:e=>b({timeoutSec:e})})}),(0,Y.jsx)(P,{label:n(`providers.quota.baseUrl`),detail:n(`providers.quota.baseUrlHint`),children:(0,Y.jsx)(D,{className:`w-64 font-mono`,"aria-label":n(`providers.quota.baseUrl`),placeholder:t.endpoints[0]?.baseUrl,value:d.baseUrl,onChange:e=>b({baseUrl:e.target.value})})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,Y.jsx)(R,{size:`sm`,variant:`primary`,disabled:!x,loading:a.isPending,onClick:w,children:n(`common.save`)}),(0,Y.jsx)(R,{size:`sm`,icon:(0,Y.jsx)(De,{className:`size-3.5`}),loading:s.isPending,onClick:E,title:n(`providers.quota.testDesc`),children:n(`providers.quota.test`)}),(0,Y.jsx)(R,{size:`sm`,icon:(0,Y.jsx)(Xe,{className:`size-3.5`}),disabled:x,loading:c.isPending,onClick:()=>c.mutate(t.id,{onError:e=>r(K(e),`error`)}),children:n(`providers.quota.fetch`)})]}),(0,Y.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Y.jsx)(un,{snapshot:t.quota,checkedAtUtc:t.quotaCheckedAtUtc})})]}),(0,Y.jsx)(_e,{open:p!==null,onOpenChange:e=>!e&&m(null),title:n(`providers.quota.test`),description:n(`providers.quota.testDesc`),width:560,children:p&&(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(H,{tone:p.ok?`success`:`danger`,title:p.ok?n(`providers.quota.testOk`):n(`providers.quota.testFailed`),children:[!p.ok&&me({code:p.errorCode??null,message:p.error??``},n),!p.ok&&p.error&&p.errorCode&&(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:p.error})]}),p.url&&(0,Y.jsx)(O,{label:n(`providers.quota.requestUrl`),mono:!0,children:p.url}),p.httpStatus!=null&&(0,Y.jsx)(O,{label:n(`providers.quota.httpStatus`),children:p.httpStatus}),p.snapshot&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.quota.extracted`)}),(0,Y.jsx)(un,{snapshot:p.snapshot})]}),p.raw!==void 0&&p.raw!==null&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.quota.rawResponse`)}),(0,Y.jsx)(A,{children:on(p.raw)})]})]})})]})}function un({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=V(),i=xe(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,Y.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,Y.jsxs)(H,{tone:`warning`,title:n(`providers.quota.failed`,{error:me(i,n)}),children:[(0,Y.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,Y.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,Y.jsx)(H,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,Y.jsx)(I,{children:e.name}),(0,Y.jsx)(`span`,{className:`num`,children:Ce(e,n,r)??`—`}),he(e,n,r)&&(0,Y.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:he(e,n,r)}),e.extra&&(0,Y.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,Y.jsx)(I,{tone:`accent`,children:e.planLabel}),o>0&&(0,Y.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:pe(o,r,n(`tray.justNow`))??``})})]})]})}function dn({provider:e}){let{t,locale:n}=V(),{toast:r}=be(),i=F();if(!ge(e))return null;let a=ye(e.quota,t,n),o=xe(e.quota);return(0,Y.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-center gap-2 text-[12px]`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a&&(0,Y.jsx)(`div`,{className:`num truncate text-[var(--text-secondary)]`,title:a,children:a}),o&&(0,Y.jsx)(`div`,{className:`truncate text-[var(--warning)]`,title:o.message,children:t(`providers.quota.failed`,{error:me(o,t)})}),!a&&!o&&(0,Y.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,Y.jsx)(R,{size:`sm`,variant:`plain`,icon:(0,Y.jsx)(Xe,{className:`size-3.5`}),"aria-label":t(`providers.quota.refresh`),title:t(`providers.quota.refresh`),loading:i.isPending,onClick:()=>i.mutate(e.id,{onError:e=>r(K(e),`error`)})})]})}var fn=3,pn=256,mn=4096,hn={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 gn(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var _n=e=>typeof e==`number`?e:null,vn=e=>typeof e==`string`?e:null;function yn({provider:e,open:t,onOpenChange:n}){let{t:r}=V(),i=W(),a=te(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,q.useState)(`single`),[l,u]=(0,q.useState)(()=>gn(e)),[d,f]=(0,q.useState)(!0),[p,m]=(0,q.useState)(``),[h,g]=(0,q.useState)(pn),[_,v]=(0,q.useState)(``),[y,b]=(0,q.useState)(null),[S,C]=(0,q.useState)({}),[w,T]=(0,q.useState)([]),[E,D]=(0,q.useState)(new Set),[O,k]=(0,q.useState)([]),[A,j]=(0,q.useState)(``),[M,P]=(0,q.useState)(null),[F,I]=(0,q.useState)(!1),L=(0,q.useRef)(null),z=(0,q.useRef)(new Map),B=(0,q.useRef)(!1),H=(0,q.useRef)(!1),U=(0,q.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...O.filter(t=>!e.includes(t))]},[a.data,O]);(0,q.useEffect)(()=>{if(t){v(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}H.current=!1,L.current?.abort();for(let e of z.current.values())e.abort();z.current.clear(),b(null),C({}),T([]),D(new Set),k([]),j(``),P(null)},[t,a.data]);let ne=(0,q.useCallback)(e=>({modelId:e,protocol:l,stream:d,prompt:p.trim()||null,maxOutputTokens:h??pn}),[l,d,p,h]),re=(0,q.useCallback)((t,n,r)=>On(e.id,t,ne(t),n,r),[e.id,ne]),ie=()=>{let e=_.trim();if(!e)return;L.current?.abort();let t=new AbortController;L.current=t,H.current=!0,P(null),b({modelId:e,status:`running`,text:``,reasoning:``}),re(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&ae(),b(e)})},G=e=>{if(e.length===0)return;H.current=!0,B.current=!1,P(null),T(e),C(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(fn,e.length)},async()=>{for(;;){if(!H.current)return;let n=e[t++];if(n===void 0)return;if(B.current){C(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;z.current.set(n,r),await re(n,r.signal,e=>C(t=>({...t,[n]:e}))),z.current.delete(n),ae()}}))},ae=()=>void i.invalidateQueries({queryKey:[`requests`]}),oe=()=>{B.current=!0,C(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},se=y?.status===`running`||w.some(e=>S[e]?.status===`running`||S[e]?.status===`queued`&&!B.current),ce=w.filter(e=>S[e]&&S[e].status!==`queued`&&S[e].status!==`running`).length,le=w.filter(e=>S[e]?.status===`success`).length,ue=w.filter(e=>S[e]?.status===`failed`).length,de=(e,t)=>D(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),fe=()=>{se||n(!1)},pe=e=>e.stopPropagation();return(0,Y.jsx)(`span`,{onClick:pe,onKeyDown:pe,children:(0,Y.jsxs)(_e,{open:t,onOpenChange:e=>e?n(!0):fe(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,Y.jsx)(R,{disabled:se,onClick:()=>n(!1),icon:(0,Y.jsx)(ee,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?se?(0,Y.jsx)(R,{variant:`primary`,icon:(0,Y.jsx)(Qe,{className:`size-3.5`}),onClick:()=>L.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,Y.jsx)(R,{variant:`primary`,disabled:_.trim()===``,icon:(0,Y.jsx)(De,{className:`size-3.5`}),onClick:ie,children:r(y?`providers.testDialog.retest`:`providers.testDialog.start`)}):se?(0,Y.jsx)(R,{variant:`primary`,icon:(0,Y.jsx)(Qe,{className:`size-3.5`}),onClick:oe,children:r(`providers.testDialog.stopRest`)}):(0,Y.jsx)(R,{variant:`primary`,disabled:E.size===0,icon:(0,Y.jsx)(De,{className:`size-3.5`}),onClick:()=>G([...E]),children:r(`providers.testDialog.testN`,{count:E.size})})]}),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,Y.jsx)(We,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,Y.jsx)(x,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),P(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,Y.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,Y.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,Y.jsx)(N,{label:r(`providers.testDialog.model`),children:(0,Y.jsx)(bn,{value:_,models:U,onChange:v})}),(0,Y.jsx)(xn,{protocols:o,protocol:l,onProtocol:u,stream:d,onStream:f,maxTokens:h,onMaxTokens:g,prompt:p,onPrompt:m}),(0,Y.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,Y.jsx)(Sn,{run:y,onRetest:ie})]}):M===null?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(En,{known:U,selected:E,onToggle:de,onSelectAll:e=>D(e?new Set(U):new Set),onClear:()=>D(new Set),search:A,onSearch:j,onAdd:e=>{k(t=>t.includes(e)?t:[...t,e]),D(t=>new Set(t).add(e)),j(``)},configOpen:F,onConfigOpen:I,protocols:o,protocol:l,onProtocol:u,stream:d,onStream:f,maxTokens:h,onMaxTokens:g,prompt:p,onPrompt:m}),w.length>0?(0,Y.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:se?r(`providers.testDialog.progress`,{done:ce,total:w.length,ok:le,failed:ue}):r(`providers.testDialog.progressDone`,{total:w.length,ok:le,failed:ue})}),(0,Y.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${ce/w.length*100}%`,background:`var(--accent)`}})})]}):null,w.length>0?(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsx)(Dn,{order:w,runs:S,onView:P})}):null]}):(0,Y.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(R,{variant:`plain`,icon:(0,Y.jsx)(Te,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>P(null)}),(0,Y.jsx)(`span`,{className:`font-mono text-[13px]`,children:M})]}),(0,Y.jsx)(Sn,{run:S[M]??null})]})]})})}function bn({value:e,models:t,onChange:n}){let{t:r}=V(),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(0),[c,l]=(0,q.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,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(D,{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,Y.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,Y.jsx)(S,{className:`size-4`})}),i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,Y.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,Y.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(`button`,{type:`button`,className:w(`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))})]})]})}function xn({protocols:e,...t}){let{t:n}=V(),r=e.map(e=>({value:e,label:jn.find(t=>t.value===e)?.label??e}));return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(N,{label:n(`providers.testDialog.protocol`),children:(0,Y.jsx)(Se,{value:t.protocol,onChange:t.onProtocol,options:r})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`providers.testDialog.stream`)}),(0,Y.jsx)(ae,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,Y.jsx)(N,{label:n(`providers.testDialog.maxTokens`),children:(0,Y.jsx)(L,{value:t.maxTokens,min:1,placeholder:String(pn),label:n(`providers.testDialog.maxTokens`),onChange:e=>t.onMaxTokens(e===null?null:Math.min(mn,Math.max(1,Math.round(e))))})}),(0,Y.jsx)(N,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,Y.jsx)(T,{rows:4,value:t.prompt,placeholder:`Reply with OK.`,onChange:e=>t.onPrompt(e.target.value)})})]})}function Sn({run:e,onRetest:t}){let{t:n}=V(),[r,i]=(0,q.useState)(`preview`),a=e?.text??``,o=e?.raw??``,s=Object.entries(e?.headers??{}),c=e?.ttftMs!=null&&e?.httpMs!=null?Math.max(0,e.ttftMs-e.httpMs):null,l=r===`raw`?o:r===`headers`?s.map(([e,t])=>`${e}: ${t}`).join(`
|
|
2
|
+
`):a;return(0,Y.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[t&&e&&e.status!==`running`?(0,Y.jsx)(R,{size:`sm`,icon:(0,Y.jsx)(De,{className:`size-3.5`}),onClick:t,children:n(`providers.testDialog.retest`)}):null,(0,Y.jsx)(ze,{content:n(`providers.testDialog.metricsHelp`),children:(0,Y.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center text-[var(--text-muted)]`,tabIndex:0,children:(0,Y.jsx)(Je,{className:`size-4`})})}),(0,Y.jsx)(Tn,{run:e}),e?.httpStatus?(0,Y.jsxs)(I,{tone:`neutral`,children:[`HTTP `,e.httpStatus]}):null]}),(0,Y.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,Y.jsx)(wn,{label:n(`providers.testDialog.metrics.http`),value:e?.httpMs}),(0,Y.jsx)(wn,{label:n(`providers.testDialog.metrics.firstWait`),value:c}),(0,Y.jsx)(wn,{label:n(`providers.testDialog.metrics.ttft`),value:e?.ttftMs}),(0,Y.jsx)(wn,{label:n(`providers.testDialog.metrics.total`),value:e?.totalMs})]}),(0,Y.jsxs)(`section`,{className:`card overflow-hidden`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-[var(--border)] px-4 py-2.5`,children:[(0,Y.jsx)(`h3`,{className:`text-[12px] font-medium`,children:n(`providers.testDialog.reply`)}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,Y.jsx)(x,{items:[{value:`preview`,label:n(`providers.testDialog.preview`)},{value:`raw`,label:n(`providers.testDialog.raw`)},{value:`headers`,label:n(`providers.testDialog.headers`)}],value:r,onChange:i,ariaLabel:n(`providers.testDialog.reply`)}),(0,Y.jsx)(ie,{value:l,label:n(r===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,Y.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:r===`headers`?s.length===0?(0,Y.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.headersEmpty`)}):(0,Y.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,Y.jsx)(`tbody`,{children:s.map(([e,t])=>(0,Y.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0 align-top`,children:[(0,Y.jsx)(`th`,{className:`w-[220px] py-1.5 pr-4 text-left font-mono font-normal text-[var(--text-secondary)]`,children:e}),(0,Y.jsx)(`td`,{className:`py-1.5 font-mono break-all whitespace-pre-wrap selectable`,children:t})]},e))})}):r===`raw`?o?(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[n(`providers.testDialog.rawNote`),e?.contentType?` · ${e.contentType}`:``]}),(0,Y.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:o}),e?.rawTruncated?(0,Y.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:n(`providers.testDialog.rawTruncated`)}):null]}):(0,Y.jsx)(Cn,{run:e}):e?.error?(0,Y.jsx)(H,{tone:`danger`,title:n(`providers.testDialog.status.failed`),children:e.error}):a||e?.reasoning?(0,Y.jsxs)(`div`,{className:`grid gap-3`,children:[e?.reasoning?(0,Y.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:n(`providers.testDialog.reasoning`)}),(0,Y.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:e.reasoning})]}):null,a?(0,Y.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:a}):null]}):e?.status===`success`?(0,Y.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.noText`)}):(0,Y.jsx)(Cn,{run:e})})]})]})}function Cn({run:e}){let{t}=V();return e?.status===`running`||e?.status===`queued`?(0,Y.jsx)(`div`,{className:`grid h-full place-items-center text-[12px] text-[var(--text-muted)]`,children:t(hn[e.status])}):(0,Y.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,Y.jsx)(je,{className:`mx-auto size-6 text-[var(--text-muted)]`}),(0,Y.jsx)(`div`,{className:`text-[13px]`,children:t(`providers.testDialog.emptyTitle`)}),(0,Y.jsx)(`p`,{className:`mx-auto max-w-[320px] text-[11px] text-[var(--text-muted)]`,children:t(`providers.testDialog.emptyDetail`)})]})}function wn({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`bg-[var(--surface)] px-4 py-3`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 font-mono text-[15px] tabular-nums`,children:t==null?`—`:a(t)})]})}function Tn({run:e}){let{t}=V(),n=e?.status??`idle`;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,Y.jsx)(B,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(hn[n])]})}function En({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:i,search:a,onSearch:o,onAdd:s,configOpen:c,onConfigOpen:l,...u}){let{t:d}=V(),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,Y.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:d(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,Y.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,Y.jsx)(k,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,Y.jsx)(R,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,Y.jsx)(R,{icon:(0,Y.jsx)(De,{className:`size-3.5`}),onClick:()=>l(!0),children:d(`providers.testDialog.config`)})]}),(0,Y.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:m.length===0&&!h?(0,Y.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:d(`providers.testDialog.noModels`)}):(0,Y.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,Y.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,Y.jsx)(Ge,{checked:t.size===e.length&&e.length>0||t.size!==0&&`indeterminate`,onCheckedChange:e=>r(e!==!1),"aria-label":d(`providers.testDialog.clearSelection`)}),(0,Y.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:d(`providers.testDialog.ownFilter`)})]}),h?(0,Y.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Y.jsx)(Ne,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,Y.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,Y.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Y.jsx)(Ge,{checked:t.has(e),onCheckedChange:t=>n(e,t!==!1),"aria-label":e}),(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,title:e,children:e})]},e))]})}),(0,Y.jsx)(_e,{open:c,onOpenChange:l,width:480,title:d(`providers.testDialog.config`),description:d(`providers.testDialog.savedCredentials`),children:(0,Y.jsx)(`div`,{className:`grid gap-4`,children:(0,Y.jsx)(xn,{...u})})})]})}function Dn({order:e,runs:t,onView:n}){let{t:r}=V();return(0,Y.jsx)(`div`,{className:`card overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-[var(--border)] text-left text-[11px] text-[var(--text-muted)]`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.model`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.statusColumn`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.ttft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.total`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.reply`)})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>{let i=t[e];return(0,Y.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2 font-mono`,children:e}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(Tn,{run:i??null})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:a(i.ttftMs)}),(0,Y.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:a(i.totalMs)}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.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 On(e,n,r,i,a){let o={modelId:n,status:`running`,text:``,reasoning:``};a(o);let s=e=>{o={...o,...e},a(o)};try{await t(e,r,e=>{let t=e.data??{};switch(e.event){case`headers`:s({httpStatus:_n(t.httpStatus),httpMs:_n(t.httpMs),contentType:vn(t.contentType),headers:kn(t.headers)});break;case`delta`:{let e=vn(t.text)??``;vn(t.kind)===`reasoning`?s({reasoning:o.reasoning+e}):s({text:o.text+e});break}case`done`:{let t=e.data;s({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,contentType:t.contentType??null,headers:kn(t.headers)});break}}},i)}catch(e){e?.name===`AbortError`?s({status:`cancelled`,error:null}):s({status:`failed`,error:e instanceof re?e.message:String(e)})}}function kn(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 An=f({AUTH_OPTIONS:()=>Mn,PROTOCOL_OPTIONS:()=>jn,ProvidersPage:()=>Nn}),jn=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],Mn=[{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 Nn(){let{t:e}=V(),t=Fe(),[n,r]=ke(),i=z(),[a,o]=(0,q.useState)(n.get(`new`)===`1`),[s,c]=(0,q.useState)(!1);(0,q.useEffect)(()=>{n.get(`new`)===`1`&&(o(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),Ve(e=>{e===`new-provider`&&o(!0)});let l=y(`7d`,`day`,`provider`),[u,d]=(0,q.useState)(null),f=(0,q.useMemo)(()=>{let e=Fn(Pn),t=new Map;for(let n of l.data??[]){let r=e.indexOf(n.bucket);if(r<0)continue;let i=t.get(n.key);i||t.set(n.key,i={requests:e.map(()=>0),costUsd:0}),i.requests[r]=(i.requests[r]??0)+n.requests,i.costUsd+=n.costUsd}return{days:e,byProvider:t}},[l.data]);return(0,Y.jsxs)(Be,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{icon:(0,Y.jsx)(Ee,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,Y.jsx)(R,{variant:`primary`,icon:(0,Y.jsx)(Ne,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)})]}),children:[(0,Y.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,Y.jsx)(ne,{lines:4}),i.isError&&(0,Y.jsx)(H,{tone:`danger`,title:e(`common.error`),children:K(i.error)}),i.data?.length===0&&(0,Y.jsx)(`div`,{className:`card`,children:(0,Y.jsx)(E,{icon:(0,Y.jsx)(Ae,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,Y.jsx)(R,{variant:`primary`,icon:(0,Y.jsx)(Ne,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,Y.jsx)(R,{icon:(0,Y.jsx)(Ee,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,Y.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,Y.jsx)(Rn,{p:e,days:f.days,usage:f.byProvider.get(e.name),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>d(e)},e.id))})]}),(0,Y.jsx)(Zt,{open:s,onOpenChange:c}),(0,Y.jsx)(Gn,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),u&&(0,Y.jsx)(yn,{provider:u,open:!0,onOpenChange:e=>!e&&d(null)})]})}var Pn=7;function Fn(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`)}`})}function In(e){if(!e)return null;try{return new URL(e).host}catch{return e}}var Ln=e=>e.stopPropagation();function Rn({p:e,days:t,usage:n,onOpen:r,onTest:i}){let{t:a}=V(),o=C(e.id),{toast:s}=be(),c=[...new Set(e.endpoints.map(e=>e.protocol))],l=!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,u=[e.priceKey?a(`providers.priceKeyShort`,{key:e.priceKey}):null,e.priceMultiplier===1?null:`×${e.priceMultiplier}`].filter(Boolean).join(` · `),d=e.authScheme===`plugin`?a(`providers.card.plugin`):e.authScheme===`oauth-subscription`?a(`providers.card.subscription`):e.authScheme===`none`?a(`providers.card.noAuth`):e.hasApiKey?e.apiKeyMasked??`••••`:a(`providers.noKey`),f=e.enabled?l?{tone:`orange`,label:a(`providers.noKey`)}:{tone:`green`,label:a(`providers.card.active`)}:{tone:`neutral`,label:a(`providers.card.disabled`)},p=n?.requests??t.map(()=>0),h=p.reduce((e,t)=>e+t,0),g=e.templateUpdateAvailable?5:8;return(0,Y.jsxs)(gt,{className:`flex flex-col [&>div:first-child>div]:min-h-0! [&>div:last-child]:flex [&>div:last-child]:flex-1 [&>div:last-child]:flex-col [&>div:last-child]:p-3 [&>div:last-child>:last-child]:mt-auto! [&>div:last-child>:last-child]:min-h-[44px] [&>div:last-child>:last-child]:pt-2 [&>div:last-child>h3]:line-clamp-1 [&>div:last-child>h3]:text-[15px] [&>div:last-child>p]:line-clamp-2 [&>div:last-child>p]:min-h-[2lh] [&>div:last-child>p]:text-[12px]`,"data-density":`compact`,role:`button`,tabIndex:0,"aria-label":e.name,onClick:r,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},style:{backgroundColor:`var(--surface)`},title:e.name,description:c.map(e=>jn.find(t=>t.value===e)?.label??e).join(` / `),media:(0,Y.jsxs)(`div`,{className:`flex flex-col justify-between gap-1.5 self-stretch justify-self-stretch px-3 py-2.5`,style:{background:`linear-gradient(135deg, color-mix(in oklab, var(--accent) 12%, transparent), transparent 70%)`},children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:w(`transition-[filter,opacity]`,!e.enabled&&`opacity-50 grayscale`),children:(0,Y.jsx)(We,{name:e.name,icon:e.icon,colorKey:e.templateId,size:28})}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-[var(--border)] bg-[color-mix(in_oklab,var(--surface)_80%,transparent)] px-2 py-0.5 text-[11px] text-[var(--text-secondary)]`,children:[(0,Y.jsx)(B,{tone:f.tone}),f.label]})]}),(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-[11px] text-[var(--text-muted)]`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:In(e.endpoints[0]?.baseUrl)??`—`}),(0,Y.jsx)(`span`,{className:`shrink-0`,children:a(`providers.modelCount`,{count:e.modelCount})})]})]}),meta:(0,Y.jsx)(`span`,{className:w(e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:d}),status:u||void 0,action:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:Ln,children:[(0,Y.jsx)(R,{variant:`plain`,size:`sm`,icon:(0,Y.jsx)(De,{className:`size-3.5`}),"aria-label":a(`providers.test`),title:a(`providers.test`),onClick:i}),(0,Y.jsx)(`span`,{className:`ml-1 inline-flex`,children:(0,Y.jsx)(ae,{checked:e.enabled,label:a(`common.enabled`),onChange:e=>o.mutate({enabled:e},{onError:e=>s(K(e),`error`)})})})]}),children:[(0,Y.jsxs)(`div`,{className:`mt-1.5 flex h-5 flex-nowrap items-center gap-1 overflow-hidden`,children:[e.templateUpdateAvailable&&(0,Y.jsx)(I,{tone:`accent`,children:a(`providers.templateUpdate`)}),e.boundClients.slice(0,g).map(e=>e in Ie?(0,Y.jsx)(`span`,{title:Pe(e),className:`inline-flex shrink-0`,children:(0,Y.jsx)(Le,{kind:e,size:18})},e):(0,Y.jsx)(I,{tone:`green`,children:e},e)),e.boundClients.length>g&&(0,Y.jsxs)(`span`,{title:e.boundClients.slice(g).map(e=>Ie[e]?.name??e).join(`, `),className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:[`+`,e.boundClients.length-g]})]}),(0,Y.jsx)(`div`,{className:`min-h-[32px] [&>div]:mt-1`,onClick:Ln,children:(0,Y.jsx)(dn,{provider:e})}),(0,Y.jsx)(`div`,{className:`mt-2`,onClick:Ln,children:h>0?(0,Y.jsx)(Mt,{label:a(`providers.card.requests7d`),data:p,labels:t.map(e=>e.slice(5)),value:b(h,!0),change:m(n?.costUsd??0),width:320,height:28,formatValue:e=>b(e,!0)}):(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-[13px] text-[var(--text-secondary)]`,children:a(`providers.card.requests7d`)}),(0,Y.jsx)(`div`,{className:`grid aspect-[320/28] place-items-center border-b border-dashed border-[var(--border)] text-[11px] text-[var(--text-muted)]`,children:a(`providers.card.noRequests`)})]})})]})}var zn=`plugin:`,Bn=[`recommended`,`official`,`subscription`,`coding`,`cn`,`aggregator`,`inference`,`local`,`custom`],Vn={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Hn=e=>jn.find(t=>t.value===e)?.label??e,Un=e=>(0,Y.jsx)(`span`,{title:e,children:e}),Wn=e=>{let t=/^(.+?)\s*[((]([^()()]+)[))]$/.exec(e);return t?[t[1],t[2]]:[e,null]};function Gn({open:e,onOpenChange:t,onCreated:n}){let{t:r}=V(),{toast:i}=be(),a=v(),o=c(),s=h(),l=z(),u=(0,q.useMemo)(()=>new Set((l.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[l.data]),d=Fe(),[f,p]=(0,q.useState)(``),[m,g]=(0,q.useState)(null),[_,y]=(0,q.useState)(null),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(``),[w,T]=(0,q.useState)(``),[E,O]=(0,q.useState)(``),[A,j]=(0,q.useState)(``),[M,ee]=(0,q.useState)(`openai-chat`),[P,F]=(0,q.useState)(`bearer`);(0,q.useEffect)(()=>{e||(g(null),y(null),p(``),x(``),C(``),T(``),O(``),j(``))},[e]);let I=(0,q.useMemo)(()=>{let e=f.trim().toLowerCase(),t=(a.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return Bn.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[a.data,f]),L=(0,q.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]),B=e=>{g(e),e===`custom`?(x(``),O(``),T(``)):(x(e.name),O(e.priceKey??e.id),T(``),F(e.auth.scheme))},te=()=>{let e=m===`custom`;s.mutate({templateId:e?null:m.id,variantId:w||null,name:b.trim()||null,apiKey:S.trim()||null,priceKey:E,...e?{endpoints:[{protocol:M,baseUrl:A.trim()}],authScheme:P}:{}},{onSuccess:e=>{t(!1),i(r(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>i(K(e),`error`)})},U=m&&m!==`custom`?m:null,re=()=>{if(_===`custom`)B(`custom`);else if(_?.startsWith(zn)){let e=L.find(e=>zn+e.id===_);e&&(t(!1),n(e))}else{let e=(a.data??[]).find(e=>e.id===_);e&&!u.has(e.id)&&B(e)}},ie=m!==null&&(m===`custom`?/^https?:\/\//.test(A.trim())&&b.trim()!==``:!U.requiresApiKey||S.trim()!==``);return(0,Y.jsxs)(_e,{open:e,onOpenChange:t,width:640,title:r(m?`providers.addTitleDetails`:`providers.addTitle`),description:m?U?U.name:r(`providers.custom`):r(`providers.addDetail`),footer:m?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`mr-auto`,variant:`plain`,onClick:()=>g(null),children:r(`common.back`)}),(0,Y.jsx)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Y.jsx)(R,{variant:`primary`,disabled:!ie,loading:s.isPending,onClick:te,children:r(`providers.create`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Y.jsx)(R,{variant:`primary`,disabled:!_,onClick:re,children:r(`common.continue`)})]}),children:[(0,Y.jsx)(Gt,{className:`mb-6`,label:r(`providers.addTitle`),current:+!!m,steps:[{id:`template`,label:r(`providers.step.template`)},{id:`details`,label:r(`providers.step.details`)}]}),m?(0,Y.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Y.jsx)(N,{label:r(`providers.name`),children:(0,Y.jsx)(D,{value:b,onChange:e=>x(e.target.value)})}),U?.variants&&U.variants.length>0&&(0,Y.jsx)(N,{label:r(`providers.variant`),children:(0,Y.jsx)(Se,{value:w,onChange:e=>{T(e);let t=U.variants?.find(t=>t.id===e);O(t?.priceKey??U.priceKey??U.id)},options:[{value:``,label:r(`providers.variantDefault`)},...U.variants.map(e=>({value:e.id,label:e.name}))]})}),m===`custom`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(N,{label:r(`providers.baseUrl`),hint:r(`providers.baseUrlHint`),children:(0,Y.jsx)(D,{value:A,onChange:e=>j(e.target.value),placeholder:`https://api.example.com/v1`,className:`font-mono`})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(N,{label:r(`providers.protocol`),children:(0,Y.jsx)(Se,{value:M,onChange:ee,options:jn})}),(0,Y.jsx)(N,{label:r(`providers.authScheme`),children:(0,Y.jsx)(Se,{value:P,onChange:F,options:Mn})})]})]}),U?.authScheme===`oauth-subscription`?(0,Y.jsx)(H,{tone:`info`,title:r(`providers.subscriptionWizardHint`),children:r(`providers.subscriptionWizardDetail`)}):(0,Y.jsxs)(`div`,{className:`font-mono`,children:[(0,Y.jsx)(He,{label:r(`providers.apiKey`),description:r(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:S,onChange:e=>C(e.target.value)}),U?.apiKeyUrl&&(0,Y.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:U.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:r(`providers.getKey`)})]}),(0,Y.jsx)(N,{label:r(`providers.priceKey`),hint:r(`providers.priceKeyHint`),children:(0,Y.jsx)(Se,{value:E,onChange:O,options:[{value:``,label:r(`providers.priceKeyNone`)},...(o.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),U&&U.models.length>0&&(0,Y.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`providers.templateModels`,{count:U.models.length})})]}):(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(k,{value:f,onChange:p,placeholder:r(`providers.searchTemplates`)}),a.isLoading&&(0,Y.jsx)(ne,{lines:4}),a.isError&&(0,Y.jsx)(H,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),I.map(e=>(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.${e.category}`)}),(0,Y.jsx)(Oe,{name:`provider-template`,"aria-label":r(`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,i]=Wn(e.name);return{value:e.id,label:(0,Y.jsx)(`span`,{title:e.name,children:n}),description:(0,Y.jsx)(`span`,{title:t.map(Hn).join(` · `),children:i??t.map(e=>Vn[e]).join(` · `)}),icon:(0,Y.jsx)(We,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:u.has(e.id),disabledReason:Un(r(`providers.subscriptionAdded`))}})})]},e.category)),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.plugin`)}),L.length>0?(0,Y.jsx)(Oe,{name:`provider-template-plugin`,"aria-label":r(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:_?.startsWith(zn)?_:null,onValueChange:y,options:L.map(e=>({value:zn+e.id,label:Un(e.name),description:Un(r(`providers.pluginProvided`)),icon:(0,Y.jsx)(We,{name:e.name,icon:e.icon,colorKey:e.id,size:28})}))}):(0,Y.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,Y.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:r(`providers.pluginHint`)}),(0,Y.jsx)(R,{size:`sm`,onClick:()=>{t(!1),d(`/plugins/market`)},children:r(`plugins.browseMarket`)})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.custom`)}),(0,Y.jsx)(Oe,{name:`provider-template-custom`,"aria-label":r(`providers.custom`),layout:`list`,density:`compact`,value:_===`custom`?`custom`:null,onValueChange:y,options:[{value:`custom`,label:r(`providers.custom`),description:r(`providers.customDetail`),icon:(0,Y.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,Y.jsx)(Ne,{className:`size-4`})})}]})]})]})]})}export{ln as a,yn as i,jn as n,Xe as o,An as r,Mn as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$r as e,Ar as t,Ci as n,Di as r,E as i,Ea as a,Ei as o,Er as s,Fi as c,Ft as l,Gr as u,H as d,Ht as f,Li as p,Lt as m,Mi as h,Ni as g,Nt as _,On as v,Pi as y,Pt as b,Rt as x,Ta as S,Ti as C,Tr as w,Ur as T,W as ee,Xt as E,_ as te,_i as ne,br as D,ci as O,cn as re,d as k,ei as ie,en as ae,fi as oe,gi as se,hi as ce,i as le,ka as ue,l as A,li as de,ln as fe,m as j,mt as M,n as N,o as pe,or as me,p as he,pi as ge,pt as _e,qr as ve,r as P,rr as F,s as ye,st as I,t as be,ti as xe,tn as Se,u as L,v as R,wa as Ce,wn as we,wt as z,xi as Te,y as B,yi as Ee,yt as V}from"./alert-BhYHbQ5M.js";import{B as De,F as Oe,I as ke,L as Ae,R as je,a as H,gt as U,i as Me,n as W,o as G,r as K,vt as q,z as Ne}from"./overlays-CF55BHOs.js";import{t as Pe}from"./TrayPanelView-CAF6qwfK.js";import{t as Fe}from"./download-DXwZa8b6.js";import{t as Ie}from"./ellipsis-DhvUvMq3.js";import{t as Le}from"./external-link-D9cY56rt.js";import{n as Re,t as ze}from"./radio-cards-BVdDbnT-.js";import{t as Be}from"./folder-open-Dt-7Rdbw.js";import{t as Ve}from"./log-out-wpGBd0OK.js";import{t as He}from"./minus-3JX68qL9.js";import{t as Ue}from"./pencil-BjMGSY_u.js";import{t as We}from"./rotate-ccw-Omdd6cJU.js";import{B as Ge,C as Ke,E as qe,L as Je,N as Ye,Q as Xe,R as J,T as Ze,Z as Qe,h as $e,n as et,s as tt,t as nt,tt as rt,w as it}from"./index-XVK9epgF.js";var at={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};at.node;var ot=V(at),st={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};st.node;var ct=V(st),lt={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};lt.node;var ut=V(lt),dt={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};dt.node;var ft=V(dt),pt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};pt.node;var mt=V(pt),ht={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};ht.node;var gt=V(ht),_t={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};_t.node;var vt=V(_t),Y=ue(a(),1),X=S(),yt=`https://astra-gate.si/docs/guide/remote-access`,bt=`astra.remote.acknowledged`;function xt(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function St(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Ct(){try{return localStorage.getItem(bt)===`1`}catch{return!1}}function wt(){try{localStorage.setItem(bt,`1`)}catch{}}function Tt(){let{t}=I(),n=e(),r=n.data;return r?r.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Et,{s:r}),(0,X.jsx)(Dt,{s:r}),(0,X.jsx)(Ot,{s:r}),(0,X.jsx)(jt,{s:r}),(0,X.jsx)(pe,{title:r.cloudflared.path&&r.cloudflared.version?t(`settings.remote.logWithVersion`,{version:r.cloudflared.version}):t(`settings.remote.log`),children:r.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`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:r.log.join(`
|
|
2
|
+
`)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(be,{tone:`info`,title:t(`settings.remote.unsupported`),children:t(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:n.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:H(n.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=I(),{toast:r,confirm:i}=G(),a=u(),o=m(),s=xt(e,t),c=async e=>{await U.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!Ct()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;wt()}(e||!o.data?.remote||await i({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate(e,{onError:e=>r(H(e),`error`)})},f=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,p=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,h=e.state===`connected`&&p!==null?p<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:ee(p,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),g=e.cloudflared,_=g.downloading||g.path?null:g.asset?t(`settings.remote.cloudflaredMissing`,{version:g.version??``}):t(`settings.remote.cloudflaredUnsupported`),v=e.enabled?e.error??g.error??null:null,y=v!==null&&(e.state!==`connected`||/origin service|origin server/i.test(v)),b=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(j,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?d(e.connectedAt,n):void 0,children:[(0,X.jsx)(ye,{tone:f}),h,g.downloading&&g.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(g.progress*100),`%`]})]}),children:(0,X.jsx)(B,{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&&_&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:_}),e.enabled&&b&&(0,X.jsxs)(j,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${b}/v1`}),children:[(0,X.jsx)(W,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(M,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void c(`${b}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(b)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${b}/key`),separatorBefore:!0}]}),(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(b,`_blank`,`noopener`)})]}),e.enabled&&b&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),y&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(be,{tone:e.state===`connected`?`warning`:`danger`,title:St(v,e,t),children:v})})]})}function Dt({s:e}){let{t}=I(),{toast:n,confirm:r}=G(),i=oe(),[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 U.copy(e)&&n(t(`common.copied`))},c=async a=>{if(e.enabled){let n=a===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}i.mutate({mode:a},{onError:e=>n(H(e),`error`)})},l=()=>i.mutate({hostname:a.hostname.trim()||null,...a.token.trim()?{token:a.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),o(e=>({...e,token:``}))},onError:e=>n(H(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(j,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(te,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void c(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(be,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(j,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(j,{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)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(M,{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)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(P,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=I(),{toast:n,confirm:r}=G(),i=oe(),a=m(),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(H(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(j,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(N,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(j,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(B,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=I(),{toast:n}=G(),r=m(),i=w(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(P,{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)(k,{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)(P,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(P,{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(H(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=I(),{toast:n}=G(),r=oe(),i=fe(),a=m(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[p,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(H(e),`error`)}),_=t=>{h(t),(t!==`custom`||e.download.downloadBaseUrl)&&g({downloadSource:t})},v=()=>i.mutate(void 0,{onSuccess:e=>e.path?f(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(H(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)(j,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:y}),children:(0,X.jsx)(ye,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${p}.hint`),children:(0,X.jsx)(K,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:p,onChange:_,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),p===`custom`&&(0,X.jsxs)(j,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(P,{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)(j,{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)(P,{size:`sm`,disabled:r.isPending,onClick:()=>g({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(P,{size:`sm`,onClick:()=>{u(!0),v()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(k,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:d,onChange:e=>f(e.target.value)}),(0,X.jsx)(P,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:v,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(P,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(P,{size:`sm`,variant:`primary`,disabled:!d.trim(),loading:r.isPending,onClick:()=>g({cloudflaredPath:d.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=I(),{toast:t,confirm:n}=G(),r=Ce(),i=we(),a=m(),s=xe(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=i.data;if(!f)return(0,X.jsx)(j,{label:e(`settings.listen`),detail:i.isError?H(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,h=Pt(f.configuredHost),g=f.configuredHost!==f.host,_=!!a.data?.required,v=async n=>{await U.copy(n)&&t(e(`common.copied`))},y=n=>s.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(H(e),`error`)}),b=async t=>{if(t!==h){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}y(t)}},x=async()=>{d(!0);let n=await U.restartService();if(d(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},S=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):_?e(`settings.listen.localOnly`,{address:p}):g?`${e(`settings.listen.pending`,{host:f.configuredHost})}${o?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:e(`settings.listen`),detail:S,children:!f.hostFromEnvironment&&!_&&(0,X.jsxs)(X.Fragment,{children:[g&&o&&(0,X.jsx)(P,{size:`sm`,loading:u,onClick:()=>void x(),children:e(`settings.listen.restart`)}),(0,X.jsx)(te,{ariaLabel:e(`settings.listen`),value:h,onChange:e=>void b(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(j,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(M,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void v(`${t}/v1`)})},t)),(h===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:f.passwordSet}),(0,X.jsx)(It,{open:c,onOpenChange:l,onSaved:()=>y(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=I(),{toast:i}=G(),a=w(),[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(H(e),`error`)})};return(0,X.jsx)(Me,{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)(P,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(P,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(k,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(k,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Lt=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],Rt={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},zt=e=>e===`feishu`||e===`dingtalk`,Bt=(e,t)=>e(`alerts.event.${t}`),Vt=(e,t)=>e(`alerts.event.${t}.hint`);function Ht(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(Ut,{}),(0,X.jsx)(Wt,{}),(0,X.jsx)(Yt,{})]})}function Ut(){let{t:e,locale:t}=I(),n=l(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),n.data?.length===0&&(0,X.jsx)(j,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(j,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${d(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=I(),{toast:t,confirm:n}=G(),r=ne(),i=re(),a=T(),o=D(),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),p=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(H(e),`error`)}),m=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>f(e.secret??null),onError:e=>t(H(e),`error`)})},h=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(H(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)(j,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(j,{icon:(0,X.jsx)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(N,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||zt(t.format))&&(0,X.jsx)(N,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(P,{size:`sm`,icon:(0,X.jsx)(Re,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>p(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(W,{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)(ft,{className:`size-3.5`}),onSelect:()=>u(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ge,{className:`size-3.5`}),onSelect:()=>void m(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(Ye,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void h(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(P,{size:`sm`,icon:(0,X.jsx)(J,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:s,onClose:()=>c(null),onSecret:f}),(0,X.jsx)(qt,{hook:l,onClose:()=>u(null)}),(0,X.jsx)(Kt,{secret:d,onClose:()=>f(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=I(),{toast:i}=G(),a=ae(),o=ge(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(10),[p,m]=(0,Y.useState)(!0),[h,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(`generic`),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)([]),T=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;c(t?.name??``),u(t?.url??``),f(t?.timeoutSec??10),m(t?.useProxy??!0),g(t?.enabled??!0),v(!t||t.hasSecret),b(t?.format??`generic`),S(``),w((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Me,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(T?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(P,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(H(e),`error`)},m=!T&&e!==null&&e.format!==y,g=zt(y)?_?x.trim()||void 0:``:void 0;T?a.mutate({...u,format:y,...y===`generic`?{signed:_}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:y}:{},...y===`generic`?_||!e.hasSecret||m?{}:{signed:!1}:g===void 0?{}:{secret:g}},{...f,onSuccess:()=>{t(),i(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(A,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(k,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(A,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${y}.hint`),children:(0,X.jsx)(K,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(A,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(k,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(A,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(k,{mono:!0,type:`password`,autoComplete:`off`,value:x,placeholder:e!==`new`&&e!==null&&e.format===y&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>S(e.target.value)})}),(0,X.jsx)(A,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(he,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(A,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[C.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(k,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>w(C.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(k,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ye,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>w(C.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(P,{size:`sm`,icon:(0,X.jsx)(J,{className:`size-3.5`}),onClick:()=>w([...C,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(j,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(B,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:g})}),(0,X.jsx)(j,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(B,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?T||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(j,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(B,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=I(),{toast:r}=G();return(0,X.jsx)(Me,{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)(P,{onClick:async()=>e&&await U.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(P,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=I(),{toast:i}=G(),a=se(e?.id),o=me(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Me,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(N,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):Bt(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:d(e.createdAt,r)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?n(`alerts.delivery.next`,{time:d(e.nextAttemptAt,r)}):n(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.payload`)}),(0,X.jsx)(le,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(le,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(P,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(H(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(e){let t=F(),n=ve(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=q({queries:r.map(t=>({queryKey:z.providerAccounts(t.id),queryFn:()=>Ee(`GET`,`/api/providers/${Te(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 Yt(){let{t:e}=I(),{toast:t,confirm:n}=G(),r=b(),i=ne(),a=ie(),o=Se(),[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(H(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)(j,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(j,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(N,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(N,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Bt(e,n.event)} → ${n.webhookIds.map(l).join(`, `)||`—`}`,children:[(0,X.jsx)(B,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(H(e),`error`)})}),(0,X.jsx)(W,{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)(Ye,{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)(P,{size:`sm`,icon:(0,X.jsx)(J,{className:`size-3.5`}),onClick:()=>c(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Zt,{rule:s,onClose:()=>c(null)})]})}function Xt(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Zt({rule:e,onClose:t}){let{t:n}=I(),{toast:r}=G(),i=_(),a=ne(),o=E(),s=ie(),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)({}),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[T,ee]=(0,Y.useState)(60),D=i.data?.find(e=>e.id===u),O=Jt(D?.subjectType),re=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=i.data?.[0];l(t?.name??``),d(t?.event??n?.id??``),p(t?{...Xt(i.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),h(t?.subjects?`only`:`all`),v(t?.subjects??[]),b(t?.webhookIds??(a.data??[]).map(e=>e.id)),S(t?.notifyResolved??!1),w(t?.repeatMinutes??null),ee(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(Me,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(re?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(P,{variant:`primary`,disabled:!c.trim()||!u,loading:o.isPending||s.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(f).filter(([,e])=>e!==null&&e!==``)),a={name:c.trim(),event:u,condition:i,subjects:m===`all`?null:g,webhookIds:y,notifyResolved:x,repeatMinutes:C&&C>0?Math.floor(C):null,cooldownMinutes:Math.max(0,Math.floor(T??0))},l={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(H(e),`error`)};re?o.mutate(a,l):e&&s.mutate({id:e.id,...a},l)},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(A,{label:n(`alerts.rules.name`),children:(0,X.jsx)(k,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,X.jsx)(A,{label:n(`alerts.rules.event`),hint:u?Vt(n,u):void 0,children:(0,X.jsx)(K,{ariaLabel:n(`alerts.rules.event`),value:u,onChange:e=>{d(e),p(Xt(i.data?.find(t=>t.id===e))),v([])},options:(i.data??[]).map(e=>({value:e.id,label:Bt(n,e.id)}))})}),D?.params.map(e=>(0,X.jsx)(A,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(he,{value:typeof f[e.name]==`number`?f[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>p({...f,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(K,{ariaLabel:n(`alerts.param.${e.name}`),value:String(f[e.name]??``),onChange:t=>p({...f,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(k,{mono:!0,value:String(f[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>p({...f,[e.name]:t.target.value})})},e.name)),D&&(0,X.jsx)(A,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${D.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(te,{ariaLabel:n(`alerts.rules.subjects`),value:m,onChange:h,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),m===`only`&&(0,X.jsx)(tt,{label:n(`alerts.rules.subjects`),value:g,onValueChange:v,options:[...O,...g.filter(e=>!O.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(A,{label:n(`alerts.rules.webhooks`),children:(a.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.rules.noWebhooks`)}):(0,X.jsx)(tt,{label:n(`alerts.rules.webhooks`),value:y,onValueChange:b,options:(a.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(A,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(he,{value:C,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:w})}),(0,X.jsx)(A,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(he,{value:T,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:ee})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(j,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(B,{checked:x,label:n(`alerts.rules.notifyResolved`),onChange:S})})})]})})}function Qt(){let{t:e}=I(),t=x(),n=C()?.loginItem,i=t.data?.mechanism===`launchd`||!!n&&r;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:i?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=I(),{toast:n}=G(),[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)(j,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(B,{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(H(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=I(),{toast:t}=G(),n=x(),r=s(),i=n.data;if(!i)return(0,X.jsx)(j,{label:e(`settings.startup.service`),detail:n.isError?H(n.error):void 0,children:n.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let a=!i.supported||i.mechanism===`none`?e(`settings.startup.unsupported.${i.unsupported??`platform`}`):i.canChange?i.enabled&&i.location?e(`settings.startup.entry`,{location:i.location}):e(`settings.startup.service.${i.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(j,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(B,{checked:i.enabled,disabled:!i.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(H(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=i,nn=[...i.ease.enter],rn=[...i.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=rt(e,e=>`${n(e)*1.05}em`),i=rt(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=rt(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=rt(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(h.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function Dn({digit:e,direction:t,instant:n}){let r=y(),i=c(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):g(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),an.map(e=>(0,X.jsx)(En,{position:i,digit:e},e))]})}function On({value:e,format:t,direction:n,instant:r}){let i=y(),a=r?Tn:i?wn:Sn;return(0,X.jsx)(p,{initial:!1,custom:n,children:xn(e,t).map(e=>(0,X.jsx)(h.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(Dn,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function kn({text:e,direction:t,className:n}){let r=y();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(p,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(h.span,{className:Z.char,custom:t,variants:r?wn:Sn,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var An=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},jn=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=An(n[t]),i=An(e);return r!==null&&i!==null&&i<r?-1:1})},Mn={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:nn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{duration:.14,ease:rn}})},Nn={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function Pn({word:e,direction:t}){let n=y(),r=(0,Y.useRef)(null),i=c(`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):g(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(h.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(p,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(h.span,{className:Z.word,custom:t,variants:n?Nn:Mn,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Fn({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:jn(t.text,e)});let r=t.text===e?t.directions:jn(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(Pn,{word:e,direction:r[t]??1})]},t))})]})}function In({id:e,text:t,className:n}){return(0,X.jsx)(p,{initial:!1,children:t?(0,X.jsx)(Ln,{id:e,text:t,className:n},`message`):null})}function Ln({id:e,text:t,className:n}){let r=y(),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)(h.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)(h.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${tn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:nn},children:(0,X.jsx)(Fn,{text:t})})})}function Rn({id:e,edge:t,text:n}){let r=y();return(0,X.jsx)(p,{initial:!1,children:t!==0&&(0,X.jsx)(h.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${tn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:rn}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function zn({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?J: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 Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:l,disabled:u,id:d,prefix:f,suffix:p,scrub:m=!1,locale:_=`en-US`,formatOptions:v,size:b=`md`,limitHint:x=!0}){let S=y(),C=(0,Y.useId)(),w=d??C,T=l?`${w}-description`:void 0,ee=`${w}-limit`,E=o>0?o:1,[te,ne]=(0,Y.useState)(n),D=t??te,[O,re]=(0,Y.useState)(``),[k,ie]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(0),[se,ce]=(0,Y.useState)(!1),[le,ue]=(0,Y.useState)(``),[A,de]=(0,Y.useState)(0),[fe,j]=(0,Y.useState)(!1),M=(0,Y.useRef)(null),N=(0,Y.useRef)(null),pe=(0,Y.useRef)(null),me=(0,Y.useRef)(void 0),he=(0,Y.useRef)(void 0),ge=(0,Y.useRef)(void 0),_e=(0,Y.useRef)({edge:0,count:0,at:0}),ve=(0,Y.useRef)(null),P=(0,Y.useRef)(null),F=(0,Y.useRef)(D),ye=(0,Y.useRef)(D),I=(0,Y.useRef)(void 0),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(!1),Se=(0,Y.useRef)(null),L=(0,Y.useRef)(!1),R=(0,Y.useRef)(()=>!1),Ce=c(0),we=c(0),z=c(0),Te=rt(()=>we.get()+z.get()),B=Number.isFinite(i)?i:0,Ee=Math.max(_n(E),_n(B)),V=v?.minimumFractionDigits??Ee,De=Math.max(V,v?.maximumFractionDigits??Ee),Oe=v?.useGrouping??!0,ke=(0,Y.useMemo)(()=>new Intl.NumberFormat(_,{minimumFractionDigits:V,maximumFractionDigits:De,useGrouping:Oe,numberingSystem:`latn`}),[_,V,De,Oe]),Ae=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(_).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[_]),je=e=>Number(e.toFixed(Ee))||0,H=e=>Math.min(a,Math.max(i,e)),U=e=>je(B+Math.round((e-B)/E)*E),Me=(e,t)=>{let n=(e-B)/E;return je(B+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*E)},W=e=>`${yn(f,e)}${ke.format(e)}${yn(p,e)}`.trim();function G(e){let t=e.split(Ae.group).join(``).replace(Ae.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let K=k?G(O):null,q=K??D,[Ne,Pe]=(0,Y.useState)({value:q,direction:1});Ne.value!==q&&Pe({value:q,direction:q>Ne.value?1:-1});let Fe=Ne.value===q?Ne.direction:q>Ne.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(I.current),window.clearTimeout(me.current),window.clearTimeout(he.current),window.clearTimeout(ge.current)},[]);function Ie(e,t){let n=performance.now(),r=_e.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let i=M.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(ge.current),ge.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!S){g(Ce,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?pe:N).current;n&&(t===`button`||t===`key`)&&g(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}x&&(de(e),window.clearTimeout(me.current),me.current=window.setTimeout(()=>de(0),un))}function Le(e,n){if(!Number.isFinite(e))return!1;let i=H(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Ie(a>0?1:-1,n),ue(`${W(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&ue(W(i)),i!==F.current&&(F.current=i,t===void 0&&ne(i),r?.(i),!0)}let Re=(e,t,n)=>Le(Me(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=D,R.current=Re});function ze(){let e=P.current;e&&Se.current===null&&(Se.current=e.getBoundingClientRect().left-we.get()-z.get())}(0,Y.useLayoutEffect)(()=>{let e=Se.current,t=P.current;if(Se.current=null,L.current){L.current=!1;let e=ve.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-we.get()-z.get());Math.abs(n)<.5||(z.set(z.get()+n),S?z.jump(0):g(z,0,Q.morph))});function Be(){window.clearTimeout(he.current),j(!1)}function Ve(){if(!k)return;ze(),ie(!1),Be();let e=G(O);e!==null&&Le(U(e),`type`)}function He(){window.clearTimeout(I.current),I.current=void 0,oe(0)}function Ue(e,t,n){He(),Ve();let r=Math.max(1,Math.round(t/E));n===`button`&&oe(e);let i=0,a=()=>{let t=R.current(e,r,n);I.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};I.current=window.setTimeout(a,Re(e,r,n)?sn:360)}function We(e){let t=s??E*10,n={ArrowUp:[1,e.shiftKey?t:E],ArrowDown:[-1,e.shiftKey?t:E],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?(L.current=!0,Ve()):e.currentTarget.select()),e.key===`Escape`&&k&&(e.preventDefault(),ze(),ie(!1),Be(),L.current=!0,Le(ye.current,`type`))}function Ge(e){let t=RegExp(`[^0-9${vn(Ae.group)}${Ee||De?vn(Ae.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);k||(ye.current=D),ze(),re(n),ie(!0);let r=G(n);r!==null&&r>=i&&r<=a&&U(r)===r&&Le(r,`type`),Be(),r!==null&&r<i&&(he.current=window.setTimeout(()=>j(!0),dn))}function Ke(e){xe.current=!1,m&&!u&&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,ce(!0)}let r=n/on,o=Math.trunc(r);Le(o?Me(t.from,o):t.from,`scrub`);let s=t.from+r*E,c=s>a?(s-a)/E*on:s<i?(s-i)/E*on:0;we.set(S?0:bn(c))}function Je(e){let t=be.current;t&&t.pointer===e.pointerId&&(be.current=null,t.active&&(xe.current=!0,ce(!1),g(we,0,S?{duration:0}:Q.snappy),ue(W(F.current))))}let Ye=t=>({toward:t,label:e,disabled:u,controls:w,limit:t>0?q>=a:q<=i,pressed:ae===t}),Xe=K===null?0:K>a?1:K<i&&fe?-1:0,J=x?Xe||A:0,Ze=J>0?a:i,Qe=J?typeof x==`function`?x(J>0?`max`:`min`,Ze):`${J>0?`Max`:`Min`} ${W(Ze)}`:``,$e=[T,Xe&&x?ee:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":b,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:w,className:Z.label,"data-scrub":m&&!u||void 0,onPointerDown:Ke,onPointerMove:qe,onPointerUp:Je,onPointerCancel:Je,onClick:e=>{xe.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:ee,edge:J,text:Qe})]}),(0,X.jsxs)(`div`,{ref:M,className:Z.control,"data-scrubbing":se||void 0,"data-disabled":u||void 0,"data-warn":Xe?Xe>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Ye(-1),iconRef:N,onPress:()=>Ue(-1,E,`button`),onRelease:He,onActivate:()=>{Ve(),Re(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==ve.current&&e.preventDefault()},onClick:e=>{!u&&e.target!==ve.current&&(ve.current?.focus(),ve.current?.select())},children:(0,X.jsxs)(h.span,{ref:P,className:Z.value,style:{x:Te,y:Ce},children:[(0,X.jsx)(kn,{text:yn(f,q),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)(On,{value:q,format:ke,direction:Fe,instant:k})}),k&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:O}),(0,X.jsx)(`input`,{ref:ve,id:w,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:Ee||De?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:k?O:ke.format(D),disabled:u,"aria-describedby":$e,"aria-invalid":Xe?!0:void 0,"aria-valuenow":D,"aria-valuetext":W(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)(kn,{text:yn(p,q),direction:Fe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Ye(1),iconRef:pe,onPress:()=>Ue(1,E,`button`),onRelease:He,onActivate:()=>{Ve(),Re(1,1,`button`)}})]}),(0,X.jsx)(In,{id:T,text:l,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:le})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=I(),t=Ce(),[r,i]=je(),a=Ne(),o=Oe(r,{enabled:a.running,background:!1,live:!0}),s=t=>(0,X.jsx)(j,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(B,{checked:r.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>i(De(r,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Un,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(ze,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:r.title,onValueChange:e=>i({...r,title:e}),options:n.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Un,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:Vn.map(s)})}),(0,X.jsx)(Un,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:s(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(We,{className:`size-3.5`}),onClick:()=>i(ke),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Pe,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:r,state:a,data:o,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Un({title:e,hint:t,children:n}){let{t:r}=I();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Wn=[`general`,`notifications`,`remote`,`tray`],Gn=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Kn(){let{t:e}=I(),{tab:t}=Xe(),n=Qe(),r=Ae(),i=Wn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)($e,{title:e(`nav.settings`),children:(0,X.jsxs)(Ke,{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)(qe,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(gt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(qe,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ct,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(qe,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(_e,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(qe,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(it,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(it,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(it,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(it,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:n,locale:r,setLocale:i}=I(),a=et(),s=t(),c=O(),l=Ce(),u=ce(),d=m(),f=v(),p=e(),{toast:h,confirm:g}=G(),_=s.data,y=p.data?.state===`connected`&&p.data.publicUrl?`${p.data.publicUrl}/v1`:null,b=e=>c.mutate(e,{onError:e=>h(H(e),`error`)}),x=e=>{i(e),b({locale:e})},S=async e=>{await U.copy(e)&&h(n(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:n(`settings.appearance`),children:[(0,X.jsx)(j,{label:n(`settings.theme`),children:(0,X.jsx)(te,{ariaLabel:n(`settings.theme`),value:a.theme,onChange:a.setTheme,items:[{value:`system`,label:n(`settings.theme.system`)},{value:`light`,label:n(`settings.theme.light`)},{value:`dark`,label:n(`settings.theme.dark`)}]})}),(0,X.jsx)(j,{label:n(`settings.accent`),detail:a.accentChoice===`system`?a.systemAccent?n(`settings.accent.followingSystem`):n(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(K,{className:`w-40`,ariaLabel:n(`settings.accent`),value:a.accentChoice,onChange:a.setAccentChoice,options:[{value:`system`,label:n(`settings.accent.system`)},...nt.map(e=>({value:e.color,label:n(`settings.accent.${e.id}`)}))]})}),(0,X.jsx)(j,{label:n(`settings.language`),detail:n(`settings.languageHint`),children:(0,X.jsx)(te,{ariaLabel:n(`settings.language`),value:r,onChange:x,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:n(`settings.gateway`),footer:n(`settings.gatewayFooter`),children:[(0,X.jsx)(j,{label:n(`settings.gatewayUrl`),detail:`${_.gatewayBaseUrl}/v1`,children:(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(M,{className:`size-3.5`}),"aria-label":n(`common.copy`),onClick:()=>void S(`${_.gatewayBaseUrl}/v1`)})}),y&&(0,X.jsx)(j,{label:n(`settings.remote.publicUrl`),detail:y,children:(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(M,{className:`size-3.5`}),"aria-label":n(`common.copy`),onClick:()=>void S(y)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(j,{label:n(`settings.dataDir`),detail:_.dataDir,children:U.canOpenPaths?(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Be,{className:`size-3.5`}),"aria-label":n(`settings.openFolder`),onClick:()=>void U.openPath(_.dataDir)}):(0,X.jsx)(P,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(M,{className:`size-3.5`}),"aria-label":n(`common.copy`),onClick:()=>void S(_.dataDir)})}),(0,X.jsx)(j,{label:n(`settings.requireKey`),detail:n(`settings.requireKeyHint`),children:(0,X.jsx)(B,{checked:_.requireGatewayKey,label:n(`settings.requireKey`),onChange:async e=>{(e||await g({title:n(`settings.requireKeyOffConfirm`),detail:n(`settings.requireKeyOffDetail`),confirmLabel:n(`settings.requireKeyOff`),destructive:!0}))&&b({requireGatewayKey:e})}})}),(0,X.jsx)(j,{label:n(`settings.streamIdle`),detail:n(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:n(`settings.streamIdle`),value:_.streamIdleTimeoutSec,onCommit:e=>b({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(j,{label:n(`settings.requestCompression`),detail:n(`settings.requestCompressionHint`),children:(0,X.jsx)(K,{className:`w-40`,ariaLabel:n(`settings.requestCompression`),value:_.requestCompression,onChange:e=>b({requestCompression:e}),options:[{value:`default`,label:n(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:n(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(Yn,{settings:_}),(0,X.jsx)(Xn,{settings:_}),(0,X.jsxs)(L,{title:n(`settings.quota`),footer:n(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(j,{label:n(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:n(`settings.quota.autoInterval`),value:_.quotaAutoIntervalMinutes,onCommit:e=>c.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void l.invalidateQueries({queryKey:z.providers}),onError:e=>h(H(e),`error`)}),suffix:` ${n(`settings.minutes`)}`})}),(0,X.jsx)(j,{label:n(`settings.quota.subscriptionInterval`),detail:n(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:n(`settings.quota.subscriptionInterval`),value:_.subscriptionQuotaIntervalMinutes,onCommit:e=>b({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${n(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:n(`settings.usageTimeZone.hint`),children:(0,X.jsx)(j,{label:n(`settings.usageTimeZone`),children:(0,X.jsx)(K,{className:`w-56`,ariaLabel:n(`settings.usageTimeZone`),value:_.usageTimeZone??``,onChange:e=>b({usageTimeZone:e||null}),options:[{value:``,label:n(`settings.usageTimeZone.system`,{zone:_.effectiveUsageTimeZone})},...[...new Set([...Gn,..._.usageTimeZone?[_.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:n(`settings.logging`),footer:n(`settings.debugBodiesHint`),children:[(0,X.jsx)(j,{label:n(`settings.debugBodies`),children:(0,X.jsx)(B,{checked:_.debugBodies,label:n(`settings.debugBodies`),onChange:e=>b({debugBodies:e})})}),(0,X.jsx)(j,{label:n(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:n(`settings.bodyRetention`),value:_.bodyRetentionDays,onCommit:e=>b({bodyRetentionDays:e??7}),suffix:` ${n(`settings.days`)}`})}),(0,X.jsxs)(j,{label:n(`settings.requestRetention`),detail:_.requestRetentionDays==null?n(`settings.keepForever`):void 0,children:[(0,X.jsx)(B,{checked:_.requestRetentionDays!=null,label:n(`settings.requestRetention`),onChange:e=>b({requestRetentionDays:e?90:null})}),_.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:n(`settings.requestRetention`),value:_.requestRetentionDays,onCommit:e=>b({requestRetentionDays:e??90}),suffix:` ${n(`settings.days`)}`})]})]}),(0,X.jsx)(L,{title:n(`settings.effort`),footer:n(`settings.effortHint`),children:[`low`,`medium`,`high`].map(e=>(0,X.jsx)(j,{label:n(`settings.effort.${e}`),children:(0,X.jsx)(Zn,{label:n(`settings.effort.${e}`),value:_.effortBudgets[e],onCommit:t=>b({effortBudgets:{..._.effortBudgets,[e]:t??_.effortBudgets[e]}}),suffix:` tokens`,step:1024})},e))})]}):s.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:H(s.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:n(`settings.about`),children:[(0,X.jsx)(j,{label:n(`settings.serverVersion`),detail:u.data?`${u.data.version} · API ${u.data.apiVersion}`:`—`}),o&&(0,X.jsx)(j,{label:n(`settings.desktopVersion`),detail:C()?.version||`—`}),(0,X.jsx)(Jn,{}),o&&(0,X.jsx)(j,{label:n(`settings.logs`),onClick:()=>void U.revealLogs(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(j,{label:n(`settings.logout`),onClick:()=>f.mutate(),children:(0,X.jsx)(Ve,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=I(),{toast:n}=G(),r=Ce(),i=O(),a=t(),o=de(),s=f(),c=o.data,l=a.data?.updateChannel??c?.channel,u=C()?.updates??null,[d,p]=(0,Y.useState)(!1),m=()=>s.mutate(void 0,{onSuccess:t=>t.error?n(e(`settings.updateCheckFailed`,{error:t.error}),`error`):n(t.available?e(`settings.updateAvailable`,{version:t.available}):e(`settings.upToDate`)),onError:e=>n(H(e),`error`)}),h=()=>{u&&!d&&(p(!0),u.apply().then(t=>{t===`server`?(n(e(`settings.updateApplied`)),r.invalidateQueries({queryKey:z.version}),r.invalidateQueries({queryKey:z.update})):n(e(t===`desktop`?`settings.updateDesktopRelaunch`:t===`download`?`settings.updateDownloadOpened`:`settings.upToDate`))}).catch(e=>n(H(e),`error`)).finally(()=>p(!1)))},g=c?.lastCheckAt?new Date(c.lastCheckAt).toLocaleString():void 0,_=c?.available?u?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)(j,{label:e(`settings.autoCheck`),detail:c&&!c.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(B,{checked:c?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>i.mutate({updateAutoCheck:e},{onError:e=>n(H(e),`error`)})})}),(0,X.jsx)(j,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(B,{checked:l===`preview`,label:e(`settings.previewUpdates`),disabled:!l||i.isPending,onChange:e=>i.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:m,onError:e=>n(H(e),`error`)})})}),(0,X.jsxs)(j,{label:e(`settings.checkUpdates`),detail:s.isError?e(`settings.updateCheckFailed`,{error:H(s.error)}):c?.available?_:g?e(`settings.lastChecked`,{time:g}):void 0,children:[(0,X.jsx)(P,{size:`sm`,variant:`plain`,disabled:s.isPending,onClick:m,children:s.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Je,{className:`size-3.5`})}),u&&c?.available&&(0,X.jsx)(P,{size:`sm`,variant:`plain`,disabled:d,"aria-label":e(`settings.updateApply`),onClick:h,children:d?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Fe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=I(),{toast:n}=G(),r=O(),[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(H(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(H(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)(j,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(te,{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)(j,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(j,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(j,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(k,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(j,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(k,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(P,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=I(),{toast:n}=G(),r=O(),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(H(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(j,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(B,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(k,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(P,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(P,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Zn({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Bn,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Kn as SettingsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Ea as e,Fr as t,G as n,J as r,Jr as i,Kr as ee,Q as a,Ta as o,Wr as te,Y as s,_ as c,c as l,gr as u,ka as d,n as f,nr as p,q as m,r as h,rr as g,s as _,st as v,t as y,v as b}from"./alert-BhYHbQ5M.js";import{a as ne,at as re,it as ie,nt as ae,ot as oe,rt as x}from"./overlays-CF55BHOs.js";import{t as S}from"./arrow-left-ByzgpjKh.js";import{D as C,I as w,O as T,Q as E,Y as D,Z as O,h as k,m as A}from"./index-XVK9epgF.js";import{a as j,n as M}from"./TokenPoolEditor-BITgITLH.js";var N=d(e(),1),P=o();function F(){let{id:e=``}=E(),{t:o,locale:d}=v(),F=O(),[L,R]=(0,N.useState)(`7d`),z=ee(e),B=g(),V=t(L,void 0,e),H=te(L,L===`today`?`hour`:`day`,`token`,void 0,e),U=i(L,void 0,20,e),W=p(L,e),G=u({token:e,page:1,pageSize:10},!1),K=j(),q=(0,P.jsx)(h,{variant:`glass`,icon:(0,P.jsx)(S,{className:`size-4`}),"aria-label":o(`common.back`),onClick:()=>F(`/tokens`)}),J=o(`range.${L}`),se=(0,N.useMemo)(()=>re(ie(H.data??[],`requests`),oe(L)).map(e=>({key:e.bucket,label:x(e.bucket),axisLabel:ae(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:o(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:o(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`share`,label:o(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>m(e)},{key:`success`,label:o(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?m(e):`—`},{key:`ttft`,label:o(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>n(e)},{key:`cost`,label:o(`overview.cost`),sortable:!0,numeric:!0,render:e=>a(e)},{key:`out`,label:o(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:o(`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:o(`tokens.detail.model`),sortable:!0},{key:`requests`,label:o(`overview.requests`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`tokens`,label:o(`overview.tokens`),sortable:!0,numeric:!0,render:e=>s(e,!0)},{key:`cost`,label:o(`overview.cost`),sortable:!0,numeric:!0,render:e=>a(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:o(`tokens.detail.time`),render:(e,t)=>r(t.r.startedAtUtc,d)},{key:`model`,label:o(`tokens.detail.model`)},{key:`provider`,label:o(`tokens.detail.provider`)},{key:`status`,label:o(`tokens.detail.status`),render:e=>(0,P.jsx)(f,{tone:e===`success`?`green`:`red`,children:o(`status.${e}`)})},{key:`cost`,label:o(`overview.cost`),numeric:!0,render:e=>a(e)}];if(z.isError)return(0,P.jsx)(k,{title:o(`nav.tokens`),leading:q,children:(0,P.jsx)(y,{tone:`danger`,title:o(`common.error`),children:ne(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)(h,{icon:(0,P.jsx)(w,{className:`size-3.5`}),children:o(`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:o(`overview.range`),value:L,onChange:R,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:o(`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:o(`overview.totalCost`),value:a($.costUsd),context:J}),(0,P.jsx)(I,{label:o(`overview.totalRequests`),value:s($.requests),context:J}),(0,P.jsx)(I,{label:o(`overview.tokens`),value:s($.inputTokens+$.outputTokens,!0),context:o(`overview.tokensContext`,{input:s($.inputTokens,!0),output:s($.outputTokens,!0)})}),(0,P.jsx)(I,{label:o(`usage.hitRate`),value:m(A($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,P.jsx)(I,{label:o(`overview.successRate`),value:$.requests?m($.successRate):`—`,context:n($.avgTtftMs)})]}):(0,P.jsx)(b,{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:[o(`tokens.pool.title`),` · `,o(`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)(_,{tone:M(e.health.state)}),Y.get(e.providerId)??e.providerId,(0,P.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:K(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,P.jsx)(`div`,{className:`card`,children:(0,P.jsx)(l,{title:o(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:o(`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:[o(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,P.jsx)(b,{lines:4}):(0,P.jsx)(T,{data:se,label:o(`overview.requests`),period:J,height:160,formatValue:e=>s(e),averageLabel:o(L===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:o(`overview.total`),categoryLabel:o(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:o(`tokens.detail.byProvider`)}),(0,P.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:o(`tokens.detail.byProviderHint`)}),(0,P.jsx)(C,{caption:o(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:o(`common.noData`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:o(`tokens.detail.byModel`)}),(0,P.jsx)(C,{caption:o(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:o(`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:o(`tokens.detail.recent`)}),(0,P.jsx)(D,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(e)}`,children:o(`tokens.detail.viewLogs`)})]}),(0,P.jsx)(C,{caption:o(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:o(`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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{J as e,Ta as t,_ as n,at as r,er as i,n as a,p as o,r as s,st as c,y as l}from"./alert-BhYHbQ5M.js";import{r as u}from"./overlays-CF55BHOs.js";import{a as d,c as f,d as p,f as m,i as h,l as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./sortable.esm-CTCQ-9IR.js";import{N as w,x as T}from"./index-XVK9epgF.js";var E=t(),D=[`failover`,`round_robin`,`weighted`,`tiered`,`least_busy`];function O(e){return e.pool?{strategy:e.pool.strategy,sticky:e.pool.sticky,failover:e.pool.failover,maxAttempts:e.pool.maxAttempts,members:e.pool.members.map(e=>({providerId:e.providerId,accountId:e.accountId??null,weight:e.weight,tier:e.tier}))}:{strategy:`failover`,sticky:`session`,failover:!0,maxAttempts:3,members:e.providerId?[{providerId:e.providerId,accountId:e.accountId??null,weight:1,tier:1}]:[]}}function k(e,t){let n=new Set(t.map(e=>e.id));return{strategy:e.strategy,sticky:e.sticky,failover:e.failover,maxAttempts:Math.min(5,Math.max(1,Math.floor(e.maxAttempts||1))),members:e.members.filter(e=>n.has(e.providerId)).map(e=>({...e,weight:Math.max(1,Math.floor(e.weight||1))}))}}function A(e){let{members:t,strategy:n}=e;if(t.length===0)return[];let r=e=>e.reduce((e,t)=>e+Math.max(1,t.weight),0);switch(n){case`failover`:return t.map((e,t)=>+(t===0));case`weighted`:{let e=r(t);return t.map(t=>Math.max(1,t.weight)/e)}case`tiered`:{let e=Math.min(...t.map(e=>e.tier)),n=r(t.filter(t=>t.tier===e));return t.map(t=>t.tier===e?Math.max(1,t.weight)/n:0)}default:return t.map(()=>1/t.length)}}var j=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],M=new Set([`oauth-subscription`,`plugin`]);function N(e){return e===`healthy`?`green`:e===`cooling`||e===`open`||e===`half_open`?`orange`:`red`}function P(){let{t,locale:n}=c();return r=>r.state===`cooling`||r.state===`open`?t(`tokens.health.${r.state}`,{time:r.until?e(r.until,n):`—`}):t(`tokens.health.${r.state}`)}function F({draft:e,onChange:t,providers:r,health:i}){let{t:a}=c(),s=new Map(r.map(e=>[e.id,e])),m=e.members.length>1,h=p(C(f,{activationConstraint:{distance:4}}),C(x,{coordinateGetter:b})),y=n=>t({...e,members:n}),w=(t,n)=>y(e.members.map((e,r)=>r===t?{...e,...n}:e)),T=({active:t,over:n})=>{if(!n||t.id===n.id)return;let r=e.members.findIndex(e=>e.providerId===t.id),i=e.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&y(_(e.members,r,i))},O=r.filter(t=>t.enabled&&!e.members.some(e=>e.providerId===t.id)),k=A(e),M=e.members.flatMap(e=>{let t=s.get(e.providerId);return t&&t.modelCount===0?[t.name]:[]});return(0,E.jsxs)(`div`,{className:`grid gap-3`,children:[m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(n,{ariaLabel:a(`tokens.pool.strategy`),value:e.strategy,onChange:n=>t({...e,strategy:n}),items:D.map(e=>({value:e,label:a(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:a(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(v,{sensors:h,collisionDetection:g,onDragEnd:T,children:(0,E.jsx)(S,{items:e.members.map(e=>e.providerId),strategy:d,children:e.members.map((t,n)=>(0,E.jsx)(I,{member:t,index:n,draft:e,provider:s.get(t.providerId),health:i?.get(t.providerId),onChange:e=>w(n,e),onRemove:()=>y(e.members.filter((e,t)=>t!==n))},t.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:a(`tokens.pool.add`),placeholder:a(`tokens.pool.add`),value:null,onChange:t=>y([...e.members,{providerId:t,accountId:null,weight:1,tier:1}]),options:O.map(e=>({value:e.id,label:e.name}))}),M.length>0&&(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--warning)]`,children:a(`tokens.pool.noModels`,{providers:M.join(`, `)})}),m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2 text-[12px]`,children:[(0,E.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:a(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`tokens.pool.shareHint`)})]}),(0,E.jsx)(`div`,{className:`flex h-2 gap-0.5 overflow-hidden rounded-full bg-[var(--fill-2)]`,"aria-hidden":`true`,children:e.members.map((e,t)=>k[t]>0?(0,E.jsx)(`span`,{style:{flex:k[t],background:j[t%j.length]}},e.providerId):null)}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:e.members.map((e,t)=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`inline-block size-2 rounded-sm`,style:{background:j[t%j.length]}}),s.get(e.providerId)?.name??e.providerId,(0,E.jsxs)(`b`,{className:`tabular-nums text-[var(--text-primary)]`,children:[Math.round(k[t]*100),`%`]}),k[t]===0&&(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`tokens.pool.standby`)})]},e.providerId))})]}),m&&(0,E.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:a(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(l,{label:a(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:n=>t({...e,sticky:n?`session`:`off`})})]}),(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:a(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(l,{label:a(`tokens.pool.failover`),checked:e.failover,onChange:n=>t({...e,failover:n})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:a(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(o,{label:a(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:n=>t({...e,maxAttempts:n??1})})})]})]})]})}function I({member:e,index:t,draft:n,provider:l,health:d,onChange:f,onRemove:p}){let{t:g}=c(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!l&&M.has(l.authScheme),A=i(l?.id,k),j=l?.name??e.providerId,F=n.members.length>1,I=l?l.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:r(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,O&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,E.jsx)(`button`,{ref:S,type:`button`,"aria-label":g(`clients.dragToReorder`,{provider:j}),title:g(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...v,...b,children:(0,E.jsx)(y,{className:`size-4`})}),l&&(0,E.jsx)(T,{name:l.name,icon:l.icon,colorKey:l.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&n.strategy===`failover`&&(0,E.jsx)(a,{tone:t===0?`accent`:`neutral`,children:t===0?g(`tokens.pool.primary`):g(`tokens.pool.backup`,{n:t})}),I&&(0,E.jsx)(a,{tone:N(I.state),children:_(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(n.strategy===`weighted`||n.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(o,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&n.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:g(`tokens.pool.tier`),value:String(e.tier),onChange:e=>f({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:g(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:g(`tokens.directAccount`),value:e.accountId??``,onChange:e=>f({accountId:e||null}),options:[{value:``,label:g(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(s,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(w,{className:`size-3.5`}),"aria-label":g(`tokens.pool.remove`,{provider:j}),title:g(`tokens.pool.remove`,{provider:j}),onClick:p})]})]})}export{P as a,k as i,N as n,O as r,F as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$r as e,$t as t,Ar as n,Ea as r,H as i,J as a,Q as o,Sr as s,Ta as c,X as l,Y as u,_ as d,c as f,d as p,di as m,ka as h,l as g,mt as _,n as v,p as y,q as b,qr as x,r as S,rr as C,s as w,sn as T,st as E,t as D,v as O,yr as ee,yt as k}from"./alert-BhYHbQ5M.js";import{a as A,gt as j,i as M,n as te,o as N,r as P}from"./overlays-CF55BHOs.js";import{t as ne}from"./ellipsis-DhvUvMq3.js";import{t as re}from"./pencil-BjMGSY_u.js";import{t as ie}from"./power-zBXM8vYz.js";import{t as ae}from"./rotate-ccw-Omdd6cJU.js";import{B as F,I as oe,N as I,R as L,V as se,Y as R,_ as z,h as B,s as V,y as H}from"./index-XVK9epgF.js";import{a as ce,i as U,n as W,r as G,t as K}from"./TokenPoolEditor-BITgITLH.js";var q={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};q.node;var le=k(q),J={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`}]]};J.node;var ue=k(J),Y=h(r(),1),X=c();function de(){let{t}=E(),r=x(),i=n(),a=e(),o=a.data?.state===`connected`?a.data.publicUrl:null,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null);return(0,X.jsxs)(B,{title:t(`nav.tokens`),subtitle:t(`tokens.subtitle`),actions:(0,X.jsx)(S,{variant:`primary`,icon:(0,X.jsx)(L,{className:`size-3.5`}),onClick:()=>c(!0),children:t(`tokens.add`)}),children:[(0,X.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[i.data&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.jsx)(`p`,{children:t(`tokens.directHint`,{url:`${i.data.gatewayBaseUrl}/v1`})}),(0,X.jsx)(`p`,{className:`selectable`,children:t(`tokens.selfServiceHint`,{url:i.data.gatewayBaseUrl})}),o&&(0,X.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:t(`tokens.remoteHint`,{url:`${o}/v1`,key:`${o}/key`})})]}),r.isLoading&&(0,X.jsx)(O,{lines:4}),r.isError&&(0,X.jsx)(D,{tone:`danger`,title:t(`common.error`),children:A(r.error)}),r.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(f,{icon:(0,X.jsx)(F,{className:`size-6`}),title:t(`tokens.empty`)})}),r.data&&r.data.length>0&&(0,X.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:r.data.map(e=>(0,X.jsx)(fe,{token:e,defaultOpen:r.data.length===1,onEdit:()=>u(e)},e.id))})]}),(0,X.jsx)(_e,{open:s,onOpenChange:c}),(0,X.jsx)(ve,{token:l,onClose:()=>u(null)})]})}function fe({token:e,defaultOpen:t,onEdit:r}){let{t:c,locale:l}=E(),{toast:d,confirm:f}=N(),p=C(),h=n(),g=s(),y=m(),b=ee(),x=T(),[D,O]=(0,Y.useState)(t),k=(p.data??[]).find(t=>t.id===e.providerId),M=ce(),P=`token-detail-${e.id}`,F=(e,t)=>{d(t,`success`),e.skipped.length>0&&d(c(`tokens.skipped`,{clients:e.skipped.map(e=>z[e]?.name??e).join(`, `)}),`error`)},L=()=>g.mutate(e.id,{onSuccess:async({token:e})=>{await j.copy(e)?d(c(`tokens.copied`)):d(c(`tokens.copyFailed`),`error`)},onError:e=>d(A(e),`error`)}),B=async()=>{let e=h.data?.gatewayBaseUrl;e&&(await j.copy(`${e}/v1`)?d(c(`tokens.urlCopied`)):d(c(`tokens.copyFailed`),`error`))},V=async()=>{(!e.enabled||await f({title:c(`tokens.disableConfirm`,{name:e.name}),detail:c(`tokens.disableDetail`),confirmLabel:c(`tokens.disable`),destructive:!0}))&&y.mutate({id:e.id,enabled:!e.enabled},{onError:e=>d(A(e),`error`)})},U=async()=>{await f({title:c(`tokens.resetConfirm`,{name:e.name}),detail:c(`tokens.resetDetail`),confirmLabel:c(`tokens.reset`),destructive:!0})&&b.mutate(e.id,{onSuccess:e=>F(e,c(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>d(A(e),`error`)})},G=async()=>{await f({title:c(`tokens.deleteConfirm`,{name:e.name}),detail:c(`tokens.deleteDetail`),confirmLabel:c(`common.delete`),destructive:!0})&&x.mutate(e.id,{onSuccess:t=>F(t,c(`tokens.deleted`,{name:e.name})),onError:e=>d(A(e),`error`)})},K=e.lastUsedAt?i(e.lastUsedAt,l):c(`tokens.neverUsed`);return(0,X.jsxs)(`article`,{children:[(0,X.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,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,X.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":D,"aria-controls":P,"aria-label":c(`tokens.details`),onClick:e=>{e.stopPropagation(),O(e=>!e)},children:(0,X.jsx)(se,{className:`size-4 transition-transform ${D?`rotate-90`:``}`})}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,X.jsx)(v,{tone:`accent`,children:c(`tokens.default`)}),!e.enabled&&(0,X.jsx)(v,{tone:`orange`,children:c(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,X.jsx)(v,{tone:`orange`,children:c(`tokens.limitExhausted`)}),e.pool&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,X.jsx)(v,{children:c(`tokens.pool.summary`,{count:e.pool.members.length,strategy:c(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,X.jsx)(w,{tone:W(e.health.state)},e.providerId))]})]}),(0,X.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,X.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(_,{className:`size-3.5`}),"aria-label":c(`tokens.copy`),title:c(`tokens.copy`),loading:g.isPending,onClick:L}),(0,X.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ue,{className:`size-3.5`}),"aria-label":c(`tokens.copyUrl`),title:c(`tokens.copyUrl`),disabled:!h.data,onClick:()=>void B()})]})]})]}),(0,X.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>z[e]?.name??e).join(`, `)||c(`tokens.noClients`),children:e.clients.length===0?(0,X.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,X.jsx)(H,{kind:e,size:16},e))}),(0,X.jsx)(Z,{label:c(`tokens.today`),value:o(e.today.costUsd),context:c(`tokens.requestsContext`,{count:u(e.today.requests)})}),(0,X.jsx)(Z,{label:c(`tokens.total`),value:o(e.total.costUsd),context:`${u(e.total.totalTokens,!0)} Token`}),(0,X.jsx)(Z,{label:c(`tokens.lastUsedTitle`),value:e.lastUsedAt?a(e.lastUsedAt,l):`—`,context:e.lastUsedAt?``:c(`tokens.neverUsed`),title:K}),(0,X.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,X.jsx)(te,{label:c(`common.more`),icon:(0,X.jsx)(ne,{className:`size-4`}),items:[{id:`settings`,label:c(`tokens.settings`),icon:(0,X.jsx)(re,{className:`size-3.5`}),onSelect:r},{id:`toggle`,label:e.enabled?c(`tokens.disable`):c(`tokens.enable`),icon:(0,X.jsx)(ie,{className:`size-3.5`}),onSelect:()=>void V()},{id:`reset`,label:c(`tokens.reset`),icon:(0,X.jsx)(ae,{className:`size-3.5`}),onSelect:()=>void U()},...e.isDefault?[]:[{id:`delete`,label:c(`tokens.delete`),icon:(0,X.jsx)(I,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void G()}]]})})]}),D&&(0,X.jsxs)(`div`,{id:P,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,X.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.clients`)}),(0,X.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?c(`tokens.noClients`):e.clients.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(H,{kind:e,size:14}),z[e]?.name??e]},e))})]}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?c(`tokens.pool.title`):c(`tokens.directProvider`)}),e.pool?(0,X.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,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:M(e.health),children:[(0,X.jsx)(w,{tone:W(e.health.state)}),(p.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,X.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:k?.name??(e.providerId?e.providerId:c(`tokens.directNone`))})]}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.allowedClients`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?c(`tokens.allowedClientsAny`):e.allowedClients.length===0?c(`tokens.directOnly`):e.allowedClients.map(e=>z[e]?.name??e).join(`, `)})]}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:c(`tokens.lastUsedTitle`)}),(0,X.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:K})]})]}),(0,X.jsx)(pe,{token:e}),(0,X.jsx)(he,{today:e.today,total:e.total}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,X.jsx)(R,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,X.jsx)(S,{size:`sm`,icon:(0,X.jsx)(le,{className:`size-3.5`}),children:c(`tokens.detail.open`)})}),(0,X.jsx)(R,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,X.jsx)(S,{size:`sm`,icon:(0,X.jsx)(oe,{className:`size-3.5`}),children:c(`tokens.detail.viewLogs`)})})]})]})]})}function pe({token:e}){let{t}=E(),n=e.limits?.rpm;return(0,X.jsxs)(`div`,{className:`mt-3`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,X.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,X.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,X.jsx)(me,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,X.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,X.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function me({usage:e}){let{t,locale:n}=E(),r=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,a=t=>e.metric===`cost`?o(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,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,X.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:r}),(0,X.jsx)(`span`,{className:`num`,children:t(`tokens.limitUsed`,{used:a(e.used),limit:a(e.limit)})})]}),(0,X.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,X.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:t(`tokens.limitResets`,{time:i(e.resetsAt,n)})})]})}function Z({label:e,value:t,context:n,title:r}){return(0,X.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,X.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,X.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,X.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function he({today:e,total:t}){let{t:n}=E(),r=[[n(`tokens.today`),e],[n(`tokens.total`),t]],i=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,a=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,X.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,X.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,X.jsx)(`th`,{className:`${i} text-left`}),(0,X.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,X.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,X.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,X.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,X.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,X.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,X.jsx)(`tbody`,{children:r.map(([e,t])=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,X.jsx)(`td`,{className:`${a} font-semibold selectable`,children:o(t.costUsd)}),(0,X.jsx)(`td`,{className:a,children:u(t.requests)}),(0,X.jsx)(`td`,{className:a,children:u(t.totalTokens,!0)}),(0,X.jsxs)(`td`,{className:`${a} text-[var(--text-secondary)]`,children:[u(t.inputTokens,!0),` / `,u(t.outputTokens,!0)]}),(0,X.jsx)(`td`,{className:a,title:n(`usage.cacheAmounts`,{read:u(t.cacheReadTokens,!0),write:u(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:b(t.cacheHitRate)}),(0,X.jsx)(`td`,{className:a,children:t.tps==null?`—`:l(t.tps)})]},e))})]})})}function ge(){let{t:e}=E(),t=(C().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function _e({open:e,onOpenChange:n}){let{t:r}=E(),{toast:i}=N(),a=t(),{options:o}=ge(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``);return(0,Y.useEffect)(()=>{e&&(c(``),u(``))},[e]),(0,X.jsx)(M,{open:e,onOpenChange:n,title:r(`tokens.createTitle`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{onClick:()=>n(!1),children:r(`common.cancel`)}),(0,X.jsx)(S,{variant:`primary`,disabled:!s.trim(),loading:a.isPending,onClick:()=>a.mutate({name:s.trim(),providerId:l||null},{onSuccess:e=>{n(!1),i(r(`tokens.created`,{name:e.name}),`success`)},onError:e=>i(A(e),`error`)}),children:r(`common.create`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(g,{label:r(`tokens.name`),children:(0,X.jsx)(p,{value:s,maxLength:64,placeholder:r(`tokens.namePlaceholder`),onChange:e=>c(e.target.value)})}),(0,X.jsx)(g,{label:r(`tokens.directProvider`),children:(0,X.jsx)(P,{value:l,onChange:u,options:o})})]})})}function ve({token:e,onClose:t}){let{t:n}=E(),{toast:r}=N(),i=m(),a=C(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(null),[u,f]=(0,Y.useState)([]),[h,_]=(0,Y.useState)(null),[v,b]=(0,Y.useState)(`any`),[x,w]=(0,Y.useState)([]),T=new Set(u.map(e=>`${e.metric}:${e.period}`)).size<u.length,D=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,Y.useEffect)(()=>{e&&(s(e.name),l(G(e)),f(e.limits?.budgets.map(e=>({...e}))??[]),_(e.limits?.rpm??null),b(e.allowedClients==null?`any`:`only`),w(e.allowedClients??[]))},[e]),(0,X.jsx)(M,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(S,{variant:`primary`,disabled:!o.trim()||T,loading:i.isPending,onClick:()=>{if(!e)return;let s=u.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),l=s.length>0||h!=null&&h>0?{budgets:s,rpm:h!=null&&h>0?Math.floor(h):null}:null;i.mutate({id:e.id,name:o.trim(),...c?{pool:U(c,a.data??[])}:{},limits:l,allowedClients:v===`any`?null:x},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(A(e),`error`)})},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(g,{label:n(`tokens.name`),children:(0,X.jsx)(p,{value:o,maxLength:64,onChange:e=>s(e.target.value)})}),(0,X.jsx)(g,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:c&&(0,X.jsx)(K,{draft:c,onChange:l,providers:a.data??[],health:D})}),(0,X.jsx)(g,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:T?n(`tokens.limitDuplicate`):void 0,children:(0,X.jsx)(ye,{budgets:u,onChange:f})}),(0,X.jsx)(g,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,X.jsx)(y,{value:h,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:_})}),(0,X.jsx)(g,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:v,onChange:b,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),v===`only`&&(0,X.jsx)(V,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(z),...x])].map(e=>({value:e,label:z[e]?.name??e})),value:x,onValueChange:e=>w(e)})]})})]})})}var Q=[`cost`,`requests`,`tokens`],$=[`day`,`week`,`month`,`total`];function ye({budgets:e,onChange:t}){let{t:n}=E(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=Q.flatMap(e=>$.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,X.jsx)(P,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:Q.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,X.jsx)(P,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:$.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,X.jsx)(y,{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,X.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(I,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,X.jsx)(`div`,{children:(0,X.jsx)(S,{size:`sm`,icon:(0,X.jsx)(L,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{de as TokensPage};
|