@aidotnet/server-win32-x64 0.14.3110 → 0.14.3112

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 (65) hide show
  1. package/bin/astra-server.exe +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-CE9QdKbh.js +11 -0
  3. package/bin/wwwroot/assets/KeyPage-Db9tYWgA.js +1 -0
  4. package/bin/wwwroot/assets/LibraryPage-Djro5zZa.js +2 -0
  5. package/bin/wwwroot/assets/McpPage-BJ7D5vt6.js +9 -0
  6. package/bin/wwwroot/assets/ModelDetailPage-DuyD1_Ei.js +1 -0
  7. package/bin/wwwroot/assets/ModelsPage-Dc1KK7-3.js +1 -0
  8. package/bin/wwwroot/assets/PluginsPage-Dn1IYmlm.js +2 -0
  9. package/bin/wwwroot/assets/PrivacyPage-Dsaaw5Ko.js +1 -0
  10. package/bin/wwwroot/assets/ProviderDetailPage-C5YbB46r.js +3 -0
  11. package/bin/wwwroot/assets/ProvidersPage-BzICHtxh.js +3 -0
  12. package/bin/wwwroot/assets/RoutingGroupsPage-B-7FNn_B.js +3 -0
  13. package/bin/wwwroot/assets/SettingsPage-CCOHxf9s.js +2 -0
  14. package/bin/wwwroot/assets/SkillsPage-BdZSd_hw.js +1 -0
  15. package/bin/wwwroot/assets/SmartRoutingPage-DIkU4HND.js +2 -0
  16. package/bin/wwwroot/assets/TokenDetailPage-DA6q9gbd.js +1 -0
  17. package/bin/wwwroot/assets/TokenPoolEditor-CISTyNzC.js +1 -0
  18. package/bin/wwwroot/assets/TokensPage-CUJXAz7I.js +1 -0
  19. package/bin/wwwroot/assets/ToolsPage-DOHJoH86.js +1 -0
  20. package/bin/wwwroot/assets/TracesPage-f3hY7JcZ.js +8 -0
  21. package/bin/wwwroot/assets/{TrayPanelPage-CackS8OH.js → TrayPanelPage-HGV5ST-e.js} +1 -1
  22. package/bin/wwwroot/assets/{TrayPanelView-Cj0Pwm7y.js → TrayPanelView-BhyK24F_.js} +1 -1
  23. package/bin/wwwroot/assets/TrayTitleSource-DN10ruw2.js +41 -0
  24. package/bin/wwwroot/assets/{checkbox-DFbPH3ZB.js → checkbox-CZ-rG7I2.js} +1 -1
  25. package/bin/wwwroot/assets/clientNames-Bskc9G1M.js +1 -0
  26. package/bin/wwwroot/assets/{confirm-morph-Cu1awcrW.js → confirm-morph-Cakq9Lho.js} +1 -1
  27. package/bin/wwwroot/assets/file-up-BZh1Gcck.js +1 -0
  28. package/bin/wwwroot/assets/flame-BPbKoD7V.js +1 -0
  29. package/bin/wwwroot/assets/format-CmXxTS5M.js +15 -0
  30. package/bin/wwwroot/assets/index-BW8keTkg.js +124 -0
  31. package/bin/wwwroot/assets/index-WJKZ_ywJ.css +1 -0
  32. package/bin/wwwroot/assets/layers-lBgMUT4n.js +1 -0
  33. package/bin/wwwroot/assets/library-BUD1zsIb.js +1 -0
  34. package/bin/wwwroot/assets/{radio-cards-C0nGl7Px.js → radio-cards-BTn8kpAx.js} +1 -1
  35. package/bin/wwwroot/assets/{sortable.esm-KYAcfdq_.js → sortable.esm-Cj5-STJU.js} +1 -1
  36. package/bin/wwwroot/assets/use-transform-BcmlojQJ.js +1 -0
  37. package/bin/wwwroot/assets/wrench-gp64nTHm.js +1 -0
  38. package/bin/wwwroot/index.html +8 -5
  39. package/package.json +1 -1
  40. package/bin/wwwroot/assets/ClientsPage-DF3rflag.js +0 -9
  41. package/bin/wwwroot/assets/KeyPage-B7_1Yr16.js +0 -1
  42. package/bin/wwwroot/assets/McpPage-CvN5NYlZ.js +0 -9
  43. package/bin/wwwroot/assets/ModelDetailPage-CyE8Xpqg.js +0 -1
  44. package/bin/wwwroot/assets/ModelsPage-Cct68Oc8.js +0 -1
  45. package/bin/wwwroot/assets/PluginsPage-DiMYLnBv.js +0 -2
  46. package/bin/wwwroot/assets/PrivacyPage-Bdyo4YN_.js +0 -1
  47. package/bin/wwwroot/assets/ProviderDetailPage-CZLD3Mo2.js +0 -3
  48. package/bin/wwwroot/assets/ProvidersPage-DhvpZLqS.js +0 -3
  49. package/bin/wwwroot/assets/SettingsPage-QVURVf8n.js +0 -2
  50. package/bin/wwwroot/assets/SkillsPage-DUAhBBjy.js +0 -1
  51. package/bin/wwwroot/assets/SmartRoutingPage-yxPbwM3u.js +0 -2
  52. package/bin/wwwroot/assets/TokenDetailPage-jvkJ9wIf.js +0 -1
  53. package/bin/wwwroot/assets/TokenPoolEditor-eWoOGd9t.js +0 -1
  54. package/bin/wwwroot/assets/TokensPage-BTnINKwi.js +0 -1
  55. package/bin/wwwroot/assets/TracesPage-CGAcVl3u.js +0 -8
  56. package/bin/wwwroot/assets/TrayTitleSource-EINzpQeQ.js +0 -41
  57. package/bin/wwwroot/assets/file-up-mqWdjdlX.js +0 -1
  58. package/bin/wwwroot/assets/flame-DLlSOIlR.js +0 -1
  59. package/bin/wwwroot/assets/format-Bw-mDeuE.js +0 -15
  60. package/bin/wwwroot/assets/index-D2hgi2oA.js +0 -122
  61. package/bin/wwwroot/assets/index-D74BlcEH.css +0 -1
  62. package/bin/wwwroot/assets/layers-Dzm_l0k4.js +0 -1
  63. package/bin/wwwroot/assets/library-CQ0z7xCA.js +0 -1
  64. package/bin/wwwroot/assets/use-transform-BEsJGrlr.js +0 -1
  65. package/bin/wwwroot/assets/wrench-DVonHu-a.js +0 -1
@@ -0,0 +1,3 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{A as n,Aa as r,An as i,Ar as a,B as o,Br as s,Ca as c,Ct as l,D as u,Da as d,Di as f,Do as p,Dt as m,Ea as h,Ei as g,F as _,Fi as v,Fr as y,Ft as b,G as x,I as S,Ir as C,Kn as w,Kr as T,Kt as ee,L as E,M as te,Mn as ne,Mr as re,N as D,Nn as ie,O,Ot as ae,P as k,Pr as oe,Pt as se,Qs as ce,R as A,Ra as le,S as j,Tt as ue,U as M,Ur as N,Va as de,W as P,Wn as fe,Wo as F,Wr as pe,Xn as me,Xr as he,Yn as ge,Zs as _e,_o as ve,_r as ye,ar as be,b as xe,bi as Se,co as Ce,d as I,di as we,dn as Te,dt as L,ea as R,en as Ee,fi as z,fn as De,gi as Oe,in as ke,ir as Ae,jn as je,jt as Me,k as Ne,ka as Pe,kt as Fe,li as Ie,m as B,mi as Le,n as V,or as Re,r as H,rn as ze,ti as Be,ua as Ve,ui as He,v as Ue,vo as We,vr as Ge,w as U,wi as Ke,wt as qe,y as Je,yi as Ye,yo as Xe,z as W}from"./format-CmXxTS5M.js";import{A as Ze,B as Qe,F as $e,H as G,M as et,N as tt,R as nt,U as K,V as q,W as J,v as rt}from"./TrayTitleSource-DN10ruw2.js";import{t as it}from"./arrow-down-Def8Fl70.js";import{t as at}from"./arrow-left-right-6suyY7uV.js";import{t as Y}from"./arrow-left-DhPqlXf4.js";import{t as ot}from"./arrow-right-left-CYfMM55E.js";import{t as st}from"./arrow-right-qPGkuoiX.js";import{t as ct}from"./arrow-up-DE65OgjV.js";import{t as lt}from"./cloud-download-l1GjuXcO.js";import{t as ut}from"./copy-48gwhhDO.js";import{t as dt}from"./ellipsis-CidyZaW2.js";import{t as ft}from"./external-link-D6jQM2CZ.js";import{t as pt}from"./flask-conical-P-TiuT25.js";import{t as mt}from"./gauge-51NSdHOx.js";import{t as ht}from"./gift-BHKj6Vbm.js";import{t as gt}from"./globe-CFH0vwgV.js";import{t as _t}from"./key-round-m9ps8ZDi.js";import{t as vt}from"./list-plus-BPdeHOZu.js";import{t as yt}from"./log-in-A3md9AGL.js";import{t as bt}from"./log-out-CgcpH2Q7.js";import{t as xt}from"./pencil-CpF9MxGZ.js";import{t as St}from"./plug-DKn7uRWT.js";import{t as X}from"./plus-c3HzV6VX.js";import{t as Ct}from"./power-BZC18Gj2.js";import{t as wt}from"./rotate-ccw-fsXoCwyv.js";import{t as Tt}from"./shield-check-CD30JqBi.js";import{t as Et}from"./sparkles-ibXDb_LG.js";import{t as Dt}from"./ticket-CcW0RtCe.js";import{t as Z}from"./trash-BHBJn5GS.js";import{t as Ot}from"./upload-yXA41tlC.js";import{t as kt}from"./x-AFrW8zH7.js";import{B as At,D as jt,E as Mt,G as Nt,O as Pt,R as Ft,W as It,a as Lt,b as Rt,c as zt,k as Bt,l as Vt,o as Ht,u as Ut,v as Wt,z as Gt}from"./index-BW8keTkg.js";import{a as Kt,c as qt,d as Jt,f as Yt,i as Xt,l as Zt,n as Qt,o as $t,s as en,t as tn,u as nn}from"./ProvidersPage-BzICHtxh.js";import{t as rn}from"./checkbox-CZ-rG7I2.js";import{t as an}from"./confirm-morph-Cakq9Lho.js";var Q=e(t(),1),$=ce();function on({usage:e,compact:t=!1}){let{t:n}=U(),r=[{label:n(`providers.usage.requests`),values:[e?.today.requests,e?.total.requests],format:(e,n=t)=>I(e,n)},{label:n(`providers.usage.tokens`),values:[e?.today.tokens,e?.total.tokens],format:(e,n=t)=>I(e,n)},{label:n(`providers.usage.cost`),values:[e?.today.costNanoUsd,e?.total.costNanoUsd],format:(e,n=t)=>B(xe(e),{compact:n})}];return(0,$.jsxs)(`table`,{className:L(`w-full table-fixed text-right tabular-nums`,t?`text-[11px]`:`text-[12px]`),"aria-label":n(`providers.usage.title`),children:[(0,$.jsx)(`thead`,{className:`text-[var(--text-muted)]`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-[34%] pb-1 text-left font-normal`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:n(`providers.usage.title`)})}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.today`)}),(0,$.jsx)(`th`,{scope:`col`,className:`pb-1 font-normal`,children:n(`providers.usage.total`)})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`py-0.5 text-left font-normal text-[var(--text-secondary)]`,children:e.label}),e.values.map((t,n)=>(0,$.jsx)(`td`,{className:`truncate py-0.5 pl-1 font-mono`,title:t==null?void 0:e.format(t,!1),children:t==null?`—`:e.format(t)},n))]},e.label))})]})}function sn({timeZone:e}){let{t}=U();return(0,$.jsxs)(`p`,{className:`text-[11px] leading-relaxed text-[var(--text-muted)]`,children:[t(`providers.usage.hint`),e&&(0,$.jsxs)($.Fragment,{children:[` `,t(`providers.usage.dayHint`,{zone:e})]})]})}var cn=``,ln=`custom`,un=[{name:`userId`,secret:!1,required:!1},{name:`accessToken`,secret:!0,required:!1}],dn={method:`GET`,url:`{{baseUrl}}/user/balance`,auth:`provider`,headers:{}},fn={isValid:`is_active`,remaining:`balance`,unit:{$const:`USD`}},pn=e=>JSON.stringify(e??{},null,2);function mn(e){return{enabled:e.enabled,template:e.template??cn,intervalMinutes:e.intervalMinutes??null,timeoutSec:e.timeoutSec,baseUrl:e.baseUrl??``,params:{...e.params},secrets:{},method:e.request?.method??`GET`,url:e.request?.url??``,auth:e.request?.auth??`provider`,headers:pn(e.request?.headers),extract:e.extract?pn(e.extract):``}}function hn(e){try{let t=JSON.parse(e||`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function gn({provider:e}){let{t}=U(),{toast:n}=J(),r=Oe(),i=R(e.id),a=de(e.id),o=me(),s=e.quotaConfig,c=(0,Q.useMemo)(()=>mn(s),[s]),[l,u]=(0,Q.useState)(c),[d,f]=(0,Q.useState)(null);(0,Q.useEffect)(()=>u(c),[c]);let p=r.data??[],m=p.find(e=>e.id===s.suggestedTemplate),h=l.template===cn?m:p.find(e=>e.id===l.template),g=l.template===ln,v=g?un:h?.params??[],y=e=>u(t=>({...t,...e})),b=JSON.stringify(l)!==JSON.stringify(c),C=e=>{if(e!==ln||l.url)return y({template:e});let t=h??m;y({template:e,method:t?.request.method??dn.method,url:t?.request.url??dn.url,auth:t?.request.auth??dn.auth,headers:pn(t?.request.headers??dn.headers),extract:pn(t?.extract??fn)})},w=()=>{let e={enabled:l.enabled,template:l.template===cn?null:l.template,intervalMinutes:l.intervalMinutes,timeoutSec:l.timeoutSec??10,baseUrl:l.baseUrl.trim()||null,params:Object.fromEntries(Object.entries(l.params).filter(([,e])=>e.trim()!==``).map(([e,t])=>[e,t.trim()])),secrets:Object.fromEntries(Object.entries(l.secrets).filter(([,e])=>e.trim()!==``))};if(g){let r=hn(l.headers),i=hn(l.extract);if(!r||!i)return n(t(`providers.quota.invalidJson`,{field:t(r?`providers.quota.extract`:`providers.quota.headers`)}),`error`),null;e.request={method:l.method,url:l.url.trim(),auth:l.auth,headers:r},e.extract=i}return e},T=()=>{let r=w();if(!r)return;let a=r.enabled&&!s.enabled;i.mutate(r,{onSuccess:()=>{n(t(`common.saved`),`success`),a&&o.mutate(e.id,{onError:e=>n(K(e),`error`)})},onError:e=>n(K(e),`error`)})},ee=()=>{let e=w();e&&a.mutate(e,{onSuccess:f,onError:e=>n(K(e),`error`)})},te=s.effectiveIntervalMinutes>0?t(`providers.quota.intervalEvery`,{minutes:s.effectiveIntervalMinutes}):t(`providers.quota.intervalOff`),ne=[{value:cn,label:m?t(`providers.quota.templateAuto`,{name:m.name}):t(`providers.quota.templateNone`)},...p.map(e=>({value:e.id,label:e.name,detail:t(`providers.quota.kind.${e.kind}`)})),{value:ln,label:t(`providers.quota.custom`)}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(_,{title:t(`providers.quota.title`),footer:t(`providers.quota.footer`),children:[(0,$.jsx)(W,{label:t(`providers.quota.enable`),detail:t(`providers.quota.enableHint`),children:(0,$.jsx)(P,{checked:l.enabled,label:t(`providers.quota.enable`),onChange:e=>y({enabled:e})})}),(0,$.jsx)(W,{label:t(`providers.quota.template`),children:(0,$.jsx)(q,{className:`w-64`,ariaLabel:t(`providers.quota.template`),value:l.template,onChange:C,options:ne})}),v.map(e=>{let n=t(`providers.quota.param.${e.name}`),r=s.secrets.includes(e.name);return e.secret?(0,$.jsx)(W,{label:n,detail:r?t(`providers.quota.secretStored`):void 0,children:(0,$.jsx)(S,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":n,placeholder:r?`••••••••`:``,value:l.secrets[e.name]??``,onChange:t=>y({secrets:{...l.secrets,[e.name]:t.target.value}})})},e.name):(0,$.jsx)(W,{label:n,children:(0,$.jsx)(S,{className:`w-64 font-mono`,"aria-label":n,value:l.params[e.name]??``,onChange:t=>y({params:{...l.params,[e.name]:t.target.value}})})},e.name)}),v.length>0&&(0,$.jsx)(`div`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.paramsHint`)}),g&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{className:`w-28`,ariaLabel:t(`providers.quota.method`),value:l.method,onChange:e=>y({method:e}),options:[{value:`GET`,label:`GET`},{value:`POST`,label:`POST`}]}),(0,$.jsx)(S,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.quota.url`),value:l.url,onChange:e=>y({url:e.target.value})}),(0,$.jsx)(q,{className:`w-52`,ariaLabel:t(`providers.quota.auth`),value:l.auth,onChange:e=>y({auth:e}),options:[{value:`provider`,label:t(`providers.quota.auth.provider`)},{value:`none`,label:t(`providers.quota.auth.none`)}]})]}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.urlHint`)}),(0,$.jsx)(x,{label:t(`providers.quota.headers`),mono:!0,rows:3,value:l.headers,onChange:e=>y({headers:e.target.value})}),(0,$.jsx)(x,{label:t(`providers.quota.extract`),mono:!0,rows:8,value:l.extract,onChange:e=>y({extract:e.target.value})}),(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.quota.extractHint`)})]}),(0,$.jsx)(W,{label:t(`providers.quota.interval`),detail:t(`providers.quota.intervalHint`,{value:te}),children:(0,$.jsx)(A,{className:`w-28`,label:t(`providers.quota.interval`),min:0,step:1,value:l.intervalMinutes,onChange:e=>y({intervalMinutes:e})})}),(0,$.jsx)(W,{label:t(`providers.quota.timeout`),children:(0,$.jsx)(A,{className:`w-28`,label:t(`providers.quota.timeout`),min:1,step:1,value:l.timeoutSec,onChange:e=>y({timeoutSec:e})})}),(0,$.jsx)(W,{label:t(`providers.quota.baseUrl`),detail:t(`providers.quota.baseUrlHint`),children:(0,$.jsx)(S,{className:`w-64 font-mono`,"aria-label":t(`providers.quota.baseUrl`),placeholder:e.endpoints[0]?.baseUrl,value:l.baseUrl,onChange:e=>y({baseUrl:e.target.value})})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(O,{size:`sm`,variant:`primary`,disabled:!b,loading:i.isPending,onClick:T,children:t(`common.save`)}),(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(pt,{className:`size-3.5`}),loading:a.isPending,onClick:ee,title:t(`providers.quota.testDesc`),children:t(`providers.quota.test`)}),(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(mt,{className:`size-3.5`}),disabled:b,loading:o.isPending,onClick:()=>o.mutate(e.id,{onError:e=>n(K(e),`error`)}),children:t(`providers.quota.fetch`)})]}),(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsx)(_n,{snapshot:e.quota,checkedAtUtc:e.quotaCheckedAtUtc})})]}),(0,$.jsx)(G,{open:d!==null,onOpenChange:e=>!e&&f(null),title:t(`providers.quota.test`),description:t(`providers.quota.testDesc`),width:560,children:d&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(j,{tone:d.ok?`success`:`danger`,title:d.ok?t(`providers.quota.testOk`):t(`providers.quota.testFailed`),children:[!d.ok&&Ze({code:d.errorCode??null,message:d.error??``},t),!d.ok&&d.error&&d.errorCode&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px] opacity-80`,children:d.error})]}),d.url&&(0,$.jsx)(E,{label:t(`providers.quota.requestUrl`),mono:!0,children:d.url}),d.httpStatus!=null&&(0,$.jsx)(E,{label:t(`providers.quota.httpStatus`),children:d.httpStatus}),d.snapshot&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.extracted`)}),(0,$.jsx)(_n,{snapshot:d.snapshot})]}),d.raw!==void 0&&d.raw!==null&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-[12px] text-[var(--text-secondary)]`,children:t(`providers.quota.rawResponse`)}),(0,$.jsx)(Ne,{children:pn(d.raw)})]})]})})]})}function _n({snapshot:e,checkedAtUtc:t}){let{t:n,locale:r}=U(),i=$e(e),a=e?.plans??[],o=e?.fetchedAtUtc?new Date(e.fetchedAtUtc).getTime():0;return!e&&!t?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.quota.never`)}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i&&(0,$.jsxs)(j,{tone:`warning`,title:n(`providers.quota.failed`,{error:Ze(i,n)}),children:[(0,$.jsx)(`span`,{className:`text-[11px]`,children:i.message}),a.length>0&&(0,$.jsx)(`div`,{className:`mt-1 text-[11px]`,children:n(`providers.quota.lastGood`)})]}),e?.isValid===!1&&(0,$.jsx)(j,{tone:`warning`,title:n(`providers.quota.invalid`),children:e.invalidMessage}),a.length>0&&(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-[13px]`,children:[e.name&&(0,$.jsx)(u,{children:e.name}),(0,$.jsx)(`span`,{className:`num`,children:et(e,n,r)??`—`}),tt(e,n,r)&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:tt(e,n,r)}),e.extra&&(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:e.extra})]},t))}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-[var(--text-muted)]`,children:[e?.planLabel&&(0,$.jsx)(u,{tone:`accent`,children:e.planLabel}),o>0&&(0,$.jsx)(`span`,{children:n(`providers.quota.fetchedAt`,{time:rt(o,r,n(`tray.justNow`))??``})})]})]})}var vn={settings:`claudeBridge.source.settings`,path:`claudeBridge.source.path`,installer:`claudeBridge.source.installer`};function yn({provider:e,accounts:t}){let{t:n}=U(),{toast:r}=J(),i=Ee(),a=Ce(),o=Me(),s=t.filter(e=>e.kind===`claude_bridge`),[c,l]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(6),[p,m]=(0,Q.useState)(10),[h,g]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(``),C=i.data;return(0,Q.useEffect)(()=>{C&&(l(C.settings.binaryPath??``),f(C.settings.maxRuns),m(C.settings.idleMinutes))},[C?.settings.binaryPath,C?.settings.maxRuns,C?.settings.idleMinutes]),C?(0,$.jsxs)(_,{title:n(`claudeBridge.title`),footer:n(`claudeBridge.hint`),children:[(0,$.jsxs)(W,{label:C.found?C.version?n(`claudeBridge.found`,{version:C.version}):n(`claudeBridge.foundNoVersion`):n(`claudeBridge.notFound`),detail:C.found&&C.path?n(`claudeBridge.path`,{path:C.path,source:C.source?n(vn[C.source]??`claudeBridge.source.path`):``}):void 0,children:[(0,$.jsx)(u,{tone:C.found?`green`:`orange`,children:C.found?`claude`:`—`}),C.runs.length>0&&(0,$.jsx)(u,{tone:`neutral`,children:n(`claudeBridge.runs`,{n:C.runs.length})})]}),C.runs.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11.5px] text-[var(--text-secondary)]`,children:C.runs.map(e=>(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-x-3`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:e.pid??`—`}),(0,$.jsx)(`span`,{children:e.model}),(0,$.jsx)(`span`,{children:n(`claudeBridge.run.${e.state}`)}),(0,$.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e.configDir||n(`claudeBridge.defaultDir`)})]},e.id))}),(0,$.jsxs)(`div`,{className:`grid gap-3 px-4 py-3 sm:grid-cols-3`,children:[(0,$.jsx)(k,{label:n(`claudeBridge.binaryPath`),children:(0,$.jsx)(S,{mono:!0,value:c,placeholder:n(`claudeBridge.binaryPathPlaceholder`),onChange:e=>l(e.target.value)})}),(0,$.jsx)(k,{label:n(`claudeBridge.maxRuns`),children:(0,$.jsx)(A,{value:d,min:1,onChange:f})}),(0,$.jsx)(k,{label:n(`claudeBridge.idleMinutes`),children:(0,$.jsx)(A,{value:p,min:1,onChange:m})}),(0,$.jsx)(`div`,{className:`sm:col-span-3`,children:(0,$.jsx)(O,{size:`sm`,disabled:a.isPending,onClick:()=>a.mutate({binaryPath:c.trim(),maxRuns:d??6,idleMinutes:p??10},{onSuccess:()=>r(n(`claudeBridge.saved`),`success`),onError:e=>r(K(e),`error`)}),children:n(`common.save`)})})]}),C.clientPolicy===`claude-code-only`&&(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(j,{tone:`info`,title:n(`claudeBridge.clientPolicy`)})}),(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`claudeBridge.cost`)}),s.map(e=>(0,$.jsx)(bn,{account:e,found:C.found},e.id)),(0,$.jsxs)(`div`,{className:`grid gap-3 px-4 py-3 sm:grid-cols-3`,children:[(0,$.jsx)(k,{label:n(`claudeBridge.add.name`),children:(0,$.jsx)(S,{value:h,onChange:e=>g(e.target.value)})}),(0,$.jsx)(k,{label:n(`claudeBridge.add.configDir`),hint:n(`claudeBridge.add.configDirHint`),children:(0,$.jsx)(S,{mono:!0,value:v,placeholder:`~/.claude-work`,onChange:e=>y(e.target.value)})}),(0,$.jsx)(k,{label:n(`claudeBridge.add.proxy`),children:(0,$.jsx)(S,{mono:!0,value:b,placeholder:`http://127.0.0.1:7890`,onChange:e=>x(e.target.value)})}),(0,$.jsx)(`div`,{className:`sm:col-span-3`,children:(0,$.jsx)(O,{size:`sm`,variant:`primary`,disabled:o.isPending,onClick:()=>o.mutate({providerId:e.id,displayName:h.trim()||void 0,configDir:v.trim(),httpProxy:b.trim()||void 0},{onSuccess:()=>{r(n(`claudeBridge.added`),`success`),g(``),y(``),x(``)},onError:e=>r(K(e),`error`)}),children:n(`claudeBridge.add`)})})]})]}):null}function bn({account:e,found:t}){let{t:n}=U(),{toast:r}=J(),[i,a]=(0,Q.useState)(!1),o=ke(i?e.id:null),s=c(),[l,u]=(0,Q.useState)(!1),d=ze(l?e.id:null),f=d.data?.state;(0,Q.useEffect)(()=>{f===`done`&&(u(!1),a(!0),o.refetch(),r(n(`claudeBridge.login.done`),`success`))},[f]);let p=o.data?.loggedIn?[o.data.email,o.data.plan].filter(Boolean).join(` · `):``,m=o.data?o.data.known?o.data.loggedIn?n(`claudeBridge.signin.ok`,{who:p}):n(`claudeBridge.signin.out`):n(`claudeBridge.signin.unknown`,{error:o.data.error??``}):n(`claudeBridge.dir`,{dir:e.claudeConfigDir||n(`claudeBridge.defaultDir`)});return(0,$.jsxs)(W,{label:e.displayName||e.id,detail:m,children:[(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Tt,{className:`size-3.5`}),disabled:!t,onClick:()=>i?void o.refetch():a(!0),children:n(`claudeBridge.signin.check`)}),(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(yt,{className:`size-3.5`}),disabled:!t||s.isPending||f===`waiting`,onClick:()=>s.mutate(e.id,{onSuccess:()=>u(!0),onError:e=>r(K(e),`error`)}),children:n(`claudeBridge.login`)}),l&&f===`waiting`&&(0,$.jsxs)(`span`,{className:`flex items-center gap-2 text-[11.5px] text-[var(--text-secondary)]`,children:[n(`claudeBridge.login.waiting`),d.data?.url&&(0,$.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-[var(--accent)]`,href:d.data.url,target:`_blank`,rel:`noopener noreferrer`,children:[n(`claudeBridge.login.open`),` `,(0,$.jsx)(ft,{className:`size-3`})]})]}),l&&f===`failed`&&(0,$.jsx)(`span`,{className:`text-[11.5px] text-[var(--danger)]`,children:n(`claudeBridge.login.failed`,{message:d.data?.message??``})})]})}var xn={imported:`providers.subscription.importBatchStatus.imported`,updated:`providers.subscription.importBatchStatus.updated`,duplicate:`providers.subscription.importBatchStatus.duplicate`,invalid_format:`providers.subscription.importBatchStatus.invalid_format`,failed:`providers.subscription.importBatchStatus.failed`,ready:`providers.subscription.importBatchStatus.ready`},Sn={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Cn={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function wn(e){return e.split(/[,\s]+/).flatMap(e=>{let t=e.replace(/^["']+|["']+$/g,``);return t.startsWith(`tid=`)||t.startsWith(`exp=`)?[t]:t.split(`;`)}).filter(e=>e.replace(/^["']+|["']+$/g,``).length>0).length}function Tn(e){let t=e.trim();if(t.length===0)return 0;if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e.filter(e=>typeof e==`object`&&!!e||typeof e==`string`&&e.trim().length>0).length;if(typeof e==`object`&&e)return 1}catch{}let n=0;for(let t of e.split(`
2
+ `)){let e=t.trim();e.length===0||e.startsWith(`#`)||(n+=e.startsWith(`{`)?1:wn(e))}return n}function En({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=U(),{toast:o}=J(),s=Ae(e),[c,l]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),h=(0,Q.useMemo)(()=>Tn(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),m(null))},[n]),n===null)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let g=n===`apiKey`,_=g?t.formats.filter(e=>e.endsWith(`-api-key`)):t.formats,v=!g&&t.formats.some(e=>e.includes(`refresh-token`)||e.endsWith(`-json`)),y=a(g?`providers.accounts.import.apiKeyLabel`:`providers.accounts.import.label`),b=e=>s.mutate({text:c,asApiKey:g||void 0,dryRun:e||void 0,httpProxy:d.trim()||void 0},{onSuccess:t=>{m({...t,dryRun:e}),!e&&(o(a(`providers.accounts.import.summary`,{ok:t.imported,dup:t.duplicates,fail:t.failed}),t.failed>0?`info`:`success`),!(t.failed>0)&&(n===`batch`?l(``):i()))},onError:e=>o(K(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:a(Cn[n]),description:a(`providers.accounts.import.desc`),width:560,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[_.length>0&&(0,$.jsx)(`p`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:a(`providers.accounts.import.formats`,{formats:_.map(e=>a(`providers.accounts.format.${e}`)).join(` · `)})}),(0,$.jsx)(x,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":y,placeholder:y,spellCheck:!1}),(0,$.jsx)(S,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:d,onChange:e=>f(e.target.value)}),v&&(0,$.jsx)(j,{tone:`info`,title:a(`providers.accounts.import.rotateWarning`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.import.count`,{n:h})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[n===`batch`&&(0,$.jsx)(O,{disabled:h===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>b(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(O,{variant:`primary`,disabled:h===0||h>t.maxBatch,loading:s.isPending&&!s.variables?.dryRun,onClick:()=>b(!1),children:a(`providers.accounts.import.run`)})]})]}),p&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[12px] font-medium`,children:a(p.dryRun?`providers.accounts.import.previewSummary`:`providers.accounts.import.summary`,{ok:p.imported,dup:p.duplicates,fail:p.failed})}),(0,$.jsx)(`ul`,{className:`card max-h-72 divide-y divide-[var(--border)] overflow-auto`,children:p.items.map(e=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`w-6 shrink-0 text-[var(--text-muted)]`,children:e.index}),(0,$.jsx)(`span`,{className:`selectable w-28 shrink-0 truncate font-mono`,children:e.source}),(0,$.jsx)(u,{tone:Sn[e.status],children:a(xn[e.status])}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-[var(--text-muted)]`,children:a(`providers.accounts.credential.${e.kind}`)}),(0,$.jsx)(`span`,{className:`selectable min-w-0 flex-1 break-words text-[var(--text-secondary)]`,children:e.account?.displayName&&(e.status===`imported`||e.status===`updated`)?`${e.account.displayName}${e.message?` · ${e.message}`:``}`:e.message??``})]},e.index))})]})]})})}function Dn(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var On={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},kn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function An(e,t){let n=(e??``).toLowerCase(),r=t?`110,115,135`:/max|ultra/.test(n)?`47,124,246`:/pro|plus|premium/.test(n)?`52,195,143`:/team|business|enterprise|allegro|vivace/.test(n)?`130,100,230`:`110,115,135`;return`linear-gradient(135deg, rgba(${r},.34), rgba(${r},.08))`}function jn({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:s,usage:c}){let{t:l,locale:u}=U(),d=Lt(`provider.account.row`,{providerId:e.providerId,accountId:e.id}),f=Dn(e),p=e.displayName||e.accountEmail||e.keyMasked||e.id,m=e.kind===`api_key`,h=e.plan?.trim(),g=f===`cooling`?{text:l(`providers.subscription.cooldown`,{when:H(e.cooldownUntilUtc,u)}),tone:`var(--warning)`}:f===`dead`?{text:e.lastError||l(kn[e.status]),tone:`var(--danger)`}:m?{text:e.keyMasked??l(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:l(`providers.accounts.expiresAt`,{when:H(e.expiresAtUtc,u)}),tone:void 0}:null,_=[{id:`activate`,label:l(`providers.subscription.activate`),icon:(0,$.jsx)(ot,{className:`size-3.5`}),disabled:e.isCurrent||f===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:l(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(Ct,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:l(`providers.subscription.moveUp`),icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:l(`providers.subscription.moveDown`),icon:(0,$.jsx)(it,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:l(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(mt,{className:`size-3.5`}),disabled:f===`dead`,onSelect:()=>n.refreshQuota(e)},...m?[]:[{id:`refresh`,label:l(`providers.subscription.refreshToken`),icon:(0,$.jsx)(wt,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:l(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],...d,{id:`remove`,label:l(`providers.subscription.logout`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],v=l(f===`disabled`?`providers.subscription.disabled`:kn[e.status]),y=l(m?`providers.accounts.kind.api_key`:e.kind===`claude_bridge`?`providers.accounts.kind.claude_bridge`:`providers.accounts.kind.oauth`),b=e.quota?.session?.usedPercent!=null||e.quota?.weekly?.usedPercent!=null||e.quota?.credits?.usedPercent!=null;return(0,$.jsxs)(`div`,{"data-testid":`account-card`,className:L(`group card relative flex min-h-[292px] min-w-0 cursor-pointer flex-col overflow-hidden transition-colors hover:bg-[var(--fill)]`,e.isCurrent&&`ring-1 ring-[var(--accent)]`,r&&`bg-[var(--accent-subtle)]`,f===`disabled`&&`opacity-55`),onClick:()=>i?a(e.id):n.open(e),children:[(0,$.jsxs)(`div`,{className:`relative shrink-0 px-3 pb-3 pt-2.5`,style:{background:An(h,m)},children:[(f===`cooling`||f===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:On[f]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:L(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rn,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":l(`providers.accounts.select`,{name:p})})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{role:`img`,"aria-label":v,className:`size-1.5 shrink-0 rounded-full`,style:{background:On[f]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:v})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${l(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(gt,{className:`size-3.5`,"aria-label":l(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Qe,{iconOnly:!0,label:l(`common.more`),icon:(0,$.jsx)(dt,{className:`size-4`}),items:_})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 truncate text-[17px] font-bold tracking-[.01em]`,title:h||y,children:h||y})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col px-3 pb-3 pt-2.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-[13px] font-medium outline-none focus-visible:underline`,title:p,onClick:t=>{t.stopPropagation(),i?a(e.id):n.open(e)},children:p}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 items-center gap-1 whitespace-nowrap text-[11px] text-[var(--text-muted)]`,children:[e.isCurrent&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[var(--success)]`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`●`}),(0,$.jsx)(`span`,{children:l(`providers.subscription.current`)})]}),e.isCurrent&&(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`shrink-0`,children:y}),e.source&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,$.jsx)(`span`,{className:`truncate`,children:l(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:l(`providers.accounts.order`,{n:t+1})})]}),(0,$.jsx)(`div`,{className:`mt-1.5 min-h-[28px]`,children:g&&(f===`cooling`||f===`dead`||!b)&&(0,$.jsx)(`div`,{className:`line-clamp-2 text-[11px] leading-snug`,style:{color:g.tone??`var(--text-muted)`},title:g.text,children:g.text})}),(0,$.jsx)(`div`,{className:`mt-3 shrink-0 border-t border-[var(--border-subtle)] pt-2`,children:(0,$.jsx)(on,{usage:c,compact:!0})}),f===`dead`?(0,$.jsxs)(`div`,{className:`mt-auto flex items-center gap-2 pt-2`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:l(`providers.accounts.signedOut`)}),!m&&(0,$.jsx)(O,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:l(`providers.subscription.relogin`)})]}):(0,$.jsx)(Nn,{quota:e.quota??null,pending:s})]})]})}var Mn=10;function Nn({quota:e,pending:t}){let{t:n,locale:r}=U(),i=[];return e?.session?.usedPercent!=null&&i.push({key:`session`,label:e.session.windowMinutes?`${Math.round(e.session.windowMinutes/60)}h`:n(`providers.accounts.quotaShortSession`),percent:e.session.usedPercent,reset:e.session.resetsAtUtc}),e?.weekly?.usedPercent!=null&&i.push({key:`weekly`,label:n(`providers.accounts.quotaShortWeekly`),percent:e.weekly.usedPercent,reset:e.weekly.resetsAtUtc}),i.length<2&&e?.credits?.usedPercent!=null&&i.push({key:`credits`,label:n(e.entitlement==null?`providers.accounts.quotaShortCredits`:`providers.accounts.quotaShortPremium`),percent:e.credits.usedPercent,reset:e.credits.resetsAtUtc}),i.length===0?null:(0,$.jsx)(`div`,{className:L(`mt-auto flex flex-col gap-2 pt-2`,t&&`opacity-60`),children:i.slice(0,2).map(e=>{let t=Math.max(0,Math.min(100,Math.round(e.percent))),i=t>=90?`var(--danger)`:t>=70?`var(--warning)`:`var(--accent)`,a=Math.round(t/100*Mn),o=e.reset?n(`providers.subscription.quotaResets`,{when:H(e.reset,r)}):void 0;return(0,$.jsxs)(`div`,{className:`min-w-0`,title:o,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-[11px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[t,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-label":e.label,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,className:`mt-0.5 flex gap-[3px]`,children:Array.from({length:Mn},(e,t)=>(0,$.jsx)(`i`,{className:`h-[5px] flex-1 rounded-[2px] bg-[var(--surface-muted)]`,style:t<a?{background:i}:void 0},t))})]},e.key)})})}function Pn({quota:e,className:t}){let{t:n,locale:r}=U(),i=e=>{if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:n(`providers.subscription.quotaResets`,{when:t.toLocaleString(r)})},a=[];e.session?.usedPercent!=null&&a.push({key:`session`,label:n(`providers.subscription.quotaWindowSession`),window:e.session}),e.weekly?.usedPercent!=null&&a.push({key:`weekly`,label:n(`providers.subscription.quotaWindowWeekly`),window:e.weekly}),e.credits?.usedPercent!=null&&a.push({key:`credits`,label:e.entitlement==null?n(`providers.subscription.quotaWindowCredits`):n(`providers.subscription.quotaWindowPremium`),window:{usedPercent:e.credits.usedPercent,resetsAtUtc:e.credits.resetsAtUtc??null}});let o=e.credits?.prepaidBalance==null?null:n(`providers.subscription.quotaBalance`,{balance:e.credits.prepaidBalance}),s=e.entitlement!=null&&e.entitlement>=0?[n(`providers.subscription.quotaPremiumCount`,{used:Math.max(0,(e.entitlement??0)-(e.remaining??0)),total:e.entitlement}),e.overageUsed?n(`providers.subscription.quotaOverage`,{count:e.overageUsed}):null,e.overagePermitted===!1?n(`providers.subscription.quotaOverageOff`):null].filter(Boolean).join(` · `):null,c=e.planLabel??(e.fetchedAtUtc?n(`providers.subscription.quotaFetchedAt`,{when:new Date(e.fetchedAtUtc).toLocaleString(r)}):null);return(0,$.jsx)(`div`,{className:L(`px-4 py-1`,t),children:(0,$.jsxs)(`div`,{className:`card flex flex-col gap-3 p-3`,children:[(c||o)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] text-[var(--text-secondary)]`,children:[c&&(0,$.jsx)(`span`,{children:c}),o&&(0,$.jsx)(`span`,{children:o})]}),a.length===0?(0,$.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`providers.subscription.quotaNoWindows`)}):a.map(e=>(0,$.jsx)(Fn,{label:e.label,window:e.window,reset:i(e.window.resetsAtUtc)},e.key)),s&&(0,$.jsx)(`div`,{className:`text-[10.5px] text-[var(--text-muted)]`,children:s})]})})}function Fn({label:e,window:t,reset:n}){let r=Math.max(0,Math.min(100,Math.round(t.usedPercent??0))),[i,a]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches){a(r);return}let e=requestAnimationFrame(()=>a(r));return()=>cancelAnimationFrame(e)},[r]);let o=r>=90?`var(--danger)`:r>=70?`var(--warning)`:`var(--accent)`,s=t.windowMinutes?Math.round(t.windowMinutes/60):null;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,$.jsxs)(`span`,{className:`text-[var(--text-secondary)]`,children:[e,s!=null&&(0,$.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[` · `,s,`h`]})]}),(0,$.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[r,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":e,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface-muted)]`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-[width] duration-500 ease-out`,style:{width:`${i}%`,background:o}})}),n&&(0,$.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n})]})}var In={available:`green`,redeemed:`neutral`,expired:`orange`};function Ln({account:e,providerId:t}){let{t:n}=U(),{toast:r,confirm:i}=J(),a=v(e.id,e.status===`active`),o=De(t),s=a.data?.credits??[],c=a.data?.available_count??s.filter(e=>e.status===`available`).length,l=async t=>{await i({title:n(`providers.subscription.credits.consumeConfirm`,{title:t.title??t.reset_type??``}),detail:n(`providers.subscription.credits.consumeDetail`),confirmLabel:n(`providers.subscription.credits.consume`),destructive:!0})&&o.mutate({accountId:e.id,creditId:t.id},{onSuccess:()=>r(n(`providers.subscription.credits.consumed`),`success`),onError:e=>r(e instanceof F&&e.status===409?K(e):`${n(`providers.subscription.credits.consumeFailed`)}:${K(e)}`,`error`)})};return(0,$.jsxs)(_,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(M,{className:`my-4`}),a.isError&&(0,$.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.unavailable`)}),a.data&&s.length===0&&(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:n(`providers.subscription.credits.none`)}),s.map(e=>{let t=e.status!==`available`;return(0,$.jsxs)(W,{className:L(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ht,{className:`size-3.5 text-[var(--text-secondary)]`}),e.title??e.reset_type??e.id]}),detail:[e.description,e.expires_at?n(`providers.subscription.credits.expires`,{when:new Date(e.expires_at).toLocaleString()}):null,e.redeemed_at?n(`providers.subscription.credits.redeemedAt`,{when:new Date(e.redeemed_at).toLocaleString()}):null,e.is_supported_by_plan===!1?n(`providers.subscription.credits.notInPlan`):null].filter(Boolean).join(` · `),children:[(0,$.jsx)(u,{tone:In[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Dt,{className:`size-3.5`}),disabled:t,loading:o.isPending&&o.variables?.creditId===e.id,onClick:()=>void l(e),children:n(`providers.subscription.credits.consume`)})]},e.id)}),a.data&&s.length>0&&(0,$.jsx)(`div`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:n(`providers.subscription.credits.availableCount`,{count:c})})]})}var Rn={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function zn({provider:e,account:t,index:n,actions:r,onClose:i,usage:a,usageTimeZone:o}){let{t:s,locale:c}=U(),{toast:l}=J(),d=We(e.id),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(``);if((0,Q.useEffect)(()=>{p(t?.displayName??``),h(t?.httpProxy??``)},[t?.id,t?.displayName,t?.httpProxy]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let g=Dn(t),_=t.kind===`api_key`,v=e.templateId===`openai-subscription`,y=e.httpProxy||s(`providers.accounts.proxyFallbackSystem`),b=e=>e?H(e,c):`—`,x=(e,n)=>d.mutate({id:t.id,...e},{onSuccess:()=>l(s(n),`success`),onError:e=>l(K(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,s(_?`providers.accounts.kind.api_key`:t.kind===`claude_bridge`?`providers.accounts.kind.claude_bridge`:`providers.accounts.kind.oauth`)].filter(Boolean).join(` · `),width:520,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(ot,{className:`size-3.5`}),disabled:t.isCurrent||g===`dead`,onClick:()=>r.activate(t),children:s(`providers.subscription.activate`)}),(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(mt,{className:`size-3.5`}),disabled:g===`dead`,onClick:()=>r.refreshQuota(t),children:s(`providers.subscription.quotaRefresh`)}),!_&&(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(wt,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:s(`providers.subscription.refreshToken`)}),!_&&t.status!==`active`&&(0,$.jsx)(O,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:s(`providers.subscription.relogin`)}),(0,$.jsx)(O,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),onClick:()=>r.remove(t),children:s(`providers.subscription.logout`)})]}),g===`dead`&&t.lastError&&(0,$.jsx)(j,{tone:`danger`,title:t.lastError}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.usage.title`)}),(0,$.jsx)(`div`,{className:`card px-3 py-2`,children:(0,$.jsx)(on,{usage:a})}),(0,$.jsx)(sn,{timeZone:o})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(S,{className:`flex-1`,label:s(`providers.accounts.detail.name`),value:f,onChange:e=>p(e.target.value)}),(0,$.jsx)(O,{disabled:f.trim().length===0||f.trim()===t.displayName,loading:d.isPending&&d.variables?.displayName!==void 0,onClick:()=>x({displayName:f.trim()},`providers.accounts.renamed`),children:s(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(S,{className:`flex-1`,mono:!0,label:s(`providers.accounts.detail.proxy`),placeholder:y,value:m,onChange:e=>h(e.target.value)}),(0,$.jsx)(O,{disabled:m.trim()===(t.httpProxy??``),loading:d.isPending&&d.variables?.httpProxy!==void 0,onClick:()=>x({httpProxy:m.trim()},`providers.accounts.proxySaved`),children:s(`common.save`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:s(`providers.accounts.detail.proxyHint`,{fallback:y})})]}),t.quota&&(0,$.jsxs)(`section`,{className:`-mx-4 flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`px-4 text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.quota`)}),(0,$.jsx)(Pn,{quota:t.quota})]}),v&&g!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(Ln,{account:t,providerId:e.id})}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`h4`,{className:`text-[11px] font-medium text-[var(--text-secondary)]`,children:s(`providers.accounts.detail.credentials`)}),(0,$.jsxs)(`div`,{className:`card divide-y divide-[var(--border)] px-3`,children:[(0,$.jsx)(E,{label:s(`providers.accounts.detail.status`),children:(0,$.jsx)(u,{tone:g===`usable`?`green`:g===`cooling`?`orange`:g===`dead`?`red`:`neutral`,children:s(g===`disabled`?`providers.subscription.disabled`:Rn[t.status])})}),t.source&&(0,$.jsx)(E,{label:s(`providers.accounts.detail.source`),children:s(`providers.accounts.source.${t.source}`)}),_?(0,$.jsx)(E,{label:s(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(E,{label:s(`providers.accounts.detail.expires`),children:b(t.expiresAtUtc)}),(0,$.jsx)(E,{label:s(`providers.accounts.detail.lastRefresh`),children:b(t.lastRefreshAtUtc)})]}),g===`cooling`&&(0,$.jsx)(E,{label:s(`providers.accounts.filter.cooling`),children:b(t.cooldownUntilUtc)}),(0,$.jsx)(E,{label:s(`providers.accounts.detail.order`),children:s(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(E,{label:s(`providers.accounts.detail.created`),children:b(t.createdAt)}),t.lastError&&g!==`dead`&&(0,$.jsx)(E,{label:s(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function Bn({provider:e}){let{t}=U(),{toast:n}=J(),i=e.authScheme===`oauth-subscription`,a=r(e.id,i),o=p(e.id);if(!i||!a.data)return null;let s=a.data,c=e=>o.mutate(e,{onError:e=>n(K(e),`error`)}),l=s.claudeSubscription||s.clientPolicy===`claude-code-only`;return!l&&!s.claudeSubscription?null:(0,$.jsxs)(_,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[l&&(0,$.jsx)(W,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(P,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:s.clientPolicy===`claude-code-only`,disabled:o.isPending,onChange:e=>c({clientPolicy:e?`claude-code-only`:`any`})})}),s.claudeSubscription&&(0,$.jsx)(W,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(P,{label:t(`providers.subscription.policy.mimic`),checked:s.mimicClaudeCode,disabled:o.isPending,onChange:e=>c({mimicClaudeCode:e})})}),l&&s.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:s.mimicClaudeCode?(0,$.jsx)(j,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(j,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Vn=[{value:`all`,label:`providers.accounts.filter.all`},{value:`usable`,label:`providers.accounts.filter.usable`},{value:`cooling`,label:`providers.accounts.filter.cooling`},{value:`dead`,label:`providers.accounts.filter.dead`},{value:`disabled`,label:`providers.accounts.filter.disabled`}],Hn=3e5;function Un({provider:e}){let{t}=U(),{toast:n,confirm:i}=J(),a=_e(),s=e.authScheme===`oauth-subscription`,c=He(e.id,s),u=Le(e.id,s),f=r(e.id,s),h=p(e.id),_=m(e.id,s),v=d(e.id),y=he(e.id),b=Te(e.id),x=ge(e.id),C=Ye(e.id),T=je(e.id),ee=w(e.id),E=ae(e.id),te=We(e.id),ne=g(e.id),re=e.templateId===`openai-subscription`,D=ye(s&&re),ie=be(e.id),k=e.templateId===`github-copilot-subscription`,oe=Ge(s&&k),se=Re(e.id),[ce,A]=(0,Q.useState)(`all`),[le,ue]=(0,Q.useState)(``),[N,de]=(0,Q.useState)(new Set),[P,fe]=(0,Q.useState)(null),[pe,me]=(0,Q.useState)(null),[ve,xe]=(0,Q.useState)(!1),[Se,Ce]=(0,Q.useState)(``),[I,we]=(0,Q.useState)(!1),[R,Ee]=(0,Q.useState)(!1),[z,De]=(0,Q.useState)(null),[Oe,ke]=(0,Q.useState)(null),[Ae,Me]=(0,Q.useState)(!1),[Ne,Pe]=(0,Q.useState)(``),Fe=(0,Q.useRef)(new Set),Ie=(0,Q.useRef)(new Set),B=(0,Q.useMemo)(()=>c.data??[],[c.data]);if((0,Q.useEffect)(()=>{if(s)for(let e of B){if(e.status!==`active`||e.kind===`claude_bridge`||Ie.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<Hn||(Ie.current.add(e.id),x.mutate(e.id,{onError:()=>{}}))}},[B,s]),(0,Q.useEffect)(()=>{let e=new Set(B.map(e=>e.id));de(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),P&&!e.has(P)&&fe(null)},[B,P]),(0,Q.useEffect)(()=>{if(!R||z?.mode!==`pkce`)return;let e=setInterval(()=>void c.refetch(),3e3);return()=>clearInterval(e)},[R,z,c]),(0,Q.useEffect)(()=>{if(!R||z?.mode!==`pkce`)return;let e=B.find(e=>!Fe.current.has(e.id));e&&H(!0,e.displayName||e.accountEmail||e.id)},[B,R,z]),(0,Q.useEffect)(()=>{if(!R||z?.mode!==`device`&&z?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await y.mutateAsync(z.state);if(e)return;t=0,n.status===`done`?H(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&H(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof F&&(n.status===404||n.status===400)){H(!1,void 0,K(n));return}++t>=5&&H(!1,void 0,K(n))}},r=setInterval(()=>void n(),Math.max(z.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[R,z]),!s)return null;let V=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,H=(r,i,o)=>{if(a.invalidateQueries({queryKey:l.providerAccounts(e.id)}),r){De(null),ke(null),Ee(!1),n(t(`providers.subscription.loginOk`,{name:i??``}),`success`);return}o&&ke(o)},ze=(e,r)=>{Fe.current=new Set(B.map(e=>e.id)),ke(null),v.mutate({accountId:e,httpProxy:r},{onSuccess:e=>{xe(!1),De(e),Ee(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof F&&e.details?.needsVerification?n(t(`providers.subscription.needsVerification`),`error`):n(K(e),`error`)}})},Be=async()=>{if(z){Me(!0);try{let e=await y.mutateAsync(z.state);e.status===`done`?H(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?n(t(`providers.subscription.stillWaiting`),`info`):H(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof F&&e.status===404){let t=((await c.refetch()).data??[]).find(e=>!Fe.current.has(e.id));t?H(!0,t.displayName||t.accountEmail||t.id):H(!1,void 0,K(e))}else H(!1,void 0,K(e))}finally{Me(!1)}}},Ve=async()=>{if(z&&z.mode===`paste`&&Ne.trim().length!==0){Me(!0);try{let e=await b.mutateAsync({state:z.state,code:Ne.trim()});e.status===`done`?(Pe(``),H(!0,e.account.displayName||e.account.accountEmail||e.account.id)):H(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){H(!1,void 0,K(e))}finally{Me(!1)}}},Ue=()=>ie.mutate(void 0,{onSuccess:e=>{n(t(`providers.subscription.importOk`,{name:V(e.account)}),e.warning?`info`:`success`),e.warning&&n(e.warning,`error`),D.refetch()},onError:e=>n(K(e),`error`)}),Ke=()=>se.mutate(``,{onSuccess:e=>{n(t(`providers.subscription.importOk`,{name:V(e.account)}),e.warning?`info`:`success`),e.warning&&n(e.warning,`error`)},onError:e=>n(K(e),`error`)}),qe=(e,t)=>{let r=B.map(e=>e.id),i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],ne.mutate(r,{onError:e=>n(K(e),`error`)}))},Je=async()=>{if(await i({title:t(`providers.accounts.exportConfirm`),detail:t(`providers.accounts.exportDetail`),confirmLabel:t(`providers.accounts.export`)}))try{let e=await ee.mutateAsync();if(e.count===0){n(t(`providers.accounts.exportNone`),`info`);return}if(!await nt.copy(e.text)){n(t(`providers.accounts.exportCopyFailed`),`error`);return}n(t(`providers.accounts.exportDone`,{n:e.count})+(e.skipped>0?t(`providers.accounts.exportSkipped`,{n:e.skipped}):``),`success`)}catch(e){n(K(e),`error`)}},Xe=async e=>{let r=V(e);await i({title:t(`providers.subscription.logoutConfirm`,{name:r}),destructive:!0,confirmLabel:t(`providers.subscription.logout`)})&&T.mutate(e.id,{onError:e=>n(K(e),`error`)})},W={open:e=>fe(e.id),activate:e=>E.mutate(e.id,{onSuccess:()=>n(t(`providers.subscription.activated`,{name:V(e)}),`success`),onError:e=>n(K(e),`error`)}),toggleEnabled:e=>te.mutate({id:e.id,enabled:!e.enabled},{onError:e=>n(K(e),`error`)}),refreshQuota:e=>x.mutate(e.id,{onError:e=>{e instanceof F&&e.status===501?n(t(`providers.subscription.quotaUnsupported`),`error`):n(K(e),`error`)}}),refreshToken:e=>C.mutate(e.id,{onSuccess:()=>n(t(`providers.subscription.tokenRefreshed`),`success`),onError:e=>n(K(e),`error`)}),relogin:e=>ze(e.id),remove:e=>void Xe(e)},Ze=e=>de(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),$e=async r=>{let i=B.filter(e=>N.has(e.id));we(!0);let o=0;for(let e of i)try{await r(e),o++}catch(t){n(`${V(e)}: ${K(t)}`,`error`)}we(!1),de(new Set),a.invalidateQueries({queryKey:l.providerAccounts(e.id)}),o>0&&n(t(`providers.accounts.bulkDone`,{n:o}),`success`)},et=async()=>{await i({title:t(`providers.accounts.bulkDeleteConfirm`,{n:N.size}),detail:t(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&await $e(e=>T.mutateAsync(e.id))},tt=B.map(e=>Dn(e)),q=e=>e===`all`?B.length:tt.filter(t=>t===e).length,rt=le.trim().toLowerCase(),it=B.map((e,t)=>({a:e,index:t,state:tt[t]})).filter(({a:e,state:t})=>(ce===`all`||t===ce)&&(rt.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes(rt)))),at=B.find(e=>e.id===P)??null,Y=_.data,ot=N.size>0,st=[{id:`login`,label:t(`providers.accounts.addLogin`),icon:(0,$.jsx)(yt,{className:`size-3.5`}),onSelect:()=>ze()},{id:`login-proxy`,label:t(`providers.accounts.addLoginProxy`),onSelect:()=>xe(!0)},...re&&D.data?.available?[{id:`codex`,separatorBefore:!0,label:t(`providers.subscription.importCodex`),icon:(0,$.jsx)(At,{className:`size-3.5`}),onSelect:Ue}]:[],...k?[{id:`copilot`,separatorBefore:!0,label:t(`providers.subscription.importCopilot`),icon:(0,$.jsx)(At,{className:`size-3.5`}),onSelect:Ke}]:[],...Y?.supported?[{id:`token`,separatorBefore:!(re&&D.data?.available)&&!k,label:t(`providers.accounts.addToken`),onSelect:()=>me(`token`)}]:[],...Y?.apiKey?[{id:`apikey`,label:t(`providers.accounts.addApiKey`),icon:(0,$.jsx)(_t,{className:`size-3.5`}),onSelect:()=>me(`apiKey`)}]:[]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`card mb-3 flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`mr-auto flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[var(--text)]`,children:t(`providers.accounts.statTotal`,{n:B.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:t(`providers.accounts.statUsable`,{n:q(`usable`)})}),q(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:t(`providers.accounts.statCooling`,{n:q(`cooling`)})}),q(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:t(`providers.accounts.statDead`,{n:q(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`providers.accounts.providerProxy`,{proxy:e.httpProxy||t(`providers.accounts.proxyFallbackSystem`)})})]}),f.data&&(0,$.jsx)(Kn,{policy:f.data,onChange:e=>h.mutate({switchMode:e},{onError:e=>n(K(e),`error`)})})]}),f.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:t(Gn(f.data.switchMode))}),e.templateId===`claude-subscription`&&(0,$.jsx)(yn,{provider:e,accounts:B}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(o,{className:`w-52`,value:le,onChange:ue,placeholder:t(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":t(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Vn.filter(e=>e.value===`all`||q(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":ce===e.value,onClick:()=>A(e.value),className:L(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,ce===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[t(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:q(e.value)})]},e.value))}),Y?.supported&&(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(vt,{className:`size-3.5`}),onClick:()=>me(`batch`),children:t(`providers.accounts.batchImport`)}),Y?.supported&&B.length>0&&(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(Ot,{className:`size-3.5`}),disabled:ee.isPending,onClick:()=>void Je(),children:t(`providers.accounts.export`)}),(0,$.jsx)(Qe,{label:t(`providers.accounts.add`),icon:(0,$.jsx)(X,{className:`size-3.5`}),items:st})]}),re&&D.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[t(`providers.subscription.localCodexFound`,{who:D.data.accountEmail??D.data.plan??t(`providers.subscription.unknownAccount`)}),D.data.detail?` · ${D.data.detail}`:``]}),k&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[oe.data?.available?t(`providers.subscription.localCopilotFound`,{source:oe.data.source??``}):t(`providers.subscription.localCopilotHint`),oe.data?.detail?` · ${oe.data.detail}`:``]}),c.isLoading?(0,$.jsx)(M,{className:`my-4`}):B.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ze(),className:`flex w-full flex-col items-center gap-1 rounded-[var(--radius-card,12px)] border border-dashed border-[var(--border)] px-4 py-6 text-[12px] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--text)]`,children:[(0,$.jsx)(`span`,{children:t(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(X,{className:`size-3.5`}),` `,t(`providers.subscription.login`)]})]}):it.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:t(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:it.map(({a:e,index:t})=>(0,$.jsx)(jn,{account:e,usage:u.data?.accounts.find(t=>t.accountId===e.id),index:t,actions:W,selected:N.has(e.id),selecting:ot,onToggleSelect:Ze,quotaPending:x.isPending&&x.variables===e.id,onMove:B.length>1?{up:t>0?()=>qe(t,-1):void 0,down:t<B.length-1?()=>qe(t,1):void 0}:void 0},e.id))}),u.isError&&(0,$.jsx)(j,{tone:`danger`,title:t(`providers.usage.error`),children:K(u.error)}),B.length>0&&(0,$.jsx)(sn,{timeZone:u.data?.timeZone}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:t(`providers.subscription.footer`)}),ot&&(0,$.jsxs)(`div`,{className:`card sticky bottom-3 z-10 mt-3 flex flex-wrap items-center gap-1.5 px-3 py-1.5 shadow-lg`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[12px] text-[var(--text-secondary)]`,children:t(`providers.accounts.selected`,{n:N.size})}),(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(Ct,{className:`size-3.5`}),disabled:I,onClick:()=>void $e(e=>te.mutateAsync({id:e.id,enabled:!0})),children:t(`providers.subscription.enable`)}),(0,$.jsx)(O,{size:`sm`,disabled:I,onClick:()=>void $e(e=>te.mutateAsync({id:e.id,enabled:!1})),children:t(`providers.subscription.disable`)}),(0,$.jsx)(O,{size:`sm`,disabled:I,onClick:()=>void $e(e=>x.mutateAsync(e.id)),children:t(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(O,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:I,onClick:()=>void et(),children:t(`common.delete`)}),(0,$.jsx)(O,{size:`sm`,variant:`plain`,onClick:()=>de(new Set),children:t(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(Bn,{provider:e})}),(0,$.jsx)(zn,{provider:e,account:at,usage:u.data?.accounts.find(e=>e.accountId===at?.id),usageTimeZone:u.data?.timeZone,index:at?B.indexOf(at):0,actions:W,onClose:()=>fe(null)}),Y&&(0,$.jsx)(En,{providerId:e.id,info:Y,mode:pe,providerProxy:e.httpProxy,onClose:()=>me(null)}),(0,$.jsx)(G,{open:ve,onOpenChange:xe,title:t(`providers.accounts.loginProxyTitle`),description:t(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(O,{variant:`primary`,loading:v.isPending,disabled:Se.trim().length===0,onClick:()=>ze(void 0,Se),children:t(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(S,{mono:!0,label:t(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:Se,onChange:e=>Ce(e.target.value)})}),(0,$.jsxs)(G,{open:R,onOpenChange:e=>{Ee(e),e||(De(null),ke(null))},title:t(`providers.subscription.login`),description:t(`providers.subscription.loginDesc`),children:[Oe&&(0,$.jsx)(j,{tone:`danger`,title:t(`providers.subscription.loginFailed`),children:Oe}),z?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(j,{tone:`info`,title:t(`providers.subscription.pasteTitle`),children:t(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(O,{onClick:()=>window.open(z.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(S,{mono:!0,value:Ne,onChange:e=>Pe(e.target.value),placeholder:t(`providers.subscription.pastePlaceholder`),"aria-label":t(`providers.subscription.pasteCode`)}),(0,$.jsx)(O,{variant:`primary`,loading:Ae,onClick:()=>void Ve(),children:t(`providers.subscription.pasteSubmit`)})]}),z?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(j,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(O,{onClick:()=>window.open(z.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)}),(0,$.jsx)(O,{variant:`primary`,onClick:()=>{a.invalidateQueries({queryKey:l.providerAccounts(e.id)}),c.refetch()},children:t(`providers.subscription.doneAuthorize`)})]})]}),z?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(j,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.cliDetail`)}),(0,$.jsx)(O,{onClick:()=>window.open(z.authorizeUrl,`_blank`,`noopener`),children:t(`providers.subscription.openAuthorize`)})]}),z?.mode===`device`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-[11px] text-[var(--text-secondary)]`,children:t(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:z.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[z.verificationUrl&&(0,$.jsx)(O,{onClick:()=>window.open(z.verificationUrl??void 0,`_blank`,`noopener`),children:t(`providers.subscription.visitPage`)}),(0,$.jsx)(O,{variant:`primary`,loading:Ae,onClick:()=>void Be(),children:t(`providers.subscription.checkNow`)})]}),(0,$.jsx)(j,{tone:`info`,title:t(`providers.subscription.waiting`),children:t(`providers.subscription.checkNowHint`)})]})]})]})}var Wn=[`manual`,`failover`,`balanced`,`smart`,`pace`,`usage`];function Gn(e){return`providers.subscription.policy.${e}Detail`}function Kn({policy:e,onChange:t}){let{t:n}=U();return(0,$.jsx)(q,{ariaLabel:n(`providers.subscription.policy.switchMode`),value:e.switchMode,onChange:t,options:Wn.map(e=>({value:e,label:n(`providers.subscription.policy.${e}`)}))})}function qn(e){let t=e.settings?.plugin??null;return t?.v2&&t.plugin&&t.provider?{plugin:t.plugin,provider:t.provider,signIn:t.signIn}:null}function Jn({provider:e,account:t,label:n}){let{t:r}=U(),i=Gt(),a=_e(),[o,s]=(0,Q.useState)(!1),c=qn(e),u=c?.signIn?i?.flows?.find(e=>e.plugin===c.plugin&&e.id===c.signIn):void 0;if(!c||!u)return null;let d=()=>{s(!1),a.invalidateQueries({queryKey:l.providerAccounts(e.id)})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{variant:`primary`,icon:(0,$.jsx)(yt,{className:`size-3.5`}),onClick:()=>s(!0),children:n??r(`pluginUi.flow.signIn`)}),(0,$.jsx)(G,{open:o,onOpenChange:e=>e?s(!0):d(),title:u.title,width:520,children:o&&(0,$.jsx)(Ft,{target:{plugin:u.plugin,view:u.view,params:{flow:u.id,provider:c.provider,...t?{account:t}:{}}},surface:`sheet`,onClose:d})})]})}function Yn({provider:e}){let{t}=U(),n=He(e.id),i=Le(e.id),a=qn(e),o=s(e.id,!a),c=r(e.id,!0),l=p(e.id),{toast:u}=J(),[d,f]=(0,Q.useState)(null);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a&&(0,$.jsx)(Jn,{provider:e}),o.isLoading&&(0,$.jsx)(M,{lines:1}),o.isError&&(0,$.jsx)(j,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:K(o.error)}),o.data?.map(e=>(0,$.jsx)(O,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(_t,{className:`size-3.5`}):(0,$.jsx)(yt,{className:`size-3.5`}),onClick:()=>f(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(M,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(D,{icon:(0,$.jsx)(St,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&c.data&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-1`,children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:t(Gn(c.data.switchMode))}),(0,$.jsx)(Kn,{policy:c.data,onChange:e=>l.mutate({switchMode:e},{onError:e=>u(K(e),`error`)})})]}),n.data&&n.data.length>0&&(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:n.data.map(t=>(0,$.jsx)(Zn,{provider:e,account:t,gatewayUsage:i.data?.accounts.find(e=>e.accountId===t.id)},t.id))}),i.isError&&(0,$.jsx)(j,{tone:`danger`,title:t(`providers.usage.error`),children:K(i.error)}),n.data&&n.data.length>0&&(0,$.jsx)(sn,{timeZone:i.data?.timeZone}),(0,$.jsx)(Xn,{provider:e}),d&&(0,$.jsx)(Qn,{provider:e,method:d,onClose:()=>f(null)})]})}function Xn({provider:e}){let{t,locale:n}=U(),{toast:r}=J(),i=y(e.id),a=C(e.id);if(!i.data?.supported)return null;let o=e=>a.mutate(e,{onError:e=>r(K(e),`error`)}),s={claimed:`green`,done:`green`,ineligible:`neutral`,inactive:`neutral`,captcha:`orange`,failed:`red`};return(0,$.jsxs)(`section`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`pluginAccounts.checkin`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`pluginAccounts.checkinDetail`)})]}),(0,$.jsx)(P,{checked:i.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>o(e)}),(0,$.jsx)(O,{size:`sm`,loading:a.isPending,onClick:()=>o(),children:t(`pluginAccounts.checkinNow`)})]}),i.data.accounts.map(e=>{let r=[e.credit?t(`pluginAccounts.credit`,{credit:e.credit}):null,e.streak?t(`pluginAccounts.streak`,{days:e.streak}):null,e.message,e.at?H(e.at,n):null].filter(Boolean);return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px]`,children:e.account}),r.length>0&&(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-[var(--text-secondary)]`,children:r.join(` · `)}),e.outcome?(0,$.jsx)(u,{tone:s[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(u,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function Zn({provider:e,account:t,gatewayUsage:n}){let{t:r,locale:i}=U(),{toast:a,confirm:o}=J(),s=pe(e.id),[c,l]=(0,Q.useState)(!1),d=e.settings?.plugin?.usage===!0,f=T(e.id,t.id,c),p=async()=>{await o({title:r(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:r(`pluginAccounts.signOut`),destructive:!0})&&s.mutate(t.id,{onError:e=>a(K(e),`error`)})};return(0,$.jsxs)(`article`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-medium`,children:t.displayName}),t.isCurrent&&(0,$.jsx)(u,{tone:`accent`,children:r(`pluginAccounts.current`)}),(0,$.jsx)(u,{tone:t.status===`active`?`green`:`red`,children:r(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),d&&(0,$.jsx)(O,{size:`sm`,onClick:()=>l(e=>!e),children:r(`pluginAccounts.usage`)}),(0,$.jsx)(O,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(bt,{className:`size-3.5`}),onClick:()=>void p(),children:r(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:r(`pluginAccounts.lapsedDetail`)}),(0,$.jsx)(on,{usage:n}),c&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[f.isLoading&&(0,$.jsx)(M,{lines:2}),f.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:K(f.error)}),f.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:f.data.error}),f.data?.plan&&(0,$.jsx)(E,{label:r(`pluginAccounts.plan`),children:f.data.plan}),f.data?.until&&(0,$.jsx)(E,{label:r(`pluginAccounts.until`),children:H(f.data.until,i)}),f.data?.windows?.map(e=>(0,$.jsxs)(E,{label:e.name,children:[e.display??(e.limit?`${e.amount??e.used??0} / ${e.limit} ${e.unit??``}`:`${e.used??0}%`),e.resetsAt?` · ${r(`pluginAccounts.resets`,{at:H(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function Qn({provider:e,method:t,onClose:n}){let{t:r}=U(),{toast:i}=J(),[a,o]=(0,Q.useState)({}),[s,c]=(0,Q.useState)(void 0),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),b=h(e.id),x=oe(e.id),C=Pe(e.id),w=N(e.id,v).data;(0,Q.useEffect)(()=>{let n=!0;return qe(e.id,t.index,a).then(e=>{n&&(c(e.prompt),u(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>n&&i(K(e),`error`)),()=>{n=!1}},[e.id,t.index,a,i]),(0,Q.useEffect)(()=>{w?.state===`done`&&(i(r(`pluginAccounts.signedIn`),`success`),n())},[w?.state,n,r,i]);let T=async()=>{if(!s)return;let n=await ue(e.id,t.index,s.key,l).catch(()=>({error:null}));if(n.error)return f(n.error);f(null),o(e=>({...e,[s.key]:l}))};return(0,$.jsxs)(G,{open:!0,onOpenChange:e=>!e&&n(),title:r(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[s===void 0&&(0,$.jsx)(M,{lines:2}),s&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:s.message,error:d??void 0,children:s.type===`select`?(0,$.jsx)(q,{value:l,onChange:u,options:(s.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(S,{value:l,placeholder:s.placeholder??void 0,onChange:e=>u(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(O,{variant:`primary`,onClick:()=>void T(),children:r(`pluginAccounts.continue`)})})]}),s===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(k,{label:r(`pluginAccounts.key`),children:(0,$.jsx)(S,{mono:!0,type:`password`,value:p,placeholder:t.placeholder??void 0,onChange:e=>m(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(O,{variant:`primary`,disabled:!p.trim()||x.isPending,onClick:()=>x.mutate({method:t.index,inputs:a,key:p},{onSuccess:()=>(i(r(`pluginAccounts.signedIn`),`success`),n()),onError:e=>i(K(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),s===null&&t.type!==`api`&&!w&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(O,{variant:`primary`,icon:(0,$.jsx)(ft,{className:`size-3.5`}),disabled:b.isPending,onClick:()=>b.mutate({method:t.index,inputs:a},{onSuccess:e=>{y(e.id),e.url&&!e.opened&&window.open(e.url,`_blank`,`noopener`)},onError:e=>i(K(e),`error`)}),children:r(`pluginAccounts.openPage`)})}),w&&w.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[w.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:w.instructions}),w.deviceCode&&(0,$.jsx)(E,{label:r(`pluginAccounts.deviceCode`),mono:!0,children:w.deviceCode}),w.url&&(0,$.jsx)(O,{icon:(0,$.jsx)(ft,{className:`size-3.5`}),onClick:()=>window.open(w.url,`_blank`,`noopener`),children:r(`pluginAccounts.openAgain`)}),w.state===`waiting`&&w.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{label:r(`pluginAccounts.code`),children:(0,$.jsx)(S,{mono:!0,value:g,onChange:e=>_(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(O,{variant:`primary`,disabled:!g.trim()||C.isPending,onClick:()=>C.mutate({flow:w.id,code:g.trim()},{onError:e=>i(K(e),`error`)}),children:r(`pluginAccounts.signIn`)})})]}),w.state===`waiting`&&!w.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`pluginAccounts.waiting`)}),w.state===`failed`&&(0,$.jsx)(j,{tone:`danger`,title:r(`pluginAccounts.failed`),children:w.error})]})]})}function $n(e,t=Date.now()){return e.enabled?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?/^40[13] /.test(e.lastError??``)?`authFailed`:`cooling`:`ok`:`off`}var er={ok:`green`,off:`neutral`,authFailed:`red`,cooling:`orange`},tr={"openai-chat":`Chat`,"openai-responses":`Responses`,anthropic:`Anthropic`,gemini:`Gemini`};function nr({provider:e}){let{t}=U(),{toast:n,confirm:i}=J(),a=e.settings.key_pool===!0,o=we(e.id,a),s=Le(e.id,a),c=r(e.id,a),l=p(e.id),u=re(e.id),d=Ke(e.id),m=f(e.id),h=Fe(e.id),[g,v]=(0,Q.useState)(null),y=o.data??[],b=e=>n(K(e),`error`),x=(e,t)=>{let n=y.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],m.mutate(n,{onError:b}))},S=async e=>{await i({title:t(`providers.keys.removeConfirm`,{name:e.displayName}),destructive:!0,confirmLabel:t(`common.delete`)})&&d.mutate(e.id,{onError:b})};if(!a)return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{footer:t(`providers.keys.footer`),children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`min-w-0 text-[13px]`,children:t(`providers.keys.addAnother`)}),(0,$.jsx)(O,{icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>v(`new`),children:t(`providers.keys.add`)})]})}),(0,$.jsx)(ir,{provider:e,editing:g,onClose:()=>v(null)})]});let C=e=>s.data?.accounts.find(t=>t.accountId===e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(_,{title:t(`providers.keys.title`),footer:t(`providers.keys.mode${(c.data?.switchMode??`manual`).replace(/^./,e=>e.toUpperCase())}`),children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3`,children:[c.data?(0,$.jsx)(Kn,{policy:c.data,onChange:e=>l.mutate({switchMode:e},{onError:b})}):(0,$.jsx)(`span`,{}),(0,$.jsx)(O,{variant:`primary`,icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>v(`new`),children:t(`providers.keys.add`)})]}),o.isError&&(0,$.jsx)(j,{tone:`danger`,title:t(`providers.keys.error`),children:K(o.error)}),y.map((e,t)=>(0,$.jsx)(rr,{k:e,first:t===0,last:t===y.length-1,usage:C(e.id),manual:c.data?.switchMode===`manual`,onToggle:t=>u.mutate({id:e.id,enabled:t},{onError:b}),onUp:()=>x(t,-1),onDown:()=>x(t,1),onUse:()=>h.mutate(e.id,{onError:b}),onEdit:()=>v(e),onDelete:()=>void S(e)},e.id))]}),(0,$.jsx)(ir,{provider:e,editing:g,onClose:()=>v(null)})]})}function rr({k:e,first:t,last:n,usage:r,manual:i,onToggle:a,onUp:o,onDown:s,onUse:c,onEdit:l,onDelete:d}){let{t:f,locale:p}=U(),m=$n(e),h=e.weight??1,g=m===`off`?f(`providers.keys.state.off`):m===`ok`?f(`providers.keys.state.ok`):f(m===`authFailed`?`providers.keys.state.authFailed`:`providers.keys.state.cooling`,{when:H(e.cooldownUntilUtc,p)});return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(te,{tone:er[m]}),(0,$.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:e.displayName}),e.isCurrent&&i&&(0,$.jsx)(u,{tone:`accent`,children:f(`providers.keys.current`)}),e.protocol&&(0,$.jsx)(u,{children:tr[e.protocol]}),h>1&&(0,$.jsxs)(u,{title:f(`providers.keys.weightHint`),children:[`×`,h]}),e.httpProxy&&(0,$.jsx)(u,{children:f(`providers.keys.proxyBadge`)})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 text-[11px] text-[var(--text-muted)]`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:e.keyMasked??`••••`}),(0,$.jsx)(`span`,{children:g}),e.notes&&(0,$.jsx)(`span`,{className:`truncate`,children:e.notes})]})]}),(0,$.jsxs)(`div`,{className:`w-44 shrink-0 text-[11px] tabular-nums text-[var(--text-secondary)]`,"aria-label":f(`providers.usage.title`),children:[(0,$.jsxs)(`div`,{children:[f(`providers.usage.today`),`: `,I(r?.today.requests??0,!0),` `,f(`providers.usage.requests`),` ·`,` `,I(r?.today.tokens??0,!0),` `,f(`providers.usage.tokens`)]}),(0,$.jsxs)(`div`,{className:`text-[var(--text-muted)]`,children:[f(`providers.usage.total`),`: `,I(r?.total.requests??0,!0),` · `,B(xe(r?.total.costNanoUsd??0),{compact:!0})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i&&!e.isCurrent&&(0,$.jsx)(O,{size:`sm`,icon:(0,$.jsx)(_t,{className:`size-3.5`}),onClick:c,children:f(`providers.keys.use`)}),(0,$.jsx)(O,{size:`sm`,"aria-label":f(`providers.keys.moveUp`),icon:(0,$.jsx)(ct,{className:`size-3.5`}),disabled:t,onClick:o}),(0,$.jsx)(O,{size:`sm`,"aria-label":f(`providers.keys.moveDown`),icon:(0,$.jsx)(it,{className:`size-3.5`}),disabled:n,onClick:s}),(0,$.jsx)(O,{size:`sm`,"aria-label":f(`common.edit`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),onClick:l}),(0,$.jsx)(O,{size:`sm`,variant:`destructive`,"aria-label":f(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),onClick:d}),(0,$.jsx)(P,{checked:e.enabled,onChange:a,label:f(`providers.keys.enabled`)})]})]})}function ir({provider:e,editing:t,onClose:n}){let{t:r}=U();return(0,$.jsx)(G,{open:t!==null,onOpenChange:e=>!e&&n(),title:r(t===`new`?`providers.keys.addTitle`:`providers.keys.editTitle`),children:t!==null&&(0,$.jsx)(ar,{provider:e,editing:t,onClose:n},t===`new`?`new`:t.id)})}function ar({provider:e,editing:t,onClose:n}){let{t:r}=U(),{toast:i}=J(),a=se(e.id),o=re(e.id),s=t===`new`?null:t,[c,l]=(0,Q.useState)(s?.displayName??``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(s?.protocol??``),[m,h]=(0,Q.useState)(s?.weight??1),[g,_]=(0,Q.useState)(s?.httpProxy??``),[v,y]=(0,Q.useState)(s?.notes??``),b=m===null||Number.isInteger(m)&&m>=1&&m<=1e3,C=b&&(s!==null||u.trim().length>0),w=a.isPending||o.isPending,T=e.endpoints.map(e=>e.protocol),ee=()=>{let e={onSuccess:n,onError:e=>i(K(e),`error`)};s===null?a.mutate({key:u.trim(),...c.trim()?{name:c.trim()}:{},...f?{protocol:f}:{},...m&&m>1?{weight:m}:{},...g.trim()?{httpProxy:g.trim()}:{},...v.trim()?{notes:v.trim()}:{}},e):o.mutate({id:s.id,name:c.trim()||s.displayName,...u.trim()?{key:u.trim()}:{},protocol:f,weight:m??1,httpProxy:g.trim(),notes:v.trim()},e)};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(k,{label:r(`providers.keys.name`),children:(0,$.jsx)(S,{value:c,placeholder:r(`providers.keys.namePlaceholder`),onChange:e=>l(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.apiKey`),hint:s?r(`providers.keys.replaceHint`,{mask:s.keyMasked??`••••`}):void 0,children:(0,$.jsx)(S,{type:`password`,autoComplete:`off`,mono:!0,placeholder:s?r(`providers.replaceKey`):`sk-…`,value:u,onChange:e=>d(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.keys.protocol`),hint:r(`providers.keys.protocolHint`),children:(0,$.jsx)(q,{value:f,onChange:p,options:[{value:``,label:r(`providers.keys.protocolAll`)},...T.map(e=>({value:e,label:tr[e]}))]})}),(0,$.jsx)(k,{label:r(`providers.keys.weight`),hint:r(`providers.keys.weightHint`),error:b?void 0:r(`providers.keys.weightInvalid`),children:(0,$.jsx)(A,{value:m,min:1,step:1,onChange:h,className:`w-28`})}),(0,$.jsx)(k,{label:r(`providers.keys.proxy`),hint:r(`providers.keys.proxyHint`),children:(0,$.jsx)(S,{mono:!0,value:g,placeholder:`http://127.0.0.1:7890`,spellCheck:!1,onChange:e=>_(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.keys.notes`),children:(0,$.jsx)(x,{rows:2,value:v,onChange:e=>y(e.target.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(O,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!C,loading:w,onClick:ee,children:r(`common.save`)})]})]})}function or(e){let t=e?.model_map,n={};if(!t||typeof t!=`object`||Array.isArray(t))return n;for(let[e,r]of Object.entries(t))e&&typeof r==`string`&&r&&(n[e]=r);return n}function sr(){let{t:e}=U(),{id:t=``}=Nt(),n=It(),r=Ie(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=z(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(Wt,{title:e(`nav.providers`),leading:(0,$.jsx)(lr,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(j,{tone:`danger`,title:e(`common.error`),children:K(r.error)})});let u=r.data;return(0,$.jsxs)(Wt,{title:u?u.name:``,subtitle:u?[u.templateId,u.priceKey?e(`providers.priceKeyShort`,{key:u.priceKey}):null].filter(Boolean).join(` · `):void 0,leading:(0,$.jsx)(lr,{onClick:()=>n(`/providers`)}),actions:u&&(0,$.jsx)(ur,{p:u}),children:[u?(0,$.jsxs)(Mt,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(Pt,{"aria-label":u.name,children:[(0,$.jsx)(Bt,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)(Bt,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)(Bt,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(jt,{value:`models`,className:`pt-4`,children:(0,$.jsx)(fr,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(jt,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(Yn,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(Un,{provider:u}):(0,$.jsx)(xr,{provider:u})}),(0,$.jsx)(jt,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(Cr,{provider:u})}),(0,$.jsx)(br,{provider:u,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(M,{lines:4,className:`mx-auto mt-6 max-w-[860px]`}),u&&(0,$.jsx)(`div`,{className:`mt-6`,children:(0,$.jsx)(Ht,{name:`provider.detail.tabs`,params:{providerId:u.id}})})]})}var cr=e=>e.subscription?.mimic_claude_code===!0;function lr({onClick:e}){let{t}=U();return(0,$.jsx)(O,{variant:`glass`,icon:(0,$.jsx)(Y,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function ur({p:e}){let t=Lt(`provider.row`,{providerId:e.id}),{t:n}=U(),r=It(),{toast:a,confirm:o}=J(),s=fe(),c=i(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),h=async()=>{let t=e.boundClients.map(e=>Rt[e]?.name??e).join(`, `),i=t?n(`providers.deleteDetailBound`,{clients:t}):n(`providers.deleteDetail`);await o({title:n(`providers.deleteConfirm`,{name:e.name}),detail:i,destructive:!0,confirmLabel:n(`common.delete`)})&&c.mutate(e.id,{onSuccess:()=>{a(n(`providers.deleted`)),r(`/providers`)},onError:e=>{let t=e instanceof F&&e.status===409?e.details?.boundClients??[]:[];a(t.length?n(`providers.deleteBound`,{clients:t.map(e=>Rt[e]?.name??e).join(`, `)}):K(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{icon:(0,$.jsx)(pt,{className:`size-3.5`}),onClick:()=>m(!0),children:n(`providers.test`)}),(0,$.jsx)(Qe,{label:n(`common.more`),icon:(0,$.jsx)(dt,{className:`size-4`}),items:[{id:`dup`,label:n(`providers.duplicate`),icon:(0,$.jsx)(ut,{className:`size-3.5`}),onSelect:()=>s.mutate(e.id,{onSuccess:e=>r(`/providers/${e.id}`),onError:e=>a(K(e),`error`)})},{id:`tpl`,label:n(`providers.templateUpdate`),icon:(0,$.jsx)(Et,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>u(!0)},{id:`switch`,label:n(`providers.templateSwitch`),icon:(0,$.jsx)(at,{className:`size-3.5`}),disabled:!en(e),onSelect:()=>f(!0)},...t,{id:`del`,label:n(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void h()}]}),(0,$.jsx)(dr,{open:l,onOpenChange:u,provider:e}),(0,$.jsx)($t,{open:d,onOpenChange:f,provider:e}),(0,$.jsx)(Xt,{provider:e,open:p,onOpenChange:m})]})}function dr({open:e,onOpenChange:t,provider:n}){let{t:r}=U(),{toast:i}=J(),a=le(n.id,e),o=ee(n.id),s=a.data&&a.data.latestVersion<=a.data.currentVersion;return(0,$.jsxs)(G,{open:e,onOpenChange:t,title:r(`providers.templateUpdate`),description:a.data?r(`providers.templateVersions`,{current:a.data.currentVersion,latest:a.data.latestVersion}):void 0,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!a.data||s,loading:o.isPending,onClick:()=>o.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(K(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(M,{}),a.isError&&(0,$.jsx)(j,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),s&&(0,$.jsx)(j,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!s&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function fr({provider:e,models:t,loading:n,selected:r,onSelect:i}){let{t:a}=U(),{toast:s,confirm:c}=J(),[l,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,v]=(0,Q.useState)(new Set),y=Xe(e.id),b=ie(e.id),x=(t??[]).filter(e=>!l||e.modelId.toLowerCase().includes(l.toLowerCase())||e.effective.displayName.toLowerCase().includes(l.toLowerCase())),S=x.filter(e=>g.has(e.id)),C=x.length>0&&S.length===x.length,w=e=>v(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),T=async()=>{if(!await c({title:a(`providers.removeSelectedConfirm`,{n:S.length}),destructive:!0,confirmLabel:a(`common.delete`)}))return;let e=S.map(e=>e.id);b.mutate(e,{onSuccess:()=>{v(new Set),r!==null&&e.includes(r)&&i(null)},onError:e=>s(K(e),`error`)})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[x.length>0&&(0,$.jsx)(rn,{"aria-label":a(`providers.selectAllModels`),checked:C,onCheckedChange:()=>v(C?new Set:new Set(x.map(e=>e.id)))}),(0,$.jsx)(o,{className:`w-56`,value:l,onChange:d,placeholder:a(`providers.searchModels`)}),S.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:a(`providers.selectedModels`,{n:S.length})}),(0,$.jsx)(O,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:b.isPending,onClick:()=>void T(),children:a(`providers.removeSelected`)})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(O,{icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>h(!0),children:a(`providers.addModels`)}),(0,$.jsx)(O,{variant:`primary`,icon:(0,$.jsx)(lt,{className:`size-3.5`}),onClick:()=>p(!0),children:a(`providers.fetchRemote`)})]})]}),n&&(0,$.jsx)(M,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(D,{title:a(`providers.noModels`),detail:a(`providers.noModelsDetail`)})}),x.length>0&&(0,$.jsx)(_,{footer:a(`providers.modelsFooter`),children:x.map(e=>(0,$.jsxs)(W,{selected:e.id===r,onClick:()=>i(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:L(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(u,{tone:`orange`,children:a(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?V(e.effective.contextWindow):null,Je(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(zt,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rn,{"aria-label":a(`providers.selectModel`,{id:e.modelId}),checked:g.has(e.id),onCheckedChange:()=>w(e.id)})}),(0,$.jsx)(P,{checked:e.enabled,label:a(`common.enabled`),onChange:t=>y.mutate({pmId:e.id,enabled:t},{onError:e=>s(K(e),`error`)})})]},e.id))}),(0,$.jsx)(pr,{provider:e}),(0,$.jsx)(mr,{provider:e}),t&&(0,$.jsx)(hr,{provider:e,models:t}),(0,$.jsx)(_r,{open:m,onOpenChange:h,provider:e}),(0,$.jsx)(vr,{open:f,onOpenChange:p,provider:e})]})}function pr({provider:e}){let{t}=U(),{toast:n}=J(),r=ve(e.id),i=typeof e.settings.alias==`string`?e.settings.alias:``,[a,o]=(0,Q.useState)(i);return(0,Q.useEffect)(()=>o(i),[i]),(0,$.jsx)(_,{title:t(`providers.alias.title`),footer:t(`providers.alias.footer`),children:(0,$.jsxs)(W,{label:t(`providers.alias.label`),detail:t(`providers.alias.hint`),children:[(0,$.jsx)(S,{className:`w-56`,mono:!0,maxLength:64,"aria-label":t(`providers.alias.label`),placeholder:e.name,value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(O,{size:`sm`,disabled:r.isPending||a.trim()===i,onClick:()=>{let i=a.trim(),o={...e.settings};i?o.alias=i:delete o.alias,r.mutate({settings:o},{onSuccess:()=>n(t(`providers.alias.saved`),`success`),onError:e=>n(K(e),`error`)})},children:t(`common.save`)})]})})}function mr({provider:e}){let{t}=U(),{toast:n}=J(),r=ve(e.id),i=e.settings.first_byte_timeout_sec,a=typeof i==`number`&&i>0?String(i):``,[o,s]=(0,Q.useState)(a);return(0,Q.useEffect)(()=>s(a),[a]),(0,$.jsx)(_,{title:t(`providers.timeout.title`),footer:t(`providers.timeout.footer`),children:(0,$.jsxs)(W,{label:t(`providers.timeout.label`),detail:t(`providers.timeout.hint`),children:[(0,$.jsx)(S,{className:`w-28`,mono:!0,inputMode:`numeric`,"aria-label":t(`providers.timeout.label`),placeholder:`—`,value:o,onChange:e=>s(e.target.value.replace(/\D/g,``).slice(0,4))}),(0,$.jsx)(O,{size:`sm`,disabled:r.isPending||o===a,onClick:()=>{let i=Math.min(3600,Math.floor(Number(o))),a={...e.settings};o.trim()&&i>0?a.first_byte_timeout_sec=i:delete a.first_byte_timeout_sec,r.mutate({settings:a},{onSuccess:()=>n(t(`providers.timeout.saved`),`success`),onError:e=>n(K(e),`error`)})},children:t(`common.save`)})]})})}function hr({provider:e,models:t}){let{t:n}=U(),{toast:r}=J(),i=Ve(e.id),[a,o]=(0,Q.useState)(!1),s=or(e.settings),c=Object.entries(s),l=new Set(t.map(e=>e.modelId)),d=(e,t)=>i.mutate(e,{onSuccess:()=>{t?.(),r(n(`providers.modelMap.saved`),`success`)},onError:e=>r(K(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(_,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(W,{label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2 font-mono text-[12.5px]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e}),(0,$.jsx)(st,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:L(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(u,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(kt,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>d(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(W,{icon:(0,$.jsx)(X,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`providers.modelMap.add`),detail:t.length===0?n(`providers.modelMap.needModels`):void 0,onClick:t.length===0?void 0:()=>o(!0)})]}),(0,$.jsx)(gr,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>d({...s,[e]:t},()=>o(!1))})]})}function gr({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=U(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(s(``),l(``))},[e]);let u=o.trim();return(0,$.jsx)(G,{open:e,onOpenChange:t,title:a(`providers.modelMap.add`),description:a(`providers.modelMap.addDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!u||!c||u===c,loading:r,onClick:()=>i(u,c),children:a(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(S,{autoFocus:!0,mono:!0,label:a(`providers.modelMap.from`),placeholder:`deepseek-v4.1`,spellCheck:!1,value:o,onChange:e=>s(e.target.value)}),(0,$.jsx)(q,{label:a(`providers.modelMap.to`),value:c,onChange:l,placeholder:a(`providers.modelMap.toPlaceholder`),options:n.map(e=>({value:e.modelId,label:e.modelId}))})]})})}function _r({open:e,onOpenChange:t,provider:n}){let{t:r}=U(),{toast:i}=J(),a=b(n.id),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&s(``)},[e]);let c=[...new Set(o.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addModels`),description:r(`providers.addModelsDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:c.length===0,loading:a.isPending,onClick:()=>a.mutate(c,{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(K(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(x,{autoFocus:!0,label:r(`providers.modelIds`),rows:6,spellCheck:!1,className:`w-full font-mono text-[12px]`,placeholder:`deepseek-v4-pro
3
+ claude-sonnet-4-6`,value:o,onChange:e=>s(e.target.value)})})}function vr({open:e,onOpenChange:t,provider:n}){let{t:r}=U(),{toast:i}=J(),a=Se(n.id,e),s=b(n.id),[c,l]=(0,Q.useState)(new Set),[d,f]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&l(new Set)},[e]);let p=(a.data??[]).filter(e=>!d||e.id.toLowerCase().includes(d.toLowerCase())),m=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(G,{open:e,onOpenChange:t,width:560,title:r(`providers.fetchRemote`),description:r(`providers.fetchRemoteDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{variant:`plain`,className:`mr-auto`,onClick:()=>l(new Set(p.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:p.length===0,children:r(`common.selectAll`)}),(0,$.jsx)(O,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:c.size===0,loading:s.isPending,onClick:()=>s.mutate([...c],{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(K(e),`error`)}),children:r(`providers.addSelected`,{count:c.size})})]}),children:[(0,$.jsx)(o,{className:`mb-3`,value:d,onChange:f,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(M,{lines:4}),a.isError&&(0,$.jsx)(j,{tone:`danger`,title:r(`common.error`),children:K(a.error)}),a.error instanceof F&&(0,$.jsx)(Kt,{className:`mt-3`,provider:n,httpStatus:a.error.details?.httpStatus}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:p.map(e=>(0,$.jsx)(W,{onClick:e.alreadyAdded?void 0:()=>m(e.id),label:(0,$.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id}),detail:e.linkedSystemModelId?r(`providers.linksTo`,{id:e.linkedSystemModelId}):r(`providers.noLink`),children:e.alreadyAdded?(0,$.jsx)(u,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(rn,{"aria-label":e.id,checked:c.has(e.id),onCheckedChange:()=>m(e.id)})})},e.id))})]})}function yr({origin:e}){let{t}=U();return e===`overridden`?(0,$.jsx)(u,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(u,{children:t(`origin.inherited`)}):(0,$.jsx)(u,{tone:`red`,children:t(`origin.unset`)})}function br({provider:e,pm:t,onClose:r}){let{t:i}=U(),{toast:o}=J(),s=Xe(e.id),c=ne(e.id),l=a(),[d,f]=(0,Q.useState)({}),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(f(t.overrides),m(t.systemModelId??``),g(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:()=>r(),title:i(`providers.tab.models`)});let _={...d,pricing:h?d.pricing??null:null},v=JSON.stringify(_)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||p!==(t.systemModelId??``),y=()=>s.mutate({pmId:t.id,overrides:_,systemModelId:p||null},{onSuccess:()=>{o(i(`common.saved`),`success`),r()},onError:e=>o(K(e),`error`)}),b=(e,n,r)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:n}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(yr,{origin:d[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),d[e]!=null&&(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(wt,{className:`size-3`}),title:i(`origin.reset`),"aria-label":i(`origin.reset`),onClick:()=>f({...d,[e]:null})})]})]}),r]});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&r(),width:720,title:t.modelId,description:e.name,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mr-auto`,children:(0,$.jsx)(an,{label:i(`providers.removeModelShort`),icon:(0,$.jsx)(Z,{className:`size-4`}),prompt:i(`providers.removeModel`,{id:t.modelId}),confirmLabel:i(`common.delete`),cancelLabel:i(`common.cancel`),pendingLabel:i(`common.deleting`),doneLabel:i(`common.deleted`),errorLabel:i(`common.error`),retryLabel:i(`common.retry`),onConfirm:async()=>{await c.mutateAsync(t.id),r()}})}),(0,$.jsx)(O,{onClick:r,children:i(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!v,loading:s.isPending,onClick:y,children:i(`common.save`)})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(zt,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(u,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(n,{title:i(`providers.linkedModel`),children:[(0,$.jsx)(q,{className:`w-full`,ariaLabel:i(`providers.linkedModel`),value:p,onChange:m,options:[{value:``,label:i(`providers.noLink`)},...(l.data??[]).map(e=>({value:e.id,label:e.id,detail:e.displayName}))]}),(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:i(`providers.linkedModelHint`)})]}),(0,$.jsx)(n,{title:i(`providers.overrides`),children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[b(`displayName`,i(`models.field.displayName`),(0,$.jsx)(S,{className:`w-full`,"aria-label":i(`models.field.displayName`),placeholder:t.effective.displayName,value:d.displayName??``,onChange:e=>f({...d,displayName:e.target.value||null})})),b(`contextWindow`,i(`models.field.contextWindow`),(0,$.jsx)(A,{className:`w-full`,label:i(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:d.contextWindow,onChange:e=>f({...d,contextWindow:e})})),b(`maxOutputTokens`,i(`models.field.maxOutputTokens`),(0,$.jsx)(A,{className:`w-full`,label:i(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:d.maxOutputTokens,onChange:e=>f({...d,maxOutputTokens:e})}))]})}),(0,$.jsxs)(n,{title:i(`providers.price`),action:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[i(`providers.customPrice`),(0,$.jsx)(P,{checked:h,label:i(`providers.customPrice`),onChange:e=>{g(e),e&&d.pricing==null&&f({...d,pricing:t.effectivePricing??{currency:`USD`,unit:`per_1m_tokens`,base:{input:null,output:null}}})}})]}),children:[(0,$.jsx)(`p`,{className:`mb-3 text-[11px] text-[var(--text-muted)]`,children:i(h?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),h?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(Vt,{value:d.pricing??null,onChange:e=>f({...d,pricing:e})})}):t.effectivePricing?(0,$.jsx)(Ne,{maxHeight:220,children:Ue(t.effectivePricing)}):(0,$.jsx)(j,{tone:`warning`,title:i(`pricingSource.none`)})]})]})})}function xr({provider:e}){let{t}=U(),{toast:n}=J(),r=ve(e.id),i=Le(e.id),[a,o]=(0,Q.useState)(``),s=Yt(e.authScheme)?e.authScheme:null,[c,l]=(0,Q.useState)(0),u=e.settings.vertex,[d,f]=(0,Q.useState)({project:u?.project??``,location:u?.location??`global`}),p=s===`gcp-service-account`&&(d.project.trim()!==(u?.project??``)||d.location!==(u?.location??`global`)),m=()=>r.mutate({...a.trim()?{apiKey:a}:{},...s===`gcp-service-account`?{settings:{...e.settings,vertex:{project:d.project.trim(),location:d.location}}}:{}},{onSuccess:()=>{o(``),l(e=>e+1),n(t(`common.saved`),`success`)},onError:e=>n(K(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[e.settings.key_pool!==!0&&(0,$.jsx)(_,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{label:t(s===`aws-sigv4`?`providers.cloud.aws.key`:`providers.cloud.gcp.keyFile`),detail:e.hasApiKey?e.apiKeyMasked??`••••`:t(`providers.noKey`)}),(0,$.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[s===`aws-sigv4`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(qt,{onChange:o},c),(0,$.jsx)(Zt,{endpoints:e.endpoints})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nn,{onChange:o},c),(0,$.jsx)(Jt,{project:d.project,location:d.location,onChange:f})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(O,{variant:`primary`,disabled:a.trim().length===0&&!p,loading:r.isPending,onClick:m,children:t(`common.save`)})})]})]}):(0,$.jsx)(W,{label:t(`providers.apiKey`),detail:e.hasApiKey?e.apiKeyMasked??`••••`:t(`providers.noKey`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(S,{type:`password`,autoComplete:`off`,className:`w-64 font-mono`,"aria-label":t(`providers.apiKey`),placeholder:t(`providers.replaceKey`),value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(O,{variant:`primary`,disabled:a.trim().length===0,loading:r.isPending,onClick:m,children:t(`common.save`)})]})})}),!s&&e.authScheme!==`none`&&(0,$.jsx)(nr,{provider:e}),(0,$.jsxs)(`section`,{className:`card my-4 flex flex-col gap-2 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-[13px] font-medium`,children:t(`providers.usage.title`)}),i.isError&&(0,$.jsx)(j,{tone:`danger`,title:t(`providers.usage.error`),children:K(i.error)}),(0,$.jsx)(on,{usage:i.data?.accounts.find(e=>!e.accountId)}),(0,$.jsx)(sn,{timeZone:i.data?.timeZone})]}),(0,$.jsx)(gn,{provider:e})]})}function Sr(e){return{name:e.name,apiKey:``,endpoints:e.endpoints,preferredUpstreamProtocols:e.preferredUpstreamProtocols,authScheme:e.authScheme,extraHeaders:e.extraHeaders,httpProxy:e.httpProxy??null,priceMultiplier:e.priceMultiplier,priceKey:e.priceKey??null,settings:e.settings,enabled:e.enabled,notes:e.notes??null}}function Cr({provider:e}){let{t}=U(),{toast:n}=J(),r=ve(e.id),i=Be(),a=(0,Q.useMemo)(()=>Sr(e),[e]),[o,s]=(0,Q.useState)(a),[c,l]=(0,Q.useState)(Object.entries(e.extraHeaders)),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{s(a),l(Object.entries(a.extraHeaders))},[a]);let m=e=>s(t=>({...t,...e})),h={...o,extraHeaders:Object.fromEntries(c.filter(([e])=>e.trim()))},g=JSON.stringify(h)!==JSON.stringify(a),v=()=>{let e={};for(let t of Object.keys(h))t!==`apiKey`&&JSON.stringify(h[t])!==JSON.stringify(a[t])&&(e[t]=h[t]);o.apiKey&&(e.apiKey=o.apiKey),r.mutate(e,{onSuccess:()=>n(t(`common.saved`),`success`),onError:e=>n(K(e),`error`)})},y=(e,t)=>m({endpoints:o.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(_,{title:t(`providers.section.basic`),children:[(0,$.jsx)(W,{label:t(`providers.name`),children:(0,$.jsx)(S,{className:`w-64`,"aria-label":t(`providers.name`),value:o.name,onChange:e=>m({name:e.target.value})})}),(0,$.jsx)(W,{label:t(`common.enabled`),children:(0,$.jsx)(P,{checked:o.enabled,label:t(`common.enabled`),onChange:e=>m({enabled:e})})}),(0,$.jsx)(W,{label:t(`providers.notes`),children:(0,$.jsx)(S,{className:`w-64`,"aria-label":t(`providers.notes`),value:o.notes??``,onChange:e=>m({notes:e.target.value||null})})})]}),(0,$.jsx)(_,{title:t(`providers.section.auth`),children:(0,$.jsx)(W,{label:t(`providers.authScheme`),children:(0,$.jsx)(q,{className:`w-48`,value:o.authScheme,onChange:e=>m({authScheme:e}),options:tn})})}),(0,$.jsxs)(_,{title:t(`providers.section.endpoints`),footer:t(`providers.endpointsFooter`),children:[o.endpoints.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-3`,children:[(0,$.jsx)(q,{className:`w-48`,value:e.protocol,onChange:e=>y(n,{protocol:e}),options:Qt}),(0,$.jsx)(S,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.baseUrl`),value:e.baseUrl,onChange:e=>y(n,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(P,{checked:!!e.fullUrl,label:t(`providers.fullUrl`),onChange:e=>y(n,{fullUrl:e})}),t(`providers.fullUrl`)]}),(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>m({endpoints:o.endpoints.filter((e,t)=>t!==n)})})]},n)),(0,$.jsx)(`div`,{className:`px-4 py-2`,children:(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>d(!0),children:t(`providers.addEndpoint`)})}),(0,$.jsx)(W,{label:t(`providers.preferred`),detail:(0,$.jsxs)($.Fragment,{children:[t(`providers.preferredHint`),o.preferredUpstreamProtocols.filter(e=>!o.endpoints.some(t=>t.protocol===e)).map(e=>(0,$.jsx)(`span`,{className:`mt-1 block text-[var(--warning)]`,children:t(`providers.preferredMissing`,{protocol:Qt.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(Ut,{label:t(`providers.preferred`),options:Qt.map(e=>{let t=o.preferredUpstreamProtocols.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:o.preferredUpstreamProtocols,onValueChange:e=>{let t=o.preferredUpstreamProtocols.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));m({preferredUpstreamProtocols:[...t,...n]})}})})]}),(0,$.jsxs)(_,{title:t(`providers.section.billing`),footer:t(`providers.billingFooter`),children:[(0,$.jsx)(W,{label:t(`providers.priceKey`),detail:t(`providers.priceKeyHint`),children:(0,$.jsx)(q,{className:`w-56`,value:o.priceKey==null?`inherit`:`price:${o.priceKey}`,onChange:e=>m({priceKey:e===`inherit`?null:e.slice(6)}),options:[{value:`inherit`,label:t(`providers.priceKeyDefault`,{id:e.templateId??`—`})},{value:`price:`,label:t(`providers.priceKeyNone`)},...(i.data??[]).map(e=>({value:`price:${e.priceKey}`,label:e.label,detail:e.priceKey}))]})}),(0,$.jsx)(W,{label:t(`providers.multiplier`),detail:t(`providers.multiplierHint`),children:(0,$.jsx)(A,{className:`w-28`,label:t(`providers.multiplier`),step:.01,min:0,value:o.priceMultiplier,onChange:e=>m({priceMultiplier:e??1})})})]}),(0,$.jsxs)(_,{title:t(`providers.section.advanced`),children:[o.authScheme!==`oauth-subscription`&&o.authScheme!==`plugin`&&o.endpoints.some(e=>e.protocol===`anthropic`)&&(0,$.jsx)(W,{label:t(`providers.mimicClaudeCode`),detail:t(`providers.mimicClaudeCode.hint`),children:(0,$.jsx)(P,{checked:cr(o.settings),label:t(`providers.mimicClaudeCode`),onChange:e=>m({settings:{...o.settings,subscription:{...o.settings.subscription,mimic_claude_code:e}}})})}),(0,$.jsx)(W,{label:t(`providers.proxy`),detail:t(`providers.proxyHint`),children:(0,$.jsx)(S,{className:`w-64 font-mono`,"aria-label":t(`providers.proxy`),placeholder:`http://127.0.0.1:7890`,value:o.httpProxy??``,onChange:e=>m({httpProxy:e.target.value||null})})}),(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-[13px]`,children:t(`providers.headers`)}),c.map(([e,n],r)=>(0,$.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,$.jsx)(S,{className:`w-48 font-mono`,"aria-label":t(`providers.headerName`),placeholder:`Header`,value:e,onChange:e=>l(c.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,$.jsx)(S,{className:`flex-1 font-mono`,"aria-label":t(`providers.headerValue`),placeholder:`value`,value:n,onChange:e=>l(c.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),"aria-label":t(`common.delete`),onClick:()=>l(c.filter((e,t)=>t!==r))})]},r)),(0,$.jsx)(O,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(X,{className:`size-3.5`}),onClick:()=>p(!0),children:t(`providers.addHeader`)})]}),Object.keys(e.settings).length>0&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(x,{label:t(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:Ue(o.settings),onBlur:e=>{try{m({settings:JSON.parse(e.target.value)})}catch{n(t(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(_,{title:t(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(E,{label:`ID`,children:e.id}),e.adapterId&&(0,$.jsx)(E,{label:t(`providers.adapter`),children:e.adapterId}),(0,$.jsx)(E,{label:t(`providers.boundClients`),children:e.boundClients.map(e=>Rt[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(wr,{open:u,onOpenChange:d,onAdd:e=>m({endpoints:[...o.endpoints,e]})}),(0,$.jsx)(Tr,{open:f,onOpenChange:p,onAdd:e=>l([...c.filter(([t])=>t.toLowerCase()!==e[0].toLowerCase()),e])}),(0,$.jsx)(`div`,{className:`sticky bottom-2 flex justify-end`,children:g&&(0,$.jsxs)(`div`,{className:`glass flex items-center gap-2 rounded-full p-1 pl-4 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:t(`common.unsaved`)}),(0,$.jsx)(O,{size:`sm`,onClick:()=>{s(a),l(Object.entries(a.extraHeaders))},children:t(`common.revert`)}),(0,$.jsx)(O,{size:`sm`,variant:`primary`,loading:r.isPending,onClick:v,children:t(`common.save`)})]})})]})}function wr({open:e,onOpenChange:t,onAdd:n}){let{t:r}=U(),[i,a]=(0,Q.useState)(`openai-chat`),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(s(``),l(!1))},[e]);let u=/^https?:\/\/\S+$/.test(o.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addEndpoint`),description:r(`providers.addEndpointDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!u,onClick:()=>{n({protocol:i,baseUrl:o.trim(),...c?{fullUrl:!0}:{}}),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(k,{label:r(`providers.protocol`),children:(0,$.jsx)(q,{value:i,onChange:a,options:Qt})}),(0,$.jsx)(k,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(S,{autoFocus:!0,className:`font-mono`,placeholder:`https://api.example.com/v1`,value:o,invalid:o!==``&&!u,onChange:e=>s(e.target.value)})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(P,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function Tr({open:e,onOpenChange:t,onAdd:n}){let{t:r}=U(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&(a(``),s(``))},[e]);let c=/^[A-Za-z0-9-]+$/.test(i.trim());return(0,$.jsx)(G,{open:e,onOpenChange:t,title:r(`providers.addHeader`),description:r(`providers.addHeaderDetail`),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(O,{variant:`primary`,disabled:!c,onClick:()=>{n([i.trim(),o]),t(!1)},children:r(`common.add`)})]}),children:(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(k,{label:r(`providers.headerName`),children:(0,$.jsx)(S,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(k,{label:r(`providers.headerValue`),children:(0,$.jsx)(S,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{sr as ProviderDetailPage};
@@ -0,0 +1,3 @@
1
+ import{a as e,o as t,r as n}from"./createLucideIcon-7fjTeqBK.js";import{B as r,D as i,Et as a,Fo as o,G as s,Ga as c,H as l,Hi as u,I as d,Jn as f,M as p,N as m,Na as h,O as g,P as _,Qs as v,R as y,S as b,U as x,Vo as S,W as C,Wo as w,Y as T,Z as E,Zs as D,_n as O,_o as k,as as A,c as j,cs as M,d as N,dr as ee,dt as P,ei as te,er as F,fi as I,hi as ne,j as L,lr as re,m as R,o as z,os as B,pi as V,qa as ie,ra as H,ss as ae,ti as oe,ur as se,us as ce,w as U,za as le}from"./format-CmXxTS5M.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-DN10ruw2.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-BW8keTkg.js";import{t as He}from"./radio-cards-BTn8kpAx.js";import{t as Ue}from"./checkbox-CZ-rG7I2.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=v(),We=e=>`blur(${e}px)`,Q={duration:0},Ge={duration:E.duration.fast,ease:[...E.ease.standard]},Ke={duration:E.duration.standard,ease:[...E.ease.enter]},qe={opacity:0,y:`0.3em`,filter:We(E.blur.soft)},Je={opacity:1,y:0,filter:We(0)},Ye={opacity:0,y:`-0.3em`,filter:We(E.blur.subtle)},Xe={opacity:0,scale:.5,filter:We(E.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=M(`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}B(a,t,E.spring.smooth)});return s.observe(e),()=>s.disconnect()},[a,n]),(0,Z.jsx)(A.span,{className:Y.slot,style:{height:a},children:(0,Z.jsx)(`span`,{ref:r,className:Y.slotInner,children:(0,Z.jsx)(ce,{mode:`popLayout`,initial:!1,children:e?(0,Z.jsx)(A.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:{...E.spring.snappy,delay:n},opacity:{duration:E.duration.fast,delay:n},filter:{duration:E.duration.fast,delay:n}},a={...Xe,transition:r?Q:Ge},o=r?Q:{duration:E.duration.standard,ease:E.ease.enter,delay:n+.04};return e===`number`?(0,Z.jsx)(A.span,{className:Y.glyph,initial:Xe,animate:Ze,exit:a,transition:i,children:t}):(0,Z.jsx)(A.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)(A.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)(A.path,{d:`M12 6.75v6.5`,initial:{pathLength:0},animate:{pathLength:1},transition:o}),(0,Z.jsx)(A.circle,{cx:12,cy:17.4,r:1.4,fill:`currentColor`,stroke:`none`,initial:{scale:0},animate:{scale:1},transition:r?Q:{...E.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)(ce,{initial:!1,children:n?(0,Z.jsx)(A.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:{...E.spring.snappy,delay:i},opacity:{duration:E.duration.fast,delay:i}}},`ring`):null}),(0,Z.jsx)(`span`,{className:Y.disc,children:(0,Z.jsx)(ce,{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=ae()??!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=E.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)(A.span,{className:Y.fill,initial:!1,animate:y?{scaleY:+(t<d)}:{scaleX:+(t<d)},transition:l?Q:{...E.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)(_,{label:t(`providers.cloud.aws.accessKeyId`),children:(0,Z.jsx)(d,{mono:!0,autoComplete:`off`,spellCheck:!1,placeholder:`AKIA…`,value:n,onChange:e=>r(e.target.value)})}),(0,Z.jsx)(_,{label:t(`providers.cloud.aws.secretAccessKey`),hint:t(`providers.apiKeyHint`),children:(0,Z.jsx)(d,{mono:!0,type:`password`,autoComplete:`off`,value:i,onChange:e=>a(e.target.value)})}),(0,Z.jsx)(_,{label:t(`providers.cloud.aws.sessionToken`),hint:t(`providers.cloud.aws.sessionTokenHint`),children:(0,Z.jsx)(d,{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)(_,{label:i(`providers.cloud.gcp.project`),hint:i(`providers.cloud.gcp.projectHint`),children:(0,Z.jsx)(d,{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)(_,{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 c=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)(_,{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)(s,{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 c(e.target.files?.[0])}),(0,Z.jsxs)(g,{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:i}=q(),a=ee(e),o=se(),[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]),_=(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)(g,{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)(g,{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 r=e.skipped.length;i(r>0?n(`import.doneSkipped`,{count:e.added.length,skipped:r}):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)(r,{value:s,onChange:c,placeholder:n(`import.search`)}),d&&(0,Z.jsx)(b,{tone:`danger`,title:n(`common.error`),children:d}),a.isLoading&&(0,Z.jsx)(x,{lines:3}),a.isError&&(0,Z.jsx)(b,{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:_,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)(b,{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(),a=ht(e),o=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:P(`flex items-start gap-3 px-4 py-3`,!a&&`opacity-60`),children:[(0,Z.jsx)(Ue,{checked:t&&a,disabled:!a,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)(i,{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})})]}),o&&(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-[var(--text-secondary,var(--text-muted))]`,children:o}),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=S(),i=H(),a=F(),s=c(),l=o(),f=u(),[p,m]=(0,X.useState)(``),[h,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(``),[x,C]=(0,X.useState)(`astra`),[w,T]=(0,X.useState)(`none`),[E,D]=(0,X.useState)(``),[O,k]=(0,X.useState)(null);(0,X.useEffect)(()=>{r.data&&(m(r.data.url),_(r.data.username),C(r.data.folder))},[r.data]);let A=e=>k(G(e)),j=r.data?.configured===!0,M=i.isPending||s.isPending||l.isPending||f.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)(d,{"aria-label":t(`backup.webdav.url`),placeholder:`https://dav.example.com/remote.php/dav/files/me`,mono:!0,value:p,onChange:e=>m(e.target.value)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(d,{"aria-label":t(`backup.webdav.username`),placeholder:t(`backup.webdav.username`),autoComplete:`off`,value:h,onChange:e=>_(e.target.value)}),(0,Z.jsx)(d,{type:`password`,autoComplete:`new-password`,"aria-label":t(`backup.webdav.password`),placeholder:r.data?.hasPassword?t(`backup.webdav.passwordKept`):t(`backup.webdav.password`),value:v,onChange:e=>y(e.target.value)})]}),(0,Z.jsx)(d,{"aria-label":t(`backup.webdav.folder`),placeholder:t(`backup.webdav.folder`),mono:!0,value:x,onChange:e=>C(e.target.value)}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(g,{variant:`primary`,disabled:M||p.trim().length===0,onClick:()=>{k(null),i.mutate({url:p,username:h,folder:x,password:v||void 0},{onSuccess:()=>{y(``),n(t(`backup.webdav.saved`))},onError:A})},children:t(`backup.webdav.save`)}),(0,Z.jsx)(g,{disabled:M||!j,onClick:()=>{k(null),s.mutate(void 0,{onSuccess:()=>n(t(`backup.webdav.testOk`)),onError:A})},children:t(`backup.webdav.test`)}),j&&(0,Z.jsx)(g,{disabled:M,onClick:()=>{k(null),a.mutate(void 0,{onSuccess:()=>{m(``),_(``),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:w,onChange:e=>T(e),options:[{value:`none`,label:t(`backup.secrets.none`)},{value:`passphrase`,label:t(`backup.secrets.passphrase`)}]})]}),w===`passphrase`&&(0,Z.jsx)(d,{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)(g,{variant:`primary`,icon:(0,Z.jsx)(be,{className:`size-3.5`}),disabled:M||w===`passphrase`&&E.length<8,onClick:()=>{k(null),l.mutate({secrets:w,passphrase:w===`passphrase`?E:void 0},{onSuccess:e=>n(t(`backup.webdav.uploadDone`,{count:e.uploaded})),onError:A})},children:t(`backup.webdav.upload`)}),(0,Z.jsx)(g,{icon:(0,Z.jsx)(ye,{className:`size-3.5`}),disabled:M,onClick:()=>{k(null),f.mutate(void 0,{onSuccess:e,onError:A})},children:t(`backup.webdav.restore`)})]})]}),O&&(0,Z.jsx)(b,{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=f(),a=te(),o=re(),s=(0,X.useRef)(null),[c,l]=(0,X.useState)(`none`),[u,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(new Set),[E,D]=(0,X.useState)(null),O=()=>{h(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})),p(``)},onError:e=>h(G(e))})},k=(e,t)=>{D(null),a.mutate({file:e,passphrase:e.secrets===`passphrase`?t:void 0},{onSuccess:e=>{C(e),T(new Set(e.items.filter(e=>e.status===`new`).map(e=>e.index)))},onError:e=>{C(null),D(G(e))}})},A=e=>{C(null),D(null),v(e),e.secrets!==`passphrase`&&k(e,``)},j=async e=>{if(C(null),v(null),D(null),e)try{let t=JSON.parse(await e.text());if(!wt(t))throw Error(`not a backup`);v(t),t.secrets!==`passphrase`&&k(t,``)}catch{D(n(`backup.import.badFile`))}},M=()=>{_&&(D(null),o.mutate({file:_,passphrase:_.secrets===`passphrase`?y:void 0,indexes:[...w]},{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})),v(null),C(null),x(``),t(!1)},onError:e=>D(G(e))}))},N=(e,t)=>T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),ee=_?.secrets===`passphrase`&&!S,P=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)(d,{type:`password`,autoComplete:`new-password`,"aria-label":n(`backup.passphrase`),placeholder:n(`backup.passphrase`),value:u,onChange:e=>p(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)(b,{tone:`warning`,title:n(`backup.plaintext.warn`)}),m&&(0,Z.jsx)(b,{tone:`danger`,title:n(`common.error`),children:m}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(g,{variant:`primary`,icon:(0,Z.jsx)(Me,{className:`size-3.5`}),disabled:P,onClick:O,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)(g,{icon:(0,Z.jsx)(ke,{className:`size-3.5`}),onClick:()=>s.current?.click(),children:n(`backup.import.choose`)})]}),ee&&(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)(d,{className:`flex-1`,type:`password`,autoComplete:`off`,"aria-label":n(`backup.passphrase`),placeholder:n(`backup.passphrase`),value:y,onChange:e=>x(e.target.value)}),(0,Z.jsx)(g,{disabled:y.length===0||a.isPending,onClick:()=>_&&k(_,y),children:n(`backup.import.preview`)})]})]}),E&&(0,Z.jsx)(b,{tone:`danger`,title:n(`common.error`),children:E}),S&&(0,Z.jsxs)(Z.Fragment,{children:[S.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:S.items.map(e=>(0,Z.jsx)(Et,{item:e,checked:w.has(e.index),onToggle:t=>N(e.index,t)},e.index))}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(g,{variant:`primary`,disabled:w.size===0||o.isPending,onClick:M,children:n(`backup.import.run`,{count:w.size})})})]})]}),(0,Z.jsx)(bt,{onRestored:A})]})})}function Et({item:e,checked:t,onToggle:n}){let{t:r}=U(),a=St(e);return(0,Z.jsxs)(`li`,{className:P(`flex items-start gap-3 px-4 py-3`,!a&&`opacity-60`),children:[(0,Z.jsx)(Ue,{checked:t&&a,disabled:!a,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)(i,{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:P(`flex h-[22px] shrink-0 items-end gap-[2px]`,r),title:e.map((e,n)=>`${t[n]}: ${e}`).join(`
2
+ `),children:e.map((e,t)=>(0,Z.jsx)(`i`,{className:`block w-[6px] rounded-t-[2px]`,style:{height:e>0?`${Math.max(14,Math.sqrt(e/Math.max(1,n))*100)}%`:2,background:e>0?`var(--accent)`:`var(--border)`}},t))})}function Ht(e,t,n,r){let i=e.filter(e=>n(e)>0).sort((e,t)=>n(t)-n(e)),a=i.slice(0,Rt.length).map((e,r)=>({key:e.providerId,name:t.get(e.providerId)??e.name??e.providerId,value:n(e),color:Rt[r]})),o=i.slice(Rt.length).reduce((e,t)=>e+n(t),0);return o>0?[...a,{key:`__other`,name:r,value:o,color:zt}]:a}var Ut=[`today`,`7d`,`30d`];function Wt({providers:e,stats:t,stats7d:n,range:r,chartsOpen:i}){let{t:a}=U(),o=new Map(e.map(e=>[e.id,e.name])),s=t.reduce((e,t)=>e+t.requests,0),c=t.reduce((e,t)=>e+t.successRequests,0),l=t.reduce((e,t)=>e+t.costUsd,0),u=t.reduce((e,t)=>e+t.failoversOut,0),d=e.filter(e=>e.enabled).length,f=t.filter(e=>e.requests>0&&o.has(e.providerId)).length,p=Ht(t,o,e=>e.requests,a(`providers.overview.others`)),m=Ht(t,o,e=>e.costUsd,a(`providers.overview.others`)),h=p.filter(e=>e.key!==`__other`),g={healthy:0,noKey:0,lowSuccess:0,disabled:0};for(let t of e)g[Ft(t,n.get(t.id))]++;let _=a(`range.${r}`);return(0,Z.jsxs)(`div`,{className:`mb-3 grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`card px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,Z.jsx)(Gt,{label:a(`providers.overview.requests`),value:N(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?j(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} (${j(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:N(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:P(`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:j(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)(p,{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:P(!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:P(`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)(p,{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?N(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:j(t.successRate)})]})},{key:`ttft`,label:o(`providers.col.ttft`),numeric:!0,width:92,render:(e,t)=>(0,Z.jsx)($t,{children:t.ttft<0?`—`:z(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?`${N(t.stat.inputTokens,!0)} / ${N(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=k(e.id),{toast:r}=q();return(0,Z.jsx)(`span`,{className:`ml-1 inline-flex`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(C,{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(),a=le(),o=h(n.id),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(``),d=(a.data??[]).filter(rn);(0,X.useEffect)(()=>{e&&(c(n.templateId??``),u(``))},[e,n.templateId]);let f=d.find(e=>e.id===s),p=f?f.variants?.find(e=>e.id===l)?.endpointsOverride??f.endpoints:[],m=s===n.templateId&&!l;return(0,Z.jsxs)(fe,{open:e,onOpenChange:t,title:r(`providers.templateSwitch`),description:r(`providers.templateSwitchDetail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(g,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,Z.jsx)(g,{variant:`primary`,disabled:!f||m,loading:o.isPending,onClick:()=>f&&o.mutate({templateId:f.id,variantId:l||null},{onSuccess:()=>{t(!1),i(r(`providers.templateSwitched`,{name:f.name}),`success`)},onError:e=>i(G(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,Z.jsx)(x,{}),a.isError&&(0,Z.jsx)(b,{tone:`danger`,title:r(`common.error`),children:G(a.error)}),(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(_,{label:r(`providers.templateSwitchTarget`),children:(0,Z.jsx)(K,{value:s,onChange:e=>{c(e),u(``)},options:d.map(e=>({value:e.id,label:e.id===n.templateId?r(`providers.templateSwitchCurrent`,{name:e.name}):e.name,detail:e.id}))})}),f?.variants&&f.variants.length>0&&(0,Z.jsx)(_,{label:r(`providers.variant`),children:(0,Z.jsx)(K,{value:l,onChange:u,options:[{value:``,label:r(`providers.variantDefault`)},...f.variants.map(e=>({value:e.id,label:e.name}))]})}),f&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`mb-2 text-[13px] font-medium`,children:r(`providers.templateSwitchEndpoints`)}),(0,Z.jsx)(`ul`,{className:`grid gap-1 text-[12px]`,children:p.map(e=>(0,Z.jsxs)(`li`,{className:`flex gap-3`,children:[(0,Z.jsx)(`span`,{className:`w-36 shrink-0 text-[var(--text-secondary)]`,children:$.find(t=>t.value===e.protocol)?.label??e.protocol}),(0,Z.jsx)(`span`,{className:`min-w-0 font-mono break-all`,children:e.baseUrl})]},e.protocol))})]})]})]})}function 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(),a=le(),o=h(e.id),s=a.data?.find(t=>t.id===e.templateId),c=(s?.keyAlternatives??[]).flatMap(e=>a.data?.filter(t=>t.id===e)??[]);if(!s||c.length===0)return null;let l=async e=>{let t=[...new Set(e.endpoints.map(e=>e.baseUrl))].join(`, `);await i({title:n(`providers.templateSwitchConfirm`,{alt:e.name}),detail:n(`providers.templateSwitchConfirmDetail`,{urls:t}),confirmLabel:n(`providers.keyAlternative.switch`,{alt:e.name})})&&o.mutate({templateId:e.id},{onSuccess:()=>r(n(`providers.templateSwitched`,{name:e.name}),`success`),onError:e=>r(G(e),`error`)})};return(0,Z.jsxs)(b,{className:t,tone:`warning`,title:n(`providers.keyAlternative.title`),children:[n(`providers.keyAlternative.rejected`,{name:s.name,alt:c.map(e=>e.name).join(` / `)}),(0,Z.jsx)(`span`,{className:`mt-2 flex flex-wrap gap-2`,children:c.map(e=>(0,Z.jsx)(g,{size:`sm`,loading:o.isPending,onClick:()=>void l(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=D(),a=I(t?e.id:void 0),o=e.endpoints.map(e=>e.protocol),[s,c]=(0,X.useState)(`single`),[u,d]=(0,X.useState)(()=>hn(e)),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(``),[v,y]=(0,X.useState)(ln),[b,x]=(0,X.useState)({size:``,quality:``,count:1,operation:`generate`,input:null}),[S,C]=(0,X.useState)(``),w=(0,X.useRef)(S);w.current=S;let[T,E]=(0,X.useState)(null),[O,k]=(0,X.useState)({}),[A,j]=(0,X.useState)([]),[M,N]=(0,X.useState)(new Set),[ee,P]=(0,X.useState)([]),[te,F]=(0,X.useState)(``),[ne,L]=(0,X.useState)(null),[re,R]=(0,X.useState)(!1),z=(0,X.useRef)(null),B=(0,X.useRef)(new Map),V=(0,X.useRef)(!1),ie=(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,...ee.filter(t=>!e.includes(t))]},[a.data,ee]);(0,X.useEffect)(()=>{if(t){let e=w.current||(a.data??[]).find(e=>e.enabled)?.modelId||(a.data??[])[0]?.modelId||``;!w.current&&e&&pn(e)&&d(`openai-images`),C(e);return}ie.current=!1,z.current?.abort();for(let e of B.current.values())e.abort();B.current.clear(),E(null),k({}),j([]),N(new Set),P([]),F(``),L(null)},[t,a.data]);let ae=(0,X.useCallback)((t,n=!1)=>pn(t)||!n&&u===`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:u===`openai-images`?hn(e):u,stream:f,prompt:m.trim()||null,maxOutputTokens:v??ln},[u,f,m,v,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=>{C(t),pn(t)?d(`openai-images`):u===`openai-images`&&d(hn(e))},ce=()=>{let e=S.trim();if(!e)return;z.current?.abort();let t=new AbortController;z.current=t,ie.current=!0,L(null),E({modelId:e,status:`running`,text:``,reasoning:``}),oe(e,t.signal,e=>{e.status!==`running`&&e.status!==`queued`&&ue(),E(e)})},le=e=>{if(e.length===0)return;ie.current=!0,V.current=!1,L(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(!ie.current)return;let n=e[t++];if(n===void 0)return;if(V.current){k(e=>({...e,[n]:{...e[n],status:`cancelled`}}));continue}let r=new AbortController;B.current.set(n,r),await oe(n,r.signal,e=>k(t=>({...t,[n]:e})),!0),B.current.delete(n),ue()}}))},ue=()=>void i.invalidateQueries({queryKey:[`requests`]}),de=()=>{V.current=!0,k(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.status===`queued`?{...t,status:`cancelled`}:t])))},W=T?.status===`running`||A.some(e=>O[e]?.status===`running`||O[e]?.status===`queued`&&!V.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)(g,{disabled:W,onClick:()=>n(!1),icon:(0,Z.jsx)(Ae,{className:`size-3.5`}),children:r(`common.close`)}),s===`single`?W?(0,Z.jsx)(g,{variant:`primary`,icon:(0,Z.jsx)(De,{className:`size-3.5`}),onClick:()=>z.current?.abort(),children:r(`providers.testDialog.stop`)}):(0,Z.jsx)(g,{variant:`primary`,disabled:S.trim()===``,icon:(0,Z.jsx)(Se,{className:`size-3.5`}),onClick:ce,children:r(T?`providers.testDialog.retest`:`providers.testDialog.start`)}):W?(0,Z.jsx)(g,{variant:`primary`,icon:(0,Z.jsx)(De,{className:`size-3.5`}),onClick:de,children:r(`providers.testDialog.stopRest`)}):(0,Z.jsx)(g,{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)(l,{items:[{value:`single`,label:r(`providers.testDialog.modeSingle`)},{value:`batch`,label:r(`providers.testDialog.modeBatch`)}],value:s,onChange:e=>{c(e),L(null)},ariaLabel:r(`providers.testDialog.config`)})]}),s===`single`?(0,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)(_,{label:r(`providers.testDialog.model`),children:(0,Z.jsx)(yn,{value:S,models:H,onChange:se})}),(0,Z.jsx)(Tn,{protocols:o,protocol:u,onProtocol:d,stream:f,onStream:p,maxTokens:v,onMaxTokens:y,prompt:m,onPrompt:h,image:b,onImage:x}),(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:T,onRetest:ce})]}):ne===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:te,onSearch:F,onAdd:e=>{P(t=>t.includes(e)?t:[...t,e]),N(t=>new Set(t).add(e)),F(``)},configOpen:re,onConfigOpen:R,protocols:o,protocol:u,onProtocol:d,stream:f,onStream:p,maxTokens:v,onMaxTokens:y,prompt:m,onPrompt:h,image:b,onImage:x,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:L})}):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)(g,{variant:`plain`,icon:(0,Z.jsx)(he,{className:`size-4`}),"aria-label":r(`common.back`),onClick:()=>L(null)}),(0,Z.jsx)(`span`,{className:`font-mono text-[13px]`,children:ne})]}),(0,Z.jsx)(Dn,{provider:e,run:O[ne]??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())),f=()=>{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)(d,{className:`pr-9 font-mono`,value:e,placeholder:r(`providers.testDialog.modelPlaceholder`),"aria-expanded":i,role:`combobox`,onFocus:f,onClick:f,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 f();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):f(),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:P(`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`,c=e=>r.onImage({...r.image,...e}),u=r.image.operation===`edit`,f=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_,{label:i(`providers.testDialog.imageOperation`),hint:u?i(`providers.testDialog.imageEditHint`):void 0,children:(0,Z.jsx)(l,{items:[{value:`generate`,label:i(`providers.testDialog.imageGenerate`)},{value:`edit`,label:i(`providers.testDialog.imageEdit`)}],value:r.image.operation,onChange:e=>c({operation:e}),ariaLabel:i(`providers.testDialog.imageOperation`)})}),u?(0,Z.jsx)(En,{value:r.image.input,onChange:e=>c({input:e})}):null,(0,Z.jsxs)(_,{label:i(`providers.testDialog.imageSize`),hint:i(`providers.testDialog.imageSizeHint`),children:[(0,Z.jsx)(d,{className:`font-mono`,list:`provider-test-image-sizes`,value:r.image.size,placeholder:`1024x1024`,"aria-label":i(`providers.testDialog.imageSize`),onChange:e=>c({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)(_,{label:i(`providers.testDialog.imageQuality`),children:(0,Z.jsx)(K,{value:r.image.quality,onChange:e=>c({quality:e}),options:[{value:``,label:i(`providers.testDialog.imageDefault`)},...Cn.map(e=>({value:e,label:e}))]})}),(0,Z.jsx)(_,{label:i(`providers.testDialog.imageCount`),children:(0,Z.jsx)(y,{value:r.image.count,min:1,placeholder:`1`,label:i(`providers.testDialog.imageCount`),onChange:e=>c({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)(C,{checked:r.stream,label:i(`providers.testDialog.stream`),onChange:r.onStream})]}),(0,Z.jsx)(_,{label:i(`providers.testDialog.maxTokens`),children:(0,Z.jsx)(y,{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)(_,{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`)}),f]}):null]}):o?f:p,(0,Z.jsx)(_,{label:i(`providers.testDialog.prompt`),hint:i(`providers.testDialog.promptHint`),children:(0,Z.jsx)(s,{rows:4,value:r.prompt,placeholder:o?u?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)(_,{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)(g,{size:`sm`,icon:(0,Z.jsx)(Ce,{className:`size-3.5`}),onClick:()=>r.current?.click(),children:n(`providers.testDialog.imageInputPick`)}),e?(0,Z.jsx)(g,{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(),[a,o]=(0,X.useState)(`preview`),s=t?.text??``,c=t?.raw??``,u=Object.entries(t?.headers??{}),d=t?.ttftMs!=null&&t?.httpMs!=null?Math.max(0,t.ttftMs-t.httpMs):null,f=a===`raw`?c:a===`headers`?u.map(([e,t])=>`${e}: ${t}`).join(`
3
+ `):s;return(0,Z.jsxs)(`div`,{className:`grid min-w-0 content-start gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n&&t&&t.status!==`running`?(0,Z.jsx)(g,{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)(i,{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)(l,{items:[{value:`preview`,label:r(`providers.testDialog.preview`)},{value:`raw`,label:r(`providers.testDialog.raw`)},{value:`headers`,label:r(`providers.testDialog.headers`)}],value:a,onChange:o,ariaLabel:r(`providers.testDialog.reply`)}),(0,Z.jsx)(T,{value:f,label:r(a===`headers`?`providers.testDialog.headers`:`providers.testDialog.reply`),iconOnly:!0})]})]}),(0,Z.jsx)(`div`,{className:`h-[360px] overflow-auto px-4 py-3`,children:a===`headers`?u.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:u.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))})}):a===`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)(b,{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?`—`:z(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)(p,{tone:n===`success`?`green`:n===`failed`?`red`:n===`running`?`orange`:`neutral`}),t(mn[n])]})}function jn({known:e,selected:t,onToggle:n,onSelectAll:i,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,_=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)(r,{value:o,onChange:s,placeholder:f(`providers.testDialog.searchModels`)})}),(0,Z.jsx)(g,{variant:`plain`,disabled:t.size===0,onClick:a,children:f(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(g,{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&&!_?(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=>i(e!==!1),"aria-label":f(`providers.testDialog.clearSelection`)}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:f(`providers.testDialog.ownFilter`)})]}),_?(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 a=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,a?.imageOperation?(0,Z.jsx)(i,{tone:`neutral`,className:`ml-2 align-middle`,children:r(a.imageOperation===`edit`?`providers.testDialog.imageEdit`:`providers.testDialog.imageGenerate`)}):null]}),(0,Z.jsx)(`td`,{className:`px-4 py-2`,children:(0,Z.jsx)(An,{run:a??null})}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:a?.ttftMs==null?`—`:z(a.ttftMs)}),(0,Z.jsx)(`td`,{className:`px-4 py-2 font-mono tabular-nums`,children:a?.totalMs==null?`—`:z(a.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:!a,onClick:()=>n(e),children:r(`providers.testDialog.view`)})})]},e)})})]})})}async function Nn(e,t,n,r,i){let o={modelId:t,status:`running`,text:``,reasoning:``,...n.protocol===`openai-images`?{imageOperation:n.imageOperation===`edit`?`edit`:`generate`}:{}};i(o);let s=e=>{o={...o,...e},i(o)};try{await a(e,n,e=>{let t=e.data??{};switch(e.event){case`headers`:s({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`?s({reasoning:o.reasoning+e}):s({text:o.text+e});break}case`done`:{let t=e.data;s({status:t.ok?`success`:`failed`,error:t.error??null,httpStatus:t.httpStatus??null,httpMs:t.httpMs??null,ttftMs:t.ttftMs??null,totalMs:t.totalMs??null,text:t.text??``,reasoning:t.reasoning??``,raw:t.raw??``,rawTruncated:t.rawTruncated??!1,images:t.images??[],contentType:t.contentType??null,headers:Pn(t.headers)});break}}},r)}catch(e){e?.name===`AbortError`?s({status:`cancelled`,error:null}):s({status:`failed`,error:e instanceof w?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=ne(),[a,o]=(0,X.useState)(n.get(`new`)===`1`),[s,c]=(0,X.useState)(!1),[u,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=ie(`7d`,`day`,`provider`),[p,h]=(0,X.useState)(`7d`),_=V(`7d`),v=V(p),[y,S]=jt(),[C,w]=Mt(),[T,E]=(0,X.useState)(null),D=(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]),O=(0,X.useMemo)(()=>new Map((_.data??[]).map(e=>[e.providerId,e])),[_.data]),k=e=>D.byProvider.get(e.name)?.requests??D.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)(g,{icon:(0,Z.jsx)(me,{className:`size-3.5`}),onClick:()=>d(!0),children:e(`providers.backup`)}),(0,Z.jsx)(g,{icon:(0,Z.jsx)(Me,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`providers.import`)}),(0,Z.jsx)(g,{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)(x,{lines:4}),i.isError&&(0,Z.jsx)(b,{tone:`danger`,title:e(`common.error`),children:G(i.error)}),i.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(m,{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)(g,{variant:`primary`,icon:(0,Z.jsx)(we,{className:`size-3.5`}),onClick:()=>o(!0),children:e(`providers.add`)}),(0,Z.jsx)(g,{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)(l,{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)(g,{variant:`plain`,size:`sm`,icon:C?(0,Z.jsx)(ve,{className:`size-3.5`}):(0,Z.jsx)(ge,{className:`size-3.5`}),onClick:()=>w(!C),children:e(C?`providers.overview.hideCharts`:`providers.overview.showCharts`)}),(0,Z.jsx)(l,{ariaLabel:e(`providers.view.label`),value:y,onChange:S,items:[{value:`grid`,label:e(`providers.view.grid`)},{value:`table`,label:e(`providers.view.table`)}]})]})]}),(0,Z.jsx)(Wt,{providers:i.data,stats:v.data??[],stats7d:O,range:p,chartsOpen:C}),y===`table`?(0,Z.jsx)(Qt,{providers:i.data,stats7d:O,usage:k,labels:D.labels,max:D.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:D.labels,max:D.max,requests:k(e),stat:O.get(e.id),onOpen:()=>t(`/providers/${e.id}`),onTest:()=>E(e)},e.id))})]})]}),(0,Z.jsx)(_t,{open:s,onOpenChange:c}),(0,Z.jsx)(Tt,{open:u,onOpenChange:d}),(0,Z.jsx)($n,{open:a,onOpenChange:o,onCreated:e=>t(`/providers/${e.id}`)}),T&&(0,Z.jsx)(vn,{provider:T,open:!0,onOpenChange:e=>!e&&E(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:a,onOpen:o,onTest:s}){let{t:c,locale:l}=U(),u=Ft(e,a),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,m=pe(e)?de(e.quota):null,h=r.reduce((e,t)=>e+t,0),_=en(e.endpoints[0]?.baseUrl);return(0,Z.jsxs)(`div`,{className:P(`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:o,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:P(`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)(p,{tone:It[u]})}),e.templateUpdateAvailable&&(0,Z.jsx)(i,{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)(g,{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:_??`—`}),(0,Z.jsx)(`span`,{children:`·`}),m?(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[var(--warning)]`,title:m.message,children:c(`providers.quota.failed`,{error:ue(m,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:P(`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}),h>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:N(h,!0)}),` `,c(`providers.card.requestsUnit`)]}),a&&a.requests>0&&(0,Z.jsx)(`span`,{className:`num`,style:{color:Bt(a.successRate)},title:c(`providers.col.successRate`),children:j(a.successRate)}),a&&a.costUsd>0&&(0,Z.jsx)(`span`,{className:`num`,children:R(a.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)(d,{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)(C,{checked:!!i.fullUrl,label:n(`providers.fullUrl`),onChange:e=>a(o,{fullUrl:e})}),n(`providers.fullUrl`)]}),(0,Z.jsx)(g,{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)(g,{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)(d,{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)(d,{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)(g,{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)(g,{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:i}=U(),{toast:a}=q(),o=le(),c=oe(),l=O(),u=ne(),f=(0,X.useMemo)(()=>new Set((u.data??[]).filter(e=>e.authScheme===`oauth-subscription`&&e.templateId).map(e=>e.templateId)),[u.data]),p=Le(),[m,h]=(0,X.useState)(``),[v,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(``),[D,k]=(0,X.useState)(``),[A,j]=(0,X.useState)({project:``,location:`global`}),[M,N]=(0,X.useState)(``),[ee,P]=(0,X.useState)(``),[te,F]=(0,X.useState)(``),[I,re]=(0,X.useState)(`bearer`),[R,z]=(0,X.useState)([]),[B,V]=(0,X.useState)([]),[ie,H]=(0,X.useState)([]),[ae,se]=(0,X.useState)(``),[ce,ue]=(0,X.useState)(1),[de,W]=(0,X.useState)(``),[pe,me]=(0,X.useState)(``);(0,X.useEffect)(()=>{e||(S(null),w(null),h(``),E(``),k(``),j({project:``,location:`global`}),N(``),P(``),F(``))},[e]);let he=(0,X.useMemo)(()=>{let e=m.trim().toLowerCase(),t=(o.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)},[o.data,m]),ge=(0,X.useMemo)(()=>{let e=m.trim().toLowerCase();return(u.data??[]).filter(t=>t.authScheme===`plugin`&&!t.settings.plugin?.absent&&(!e||t.name.toLowerCase().includes(e)||t.id.includes(e)))},[u.data,m]),_e=e=>{S(e),P(``),se(``),W(``),me(``),(rt(I)||e!==`custom`&&rt(e.auth.scheme))&&k(``),j({project:``,location:e!==`custom`&&e.settings?.vertex?.location||`global`}),N(``),e===`custom`?(E(``),F(``),re(`bearer`),z([{protocol:`openai-chat`,baseUrl:``}]),V([`openai-chat`]),H([]),ue(1)):(E(e.name),F(e.priceKey??e.id),re(e.auth.scheme),z(e.endpoints.map(e=>({...e}))),V([...e.preferredUpstreamProtocols]),H(Object.entries(e.defaultHeaders??{})),ue(e.defaultPriceMultiplier??1))},ve=e=>{V(t=>Yn(t,R,e)),z(e)},J=v&&v!==`custom`?v:null,ye=J?.authScheme===`oauth-subscription`,be=pe.split(Jn).map(e=>e.trim()).filter(Boolean),xe=(J?.keyAlternatives??[]).flatMap(e=>(o.data??[]).filter(t=>t.id===e)),Se=()=>{let e=v===`custom`;l.mutate({templateId:e?null:v.id,variantId:ee||null,name:T.trim()||null,apiKey:D.trim()||null,priceKey:te,...I===`gcp-service-account`?{settings:{vertex:{project:A.project.trim(),location:A.location}}}:{},...ye?{}:{endpoints:R.map(e=>({...e,baseUrl:e.baseUrl.trim()})),authScheme:I,preferredUpstreamProtocols:B.filter(e=>R.some(t=>t.protocol===e)),extraHeaders:Object.fromEntries(ie.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t])),httpProxy:ae.trim()||null,priceMultiplier:ce,notes:de.trim()||null,...be.length>0?{models:be}:{}}},{onSuccess:e=>{t(!1),a(i(`providers.created`,{name:e.name}),`success`),n(e)},onError:e=>a(G(e),`error`)})},Ce=()=>{if(C===`custom`)_e(`custom`);else if(C?.startsWith(Hn)){let e=ge.find(e=>Hn+e.id===C);e&&(t(!1),n(e))}else{let e=(o.data??[]).find(e=>e.id===C);e&&!f.has(e.id)&&_e(e)}},Te=ye||R.length>0&&R.every(e=>/^https?:\/\//.test(e.baseUrl.trim())),Ee=v!==null&&Te&&(v===`custom`?T.trim()!==``:!J.requiresApiKey||I===`none`||D.trim()!==``);return(0,Z.jsxs)(fe,{open:e,onOpenChange:t,width:640,title:i(v?`providers.addTitleDetails`:`providers.addTitle`),description:v?J?J.name:i(`providers.custom`):i(`providers.addDetail`),footer:v?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(g,{className:`mr-auto`,variant:`plain`,onClick:()=>S(null),children:i(`common.back`)}),(0,Z.jsx)(g,{onClick:()=>t(!1),children:i(`common.cancel`)}),(0,Z.jsx)(g,{variant:`primary`,disabled:!Ee,loading:l.isPending,onClick:Se,children:i(`providers.create`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(g,{onClick:()=>t(!1),children:i(`common.cancel`)}),(0,Z.jsx)(g,{variant:`primary`,disabled:!C,onClick:Ce,children:i(`common.continue`)})]}),children:[(0,Z.jsx)(nt,{className:`mb-6`,label:i(`providers.addTitle`),current:+!!v,steps:[{id:`template`,label:i(`providers.step.template`)},{id:`details`,label:i(`providers.step.details`)}]}),v?(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(_,{label:i(`providers.name`),children:(0,Z.jsx)(d,{value:T,onChange:e=>E(e.target.value)})}),J?.variants&&J.variants.length>0&&(0,Z.jsx)(_,{label:i(`providers.variant`),children:(0,Z.jsx)(K,{value:ee,onChange:e=>{P(e);let t=J.variants?.find(t=>t.id===e);F(t?.priceKey??J.priceKey??J.id),ve((t?.endpointsOverride??J.endpoints).map(e=>({...e})))},options:[{value:``,label:i(`providers.variantDefault`)},...J.variants.map(e=>({value:e.id,label:e.name}))]})}),v===`custom`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Xn,{label:i(`providers.section.endpoints`),hint:i(`providers.baseUrlHint`),children:(0,Z.jsx)(Zn,{value:R,onChange:ve})}),(0,Z.jsx)(_,{label:i(`providers.authScheme`),children:(0,Z.jsx)(K,{value:I,onChange:re,options:In})})]}),ye?(0,Z.jsx)(b,{tone:`info`,title:i(`providers.subscriptionWizardHint`),children:i(`providers.subscriptionWizardDetail`)}):I===`aws-sigv4`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(st,{onChange:k}),(0,Z.jsx)(ct,{endpoints:R})]}):I===`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:i(`providers.apiKey`),description:i(`providers.apiKeyHint`),autoComplete:`off`,placeholder:`sk-…`,value:D,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:i(`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:i(`providers.keyAlternative.wizard`,{name:J.name,alt:xe.map(e=>e.name).join(` / `)})}),xe.map(e=>(0,Z.jsx)(g,{size:`sm`,variant:`plain`,onClick:()=>{w(e.id),_e(e)},children:i(`providers.keyAlternative.pick`,{alt:e.name})},e.id))]}),(0,Z.jsx)(_,{label:i(`providers.priceKey`),hint:i(`providers.priceKeyHint`),children:(0,Z.jsx)(K,{value:te,onChange:F,options:[{value:``,label:i(`providers.priceKeyNone`)},...(c.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey}))]})}),!ye&&(0,Z.jsx)(L,{title:i(`providers.moreOptions`),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[J&&(0,Z.jsx)(Xn,{label:i(`providers.section.endpoints`),hint:i(`providers.endpointsFooter`),children:(0,Z.jsx)(Zn,{value:R,onChange:ve})}),new Set(R.map(e=>e.protocol)).size>1&&(0,Z.jsx)(Xn,{label:i(`providers.preferred`),hint:i(`providers.preferredHint`),children:(0,Z.jsx)(Re,{label:i(`providers.preferred`),options:$.filter(e=>R.some(t=>t.protocol===e.value)).map(e=>{let t=B.indexOf(e.value);return{value:e.value,label:t>=0?`${t+1}. ${e.label}`:e.label}}),value:B,onValueChange:e=>{let t=B.filter(t=>e.includes(t)),n=e.filter(e=>!t.includes(e));V([...t,...n])}})}),J&&(0,Z.jsx)(_,{label:i(`providers.authScheme`),children:(0,Z.jsx)(K,{value:I,onChange:re,options:In})}),(0,Z.jsx)(Xn,{label:i(`providers.headers`),children:(0,Z.jsx)(Qn,{value:ie,onChange:H})}),(0,Z.jsx)(_,{label:i(`providers.proxy`),hint:i(`providers.proxyHint`),children:(0,Z.jsx)(d,{mono:!0,placeholder:`http://127.0.0.1:7890`,value:ae,onChange:e=>se(e.target.value)})}),(0,Z.jsx)(Xn,{label:i(`providers.multiplier`),hint:i(`providers.multiplierHint`),children:(0,Z.jsx)(y,{className:`w-28`,label:i(`providers.multiplier`),step:.01,min:0,value:ce,onChange:e=>ue(e??1)})}),(0,Z.jsx)(_,{label:i(`providers.initialModels`),hint:J?i(`providers.initialModelsTemplateHint`,{count:J.models.length}):i(`providers.initialModelsCustomHint`),children:(0,Z.jsx)(s,{rows:3,mono:!0,value:pe,onChange:e=>me(e.target.value)})}),(0,Z.jsx)(_,{label:i(`providers.notes`),children:(0,Z.jsx)(d,{value:de,onChange:e=>W(e.target.value)})}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`providers.moreOptionsDetail`)})]})}),J&&J.models.length>0&&be.length===0&&(0,Z.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`providers.templateModels`,{count:J.models.length})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsx)(r,{value:m,onChange:h,placeholder:i(`providers.searchTemplates`)}),o.isLoading&&(0,Z.jsx)(x,{lines:4}),o.isError&&(0,Z.jsx)(b,{tone:`danger`,title:i(`common.error`),children:G(o.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:i(`providers.category.${e.category}`)}),(0,Z.jsx)(He,{name:`provider-template`,"aria-label":i(`providers.category.${e.category}`),density:`compact`,minColumnWidth:168,value:e.items.some(e=>e.id===C)?C:null,onValueChange:w,options:e.items.map(e=>{let t=[...new Set(e.endpoints.map(e=>e.protocol))],[n,r]=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:r??t.map(e=>Wn[e]).join(` · `)}),icon:(0,Z.jsx)(Be,{name:e.name,icon:e.icon,colorKey:e.id,size:28}),disabled:f.has(e.id),disabledReason:Kn(i(`providers.subscriptionAdded`))}})})]},e.category)),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.category.plugin`)}),ge.length>0?(0,Z.jsx)(He,{name:`provider-template-plugin`,"aria-label":i(`providers.category.plugin`),density:`compact`,minColumnWidth:168,value:C?.startsWith(Hn)?C:null,onValueChange:w,options:ge.map(e=>({value:Hn+e.id,label:Kn(e.name),description:Kn(i(`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:i(`providers.pluginHint`)}),(0,Z.jsx)(g,{size:`sm`,onClick:()=>{t(!1),p(`/plugins/market`)},children:i(`plugins.browseMarket`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`providers.custom`)}),(0,Z.jsx)(He,{name:`provider-template-custom`,"aria-label":i(`providers.custom`),layout:`list`,density:`compact`,value:C===`custom`?`custom`:null,onValueChange:w,options:[{value:`custom`,label:i(`providers.custom`),description:i(`providers.customDetail`),icon:(0,Z.jsx)(`span`,{className:`inline-flex size-7 items-center justify-center rounded-[8px] border border-dashed border-[var(--border-strong)] text-[var(--text-secondary)]`,children:(0,Z.jsx)(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};
@@ -0,0 +1,3 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{D as n,E as r,Fn as i,I as a,Ji as o,N as s,O as c,P as l,Qs as u,R as d,S as f,U as p,W as m,Wo as h,Yi as g,bo as _,dt as v,qi as y,r as b,vn as ee,w as x}from"./format-CmXxTS5M.js";import{H as S,U as C,V as w,W as T}from"./TrayTitleSource-DN10ruw2.js";import{t as E}from"./grip-vertical-DFI2_ajd.js";import{t as D}from"./layers-lBgMUT4n.js";import{t as O}from"./pencil-CpF9MxGZ.js";import{t as k}from"./plus-c3HzV6VX.js";import{t as A}from"./trash-BHBJn5GS.js";import{a as te,c as ne,d as re,f as j,i as M,l as N,n as P,o as F,r as I,s as L,t as R,u as z}from"./sortable.esm-Cj5-STJU.js";import{v as B}from"./index-BW8keTkg.js";var V=e(t(),1),H=u(),U=[`smart`,`order`,`rotate`,`usage`,`pace`,`weight`],W=[`auto`,`session`,`turn`,`off`,`strict`],G=e=>e.group?`group/${e.group}`:`${e.provider}/${e.model}`;function ie(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t.length>48?t.slice(0,48).replace(/-+$/,``):t}var K=()=>({name:``,slug:``,mode:`smart`,stays:`auto`,enabled:!0,listed:!0,members:[]}),q=e=>({name:e.name,slug:e.slug,mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({provider:e.provider??null,model:e.model??null,group:e.group??null,weight:e.weight}))});function ae(e){return e.name.trim()!==``&&/^[a-z0-9][a-z0-9-]{0,47}$/.test(e.slug)&&e.members.length>0}function oe(e,t){return{name:e.name.trim(),...t?{slug:e.slug}:{},mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({...e,weight:Math.min(1e3,Math.max(1,Math.floor(e.weight||1)))}))}}function J(e,t){if(e instanceof h){let n=e.details?.problems;if(n?.length)return n.map(e=>{let n=`routingGroups.problem.${e.code}`;return n in r?t(n):e.message})}return[C(e)]}var Y={healthy:`green`,cooling:`orange`,open:`orange`,half_open:`orange`,no_account:`red`,off:`red`,missing:`red`,group:`neutral`};function X(e,t){if(!e)return`—`;let n=`routingGroups.reason.${e}`;return n in r?t(n):e}function Z(){let{t:e,locale:t}=x();return n=>n.health===`cooling`||n.health===`open`?e(`routingGroups.health.${n.health}`,{time:n.coolingUntil?b(n.coolingUntil,t):`—`}):e(`routingGroups.health.${n.health}`)}function Q(){let{t:e}=x(),{toast:t,confirm:n}=T(),r=o(),a=y(),l=_(),u=i(),[d,f]=(0,V.useState)(null),m=e=>a.data?.find(t=>t.id===e),h=async r=>{await n({title:e(`routingGroups.deleteTitle`,{name:r.name}),detail:e(`routingGroups.deleteDetail`,{model:r.modelId}),confirmLabel:e(`common.delete`),destructive:!0})&&u.mutate(r.id,{onError:n=>t(J(n,e).join(`
2
+ `),`error`)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:e(`routingGroups.intro`)}),(0,H.jsx)(c,{variant:`primary`,icon:(0,H.jsx)(k,{className:`size-3.5`}),onClick:()=>f(K()),children:e(`routingGroups.add`)})]}),r.isLoading&&(0,H.jsx)(p,{lines:3}),r.data?.length===0&&(0,H.jsx)(`div`,{className:`card`,children:(0,H.jsx)(s,{icon:(0,H.jsx)(D,{className:`size-6`}),title:e(`routingGroups.empty`),detail:e(`routingGroups.emptyDetail`)})}),(0,H.jsx)(`div`,{className:`grid gap-3`,children:r.data?.map(n=>(0,H.jsx)($,{group:n,status:m(n.id),onEdit:()=>f({id:n.id,draft:q(n)}),onDelete:()=>void h(n),onToggle:r=>l.mutate({id:n.id,body:{enabled:r}},{onError:n=>t(J(n,e).join(`
3
+ `),`error`)})},n.id))}),(0,H.jsx)(ce,{target:d,groups:r.data??[],status:d&&`id`in d?m(d.id):void 0,onClose:()=>f(null)})]})}function $({group:e,status:t,onEdit:r,onDelete:i,onToggle:a}){let{t:o,locale:s}=x(),l=Z(),u=new Map(t?.members.map(e=>[e.key,e])??[]);return(0,H.jsxs)(`div`,{className:v(`card p-4`,!e.enabled&&`opacity-70`),children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.name}),(0,H.jsx)(n,{tone:`accent`,children:o(`routingGroups.mode.${e.mode}`)}),!e.enabled&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.disabled`)}),!e.listed&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.unlisted`)})]}),(0,H.jsx)(`code`,{className:`selectable text-[12px] text-[var(--text-secondary)]`,children:e.modelId})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(m,{label:o(`routingGroups.enabled`),checked:e.enabled,onChange:a}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(O,{className:`size-3.5`}),"aria-label":o(`common.edit`),title:o(`common.edit`),onClick:r}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":o(`common.delete`),title:o(`common.delete`),onClick:i})]})]}),(0,H.jsx)(`div`,{className:`mt-3 divide-y divide-[var(--border-subtle)] overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:e.members.map((t,n)=>(0,H.jsx)(se,{member:t,index:n,group:e,live:u.get(G(t)),healthText:l},G(t)))}),t?.lastReason&&t.lastDecisionAt&&(0,H.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:o(`routingGroups.lastDecision`,{reason:X(t.lastReason,o),time:b(t.lastDecisionAt,s)})})]})}function se({member:e,index:t,group:r,live:i,healthText:a}){let{t:o,locale:s}=x(),c=e.group?`group/${e.group}`:`${i?.providerName??e.provider} · ${e.model}`,l=i?.usedPercent==null?null:o(`routingGroups.quotaUsed`,{percent:Math.round(i.usedPercent)})+(i.resetsAt?` · `+o(`routingGroups.resets`,{time:b(i.resetsAt,s)}):``);return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2 text-[12px]`,children:[(0,H.jsx)(`span`,{className:`w-5 shrink-0 text-center tabular-nums text-[var(--text-muted)]`,children:t+1}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 basis-44 truncate text-[13px]`,children:c}),r.mode===`weight`&&(0,H.jsx)(n,{tone:`neutral`,children:o(`routingGroups.weightN`,{n:e.weight})}),i&&(0,H.jsx)(n,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(n,{tone:`red`,children:o(`routingGroups.memberProblem.${i.problem}`)}),l&&(0,H.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:l}),i&&!l&&i.health!==`group`&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.quotaUnknown`)}),i?.lastUsed&&(0,H.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`routingGroups.lastUsed`,{time:b(i.lastUsed,s)})})]})}function ce({target:e,groups:t,status:n,onClose:r}){let{t:i}=x(),o=Z(),s=ee(),u=_(),d=g(),p=e&&`id`in e?e.id:null,[h,v]=(0,V.useState)(K()),[y,b]=(0,V.useState)(!1),[C,T]=(0,V.useState)([]);(0,V.useEffect)(()=>{e&&(v(`id`in e?e.draft:e),b(`id`in e),T([]))},[e]);let E=p?t.find(e=>e.id===p):void 0,D=s.isPending||u.isPending,O=re(z(ne,{activationConstraint:{distance:4}}),z(L,{coordinateGetter:I})),k=e=>v(t=>({...t,...e})),A=e=>k({members:e}),j=new Set(h.members.map(G)),M=(0,V.useMemo)(()=>(d.data??[]).filter(e=>!j.has(`${e.providerId}/${e.id}`)).map(e=>({value:`${e.providerId}/${e.id}`,label:`${e.providerName} · ${e.id}`,m:e})),[d.data,h.members]),B=t.filter(e=>e.id!==p&&!j.has(`group/${e.slug}`)).map(e=>({value:e.slug,label:`group/${e.slug} · ${e.name}`})),q=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=h.members.findIndex(t=>G(t)===e.id),r=h.members.findIndex(e=>G(e)===t.id);n>=0&&r>=0&&A(P(h.members,n,r))},Y=()=>{let e=oe(h,p===null),t={onSuccess:()=>r(),onError:e=>T(J(e,i))};p?u.mutate({id:p,body:e},t):s.mutate(e,t)},X=new Map(n?.members.map(e=>[e.key,e])??[]),Q=(e,t)=>e.group?`group/${e.group}`:`${t?.providerName??X.get(G(e))?.providerName??e.provider} · ${e.model}`,$=new Map((d.data??[]).map(e=>[`${e.providerId}/${e.id}`,e]));return(0,H.jsx)(S,{open:e!==null,onOpenChange:e=>!e&&r(),width:600,title:E?i(`routingGroups.editTitle`,{name:E.name}):i(`routingGroups.addTitle`),footer:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(c,{onClick:r,children:i(`common.cancel`)}),(0,H.jsx)(c,{variant:`primary`,disabled:!ae(h),loading:D,onClick:Y,children:i(`common.save`)})]}),children:(0,H.jsxs)(`div`,{className:`grid gap-4`,children:[(0,H.jsx)(l,{label:i(`routingGroups.name`),children:(0,H.jsx)(a,{value:h.name,maxLength:80,placeholder:`Opus anywhere`,onChange:e=>k({name:e.target.value,...!y&&p===null?{slug:ie(e.target.value)}:{}})})}),(0,H.jsx)(l,{label:i(`routingGroups.slug`),hint:p?i(`routingGroups.slugLocked`):i(`routingGroups.slugHint`,{model:`group/${h.slug||`…`}`}),children:(0,H.jsx)(a,{mono:!0,value:h.slug,maxLength:48,disabled:p!==null,placeholder:`opus-anywhere`,onChange:e=>{b(!0),k({slug:e.target.value})}})}),(0,H.jsx)(l,{label:i(`routingGroups.modeLabel`),hint:i(`routingGroups.mode.${h.mode}.hint`),children:(0,H.jsx)(w,{value:h.mode,onChange:e=>k({mode:e}),options:U.map(e=>({value:e,label:i(`routingGroups.mode.${e}`)}))})}),(0,H.jsx)(l,{label:i(`routingGroups.staysLabel`),hint:i(`routingGroups.stays.${h.stays}.hint`),children:(0,H.jsx)(w,{value:h.stays,onChange:e=>k({stays:e}),options:W.map(e=>({value:e,label:i(`routingGroups.stays.${e}`)}))})}),(0,H.jsxs)(`div`,{className:`grid gap-2`,children:[(0,H.jsx)(`div`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:i(`routingGroups.membersTitle`)}),(0,H.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.membersHint`)}),h.members.length===0?(0,H.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.noMembers`)}):(0,H.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,H.jsx)(F,{sensors:O,collisionDetection:N,onDragEnd:q,children:(0,H.jsx)(R,{items:h.members.map(G),strategy:te,children:h.members.map((e,t)=>(0,H.jsx)(le,{member:e,name:Q(e,$.get(G(e))),weighted:h.mode===`weight`,live:X.get(G(e)),healthText:o,onWeight:e=>A(h.members.map((n,r)=>r===t?{...n,weight:e}:n)),onRemove:()=>A(h.members.filter((e,n)=>n!==t))},G(e)))})})}),(0,H.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addModel`),placeholder:i(`routingGroups.addModel`),value:null,disabled:M.length===0,onChange:e=>{let t=M.find(t=>t.value===e)?.m;t&&A([...h.members,{provider:t.providerId,model:t.id,group:null,weight:1}])},options:M.map(({value:e,label:t})=>({value:e,label:t}))}),(0,H.jsx)(w,{ariaLabel:i(`routingGroups.addGroup`),placeholder:i(`routingGroups.addGroup`),value:null,disabled:B.length===0,onChange:e=>A([...h.members,{provider:null,model:null,group:e,weight:1}]),options:B})]})]}),(0,H.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,H.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.listed`)}),(0,H.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`routingGroups.listedHint`)})]}),(0,H.jsx)(m,{label:i(`routingGroups.listed`),checked:h.listed,onChange:e=>k({listed:e})})]}),(0,H.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{children:i(`routingGroups.enabled`)}),(0,H.jsx)(m,{label:i(`routingGroups.enabled`),checked:h.enabled,onChange:e=>k({enabled:e})})]})]}),C.length>0&&(0,H.jsx)(f,{tone:`danger`,title:i(`routingGroups.refused`),children:(0,H.jsx)(`ul`,{className:`list-disc pl-4`,children:C.map(e=>(0,H.jsx)(`li`,{children:e},e))})})]})})}function le({member:e,name:t,weighted:r,live:i,healthText:a,onWeight:o,onRemove:s}){let{t:l}=x(),{attributes:u,listeners:f,setNodeRef:p,setActivatorNodeRef:m,transform:h,transition:g,isDragging:_}=M({id:G(e)});return(0,H.jsxs)(`div`,{ref:p,style:{transform:j.Transform.toString(h),transition:g},className:v(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,_&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,H.jsx)(`button`,{ref:m,type:`button`,"aria-label":l(`clients.dragToReorder`,{provider:t}),title:l(`clients.dragToReorder`,{provider:t}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...u,...f,children:(0,H.jsx)(E,{className:`size-4`})}),(0,H.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:t}),i&&(0,H.jsx)(n,{tone:Y[i.health]??`neutral`,children:a(i)}),i?.problem&&(0,H.jsx)(n,{tone:`red`,children:l(`routingGroups.memberProblem.${i.problem}`)})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,H.jsx)(`div`,{className:`w-20`,children:(0,H.jsx)(d,{label:l(`routingGroups.weight`),placeholder:l(`routingGroups.weight`),value:e.weight,min:1,step:1,onChange:e=>o(e??1)})}),(0,H.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,H.jsx)(A,{className:`size-3.5`}),"aria-label":l(`routingGroups.remove`,{name:t}),title:l(`routingGroups.remove`,{name:t}),onClick:s})]})]})}function ue(){let{t:e}=x();return(0,H.jsx)(B,{title:e(`nav.routingGroups`),subtitle:e(`routingGroups.subtitle`),children:(0,H.jsx)(Q,{})})}export{ue as RoutingGroupsPage};