@aidotnet/server-darwin-arm64 0.11.1 → 0.11.4
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/libe_sqlite3.dylib +0 -0
- package/bin/wwwroot/assets/ClientsPage-TqHAFA25.js +9 -0
- package/bin/wwwroot/assets/KeyPage-CNp0pPiQ.js +1 -0
- package/bin/wwwroot/assets/ModelDetailPage-B61Xlxp4.js +1 -0
- package/bin/wwwroot/assets/ModelsPage-KeUV0kEe.js +1 -0
- package/bin/wwwroot/assets/PluginsPage-D-Idp7rX.js +2 -0
- package/bin/wwwroot/assets/PrivacyPage-C3YpZHD5.js +1 -0
- package/bin/wwwroot/assets/ProviderDetailPage-CeXebQjO.js +3 -0
- package/bin/wwwroot/assets/ProvidersPage-Ca7aGIQg.js +2 -0
- package/bin/wwwroot/assets/SettingsPage-CpD7hQB4.js +2 -0
- package/bin/wwwroot/assets/SmartRoutingPage-d7VpOJbs.js +2 -0
- package/bin/wwwroot/assets/TokenDetailPage-TJa2J-N_.js +1 -0
- package/bin/wwwroot/assets/{TokenPoolEditor-BITgITLH.js → TokenPoolEditor-D1m8Jjy3.js} +1 -1
- package/bin/wwwroot/assets/TokensPage-CnAympZG.js +1 -0
- package/bin/wwwroot/assets/TracesPage-D8KIKCul.js +7 -0
- package/bin/wwwroot/assets/{TrayPanelPage-BwaSGRbR.js → TrayPanelPage-DaxLSbIE.js} +1 -1
- package/bin/wwwroot/assets/{TrayPanelView-CAF6qwfK.js → TrayPanelView-D6QJsy-r.js} +1 -1
- package/bin/wwwroot/assets/alert-BadMvy1R.js +15 -0
- package/bin/wwwroot/assets/{arrow-down-CHVkKqVB.js → arrow-down-Cv-6a_e3.js} +1 -1
- package/bin/wwwroot/assets/{arrow-left-ByzgpjKh.js → arrow-left-dS7bcLEo.js} +1 -1
- package/bin/wwwroot/assets/{checkbox-B_oHm90b.js → checkbox-CaaP8Tue.js} +1 -1
- package/bin/wwwroot/assets/{cloud-download-DEv0Zu87.js → cloud-download-CpuzW7lP.js} +1 -1
- package/bin/wwwroot/assets/confirm-morph-XE52Kxj6.js +1 -0
- package/bin/wwwroot/assets/{download-DXwZa8b6.js → download-DhWYUpCm.js} +1 -1
- package/bin/wwwroot/assets/{ellipsis-DhvUvMq3.js → ellipsis-DhDdch5j.js} +1 -1
- package/bin/wwwroot/assets/{external-link-D9cY56rt.js → external-link-D3yhOoFs.js} +1 -1
- package/bin/wwwroot/assets/{folder-open-Dt-7Rdbw.js → folder-open-Bggy7qkR.js} +1 -1
- package/bin/wwwroot/assets/index-BUGU_FDT.js +17 -0
- package/bin/wwwroot/assets/{index-Dt3DJ3Cx.css → index-BUzE8kPN.css} +1 -1
- package/bin/wwwroot/assets/{log-out-wpGBd0OK.js → log-out-DV1PNbkn.js} +1 -1
- package/bin/wwwroot/assets/minus-DxRH0N_9.js +1 -0
- package/bin/wwwroot/assets/overlays-D-LaJu2w.js +41 -0
- package/bin/wwwroot/assets/{pencil-BjMGSY_u.js → pencil-TH_5IGXD.js} +1 -1
- package/bin/wwwroot/assets/{power-zBXM8vYz.js → power-DF2viDB7.js} +1 -1
- package/bin/wwwroot/assets/radio-cards-Geph_wiF.js +1 -0
- package/bin/wwwroot/assets/{rotate-ccw-Omdd6cJU.js → rotate-ccw-BxvPRjim.js} +1 -1
- package/bin/wwwroot/assets/{sortable.esm-CTCQ-9IR.js → sortable.esm-DYxWT0KU.js} +1 -1
- package/bin/wwwroot/assets/tkcode-COOcwqQh.png +0 -0
- package/bin/wwwroot/index.html +4 -4
- package/package.json +1 -1
- package/bin/wwwroot/assets/ClientsPage-C-x5kPpG.js +0 -9
- package/bin/wwwroot/assets/KeyPage-CxvUUC6Z.js +0 -1
- package/bin/wwwroot/assets/ModelDetailPage-CQol60ci.js +0 -1
- package/bin/wwwroot/assets/ModelsPage-Bp1-Rhad.js +0 -1
- package/bin/wwwroot/assets/PluginsPage-YPDqytJ6.js +0 -2
- package/bin/wwwroot/assets/PrivacyPage-Co1ffmVU.js +0 -1
- package/bin/wwwroot/assets/ProviderDetailPage-CacRreeZ.js +0 -3
- package/bin/wwwroot/assets/ProvidersPage-DSwvae35.js +0 -2
- package/bin/wwwroot/assets/SettingsPage-CvIE8pBq.js +0 -2
- package/bin/wwwroot/assets/TokenDetailPage-w1XONN5-.js +0 -1
- package/bin/wwwroot/assets/TokensPage-CiL0dLkj.js +0 -1
- package/bin/wwwroot/assets/TracesPage-zcvvDcj3.js +0 -7
- package/bin/wwwroot/assets/alert-BhYHbQ5M.js +0 -15
- package/bin/wwwroot/assets/confirm-morph-RDk31i1j.js +0 -1
- package/bin/wwwroot/assets/index-XVK9epgF.js +0 -17
- package/bin/wwwroot/assets/minus-3JX68qL9.js +0 -1
- package/bin/wwwroot/assets/overlays-CF55BHOs.js +0 -41
- package/bin/wwwroot/assets/radio-cards-BVdDbnT-.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Bi as e,Cn as t,Dr as n,E as r,Fa as i,G as a,Hi as o,Ia as s,Kr as c,Ma as l,Na as u,Q as d,Ti as f,Ui as p,Vi as m,Wi as h,Xn as g,Xr as _,Y as v,_ as y,b,c as x,ct as S,d as C,di as w,dt as T,en as E,f as D,gn as O,h as k,i as A,ja as j,kt as M,l as N,m as P,n as F,or as I,ot as L,p as R,qr as ee,r as z,rr as te,s as B,sr as V,t as H,u as U,v as ne,w as re,wn as W,xt as G,y as ie,yt as ae,zi as K}from"./alert-BadMvy1R.js";import{A as oe,C as se,D as ce,E as le,O as ue,T as de,X as fe,a as q,ct as pe,dt as me,ft as he,i as ge,k as _e,mt as ve,o as ye,pt as be,r as xe,ut as Se,w as Ce}from"./overlays-D-LaJu2w.js";import{t as we}from"./arrow-left-dS7bcLEo.js";import{t as Te}from"./download-DhWYUpCm.js";import{n as Ee,t as De}from"./radio-cards-Geph_wiF.js";import{I as Oe,Q as ke,R as Ae,S as je,Y as Me,_ as Ne,b as Pe,et as Fe,g as Ie,h as Le,j as Re,k as ze,nt as Be,tt as Ve,x as He,z as Ue}from"./index-BUGU_FDT.js";import{t as We}from"./checkbox-CaaP8Tue.js";var J=s(u(),1);function Ge(e,t,n){(0,J.useInsertionEffect)(()=>e.on(t,n),[e,t,n])}var Ke={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`]};Ke.node;var qe=G(Ke),Je={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`}]]};Je.node;var Ye=G(Je),Xe={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Xe.node;var Ze=G(Xe),Y={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`},X=l(),{blur:Qe,duration:Z,ease:$e,spring:et,stagger:tt}=r,nt={...et.smooth,visualDuration:.3},rt={...et.smooth,visualDuration:.26},it=300,at={duration:Z.instant},ot=1.04,st={duration:Z.considered*2,ease:[...$e.standard]},ct={duration:Z.considered,ease:[...$e.standard]},lt={delay:Z.instant,duration:Z.standard,ease:[...$e.enter]},ut={delay:Z.instant,duration:Z.fast,ease:[...$e.enter]},dt={enter:{},center:{},exit:{opacity:0,y:`-.3em`,filter:`blur(${Qe.subtle}px)`,transition:{duration:Z.fast,ease:[...$e.standard]}}},ft={enter:{opacity:0,y:`.3em`,filter:`blur(${Qe.soft}px)`},center:e=>({opacity:1,y:0,filter:`blur(0px)`,transition:{duration:Z.standard,ease:[...$e.enter],delay:e*tt.word}})};function pt({text:e,reduced:t}){return(0,X.jsxs)(`span`,{className:Y.status,role:`status`,children:[(0,X.jsx)(`span`,{className:Y.srOnly,children:e}),(0,X.jsx)(`span`,{className:Y.roll,"aria-hidden":`true`,children:(0,X.jsx)(h,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(K.span,{className:Y.line,variants:dt,initial:!t&&`enter`,animate:`center`,exit:t?void 0:`exit`,children:e.split(/(\s+)/).map((e,t)=>(0,X.jsx)(K.span,{className:Y.word,custom:t/2,variants:ft,children:e},t))},e)})})]})}function mt(e,t){let n=parseFloat(t);if(Number.isFinite(n))return t.trim().endsWith(`rem`)?n*parseFloat(getComputedStyle(e.ownerDocument.documentElement).fontSize):n}function ht({title:e,description:t,media:n,action:r,avatar:i,meta:a,status:o,details:s,open:c,defaultOpen:l=!1,onOpenChange:u,children:d,className:f,style:g,..._}){let v=m()??!1,y=(0,J.useId)(),b=(0,J.useRef)(null),x=(0,J.useRef)(null),[S,C]=(0,J.useState)(l),[w,E]=(0,J.useState)(!1),[D,O]=(0,J.useState)({}),[k,A]=(0,J.useState)(null),j=s?c??S:!1,M=!!s&&!v,N=!j&&k!==null,P=!!t,F=(0,J.useCallback)(e=>{c===void 0&&C(e),u?.(e)},[c,u]);(0,J.useEffect)(()=>{let e=b.current,t=x.current;if(!M||!e||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{let n=getComputedStyle(e),r=mt(e,n.borderTopLeftRadius),i=mt(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,J.useRef)(j);(0,J.useLayoutEffect)(()=>{let e=I.current&&!j;I.current=j;let t=b.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,J.useEffect)(()=>{if(!N)return;let e=window.setTimeout(()=>A(null),it);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`?rt:nt}}:{},R=e=>i||a||o||r?(0,X.jsxs)(`div`,{className:Y.footer,children:[i||a||o?(0,X.jsxs)(K.div,{className:Y.byline,...L(`byline`,e,`position`),children:[i?(0,X.jsx)(`span`,{className:Y.avatar,children:i}):null,(0,X.jsxs)(`span`,{className:Y.bylineText,children:[a?(0,X.jsx)(`span`,{className:Y.meta,children:a}):null,o?(0,X.jsx)(pt,{text:o,reduced:v}):null]})]}):null,r?(0,X.jsx)(K.div,{className:Y.action,...L(`action`,e,`position`),children:r}):null]}):null,ee=(0,X.jsxs)(K.article,{..._,ref:b,className:[Y.card,f].filter(Boolean).join(` `),style:{...g,borderRadius:D.card??g?.borderRadius},"data-hover":w||void 0,whileHover:v?void 0:{y:-2},onHoverStart:()=>E(!0),onHoverEnd:()=>E(!1),...L(`card`,`card`),transition:{default:et.snappy,layout:rt},children:[n?(0,X.jsx)(K.div,{className:Y.media,...L(`media`,`card`),children:(0,X.jsx)(K.div,{className:Y.zoom,initial:!1,animate:{scale:w&&!v?ot:1},transition:w?st:ct,children:n})}):null,(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(K.h3,{className:Y.title,...L(`title`,`card`),children:s?(0,X.jsx)(oe,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:Y.trigger,children:e})}):e}),t?(0,X.jsx)(K.p,{ref:x,className:Y.description,...L(`description`,`card`,`position`),children:t}):null,d,R(`card`)]})]});return s?(0,X.jsx)(se,{open:j,onOpenChange:F,children:(0,X.jsxs)(p,{id:y,children:[ee,(0,X.jsx)(h,{children:(j||N)&&(0,X.jsxs)(ue,{forceMount:!0,children:[(0,X.jsx)(h,{children:j&&(0,X.jsx)(ce,{asChild:!0,forceMount:!0,children:(0,X.jsx)(K.div,{className:Y.overlay,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:v?at:{duration:Z.exit,ease:[...$e.standard]}},transition:v?at:{duration:Z.standard,ease:[...$e.enter]}})},`overlay`)}),(0,X.jsx)(de,{asChild:!0,forceMount:!0,...t?{}:{"aria-describedby":void 0},children:(0,X.jsxs)(K.div,{className:Y.panel,"data-framer-portal-id":y,"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?rt:nt,borderRadius:N?rt:nt},exit:{opacity:0,transition:{duration:0}}}:{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:at},transition:at},children:[n?(0,X.jsx)(K.div,{className:Y.media,...L(`media`,`panel`),children:(0,X.jsx)(K.div,{className:Y.zoom,initial:{scale:w&&!v?ot:1},animate:{scale:1},transition:nt,children:n})}):null,(0,X.jsx)(K.span,{className:Y.closeSlot,initial:v?{opacity:0}:{opacity:0,scale:.9},animate:N?{opacity:0,scale:.9}:{opacity:1,scale:1},transition:N||v?at:ut,children:(0,X.jsx)(Ce,{asChild:!0,children:(0,X.jsx)(K.button,{type:`button`,className:Y.close,"aria-label":`Close quick look`,whileTap:v?void 0:{scale:.94},transition:et.snappy,children:(0,X.jsx)(T,{width:16,height:16,strokeWidth:1.75,"aria-hidden":`true`})})})}),(0,X.jsxs)(`div`,{className:Y.content,children:[(0,X.jsx)(_e,{asChild:!0,children:(0,X.jsx)(K.h2,{className:Y.title,...L(`title`,`panel`),children:e})}),t?(0,X.jsx)(le,{asChild:!0,children:(0,X.jsx)(K.p,{className:Y.description,...L(`description`,`panel`,`position`),children:t})}):null,d,R(`panel`),(0,X.jsx)(K.div,{className:Y.details,initial:!v&&{opacity:0,y:6},animate:N?{opacity:0,y:0}:{opacity:1,y:0},exit:{opacity:0,transition:at},transition:N||v?at:lt,children:s})]})]})})]},`quick-look`)})]})}):ee}var Q={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`},gt={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${r.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.standard,ease:[...r.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${r.blur.subtle}px)`,transition:{duration:r.duration.fast,ease:[...r.ease.standard]}})},_t={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:r.duration.instant}}},vt=e=>Number(e.replace(/,/g,``).replace(/−/g,`-`).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN),yt=new Intl.NumberFormat(`en-US`),bt={duration:r.duration.considered*1.75,ease:[...r.ease.inOut]},xt={duration:r.duration.fast,ease:[...r.ease.standard]};function St(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 Ct({text:t,direction:n,whole:i=!1,morph:a=!1,tone:s}){let c=!!m(),l=(0,J.useRef)(null),u=o(`auto`),[d,f]=(0,J.useState)({text:t,direction:1});d.text!==t&&f({text:t,direction:n??(vt(t)<vt(d.text)?-1:1)}),(0,J.useEffect)(()=>{let t=l.current;if(!t||typeof ResizeObserver>`u`)return;let n=null,i=new ResizeObserver(([i])=>{if(!i)return;let a=i.borderBoxSize?.[0]?.inlineSize??t.offsetWidth;n!==null&&n!==t.textContent&&!c?e(u,a,r.spring.morph):u.jump(a),n=t.textContent});return i.observe(t),()=>i.disconnect()},[a,c,u]);let p=!i&&!/\p{L}/u.test(t),g=c?_t:gt,_=p?`right`:`left`;return(0,X.jsxs)(K.span,{className:Q.roll,"data-end":p||void 0,"data-whole":i||void 0,style:a?{width:u}:void 0,children:[a&&(0,X.jsx)(`span`,{ref:l,className:Q.sizer,"aria-hidden":`true`,children:t}),(0,X.jsx)(`span`,{className:Q.track,children:(0,X.jsx)(h,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:_,children:St(t,i).map(e=>(0,X.jsx)(K.span,{className:Q.slot,custom:d.direction,variants:g,initial:`hidden`,animate:`shown`,exit:`gone`,children:(0,X.jsx)(h,{mode:`popLayout`,initial:!1,custom:d.direction,anchorX:_,children:(0,X.jsx)(K.span,{className:s?`${Q.glyph} ${s}`:Q.glyph,custom:d.direction,variants:g,initial:`hidden`,animate:`shown`,exit:`gone`,children:e.text},`${s??``}${e.key}`)})},e.slot))})})]})}var wt=5,Tt=1.25,Et=Array.from({length:161},(e,t)=>t/160);function Dt(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 Ot(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 kt(e,t,n,r){let i=e=>wt+(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(Ot(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 At(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 jt({data:t,label:n,value:i,change:a,tone:s=`accent`,width:c=160,height:l=52,labels:u,formatValue:d,area:f=!0,interactive:p=!0}){let h=t.length>1?t:[t[0]??0,t[0]??0],g=h.length-1,_=h.join(`,`),v=(0,J.useMemo)(()=>Dt(_.split(`,`).map(Number)),[_]),y=`${n}: ${i??h[g]}. ${a??``}`.trim(),b=`sparkline${(0,J.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,x=(0,J.useRef)(null),S=(0,J.useRef)(null),C=Ve(x,{once:!0,amount:.5}),w=!!m(),[T,E]=(0,J.useState)({w:c,h:l}),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(!1),j=D===null?null:Math.min(D,g),[M,N]=(0,J.useState)({index:j,direction:1});M.index!==j&&N({index:j,direction:j===null||M.index===null?1:Math.sign(j-M.index)||1});let[P]=(0,J.useState)(()=>kt(v,c,l,1)),F=(0,J.useRef)(v),I=(0,J.useRef)(T),L=o(0),R=o(1),ee=o(P.line),z=o(P.trail),te=o(P.fill),B=o(P.dot),V=o(P.cx),H=o(P.cx+Tt+16),U=o(P.cx+Tt),ne=o(0),re=Be(L,e=>+(e>.001)),W=(0,J.useCallback)(()=>{let{w:e,h:t}=I.current,n=L.get(),r=kt(F.current,e,t,R.get());ee.set(r.line),z.set(r.trail),te.set(r.fill),B.set(r.dot),V.set(r.cx),H.set(r.cx+Tt+16),U.set(r.cx+Tt),ne.set(n>=1?e+32:At(r.points,n)+16)},[R,V,U,B,L,te,ee,H,ne,z]);Ge(R,`change`,W),Ge(L,`change`,W),(0,J.useLayoutEffect)(()=>{let e=S.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth;t&&E(e=>Math.abs(e.w-t)<.5?e:{w:t,h:t*l/c})});return t.observe(e),()=>t.disconnect()},[l,c]),(0,J.useLayoutEffect)(()=>{I.current=T,W()},[T,W]),(0,J.useEffect)(()=>{if(w){L.jump(1);let e=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(e)}if(!C)return;let t=e(L,1,{...bt,onComplete:()=>A(!0)});return()=>t.stop()},[L,C,w]),(0,J.useEffect)(()=>{let t=F.current;if(t===v)return;if(w){F.current=v,W();return}let n=[...new Set([...Et,...v.map(([e])=>e)])].sort((e,t)=>e-t),i=n.map(e=>Ot(t,e)),a=n.map(e=>Ot(v,e)),o=e(0,1,{...r.spring.smooth,onUpdate:e=>{F.current=n.map((t,n)=>[t,i[n]+(a[n]-i[n])*e]),W()},onComplete:()=>{F.current=v,W()}});return()=>o.stop()},[W,w,v]),(0,J.useEffect)(()=>{let t=j===null?1:j/g;if(w){R.jump(t);return}let n=e(R,t,r.spring.snappy);return()=>n.stop()},[R,j,g,w]);let G=j!==null,ie=(e=>d?d(h[e],e):yt.format(h[e]))(j??g),ae=u?.[j??g],oe=i===void 0?void 0:G?ie:i,se=j===null?a??``:i===void 0?[ie,ae].filter(Boolean).join(` · `):ae??`${j+1} of ${g+1}`,ce=e=>{let t=S.current?.getBoundingClientRect();return t?.width?Math.max(0,Math.min(g,Math.round((e-t.left)/t.width*g))):g},le=p?{role:`slider`,tabIndex:0,"aria-label":`${n}, explore values`,"aria-valuemin":1,"aria-valuemax":g+1,"aria-valuenow":(j??g)+1,"aria-valuetext":`${ae??(j===null?`Latest`:`Point ${j+1} of ${g+1}`)}: ${ie}`,onPointerDown:e=>O(ce(e.clientX)),onPointerMove:e=>{(e.pointerType===`mouse`||e.buttons)&&O(ce(e.clientX))},onPointerUp:e=>{e.pointerType!==`mouse`&&O(null)},onPointerLeave:()=>O(null),onPointerCancel:()=>O(null),onBlur:()=>O(null),onKeyDown:e=>{if(e.key===`Escape`&&G){e.preventDefault(),O(null);return}let t=j??g,n=Math.max(1,Math.round((g+1)/6)),r={ArrowLeft:t-1,ArrowDown:t-1,ArrowRight:t+1,ArrowUp:t+1,PageDown:t-n,PageUp:t+n,Home:0,End:g}[e.key];r!==void 0&&(e.preventDefault(),O(Math.max(0,Math.min(g,r))))}}:{};return(0,X.jsxs)(`figure`,{ref:x,className:Q.figure,"aria-label":y,children:[(0,X.jsxs)(`figcaption`,{className:Q.caption,children:[(0,X.jsx)(`span`,{className:Q.label,children:(0,X.jsx)(Ct,{text:n,whole:!0})}),oe!==void 0&&(0,X.jsx)(`strong`,{children:(0,X.jsx)(Ct,{text:oe,morph:!0})}),(0,X.jsx)(`small`,{className:Q[s],children:(0,X.jsx)(Ct,{text:se,direction:G?M.direction:void 0,tone:G?Q.point:void 0,morph:!0})})]}),(0,X.jsx)(`div`,{ref:S,className:Q.plot,"data-interactive":p||void 0,...le,children:(0,X.jsxs)(`svg`,{className:Q.chart,viewBox:`0 0 ${T.w} ${T.h}`,"aria-hidden":`true`,focusable:`false`,children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsx)(`clipPath`,{id:`${b}-lit`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(K.rect,{x:-16,y:-16,width:H,height:T.h+32})}),(0,X.jsx)(`clipPath`,{id:`${b}-dim`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(K.rect,{x:U,y:-16,width:T.w+32,height:T.h+32})}),(0,X.jsx)(`clipPath`,{id:`${b}-fill`,clipPathUnits:`userSpaceOnUse`,children:(0,X.jsx)(K.rect,{x:-16,y:-16,width:ne,height:T.h+32})})]}),f&&(0,X.jsx)(K.path,{className:`${Q.area} ${Q[s]}`,d:te,clipPath:`url(#${b}-fill)`}),(0,X.jsx)(`line`,{className:Q.baseline,x1:`0`,y1:T.h-.5,x2:T.w,y2:T.h-.5}),(0,X.jsx)(K.path,{className:Q.trail,d:z,clipPath:`url(#${b}-dim)`,initial:!1,animate:{opacity:G&&k?1:0},transition:w?{duration:0}:xt}),(0,X.jsx)(K.polyline,{className:[Q.line,Q[s]].join(` `),points:ee,clipPath:`url(#${b}-lit)`,style:{pathLength:L,opacity:re}}),(0,X.jsx)(K.line,{className:Q.cursor,x1:V,x2:V,y1:0,y2:T.h,initial:!1,animate:{opacity:+!!G},transition:w?{duration:0}:xt}),(0,X.jsx)(K.polyline,{className:[Q.end,Q[s]].join(` `),points:B,initial:!1,animate:{opacity:+!!k,strokeWidth:k?G?10:7:0},transition:w?{duration:0}:{opacity:xt,strokeWidth:r.spring.snappy},fill:`none`,strokeLinecap:`round`})]})})]})}var $={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`},Mt=e=>`blur(${e}px)`,Nt={duration:0},Pt={duration:r.duration.fast,ease:[...r.ease.standard]},Ft={duration:r.duration.standard,ease:[...r.ease.enter]},It={opacity:0,y:`0.3em`,filter:Mt(r.blur.soft)},Lt={opacity:1,y:0,filter:Mt(0)},Rt={opacity:0,y:`-0.3em`,filter:Mt(r.blur.subtle)},zt={opacity:0,scale:.5,filter:Mt(r.blur.subtle)},Bt={opacity:1,scale:1,filter:Mt(0)};function Vt({text:t,className:n,reduced:i}){let a=(0,J.useRef)(null),s=(0,J.useRef)(0),c=o(`auto`);return(0,J.useLayoutEffect)(()=>{s.current=performance.now()+700},[t]),(0,J.useEffect)(()=>{let t=a.current,n=t?.parentElement;if(!t||!n||typeof ResizeObserver>`u`)return;let o=!1,l=new ResizeObserver(()=>{let n=t.offsetHeight;if(!o||i||performance.now()>s.current){o=!0,c.jump(n);return}e(c,n,r.spring.smooth)});return l.observe(t),()=>l.disconnect()},[c,i]),(0,X.jsx)(K.span,{className:$.slot,style:{height:c},children:(0,X.jsx)(`span`,{ref:a,className:$.slotInner,children:(0,X.jsx)(h,{mode:`popLayout`,initial:!1,children:t?(0,X.jsx)(K.span,{className:n,initial:It,animate:Lt,exit:{...Rt,transition:i?Nt:Pt},transition:i?Nt:Ft,children:t},`${n}:${t}`):null})})})}function Ht({kind:e,number:t,delay:n,reduced:i}){let a=i?Nt:{scale:{...r.spring.snappy,delay:n},opacity:{duration:r.duration.fast,delay:n},filter:{duration:r.duration.fast,delay:n}},o={...zt,transition:i?Nt:Pt},s=i?Nt:{duration:r.duration.standard,ease:r.ease.enter,delay:n+.04};return e===`number`?(0,X.jsx)(K.span,{className:$.glyph,initial:zt,animate:Bt,exit:o,transition:a,children:t}):(0,X.jsx)(K.svg,{className:`${$.glyph} ${$.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,X.jsx)(K.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:s}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(K.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:s}),(0,X.jsx)(K.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:i?Nt:{...r.spring.snappy,delay:n+.16}})]})})}function Ut({number:e,kind:t,current:n,glyphDelay:i,ringDelay:a,reduced:o}){return(0,X.jsxs)(`span`,{className:$.marker,"aria-hidden":`true`,children:[(0,X.jsx)(h,{initial:!1,children:n?(0,X.jsx)(K.span,{className:$.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:o?Nt:Pt},transition:o?Nt:{scale:{...r.spring.snappy,delay:a},opacity:{duration:r.duration.fast,delay:a}}},`ring`):null}),(0,X.jsx)(`span`,{className:$.disc,children:(0,X.jsx)(h,{initial:!1,children:(0,X.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:n=`horizontal`,onStepSelect:i,details:a=`all`,compact:o=!1,label:s=`Progress`,completeLabel:c=`All steps complete`,className:l}){let u=m()??!1,d=e.length,f=Math.min(Math.max(Math.round(t),0),d),[p,h]=(0,J.useState)({to:f,from:f});p.to!==f&&h({to:f,from:p.to});let g=p.from,_=r.stagger.line,v=e=>u?0:f>g?e>=g&&e<f?(e-g)*_:0:e>=f&&e<g?(g-1-e)*_:0,y=u?0:Math.max(0,Math.abs(f-g)-1)*_+.12,b=!!i,x=n===`vertical`,S=f>=d?void 0:e[f];function C(e){let t=!x&&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 w=b?`nav`:`div`,T=[$.root,x?$.vertical:$.horizontal,o?$.compact:``,l].filter(Boolean).join(` `);return(0,X.jsxs)(w,{className:T,"aria-label":s,role:b?void 0:`group`,children:[(0,X.jsx)(`ol`,{className:$.list,style:x?void 0:{gridTemplateColumns:d>1?`repeat(${d-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:b?C:void 0,children:e.map((e,t)=>{let o=t===f,s=e.error?`error`:t<f?`complete`:o?`current`:`upcoming`,c=b&&t<f,l=e.error??(a===`all`||o?e.description:void 0),p=e.error?`error`:t<f?`check`:`number`,m=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ut,{number:t+1,kind:p,current:o,glyphDelay:v(t),ringDelay:y,reduced:u}),(0,X.jsxs)(`span`,{className:$.text,children:[(0,X.jsx)(`span`,{className:$.label,children:e.label}),Wt[s]?(0,X.jsxs)(`span`,{className:$.srOnly,children:[`, `,Wt[s]]}):null,(0,X.jsx)(Vt,{text:l,className:e.error?$.error:$.description,reduced:u})]})]});return(0,X.jsxs)(`li`,{className:$.item,"data-status":s,children:[t<d-1?(0,X.jsx)(`span`,{className:$.connector,"aria-hidden":`true`,children:(0,X.jsx)(K.span,{className:$.fill,initial:!1,animate:x?{scaleY:+(t<f)}:{scaleX:+(t<f)},transition:u?Nt:{...r.spring.smooth,delay:v(t)}},n)}):null,b?(0,X.jsx)(`button`,{type:`button`,className:$.head,"data-clickable":c||void 0,"data-reachable":t<=f||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:m}):(0,X.jsx)(`span`,{className:$.head,"aria-current":o?`step`:void 0,children:m})]},e.id)})}),x?null:(0,X.jsxs)(`span`,{className:$.caption,"aria-hidden":`true`,children:[(0,X.jsx)(Vt,{text:S?.label??c,className:$.captionLabel,reduced:u}),(0,X.jsx)(Vt,{text:S?.error??S?.description,className:S?.error?$.error:$.description,reduced:u})]}),(0,X.jsx)(`span`,{className:$.srOnly,"aria-live":`polite`,children:S?`Step ${f+1} of ${d}: ${S.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:n}){let{t:r}=S(),{toast:i}=ye(),a=W(e),o=t(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(new Set),[d,f]=(0,J.useState)(null);(0,J.useEffect)(()=>{a.data&&u(new Set(a.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(Jt)))},[a.data]),(0,J.useEffect)(()=>{e&&(c(``),f(null))},[e]);let p=s.trim().toLowerCase(),m=e=>!p||e.name.toLowerCase().includes(p)||e.endpoints.some(e=>e.baseUrl.toLowerCase().includes(p)),h=(0,J.useMemo)(()=>(a.data??[]).flatMap(e=>e.items).filter(e=>l.has(Jt(e))&&Yt(e)),[a.data,l]),g=(e,t)=>u(n=>{let r=new Set(n);return t?r.add(Jt(e)):r.delete(Jt(e)),r});return(0,X.jsx)(ge,{open:e,onOpenChange:n,width:680,title:r(`import.title`),description:r(`import.detail`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{icon:(0,X.jsx)(Ae,{className:`size-3.5`}),onClick:()=>void a.refetch(),disabled:a.isFetching||o.isPending,children:r(`import.rescan`)}),(0,X.jsx)(z,{variant:`primary`,disabled:h.length===0||o.isPending,onClick:()=>{f(null),o.mutate(h.map(e=>({source:e.source,ref:e.ref})),{onSuccess:e=>{let t=e.skipped.length;i(t>0?r(`import.doneSkipped`,{count:e.added.length,skipped:t}):r(`import.done`,{count:e.added.length})),n(!1)},onError:e=>{f(q(e)),a.refetch()}})},children:r(`import.selected`,{count:h.length})})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(k,{value:s,onChange:c,placeholder:r(`import.search`)}),d&&(0,X.jsx)(H,{tone:`danger`,title:r(`common.error`),children:d}),a.isLoading&&(0,X.jsx)(ne,{lines:3}),a.isError&&(0,X.jsx)(H,{tone:`danger`,title:r(`common.error`),children:q(a.error)}),(0,X.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:a.data?.map(e=>(0,X.jsx)(Qt,{source:e,matches:m,selected:l,onToggle:g,filtering:p.length>0},e.id))}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`import.footnote`)})]})})}function Qt({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=S(),o=e.items.filter(t);return(0,X.jsxs)(`section`,{"aria-label":e.name,children:[(0,X.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,X.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,X.jsx)(H,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,X.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,X.jsx)($t,{c:e,checked:n.has(Jt(e)),onToggle:t=>r(e,t)},Jt(e)))}):(0,X.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}=S(),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,X.jsxs)(`li`,{className:L(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,X.jsx)(We,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,X.jsx)(F,{tone:qt[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),o&&(0,X.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:o,children:o}),(0,X.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),e.models.length>0&&(0,X.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,X.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,X.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:e}){let{t}=S(),{toast:r}=ye(),i=V(),a=n(e.id),o=ee(e.id),s=O(),c=e.quotaConfig,l=(0,J.useMemo)(()=>sn(c),[c]),[u,d]=(0,J.useState)(l),[f,p]=(0,J.useState)(null);(0,J.useEffect)(()=>d(l),[l]);let m=i.data??[],h=m.find(e=>e.id===c.suggestedTemplate),g=u.template===en?h:m.find(e=>e.id===u.template),_=u.template===tn,v=_?nn:g?.params??[],y=e=>d(t=>({...t,...e})),x=JSON.stringify(u)!==JSON.stringify(l),w=e=>{if(e!==tn||u.url)return y({template:e});let t=g??h;y({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)})},T=()=>{let e={enabled:u.enabled,template:u.template===en?null:u.template,intervalMinutes:u.intervalMinutes,timeoutSec:u.timeoutSec??10,baseUrl:u.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(u.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(u.secrets).filter(([,e])=>e.trim()!==``))};if(_){let n=cn(u.headers),i=cn(u.extract);if(!n||!i)return r(t(`providers.quota.invalidJson`,{field:t(n?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:u.method,url:u.url.trim(),auth:u.auth,headers:n},e.extract=i}return e},E=()=>{let n=T();if(!n)return;let i=n.enabled&&!c.enabled;a.mutate(n,{onSuccess:()=>{r(t(`common.saved`),`success`),i&&s.mutate(e.id,{onError:e=>r(q(e),`error`)})},onError:e=>r(q(e),`error`)})},k=()=>{let e=T();e&&o.mutate(e,{onSuccess:p,onError:e=>r(q(e),`error`)})},j=c.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:c.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),M=[{value:en,label:h?t(`providers.quota.templateAuto`,{name:h.name}):t(`providers.quota.templateNone`)},...m.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:tn,label:t(`providers.quota.custom`)}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,X.jsx)(P,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,X.jsx)(ie,{checked:u.enabled,label:t(`providers.quota.enable`),onChange:e=>y({enabled:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.template`),children:(0,X.jsx)(xe,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:u.template,onChange:w,options:M})}),v.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=c.secrets.includes(e.name);return e.secret?(0,X.jsx)(P,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,X.jsx)(C,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:u.secrets[e.name]??``,onChange:t=>y({secrets:{...u.secrets,[e.name]:t.target.value}})})},e.name):(0,X.jsx)(P,{label:n,children:(0,X.jsx)(C,{className:`w-64 font-mono`,"aria-label":n,value:u.params[e.name]??``,onChange:t=>y({params:{...u.params,[e.name]:t.target.value}})})},e.name)}),v.length>0&&(0,X.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),_&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(xe,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:u.method,onChange:e=>y({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,X.jsx)(C,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:u.url,onChange:e=>y({url:e.target.value})}),(0,X.jsx)(xe,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:u.auth,onChange:e=>y({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,X.jsx)(b,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:u.headers,onChange:e=>y({headers:e.target.value})}),(0,X.jsx)(b,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:u.extract,onChange:e=>y({extract:e.target.value})}),(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,X.jsx)(P,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:j}),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:u.intervalMinutes,onChange:e=>y({intervalMinutes:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.timeout`),children:(0,X.jsx)(R,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:u.timeoutSec,onChange:e=>y({timeoutSec:e})})}),(0,X.jsx)(P,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,X.jsx)(C,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:u.baseUrl,onChange:e=>y({baseUrl:e.target.value})})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,X.jsx)(z,{size:`sm`,variant:`primary`,disabled:!x,loading:a.isPending,onClick:E,children:t(`common.save`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),loading:o.isPending,onClick:k,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Ye,{className:`size-3.5`}),disabled:x,loading:s.isPending,onClick:()=>s.mutate(e.id,{onError:e=>r(q(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(un,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,X.jsx)(ge,{open:f!==null,onOpenChange:e=>!e&&p(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:f&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(H,{tone:f.ok?`success`:`danger`,title:f.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!f.ok&&pe({code:f.errorCode??null,message:f.error??``},t),!f.ok&&f.error&&f.errorCode&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:f.error})]}),f.url&&(0,X.jsx)(D,{label:t(`providers.quota.requestUrl`),mono:!0,children:f.url}),f.httpStatus!=null&&(0,X.jsx)(D,{label:t(`providers.quota.httpStatus`),children:f.httpStatus}),f.snapshot&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,X.jsx)(un,{snapshot:f.snapshot})]}),f.raw!==void 0&&f.raw!==null&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,X.jsx)(A,{children:on(f.raw)})]})]})})]})}function un({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=S(),i=be(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,X.jsxs)(H,{tone:`warning`,title:n(`providers.quota.failed`,{error:pe(i,n)}),children:[(0,X.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,X.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,X.jsx)(H,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,X.jsx)(F,{children:e.name}),(0,X.jsx)(`span`,{className:`num`,children:Se(e,n,r)??`—`}),me(e,n,r)&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:me(e,n,r)}),e.extra&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,X.jsx)(F,{tone:`accent`,children:e.planLabel}),o>0&&(0,X.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:fe(o,r,n(`tray.justNow`))??``})})]})]})}function dn({provider:e}){let{t,locale:n}=S(),{toast:r}=ye(),i=O();if(!he(e))return null;let a=ve(e.quota,t,n),o=be(e.quota);return(0,X.jsxs)(`div`,{className:`mt-3 flex min-w-0 items-center gap-2 text-[12px]`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a&&(0,X.jsx)(`div`,{className:`num truncate text-[var(--text-secondary)]`,title:a,children:a}),o&&(0,X.jsx)(`div`,{className:`truncate text-[var(--warning)]`,title:o.message,children:t(`providers.quota.failed`,{error:pe(o,t)})}),!a&&!o&&(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`providers.quota.never`)})]}),(0,X.jsx)(z,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ye,{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(q(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}=S(),i=j(),a=te(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,J.useState)(`single`),[l,u]=(0,J.useState)(()=>gn(e)),[d,f]=(0,J.useState)(!0),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(pn),[_,v]=(0,J.useState)(``),[b,x]=(0,J.useState)(null),[C,w]=(0,J.useState)({}),[E,D]=(0,J.useState)([]),[O,k]=(0,J.useState)(new Set),[A,M]=(0,J.useState)([]),[P,F]=(0,J.useState)(``),[I,L]=(0,J.useState)(null),[R,ee]=(0,J.useState)(!1),B=(0,J.useRef)(null),V=(0,J.useRef)(new Map),H=(0,J.useRef)(!1),U=(0,J.useRef)(!1),ne=(0,J.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...A.filter(t=>!e.includes(t))]},[a.data,A]);(0,J.useEffect)(()=>{if(t){v(e=>e||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``);return}U.current=!1,B.current?.abort();for(let e of V.current.values())e.abort();V.current.clear(),x(null),w({}),D([]),k(new Set),M([]),F(``),L(null)},[t,a.data]);let re=(0,J.useCallback)(e=>({modelId:e,protocol:l,stream:d,prompt:p.trim()||null,maxOutputTokens:h??pn}),[l,d,p,h]),W=(0,J.useCallback)((t,n,r)=>On(e.id,t,re(t),n,r),[e.id,re]),G=()=>{let e=_.trim();if(!e)return;B.current?.abort();let t=new AbortController;B.current=t,U.current=!0,L(null),x({modelId:e,status:`running`,text:``,reasoning:``}),W(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&ae(),x(e)})},ie=e=>{if(e.length===0)return;U.current=!0,H.current=!1,L(null),D(e),w(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(!U.current)return;let n=e[t++];if(n===void 0)return;if(H.current){w(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;V.current.set(n,r),await W(n,r.signal,e=>w(t=>({...t,[n]:e}))),V.current.delete(n),ae()}}))},ae=()=>void i.invalidateQueries({queryKey:[`requests`]}),K=()=>{H.current=!0,w(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},oe=b?.status===`running`||E.some(e=>C[e]?.status===`running`||C[e]?.status===`queued`&&!H.current),se=E.filter(e=>C[e]&&C[e].status!==`queued`&&C[e].status!==`running`).length,ce=E.filter(e=>C[e]?.status===`success`).length,le=E.filter(e=>C[e]?.status===`failed`).length,ue=(e,t)=>k(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),de=()=>{oe||n(!1)},fe=e=>e.stopPropagation();return(0,X.jsx)(`span`,{onClick:fe,onKeyDown:fe,children:(0,X.jsxs)(ge,{open:t,onOpenChange:e=>e?n(!0):de(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,X.jsx)(z,{disabled:oe,onClick:()=>n(!1),icon:(0,X.jsx)(T,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?oe?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onClick:()=>B.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,X.jsx)(z,{variant:`primary`,disabled:_.trim()===``,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:G,children:r(b?`providers.testDialog.retest`:`providers.testDialog.start`)}):oe?(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onClick:K,children:r(`providers.testDialog.stopRest`)}):(0,X.jsx)(z,{variant:`primary`,disabled:O.size===0,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:()=>ie([...O]),children:r(`providers.testDialog.testN`,{count:O.size})})]}),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,X.jsx)(He,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,X.jsx)(y,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),L(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,X.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,X.jsx)(N,{label:r(`providers.testDialog.model`),children:(0,X.jsx)(bn,{value:_,models:ne,onChange:v})}),(0,X.jsx)(xn,{protocols:o,protocol:l,onProtocol:u,stream:d,onStream:f,maxTokens:h,onMaxTokens:g,prompt:p,onPrompt:m}),(0,X.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,X.jsx)(Sn,{run:b,onRetest:G})]}):I===null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(En,{known:ne,selected:O,onToggle:ue,onSelectAll:e=>k(e?new Set(ne):new Set),onClear:()=>k(new Set),search:P,onSearch:F,onAdd:e=>{M(t=>t.includes(e)?t:[...t,e]),k(t=>new Set(t).add(e)),F(``)},configOpen:R,onConfigOpen:ee,protocols:o,protocol:l,onProtocol:u,stream:d,onStream:f,maxTokens:h,onMaxTokens:g,prompt:p,onPrompt:m}),E.length>0?(0,X.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:oe?r(`providers.testDialog.progress`,{done:se,total:E.length,ok:ce,failed:le}):r(`providers.testDialog.progressDone`,{total:E.length,ok:ce,failed:le})}),(0,X.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${se/E.length*100}%`,background:`var(--accent)`}})})]}):null,E.length>0?(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Dn,{order:E,runs:C,onView:L})}):null]}):(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(z,{variant:`plain`,icon:(0,X.jsx)(we,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>L(null)}),(0,X.jsx)(`span`,{className:`font-mono text-[13px]`,children:I})]}),(0,X.jsx)(Sn,{run:C[I]??null})]})]})})}function bn({value:e,models:t,onChange:n}){let{t:r}=S(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(0),[c,l]=(0,J.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,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(C,{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,X.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,X.jsx)(ae,{className:`size-4`})}),i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,X.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,X.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{type:`button`,className:L(`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}=S(),r=e.map(e=>({value:e,label:jn.find(t=>t.value===e)?.label??e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:n(`providers.testDialog.protocol`),children:(0,X.jsx)(xe,{value:t.protocol,onChange:t.onProtocol,options:r})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,X.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`providers.testDialog.stream`)}),(0,X.jsx)(ie,{checked:t.stream,label:n(`providers.testDialog.stream`),onChange:t.onStream})]}),(0,X.jsx)(N,{label:n(`providers.testDialog.maxTokens`),children:(0,X.jsx)(R,{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,X.jsx)(N,{label:n(`providers.testDialog.prompt`),hint:n(`providers.testDialog.promptHint`),children:(0,X.jsx)(b,{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}=S(),[r,i]=(0,J.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,X.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[t&&e&&e.status!==`running`?(0,X.jsx)(z,{size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:t,children:n(`providers.testDialog.retest`)}):null,(0,X.jsx)(Ie,{content:n(`providers.testDialog.metricsHelp`),children:(0,X.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center text-[var(--text-muted)]`,tabIndex:0,children:(0,X.jsx)(qe,{className:`size-4`})})}),(0,X.jsx)(Tn,{run:e}),e?.httpStatus?(0,X.jsxs)(F,{tone:`neutral`,children:[`HTTP `,e.httpStatus]}):null]}),(0,X.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,X.jsx)(wn,{label:n(`providers.testDialog.metrics.http`),value:e?.httpMs}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.firstWait`),value:c}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.ttft`),value:e?.ttftMs}),(0,X.jsx)(wn,{label:n(`providers.testDialog.metrics.total`),value:e?.totalMs})]}),(0,X.jsxs)(`section`,{className:`card overflow-hidden`,children:[(0,X.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-[var(--border)] px-4 py-2.5`,children:[(0,X.jsx)(`h3`,{className:`text-[12px] font-medium`,children:n(`providers.testDialog.reply`)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,X.jsx)(y,{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,X.jsx)(re,{value:l,label:n(r===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,X.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:r===`headers`?s.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.headersEmpty`)}):(0,X.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,X.jsx)(`tbody`,{children:s.map(([e,t])=>(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0 align-top`,children:[(0,X.jsx)(`th`,{className:`w-[220px] py-1.5 pr-4 text-left font-mono font-normal text-[var(--text-secondary)]`,children:e}),(0,X.jsx)(`td`,{className:`py-1.5 font-mono break-all whitespace-pre-wrap selectable`,children:t})]},e))})}):r===`raw`?o?(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[n(`providers.testDialog.rawNote`),e?.contentType?` · ${e.contentType}`:``]}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:o}),e?.rawTruncated?(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:n(`providers.testDialog.rawTruncated`)}):null]}):(0,X.jsx)(Cn,{run:e}):e?.error?(0,X.jsx)(H,{tone:`danger`,title:n(`providers.testDialog.status.failed`),children:e.error}):a||e?.reasoning?(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[e?.reasoning?(0,X.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,X.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:n(`providers.testDialog.reasoning`)}),(0,X.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:e.reasoning})]}):null,a?(0,X.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:a}):null]}):e?.status===`success`?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.testDialog.noText`)}):(0,X.jsx)(Cn,{run:e})})]})]})}function Cn({run:e}){let{t}=S();return e?.status===`running`||e?.status===`queued`?(0,X.jsx)(`div`,{className:`grid h-full place-items-center text-[12px] text-[var(--text-muted)]`,children:t(hn[e.status])}):(0,X.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,X.jsx)(Me,{className:`mx-auto size-6 text-[var(--text-muted)]`}),(0,X.jsx)(`div`,{className:`text-[13px]`,children:t(`providers.testDialog.emptyTitle`)}),(0,X.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,X.jsxs)(`div`,{className:`bg-[var(--surface)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e}),(0,X.jsx)(`div`,{className:`mt-1 font-mono text-[15px] tabular-nums`,children:t==null?`—`:a(t)})]})}function Tn({run:e}){let{t}=S(),n=e?.status??`idle`;return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,X.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}=S(),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,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:d(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,X.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,X.jsx)(k,{value:a,onChange:o,placeholder:d(`providers.testDialog.searchModels`)})}),(0,X.jsx)(z,{variant:`plain`,disabled:t.size===0,onClick:i,children:d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(z,{icon:(0,X.jsx)(Ee,{className:`size-3.5`}),onClick:()=>l(!0),children:d(`providers.testDialog.config`)})]}),(0,X.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:m.length===0&&!h?(0,X.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:d(`providers.testDialog.noModels`)}):(0,X.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,X.jsx)(We,{checked:t.size===e.length&&e.length>0||t.size!==0&&`indeterminate`,onCheckedChange:e=>r(e!==!1),"aria-label":d(`providers.testDialog.clearSelection`)}),(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:d(`providers.testDialog.ownFilter`)})]}),h?(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(Ue,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,X.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,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,X.jsx)(We,{checked:t.has(e),onCheckedChange:t=>n(e,t!==!1),"aria-label":e}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,title:e,children:e})]},e))]})}),(0,X.jsx)(ge,{open:c,onOpenChange:l,width:480,title:d(`providers.testDialog.config`),description:d(`providers.testDialog.savedCredentials`),children:(0,X.jsx)(`div`,{className:`grid gap-4`,children:(0,X.jsx)(xn,{...u})})})]})}function Dn({order:e,runs:t,onView:n}){let{t:r}=S();return(0,X.jsx)(`div`,{className:`card overflow-hidden`,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)] text-left text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.model`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.statusColumn`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.ttft`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.total`)}),(0,X.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.reply`)})]})}),(0,X.jsx)(`tbody`,{children:e.map(e=>{let i=t[e];return(0,X.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0`,children:[(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono`,children:e}),(0,X.jsx)(`td`,{className:`px-4 py-2`,children:(0,X.jsx)(Tn,{run:i??null})}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:a(i.ttftMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:a(i.totalMs)}),(0,X.jsx)(`td`,{className:`px-4 py-2`,children:(0,X.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,t,n,r,i){let a={modelId:t,status:`running`,text:``,reasoning:``};i(a);let o=e=>{a={...a,...e},i(a)};try{await M(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:o({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`?o({reasoning:a.reasoning+e}):o({text:a.text+e});break}case`done`:{let t=e.data;o({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,contentType:t.contentType??null,headers:kn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?o({status:`cancelled`,error:null}):o({status:`failed`,error:e instanceof f?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=i({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}=S(),t=ke(),[n,r]=Fe(),i=I(),[a,o]=(0,J.useState)(n.get(`new`)===`1`),[s,c]=(0,J.useState)(!1);(0,J.useEffect)(()=>{n.get(`new`)===`1`&&(o(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),Re(e=>{e===`new-provider`&&o(!0)});let l=_(`7d`,`day`,`provider`),[u,d]=(0,J.useState)(null),f=(0,J.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,X.jsxs)(Le,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)})]}),children:[(0,X.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,X.jsx)(ne,{lines:4}),i.isError&&(0,X.jsx)(H,{tone:`danger`,title:e(`common.error`),children:q(i.error)}),i.data?.length===0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(x,{icon:(0,X.jsx)(Oe,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,X.jsx)(z,{variant:`primary`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,X.jsx)(z,{icon:(0,X.jsx)(Te,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,X.jsx)(Rn,{p:e,days:f.days,usage:f.byProvider.get(e.name),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>d(e)},e.id))})]}),(0,X.jsx)(Zt,{open:s,onOpenChange:c}),(0,X.jsx)(Gn,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),u&&(0,X.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}=S(),o=w(e.id),{toast:s}=ye(),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(` · `),f=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`),p=e.enabled?l?{tone:`orange`,label:a(`providers.noKey`)}:{tone:`green`,label:a(`providers.card.active`)}:{tone:`neutral`,label:a(`providers.card.disabled`)},m=n?.requests??t.map(()=>0),h=m.reduce((e,t)=>e+t,0),g=e.templateUpdateAvailable?5:8;return(0,X.jsxs)(ht,{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,X.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,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:L(`transition-[filter,opacity]`,!e.enabled&&`opacity-50 grayscale`),children:(0,X.jsx)(He,{name:e.name,icon:e.icon,colorKey:e.templateId,size:28})}),(0,X.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,X.jsx)(B,{tone:p.tone}),p.label]})]}),(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-[11px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:In(e.endpoints[0]?.baseUrl)??`—`}),(0,X.jsx)(`span`,{className:`shrink-0`,children:a(`providers.modelCount`,{count:e.modelCount})})]})]}),meta:(0,X.jsx)(`span`,{className:L(e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:f}),status:u||void 0,action:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:Ln,children:[(0,X.jsx)(z,{variant:`plain`,size:`sm`,icon:(0,X.jsx)(Ee,{className:`size-3.5`}),"aria-label":a(`providers.test`),title:a(`providers.test`),onClick:i}),(0,X.jsx)(`span`,{className:`ml-1 inline-flex`,children:(0,X.jsx)(ie,{checked:e.enabled,label:a(`common.enabled`),onChange:e=>o.mutate({enabled:e},{onError:e=>s(q(e),`error`)})})})]}),children:[(0,X.jsxs)(`div`,{className:`mt-1.5 flex h-5 flex-nowrap items-center gap-1 overflow-hidden`,children:[e.templateUpdateAvailable&&(0,X.jsx)(F,{tone:`accent`,children:a(`providers.templateUpdate`)}),e.boundClients.slice(0,g).map(e=>e in Ne?(0,X.jsx)(`span`,{title:je(e),className:`inline-flex shrink-0`,children:(0,X.jsx)(Pe,{kind:e,size:18})},e):(0,X.jsx)(F,{tone:`green`,children:e},e)),e.boundClients.length>g&&(0,X.jsxs)(`span`,{title:e.boundClients.slice(g).map(e=>Ne[e]?.name??e).join(`, `),className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:[`+`,e.boundClients.length-g]})]}),(0,X.jsx)(`div`,{className:`min-h-[32px] [&>div]:mt-1`,onClick:Ln,children:(0,X.jsx)(dn,{provider:e})}),(0,X.jsx)(`div`,{className:`mt-2`,onClick:Ln,children:h>0?(0,X.jsx)(jt,{label:a(`providers.card.requests7d`),data:m,labels:t.map(e=>e.slice(5)),value:v(h,!0),change:d(n?.costUsd??0),width:320,height:28,formatValue:e=>v(e,!0)}):(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[13px] text-[var(--text-secondary)]`,children:a(`providers.card.requests7d`)}),(0,X.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,X.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}=S(),{toast:i}=ye(),a=c(),o=g(),s=E(),l=I(),u=(0,J.useMemo)(()=>new Set((l.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[l.data]),d=ke(),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(null),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(``),[x,w]=(0,J.useState)(``),[T,D]=(0,J.useState)(``),[O,A]=(0,J.useState)(``),[j,M]=(0,J.useState)(``),[P,F]=(0,J.useState)(`openai-chat`),[L,R]=(0,J.useState)(`bearer`);(0,J.useEffect)(()=>{e||(h(null),v(null),p(``),b(``),w(``),D(``),A(``),M(``))},[e]);let ee=(0,J.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]),te=(0,J.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=>{h(e),e===`custom`?(b(``),A(``),D(``)):(b(e.name),A(e.priceKey??e.id),D(``),R(e.auth.scheme))},V=()=>{let e=m===`custom`;s.mutate({templateId:e?null:m.id,variantId:T||null,name:y.trim()||null,apiKey:x.trim()||null,priceKey:O,...e?{endpoints:[{protocol:P,baseUrl:j.trim()}],authScheme:L}:{}},{onSuccess:e=>{t(!1),i(r(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>i(q(e),`error`)})},U=m&&m!==`custom`?m:null,re=()=>{if(_===`custom`)B(`custom`);else if(_?.startsWith(zn)){let e=te.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)}},W=m!==null&&(m===`custom`?/^https?:\/\//.test(j.trim())&&y.trim()!==``:!U.requiresApiKey||x.trim()!==``);return(0,X.jsxs)(ge,{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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{className:`mr-auto`,variant:`plain`,onClick:()=>h(null),children:r(`common.back`)}),(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!W,loading:s.isPending,onClick:V,children:r(`providers.create`)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,X.jsx)(z,{variant:`primary`,disabled:!_,onClick:re,children:r(`common.continue`)})]}),children:[(0,X.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,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(N,{label:r(`providers.name`),children:(0,X.jsx)(C,{value:y,onChange:e=>b(e.target.value)})}),U?.variants&&U.variants.length>0&&(0,X.jsx)(N,{label:r(`providers.variant`),children:(0,X.jsx)(xe,{value:T,onChange:e=>{D(e);let t=U.variants?.find(t=>t.id===e);A(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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:r(`providers.baseUrl`),hint:r(`providers.baseUrlHint`),children:(0,X.jsx)(C,{value:j,onChange:e=>M(e.target.value),placeholder:`https://api.example.com/v1`,className:`font-mono`})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(N,{label:r(`providers.protocol`),children:(0,X.jsx)(xe,{value:P,onChange:F,options:jn})}),(0,X.jsx)(N,{label:r(`providers.authScheme`),children:(0,X.jsx)(xe,{value:L,onChange:R,options:Mn})})]})]}),U?.authScheme===`oauth-subscription`?(0,X.jsx)(H,{tone:`info`,title:r(`providers.subscriptionWizardHint`),children:r(`providers.subscriptionWizardDetail`)}):(0,X.jsxs)(`div`,{className:`font-mono`,children:[(0,X.jsx)(ze,{label:r(`providers.apiKey`),description:r(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:x,onChange:e=>w(e.target.value)}),U?.apiKeyUrl&&(0,X.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,X.jsx)(N,{label:r(`providers.priceKey`),hint:r(`providers.priceKeyHint`),children:(0,X.jsx)(xe,{value:O,onChange:A,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,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`providers.templateModels`,{count:U.models.length})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(k,{value:f,onChange:p,placeholder:r(`providers.searchTemplates`)}),a.isLoading&&(0,X.jsx)(ne,{lines:4}),a.isError&&(0,X.jsx)(H,{tone:`danger`,title:r(`common.error`),children:q(a.error)}),ee.map(e=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.${e.category}`)}),(0,X.jsx)(De,{name:`provider-template`,"aria-label":r(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===_)?_:null,onValueChange:v,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,X.jsx)(`span`,{title:e.name,children:n}),description:(0,X.jsx)(`span`,{title:t.map(Hn).join(` · `),children:i??t.map(e=>Vn[e]).join(` · `)}),icon:(0,X.jsx)(He,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:u.has(e.id),disabledReason:Un(r(`providers.subscriptionAdded`))}})})]},e.category)),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.plugin`)}),te.length>0?(0,X.jsx)(De,{name:`provider-template-plugin`,"aria-label":r(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:_?.startsWith(zn)?_:null,onValueChange:v,options:te.map(e=>({value:zn+e.id,label:Un(e.name),description:Un(r(`providers.pluginProvided`)),icon:(0,X.jsx)(He,{name:e.name,icon:e.icon,colorKey:e.id,size:28})}))}):(0,X.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,X.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:r(`providers.pluginHint`)}),(0,X.jsx)(z,{size:`sm`,onClick:()=>{t(!1),d(`/plugins/market`)},children:r(`plugins.browseMarket`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.custom`)}),(0,X.jsx)(De,{name:`provider-template-custom`,"aria-label":r(`providers.custom`),layout:`list`,density:`compact`,value:_===`custom`?`custom`:null,onValueChange:v,options:[{value:`custom`,label:r(`providers.custom`),description:r(`providers.customDetail`),icon:(0,X.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,X.jsx)(Ue,{className:`size-4`})})}]})]})]})]})}export{ln as a,yn as i,jn as n,Ye as o,An as r,Mn as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$r as e,Ai as t,An as n,Ar as r,Bi as i,Bt as a,Ci as o,Cr as s,E as c,Ei as l,En as u,Et as d,Ft as f,H as p,Hi as m,Ia as h,It as g,Lt as _,Ma as v,Mi as y,Na as b,Ni as x,Oi as S,Pi as C,Pr as w,Qt as T,Si as ee,Vi as E,W as te,Wi as D,Wt as ne,Yr as re,Zr as O,_ as k,ai as ie,bi as ae,ct as A,d as j,dn as oe,gi as se,gt as ce,ht as le,i as ue,ja as de,kr as fe,l as M,lr as pe,m as N,mi as me,n as P,nn as he,o as ge,oi as _e,or as F,p as ve,r as I,rn as ye,s as be,si as xe,t as Se,u as L,un as Ce,v as R,wi as z,xt as B,y as V,yi as we,zi as H,zt as U}from"./alert-BadMvy1R.js";import{B as Te,F as Ee,I as De,L as Oe,R as ke,a as W,gt as G,i as Ae,n as je,o as K,r as q,vt as J,z as Me}from"./overlays-D-LaJu2w.js";import{t as Ne}from"./TrayPanelView-D6QJsy-r.js";import{t as Pe}from"./download-DhWYUpCm.js";import{t as Fe}from"./ellipsis-DhDdch5j.js";import{t as Ie}from"./external-link-D3yhOoFs.js";import{n as Le,t as Re}from"./radio-cards-Geph_wiF.js";import{t as ze}from"./folder-open-Bggy7qkR.js";import{t as Be}from"./log-out-DV1PNbkn.js";import{t as Ve}from"./minus-DxRH0N_9.js";import{t as He}from"./pencil-TH_5IGXD.js";import{t as Ue}from"./rotate-ccw-BxvPRjim.js";import{$ as We,C as Ge,E as Ke,N as qe,Q as Je,R as Ye,T as Xe,V as Ze,h as Qe,n as $e,nt as et,s as tt,t as nt,w as rt,z as it}from"./index-BUGU_FDT.js";var at={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};at.node;var ot=B(at),st={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};st.node;var ct=B(st),lt={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};lt.node;var ut=B(lt),dt={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};dt.node;var ft=B(dt),pt={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};pt.node;var mt=B(pt),ht={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};ht.node;var gt=B(ht),_t={name:`webhook`,size:24,node:[[`path`,{d:`M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2`,key:`q3hayz`}],[`path`,{d:`m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06`,key:`1go1hn`}],[`path`,{d:`m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8`,key:`qlwsc0`}]]};_t.node;var vt=B(_t),Y=h(b(),1),X=v(),yt=`https://astra-gate.si/docs/guide/remote-access`,bt=`astra.remote.acknowledged`;function xt(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function St(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function Ct(){try{return localStorage.getItem(bt)===`1`}catch{return!1}}function wt(){try{localStorage.setItem(bt,`1`)}catch{}}function Tt(){let{t:e}=A(),t=ie(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(Et,{s:n}),(0,X.jsx)(Dt,{s:n}),(0,X.jsx)(Ot,{s:n}),(0,X.jsx)(jt,{s:n}),(0,X.jsx)(ge,{title:n.cloudflared.path&&n.cloudflared.version?e(`settings.remote.logWithVersion`,{version:n.cloudflared.version}):e(`settings.remote.log`),children:n.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:e(`settings.remote.logEmpty`)}):(0,X.jsx)(`pre`,{className:`max-h-72 overflow-auto font-mono text-[10.5px] leading-relaxed whitespace-pre-wrap text-[var(--text-secondary)] selectable`,children:n.log.join(`
|
|
2
|
+
`)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(Se,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:W(t.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`})})}function Et({s:e}){let{t,locale:n}=A(),{toast:r,confirm:i}=K(),a=O(),o=U(),s=xt(e,t),c=async e=>{await G.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(W(e),`error`)})},u=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,d=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,f=e.state===`connected`&&d!==null?d<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:te(d,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),m=e.cloudflared,h=m.downloading||m.path?null:m.asset?t(`settings.remote.cloudflaredMissing`,{version:m.version??``}):t(`settings.remote.cloudflaredUnsupported`),g=e.enabled?e.error??m.error??null:null,_=g!==null&&(e.state!==`connected`||/origin service|origin server/i.test(g)),v=e.publicUrl;return(0,X.jsxs)(L,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?p(e.connectedAt,n):void 0,children:[(0,X.jsx)(be,{tone:u}),f,m.downloading&&m.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(m.progress*100),`%`]})]}),children:(0,X.jsx)(V,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:a.isPending||!e.enabled&&s!==null,onChange:e=>void l(e)})}),!e.enabled&&s&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:s}),!e.enabled&&!s&&h&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:h}),e.enabled&&v&&(0,X.jsxs)(N,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${v}/v1`}),children:[(0,X.jsx)(je,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(ce,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void c(`${v}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void c(v)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void c(`${v}/key`),separatorBefore:!0}]}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ie,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(v,`_blank`,`noopener`)})]}),e.enabled&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),_&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Se,{tone:e.state===`connected`?`warning`:`danger`,title:St(g,e,t),children:g})})]})}function Dt({s:e}){let{t}=A(),{toast:n,confirm:r}=K(),i=we(),[a,o]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>o(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let s=async e=>{await G.copy(e)&&n(t(`common.copied`))},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(W(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(W(e),`error`)}),u=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(L,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(N,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(k,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void c(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Se,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:a.token,onChange:e=>o({...a,token:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:a.hostname,onChange:e=>o({...a,hostname:e.target.value})})}),(0,X.jsxs)(N,{label:t(`settings.remote.origin`),detail:t(`settings.remote.originHint`),children:[(0,X.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.originUrl}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void s(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ut,{className:`size-3.5`}),onClick:()=>window.open(yt,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(I,{size:`sm`,disabled:!u||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function Ot({s:e}){let{t}=A(),{toast:n,confirm:r}=K(),i=we(),a=U(),o=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!a.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&i.mutate({allowAdmin:e},{onError:e=>n(W(e),`error`)})};return(0,X.jsxs)(L,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(N,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(P,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(N,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(V,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:i.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void o(e)})}),(0,X.jsx)(kt,{passwordSet:e.checks.passwordSet})]})}function kt({passwordSet:e}){let{t}=A(),{toast:n}=K(),r=U(),i=fe(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(I,{size:`sm`,onClick:()=>o(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),a&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:s.length<8,loading:i.isPending,onClick:()=>i.mutate(s,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),o(!1),c(``)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})]})}var At=[`auto`,`github`,`astra`,`custom`];function jt({s:e}){let{t}=A(),{toast:n}=K(),r=we(),i=oe(),a=U(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[p,m]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>m(e.download.downloadSource),[e.download.downloadSource]);let h=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(W(e),`error`)}),g=t=>{m(t),(t!==`custom`||e.download.downloadBaseUrl)&&h({downloadSource:t})},_=()=>i.mutate(void 0,{onSuccess:e=>e.path?f(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(W(e),`error`)}),v=o.fromEnvironment?t(`settings.remote.cf.fromEnv`):o.installed?o.version?t(`settings.remote.cf.installedProgram`,{version:o.version}):t(`settings.remote.cf.installedUnknown`):o.path?t(`settings.remote.cf.downloaded`,{version:o.version??``}):o.asset?t(`settings.remote.cf.notDownloaded`,{version:o.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(L,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:v}),children:(0,X.jsx)(be,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${p}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:p,onChange:g,options:At.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),p===`custom`&&(0,X.jsxs)(N,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(I,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>h({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(N,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>h({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(I,{size:`sm`,onClick:()=>{u(!0),_()},children:t(`settings.remote.cf.choose`)})}),l&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(j,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:d,onChange:e=>f(e.target.value)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:_,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,onClick:()=>u(!1),children:t(`common.cancel`)}),(0,X.jsx)(I,{size:`sm`,variant:`primary`,disabled:!d.trim(),loading:r.isPending,onClick:()=>h({cloudflaredPath:d.trim()},()=>u(!1)),children:t(`settings.remote.cf.use`)})]})]})}var Mt=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],Nt={local:`127.0.0.1`,lan:`0.0.0.0`},Pt=e=>Mt.includes(e)?`local`:`lan`;function Ft(){let{t:e}=A(),{toast:t,confirm:n}=K(),r=de(),i=u(),a=U(),o=xe(),[s,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(!1),f=i.data;if(!f)return(0,X.jsx)(N,{label:e(`settings.listen`),detail:i.isError?W(i.error):void 0,children:i.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=Pt(f.configuredHost),h=f.configuredHost!==f.host,g=!!a.data?.required,_=async n=>{await G.copy(n)&&t(e(`common.copied`))},v=n=>o.mutate(Nt[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(W(e),`error`)}),y=async t=>{if(t!==m){if(t===`lan`){if(!f.passwordSet){c(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}v(t)}},b=async()=>{d(!0);let n=await G.restartService();if(d(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},S=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${x?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.listen`),detail:S,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&x&&(0,X.jsx)(I,{size:`sm`,loading:l,onClick:()=>void b(),children:e(`settings.listen.restart`)}),(0,X.jsx)(k,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void y(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(N,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(kt,{passwordSet:f.passwordSet}),(0,X.jsx)(It,{open:s,onOpenChange:c,onSaved:()=>v(`lan`)})]})}function It({open:e,onOpenChange:t,onSaved:n}){let{t:r}=A(),{toast:i}=K(),a=fe(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(W(e),`error`)})};return(0,X.jsx)(Ae,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(j,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(j,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var 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}=A(),n=_(!0);return(0,X.jsxs)(L,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(R,{}),n.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(N,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--danger)]`}),label:`${Bt(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${p(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function Wt(){let{t:e}=A(),{toast:t,confirm:n}=K(),r=z(),i=Ce(),a=re(),o=s(),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),m=n=>a.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(W(e),`error`)}),h=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>p(e.secret??null),onError:e=>t(W(e),`error`)})},g=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(N,{icon:(0,X.jsx)(vt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(P,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(P,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||zt(t.format))&&(0,X.jsx)(P,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(Le,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(je,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(Ze,{className:`size-3.5`}),onSelect:()=>void h(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void g(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(Gt,{hook:c,onClose:()=>l(null),onSecret:p}),(0,X.jsx)(qt,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(Kt,{secret:f,onClose:()=>p(null)})]})}function Gt({hook:e,onClose:t,onSecret:n}){let{t:r}=A(),{toast:i}=K(),a=he(),o=ae(),[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)(Ae,{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)(I,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(C.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),u={name:s.trim(),url:l.trim(),timeoutSec:d??10,useProxy:p,enabled:h,headers:Object.keys(c).length>0?c:null},f={onError:e=>i(W(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)(M,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(j,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${y}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:y,onChange:t=>{b(t),v(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||zt(t))},options:Lt.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(j,{mono:!0,value:l,placeholder:Rt[y],onChange:e=>u(e.target.value)})}),zt(y)&&_&&(0,X.jsx)(M,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(j,{mono:!0,type:`password`,autoComplete:`off`,value:x,placeholder:e!==`new`&&e!==null&&e.format===y&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>S(e.target.value)})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(ve,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(M,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[C.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(j,{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)(j,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>w(C.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(qe,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>w(C.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(it,{className:`size-3.5`}),onClick:()=>w([...C,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(N,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(V,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:g})}),(0,X.jsx)(N,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(V,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(y===`generic`?T||e!==null&&e.format===`generic`&&e.hasSecret:zt(y))&&(0,X.jsx)(N,{label:r(`alerts.webhooks.signed`),detail:r(y===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(V,{checked:_,label:r(`alerts.webhooks.signed`),onChange:v})})]})]})})}function Kt({secret:e,onClose:t}){let{t:n}=A(),{toast:r}=K();return(0,X.jsx)(Ae,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:async()=>e&&await G.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(I,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function qt({hook:e,onClose:t}){let{t:n,locale:r}=A(),{toast:i}=K(),a=o(e?.id),s=pe(),c={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Ae,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(R,{lines:4}),a.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:a.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(P,{tone:c[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:p(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:p(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)(ue,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:n(`alerts.delivery.response`)}),(0,X.jsx)(ue,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(I,{size:`sm`,loading:s.isPending&&s.variables===e.id,onClick:()=>s.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(W(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Jt(t){let n=F(),r=e(),i=(0,Y.useMemo)(()=>(n.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[n.data]),a=J({queries:i.map(e=>({queryKey:d.providerAccounts(e.id),queryFn:()=>l(`GET`,`/api/providers/${S(e.id)}/accounts`),enabled:t===`account`}))});return t===`provider`?(n.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):t===`token`?(r.data??[]).map(e=>({value:e.id,label:e.name})):t===`account`?i.flatMap((e,t)=>(a[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Yt(){let{t:e}=A(),{toast:t,confirm:n}=K(),r=g(),i=z(),a=_e(),o=ye(),[s,c]=(0,Y.useState)(null),l=e=>i.data?.find(t=>t.id===e)?.name??e,u=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(W(e),`error`)})};return(0,X.jsxs)(L,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(R,{}),r.data?.length===0&&(0,X.jsx)(N,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(N,{icon:(0,X.jsx)(ot,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(P,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(P,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${Bt(e,n.event)} → ${n.webhookIds.map(l).join(`, `)||`—`}`,children:[(0,X.jsx)(V,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(W(e),`error`)})}),(0,X.jsx)(je,{label:e(`common.more`),icon:(0,X.jsx)(Fe,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(He,{className:`size-3.5`}),onSelect:()=>c(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(qe,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void u(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,icon:(0,X.jsx)(it,{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}=A(),{toast:r}=K(),i=f(),a=z(),o=T(),s=_e(),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(``),[p,m]=(0,Y.useState)({}),[h,g]=(0,Y.useState)(`all`),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[ee,E]=(0,Y.useState)(60),te=i.data?.find(e=>e.id===u),D=Jt(te?.subjectType),ne=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??``),m(t?{...Xt(i.data?.find(e=>e.id===t.event)),...t.condition}:Xt(n)),g(t?.subjects?`only`:`all`),v(t?.subjects??[]),b(t?.webhookIds??(a.data??[]).map(e=>e.id)),S(t?.notifyResolved??!1),w(t?.repeatMinutes??null),E(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(Ae,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(ne?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(I,{variant:`primary`,disabled:!c.trim()||!u,loading:o.isPending||s.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(p).filter(([,e])=>e!==null&&e!==``)),a={name:c.trim(),event:u,condition:i,subjects:h===`all`?null:_,webhookIds:y,notifyResolved:x,repeatMinutes:C&&C>0?Math.floor(C):null,cooldownMinutes:Math.max(0,Math.floor(ee??0))},l={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(W(e),`error`)};ne?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)(M,{label:n(`alerts.rules.name`),children:(0,X.jsx)(j,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,X.jsx)(M,{label:n(`alerts.rules.event`),hint:u?Vt(n,u):void 0,children:(0,X.jsx)(q,{ariaLabel:n(`alerts.rules.event`),value:u,onChange:e=>{d(e),m(Xt(i.data?.find(t=>t.id===e))),v([])},options:(i.data??[]).map(e=>({value:e.id,label:Bt(n,e.id)}))})}),te?.params.map(e=>(0,X.jsx)(M,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(ve,{value:typeof p[e.name]==`number`?p[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>m({...p,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:n(`alerts.param.${e.name}`),value:String(p[e.name]??``),onChange:t=>m({...p,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(j,{mono:!0,value:String(p[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>m({...p,[e.name]:t.target.value})})},e.name)),te&&(0,X.jsx)(M,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${te.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(k,{ariaLabel:n(`alerts.rules.subjects`),value:h,onChange:g,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),h===`only`&&(0,X.jsx)(tt,{label:n(`alerts.rules.subjects`),value:_,onValueChange:v,options:[...D,..._.filter(e=>!D.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(M,{label:n(`alerts.rules.webhooks`),children:(a.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.rules.noWebhooks`)}):(0,X.jsx)(tt,{label:n(`alerts.rules.webhooks`),value: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)(M,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(ve,{value:C,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:w})}),(0,X.jsx)(M,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(ve,{value:ee,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:E})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(N,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(V,{checked:x,label:n(`alerts.rules.notifyResolved`),onChange:S})})})]})})}function Qt(){let{t:e}=A(),t=a(),n=y()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&C;return(0,X.jsxs)(L,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)($t,{loginItem:n}),(0,X.jsx)(en,{})]})}function $t({loginItem:e}){let{t}=A(),{toast:n}=K(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&i(e)});let n=e.onChanged(i);return()=>{t=!1,n()}},[e]),(0,X.jsx)(N,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(V,{checked:r.enabled,disabled:!r.supported||a,label:t(`settings.startup.app`),onChange:r=>{o(!0),e.set(r).then(e=>{i(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(W(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(R,{className:`size-3.5`})})}function en(){let{t:e}=A(),{toast:t}=K(),n=a(),i=r(),o=n.data;if(!o)return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:n.isError?W(n.error):void 0,children:n.isPending&&(0,X.jsx)(R,{className:`size-3.5`})});let s=!o.supported||o.mechanism===`none`?e(`settings.startup.unsupported.${o.unsupported??`platform`}`):o.canChange?o.enabled&&o.location?e(`settings.startup.entry`,{location:o.location}):e(`settings.startup.service.${o.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(N,{label:e(`settings.startup.service`),detail:s,children:o.supported&&(0,X.jsx)(V,{checked:o.enabled,disabled:!o.canChange||i.isPending,label:e(`settings.startup.service`),onChange:n=>i.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(W(e),`error`)})})})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:tn}=c,nn=[...c.ease.enter],rn=[...c.ease.standard],an=[0,1,2,3,4,5,6,7,8,9],on=6,sn=400,cn=40,ln=240,un=1500,dn=700,fn=700,pn=.22,mn=4,hn=130,gn=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),_n=e=>(String(e).split(`.`)[1]??``).length,vn=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),yn=(e,t)=>typeof e==`function`?e(t):e??``,bn=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function xn(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var Sn={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${tn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:rn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${tn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:rn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},Cn=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),wn={enter:Cn(0),center:{...Cn(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},Tn={enter:Cn(1),center:{...Cn(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function En({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=et(e,e=>`${n(e)*1.05}em`),i=et(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=et(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=et(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*tn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(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=E(),a=m(e),o=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let s=o.current;if(s.digit===e)return;let c=t>0?(e-s.digit+10)%10:-((s.digit-e+10)%10);Math.abs(c)>5&&(c-=Math.sign(c)*10),s.target+=c,s.digit=e,n||r?a.jump(s.target):i(a,s.target,Q.snappy)},[e,t,n,a,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),an.map(e=>(0,X.jsx)(En,{position:a,digit:e},e))]})}function On({value:e,format:t,direction:n,instant:r}){let i=E(),a=r?Tn:i?wn:Sn;return(0,X.jsx)(D,{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=E();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(D,{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=E(),r=(0,Y.useRef)(null),a=m(`auto`),o=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!o.current||n?a.jump(e.offsetWidth):i(a,e.offsetWidth,Q.morph),o.current=!0});return t.observe(e),()=>t.disconnect()},[n,a]),(0,X.jsxs)(H.span,{className:Z.wordSlot,style:{width:a},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(D,{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)(D,{initial:!1,children:t?(0,X.jsx)(Ln,{id:e,text:t,className:n},`message`):null})}function Ln({id:e,text:t,className:n}){let r=E(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(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=E();return(0,X.jsx)(D,{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?it:Ve;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Bn({label:e,value:t,defaultValue:n=0,onValueChange:r,min:a=0,max:o=2**53-1,step:s=1,largeStep:c,description:l,disabled:u,id:d,prefix:f,suffix:p,scrub:h=!1,locale:g=`en-US`,formatOptions:_,size:v=`md`,limitHint:y=!0}){let b=E(),x=(0,Y.useId)(),S=d??x,C=l?`${S}-description`:void 0,w=`${S}-limit`,T=s>0?s:1,[ee,te]=(0,Y.useState)(n),D=t??ee,[ne,re]=(0,Y.useState)(``),[O,k]=(0,Y.useState)(!1),[ie,ae]=(0,Y.useState)(0),[A,j]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(``),[ce,le]=(0,Y.useState)(0),[ue,de]=(0,Y.useState)(!1),fe=(0,Y.useRef)(null),M=(0,Y.useRef)(null),pe=(0,Y.useRef)(null),N=(0,Y.useRef)(void 0),me=(0,Y.useRef)(void 0),P=(0,Y.useRef)(void 0),he=(0,Y.useRef)({edge:0,count:0,at:0}),ge=(0,Y.useRef)(null),_e=(0,Y.useRef)(null),F=(0,Y.useRef)(D),ve=(0,Y.useRef)(D),I=(0,Y.useRef)(void 0),ye=(0,Y.useRef)(null),be=(0,Y.useRef)(!1),xe=(0,Y.useRef)(null),Se=(0,Y.useRef)(!1),L=(0,Y.useRef)(()=>!1),Ce=m(0),R=m(0),z=m(0),B=et(()=>R.get()+z.get()),V=Number.isFinite(a)?a:0,we=Math.max(_n(T),_n(V)),U=_?.minimumFractionDigits??we,Te=Math.max(U,_?.maximumFractionDigits??we),Ee=_?.useGrouping??!0,De=(0,Y.useMemo)(()=>new Intl.NumberFormat(g,{minimumFractionDigits:U,maximumFractionDigits:Te,useGrouping:Ee,numberingSystem:`latn`}),[g,U,Te,Ee]),Oe=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(g).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[g]),ke=e=>Number(e.toFixed(we))||0,W=e=>Math.min(o,Math.max(a,e)),G=e=>ke(V+Math.round((e-V)/T)*T),Ae=(e,t)=>{let n=(e-V)/T;return ke(V+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*T)},je=e=>`${yn(f,e)}${De.format(e)}${yn(p,e)}`.trim();function K(e){let t=e.split(Oe.group).join(``).replace(Oe.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let q=O?K(ne):null,J=q??D,[Me,Ne]=(0,Y.useState)({value:J,direction:1});Me.value!==J&&Ne({value:J,direction:J>Me.value?1:-1});let Pe=Me.value===J?Me.direction:J>Me.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(I.current),window.clearTimeout(N.current),window.clearTimeout(me.current),window.clearTimeout(P.current)},[]);function Fe(e,t){let n=performance.now(),r=he.current;r.count=r.edge===e&&n-r.at<fn?r.count+1:1,r.edge=e,r.at=n;let a=fe.current;if(a&&(a.dataset.strain=e>0?`max`:`min`,window.clearTimeout(P.current),P.current=window.setTimeout(()=>{delete a.dataset.strain},420)),!b){i(Ce,0,{...gn,velocity:-e*hn*(1+Math.min(r.count-1,mn)*pn)});let n=(e>0?pe:M).current;n&&(t===`button`||t===`key`)&&i(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}y&&(le(e),window.clearTimeout(N.current),N.current=window.setTimeout(()=>le(0),un))}function Ie(e,n){if(!Number.isFinite(e))return!1;let i=W(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Fe(a>0?1:-1,n),se(`${je(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==F.current&&se(je(i)),i!==F.current&&(F.current=i,t===void 0&&te(i),r?.(i),!0)}let Le=(e,t,n)=>Ie(Ae(F.current,e*t),n);(0,Y.useLayoutEffect)(()=>{F.current=D,L.current=Le});function Re(){let e=_e.current;e&&xe.current===null&&(xe.current=e.getBoundingClientRect().left-R.get()-z.get())}(0,Y.useLayoutEffect)(()=>{let e=xe.current,t=_e.current;if(xe.current=null,Se.current){Se.current=!1;let e=ge.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-R.get()-z.get());Math.abs(n)<.5||(z.set(z.get()+n),b?z.jump(0):i(z,0,Q.morph))});function ze(){window.clearTimeout(me.current),de(!1)}function Be(){if(!O)return;Re(),k(!1),ze();let e=K(ne);e!==null&&Ie(G(e),`type`)}function Ve(){window.clearTimeout(I.current),I.current=void 0,ae(0)}function He(e,t,n){Ve(),Be();let r=Math.max(1,Math.round(t/T));n===`button`&&ae(e);let i=0,a=()=>{let t=L.current(e,r,n);I.current=window.setTimeout(a,t?Math.max(cn,150*.86**++i):ln)};I.current=window.setTimeout(a,Le(e,r,n)?sn:360)}function Ue(e){let t=c??T*10,n={ArrowUp:[1,e.shiftKey?t:T],ArrowDown:[-1,e.shiftKey?t:T],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||He(n[0],n[1],`key`);return}if(!O&&(e.key===`Home`&&Number.isFinite(a)||e.key===`End`&&o<2**53-1)){e.preventDefault(),Ie(e.key===`Home`?a:o,`key`);return}e.key===`Enter`&&(e.preventDefault(),O?(Se.current=!0,Be()):e.currentTarget.select()),e.key===`Escape`&&O&&(e.preventDefault(),Re(),k(!1),ze(),Se.current=!0,Ie(ve.current,`type`))}function We(e){let t=RegExp(`[^0-9${vn(Oe.group)}${we||Te?vn(Oe.decimal):``}${a<0?`\\-`:``}]`,`g`),n=e.replace(t,``);O||(ve.current=D),Re(),re(n),k(!0);let r=K(n);r!==null&&r>=a&&r<=o&&G(r)===r&&Ie(r,`type`),ze(),r!==null&&r<a&&(me.current=window.setTimeout(()=>de(!0),dn))}function Ge(e){be.current=!1,h&&!u&&e.button===0&&(Be(),ye.current={pointer:e.pointerId,x:e.clientX,from:F.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=ye.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,j(!0)}let r=n/on,i=Math.trunc(r);Ie(i?Ae(t.from,i):t.from,`scrub`);let s=t.from+r*T,c=s>o?(s-o)/T*on:s<a?(s-a)/T*on:0;R.set(b?0:bn(c))}function qe(e){let t=ye.current;t&&t.pointer===e.pointerId&&(ye.current=null,t.active&&(be.current=!0,j(!1),i(R,0,b?{duration:0}:Q.snappy),se(je(F.current))))}let Je=t=>({toward:t,label:e,disabled:u,controls:S,limit:t>0?J>=o:J<=a,pressed:ie===t}),Ye=q===null?0:q>o?1:q<a&&ue?-1:0,Xe=y?Ye||ce:0,Ze=Xe>0?o:a,Qe=Xe?typeof y==`function`?y(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${je(Ze)}`:``,$e=[C,Ye&&y?w:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":v,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:S,className:Z.label,"data-scrub":h&&!u||void 0,onPointerDown:Ge,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{be.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Rn,{id:w,edge:Xe,text:Qe})]}),(0,X.jsxs)(`div`,{ref:fe,className:Z.control,"data-scrubbing":A||void 0,"data-disabled":u||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(zn,{...Je(-1),iconRef:M,onPress:()=>He(-1,T,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==ge.current&&e.preventDefault()},onClick:e=>{!u&&e.target!==ge.current&&(ge.current?.focus(),ge.current?.select())},children:(0,X.jsxs)(H.span,{ref:_e,className:Z.value,style:{x:B,y:Ce},children:[(0,X.jsx)(kn,{text:yn(f,J),direction:Pe,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":O||void 0,"aria-hidden":`true`,children:(0,X.jsx)(On,{value:J,format:De,direction:Pe,instant:O})}),O&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:ne}),(0,X.jsx)(`input`,{ref:ge,id:S,className:Z.input,type:`text`,role:`spinbutton`,inputMode:a<0?`text`:we||Te?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:O?ne:De.format(D),disabled:u,"aria-describedby":$e,"aria-invalid":Ye?!0:void 0,"aria-valuenow":D,"aria-valuetext":je(D),"aria-valuemin":Number.isFinite(a)?a:void 0,"aria-valuemax":o<2**53-1?o:void 0,onChange:e=>We(e.currentTarget.value),onKeyDown:Ue,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ve()},onBlur:()=>{Ve(),Be()}})]}),(0,X.jsx)(kn,{text:yn(p,J),direction:Pe,className:Z.affix})]})}),(0,X.jsx)(zn,{...Je(1),iconRef:pe,onPress:()=>He(1,T,`button`),onRelease:Ve,onActivate:()=>{Be(),Le(1,1,`button`)}})]}),(0,X.jsx)(In,{id:C,text:l,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:oe})]})}var Vn=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Hn(){let{t:e}=A(),n=de(),[r,i]=ke(),a=Me(),o=Ee(r,{enabled:a.running,background:!1,live:!0}),s=t=>(0,X.jsx)(N,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(V,{checked:r.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>i(Te(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)(Re,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:r.title,onValueChange:e=>i({...r,title:e}),options:t.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)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(Ue,{className:`size-3.5`}),onClick:()=>i(De),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Un,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Ne,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:r,state:a,data:o,onRefresh:()=>void n.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}=A();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var 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}=A(),{tab:t}=We(),n=Je(),r=Oe(),i=Wn.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsx)(Qe,{title:e(`nav.settings`),children:(0,X.jsxs)(Ge,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(Xe,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Ke,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(gt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Ke,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ct,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Ke,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(le,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),r&&(0,X.jsx)(Ke,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(mt,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(rt,{value:`general`,className:`pt-5`,children:(0,X.jsx)(qn,{})}),(0,X.jsx)(rt,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(Ht,{})}),(0,X.jsx)(rt,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(Tt,{})}),r&&(0,X.jsx)(rt,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Hn,{})})]})})}function qn(){let{t:e,locale:t,setLocale:r}=A(),i=$e(),a=w(),o=me(),s=de(),c=ee(),l=U(),u=n(),f=ie(),{toast:p,confirm:m}=K(),h=a.data,g=f.data?.state===`connected`&&f.data.publicUrl?`${f.data.publicUrl}/v1`:null,_=e=>o.mutate(e,{onError:e=>p(W(e),`error`)}),v=e=>{r(e),_({locale:e})},b=async t=>{await G.copy(t)&&p(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(L,{title:e(`settings.appearance`),children:[(0,X.jsx)(N,{label:e(`settings.theme`),children:(0,X.jsx)(k,{ariaLabel:e(`settings.theme`),value:i.theme,onChange:i.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(N,{label:e(`settings.accent`),detail:i.accentChoice===`system`?i.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:i.accentChoice,onChange:i.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...nt.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(N,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(k,{ariaLabel:e(`settings.language`),value:t,onChange:v,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Qt,{}),h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(L,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(N,{label:e(`settings.gatewayUrl`),detail:`${h.gatewayBaseUrl}/v1`,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(`${h.gatewayBaseUrl}/v1`)})}),g&&(0,X.jsx)(N,{label:e(`settings.remote.publicUrl`),detail:g,children:(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(g)})}),(0,X.jsx)(Ft,{}),(0,X.jsx)(N,{label:e(`settings.dataDir`),detail:h.dataDir,children:G.canOpenPaths?(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ze,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void G.openPath(h.dataDir)}):(0,X.jsx)(I,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ce,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void b(h.dataDir)})}),(0,X.jsx)(N,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(V,{checked:h.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await m({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&_({requireGatewayKey:t})}})}),(0,X.jsx)(N,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Zn,{label:e(`settings.streamIdle`),value:h.streamIdleTimeoutSec,onCommit:e=>_({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(N,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:h.requestCompression,onChange:e=>_({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(Yn,{settings:h}),(0,X.jsx)(Xn,{settings:h}),(0,X.jsxs)(L,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(N,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.autoInterval`),value:h.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:d.providers}),onError:e=>p(W(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(N,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Zn,{label:e(`settings.quota.subscriptionInterval`),value:h.subscriptionQuotaIntervalMinutes,onCommit:e=>_({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(L,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(N,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:h.usageTimeZone??``,onChange:e=>_({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:h.effectiveUsageTimeZone})},...[...new Set([...Gn,...h.usageTimeZone?[h.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(L,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(N,{label:e(`settings.debugBodies`),children:(0,X.jsx)(V,{checked:h.debugBodies,label:e(`settings.debugBodies`),onChange:e=>_({debugBodies:e})})}),(0,X.jsx)(N,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Zn,{label:e(`settings.bodyRetention`),value:h.bodyRetentionDays,onCommit:e=>_({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(N,{label:e(`settings.requestRetention`),detail:h.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(V,{checked:h.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>_({requestRetentionDays:e?90:null})}),h.requestRetentionDays!=null&&(0,X.jsx)(Zn,{label:e(`settings.requestRetention`),value:h.requestRetentionDays,onCommit:e=>_({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(L,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(N,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Zn,{label:e(`settings.effort.${t}`),value:h.effortBudgets[t],onCommit:e=>_({effortBudgets:{...h.effortBudgets,[t]:e??h.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:W(a.error)}):(0,X.jsx)(R,{className:`mx-auto my-8`}),(0,X.jsxs)(L,{title:e(`settings.about`),children:[(0,X.jsx)(N,{label:e(`settings.serverVersion`),detail:c.data?`${c.data.version} · API ${c.data.apiVersion}`:`—`}),x&&(0,X.jsx)(N,{label:e(`settings.desktopVersion`),detail:y()?.version||`—`}),(0,X.jsx)(Jn,{}),x&&(0,X.jsx)(N,{label:e(`settings.logs`),onClick:()=>void G.revealLogs(),children:(0,X.jsx)(ze,{className:`size-4 text-[var(--text-secondary)]`})}),l.data?.required&&(0,X.jsx)(N,{label:e(`settings.logout`),onClick:()=>u.mutate(),children:(0,X.jsx)(Be,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Jn(){let{t:e}=A(),{toast:t}=K(),n=de(),r=me(),i=w(),a=se(),o=ne(),s=a.data,c=i.data?.updateChannel??s?.channel,l=y()?.updates??null,[u,f]=(0,Y.useState)(!1),p=()=>o.mutate(void 0,{onSuccess:n=>n.error?t(e(`settings.updateCheckFailed`,{error:n.error}),`error`):t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(W(e),`error`)}),m=()=>{l&&!u&&(f(!0),l.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:d.version}),n.invalidateQueries({queryKey:d.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(W(e),`error`)).finally(()=>f(!1)))},h=s?.lastCheckAt?new Date(s.lastCheckAt).toLocaleString():void 0,g=s?.available?l?e(`settings.updateAvailable`,{version:s.available}):`${e(`settings.updateAvailable`,{version:s.available})} ${e(`settings.updateApplyHint`)}`:void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:e(`settings.autoCheck`),detail:s&&!s.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(V,{checked:s?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>r.mutate({updateAutoCheck:e},{onError:e=>t(W(e),`error`)})})}),(0,X.jsx)(N,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(V,{checked:c===`preview`,label:e(`settings.previewUpdates`),disabled:!c||r.isPending,onChange:e=>r.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:p,onError:e=>t(W(e),`error`)})})}),(0,X.jsxs)(N,{label:e(`settings.checkUpdates`),detail:o.isError?e(`settings.updateCheckFailed`,{error:W(o.error)}):s?.available?g:h?e(`settings.lastChecked`,{time:h}):void 0,children:[(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:o.isPending,onClick:p,children:o.isPending?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Ye,{className:`size-3.5`})}),l&&s?.available&&(0,X.jsx)(I,{size:`sm`,variant:`plain`,disabled:u,"aria-label":e(`settings.updateApply`),onClick:m,children:u?(0,X.jsx)(R,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`})})]})]})}function Yn({settings:e}){let{t}=A(),{toast:n}=K(),r=me(),[i,a]=(0,Y.useState)(e.proxyMode),[o,s]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>a(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>s({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let c=t=>{a(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(W(e),`error`)})},l=()=>r.mutate({proxyMode:`custom`,proxyUrl:o.url.trim()||null,proxyUsername:o.username.trim()||null,proxyBypass:o.bypass.trim()||null,...o.password?{proxyPassword:o.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(W(e),`error`)}),u=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(L,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(N,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(k,{ariaLabel:t(`settings.proxy.mode`),value:i,onChange:c,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),i===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:o.url,onChange:e=>s({...o,url:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(j,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:o.username,onChange:e=>s({...o,username:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(j,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:o.password,onChange:e=>s({...o,password:e.target.value})})}),(0,X.jsx)(N,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(j,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:o.bypass,onChange:e=>s({...o,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(I,{size:`sm`,disabled:!u||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function Xn({settings:e}){let{t}=A(),{toast:n}=K(),r=me(),i=e.pluginMarketUrl===``,[a,o]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>o(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let s=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(W(e),`error`)});return(0,X.jsxs)(L,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(V,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(N,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(j,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:a,onChange:e=>o(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(I,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(I,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function 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,2 @@
|
|
|
1
|
+
import{Er as e,Ia as t,Ir as n,J as r,Jr as i,Ma as a,Na as o,Ti as s,_ as c,b as l,ct as u,d,gt as f,hi as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,ut as S,v as C,y as w}from"./alert-BadMvy1R.js";import{a as T,gt as E,o as D,r as O}from"./overlays-D-LaJu2w.js";import{t as k}from"./arrow-down-Cv-6a_e3.js";import{K as A,N as j,S as M,h as N,z as P}from"./index-BUGU_FDT.js";var F=t(o(),1),I=a(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(m,{...t,detail:e==null?void 0:(0,I.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var B={typesafe:[{id:`typesafe`,baseUrl:``,model:`jev-latest`},{id:`openrouter`,baseUrl:`https://openrouter.ai/api`,model:`~typesafe/jev-latest`},{id:`vercel`,baseUrl:`https://ai-gateway.vercel.sh/typesafe`,model:`typesafe-ai/jev`}],openai:[{id:`openai`,baseUrl:``}]},V=(e,t)=>`${e??``}\n${t}`;function H(e,t){let n=t.trim().replace(/\/+$/,``);return B[e].find(e=>e.baseUrl===n)?.id??`custom`}function U(e,t,n){let r=e.trim()||(n.find(e=>e.id===t)?.defaultBaseUrl??``);try{return new URL(r).origin.toLowerCase()}catch{return r}}function W(e){return{virtualModel:e.virtualModel,protocol:e.judge.protocol,baseUrl:e.judge.baseUrl??``,apiKey:``,model:e.judge.model,instructions:e.judge.instructions??``,timeoutMs:e.judge.timeoutMs,grades:e.grades.map(e=>({...e})),mode:e.rules.mode,sessionTtlMinutes:e.rules.sessionTtlMinutes,fallbackGrade:e.rules.fallbackGrade,minConfidence:e.rules.minConfidence,contextTurns:e.rules.contextTurns,maxChars:e.rules.maxChars}}var G=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function K(e){return{protocol:e.protocol,baseUrl:e.baseUrl,model:e.model,instructions:e.instructions,...e.timeoutMs!==null&&{timeoutMs:e.timeoutMs},...e.apiKey!==``&&{apiKey:e.apiKey}}}function q(e){return{virtualModel:e.virtualModel,judge:K(e),grades:e.grades,rules:{mode:e.mode,fallbackGrade:e.fallbackGrade,...e.sessionTtlMinutes!==null&&{sessionTtlMinutes:e.sessionTtlMinutes},...e.minConfidence!==null&&{minConfidence:e.minConfidence},...e.contextTurns!==null&&{contextTurns:e.contextTurns},...e.maxChars!==null&&{maxChars:e.maxChars}}}}function J(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in S))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(e,t,n){if(e instanceof s){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>J(e,t,n))}return[T(e)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in S?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in S?t(n):e??``}function Q(){let{t:e}=u(),t=n();return t.data?(0,I.jsx)($,{saved:t.data}):(0,I.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,I.jsx)(b,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(C,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=u(),{toast:n}=D(),r=p(),[i,a]=(0,F.useState)(()=>W(e)),[o,s]=(0,F.useState)([]),c=e=>a(t=>({...t,...e})),l=JSON.stringify(i)!==JSON.stringify(W(e)),d=G(i),f=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:d,onToggle:e=>f(e),problems:o}),(0,I.jsx)(ne,{saved:e,draft:i,patch:c}),(0,I.jsx)(ie,{draft:i,patch:c}),(0,I.jsx)(ae,{draft:i,patch:c}),!d&&(0,I.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[l&&(0,I.jsx)(v,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!l||!d,loading:r.isPending,onClick:()=>f(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=u(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(x,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(y,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(f,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`danger`,title:a(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:i.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:e}){let{t,locale:n}=u(),i=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=i.outcomes.judge??0,c=Object.entries(i.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=i.total-s,d=[t(`smartRouting.recent.judged`,{count:s,total:i.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...i.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:i.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:i.total===0?t(`smartRouting.recent.none`):d}),l>=2&&l*2>i.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in S?f:`smartRouting.recent.hint.other`)}),i.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(i.lastFallback,t),time:r(i.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let i=X(e.reason),a={count:e.count,time:r(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(i??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),i&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${i}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=u(),i=H(t.protocol,t.baseUrl),a=e.judge.hasApiKey&&t.apiKey===``&&U(t.baseUrl,t.protocol,e.protocols)!==U(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,I.jsxs)(x,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>n({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=B[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(d,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>n({model:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(_,{className:`w-28`,label:r(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(b,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(g,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(l,{rows:4,"aria-label":r(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:e}){let{t}=u(),n=i(),[r,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(null),[c,d]=(0,F.useState)([]),f=()=>{s(null),d([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:s,onError:n=>d(Y(n,e,t))})},p=o!==null&&o.latencyMs>o.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,I.jsx)(l,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>a(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(v,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:f,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(b,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),o&&(o.ok?(0,I.jsx)(b,{tone:o.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:o.gradeName??o.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:o.model?t(`smartRouting.test.model`,{model:o.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((o.confidence??0)*100)}),` ·`,` `,o.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:o.latencyMs,limit:o.limitMs}),o.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:o.latencyMs,input:o.inputTokens,output:o.outputTokens,model:o.judgeModel??``})})]})}):(0,I.jsxs)(b,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(o.failure,t)}),children:[o.message,o.failure===`timeout`&&o.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:t,patch:n}){let{t:r}=u(),i=e(),a=t.grades,o=(e,r=t.fallbackGrade)=>n({grades:e,fallbackGrade:e.some(e=>e.id===r)?r:e[Math.floor(e.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},f=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],m=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:m.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:m.has(e.id)?void 0:e.providerName})),_=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
|
|
2
|
+
`);s(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(x,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[a.map((e,n)=>(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,I.jsx)(d,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:e.id,value:e.name,onChange:e=>s(n,{name:e.target.value})}),t.fallbackGrade===e.id&&(0,I.jsx)(h,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(A,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>c(n,-1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===a.length-1,onClick:()=>c(n,1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:a.length<=L,onClick:()=>o(a.filter((e,t)=>t!==n))})]}),(0,I.jsx)(l,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:e.description,onChange:e=>s(n,{description:e.target.value})}),(0,I.jsx)(O,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:e.model?V(e.providerId,e.model):``,options:_(e),onChange:e=>y(n,e)})]},e.id)),i.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(v,{size:`sm`,icon:(0,I.jsx)(P,{className:`size-3.5`}),disabled:a.length>=R,onClick:f,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=u();return(0,I.jsxs)(x,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(c,{ariaLabel:n(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:n(`smartRouting.rules.mode.session`)},{value:`turn`,label:n(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(O,{className:`w-44`,ariaLabel:n(`smartRouting.rules.fallback`),value:e.fallbackGrade,onChange:e=>t({fallbackGrade:e}),options:e.grades.map(e=>({value:e.id,label:e.name||e.id}))})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(g,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(d,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=u();return(0,I.jsx)(N,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Br as e,G as t,Ia as n,J as r,Ma as i,Na as a,Q as o,Qr as ee,Xr as s,Y as c,_ as l,c as u,ct as d,ei as f,ir as p,n as m,or as h,q as g,r as _,s as v,t as y,v as b,yr as te}from"./alert-BadMvy1R.js";import{a as ne,at as re,it as ie,nt as ae,ot as oe,rt as x}from"./overlays-D-LaJu2w.js";import{t as S}from"./arrow-left-dS7bcLEo.js";import{$ as C,D as w,L as T,O as E,Q as D,X as O,h as k,m as A}from"./index-BUGU_FDT.js";import{a as j,n as M}from"./TokenPoolEditor-D1m8Jjy3.js";var N=n(a(),1),P=i();function F(){let{id:n=``}=C(),{t:i,locale:a}=d(),F=D(),[L,R]=(0,N.useState)(`7d`),z=ee(n),B=h(),V=e(L,void 0,n),H=s(L,L===`today`?`hour`:`day`,`token`,void 0,n),U=f(L,void 0,20,n),W=p(L,n),G=te({token:n,page:1,pageSize:10},!1),K=j(),q=(0,P.jsx)(_,{variant:`glass`,icon:(0,P.jsx)(S,{className:`size-4`}),"aria-label":i(`common.back`),onClick:()=>F(`/tokens`)}),J=i(`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:i(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:i(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`share`,label:i(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>g(e)},{key:`success`,label:i(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?g(e):`—`},{key:`ttft`,label:i(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>t(e)},{key:`cost`,label:i(`overview.cost`),sortable:!0,numeric:!0,render:e=>o(e)},{key:`out`,label:i(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:i(`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:i(`tokens.detail.model`),sortable:!0},{key:`requests`,label:i(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`tokens`,label:i(`overview.tokens`),sortable:!0,numeric:!0,render:e=>c(e,!0)},{key:`cost`,label:i(`overview.cost`),sortable:!0,numeric:!0,render:e=>o(e)}],de=(G.data?.items??[]).map(e=>({id:e.id,time:new Date(e.startedAtUtc).getTime(),model:e.requestedModel??`—`,provider:e.providerName??e.providerId??`—`,status:e.status,cost:e.costNanoUsd/1e9,r:e})),fe=[{key:`time`,label:i(`tokens.detail.time`),render:(e,t)=>r(t.r.startedAtUtc,a)},{key:`model`,label:i(`tokens.detail.model`)},{key:`provider`,label:i(`tokens.detail.provider`)},{key:`status`,label:i(`tokens.detail.status`),render:e=>(0,P.jsx)(m,{tone:e===`success`?`green`:`red`,children:i(`status.${e}`)})},{key:`cost`,label:i(`overview.cost`),numeric:!0,render:e=>o(e)}];if(z.isError)return(0,P.jsx)(k,{title:i(`nav.tokens`),leading:q,children:(0,P.jsx)(y,{tone:`danger`,title:i(`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)(O,{to:`/requests?token=${encodeURIComponent(n)}`,children:(0,P.jsx)(_,{icon:(0,P.jsx)(T,{className:`size-3.5`}),children:i(`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)(l,{ariaLabel:i(`overview.range`),value:L,onChange:R,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:i(`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:i(`overview.totalCost`),value:o($.costUsd),context:J}),(0,P.jsx)(I,{label:i(`overview.totalRequests`),value:c($.requests),context:J}),(0,P.jsx)(I,{label:i(`overview.tokens`),value:c($.inputTokens+$.outputTokens,!0),context:i(`overview.tokensContext`,{input:c($.inputTokens,!0),output:c($.outputTokens,!0)})}),(0,P.jsx)(I,{label:i(`usage.hitRate`),value:g(A($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,P.jsx)(I,{label:i(`overview.successRate`),value:$.requests?g($.successRate):`—`,context:t($.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:[i(`tokens.pool.title`),` · `,i(`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)(v,{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)(u,{title:i(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:i(`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:[i(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,P.jsx)(b,{lines:4}):(0,P.jsx)(E,{data:se,label:i(`overview.requests`),period:J,height:160,formatValue:e=>c(e),averageLabel:i(L===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:i(`overview.total`),categoryLabel:i(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:i(`tokens.detail.byProvider`)}),(0,P.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:i(`tokens.detail.byProviderHint`)}),(0,P.jsx)(w,{caption:i(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:i(`common.noData`)})]}),(0,P.jsxs)(`section`,{className:`card p-5`,children:[(0,P.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:i(`tokens.detail.byModel`)}),(0,P.jsx)(w,{caption:i(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:i(`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:i(`tokens.detail.recent`)}),(0,P.jsx)(O,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(n)}`,children:i(`tokens.detail.viewLogs`)})]}),(0,P.jsx)(w,{caption:i(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:i(`common.noData`)})]})]})})}function I({label:e,value:t,context:n}){return(0,P.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,P.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,P.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,P.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{F as TokenDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{J as e,
|
|
1
|
+
import{J as e,Ma as t,_ as n,ct as r,n as i,nr as a,ot as o,p as s,r as c,y as l}from"./alert-BadMvy1R.js";import{r as u}from"./overlays-D-LaJu2w.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-DYxWT0KU.js";import{N as w,x as T}from"./index-BUGU_FDT.js";var E=t(),D=[`failover`,`round_robin`,`weighted`,`tiered`,`least_busy`];function O(e){return e.pool?{strategy:e.pool.strategy,sticky:e.pool.sticky,failover:e.pool.failover,maxAttempts:e.pool.maxAttempts,members:e.pool.members.map(e=>({providerId:e.providerId,accountId:e.accountId??null,weight:e.weight,tier:e.tier}))}:{strategy:`failover`,sticky:`session`,failover:!0,maxAttempts:3,members:e.providerId?[{providerId:e.providerId,accountId:e.accountId??null,weight:1,tier:1}]:[]}}function k(e,t){let n=new Set(t.map(e=>e.id));return{strategy:e.strategy,sticky:e.sticky,failover:e.failover,maxAttempts:Math.min(5,Math.max(1,Math.floor(e.maxAttempts||1))),members:e.members.filter(e=>n.has(e.providerId)).map(e=>({...e,weight:Math.max(1,Math.floor(e.weight||1))}))}}function A(e){let{members:t,strategy:n}=e;if(t.length===0)return[];let r=e=>e.reduce((e,t)=>e+Math.max(1,t.weight),0);switch(n){case`failover`:return t.map((e,t)=>+(t===0));case`weighted`:{let e=r(t);return t.map(t=>Math.max(1,t.weight)/e)}case`tiered`:{let e=Math.min(...t.map(e=>e.tier)),n=r(t.filter(t=>t.tier===e));return t.map(t=>t.tier===e?Math.max(1,t.weight)/n:0)}default:return t.map(()=>1/t.length)}}var j=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],M=new Set([`oauth-subscription`,`plugin`]);function N(e){return e===`healthy`?`green`:e===`cooling`||e===`open`||e===`half_open`?`orange`:`red`}function P(){let{t,locale:n}=r();return r=>r.state===`cooling`||r.state===`open`?t(`tokens.health.${r.state}`,{time:r.until?e(r.until,n):`—`}):t(`tokens.health.${r.state}`)}function F({draft:e,onChange:t,providers:i,health:a}){let{t:o}=r(),c=new Map(i.map(e=>[e.id,e])),m=e.members.length>1,h=p(C(f,{activationConstraint:{distance:4}}),C(x,{coordinateGetter:b})),y=n=>t({...e,members:n}),w=(t,n)=>y(e.members.map((e,r)=>r===t?{...e,...n}:e)),T=({active:t,over:n})=>{if(!n||t.id===n.id)return;let r=e.members.findIndex(e=>e.providerId===t.id),i=e.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&y(_(e.members,r,i))},O=i.filter(t=>t.enabled&&!e.members.some(e=>e.providerId===t.id)),k=A(e),M=e.members.flatMap(e=>{let t=c.get(e.providerId);return t&&t.modelCount===0?[t.name]:[]});return(0,E.jsxs)(`div`,{className:`grid gap-3`,children:[m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(n,{ariaLabel:o(`tokens.pool.strategy`),value:e.strategy,onChange:n=>t({...e,strategy:n}),items:D.map(e=>({value:e,label:o(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(v,{sensors:h,collisionDetection:g,onDragEnd:T,children:(0,E.jsx)(S,{items:e.members.map(e=>e.providerId),strategy:d,children:e.members.map((t,n)=>(0,E.jsx)(I,{member:t,index:n,draft:e,provider:c.get(t.providerId),health:a?.get(t.providerId),onChange:e=>w(n,e),onRemove:()=>y(e.members.filter((e,t)=>t!==n))},t.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:o(`tokens.pool.add`),placeholder:o(`tokens.pool.add`),value:null,onChange:t=>y([...e.members,{providerId:t,accountId:null,weight:1,tier:1}]),options:O.map(e=>({value:e.id,label:e.name}))}),M.length>0&&(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--warning)]`,children:o(`tokens.pool.noModels`,{providers:M.join(`, `)})}),m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2 text-[12px]`,children:[(0,E.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:o(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.shareHint`)})]}),(0,E.jsx)(`div`,{className:`flex h-2 gap-0.5 overflow-hidden rounded-full bg-[var(--fill-2)]`,"aria-hidden":`true`,children:e.members.map((e,t)=>k[t]>0?(0,E.jsx)(`span`,{style:{flex:k[t],background:j[t%j.length]}},e.providerId):null)}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:e.members.map((e,t)=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`inline-block size-2 rounded-sm`,style:{background:j[t%j.length]}}),c.get(e.providerId)?.name??e.providerId,(0,E.jsxs)(`b`,{className:`tabular-nums text-[var(--text-primary)]`,children:[Math.round(k[t]*100),`%`]}),k[t]===0&&(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.standby`)})]},e.providerId))})]}),m&&(0,E.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:n=>t({...e,sticky:n?`session`:`off`})})]}),(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.failover`),checked:e.failover,onChange:n=>t({...e,failover:n})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:o(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:n=>t({...e,maxAttempts:n??1})})})]})]})]})}function I({member:e,index:t,draft:n,provider:l,health:d,onChange:f,onRemove:p}){let{t:g}=r(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!l&&M.has(l.authScheme),A=a(l?.id,k),j=l?.name??e.providerId,F=n.members.length>1,I=l?l.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:o(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,O&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,E.jsx)(`button`,{ref:S,type:`button`,"aria-label":g(`clients.dragToReorder`,{provider:j}),title:g(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...v,...b,children:(0,E.jsx)(y,{className:`size-4`})}),l&&(0,E.jsx)(T,{name:l.name,icon:l.icon,colorKey:l.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&n.strategy===`failover`&&(0,E.jsx)(i,{tone:t===0?`accent`:`neutral`,children:t===0?g(`tokens.pool.primary`):g(`tokens.pool.backup`,{n:t})}),I&&(0,E.jsx)(i,{tone:N(I.state),children:_(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(n.strategy===`weighted`||n.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&n.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:g(`tokens.pool.tier`),value:String(e.tier),onChange:e=>f({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:g(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:g(`tokens.directAccount`),value:e.accountId??``,onChange:e=>f({accountId:e||null}),options:[{value:``,label:g(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(w,{className:`size-3.5`}),"aria-label":g(`tokens.pool.remove`,{provider:j}),title:g(`tokens.pool.remove`,{provider:j}),onClick:p})]})]})}export{P as a,k as i,N as n,O as r,F as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$r as e,H as t,Ia as n,J as r,Ma as i,Na as a,Pr as o,Q as s,Sr as c,Tr as l,X as u,Y as d,_ as f,ai as p,c as m,ct as h,d as g,gt as _,l as v,ln as y,n as b,or as x,p as S,q as C,r as w,s as T,t as E,tn as D,v as O,vi as k,xt as A}from"./alert-BadMvy1R.js";import{a as j,gt as M,i as N,n as ee,o as P,r as F}from"./overlays-D-LaJu2w.js";import{t as te}from"./ellipsis-DhDdch5j.js";import{t as ne}from"./pencil-TH_5IGXD.js";import{t as re}from"./power-DF2viDB7.js";import{t as ie}from"./rotate-ccw-BxvPRjim.js";import{H as ae,L as oe,N as I,P as se,V as L,X as R,_ as z,h as B,s as V,y as H,z as U}from"./index-BUGU_FDT.js";import{a as ce,i as W,n as G,r as K,t as q}from"./TokenPoolEditor-D1m8Jjy3.js";var J={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`]};J.node;var le=A(J),Y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Y.node;var ue=A(Y),X=n(a(),1),Z=i();function de(){let{t}=h(),n=e(),r=o(),i=p(),a=i.data?.state===`connected`?i.data.publicUrl:null,[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(null);return(0,Z.jsxs)(B,{title:t(`nav.tokens`),subtitle:t(`tokens.subtitle`),actions:(0,Z.jsx)(w,{variant:`primary`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>c(!0),children:t(`tokens.add`)}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[r.data&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`p`,{children:t(`tokens.directHint`,{url:`${r.data.gatewayBaseUrl}/v1`})}),(0,Z.jsx)(`p`,{className:`selectable`,children:t(`tokens.selfServiceHint`,{url:r.data.gatewayBaseUrl})}),a&&(0,Z.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:t(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),n.isLoading&&(0,Z.jsx)(O,{lines:4}),n.isError&&(0,Z.jsx)(E,{tone:`danger`,title:t(`common.error`),children:j(n.error)}),n.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(m,{icon:(0,Z.jsx)(L,{className:`size-6`}),title:t(`tokens.empty`)})}),n.data&&n.data.length>0&&(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(e=>(0,Z.jsx)(fe,{token:e,defaultOpen:n.data.length===1,onEdit:()=>u(e)},e.id))})]}),(0,Z.jsx)(_e,{open:s,onOpenChange:c}),(0,Z.jsx)(ve,{token:l,onClose:()=>u(null)})]})}function fe({token:e,defaultOpen:n,onEdit:i}){let{t:a,locale:u}=h(),{toast:f,confirm:p}=P(),m=x(),g=o(),v=l(),S=k(),C=c(),E=y(),[D,O]=(0,X.useState)(n),A=(m.data??[]).find(t=>t.id===e.providerId),N=ce(),F=`token-detail-${e.id}`,L=(e,t)=>{f(t,`success`),e.skipped.length>0&&f(a(`tokens.skipped`,{clients:e.skipped.map(e=>z[e]?.name??e).join(`, `)}),`error`)},B=()=>v.mutate(e.id,{onSuccess:async({token:e})=>{await M.copy(e)?f(a(`tokens.copied`)):f(a(`tokens.copyFailed`),`error`)},onError:e=>f(j(e),`error`)}),V=async()=>{let e=g.data?.gatewayBaseUrl;e&&(await M.copy(`${e}/v1`)?f(a(`tokens.urlCopied`)):f(a(`tokens.copyFailed`),`error`))},U=async()=>{let e=g.data?.gatewayBaseUrl;e&&(await M.copy(`npx @aidotnet/astra-connect join ${e}`)?f(a(`tokens.joinCopied`)):f(a(`tokens.copyFailed`),`error`))},W=async()=>{(!e.enabled||await p({title:a(`tokens.disableConfirm`,{name:e.name}),detail:a(`tokens.disableDetail`),confirmLabel:a(`tokens.disable`),destructive:!0}))&&S.mutate({id:e.id,enabled:!e.enabled},{onError:e=>f(j(e),`error`)})},K=async()=>{await p({title:a(`tokens.resetConfirm`,{name:e.name}),detail:a(`tokens.resetDetail`),confirmLabel:a(`tokens.reset`),destructive:!0})&&C.mutate(e.id,{onSuccess:e=>L(e,a(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>f(j(e),`error`)})},q=async()=>{await p({title:a(`tokens.deleteConfirm`,{name:e.name}),detail:a(`tokens.deleteDetail`),confirmLabel:a(`common.delete`),destructive:!0})&&E.mutate(e.id,{onSuccess:t=>L(t,a(`tokens.deleted`,{name:e.name})),onError:e=>f(j(e),`error`)})},J=e.lastUsedAt?t(e.lastUsedAt,u):a(`tokens.neverUsed`);return(0,Z.jsxs)(`article`,{children:[(0,Z.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>O(e=>!e),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":D,"aria-controls":F,"aria-label":a(`tokens.details`),onClick:e=>{e.stopPropagation(),O(e=>!e)},children:(0,Z.jsx)(ae,{className:`size-4 transition-transform ${D?`rotate-90`:``}`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Z.jsx)(b,{tone:`accent`,children:a(`tokens.default`)}),!e.enabled&&(0,Z.jsx)(b,{tone:`orange`,children:a(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Z.jsx)(b,{tone:`orange`,children:a(`tokens.limitExhausted`)}),e.pool&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Z.jsx)(b,{children:a(`tokens.pool.summary`,{count:e.pool.members.length,strategy:a(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Z.jsx)(T,{tone:G(e.health.state)},e.providerId))]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(_,{className:`size-3.5`}),"aria-label":a(`tokens.copy`),title:a(`tokens.copy`),loading:v.isPending,onClick:B}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ue,{className:`size-3.5`}),"aria-label":a(`tokens.copyUrl`),title:a(`tokens.copyUrl`),disabled:!g.data,onClick:()=>void V()}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(se,{className:`size-3.5`}),"aria-label":a(`tokens.copyJoin`),title:a(`tokens.copyJoin`),disabled:!g.data,onClick:()=>void U()})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>z[e]?.name??e).join(`, `)||a(`tokens.noClients`),children:e.clients.length===0?(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Z.jsx)(H,{kind:e,size:16},e))}),(0,Z.jsx)(Q,{label:a(`tokens.today`),value:s(e.today.costUsd),context:a(`tokens.requestsContext`,{count:d(e.today.requests)})}),(0,Z.jsx)(Q,{label:a(`tokens.total`),value:s(e.total.costUsd),context:`${d(e.total.totalTokens,!0)} Token`}),(0,Z.jsx)(Q,{label:a(`tokens.lastUsedTitle`),value:e.lastUsedAt?r(e.lastUsedAt,u):`—`,context:e.lastUsedAt?``:a(`tokens.neverUsed`),title:J}),(0,Z.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(ee,{label:a(`common.more`),icon:(0,Z.jsx)(te,{className:`size-4`}),items:[{id:`settings`,label:a(`tokens.settings`),icon:(0,Z.jsx)(ne,{className:`size-3.5`}),onSelect:i},{id:`toggle`,label:e.enabled?a(`tokens.disable`):a(`tokens.enable`),icon:(0,Z.jsx)(re,{className:`size-3.5`}),onSelect:()=>void W()},{id:`reset`,label:a(`tokens.reset`),icon:(0,Z.jsx)(ie,{className:`size-3.5`}),onSelect:()=>void K()},...e.isDefault?[]:[{id:`delete`,label:a(`tokens.delete`),icon:(0,Z.jsx)(I,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),D&&(0,Z.jsxs)(`div`,{id:F,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Z.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:a(`tokens.clients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?a(`tokens.noClients`):e.clients.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(H,{kind:e,size:14}),z[e]?.name??e]},e))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?a(`tokens.pool.title`):a(`tokens.directProvider`)}),e.pool?(0,Z.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:N(e.health),children:[(0,Z.jsx)(T,{tone:G(e.health.state)}),(m.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:A?.name??(e.providerId?e.providerId:a(`tokens.directNone`))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:a(`tokens.allowedClients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?a(`tokens.allowedClientsAny`):e.allowedClients.length===0?a(`tokens.directOnly`):e.allowedClients.map(e=>z[e]?.name??e).join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:a(`tokens.lastUsedTitle`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:J})]})]}),(0,Z.jsx)(pe,{token:e}),(0,Z.jsx)(he,{today:e.today,total:e.total}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Z.jsx)(R,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(le,{className:`size-3.5`}),children:a(`tokens.detail.open`)})}),(0,Z.jsx)(R,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(oe,{className:`size-3.5`}),children:a(`tokens.detail.viewLogs`)})})]})]})]})}function pe({token:e}){let{t}=h(),n=e.limits?.rpm;return(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Z.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Z.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Z.jsx)(me,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Z.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function me({usage:e}){let{t:n,locale:r}=h(),i=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,a=t=>e.metric===`cost`?s(t):d(t,!0),o=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=o>=90?`var(--danger)`:o>=70?`var(--warning)`:`var(--accent)`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Z.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:a(e.used),limit:a(e.limit)})})]}),(0,Z.jsx)(`div`,{role:`progressbar`,"aria-valuenow":o,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${o}%`,background:c}})}),e.resetsAt&&(0,Z.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:t(e.resetsAt,r)})})]})}function Q({label:e,value:t,context:n,title:r}){return(0,Z.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function he({today:e,total:t}){let{t:n}=h(),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,Z.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Z.jsx)(`th`,{className:`${i} text-left`}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Z.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Z.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`${a} font-semibold selectable`,children:s(t.costUsd)}),(0,Z.jsx)(`td`,{className:a,children:d(t.requests)}),(0,Z.jsx)(`td`,{className:a,children:d(t.totalTokens,!0)}),(0,Z.jsxs)(`td`,{className:`${a} text-[var(--text-secondary)]`,children:[d(t.inputTokens,!0),` / `,d(t.outputTokens,!0)]}),(0,Z.jsx)(`td`,{className:a,title:n(`usage.cacheAmounts`,{read:d(t.cacheReadTokens,!0),write:d(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:C(t.cacheHitRate)}),(0,Z.jsx)(`td`,{className:a,children:t.tps==null?`—`:u(t.tps)})]},e))})]})})}function ge(){let{t:e}=h(),t=(x().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:t}){let{t:n}=h(),{toast:r}=P(),i=D(),{options:a}=ge(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``);return(0,X.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Z.jsx)(N,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(j(e),`error`)}),children:n(`common.create`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(g,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.directProvider`),children:(0,Z.jsx)(F,{value:c,onChange:l,options:a})})]})})}function ve({token:e,onClose:t}){let{t:n}=h(),{toast:r}=P(),i=k(),a=x(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)([]),[p,m]=(0,X.useState)(null),[_,y]=(0,X.useState)(`any`),[b,C]=(0,X.useState)([]),T=new Set(u.map(e=>`${e.metric}:${e.period}`)).size<u.length,E=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,X.useEffect)(()=>{e&&(s(e.name),l(K(e)),d(e.limits?.budgets.map(e=>({...e}))??[]),m(e.limits?.rpm??null),y(e.allowedClients==null?`any`:`only`),C(e.allowedClients??[]))},[e]),(0,Z.jsx)(N,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,Z.jsx)(w,{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||p!=null&&p>0?{budgets:s,rpm:p!=null&&p>0?Math.floor(p):null}:null;i.mutate({id:e.id,name:o.trim(),...c?{pool:W(c,a.data??[])}:{},limits:l,allowedClients:_===`any`?null:b},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(j(e),`error`)})},children:n(`common.save`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(g,{value:o,maxLength:64,onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:c&&(0,Z.jsx)(q,{draft:c,onChange:l,providers:a.data??[],health:E})}),(0,Z.jsx)(v,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:T?n(`tokens.limitDuplicate`):void 0,children:(0,Z.jsx)(be,{budgets:u,onChange:d})}),(0,Z.jsx)(v,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Z.jsx)(S,{value:p,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:m})}),(0,Z.jsx)(v,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(f,{ariaLabel:n(`tokens.allowedClients`),value:_,onChange:y,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),_===`only`&&(0,Z.jsx)(V,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(z),...b])].map(e=>({value:e,label:z[e]?.name??e})),value:b,onValueChange:e=>C(e)})]})})]})})}var $=[`cost`,`requests`,`tokens`],ye=[`day`,`week`,`month`,`total`];function be({budgets:e,onChange:t}){let{t:n}=h(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=$.flatMap(e=>ye.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:$.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:ye.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Z.jsx)(S,{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,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.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,Z.jsx)(`div`,{children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{de as TokensPage};
|