@aidotnet/server-win32-x64 0.14.3112 → 0.14.3114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/bin/astra-server.exe +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-BhnTX0ew.js +11 -0
  3. package/bin/wwwroot/assets/{KeyPage-Db9tYWgA.js → KeyPage-D8xcW85A.js} +1 -1
  4. package/bin/wwwroot/assets/LibraryPage-BO51S5vR.js +2 -0
  5. package/bin/wwwroot/assets/McpPage-BFav-GE-.js +9 -0
  6. package/bin/wwwroot/assets/ModelDetailPage-CRE3OFy5.js +1 -0
  7. package/bin/wwwroot/assets/{ModelsPage-Dc1KK7-3.js → ModelsPage-BsRk0_yk.js} +1 -1
  8. package/bin/wwwroot/assets/PluginsPage-blIrwXbf.js +2 -0
  9. package/bin/wwwroot/assets/{PrivacyPage-Dsaaw5Ko.js → PrivacyPage-bKxw2Y54.js} +1 -1
  10. package/bin/wwwroot/assets/ProviderDetailPage-3YGtfo9v.js +3 -0
  11. package/bin/wwwroot/assets/ProvidersPage-B0XULeAs.js +3 -0
  12. package/bin/wwwroot/assets/{RoutingGroupsPage-B-7FNn_B.js → RoutingGroupsPage-Dz-TTq1a.js} +3 -3
  13. package/bin/wwwroot/assets/SettingsPage-CFVirZNv.js +2 -0
  14. package/bin/wwwroot/assets/{SkillsPage-BdZSd_hw.js → SkillsPage-DI61DG2m.js} +1 -1
  15. package/bin/wwwroot/assets/SmartRoutingPage-CpchDlXC.js +2 -0
  16. package/bin/wwwroot/assets/TokenDetailPage-PqVFcudk.js +1 -0
  17. package/bin/wwwroot/assets/{TokenPoolEditor-CISTyNzC.js → TokenPoolEditor-IS5Zwuqf.js} +1 -1
  18. package/bin/wwwroot/assets/TokensPage-CXK5_J6v.js +1 -0
  19. package/bin/wwwroot/assets/ToolsPage-B_JZpB1h.js +1 -0
  20. package/bin/wwwroot/assets/{TracesPage-f3hY7JcZ.js → TracesPage-CgbFQFzA.js} +3 -3
  21. package/bin/wwwroot/assets/{TrayPanelPage-HGV5ST-e.js → TrayPanelPage-Z4vWiyK-.js} +1 -1
  22. package/bin/wwwroot/assets/{TrayPanelView-BhyK24F_.js → TrayPanelView-Cauh6r_o.js} +1 -1
  23. package/bin/wwwroot/assets/TrayTitleSource-B98nYas3.js +41 -0
  24. package/bin/wwwroot/assets/{checkbox-CZ-rG7I2.js → checkbox-29lSW_6h.js} +1 -1
  25. package/bin/wwwroot/assets/confirm-morph-DpNjlFyg.js +1 -0
  26. package/bin/wwwroot/assets/{format-CmXxTS5M.js → format-CskGUFYy.js} +4 -4
  27. package/bin/wwwroot/assets/{index-BW8keTkg.js → index-D2siu6xk.js} +16 -16
  28. package/bin/wwwroot/assets/{radio-cards-BTn8kpAx.js → radio-cards-CNQWIuu8.js} +1 -1
  29. package/bin/wwwroot/assets/{sortable.esm-Cj5-STJU.js → sortable.esm-BvMId5KB.js} +1 -1
  30. package/bin/wwwroot/assets/use-transform-BPiFWEVF.js +1 -0
  31. package/bin/wwwroot/index.html +4 -4
  32. package/package.json +1 -1
  33. package/bin/wwwroot/assets/ClientsPage-CE9QdKbh.js +0 -11
  34. package/bin/wwwroot/assets/LibraryPage-Djro5zZa.js +0 -2
  35. package/bin/wwwroot/assets/McpPage-BJ7D5vt6.js +0 -9
  36. package/bin/wwwroot/assets/ModelDetailPage-DuyD1_Ei.js +0 -1
  37. package/bin/wwwroot/assets/PluginsPage-Dn1IYmlm.js +0 -2
  38. package/bin/wwwroot/assets/ProviderDetailPage-C5YbB46r.js +0 -3
  39. package/bin/wwwroot/assets/ProvidersPage-BzICHtxh.js +0 -3
  40. package/bin/wwwroot/assets/SettingsPage-CCOHxf9s.js +0 -2
  41. package/bin/wwwroot/assets/SmartRoutingPage-DIkU4HND.js +0 -2
  42. package/bin/wwwroot/assets/TokenDetailPage-DA6q9gbd.js +0 -1
  43. package/bin/wwwroot/assets/TokensPage-CUJXAz7I.js +0 -1
  44. package/bin/wwwroot/assets/ToolsPage-DOHJoH86.js +0 -1
  45. package/bin/wwwroot/assets/TrayTitleSource-DN10ruw2.js +0 -41
  46. package/bin/wwwroot/assets/confirm-morph-Cakq9Lho.js +0 -1
  47. package/bin/wwwroot/assets/use-transform-BcmlojQJ.js +0 -1
@@ -0,0 +1,3 @@
1
+ import{a as e,o as t,r as n}from"./createLucideIcon-7fjTeqBK.js";import{$s as r,B as i,Ba as a,D as o,Et as s,G as c,Go as l,H as u,Ho as d,I as f,Io as p,Ja as m,Ka as h,M as g,N as _,O as v,P as y,Pa as b,Qs as x,R as S,S as C,U as w,Ui as T,W as E,Y as D,Yn as O,Z as k,c as A,cs as j,d as M,dr as N,ds as P,dt as F,fr as ee,gi as te,ia as I,j as ne,ls as L,m as R,mi as z,ni as re,o as B,os as V,pi as ie,ss as H,ti as ae,tr as oe,ur as se,vn as ce,vo as le,w as U}from"./format-CskGUFYy.js";import{A as ue,F as de,H as fe,I as W,P as pe,U as G,V as K,W as q}from"./TrayTitleSource-B98nYas3.js";import{t as me}from"./archive-CiVf7slo.js";import{t as he}from"./arrow-left-DhPqlXf4.js";import{t as ge}from"./chart-column-TQVFilUc.js";import{t as _e}from"./chevron-down-CQQqnJvT.js";import{t as ve}from"./chevron-up-BNvDpRa-.js";import{t as J}from"./circle-question-mark-DdDavLt6.js";import{t as ye}from"./cloud-download-l1GjuXcO.js";import{t as be}from"./cloud-upload-CincxlRw.js";import{t as xe}from"./file-up-BZh1Gcck.js";import{t as Se}from"./flask-conical-P-TiuT25.js";import{t as Ce}from"./image-plus-C5rL1_SU.js";import{t as we}from"./plus-c3HzV6VX.js";import{t as Te}from"./refresh-cw-CoLAai2c.js";import{t as Ee}from"./server-CuiQSQOX.js";import{t as De}from"./square-DO9MseLK.js";import{t as Oe}from"./trash-BHBJn5GS.js";import{t as ke}from"./upload-yXA41tlC.js";import{t as Ae}from"./x-AFrW8zH7.js";import{A as je,B as Me,F as Ne,K as Pe,M as Fe,V as Ie,W as Le,u as Re,v as ze,w as Be,y as Ve}from"./index-D2siu6xk.js";import{t as He}from"./radio-cards-CNQWIuu8.js";import{t as Ue}from"./checkbox-29lSW_6h.js";var Y={root:`_root_2bejs_1`,horizontal:`_horizontal_2bejs_5`,list:`_list_2bejs_7`,item:`_item_2bejs_9`,vertical:`_vertical_2bejs_13`,compact:`_compact_2bejs_15`,head:`_head_2bejs_21`,marker:`_marker_2bejs_39`,ring:`_ring_2bejs_41`,disc:`_disc_2bejs_43`,glyph:`_glyph_2bejs_45`,icon:`_icon_2bejs_47`,connector:`_connector_2bejs_61`,fill:`_fill_2bejs_69`,text:`_text_2bejs_79`,label:`_label_2bejs_85`,slot:`_slot_2bejs_93`,slotInner:`_slotInner_2bejs_95`,description:`_description_2bejs_97`,error:`_error_2bejs_97`,caption:`_caption_2bejs_105`,captionLabel:`_captionLabel_2bejs_107`,srOnly:`_srOnly_2bejs_125`},X=t(n(),1),Z=r(),We=e=>`blur(${e}px)`,Q={duration:0},Ge={duration:k.duration.fast,ease:[...k.ease.standard]},Ke={duration:k.duration.standard,ease:[...k.ease.enter]},qe={opacity:0,y:`0.3em`,filter:We(k.blur.soft)},Je={opacity:1,y:0,filter:We(0)},Ye={opacity:0,y:`-0.3em`,filter:We(k.blur.subtle)},Xe={opacity:0,scale:.5,filter:We(k.blur.subtle)},Ze={opacity:1,scale:1,filter:We(0)};function Qe({text:e,className:t,reduced:n}){let r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=L(`auto`);return(0,X.useLayoutEffect)(()=>{i.current=performance.now()+700},[e]),(0,X.useEffect)(()=>{let e=r.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver>`u`)return;let o=!1,s=new ResizeObserver(()=>{let t=e.offsetHeight;if(!o||n||performance.now()>i.current){o=!0,a.jump(t);return}H(a,t,k.spring.smooth)});return s.observe(e),()=>s.disconnect()},[a,n]),(0,Z.jsx)(V.span,{className:Y.slot,style:{height:a},children:(0,Z.jsx)(`span`,{ref:r,className:Y.slotInner,children:(0,Z.jsx)(P,{mode:`popLayout`,initial:!1,children:e?(0,Z.jsx)(V.span,{className:t,initial:qe,animate:Je,exit:{...Ye,transition:n?Q:Ge},transition:n?Q:Ke,children:e},`${t}:${e}`):null})})})}function $e({kind:e,number:t,delay:n,reduced:r}){let i=r?Q:{scale:{...k.spring.snappy,delay:n},opacity:{duration:k.duration.fast,delay:n},filter:{duration:k.duration.fast,delay:n}},a={...Xe,transition:r?Q:Ge},o=r?Q:{duration:k.duration.standard,ease:k.ease.enter,delay:n+.04};return e===`number`?(0,Z.jsx)(V.span,{className:Y.glyph,initial:Xe,animate:Ze,exit:a,transition:i,children:t}):(0,Z.jsx)(V.svg,{className:`${Y.glyph} ${Y.icon}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2.5,strokeLinecap:`round`,strokeLinejoin:`round`,initial:Xe,animate:Ze,exit:a,transition:i,children:e===`check`?(0,Z.jsx)(V.path,{d:`M5.5 12.5l4.25 4.25L18.5 8`,initial:{pathLength:0},animate:{pathLength:1},transition:o}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:o}),(0,Z.jsx)(V.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:r?Q:{...k.spring.snappy,delay:n+.16}})]})})}function et({number:e,kind:t,current:n,glyphDelay:r,ringDelay:i,reduced:a}){return(0,Z.jsxs)(`span`,{className:Y.marker,"aria-hidden":`true`,children:[(0,Z.jsx)(P,{initial:!1,children:n?(0,Z.jsx)(V.span,{className:Y.ring,initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:a?Q:Ge},transition:a?Q:{scale:{...k.spring.snappy,delay:i},opacity:{duration:k.duration.fast,delay:i}}},`ring`):null}),(0,Z.jsx)(`span`,{className:Y.disc,children:(0,Z.jsx)(P,{initial:!1,children:(0,Z.jsx)($e,{kind:t,number:e,delay:r,reduced:a},t)})})]})}var tt={complete:`Completed`,current:``,upcoming:`Not started`,error:`Error`};function nt({steps:e,current:t,orientation:n=`horizontal`,onStepSelect:r,details:i=`all`,compact:a=!1,label:o=`Progress`,completeLabel:s=`All steps complete`,className:c}){let l=j()??!1,u=e.length,d=Math.min(Math.max(Math.round(t),0),u),[f,p]=(0,X.useState)({to:d,from:d});f.to!==d&&p({to:d,from:f.to});let m=f.from,h=k.stagger.line,g=e=>l?0:d>m?e>=m&&e<d?(e-m)*h:0:e>=d&&e<m?(m-1-e)*h:0,_=l?0:Math.max(0,Math.abs(d-m)-1)*h+.12,v=!!r,y=n===`vertical`,b=d>=u?void 0:e[d];function x(e){let t=!y&&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 S=v?`nav`:`div`,C=[Y.root,y?Y.vertical:Y.horizontal,a?Y.compact:``,c].filter(Boolean).join(` `);return(0,Z.jsxs)(S,{className:C,"aria-label":o,role:v?void 0:`group`,children:[(0,Z.jsx)(`ol`,{className:Y.list,style:y?void 0:{gridTemplateColumns:u>1?`repeat(${u-1}, minmax(0, 1fr)) auto`:`auto`},onKeyDown:v?x:void 0,children:e.map((e,t)=>{let a=t===d,o=e.error?`error`:t<d?`complete`:a?`current`:`upcoming`,s=v&&t<d,c=e.error??(i===`all`||a?e.description:void 0),f=e.error?`error`:t<d?`check`:`number`,p=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(et,{number:t+1,kind:f,current:a,glyphDelay:g(t),ringDelay:_,reduced:l}),(0,Z.jsxs)(`span`,{className:Y.text,children:[(0,Z.jsx)(`span`,{className:Y.label,children:e.label}),tt[o]?(0,Z.jsxs)(`span`,{className:Y.srOnly,children:[`, `,tt[o]]}):null,(0,Z.jsx)(Qe,{text:c,className:e.error?Y.error:Y.description,reduced:l})]})]});return(0,Z.jsxs)(`li`,{className:Y.item,"data-status":o,children:[t<u-1?(0,Z.jsx)(`span`,{className:Y.connector,"aria-hidden":`true`,children:(0,Z.jsx)(V.span,{className:Y.fill,initial:!1,animate:y?{scaleY:+(t<d)}:{scaleX:+(t<d)},transition:l?Q:{...k.spring.smooth,delay:g(t)}},n)}):null,v?(0,Z.jsx)(`button`,{type:`button`,className:Y.head,"data-clickable":s||void 0,"data-reachable":t<=d||void 0,"aria-current":a?`step`:void 0,"aria-disabled":!s||void 0,tabIndex:s?void 0:-1,onClick:s?()=>r?.(t):void 0,children:p}):(0,Z.jsx)(`span`,{className:Y.head,"aria-current":a?`step`:void 0,children:p})]},e.id)})}),y?null:(0,Z.jsxs)(`span`,{className:Y.caption,"aria-hidden":`true`,children:[(0,Z.jsx)(Qe,{text:b?.label??s,className:Y.captionLabel,reduced:l}),(0,Z.jsx)(Qe,{text:b?.error??b?.description,className:b?.error?Y.error:Y.description,reduced:l})]}),(0,Z.jsx)(`span`,{className:Y.srOnly,"aria-live":`polite`,children:b?`Step ${d+1} of ${u}: ${b.label}`:s})]})}var rt=e=>e===`aws-sigv4`||e===`gcp-service-account`;function it(e){try{let t=new URL(e??``).hostname.toLowerCase();if(!/\.(amazonaws\.com|api\.aws)$/.test(t))return null;let n=t.split(`.`).at(-3);return n&&/^[a-z]{2,}(-[a-z0-9]+)+$/.test(n)?n:null}catch{return null}}function at(e){try{let t=JSON.parse(e);return typeof t.client_email!=`string`||typeof t.private_key!=`string`||t.type!==void 0&&t.type!==`service_account`?null:{email:t.client_email,projectId:typeof t.project_id==`string`?t.project_id:``}}catch{return null}}function ot(e,t,n){let r=e.trim(),i=t.trim();if(!r||!i)return``;let a=n.trim();return JSON.stringify({accessKeyId:r,secretAccessKey:i,...a?{sessionToken:a}:{}})}function st({onChange:e}){let{t}=U(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``);return(0,X.useEffect)(()=>e(ot(n,i,o)),[n,i,o,e]),(0,Z.jsxs)(`div`,{className:`grid gap-3 font-sans`,children:[(0,Z.jsx)(y,{label:t(`providers.cloud.aws.accessKeyId`),children:(0,Z.jsx)(f,{mono:!0,autoComplete:`off`,spellCheck:!1,placeholder:`AKIA…`,value:n,onChange:e=>r(e.target.value)})}),(0,Z.jsx)(y,{label:t(`providers.cloud.aws.secretAccessKey`),hint:t(`providers.apiKeyHint`),children:(0,Z.jsx)(f,{mono:!0,type:`password`,autoComplete:`off`,value:i,onChange:e=>a(e.target.value)})}),(0,Z.jsx)(y,{label:t(`providers.cloud.aws.sessionToken`),hint:t(`providers.cloud.aws.sessionTokenHint`),children:(0,Z.jsx)(f,{mono:!0,type:`password`,autoComplete:`off`,value:o,onChange:e=>s(e.target.value)})})]})}function ct({endpoints:e}){let{t}=U(),n=it(e[0]?.baseUrl);return(0,Z.jsx)(`div`,{className:`mt-2 font-sans text-[12px] text-[var(--text-muted)]`,children:n?t(`providers.cloud.aws.region`,{region:n}):t(`providers.cloud.aws.regionUnknown`)})}var lt=[`global`,`us`,`eu`,`us-central1`,`us-east1`,`us-east4`,`us-east5`,`us-south1`,`us-west1`,`us-west4`,`northamerica-northeast1`,`europe-west1`,`europe-west4`,`europe-west9`,`asia-northeast1`,`asia-southeast1`,`australia-southeast1`,`southamerica-east1`];function ut({project:e,location:t,projectPlaceholder:n,onChange:r}){let{t:i}=U(),a=lt.includes(t)||t===``?lt:[...lt,t];return(0,Z.jsxs)(`div`,{className:`grid gap-3 font-sans sm:grid-cols-2`,children:[(0,Z.jsx)(y,{label:i(`providers.cloud.gcp.project`),hint:i(`providers.cloud.gcp.projectHint`),children:(0,Z.jsx)(f,{mono:!0,autoComplete:`off`,spellCheck:!1,placeholder:n||`my-project-123`,value:e,onChange:e=>r({project:e.target.value,location:t})})}),(0,Z.jsx)(y,{label:i(`providers.cloud.gcp.location`),hint:i(`providers.cloud.gcp.locationHint`),children:(0,Z.jsx)(K,{value:t||`global`,onChange:t=>r({project:e,location:t}),options:a.map(e=>({value:e,label:e}))})})]})}function dt({onChange:e,onFacts:t}){let{t:n}=U(),[r,i]=(0,X.useState)(``),a=(0,X.useRef)(null),o=r.trim()?at(r):null;(0,X.useEffect)(()=>{e(o?r.trim():``),t?.(o)},[r]);let s=async e=>{e&&(i(await e.text()),a.current&&(a.current.value=``))};return(0,Z.jsxs)(`div`,{className:`grid gap-2 font-sans`,children:[(0,Z.jsx)(y,{label:n(`providers.cloud.gcp.keyFile`),hint:r.trim()?void 0:n(`providers.cloud.gcp.keyFileHint`),error:r.trim()&&!o?n(`providers.cloud.gcp.invalid`):void 0,children:(0,Z.jsx)(c,{mono:!0,rows:5,spellCheck:!1,autoComplete:`off`,placeholder:`{ "type": "service_account", … }`,value:r,onChange:e=>i(e.target.value)})}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`input`,{ref:a,type:`file`,accept:`.json,application/json`,className:`hidden`,"aria-label":n(`providers.cloud.gcp.chooseFile`),onChange:e=>void s(e.target.files?.[0])}),(0,Z.jsxs)(v,{size:`sm`,onClick:()=>a.current?.click(),children:[(0,Z.jsx)(xe,{className:`size-3.5`}),n(`providers.cloud.gcp.chooseFile`)]}),o&&(0,Z.jsx)(`span`,{children:n(`providers.cloud.gcp.detected`,{email:o.email})})]})]})}var ft={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},pt={new:`green`,same:`neutral`,sameHost:`orange`,off:`neutral`,skip:`red`},mt=e=>`${e.source}\u0000${e.ref}`,ht=e=>e.status!==`skip`&&e.status!==`same`;function gt(e){try{return new URL(e).host}catch{return e}}function _t({open:e,onOpenChange:t}){let{t:n}=U(),{toast:r}=q(),a=ee(e),o=N(),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(new Set),[d,f]=(0,X.useState)(null);(0,X.useEffect)(()=>{a.data&&u(new Set(a.data.flatMap(e=>e.items).filter(e=>e.status===`new`).map(mt)))},[a.data]),(0,X.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,X.useMemo)(()=>(a.data??[]).flatMap(e=>e.items).filter(e=>l.has(mt(e))&&ht(e)),[a.data,l]),g=(e,t)=>u(n=>{let r=new Set(n);return t?r.add(mt(e)):r.delete(mt(e)),r});return(0,Z.jsx)(fe,{open:e,onOpenChange:t,width:680,title:n(`import.title`),description:n(`import.detail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{icon:(0,Z.jsx)(Te,{className:`size-3.5`}),onClick:()=>void a.refetch(),disabled:a.isFetching||o.isPending,children:n(`import.rescan`)}),(0,Z.jsx)(v,{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 i=e.skipped.length;r(i>0?n(`import.doneSkipped`,{count:e.added.length,skipped:i}):n(`import.done`,{count:e.added.length})),t(!1)},onError:e=>{f(G(e)),a.refetch()}})},children:n(`import.selected`,{count:h.length})})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(i,{value:s,onChange:c,placeholder:n(`import.search`)}),d&&(0,Z.jsx)(C,{tone:`danger`,title:n(`common.error`),children:d}),a.isLoading&&(0,Z.jsx)(w,{lines:3}),a.isError&&(0,Z.jsx)(C,{tone:`danger`,title:n(`common.error`),children:G(a.error)}),(0,Z.jsx)(`div`,{className:`grid max-h-[460px] gap-4 overflow-auto pr-1`,children:a.data?.map(e=>(0,Z.jsx)(vt,{source:e,matches:m,selected:l,onToggle:g,filtering:p.length>0},e.id))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`import.footnote`)})]})})}function vt({source:e,matches:t,selected:n,onToggle:r,filtering:i}){let{t:a}=U(),o=e.items.filter(t);return(0,Z.jsxs)(`section`,{"aria-label":e.name,children:[(0,Z.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline gap-x-2 px-1`,children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:e.name}),e.path&&(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:a(`import.path`,{path:e.path}),children:e.path})]}),e.error?(0,Z.jsx)(C,{tone:`danger`,title:a(`import.sourceError`,{error:e.error})}):e.found?o.length===0?(0,Z.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(i?`import.noMatch`:`import.noItems`)}):(0,Z.jsx)(`ul`,{className:`card divide-y divide-[var(--border)]`,children:o.map(e=>(0,Z.jsx)(yt,{c:e,checked:n.has(mt(e)),onToggle:t=>r(e,t)},mt(e)))}):(0,Z.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`import.notFound`)})]})}function yt({c:e,checked:t,onToggle:n}){let{t:r}=U(),i=ht(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,s=e.endpoints.map(e=>`${ft[e.protocol]??e.protocol} · ${gt(e.baseUrl)}`).join(` / `);return(0,Z.jsxs)(`li`,{className:F(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,Z.jsx)(Ue,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,Z.jsx)(o,{tone:pt[e.status],children:r(`import.status.${e.status}`)}),e.fromApp&&(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.fromApp})]}),s&&(0,Z.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,title:s,children:s}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.hasKey?e.keyMasked??`••••`:r(`import.noKey`)}),(e.keyCount??1)>1&&(0,Z.jsx)(`span`,{children:r(`import.keyCount`,{n:e.keyCount??1})}),e.models.length>0&&(0,Z.jsx)(`span`,{children:r(`import.models`,{count:e.models.length})}),e.templateId&&(0,Z.jsx)(`span`,{children:r(`import.template`,{id:e.templateId})})]}),a&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:a}),e.ignoredFields.length>0&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignoredFields.join(`, `)})})]})]})}function bt({onRestored:e}){let{t}=U(),{toast:n}=q(),r=d(),i=I(),a=oe(),o=h(),s=p(),c=T(),[l,u]=(0,X.useState)(``),[m,g]=(0,X.useState)(``),[_,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(`astra`),[S,w]=(0,X.useState)(`none`),[E,D]=(0,X.useState)(``),[O,k]=(0,X.useState)(null);(0,X.useEffect)(()=>{r.data&&(u(r.data.url),g(r.data.username),x(r.data.folder))},[r.data]);let A=e=>k(G(e)),j=r.data?.configured===!0,M=i.isPending||o.isPending||s.isPending||c.isPending||a.isPending;return(0,Z.jsxs)(`section`,{className:`grid gap-3`,"aria-label":t(`backup.webdav.title`),children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`backup.webdav.title`)}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`backup.webdav.hint`)}),(0,Z.jsx)(f,{"aria-label":t(`backup.webdav.url`),placeholder:`https://dav.example.com/remote.php/dav/files/me`,mono:!0,value:l,onChange:e=>u(e.target.value)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(f,{"aria-label":t(`backup.webdav.username`),placeholder:t(`backup.webdav.username`),autoComplete:`off`,value:m,onChange:e=>g(e.target.value)}),(0,Z.jsx)(f,{type:`password`,autoComplete:`new-password`,"aria-label":t(`backup.webdav.password`),placeholder:r.data?.hasPassword?t(`backup.webdav.passwordKept`):t(`backup.webdav.password`),value:_,onChange:e=>y(e.target.value)})]}),(0,Z.jsx)(f,{"aria-label":t(`backup.webdav.folder`),placeholder:t(`backup.webdav.folder`),mono:!0,value:b,onChange:e=>x(e.target.value)}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(v,{variant:`primary`,disabled:M||l.trim().length===0,onClick:()=>{k(null),i.mutate({url:l,username:m,folder:b,password:_||void 0},{onSuccess:()=>{y(``),n(t(`backup.webdav.saved`))},onError:A})},children:t(`backup.webdav.save`)}),(0,Z.jsx)(v,{disabled:M||!j,onClick:()=>{k(null),o.mutate(void 0,{onSuccess:()=>n(t(`backup.webdav.testOk`)),onError:A})},children:t(`backup.webdav.test`)}),j&&(0,Z.jsx)(v,{disabled:M,onClick:()=>{k(null),a.mutate(void 0,{onSuccess:()=>{u(``),g(``),y(``)},onError:A})},children:t(`backup.webdav.forget`)})]}),j&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:t(`backup.export.secrets`)}),(0,Z.jsx)(K,{className:`w-64`,ariaLabel:t(`backup.export.secrets`),value:S,onChange:e=>w(e),options:[{value:`none`,label:t(`backup.secrets.none`)},{value:`passphrase`,label:t(`backup.secrets.passphrase`)}]})]}),S===`passphrase`&&(0,Z.jsx)(f,{type:`password`,autoComplete:`new-password`,"aria-label":`${t(`backup.webdav.title`)} ${t(`backup.passphrase`)}`,placeholder:t(`backup.passphrase`),value:E,onChange:e=>D(e.target.value)}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(be,{className:`size-3.5`}),disabled:M||S===`passphrase`&&E.length<8,onClick:()=>{k(null),s.mutate({secrets:S,passphrase:S===`passphrase`?E:void 0},{onSuccess:e=>n(t(`backup.webdav.uploadDone`,{count:e.uploaded})),onError:A})},children:t(`backup.webdav.upload`)}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(ye,{className:`size-3.5`}),disabled:M,onClick:()=>{k(null),c.mutate(void 0,{onSuccess:e,onError:A})},children:t(`backup.webdav.restore`)})]})]}),O&&(0,Z.jsx)(C,{tone:`danger`,title:t(`common.error`),children:O})]})}var xt={new:`green`,sameHost:`orange`,same:`neutral`,invalid:`red`},St=e=>e.status===`new`||e.status===`sameHost`;function Ct(e,t){let n=URL.createObjectURL(new Blob([JSON.stringify(t,null,2)],{type:`application/json`})),r=document.createElement(`a`);r.href=n,r.download=e,r.click(),URL.revokeObjectURL(n)}function wt(e){return typeof e==`object`&&!!e&&e.format===`astra-providers`&&Array.isArray(e.providers)}function Tt({open:e,onOpenChange:t}){let{t:n}=U(),{toast:r}=q(),i=O(),a=ae(),o=se(),s=(0,X.useRef)(null),[c,l]=(0,X.useState)(`none`),[u,d]=(0,X.useState)(``),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(null),[S,w]=(0,X.useState)(new Set),[T,E]=(0,X.useState)(null),D=()=>{m(null),i.mutate({secrets:c,passphrase:c===`passphrase`?u:void 0},{onSuccess:e=>{Ct(`astra-providers-${new Date().toISOString().slice(0,10)}.json`,e),r(n(`backup.export.done`,{count:e.providers.length})),d(``)},onError:e=>m(G(e))})},k=(e,t)=>{E(null),a.mutate({file:e,passphrase:e.secrets===`passphrase`?t:void 0},{onSuccess:e=>{x(e),w(new Set(e.items.filter(e=>e.status===`new`).map(e=>e.index)))},onError:e=>{x(null),E(G(e))}})},A=e=>{x(null),E(null),g(e),e.secrets!==`passphrase`&&k(e,``)},j=async e=>{if(x(null),g(null),E(null),e)try{let t=JSON.parse(await e.text());if(!wt(t))throw Error(`not a backup`);g(t),t.secrets!==`passphrase`&&k(t,``)}catch{E(n(`backup.import.badFile`))}},M=()=>{h&&(E(null),o.mutate({file:h,passphrase:h.secrets===`passphrase`?_:void 0,indexes:[...S]},{onSuccess:e=>{r(e.skipped.length>0?n(`backup.import.doneSkipped`,{count:e.added.length,skipped:e.skipped.length}):n(`backup.import.done`,{count:e.added.length})),g(null),x(null),y(``),t(!1)},onError:e=>E(G(e))}))},N=(e,t)=>w(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),P=h?.secrets===`passphrase`&&!b,F=i.isPending||c===`passphrase`&&u.length<8;return(0,Z.jsx)(fe,{open:e,onOpenChange:t,width:640,title:n(`backup.title`),description:n(`backup.detail`),children:(0,Z.jsxs)(`div`,{className:`grid gap-6`,children:[(0,Z.jsxs)(`section`,{className:`grid gap-3`,"aria-label":n(`backup.export.title`),children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:n(`backup.export.title`)}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:n(`backup.export.secrets`)}),(0,Z.jsx)(K,{className:`w-64`,ariaLabel:n(`backup.export.secrets`),value:c,onChange:e=>l(e),options:[{value:`none`,label:n(`backup.secrets.none`)},{value:`passphrase`,label:n(`backup.secrets.passphrase`)},{value:`plaintext`,label:n(`backup.secrets.plaintext`)}]})]}),c!==`none`&&(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`backup.secrets.hint`)}),c===`passphrase`&&(0,Z.jsx)(f,{type:`password`,autoComplete:`new-password`,"aria-label":n(`backup.passphrase`),placeholder:n(`backup.passphrase`),value:u,onChange:e=>d(e.target.value)}),c===`passphrase`&&(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`backup.passphrase.hint`)}),c===`plaintext`&&(0,Z.jsx)(C,{tone:`warning`,title:n(`backup.plaintext.warn`)}),p&&(0,Z.jsx)(C,{tone:`danger`,title:n(`common.error`),children:p}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(Me,{className:`size-3.5`}),disabled:F,onClick:D,children:n(`backup.export.run`)})})]}),(0,Z.jsxs)(`section`,{className:`grid gap-3`,"aria-label":n(`backup.import.title`),children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:n(`backup.import.title`)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`input`,{ref:s,type:`file`,accept:`.json,application/json`,className:`hidden`,"aria-label":n(`backup.import.choose`),onChange:e=>{j(e.target.files?.[0]),e.target.value=``}}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(ke,{className:`size-3.5`}),onClick:()=>s.current?.click(),children:n(`backup.import.choose`)})]}),P&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`backup.import.encrypted`)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(f,{className:`flex-1`,type:`password`,autoComplete:`off`,"aria-label":n(`backup.passphrase`),placeholder:n(`backup.passphrase`),value:_,onChange:e=>y(e.target.value)}),(0,Z.jsx)(v,{disabled:_.length===0||a.isPending,onClick:()=>h&&k(h,_),children:n(`backup.import.preview`)})]})]}),T&&(0,Z.jsx)(C,{tone:`danger`,title:n(`common.error`),children:T}),b&&(0,Z.jsxs)(Z.Fragment,{children:[b.secrets===`none`&&(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`backup.import.noKeys`)}),(0,Z.jsx)(`ul`,{className:`card max-h-[320px] divide-y divide-[var(--border)] overflow-auto`,children:b.items.map(e=>(0,Z.jsx)(Et,{item:e,checked:S.has(e.index),onToggle:t=>N(e.index,t)},e.index))}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{variant:`primary`,disabled:S.size===0||o.isPending,onClick:M,children:n(`backup.import.run`,{count:S.size})})})]})]}),(0,Z.jsx)(bt,{onRestored:A})]})})}function Et({item:e,checked:t,onToggle:n}){let{t:r}=U(),i=St(e);return(0,Z.jsxs)(`li`,{className:F(`flex items-start gap-3 px-4 py-3`,!i&&`opacity-60`),children:[(0,Z.jsx)(Ue,{checked:t&&i,disabled:!i,onCheckedChange:e=>n(e===!0),"aria-label":e.name}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[13px] font-medium`,title:e.name,children:e.name}),(0,Z.jsx)(o,{tone:xt[e.status],children:r(`backup.status.${e.status}`)})]}),e.endpoints&&e.endpoints.length>0&&(0,Z.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--text-muted)]`,children:e.endpoints.map(e=>e.baseUrl).join(` / `)}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[e.hasKey&&(0,Z.jsx)(`span`,{className:`font-mono`,children:e.keyMasked??`••••`}),(0,Z.jsx)(`span`,{children:r(`backup.models`,{count:e.modelCount})})]}),e.existing&&e.status!==`new`&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-muted)]`,children:e.existing.name}),e.error&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--danger)]`,children:e.error}),e.ignored.length>0&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--warning)]`,children:r(`import.ignored`,{fields:e.ignored.join(`, `)})})]})]})}var Dt=`astra.providers.view`,Ot=`astra.providers.charts`;function kt(e){try{return localStorage.getItem(e)}catch{return null}}function At(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function jt(){let[e,t]=(0,X.useState)(()=>kt(Dt)===`table`?`table`:`grid`);return[e,e=>{t(e),At(Dt,e===`table`?`table`:null)}]}function Mt(){let[e,t]=(0,X.useState)(()=>kt(Ot)!==`0`);return[e,e=>{t(e),At(Ot,e?null:`0`)}]}var Nt=5;function Pt(e){return!e.hasApiKey&&e.authScheme!==`none`&&e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`}function Ft(e,t){return e.enabled?Pt(e)?`noKey`:t&&t.requests>=Nt&&t.successRate<.9?`lowSuccess`:`healthy`:`disabled`}var It={healthy:`green`,noKey:`orange`,lowSuccess:`red`,disabled:`neutral`};function Lt(e,t){return t(e===`disabled`?`providers.card.disabled`:e===`noKey`?`providers.noKey`:e===`lowSuccess`?`providers.card.lowSuccess`:`providers.card.active`)}var Rt=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],zt=`var(--text-muted)`;function Bt(e){return e>=.97?`var(--success)`:e>=.9?`var(--warning)`:`var(--danger)`}function Vt({data:e,labels:t,max:n,className:r}){return(0,Z.jsx)(`span`,{className:F(`flex h-[22px] shrink-0 items-end gap-[2px]`,r),title:e.map((e,n)=>`${t[n]}: ${e}`).join(`
2
+ `),children:e.map((e,t)=>(0,Z.jsx)(`i`,{className:`block w-[6px] rounded-t-[2px]`,style:{height:e>0?`${Math.max(14,Math.sqrt(e/Math.max(1,n))*100)}%`:2,background:e>0?`var(--accent)`:`var(--border)`}},t))})}function Ht(e,t,n,r){let i=e.filter(e=>n(e)>0).sort((e,t)=>n(t)-n(e)),a=i.slice(0,Rt.length).map((e,r)=>({key:e.providerId,name:t.get(e.providerId)??e.name??e.providerId,value:n(e),color:Rt[r]})),o=i.slice(Rt.length).reduce((e,t)=>e+n(t),0);return o>0?[...a,{key:`__other`,name:r,value:o,color:zt}]:a}var Ut=[`today`,`7d`,`30d`];function Wt({providers:e,stats:t,stats7d:n,range:r,chartsOpen:i}){let{t:a}=U(),o=new Map(e.map(e=>[e.id,e.name])),s=t.reduce((e,t)=>e+t.requests,0),c=t.reduce((e,t)=>e+t.successRequests,0),l=t.reduce((e,t)=>e+t.costUsd,0),u=t.reduce((e,t)=>e+t.failoversOut,0),d=e.filter(e=>e.enabled).length,f=t.filter(e=>e.requests>0&&o.has(e.providerId)).length,p=Ht(t,o,e=>e.requests,a(`providers.overview.others`)),m=Ht(t,o,e=>e.costUsd,a(`providers.overview.others`)),h=p.filter(e=>e.key!==`__other`),g={healthy:0,noKey:0,lowSuccess:0,disabled:0};for(let t of e)g[Ft(t,n.get(t.id))]++;let _=a(`range.${r}`);return(0,Z.jsxs)(`div`,{className:`mb-3 grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`card px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,Z.jsx)(Gt,{label:a(`providers.overview.requests`),value:M(s,!0),hint:_}),(0,Z.jsx)(Gt,{label:a(`providers.overview.cost`),value:R(l),hint:_}),(0,Z.jsx)(Gt,{label:a(`providers.overview.successRate`),value:s>0?A(c/s):`—`,color:s>0?Bt(c/s):void 0,hint:u>0?a(`providers.overview.failoverCount`,{count:u}):_}),(0,Z.jsx)(Gt,{label:a(`providers.overview.enabled`),value:`${d} / ${e.length}`,hint:a(`providers.overview.withTraffic`,{count:f})})]}),i&&p.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`mt-3 flex h-2.5 overflow-hidden rounded-full bg-[var(--border)]`,"aria-label":a(`providers.overview.share`),children:p.map(e=>(0,Z.jsx)(`span`,{className:`h-full border-r border-[var(--surface)] last:border-r-0`,style:{width:`${e.value/s*100}%`,background:e.color},title:`${e.name}: ${e.value} (${A(e.value/s)})`},e.key))}),(0,Z.jsx)(Jt,{items:p,total:s})]})]}),i&&(0,Z.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1.3fr_1fr_1fr]`,children:[(0,Z.jsx)(Kt,{title:a(`providers.overview.ranking`),hint:_,children:h.length===0?(0,Z.jsx)(qt,{text:a(`providers.overview.noData`)}):(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:h.map(e=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[96px_1fr_44px] items-center gap-2 text-[12px]`,children:[(0,Z.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,Z.jsx)(`span`,{className:`h-2 overflow-hidden rounded-full bg-[var(--border)]`,children:(0,Z.jsx)(`i`,{className:`block h-full rounded-full`,style:{width:`${e.value/h[0].value*100}%`,background:e.color}})}),(0,Z.jsx)(`span`,{className:`num text-right text-[var(--text-secondary)]`,children:M(e.value,!0)})]},e.key))})}),(0,Z.jsx)(Kt,{title:a(`providers.overview.costShare`),hint:R(l),children:m.length===0?(0,Z.jsx)(qt,{text:a(`providers.overview.noCost`)}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(Yt,{items:m,total:l,label:R(l,{compact:!0})}),(0,Z.jsx)(Jt,{items:m,total:l,column:!0})]})}),(0,Z.jsx)(Kt,{title:a(`providers.overview.health`),hint:a(`range.7d`),children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Xt,{tone:`green`,label:a(`providers.overview.healthy`),value:g.healthy}),(0,Z.jsx)(Xt,{tone:`red`,label:a(`providers.overview.lowSuccess`),value:g.lowSuccess}),(0,Z.jsx)(Xt,{tone:`orange`,label:a(`providers.noKey`),value:g.noKey}),(0,Z.jsx)(Xt,{tone:`neutral`,label:a(`providers.card.disabled`),value:g.disabled})]})})]})]})}function Gt({label:e,value:t,hint:n,color:r}){return(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[19px] font-semibold leading-tight`,style:r?{color:r}:void 0,children:t}),n&&(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n})]})}function Kt({title:e,hint:t,children:n}){return(0,Z.jsxs)(`div`,{className:`card min-h-[164px] px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-2.5 flex items-center justify-between gap-2 text-[12px]`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:e}),t&&(0,Z.jsx)(`span`,{className:`num text-[var(--text-muted)]`,children:t})]}),n]})}function qt({text:e}){return(0,Z.jsx)(`div`,{className:`grid h-[110px] place-items-center text-[12px] text-[var(--text-muted)]`,children:e})}function Jt({items:e,total:t,column:n}){return(0,Z.jsx)(`div`,{className:F(`mt-2 flex min-w-0 gap-x-3.5 gap-y-1 text-[11px] text-[var(--text-secondary)]`,n?`mt-0 flex-col`:`flex-wrap`),children:e.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,title:e.name,children:[(0,Z.jsx)(`i`,{className:`size-2 shrink-0 rounded-[2px]`,style:{background:e.color}}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`num shrink-0 text-[var(--text-muted)]`,children:A(e.value/t)})]},e.key))})}function Yt({items:e,total:t,label:n}){let r=0,i=e.map(e=>{let n=r;return r+=e.value/t*360,`${e.color} ${n}deg ${r}deg`}).join(`, `);return(0,Z.jsx)(`div`,{className:`grid size-[104px] shrink-0 place-items-center rounded-full`,style:{background:`conic-gradient(${i})`},children:(0,Z.jsx)(`div`,{className:`num grid size-[70px] place-items-center rounded-full bg-[var(--surface)] text-[12px] font-semibold`,children:n})})}function Xt({tone:e,label:t,value:n}){return(0,Z.jsxs)(`div`,{className:`rounded-lg bg-[color-mix(in_oklab,var(--text)_5%,transparent)] px-2.5 py-2`,children:[(0,Z.jsx)(`div`,{className:`num text-[18px] font-semibold leading-tight`,children:n}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(g,{tone:e}),t]})]})}var Zt={lowSuccess:0,noKey:1,healthy:2,disabled:3};function Qt({providers:e,stats7d:t,usage:n,labels:r,max:i,onOpen:a}){let{t:o}=U(),s=e.map(e=>{let r=t.get(e.id),i=n(e);return{id:e.id,name:e.name,health:Zt[Ft(e,r)],models:e.modelCount,requests:i.reduce((e,t)=>e+t,0),successRate:r&&r.requests>0?r.successRate:-1,ttft:r?.avgTtftMs??-1,tokens:r?r.inputTokens+r.outputTokens:0,cost:r?.costUsd??0,enabled:+!!e.enabled,p:e,stat:r,days:i}}),c=[{key:`name`,label:o(`providers.col.provider`),render:(e,t)=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex w-full min-w-0 items-center gap-2 text-left`,onClick:()=>a(t.p),children:[(0,Z.jsx)(`span`,{className:F(!t.p.enabled&&`opacity-50 grayscale`),children:(0,Z.jsx)(Be,{name:t.p.name,icon:t.p.icon,colorKey:t.p.templateId,size:22})}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:F(`block truncate font-medium hover:text-[var(--accent)]`,!t.p.enabled&&`text-[var(--text-muted)]`),children:t.name}),(0,Z.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-[var(--text-muted)]`,children:en(t.p.endpoints[0]?.baseUrl)??`—`})]})]})},{key:`health`,label:o(`providers.col.status`),width:112,render:(e,t)=>{let n=Ft(t.p,t.stat);return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(g,{tone:It[n]}),Lt(n,o)]})}},{key:`models`,label:o(`providers.col.models`),numeric:!0,width:56},{key:`days`,label:o(`providers.col.trend`),sortable:!1,width:84,render:(e,t)=>(0,Z.jsx)(Vt,{data:t.days,labels:r,max:i})},{key:`requests`,label:o(`providers.col.requests`),numeric:!0,width:80,render:(e,t)=>t.requests?M(t.requests,!0):`—`},{key:`successRate`,label:o(`providers.col.successRate`),width:124,render:(e,t)=>t.successRate<0?(0,Z.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`—`}):(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:[(0,Z.jsx)(`span`,{className:`h-[5px] w-10 overflow-hidden rounded-full bg-[var(--border)]`,children:(0,Z.jsx)(`i`,{className:`block h-full`,style:{width:`${t.successRate*100}%`,background:Bt(t.successRate)}})}),(0,Z.jsx)(`span`,{className:`num text-[12px]`,children:A(t.successRate)})]})},{key:`ttft`,label:o(`providers.col.ttft`),numeric:!0,width:92,render:(e,t)=>(0,Z.jsx)($t,{children:t.ttft<0?`—`:B(t.ttft)})},{key:`tokens`,label:o(`providers.col.tokens`),numeric:!0,width:128,render:(e,t)=>(0,Z.jsx)($t,{children:t.stat&&t.tokens>0?`${M(t.stat.inputTokens,!0)} / ${M(t.stat.outputTokens,!0)}`:`—`})},{key:`cost`,label:o(`providers.col.cost`),numeric:!0,width:96,render:(e,t)=>(0,Z.jsx)($t,{children:t.cost>0?R(t.cost):`—`})},{key:`enabled`,label:o(`providers.col.enabled`),width:64,render:(e,t)=>(0,Z.jsx)(tn,{provider:t.p})}];return(0,Z.jsx)(je,{caption:o(`nav.providers`),rowKey:`id`,rows:s,columns:c,defaultSort:{key:`requests`,direction:`desc`}})}var $t=({children:e})=>(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:e});function en(e){if(!e)return null;try{return new URL(e).host}catch{return e}}function tn({provider:e}){let{t}=U(),n=le(e.id),{toast:r}=q();return(0,Z.jsx)(`span`,{className:`ml-1 inline-flex`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(E,{checked:e.enabled,label:t(`common.enabled`),onChange:e=>n.mutate({enabled:e},{onError:e=>r(G(e),`error`)})})})}var nn=e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`,rn=e=>e.category!==`subscription`&&e.category!==`custom`&&e.authScheme!==`oauth-subscription`;function an({open:e,onOpenChange:t,provider:n}){let{t:r}=U(),{toast:i}=q(),o=a(),s=b(n.id),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),f=(o.data??[]).filter(rn);(0,X.useEffect)(()=>{e&&(l(n.templateId??``),d(``))},[e,n.templateId]);let p=f.find(e=>e.id===c),m=p?p.variants?.find(e=>e.id===u)?.endpointsOverride??p.endpoints:[],h=c===n.templateId&&!u;return(0,Z.jsxs)(fe,{open:e,onOpenChange:t,title:r(`providers.templateSwitch`),description:r(`providers.templateSwitchDetail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Z.jsx)(v,{variant:`primary`,disabled:!p||h,loading:s.isPending,onClick:()=>p&&s.mutate({templateId:p.id,variantId:u||null},{onSuccess:()=>{t(!1),i(r(`providers.templateSwitched`,{name:p.name}),`success`)},onError:e=>i(G(e),`error`)}),children:r(`common.apply`)})]}),children:[o.isLoading&&(0,Z.jsx)(w,{}),o.isError&&(0,Z.jsx)(C,{tone:`danger`,title:r(`common.error`),children:G(o.error)}),(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(y,{label:r(`providers.templateSwitchTarget`),children:(0,Z.jsx)(K,{value:c,onChange:e=>{l(e),d(``)},options:f.map(e=>({value:e.id,label:e.id===n.templateId?r(`providers.templateSwitchCurrent`,{name:e.name}):e.name,detail:e.id}))})}),p?.variants&&p.variants.length>0&&(0,Z.jsx)(y,{label:r(`providers.variant`),children:(0,Z.jsx)(K,{value:u,onChange:d,options:[{value:``,label:r(`providers.variantDefault`)},...p.variants.map(e=>({value:e.id,label:e.name}))]})}),p&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:r(`providers.templateSwitchEndpoints`)}),(0,Z.jsx)(`ul`,{className:`grid gap-1 text-[12px]`,children:m.map(e=>(0,Z.jsxs)(`li`,{className:`flex gap-3`,children:[(0,Z.jsx)(`span`,{className:`w-36 shrink-0 text-[var(--text-secondary)]`,children:$.find(t=>t.value===e.protocol)?.label??e.protocol}),(0,Z.jsx)(`span`,{className:`min-w-0 font-mono break-all`,children:e.baseUrl})]},e.protocol))})]})]})]})}function on({provider:e,httpStatus:t,className:n}){return t!==401&&t!==403||!e.templateId||!nn(e)?null:(0,Z.jsx)(sn,{provider:e,className:n})}function sn({provider:e,className:t}){let{t:n}=U(),{toast:r,confirm:i}=q(),o=a(),s=b(e.id),c=o.data?.find(t=>t.id===e.templateId),l=(c?.keyAlternatives??[]).flatMap(e=>o.data?.filter(t=>t.id===e)??[]);if(!c||l.length===0)return null;let u=async e=>{let t=[...new Set(e.endpoints.map(e=>e.baseUrl))].join(`, `);await i({title:n(`providers.templateSwitchConfirm`,{alt:e.name}),detail:n(`providers.templateSwitchConfirmDetail`,{urls:t}),confirmLabel:n(`providers.keyAlternative.switch`,{alt:e.name})})&&s.mutate({templateId:e.id},{onSuccess:()=>r(n(`providers.templateSwitched`,{name:e.name}),`success`),onError:e=>r(G(e),`error`)})};return(0,Z.jsxs)(C,{className:t,tone:`warning`,title:n(`providers.keyAlternative.title`),children:[n(`providers.keyAlternative.rejected`,{name:c.name,alt:l.map(e=>e.name).join(` / `)}),(0,Z.jsx)(`span`,{className:`mt-2 flex flex-wrap gap-2`,children:l.map(e=>(0,Z.jsx)(v,{size:`sm`,loading:s.isPending,onClick:()=>void u(e),children:n(`providers.keyAlternative.switch`,{alt:e.name})},e.id))})]})}var cn=3,ln=256,un=4096,dn=`A small red circle on a white background.`,fn=`Change the red circle to blue. Keep everything else the same.`;function pn(e){let t=e.slice(e.lastIndexOf(`/`)+1).toLowerCase();return t.startsWith(`gpt-image`)||t.startsWith(`chatgpt-image`)||t.startsWith(`dall-e`)}var mn={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 hn(e){let t=e.endpoints.map(e=>e.protocol);return e.preferredUpstreamProtocols.find(e=>t.includes(e))??t[0]??`openai-chat`}var gn=e=>typeof e==`number`?e:null,_n=e=>typeof e==`string`?e:null;function vn({provider:e,open:t,onOpenChange:n}){let{t:r}=U(),i=x(),a=ie(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,X.useState)(`single`),[l,d]=(0,X.useState)(()=>hn(e)),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(ln),[b,S]=(0,X.useState)({size:``,quality:``,count:1,operation:`generate`,input:null}),[C,w]=(0,X.useState)(``),T=(0,X.useRef)(C);T.current=C;let[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)({}),[A,j]=(0,X.useState)([]),[M,N]=(0,X.useState)(new Set),[P,F]=(0,X.useState)([]),[ee,te]=(0,X.useState)(``),[I,ne]=(0,X.useState)(null),[L,R]=(0,X.useState)(!1),z=(0,X.useRef)(null),re=(0,X.useRef)(new Map),B=(0,X.useRef)(!1),V=(0,X.useRef)(!1),H=(0,X.useMemo)(()=>{let e=[...a.data??[]].sort((e,t)=>Number(t.enabled)-Number(e.enabled)||e.sortOrder-t.sortOrder).map(e=>e.modelId);return[...e,...P.filter(t=>!e.includes(t))]},[a.data,P]);(0,X.useEffect)(()=>{if(t){let e=T.current||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``;!T.current&&e&&pn(e)&&d(`openai-images`),w(e);return}V.current=!1,z.current?.abort();for(let e of re.current.values())e.abort();re.current.clear(),D(null),k({}),j([]),N(new Set),F([]),te(``),ne(null)},[t,a.data]);let ae=(0,X.useCallback)((t,n=!1)=>pn(t)||!n&&l===`openai-images`?{modelId:t,protocol:`openai-images`,prompt:m.trim()||null,imageOperation:b.operation,...b.operation===`edit`&&b.input?{imageInput:b.input.data}:{},imageSize:b.size.trim()||null,imageQuality:b.quality||null,imageCount:b.count,imagePreview:!n}:{modelId:t,protocol:l===`openai-images`?hn(e):l,stream:f,prompt:m.trim()||null,maxOutputTokens:g??ln},[l,f,m,g,b,e]),oe=(0,X.useCallback)((t,n,r,i=!1)=>Nn(e.id,t,ae(t,i),n,r),[e.id,ae]),se=t=>{w(t),pn(t)?d(`openai-images`):l===`openai-images`&&d(hn(e))},ce=()=>{let e=C.trim();if(!e)return;z.current?.abort();let t=new AbortController;z.current=t,V.current=!0,ne(null),D({modelId:e,status:`running`,text:``,reasoning:``}),oe(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&ue(),D(e)})},le=e=>{if(e.length===0)return;V.current=!0,B.current=!1,ne(null),j(e),k(Object.fromEntries(e.map(e=>[e,{modelId:e,status:`queued`,text:``,reasoning:``}])));let t=0;Promise.all(Array.from({length:Math.min(cn,e.length)},async()=>{for(;;){if(!V.current)return;let n=e[t++];if(n===void 0)return;if(B.current){k(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;re.current.set(n,r),await oe(n,r.signal,e=>k(t=>({...t,[n]:e})),!0),re.current.delete(n),ue()}}))},ue=()=>void i.invalidateQueries({queryKey:[`requests`]}),de=()=>{B.current=!0,k(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},W=E?.status===`running`||A.some(e=>O[e]?.status===`running`||O[e]?.status===`queued`&&!B.current),pe=A.filter(e=>O[e]&&O[e].status!==`queued`&&O[e].status!==`running`).length,G=A.filter(e=>O[e]?.status===`success`).length,K=A.filter(e=>O[e]?.status===`failed`).length,q=(e,t)=>N(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),me=()=>{W||n(!1)},ge=e=>e.stopPropagation();return(0,Z.jsx)(`span`,{onClick:ge,onKeyDown:ge,children:(0,Z.jsxs)(fe,{open:t,onOpenChange:e=>e?n(!0):me(),width:1040,title:r(`providers.testDialog.title`,{name:e.name}),description:r(`providers.testDialog.subtitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`mr-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.realRequest`)}),(0,Z.jsx)(v,{disabled:W,onClick:()=>n(!1),icon:(0,Z.jsx)(Ae,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?W?(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(De,{className:`size-3.5`}),onClick:()=>z.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,Z.jsx)(v,{variant:`primary`,disabled:C.trim()===``,icon:(0,Z.jsx)(Se,{className:`size-3.5`}),onClick:ce,children:r(E?`providers.testDialog.retest`:`providers.testDialog.start`)}):W?(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(De,{className:`size-3.5`}),onClick:de,children:r(`providers.testDialog.stopRest`)}):(0,Z.jsx)(v,{variant:`primary`,disabled:M.size===0,icon:(0,Z.jsx)(Se,{className:`size-3.5`}),onClick:()=>le([...M]),children:r(`providers.testDialog.testN`,{count:M.size})})]}),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-4`,children:[(0,Z.jsx)(Be,{name:e.name,icon:e.icon,colorKey:e.templateId,size:32}),(0,Z.jsx)(u,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),ne(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,300px)_minmax(0,1fr)] gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 border-r border-[var(--border)] pr-6`,children:[(0,Z.jsx)(`h3`,{className:`text-[13px] font-medium`,children:r(`providers.testDialog.config`)}),(0,Z.jsx)(y,{label:r(`providers.testDialog.model`),children:(0,Z.jsx)(yn,{value:C,models:H,onChange:se})}),(0,Z.jsx)(Tn,{protocols:o,protocol:l,onProtocol:d,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h,image:b,onImage:S}),(0,Z.jsx)(`p`,{className:`mt-auto text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.savedCredentials`)})]}),(0,Z.jsx)(Dn,{provider:e,run:E,onRetest:ce})]}):I===null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(jn,{known:H,selected:M,onToggle:q,onSelectAll:e=>N(e?new Set(H):new Set),onClear:()=>N(new Set),search:ee,onSearch:te,onAdd:e=>{F(t=>t.includes(e)?t:[...t,e]),N(t=>new Set(t).add(e)),te(``)},configOpen:L,onConfigOpen:R,protocols:o,protocol:l,onProtocol:d,stream:f,onStream:p,maxTokens:g,onMaxTokens:_,prompt:m,onPrompt:h,image:b,onImage:S,batch:!0,hasImageModels:H.some(pn)}),A.length>0?(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:W?r(`providers.testDialog.progress`,{done:pe,total:A.length,ok:G,failed:K}):r(`providers.testDialog.progressDone`,{total:A.length,ok:G,failed:K})}),(0,Z.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-strong)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-[width]`,style:{width:`${pe/A.length*100}%`,background:`var(--accent)`}})})]}):null,A.length>0?(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(Mn,{order:A,runs:O,onView:ne})}):null]}):(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(v,{variant:`plain`,icon:(0,Z.jsx)(he,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>ne(null)}),(0,Z.jsx)(`span`,{className:`font-mono text-[13px]`,children:I})]}),(0,Z.jsx)(Dn,{provider:e,run:O[I]??null})]})]})})}function yn({value:e,models:t,onChange:n}){let{t:r}=U(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(0),[c,l]=(0,X.useState)(null),u=c===null?t:t.filter(e=>e.toLowerCase().includes(c.trim().toLowerCase())),d=()=>{l(null),s(Math.max(0,t.indexOf(e))),a(!0)},p=e=>{n(e),l(null),a(!1)};return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(f,{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]&&p(u[o])):e.key===`Escape`&&a(!1)}}),(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-y-0 right-0 grid w-8 place-items-center text-[var(--text-muted)] hover:text-[var(--text)]`,"aria-label":r(`providers.testDialog.showModels`),onClick:()=>i?a(!1):d(),children:(0,Z.jsx)(_e,{className:`size-4`})}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-40`,onMouseDown:()=>a(!1)}),(0,Z.jsx)(`ul`,{className:`absolute inset-x-0 top-full z-50 mt-1 max-h-64 overflow-auto rounded-lg border border-[var(--border)] bg-[var(--surface-raised)] py-1 shadow-lg`,children:u.length===0?(0,Z.jsx)(`li`,{className:`px-3 py-2 text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noModels`)}):u.map((e,t)=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`button`,{type:`button`,className:F(`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(),p(e)},children:e})},e))})]})]})}var bn=4194304,xn=[`image/png`,`image/jpeg`,`image/webp`],Sn=[`auto`,`1024x1024`,`1536x1024`,`1024x1536`,`512x512`,`256x256`],Cn=[`auto`,`low`,`medium`,`high`,`standard`,`hd`],wn=4;function Tn({protocols:e,batch:t=!1,hasImageModels:n=!1,...r}){let{t:i}=U(),a=e.map(e=>({value:e,label:$.find(t=>t.value===e)?.label??e}));!t&&e.some(e=>e===`openai-chat`||e===`openai-responses`)&&a.push({value:`openai-images`,label:`OpenAI Images`});let o=!t&&r.protocol===`openai-images`,s=e=>r.onImage({...r.image,...e}),l=r.image.operation===`edit`,d=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{label:i(`providers.testDialog.imageOperation`),hint:l?i(`providers.testDialog.imageEditHint`):void 0,children:(0,Z.jsx)(u,{items:[{value:`generate`,label:i(`providers.testDialog.imageGenerate`)},{value:`edit`,label:i(`providers.testDialog.imageEdit`)}],value:r.image.operation,onChange:e=>s({operation:e}),ariaLabel:i(`providers.testDialog.imageOperation`)})}),l?(0,Z.jsx)(En,{value:r.image.input,onChange:e=>s({input:e})}):null,(0,Z.jsxs)(y,{label:i(`providers.testDialog.imageSize`),hint:i(`providers.testDialog.imageSizeHint`),children:[(0,Z.jsx)(f,{className:`font-mono`,list:`provider-test-image-sizes`,value:r.image.size,placeholder:`1024x1024`,"aria-label":i(`providers.testDialog.imageSize`),onChange:e=>s({size:e.target.value})}),(0,Z.jsx)(`datalist`,{id:`provider-test-image-sizes`,children:Sn.map(e=>(0,Z.jsx)(`option`,{value:e},e))})]}),(0,Z.jsx)(y,{label:i(`providers.testDialog.imageQuality`),children:(0,Z.jsx)(K,{value:r.image.quality,onChange:e=>s({quality:e}),options:[{value:``,label:i(`providers.testDialog.imageDefault`)},...Cn.map(e=>({value:e,label:e}))]})}),(0,Z.jsx)(y,{label:i(`providers.testDialog.imageCount`),children:(0,Z.jsx)(S,{value:r.image.count,min:1,placeholder:`1`,label:i(`providers.testDialog.imageCount`),onChange:e=>s({count:e===null?1:Math.min(wn,Math.max(1,Math.round(e)))})})})]}),p=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.testDialog.stream`)}),(0,Z.jsx)(E,{checked:r.stream,label:i(`providers.testDialog.stream`),onChange:r.onStream})]}),(0,Z.jsx)(y,{label:i(`providers.testDialog.maxTokens`),children:(0,Z.jsx)(S,{value:r.maxTokens,min:1,placeholder:String(ln),label:i(`providers.testDialog.maxTokens`),onChange:e=>r.onMaxTokens(e===null?null:Math.min(un,Math.max(1,Math.round(e))))})})]});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{label:i(`providers.testDialog.protocol`),hint:t&&n?i(`providers.testDialog.batchAutoHint`):void 0,children:(0,Z.jsx)(K,{value:r.protocol,onChange:r.onProtocol,options:a})}),t?(0,Z.jsxs)(Z.Fragment,{children:[p,n?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h4`,{className:`pt-1 text-[12px] font-medium`,children:i(`providers.testDialog.imageSection`)}),d]}):null]}):o?d:p,(0,Z.jsx)(y,{label:i(`providers.testDialog.prompt`),hint:i(`providers.testDialog.promptHint`),children:(0,Z.jsx)(c,{rows:4,value:r.prompt,placeholder:o?l?fn:dn:`Reply with OK.`,onChange:e=>r.onPrompt(e.target.value)})})]})}function En({value:e,onChange:t}){let{t:n}=U(),r=(0,X.useRef)(null),[i,a]=(0,X.useState)(null),o=e=>{if(!e)return;if(!xn.includes(e.type))return a(n(`providers.testDialog.imageInputType`));if(e.size>bn)return a(n(`providers.testDialog.imageInputTooLarge`));let r=new FileReader;r.onerror=()=>a(n(`providers.testDialog.imageInputUnreadable`)),r.onload=()=>{let n=String(r.result);a(null),t({name:e.name,bytes:e.size,data:n.slice(n.indexOf(`,`)+1),preview:n})},r.readAsDataURL(e)};return(0,Z.jsxs)(y,{label:n(`providers.testDialog.imageInput`),hint:i??void 0,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e?(0,Z.jsx)(`img`,{src:e.preview,alt:``,className:`size-12 shrink-0 rounded-md border border-[var(--border)] object-cover`}):(0,Z.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center rounded-md border border-[var(--border)] bg-white`,children:(0,Z.jsx)(`span`,{className:`size-7 rounded-full bg-[#ff2020]`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[12px]`,title:e?.name,children:e?e.name:n(`providers.testDialog.imageInputDefault`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e?`${(e.bytes/1024).toFixed(+(e.bytes<10240))} KB`:n(`providers.testDialog.imageInputLimits`)})]}),(0,Z.jsx)(`input`,{ref:r,type:`file`,hidden:!0,accept:xn.join(`,`),"aria-label":n(`providers.testDialog.imageInput`),onChange:e=>{o(e.target.files?.[0]),e.target.value=``}}),(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(Ce,{className:`size-3.5`}),onClick:()=>r.current?.click(),children:n(`providers.testDialog.imageInputPick`)}),e?(0,Z.jsx)(v,{size:`sm`,variant:`plain`,onClick:()=>(a(null),t(null)),children:n(`providers.testDialog.imageInputReset`)}):null]}),i?(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-[var(--danger)]`,children:i}):null]})}function Dn({provider:e,run:t,onRetest:n}){let{t:r}=U(),[i,a]=(0,X.useState)(`preview`),s=t?.text??``,c=t?.raw??``,l=Object.entries(t?.headers??{}),d=t?.ttftMs!=null&&t?.httpMs!=null?Math.max(0,t.ttftMs-t.httpMs):null,f=i===`raw`?c:i===`headers`?l.map(([e,t])=>`${e}: ${t}`).join(`
3
+ `):s;return(0,Z.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n&&t&&t.status!==`running`?(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(Se,{className:`size-3.5`}),onClick:n,children:r(`providers.testDialog.retest`)}):null,(0,Z.jsx)(Ve,{content:r(`providers.testDialog.metricsHelp`),children:(0,Z.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center text-[var(--text-muted)]`,tabIndex:0,children:(0,Z.jsx)(J,{className:`size-4`})})}),(0,Z.jsx)(An,{run:t}),t?.httpStatus?(0,Z.jsxs)(o,{tone:`neutral`,children:[`HTTP `,t.httpStatus]}):null]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-px overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--border)] sm:grid-cols-4`,children:[(0,Z.jsx)(kn,{label:r(`providers.testDialog.metrics.http`),value:t?.httpMs}),(0,Z.jsx)(kn,{label:r(`providers.testDialog.metrics.firstWait`),value:d}),(0,Z.jsx)(kn,{label:r(`providers.testDialog.metrics.ttft`),value:t?.ttftMs}),(0,Z.jsx)(kn,{label:r(`providers.testDialog.metrics.total`),value:t?.totalMs})]}),(0,Z.jsxs)(`section`,{className:`card overflow-hidden`,children:[(0,Z.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-[var(--border)] px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[12px] font-medium`,children:r(`providers.testDialog.reply`)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,Z.jsx)(u,{items:[{value:`preview`,label:r(`providers.testDialog.preview`)},{value:`raw`,label:r(`providers.testDialog.raw`)},{value:`headers`,label:r(`providers.testDialog.headers`)}],value:i,onChange:a,ariaLabel:r(`providers.testDialog.reply`)}),(0,Z.jsx)(D,{value:f,label:r(i===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,Z.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:i===`headers`?l.length===0?(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.headersEmpty`)}):(0,Z.jsx)(`table`,{className:`w-full text-[11px]`,children:(0,Z.jsx)(`tbody`,{children:l.map(([e,t])=>(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0 align-top`,children:[(0,Z.jsx)(`th`,{className:`w-[220px] py-1.5 pr-4 text-left font-mono font-normal text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`py-1.5 font-mono break-all whitespace-pre-wrap selectable`,children:t})]},e))})}):i===`raw`?c?(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsxs)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:[r(`providers.testDialog.rawNote`),t?.contentType?` · ${t.contentType}`:``]}),(0,Z.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] break-all whitespace-pre-wrap selectable`,children:c}),t?.rawTruncated?(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--warning)]`,children:r(`providers.testDialog.rawTruncated`)}):null]}):(0,Z.jsx)(On,{run:t}):t?.error?(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsx)(C,{tone:`danger`,title:r(`providers.testDialog.status.failed`),children:t.error}),(0,Z.jsx)(on,{provider:e,httpStatus:t.httpStatus})]}):s||t?.reasoning||t?.images?.length?(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[t?.reasoning?(0,Z.jsxs)(`div`,{className:`rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-3`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[11px] text-[var(--text-muted)]`,children:r(`providers.testDialog.reasoning`)}),(0,Z.jsx)(`pre`,{className:`font-mono text-[11px] leading-[1.6] whitespace-pre-wrap selectable`,children:t.reasoning})]}):null,s?(0,Z.jsx)(`pre`,{className:`font-mono text-[12px] leading-[1.7] break-words whitespace-pre-wrap selectable`,children:s}):null,t?.images?.length?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:t.images.map((e,t)=>{let n=`data:${e.mime};base64,${e.data}`;return(0,Z.jsxs)(`figure`,{className:`grid gap-1.5`,children:[(0,Z.jsx)(`img`,{src:n,alt:r(`providers.testDialog.imageAlt`,{n:t+1}),className:`max-h-[420px] max-w-full self-start rounded-md border border-[var(--border)] object-contain`}),(0,Z.jsx)(`a`,{className:`self-start text-[11px] text-[var(--accent)]`,href:n,download:`astra-test-${t+1}.${e.mime===`image/jpeg`?`jpg`:e.mime===`image/webp`?`webp`:`png`}`,children:r(`providers.testDialog.imageSave`)})]},t)})}):null]}):t?.status===`success`?(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`providers.testDialog.noText`)}):(0,Z.jsx)(On,{run:t})})]})]})}function On({run:e}){let{t}=U();return e?.status===`running`||e?.status===`queued`?(0,Z.jsx)(`div`,{className:`grid h-full place-items-center text-[12px] text-[var(--text-muted)]`,children:t(mn[e.status])}):(0,Z.jsxs)(`div`,{className:`grid h-full place-items-center content-center gap-2 text-center`,children:[(0,Z.jsx)(Ie,{className:`mx-auto size-6 text-[var(--text-muted)]`}),(0,Z.jsx)(`div`,{className:`text-[13px]`,children:t(`providers.testDialog.emptyTitle`)}),(0,Z.jsx)(`p`,{className:`mx-auto max-w-[320px] text-[11px] text-[var(--text-muted)]`,children:t(`providers.testDialog.emptyDetail`)})]})}function kn({label:e,value:t}){return(0,Z.jsxs)(`div`,{className:`bg-[var(--surface)] px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[15px] tabular-nums`,children:t==null?`—`:B(t)})]})}function An({run:e}){let{t}=U(),n=e?.status??`idle`;return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(g,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(mn[n])]})}function jn({known:e,selected:t,onToggle:n,onSelectAll:r,onClear:a,search:o,onSearch:s,onAdd:c,configOpen:l,onConfigOpen:u,...d}){let{t:f}=U(),p=o.trim(),m=p.toLowerCase(),h=m?e.filter(e=>e.toLowerCase().includes(m)):e,g=p!==``&&!e.some(e=>e.toLowerCase()===m);return(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[12px] text-[var(--text-secondary)]`,children:f(`providers.testDialog.selected`,{n:t.size,total:e.length})}),(0,Z.jsx)(`div`,{className:`min-w-[220px] flex-1`,children:(0,Z.jsx)(i,{value:o,onChange:s,placeholder:f(`providers.testDialog.searchModels`)})}),(0,Z.jsx)(v,{variant:`plain`,disabled:t.size===0,onClick:a,children:f(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(Se,{className:`size-3.5`}),onClick:()=>u(!0),children:f(`providers.testDialog.config`)})]}),(0,Z.jsx)(`div`,{className:`card max-h-[420px] overflow-auto`,children:h.length===0&&!g?(0,Z.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-[var(--text-muted)]`,children:f(`providers.testDialog.noModels`)}):(0,Z.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,Z.jsx)(Ue,{checked:t.size===e.length&&e.length>0||t.size!==0&&`indeterminate`,onCheckedChange:e=>r(e!==!1),"aria-label":f(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:f(`providers.testDialog.ownFilter`)})]}),g?(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Z.jsx)(we,{className:`size-3.5 shrink-0 text-[var(--accent)]`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-left font-mono text-[12px] text-[var(--accent)]`,onClick:()=>c(p),children:f(`providers.testDialog.addModel`,{id:p})})]}):null,h.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,Z.jsx)(Ue,{checked:t.has(e),onCheckedChange:t=>n(e,t!==!1),"aria-label":e}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,title:e,children:e})]},e))]})}),(0,Z.jsx)(fe,{open:l,onOpenChange:u,width:480,title:f(`providers.testDialog.config`),description:f(`providers.testDialog.savedCredentials`),children:(0,Z.jsx)(`div`,{className:`grid gap-4`,children:(0,Z.jsx)(Tn,{...d})})})]})}function Mn({order:e,runs:t,onView:n}){let{t:r}=U();return(0,Z.jsx)(`div`,{className:`card overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border)] text-left text-[11px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.model`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.statusColumn`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.ttft`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.metrics.total`)}),(0,Z.jsx)(`th`,{className:`px-4 py-2 font-normal`,children:r(`providers.testDialog.reply`)})]})}),(0,Z.jsx)(`tbody`,{children:e.map(e=>{let i=t[e];return(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border)] last:border-0`,children:[(0,Z.jsxs)(`td`,{className:`px-4 py-2 font-mono`,children:[e,i?.imageOperation?(0,Z.jsx)(o,{tone:`neutral`,className:`ml-2 align-middle`,children:r(i.imageOperation===`edit`?`providers.testDialog.imageEdit`:`providers.testDialog.imageGenerate`)}):null]}),(0,Z.jsx)(`td`,{className:`px-4 py-2`,children:(0,Z.jsx)(An,{run:i??null})}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.ttftMs==null?`—`:B(i.ttftMs)}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:i?.totalMs==null?`—`:B(i.totalMs)}),(0,Z.jsx)(`td`,{className:`px-4 py-2`,children:(0,Z.jsx)(`button`,{type:`button`,className:`text-[var(--accent)] disabled:text-[var(--text-muted)]`,disabled:!i,onClick:()=>n(e),children:r(`providers.testDialog.view`)})})]},e)})})]})})}async function Nn(e,t,n,r,i){let a={modelId:t,status:`running`,text:``,reasoning:``,...n.protocol===`openai-images`?{imageOperation:n.imageOperation===`edit`?`edit`:`generate`}:{}};i(a);let o=e=>{a={...a,...e},i(a)};try{await s(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:o({httpStatus:gn(t.httpStatus),httpMs:gn(t.httpMs),contentType:_n(t.contentType),headers:Pn(t.headers)});break;case`delta`:{let e=_n(t.text)??``;_n(t.kind)===`reasoning`?o({reasoning:a.reasoning+e}):o({text:a.text+e});break}case`done`:{let t=e.data;o({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,images:t.images??[],contentType:t.contentType??null,headers:Pn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?o({status:`cancelled`,error:null}):o({status:`failed`,error:e instanceof l?e.message:String(e)})}}function Pn(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 Fn=e({AUTH_OPTIONS:()=>In,PROTOCOL_OPTIONS:()=>$,ProvidersPage:()=>Ln}),$=[{value:`openai-chat`,label:`OpenAI Chat`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic`,label:`Anthropic Messages`},{value:`gemini`,label:`Gemini`}],In=[{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:`api-key`,label:`api-key`},{value:`aws-sigv4`,label:`AWS SigV4`},{value:`gcp-service-account`,label:`Google service account`},{value:`none`,label:`—`},{value:`oauth-subscription`,label:`OAuth 订阅`}];function Ln(){let{t:e}=U(),t=Le(),[n,r]=Pe(),i=te(),[a,o]=(0,X.useState)(n.get(`new`)===`1`),[s,c]=(0,X.useState)(!1),[l,d]=(0,X.useState)(!1);(0,X.useEffect)(()=>{n.get(`new`)===`1`&&(o(!0),n.delete(`new`),r(n,{replace:!0}))},[n,r]),Ne(e=>{e===`new-provider`&&o(!0)});let f=m(`7d`,`day`,`provider`),[p,h]=(0,X.useState)(`7d`),g=z(`7d`),y=z(p),[b,x]=jt(),[S,T]=Mt(),[E,D]=(0,X.useState)(null),O=(0,X.useMemo)(()=>{let e=zn(Rn),t=new Map,n=0;for(let r of f.data??[]){let i=e.indexOf(r.bucket);if(i<0)continue;let a=t.get(r.key);a||t.set(r.key,a={requests:e.map(()=>0),costUsd:0}),a.requests[i]=(a.requests[i]??0)+r.requests,a.costUsd+=r.costUsd,n=Math.max(n,a.requests[i])}return{days:e,labels:e.map(e=>e.slice(5)),byProvider:t,max:n}},[f.data]),k=(0,X.useMemo)(()=>new Map((g.data??[]).map(e=>[e.providerId,e])),[g.data]),A=e=>O.byProvider.get(e.name)?.requests??O.days.map(()=>0);return(0,Z.jsxs)(ze,{title:e(`nav.providers`),subtitle:i.data?e(`providers.count`,{count:i.data.length}):void 0,actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{icon:(0,Z.jsx)(me,{className:`size-3.5`}),onClick:()=>d(!0),children:e(`providers.backup`)}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(Me,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(we,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)})]}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto max-w-[1100px]`,children:[i.isLoading&&(0,Z.jsx)(w,{lines:4}),i.isError&&(0,Z.jsx)(C,{tone:`danger`,title:e(`common.error`),children:G(i.error)}),i.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(_,{icon:(0,Z.jsx)(Ee,{className:`size-6`}),title:e(`providers.empty`),detail:e(`providers.emptyDetail`),action:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(we,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(Me,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)})]})})}),i.data&&i.data.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,Z.jsx)(u,{ariaLabel:e(`providers.overview.range`),value:p,onChange:h,items:Ut.map(t=>({value:t,label:e(`range.${t}`)}))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(v,{variant:`plain`,size:`sm`,icon:S?(0,Z.jsx)(ve,{className:`size-3.5`}):(0,Z.jsx)(ge,{className:`size-3.5`}),onClick:()=>T(!S),children:e(S?`providers.overview.hideCharts`:`providers.overview.showCharts`)}),(0,Z.jsx)(u,{ariaLabel:e(`providers.view.label`),value:b,onChange:x,items:[{value:`grid`,label:e(`providers.view.grid`)},{value:`table`,label:e(`providers.view.table`)}]})]})]}),(0,Z.jsx)(Wt,{providers:i.data,stats:y.data??[],stats7d:k,range:p,chartsOpen:S}),b===`table`?(0,Z.jsx)(Qt,{providers:i.data,stats7d:k,usage:A,labels:O.labels,max:O.max,onOpen:e=>t(`/providers/${e.id}`)}):(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,260px),1fr))] gap-3`,children:i.data.map(e=>(0,Z.jsx)(Vn,{p:e,labels:O.labels,max:O.max,requests:A(e),stat:k.get(e.id),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>D(e)},e.id))})]})]}),(0,Z.jsx)(_t,{open:s,onOpenChange:c}),(0,Z.jsx)(Tt,{open:l,onOpenChange:d}),(0,Z.jsx)($n,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),E&&(0,Z.jsx)(vn,{provider:E,open:!0,onOpenChange:e=>!e&&D(null)})]})}var Rn=7;function zn(e){let t=new Date;return Array.from({length:e},(n,r)=>{let i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(e-1-r));return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,`0`)}-${String(i.getDate()).padStart(2,`0`)}`})}var Bn=e=>e.stopPropagation();function Vn({p:e,labels:t,max:n,requests:r,stat:i,onOpen:a,onTest:s}){let{t:c,locale:l}=U(),u=Ft(e,i),d=e.authScheme===`plugin`?c(`providers.card.plugin`):e.authScheme===`oauth-subscription`?c(`providers.card.subscription`):e.authScheme===`none`?c(`providers.card.noAuth`):e.hasApiKey?e.apiKeyMasked??`••••`:c(`providers.noKey`),f=pe(e)?W(e.quota,c,l):null,p=pe(e)?de(e.quota):null,m=r.reduce((e,t)=>e+t,0),h=en(e.endpoints[0]?.baseUrl);return(0,Z.jsxs)(`div`,{className:F(`card flex h-[116px] cursor-pointer flex-col gap-[7px] px-3 py-2.5 transition-colors hover:border-[var(--border-strong,var(--border))]`,!e.enabled&&`opacity-60`),role:`button`,tabIndex:0,"aria-label":e.name,title:e.name,onClick:a,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:F(`inline-flex shrink-0`,!e.enabled&&`grayscale`),children:(0,Z.jsx)(Be,{name:e.name,icon:e.icon,colorKey:e.templateId,size:24})}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[14px] font-semibold`,children:e.name}),(0,Z.jsx)(`span`,{title:Lt(u,c),className:`inline-flex`,children:(0,Z.jsx)(g,{tone:It[u]})}),e.templateUpdateAvailable&&(0,Z.jsx)(o,{tone:`accent`,children:c(`providers.templateUpdate`)}),(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[11.5px] text-[var(--text-muted)]`,children:c(`providers.modelCount`,{count:e.modelCount})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center`,onClick:Bn,children:[(0,Z.jsx)(v,{variant:`plain`,size:`sm`,icon:(0,Z.jsx)(Se,{className:`size-3.5`}),"aria-label":c(`providers.test`),title:c(`providers.test`),onClick:s}),(0,Z.jsx)(tn,{provider:e})]})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 gap-1.5 text-[11.5px] text-[var(--text-muted)]`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 shrink truncate font-mono`,title:e.endpoints[0]?.baseUrl,children:h??`—`}),(0,Z.jsx)(`span`,{children:`·`}),p?(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[var(--warning)]`,title:p.message,children:c(`providers.quota.failed`,{error:ue(p,c)})}):f?(0,Z.jsx)(`span`,{className:`num min-w-0 truncate text-[var(--text-secondary)]`,title:f,children:f}):(0,Z.jsx)(`span`,{className:F(`min-w-0 truncate`,e.hasApiKey&&e.authScheme!==`oauth-subscription`&&`font-mono`),children:d})]}),(0,Z.jsxs)(`div`,{className:`mt-auto flex items-end justify-between gap-2.5`,onClick:Bn,children:[(0,Z.jsx)(Vt,{data:r,labels:t,max:n}),m>0?(0,Z.jsxs)(`span`,{className:`flex gap-2.5 whitespace-nowrap text-[11.5px] text-[var(--text-secondary)]`,title:c(`providers.card.requests7d`),children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`b`,{className:`num font-semibold text-[var(--text)]`,children:M(m,!0)}),` `,c(`providers.card.requestsUnit`)]}),i&&i.requests>0&&(0,Z.jsx)(`span`,{className:`num`,style:{color:Bt(i.successRate)},title:c(`providers.col.successRate`),children:A(i.successRate)}),i&&i.costUsd>0&&(0,Z.jsx)(`span`,{className:`num`,children:R(i.costUsd)})]}):(0,Z.jsx)(`span`,{className:`text-[11.5px] text-[var(--text-muted)]`,children:c(`providers.card.noRequests7d`)})]})]})}var Hn=`plugin:`,Un=[`recommended`,`official`,`subscription`,`coding`,`cn`,`aggregator`,`inference`,`local`,`custom`],Wn={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`},Gn=e=>$.find(t=>t.value===e)?.label??e,Kn=e=>(0,Z.jsx)(`span`,{title:e,children:e}),qn=e=>{let t=/^(.+?)\s*[((]([^()()]+)[))]$/.exec(e);return t?[t[1],t[2]]:[e,null]},Jn=/[\s,,]+/;function Yn(e,t,n){let r=new Set(t.map(e=>e.protocol)),i=n.map(e=>e.protocol);return[...e.filter(e=>i.includes(e)),...i.filter(t=>!r.has(t)&&!e.includes(t))]}function Xn({label:e,hint:t,children:n}){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:e}),n,t&&(0,Z.jsx)(`div`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:t})]})}function Zn({value:e,onChange:t}){let{t:n}=U(),r=e.map(e=>e.protocol),i=$.filter(e=>!r.includes(e.value)),a=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.map((i,o)=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(K,{className:`w-44`,ariaLabel:n(`providers.protocol`),value:i.protocol,onChange:e=>a(o,{protocol:e}),options:$.filter(e=>e.value===i.protocol||!r.includes(e.value))}),(0,Z.jsx)(f,{className:`min-w-52 flex-1`,mono:!0,"aria-label":n(`providers.baseUrl`),placeholder:`https://api.example.com/v1`,value:i.baseUrl,onChange:e=>a(o,{baseUrl:e.target.value})}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,title:n(`providers.fullUrlHint`),children:[(0,Z.jsx)(E,{checked:!!i.fullUrl,label:n(`providers.fullUrl`),onChange:e=>a(o,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,Z.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(Oe,{className:`size-3.5`}),"aria-label":n(`common.delete`),disabled:e.length===1,onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),i.length>0&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(we,{className:`size-3.5`}),onClick:()=>t([...e,{protocol:i[0].value,baseUrl:e[0]?.baseUrl??``}]),children:n(`providers.addEndpoint`)})})]})}function Qn({value:e,onChange:t}){let{t:n}=U(),r=(n,r)=>t(e.map((e,t)=>t===n?r:e));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.map(([i,a],o)=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(f,{className:`w-44`,mono:!0,"aria-label":n(`providers.headerName`),placeholder:`Header`,value:i,onChange:e=>r(o,[e.target.value,a])}),(0,Z.jsx)(f,{className:`min-w-0 flex-1`,mono:!0,"aria-label":n(`providers.headerValue`),placeholder:`value`,value:a,onChange:e=>r(o,[i,e.target.value])}),(0,Z.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(Oe,{className:`size-3.5`}),"aria-label":n(`common.delete`),onClick:()=>t(e.filter((e,t)=>t!==o))})]},o)),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(we,{className:`size-3.5`}),onClick:()=>t([...e,[``,``]]),children:n(`providers.addHeader`)})})]})}function $n({open:e,onOpenChange:t,onCreated:n}){let{t:r}=U(),{toast:o}=q(),s=a(),l=re(),u=ce(),d=te(),p=(0,X.useMemo)(()=>new Set((d.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[d.data]),m=Le(),[h,g]=(0,X.useState)(``),[_,b]=(0,X.useState)(null),[x,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(``),[O,k]=(0,X.useState)(``),[A,j]=(0,X.useState)({project:``,location:`global`}),[M,N]=(0,X.useState)(``),[P,F]=(0,X.useState)(``),[ee,I]=(0,X.useState)(``),[L,R]=(0,X.useState)(`bearer`),[z,B]=(0,X.useState)([]),[V,ie]=(0,X.useState)([]),[H,ae]=(0,X.useState)([]),[oe,se]=(0,X.useState)(``),[le,ue]=(0,X.useState)(1),[de,W]=(0,X.useState)(``),[pe,me]=(0,X.useState)(``);(0,X.useEffect)(()=>{e||(b(null),T(null),g(``),D(``),k(``),j({project:``,location:`global`}),N(``),F(``),I(``))},[e]);let he=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase(),t=(s.data??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.id.includes(e));return Un.map(e=>({category:e,items:t.filter(t=>t.category===e)})).filter(e=>e.items.length)},[s.data,h]),ge=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase();return(d.data??[]).filter(t=>t.authScheme===`plugin`&&!t.settings.plugin?.absent&&(!e||t.name.toLowerCase().includes(e)||t.id.includes(e)))},[d.data,h]),_e=e=>{b(e),F(``),se(``),W(``),me(``),(rt(L)||e!==`custom`&&rt(e.auth.scheme))&&k(``),j({project:``,location:e!==`custom`&&e.settings?.vertex?.location||`global`}),N(``),e===`custom`?(D(``),I(``),R(`bearer`),B([{protocol:`openai-chat`,baseUrl:``}]),ie([`openai-chat`]),ae([]),ue(1)):(D(e.name),I(e.priceKey??e.id),R(e.auth.scheme),B(e.endpoints.map(e=>({...e}))),ie([...e.preferredUpstreamProtocols]),ae(Object.entries(e.defaultHeaders??{})),ue(e.defaultPriceMultiplier??1))},ve=e=>{ie(t=>Yn(t,z,e)),B(e)},J=_&&_!==`custom`?_:null,ye=J?.authScheme===`oauth-subscription`,be=pe.split(Jn).map(e=>e.trim()).filter(Boolean),xe=(J?.keyAlternatives??[]).flatMap(e=>(s.data??[]).filter(t=>t.id===e)),Se=()=>{let e=_===`custom`;u.mutate({templateId:e?null:_.id,variantId:P||null,name:E.trim()||null,apiKey:O.trim()||null,priceKey:ee,...L===`gcp-service-account`?{settings:{vertex:{project:A.project.trim(),location:A.location}}}:{},...ye?{}:{endpoints:z.map(e=>({...e,baseUrl:e.baseUrl.trim()})),authScheme:L,preferredUpstreamProtocols:V.filter(e=>z.some(t=>t.protocol===e)),extraHeaders:Object.fromEntries(H.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t])),httpProxy:oe.trim()||null,priceMultiplier:le,notes:de.trim()||null,...be.length>0?{models:be}:{}}},{onSuccess:e=>{t(!1),o(r(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>o(G(e),`error`)})},Ce=()=>{if(x===`custom`)_e(`custom`);else if(x?.startsWith(Hn)){let e=ge.find(e=>Hn+e.id===x);e&&(t(!1),n(e))}else{let e=(s.data??[]).find(e=>e.id===x);e&&!p.has(e.id)&&_e(e)}},Te=ye||z.length>0&&z.every(e=>/^https?:\/\//.test(e.baseUrl.trim())),Ee=_!==null&&Te&&(_===`custom`?E.trim()!==``:!J.requiresApiKey||L===`none`||O.trim()!==``);return(0,Z.jsxs)(fe,{open:e,onOpenChange:t,width:640,title:r(_?`providers.addTitleDetails`:`providers.addTitle`),description:_?J?J.name:r(`providers.custom`):r(`providers.addDetail`),footer:_?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{className:`mr-auto`,variant:`plain`,onClick:()=>b(null),children:r(`common.back`)}),(0,Z.jsx)(v,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Z.jsx)(v,{variant:`primary`,disabled:!Ee,loading:u.isPending,onClick:Se,children:r(`providers.create`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Z.jsx)(v,{variant:`primary`,disabled:!x,onClick:Ce,children:r(`common.continue`)})]}),children:[(0,Z.jsx)(nt,{className:`mb-6`,label:r(`providers.addTitle`),current:+!!_,steps:[{id:`template`,label:r(`providers.step.template`)},{id:`details`,label:r(`providers.step.details`)}]}),_?(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(y,{label:r(`providers.name`),children:(0,Z.jsx)(f,{value:E,onChange:e=>D(e.target.value)})}),J?.variants&&J.variants.length>0&&(0,Z.jsx)(y,{label:r(`providers.variant`),children:(0,Z.jsx)(K,{value:P,onChange:e=>{F(e);let t=J.variants?.find(t=>t.id===e);I(t?.priceKey??J.priceKey??J.id),ve((t?.endpointsOverride??J.endpoints).map(e=>({...e})))},options:[{value:``,label:r(`providers.variantDefault`)},...J.variants.map(e=>({value:e.id,label:e.name}))]})}),_===`custom`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Xn,{label:r(`providers.section.endpoints`),hint:r(`providers.baseUrlHint`),children:(0,Z.jsx)(Zn,{value:z,onChange:ve})}),(0,Z.jsx)(y,{label:r(`providers.authScheme`),children:(0,Z.jsx)(K,{value:L,onChange:R,options:In})})]}),ye?(0,Z.jsx)(C,{tone:`info`,title:r(`providers.subscriptionWizardHint`),children:r(`providers.subscriptionWizardDetail`)}):L===`aws-sigv4`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(st,{onChange:k}),(0,Z.jsx)(ct,{endpoints:z})]}):L===`gcp-service-account`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(dt,{onChange:k,onFacts:e=>N(e?.projectId??``)}),(0,Z.jsx)(ut,{project:A.project,location:A.location,projectPlaceholder:M,onChange:j})]}):(0,Z.jsxs)(`div`,{className:`font-mono`,children:[(0,Z.jsx)(Fe,{label:r(`providers.apiKey`),description:r(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:O,onChange:e=>k(e.target.value)}),J?.apiKeyUrl&&(0,Z.jsx)(`a`,{className:`mt-2 inline-block font-sans text-[12px] text-[var(--accent)]`,href:J.apiKeyUrl,target:`_blank`,rel:`noreferrer`,children:r(`providers.getKey`)})]}),J&&xe.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`span`,{children:r(`providers.keyAlternative.wizard`,{name:J.name,alt:xe.map(e=>e.name).join(` / `)})}),xe.map(e=>(0,Z.jsx)(v,{size:`sm`,variant:`plain`,onClick:()=>{T(e.id),_e(e)},children:r(`providers.keyAlternative.pick`,{alt:e.name})},e.id))]}),(0,Z.jsx)(y,{label:r(`providers.priceKey`),hint:r(`providers.priceKeyHint`),children:(0,Z.jsx)(K,{value:ee,onChange:I,options:[{value:``,label:r(`providers.priceKeyNone`)},...(l.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),!ye&&(0,Z.jsx)(ne,{title:r(`providers.moreOptions`),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[J&&(0,Z.jsx)(Xn,{label:r(`providers.section.endpoints`),hint:r(`providers.endpointsFooter`),children:(0,Z.jsx)(Zn,{value:z,onChange:ve})}),new Set(z.map(e=>e.protocol)).size>1&&(0,Z.jsx)(Xn,{label:r(`providers.preferred`),hint:r(`providers.preferredHint`),children:(0,Z.jsx)(Re,{label:r(`providers.preferred`),options:$.filter(e=>z.some(t=>t.protocol===e.value)).map(e=>{let t=V.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:V,onValueChange:e=>{let t=V.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));ie([...t,...n])}})}),J&&(0,Z.jsx)(y,{label:r(`providers.authScheme`),children:(0,Z.jsx)(K,{value:L,onChange:R,options:In})}),(0,Z.jsx)(Xn,{label:r(`providers.headers`),children:(0,Z.jsx)(Qn,{value:H,onChange:ae})}),(0,Z.jsx)(y,{label:r(`providers.proxy`),hint:r(`providers.proxyHint`),children:(0,Z.jsx)(f,{mono:!0,placeholder:`http://127.0.0.1:7890`,value:oe,onChange:e=>se(e.target.value)})}),(0,Z.jsx)(Xn,{label:r(`providers.multiplier`),hint:r(`providers.multiplierHint`),children:(0,Z.jsx)(S,{className:`w-28`,label:r(`providers.multiplier`),step:.01,min:0,value:le,onChange:e=>ue(e??1)})}),(0,Z.jsx)(y,{label:r(`providers.initialModels`),hint:J?r(`providers.initialModelsTemplateHint`,{count:J.models.length}):r(`providers.initialModelsCustomHint`),children:(0,Z.jsx)(c,{rows:3,mono:!0,value:pe,onChange:e=>me(e.target.value)})}),(0,Z.jsx)(y,{label:r(`providers.notes`),children:(0,Z.jsx)(f,{value:de,onChange:e=>W(e.target.value)})}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`providers.moreOptionsDetail`)})]})}),J&&J.models.length>0&&be.length===0&&(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`providers.templateModels`,{count:J.models.length})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsx)(i,{value:h,onChange:g,placeholder:r(`providers.searchTemplates`)}),s.isLoading&&(0,Z.jsx)(w,{lines:4}),s.isError&&(0,Z.jsx)(C,{tone:`danger`,title:r(`common.error`),children:G(s.error)}),he.map(e=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.${e.category}`)}),(0,Z.jsx)(He,{name:`provider-template`,"aria-label":r(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===x)?x:null,onValueChange:T,options:e.items.map(e=>{let t=[...new Set(e.endpoints.map(e=>e.protocol))],[n,i]=qn(e.name);return{value:e.id,label:(0,Z.jsx)(`span`,{title:e.name,children:n}),description:(0,Z.jsx)(`span`,{title:t.map(Gn).join(` · `),children:i??t.map(e=>Wn[e]).join(` · `)}),icon:(0,Z.jsx)(Be,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:p.has(e.id),disabledReason:Kn(r(`providers.subscriptionAdded`))}})})]},e.category)),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.category.plugin`)}),ge.length>0?(0,Z.jsx)(He,{name:`provider-template-plugin`,"aria-label":r(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:x?.startsWith(Hn)?x:null,onValueChange:T,options:ge.map(e=>({value:Hn+e.id,label:Kn(e.name),description:Kn(r(`providers.pluginProvided`)),icon:(0,Z.jsx)(Be,{name:e.name,icon:e.icon,colorKey:e.id,size:28})}))}):(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-[var(--radius-md)] border border-dashed border-[var(--border)] px-3 py-2.5`,children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:r(`providers.pluginHint`)}),(0,Z.jsx)(v,{size:`sm`,onClick:()=>{t(!1),m(`/plugins/market`)},children:r(`plugins.browseMarket`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:r(`providers.custom`)}),(0,Z.jsx)(He,{name:`provider-template-custom`,"aria-label":r(`providers.custom`),layout:`list`,density:`compact`,value:x===`custom`?`custom`:null,onValueChange:T,options:[{value:`custom`,label:r(`providers.custom`),description:r(`providers.customDetail`),icon:(0,Z.jsx)(`span`,{className:`inline-flex size-7 items-center justify-center rounded-[8px] border border-dashed border-[var(--border-strong)] text-[var(--text-secondary)]`,children:(0,Z.jsx)(we,{className:`size-4`})})}]})]})]})]})}export{on as a,st as c,ut as d,rt as f,vn as i,ct as l,$ as n,an as o,Fn as r,nn as s,In as t,dt as u};
@@ -1,3 +1,3 @@
1
- import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{D as n,E as r,Fn as i,I as a,Ji as o,N as s,O as c,P as l,Qs as u,R as d,S as f,U as p,W as m,Wo as h,Yi as g,bo as _,dt as v,qi as y,r as b,vn as ee,w as x}from"./format-CmXxTS5M.js";import{H as S,U as C,V as w,W as T}from"./TrayTitleSource-DN10ruw2.js";import{t as E}from"./grip-vertical-DFI2_ajd.js";import{t as D}from"./layers-lBgMUT4n.js";import{t as O}from"./pencil-CpF9MxGZ.js";import{t as k}from"./plus-c3HzV6VX.js";import{t as A}from"./trash-BHBJn5GS.js";import{a as te,c as ne,d as re,f as j,i as M,l as N,n as P,o as F,r as I,s as L,t as R,u as z}from"./sortable.esm-Cj5-STJU.js";import{v as B}from"./index-BW8keTkg.js";var V=e(t(),1),H=u(),U=[`smart`,`order`,`rotate`,`usage`,`pace`,`weight`],W=[`auto`,`session`,`turn`,`off`,`strict`],G=e=>e.group?`group/${e.group}`:`${e.provider}/${e.model}`;function ie(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t.length>48?t.slice(0,48).replace(/-+$/,``):t}var K=()=>({name:``,slug:``,mode:`smart`,stays:`auto`,enabled:!0,listed:!0,members:[]}),q=e=>({name:e.name,slug:e.slug,mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({provider:e.provider??null,model:e.model??null,group:e.group??null,weight:e.weight}))});function ae(e){return e.name.trim()!==``&&/^[a-z0-9][a-z0-9-]{0,47}$/.test(e.slug)&&e.members.length>0}function oe(e,t){return{name:e.name.trim(),...t?{slug:e.slug}:{},mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({...e,weight:Math.min(1e3,Math.max(1,Math.floor(e.weight||1)))}))}}function J(e,t){if(e instanceof h){let n=e.details?.problems;if(n?.length)return n.map(e=>{let n=`routingGroups.problem.${e.code}`;return n in r?t(n):e.message})}return[C(e)]}var Y={healthy:`green`,cooling:`orange`,open:`orange`,half_open:`orange`,no_account:`red`,off:`red`,missing:`red`,group:`neutral`};function X(e,t){if(!e)return`—`;let n=`routingGroups.reason.${e}`;return n in r?t(n):e}function Z(){let{t:e,locale:t}=x();return n=>n.health===`cooling`||n.health===`open`?e(`routingGroups.health.${n.health}`,{time:n.coolingUntil?b(n.coolingUntil,t):`—`}):e(`routingGroups.health.${n.health}`)}function Q(){let{t:e}=x(),{toast:t,confirm:n}=T(),r=o(),a=y(),l=_(),u=i(),[d,f]=(0,V.useState)(null),m=e=>a.data?.find(t=>t.id===e),h=async r=>{await n({title:e(`routingGroups.deleteTitle`,{name:r.name}),detail:e(`routingGroups.deleteDetail`,{model:r.modelId}),confirmLabel:e(`common.delete`),destructive:!0})&&u.mutate(r.id,{onError:n=>t(J(n,e).join(`
2
- `),`error`)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:e(`routingGroups.intro`)}),(0,H.jsx)(c,{variant:`primary`,icon:(0,H.jsx)(k,{className:`size-3.5`}),onClick:()=>f(K()),children:e(`routingGroups.add`)})]}),r.isLoading&&(0,H.jsx)(p,{lines:3}),r.data?.length===0&&(0,H.jsx)(`div`,{className:`card`,children:(0,H.jsx)(s,{icon:(0,H.jsx)(D,{className:`size-6`}),title:e(`routingGroups.empty`),detail:e(`routingGroups.emptyDetail`)})}),(0,H.jsx)(`div`,{className:`grid gap-3`,children:r.data?.map(n=>(0,H.jsx)($,{group:n,status:m(n.id),onEdit:()=>f({id:n.id,draft:q(n)}),onDelete:()=>void h(n),onToggle:r=>l.mutate({id:n.id,body:{enabled:r}},{onError:n=>t(J(n,e).join(`
3
- `),`error`)})},n.id))}),(0,H.jsx)(ce,{target:d,groups:r.data??[],status:d&&`id`in d?m(d.id):void 0,onClose:()=>f(null)})]})}function $({group:e,status:t,onEdit:r,onDelete:i,onToggle:a}){let{t:o,locale:s}=x(),l=Z(),u=new Map(t?.members.map(e=>[e.key,e])??[]);return(0,H.jsxs)(`div`,{className:v(`card p-4`,!e.enabled&&`opacity-70`),children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.name}),(0,H.jsx)(n,{tone:`accent`,children:o(`routingGroups.mode.${e.mode}`)}),!e.enabled&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.disabled`)}),!e.listed&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.unlisted`)})]}),(0,H.jsx)(`code`,{className:`selectable text-[12px] text-[var(--text-secondary)]`,children:e.modelId})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(m,{label:o(`routingGroups.enabled`),checked:e.enabled,onChange:a}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(O,{className:`size-3.5`}),"aria-label":o(`common.edit`),title:o(`common.edit`),onClick:r}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":o(`common.delete`),title:o(`common.delete`),onClick:i})]})]}),(0,H.jsx)(`div`,{className:`mt-3 divide-y divide-[var(--border-subtle)] overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:e.members.map((t,n)=>(0,H.jsx)(se,{member:t,index:n,group:e,live:u.get(G(t)),healthText:l},G(t)))}),t?.lastReason&&t.lastDecisionAt&&(0,H.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:o(`routingGroups.lastDecision`,{reason:X(t.lastReason,o),time:b(t.lastDecisionAt,s)})})]})}function se({member:e,index:t,group:r,live:i,healthText:a}){let{t:o,locale:s}=x(),c=e.group?`group/${e.group}`:`${i?.providerName??e.provider} · ${e.model}`,l=i?.usedPercent==null?null:o(`routingGroups.quotaUsed`,{percent:Math.round(i.usedPercent)})+(i.resetsAt?` · `+o(`routingGroups.resets`,{time:b(i.resetsAt,s)}):``);return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2 text-[12px]`,children:[(0,H.jsx)(`span`,{className:`w-5 shrink-0 text-center tabular-nums text-[var(--text-muted)]`,children:t+1}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 basis-44 truncate text-[13px]`,children:c}),r.mode===`weight`&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.weightN`,{n:e.weight})}),i&&(0,H.jsx)(n,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(n,{tone:`red`,children:o(`routingGroups.memberProblem.${i.problem}`)}),l&&(0,H.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:l}),i&&!l&&i.health!==`group`&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.quotaUnknown`)}),i?.lastUsed&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.lastUsed`,{time:b(i.lastUsed,s)})})]})}function ce({target:e,groups:t,status:n,onClose:r}){let{t:i}=x(),o=Z(),s=ee(),u=_(),d=g(),p=e&&`id`in e?e.id:null,[h,v]=(0,V.useState)(K()),[y,b]=(0,V.useState)(!1),[C,T]=(0,V.useState)([]);(0,V.useEffect)(()=>{e&&(v(`id`in e?e.draft:e),b(`id`in e),T([]))},[e]);let E=p?t.find(e=>e.id===p):void 0,D=s.isPending||u.isPending,O=re(z(ne,{activationConstraint:{distance:4}}),z(L,{coordinateGetter:I})),k=e=>v(t=>({...t,...e})),A=e=>k({members:e}),j=new Set(h.members.map(G)),M=(0,V.useMemo)(()=>(d.data??[]).filter(e=>!j.has(`${e.providerId}/${e.id}`)).map(e=>({value:`${e.providerId}/${e.id}`,label:`${e.providerName} · ${e.id}`,m:e})),[d.data,h.members]),B=t.filter(e=>e.id!==p&&!j.has(`group/${e.slug}`)).map(e=>({value:e.slug,label:`group/${e.slug} · ${e.name}`})),q=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=h.members.findIndex(t=>G(t)===e.id),r=h.members.findIndex(e=>G(e)===t.id);n>=0&&r>=0&&A(P(h.members,n,r))},Y=()=>{let e=oe(h,p===null),t={onSuccess:()=>r(),onError:e=>T(J(e,i))};p?u.mutate({id:p,body:e},t):s.mutate(e,t)},X=new Map(n?.members.map(e=>[e.key,e])??[]),Q=(e,t)=>e.group?`group/${e.group}`:`${t?.providerName??X.get(G(e))?.providerName??e.provider} · ${e.model}`,$=new Map((d.data??[]).map(e=>[`${e.providerId}/${e.id}`,e]));return(0,H.jsx)(S,{open:e!==null,onOpenChange:e=>!e&&r(),width:600,title:E?i(`routingGroups.editTitle`,{name:E.name}):i(`routingGroups.addTitle`),footer:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(c,{onClick:r,children:i(`common.cancel`)}),(0,H.jsx)(c,{variant:`primary`,disabled:!ae(h),loading:D,onClick:Y,children:i(`common.save`)})]}),children:(0,H.jsxs)(`div`,{className:`grid gap-4`,children:[(0,H.jsx)(l,{label:i(`routingGroups.name`),children:(0,H.jsx)(a,{value:h.name,maxLength:80,placeholder:`Opus anywhere`,onChange:e=>k({name:e.target.value,...!y&&p===null?{slug:ie(e.target.value)}:{}})})}),(0,H.jsx)(l,{label:i(`routingGroups.slug`),hint:p?i(`routingGroups.slugLocked`):i(`routingGroups.slugHint`,{model:`group/${h.slug||`…`}`}),children:(0,H.jsx)(a,{mono:!0,value:h.slug,maxLength:48,disabled:p!==null,placeholder:`opus-anywhere`,onChange:e=>{b(!0),k({slug:e.target.value})}})}),(0,H.jsx)(l,{label:i(`routingGroups.modeLabel`),hint:i(`routingGroups.mode.${h.mode}.hint`),children:(0,H.jsx)(w,{value:h.mode,onChange:e=>k({mode:e}),options:U.map(e=>({value:e,label:i(`routingGroups.mode.${e}`)}))})}),(0,H.jsx)(l,{label:i(`routingGroups.staysLabel`),hint:i(`routingGroups.stays.${h.stays}.hint`),children:(0,H.jsx)(w,{value:h.stays,onChange:e=>k({stays:e}),options:W.map(e=>({value:e,label:i(`routingGroups.stays.${e}`)}))})}),(0,H.jsxs)(`div`,{className:`grid gap-2`,children:[(0,H.jsx)(`div`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`routingGroups.membersTitle`)}),(0,H.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.membersHint`)}),h.members.length===0?(0,H.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.noMembers`)}):(0,H.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,H.jsx)(F,{sensors:O,collisionDetection:N,onDragEnd:q,children:(0,H.jsx)(R,{items:h.members.map(G),strategy:te,children:h.members.map((e,t)=>(0,H.jsx)(le,{member:e,name:Q(e,$.get(G(e))),weighted:h.mode===`weight`,live:X.get(G(e)),healthText:o,onWeight:e=>A(h.members.map((n,r)=>r===t?{...n,weight:e}:n)),onRemove:()=>A(h.members.filter((e,n)=>n!==t))},G(e)))})})}),(0,H.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addModel`),placeholder:i(`routingGroups.addModel`),value:null,disabled:M.length===0,onChange:e=>{let t=M.find(t=>t.value===e)?.m;t&&A([...h.members,{provider:t.providerId,model:t.id,group:null,weight:1}])},options:M.map(({value:e,label:t})=>({value:e,label:t}))}),(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addGroup`),placeholder:i(`routingGroups.addGroup`),value:null,disabled:B.length===0,onChange:e=>A([...h.members,{provider:null,model:null,group:e,weight:1}]),options:B})]})]}),(0,H.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,H.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.listed`)}),(0,H.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.listedHint`)})]}),(0,H.jsx)(m,{label:i(`routingGroups.listed`),checked:h.listed,onChange:e=>k({listed:e})})]}),(0,H.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.enabled`)}),(0,H.jsx)(m,{label:i(`routingGroups.enabled`),checked:h.enabled,onChange:e=>k({enabled:e})})]})]}),C.length>0&&(0,H.jsx)(f,{tone:`danger`,title:i(`routingGroups.refused`),children:(0,H.jsx)(`ul`,{className:`list-disc pl-4`,children:C.map(e=>(0,H.jsx)(`li`,{children:e},e))})})]})})}function le({member:e,name:t,weighted:r,live:i,healthText:a,onWeight:o,onRemove:s}){let{t:l}=x(),{attributes:u,listeners:f,setNodeRef:p,setActivatorNodeRef:m,transform:h,transition:g,isDragging:_}=M({id:G(e)});return(0,H.jsxs)(`div`,{ref:p,style:{transform:j.Transform.toString(h),transition:g},className:v(`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`,_&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,H.jsx)(`button`,{ref:m,type:`button`,"aria-label":l(`clients.dragToReorder`,{provider:t}),title:l(`clients.dragToReorder`,{provider:t}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...u,...f,children:(0,H.jsx)(E,{className:`size-4`})}),(0,H.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:t}),i&&(0,H.jsx)(n,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(n,{tone:`red`,children:l(`routingGroups.memberProblem.${i.problem}`)})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,H.jsx)(`div`,{className:`w-20`,children:(0,H.jsx)(d,{label:l(`routingGroups.weight`),placeholder:l(`routingGroups.weight`),value:e.weight,min:1,step:1,onChange:e=>o(e??1)})}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":l(`routingGroups.remove`,{name:t}),title:l(`routingGroups.remove`,{name:t}),onClick:s})]})]})}function ue(){let{t:e}=x();return(0,H.jsx)(B,{title:e(`nav.routingGroups`),subtitle:e(`routingGroups.subtitle`),children:(0,H.jsx)(Q,{})})}export{ue as RoutingGroupsPage};
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$s as n,D as r,E as i,Go as a,I as o,In as s,Ji as c,N as l,O as u,P as d,R as f,S as p,U as m,W as h,Xi as g,Yi as _,dt as v,r as y,w as b,xo as x,yn as ee}from"./format-CskGUFYy.js";import{H as S,U as C,V as w,W as T}from"./TrayTitleSource-B98nYas3.js";import{t as E}from"./grip-vertical-DFI2_ajd.js";import{t as D}from"./layers-lBgMUT4n.js";import{t as O}from"./pencil-CpF9MxGZ.js";import{t as k}from"./plus-c3HzV6VX.js";import{t as A}from"./trash-BHBJn5GS.js";import{a as te,c as ne,d as re,f as j,i as M,l as N,n as P,o as F,r as I,s as L,t as R,u as z}from"./sortable.esm-BvMId5KB.js";import{v as B}from"./index-D2siu6xk.js";var V=e(t(),1),H=n(),U=[`smart`,`order`,`rotate`,`usage`,`pace`,`weight`],W=[`auto`,`session`,`turn`,`off`,`strict`],G=e=>e.group?`group/${e.group}`:`${e.provider}/${e.model}`;function ie(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t.length>48?t.slice(0,48).replace(/-+$/,``):t}var K=()=>({name:``,slug:``,mode:`smart`,stays:`auto`,enabled:!0,listed:!0,members:[]}),q=e=>({name:e.name,slug:e.slug,mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({provider:e.provider??null,model:e.model??null,group:e.group??null,weight:e.weight}))});function ae(e){return e.name.trim()!==``&&/^[a-z0-9][a-z0-9-]{0,47}$/.test(e.slug)&&e.members.length>0}function oe(e,t){return{name:e.name.trim(),...t?{slug:e.slug}:{},mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({...e,weight:Math.min(1e3,Math.max(1,Math.floor(e.weight||1)))}))}}function J(e,t){if(e instanceof a){let n=e.details?.problems;if(n?.length)return n.map(e=>{let n=`routingGroups.problem.${e.code}`;return n in i?t(n):e.message})}return[C(e)]}var Y={healthy:`green`,cooling:`orange`,open:`orange`,half_open:`orange`,no_account:`red`,off:`red`,missing:`red`,group:`neutral`};function X(e,t){if(!e)return`—`;let n=`routingGroups.reason.${e}`;return n in i?t(n):e}function Z(){let{t:e,locale:t}=b();return n=>n.health===`cooling`||n.health===`open`?e(`routingGroups.health.${n.health}`,{time:n.coolingUntil?y(n.coolingUntil,t):`—`}):e(`routingGroups.health.${n.health}`)}function Q(){let{t:e}=b(),{toast:t,confirm:n}=T(),r=_(),i=c(),a=x(),o=s(),[d,f]=(0,V.useState)(null),p=e=>i.data?.find(t=>t.id===e),h=async r=>{await n({title:e(`routingGroups.deleteTitle`,{name:r.name}),detail:e(`routingGroups.deleteDetail`,{model:r.modelId}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onError:n=>t(J(n,e).join(`
2
+ `),`error`)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:e(`routingGroups.intro`)}),(0,H.jsx)(u,{variant:`primary`,icon:(0,H.jsx)(k,{className:`size-3.5`}),onClick:()=>f(K()),children:e(`routingGroups.add`)})]}),r.isLoading&&(0,H.jsx)(m,{lines:3}),r.data?.length===0&&(0,H.jsx)(`div`,{className:`card`,children:(0,H.jsx)(l,{icon:(0,H.jsx)(D,{className:`size-6`}),title:e(`routingGroups.empty`),detail:e(`routingGroups.emptyDetail`)})}),(0,H.jsx)(`div`,{className:`grid gap-3`,children:r.data?.map(n=>(0,H.jsx)($,{group:n,status:p(n.id),onEdit:()=>f({id:n.id,draft:q(n)}),onDelete:()=>void h(n),onToggle:r=>a.mutate({id:n.id,body:{enabled:r}},{onError:n=>t(J(n,e).join(`
3
+ `),`error`)})},n.id))}),(0,H.jsx)(ce,{target:d,groups:r.data??[],status:d&&`id`in d?p(d.id):void 0,onClose:()=>f(null)})]})}function $({group:e,status:t,onEdit:n,onDelete:i,onToggle:a}){let{t:o,locale:s}=b(),c=Z(),l=new Map(t?.members.map(e=>[e.key,e])??[]);return(0,H.jsxs)(`div`,{className:v(`card p-4`,!e.enabled&&`opacity-70`),children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.name}),(0,H.jsx)(r,{tone:`accent`,children:o(`routingGroups.mode.${e.mode}`)}),!e.enabled&&(0,H.jsx)(r,{tone:`neutral`,children:o(`routingGroups.disabled`)}),!e.listed&&(0,H.jsx)(r,{tone:`neutral`,children:o(`routingGroups.unlisted`)})]}),(0,H.jsx)(`code`,{className:`selectable text-[12px] text-[var(--text-secondary)]`,children:e.modelId})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(h,{label:o(`routingGroups.enabled`),checked:e.enabled,onChange:a}),(0,H.jsx)(u,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(O,{className:`size-3.5`}),"aria-label":o(`common.edit`),title:o(`common.edit`),onClick:n}),(0,H.jsx)(u,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":o(`common.delete`),title:o(`common.delete`),onClick:i})]})]}),(0,H.jsx)(`div`,{className:`mt-3 divide-y divide-[var(--border-subtle)] overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:e.members.map((t,n)=>(0,H.jsx)(se,{member:t,index:n,group:e,live:l.get(G(t)),healthText:c},G(t)))}),t?.lastReason&&t.lastDecisionAt&&(0,H.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:o(`routingGroups.lastDecision`,{reason:X(t.lastReason,o),time:y(t.lastDecisionAt,s)})})]})}function se({member:e,index:t,group:n,live:i,healthText:a}){let{t:o,locale:s}=b(),c=e.group?`group/${e.group}`:`${i?.providerName??e.provider} · ${e.model}`,l=i?.usedPercent==null?null:o(`routingGroups.quotaUsed`,{percent:Math.round(i.usedPercent)})+(i.resetsAt?` · `+o(`routingGroups.resets`,{time:y(i.resetsAt,s)}):``);return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2 text-[12px]`,children:[(0,H.jsx)(`span`,{className:`w-5 shrink-0 text-center tabular-nums text-[var(--text-muted)]`,children:t+1}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 basis-44 truncate text-[13px]`,children:c}),n.mode===`weight`&&(0,H.jsx)(r,{tone:`neutral`,children:o(`routingGroups.weightN`,{n:e.weight})}),i&&(0,H.jsx)(r,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(r,{tone:`red`,children:o(`routingGroups.memberProblem.${i.problem}`)}),l&&(0,H.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:l}),i&&!l&&i.health!==`group`&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.quotaUnknown`)}),i?.lastUsed&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.lastUsed`,{time:y(i.lastUsed,s)})})]})}function ce({target:e,groups:t,status:n,onClose:r}){let{t:i}=b(),a=Z(),s=ee(),c=x(),l=g(),f=e&&`id`in e?e.id:null,[m,_]=(0,V.useState)(K()),[v,y]=(0,V.useState)(!1),[C,T]=(0,V.useState)([]);(0,V.useEffect)(()=>{e&&(_(`id`in e?e.draft:e),y(`id`in e),T([]))},[e]);let E=f?t.find(e=>e.id===f):void 0,D=s.isPending||c.isPending,O=re(z(ne,{activationConstraint:{distance:4}}),z(L,{coordinateGetter:I})),k=e=>_(t=>({...t,...e})),A=e=>k({members:e}),j=new Set(m.members.map(G)),M=(0,V.useMemo)(()=>(l.data??[]).filter(e=>!j.has(`${e.providerId}/${e.id}`)).map(e=>({value:`${e.providerId}/${e.id}`,label:`${e.providerName} · ${e.id}`,m:e})),[l.data,m.members]),B=t.filter(e=>e.id!==f&&!j.has(`group/${e.slug}`)).map(e=>({value:e.slug,label:`group/${e.slug} · ${e.name}`})),q=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=m.members.findIndex(t=>G(t)===e.id),r=m.members.findIndex(e=>G(e)===t.id);n>=0&&r>=0&&A(P(m.members,n,r))},Y=()=>{let e=oe(m,f===null),t={onSuccess:()=>r(),onError:e=>T(J(e,i))};f?c.mutate({id:f,body:e},t):s.mutate(e,t)},X=new Map(n?.members.map(e=>[e.key,e])??[]),Q=(e,t)=>e.group?`group/${e.group}`:`${t?.providerName??X.get(G(e))?.providerName??e.provider} · ${e.model}`,$=new Map((l.data??[]).map(e=>[`${e.providerId}/${e.id}`,e]));return(0,H.jsx)(S,{open:e!==null,onOpenChange:e=>!e&&r(),width:600,title:E?i(`routingGroups.editTitle`,{name:E.name}):i(`routingGroups.addTitle`),footer:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(u,{onClick:r,children:i(`common.cancel`)}),(0,H.jsx)(u,{variant:`primary`,disabled:!ae(m),loading:D,onClick:Y,children:i(`common.save`)})]}),children:(0,H.jsxs)(`div`,{className:`grid gap-4`,children:[(0,H.jsx)(d,{label:i(`routingGroups.name`),children:(0,H.jsx)(o,{value:m.name,maxLength:80,placeholder:`Opus anywhere`,onChange:e=>k({name:e.target.value,...!v&&f===null?{slug:ie(e.target.value)}:{}})})}),(0,H.jsx)(d,{label:i(`routingGroups.slug`),hint:f?i(`routingGroups.slugLocked`):i(`routingGroups.slugHint`,{model:`group/${m.slug||`…`}`}),children:(0,H.jsx)(o,{mono:!0,value:m.slug,maxLength:48,disabled:f!==null,placeholder:`opus-anywhere`,onChange:e=>{y(!0),k({slug:e.target.value})}})}),(0,H.jsx)(d,{label:i(`routingGroups.modeLabel`),hint:i(`routingGroups.mode.${m.mode}.hint`),children:(0,H.jsx)(w,{value:m.mode,onChange:e=>k({mode:e}),options:U.map(e=>({value:e,label:i(`routingGroups.mode.${e}`)}))})}),(0,H.jsx)(d,{label:i(`routingGroups.staysLabel`),hint:i(`routingGroups.stays.${m.stays}.hint`),children:(0,H.jsx)(w,{value:m.stays,onChange:e=>k({stays:e}),options:W.map(e=>({value:e,label:i(`routingGroups.stays.${e}`)}))})}),(0,H.jsxs)(`div`,{className:`grid gap-2`,children:[(0,H.jsx)(`div`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`routingGroups.membersTitle`)}),(0,H.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.membersHint`)}),m.members.length===0?(0,H.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.noMembers`)}):(0,H.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,H.jsx)(F,{sensors:O,collisionDetection:N,onDragEnd:q,children:(0,H.jsx)(R,{items:m.members.map(G),strategy:te,children:m.members.map((e,t)=>(0,H.jsx)(le,{member:e,name:Q(e,$.get(G(e))),weighted:m.mode===`weight`,live:X.get(G(e)),healthText:a,onWeight:e=>A(m.members.map((n,r)=>r===t?{...n,weight:e}:n)),onRemove:()=>A(m.members.filter((e,n)=>n!==t))},G(e)))})})}),(0,H.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addModel`),placeholder:i(`routingGroups.addModel`),value:null,disabled:M.length===0,onChange:e=>{let t=M.find(t=>t.value===e)?.m;t&&A([...m.members,{provider:t.providerId,model:t.id,group:null,weight:1}])},options:M.map(({value:e,label:t})=>({value:e,label:t}))}),(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addGroup`),placeholder:i(`routingGroups.addGroup`),value:null,disabled:B.length===0,onChange:e=>A([...m.members,{provider:null,model:null,group:e,weight:1}]),options:B})]})]}),(0,H.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,H.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.listed`)}),(0,H.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.listedHint`)})]}),(0,H.jsx)(h,{label:i(`routingGroups.listed`),checked:m.listed,onChange:e=>k({listed:e})})]}),(0,H.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.enabled`)}),(0,H.jsx)(h,{label:i(`routingGroups.enabled`),checked:m.enabled,onChange:e=>k({enabled:e})})]})]}),C.length>0&&(0,H.jsx)(p,{tone:`danger`,title:i(`routingGroups.refused`),children:(0,H.jsx)(`ul`,{className:`list-disc pl-4`,children:C.map(e=>(0,H.jsx)(`li`,{children:e},e))})})]})})}function le({member:e,name:t,weighted:n,live:i,healthText:a,onWeight:o,onRemove:s}){let{t:c}=b(),{attributes:l,listeners:d,setNodeRef:p,setActivatorNodeRef:m,transform:h,transition:g,isDragging:_}=M({id:G(e)});return(0,H.jsxs)(`div`,{ref:p,style:{transform:j.Transform.toString(h),transition:g},className:v(`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`,_&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,H.jsx)(`button`,{ref:m,type:`button`,"aria-label":c(`clients.dragToReorder`,{provider:t}),title:c(`clients.dragToReorder`,{provider:t}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...l,...d,children:(0,H.jsx)(E,{className:`size-4`})}),(0,H.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:t}),i&&(0,H.jsx)(r,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(r,{tone:`red`,children:c(`routingGroups.memberProblem.${i.problem}`)})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,H.jsx)(`div`,{className:`w-20`,children:(0,H.jsx)(f,{label:c(`routingGroups.weight`),placeholder:c(`routingGroups.weight`),value:e.weight,min:1,step:1,onChange:e=>o(e??1)})}),(0,H.jsx)(u,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":c(`routingGroups.remove`,{name:t}),title:c(`routingGroups.remove`,{name:t}),onClick:s})]})]})}function ue(){let{t:e}=b();return(0,H.jsx)(B,{title:e(`nav.routingGroups`),subtitle:e(`routingGroups.subtitle`),children:(0,H.jsx)(Q,{})})}export{ue as RoutingGroupsPage};
@@ -0,0 +1,2 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$o as n,$s as r,Bo as i,Bt as a,Cr as o,Ct as s,D as c,Do as l,F as u,Fo as d,Ga as f,H as p,Hi as m,Hn as h,I as g,Ia as _,Jn as v,Jt as y,Ko as b,M as x,Mo as S,No as C,O as w,P as T,Pr as E,Qa as D,Qi as O,Qs as k,R as ee,Ra as A,Ro as te,Rt as ne,S as j,Sn as re,Tn as M,U as N,Uo as ie,Ut as ae,Vn as oe,Vo as se,W as P,Wo as ce,Xt as le,Ya as ue,Yo as de,Yt as fe,Z as F,Zi as I,Zo as L,_r as pe,a as me,ca as he,co as R,cs as ge,ds as _e,ei as ve,en as ye,er as be,es as z,ft as B,gi as xe,ha as V,j as Se,jo as Ce,k as we,ls as Te,mn as Ee,mt as De,nr as Oe,os as ke,qa as Ae,r as je,ra as Me,sa as Ne,sn as Pe,so as Fe,ss as Ie,ts as Le,uo as H,w as U,wn as Re,wo as ze,yi as Be,z as W,zi as Ve,zo as He,zt as Ue}from"./format-CskGUFYy.js";import{B as We,H as Ge,R as G,U as K,V as q,W as J,a as Ke,c as qe,dt as Je,i as Ye,o as Xe,r as Ze,s as Qe}from"./TrayTitleSource-B98nYas3.js";import{t as $e}from"./use-transform-BPiFWEVF.js";import{t as et}from"./archive-CiVf7slo.js";import{t as tt}from"./bell-ring-kS9kGwcv.js";import{t as nt}from"./bell-i0ZTNxjY.js";import{t as rt}from"./book-open-W5VGeEf_.js";import{t as it}from"./copy-48gwhhDO.js";import{t as at}from"./ellipsis-CidyZaW2.js";import{t as ot}from"./external-link-D6jQM2CZ.js";import{t as st}from"./flame-BPbKoD7V.js";import{t as ct}from"./flask-conical-P-TiuT25.js";import{t as lt}from"./folder-open-z1RXMZa1.js";import{t as ut}from"./globe-CFH0vwgV.js";import{t as dt}from"./key-round-m9ps8ZDi.js";import{t as ft}from"./list-checks-CStYtbur.js";import{t as pt}from"./log-out-CgcpH2Q7.js";import{t as mt}from"./minus-BxRsdlKm.js";import{t as ht}from"./panel-top-dXjBAa0g.js";import{t as gt}from"./pencil-CpF9MxGZ.js";import{t as _t}from"./plus-c3HzV6VX.js";import{t as vt}from"./refresh-cw-CoLAai2c.js";import{t as yt}from"./rotate-ccw-fsXoCwyv.js";import{t as bt}from"./sliders-horizontal-B2K_lfHz.js";import{t as xt}from"./trash-BHBJn5GS.js";import{t as St}from"./upload-yXA41tlC.js";import{t as Ct}from"./webhook-BiqcD9Uv.js";import{t as wt}from"./x-AFrW8zH7.js";import{B as Tt,D as Et,E as Dt,G as Ot,O as kt,P as At,W as jt,k as Mt,n as Nt,o as Pt,t as Ft,u as It,v as Lt}from"./index-D2siu6xk.js";import{t as Rt}from"./radio-cards-CNQWIuu8.js";import{t as zt}from"./checkbox-29lSW_6h.js";import{t as Bt}from"./TrayPanelView-Cauh6r_o.js";var Y=e(t(),1),X=r(),Vt=[`settings`,`prices`,`providers`,`signins`,`tokens`,`routing`,`privacy`,`tools`,`profiles`,`mcp`,`alerts`,`plugins`,`library`,`clients`,`usage`],Ht=(e,t)=>{let n=`backup.all.section.${t}`,r=e(n);return r===n?t:r};function Ut(e,t){let n=URL.createObjectURL(new Blob([t],{type:`application/json`})),r=document.createElement(`a`);r.href=n,r.download=e,r.click(),URL.revokeObjectURL(n)}function Wt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Gt(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Kt({ids:e,picked:t,onChange:n,counts:r,disabled:i}){let{t:a}=U();return(0,X.jsx)(`div`,{className:`grid gap-x-4 gap-y-1.5 sm:grid-cols-2 md:grid-cols-3`,role:`group`,"aria-label":a(`backup.all.sections`),children:e.map(e=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(zt,{checked:t.has(e),disabled:i,"aria-label":Ht(a,e),onCheckedChange:r=>{let i=new Set(t);r===!0?i.add(e):i.delete(e),n(i)}}),(0,X.jsx)(`span`,{children:Ht(a,e)}),r&&e in r&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:r[e]})]},e))})}var qt={added:`green`,changed:`orange`,removed:`red`,unchanged:`neutral`};function Jt({items:e,truncated:t}){let{t:n}=U();return(0,X.jsxs)(`ul`,{className:`max-h-[220px] divide-y divide-[var(--border)] overflow-auto text-[12px]`,children:[e.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,X.jsx)(c,{tone:qt[e.status]??`neutral`,children:n(`backup.all.status.${e.status}`)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,title:e.id,children:e.label||e.id})]},`${e.id}-${e.status}`)),t&&(0,X.jsx)(`li`,{className:`px-3 py-1.5 text-[11px] text-[var(--text-muted)]`,children:n(`backup.all.truncated`)})]})}function Yt({plan:e}){let{t}=U();return(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:Ht(t,e.section)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,"data-testid":`plan-${e.section}`,children:t(`backup.all.counts`,{added:e.added,changed:e.changed,removed:e.removed,unchanged:e.unchanged})})]}),e.items.length>0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(Jt,{items:e.items,truncated:e.truncated})})]})}function Xt({localOnly:e,onRestore:t}){let{t:n}=U(),{toast:r,confirm:i}=J(),a=fe(),o=O(),s=I(),l=M(),d=a.data,[f,p]=(0,Y.useState)(`24`),[m,h]=(0,Y.useState)(`7`),[_,v]=(0,Y.useState)(``);(0,Y.useEffect)(()=>{d&&(p(String(d.hours)),h(String(d.keep)))},[d?.hours,d?.keep]);let y=(e,t)=>o.mutate(e,{onSuccess:t,onError:e=>r(K(e),`error`)});if(!d)return null;let b=Number(f),x=Number(m),S=Number.isInteger(b)&&b>=1&&Number.isInteger(x)&&x>=1;return(0,X.jsxs)(u,{title:n(`backup.all.auto.title`),footer:e?n(`backup.all.localOnly`):n(`backup.all.auto.hint`,{dir:d.dir}),children:[(0,X.jsx)(W,{label:n(`backup.all.auto.enabled`),children:(0,X.jsx)(P,{checked:d.enabled,disabled:e||o.isPending,label:n(`backup.all.auto.enabled`),onChange:e=>y({enabled:e})})}),(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[12.5px]`,children:[(0,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[n(`backup.all.auto.every`),(0,X.jsx)(g,{className:`w-20`,type:`number`,min:1,"aria-label":n(`backup.all.auto.every`),value:f,onChange:e=>p(e.target.value)}),n(`backup.all.auto.hours`)]}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[n(`backup.all.auto.keep`),(0,X.jsx)(g,{className:`w-20`,type:`number`,min:1,"aria-label":n(`backup.all.auto.keep`),value:m,onChange:e=>h(e.target.value)})]}),(0,X.jsx)(w,{size:`sm`,disabled:e||!S||o.isPending||b===d.hours&&x===d.keep,onClick:()=>y({hours:b,keep:x}),children:n(`common.save`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(g,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":n(`backup.all.auto.passphrase`),placeholder:d.hasPassphrase?n(`backup.all.auto.passphraseSet`):n(`backup.all.auto.passphrase`),value:_,disabled:e,onChange:e=>v(e.target.value)}),(0,X.jsx)(w,{size:`sm`,disabled:e||_.length<8||o.isPending,onClick:()=>y({passphrase:_},()=>v(``)),children:n(`backup.all.auto.setPassphrase`)}),d.hasPassphrase&&(0,X.jsx)(w,{size:`sm`,disabled:e||o.isPending,onClick:()=>y({clearPassphrase:!0}),children:n(`backup.all.auto.clearPassphrase`)})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`backup.all.auto.passphraseHint`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{variant:`primary`,disabled:e||s.isPending,onClick:()=>s.mutate(void 0,{onSuccess:()=>r(n(`backup.all.auto.ran`)),onError:e=>r(K(e),`error`)}),children:n(`backup.all.auto.run`)})})]}),d.files.length===0?(0,X.jsx)(`p`,{className:`px-4 py-3 text-[12px] text-[var(--text-muted)]`,children:n(`backup.all.auto.empty`)}):d.files.map(a=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-2.5 text-[12.5px]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,title:a.name,children:a.name}),(0,X.jsx)(c,{tone:a.kind===`auto`?`neutral`:`accent`,children:n(`backup.all.auto.kind.${a.kind}`)}),a.encrypted&&(0,X.jsx)(c,{tone:`orange`,children:n(`backup.all.auto.encrypted`)}),(0,X.jsxs)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:[Gt(a.at),` · `,Wt(a.size)]}),(0,X.jsx)(w,{size:`sm`,disabled:e,onClick:()=>t(a.name),children:n(`backup.all.auto.restoreFrom`)}),(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(xt,{className:`size-3.5`}),"aria-label":n(`common.delete`),disabled:e||l.isPending,onClick:async()=>{await i({title:n(`backup.all.auto.deleteConfirm`,{name:a.name}),destructive:!0,confirmLabel:n(`common.delete`)})&&l.mutate(a.name,{onError:e=>r(K(e),`error`)})}})]},a.name))]})}function Zt({localOnly:e}){let{t}=U(),{toast:n}=J(),r=Oe(),i=v(),[a,o]=(0,Y.useState)(()=>new Set(Vt.filter(e=>e!==`usage`))),[s,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(null),m=s&&!e,h=i.isPending||a.size===0||m&&l.length<8;return(0,X.jsx)(u,{title:t(`backup.all.export.title`),footer:t(`backup.all.export.hint`),children:(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsx)(Kt,{ids:Vt,picked:a,onChange:o,counts:r.data?.sections}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(zt,{checked:m,disabled:e,"aria-label":t(`backup.all.export.keys`),onCheckedChange:e=>c(e===!0)}),(0,X.jsx)(`span`,{children:t(`backup.all.export.keys`)})]}),e&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`backup.all.localOnly.keys`)}),m&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(g,{type:`password`,autoComplete:`new-password`,"aria-label":t(`backup.all.passphrase`),placeholder:t(`backup.all.passphrase`),value:l,onChange:e=>d(e.target.value)}),(0,X.jsx)(j,{tone:`warning`,title:t(`backup.all.passphrase.warn`)}),l.length>0&&l.length<8&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--danger)]`,children:t(`backup.all.passphrase.short`,{min:8})})]}),!m&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`backup.all.export.noKeys`)}),f&&(0,X.jsx)(j,{tone:`danger`,title:t(`common.error`),children:f}),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{variant:`primary`,icon:(0,X.jsx)(Tt,{className:`size-3.5`}),disabled:h,onClick:()=>{p(null),i.mutate({sections:Vt.filter(e=>a.has(e)&&e!==`usage`),includeUsage:a.has(`usage`),includeKeys:m,passphrase:m?l:void 0},{onSuccess:e=>{Ut(e.name,e.content),n(t(`backup.all.export.done`,{count:e.documents})),d(``)},onError:e=>p(K(e))})},children:t(`backup.all.export.run`)})})]})})}function Qt({localOnly:e,autoName:t}){let{t:n}=U(),{toast:r,confirm:i}=J(),a=fe(!e),o=ve(),s=m(),l=(0,Y.useRef)(null),[d,f]=(0,Y.useState)(`file`),[h,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(``),[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)(``),[T,E]=(0,Y.useState)(`merge`),[D,O]=(0,Y.useState)(null),[k,ee]=(0,Y.useState)(new Set),[A,te]=(0,Y.useState)(null),[ne,re]=(0,Y.useState)(null),M=()=>{O(null),te(null),re(null)};(0,Y.useEffect)(()=>{t&&(f(`auto`),x(t),M())},[t]);let N=e=>({source:d,content:d===`file`?h??void 0:void 0,name:d===`auto`?b:void 0,passphrase:S||void 0,sections:e,mode:T}),ie=d===`file`?h!==null:d!==`auto`||b!==``,ae=()=>{M(),o.mutate(N(),{onSuccess:e=>{O(e),ee(new Set(e.available))},onError:e=>re(K(e))})},oe=async()=>{D&&(T!==`replace`||await i({title:n(`backup.all.restore.replaceConfirm`),detail:n(`backup.all.restore.replaceDetail`),confirmLabel:n(`backup.all.restore.run`),destructive:!0}))&&(re(null),s.mutate(N(D.legacy?void 0:[...k]),{onSuccess:e=>{te(e),O(null),C(``),r(n(`backup.all.restore.done`,{written:e.written,removed:e.removed}))},onError:e=>re(K(e))}))},se=async e=>{M(),_(null),y(``),e&&(_(await e.text()),y(e.name))},P=a.data?.files??[];return(0,X.jsx)(u,{title:n(`backup.all.restore.title`),footer:e?n(`backup.all.localOnly`):void 0,children:(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsx)(p,{value:d,onChange:e=>{f(e),M()},items:[{value:`file`,label:n(`backup.all.restore.source.file`)},{value:`auto`,label:n(`backup.all.restore.source.auto`)},{value:`remote`,label:n(`backup.all.restore.source.remote`)}]}),d===`file`&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{ref:l,type:`file`,className:`hidden`,"aria-label":n(`backup.all.restore.choose`),onChange:e=>{se(e.target.files?.[0]),e.target.value=``}}),(0,X.jsx)(w,{icon:(0,X.jsx)(St,{className:`size-3.5`}),disabled:e,onClick:()=>l.current?.click(),children:n(`backup.all.restore.choose`)}),v&&(0,X.jsx)(`span`,{className:`truncate font-mono text-[12px]`,children:v})]}),d===`auto`&&(0,X.jsx)(q,{className:`w-full`,ariaLabel:n(`backup.all.restore.source.auto`),placeholder:n(`backup.all.restore.pickAuto`),value:b||null,onChange:e=>{x(e),M()},options:P.map(e=>({value:e.name,label:`${e.name} · ${Gt(e.at)}`}))}),d===`remote`&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`backup.all.restore.remoteHint`)}),(0,X.jsx)(g,{type:`password`,autoComplete:`off`,"aria-label":n(`backup.all.restore.passphrase`),placeholder:n(`backup.all.restore.passphrase`),value:S,onChange:e=>C(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:n(`backup.all.restore.mode`)}),(0,X.jsx)(p,{value:T,onChange:e=>{E(e),M()},items:[{value:`merge`,label:n(`backup.all.restore.mode.merge`)},{value:`replace`,label:n(`backup.all.restore.mode.replace`)}]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(T===`merge`?`backup.all.restore.mode.mergeHint`:`backup.all.restore.mode.replaceHint`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{disabled:e||!ie||o.isPending,onClick:ae,children:n(`backup.all.restore.preview`)})}),ne&&(0,X.jsx)(j,{tone:`danger`,title:n(`common.error`),children:ne}),D&&(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{children:n(`backup.all.restore.created`,{time:Gt(D.createdAt),version:D.astraVersion})}),(0,X.jsx)(c,{tone:D.hasKeys?`orange`:`neutral`,children:D.hasKeys?n(`backup.all.restore.hasKeys`):n(`backup.all.restore.noKeys`)})]}),D.notes.map(e=>(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:e},e)),D.legacy?(0,X.jsx)(j,{tone:`info`,title:n(`backup.all.restore.legacy`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Kt,{ids:D.available,picked:k,onChange:ee}),(0,X.jsx)(`div`,{className:`grid gap-3`,children:D.sections.filter(e=>k.has(e.section)).map(e=>(0,X.jsx)(Yt,{plan:e},e.section))})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{variant:`primary`,disabled:s.isPending||!D.legacy&&k.size===0,onClick:()=>void oe(),children:n(`backup.all.restore.run`)})})]}),A&&(0,X.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`restore-result`,children:[(0,X.jsx)(j,{tone:A.errors.length>0?`warning`:`success`,title:n(`backup.all.restore.done`,{written:A.written,removed:A.removed})}),A.safetyBackup&&(0,X.jsx)(`p`,{className:`text-[12px]`,children:n(`backup.all.restore.safety`,{name:A.safetyBackup})}),A.skipped.length>0&&(0,X.jsxs)(`div`,{className:`text-[12px]`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:n(`backup.all.restore.skipped`,{count:A.skipped.length})}),(0,X.jsx)(`ul`,{className:`list-disc pl-5 text-[var(--text-muted)]`,children:A.skipped.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),A.errors.length>0&&(0,X.jsxs)(`div`,{className:`text-[12px]`,children:[(0,X.jsx)(`div`,{className:`font-medium text-[var(--danger)]`,children:n(`backup.all.restore.errors`,{count:A.errors.length})}),(0,X.jsx)(`ul`,{className:`list-disc pl-5 text-[var(--danger)]`,children:A.errors.map(e=>(0,X.jsx)(`li`,{children:e},e))})]})]})]})})}var $t=Vt.filter(e=>e!==`usage`),en=[`folder`,`webdav`,`s3`,`github`];function tn({localOnly:e}){let{t}=U(),{toast:n,confirm:r}=J(),i=A().data,a=Me(),o=f(),s=_(),l=be(),p=Pe(),m=d(),[h,v]=(0,Y.useState)(`folder`),[y,b]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(``),[C,T]=(0,Y.useState)(``),[E,D]=(0,Y.useState)(``),[O,k]=(0,Y.useState)(``),[ee,te]=(0,Y.useState)(``),[ne,re]=(0,Y.useState)(!1),[M,N]=(0,Y.useState)(``),[ie,ae]=(0,Y.useState)(``),[oe,se]=(0,Y.useState)(`15`),[ce,le]=(0,Y.useState)(new Set($t)),[ue,de]=(0,Y.useState)(!1),[fe,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(null),[pe,me]=(0,Y.useState)(null),he=i?.configured;if((0,Y.useEffect)(()=>{if(!i)return;let e=i.target;v(e.kind||`folder`),b(e.url),S(e.username),D(e.folder),k(e.bucket),te(e.region),re(e.pathStyle),N(e.branch),se(String(i.intervalMinutes||15)),le(new Set(i.sections.length>0?i.sections:$t)),de(i.includeKeys),F(i.includeSignins),T(``),ae(``)},[i===void 0,he]),!i)return null;let R=e=>me(K(e)),ge=()=>({kind:h,url:h===`webdav`||h===`s3`||h===`github`?y.trim():void 0,username:h===`webdav`||h===`s3`?x.trim():void 0,secret:C||void 0,folder:E.trim(),bucket:h===`s3`?O.trim():void 0,region:h===`s3`?ee.trim():void 0,pathStyle:h===`s3`?ne:void 0,branch:h===`github`?M.trim():void 0}),_e=()=>({target:ge(),passphrase:ie||void 0,intervalMinutes:Math.max(1,Number(oe)||15),sections:[...$t.filter(e=>ce.has(e))],includeKeys:ue,includeSignins:fe}),ve=e=>{me(null),a.mutate(_e(),{onSuccess:()=>{T(``),ae(``),e?.()},onError:R})},ye=()=>ve(()=>o.mutate(void 0,{onSuccess:()=>n(t(`sync.test.ok`)),onError:R})),z=e=>{me(null),L(null),s.mutate(e,{onSuccess:r=>{L(r),e||n(t(`sync.run.done`,{pushed:r.pushed,pulled:r.pulled}))},onError:R})},B=async()=>{await r({title:t(`sync.forget.confirm`),detail:t(`sync.forget.detail`),destructive:!0,confirmLabel:t(`sync.forget`)})&&l.mutate(void 0,{onSuccess:()=>L(null),onError:R})},xe=()=>{me(null),m.mutate({sections:[...$t.filter(e=>ce.has(e))],includeKeys:ue,passphrase:ie||void 0},{onSuccess:e=>n(t(`sync.upload.done`,{name:e.name})),onError:R})},V=a.isPending||o.isPending||s.isPending||i.running,Se=i.target.hasSecret&&i.target.kind===h?t(`sync.secret.saved`):t(`sync.secret.${h}`),Ce=ie.length===0?i.hasPassphrase:ie.length>=8;return(0,X.jsxs)(u,{title:t(`sync.title`),footer:t(e?`backup.all.localOnly`:`sync.hint`),children:[(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:t(`sync.kind`)}),(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`sync.kind`),value:h,disabled:e,onChange:e=>v(e),options:en.map(e=>({value:e,label:t(`sync.kind.${e}`)}))})]}),(h===`webdav`||h===`s3`||h===`github`)&&(0,X.jsx)(g,{"aria-label":t(`sync.url.${h}`),placeholder:t(`sync.url.${h}`),value:y,disabled:e,onChange:e=>b(e.target.value)}),h===`s3`&&(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsx)(g,{"aria-label":t(`sync.bucket`),placeholder:t(`sync.bucket`),value:O,disabled:e,onChange:e=>k(e.target.value)}),(0,X.jsx)(g,{"aria-label":t(`sync.region`),placeholder:t(`sync.region`),value:ee,disabled:e,onChange:e=>te(e.target.value)})]}),(h===`webdav`||h===`s3`)&&(0,X.jsx)(g,{"aria-label":t(h===`s3`?`sync.accessKey`:`sync.username`),placeholder:t(h===`s3`?`sync.accessKey`:`sync.username`),value:x,disabled:e,onChange:e=>S(e.target.value)}),h!==`folder`&&(0,X.jsx)(g,{type:`password`,autoComplete:`new-password`,"aria-label":t(`sync.secret`),placeholder:Se,value:C,disabled:e,onChange:e=>T(e.target.value)}),h===`github`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(g,{"aria-label":t(`sync.branch`),placeholder:t(`sync.branch`),value:M,disabled:e,onChange:e=>N(e.target.value)}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.github.private`)})]}),h===`s3`&&(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(zt,{checked:ne,disabled:e,"aria-label":t(`sync.pathStyle`),onCheckedChange:e=>re(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.pathStyle`)})]}),(0,X.jsx)(g,{"aria-label":t(`sync.folder`),placeholder:t(`sync.folder.${h}`),value:E,disabled:e,onChange:e=>D(e.target.value)}),(0,X.jsx)(g,{type:`password`,autoComplete:`new-password`,"aria-label":t(`sync.passphrase`),placeholder:i.hasPassphrase?t(`sync.passphrase.saved`):t(`sync.passphrase`),value:ie,disabled:e,onChange:e=>ae(e.target.value)}),(0,X.jsx)(j,{tone:`warning`,title:t(`sync.passphrase.warn`)}),ie.length>0&&ie.length<8&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--danger)]`,children:t(`backup.all.passphrase.short`,{min:8})}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[t(`sync.interval`),(0,X.jsx)(g,{className:`w-20`,type:`number`,min:1,"aria-label":t(`sync.interval`),value:oe,disabled:e,onChange:e=>se(e.target.value)}),t(`sync.minutes`)]}),(0,X.jsx)(Kt,{ids:$t,picked:ce,onChange:le,disabled:e}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(zt,{checked:fe,disabled:e,"aria-label":t(`sync.includeSignins`),onCheckedChange:e=>F(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.includeSignins`)})]}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(zt,{checked:ue,disabled:e,"aria-label":t(`sync.includeKeys`),onCheckedChange:e=>de(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.includeKeys`)})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.includeKeys.hint`)}),pe&&(0,X.jsx)(j,{tone:`danger`,title:t(`common.error`),children:pe}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(w,{disabled:e||V,onClick:ye,children:t(`sync.test`)}),(0,X.jsx)(w,{variant:`primary`,disabled:e||V||!Ce,onClick:()=>ve(()=>n(t(`sync.saved`))),children:t(`common.save`)}),(0,X.jsx)(w,{disabled:e||V||!i.configured,onClick:()=>z(!1),children:t(`sync.now`)}),(0,X.jsx)(w,{disabled:e||V||!i.configured,onClick:()=>z(!0),children:t(`sync.preview`)}),(0,X.jsx)(w,{disabled:e||V||!i.configured,onClick:xe,children:t(`sync.upload`)}),(0,X.jsx)(w,{disabled:e||l.isPending||!i.configured,onClick:()=>void B(),children:t(`sync.forget`)})]})]}),(0,X.jsx)(W,{label:t(`sync.enabled`),detail:i.configured?void 0:t(`sync.notConfigured`),children:(0,X.jsx)(P,{checked:i.enabled,disabled:e||!i.configured||a.isPending,label:t(`sync.enabled`),onChange:e=>a.mutate({enabled:e},{onError:R})})}),(0,X.jsx)(nn,{s:i}),I&&(0,X.jsxs)(`div`,{className:`grid gap-2 p-4`,"data-testid":`sync-run`,children:[(0,X.jsx)(`div`,{className:`text-[12.5px] font-medium`,children:I.dryRun?t(`sync.run.preview`,{pushed:I.pushed,pulled:I.pulled}):t(`sync.run.done`,{pushed:I.pushed,pulled:I.pulled})}),I.firstSync&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.run.first`)}),I.items.length>0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(Jt,{items:I.items})}),I.errors.map(e=>(0,X.jsx)(j,{tone:`danger`,title:e},e))]}),i.conflicts.length>0&&(0,X.jsxs)(`div`,{className:`grid gap-2 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] font-medium`,children:t(`sync.conflicts`,{count:i.conflicts.length})}),(0,X.jsx)(w,{size:`sm`,disabled:e||p.isPending,onClick:()=>p.mutate(void 0,{onError:R}),children:t(`sync.conflicts.clear`)})]}),(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)] text-[12px]`,children:i.conflicts.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 px-3 py-1.5`,children:[(0,X.jsx)(c,{children:t(`backup.all.section.${e.section}`)}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label||e.id}),(0,X.jsx)(c,{tone:e.winner===`local`?`green`:`orange`,children:e.winner===`local`?t(`sync.winner.local`):t(`sync.winner.remote`)}),(0,X.jsxs)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:[Gt(e.at),` · `,e.device]})]},`${e.section}/${e.id}/${e.at}`))})]})]})}function nn({s:e}){let{t}=U();return(0,X.jsxs)(`div`,{className:`grid gap-1 p-4 text-[12px]`,"data-testid":`sync-status`,children:[(0,X.jsxs)(`div`,{children:[t(`sync.status.last`),`: `,e.lastSyncAt?Gt(e.lastSyncAt):t(`sync.status.never`),e.running&&` · ${t(`sync.status.running`)}`]}),(0,X.jsx)(`div`,{children:t(`sync.status.counts`,{pushed:e.lastPushed,pulled:e.lastPulled,tracked:e.tracked})}),(0,X.jsxs)(`div`,{className:`text-[var(--text-muted)]`,children:[t(`sync.status.device`),`: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.deviceId})]}),e.lastError&&(0,X.jsx)(j,{tone:`danger`,title:t(`sync.status.error`),children:e.lastError})]})}function rn(){let{t:e}=U(),t=y().data?.required===!0,[n,r]=(0,Y.useState)(null);return(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[t&&(0,X.jsx)(j,{tone:`info`,title:e(`backup.all.localOnly`)}),(0,X.jsx)(Zt,{localOnly:t}),(0,X.jsx)(Qt,{localOnly:t,autoName:n}),(0,X.jsx)(Xt,{localOnly:t,onRestore:r}),(0,X.jsx)(tn,{localOnly:t})]})}var an=`https://astra-gate.si/docs/guide/remote-access`,on=`astra.remote.acknowledged`;function sn(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 cn(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 ln(){try{return localStorage.getItem(on)===`1`}catch{return!1}}function un(){try{localStorage.setItem(on,`1`)}catch{}}function dn(){let{t:e}=U(),t=Fe(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(fn,{s:n}),(0,X.jsx)(pn,{s:n}),(0,X.jsx)(mn,{s:n}),(0,X.jsx)(_n,{s:n}),(0,X.jsx)(Se,{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)(j,{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:K(t.error)}):(0,X.jsx)(N,{className:`mx-auto my-8`})})}function fn({s:e}){let{t,locale:n}=U(),{toast:r,confirm:i}=J(),a=ue(),o=y(),s=sn(e,t),c=async e=>{await G.copy(e)&&r(t(`common.copied`))},l=async e=>{if(e&&!ln()){if(!await i({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;un()}(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(K(e),`error`)})},d=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,f=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,p=e.state===`connected`&&f!==null?f<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:me(f,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)(u,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(W,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?je(e.connectedAt,n):void 0,children:[(0,X.jsx)(x,{tone:d}),p,m.downloading&&m.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(m.progress*100),`%`]})]}),children:(0,X.jsx)(P,{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)(W,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${v}/v1`}),children:[(0,X.jsx)(We,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(it,{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)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ot,{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)(j,{tone:e.state===`connected`?`warning`:`danger`,title:cn(g,e,t),children:g})})]})}function pn({s:e}){let{t}=U(),{toast:n,confirm:r}=J(),i=Ce(),[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(K(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(K(e),`error`)}),d=a.token.trim()!==``||a.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(u,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(W,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(p,{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)(j,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(g,{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)(W,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(g,{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)(W,{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)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{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)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(rt,{className:`size-3.5`}),onClick:()=>window.open(an,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(w,{size:`sm`,disabled:!d||i.isPending,onClick:l,children:t(`common.save`)})]})]})]})}function mn({s:e}){let{t}=U(),{toast:n,confirm:r}=J(),i=Ce(),a=y(),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(K(e),`error`)})};return(0,X.jsxs)(u,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(W,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(c,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(W,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(P,{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)(hn,{passwordSet:e.checks.passwordSet})]})}function hn({passwordSet:e}){let{t}=U(),{toast:n}=J(),r=y(),i=Ne(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!a&&!r.data?.required&&(0,X.jsx)(w,{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)(g,{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)(w,{size:`sm`,variant:`plain`,onClick:()=>o(!1),children:t(`common.cancel`)}),(0,X.jsx)(w,{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(K(e),`error`)}),children:t(`common.save`)})]})]})}var gn=[`auto`,`github`,`astra`,`custom`];function _n({s:e}){let{t}=U(),{toast:n}=J(),r=Ce(),i=h(),a=y(),o=e.cloudflared,[s,c]=(0,Y.useState)(e.download.downloadBaseUrl??``),[l,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>c(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[m,_]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>_(e.download.downloadSource),[e.download.downloadSource]);let v=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(K(e),`error`)}),b=t=>{_(t),(t!==`custom`||e.download.downloadBaseUrl)&&v({downloadSource:t})},S=()=>i.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(K(e),`error`)}),C=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)(u,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(W,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:o.path??void 0,children:C}),children:(0,X.jsx)(x,{tone:o.path?`green`:o.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!o.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${m}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:m,onChange:b,options:gn.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),m===`custom`&&(0,X.jsxs)(W,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(g,{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)(w,{size:`sm`,disabled:!s.trim()||r.isPending||s.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>v({downloadSource:`custom`,downloadBaseUrl:s.trim()}),children:t(`common.save`)})]})]}),!a.data?.remote&&!o.fromEnvironment&&(0,X.jsx)(W,{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)(w,{size:`sm`,disabled:r.isPending,onClick:()=>v({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!l&&(0,X.jsx)(w,{size:`sm`,onClick:()=>{d(!0),S()},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)(g,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(w,{size:`sm`,variant:`plain`,loading:i.isPending,onClick:S,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(w,{size:`sm`,variant:`plain`,onClick:()=>d(!1),children:t(`common.cancel`)}),(0,X.jsx)(w,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>v({cloudflaredPath:f.trim()},()=>d(!1)),children:t(`settings.remote.cf.use`)})]})]})}var vn=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],yn={local:`127.0.0.1`,lan:`0.0.0.0`},bn=e=>vn.includes(e)?`local`:`lan`;function xn(){let{t:e}=U(),{toast:t,confirm:n}=J(),r=k(),i=pe(),a=y(),o=H(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=i.data;if(!d)return(0,X.jsx)(W,{label:e(`settings.listen`),detail:i.isError?K(i.error):void 0,children:i.isPending&&(0,X.jsx)(N,{className:`size-3.5`})});let f=`${d.host}:${d.port}`,m=bn(d.configuredHost),h=d.configuredHost!==d.host,g=!!a.data?.required,_=async n=>{await G.copy(n)&&t(e(`common.copied`))},v=n=>o.mutate(yn[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(K(e),`error`)}),b=async t=>{if(t!==m){if(t===`lan`){if(!d.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)}},x=async()=>{u(!0);let n=await G.restartService();if(u(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},S=d.hostFromEnvironment?e(`settings.listen.env`,{address:f}):g?e(`settings.listen.localOnly`,{address:f}):h?`${e(`settings.listen.pending`,{host:d.configuredHost})}${z?``:` · ${e(`settings.listen.restartHint`)}`}`:f;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:e(`settings.listen`),detail:S,children:!d.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&z&&(0,X.jsx)(w,{size:`sm`,loading:l,onClick:()=>void x(),children:e(`settings.listen.restart`)}),(0,X.jsx)(p,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void b(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),d.networkUrls.map(t=>(0,X.jsx)(W,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||d.networkUrls.length>0)&&(0,X.jsx)(hn,{passwordSet:d.passwordSet}),(0,X.jsx)(Sn,{open:s,onOpenChange:c,onSaved:()=>v(`lan`)})]})}function Sn({open:e,onOpenChange:t,onSaved:n}){let{t:r}=U(),{toast:i}=J(),a=Ne(),[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(K(e),`error`)})};return(0,X.jsx)(Ge,{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)(w,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(w,{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)(g,{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)(g,{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 Cn=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],wn={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/…`},Tn=e=>e===`feishu`||e===`dingtalk`,En=(e,t)=>e(`alerts.event.${t}`),Dn=(e,t)=>e(`alerts.event.${t}.hint`);function On(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(kn,{}),(0,X.jsx)(An,{}),(0,X.jsx)(Fn,{})]})}function kn(){let{t:e,locale:t}=U(),n=a(!0);return(0,X.jsxs)(u,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(N,{}),n.data?.length===0&&(0,X.jsx)(W,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(W,{icon:(0,X.jsx)(tt,{className:`size-4 text-[var(--danger)]`}),label:`${En(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${je(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function An(){let{t:e}=U(),{toast:t,confirm:n}=J(),r=ce(),i=oe(),a=Ae(),o=Ve(),[s,l]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),h=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(K(e),`error`)}),g=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&o.mutate(r.id,{onSuccess:e=>m(e.secret??null),onError:e=>t(K(e),`error`)})},_=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&i.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(K(e),`error`)})};return(0,X.jsxs)(u,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(N,{}),r.data?.length===0&&(0,X.jsx)(W,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(W,{icon:(0,X.jsx)(Ct,{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)(c,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(c,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||Tn(t.format))&&(0,X.jsx)(c,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(ct,{className:`size-3.5`}),loading:a.isPending&&a.variables===t.id,onClick:()=>h(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(We,{label:e(`common.more`),icon:(0,X.jsx)(at,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(gt,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>f(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(dt,{className:`size-3.5`}),onSelect:()=>void g(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(xt,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void _(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(jn,{hook:s,onClose:()=>l(null),onSecret:m}),(0,X.jsx)(Nn,{hook:d,onClose:()=>f(null)}),(0,X.jsx)(Mn,{secret:p,onClose:()=>m(null)})]})}function jn({hook:e,onClose:t,onSecret:n}){let{t:r}=U(),{toast:i}=J(),a=re(),o=C(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(10),[p,m]=(0,Y.useState)(!0),[h,_]=(0,Y.useState)(!0),[v,y]=(0,Y.useState)(!0),[b,x]=(0,Y.useState)(`generic`),[S,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)([]),k=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),_(t?.enabled??!0),y(!t||t.hasSecret),x(t?.format??`generic`),E(``),O((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(k?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(w,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(w,{variant:`primary`,disabled:!s.trim()||!l.trim(),loading:a.isPending||o.isPending,onClick:()=>{let c=Object.fromEntries(D.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(K(e),`error`)},m=!k&&e!==null&&e.format!==b,g=Tn(b)?v?S.trim()||void 0:``:void 0;k?a.mutate({...u,format:b,...b===`generic`?{signed:v}:g?{secret:g}:{}},{...f,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&o.mutate({id:e.id,...u,...m?{format:b}:{},...b===`generic`?v||!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)(T,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(g,{value:s,maxLength:64,onChange:e=>c(e.target.value)})}),(0,X.jsx)(T,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${b}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:b,onChange:t=>{x(t),y(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||Tn(t))},options:Cn.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(T,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(g,{mono:!0,value:l,placeholder:wn[b],onChange:e=>u(e.target.value)})}),Tn(b)&&v&&(0,X.jsx)(T,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(g,{mono:!0,type:`password`,autoComplete:`off`,value:S,placeholder:e!==`new`&&e!==null&&e.format===b&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>E(e.target.value)})}),(0,X.jsx)(T,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(ee,{value:d,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:f})}),(0,X.jsx)(T,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[D.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)(g,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>O(D.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(g,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>O(D.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(xt,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>O(D.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>O([...D,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(W,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(P,{checked:h,label:r(`alerts.webhooks.enabled`),onChange:_})}),(0,X.jsx)(W,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(P,{checked:p,label:r(`alerts.webhooks.useProxy`),onChange:m})}),(b===`generic`?k||e!==null&&e.format===`generic`&&e.hasSecret:Tn(b))&&(0,X.jsx)(W,{label:r(`alerts.webhooks.signed`),detail:r(b===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(P,{checked:v,label:r(`alerts.webhooks.signed`),onChange:y})})]})]})})}function Mn({secret:e,onClose:t}){let{t:n}=U(),{toast:r}=J();return(0,X.jsx)(Ge,{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)(w,{onClick:async()=>e&&await G.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(w,{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 Nn({hook:e,onClose:t}){let{t:n,locale:r}=U(),{toast:i}=J(),a=ie(e?.id),o=Be(),s={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${n(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[a.isLoading&&(0,X.jsx)(N,{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)(c,{tone:s[e.status],children:n(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?n(`alerts.webhooks.test`):En(n,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:je(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:je(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)(we,{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)(we,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{size:`sm`,loading:o.isPending&&o.variables===e.id,onClick:()=>o.mutate(e.id,{onSuccess:()=>i(n(`alerts.delivery.redelivered`)),onError:e=>i(K(e),`error`)}),children:n(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Pn(e){let t=xe(),n=D(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=Je({queries:r.map(t=>({queryKey:s.providerAccounts(t.id),queryFn:()=>b(`GET`,`/api/providers/${de(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(t.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(n.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?r.flatMap((e,t)=>(i[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Fn(){let{t:e}=U(),{toast:t,confirm:n}=J(),r=Ue(),i=ce(),a=R(),o=Re(),[s,l]=(0,Y.useState)(null),d=e=>i.data?.find(t=>t.id===e)?.name??e,f=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(K(e),`error`)})};return(0,X.jsxs)(u,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(N,{}),r.data?.length===0&&(0,X.jsx)(W,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(W,{icon:(0,X.jsx)(tt,{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)(c,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(c,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${En(e,n.event)} → ${n.webhookIds.map(d).join(`, `)||`—`}`,children:[(0,X.jsx)(P,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>a.mutate({id:n.id,enabled:e},{onError:e=>t(K(e),`error`)})}),(0,X.jsx)(We,{label:e(`common.more`),icon:(0,X.jsx)(at,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(gt,{className:`size-3.5`}),onSelect:()=>l(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(xt,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void f(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Ln,{rule:s,onClose:()=>l(null)})]})}function In(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 Ln({rule:e,onClose:t}){let{t:n}=U(),{toast:r}=J(),i=ne(),a=ce(),o=Ee(),s=R(),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(``),[f,m]=(0,Y.useState)({}),[h,_]=(0,Y.useState)(`all`),[v,y]=(0,Y.useState)([]),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(60),A=i.data?.find(e=>e.id===u),te=Pn(A?.subjectType),j=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?{...In(i.data?.find(e=>e.id===t.event)),...t.condition}:In(n)),_(t?.subjects?`only`:`all`),y(t?.subjects??[]),x(t?.webhookIds??(a.data??[]).map(e=>e.id)),C(t?.notifyResolved??!1),D(t?.repeatMinutes??null),k(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(j?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(w,{variant:`primary`,disabled:!c.trim()||!u,loading:o.isPending||s.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(f).filter(([,e])=>e!==null&&e!==``)),a={name:c.trim(),event:u,condition:i,subjects:h===`all`?null:v,webhookIds:b,notifyResolved:S,repeatMinutes:E&&E>0?Math.floor(E):null,cooldownMinutes:Math.max(0,Math.floor(O??0))},l={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(K(e),`error`)};j?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)(T,{label:n(`alerts.rules.name`),children:(0,X.jsx)(g,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,X.jsx)(T,{label:n(`alerts.rules.event`),hint:u?Dn(n,u):void 0,children:(0,X.jsx)(q,{ariaLabel:n(`alerts.rules.event`),value:u,onChange:e=>{d(e),m(In(i.data?.find(t=>t.id===e))),y([])},options:(i.data??[]).map(e=>({value:e.id,label:En(n,e.id)}))})}),A?.params.map(e=>(0,X.jsx)(T,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(ee,{value:typeof f[e.name]==`number`?f[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>m({...f,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:n(`alerts.param.${e.name}`),value:String(f[e.name]??``),onChange:t=>m({...f,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(g,{mono:!0,value:String(f[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>m({...f,[e.name]:t.target.value})})},e.name)),A&&(0,X.jsx)(T,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${A.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(p,{ariaLabel:n(`alerts.rules.subjects`),value:h,onChange:_,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),h===`only`&&(0,X.jsx)(It,{label:n(`alerts.rules.subjects`),value:v,onValueChange:y,options:[...te,...v.filter(e=>!te.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(T,{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)(It,{label:n(`alerts.rules.webhooks`),value:b,onValueChange:x,options:(a.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(T,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(ee,{value:E,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:D})}),(0,X.jsx)(T,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(ee,{value:O,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:k})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(W,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(P,{checked:S,label:n(`alerts.rules.notifyResolved`),onChange:C})})})]})})}function Rn(){let{t:e}=U(),t=le(),r=n()?.loginItem,i=t.data?.mechanism===`launchd`||!!r&&Le;return(0,X.jsxs)(u,{title:e(`settings.startup`),footer:i?e(`settings.startup.macFooter`):void 0,children:[r&&(0,X.jsx)(zn,{loginItem:r}),(0,X.jsx)(Bn,{})]})}function zn({loginItem:e}){let{t}=U(),{toast:n}=J(),[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)(W,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(P,{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(K(e),`error`)).finally(()=>o(!1))}}):(0,X.jsx)(N,{className:`size-3.5`})})}function Bn(){let{t:e}=U(),{toast:t}=J(),n=le(),r=he(),i=n.data;if(!i)return(0,X.jsx)(W,{label:e(`settings.startup.service`),detail:n.isError?K(n.error):void 0,children:n.isPending&&(0,X.jsx)(N,{className:`size-3.5`})});let a=!i.supported||i.mechanism===`none`?e(`settings.startup.unsupported.${i.unsupported??`platform`}`):i.canChange?i.enabled&&i.location?e(`settings.startup.entry`,{location:i.location}):e(`settings.startup.service.${i.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(W,{label:e(`settings.startup.service`),detail:a,children:i.supported&&(0,X.jsx)(P,{checked:i.enabled,disabled:!i.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(K(e),`error`)})})})}function Vn(){let{t:e}=U(),{toast:t}=J(),r=k(),i=ze(),a=V(),o=l(),c=ye(),u=o.data,d=a.data?.updateChannel??u?.channel,f=n()?.updates??null,[p,m]=(0,Y.useState)(!1),h=ae(),g=!f&&u?.containerUpdater===!0,_=()=>h.mutate(void 0,{onSuccess:n=>n.applyError?t(e(`settings.updateContainerFailed`,{error:n.applyError}),`error`):t(e(`settings.updateContainerRequested`)),onError:e=>t(K(e),`error`)}),v=()=>c.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(K(e),`error`)}),y=()=>{f&&!p&&(m(!0),f.apply().then(n=>{n===`server`?(t(e(`settings.updateApplied`)),r.invalidateQueries({queryKey:s.version}),r.invalidateQueries({queryKey:s.update})):t(e(n===`desktop`?`settings.updateDesktopRelaunch`:n===`download`?`settings.updateDownloadOpened`:n===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(K(e),`error`)).finally(()=>m(!1)))},b=u?.lastCheckAt?new Date(u.lastCheckAt).toLocaleString():void 0,x=g&&u?.available&&u.applyVersion===u.available&&u.applyRequestedAt?u.applyError?e(`settings.updateContainerFailed`,{error:u.applyError}):e(`settings.updateContainerPending`,{version:u.available,time:new Date(u.applyRequestedAt).toLocaleString()}):void 0,S=u?.available?x??(f?e(`settings.updateAvailable`,{version:u.available}):`${e(`settings.updateAvailable`,{version:u.available})} ${e(g?`settings.updateContainerHint`:`settings.updateApplyHint`)}`):void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:e(`settings.autoCheck`),detail:u&&!u.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(P,{checked:u?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>i.mutate({updateAutoCheck:e},{onError:e=>t(K(e),`error`)})})}),g&&(0,X.jsx)(W,{label:e(`settings.autoApply`),detail:e(`settings.autoApplyHint`),children:(0,X.jsx)(P,{checked:u?.autoApply??!0,label:e(`settings.autoApply`),disabled:i.isPending,onChange:e=>i.mutate({updateAutoApply:e},{onSuccess:()=>void r.invalidateQueries({queryKey:s.update}),onError:e=>t(K(e),`error`)})})}),(0,X.jsx)(W,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(P,{checked:d===`preview`,label:e(`settings.previewUpdates`),disabled:!d||i.isPending,onChange:e=>i.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:v,onError:e=>t(K(e),`error`)})})}),(0,X.jsxs)(W,{label:e(`settings.checkUpdates`),detail:c.isError?e(`settings.updateCheckFailed`,{error:K(c.error)}):u?.available?S:b?e(`settings.lastChecked`,{time:b}):void 0,children:[(0,X.jsx)(w,{size:`sm`,variant:`plain`,disabled:c.isPending,onClick:v,children:c.isPending?(0,X.jsx)(N,{className:`size-3.5`}):(0,X.jsx)(vt,{className:`size-3.5`})}),f&&u?.available&&(0,X.jsx)(w,{size:`sm`,variant:`plain`,disabled:p,"aria-label":e(`settings.updateApply`),onClick:y,children:p?(0,X.jsx)(N,{className:`size-3.5`}):(0,X.jsx)(Tt,{className:`size-3.5`})}),g&&u?.available&&(0,X.jsx)(w,{size:`sm`,variant:`plain`,disabled:h.isPending,"aria-label":e(`settings.updateApply`),onClick:_,children:h.isPending?(0,X.jsx)(N,{className:`size-3.5`}):(0,X.jsx)(Tt,{className:`size-3.5`})})]})]})}var Hn=[1,2,3,4,5,6,0],Un=/^([01]\d|2[0-3]):[0-5]\d$/;function Wn(){let{t:e}=U(),{toast:t}=J(),n=se(),r=S(),[i,a]=(0,Y.useState)(``),o=n.data;if(!o)return n.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:K(n.error)}):(0,X.jsx)(N,{className:`mx-auto my-8`});let s=n=>r.mutate(n,{onSuccess:()=>t(e(`warmup.saved`),`success`),onError:e=>t(K(e),`error`)}),l=()=>{Un.test(i)&&!o.times.includes(i)&&(s({times:[...o.times,i].sort()}),a(``))},d=e=>s({weekdays:o.weekdays.includes(e)?o.weekdays.filter(t=>t!==e):[...o.weekdays,e].sort()});return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(u,{title:e(`warmup.title`),footer:e(`warmup.hint`),children:[(0,X.jsx)(W,{label:e(`warmup.enabled`),icon:(0,X.jsx)(st,{className:`size-4`}),children:(0,X.jsx)(P,{checked:o.enabled,disabled:r.isPending,label:e(`warmup.enabled`),onChange:e=>s({enabled:e})})}),(0,X.jsx)(W,{label:e(`warmup.mode`),children:(0,X.jsx)(p,{ariaLabel:e(`warmup.mode`),value:o.mode,onChange:e=>s({mode:e}),items:[{value:`daily`,label:e(`warmup.mode.daily`)},{value:`auto`,label:e(`warmup.mode.auto`)}]})}),o.mode===`daily`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:e(`warmup.times`),detail:e(`warmup.zone`,{zone:o.timeZone}),children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[o.times.map(t=>(0,X.jsx)(c,{tone:`neutral`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono`,children:[t,(0,X.jsx)(`button`,{type:`button`,"aria-label":e(`warmup.removeTime`,{time:t}),onClick:()=>s({times:o.times.filter(e=>e!==t)}),children:(0,X.jsx)(wt,{className:`size-3`})})]})},t)),(0,X.jsx)(g,{mono:!0,className:`w-20`,placeholder:`06:00`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&l()}),(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),disabled:!Un.test(i),onClick:l,children:e(`warmup.addTime`)})]})}),(0,X.jsx)(W,{label:e(`warmup.weekdays`),detail:o.weekdays.length===0?e(`warmup.everyDay`):void 0,children:(0,X.jsx)(`div`,{role:`group`,"aria-label":e(`warmup.weekdays`),className:`flex gap-1`,children:Hn.map(t=>(0,X.jsx)(`button`,{type:`button`,"aria-pressed":o.weekdays.length===0||o.weekdays.includes(t),onClick:()=>d(t),className:`rounded-full px-2.5 py-0.5 text-[11.5px] ${o.weekdays.length===0||o.weekdays.includes(t)?`bg-[var(--fill)] text-[var(--text)]`:`text-[var(--text-muted)]`}`,children:e(`warmup.day.${t}`)},t))})})]}),(0,X.jsx)(W,{label:e(`warmup.claude`),children:(0,X.jsx)(P,{checked:o.claude,disabled:r.isPending,label:e(`warmup.claude`),onChange:e=>s({claude:e})})}),(0,X.jsx)(W,{label:e(`warmup.codex`),children:(0,X.jsx)(P,{checked:o.codex,disabled:r.isPending,label:e(`warmup.codex`),onChange:e=>s({codex:e})})})]}),(0,X.jsx)(Gn,{})]})}function Gn(){let{t:e,locale:t}=U(),{toast:n}=J(),r=i(),a=E(),o=He(),s=r.data??[],c=(e,t)=>a.mutate({id:e.accountId,...t},{onError:e=>n(K(e),`error`)}),l=t=>o.mutate(t.accountId,{onSuccess:r=>n(e(`warmup.ran`,{name:t.accountName,result:e(`warmup.result.${r.result}`)})+(r.message?` — ${r.message}`:``),r.result===`ok`?`success`:`error`),onError:e=>n(K(e),`error`)});return(0,X.jsxs)(u,{title:e(`warmup.accounts`),children:[s.length===0&&(0,X.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-muted)]`,children:e(`warmup.accounts.empty`)}),s.map(n=>(0,X.jsxs)(W,{label:`${n.providerName} · ${n.accountName}`,detail:(0,X.jsxs)(`span`,{className:`block whitespace-normal`,children:[n.lastAt&&n.lastResult?e(`warmup.last`,{result:e(`warmup.result.${n.lastResult}`),when:je(n.lastAt,t)}):null,n.lastMessage?` — ${n.lastMessage}`:``,n.nextAt?` ${e(`warmup.next`,{when:je(n.nextAt,t)})}`:``,n.warmed?``:` ${e(`warmup.notWarmed`)}`]}),children:[(0,X.jsx)(p,{ariaLabel:e(`warmup.mode`),value:n.mode,onChange:e=>c(n,{mode:e}),items:[{value:`inherit`,label:e(`warmup.mode.inherit`)},{value:`daily`,label:e(`warmup.mode.daily`)},{value:`auto`,label:e(`warmup.mode.auto`)},{value:`off`,label:e(`warmup.mode.off`)}]}),(0,X.jsx)(w,{size:`sm`,icon:(0,X.jsx)(st,{className:`size-3.5`}),disabled:o.isPending,onClick:()=>l(n),children:e(`warmup.runNow`)})]},n.accountId))]})}var Z={field:`_field_bzdr6_1`,head:`_head_bzdr6_11`,label:`_label_bzdr6_13`,limit:`_limit_bzdr6_17`,control:`_control_bzdr6_27`,step:`_step_bzdr6_43`,icon:`_icon_bzdr6_45`,valueWrap:`_valueWrap_bzdr6_67`,value:`_value_bzdr6_67`,affix:`_affix_bzdr6_75`,char:`_char_bzdr6_77`,number:`_number_bzdr6_83`,display:`_display_bzdr6_85`,mirror:`_mirror_bzdr6_89`,input:`_input_bzdr6_91`,column:`_column_bzdr6_103`,sizer:`_sizer_bzdr6_105`,glyph:`_glyph_bzdr6_107`,symbol:`_symbol_bzdr6_109`,messageSlot:`_messageSlot_bzdr6_113`,hint:`_hint_bzdr6_115`,words:`_words_bzdr6_119`,wordSlot:`_wordSlot_bzdr6_121`,wordSizer:`_wordSizer_bzdr6_123`,word:`_word_bzdr6_119`,srOnly:`_srOnly_bzdr6_127`},{spring:Q,duration:$,blur:Kn}=F,qn=[...F.ease.enter],Jn=[...F.ease.standard],Yn=[0,1,2,3,4,5,6,7,8,9],Xn=6,Zn=400,Qn=40,$n=240,er=1500,tr=700,nr=700,rr=.22,ir=4,ar=130,or=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),sr=e=>(String(e).split(`.`)[1]??``).length,cr=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),lr=(e,t)=>typeof e==`function`?e(t):e??``,ur=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function dr(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 fr={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Kn.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:Jn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Kn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Jn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},pr=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),mr={enter:pr(0),center:{...pr(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},hr={enter:pr(1),center:{...pr(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function gr({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=$e(e,e=>`${n(e)*1.05}em`),i=$e(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=$e(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=$e(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*Kn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(ke.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function _r({digit:e,direction:t,instant:n}){let r=ge(),i=Te(e),a=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let o=a.current;if(o.digit===e)return;let s=t>0?(e-o.digit+10)%10:-((o.digit-e+10)%10);Math.abs(s)>5&&(s-=Math.sign(s)*10),o.target+=s,o.digit=e,n||r?i.jump(o.target):Ie(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),Yn.map(e=>(0,X.jsx)(gr,{position:i,digit:e},e))]})}function vr({value:e,format:t,direction:n,instant:r}){let i=ge(),a=r?hr:i?mr:fr;return(0,X.jsx)(_e,{initial:!1,custom:n,children:dr(e,t).map(e=>(0,X.jsx)(ke.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)(_r,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function yr({text:e,direction:t,className:n}){let r=ge();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(_e,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(ke.span,{className:Z.char,custom:t,variants:r?mr:fr,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var br=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},xr=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=br(n[t]),i=br(e);return r!==null&&i!==null&&i<r?-1:1})},Sr={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Kn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:qn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Kn.subtle}px)`,transition:{duration:.14,ease:Jn}})},Cr={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function wr({word:e,direction:t}){let n=ge(),r=(0,Y.useRef)(null),i=Te(`auto`),a=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!a.current||n?i.jump(e.offsetWidth):Ie(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(ke.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(_e,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(ke.span,{className:Z.word,custom:t,variants:n?Cr:Sr,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Tr({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:xr(t.text,e)});let r=t.text===e?t.directions:xr(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)(wr,{word:e,direction:r[t]??1})]},t))})]})}function Er({id:e,text:t,className:n}){return(0,X.jsx)(_e,{initial:!1,children:t?(0,X.jsx)(Dr,{id:e,text:t,className:n},`message`):null})}function Dr({id:e,text:t,className:n}){let r=ge(),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)(ke.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)(ke.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${Kn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:qn},children:(0,X.jsx)(Tr,{text:t})})})}function Or({id:e,edge:t,text:n}){let r=ge();return(0,X.jsx)(_e,{initial:!1,children:t!==0&&(0,X.jsx)(ke.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${Kn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:Jn}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function kr({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?_t:mt;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 Ar({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:p=!1,locale:m=`en-US`,formatOptions:h,size:g=`md`,limitHint:_=!0}){let v=ge(),y=(0,Y.useId)(),b=u??y,x=c?`${b}-description`:void 0,S=`${b}-limit`,C=o>0?o:1,[w,T]=(0,Y.useState)(n),E=t??w,[D,O]=(0,Y.useState)(``),[k,ee]=(0,Y.useState)(!1),[A,te]=(0,Y.useState)(0),[ne,j]=(0,Y.useState)(!1),[re,M]=(0,Y.useState)(``),[N,ie]=(0,Y.useState)(0),[ae,oe]=(0,Y.useState)(!1),se=(0,Y.useRef)(null),P=(0,Y.useRef)(null),ce=(0,Y.useRef)(null),le=(0,Y.useRef)(void 0),ue=(0,Y.useRef)(void 0),de=(0,Y.useRef)(void 0),fe=(0,Y.useRef)({edge:0,count:0,at:0}),F=(0,Y.useRef)(null),I=(0,Y.useRef)(null),L=(0,Y.useRef)(E),pe=(0,Y.useRef)(E),me=(0,Y.useRef)(void 0),he=(0,Y.useRef)(null),R=(0,Y.useRef)(!1),_e=(0,Y.useRef)(null),ve=(0,Y.useRef)(!1),ye=(0,Y.useRef)(()=>!1),be=Te(0),z=Te(0),B=Te(0),xe=$e(()=>z.get()+B.get()),V=Number.isFinite(i)?i:0,Se=Math.max(sr(C),sr(V)),Ce=h?.minimumFractionDigits??Se,we=Math.max(Ce,h?.maximumFractionDigits??Se),Ee=h?.useGrouping??!0,De=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:Ce,maximumFractionDigits:we,useGrouping:Ee,numberingSystem:`latn`}),[m,Ce,we,Ee]),Oe=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(m).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[m]),Ae=e=>Number(e.toFixed(Se))||0,je=e=>Math.min(a,Math.max(i,e)),Me=e=>Ae(V+Math.round((e-V)/C)*C),Ne=(e,t)=>{let n=(e-V)/C;return Ae(V+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*C)},Pe=e=>`${lr(d,e)}${De.format(e)}${lr(f,e)}`.trim();function Fe(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 Le=k?Fe(D):null,H=Le??E,[U,Re]=(0,Y.useState)({value:H,direction:1});U.value!==H&&Re({value:H,direction:H>U.value?1:-1});let ze=U.value===H?U.direction:H>U.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(me.current),window.clearTimeout(le.current),window.clearTimeout(ue.current),window.clearTimeout(de.current)},[]);function Be(e,t){let n=performance.now(),r=fe.current;r.count=r.edge===e&&n-r.at<nr?r.count+1:1,r.edge=e,r.at=n;let i=se.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(de.current),de.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!v){Ie(be,0,{...or,velocity:-e*ar*(1+Math.min(r.count-1,ir)*rr)});let n=(e>0?ce:P).current;n&&(t===`button`||t===`key`)&&Ie(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}_&&(ie(e),window.clearTimeout(le.current),le.current=window.setTimeout(()=>ie(0),er))}function W(e,n){if(!Number.isFinite(e))return!1;let i=je(e),a=Math.sign(e-i);return a&&n!==`scrub`?(Be(a>0?1:-1,n),M(`${Pe(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==L.current&&M(Pe(i)),i!==L.current&&(L.current=i,t===void 0&&T(i),r?.(i),!0)}let Ve=(e,t,n)=>W(Ne(L.current,e*t),n);(0,Y.useLayoutEffect)(()=>{L.current=E,ye.current=Ve});function He(){let e=I.current;e&&_e.current===null&&(_e.current=e.getBoundingClientRect().left-z.get()-B.get())}(0,Y.useLayoutEffect)(()=>{let e=_e.current,t=I.current;if(_e.current=null,ve.current){ve.current=!1;let e=F.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-z.get()-B.get());Math.abs(n)<.5||(B.set(B.get()+n),v?B.jump(0):Ie(B,0,Q.morph))});function Ue(){window.clearTimeout(ue.current),oe(!1)}function We(){if(!k)return;He(),ee(!1),Ue();let e=Fe(D);e!==null&&W(Me(e),`type`)}function Ge(){window.clearTimeout(me.current),me.current=void 0,te(0)}function G(e,t,n){Ge(),We();let r=Math.max(1,Math.round(t/C));n===`button`&&te(e);let i=0,a=()=>{let t=ye.current(e,r,n);me.current=window.setTimeout(a,t?Math.max(Qn,150*.86**++i):$n)};me.current=window.setTimeout(a,Ve(e,r,n)?Zn:360)}function K(e){let t=s??C*10,n={ArrowUp:[1,e.shiftKey?t:C],ArrowDown:[-1,e.shiftKey?t:C],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||G(n[0],n[1],`key`);return}if(!k&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),W(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),k?(ve.current=!0,We()):e.currentTarget.select()),e.key===`Escape`&&k&&(e.preventDefault(),He(),ee(!1),Ue(),ve.current=!0,W(pe.current,`type`))}function q(e){let t=RegExp(`[^0-9${cr(Oe.group)}${Se||we?cr(Oe.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);k||(pe.current=E),He(),O(n),ee(!0);let r=Fe(n);r!==null&&r>=i&&r<=a&&Me(r)===r&&W(r,`type`),Ue(),r!==null&&r<i&&(ue.current=window.setTimeout(()=>oe(!0),tr))}function J(e){R.current=!1,p&&!l&&e.button===0&&(We(),he.current={pointer:e.pointerId,x:e.clientX,from:L.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=he.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/Xn,o=Math.trunc(r);W(o?Ne(t.from,o):t.from,`scrub`);let s=t.from+r*C,c=s>a?(s-a)/C*Xn:s<i?(s-i)/C*Xn:0;z.set(v?0:ur(c))}function qe(e){let t=he.current;t&&t.pointer===e.pointerId&&(he.current=null,t.active&&(R.current=!0,j(!1),Ie(z,0,v?{duration:0}:Q.snappy),M(Pe(L.current))))}let Je=t=>({toward:t,label:e,disabled:l,controls:b,limit:t>0?H>=a:H<=i,pressed:A===t}),Ye=Le===null?0:Le>a?1:Le<i&&ae?-1:0,Xe=_?Ye||N:0,Ze=Xe>0?a:i,Qe=Xe?typeof _==`function`?_(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${Pe(Ze)}`:``,et=[x,Ye&&_?S:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":g,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:b,className:Z.label,"data-scrub":p&&!l||void 0,onPointerDown:J,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{R.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Or,{id:S,edge:Xe,text:Qe})]}),(0,X.jsxs)(`div`,{ref:se,className:Z.control,"data-scrubbing":ne||void 0,"data-disabled":l||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(kr,{...Je(-1),iconRef:P,onPress:()=>G(-1,C,`button`),onRelease:Ge,onActivate:()=>{We(),Ve(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==F.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==F.current&&(F.current?.focus(),F.current?.select())},children:(0,X.jsxs)(ke.span,{ref:I,className:Z.value,style:{x:xe,y:be},children:[(0,X.jsx)(yr,{text:lr(d,H),direction:ze,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":k||void 0,"aria-hidden":`true`,children:(0,X.jsx)(vr,{value:H,format:De,direction:ze,instant:k})}),k&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:D}),(0,X.jsx)(`input`,{ref:F,id:b,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:Se||we?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:k?D:De.format(E),disabled:l,"aria-describedby":et,"aria-invalid":Ye?!0:void 0,"aria-valuenow":E,"aria-valuetext":Pe(E),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a:void 0,onChange:e=>q(e.currentTarget.value),onKeyDown:K,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ge()},onBlur:()=>{Ge(),We()}})]}),(0,X.jsx)(yr,{text:lr(f,H),direction:ze,className:Z.affix})]})}),(0,X.jsx)(kr,{...Je(1),iconRef:ce,onPress:()=>G(1,C,`button`),onRelease:Ge,onActivate:()=>{We(),Ve(1,1,`button`)}})]}),(0,X.jsx)(Er,{id:x,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:re})]})}var jr=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Mr(){let{t:e}=U(),t=k(),[n,r]=Xe(),i=Qe(),a=Ze(n,{enabled:i.running,background:!1,live:!0}),o=t=>(0,X.jsx)(W,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(P,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(qe(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Nr,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Rt,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:L.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Nr,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:jr.map(o)})}),(0,X.jsx)(Nr,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:o(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(yt,{className:`size-3.5`}),onClick:()=>r(Ye),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Nr,{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)(Bt,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:i,data:a,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Nr({title:e,hint:t,children:n}){let{t:r}=U();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 Pr=[`general`,`notifications`,`remote`,`backup`,`tray`],Fr=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Ir(){let{t:e}=U(),{tab:t}=Ot(),n=jt(),r=Ke(),i=Pr.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsxs)(Lt,{title:e(`nav.settings`),children:[(0,X.jsxs)(Dt,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(kt,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Mt,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(bt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Mt,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(nt,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Mt,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ut,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),(0,X.jsx)(Mt,{value:`backup`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(et,{className:`size-3.5`}),e(`settings.tab.backup`)]})}),r&&(0,X.jsx)(Mt,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ht,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(Et,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Lr,{})}),(0,X.jsx)(Et,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(On,{})}),(0,X.jsx)(Et,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(dn,{})}),(0,X.jsx)(Et,{value:`backup`,className:`pt-5`,children:(0,X.jsx)(rn,{})}),r&&(0,X.jsx)(Et,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Mr,{})})]}),(0,X.jsx)(`div`,{className:`mt-6`,children:(0,X.jsx)(Pt,{name:`settings.sections`})})]})}function Lr(){let{t:e,locale:t,setLocale:r}=U(),i=Nt(),a=V(),c=ze(),l=k(),d=te(),f=y(),m=o(),h=Fe(),{toast:g,confirm:_}=J(),v=a.data,b=h.data?.state===`connected`&&h.data.publicUrl?`${h.data.publicUrl}/v1`:null,x=e=>c.mutate(e,{onError:e=>g(K(e),`error`)}),S=e=>{r(e),x({locale:e})},C=async t=>{await G.copy(t)&&g(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(u,{title:e(`settings.appearance`),children:[(0,X.jsx)(W,{label:e(`settings.theme`),children:(0,X.jsx)(p,{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)(W,{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`)},...Ft.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(W,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(p,{ariaLabel:e(`settings.language`),value:t,onChange:S,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Rn,{}),(0,X.jsx)(Wn,{}),v?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(u,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(W,{label:e(`settings.gatewayUrl`),detail:`${v.gatewayBaseUrl}/v1`,children:(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void C(`${v.gatewayBaseUrl}/v1`)})}),b&&(0,X.jsx)(W,{label:e(`settings.remote.publicUrl`),detail:b,children:(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void C(b)})}),(0,X.jsx)(xn,{}),(0,X.jsx)(W,{label:e(`settings.dataDir`),detail:v.dataDir,children:G.canOpenPaths?(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(lt,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void G.openPath(v.dataDir)}):(0,X.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void C(v.dataDir)})}),(0,X.jsx)(W,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(P,{checked:v.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await _({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&x({requireGatewayKey:t})}})}),(0,X.jsx)(W,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Ur,{label:e(`settings.streamIdle`),value:v.streamIdleTimeoutSec,onCommit:e=>x({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(W,{label:e(`settings.maxBody`),detail:e(`settings.maxBodyHint`),children:(0,X.jsx)(Ur,{label:e(`settings.maxBody`),value:v.maxRequestBodyMb??64,onCommit:e=>x({maxRequestBodyMb:e??64}),suffix:` MiB`})}),(0,X.jsx)(W,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:v.requestCompression,onChange:e=>x({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)(u,{footer:e(`settings.preventSleepHint`),children:(0,X.jsx)(W,{label:e(`settings.preventSleep`),children:(0,X.jsx)(P,{checked:v.preventSleep??!1,label:e(`settings.preventSleep`),onChange:e=>x({preventSleep:e})})})}),(0,X.jsx)(u,{footer:e(`settings.clientFailoverHint`),children:(0,X.jsx)(W,{label:e(`settings.clientFailover`),children:(0,X.jsx)(P,{checked:v.clientProviderFailover??!0,label:e(`settings.clientFailover`),onChange:e=>x({clientProviderFailover:e})})})}),(0,X.jsx)(u,{footer:e(`settings.stripStaleReasoningHint`),children:(0,X.jsx)(W,{label:e(`settings.stripStaleReasoning`),children:(0,X.jsx)(P,{checked:v.stripStaleReasoning??!0,label:e(`settings.stripStaleReasoning`),onChange:e=>x({stripStaleReasoning:e})})})}),(0,X.jsx)(zr,{settings:v}),(0,X.jsx)(Br,{settings:v}),(0,X.jsx)(Vr,{settings:v}),(0,X.jsx)(Rr,{settings:v}),(0,X.jsx)(Hr,{settings:v}),(0,X.jsxs)(u,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(W,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Ur,{label:e(`settings.quota.autoInterval`),value:v.quotaAutoIntervalMinutes,onCommit:e=>c.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void l.invalidateQueries({queryKey:s.providers}),onError:e=>g(K(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(W,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Ur,{label:e(`settings.quota.subscriptionInterval`),value:v.subscriptionQuotaIntervalMinutes,onCommit:e=>x({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(u,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(W,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:v.usageTimeZone??``,onChange:e=>x({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:v.effectiveUsageTimeZone})},...[...new Set([...Fr,...v.usageTimeZone?[v.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(u,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(W,{label:e(`settings.debugBodies`),children:(0,X.jsx)(P,{checked:v.debugBodies,label:e(`settings.debugBodies`),onChange:e=>x({debugBodies:e})})}),(0,X.jsx)(W,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Ur,{label:e(`settings.bodyRetention`),value:v.bodyRetentionDays,onCommit:e=>x({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(W,{label:e(`settings.requestRetention`),detail:v.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(P,{checked:v.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>x({requestRetentionDays:e?90:null})}),v.requestRetentionDays!=null&&(0,X.jsx)(Ur,{label:e(`settings.requestRetention`),value:v.requestRetentionDays,onCommit:e=>x({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(u,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(W,{label:e(`settings.traceContent`),children:(0,X.jsx)(P,{checked:v.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>x({traceContent:e})})})}),(0,X.jsx)(u,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(W,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Ur,{label:e(`settings.effort.${t}`),value:v.effortBudgets[t],onCommit:e=>x({effortBudgets:{...v.effortBudgets,[t]:e??v.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:K(a.error)}):(0,X.jsx)(N,{className:`mx-auto my-8`}),(0,X.jsxs)(u,{title:e(`settings.about`),children:[(0,X.jsx)(W,{label:e(`settings.serverVersion`),detail:d.data?`${d.data.version} · API ${d.data.apiVersion}`:`—`}),z&&(0,X.jsx)(W,{label:e(`settings.desktopVersion`),detail:n()?.version||`—`}),(0,X.jsx)(Vn,{}),z&&(0,X.jsx)(W,{label:e(`settings.logs`),onClick:()=>void G.revealLogs(),children:(0,X.jsx)(lt,{className:`size-4 text-[var(--text-secondary)]`})}),f.data?.required&&(0,X.jsx)(W,{label:e(`settings.logout`),onClick:()=>m.mutate(),children:(0,X.jsx)(pt,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Rr({settings:e}){let{t}=U(),{toast:n}=J(),r=ze(),[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(K(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(K(e),`error`)}),d=i!==e.proxyMode||o.url!==(e.proxyUrl??``)||o.username!==(e.proxyUsername??``)||o.password!==``||o.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(u,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(W,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${i}.hint`),children:(0,X.jsx)(p,{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)(W,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(g,{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)(W,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(g,{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)(W,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(g,{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)(W,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(g,{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)(w,{size:`sm`,disabled:!d||!o.url.trim()||r.isPending,onClick:l,children:t(`common.save`)})})]})]})}function zr({settings:e}){let{t}=U(),{toast:n}=J(),r=ze(),i=e.providerQualifiedModels??!1,a=i?e.modelQualifyScope??`shared`:`off`,o=e.modelProviderSeparator??`@`,[s,c]=(0,Y.useState)(o);(0,Y.useEffect)(()=>c(o),[o]);let l=e=>r.mutate(e,{onError:e=>{c(o),n(K(e),`error`)}});return(0,X.jsxs)(u,{title:t(`settings.qualifiedModels`),footer:t(`settings.qualifiedModels.footer`),children:[(0,X.jsx)(W,{label:t(`settings.qualifiedModels.mode`),detail:t(`settings.qualifiedModels.modeHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.qualifiedModels.mode`),value:a,onChange:e=>l(e===`off`?{providerQualifiedModels:!1}:{providerQualifiedModels:!0,modelQualifyScope:e}),options:[{value:`off`,label:t(`settings.qualifiedModels.mode.off`)},{value:`shared`,label:t(`settings.qualifiedModels.mode.shared`)},{value:`all`,label:t(`settings.qualifiedModels.mode.all`)}]})}),i&&(0,X.jsx)(W,{label:t(`settings.qualifiedModels.separator`),detail:t(`settings.qualifiedModels.separatorHint`),children:(0,X.jsx)(g,{className:`w-24`,mono:!0,maxLength:8,"aria-label":t(`settings.qualifiedModels.separator`),value:s,onChange:e=>c(e.target.value),onBlur:()=>s!==o&&l({modelProviderSeparator:s})})})]})}function Br({settings:e}){let{t}=U(),{toast:n}=J(),r=ze(),i=e.currencyRates??{},a=e.displayCurrency??`USD`,[o,s]=(0,Y.useState)({}),c=e=>r.mutate(e,{onError:e=>n(K(e),`error`)}),l=B.filter(e=>e.code!==`USD`&&(i[e.code]!=null||o[e.code]!=null)),d=B.filter(e=>e.code!==`USD`&&!l.includes(e)),f=e=>s(({[e]:t,...n})=>n),p=e=>{let r=(o[e]??i[e]??``).trim();if(r===i[e])return f(e);if(De(r)==null)return n(t(`settings.currency.badRate`),`error`);f(e),c({currencyRates:{...i,[e]:r}})},m=e=>{if(f(e),i[e]==null)return;let{[e]:t,...n}=i;c(a===e?{displayCurrency:`USD`,currencyRates:n}:{currencyRates:n})};return(0,X.jsxs)(u,{title:t(`settings.currency`),footer:t(`settings.currency.footer`),children:[(0,X.jsx)(W,{label:t(`settings.currency.display`),detail:t(`settings.currency.displayHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.currency.display`),value:a,onChange:e=>c({displayCurrency:e}),options:[{value:`USD`,label:`USD · $`},...B.filter(e=>e.code!==`USD`&&De(i[e.code])!=null).map(e=>({value:e.code,label:`${e.code} · ${e.symbol.trim()}`}))]})}),l.map(e=>(0,X.jsx)(W,{label:t(`settings.currency.rateRow`,{code:e.code}),children:(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`num text-[12px] text-[var(--text-secondary)]`,children:`1 USD =`}),(0,X.jsx)(g,{className:`w-28`,mono:!0,inputMode:`decimal`,"aria-label":t(`settings.currency.rateOf`,{code:e.code}),value:o[e.code]??i[e.code]??``,onChange:t=>s(n=>({...n,[e.code]:t.target.value})),onBlur:()=>p(e.code)}),(0,X.jsx)(`span`,{className:`num text-[12px] text-[var(--text-secondary)]`,children:e.code}),(0,X.jsx)(w,{size:`sm`,variant:`plain`,onClick:()=>m(e.code),children:t(`settings.currency.remove`)})]})},e.code)),d.length>0&&(0,X.jsx)(W,{label:t(`settings.currency.add`),detail:t(`settings.currency.addHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.currency.add`),value:null,placeholder:t(`settings.currency.addPlaceholder`),onChange:e=>s(t=>({...t,[e]:``})),options:d.map(e=>({value:e.code,label:`${e.code} · ${e.symbol.trim()}`}))})})]})}function Vr({settings:e}){let{t}=U(),{toast:n}=J(),r=ze(),i=e.hiddenNav??[],a=At.flatMap(e=>e.items).filter(e=>e.id!==`settings`),o=(e,t)=>r.mutate({hiddenNav:t?i.filter(t=>t!==e):[...i,e]},{onError:e=>n(K(e),`error`)});return(0,X.jsx)(u,{title:t(`settings.sidebar`),footer:t(`settings.sidebar.footer`),children:a.map(e=>(0,X.jsx)(W,{label:t(e.label),children:(0,X.jsx)(P,{checked:!i.includes(e.id),label:t(e.label),onChange:t=>o(e.id,t)})},e.id))})}function Hr({settings:e}){let{t}=U(),{toast:n}=J(),r=ze(),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(K(e),`error`)});return(0,X.jsxs)(u,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(W,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(P,{checked:i,label:t(`settings.pluginMarket.offline`),onChange:e=>s(e?``:null)})}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(g,{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)(w,{size:`sm`,disabled:r.isPending,onClick:()=>s(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(w,{size:`sm`,disabled:r.isPending||a.trim()===(e.pluginMarketUrl??``),onClick:()=>s(a.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Ur({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)(Ar,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Ir as SettingsPage};