@aidotnet/server-win32-arm64 0.14.3114 → 0.14.3116

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 (25) hide show
  1. package/bin/astra-server.exe +2 -2
  2. package/bin/wwwroot/assets/{ClientsPage-BhnTX0ew.js → ClientsPage--PWh6ozr.js} +2 -2
  3. package/bin/wwwroot/assets/{KeyPage-D8xcW85A.js → KeyPage-Ba3ujEEH.js} +1 -1
  4. package/bin/wwwroot/assets/{LibraryPage-BO51S5vR.js → LibraryPage-C6UNNxnM.js} +1 -1
  5. package/bin/wwwroot/assets/{McpPage-BFav-GE-.js → McpPage-ZqGX2X-C.js} +1 -1
  6. package/bin/wwwroot/assets/{ModelDetailPage-CRE3OFy5.js → ModelDetailPage-BXxaDBuf.js} +1 -1
  7. package/bin/wwwroot/assets/{ModelsPage-BsRk0_yk.js → ModelsPage-RS-BTSFJ.js} +1 -1
  8. package/bin/wwwroot/assets/{PluginsPage-blIrwXbf.js → PluginsPage-Cz_JmDlj.js} +1 -1
  9. package/bin/wwwroot/assets/{PrivacyPage-bKxw2Y54.js → PrivacyPage-DSVNG7Et.js} +1 -1
  10. package/bin/wwwroot/assets/{ProviderDetailPage-3YGtfo9v.js → ProviderDetailPage-CGiaHQQW.js} +1 -1
  11. package/bin/wwwroot/assets/{ProvidersPage-B0XULeAs.js → ProvidersPage-CSNuqB_1.js} +1 -1
  12. package/bin/wwwroot/assets/{RoutingGroupsPage-Dz-TTq1a.js → RoutingGroupsPage-DKSTVbGU.js} +1 -1
  13. package/bin/wwwroot/assets/{SettingsPage-CFVirZNv.js → SettingsPage-DAPUfR-h.js} +1 -1
  14. package/bin/wwwroot/assets/{SkillsPage-DI61DG2m.js → SkillsPage-DRtTyTNp.js} +1 -1
  15. package/bin/wwwroot/assets/{SmartRoutingPage-CpchDlXC.js → SmartRoutingPage-CY-7vgHw.js} +1 -1
  16. package/bin/wwwroot/assets/{TokenDetailPage-PqVFcudk.js → TokenDetailPage-Dsic3ZDE.js} +1 -1
  17. package/bin/wwwroot/assets/{TokenPoolEditor-IS5Zwuqf.js → TokenPoolEditor-B0smjOAZ.js} +1 -1
  18. package/bin/wwwroot/assets/{TokensPage-CXK5_J6v.js → TokensPage-Zd92s99T.js} +1 -1
  19. package/bin/wwwroot/assets/{ToolsPage-B_JZpB1h.js → ToolsPage-DkIZ14z2.js} +1 -1
  20. package/bin/wwwroot/assets/{TracesPage-CgbFQFzA.js → TracesPage-B5lkV7Kg.js} +1 -1
  21. package/bin/wwwroot/assets/{TrayPanelPage-Z4vWiyK-.js → TrayPanelPage-DDo9i5gp.js} +1 -1
  22. package/bin/wwwroot/assets/{TrayPanelView-Cauh6r_o.js → TrayPanelView-CGEASzOn.js} +1 -1
  23. package/bin/wwwroot/assets/{index-D2siu6xk.js → index-Chd2TNCi.js} +2 -2
  24. package/bin/wwwroot/index.html +1 -1
  25. package/package.json +1 -1
@@ -1,3 +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(`
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-Chd2TNCi.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
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
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{$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(`
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-Chd2TNCi.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
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
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};