@aidotnet/server-linux-x64 0.11.0 → 0.11.3

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 (59) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/libe_sqlite3.so +0 -0
  3. package/bin/wwwroot/assets/ClientsPage-DUe3cdEu.js +9 -0
  4. package/bin/wwwroot/assets/KeyPage-D2ItNgUp.js +1 -0
  5. package/bin/wwwroot/assets/ModelDetailPage-HlmdOI1u.js +1 -0
  6. package/bin/wwwroot/assets/ModelsPage-jTdzziih.js +1 -0
  7. package/bin/wwwroot/assets/PluginsPage-CrRbTNkX.js +2 -0
  8. package/bin/wwwroot/assets/PrivacyPage-C24xx5h0.js +1 -0
  9. package/bin/wwwroot/assets/ProviderDetailPage-C8oS6Rpp.js +3 -0
  10. package/bin/wwwroot/assets/ProvidersPage-CtzKM5FI.js +2 -0
  11. package/bin/wwwroot/assets/SettingsPage-CuaktA37.js +2 -0
  12. package/bin/wwwroot/assets/SmartRoutingPage-DRExfwox.js +2 -0
  13. package/bin/wwwroot/assets/TokenDetailPage-BecIf_R9.js +1 -0
  14. package/bin/wwwroot/assets/{TokenPoolEditor-BITgITLH.js → TokenPoolEditor-B3t0QNlg.js} +1 -1
  15. package/bin/wwwroot/assets/TokensPage-DnMBcutS.js +1 -0
  16. package/bin/wwwroot/assets/TracesPage-AYH3RZE9.js +7 -0
  17. package/bin/wwwroot/assets/{TrayPanelPage-BwaSGRbR.js → TrayPanelPage-OyBx1HTr.js} +1 -1
  18. package/bin/wwwroot/assets/{TrayPanelView-CAF6qwfK.js → TrayPanelView-B4sGBvxd.js} +1 -1
  19. package/bin/wwwroot/assets/alert-qNPoglGp.js +15 -0
  20. package/bin/wwwroot/assets/{arrow-down-CHVkKqVB.js → arrow-down-BtJQJK1L.js} +1 -1
  21. package/bin/wwwroot/assets/{arrow-left-ByzgpjKh.js → arrow-left-D6dVbOnl.js} +1 -1
  22. package/bin/wwwroot/assets/{checkbox-B_oHm90b.js → checkbox-B47xSnbl.js} +1 -1
  23. package/bin/wwwroot/assets/{cloud-download-DEv0Zu87.js → cloud-download-D2BBix7a.js} +1 -1
  24. package/bin/wwwroot/assets/confirm-morph-CgGgkVSl.js +1 -0
  25. package/bin/wwwroot/assets/{download-DXwZa8b6.js → download-COSgQOSF.js} +1 -1
  26. package/bin/wwwroot/assets/{ellipsis-DhvUvMq3.js → ellipsis-DU9LNejQ.js} +1 -1
  27. package/bin/wwwroot/assets/{external-link-D9cY56rt.js → external-link--dZT5Rkw.js} +1 -1
  28. package/bin/wwwroot/assets/{folder-open-Dt-7Rdbw.js → folder-open-ClaryP3F.js} +1 -1
  29. package/bin/wwwroot/assets/{index-Dt3DJ3Cx.css → index-BUzE8kPN.css} +1 -1
  30. package/bin/wwwroot/assets/index-DDjZdUEf.js +17 -0
  31. package/bin/wwwroot/assets/{log-out-wpGBd0OK.js → log-out-Tl6vCHvW.js} +1 -1
  32. package/bin/wwwroot/assets/minus-Bs-msHR3.js +1 -0
  33. package/bin/wwwroot/assets/overlays-ORpFxiz4.js +41 -0
  34. package/bin/wwwroot/assets/{pencil-BjMGSY_u.js → pencil-jnrNOWQy.js} +1 -1
  35. package/bin/wwwroot/assets/{power-zBXM8vYz.js → power-BYCH_AFm.js} +1 -1
  36. package/bin/wwwroot/assets/radio-cards-CyXEQMJG.js +1 -0
  37. package/bin/wwwroot/assets/{rotate-ccw-Omdd6cJU.js → rotate-ccw-D-Km3lpa.js} +1 -1
  38. package/bin/wwwroot/assets/{sortable.esm-CTCQ-9IR.js → sortable.esm-Br0EL6LB.js} +1 -1
  39. package/bin/wwwroot/assets/tkcode-COOcwqQh.png +0 -0
  40. package/bin/wwwroot/index.html +4 -4
  41. package/package.json +1 -1
  42. package/bin/wwwroot/assets/ClientsPage-C-x5kPpG.js +0 -9
  43. package/bin/wwwroot/assets/KeyPage-CxvUUC6Z.js +0 -1
  44. package/bin/wwwroot/assets/ModelDetailPage-CQol60ci.js +0 -1
  45. package/bin/wwwroot/assets/ModelsPage-Bp1-Rhad.js +0 -1
  46. package/bin/wwwroot/assets/PluginsPage-YPDqytJ6.js +0 -2
  47. package/bin/wwwroot/assets/PrivacyPage-Co1ffmVU.js +0 -1
  48. package/bin/wwwroot/assets/ProviderDetailPage-CacRreeZ.js +0 -3
  49. package/bin/wwwroot/assets/ProvidersPage-DSwvae35.js +0 -2
  50. package/bin/wwwroot/assets/SettingsPage-CvIE8pBq.js +0 -2
  51. package/bin/wwwroot/assets/TokenDetailPage-w1XONN5-.js +0 -1
  52. package/bin/wwwroot/assets/TokensPage-CiL0dLkj.js +0 -1
  53. package/bin/wwwroot/assets/TracesPage-zcvvDcj3.js +0 -7
  54. package/bin/wwwroot/assets/alert-BhYHbQ5M.js +0 -15
  55. package/bin/wwwroot/assets/confirm-morph-RDk31i1j.js +0 -1
  56. package/bin/wwwroot/assets/index-XVK9epgF.js +0 -17
  57. package/bin/wwwroot/assets/minus-3JX68qL9.js +0 -1
  58. package/bin/wwwroot/assets/overlays-CF55BHOs.js +0 -41
  59. package/bin/wwwroot/assets/radio-cards-BVdDbnT-.js +0 -1
package/bin/astra-server CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/astra-server
3
- size: 49808624 bytes
4
- sha256: 0873cedfa46f644accb04ca633be44bd1df419c5391b938a165d35eff420b7d6
3
+ size: 52005808 bytes
4
+ sha256: c4eeeec74ac748ddf6692f9983adc54872b0a772a0b717c7ff2be329b88ab9bb
Binary file
@@ -0,0 +1,9 @@
1
+ import{$r as e,Et as t,G as n,Gt as r,H as i,Ht as a,Ia as o,Jt as s,K as c,Kt as l,Lr as u,Ma as d,Mr as f,Na as p,Or as m,Ut as h,Vt as g,Y as _,Yn as v,Yt as y,_ as b,_n as x,bt as S,c as C,ct as w,d as T,dt as ee,fn as te,gt as ne,hr as re,ja as ie,jr as ae,m as E,mn as D,n as O,nr as oe,or as se,ot as k,qt as ce,r as A,s as le,t as j,u as M,v as N,wr as ue,xt as P,y as F}from"./alert-qNPoglGp.js";import{a as I,gt as L,ht as de,i as fe,o as R,r as z}from"./overlays-ORpFxiz4.js";import{n as B}from"./ProvidersPage-CtzKM5FI.js";import{t as pe}from"./download-COSgQOSF.js";import{t as me}from"./external-link--dZT5Rkw.js";import{t as he}from"./folder-open-ClaryP3F.js";import{a as ge,c as V,d as H,f as _e,i as U,l as W,n as G,o as ve,p as K,r as ye,s as be,t as xe,u as Se}from"./sortable.esm-Br0EL6LB.js";import{t as Ce}from"./rotate-ccw-D-Km3lpa.js";import{$ as we,B as Te,L as q,Q as Ee,R as De,S as J,V as Oe,X as ke,b as Ae,h as je,v as Me,x as Y,z as Ne}from"./index-DDjZdUEf.js";var Pe={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};Pe.node;var Fe=P(Pe),Ie={name:`circle-arrow-up`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]],aliases:[`arrow-up-circle`]};Ie.node;var Le=P(Ie),Re={name:`shield-alert`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]};Re.node;var ze=P(Re),X=o(p(),1),Z=d(),Be=`astra claude`;function Ve(e){return e.reduce((e,t)=>({requests:e.requests+1,inputTokens:e.inputTokens+t.inputTokens,totalInputTokens:e.totalInputTokens+t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,outputTokens:e.outputTokens+t.outputTokens,failed:e.failed+ +(t.status===`error`),estimatedCostNanoUsd:e.estimatedCostNanoUsd+(t.estimatedCostNanoUsd??0)}),{requests:0,inputTokens:0,totalInputTokens:0,outputTokens:0,failed:0,estimatedCostNanoUsd:0})}var He=e=>e.status===`active`&&e.enabled;function Ue(e,t){let n=[e.name||e.id,e.email?`· ${e.email}`:null,e.plan?`· ${e.plan}`:null].filter(Boolean).join(` `);return He(e)?n:`${n} · ${t}`}function We({enabled:e,gatewayEnabled:t}){let{t:n}=w(),{toast:i}=R(),a=Ee(),o=r(e),s=m(),[c,u]=(0,X.useState)(null),d=o.data?.mode??`gateway`,f=o.data?.accounts??[],p=o.data?.accountId??null??f.find(He)?.id??null,h=f.find(e=>e.id===p),g=d===`direct`,_=t&&(g||o.data!=null),v=g&&h?.telemetryEnabled===!0,y=l(v?h?.id:null,v),x=s.isPending,S=e=>s.mutate(e,{onError:e=>i(I(e),`error`)});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(M,{title:n(`clients.claudeDirect.modeTitle`),footer:n(`clients.claudeDirect.modeFooter`),children:[(0,Z.jsx)(E,{label:n(`clients.claudeDirect.mode`),detail:n(g?`clients.claudeDirect.directDetail`:`clients.claudeDirect.gatewayDetail`),children:(0,Z.jsx)(b,{ariaLabel:n(`clients.claudeDirect.mode`),value:d,onChange:e=>{if(e===d||x||!o.data)return;let t=p??f.find(He)?.id??null;if(e===`direct`&&!t){i(n(`clients.claudeDirect.needAccountToast`),`error`);return}S({mode:e,accountId:t})},items:[{value:`gateway`,label:n(`clients.claudeDirect.gateway`)},{value:`direct`,label:n(`clients.claudeDirect.direct`)}]})}),(0,Z.jsx)(`p`,{className:`px-4 pb-2 text-[11px] text-[var(--text-muted)]`,children:n(`clients.claudeDirect.modeNote`)})]}),o.isLoading&&(0,Z.jsx)(N,{lines:3}),o.isError&&(0,Z.jsx)(`div`,{className:`mb-5`,children:(0,Z.jsx)(j,{tone:`danger`,title:n(`clients.claudeDirect.loadFailed`),children:I(o.error)})}),_&&(0,Z.jsx)(`div`,{className:`mb-5`,children:(0,Z.jsx)(j,{tone:`warning`,title:n(`clients.claudeDirect.gatewayOnTitle`),children:n(`clients.claudeDirect.gatewayOnDetail`)})}),o.data&&(0,Z.jsx)(M,{title:n(`clients.claudeDirect.accountsTitle`),footer:n(`clients.claudeDirect.accountsFooter`),children:f.length===0?(0,Z.jsx)(C,{title:n(`clients.claudeDirect.noAccount`),detail:n(`clients.claudeDirect.noAccountDetail`),action:(0,Z.jsx)(A,{variant:`primary`,onClick:()=>a(`/providers`),children:n(`clients.claudeDirect.goProviders`)})}):(0,Z.jsx)(E,{label:n(`clients.claudeDirect.account`),children:(0,Z.jsx)(z,{className:`max-w-[300px]`,ariaLabel:n(`clients.claudeDirect.account`),value:p,onChange:e=>{x||e===p||S({mode:d,accountId:e})},options:f.map(e=>({value:e.id,label:Ue(e,n(`clients.claudeDirect.accountDisabledSuffix`,{status:n(`providers.subscription.status.${e.status}`)})),disabled:!He(e)}))})})}),o.data&&g&&h&&(0,Z.jsx)(M,{title:n(`clients.claudeDirect.launchTitle`),footer:n(`clients.claudeDirect.launchNote`),children:(0,Z.jsx)(Ge,{command:Be,copied:c,onCopy:async e=>{await L.copy(e)&&(u(e),i(n(`common.copied`)))}})}),o.data&&g&&h&&(0,Z.jsxs)(M,{title:n(`clients.claudeDirect.statsTitle`),footer:n(`clients.claudeDirect.statsFooter`),children:[(0,Z.jsx)(E,{label:n(`clients.claudeDirect.statsConsent`),detail:n(`clients.claudeDirect.statsConsentDetail`),children:(0,Z.jsx)(F,{label:n(`clients.claudeDirect.statsConsent`),checked:h.telemetryEnabled,disabled:x,onChange:e=>{h&&!x&&S({mode:d,accountId:h.id,telemetryEnabled:e})}})}),v&&(0,Z.jsx)(Ke,{requests:y})]})]})}function Ge({command:e,copied:t,onCopy:n}){let{t:r}=w();return(0,Z.jsx)(E,{label:(0,Z.jsx)(`span`,{className:`font-mono text-[12px] break-all selectable`,children:e}),children:(0,Z.jsx)(A,{size:`sm`,icon:(0,Z.jsx)(ne,{className:`size-3`}),variant:t===e?`primary`:`glass`,"aria-label":r(`common.copy`),title:r(`common.copy`),onClick:()=>void n(e),children:r(t===e?`common.copied`:`common.copy`)})})}function Ke({requests:e}){let{t,locale:r}=w(),a=e.data??[],o=Ve(a);return e.isLoading?(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsx)(N,{lines:3})}):e.isError?(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsx)(j,{tone:`danger`,title:t(`clients.claudeDirect.statsFailed`),children:I(e.error)})}):a.length===0?(0,Z.jsx)(C,{icon:(0,Z.jsx)(Oe,{className:`size-6`}),title:t(`clients.claudeDirect.statsEmpty`),detail:t(`clients.claudeDirect.statsEmptyDetail`)}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(E,{label:t(`clients.claudeDirect.statsTotals`,{count:_(o.requests)}),detail:t(`clients.claudeDirect.statsInDetail`,{input:_(o.totalInputTokens),cache:_(a.reduce((e,t)=>e+t.cacheReadTokens,0)),output:_(o.outputTokens)})}),(0,Z.jsx)(E,{label:t(`clients.claudeDirect.statsCost`),detail:t(`clients.claudeDirect.statsCostDetail`),children:(0,Z.jsx)(`span`,{className:`num text-[13px]`,children:c(a.some(e=>e.estimatedCostNanoUsd!=null)?o.estimatedCostNanoUsd:null)})}),o.failed>0&&(0,Z.jsx)(E,{label:t(`clients.claudeDirect.statsFailedCount`,{count:_(o.failed)}),children:(0,Z.jsx)(O,{tone:`red`,children:t(`clients.claudeDirect.statusError`)})}),a.map(e=>(0,Z.jsx)(E,{label:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:e.model}),e.status===`error`?(0,Z.jsx)(O,{tone:`red`,children:t(`clients.claudeDirect.statusError`)}):(0,Z.jsx)(O,{tone:`green`,children:t(`status.success`)})]}),detail:(0,Z.jsx)(`span`,{className:`num`,children:[i(e.occurredAtUtc,r),t(`clients.claudeDirect.tokensDetail`,{input:_(e.inputTokens),output:_(e.outputTokens)}),e.durationMs==null?null:n(e.durationMs),e.accountUuid??null].filter(Boolean).join(` · `)}),children:(0,Z.jsx)(`span`,{className:`num text-[13px]`,children:c(e.estimatedCostNanoUsd)})},e.id))]})}function qe({descriptors:e,values:t,onChange:n,enabled:r}){let{t:i}=w(),a=(e,r)=>{let i={...t};r===void 0||r===!1||r===0||r==="default"||r===``?delete i[e]:i[e]=r,n(i)};return(0,Z.jsx)(M,{title:i(`clients.options.title`),footer:i(r?`clients.options.footerEnabled`:`clients.options.footer`),children:e.map(e=>{let n=i(`clients.option.${e.key}`),r=i(`clients.option.${e.key}.hint`),o=t[e.key];return(0,Z.jsxs)(E,{label:n,detail:r,children:[e.type===`bool`&&(0,Z.jsx)(F,{label:n,checked:o===!0,onChange:t=>a(e.key,t)}),e.type===`int`&&(0,Z.jsx)(T,{className:`w-36`,mono:!0,inputMode:`numeric`,"aria-label":n,placeholder:i(`clients.options.unset`),value:typeof o==`number`?String(o):``,onChange:t=>{let n=Number.parseInt(t.target.value.replace(/\D/g,``),10);a(e.key,Number.isFinite(n)?n:void 0)}}),e.type===`enum`&&(0,Z.jsx)(z,{ariaLabel:n,value:typeof o==`string`?o:`default`,onChange:t=>a(e.key,t),options:(e.choices??[]).map(e=>({value:e,label:i(`clients.optionChoice.${e}`)})),className:`w-36`})]},e.key)})})}var Je=[`openai-chat`,`openai-responses`,`anthropic`,`gemini`],Ye=e=>typeof e==`string`&&Je.includes(e);function Xe(e){let t=e?.protocolOverrides,n={};if(!t||typeof t!=`object`)return n;for(let[e,r]of Object.entries(t))Ye(r)&&(n[e]=r);return n}function Ze(e){let t=e?.models;if(!t||typeof t!=`object`)return[];let n=[];for(let e of Object.values(t)){if(!e||typeof e!=`object`)continue;let t=e;typeof t.id==`string`&&t.id&&!n.some(e=>e.id===t.id)&&n.push({id:t.id,name:typeof t.name==`string`&&t.name?t.name:t.id,native:Array.isArray(t.protocols)?t.protocols.filter(Ye):[]})}return n}function Qe(e,t){let n=e.native.find(e=>t.includes(e));return n?{protocol:n,translated:!1}:{protocol:t[0],translated:!0}}var $e=e=>Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`
2
+ `),et=`auto`,tt=e=>B.find(t=>t.value===e)?.label??e;function nt({models:e,supported:t,values:n,onChange:r,enabled:i}){let{t:a}=w(),o=(e,t)=>{let i={...n};t===et?delete i[e]:i[e]=t,r(i)};return(0,Z.jsx)(M,{title:a(`clients.protocols.title`),footer:a(i?`clients.protocols.footerEnabled`:`clients.protocols.footer`),children:e.map(e=>{let r=Qe(e,t),i=e.native.filter(e=>t.includes(e));return(0,Z.jsx)(E,{label:e.name,detail:i.length>0?a(`clients.protocols.native`,{protocols:i.map(tt).join(` · `)}):a(`clients.protocols.noNative`),children:(0,Z.jsx)(z,{ariaLabel:e.name,className:`w-60`,value:n[e.id]&&t.includes(n[e.id])?n[e.id]:et,onChange:t=>o(e.id,t),options:[{value:et,label:a(r.translated?`clients.protocols.autoTranslated`:`clients.protocols.auto`,{protocol:tt(r.protocol)})},...t.map(e=>({value:e,label:tt(e)}))]})},e.id)})})}function rt(e,t){let n=e?.options,r={};if(!n||typeof n!=`object`)return r;for(let e of t??[]){let t=n[e.key];e.type===`bool`&&t===!0?r[e.key]=!0:(e.type===`int`&&typeof t==`number`&&t>0||e.type===`enum`&&typeof t==`string`&&t!=="default"&&e.choices?.includes(t))&&(r[e.key]=t)}return r}var it=e=>Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`
3
+ `),at=[`ANTHROPIC_MODEL`,`ANTHROPIC_DEFAULT_OPUS_MODEL`,`ANTHROPIC_DEFAULT_SONNET_MODEL`,`ANTHROPIC_DEFAULT_HAIKU_MODEL`];function ot(e){let t=e?.models,n={};if(!t||typeof t!=`object`)return n;for(let e of at){let r=t[e];typeof r==`string`&&r.trim()&&(n[e]=r.trim())}return n}var st=e=>at.map(t=>e[t]??``).join(`
4
+ `),Q=[`sonnet`,`opus`,`haiku`];function ct(e){let t=e?.roleMap,n={};if(!t||typeof t!=`object`)return n;for(let e of Q){let r=t[e];typeof r==`string`&&r.trim()&&(n[e]=r.trim())}return n}var $=e=>Q.map(t=>e[t]??``).join(`
5
+ `),lt=/(^|[-_.:/\s])(haiku|flash|mini|lite|nano|small|fast|air)($|[-_.:/\s])/i;function ut(e){if(e.length===0)return{};let t=t=>e.find(e=>e.toLowerCase().includes(t)),n=e.find(e=>!lt.test(e))??e[0],r=e.find(e=>lt.test(e))??n;return{sonnet:t(`sonnet`)??n,opus:t(`opus`)??t(`sonnet`)??n,haiku:t(`haiku`)??r}}function dt(){let{t:e}=w(),t=Ee(),{toast:n}=R(),r=we(),i=y(),a=h(),o=(0,X.useMemo)(()=>new Map((i.data??[]).map(e=>[e.kind,e])),[i.data]),s=pt(i.data).includes(r.kind)?r.kind:`codex`,c=o.get(s);return(0,X.useEffect)(()=>a.mutate(!1),[]),(0,Z.jsx)(je,{title:e(`nav.clients`),subtitle:e(`clients.subtitle`),actions:(0,Z.jsx)(A,{icon:(0,Z.jsx)(De,{className:`size-3.5`}),loading:a.isPending,onClick:()=>a.mutate(!0,{onSuccess:t=>{let r=t.filter(e=>e.install?.updateAvailable&&e.install.blocker!==`shadowed`).length;n(r>0?e(`clients.updatesFound`,{count:r}):e(`clients.allUpToDate`),r>0?void 0:`success`)},onError:e=>n(I(e),`error`)}),children:e(`clients.checkUpdates`)}),children:(0,Z.jsx)(`div`,{className:`@container mx-auto max-w-[1200px]`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 @3xl:flex-row @3xl:items-start @3xl:gap-5`,children:[(0,Z.jsx)(_t,{clients:i.data,loading:i.isLoading,selected:s,onSelect:e=>t(`/clients/${e}`,{replace:!0})}),(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-[760px] min-w-0 flex-1`,children:[i.isLoading&&(0,Z.jsx)(N,{lines:4}),i.isError&&(0,Z.jsx)(j,{tone:`danger`,title:e(`common.error`),children:I(i.error)}),c&&(0,Z.jsx)(xt,{client:c})]})]})})})}var ft=new Set([`opencode`,`pi`,`minimax-code`,`copilot-cli`,`vscode-copilot`,`crush`,`qwen-code`,`droid`,`kimi-code`,`zed`,`vscode-insiders`,`vscodium`,`omp`,`mimo-code`,`deepseek-harness`,`workbuddy`,`workbuddy-ai`,`nextcowork`,`paseo`,`zcode`,`tkcode`,`muse-code`,`codex`,`grok-build`,`hermes-agent`]);function pt(e){let t=(e??[]).filter(e=>!Me.includes(e.kind)).sort((e,t)=>e.name.localeCompare(t.name));return[...Me,...t.map(e=>e.kind)]}var mt=[`installed`,`notInstalled`,`comingSoon`];function ht(e){return e.availability===`coming_soon`?`comingSoon`:e.detection.installed||e.enabled||e.install?.installed?`installed`:`notInstalled`}function gt(e){return e.install?.version??e.detection.version??null}function _t({clients:e,loading:t,selected:n,onSelect:r}){let{t:i}=w(),a=new Map((e??[]).map(e=>[e.kind,e])),o=mt.map(t=>({group:t,items:pt(e).flatMap(e=>{let n=a.get(e);return n&&ht(n)===t?[n]:[]})})).filter(e=>e.items.length>0);return(0,Z.jsxs)(`nav`,{"aria-label":i(`nav.clients`),className:`card shrink-0 p-1.5 @3xl:sticky @3xl:top-0 @3xl:w-[232px]`,children:[t&&(0,Z.jsx)(N,{lines:6,className:`p-2`}),(0,Z.jsx)(`div`,{className:`flex gap-1 overflow-x-auto @3xl:flex-col @3xl:gap-0 @3xl:overflow-visible`,children:o.map(({group:e,items:t})=>(0,Z.jsxs)(`div`,{className:`contents @3xl:block`,children:[(0,Z.jsxs)(`h3`,{className:`hidden px-2.5 pt-2 pb-1 text-[11px] font-medium text-[var(--text-muted)] @3xl:block`,children:[i(`clients.group.${e}`),` · `,t.length]}),t.map(e=>(0,Z.jsx)(vt,{client:e,active:e.kind===n,onSelect:()=>r(e.kind)},e.kind))]},e))})]})}function vt({client:e,active:t,onSelect:n}){let{t:r}=w(),i=ht(e)!==`installed`,a=gt(e),o=e.install?.blocker===`shadowed`,s=e.install?.updateAvailable&&!o?e.install.latestVersion:null;return(0,Z.jsxs)(`button`,{type:`button`,"aria-label":J(e.kind,e.name),"aria-current":t?`page`:void 0,onClick:n,className:k(`flex shrink-0 items-center gap-2.5 rounded-[var(--radius-control)] px-2.5 py-1.5 text-left transition-colors @3xl:w-full`,t?`bg-[var(--accent-subtle)]`:`hover:bg-[var(--surface-muted)]`),children:[(0,Z.jsx)(`span`,{className:k(`inline-flex`,i&&!t&&`opacity-60`),children:(0,Z.jsx)(Ae,{kind:e.kind,size:24})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:k(`block truncate text-[13px] whitespace-nowrap`,t&&`font-medium`),children:J(e.kind,e.name)}),a&&(0,Z.jsxs)(`span`,{className:`hidden truncate text-[11px] text-[var(--text-secondary)] @3xl:block`,children:[a,s&&(0,Z.jsxs)(`span`,{className:`text-[var(--warning)]`,children:[` → `,s]})]})]}),e.install?.busy&&(0,Z.jsx)(yt,{}),s&&!e.install?.busy&&(0,Z.jsx)(O,{tone:`orange`,title:r(`clients.updateTo`,{version:s}),children:r(`clients.updateBadge`)}),o&&!e.install?.busy&&(0,Z.jsx)(O,{tone:`orange`,title:r(`clients.shadowed.title`,{version:e.install?.latestVersion??``}),children:r(`clients.shadowedBadge`)}),e.status===`drifted`?(0,Z.jsx)(`span`,{title:r(`clients.drifted`),"aria-label":r(`clients.drifted`),className:`inline-flex`,children:(0,Z.jsx)(le,{tone:`orange`})}):e.enabled?(0,Z.jsx)(S,{className:`size-3.5 shrink-0 text-[var(--success)]`,strokeWidth:2.5,"aria-label":r(`clients.enabled`)}):null]})}function yt(){return(0,Z.jsx)(Te,{className:`size-3.5 shrink-0 animate-spin text-[var(--text-secondary)] motion-reduce:animate-none`,"aria-hidden":!0})}function bt(e,t){return e.availability===`coming_soon`?(0,Z.jsx)(O,{children:t(`clients.comingSoon`)}):e.status===`drifted`?(0,Z.jsx)(O,{tone:`orange`,children:t(`clients.drifted`)}):e.enabled?(0,Z.jsx)(O,{tone:`green`,children:t(`clients.enabled`)}):(0,Z.jsx)(O,{children:t(`clients.disabled`)})}function xt({client:t}){let{t:n,locale:a}=w(),o=Ee(),{toast:c,confirm:l}=R(),u=se(),d=ae(),f=te(),p=x(),m=re(),h=e(),g=s(t.kind,!!t.providerId),[_,v]=(0,X.useState)(t.selectedModel??null),[y,b]=(0,X.useState)(t.accountId??``),S=t.tokenId??`default`,[C,T]=(0,X.useState)(S),ee=(h.data??[]).filter(e=>e.enabled||e.id===S).map(e=>({value:e.id,label:e.enabled?e.name:n(`clients.tokenDisabled`,{name:e.name}),disabled:!e.enabled})),[ie,D]=(0,X.useState)(!1),[k,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(null),P=t.availability===`coming_soon`,F=J(t.kind,t.name),fe=(u.data??[]).filter(e=>e.enabled),B=t.detection.configPaths[0],pe=fe.find(e=>e.id===t.providerId),me=pe?.authScheme===`oauth-subscription`||pe?.authScheme===`plugin`,ge=oe(pe?.id,me),V=t.kind===`claude-desktop`,H=t.kind===`claude-code`,_e=r(H),U=H&&_e.data?.mode===`direct`,W=ct(t.extras),[G,ve]=(0,X.useState)(W),K=Q.some(e=>G[e]),ye=$(G)!==$(W),be=ot(t.extras),[xe,Se]=(0,X.useState)(be),Ce=(_??null)!==(t.selectedModel??null)||st(xe)!==st(be),we=H?at.filter(e=>e!==`ANTHROPIC_MODEL`):[],Te=H?t.enabled?n(`clients.modelSlotsFooterEnabled`):n(`clients.modelSlotsFooter`):t.enabled?n(`clients.modelFooterEnabled`):n(`clients.modelFooter`),q=t.options??[],De=rt(t.extras,q),[ke,je]=(0,X.useState)(De),Me=it(ke)!==it(De),Y=t.protocols??[],Ne=Y.length>1?Ze(t.extras):[],Pe=Xe(t.extras),[Ie,Le]=(0,X.useState)(Pe),Re=$e(Ie)!==$e(Pe),ze=V?{...t.extras,roleMap:G}:H?{...t.extras,models:xe,options:ke}:q.length>0||Y.length>1?{...t.extras,...q.length>0?{options:ke}:{},...Y.length>1?{protocolOverrides:Ie}:{}}:void 0;(0,X.useEffect)(()=>v(t.selectedModel??null),[t.kind,t.selectedModel]),(0,X.useEffect)(()=>b(t.accountId??``),[t.kind,t.providerId,t.accountId]),(0,X.useEffect)(()=>T(S),[t.kind,S]),(0,X.useEffect)(()=>ve(ct(t.extras)),[t.kind,$(W)]);let Be=(0,X.useRef)({});(0,X.useEffect)(()=>{if(!V||t.enabled||Q.some(e=>W[e]))return;let e=Be.current,n=ut(g.data??[]);Be.current=n,ve(t=>(!Q.some(e=>t[e])||$(t)===$(e))&&$(t)!==$(n)?n:t)},[t.kind,t.enabled,$(W),(g.data??[]).join(`
6
+ `)]),(0,X.useEffect)(()=>Se(ot(t.extras)),[t.kind,st(be)]),(0,X.useEffect)(()=>je(rt(t.extras,t.options)),[t.kind,it(De)]),(0,X.useEffect)(()=>Le(Xe(t.extras)),[t.kind,$e(Pe)]);let Ve=()=>{t.providerId&&d.mutate({kind:t.kind,providerId:t.providerId,accountId:y},{onSuccess:()=>c(n(`common.saved`),`success`),onError:e=>c(I(e),`error`)})},He=async()=>{await l({title:n(`clients.disableConfirm`,{name:F}),detail:n(`clients.disableDetail`),confirmLabel:n(`clients.disable`)})&&f.mutate(t.kind,{onSuccess:async e=>{if(e.drifted.length===0){c(n(`clients.disabledToast`,{name:F}),`success`);return}await l({title:n(`clients.driftTitle`),detail:n(`clients.driftDetail`,{keys:e.drifted.join(`, `)}),confirmLabel:n(`clients.forceRestore`),destructive:!0})&&p.mutate(t.kind,{onSuccess:()=>c(n(`clients.disabledToast`,{name:F}),`success`),onError:e=>c(I(e),`error`)})},onError:e=>c(I(e),`error`)})},Ue=async()=>{B&&(L.canOpenPaths?await L.openPath(de(B)):await L.copy(B)&&c(n(`common.copied`)))};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(M,{children:[(0,Z.jsxs)(E,{icon:(0,Z.jsx)(Ae,{kind:t.kind,size:36}),label:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[15px] font-medium`,children:F}),U?(0,Z.jsx)(O,{children:n(`clients.claudeDirect.direct`)}):bt(t,n)]}),detail:P?t.availabilityReason??n(`clients.comingSoonDetail`):[ht(t)===`installed`?n(`clients.detected`,{version:gt(t)??``}):n(`clients.notDetected`),U?null:B].filter(Boolean).join(` · `),className:`py-3`,children:[!P&&(0,Z.jsx)(Tt,{client:t,onOpen:ue}),U?(0,Z.jsx)(A,{variant:`primary`,onClick:()=>document.getElementById(Dt)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:n(`clients.claudeDirect.configure`)}):t.enabled?(0,Z.jsx)(A,{onClick:()=>void He(),loading:f.isPending,children:n(`clients.disableRestore`)}):(0,Z.jsx)(A,{variant:`primary`,disabled:P||!t.providerId||V&&!K,onClick:()=>D(!0),title:t.providerId?V&&!K?n(`clients.roleMapRequired`):void 0:n(`clients.pickProviderFirst`),children:n(`clients.enable`)})]}),!U&&t.appliedAt&&(0,Z.jsx)(E,{label:(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`clients.appliedAt`,{time:i(t.appliedAt,a)})})})]}),!P&&!t.enabled&&V&&t.providerId&&!K&&(0,Z.jsxs)(`div`,{className:`mb-5 flex flex-col items-start gap-2`,children:[(0,Z.jsx)(j,{tone:`info`,className:`self-stretch`,title:n(`clients.roleMapHint`)}),(0,Z.jsx)(A,{onClick:()=>document.getElementById(Ot)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:n(`clients.roleMapGoto`)})]}),(t.repairs?.length??0)>0&&(0,Z.jsxs)(`div`,{className:`mb-5 flex flex-col items-start gap-2`,children:[(0,Z.jsxs)(j,{tone:`danger`,className:`self-stretch`,title:n(`clients.repair.title`,{name:F}),children:[t.repairs?.map(e=>(0,Z.jsxs)(`span`,{className:`block break-all`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.file}),` — `,n(`clients.repair.problem.${e.problem}`,{line:e.line})]},e.file)),(0,Z.jsx)(`span`,{className:`block`,children:n(`clients.repair.hint`)})]}),(0,Z.jsx)(A,{variant:`primary`,loading:m.isPending,onClick:()=>m.mutate(t.kind,{onSuccess:()=>c(n(`clients.repair.done`,{name:F}),`success`),onError:e=>c(I(e),`error`)}),children:n(`clients.repair.action`)})]}),!U&&t.warnings.length>0&&(0,Z.jsx)(`div`,{className:`mb-5 flex flex-col gap-2`,children:t.warnings.map((e,t)=>(0,Z.jsx)(j,{tone:`warning`,title:e},t))}),!U&&(0,Z.jsx)(Ct,{client:t,providers:u.data??[],loading:u.isLoading,soon:P}),!U&&me&&(0,Z.jsx)(M,{title:n(`clients.accountTitle`),footer:n(`clients.accountFooter`),children:ge.isLoading?(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsx)(N,{lines:2})}):(0,Z.jsxs)(E,{label:n(`clients.account`),children:[(0,Z.jsx)(z,{className:`max-w-[300px]`,ariaLabel:n(`clients.account`),value:y,onChange:b,options:[{value:``,label:n(`clients.accountDefault`)},...(ge.data??[]).map(e=>({value:e.id,label:(e.displayName||e.id)+(e.status===`active`?``:` · ${n(`providers.subscription.status.${e.status}`)}`)}))]}),y!==(t.accountId??``)&&(0,Z.jsx)(A,{size:`sm`,variant:`primary`,loading:d.isPending,onClick:Ve,children:n(`common.apply`)})]})}),!P&&!U&&(0,Z.jsxs)(M,{title:n(`clients.tokenTitle`),footer:t.enabled?n(`clients.tokenFooterEnabled`):n(`clients.tokenFooter`),children:[(0,Z.jsxs)(E,{label:n(`clients.token`),children:[(0,Z.jsx)(z,{className:`max-w-[300px]`,ariaLabel:n(`clients.token`),value:C,onChange:T,options:ee}),t.enabled&&C!==S&&(0,Z.jsx)(A,{size:`sm`,variant:`primary`,onClick:()=>D(!0),children:n(`common.apply`)})]}),(0,Z.jsx)(E,{icon:(0,Z.jsx)(Oe,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`clients.manageTokens`),onClick:()=>o(`/tokens`)})]}),!P&&!U&&t.providerId&&V&&(0,Z.jsx)(`div`,{id:Ot,children:(0,Z.jsxs)(M,{title:n(`clients.roleMapTitle`),footer:t.enabled?n(`clients.roleMapFooterEnabled`):n(`clients.roleMapFooter`),children:[Q.map(e=>(0,Z.jsx)(E,{label:n(`clients.role.${e}`),children:(0,Z.jsx)(z,{ariaLabel:n(`clients.role.${e}`),value:G[e]??``,onChange:t=>ve(n=>({...n,[e]:t||void 0})),placeholder:n(`clients.modelPlaceholder`),options:[{value:``,label:n(`clients.modelUnset`)},...(g.data??[]).map(e=>({value:e,label:e}))],className:`max-w-[300px]`})},e)),t.enabled&&ye&&(0,Z.jsx)(E,{label:K?``:(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--warning)]`,children:n(`clients.roleMapRequired`)}),children:(0,Z.jsx)(A,{size:`sm`,variant:`primary`,disabled:!K,onClick:()=>D(!0),children:n(`common.apply`)})})]})}),!P&&!U&&t.providerId&&!V&&(0,Z.jsxs)(M,{title:n(`clients.modelTitle`),footer:Te,children:[(0,Z.jsx)(E,{label:n(`clients.defaultModel`),children:(0,Z.jsx)(z,{value:_??``,onChange:e=>v(e||null),placeholder:n(`clients.modelPlaceholder`),options:[{value:``,label:n(`clients.modelUnset`)},...(g.data??[]).map(e=>({value:e,label:e}))],className:`max-w-[300px]`})}),we.map(e=>(0,Z.jsx)(E,{label:n(`clients.modelSlot.${e}`),children:(0,Z.jsx)(z,{ariaLabel:n(`clients.modelSlot.${e}`),value:xe[e]??``,onChange:t=>Se(n=>({...n,[e]:t||void 0})),placeholder:n(`clients.modelPlaceholder`),options:[{value:``,label:n(`clients.modelUnset`)},...(g.data??[]).map(e=>({value:e,label:e}))],className:`max-w-[300px]`})},e)),t.enabled&&(H?Ce:(_??null)!==(t.selectedModel??null))&&(0,Z.jsx)(E,{label:``,children:(0,Z.jsx)(A,{size:`sm`,variant:`primary`,onClick:()=>D(!0),children:n(`common.apply`)})})]}),!P&&!U&&q.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(qe,{descriptors:q,values:ke,onChange:je,enabled:t.enabled}),t.enabled&&Me&&(0,Z.jsx)(`div`,{className:`-mt-3 mb-5 flex justify-end`,children:(0,Z.jsx)(A,{size:`sm`,variant:`primary`,onClick:()=>D(!0),children:n(`common.apply`)})})]}),!P&&Ne.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(nt,{models:Ne,supported:Y,values:Ie,onChange:Le,enabled:t.enabled}),t.enabled&&Re&&(0,Z.jsx)(`div`,{className:`-mt-3 mb-5 flex justify-end`,children:(0,Z.jsx)(A,{size:`sm`,variant:`primary`,onClick:()=>D(!0),children:n(`common.apply`)})})]}),!P&&t.install&&(0,Z.jsx)(kt,{client:t,onShowLog:()=>ue(`log`)}),H&&(0,Z.jsx)(`div`,{id:Dt,children:(0,Z.jsx)(We,{enabled:H,gatewayEnabled:t.enabled})}),!P&&!U&&(0,Z.jsxs)(M,{title:n(`clients.maintenance`),children:[B&&(0,Z.jsx)(E,{icon:L.canOpenPaths?(0,Z.jsx)(he,{className:`size-4 text-[var(--text-secondary)]`}):(0,Z.jsx)(ne,{className:`size-4 text-[var(--text-secondary)]`}),label:L.canOpenPaths?n(`clients.openConfigDir`):n(`clients.copyConfigPath`),detail:B,onClick:()=>void Ue()}),(0,Z.jsx)(E,{icon:(0,Z.jsx)(Fe,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`clients.backups`),detail:n(`clients.backupsDetail`),onClick:()=>ce(!0)})]}),(0,Z.jsx)(jt,{open:ie,onOpenChange:D,client:t,model:_,extras:ze,tokenId:C}),(0,Z.jsx)(Pt,{open:k,onOpenChange:ce,client:t}),(0,Z.jsx)(At,{mode:le,onClose:()=>ue(null),client:t})]})}function St(e,t){return[e.priceKey??e.templateId,t(`providers.modelCount`,{count:e.modelCount}),e.priceMultiplier===1?null:`×${e.priceMultiplier}`].filter(Boolean).join(` · `)}function Ct({client:e,providers:t,loading:n,soon:r}){let{t:i}=w(),{toast:a}=R(),o=f(),s=(0,X.useMemo)(()=>e.bindings??(e.providerId?[{providerId:e.providerId,accountId:e.accountId}]:[]),[e.bindings,e.providerId,e.accountId]),[c,l]=(0,X.useState)(s);(0,X.useEffect)(()=>l(s),[s]);let u=(0,X.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),d=c.flatMap(e=>{let t=u.get(e.providerId);return t?[{binding:e,provider:t}]:[]}),p=t.filter(e=>e.enabled&&!c.some(t=>t.providerId===e.id)),m=H(Se(V,{activationConstraint:{distance:4}}),Se(be,{coordinateGetter:ye})),h=r||o.isPending,g=(t,n)=>{let r=c;l(t),o.mutate({kind:e.kind,bindings:t},{onSuccess:()=>a(ft.has(e.kind)&&e.enabled?i(`clients.providersModelsSynced`,{client:J(e.kind,e.name)}):n),onError:e=>{l(r),a(I(e),`error`)}})},_=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=c.findIndex(t=>t.providerId===e.id),r=c.findIndex(e=>e.providerId===t.id);n<0||r<0||g(G(c,n,r),i(`clients.providerOrderSaved`))},v=e=>g([...c,{providerId:e.id}],i(`clients.providerAdded`,{provider:e.name})),y=e=>g(c.filter(t=>t.providerId!==e.id),i(`clients.providerRemoved`,{provider:e.name})),b=p.map(e=>(0,Z.jsx)(E,{icon:(0,Z.jsx)(Y,{name:e.name,icon:e.icon,colorKey:e.templateId,size:24}),label:e.name,detail:St(e,i),onClick:h?void 0:()=>v(e),children:!r&&(0,Z.jsx)(Ne,{className:`size-4 text-[var(--text-secondary)]`,"aria-label":i(`common.add`)})},e.id));return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(M,{title:i(`clients.providerTitle`),footer:i(`clients.providerFooter`),children:[n&&(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsx)(N,{lines:2})}),!n&&d.length===0&&p.length===0&&(0,Z.jsx)(C,{title:i(`clients.noProviders`),detail:i(`clients.noProvidersDetail`),action:(0,Z.jsx)(ke,{to:`/providers?new=1`,children:(0,Z.jsx)(A,{variant:`primary`,icon:(0,Z.jsx)(Ne,{className:`size-3.5`}),children:i(`providers.add`)})})}),d.length>0&&(0,Z.jsx)(ve,{sensors:m,collisionDetection:W,onDragEnd:_,children:(0,Z.jsx)(xe,{items:d.map(e=>e.provider.id),strategy:ge,children:d.map(({provider:e},t)=>(0,Z.jsx)(wt,{provider:e,primary:t===0,disabled:h,onRemove:d.length>1?()=>y(e):void 0},e.id))})}),!n&&d.length===0&&b]}),d.length>0&&p.length>0&&(0,Z.jsx)(M,{title:i(`clients.moreProvidersTitle`),children:b})]})}function wt({provider:e,primary:t,disabled:n,onRemove:r}){let{t:i}=w(),{attributes:a,listeners:o,setNodeRef:s,setActivatorNodeRef:c,transform:l,transition:u,isDragging:d}=U({id:e.id,disabled:n});return(0,Z.jsx)(`div`,{ref:s,style:{transform:_e.Transform.toString(l),transition:u},className:k(d&&`relative z-10 bg-[var(--surface)] shadow-lg`),children:(0,Z.jsx)(E,{icon:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{ref:c,type:`button`,"aria-label":i(`clients.dragToReorder`,{provider:e.name}),title:i(`clients.dragToReorder`,{provider:e.name}),className:`-ml-1 inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing disabled:cursor-default disabled:opacity-50`,...a,...o,children:(0,Z.jsx)(K,{className:`size-4`})}),(0,Z.jsx)(Y,{name:e.name,icon:e.icon,colorKey:e.templateId,size:24})]}),label:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),t&&(0,Z.jsx)(O,{tone:`accent`,children:i(`clients.primaryProvider`)}),!e.enabled&&(0,Z.jsx)(O,{tone:`orange`,children:i(`clients.providerDisabledBadge`)})]}),detail:St(e,i),children:r&&(0,Z.jsx)(A,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ee,{className:`size-3.5`}),"aria-label":i(`clients.removeProvider`,{provider:e.name}),title:i(`clients.removeProvider`,{provider:e.name}),disabled:n,onClick:r})})})}function Tt({client:e,onOpen:t}){let{t:n}=w(),r=e.install;if(!r)return null;let i=r.needsAdmin?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-[var(--warning)]`,children:[(0,Z.jsx)(ze,{className:`size-3`,"aria-hidden":!0}),n(`clients.admin.badge`)]}):null,a=r.needsAdmin?n(r.adminAvailable?`clients.admin.tip`:`clients.admin.tipManual`):void 0;return r.busy?(0,Z.jsx)(A,{icon:(0,Z.jsx)(yt,{}),onClick:()=>t(`log`),children:n(`clients.installRunning`)}):r.updateAvailable&&r.updateCommand&&r.latestVersion?(0,Z.jsxs)(A,{icon:(0,Z.jsx)(Le,{className:`size-3.5`}),title:a,onClick:()=>t(`update`),children:[n(`clients.updateTo`,{version:r.latestVersion}),i]}):r.updateAvailable&&r.blocker===`shadowed`?(0,Z.jsx)(A,{icon:(0,Z.jsx)(ze,{className:`size-3.5`}),onClick:()=>document.getElementById(Et)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:n(`clients.shadowedBadge`)}):!r.installed&&r.installCommand?(0,Z.jsxs)(A,{icon:(0,Z.jsx)(pe,{className:`size-3.5`}),title:a,onClick:()=>t(`install`),children:[n(`clients.install`),i]}):!r.installed&&r.method===`manual`?(0,Z.jsx)(A,{icon:(0,Z.jsx)(me,{className:`size-3.5`}),onClick:()=>window.open(r.homepageUrl,`_blank`,`noreferrer`),children:n(`clients.download`)}):null}var Et=`client-shadowed-alert`,Dt=`claude-direct-panel`,Ot=`client-role-map`;function kt({client:e,onShowLog:t}){let{t:n,locale:r}=w(),a=e.install,o=ce(e.kind),s=(e,t=!1)=>(0,Z.jsx)(`span`,{className:k(`text-[13px] tabular-nums selectable`,t&&`text-[var(--text-secondary)]`),children:e}),c=a.blocker===`external-install`?n(`clients.blocker.external-install`,{path:a.executable??``}):a.blocker?n(`clients.blocker.${a.blocker}`):void 0,l=a.otherCopies??[],u=l.find(e=>e.newer);return(0,Z.jsxs)(Z.Fragment,{children:[u&&(0,Z.jsx)(`div`,{id:Et,className:`mb-3`,children:(0,Z.jsx)(j,{tone:`warning`,title:n(`clients.shadowed.title`,{version:u.version}),children:n(`clients.shadowed.detail`,{path:a.executable??``,version:a.version??``,other:u.path,dir:de(u.path)})})}),!u&&a.notOnPath&&a.executable&&(0,Z.jsx)(`div`,{className:`mb-3`,children:(0,Z.jsx)(j,{tone:`warning`,title:n(`clients.notOnPath.title`),children:n(`clients.notOnPath.detail`,{dir:de(a.executable)})})}),(0,Z.jsxs)(M,{title:n(`clients.versionTitle`),footer:c,children:[(0,Z.jsx)(E,{label:n(`clients.currentVersion`),detail:a.installed?a.executable:void 0,children:a.installed?s(a.version??n(`clients.versionUnknown`),!a.version):s(n(`clients.notInstalled`),!0)}),l.map(e=>(0,Z.jsxs)(E,{label:n(`clients.otherCopy`),detail:e.path,children:[e.newer&&(0,Z.jsx)(O,{tone:`orange`,children:n(`clients.otherCopyNewer`)}),s(e.version,!e.newer)]},e.path)),(a.method===`npm`||a.method===`script`)&&(0,Z.jsxs)(E,{label:n(`clients.latestVersion`),detail:a.latestError??(a.latestCheckedAt?n(`clients.checkedAt`,{time:i(a.latestCheckedAt,r)}):void 0),children:[a.updateAvailable&&(0,Z.jsx)(O,{tone:`orange`,children:n(`clients.updateBadge`)}),s(a.latestVersion??n(`clients.latestUnknown`),!a.latestVersion)]}),(0,Z.jsx)(E,{label:n(`clients.installMethod`),detail:n(`clients.method.${a.method}`,{package:a.package??``}),children:(0,Z.jsx)(A,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(me,{className:`size-3`}),onClick:()=>window.open(a.homepageUrl,`_blank`,`noreferrer`),children:n(`clients.homepage`)})}),o.data&&(0,Z.jsx)(E,{icon:(0,Z.jsx)(q,{className:`size-4 text-[var(--text-secondary)]`}),label:n(`clients.installLog`),detail:`${o.data.command} · ${n(`clients.job.${o.data.state}`)}`,onClick:t})]})]})}function At({mode:e,onClose:n,client:r}){let{t:i}=w(),{toast:o}=R(),s=ie(),c=e!==null,l=ce(r.kind,c||!!r.install?.busy),d=u(),f=a(),[p,m]=(0,X.useState)(!1),h=(0,X.useRef)(null),g=(0,X.useRef)(void 0),_=J(r.kind,r.name),v=r.install,y=e===`install`||e===`update`?e:null,b=y===`install`?v?.installCommand:y===`update`?v?.updateCommand:null,x=l.data,S=y!==null&&!p&&x?.state!==`running`,T=!!v?.needsAdmin,ee=!!v?.adminAvailable,te=x?.state===`failed`&&x.hint===`permission-denied`&&!x.elevated&&ee;(0,X.useEffect)(()=>{c&&m(!1)},[c,e]),(0,X.useEffect)(()=>{let e=x?.state;g.current===`running`&&e&&e!==`running`&&(s.invalidateQueries({queryKey:t.clients}),e===`succeeded`&&x.hint?o(i(`clients.notEffectiveToast`,{name:_})):e===`succeeded`&&o(i(x.action===`install`?`clients.installedToast`:`clients.updatedToast`,{name:_}),`success`)),g.current=e},[x?.state,x?.action,x?.hint,_,s,i,o]),(0,X.useEffect)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[x?.log.length]);let re=(e,t)=>d.mutate({kind:r.kind,action:e,elevated:t},{onSuccess:()=>m(!0),onError:e=>o(I(e),`error`)}),ae=async e=>{await L.copy(e)&&o(i(`common.copied`))},E=i((y??x?.action)===`update`?`clients.updateTitle`:`clients.installTitle`,{name:_}),D={running:`info`,succeeded:`success`,failed:`danger`,cancelled:`warning`},O=`rounded-[var(--radius-control)] border border-[var(--border)] bg-[var(--surface-muted)] px-3 py-2 font-mono text-[12px] break-all whitespace-pre-wrap selectable`,oe=v?.adminFixCommand?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-secondary)]`,children:i(`clients.admin.fixTip`)}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`pre`,{className:k(O,`min-w-0 flex-1`),children:v.adminFixCommand}),(0,Z.jsx)(A,{size:`sm`,icon:(0,Z.jsx)(ne,{className:`size-3`}),"aria-label":i(`common.copy`),onClick:()=>void ae(v.adminFixCommand)})]})]}):null;return(0,Z.jsx)(fe,{open:c,onOpenChange:e=>!e&&n(),width:620,title:E,description:S?i(`clients.installRunDetail`):void 0,footer:S?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A,{onClick:n,children:i(`common.cancel`)}),T&&!ee?(0,Z.jsx)(A,{variant:`primary`,icon:(0,Z.jsx)(ne,{className:`size-3.5`}),disabled:!b,onClick:()=>void ae(`sudo ${b}`),children:i(`clients.admin.copyCommand`)}):(0,Z.jsx)(A,{variant:`primary`,icon:T?(0,Z.jsx)(ze,{className:`size-3.5`}):void 0,disabled:!b,loading:d.isPending,onClick:()=>y&&re(y,T),children:i(T?`clients.admin.start`:`clients.installStart`)})]}):x?.state===`running`?(0,Z.jsxs)(Z.Fragment,{children:[!x.elevated&&(0,Z.jsx)(A,{variant:`destructive`,loading:f.isPending,onClick:()=>f.mutate(r.kind,{onError:e=>o(I(e),`error`)}),children:i(`clients.installStop`)}),(0,Z.jsx)(A,{onClick:n,children:i(`common.close`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A,{onClick:n,children:i(`common.done`)}),te&&(0,Z.jsx)(A,{variant:`primary`,icon:(0,Z.jsx)(ze,{className:`size-3.5`}),loading:d.isPending,onClick:()=>re(x.action,!0),children:i(`clients.admin.retry`)})]}),children:S?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[T&&(0,Z.jsx)(j,{tone:`warning`,title:i(`clients.admin.title`),children:i(ee?`clients.admin.prompt`:`clients.admin.manual`)}),b?(0,Z.jsx)(`pre`,{className:O,children:T?`sudo ${b}`:b}):(0,Z.jsx)(j,{tone:`warning`,title:i(`clients.installUnavailable`)}),v?.method===`npm`&&(0,Z.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`clients.installNpmNote`)}),T&&oe]}):x?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(j,{tone:x.state===`succeeded`&&x.hint?`warning`:D[x.state],title:i(x.state===`succeeded`&&x.hint?`clients.job.notEffective`:`clients.job.${x.state}`),children:x.state===`running`&&x.elevated?i(`clients.admin.running`):x.hint?i(`clients.hint.${x.hint}`)+(te?i(`clients.admin.retryHint`):``):void 0}),(0,Z.jsx)(`pre`,{ref:h,className:`scroll max-h-[340px] min-h-[160px] rounded-[var(--radius-control)] border border-[var(--border)] bg-[var(--surface-muted)] px-3 py-2 font-mono text-[11px] leading-relaxed break-all whitespace-pre-wrap selectable`,children:x.log.join(`
7
+ `)}),x.hint===`permission-denied`&&oe]}):l.isLoading?(0,Z.jsx)(N,{lines:4}):(0,Z.jsx)(C,{icon:(0,Z.jsx)(q,{className:`size-6`}),title:i(`clients.noInstallLog`)})})}function jt({open:e,onOpenChange:t,client:n,model:r,extras:i,tokenId:a}){let{t:o}=w(),{toast:s}=R(),c=v(),l=D(),u=J(n.kind,n.name),d=i?{providerId:n.providerId,model:r,extras:i,tokenId:a}:{providerId:n.providerId,model:r,tokenId:a};return(0,X.useEffect)(()=>{e&&c.mutate({kind:n.kind,req:d})},[e]),(0,Z.jsxs)(fe,{open:e,onOpenChange:t,width:620,title:o(`clients.enableTitle`,{name:u}),description:o(`clients.enableDetail`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A,{onClick:()=>t(!1),children:o(`common.cancel`)}),(0,Z.jsx)(A,{variant:`primary`,disabled:!c.data,loading:l.isPending,onClick:()=>l.mutate({kind:n.kind,req:d},{onSuccess:e=>{t(!1),s(e.requiresRestart?o(`clients.enabledRestart`,{name:u}):o(`clients.enabledToast`,{name:u}),`success`)},onError:e=>s(I(e),`error`)}),children:n.enabled?o(`common.apply`):o(`clients.enable`)})]}),children:[c.isPending&&(0,Z.jsx)(N,{lines:4}),c.isError&&(0,Z.jsx)(j,{tone:`danger`,title:o(`common.error`),children:I(c.error)}),c.data&&(0,Z.jsx)(Mt,{preview:c.data})]})}function Mt({preview:e}){let{t}=w();return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[e.warnings.map((e,t)=>(0,Z.jsx)(j,{tone:`warning`,title:e},t)),e.changes.length===0&&(0,Z.jsx)(j,{tone:`info`,title:t(`clients.noChanges`)}),e.diffs.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`mb-2 font-mono text-[11px] text-[var(--text-secondary)]`,children:e.file}),(0,Z.jsx)(Nt,{diff:e.unifiedDiff})]},e.file))]})}function Nt({diff:e}){return(0,Z.jsx)(`pre`,{className:`scroll max-h-[300px] rounded-[var(--radius-control)] border border-[var(--border)] bg-[var(--surface-muted)] py-2 font-mono text-[11px] leading-relaxed selectable`,children:e.split(`
8
+ `).map((e,t)=>(0,Z.jsx)(`div`,{className:k(`px-3 whitespace-pre-wrap break-all`,e.startsWith(`+`)&&!e.startsWith(`+++`)&&`bg-[color-mix(in_oklab,var(--success)_12%,transparent)] text-[var(--success)]`,e.startsWith(`-`)&&!e.startsWith(`---`)&&`bg-[color-mix(in_oklab,var(--danger)_10%,transparent)] text-[var(--danger)]`,e.startsWith(`@@`)&&`text-[var(--text-muted)]`),children:e||` `},t))})}function Pt({open:e,onOpenChange:t,client:n}){let{t:r,locale:a}=w(),{toast:o,confirm:s}=R(),c=g(n.kind,e),l=ue();return(0,Z.jsxs)(fe,{open:e,onOpenChange:t,width:520,title:r(`clients.backups`),description:r(`clients.backupsDetail`),footer:(0,Z.jsx)(A,{onClick:()=>t(!1),children:r(`common.done`)}),children:[c.isLoading&&(0,Z.jsx)(N,{lines:3}),c.isError&&(0,Z.jsx)(j,{tone:`danger`,title:r(`common.error`),children:I(c.error)}),c.data?.length===0&&(0,Z.jsx)(C,{icon:(0,Z.jsx)(Fe,{className:`size-6`}),title:r(`clients.noBackups`)}),(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:c.data?.map(e=>(0,Z.jsx)(E,{label:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[i(e.createdAt,a),e.firstWrite&&(0,Z.jsx)(O,{tone:`accent`,children:r(`clients.firstWrite`)})]}),detail:e.files.join(`, `),children:(0,Z.jsx)(A,{size:`sm`,icon:(0,Z.jsx)(Ce,{className:`size-3`}),loading:l.isPending&&l.variables?.id===e.id,onClick:async()=>{await s({title:r(`clients.restoreConfirm`),detail:e.files.join(`
9
+ `),destructive:!0,confirmLabel:r(`clients.restore`)})&&l.mutate({kind:n.kind,id:e.id},{onSuccess:()=>o(r(`clients.restored`),`success`),onError:e=>o(I(e),`error`)})},children:r(`clients.restore`)})},e.id))})]})}export{dt as ClientsPage};
@@ -0,0 +1 @@
1
+ import{Ct as e,G as t,H as n,Ia as r,J as i,Ma as a,Na as o,Q as s,St as c,Tt as l,Y as u,_ as d,ct as f,n as p,q as m,r as h,t as g,wt as _}from"./alert-qNPoglGp.js";import{A as v,_ as y,k as b}from"./index-DDjZdUEf.js";var x=r(o(),1),S=a(),C=`astra.keyLookup`;function w(){try{return sessionStorage.getItem(C)??``}catch{return``}}function T(e){try{e?sessionStorage.setItem(C,e):sessionStorage.removeItem(C)}catch{}}function E(){let{t}=f(),[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(``),[l,u]=(0,x.useState)(null),[d,p]=(0,x.useState)(!1),m=(0,x.useCallback)(async n=>{let r=n.trim();if(r){p(!0),u(null);try{a(await e(r)),s(r),T(r)}catch(e){a(null),T(null),u(e instanceof c&&e.status===401?t(`key.invalid`):t(`key.error`,{error:e.message}))}finally{p(!1)}}},[t]);return(0,x.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get(`key`);e&&window.history.replaceState(null,``,window.location.pathname);let t=e??w();t&&(r(t),m(t))},[]),(0,S.jsx)(`div`,{className:`wallpaper flex min-h-full justify-center overflow-y-auto p-4 sm:items-start sm:py-12`,children:(0,S.jsxs)(`div`,{className:`flex w-full max-w-[720px] flex-col gap-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(v,{className:`size-10 rounded-[12px]`}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-[17px] font-medium`,children:t(`key.title`)}),(0,S.jsx)(`p`,{className:`text-[13px] text-[var(--text-secondary)]`,children:t(`key.subtitle`)})]})]}),!i&&(0,S.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m(n)},className:`card flex flex-col gap-4 p-5`,children:[(0,S.jsx)(b,{label:t(`key.title`),placeholder:t(`key.placeholder`),autoFocus:!0,autoComplete:`off`,value:n,"aria-invalid":l?!0:void 0,onChange:e=>r(e.target.value)}),l&&(0,S.jsx)(g,{tone:`danger`,title:l}),(0,S.jsx)(h,{type:`submit`,variant:`primary`,loading:d,disabled:!n.trim(),children:t(`key.submit`)})]}),i&&(0,S.jsx)(D,{info:i,apiKey:o,onForget:()=>{T(null),a(null),r(``)}})]})})}function D({info:e,apiKey:t,onForget:r}){let{t:i,locale:a}=f(),[o,c]=(0,x.useState)(`overview`),l=e.allowedClients==null?i(`key.clientsAny`):e.allowedClients.length===0?i(`key.directOnly`):e.allowedClients.map(e=>y[e]?.name??e).join(`, `),m=[[i(`key.today`),e.usage.today],[i(`key.week`),e.usage.week],[i(`key.month`),e.usage.month],[i(`key.total`),e.usage.total]],g=Math.max(...e.daily.map(e=>e.costUsd),0);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`section`,{className:`card flex flex-col gap-3 p-5`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,S.jsx)(`h2`,{className:`text-[15px] font-medium`,children:e.name}),(0,S.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)]`,children:e.keyPrefix}),!e.enabled&&(0,S.jsx)(p,{tone:`orange`,children:i(`key.disabled`)}),(0,S.jsx)(h,{size:`sm`,variant:`plain`,className:`ml-auto`,onClick:r,children:i(`key.forget`)})]}),(0,S.jsxs)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:[i(`key.clients`),`: `,l,` · `,i(`key.timeZone`,{zone:e.timeZone})]}),(0,S.jsx)(d,{ariaLabel:i(`key.title`),value:o,onChange:c,items:[{value:`overview`,label:i(`key.tab.overview`)},{value:`stats`,label:i(`key.tab.stats`)},{value:`requests`,label:i(`key.tab.requests`)}]})]}),o===`stats`&&(0,S.jsx)(k,{apiKey:t}),o===`requests`&&(0,S.jsx)(M,{apiKey:t}),o===`overview`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`section`,{className:`card flex flex-col gap-3 p-5`,children:[(0,S.jsx)(`h3`,{className:`text-[13px] font-medium`,children:i(`key.limits`)}),e.limits.length===0&&e.rpm==null&&(0,S.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:i(`key.unlimited`)}),(0,S.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:e.limits.map(e=>{let t=t=>e.metric===`cost`?s(t):u(t,!0),r=Math.max(0,Math.min(100,Math.round(e.usedPercent))),o=r>=90?`var(--danger)`:r>=70?`var(--warning)`:`var(--accent)`,c=`${i(`tokens.period.${e.period}`)} · ${i(`tokens.metric.${e.metric}`)}`;return(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[12px]`,children:[(0,S.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:c}),(0,S.jsxs)(`span`,{className:`num`,children:[t(e.used),` / `,t(e.limit)]})]}),(0,S.jsx)(`div`,{role:`progressbar`,"aria-label":c,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface-muted)]`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${r}%`,background:o}})}),(0,S.jsxs)(`div`,{className:`mt-1 text-[11px] text-[var(--text-muted)]`,children:[e.exhausted?i(`key.exhausted`):``,e.exhausted&&e.resetsAt?` · `:``,e.resetsAt?i(`key.resets`,{time:n(e.resetsAt,a)}):``]})]},`${e.metric}:${e.period}`)})}),e.rpm&&(0,S.jsx)(`p`,{className:`num text-[12px] text-[var(--text-secondary)]`,children:i(`key.rpm`,{used:e.rpm.used,limit:e.rpm.limit})})]}),(0,S.jsxs)(`section`,{className:`card flex flex-col gap-3 p-5`,children:[(0,S.jsx)(`h3`,{className:`text-[13px] font-medium`,children:i(`key.usage`)}),(0,S.jsx)(`div`,{className:`overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`text-[var(--text-muted)]`,children:[(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:i(`key.cost`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:i(`key.requests`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:i(`key.tokens`)})]})}),(0,S.jsx)(`tbody`,{children:m.map(([e,t])=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{scope:`row`,className:`py-1 text-left font-medium text-[var(--text-secondary)]`,children:e}),(0,S.jsx)(`td`,{className:`num py-1 text-right font-semibold`,children:s(t.costUsd)}),(0,S.jsx)(`td`,{className:`num py-1 text-right`,children:u(t.requests)}),(0,S.jsx)(`td`,{className:`num py-1 text-right`,children:u(t.inputTokens+t.outputTokens,!0)})]},e))})]})}),(0,S.jsx)(`h4`,{className:`mt-2 text-[12px] text-[var(--text-muted)]`,children:i(`key.daily`)}),(0,S.jsx)(`div`,{className:`flex h-24 items-end gap-[2px]`,role:`list`,"aria-label":i(`key.daily`),children:e.daily.map(e=>(0,S.jsx)(`div`,{role:`listitem`,title:`${e.day} · ${s(e.costUsd)} · ${u(e.requests)} ${i(`key.requests`)}`,className:`flex-1 rounded-t-[2px] bg-[var(--accent)]`,style:{height:`${g>0?Math.max(2,e.costUsd/g*100):2}%`,opacity:e.costUsd>0?1:.25}},e.day))})]})]})]})}var O=[`today`,`7d`,`30d`,`90d`];function k({apiKey:e}){let{t:n}=f(),[r,i]=(0,x.useState)(`7d`),[a,o]=(0,x.useState)(null),[c,h]=(0,x.useState)(null);(0,x.useEffect)(()=>{let t=!0;return h(null),l(e,r).then(e=>t&&o(e),e=>t&&h(n(`key.error`,{error:e.message}))),()=>{t=!1}},[e,r,n]);let _=a?.summary,v=Math.max(...(a?.series??[]).map(e=>e.requests),0);return(0,S.jsxs)(`section`,{className:`card flex flex-col gap-4 p-5`,children:[(0,S.jsx)(d,{ariaLabel:n(`overview.range`),value:r,onChange:i,items:O.map(e=>({value:e,label:n(`range.${e}`)}))}),c&&(0,S.jsx)(g,{tone:`danger`,title:c}),!a||!_?!c&&(0,S.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:`…`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,S.jsx)(A,{label:n(`key.stats.requests`),value:u(_.requests)}),(0,S.jsx)(A,{label:n(`key.stats.successRate`),value:_.requests?m(_.successRate):`—`}),(0,S.jsx)(A,{label:n(`key.cost`),value:s(_.costUsd)}),(0,S.jsx)(A,{label:n(`key.stats.avgTtft`),value:t(_.avgTtftMs)})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h4`,{className:`mb-2 text-[12px] text-[var(--text-muted)]`,children:n(`key.stats.trend`)}),(0,S.jsx)(`div`,{className:`flex h-20 items-end gap-[2px]`,role:`list`,"aria-label":n(`key.stats.trend`),children:a.series.map(e=>(0,S.jsx)(`div`,{role:`listitem`,title:`${e.bucket} · ${u(e.requests)} ${n(`key.requests`)} · ${s(e.costUsd)}`,className:`flex-1 rounded-t-[2px] bg-[var(--accent)]`,style:{height:`${v>0?Math.max(2,e.requests/v*100):2}%`}},e.bucket))})]}),(0,S.jsx)(j,{title:n(`key.stats.byModel`),rows:a.models.map(e=>({name:e.model??`—`,...e}))}),(0,S.jsx)(j,{title:n(`key.stats.byClient`),rows:a.clients.map(e=>({name:e.client?y[e.client]?.name??e.client:n(`key.stats.direct`),...e}))}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h4`,{className:`mb-2 text-[12px] text-[var(--text-muted)]`,children:n(`key.stats.errors`)}),a.errors.length===0?(0,S.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:n(`key.stats.noErrors`)}):(0,S.jsx)(`ul`,{className:`flex flex-wrap gap-2`,children:a.errors.map(e=>(0,S.jsx)(`li`,{children:(0,S.jsxs)(p,{tone:`orange`,children:[n(`key.category.${e.category}`),` · `,u(e.count)]})},e.category))})]}),a.retentionDays!=null&&(0,S.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`key.stats.retention`,{days:a.retentionDays})})]})]})}function A({label:e,value:t}){return(0,S.jsxs)(`div`,{className:`min-w-0`,children:[(0,S.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,S.jsx)(`div`,{className:`num truncate text-[17px] font-semibold`,children:t})]})}function j({title:e,rows:t}){let{t:n}=f();return t.length===0?null:(0,S.jsx)(`div`,{className:`overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,S.jsx)(`caption`,{className:`mb-1 text-left text-[12px] text-[var(--text-muted)]`,children:e}),(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`text-[var(--text-muted)]`,children:[(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:n(`key.requests`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:n(`key.stats.successRate`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:n(`key.tokens`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:n(`key.cost`)})]})}),(0,S.jsx)(`tbody`,{children:t.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{scope:`row`,className:`max-w-[240px] truncate py-1 text-left font-medium text-[var(--text-secondary)]`,children:e.name}),(0,S.jsx)(`td`,{className:`num py-1 text-right`,children:u(e.requests)}),(0,S.jsx)(`td`,{className:`num py-1 text-right`,children:e.requests?m(e.successRequests/e.requests):`—`}),(0,S.jsx)(`td`,{className:`num py-1 text-right`,children:u(e.inputTokens+e.outputTokens,!0)}),(0,S.jsx)(`td`,{className:`num py-1 text-right font-semibold`,children:s(e.costUsd)})]},e.name))})]})})}function M({apiKey:e}){let{t:r,locale:a}=f(),[o,c]=(0,x.useState)(`all`),[l,m]=(0,x.useState)([]),[v,b]=(0,x.useState)(null),[C,w]=(0,x.useState)(!1),[T,E]=(0,x.useState)(null),D=(0,x.useCallback)(async t=>{w(!0),E(null);try{let n=await _(e,{before:t,status:o===`failed`?N:void 0});m(e=>t?[...e,...n.items]:n.items),b(n.nextBefore??null)}catch(e){E(r(`key.error`,{error:e.message}))}finally{w(!1)}},[e,o,r]);return(0,x.useEffect)(()=>{D(null)},[D]),(0,S.jsxs)(`section`,{className:`card flex flex-col gap-3 p-5`,children:[(0,S.jsx)(d,{ariaLabel:r(`key.requests.status`),value:o,onChange:c,items:[{value:`all`,label:r(`key.requests.all`)},{value:`failed`,label:r(`key.requests.failed`)}]}),T&&(0,S.jsx)(g,{tone:`danger`,title:T}),l.length===0&&!C&&!T&&(0,S.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`key.requests.empty`)}),l.length>0&&(0,S.jsx)(`div`,{className:`overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`text-[var(--text-muted)]`,children:[(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`,children:r(`key.requests.time`)}),(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`,children:r(`key.requests.model`)}),(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`,children:r(`key.requests.client`)}),(0,S.jsx)(`th`,{className:`py-1 text-left font-normal`,children:r(`key.requests.status`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:r(`key.requests.tokens`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:r(`key.cost`)}),(0,S.jsx)(`th`,{className:`py-1 text-right font-normal`,children:r(`key.requests.latency`)})]})}),(0,S.jsx)(`tbody`,{children:l.map(e=>(0,S.jsxs)(`tr`,{className:`border-t border-[var(--border-subtle)]`,children:[(0,S.jsx)(`td`,{className:`py-1.5 whitespace-nowrap text-[var(--text-secondary)]`,title:n(e.time,a),children:i(e.time,a)}),(0,S.jsx)(`td`,{className:`max-w-[200px] truncate py-1.5 font-mono`,title:e.model??``,children:e.model??`—`}),(0,S.jsx)(`td`,{className:`py-1.5 text-[var(--text-secondary)]`,children:e.client?y[e.client]?.name??e.client:r(`key.stats.direct`)}),(0,S.jsx)(`td`,{className:`py-1.5`,children:e.errorCategory?(0,S.jsx)(p,{tone:`orange`,title:e.httpStatus?`HTTP ${e.httpStatus}`:void 0,children:r(`key.category.${e.errorCategory}`)}):(0,S.jsx)(p,{tone:`green`,children:r(`key.requests.success`)})}),(0,S.jsxs)(`td`,{className:`num py-1.5 text-right`,children:[u(e.inputTokens,!0),` / `,u(e.outputTokens,!0)]}),(0,S.jsx)(`td`,{className:`num py-1.5 text-right font-semibold`,children:s(e.costUsd)}),(0,S.jsxs)(`td`,{className:`num py-1.5 text-right text-[var(--text-secondary)]`,children:[t(e.ttftMs),` / `,t(e.totalMs)]})]},e.id))})]})}),v&&(0,S.jsx)(`div`,{children:(0,S.jsx)(h,{size:`sm`,loading:C,onClick:()=>void D(v),children:r(`key.requests.more`)})})]})}var N=`upstream_error,gateway_error,client_cancelled,blocked`;export{E as KeyPage};
@@ -0,0 +1 @@
1
+ import{H as e,Ia as t,Ma as n,Mn as r,Na as i,Xn as a,an as o,ci as s,ct as c,d as l,g as u,in as d,l as f,m as p,n as m,p as h,r as g,rt as _,t as v,u as y,v as b,xi as x,xr as S,y as ee}from"./alert-qNPoglGp.js";import{a as C,i as w,o as T,r as E}from"./overlays-ORpFxiz4.js";import{t as D}from"./arrow-left-D6dVbOnl.js";import{t as O}from"./pencil-jnrNOWQy.js";import{t as k}from"./rotate-ccw-D-Km3lpa.js";import{$ as A,N as j,Q as M,X as te,h as N,i as ne,o as P,z as F}from"./index-DDjZdUEf.js";import{t as I}from"./checkbox-B47xSnbl.js";import{t as L}from"./confirm-morph-CgGgkVSl.js";var R=t(i(),1),z=n(),B=[{key:`vision`,label:`cap.vision`},{key:`tools`,label:`cap.tools`},{key:`reasoning`,label:`cap.reasoning`},{key:`promptCache`,label:`cap.promptCache`},{key:`audio`,label:`cap.audio`},{key:`pdf`,label:`cap.pdf`},{key:`structuredOutput`,label:`cap.structuredOutput`}];function V(e){return{displayName:e.displayName,vendor:e.vendor,family:e.family??null,aliases:e.aliases,contextWindow:e.contextWindow??null,maxOutputTokens:e.maxOutputTokens??null,capabilities:e.capabilities,pricing:e.pricing??null,enabled:e.enabled}}function H(){let{t,locale:n}=c(),i=M(),{id:a=``}=A(),o=decodeURIComponent(a),f=r(o),x=s(o),w=S(o),E=d(),{toast:O}=T(),j=(0,R.useMemo)(()=>f.data?V(f.data):null,[f.data]),[F,L]=(0,R.useState)(j),[H,G]=(0,R.useState)(``);(0,R.useEffect)(()=>{L(j),G(j?.aliases?.join(`, `)??``)},[j]);let q=(0,z.jsx)(g,{variant:`glass`,icon:(0,z.jsx)(D,{className:`size-4`}),"aria-label":t(`common.back`),onClick:()=>i(`/models`)});if(f.isError)return(0,z.jsx)(N,{title:t(`nav.models`),leading:q,children:(0,z.jsx)(v,{tone:`danger`,title:t(`common.error`),children:C(f.error)})});let J=f.data;if(!J||!F)return(0,z.jsx)(N,{title:``,leading:q,children:(0,z.jsx)(b,{lines:5,className:`mx-auto max-w-[1100px]`})});let Y=e=>L(t=>({...t,...e})),X={...F,aliases:H.split(/[,\n]/).map(e=>e.trim()).filter(Boolean)},Z=JSON.stringify(X)!==JSON.stringify(j),re=new Set(J.userModifiedFields),Q=J.source===`seed`,ie=()=>x.mutate(X,{onSuccess:()=>O(t(`common.saved`),`success`),onError:e=>O(C(e),`error`)}),$=e=>re.has(e)?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,z.jsx)(m,{tone:`orange`,children:t(`models.modified`)}),Q&&(0,z.jsx)(g,{size:`sm`,variant:`plain`,icon:(0,z.jsx)(k,{className:`size-3`}),title:t(`models.resetField`),"aria-label":t(`models.resetField`),onClick:()=>w.mutate(e,{onSuccess:()=>O(t(`models.fieldReset`)),onError:e=>O(C(e),`error`)})})]}):null;return(0,z.jsx)(N,{title:J.displayName,subtitle:`${J.id} · ${t(`models.source.${J.source}`)} · ${t(`models.updated`,{time:e(J.updatedAt,n)})}`,leading:q,actions:(0,z.jsxs)(z.Fragment,{children:[J.source===`user`&&(0,z.jsx)(K,{label:t(`common.delete`),prompt:t(`models.deleteConfirm`,{id:J.id}),onConfirm:async()=>{await E.mutateAsync(J.id),i(`/models`)}}),Z&&(0,z.jsx)(g,{onClick:()=>{L(j),G(j?.aliases?.join(`, `)??``)},children:t(`common.revert`)}),(0,z.jsx)(g,{variant:`primary`,disabled:!Z,loading:x.isPending,onClick:ie,children:t(`common.save`)})]}),children:(0,z.jsxs)(`div`,{className:`mx-auto grid max-w-[1100px] gap-x-6 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(y,{title:t(`models.section.basic`),footer:Q?t(`models.modifiedFooter`):void 0,children:[(0,z.jsx)(U,{label:t(`models.field.displayName`),marker:$(`displayName`),children:(0,z.jsx)(l,{className:`w-60`,"aria-label":t(`models.field.displayName`),value:F.displayName,onChange:e=>Y({displayName:e.target.value})})}),(0,z.jsx)(U,{label:t(`models.field.vendor`),children:(0,z.jsx)(l,{className:`w-60`,"aria-label":t(`models.field.vendor`),value:F.vendor,onChange:e=>Y({vendor:e.target.value})})}),(0,z.jsx)(U,{label:t(`models.field.family`),marker:$(`family`),children:(0,z.jsx)(l,{className:`w-60`,"aria-label":t(`models.field.family`),value:F.family??``,onChange:e=>Y({family:e.target.value||null})})}),(0,z.jsx)(U,{label:t(`models.field.aliases`),marker:$(`aliases`),children:(0,z.jsx)(l,{className:`w-60 font-mono`,"aria-label":t(`models.field.aliases`),value:H,onChange:e=>G(e.target.value),placeholder:`a, b, c`})}),(0,z.jsx)(U,{label:t(`models.field.contextWindow`),marker:$(`contextWindow`),children:(0,z.jsx)(h,{className:`w-36`,label:t(`models.field.contextWindow`),value:F.contextWindow,onChange:e=>Y({contextWindow:e})})}),(0,z.jsx)(U,{label:t(`models.field.maxOutputTokens`),marker:$(`maxOutputTokens`),children:(0,z.jsx)(h,{className:`w-36`,label:t(`models.field.maxOutputTokens`),value:F.maxOutputTokens,onChange:e=>Y({maxOutputTokens:e})})}),(0,z.jsx)(U,{label:t(`common.enabled`),children:(0,z.jsx)(ee,{checked:F.enabled??!0,label:t(`common.enabled`),onChange:e=>Y({enabled:e})})})]}),(0,z.jsx)(y,{title:(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t(`models.section.capabilities`),` `,$(`capabilities`)]}),children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-3 px-4 py-4`,children:B.map(e=>(0,z.jsx)(I,{label:t(e.label),checked:!!F.capabilities?.[e.key],onCheckedChange:t=>Y({capabilities:{...F.capabilities,[e.key]:t===!0}})},e.key))})}),(0,z.jsx)(W,{model:J}),J.providerOverrides.length>0&&(0,z.jsx)(y,{title:t(`models.section.overrides`),footer:t(`models.overridesFooter`),children:J.providerOverrides.map(e=>(0,z.jsx)(p,{label:(0,z.jsx)(te,{className:`text-[var(--accent)]`,to:`/providers/${e.providerId}`,children:e.providerName}),detail:`${e.modelId} · ${_(e.pricing)}`},e.providerModelId))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`section`,{className:`mb-5`,children:[(0,z.jsx)(u,{action:$(`pricing`),children:t(`models.section.pricing`)}),(0,z.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--text-secondary)]`,children:t(`models.pricingHint`)}),(0,z.jsx)(`div`,{className:`card p-4`,children:(0,z.jsx)(P,{value:F.pricing??null,onChange:e=>Y({pricing:e}),allowEmpty:!0})})]}),(0,z.jsxs)(`section`,{className:`mb-5`,children:[(0,z.jsx)(u,{children:t(`models.section.simulator`)}),(0,z.jsxs)(`div`,{className:`card p-4`,children:[(0,z.jsx)(ne,{modelId:Z?void 0:J.id,pricing:Z?X.pricing:null}),Z&&(0,z.jsx)(`p`,{className:`mt-3 text-[12px] text-[var(--text-muted)]`,children:t(`models.simulatorUnsaved`)})]})]})]})]})})}function U({label:e,marker:t,children:n}){return(0,z.jsx)(p,{label:(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e,t]}),children:n})}function W({model:e}){let{t}=c(),n=o(e.id),[r,i]=(0,R.useState)(null);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(y,{title:(0,z.jsxs)(`span`,{className:`flex items-center justify-between`,children:[t(`models.section.providerPrices`),(0,z.jsx)(g,{size:`sm`,variant:`plain`,icon:(0,z.jsx)(F,{className:`size-3.5`}),onClick:()=>i(`new`),children:t(`common.add`)})]}),footer:t(`models.providerPricesFooter`),children:[e.providerPrices.length===0&&(0,z.jsx)(p,{label:(0,z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`models.noProviderPrices`)})}),e.providerPrices.map(e=>(0,z.jsxs)(p,{label:(0,z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`font-mono text-[12.5px]`,children:e.priceKey}),e.userModified&&(0,z.jsx)(m,{tone:`orange`,children:t(`models.modified`)})]}),detail:[_(e.pricing),e.upstreamModelId,e.pricing.time_windows?.length?t(`models.hasTimeWindows`):null,e.pricing.context_tiers?.length?t(`models.hasTiers`):null].filter(Boolean).join(` · `),children:[(0,z.jsx)(g,{size:`sm`,variant:`plain`,icon:(0,z.jsx)(O,{className:`size-3.5`}),"aria-label":t(`common.edit`),onClick:()=>i(e)}),(0,z.jsx)(K,{label:t(`common.delete`),prompt:t(`models.deletePrice`,{key:e.priceKey}),onConfirm:()=>n.mutateAsync(e.priceKey)})]},e.priceKey))]}),(0,z.jsx)(G,{model:e,editing:r,onClose:()=>i(null)})]})}function G({model:e,editing:t,onClose:n}){let{t:r}=c(),{toast:i}=T(),o=a(),s=x(e.id),u=t===`new`,[d,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[_,v]=(0,R.useState)(null);(0,R.useEffect)(()=>{t&&(t===`new`?(p(``),h(``),v(e.pricing?structuredClone(e.pricing):{currency:`USD`,unit:`per_1m_tokens`,base:{input:null,output:null}})):(p(t.priceKey),h(t.upstreamModelId??``),v(structuredClone(t.pricing))))},[t,e.pricing]);let y=new Set(e.providerPrices.map(e=>e.priceKey));return(0,z.jsx)(w,{open:t!==null,onOpenChange:e=>!e&&n(),width:680,title:u?r(`models.addPrice`):r(`models.editPrice`,{key:d}),description:r(`models.priceSheetDetail`),footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(g,{onClick:n,children:r(`common.cancel`)}),(0,z.jsx)(g,{variant:`primary`,disabled:!d||!_,loading:s.isPending,onClick:()=>s.mutate({priceKey:d,upstreamModelId:m||null,pricing:_},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(C(e),`error`)}),children:r(`common.save`)})]}),children:(0,z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsx)(f,{label:r(`providers.priceKey`),children:u?(0,z.jsx)(E,{value:d,onChange:p,placeholder:r(`models.pickPriceKey`),options:(o.data??[]).map(e=>({value:e.priceKey,label:e.label,detail:e.priceKey,disabled:y.has(e.priceKey)}))}):(0,z.jsx)(l,{value:d,disabled:!0,className:`font-mono`})}),(0,z.jsx)(f,{label:r(`models.upstreamId`),hint:r(`models.upstreamIdHint`),children:(0,z.jsx)(l,{className:`font-mono`,value:m,onChange:e=>h(e.target.value),placeholder:e.id})})]}),u&&(0,z.jsx)(l,{className:`font-mono`,"aria-label":r(`models.customPriceKey`),placeholder:r(`models.customPriceKey`),value:d,onChange:e=>p(e.target.value.trim())}),(0,z.jsx)(P,{value:_,onChange:v})]})})}function K({label:e,prompt:t,onConfirm:n}){let{t:r}=c();return(0,z.jsx)(L,{label:e,icon:(0,z.jsx)(j,{className:`size-4`}),prompt:t,confirmLabel:r(`common.delete`),cancelLabel:r(`common.cancel`),pendingLabel:r(`common.deleting`),doneLabel:r(`common.deleted`),errorLabel:r(`common.error`),retryLabel:r(`common.retry`),onConfirm:n})}export{H as ModelDetailPage};
@@ -0,0 +1 @@
1
+ import{$t as e,Ia as t,Ma as n,Na as r,Nn as i,Ur as a,V as o,Wr as s,Z as c,c as l,ct as u,d,h as f,l as p,n as m,nt as h,ot as g,p as _,r as v,t as y,v as b}from"./alert-qNPoglGp.js";import{a as x,i as S,o as C,r as w}from"./overlays-ORpFxiz4.js";import{t as T}from"./cloud-download-D2BBix7a.js";import{D as E,H as D,M as O,Q as k,W as A,h as j,j as M,z as N}from"./index-DDjZdUEf.js";import{t as P}from"./checkbox-B47xSnbl.js";var F=t(r(),1),I=n();function L(){let{t:e}=u(),t=k(),[n,r]=(0,F.useState)(``),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(!1),[d,p]=(0,F.useState)(!1),m=(0,F.useRef)(null),h=O(n),g=i(),_=i(h,a),S=(0,F.useMemo)(()=>[...new Set((g.data??[]).map(e=>e.vendor))].sort(),[g.data]);return M(e=>{e===`find`&&m.current?.focus()}),(0,I.jsxs)(j,{title:e(`nav.models`),subtitle:_.data?e(`models.count`,{count:_.data.length}):void 0,actions:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(f,{inputRef:m,className:`w-52`,value:n,onChange:r,placeholder:e(`models.search`)}),(0,I.jsx)(w,{value:a,onChange:o,options:[{value:``,label:e(`models.allVendors`)},...S.map(e=>({value:e,label:e}))]}),(0,I.jsx)(v,{icon:(0,I.jsx)(T,{className:`size-3.5`}),onClick:()=>p(!0),children:e(`models.sync`)}),(0,I.jsx)(v,{variant:`primary`,icon:(0,I.jsx)(N,{className:`size-3.5`}),onClick:()=>c(!0),children:e(`models.new`)})]}),children:[_.isLoading&&(0,I.jsx)(b,{lines:5}),_.isError&&(0,I.jsx)(y,{tone:`danger`,title:e(`common.error`),children:x(_.error)}),_.data?.length===0&&(0,I.jsx)(l,{icon:(0,I.jsx)(A,{className:`size-6`}),title:e(`models.empty`)}),_.data&&_.data.length>0&&(0,I.jsx)(E,{caption:e(`nav.models`),rowKey:`id`,rows:_.data.map(e=>({id:e.id,name:e.displayName,vendor:e.vendor,context:e.contextWindow??0,input:e.pricing?.base.input??0,providerPrices:e.providerPriceKeys.length,m:e})),columns:R(e,e=>t(`/models/${encodeURIComponent(e)}`))}),(0,I.jsx)(z,{open:s,onOpenChange:c,onCreated:e=>t(`/models/${encodeURIComponent(e)}`)}),(0,I.jsx)(q,{open:d,onOpenChange:p})]})}function R(e,t){return[{key:`name`,label:e(`models.col.model`),render:(n,r)=>(0,I.jsxs)(`button`,{type:`button`,className:`block w-full min-w-0 text-left`,onClick:()=>t(r.id),children:[(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:g(`truncate font-medium hover:text-[var(--accent)]`,!r.m.enabled&&`text-[var(--text-muted)]`),children:r.name}),r.m.source===`user`&&(0,I.jsx)(m,{tone:`accent`,children:e(`models.source.user`)}),r.m.userModifiedFields.length>0&&(0,I.jsx)(m,{tone:`orange`,children:e(`models.modified`)})]}),(0,I.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-[var(--text-muted)]`,children:r.id})]})},{key:`vendor`,label:e(`models.col.vendor`),width:120},{key:`context`,label:e(`models.col.context`),numeric:!0,width:96,render:(e,t)=>o(t.m.contextWindow)},{key:`input`,label:e(`models.col.price`),numeric:!0,width:150,render:(e,t)=>{let n=t.m.pricing?.base;return n?`${c(n.input)} / ${c(n.output)}`:`—`}},{key:`providerPrices`,label:e(`models.col.providerPrices`),numeric:!0,width:130,render:(t,n)=>n.providerPrices?e(`models.providerPriceCount`,{count:n.providerPrices}):`—`}]}function z({open:t,onOpenChange:n,onCreated:r}){let{t:i}=u(),{toast:a}=C(),o=e(),[s,c]=(0,F.useState)(``),[l,f]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),[g,y]=(0,F.useState)(null),[b,w]=(0,F.useState)(null),[T,E]=(0,F.useState)(null);return(0,I.jsx)(S,{open:t,onOpenChange:n,title:i(`models.new`),description:i(`models.newDetail`),footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(v,{onClick:()=>n(!1),children:i(`common.cancel`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!s.trim()||!m.trim(),loading:o.isPending,onClick:()=>o.mutate({id:s.trim(),displayName:l.trim()||s.trim(),vendor:m.trim(),contextWindow:g,pricing:b!=null||T!=null?{currency:`USD`,unit:`per_1m_tokens`,base:{input:b,output:T}}:null},{onSuccess:e=>{n(!1),c(``),f(``),r(e.id)},onError:e=>a(x(e),`error`)}),children:i(`common.create`)})]}),children:(0,I.jsxs)(`div`,{className:`grid gap-4`,children:[(0,I.jsx)(p,{label:i(`models.field.id`),hint:i(`models.field.idHint`),children:(0,I.jsx)(d,{className:`font-mono`,value:s,onChange:e=>c(e.target.value),placeholder:`my-model-1`})}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,I.jsx)(p,{label:i(`models.field.displayName`),children:(0,I.jsx)(d,{value:l,onChange:e=>f(e.target.value)})}),(0,I.jsx)(p,{label:i(`models.field.vendor`),children:(0,I.jsx)(d,{value:m,onChange:e=>h(e.target.value),placeholder:`openai`})})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,I.jsx)(p,{label:i(`models.field.contextWindow`),children:(0,I.jsx)(_,{value:g,onChange:y})}),(0,I.jsx)(p,{label:i(`models.field.inputPrice`),children:(0,I.jsx)(_,{value:b,onChange:w})}),(0,I.jsx)(p,{label:i(`models.field.outputPrice`),children:(0,I.jsx)(_,{value:T,onChange:E})})]})]})})}var B=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function V(e,t=``,n=new Map){if(B(e)&&Object.keys(e).length>0)for(let[r,i]of Object.entries(e))V(i,t?`${t}.${r}`:r,n);else e!=null&&n.set(t,e);return n}function H(e,t){let n=V(e),r=V(t);return[...r.keys(),...[...n.keys()].filter(e=>!r.has(e))].filter(e=>JSON.stringify(n.get(e))!==JSON.stringify(r.get(e))).map(e=>({path:e.replace(/^pricing\./,``),before:n.get(e),after:r.get(e)}))}var U=e=>typeof e==`string`?e:JSON.stringify(e),W=4;function G({before:e,after:t}){let{t:n}=u(),r=H(e,t),i=r.length-W;return(0,I.jsxs)(`span`,{className:`flex w-full min-w-0 flex-col gap-0.5 font-mono text-[11px] leading-snug`,title:`${h(e)||`∅`}\n→\n${h(t)||`∅`}`,children:[r.slice(0,W).map(e=>(0,I.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-1.5 whitespace-nowrap`,children:[e.path&&(0,I.jsx)(`span`,{className:`shrink-0 text-[var(--text-secondary)]`,children:e.path}),e.before!==void 0&&(0,I.jsx)(`span`,{className:`min-w-0 truncate text-[var(--danger)] line-through opacity-80`,children:U(e.before)}),e.before!==void 0&&e.after!==void 0&&(0,I.jsx)(`span`,{className:`shrink-0 text-[var(--text-secondary)]`,children:`→`}),e.after!==void 0&&(0,I.jsx)(`span`,{className:`min-w-0 truncate text-[var(--success)]`,children:U(e.after)})]},e.path)),i>0&&(0,I.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:n(`models.sync.more`,{n:i})})]})}function K({changes:e,label:t,checked:n,onChange:r}){let{t:i}=u(),[a,o]=(0,F.useState)(new Set),s=(0,F.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.modelId,[...t.get(n.modelId)??[],n]);return[...t]},[e]),c=e=>{let t=e.filter(e=>n.has(e)).length;return t===0?!1:t===e.length||`indeterminate`},l=(e,t)=>{let i=new Set(n);for(let n of e)t?i.add(n):i.delete(n);r(i)},d=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),f=e=>(0,I.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1`,children:[(0,I.jsxs)(`span`,{className:`flex flex-wrap gap-1`,children:[(0,I.jsx)(m,{tone:e.kind===`new_model`?`green`:`neutral`,children:t(e)}),e.skippedBecauseUserModified&&(0,I.jsx)(m,{tone:`orange`,children:i(`models.sync.userModified`)})]}),e.kind!==`new_model`&&(0,I.jsx)(G,{before:e.before,after:e.after})]}),p=e.map(e=>e.id);return(0,I.jsx)(`div`,{className:`card max-h-[520px] overflow-auto`,children:(0,I.jsxs)(`ul`,{className:`divide-y divide-[var(--border)]`,children:[(0,I.jsxs)(`li`,{className:`sticky top-0 z-10 flex items-center gap-3 bg-[var(--surface)] px-4 py-2`,children:[(0,I.jsx)(P,{checked:c(p),onCheckedChange:e=>l(p,e!==!1),"aria-label":i(`models.sync.selectAll`)}),(0,I.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`models.sync.selectedOf`,{n:n.size,total:p.length,models:s.length})})]}),s.map(([e,r])=>{let o=r.map(e=>e.id),s=r.length===1?r[0]:void 0,u=!a.has(e);return(0,I.jsxs)(`li`,{className:`px-4 py-2.5`,children:[(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(P,{checked:c(o),onCheckedChange:e=>l(o,e!==!1),"aria-label":e,className:`mt-0.5`}),(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:[s?(0,I.jsx)(`span`,{className:`truncate font-mono text-[12px] font-medium`,title:e,children:e}):(0,I.jsxs)(`button`,{type:`button`,className:`flex min-w-0 items-center gap-1 text-left`,"aria-expanded":u,onClick:()=>d(e),children:[(0,I.jsx)(D,{className:g(`size-3.5 shrink-0 text-[var(--text-muted)] transition-transform`,u&&`rotate-90`)}),(0,I.jsx)(`span`,{className:`truncate font-mono text-[12px] font-medium`,title:e,children:e}),(0,I.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 text-[11px] text-[var(--text-muted)]`,children:i(`models.sync.groupCount`,{n:r.length})})]}),s&&f(s)]})]}),!s&&u&&(0,I.jsx)(`ul`,{className:`mt-2 ml-7 flex flex-col gap-2 border-l border-[var(--border)] pl-3`,children:r.map(r=>(0,I.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(P,{checked:n.has(r.id),onCheckedChange:e=>l([r.id],e!==!1),"aria-label":`${e} ${t(r)}`,className:`mt-0.5`}),f(r)]},r.id))})]},e)})]})})}function q({open:e,onOpenChange:t}){let{t:n}=u(),{toast:r}=C(),i=s(),o=a(),[c,l]=(0,F.useState)(new Set),d=()=>i.mutate(void 0,{onSuccess:e=>l(new Set(e.changes.filter(e=>!e.skippedBecauseUserModified).map(e=>e.id)))}),f=i.data?.changes??[];return(0,I.jsxs)(S,{open:e,onOpenChange:e=>{t(e),e&&!i.data&&d()},width:720,title:n(`models.sync`),description:n(`models.syncDetail`),footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(v,{className:`mr-auto`,variant:`plain`,onClick:d,loading:i.isPending,children:n(`common.refresh`)}),(0,I.jsx)(v,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,I.jsx)(v,{variant:`primary`,disabled:c.size===0,loading:o.isPending,onClick:()=>o.mutate([...c],{onSuccess:e=>{r(n(`models.sync.applied`,{count:e.applied}),`success`),t(!1),i.reset()},onError:e=>r(x(e),`error`)}),children:n(`models.sync.apply`,{count:c.size})})]}),children:[e&&!i.data&&!i.isPending&&!i.isError&&(0,I.jsx)(`div`,{className:`py-6 text-center`,children:(0,I.jsx)(v,{variant:`primary`,onClick:d,children:n(`models.sync.check`)})}),i.isPending&&(0,I.jsx)(b,{lines:4}),i.isError&&(0,I.jsx)(y,{tone:`danger`,title:n(`common.error`),children:x(i.error)}),i.data&&f.length===0&&(0,I.jsx)(y,{tone:`success`,title:n(`models.sync.none`)}),f.length>0&&(0,I.jsx)(K,{changes:f,label:e=>e.kind===`new_model`?n(`models.sync.newModel`):e.kind===`price`?n(`models.sync.price`,{key:e.priceKey??``}):n(`models.sync.field`,{field:e.field??``}),checked:c,onChange:l})]})}export{L as ModelsPage};
@@ -0,0 +1,2 @@
1
+ import{Bn as e,H as t,Hn as n,Ia as r,Jn as i,Kn as a,Ma as o,Na as s,Nt as c,Pn as l,Rn as u,Sn as d,Tn as f,_ as p,b as m,bt as h,c as g,ct as _,d as v,f as y,fr as b,h as x,i as S,jn as C,l as w,li as T,mt as E,n as D,ot as O,pr as k,r as A,t as j,v as M,xt as N,y as P,zn as F}from"./alert-qNPoglGp.js";import{a as I,i as L,n as ee,o as R}from"./overlays-ORpFxiz4.js";import{t as z}from"./arrow-down-BtJQJK1L.js";import{t as te}from"./download-COSgQOSF.js";import{t as ne}from"./ellipsis-DU9LNejQ.js";import{t as re}from"./external-link--dZT5Rkw.js";import{$ as ie,C as ae,E as B,F as oe,J as se,K as ce,N as V,Q as H,R as U,T as W,et as le,h as ue,w as G,x as de,z as fe}from"./index-DDjZdUEf.js";var K={name:`settings-2`,size:24,node:[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]};K.node;var pe=N(K),q=r(s(),1),J=o(),me=/^(?:(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*|github:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)$/,Y={provider:`plugins.kind.provider`,middleware:`plugins.kind.middleware`,agent:`plugins.kind.agent`,pi:`plugins.kind.pi`},he={provider:`neutral`,middleware:`accent`,agent:`green`,pi:`orange`};function X({name:e,icon:t,kind:n,size:r=32}){let i=Math.round(r*.28);return t&&/^(https:|data:image\/)/i.test(t)?(0,J.jsx)(`img`,{src:t,alt:``,width:r,height:r,className:`shrink-0 object-contain`,style:{borderRadius:i},draggable:!1}):n===`middleware`||n===`agent`?(0,J.jsx)(`span`,{"aria-hidden":!0,className:`inline-flex shrink-0 items-center justify-center text-white`,style:{width:r,height:r,borderRadius:i,background:n===`middleware`?`#0a84ff`:`#30b0a0`},children:(0,J.jsx)(n===`middleware`?oe:se,{className:`size-[55%]`,strokeWidth:1.75})}):(0,J.jsx)(de,{name:e,icon:t,size:r})}function Z(){let{t:e}=_(),t=H(),{tab:n}=ie(),r=n===`market`||n===`runtime`?n:`installed`,i=a(),o=T(),{toast:s}=R(),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(null);return(0,J.jsxs)(ue,{title:e(`nav.plugins`),subtitle:e(`plugins.subtitle`),actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(A,{icon:(0,J.jsx)(U,{className:`size-3.5`}),onClick:()=>o.mutate(void 0,{onSuccess:e=>p(e.id),onError:e=>s(I(e),`error`)}),disabled:!i.data?.plugins.length,children:e(`plugins.updateAll`)}),(0,J.jsx)(A,{variant:`primary`,icon:(0,J.jsx)(fe,{className:`size-3.5`}),onClick:()=>l(!0),children:e(`plugins.add`)})]}),children:[(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col`,children:[i.data?.off&&(0,J.jsx)(j,{className:`mb-4`,tone:`warning`,title:e(`plugins.off`),children:e(`plugins.offDetail`)}),(0,J.jsxs)(ae,{value:r,onValueChange:e=>t(e===`installed`?`/plugins`:`/plugins/${e}`,{replace:!0}),children:[(0,J.jsxs)(W,{"aria-label":e(`nav.plugins`),children:[(0,J.jsxs)(B,{value:`installed`,children:[e(`plugins.tab.installed`),i.data&&i.data.plugins.length>0&&(0,J.jsx)(`span`,{className:`ml-1.5 tabular-nums opacity-60`,children:i.data.plugins.length})]}),(0,J.jsx)(B,{value:`market`,children:e(`plugins.tab.market`)}),(0,J.jsx)(B,{value:`runtime`,children:e(`plugins.tab.runtime`)})]}),(0,J.jsxs)(G,{value:`installed`,className:`pt-1`,children:[i.isLoading&&(0,J.jsx)(M,{lines:4}),i.isError&&(0,J.jsx)(j,{tone:`danger`,title:e(`common.error`),children:I(i.error)}),i.data&&(0,J.jsx)(ge,{plugins:i.data.plugins,preferences:i.data.preferences,onJob:p,onBrowse:()=>t(`/plugins/market`),onImport:()=>d(!0)})]}),(0,J.jsx)(G,{value:`market`,className:`pt-1`,children:(0,J.jsx)(Se,{installed:i.data?.plugins??[],onJob:p})}),(0,J.jsx)(G,{value:`runtime`,className:`pt-1`,children:(0,J.jsx)(Ce,{onJob:p})})]})]}),(0,J.jsx)(ye,{open:c,onOpenChange:l,onJob:p}),(0,J.jsx)(be,{open:u,onOpenChange:d,onJob:p}),(0,J.jsx)(xe,{id:f,onClose:()=>p(null)})]})}function ge({plugins:e,preferences:t,onJob:n,onBrowse:r,onImport:i}){let{t:a}=_(),o=u(e.some(e=>e.kinds.includes(`provider`)||e.kinds.includes(`pi`))),s=C(),c=k(),{toast:l}=R(),d=!!(s.data?.found&&s.data.plugins.some(e=>!e.installed))&&(0,J.jsxs)(`div`,{className:`card flex flex-wrap items-center gap-3 p-4`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 text-[13px]`,children:a(`plugins.magpie.banner`,{count:s.data.plugins.filter(e=>!e.installed).length})}),(0,J.jsx)(A,{size:`sm`,icon:(0,J.jsx)(te,{className:`size-3.5`}),onClick:i,children:a(`plugins.magpie.import`)})]});if(e.length===0)return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,(0,J.jsx)(`div`,{className:`card p-6`,children:(0,J.jsx)(g,{icon:(0,J.jsx)(E,{className:`size-6`}),title:a(`plugins.empty`),detail:a(`plugins.emptyDetail`),action:(0,J.jsx)(A,{variant:`primary`,onClick:r,children:a(`plugins.browseMarket`)})})})]});let f=(t,n)=>{let r=e.map(e=>e.spec),[i]=r.splice(t,1);r.splice(t+n,0,i),c.mutate(r,{onError:e=>l(I(e),`error`)})};return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] p-0`,children:e.map((r,i)=>(0,J.jsx)(_e,{plugin:r,host:o.data,preferences:t,onJob:n,onUp:i>0?()=>f(i,-1):void 0,onDown:i<e.length-1?()=>f(i,1):void 0},r.spec))}),e.some(e=>e.middleware)&&(0,J.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:a(`plugins.orderHint`)})]})}function _e({plugin:e,host:t,preferences:n,onJob:r,onUp:a,onDown:o}){let{t:s}=_(),c=H(),{toast:u,confirm:d}=R(),f=l(),p=T(),m=b(),h=i(),[g,v]=(0,q.useState)(!1),y=t?.plugins.find(t=>t.spec===e.spec),x=e.middleware,S=e.kinds[0]??`provider`,C=async()=>{await d({title:s(`plugins.removeConfirm`,{name:e.shortName}),detail:s(`plugins.removeDetail`),confirmLabel:s(`common.delete`),destructive:!0})&&m.mutate(e.spec,{onSuccess:e=>r(e.id),onError:e=>u(I(e),`error`)})},w=[];return x&&!x.error&&w.push((0,J.jsxs)(Q,{label:s(`plugins.kind.middleware`),children:[s(`plugins.mw.stats`,{hooks:x.hooks.join(`, `),calls:x.calls,micros:x.avgMicros.toFixed(1),failures:x.failures}),x.lastError&&(0,J.jsx)(`span`,{className:`block text-[var(--danger)]`,children:s(`plugins.mw.lastError`,{error:x.lastError})})]},`mw`)),e.agent?.kind&&w.push((0,J.jsx)(Q,{label:s(`plugins.kind.agent`),children:(0,J.jsx)(`button`,{type:`button`,className:`text-[var(--accent)] underline-offset-2 hover:underline`,onClick:()=>c(`/clients/${e.agent.kind}`),children:s(`plugins.agent.adds`,{name:e.agent.name??e.agent.id??``})})},`agent`)),y&&y.provides.length>0&&w.push((0,J.jsxs)(Q,{label:s(`plugins.kind.provider`),children:[(0,J.jsx)(`span`,{children:s(`plugins.provides`,{providers:y.provides.join(`, `)})}),(0,J.jsx)(`button`,{type:`button`,className:`ml-2 text-[var(--accent)] underline-offset-2 hover:underline`,onClick:()=>c(`/providers`),children:s(`plugins.openProviders`)}),Object.entries(y.servedBy).map(([t,n])=>(0,J.jsxs)(`span`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[var(--warning)]`,children:[s(`plugins.servedBy`,{provider:t,other:n}),(0,J.jsx)(A,{size:`sm`,onClick:()=>h.mutate({spec:e.spec,provider:t},{onError:e=>u(I(e),`error`)}),children:s(`plugins.useFor`,{provider:t})})]},t)),y.provides.some(t=>n[t]===e.spec)&&(0,J.jsx)(`span`,{className:`block text-[var(--text-muted)]`,children:s(`plugins.picked`)})]},`provides`)),(0,J.jsxs)(`article`,{className:O(`flex gap-3 px-4 py-3.5`,!e.enabled&&`opacity-70`),children:[(0,J.jsx)(`div`,{className:O(`pt-0.5`,!e.enabled&&`grayscale`),children:(0,J.jsx)(X,{name:e.shortName,icon:e.icon,kind:S})}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-3 gap-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`truncate text-[14px] font-medium`,children:e.shortName}),e.version&&(0,J.jsxs)(`span`,{className:`font-mono text-[11px] text-[var(--text-muted)]`,children:[`v`,e.version]}),e.kinds.map(e=>(0,J.jsx)(D,{tone:he[e],children:s(Y[e])},e)),e.isPath&&(0,J.jsx)(D,{tone:`orange`,children:s(`plugins.local`)})]}),(0,J.jsx)(`span`,{className:`truncate font-mono text-[11px] text-[var(--text-muted)]`,title:e.spec,children:e.spec})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[x&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(A,{size:`sm`,variant:`plain`,"aria-label":s(`plugins.moveUp`),title:s(`plugins.moveUp`),disabled:!a,onClick:a,icon:(0,J.jsx)(ce,{className:`size-3.5`})}),(0,J.jsx)(A,{size:`sm`,variant:`plain`,"aria-label":s(`plugins.moveDown`),title:s(`plugins.moveDown`),disabled:!o,onClick:o,icon:(0,J.jsx)(z,{className:`size-3.5`})})]}),(0,J.jsx)(P,{checked:e.enabled,label:s(`plugins.enabled`),onChange:t=>f.mutate({spec:e.spec,enabled:t},{onError:e=>u(I(e),`error`)})}),(0,J.jsx)(ee,{label:s(`common.more`),iconOnly:!0,icon:(0,J.jsx)(ne,{className:`size-4`}),items:[{id:`options`,label:s(`plugins.options`),icon:(0,J.jsx)(pe,{className:`size-3.5`}),onSelect:()=>v(!0)},...e.isPath?[]:[{id:`update`,label:s(`plugins.update`),icon:(0,J.jsx)(U,{className:`size-3.5`}),onSelect:()=>p.mutate(e.spec,{onSuccess:e=>r(e.id),onError:e=>u(I(e),`error`)})}],{id:`remove`,label:s(`common.delete`),icon:(0,J.jsx)(V,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void C()}]})]})]}),e.error&&(0,J.jsx)(j,{tone:`danger`,title:s(`plugins.cantLoad`),children:e.error}),y?.error&&(0,J.jsx)(j,{tone:`danger`,title:s(`plugins.hostCantLoad`),children:y.error}),x?.error&&(0,J.jsx)(j,{tone:`danger`,title:s(`plugins.cantLoad`),children:s(`plugins.mw.error`,{error:x.error})}),e.agent?.error&&(0,J.jsx)(j,{tone:`danger`,title:s(`plugins.cantLoad`),children:s(`plugins.agent.error`,{error:e.agent.error})}),w.length>0&&(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5 rounded-lg bg-[var(--surface-muted)] px-3 py-2`,children:w})]}),(0,J.jsx)(ve,{plugin:e,open:g,onOpenChange:v})]})}function Q({label:e,children:t}){return(0,J.jsxs)(`div`,{className:`flex gap-3 text-[12px]`,children:[(0,J.jsx)(`span`,{className:`w-14 shrink-0 text-[var(--text-muted)]`,children:e}),(0,J.jsx)(`div`,{className:`min-w-0 flex-1 text-[var(--text-secondary)]`,children:t})]})}function ve({plugin:e,open:t,onOpenChange:n}){let{t:r}=_(),{toast:i}=R(),a=l(),[o,s]=(0,q.useState)(``),[c,u]=(0,q.useState)(null);(0,q.useEffect)(()=>{t&&(s(JSON.stringify(e.options??e.optionsExample??{},null,2)),u(null))},[t,e.options,e.optionsExample]);let d=t=>a.mutate({spec:e.spec,options:t},{onSuccess:()=>(i(r(`plugins.optionsSaved`)),n(!1)),onError:e=>i(I(e),`error`)});return(0,J.jsxs)(L,{open:t,onOpenChange:n,title:r(`plugins.optionsTitle`,{name:e.shortName}),description:e.options?void 0:e.optionsExample?r(`plugins.optionsExample`):r(`plugins.optionsNone`),width:560,footer:(0,J.jsxs)(J.Fragment,{children:[e.options&&(0,J.jsx)(A,{onClick:()=>d(null),children:r(`plugins.optionsClear`)}),(0,J.jsx)(A,{variant:`primary`,onClick:()=>{try{let e=JSON.parse(o||`{}`);if(typeof e!=`object`||!e||Array.isArray(e))throw Error(r(`plugins.optionsObject`));d(e)}catch(e){u(e instanceof Error?e.message:String(e))}},disabled:a.isPending,children:r(`common.save`)})]}),children:[(0,J.jsx)(m,{mono:!0,rows:14,value:o,invalid:!!c,onChange:e=>(s(e.target.value),u(null)),label:r(`plugins.options`)}),c&&(0,J.jsx)(`p`,{className:`mt-2 text-[12px] text-[var(--danger)]`,children:c})]})}function ye({open:e,onOpenChange:t,onJob:n}){let{t:r}=_(),{toast:i}=R(),a=c(),[o,s]=(0,q.useState)(``);return(0,q.useEffect)(()=>{e&&s(``)},[e]),(0,J.jsxs)(L,{open:e,onOpenChange:t,title:r(`plugins.addTitle`),description:r(`plugins.addDetail`),footer:(0,J.jsx)(A,{variant:`primary`,disabled:!o.trim()||a.isPending,onClick:()=>a.mutate({spec:o.trim()},{onSuccess:e=>(n(e.id),t(!1)),onError:e=>i(I(e),`error`)}),children:r(`plugins.install`)}),children:[(0,J.jsx)(w,{label:r(`plugins.spec`),hint:r(`plugins.specHint`),children:(0,J.jsx)(v,{mono:!0,value:o,onChange:e=>s(e.target.value),placeholder:`@astragate-community/middleware-word-guard`,autoFocus:!0})}),(0,J.jsx)(j,{tone:`warning`,title:r(`plugins.trustTitle`),className:`mt-4`,children:r(`plugins.trustDetail`)})]})}function be({open:e,onOpenChange:t,onJob:n}){let{t:r}=_(),{toast:i}=R(),a=C(e),o=d(),[s,c]=(0,q.useState)(!1),l=a.data;return(0,J.jsxs)(L,{open:e,onOpenChange:t,title:r(`plugins.magpie.title`),description:l?.path,width:560,footer:(0,J.jsx)(A,{variant:`primary`,disabled:!l?.found||o.isPending,onClick:()=>o.mutate(s,{onSuccess:e=>(n(e.id),t(!1)),onError:e=>i(I(e),`error`)}),children:r(`plugins.magpie.import`)}),children:[a.isLoading&&(0,J.jsx)(M,{lines:3}),l?.error&&(0,J.jsx)(j,{tone:`danger`,title:r(`common.error`),children:l.error}),l&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] p-0`,children:l.plugins.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[12px]`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,children:e.spec}),e.off&&(0,J.jsx)(D,{children:r(`plugins.magpie.off`)}),e.hasOptions&&(0,J.jsx)(D,{tone:`accent`,children:r(`plugins.options`)}),e.installed&&(0,J.jsx)(D,{tone:`green`,children:r(`plugins.installed`)})]},e.spec))}),l.signIns>0&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(P,{checked:s,onChange:c,label:r(`plugins.magpie.signIns`,{count:l.signIns})}),(0,J.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`plugins.magpie.signInsDetail`)})]})]})]})}function xe({id:e,onClose:t}){let{t:n}=_(),r=F(e).data;return(0,J.jsxs)(L,{open:!!e,onOpenChange:e=>!e&&t(),title:n(`plugins.job.title`),description:r?n(r.state===`running`?`plugins.job.running`:r.state===`succeeded`?`plugins.job.done`:`plugins.job.failed`,{target:r.target}):void 0,width:620,footer:(0,J.jsx)(A,{onClick:t,children:n(`common.close`)}),children:[!r&&(0,J.jsx)(M,{lines:3}),r&&(0,J.jsx)(S,{language:`text`,children:r.log.length?r.log.join(`
2
+ `):`…`}),r?.state===`failed`&&r.error&&(0,J.jsx)(j,{tone:`danger`,title:n(`plugins.job.failedTitle`),className:`mt-3`,children:r.error})]})}function Se({installed:t,onJob:r}){let{t:i,locale:a}=_(),{toast:o,confirm:s}=R(),l=e(),u=c(),[d,f]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[v,y]=(0,q.useState)(`all`);(0,q.useEffect)(()=>{let e=setTimeout(()=>h(d.trim()),400);return()=>clearTimeout(e)},[d]);let b=n(m),S=(0,q.useMemo)(()=>new Set(t.map(e=>e.name)),[t]),C=(e,n)=>S.has(n)||t.some(t=>t.spec===e),w=async(e,t)=>{await s({title:i(`plugins.installConfirm`,{name:e}),detail:i(`plugins.trustDetail`),confirmLabel:i(`plugins.install`)})&&u.mutate({spec:e,source:t},{onSuccess:e=>r(e.id),onError:e=>o(I(e),`error`)})},[T,D]=le(),O=T.get(`install`),k=(0,q.useRef)(null);(0,q.useEffect)(()=>{O&&k.current!==O&&(k.current=O,D({},{replace:!0}),me.test(O)?w(O,`market`):o(i(`plugins.linkInvalid`),`error`))},[O]);let A=(l.data??[]).filter(e=>v===`all`||e.kind===v),N=e=>(l.data??[]).filter(t=>e===`all`||t.kind===e).length,P=m.length>=2;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsx)(x,{className:`min-w-[220px] flex-1`,value:d,onChange:f,placeholder:i(`plugins.searchPlaceholder`)}),!P&&(0,J.jsx)(p,{ariaLabel:i(`plugins.kindFilter`),value:v,onChange:y,items:[`all`,`provider`,`middleware`,`agent`].map(e=>({value:e,label:`${i(e===`all`?`plugins.kind.all`:Y[e])} ${N(e)}`}))})]}),P?(0,J.jsxs)(J.Fragment,{children:[b.isLoading&&(0,J.jsx)(M,{lines:3}),b.data?.length===0&&(0,J.jsx)(`div`,{className:`card p-6`,children:(0,J.jsx)(g,{icon:(0,J.jsx)(E,{className:`size-6`}),title:i(`plugins.noResults`)})}),b.data&&b.data.length>0&&(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:b.data.map(e=>(0,J.jsx)($,{title:e.name,subtitle:e.spec,icon:(0,J.jsx)(X,{name:e.name,kind:e.kind}),detail:e.description??void 0,tags:[i(Y[e.kind]),e.source===`github`?`★ ${e.stars}`:e.version?`v${e.version}`:``,e.source===`astra`?i(`plugins.origin.astra`):``],installed:C(e.spec,e.name),onInstall:()=>void w(e.spec,e.source===`github`?`github`:e.source===`astra`?`market`:`npm`)},e.spec))}),(0,J.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:i(`plugins.searchNote`)})]}):(0,J.jsxs)(J.Fragment,{children:[l.isLoading&&(0,J.jsx)(M,{lines:4}),l.isError&&(0,J.jsx)(j,{tone:`danger`,title:i(`common.error`),children:I(l.error)}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:A.map(e=>(0,J.jsx)($,{title:e.name,subtitle:e.package,icon:(0,J.jsx)(X,{name:e.name,icon:e.icon,kind:e.kind}),detail:e.summary[a]??e.summary.en??e.description??void 0,tags:[i(Y[e.kind]),e.latest?`v${e.latest}`:``,e.origin===`astra`?i(`plugins.origin.astra`):``,e.minAstraVersion?i(`plugins.minVersion`,{version:e.minAstraVersion}):``].filter(Boolean),installed:C(e.package,e.package),onInstall:()=>void w(e.package,`market`)},e.package))}),(0,J.jsx)(`p`,{className:`px-1 text-[12px] text-[var(--text-muted)]`,children:i(`plugins.marketNote`)})]})]})}function $({title:e,subtitle:t,icon:n,detail:r,tags:i,installed:a,onInstall:o}){let{t:s}=_();return(0,J.jsxs)(`div`,{className:`card flex flex-col gap-3 p-4 transition-colors hover:border-[var(--border)]`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[n,(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,J.jsx)(`span`,{className:`truncate text-[14px] font-medium`,title:e,children:e}),(0,J.jsx)(`span`,{className:`truncate font-mono text-[11px] text-[var(--text-muted)]`,title:t,children:t})]})]}),(0,J.jsx)(`p`,{className:`line-clamp-2 min-h-[2lh] text-[12px] leading-relaxed text-[var(--text-secondary)]`,children:r??``}),(0,J.jsxs)(`div`,{className:`mt-auto flex items-center gap-1.5`,children:[i.filter(Boolean).map(e=>(0,J.jsx)(D,{children:e},e)),(0,J.jsx)(`span`,{className:`flex-1`}),a?(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[12px] text-[var(--success)]`,children:[(0,J.jsx)(h,{className:`size-3.5`}),s(`plugins.installed`)]}):(0,J.jsx)(A,{size:`sm`,variant:`primary`,onClick:o,children:s(`plugins.install`)})]})]})}function Ce({onJob:e}){let{t:n,locale:r}=_(),{toast:i}=R(),o=a(),s=u(),c=f(),l=o.data?.runtime;return(0,J.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,J.jsxs)(`section`,{className:`card flex flex-col gap-3 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`h3`,{className:`flex-1 text-[14px] font-medium`,children:`Bun`}),l&&(0,J.jsx)(D,{tone:l.path?`green`:`neutral`,children:l.path?n(`plugins.bunReady`):n(`plugins.bunMissing`)})]}),(0,J.jsx)(`p`,{className:`text-[12px] leading-relaxed text-[var(--text-secondary)]`,children:n(`plugins.bunDetail`)}),l&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[l.path&&(0,J.jsx)(y,{label:n(`plugins.bunPath`),mono:!0,children:l.path}),l.version&&(0,J.jsx)(y,{label:n(`plugins.bunVersion`),mono:!0,children:l.version}),(0,J.jsx)(y,{label:n(`plugins.bunTarget`),mono:!0,children:l.target??n(`plugins.bunNoBuild`)})]}),l?.error&&(0,J.jsx)(j,{tone:`danger`,title:n(`plugins.bunFailed`),children:l.error}),l&&!l.path&&(0,J.jsx)(`div`,{children:(0,J.jsx)(A,{variant:`primary`,disabled:l.downloading||c.isPending||!l.target,onClick:()=>c.mutate(void 0,{onSuccess:t=>e(t.id),onError:e=>i(I(e),`error`)}),children:l.downloading?n(`plugins.bunDownloading`):n(`plugins.bunDownload`,{version:l.version??``})})})]}),(0,J.jsxs)(`section`,{className:`card flex flex-col gap-3 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`h3`,{className:`flex-1 text-[14px] font-medium`,children:n(`plugins.host`)}),s.data&&(0,J.jsx)(D,{tone:s.data.running?`green`:`neutral`,children:s.data.running?n(`plugins.hostRunning`):n(`plugins.hostStopped`)})]}),(0,J.jsx)(`p`,{className:`text-[12px] leading-relaxed text-[var(--text-secondary)]`,children:n(`plugins.hostDetail`)}),s.data?.startError&&(0,J.jsx)(j,{tone:`danger`,title:n(`plugins.hostStartFailed`),children:s.data.startError}),s.data?.goneReason&&(0,J.jsx)(j,{tone:`warning`,title:n(`plugins.hostGone`),children:s.data.goneReason}),s.data&&s.data.plugins.length>0&&(0,J.jsx)(`div`,{className:`flex flex-col gap-1`,children:s.data.plugins.map(e=>(0,J.jsx)(y,{label:e.spec,mono:!0,children:e.error?n(`plugins.hostPluginError`,{error:e.error}):e.provides.join(`, `)||`—`},e.spec))}),s.data?.recent&&s.data.recent.length>0&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 border-t border-[var(--border-subtle)] pt-3`,children:[(0,J.jsx)(`h4`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:n(`plugins.hostRecent`)}),s.data.recent.map((e,n)=>(0,J.jsxs)(`div`,{className:`flex items-start gap-2 text-[12px]`,children:[(0,J.jsx)(D,{tone:e.variant===`error`?`red`:e.variant===`warning`?`orange`:e.variant===`success`?`green`:`neutral`,children:t(e.at,r)}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1 break-words`,children:[e.title&&(0,J.jsxs)(`span`,{className:`font-medium`,children:[e.title,` `]}),e.message]})]},n))]})]}),(0,J.jsxs)(`a`,{className:`flex items-center gap-1 px-1 text-[12px] text-[var(--text-muted)] hover:text-[var(--accent)] lg:col-span-2`,href:`https://github.com/astragate-community/astra-gate-plugins`,target:`_blank`,rel:`noreferrer`,children:[(0,J.jsx)(re,{className:`size-3`}),` astragate-community/astra-gate-plugins`]})]})}export{Z as PluginsPage};
@@ -0,0 +1 @@
1
+ import{$n as e,Bi as t,E as n,Gi as r,Hi as i,Ia as a,J as o,Ma as s,Na as c,Qn as l,Vi as u,Wi as d,Y as f,Yt as p,Zn as m,_ as h,b as g,bt as _,c as v,ct as y,d as b,dt as x,er as S,g as C,h as w,l as T,m as E,n as D,ot as O,r as k,t as ee,u as A,ui as j,v as M,xt as N,y as P,zi as F}from"./alert-qNPoglGp.js";import{a as I,i as te,o as L,r as R}from"./overlays-ORpFxiz4.js";import{$ as ne,C as z,D as B,E as re,F as ie,H as ae,M as oe,N as V,Q as se,R as H,T as ce,U as le,_ as ue,c as de,h as fe,nt as U,r as pe,tt as me,w as W,z as he}from"./index-DDjZdUEf.js";var ge={name:`shield-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]};ge.node;var _e=N(ge),G=a(c(),1),K={toolbar:`_toolbar_1p5c5_1`,leading:`_leading_1p5c5_2`,frame:`_frame_1p5c5_4`,chips:`_chips_1p5c5_5`,slot:`_slot_1p5c5_7`,chip:`_chip_1p5c5_5`,chipLabel:`_chipLabel_1p5c5_10`,value:`_value_1p5c5_11`,separator:`_separator_1p5c5_12`,morphText:`_morphText_1p5c5_13`,morphValue:`_morphValue_1p5c5_14`,measure:`_measure_1p5c5_15`,empty:`_empty_1p5c5_18`,actions:`_actions_1p5c5_19`,clear:`_clear_1p5c5_20`,clearText:`_clearText_1p5c5_21`,srOnly:`_srOnly_1p5c5_23`,menu:`_menu_1p5c5_27`,trigger:`_trigger_1p5c5_29`,face:`_face_1p5c5_31`,surface:`_surface_1p5c5_34`,panel:`_panel_1p5c5_42`,head:`_head_1p5c5_45`,back:`_back_1p5c5_47`,title:`_title_1p5c5_49`,titleText:`_titleText_1p5c5_50`,stage:`_stage_1p5c5_51`,step:`_step_1p5c5_52`,list:`_list_1p5c5_53`,highlight:`_highlight_1p5c5_54`,item:`_item_1p5c5_55`,itemIcon:`_itemIcon_1p5c5_57`,itemLabel:`_itemLabel_1p5c5_58`,itemMeta:`_itemMeta_1p5c5_59`,metaValue:`_metaValue_1p5c5_60`,hint:`_hint_1p5c5_61`,check:`_check_1p5c5_62`,noOptions:`_noOptions_1p5c5_64`},q=s(),J={duration:n.duration.standard,ease:[...n.ease.enter]},ve={duration:n.duration.instant,ease:[...n.ease.standard]},Y={duration:0},ye={duration:n.duration.instant,ease:[...n.ease.standard]},X=e=>`blur(${e}px)`,be=e=>Math.min(1,Math.max(0,e)),xe=e=>typeof e==`string`?{value:e}:e,Se=e=>e.label??e.value,Ce=e=>({initial:e?{opacity:0}:{opacity:0,y:`0.3em`,filter:X(n.blur.soft)},animate:{opacity:1,y:0,filter:X(0)},exit:e?{opacity:0,transition:Y}:{opacity:0,y:`-0.3em`,filter:X(n.blur.subtle),transition:ve},transition:e?ye:J});function we({text:e}){let r=u()??!1,a=(0,G.useRef)(null),o=i(`auto`);return(0,G.useLayoutEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let i=null,s=new ResizeObserver(([a])=>{let s=Math.ceil(a.borderBoxSize?.[0]?.inlineSize??e.offsetWidth),c=i!==null&&i!==e.textContent;i=e.textContent,c&&!r?t(o,s,n.spring.morph):o.jump(s)});return s.observe(e),()=>s.disconnect()},[r,o]),(0,q.jsxs)(F.span,{className:K.morphText,style:{width:o},children:[(0,q.jsx)(`span`,{ref:a,className:K.measure,"aria-hidden":`true`,children:e}),(0,q.jsx)(d,{mode:`popLayout`,initial:!1,children:(0,q.jsx)(F.span,{className:K.morphValue,...Ce(r),children:e},e)})]})}function Te(e,r,a){let o=i(`auto`);return(0,G.useLayoutEffect)(()=>{let i=e.current;if(!i||typeof ResizeObserver>`u`)return;let s=!1,c=new ResizeObserver(()=>{let e=i.offsetHeight;if(!s||a||performance.now()>r.current){s=!0,o.jump(e);return}t(o,e,n.spring.smooth)});return c.observe(i),()=>c.disconnect()},[r,o,e,a]),o}function Ee(e,r,i){(0,G.useLayoutEffect)(()=>{let a=e.current;if(!a||typeof ResizeObserver>`u`)return;let o=new Map,s=()=>{let e=performance.now();for(let s of Array.from(a.children)){let a=s.offsetLeft,c=s.offsetTop,l=o.get(s);if(!l){o.set(s,{x:a,y:c,dx:0,dy:0});continue}let u=l.x-a,d=l.y-c;if(l.x=a,l.y=c,i||e>r.current||Math.abs(d)<1&&Math.abs(u)<40)continue;l.stop?.();let f=l.dx+u,p=l.dy+d,m=e=>{l.dx=f*(1-e),l.dy=p*(1-e),s.style.translate=e>=1?``:`${l.dx}px ${l.dy}px`};m(0),l.stop=t(0,1,{...n.spring.smooth,onUpdate:m,onComplete:()=>m(1)}).stop}for(let e of o.keys())e.parentElement!==a&&o.delete(e)},c=new ResizeObserver(s),l=()=>{for(let e of Array.from(a.children))c.observe(e)},u=new MutationObserver(()=>{l(),s()});return c.observe(a),l(),u.observe(a,{childList:!0}),()=>{c.disconnect(),u.disconnect();for(let e of o.values())e.stop?.()}},[r,e,i])}var Z=e=>e.valueLabel??e.value,De=e=>Z(e)?`${e.label}: ${Z(e)}`:e.label,Oe={empty:`No filters applied`,clearAll:`Clear all`,back:`Back to fields`,noOptions:`No options available`,cleared:`All filters cleared`,remove:e=>`Remove ${De(e)}`,added:e=>`Added ${De(e)}`,changed:e=>`Changed ${De(e)}`,removed:e=>`Removed ${De(e)}`};function ke(e,t,n){let r=e.filter(e=>!t.some(t=>t.id===e.id));if(!t.length&&r.length>1)return n.cleared;let i=t.filter(t=>!e.some(e=>e.id===t.id)),a=t.filter(t=>e.some(e=>e.id===t.id&&e.value!==t.value));return[...i.map(n.added),...a.map(n.changed),...r.map(n.removed)].join(`. `)}function Ae({rows:e,labelledBy:t,onChoose:i,onBack:a,onLeave:o,radio:s,emptyMessage:c}){let l=u()??!1,d=r(),f=(0,G.useRef)(null),p=(0,G.useRef)(!1),m=(0,G.useRef)({text:``,at:0}),[h,g]=(0,G.useState)(()=>Math.max(0,e.findIndex(e=>e.checked))),[_,v]=(0,G.useState)(null),y=()=>Array.from(f.current?.querySelectorAll(`[data-row]`)??[]),b=e=>{let t=f.current;e&&t&&(e.focus({preventScroll:!0}),e.offsetTop<t.scrollTop?t.scrollTop=e.offsetTop:e.offsetTop+e.offsetHeight>t.scrollTop+t.clientHeight&&(t.scrollTop=e.offsetTop+e.offsetHeight-t.clientHeight))};function x(t){let n=y(),r=n.indexOf(document.activeElement),o=e=>{t.preventDefault(),p.current=!1,b(n[e])};if(t.key===`ArrowDown`)return o(r<0?0:(r+1)%n.length);if(t.key===`ArrowUp`)return o(r<0?n.length-1:(r-1+n.length)%n.length);if(t.key===`Home`)return o(0);if(t.key===`End`)return o(n.length-1);if(t.key===`ArrowRight`&&r>=0&&e[r]?.drill){t.preventDefault(),i(e[r],!0);return}if(t.key===`ArrowLeft`&&a){t.preventDefault(),a(!0);return}if(t.key.length===1&&/\S/.test(t.key)&&!t.metaKey&&!t.ctrlKey&&!t.altKey){let e=performance.now();m.current={text:e-m.current.at<700?m.current.text+t.key.toLowerCase():t.key.toLowerCase(),at:e};let i=[...n.slice(r+(m.current.text.length>1?0:1)),...n.slice(0,r+(m.current.text.length>1?0:1))].find(e=>(e.dataset.text??``).toLowerCase().startsWith(m.current.text));i&&o(n.indexOf(i))}}function S(e){let t=e.target.closest(`[data-row]`);if(!t)return;g(y().indexOf(t));let n=p.current&&!l,r=!p.current&&t.matches(`:focus-visible`);v(e=>({top:t.offsetTop,height:t.offsetHeight,glide:n&&!!e?.shown,ring:r,shown:!0}))}function C(e){f.current?.contains(e.relatedTarget)||v(e=>e&&{...e,glide:!1,ring:!1,shown:!1})}return(0,q.jsxs)(`div`,{ref:f,className:K.list,role:`menu`,"aria-labelledby":t,"data-current":d?``:void 0,onKeyDown:x,onFocus:S,onBlur:C,onPointerLeave:()=>{p.current&&f.current?.contains(document.activeElement)&&o()},children:[(0,q.jsx)(F.span,{className:K.highlight,"data-ring":_?.ring||void 0,"aria-hidden":`true`,initial:!1,animate:_?{y:_.top,height:_.height,opacity:+!!_.shown}:{opacity:0},transition:{default:_?.glide?n.spring.snappy:Y,opacity:{duration:l?0:.08}}}),e.length===0?(0,q.jsx)(`p`,{className:K.noOptions,children:c}):null,e.map((e,t)=>(0,q.jsxs)(`button`,{type:`button`,className:K.item,role:s?`menuitemradio`:`menuitem`,"aria-checked":s?!!e.checked:void 0,tabIndex:t===h?0:-1,"data-row":e.key,"data-text":e.label,onPointerMove:e=>{p.current=!0,document.activeElement!==e.currentTarget&&e.currentTarget.focus({preventScroll:!0})},onClick:t=>i(e,t.detail===0),children:[e.icon?(0,q.jsx)(`span`,{className:K.itemIcon,"aria-hidden":`true`,children:e.icon}):null,(0,q.jsx)(`span`,{className:K.itemLabel,children:e.label}),e.meta?(0,q.jsx)(`span`,{className:K.itemMeta,children:e.meta}):null]},e.key))]})}function je(e){let t={left:0,top:0,right:document.documentElement.clientWidth,bottom:window.innerHeight};for(let n=e.parentElement;n&&n!==document.body;n=n.parentElement){let e=getComputedStyle(n);if(e.overflowX===`visible`&&e.overflowY===`visible`)continue;let r=n.getBoundingClientRect();e.overflowX!==`visible`&&(t.left=Math.max(t.left,r.left),t.right=Math.min(t.right,r.right)),e.overflowY!==`visible`&&(t.top=Math.max(t.top,r.top),t.bottom=Math.min(t.bottom,r.bottom))}return t}function Me({fields:e,onSelect:r,active:a=[],label:o=`Add filter`,align:s=`end`,messages:c}){let l={...Oe,...c},f=u()??!1,p=(0,G.useId)(),m=`${p}panel`,h=`${p}title`,g=(0,G.useRef)(null),v=(0,G.useRef)(null),y=(0,G.useRef)(null),b=(0,G.useRef)(`closed`),x=(0,G.useRef)(0),S=(0,G.useRef)(null),[C,w]=(0,G.useState)(`closed`),[T,E]=(0,G.useState)(null),[D,O]=(0,G.useState)(1),[k,ee]=(0,G.useState)(!1),[A,j]=(0,G.useState)(`100% 0`),M=i(`100%`),N=i(`100%`),P=i(0),I=i(0),te=U(()=>I.get()-P.get()),L=i(0),R=i(0),ne=U(()=>{let e=M.get(),t=L.get(),n=R.get();return typeof e==`number`?n>t?be((e-t)/(n-t)):1:0}),z=U(()=>be(ne.get()/.35)),B=U(()=>be((ne.get()-.4)/.5)),re={opacity:U(()=>1-z.get()),scale:U(()=>1-z.get()*.04),filter:U(()=>z.get()?X(z.get()*n.blur.subtle):`none`)},ie={opacity:B,transformOrigin:A,scale:U(()=>.96+B.get()*.04),y:U(()=>(1-B.get())*(k?-6:6)),filter:U(()=>B.get()===1?`none`:X((1-B.get())*n.blur.soft))},oe=C===`open`,V=e.find(e=>e.id===T)??null,se=(0,G.useCallback)(e=>{let r=v.current,i=y.current;if(!r||!i)return;let a=r.getBoundingClientRect(),o=i.offsetWidth+2,c=i.offsetHeight+2,l=je(g.current??r),u=l.left+16-a.left,d=l.right-16-a.left-o,p=a.width-o,m=s===`end`?p>=u?p:0<=d?0:p:0<=d?0:p>=u?p:0;m=Math.round(Math.min(Math.max(m,u),Math.max(u,d)));let h=l.bottom-a.top,_=a.bottom-l.top,C=h<c+16&&_>h;b.current===`closed`&&(M.jump(a.width),N.jump(a.height),P.jump(0)),I.jump(m),L.jump(a.width),R.jump(o),b.current=`open`,x.current+=1,S.current=e,w(`open`),ee(C),E(null),O(-1),j(`${Math.round(a.width/2-m)}px ${C?`100%`:`0`}`);let T=f?Y:n.spring.morph;t(P,m,T),t(M,o,T),t(N,c,T)},[s,L,N,P,f,I,R,M]),H=(0,G.useCallback)(e=>{let r=v.current;if(b.current!==`open`||!r)return;b.current=`closing`;let i=x.current+=1;w(`closing`),e&&r.focus({preventScroll:!0,focusVisible:e===`keyboard`});let a=f?Y:n.spring.snappy;t(P,0,a);let o=r.getBoundingClientRect();t(N,o.height,a),t(M,o.width,{...a,onComplete:()=>{i===x.current&&(b.current=`closed`,M.jump(`100%`),N.jump(`100%`),w(`closed`),E(null))}})},[N,P,f,M]);(0,G.useLayoutEffect)(()=>{let e=y.current;if(!e||typeof ResizeObserver>`u`)return;let r=new ResizeObserver(()=>{b.current===`open`&&t(N,e.offsetHeight+2,f?Y:n.spring.smooth)});return r.observe(e),()=>r.disconnect()},[N,f]),(0,G.useLayoutEffect)(()=>{let e=S.current,t=y.current;if(!e||!t||C!==`open`)return;if(S.current=null,e===`panel`){t.focus({preventScroll:!0});return}let n=Array.from(t.querySelectorAll(`[data-current] [data-row]`));(e===`first`?n[0]:e===`last`?n.at(-1):e===`checked`?n.find(e=>e.getAttribute(`aria-checked`)===`true`)??n[0]:n.find(t=>t.dataset.row===e.key)??n[0])?.focus({preventScroll:!0})},[C,T]),(0,G.useEffect)(()=>{if(C!==`open`)return;let e=e=>{let t=g.current,n=e.target;!t||n&&t.contains(n)||(H(!1),n?.closest?.(`button, a[href], input, select, textarea, [tabindex], [contenteditable]`)||window.setTimeout(()=>{let e=document.activeElement;(!e||e===document.body||t.contains(e))&&v.current?.focus({preventScroll:!0,focusVisible:!1})},0))};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[H,C]);function ce(e){if(e.defaultPrevented)return;let t=Array.from(y.current?.querySelectorAll(`[data-current] [data-row]`)??[]);(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),(e.key===`ArrowDown`?t[0]:t.at(-1))?.focus({preventScroll:!0})),e.key===`ArrowLeft`&&V&&(e.preventDefault(),ue(!0))}function ue(e){V&&(S.current=e?{key:V.id}:`panel`,O(-1),E(null))}function de(e,t){S.current=t?`checked`:`panel`,O(1),E(e.key)}function fe(e,t){V&&(r({id:V.id,label:V.label,value:e.key,valueLabel:e.label},V),H(t?`keyboard`:`pointer`))}let pe=e=>a.find(t=>t.id===e.id),me=e.map(e=>({key:e.id,label:e.label,icon:e.icon,drill:!0,meta:(0,q.jsxs)(q.Fragment,{children:[pe(e)?(0,q.jsx)(`span`,{className:K.metaValue,children:Z(pe(e))}):null,(0,q.jsx)(ae,{size:15,strokeWidth:1.8,"aria-hidden":`true`})]})})),W=V?V.options.map(xe).map(e=>{let t=Se(e),n=pe(V)?.value===e.value;return{key:e.value,label:t,icon:e.icon,checked:n,meta:e.hint!=null||n?(0,q.jsxs)(q.Fragment,{children:[e.hint==null?null:(0,q.jsx)(`span`,{className:K.hint,children:e.hint}),(0,q.jsx)(`span`,{className:K.check,"data-on":n||void 0,children:(0,q.jsx)(_,{size:15,strokeWidth:2,"aria-hidden":`true`})})]}):null}}):[],ge={enter:e=>f?{opacity:0}:{opacity:0,x:e*18,filter:X(n.blur.soft)},center:{opacity:1,x:0,filter:X(0),transition:f?ye:{...J,x:n.spring.smooth}},exit:e=>f?{opacity:0,transition:Y}:{opacity:0,x:e*-18,filter:X(n.blur.subtle),transition:ve}};return(0,q.jsxs)(`div`,{ref:g,className:K.menu,"data-state":C,"data-y":k?`up`:`down`,onKeyDown:e=>{e.key===`Escape`&&b.current===`open`&&(e.preventDefault(),e.stopPropagation(),H(`keyboard`))},onBlur:e=>{let t=e.relatedTarget;b.current===`open`&&t&&!g.current?.contains(t)&&H(!1)},children:[(0,q.jsx)(`button`,{ref:v,type:`button`,className:K.trigger,"data-filter-trigger":``,"aria-haspopup":`dialog`,"aria-expanded":oe,"aria-controls":m,tabIndex:oe?-1:void 0,onClick:e=>{b.current!==`open`&&se(e.detail===0?`first`:`panel`)},onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),se(e.key===`ArrowDown`?`first`:`last`))},children:(0,q.jsxs)(F.span,{className:K.face,style:re,children:[(0,q.jsx)(he,{size:15,strokeWidth:1.8,"aria-hidden":`true`}),o]})}),(0,q.jsx)(F.div,{className:K.surface,style:{left:P,width:M,height:N},children:(0,q.jsx)(F.div,{ref:y,id:m,className:K.panel,role:`dialog`,"aria-labelledby":h,tabIndex:-1,inert:!oe,style:{x:te},onKeyDown:ce,children:(0,q.jsxs)(F.div,{style:ie,children:[(0,q.jsxs)(`div`,{className:K.head,children:[(0,q.jsx)(d,{initial:!1,children:V?(0,q.jsx)(F.button,{type:`button`,className:K.back,"aria-label":l.back,onClick:e=>ue(e.detail===0),initial:f?{opacity:0,width:28,marginRight:2}:{opacity:0,width:0,marginRight:0,scale:.6},animate:{opacity:1,width:28,marginRight:2,scale:1},exit:f?{opacity:0,transition:Y}:{opacity:0,width:0,marginRight:0,scale:.6,transition:{...n.spring.snappy,opacity:ve}},transition:f?ye:{...n.spring.snappy,opacity:J},children:(0,q.jsx)(le,{size:16,strokeWidth:1.8,"aria-hidden":`true`})},`back`):null}),(0,q.jsx)(`span`,{className:K.title,id:h,children:(0,q.jsx)(d,{mode:`popLayout`,initial:!1,children:(0,q.jsx)(F.span,{className:K.titleText,...Ce(f),children:V?V.label:o},V?.id??`fields`)})})]}),(0,q.jsx)(`div`,{className:K.stage,children:(0,q.jsx)(d,{mode:`popLayout`,initial:!1,custom:D,children:(0,q.jsx)(F.div,{className:K.step,custom:D,variants:ge,initial:`enter`,animate:`center`,exit:`exit`,children:V?(0,q.jsx)(Ae,{rows:W,labelledBy:h,emptyMessage:l.noOptions,radio:!0,onChoose:fe,onBack:ue,onLeave:()=>y.current?.focus({preventScroll:!0})}):(0,q.jsx)(Ae,{rows:me,labelledBy:h,emptyMessage:l.noOptions,onChoose:de,onLeave:()=>y.current?.focus({preventScroll:!0})})},V?.id??`fields`)})})]})})})]})}function Ne({filters:e,onRemove:t,onClearAll:r,leading:i,children:a,label:o=`Active filters`,addFilter:s,messages:c}){let l={...Oe,...c},f=u()??!1,p=(0,G.useRef)(null),m=(0,G.useRef)(null),h=(0,G.useRef)(0),g=(0,G.useRef)(null),[_,v]=(0,G.useState)(e),[y,b]=(0,G.useState)(``);if(_!==e){v(e);let t=ke(_,e,l);t&&b(t)}let S=e.map(e=>`${e.id}:${e.value??``}`).join(`|`);(0,G.useLayoutEffect)(()=>{h.current=performance.now()+900},[S]);let C=Te(m,h,f);Ee(m,h,f),(0,G.useLayoutEffect)(()=>{let t=g.current,n=p.current;if(t===null||!n)return;g.current=null;let r=e[Math.min(t,e.length-1)];(r?n.querySelector(`[data-chip-remove="${CSS.escape(r.id)}"]`):n.querySelector(`[data-filter-trigger]`))?.focus({preventScroll:!0})},[e]);let w={duration:0},T=e=>({initial:!f&&{width:0,marginRight:-e,overflow:`clip`,"--slot-moving":1},animate:{width:`auto`,marginRight:0,transitionEnd:{overflow:`visible`,"--slot-moving":0}},exit:f?{opacity:0,transition:w}:{width:0,marginRight:-e,overflow:`clip`,"--slot-moving":1,pointerEvents:`none`,transition:{...n.spring.smooth,"--slot-moving":w}},transition:f?w:n.spring.smooth}),E={initial:!f&&{opacity:0,scale:.9,filter:X(n.blur.soft)},animate:{opacity:1,scale:1,filter:X(0)},exit:f?{opacity:0,transition:w}:{opacity:0,scale:.9,filter:X(n.blur.subtle),transition:ve},transition:f?w:{...J,scale:n.spring.snappy}},D=f?{...Ce(!0),initial:!1}:Ce(!1),O=f?D:{...D,transition:{...J,delay:n.duration.instant*.75}};return(0,q.jsxs)(`div`,{ref:p,className:K.toolbar,role:`group`,"aria-label":o,children:[i?(0,q.jsx)(`div`,{className:K.leading,children:i}):null,(0,q.jsx)(F.div,{className:K.frame,style:{height:C},children:(0,q.jsxs)(`div`,{ref:m,className:K.chips,children:[(0,q.jsx)(d,{initial:!1,children:e.map((e,n)=>(0,q.jsx)(F.span,{className:K.slot,...T(8),children:(0,q.jsxs)(F.span,{className:K.chip,...E,children:[(0,q.jsxs)(`span`,{className:K.chipLabel,title:De(e),children:[e.label,Z(e)?(0,q.jsxs)(`span`,{className:K.value,children:[(0,q.jsx)(`span`,{className:K.separator,children:` · `}),(0,q.jsx)(we,{text:Z(e)})]}):null]}),(0,q.jsx)(`button`,{type:`button`,"data-chip-remove":e.id,"aria-label":l.remove(e),onClick:r=>{document.activeElement===r.currentTarget&&(g.current=n),t(e.id)},children:(0,q.jsx)(x,{size:14,strokeWidth:1.8,"aria-hidden":`true`})})]})},e.id))}),(0,q.jsx)(d,{initial:!1,children:e.length?null:(0,q.jsx)(F.span,{className:K.empty,...O,children:l.empty},`empty`)})]})}),(0,q.jsxs)(`div`,{className:K.actions,children:[s?(0,q.jsx)(Me,{fields:s.fields,onSelect:s.onAdd,active:e,label:s.label,align:s.align,messages:l}):null,a,(0,q.jsx)(d,{initial:!1,children:e.length>0&&r?(0,q.jsx)(F.span,{className:K.slot,...T(12),children:(0,q.jsx)(`button`,{className:K.clear,type:`button`,onClick:()=>{g.current=-1,r?.()},children:(0,q.jsx)(F.span,{className:K.clearText,...D,children:l.clearAll})})},`clear`):null})]}),(0,q.jsx)(`span`,{className:K.srOnly,role:`status`,children:y})]})}var Pe={api_key:`settings.privacy.category.api_key`,aws_key:`settings.privacy.category.aws_key`,jwt:`settings.privacy.category.jwt`,private_key:`settings.privacy.category.private_key`,email:`settings.privacy.category.email`,phone:`settings.privacy.category.phone`,intranet:`settings.privacy.category.intranet`,credit_card:`settings.privacy.category.credit_card`,national_id:`settings.privacy.category.national_id`,credential:`settings.privacy.category.credential`,custom:`settings.privacy.category.custom`},Fe={warn:`settings.privacy.action.warn`,block:`settings.privacy.action.block`,redact:`settings.privacy.action.redact`};function Ie(){let{t:e}=y();return t=>{let n=Pe[t];return n?e(n):t}}function Le({action:e}){let{t}=y();return(0,q.jsx)(D,{tone:e===`block`?`red`:e===`redact`?`orange`:`neutral`,children:t(Fe[e]??`settings.privacy.action.warn`)})}var Re=50,ze=[`block`,`redact`,`warn`];function Be(){let{t:e,locale:t}=y(),n=Ie(),[r,i]=(0,G.useState)(``),[a,s]=(0,G.useState)({client:``,category:``,action:``,blocked:``}),[c,l]=(0,G.useState)(1),[u,d]=(0,G.useState)(null),h=oe(r),g=p(),_=m(),b={model:h,...a,page:c,pageSize:Re},x=S(b,c===1),C=x.data,T=C?Math.max(1,Math.ceil(C.total/Re)):1,E=e=>e?ue[e]?.name??e:`—`,D=[...new Set((_.data?.rules??[]).map(e=>e.category))],A={client:(g.data??[]).map(e=>({value:e.kind,label:e.name})),category:D.map(e=>({value:e,label:n(e)})),action:ze.map(t=>({value:t,label:e(`settings.privacy.action.${t}`)})),blocked:[{value:`true`,label:e(`privacy.logs.blockedOnly`)},{value:`false`,label:e(`privacy.logs.passedOnly`)}]},j={client:e(`requests.col.client`),category:e(`privacy.stats.col.category`),action:e(`privacy.logs.col.action`),blocked:e(`privacy.logs.col.outcome`)},N=Object.keys(A).map(e=>({id:e,label:j[e],options:A[e].map(e=>e.label)})),P=Object.keys(a).filter(e=>a[e]).map(e=>({id:e,label:j[e],value:A[e].find(t=>t.value===a[e])?.label??a[e]})),F=(e,t)=>{s(n=>({...n,[e]:t})),l(1)},te=(C?.items??[]).map(e=>({id:e.id,time:Date.parse(e.startedAtUtc),client:E(e.clientKind),model:e.requestedModel??``,outcome:Ve(e),hits:e.hits.reduce((e,t)=>e+t.count,0),e})),L=[{key:`time`,label:e(`requests.col.time`),width:92,render:(e,n)=>(0,q.jsx)(`span`,{className:`num`,children:o(n.e.startedAtUtc,t)})},{key:`model`,label:e(`requests.col.model`),render:(t,n)=>(0,q.jsxs)(`button`,{type:`button`,className:`block w-full min-w-0 text-left`,onClick:()=>d(n.id),"aria-label":e(`privacy.logs.viewRequest`,{model:n.model||n.id}),children:[(0,q.jsx)(`span`,{className:`block truncate font-medium hover:text-[var(--accent)]`,children:n.model||`—`}),(0,q.jsx)(`span`,{className:`block truncate text-[11px] text-[var(--text-muted)]`,children:E(n.e.clientKind)})]})},{key:`outcome`,label:e(`privacy.logs.col.outcome`),width:130,render:(e,t)=>(0,q.jsx)(He,{event:t.e})},{key:`hits`,label:e(`privacy.logs.col.hits`),render:(e,t)=>(0,q.jsx)(Ue,{event:t.e})},{key:`client`,label:e(`requests.col.client`),width:110,render:e=>(0,q.jsx)(`span`,{className:`block truncate`,children:String(e||`—`)})}];return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,q.jsx)(w,{className:`w-52`,value:r,onChange:e=>{i(e),l(1)},placeholder:e(`requests.searchModel`)}),(0,q.jsx)(k,{variant:`plain`,icon:(0,q.jsx)(H,{className:O(`size-4`,x.isFetching&&`animate-spin`)}),"aria-label":e(`common.refresh`),onClick:()=>void x.refetch()})]}),(0,q.jsx)(`div`,{className:`mb-3`,children:(0,q.jsx)(Ne,{label:e(`requests.filters`),filters:P,onRemove:e=>F(e,``),onClearAll:()=>{s({client:``,category:``,action:``,blocked:``}),l(1)},addFilter:{fields:N,label:e(`requests.addFilter`),onAdd:e=>{let t=e.id,n=A[t].find(t=>t.label===e.value)?.value;n&&F(t,n)}}})}),x.isLoading&&(0,q.jsx)(M,{lines:4,className:`py-6`}),x.isError&&(0,q.jsx)(ee,{tone:`danger`,title:e(`common.error`),children:I(x.error)}),C&&C.items.length===0&&(0,q.jsx)(v,{icon:(0,q.jsx)(_e,{className:`size-6`}),title:e(`privacy.logs.empty`),detail:e(`privacy.logs.empty.detail`)}),C&&C.items.length>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mb-2 text-[12px] text-[var(--text-secondary)]`,children:e(`privacy.logs.total`,{count:f(C.total)})}),(0,q.jsx)(B,{caption:e(`privacy.tab.logs`),rows:te,columns:L,rowKey:`id`,emptyMessage:e(`privacy.logs.empty`)})]}),C&&T>1&&(0,q.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,q.jsx)(de,{page:c,pageCount:T,onPageChange:l,label:e(`requests.page`,{page:c,pages:T})})}),(0,q.jsx)(pe,{id:u,onClose:()=>d(null)})]})}function Ve(e){return e.blocked?`blocked`:e.redactions>0?`redact`:e.dryRun?`dryRun`:`warn`}function He({event:e}){let{t}=y();return e.blocked?(0,q.jsx)(D,{tone:`red`,children:t(`privacy.logs.outcome.blocked`)}):e.redactions>0?(0,q.jsx)(D,{tone:`orange`,children:t(`privacy.logs.outcome.redacted`,{count:e.redactions})}):e.dryRun?(0,q.jsx)(D,{tone:`neutral`,children:t(`privacy.logs.outcome.dryRun`)}):(0,q.jsx)(D,{tone:`neutral`,children:t(`settings.privacy.action.warn`)})}function Ue({event:e}){let t=Ie(),{t:n}=y();if(e.hits.length===0)return(0,q.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:`—`});let r=e.hits.slice(0,2),i=e.hits.length-r.length;return(0,q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[12px]`,children:[r.map(e=>(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(Le,{action:e.action}),(0,q.jsxs)(`span`,{children:[t(e.category),` × `,e.count]}),e.samples&&e.samples.length>0&&(0,q.jsx)(`span`,{className:`font-mono text-[11px] text-[var(--text-muted)]`,children:e.samples.slice(0,2).join(` `)})]},`${e.ruleId}:${e.action}`)),i>0&&(0,q.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:n(`privacy.logs.moreHits`,{count:i})})]})}var Q={counter:`_counter_dnoch_1`,label:`_label_dnoch_2`,value:`_value_dnoch_4`,column:`_column_dnoch_6`,sizer:`_sizer_dnoch_7`,glyph:`_glyph_dnoch_8`,labelText:`_labelText_dnoch_9`,labelSwap:`_labelSwap_dnoch_10`,symbol:`_symbol_dnoch_11`,srOnly:`_srOnly_dnoch_12`},We=[0,1,2,3,4,5,6,7,8,9],Ge={hidden:{opacity:0,y:`0.3em`,filter:`blur(${n.blur.soft}px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.standard,ease:[...n.ease.enter]}},gone:{opacity:0,y:`-0.3em`,filter:`blur(${n.blur.subtle}px)`,transition:{duration:n.duration.fast,ease:[...n.ease.standard]}}},Ke={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}}},qe={...n.spring.smooth,visualDuration:n.duration.considered};function Je(e,t,n){let r=new Intl.NumberFormat(n,{minimumFractionDigits:t,maximumFractionDigits:t,numberingSystem:`latn`}).formatToParts(e),i=r.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),a=0,o=0;return r.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--i}`,digit:Number(e),order:o++})):e.type===`fraction`?[...e.value].map(e=>({key:`f${a++}`,digit:Number(e),order:o++})):[{key:e.type===`group`?`g${i}`:e.type===`decimal`?`d`:`${e.type}${t}`,text:e.value}])}function Ye({position:e,digit:t}){let r=U(e,e=>((t-e)%10+15)%10-5),i=U(r,e=>`${e}em`),a=U(r,e=>Math.max(0,1-Math.abs(e))),o=U(r,e=>Math.abs(e)>=1?`hidden`:`visible`),s=U(r,e=>Math.abs(e)<.02||Math.abs(e)>=1?`none`:`blur(${(Math.abs(e)*n.blur.subtle).toFixed(2)}px)`);return(0,q.jsx)(F.span,{className:Q.glyph,style:{y:i,opacity:a,filter:s,visibility:o},children:t})}var Xe={initial:{width:0,opacity:0},animate:{width:`auto`,opacity:1},exit:{width:0,opacity:0}};function Ze({digit:e,direction:r,armed:a,delay:o,reduceMotion:s}){let c=i(a?0:e),l=(0,G.useRef)({digit:a?0:e,target:a?0:e,revealed:!a});return(0,G.useEffect)(()=>{let i=l.current;if(a||i.digit===e){a||(i.revealed=!0);return}i.target+=r<0&&i.revealed?-((i.digit-e+10)%10):(e-i.digit+10)%10,i.digit=e,s?c.jump(i.target):t(c,i.target,i.revealed?n.spring.smooth:{...qe,delay:o}),i.revealed=!0},[a,o,e,r,c,s]),(0,q.jsxs)(F.span,{className:Q.column,...Xe,transition:s?{duration:0}:n.spring.morph,children:[(0,q.jsx)(`span`,{className:Q.sizer,children:`0`}),We.map(e=>(0,q.jsx)(Ye,{position:c,digit:e},e))]})}function Qe({value:e,label:t,prefix:r=``,suffix:i=``,decimals:a=0,animateOnView:o=!1,locale:s=`en-US`}){let c=(0,G.useRef)(null),l=me(c,{once:!0,amount:.6}),f=!!u(),[p,m]=(0,G.useState)(e),[h,g]=(0,G.useState)(1);e!==p&&(m(e),g(e>p?1:-1));let _=Je(e,a,s),v=`${r}${_.map(e=>`text`in e?e.text:e.digit).join(``)}${i}`,y=o&&!l;return(0,q.jsxs)(`span`,{ref:c,className:Q.counter,children:[t&&(0,q.jsx)(`span`,{className:Q.label,children:(0,q.jsx)(`span`,{className:Q.labelSwap,children:(0,q.jsx)(d,{mode:`popLayout`,initial:!1,children:(0,q.jsx)(F.span,{className:Q.labelText,variants:f?Ke:Ge,initial:`hidden`,animate:`shown`,exit:`gone`,children:t},t)})})}),(0,q.jsx)(`span`,{className:Q.srOnly,children:v}),(0,q.jsxs)(`span`,{className:Q.value,"aria-hidden":`true`,children:[r&&(0,q.jsx)(`span`,{className:Q.symbol,children:r}),(0,q.jsx)(d,{initial:!1,children:_.map(e=>`digit`in e?(0,q.jsx)(Ze,{digit:e.digit,direction:h,armed:y,delay:Math.min(e.order*n.stagger.item,.25),reduceMotion:f},e.key):(0,q.jsx)(F.span,{className:Q.symbol,...Xe,transition:f?{duration:0}:n.spring.morph,children:e.text},e.key))}),i&&(0,q.jsx)(`span`,{className:Q.symbol,children:i})]})]})}var $={card:`_card_1r6t9_1`,top:`_top_1r6t9_2`,swap:`_swap_1r6t9_8`,swapBlock:`_swapBlock_1r6t9_8`,text:`_text_1r6t9_11`,sizer:`_sizer_1r6t9_13`},$e={hidden:e=>({opacity:0,y:`${.3*e}em`,filter:`blur(${n.blur.soft}px)`}),shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.standard,ease:[...n.ease.enter]}},gone:e=>({opacity:0,y:`${-.3*e}em`,filter:`blur(${n.blur.subtle}px)`,transition:{duration:n.duration.fast,ease:[...n.ease.standard]}})},et={hidden:{opacity:0,y:0,filter:`blur(0px)`},shown:{opacity:1,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}},gone:{opacity:0,y:0,filter:`blur(0px)`,transition:{duration:n.duration.instant}}},tt=e=>Number(e.replace(/,/g,``).match(/-?\d+(?:\.\d+)?/)?.[0]??NaN);function nt({text:e,morph:r=!1,block:a=!1}){let o=!!u(),s=(0,G.useRef)(null),c=i(`auto`),[l,f]=(0,G.useState)({text:e,direction:1});return l.text!==e&&f({text:e,direction:tt(e)<tt(l.text)?-1:1}),(0,G.useEffect)(()=>{let e=s.current;if(!e||typeof ResizeObserver>`u`)return;let r=null,i=new ResizeObserver(([i])=>{let a=i.borderBoxSize?.[0]?.inlineSize??e.offsetWidth;a&&r!==null&&r!==e.textContent&&!o?t(c,a,n.spring.morph):c.jump(a||`auto`),r=a?e.textContent:null});return i.observe(e),()=>i.disconnect()},[r,o,c]),(0,q.jsxs)(F.span,{className:a?$.swapBlock:$.swap,style:r?{width:c}:void 0,children:[r&&(0,q.jsx)(`span`,{ref:s,className:$.sizer,"aria-hidden":`true`,children:e}),(0,q.jsx)(d,{mode:`popLayout`,initial:!1,custom:l.direction,children:(0,q.jsx)(F.span,{className:$.text,custom:l.direction,variants:o?et:$e,initial:`hidden`,animate:`shown`,exit:`gone`,children:e},e)})]})}function rt({label:e,value:t,suffix:r,context:i,change:a}){let o=!!u();return(0,q.jsxs)(`article`,{className:$.card,children:[(0,q.jsxs)(`div`,{className:$.top,children:[(0,q.jsx)(`span`,{children:(0,q.jsx)(nt,{text:e,block:!0})}),(0,q.jsx)(d,{initial:!1,children:a&&(0,q.jsx)(F.small,{"data-trend":/^[+]/.test(a)?`up`:/^[-−]/.test(a)?`down`:void 0,initial:{opacity:0,scale:o?1:.96},animate:{opacity:1,scale:1},exit:{opacity:0,scale:o?1:.96,transition:{duration:n.duration.fast,ease:[...n.ease.standard]}},transition:o?{duration:0}:n.spring.snappy,children:(0,q.jsx)(nt,{text:a,morph:!0})},`change`)})]}),(0,q.jsx)(Qe,{value:t,suffix:r,animateOnView:!0}),(0,q.jsx)(`p`,{children:(0,q.jsx)(nt,{text:i,block:!0})})]})}var it=[{id:`ipv4-all`,nameKey:`settings.privacy.template.ipv4All`,hintKey:`settings.privacy.template.ipv4AllHint`,pattern:String.raw`(?<![\d.])(?:\d{1,3}\.){3}\d{1,3}(?![\d.])`},{id:`landline`,nameKey:`settings.privacy.template.landline`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<!\d)0\d{2,3}[- ]?\d{7,8}(?!\d)`},{id:`license-plate`,nameKey:`settings.privacy.template.licensePlate`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]`},{id:`passport-cn`,nameKey:`settings.privacy.template.passportCn`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![A-Za-z0-9])[EG]\d{8}(?!\d)`},{id:`uscc`,nameKey:`settings.privacy.template.uscc`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![0-9A-HJ-NPQRTUWXY])[0-9A-HJ-NPQRTUWXY]{18}(?![0-9A-HJ-NPQRTUWXY])`},{id:`long-token`,nameKey:`settings.privacy.template.longToken`,hintKey:`settings.privacy.template.longTokenHint`,pattern:String.raw`(?<![A-Za-z0-9])[A-Za-z0-9_\-]{32,}(?![A-Za-z0-9])`},{id:`mac-address`,nameKey:`settings.privacy.template.macAddress`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![0-9A-Fa-f:])(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(?![0-9A-Fa-f:])`},{id:`unix-home`,nameKey:`settings.privacy.template.unixHome`,hintKey:`settings.privacy.template.unixHomeHint`,pattern:String.raw`/(?:Users|home)/[A-Za-z0-9_.\-]+`},{id:`windows-profile`,nameKey:`settings.privacy.template.windowsProfile`,hintKey:`settings.privacy.template.unixHomeHint`,pattern:String.raw`[A-Za-z]:\\+Users\\+[A-Za-z0-9_.\-]+`},{id:`cloud-accesskey`,nameKey:`settings.privacy.template.cloudAccessKey`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![A-Za-z0-9])(?:LTAI[A-Za-z0-9]{12,20}|AKID[A-Za-z0-9]{13,40})(?![A-Za-z0-9])`},{id:`aws-secret-key`,nameKey:`settings.privacy.template.awsSecretKey`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![A-Za-z0-9/+=])[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])`},{id:`im-webhook`,nameKey:`settings.privacy.template.imWebhook`,hintKey:`settings.privacy.template.imWebhookHint`,pattern:String.raw`oapi\.dingtalk\.com/robot/send\?access_token=[0-9a-f]{64}|qyapi\.weixin\.qq\.com/cgi-bin/webhook/send\?key=[0-9a-f]{32}|open\.feishu\.cn/open-apis/bot/v2/hook/[0-9a-f\-]{20,}|hooks\.slack\.com/services/T[A-Za-z0-9]+/B[A-Za-z0-9]+/[A-Za-z0-9]+`},{id:`internal-service`,nameKey:`settings.privacy.template.internalService`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?:gitlab|jenkins|jira|confluence|wiki|nexus|harbor|grafana|kibana|sonarqube|oa|sso)\.[A-Za-z0-9\-]+(?:\.[A-Za-z0-9\-]+)+`},{id:`jdbc-conn`,nameKey:`settings.privacy.template.jdbcConn`,hintKey:`settings.privacy.template.jdbcHint`,pattern:String.raw`jdbc:[A-Za-z0-9]+:[^\s"']*(?:[Uu]ser(?:[ _]?[Ii][Dd])?|[Pp]assword)=[^\s"&';]+`},{id:`smtp-conn`,nameKey:`settings.privacy.template.smtpConn`,hintKey:`settings.privacy.template.jdbcHint`,pattern:String.raw`(?:smtp|imap|pop3)s?://[^\s:@/]+:[^\s@]+@[^\s]+`},{id:`key-file-ref`,nameKey:`settings.privacy.template.keyFileRef`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`[A-Za-z0-9_\-./\\]+\.(?:pem|key|pfx|p12|jks|keystore)\b`},{id:`confidential-marker`,nameKey:`settings.privacy.template.confidentialMarker`,hintKey:`settings.privacy.template.confidentialHint`,pattern:String.raw`(?:绝密|机密|商业秘密|内部资料|内部公开|仅限内部|请勿外传|Confidential|Internal Use Only|Internal Only|Company Private)`},{id:`employee-id`,nameKey:`settings.privacy.template.employeeId`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?<![A-Za-z0-9])(?:[Ee][Mm][Pp]|工号)[::\- ]?\d{4,10}(?!\d)`},{id:`labeled-number`,nameKey:`settings.privacy.template.labeledNumber`,hintKey:`settings.privacy.template.genericHint`,pattern:String.raw`(?:合同|订单|采购单|工单|项目)编号[::]?\s*[A-Za-z0-9_\-]{4,32}`}],at=[`off`,`warn`,`block`,`redact`],ot=Fe;function st(){let{t:e}=y(),{toast:t}=L(),n=m(),r=j(),i=n.data?.settings,a=e=>{i&&r.mutate({...i,...e},{onError:e=>t(I(e),`error`)})},o=at.map(t=>({value:t,label:e(t===`off`?`settings.privacy.action.off`:ot[t])}));return(0,q.jsxs)(A,{title:e(`settings.privacy`),footer:e(`settings.privacy.footer`),children:[n.isLoading&&(0,q.jsx)(M,{className:`my-4`}),n.isError&&(0,q.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--danger)]`,children:I(n.error)}),i&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(E,{label:e(`settings.privacy.enabled`),detail:e(`settings.privacy.enabledHint`),children:(0,q.jsx)(P,{checked:i.enabled,label:e(`settings.privacy.enabled`),onChange:e=>a({enabled:e})})}),(0,q.jsx)(E,{label:e(`settings.privacy.dryRun`),detail:e(`settings.privacy.dryRunHint`),children:(0,q.jsx)(P,{checked:i.dryRun,disabled:!i.enabled,label:e(`settings.privacy.dryRun`),onChange:e=>a({dryRun:e})})}),(0,q.jsx)(E,{label:e(`settings.privacy.restore`),detail:e(`settings.privacy.restoreHint`),children:(0,q.jsx)(P,{checked:i.restoreResponses,disabled:!i.enabled,label:e(`settings.privacy.restore`),onChange:e=>a({restoreResponses:e})})}),(0,q.jsx)(E,{label:e(`settings.privacy.recordSamples`),detail:e(`settings.privacy.recordSamplesHint`),children:(0,q.jsx)(P,{checked:i.recordSamples,disabled:!i.enabled,label:e(`settings.privacy.recordSamples`),onChange:e=>a({recordSamples:e})})}),(0,q.jsx)(E,{label:e(`settings.privacy.defaultAction`),children:(0,q.jsx)(R,{className:`w-36`,ariaLabel:e(`settings.privacy.defaultAction`),value:i.defaultAction,disabled:!i.enabled,onChange:e=>a({defaultAction:e}),options:o})})]})]})}function ct(){let{t:e}=y(),{toast:t}=L(),n=m(),r=j(),i=n.data?.settings,a=Ie(),o=e=>{i&&r.mutate({...i,...e},{onError:e=>t(I(e),`error`)})},s=(e,t)=>o({categoryActions:{...i?.categoryActions,[e]:t}}),c=at.map(t=>({value:t,label:e(t===`off`?`settings.privacy.action.off`:ot[t])})),l=[...new Set((n.data?.rules??[]).map(e=>e.category))],u=e=>n.data?.rules.find(t=>t.category===e)?.description;return n.isLoading?(0,q.jsx)(`div`,{className:`mx-auto max-w-[720px]`,children:(0,q.jsx)(M,{className:`my-4`})}):i?(0,q.jsxs)(`div`,{className:`mx-auto flex max-w-[720px] flex-col gap-4`,children:[(0,q.jsx)(A,{title:e(`settings.privacy.categories`),children:l.map(t=>{let n=i.categoryActions[t]??i.defaultAction,r=!i.enabled||n===`off`;return(0,q.jsxs)(E,{label:a(t),detail:u(t),children:[n===`off`?(0,q.jsx)(D,{children:e(`settings.privacy.action.off`)}):(0,q.jsx)(R,{className:`w-36`,ariaLabel:a(t),value:n,disabled:!i.enabled,onChange:e=>s(t,e),options:c.filter(e=>e.value!==`off`)}),r&&(0,q.jsx)(k,{size:`sm`,variant:`plain`,disabled:!i.enabled,onClick:()=>s(t,i.categoryActions[t]??i.defaultAction),children:e(`settings.privacy.enableCategory`)})]},t)})}),(0,q.jsx)(lt,{s:i,onPatch:o})]}):null}function lt({s:e,onPatch:t}){let{t:n}=y(),{confirm:r}=L(),[i,a]=(0,G.useState)(!1),o=(n,r)=>t({customRules:e.customRules.map(e=>e.id===n.id?{...e,enabled:r}:e)}),s=async i=>{await r({title:n(`settings.privacy.deleteRuleConfirm`,{name:i.name}),destructive:!0,confirmLabel:n(`common.delete`)})&&t({customRules:e.customRules.filter(e=>e.id!==i.id)})};return(0,q.jsxs)(A,{title:n(`settings.privacy.customRules`),children:[e.customRules.length===0&&(0,q.jsx)(`div`,{className:`px-4 py-4 text-[12px] text-[var(--text-secondary)]`,children:n(`settings.privacy.noCustomRules`)}),e.customRules.map(t=>(0,q.jsxs)(E,{label:t.name,detail:t.pattern,children:[(0,q.jsx)(P,{checked:t.enabled,disabled:!e.enabled,label:t.name,onChange:e=>o(t,e)}),(0,q.jsx)(k,{size:`sm`,variant:`plain`,icon:(0,q.jsx)(V,{className:`size-3.5`}),"aria-label":`${n(`common.delete`)} ${t.name}`,onClick:()=>void s(t)})]},t.id)),(0,q.jsx)(`div`,{className:`px-4 py-2`,children:(0,q.jsx)(k,{size:`sm`,icon:(0,q.jsx)(he,{className:`size-3.5`}),disabled:!e.enabled,onClick:()=>a(!0),children:n(`settings.privacy.addRule`)})}),(0,q.jsx)(ut,{open:i,onOpenChange:a,onAdd:n=>t({customRules:[...e.customRules,n]})})]})}function ut({open:e,onOpenChange:t,onAdd:n}){let{t:r}=y(),{toast:i}=L(),[a,o]=(0,G.useState)(``),[s,c]=(0,G.useState)(``),[l,u]=(0,G.useState)(``);return(0,q.jsx)(te,{open:e,onOpenChange:t,title:r(`settings.privacy.addRule`),width:480,footer:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(k,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,q.jsx)(k,{variant:`primary`,disabled:!a.trim()||!s.trim(),onClick:()=>{if(a.trim()&&s.trim()){try{new RegExp(s)}catch(e){i(`${r(`settings.privacy.invalidPattern`)}: ${I(e)}`,`error`);return}n({id:`custom-${Date.now().toString(36)}`,name:a.trim(),pattern:s.trim(),enabled:!0}),o(``),c(``),u(``),t(!1)}},children:r(`common.create`)})]}),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(T,{label:r(`settings.privacy.ruleTemplates`),hint:r(`settings.privacy.ruleTemplatesHint`),children:(0,q.jsx)(R,{ariaLabel:r(`settings.privacy.ruleTemplates`),value:l,onChange:e=>{u(e);let t=it.find(t=>t.id===e);t&&(o(r(t.nameKey)),c(t.pattern))},options:[{value:``,label:r(`settings.privacy.ruleTemplateNone`)},...it.map(e=>({value:e.id,label:r(e.nameKey)}))]})}),(0,q.jsx)(b,{label:r(`settings.privacy.ruleName`),value:a,onChange:e=>o(e.target.value),autoFocus:!0}),(0,q.jsx)(T,{label:r(`settings.privacy.rulePattern`),hint:r(`settings.privacy.rulePatternHint`),children:(0,q.jsx)(g,{mono:!0,rows:3,value:s,onChange:e=>c(e.target.value)})})]})})}function dt(){let{t:e}=y(),{toast:t}=L(),n=Ie(),r=m(),i=l(),[a,o]=(0,G.useState)(``),s=i.data,c=r.data?.settings.enabled??!1;return(0,q.jsx)(A,{title:e(`settings.privacy.tester`),footer:e(`settings.privacy.testerHint`),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-3`,children:[(0,q.jsx)(g,{"aria-label":e(`settings.privacy.tester`),placeholder:e(`settings.privacy.testerPlaceholder`),rows:4,mono:!0,value:a,onChange:e=>o(e.target.value)}),(0,q.jsx)(`div`,{children:(0,q.jsx)(k,{icon:(0,q.jsx)(ie,{className:`size-3.5`}),disabled:!c||!a.trim(),loading:i.isPending,onClick:()=>i.mutate({text:a},{onError:e=>t(I(e),`error`)}),children:e(`settings.privacy.runTest`)})}),s&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-[var(--border)] px-3 py-2 text-[12px]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.blocked&&(0,q.jsx)(D,{tone:`red`,children:e(`settings.privacy.wouldBlock`)}),s.wouldRedact>0&&(0,q.jsx)(D,{tone:`orange`,children:e(`settings.privacy.wouldRedact`,{count:s.wouldRedact})}),!s.blocked&&s.wouldRedact===0&&(0,q.jsx)(D,{tone:`green`,children:e(`settings.privacy.noHits`)})]}),s.hits.length>0&&(0,q.jsx)(`ul`,{className:`mt-2 space-y-1`,children:s.hits.map(t=>(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(D,{tone:t.action===`block`?`red`:t.action===`redact`?`orange`:`neutral`,children:e(ot[t.action])}),(0,q.jsxs)(`span`,{children:[n(t.category),` · `,t.ruleId,` × `,t.count]}),t.samples&&t.samples.length>0&&(0,q.jsx)(`span`,{className:`font-mono text-[11px] text-[var(--text-muted)]`,children:t.samples.join(` `)})]},`${t.ruleId}:${t.action}`))})]})]})})}var ft=[`today`,`7d`,`30d`,`all`];function pt(){let{t}=y(),n=Ie(),[r,i]=(0,G.useState)(`7d`),a=e(r),o=a.data,s=[{key:`category`,label:t(`privacy.stats.col.category`),render:e=>n(String(e))},{key:`requests`,label:t(`privacy.stats.col.requests`),numeric:!0,width:110},{key:`hits`,label:t(`privacy.stats.col.hits`),numeric:!0,width:96},{key:`warnHits`,label:t(`privacy.stats.col.warn`),numeric:!0,width:84},{key:`blockHits`,label:t(`privacy.stats.col.block`),numeric:!0,width:84},{key:`redactHits`,label:t(`privacy.stats.col.redact`),numeric:!0,width:84}],c=(o?.categories??[]).map(e=>({...e}));return(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsxs)(`section`,{children:[(0,q.jsx)(C,{action:(0,q.jsx)(h,{ariaLabel:t(`overview.range`),value:r,onChange:i,items:ft.map(e=>({value:e,label:t(`range.${e}`)}))}),children:t(`privacy.stats`)}),a.isLoading&&(0,q.jsx)(M,{lines:3,className:`py-4`}),a.isError&&(0,q.jsx)(ee,{tone:`danger`,title:t(`common.error`),children:I(a.error)}),o&&(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,q.jsx)(rt,{label:t(`privacy.stats.events`),value:o.events,context:t(`range.${r}`)}),(0,q.jsx)(rt,{label:t(`privacy.stats.blocked`),value:o.blocked,context:t(`range.${r}`)}),(0,q.jsx)(rt,{label:t(`privacy.stats.redactions`),value:o.redactions,context:t(`range.${r}`)}),(0,q.jsx)(rt,{label:t(`privacy.stats.dryRun`),value:o.dryRun,context:t(`range.${r}`)})]})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsx)(C,{children:t(`privacy.stats.byCategory`)}),o&&o.categories.length===0&&(0,q.jsx)(`div`,{className:`card`,children:(0,q.jsx)(mt,{})}),o&&o.categories.length>0&&(0,q.jsx)(B,{caption:t(`privacy.stats.byCategory`),rows:c,columns:s,rowKey:`category`,defaultSort:{key:`hits`,direction:`desc`}})]}),(0,q.jsx)(`div`,{className:`mx-auto w-full max-w-[720px]`,children:(0,q.jsx)(st,{})})]})}function mt(){let{t:e}=y();return(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-center`,children:[(0,q.jsx)(ie,{className:`size-6 text-[var(--text-muted)]`}),(0,q.jsx)(`div`,{className:`text-[13px]`,children:e(`privacy.logs.empty`)}),(0,q.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:e(`privacy.logs.empty.detail`)})]})}var ht=[`overview`,`logs`,`rules`,`tester`];function gt(){let{t:e}=y(),{tab:t}=ne(),n=se(),r=ht.includes(t)?t:`overview`;return(0,q.jsx)(fe,{title:e(`nav.privacy`),subtitle:e(`settings.privacy.footer`),children:(0,q.jsxs)(z,{value:r,onValueChange:e=>n(`/privacy/${e}`,{replace:!0}),children:[(0,q.jsx)(ce,{"aria-label":e(`nav.privacy`),children:ht.map(t=>(0,q.jsx)(re,{value:t,children:e(`privacy.tab.${t}`)},t))}),(0,q.jsx)(W,{value:`overview`,className:`pt-5`,children:(0,q.jsx)(pt,{})}),(0,q.jsx)(W,{value:`logs`,className:`pt-4`,children:(0,q.jsx)(Be,{})}),(0,q.jsx)(W,{value:`rules`,className:`pt-5`,children:(0,q.jsx)(ct,{})}),(0,q.jsx)(W,{value:`tester`,className:`pt-5 [&>div]:mx-auto [&>div]:max-w-[680px]`,children:(0,q.jsx)(dt,{})})]})})}export{gt as PrivacyPage};
@@ -0,0 +1,3 @@
1
+ import{At as e,Dn as t,Dt as n,Et as r,Fn as i,Gn as a,Gr as o,H as s,Hr as c,Ia as l,In as u,Ln as d,Ma as f,Na as p,Nn as m,Nr as h,On as g,Ot as _,Pt as v,Q as y,Rr as b,Rt as x,Ti as S,Un as ee,V as C,Vn as te,Vr as ne,Wn as w,Xn as T,Xt as re,Y as ie,Zt as ae,_ as oe,_i as se,a as E,ar as ce,b as le,bn as ue,br as de,c as fe,cn as D,ct as O,d as k,di as A,dr as pe,dt as me,f as j,fi as he,gt as ge,h as _e,hn as ve,ht as ye,i as be,it as xe,ja as Se,jt as Ce,l as M,m as N,mr as we,n as P,nr as Te,nt as F,on as Ee,ot as I,p as L,pi as De,pn as Oe,qn as ke,r as R,rr as Ae,rt as je,sn as Me,t as z,tr as Ne,u as B,ur as Pe,v as V,xn as Fe,xt as H,y as U,yn as Ie,zr as Le}from"./alert-qNPoglGp.js";import{a as W,i as G,n as Re,o as K,r as q}from"./overlays-ORpFxiz4.js";import{a as ze,i as J,n as Y,o as Be,t as Ve}from"./ProvidersPage-CtzKM5FI.js";import{t as He}from"./arrow-down-BtJQJK1L.js";import{t as Ue}from"./arrow-left-D6dVbOnl.js";import{t as We}from"./cloud-download-D2BBix7a.js";import{t as Ge}from"./download-COSgQOSF.js";import{t as Ke}from"./ellipsis-DU9LNejQ.js";import{t as qe}from"./external-link--dZT5Rkw.js";import{n as Je}from"./radio-cards-CyXEQMJG.js";import{t as Ye}from"./log-out-Tl6vCHvW.js";import{t as Xe}from"./power-BYCH_AFm.js";import{t as Ze}from"./rotate-ccw-D-Km3lpa.js";import{$ as Qe,C as X,E as $e,K as et,N as Z,Q as tt,T as nt,V as rt,_ as it,a as at,h as ot,o as st,q as ct,s as lt,w as ut,z as dt}from"./index-DDjZdUEf.js";import{t as ft}from"./checkbox-B47xSnbl.js";import{t as pt}from"./confirm-morph-CgGgkVSl.js";var mt={name:`arrow-right-left`,size:24,node:[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]};mt.node;var ht=H(mt),gt={name:`gift`,size:24,node:[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8`,key:`1sqzm4`}],[`path`,{d:`M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5`,key:`kc0143`}],[`rect`,{x:`3`,y:`7`,width:`18`,height:`4`,rx:`1`,key:`1hberx`}]]};gt.node;var _t=H(gt),vt={name:`list-plus`,size:24,node:[[`path`,{d:`M16 5H3`,key:`m91uny`}],[`path`,{d:`M11 12H3`,key:`51ecnj`}],[`path`,{d:`M16 19H3`,key:`zzsher`}],[`path`,{d:`M18 9v6`,key:`1twb98`}],[`path`,{d:`M21 12h-6`,key:`bt1uis`}]]};vt.node;var yt=H(vt),bt={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};bt.node;var xt=H(bt),St={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};St.node;var Ct=H(St),wt={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};wt.node;var Tt=H(wt),Et={name:`ticket`,size:24,node:[[`path`,{d:`M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z`,key:`qn84l0`}],[`path`,{d:`M13 5v2`,key:`dyzc3o`}],[`path`,{d:`M13 17v2`,key:`1ont0d`}],[`path`,{d:`M13 11v2`,key:`1wjjxi`}]]};Et.node;var Dt=H(Et),Q=l(p(),1),$=f();function Ot({usage:e,compact:t=!1}){let{t:n}=O(),r=[{label:n(`providers.usage.requests`),values:[e?.today.requests,e?.total.requests],format:(e,n=t)=>ie(e,n)},{label:n(`providers.usage.tokens`),values:[e?.today.tokens,e?.total.tokens],format:(e,n=t)=>ie(e,n)},{label:n(`providers.usage.cost`),values:[e?.today.costNanoUsd,e?.total.costNanoUsd],format:(e,n=t)=>y(xe(e),{compact:n})}];return(0,$.jsxs)(`table`,{className:I(`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 kt({timeZone:e}){let{t}=O();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 At={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`},jt={imported:`green`,updated:`accent`,ready:`accent`,duplicate:`neutral`,invalid_format:`orange`,failed:`red`},Mt={batch:`providers.accounts.import.batchTitle`,token:`providers.accounts.import.tokenTitle`,apiKey:`providers.accounts.import.apiKeyTitle`};function Nt(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 Pt(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:Nt(e))}return n}function Ft({providerId:e,info:t,mode:n,providerProxy:r,onClose:i}){let{t:a}=O(),{toast:o}=K(),s=Ie(e),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),m=(0,Q.useMemo)(()=>Pt(c),[c]);if((0,Q.useEffect)(()=>{n!==null&&(l(``),p(null))},[n]),n===null)return(0,$.jsx)(G,{open:!1,onOpenChange:i,title:``});let h=n===`apiKey`,g=h?t.formats.filter(e=>e.endsWith(`-api-key`)):t.formats,_=!h&&t.formats.some(e=>e.includes(`refresh-token`)||e.endsWith(`-json`)),v=a(h?`providers.accounts.import.apiKeyLabel`:`providers.accounts.import.label`),y=e=>s.mutate({text:c,asApiKey:h||void 0,dryRun:e||void 0,httpProxy:u.trim()||void 0},{onSuccess:t=>{p({...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(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:a(Mt[n]),description:a(`providers.accounts.import.desc`),width:560,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[g.length>0&&(0,$.jsx)(`p`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:a(`providers.accounts.import.formats`,{formats:g.map(e=>a(`providers.accounts.format.${e}`)).join(` · `)})}),(0,$.jsx)(le,{mono:!0,rows:n===`batch`?8:3,value:c,onChange:e=>l(e.target.value),"aria-label":v,placeholder:v,spellCheck:!1}),(0,$.jsx)(k,{mono:!0,label:a(`providers.accounts.import.proxy`),placeholder:r||a(`providers.accounts.proxyFallbackSystem`),value:u,onChange:e=>d(e.target.value)}),_&&(0,$.jsx)(z,{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:m})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[n===`batch`&&(0,$.jsx)(R,{disabled:m===0,loading:s.isPending&&s.variables?.dryRun===!0,onClick:()=>y(!0),children:a(`providers.accounts.import.preview`)}),(0,$.jsx)(R,{variant:`primary`,disabled:m===0||m>t.maxBatch,loading:s.isPending&&!s.variables?.dryRun,onClick:()=>y(!1),children:a(`providers.accounts.import.run`)})]})]}),f&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`text-[12px] font-medium`,children:a(f.dryRun?`providers.accounts.import.previewSummary`:`providers.accounts.import.summary`,{ok:f.imported,dup:f.duplicates,fail:f.failed})}),(0,$.jsx)(`ul`,{className:`card max-h-72 divide-y divide-[var(--border)] overflow-auto`,children:f.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)(P,{tone:jt[e.status],children:a(At[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 It(e,t=Date.now()){return e.enabled?e.status===`active`?e.cooldownUntilUtc&&new Date(e.cooldownUntilUtc).getTime()>t?`cooling`:`usable`:`dead`:`disabled`}var Lt={usable:`var(--success)`,cooling:`var(--warning)`,dead:`var(--danger)`,disabled:`var(--text-muted)`},Rt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function zt(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 Bt({account:e,index:t,actions:n,selected:r,selecting:i,onToggleSelect:a,onMove:o,quotaPending:c,usage:l}){let{t:u,locale:d}=O(),f=It(e),p=e.displayName||e.accountEmail||e.keyMasked||e.id,m=e.kind===`api_key`,h=e.plan?.trim(),g=f===`cooling`?{text:u(`providers.subscription.cooldown`,{when:s(e.cooldownUntilUtc,d)}),tone:`var(--warning)`}:f===`dead`?{text:e.lastError||u(Rt[e.status]),tone:`var(--danger)`}:m?{text:e.keyMasked??u(`providers.accounts.neverExpires`),tone:void 0}:e.expiresAtUtc?{text:u(`providers.accounts.expiresAt`,{when:s(e.expiresAtUtc,d)}),tone:void 0}:null,_=[{id:`activate`,label:u(`providers.subscription.activate`),icon:(0,$.jsx)(ht,{className:`size-3.5`}),disabled:e.isCurrent||f===`dead`,onSelect:()=>n.activate(e)},{id:`toggle`,label:u(e.enabled?`providers.subscription.disable`:`providers.subscription.enable`),icon:(0,$.jsx)(Xe,{className:`size-3.5`}),onSelect:()=>n.toggleEnabled(e)},...o?[{id:`up`,label:u(`providers.subscription.moveUp`),icon:(0,$.jsx)(et,{className:`size-3.5`}),disabled:!o.up,onSelect:()=>o.up?.()},{id:`down`,label:u(`providers.subscription.moveDown`),icon:(0,$.jsx)(He,{className:`size-3.5`}),disabled:!o.down,onSelect:()=>o.down?.()}]:[],{id:`quota`,separatorBefore:!0,label:u(`providers.subscription.quotaRefresh`),icon:(0,$.jsx)(Be,{className:`size-3.5`}),disabled:f===`dead`,onSelect:()=>n.refreshQuota(e)},...m?[]:[{id:`refresh`,label:u(`providers.subscription.refreshToken`),icon:(0,$.jsx)(Ze,{className:`size-3.5`}),disabled:e.status===`revoked`,onSelect:()=>n.refreshToken(e)},{id:`relogin`,label:u(`providers.subscription.relogin`),disabled:e.status===`active`,onSelect:()=>n.relogin(e)}],{id:`remove`,label:u(`providers.subscription.logout`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>n.remove(e)}],v=u(f===`disabled`?`providers.subscription.disabled`:Rt[e.status]),y=u(m?`providers.accounts.kind.api_key`:`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:I(`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:zt(h,m)},children:[(f===`cooling`||f===`dead`)&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 left-0 w-[3px]`,style:{background:Lt[f]}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:I(`flex size-5 items-center justify-center`,!i&&!r&&`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ft,{checked:r,onCheckedChange:()=>a(e.id),"aria-label":u(`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:Lt[f]}}),(0,$.jsx)(`span`,{"aria-hidden":!0,children:v})]}),e.httpProxy&&(0,$.jsx)(`span`,{title:`${u(`providers.accounts.proxyBadge`)}: ${e.httpProxy}`,className:`shrink-0 text-[var(--text-muted)]`,children:(0,$.jsx)(ye,{className:`size-3.5`,"aria-label":u(`providers.accounts.proxyBadge`)})}),(0,$.jsx)(`span`,{className:`-mr-1.5 ml-auto shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Re,{iconOnly:!0,label:u(`common.more`),icon:(0,$.jsx)(Ke,{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:u(`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:u(`providers.accounts.source.${e.source}`)})]}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 pl-1 opacity-0 group-hover:opacity-100`,children:u(`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)(Ot,{usage:l,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:u(`providers.accounts.signedOut`)}),!m&&(0,$.jsx)(R,{size:`sm`,className:`ml-auto`,onClick:t=>{t.stopPropagation(),n.relogin(e)},children:u(`providers.subscription.relogin`)})]}):(0,$.jsx)(Ht,{quota:e.quota??null,pending:c})]})]})}var Vt=10;function Ht({quota:e,pending:t}){let{t:n,locale:r}=O(),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:I(`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*Vt),o=e.reset?n(`providers.subscription.quotaResets`,{when:s(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:Vt},(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 Ut({quota:e,className:t}){let{t:n,locale:r}=O(),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:I(`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)(Wt,{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 Wt({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 Gt={available:`green`,redeemed:`neutral`,expired:`orange`};function Kt({account:e,providerId:t}){let{t:n}=O(),{toast:r,confirm:i}=K(),a=de(e.id,e.status===`active`),o=ae(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 S&&e.status===409?W(e):`${n(`providers.subscription.credits.consumeFailed`)}:${W(e)}`,`error`)})};return(0,$.jsxs)(B,{title:n(`providers.subscription.credits.title`),footer:n(`providers.subscription.credits.footer`),children:[a.isLoading&&(0,$.jsx)(V,{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)(N,{className:I(t&&`opacity-55`),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(_t,{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)(P,{tone:Gt[e.status]??`neutral`,children:n(`providers.subscription.credits.status.${e.status}`)}),(0,$.jsx)(R,{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 qt={active:`providers.subscription.status.active`,expired:`providers.subscription.status.expired`,revoked:`providers.subscription.status.revoked`};function Jt({provider:e,account:t,index:n,actions:r,onClose:i,usage:a,usageTimeZone:o}){let{t:c,locale:l}=O(),{toast:u}=K(),d=he(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=It(t),_=t.kind===`api_key`,v=e.templateId===`openai-subscription`,y=e.httpProxy||c(`providers.accounts.proxyFallbackSystem`),b=e=>e?s(e,l):`—`,x=(e,n)=>d.mutate({id:t.id,...e},{onSuccess:()=>u(c(n),`success`),onError:e=>u(W(e),`error`)});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&i(),title:t.displayName||t.keyMasked||t.id,description:[t.plan,c(_?`providers.accounts.kind.api_key`:`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)(R,{size:`sm`,icon:(0,$.jsx)(ht,{className:`size-3.5`}),disabled:t.isCurrent||g===`dead`,onClick:()=>r.activate(t),children:c(`providers.subscription.activate`)}),(0,$.jsx)(R,{size:`sm`,icon:(0,$.jsx)(Be,{className:`size-3.5`}),disabled:g===`dead`,onClick:()=>r.refreshQuota(t),children:c(`providers.subscription.quotaRefresh`)}),!_&&(0,$.jsx)(R,{size:`sm`,icon:(0,$.jsx)(Ze,{className:`size-3.5`}),disabled:t.status===`revoked`,onClick:()=>r.refreshToken(t),children:c(`providers.subscription.refreshToken`)}),!_&&t.status!==`active`&&(0,$.jsx)(R,{size:`sm`,variant:`primary`,onClick:()=>r.relogin(t),children:c(`providers.subscription.relogin`)}),(0,$.jsx)(R,{size:`sm`,variant:`plain`,className:`ml-auto text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),onClick:()=>r.remove(t),children:c(`providers.subscription.logout`)})]}),g===`dead`&&t.lastError&&(0,$.jsx)(z,{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:c(`providers.usage.title`)}),(0,$.jsx)(`div`,{className:`card px-3 py-2`,children:(0,$.jsx)(Ot,{usage:a})}),(0,$.jsx)(kt,{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:c(`providers.accounts.detail.identity`)}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(k,{className:`flex-1`,label:c(`providers.accounts.detail.name`),value:f,onChange:e=>p(e.target.value)}),(0,$.jsx)(R,{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:c(`common.save`)})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsx)(k,{className:`flex-1`,mono:!0,label:c(`providers.accounts.detail.proxy`),placeholder:y,value:m,onChange:e=>h(e.target.value)}),(0,$.jsx)(R,{disabled:m.trim()===(t.httpProxy??``),loading:d.isPending&&d.variables?.httpProxy!==void 0,onClick:()=>x({httpProxy:m.trim()},`providers.accounts.proxySaved`),children:c(`common.save`)})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:c(`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:c(`providers.accounts.detail.quota`)}),(0,$.jsx)(Ut,{quota:t.quota})]}),v&&g!==`dead`&&(0,$.jsx)(`div`,{className:`-mx-4`,children:(0,$.jsx)(Kt,{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:c(`providers.accounts.detail.credentials`)}),(0,$.jsxs)(`div`,{className:`card divide-y divide-[var(--border)] px-3`,children:[(0,$.jsx)(j,{label:c(`providers.accounts.detail.status`),children:(0,$.jsx)(P,{tone:g===`usable`?`green`:g===`cooling`?`orange`:g===`dead`?`red`:`neutral`,children:c(g===`disabled`?`providers.subscription.disabled`:qt[t.status])})}),t.source&&(0,$.jsx)(j,{label:c(`providers.accounts.detail.source`),children:c(`providers.accounts.source.${t.source}`)}),_?(0,$.jsx)(j,{label:c(`providers.accounts.detail.key`),mono:!0,children:t.keyMasked??`••••`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(j,{label:c(`providers.accounts.detail.expires`),children:b(t.expiresAtUtc)}),(0,$.jsx)(j,{label:c(`providers.accounts.detail.lastRefresh`),children:b(t.lastRefreshAtUtc)})]}),g===`cooling`&&(0,$.jsx)(j,{label:c(`providers.accounts.filter.cooling`),children:b(t.cooldownUntilUtc)}),(0,$.jsx)(j,{label:c(`providers.accounts.detail.order`),children:c(`providers.accounts.order`,{n:n+1})}),(0,$.jsx)(j,{label:c(`providers.accounts.detail.created`),children:b(t.createdAt)}),t.lastError&&g!==`dead`&&(0,$.jsx)(j,{label:c(`providers.accounts.detail.lastError`),children:t.lastError})]})]})]})})}function Yt({provider:e}){let{t}=O(),{toast:n}=K(),r=e.authScheme===`oauth-subscription`,i=c(e.id,r),a=se(e.id);if(!r||!i.data)return null;let o=i.data,s=e=>a.mutate(e,{onError:e=>n(W(e),`error`)}),l=o.claudeSubscription||o.clientPolicy===`claude-code-only`;return!l&&!o.claudeSubscription?null:(0,$.jsxs)(B,{title:t(`providers.subscription.policy.title`),footer:t(`providers.subscription.policy.footer`),children:[l&&(0,$.jsx)(N,{label:t(`providers.subscription.policy.claudeCodeOnly`),detail:t(`providers.subscription.policy.claudeCodeOnlyDetail`),children:(0,$.jsx)(U,{label:t(`providers.subscription.policy.claudeCodeOnly`),checked:o.clientPolicy===`claude-code-only`,disabled:a.isPending,onChange:e=>s({clientPolicy:e?`claude-code-only`:`any`})})}),o.claudeSubscription&&(0,$.jsx)(N,{label:t(`providers.subscription.policy.mimic`),detail:t(`providers.subscription.policy.mimicDetail`),children:(0,$.jsx)(U,{label:t(`providers.subscription.policy.mimic`),checked:o.mimicClaudeCode,disabled:a.isPending,onChange:e=>s({mimicClaudeCode:e})})}),l&&o.clientPolicy===`any`&&(0,$.jsx)(`div`,{className:`px-4 py-3`,children:o.mimicClaudeCode?(0,$.jsx)(z,{tone:`warning`,title:t(`providers.subscription.policy.mimicWarning`)}):(0,$.jsx)(z,{tone:`warning`,title:t(`providers.subscription.policy.anyWarning`)})})]})}var Xt=[{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`}],Zt=3e5;function Qt({provider:n}){let{t:i}=O(),{toast:a,confirm:o}=K(),s=Se(),l=n.authScheme===`oauth-subscription`,u=Te(n.id,l),d=ce(n.id,l),f=c(n.id,l),p=se(n.id),m=e(n.id,l),h=Le(n.id),_=ke(n.id),v=re(n.id),y=ve(n.id),b=Pe(n.id),x=Me(n.id),ee=Ce(n.id),C=he(n.id),te=we(n.id),ne=n.templateId===`openai-subscription`,w=t(l&&ne),T=ue(n.id),ie=n.templateId===`github-copilot-subscription`,ae=g(l&&ie),oe=Fe(n.id),[E,le]=(0,Q.useState)(`all`),[de,fe]=(0,Q.useState)(``),[D,A]=(0,Q.useState)(new Set),[pe,me]=(0,Q.useState)(null),[j,ge]=(0,Q.useState)(null),[ye,be]=(0,Q.useState)(!1),[xe,M]=(0,Q.useState)(``),[N,P]=(0,Q.useState)(!1),[F,Ee]=(0,Q.useState)(!1),[L,De]=(0,Q.useState)(null),[Oe,Ae]=(0,Q.useState)(null),[je,Ne]=(0,Q.useState)(!1),[B,H]=(0,Q.useState)(``),U=(0,Q.useRef)(new Set),Ie=(0,Q.useRef)(new Set),q=(0,Q.useMemo)(()=>u.data??[],[u.data]);if((0,Q.useEffect)(()=>{if(l)for(let e of q){if(e.status!==`active`||Ie.current.has(e.id))continue;let t=e.quota?.fetchedAtUtc?new Date(e.quota.fetchedAtUtc).getTime():0;Number.isFinite(t)&&Date.now()-t<Zt||(Ie.current.add(e.id),y.mutate(e.id,{onError:()=>{}}))}},[q,l]),(0,Q.useEffect)(()=>{let e=new Set(q.map(e=>e.id));A(t=>Array.from(t).every(t=>e.has(t))?t:new Set(Array.from(t).filter(t=>e.has(t)))),pe&&!e.has(pe)&&me(null)},[q,pe]),(0,Q.useEffect)(()=>{if(!F||L?.mode!==`pkce`)return;let e=setInterval(()=>void u.refetch(),3e3);return()=>clearInterval(e)},[F,L,u]),(0,Q.useEffect)(()=>{if(!F||L?.mode!==`pkce`)return;let e=q.find(e=>!U.current.has(e.id));e&&J(!0,e.displayName||e.accountEmail||e.id)},[q,F,L]),(0,Q.useEffect)(()=>{if(!F||L?.mode!==`device`&&L?.mode!==`cli`)return;let e=!1,t=0,n=async()=>{try{let n=await _.mutateAsync(L.state);if(e)return;t=0,n.status===`done`?J(!0,n.account.displayName||n.account.accountEmail||n.account.id):n.status!==`pending`&&n.status!==`slow_down`&&J(!1,void 0,`error`in n?n.error??n.status:n.status)}catch(n){if(e)return;if(n instanceof S&&(n.status===404||n.status===400)){J(!1,void 0,W(n));return}++t>=5&&J(!1,void 0,W(n))}},r=setInterval(()=>void n(),Math.max(L.interval||5,3)*1e3);return()=>{e=!0,clearInterval(r)}},[F,L]),!l)return null;let ze=e=>e.displayName||e.accountEmail||e.keyMasked||e.id,J=(e,t,o)=>{if(s.invalidateQueries({queryKey:r.providerAccounts(n.id)}),e){De(null),Ae(null),Ee(!1),a(i(`providers.subscription.loginOk`,{name:t??``}),`success`);return}o&&Ae(o)},Y=(e,t)=>{U.current=new Set(q.map(e=>e.id)),Ae(null),h.mutate({accountId:e,httpProxy:t},{onSuccess:e=>{be(!1),De(e),Ee(!0),e.mode!==`device`&&window.open(e.authorizeUrl,`_blank`,`noopener`)},onError:e=>{e instanceof S&&e.details?.needsVerification?a(i(`providers.subscription.needsVerification`),`error`):a(W(e),`error`)}})},Be=async()=>{if(L){Ne(!0);try{let e=await _.mutateAsync(L.state);e.status===`done`?J(!0,e.account.displayName||e.account.accountEmail||e.account.id):e.status===`pending`||e.status===`slow_down`?a(i(`providers.subscription.stillWaiting`),`info`):J(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){if(e instanceof S&&e.status===404){let t=((await u.refetch()).data??[]).find(e=>!U.current.has(e.id));t?J(!0,t.displayName||t.accountEmail||t.id):J(!1,void 0,W(e))}else J(!1,void 0,W(e))}finally{Ne(!1)}}},Ve=async()=>{if(L&&L.mode===`paste`&&B.trim().length!==0){Ne(!0);try{let e=await v.mutateAsync({state:L.state,code:B.trim()});e.status===`done`?(H(``),J(!0,e.account.displayName||e.account.accountEmail||e.account.id)):J(!1,void 0,`error`in e?e.error??e.status:e.status)}catch(e){J(!1,void 0,W(e))}finally{Ne(!1)}}},He=()=>T.mutate(void 0,{onSuccess:e=>{a(i(`providers.subscription.importOk`,{name:ze(e.account)}),e.warning?`info`:`success`),e.warning&&a(e.warning,`error`),w.refetch()},onError:e=>a(W(e),`error`)}),Ue=()=>oe.mutate(``,{onSuccess:e=>{a(i(`providers.subscription.importOk`,{name:ze(e.account)}),e.warning?`info`:`success`),e.warning&&a(e.warning,`error`)},onError:e=>a(W(e),`error`)}),We=(e,t)=>{let n=q.map(e=>e.id),r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],te.mutate(n,{onError:e=>a(W(e),`error`)}))},Ke=async e=>{let t=ze(e);await o({title:i(`providers.subscription.logoutConfirm`,{name:t}),destructive:!0,confirmLabel:i(`providers.subscription.logout`)})&&x.mutate(e.id,{onError:e=>a(W(e),`error`)})},qe={open:e=>me(e.id),activate:e=>ee.mutate(e.id,{onSuccess:()=>a(i(`providers.subscription.activated`,{name:ze(e)}),`success`),onError:e=>a(W(e),`error`)}),toggleEnabled:e=>C.mutate({id:e.id,enabled:!e.enabled},{onError:e=>a(W(e),`error`)}),refreshQuota:e=>y.mutate(e.id,{onError:e=>{e instanceof S&&e.status===501?a(i(`providers.subscription.quotaUnsupported`),`error`):a(W(e),`error`)}}),refreshToken:e=>b.mutate(e.id,{onSuccess:()=>a(i(`providers.subscription.tokenRefreshed`),`success`),onError:e=>a(W(e),`error`)}),relogin:e=>Y(e.id),remove:e=>void Ke(e)},Je=e=>A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Ye=async e=>{let t=q.filter(e=>D.has(e.id));P(!0);let o=0;for(let n of t)try{await e(n),o++}catch(e){a(`${ze(n)}: ${W(e)}`,`error`)}P(!1),A(new Set),s.invalidateQueries({queryKey:r.providerAccounts(n.id)}),o>0&&a(i(`providers.accounts.bulkDone`,{n:o}),`success`)},Ze=async()=>{await o({title:i(`providers.accounts.bulkDeleteConfirm`,{n:D.size}),detail:i(`providers.accounts.bulkDeleteDetail`),destructive:!0,confirmLabel:i(`common.delete`)})&&await Ye(e=>x.mutateAsync(e.id))},Qe=q.map(e=>It(e)),X=e=>e===`all`?q.length:Qe.filter(t=>t===e).length,$e=de.trim().toLowerCase(),et=q.map((e,t)=>({a:e,index:t,state:Qe[t]})).filter(({a:e,state:t})=>(E===`all`||t===E)&&($e.length===0||[e.displayName,e.accountEmail,e.keyMasked,e.plan].some(e=>e?.toLowerCase().includes($e)))),tt=q.find(e=>e.id===pe)??null,nt=m.data,it=D.size>0,at=[{id:`login`,label:i(`providers.accounts.addLogin`),icon:(0,$.jsx)(xt,{className:`size-3.5`}),onSelect:()=>Y()},{id:`login-proxy`,label:i(`providers.accounts.addLoginProxy`),onSelect:()=>be(!0)},...ne&&w.data?.available?[{id:`codex`,separatorBefore:!0,label:i(`providers.subscription.importCodex`),icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onSelect:He}]:[],...ie?[{id:`copilot`,separatorBefore:!0,label:i(`providers.subscription.importCopilot`),icon:(0,$.jsx)(Ge,{className:`size-3.5`}),onSelect:Ue}]:[],...nt?.supported?[{id:`token`,separatorBefore:!(ne&&w.data?.available)&&!ie,label:i(`providers.accounts.addToken`),onSelect:()=>ge(`token`)}]:[],...nt?.apiKey?[{id:`apikey`,label:i(`providers.accounts.addApiKey`),icon:(0,$.jsx)(rt,{className:`size-3.5`}),onSelect:()=>ge(`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:i(`providers.accounts.statTotal`,{n:q.length})}),(0,$.jsx)(`span`,{style:{color:`var(--success)`},children:i(`providers.accounts.statUsable`,{n:X(`usable`)})}),X(`cooling`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--warning)`},children:i(`providers.accounts.statCooling`,{n:X(`cooling`)})}),X(`dead`)>0&&(0,$.jsx)(`span`,{style:{color:`var(--danger)`},children:i(`providers.accounts.statDead`,{n:X(`dead`)})}),(0,$.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`providers.accounts.providerProxy`,{proxy:n.httpProxy||i(`providers.accounts.proxyFallbackSystem`)})})]}),f.data&&(0,$.jsx)($t,{policy:f.data,onChange:e=>p.mutate({switchMode:e},{onError:e=>a(W(e),`error`)})})]}),f.data&&(0,$.jsx)(`p`,{className:`-mt-1 mb-3 px-1 text-[11px] text-[var(--text-muted)]`,children:i(f.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:f.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(_e,{className:`w-52`,value:de,onChange:fe,placeholder:i(`providers.accounts.search`)}),(0,$.jsx)(`div`,{role:`group`,"aria-label":i(`providers.accounts.filterLabel`),className:`mr-auto flex flex-wrap gap-1`,children:Xt.filter(e=>e.value===`all`||X(e.value)>0).map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":E===e.value,onClick:()=>le(e.value),className:I(`rounded-full px-2.5 py-0.5 text-[11.5px] text-[var(--text-secondary)] transition-colors hover:bg-[var(--fill)]`,E===e.value&&`bg-[var(--fill)] text-[var(--text)]`),children:[i(e.label),(0,$.jsx)(`span`,{className:`ml-1 text-[var(--text-muted)]`,children:X(e.value)})]},e.value))}),nt?.supported&&(0,$.jsx)(R,{size:`sm`,icon:(0,$.jsx)(yt,{className:`size-3.5`}),onClick:()=>ge(`batch`),children:i(`providers.accounts.batchImport`)}),(0,$.jsx)(Re,{label:i(`providers.accounts.add`),icon:(0,$.jsx)(dt,{className:`size-3.5`}),items:at})]}),ne&&w.data?.available&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[i(`providers.subscription.localCodexFound`,{who:w.data.accountEmail??w.data.plan??i(`providers.subscription.unknownAccount`)}),w.data.detail?` · ${w.data.detail}`:``]}),ie&&(0,$.jsxs)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:[ae.data?.available?i(`providers.subscription.localCopilotFound`,{source:ae.data.source??``}):i(`providers.subscription.localCopilotHint`),ae.data?.detail?` · ${ae.data.detail}`:``]}),u.isLoading?(0,$.jsx)(V,{className:`my-4`}):q.length===0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Y(),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:i(`providers.subscription.none`)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[var(--accent)]`,children:[(0,$.jsx)(dt,{className:`size-3.5`}),` `,i(`providers.subscription.login`)]})]}):et.length===0?(0,$.jsx)(`div`,{className:`px-4 py-5 text-center text-[12px] text-[var(--text-secondary)]`,children:i(`providers.accounts.noMatch`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-3`,children:et.map(({a:e,index:t})=>(0,$.jsx)(Bt,{account:e,usage:d.data?.accounts.find(t=>t.accountId===e.id),index:t,actions:qe,selected:D.has(e.id),selecting:it,onToggleSelect:Je,quotaPending:y.isPending&&y.variables===e.id,onMove:q.length>1?{up:t>0?()=>We(t,-1):void 0,down:t<q.length-1?()=>We(t,1):void 0}:void 0},e.id))}),d.isError&&(0,$.jsx)(z,{tone:`danger`,title:i(`providers.usage.error`),children:W(d.error)}),q.length>0&&(0,$.jsx)(kt,{timeZone:d.data?.timeZone}),(0,$.jsx)(`p`,{className:`mt-2 px-1 text-[11px] text-[var(--text-muted)]`,children:i(`providers.subscription.footer`)}),it&&(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:i(`providers.accounts.selected`,{n:D.size})}),(0,$.jsx)(R,{size:`sm`,icon:(0,$.jsx)(Xe,{className:`size-3.5`}),disabled:N,onClick:()=>void Ye(e=>C.mutateAsync({id:e.id,enabled:!0})),children:i(`providers.subscription.enable`)}),(0,$.jsx)(R,{size:`sm`,disabled:N,onClick:()=>void Ye(e=>C.mutateAsync({id:e.id,enabled:!1})),children:i(`providers.subscription.disable`)}),(0,$.jsx)(R,{size:`sm`,disabled:N,onClick:()=>void Ye(e=>y.mutateAsync(e.id)),children:i(`providers.subscription.quotaRefresh`)}),(0,$.jsx)(R,{size:`sm`,className:`text-[var(--danger)]`,icon:(0,$.jsx)(Z,{className:`size-3.5`}),disabled:N,onClick:()=>void Ze(),children:i(`common.delete`)}),(0,$.jsx)(R,{size:`sm`,variant:`plain`,onClick:()=>A(new Set),children:i(`providers.accounts.clearSelection`)})]}),(0,$.jsx)(`div`,{className:`mt-5`,children:(0,$.jsx)(Yt,{provider:n})}),(0,$.jsx)(Jt,{provider:n,account:tt,usage:d.data?.accounts.find(e=>e.accountId===tt?.id),usageTimeZone:d.data?.timeZone,index:tt?q.indexOf(tt):0,actions:qe,onClose:()=>me(null)}),nt&&(0,$.jsx)(Ft,{providerId:n.id,info:nt,mode:j,providerProxy:n.httpProxy,onClose:()=>ge(null)}),(0,$.jsx)(G,{open:ye,onOpenChange:be,title:i(`providers.accounts.loginProxyTitle`),description:i(`providers.accounts.loginProxyDesc`),footer:(0,$.jsx)(R,{variant:`primary`,loading:h.isPending,disabled:xe.trim().length===0,onClick:()=>Y(void 0,xe),children:i(`providers.accounts.loginProxyStart`)}),children:(0,$.jsx)(k,{mono:!0,label:i(`providers.accounts.detail.proxy`),placeholder:`socks5://127.0.0.1:1080`,value:xe,onChange:e=>M(e.target.value)})}),(0,$.jsxs)(G,{open:F,onOpenChange:e=>{Ee(e),e||(De(null),Ae(null))},title:i(`providers.subscription.login`),description:i(`providers.subscription.loginDesc`),children:[Oe&&(0,$.jsx)(z,{tone:`danger`,title:i(`providers.subscription.loginFailed`),children:Oe}),L?.mode===`paste`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(z,{tone:`info`,title:i(`providers.subscription.pasteTitle`),children:i(`providers.subscription.pasteDetail`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsx)(R,{onClick:()=>window.open(L.authorizeUrl,`_blank`,`noopener`),children:i(`providers.subscription.openAuthorize`)})}),(0,$.jsx)(k,{mono:!0,value:B,onChange:e=>H(e.target.value),placeholder:i(`providers.subscription.pastePlaceholder`),"aria-label":i(`providers.subscription.pasteCode`)}),(0,$.jsx)(R,{variant:`primary`,loading:je,onClick:()=>void Ve(),children:i(`providers.subscription.pasteSubmit`)})]}),L?.mode===`pkce`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(z,{tone:`info`,title:i(`providers.subscription.waiting`),children:i(`providers.subscription.waitingDetail`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(R,{onClick:()=>window.open(L.authorizeUrl,`_blank`,`noopener`),children:i(`providers.subscription.openAuthorize`)}),(0,$.jsx)(R,{variant:`primary`,onClick:()=>{s.invalidateQueries({queryKey:r.providerAccounts(n.id)}),u.refetch()},children:i(`providers.subscription.doneAuthorize`)})]})]}),L?.mode===`cli`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(z,{tone:`info`,title:i(`providers.subscription.waiting`),children:i(`providers.subscription.cliDetail`)}),(0,$.jsx)(R,{onClick:()=>window.open(L.authorizeUrl,`_blank`,`noopener`),children:i(`providers.subscription.openAuthorize`)})]}),L?.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:i(`providers.subscription.deviceCode`)}),(0,$.jsx)(`div`,{className:`selectable font-mono text-[18px] font-medium tracking-wide`,children:L.userCode})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[L.verificationUrl&&(0,$.jsx)(R,{onClick:()=>window.open(L.verificationUrl??void 0,`_blank`,`noopener`),children:i(`providers.subscription.visitPage`)}),(0,$.jsx)(R,{variant:`primary`,loading:je,onClick:()=>void Be(),children:i(`providers.subscription.checkNow`)})]}),(0,$.jsx)(z,{tone:`info`,title:i(`providers.subscription.waiting`),children:i(`providers.subscription.checkNowHint`)})]})]})]})}function $t({policy:e,onChange:t}){let{t:n}=O();return(0,$.jsx)(oe,{ariaLabel:n(`providers.subscription.policy.switchMode`),value:e.switchMode,onChange:t,items:[{value:`manual`,label:n(`providers.subscription.policy.manual`)},{value:`failover`,label:n(`providers.subscription.policy.failover`)},{value:`balanced`,label:n(`providers.subscription.policy.balanced`)}]})}function en({provider:e}){let{t}=O(),n=Te(e.id),r=ce(e.id),i=te(e.id),a=c(e.id,!0),o=se(e.id),{toast:s}=K(),[l,u]=(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:[i.isLoading&&(0,$.jsx)(V,{lines:1}),i.isError&&(0,$.jsx)(z,{tone:`danger`,title:t(`pluginAccounts.noPlugin`),children:W(i.error)}),i.data?.map(e=>(0,$.jsx)(R,{variant:e.index===0?`primary`:void 0,icon:e.type===`api`?(0,$.jsx)(rt,{className:`size-3.5`}):(0,$.jsx)(xt,{className:`size-3.5`}),onClick:()=>u(e),children:e.label||t(e.type===`api`?`pluginAccounts.apiKey`:`pluginAccounts.browser`)},e.index))]}),n.isLoading&&(0,$.jsx)(V,{lines:3}),n.data?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(fe,{icon:(0,$.jsx)(Ct,{className:`size-6`}),title:t(`pluginAccounts.empty`),detail:t(`pluginAccounts.emptyDetail`)})}),n.data&&n.data.length>1&&a.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(a.data.switchMode===`balanced`?`providers.subscription.policy.balancedDetail`:a.data.switchMode===`failover`?`providers.subscription.policy.failoverDetail`:`providers.subscription.policy.manualDetail`)}),(0,$.jsx)($t,{policy:a.data,onChange:e=>o.mutate({switchMode:e},{onError:e=>s(W(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)(nn,{provider:e,account:t,gatewayUsage:r.data?.accounts.find(e=>e.accountId===t.id)},t.id))}),r.isError&&(0,$.jsx)(z,{tone:`danger`,title:t(`providers.usage.error`),children:W(r.error)}),n.data&&n.data.length>0&&(0,$.jsx)(kt,{timeZone:r.data?.timeZone}),(0,$.jsx)(tn,{provider:e}),l&&(0,$.jsx)(rn,{provider:e,method:l,onClose:()=>u(null)})]})}function tn({provider:e}){let{t,locale:n}=O(),{toast:r}=K(),i=u(e.id),a=d(e.id);if(!i.data?.supported)return null;let o=e=>a.mutate(e,{onError:e=>r(W(e),`error`)}),c={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)(U,{checked:i.data.on,label:t(`pluginAccounts.checkinOn`),onChange:e=>o(e)}),(0,$.jsx)(R,{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?s(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)(P,{tone:c[e.outcome]??`neutral`,children:t(`pluginAccounts.outcome.${e.outcome}`)}):(0,$.jsx)(P,{children:t(`pluginAccounts.checkinNever`)})]},e.accountId)})]})}function nn({provider:e,account:t,gatewayUsage:n}){let{t:r,locale:i}=O(),{toast:o,confirm:c}=K(),l=w(e.id),[u,d]=(0,Q.useState)(!1),f=e.settings?.plugin?.usage===!0,p=a(e.id,t.id,u),m=async()=>{await c({title:r(`pluginAccounts.signOutConfirm`,{name:t.displayName}),confirmLabel:r(`pluginAccounts.signOut`),destructive:!0})&&l.mutate(t.id,{onError:e=>o(W(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)(P,{tone:`accent`,children:r(`pluginAccounts.current`)}),(0,$.jsx)(P,{tone:t.status===`active`?`green`:`red`,children:r(t.status===`active`?`pluginAccounts.active`:`pluginAccounts.lapsed`)}),f&&(0,$.jsx)(R,{size:`sm`,onClick:()=>d(e=>!e),children:r(`pluginAccounts.usage`)}),(0,$.jsx)(R,{size:`sm`,variant:`destructive`,icon:(0,$.jsx)(Ye,{className:`size-3.5`}),onClick:()=>void m(),children:r(`pluginAccounts.signOut`)})]}),t.status!==`active`&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--danger)]`,children:r(`pluginAccounts.lapsedDetail`)}),(0,$.jsx)(Ot,{usage:n}),u&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md bg-[var(--surface-muted)] px-3 py-2`,children:[p.isLoading&&(0,$.jsx)(V,{lines:2}),p.isError&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:W(p.error)}),p.data?.error&&(0,$.jsx)(`span`,{className:`text-[12px] text-[var(--danger)]`,children:p.data.error}),p.data?.plan&&(0,$.jsx)(j,{label:r(`pluginAccounts.plan`),children:p.data.plan}),p.data?.until&&(0,$.jsx)(j,{label:r(`pluginAccounts.until`),children:s(p.data.until,i)}),p.data?.windows?.map(e=>(0,$.jsxs)(j,{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:s(new Date(e.resetsAt>0xe8d4a51000?e.resetsAt:e.resetsAt*1e3).toISOString(),i)})}`:``]},e.name))]})]})}function rn({provider:e,method:t,onClose:r}){let{t:a}=O(),{toast:o}=K(),[s,c]=(0,Q.useState)({}),[l,u]=(0,Q.useState)(void 0),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(``),[x,S]=(0,Q.useState)(null),C=b(e.id),te=i(e.id),w=ne(e.id),T=ee(e.id,x).data;(0,Q.useEffect)(()=>{let r=!0;return n(e.id,t.index,s).then(e=>{r&&(u(e.prompt),f(e.prompt?.type===`select`?e.prompt.options?.[0]?.value??``:``))}).catch(e=>r&&o(W(e),`error`)),()=>{r=!1}},[e.id,t.index,s,o]),(0,Q.useEffect)(()=>{T?.state===`done`&&(o(a(`pluginAccounts.signedIn`),`success`),r())},[T?.state,r,a,o]);let re=async()=>{if(!l)return;let n=await _(e.id,t.index,l.key,d).catch(()=>({error:null}));if(n.error)return m(n.error);m(null),c(e=>({...e,[l.key]:d}))};return(0,$.jsxs)(G,{open:!0,onOpenChange:e=>!e&&r(),title:a(`pluginAccounts.signInTitle`,{name:e.name}),description:t.label,width:520,children:[l===void 0&&(0,$.jsx)(V,{lines:2}),l&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(M,{label:l.message,error:p??void 0,children:l.type===`select`?(0,$.jsx)(q,{value:d,onChange:f,options:(l.options??[]).map(e=>({value:e.value,label:e.label,description:e.hint??void 0}))}):(0,$.jsx)(k,{value:d,placeholder:l.placeholder??void 0,onChange:e=>f(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(R,{variant:`primary`,onClick:()=>void re(),children:a(`pluginAccounts.continue`)})})]}),l===null&&t.type===`api`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(M,{label:a(`pluginAccounts.key`),children:(0,$.jsx)(k,{mono:!0,type:`password`,value:h,placeholder:t.placeholder??void 0,onChange:e=>g(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(R,{variant:`primary`,disabled:!h.trim()||te.isPending,onClick:()=>te.mutate({method:t.index,inputs:s,key:h},{onSuccess:()=>(o(a(`pluginAccounts.signedIn`),`success`),r()),onError:e=>o(W(e),`error`)}),children:a(`pluginAccounts.signIn`)})})]}),l===null&&t.type!==`api`&&!T&&(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(R,{variant:`primary`,icon:(0,$.jsx)(qe,{className:`size-3.5`}),disabled:C.isPending,onClick:()=>C.mutate({method:t.index,inputs:s},{onSuccess:e=>{S(e.id),e.url&&window.open(e.url,`_blank`,`noopener`)},onError:e=>o(W(e),`error`)}),children:a(`pluginAccounts.openPage`)})}),T&&T.state!==`done`&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[T.instructions&&(0,$.jsx)(`p`,{className:`whitespace-pre-wrap text-[12px] text-[var(--text-secondary)]`,children:T.instructions}),T.deviceCode&&(0,$.jsx)(j,{label:a(`pluginAccounts.deviceCode`),mono:!0,children:T.deviceCode}),T.url&&(0,$.jsx)(R,{icon:(0,$.jsx)(qe,{className:`size-3.5`}),onClick:()=>window.open(T.url,`_blank`,`noopener`),children:a(`pluginAccounts.openAgain`)}),T.state===`waiting`&&T.pasteCode&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{label:a(`pluginAccounts.code`),children:(0,$.jsx)(k,{mono:!0,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(R,{variant:`primary`,disabled:!v.trim()||w.isPending,onClick:()=>w.mutate({flow:T.id,code:v.trim()},{onError:e=>o(W(e),`error`)}),children:a(`pluginAccounts.signIn`)})})]}),T.state===`waiting`&&!T.pasteCode&&(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:a(`pluginAccounts.waiting`)}),T.state===`failed`&&(0,$.jsx)(z,{tone:`danger`,title:a(`pluginAccounts.failed`),children:T.error})]})]})}function an(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 on(){let{t:e}=O(),{id:t=``}=Qe(),n=tt(),r=Ne(t),[i,a]=(0,Q.useState)(`models`),[o,s]=(0,Q.useState)(null),c=Ae(t),l=c.data?.find(e=>e.id===o)??null;if(r.isError)return(0,$.jsx)(ot,{title:e(`nav.providers`),leading:(0,$.jsx)(sn,{onClick:()=>n(`/providers`)}),children:(0,$.jsx)(z,{tone:`danger`,title:e(`common.error`),children:W(r.error)})});let u=r.data;return(0,$.jsx)(ot,{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)(sn,{onClick:()=>n(`/providers`)}),actions:u&&(0,$.jsx)(cn,{p:u}),children:u?(0,$.jsxs)(X,{className:`mx-auto max-w-[860px]`,value:i,onValueChange:e=>a(e),children:[(0,$.jsxs)(nt,{"aria-label":u.name,children:[(0,$.jsx)($e,{value:`models`,children:e(`providers.tab.models`)}),(0,$.jsx)($e,{value:`accounts`,children:e(u.authScheme===`oauth-subscription`||u.authScheme===`plugin`?`providers.tab.accounts`:`providers.tab.apiKey`)}),(0,$.jsx)($e,{value:`settings`,children:e(`providers.tab.settings`)})]}),(0,$.jsx)(ut,{value:`models`,className:`pt-4`,children:(0,$.jsx)(un,{provider:u,models:c.data,loading:c.isLoading,selected:o,onSelect:s})}),(0,$.jsx)(ut,{value:`accounts`,className:`pt-4`,children:u.authScheme===`plugin`?(0,$.jsx)(en,{provider:u}):u.authScheme===`oauth-subscription`?(0,$.jsx)(Qt,{provider:u}):(0,$.jsx)(_n,{provider:u})}),(0,$.jsx)(ut,{value:`settings`,className:`pt-4`,children:(0,$.jsx)(yn,{provider:u})}),(0,$.jsx)(gn,{provider:u,pm:i===`models`?l:null,onClose:()=>s(null)})]}):(0,$.jsx)(V,{lines:4,className:`mx-auto mt-6 max-w-[860px]`})})}function sn({onClick:e}){let{t}=O();return(0,$.jsx)(R,{variant:`glass`,icon:(0,$.jsx)(Ue,{className:`size-4`}),"aria-label":t(`common.back`),onClick:e})}function cn({p:e}){let{t}=O(),n=tt(),{toast:r,confirm:i}=K(),a=Oe(),o=Ee(),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=async()=>{await i({title:t(`providers.deleteConfirm`,{name:e.name}),detail:t(`providers.deleteDetail`),destructive:!0,confirmLabel:t(`common.delete`)})&&o.mutate(e.id,{onSuccess:()=>{r(t(`providers.deleted`)),n(`/providers`)},onError:e=>{let n=e instanceof S&&e.status===409?e.details?.boundClients??[]:[];r(n.length?t(`providers.deleteBound`,{clients:n.map(e=>it[e]?.name??e).join(`, `)}):W(e),`error`)}})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{icon:(0,$.jsx)(Je,{className:`size-3.5`}),onClick:()=>u(!0),children:t(`providers.test`)}),(0,$.jsx)(Re,{label:t(`common.more`),icon:(0,$.jsx)(Ke,{className:`size-4`}),items:[{id:`dup`,label:t(`providers.duplicate`),icon:(0,$.jsx)(ge,{className:`size-3.5`}),onSelect:()=>a.mutate(e.id,{onSuccess:e=>n(`/providers/${e.id}`),onError:e=>r(W(e),`error`)})},{id:`tpl`,label:t(`providers.templateUpdate`),icon:(0,$.jsx)(Tt,{className:`size-3.5`}),disabled:!e.templateId,onSelect:()=>c(!0)},{id:`del`,label:t(`common.delete`),icon:(0,$.jsx)(Z,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void d()}]}),(0,$.jsx)(ln,{open:s,onOpenChange:c,provider:e}),(0,$.jsx)(J,{provider:e,open:l,onOpenChange:u})]})}function ln({open:e,onOpenChange:t,provider:n}){let{t:r}=O(),{toast:i}=K(),a=o(n.id,e),s=x(n.id),c=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)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(R,{variant:`primary`,disabled:!a.data||c,loading:s.isPending,onClick:()=>s.mutate(void 0,{onSuccess:()=>{t(!1),i(r(`providers.templateApplied`),`success`)},onError:e=>i(W(e),`error`)}),children:r(`common.apply`)})]}),children:[a.isLoading&&(0,$.jsx)(V,{}),a.isError&&(0,$.jsx)(z,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),c&&(0,$.jsx)(z,{tone:`success`,title:r(`providers.templateUpToDate`)}),a.data&&!c&&(0,$.jsx)(`ul`,{className:`list-disc pl-5 text-[12px]`,children:a.data.changes.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}function un({provider:e,models:t,loading:n,selected:r,onSelect:i}){let{t:a}=O(),{toast:o}=K(),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=De(e.id),m=(t??[]).filter(e=>!s||e.modelId.toLowerCase().includes(s.toLowerCase())||e.effective.displayName.toLowerCase().includes(s.toLowerCase()));return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(_e,{className:`w-56`,value:s,onChange:c,placeholder:a(`providers.searchModels`)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,$.jsx)(R,{icon:(0,$.jsx)(dt,{className:`size-3.5`}),onClick:()=>f(!0),children:a(`providers.addModels`)}),(0,$.jsx)(R,{variant:`primary`,icon:(0,$.jsx)(We,{className:`size-3.5`}),onClick:()=>u(!0),children:a(`providers.fetchRemote`)})]})]}),n&&(0,$.jsx)(V,{lines:4}),t?.length===0&&(0,$.jsx)(`div`,{className:`card`,children:(0,$.jsx)(fe,{title:a(`providers.noModels`),detail:a(`providers.noModelsDetail`)})}),m.length>0&&(0,$.jsx)(B,{footer:a(`providers.modelsFooter`),children:m.map(e=>(0,$.jsxs)(N,{selected:e.id===r,onClick:()=>i(e.id),label:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:I(`font-mono text-[12.5px]`,!e.enabled&&`text-[var(--text-muted)]`),children:e.modelId}),!e.systemModelId&&(0,$.jsx)(P,{tone:`orange`,children:a(`providers.unlinked`)})]}),detail:[e.effective.displayName===e.modelId?null:e.effective.displayName,e.effective.contextWindow?C(e.effective.contextWindow):null,je(e.effectivePricing)].filter(Boolean).join(` · `),children:[(0,$.jsx)(at,{source:e.pricingSource,priceKey:e.priceKey}),(0,$.jsx)(U,{checked:e.enabled,label:a(`common.enabled`),onChange:t=>p.mutate({pmId:e.id,enabled:t},{onError:e=>o(W(e),`error`)})})]},e.id))}),t&&(0,$.jsx)(dn,{provider:e,models:t}),(0,$.jsx)(pn,{open:d,onOpenChange:f,provider:e}),(0,$.jsx)(mn,{open:l,onOpenChange:u,provider:e})]})}function dn({provider:e,models:t}){let{t:n}=O(),{toast:r}=K(),i=h(e.id),[a,o]=(0,Q.useState)(!1),s=an(e.settings),c=Object.entries(s),l=new Set(t.map(e=>e.modelId)),u=(e,t)=>i.mutate(e,{onSuccess:()=>{t?.(),r(n(`providers.modelMap.saved`),`success`)},onError:e=>r(W(e),`error`)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(B,{title:n(`providers.modelMap.title`),footer:n(`providers.modelMap.footer`),children:[c.map(([e,t])=>(0,$.jsx)(N,{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)(ct,{className:`size-3.5 shrink-0 text-[var(--text-muted)]`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:I(`truncate`,!l.has(t)&&`text-[var(--text-muted)]`),children:t}),!l.has(t)&&(0,$.jsx)(P,{tone:`orange`,children:n(`providers.modelMap.missingTarget`)})]}),children:(0,$.jsx)(R,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(me,{className:`size-3.5`}),"aria-label":n(`providers.modelMap.remove`,{from:e}),title:n(`providers.modelMap.remove`,{from:e}),disabled:i.isPending,onClick:()=>u(Object.fromEntries(c.filter(([t])=>t!==e)))})},e)),(0,$.jsx)(N,{icon:(0,$.jsx)(dt,{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)(fn,{open:a,onOpenChange:o,models:t,saving:i.isPending,onSave:(e,t)=>u({...s,[e]:t},()=>o(!1))})]})}function fn({open:e,onOpenChange:t,models:n,saving:r,onSave:i}){let{t:a}=O(),[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)(R,{onClick:()=>t(!1),children:a(`common.cancel`)}),(0,$.jsx)(R,{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)(k,{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 pn({open:e,onOpenChange:t,provider:n}){let{t:r}=O(),{toast:i}=K(),a=v(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)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(R,{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(W(e),`error`)}),children:r(`providers.addSelected`,{count:c.length})})]}),children:(0,$.jsx)(le,{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 mn({open:e,onOpenChange:t,provider:n}){let{t:r}=O(),{toast:i}=K(),a=pe(n.id,e),o=v(n.id),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&c(new Set)},[e]);let d=(a.data??[]).filter(e=>!l||e.id.toLowerCase().includes(l.toLowerCase())),f=e=>c(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)(R,{variant:`plain`,className:`mr-auto`,onClick:()=>c(new Set(d.filter(e=>!e.alreadyAdded).map(e=>e.id))),disabled:d.length===0,children:r(`common.selectAll`)}),(0,$.jsx)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(R,{variant:`primary`,disabled:s.size===0,loading:o.isPending,onClick:()=>o.mutate([...s],{onSuccess:e=>{t(!1),i(r(`providers.modelsAdded`,{count:e.length}),`success`)},onError:e=>i(W(e),`error`)}),children:r(`providers.addSelected`,{count:s.size})})]}),children:[(0,$.jsx)(_e,{className:`mb-3`,value:l,onChange:u,placeholder:r(`providers.searchModels`)}),a.isLoading&&(0,$.jsx)(V,{lines:4}),a.isError&&(0,$.jsx)(z,{tone:`danger`,title:r(`common.error`),children:W(a.error)}),(0,$.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:d.map(e=>(0,$.jsx)(N,{onClick:e.alreadyAdded?void 0:()=>f(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)(P,{children:r(`providers.added`)}):(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ft,{"aria-label":e.id,checked:s.has(e.id),onCheckedChange:()=>f(e.id)})})},e.id))})]})}function hn({origin:e}){let{t}=O();return e===`overridden`?(0,$.jsx)(P,{tone:`orange`,children:t(`origin.overridden`)}):e===`inherited`?(0,$.jsx)(P,{children:t(`origin.inherited`)}):(0,$.jsx)(P,{tone:`red`,children:t(`origin.unset`)})}function gn({provider:e,pm:t,onClose:n}){let{t:r}=O(),{toast:i}=K(),a=De(e.id),o=D(e.id),s=m(),[c,l]=(0,Q.useState)({}),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{t&&(l(t.overrides),d(t.systemModelId??``),p(t.overrides.pricing!=null))},[t]),!t)return(0,$.jsx)(G,{open:!1,onOpenChange:()=>n(),title:r(`providers.tab.models`)});let h={...c,pricing:f?c.pricing??null:null},g=JSON.stringify(h)!==JSON.stringify({...t.overrides,pricing:t.overrides.pricing??null})||u!==(t.systemModelId??``),_=()=>a.mutate({pmId:t.id,overrides:h,systemModelId:u||null},{onSuccess:()=>{i(r(`common.saved`),`success`),n()},onError:e=>i(W(e),`error`)}),v=(e,n,i)=>(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)(hn,{origin:c[e]==null?t.origins[e]===`overridden`?`inherited`:t.origins[e]:`overridden`}),c[e]!=null&&(0,$.jsx)(R,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(Ze,{className:`size-3`}),title:r(`origin.reset`),"aria-label":r(`origin.reset`),onClick:()=>l({...c,[e]:null})})]})]}),i]});return(0,$.jsx)(G,{open:!0,onOpenChange:e=>!e&&n(),width:720,title:t.modelId,description:e.name,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mr-auto`,children:(0,$.jsx)(pt,{label:r(`providers.removeModelShort`),icon:(0,$.jsx)(Z,{className:`size-4`}),prompt:r(`providers.removeModel`,{id:t.modelId}),confirmLabel:r(`common.delete`),cancelLabel:r(`common.cancel`),pendingLabel:r(`common.deleting`),doneLabel:r(`common.deleted`),errorLabel:r(`common.error`),retryLabel:r(`common.retry`),onConfirm:async()=>{await o.mutateAsync(t.id),n()}})}),(0,$.jsx)(R,{onClick:n,children:r(`common.cancel`)}),(0,$.jsx)(R,{variant:`primary`,disabled:!g,loading:a.isPending,onClick:_,children:r(`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)(at,{source:t.pricingSource,priceKey:t.priceKey}),t.multiplier!==1&&t.pricingSource!==`provider_override`&&(0,$.jsxs)(P,{children:[`×`,t.multiplier]})]}),(0,$.jsxs)(E,{title:r(`providers.linkedModel`),children:[(0,$.jsx)(q,{className:`w-full`,ariaLabel:r(`providers.linkedModel`),value:u,onChange:d,options:[{value:``,label:r(`providers.noLink`)},...(s.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:r(`providers.linkedModelHint`)})]}),(0,$.jsx)(E,{title:r(`providers.overrides`),children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[v(`displayName`,r(`models.field.displayName`),(0,$.jsx)(k,{className:`w-full`,"aria-label":r(`models.field.displayName`),placeholder:t.effective.displayName,value:c.displayName??``,onChange:e=>l({...c,displayName:e.target.value||null})})),v(`contextWindow`,r(`models.field.contextWindow`),(0,$.jsx)(L,{className:`w-full`,label:r(`models.field.contextWindow`),placeholder:String(t.effective.contextWindow??``),value:c.contextWindow,onChange:e=>l({...c,contextWindow:e})})),v(`maxOutputTokens`,r(`models.field.maxOutputTokens`),(0,$.jsx)(L,{className:`w-full`,label:r(`models.field.maxOutputTokens`),placeholder:String(t.effective.maxOutputTokens??``),value:c.maxOutputTokens,onChange:e=>l({...c,maxOutputTokens:e})}))]})}),(0,$.jsxs)(E,{title:r(`providers.price`),action:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[r(`providers.customPrice`),(0,$.jsx)(U,{checked:f,label:r(`providers.customPrice`),onChange:e=>{p(e),e&&c.pricing==null&&l({...c,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:r(f?`providers.customPriceHint`:`providers.inheritedPriceHint`)}),f?(0,$.jsx)(`div`,{className:`card p-4`,children:(0,$.jsx)(st,{value:c.pricing??null,onChange:e=>l({...c,pricing:e})})}):t.effectivePricing?(0,$.jsx)(be,{maxHeight:220,children:F(t.effectivePricing)}):(0,$.jsx)(z,{tone:`warning`,title:r(`pricingSource.none`)})]})]})})}function _n({provider:e}){let{t}=O(),{toast:n}=K(),r=A(e.id),i=ce(e.id),[a,o]=(0,Q.useState)(``);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(B,{title:t(`providers.section.auth`),footer:t(`providers.apiKeyStored`),children:(0,$.jsx)(N,{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)(k,{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)(R,{variant:`primary`,disabled:a.trim().length===0,loading:r.isPending,onClick:()=>r.mutate({apiKey:a},{onSuccess:()=>{o(``),n(t(`common.saved`),`success`)},onError:e=>n(W(e),`error`)}),children:t(`common.save`)})]})})}),(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)(z,{tone:`danger`,title:t(`providers.usage.error`),children:W(i.error)}),(0,$.jsx)(Ot,{usage:i.data?.accounts.find(e=>!e.accountId)}),(0,$.jsx)(kt,{timeZone:i.data?.timeZone})]}),(0,$.jsx)(ze,{provider:e})]})}function vn(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 yn({provider:e}){let{t}=O(),{toast:n}=K(),r=A(e.id),i=T(),a=(0,Q.useMemo)(()=>vn(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),_=()=>{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(W(e),`error`)})},v=(e,t)=>m({endpoints:o.endpoints.map((n,r)=>r===e?{...n,...t}:n)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(B,{title:t(`providers.section.basic`),children:[(0,$.jsx)(N,{label:t(`providers.name`),children:(0,$.jsx)(k,{className:`w-64`,"aria-label":t(`providers.name`),value:o.name,onChange:e=>m({name:e.target.value})})}),(0,$.jsx)(N,{label:t(`common.enabled`),children:(0,$.jsx)(U,{checked:o.enabled,label:t(`common.enabled`),onChange:e=>m({enabled:e})})}),(0,$.jsx)(N,{label:t(`providers.notes`),children:(0,$.jsx)(k,{className:`w-64`,"aria-label":t(`providers.notes`),value:o.notes??``,onChange:e=>m({notes:e.target.value||null})})})]}),(0,$.jsx)(B,{title:t(`providers.section.auth`),children:(0,$.jsx)(N,{label:t(`providers.authScheme`),children:(0,$.jsx)(q,{className:`w-48`,value:o.authScheme,onChange:e=>m({authScheme:e}),options:Ve})})}),(0,$.jsxs)(B,{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=>v(n,{protocol:e}),options:Y}),(0,$.jsx)(k,{className:`min-w-60 flex-1 font-mono`,"aria-label":t(`providers.baseUrl`),value:e.baseUrl,onChange:e=>v(n,{baseUrl:e.target.value})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-[var(--text-secondary)]`,children:[(0,$.jsx)(U,{checked:!!e.fullUrl,label:t(`providers.fullUrl`),onChange:e=>v(n,{fullUrl:e})}),t(`providers.fullUrl`)]}),(0,$.jsx)(R,{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)(R,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(dt,{className:`size-3.5`}),onClick:()=>d(!0),children:t(`providers.addEndpoint`)})}),(0,$.jsx)(N,{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:Y.find(t=>t.value===e)?.label??e})},e))]}),children:(0,$.jsx)(lt,{label:t(`providers.preferred`),options:Y.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)(B,{title:t(`providers.section.billing`),footer:t(`providers.billingFooter`),children:[(0,$.jsx)(N,{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)(N,{label:t(`providers.multiplier`),detail:t(`providers.multiplierHint`),children:(0,$.jsx)(L,{className:`w-28`,label:t(`providers.multiplier`),step:.01,min:0,value:o.priceMultiplier,onChange:e=>m({priceMultiplier:e??1})})})]}),(0,$.jsxs)(B,{title:t(`providers.section.advanced`),children:[(0,$.jsx)(N,{label:t(`providers.proxy`),detail:t(`providers.proxyHint`),children:(0,$.jsx)(k,{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)(k,{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)(k,{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)(R,{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)(R,{size:`sm`,variant:`plain`,icon:(0,$.jsx)(dt,{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)(le,{label:t(`providers.adapterSettings`),rows:4,className:`w-full font-mono`,defaultValue:F(o.settings),onBlur:e=>{try{m({settings:JSON.parse(e.target.value)})}catch{n(t(`common.invalidJson`),`error`)}}})})]}),(0,$.jsx)(B,{title:t(`providers.section.info`),children:(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(j,{label:`ID`,children:e.id}),e.adapterId&&(0,$.jsx)(j,{label:t(`providers.adapter`),children:e.adapterId}),(0,$.jsx)(j,{label:t(`providers.boundClients`),children:e.boundClients.map(e=>it[e]?.name??e).join(`, `)||`—`})]})}),(0,$.jsx)(bn,{open:u,onOpenChange:d,onAdd:e=>m({endpoints:[...o.endpoints,e]})}),(0,$.jsx)(xn,{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)(R,{size:`sm`,onClick:()=>{s(a),l(Object.entries(a.extraHeaders))},children:t(`common.revert`)}),(0,$.jsx)(R,{size:`sm`,variant:`primary`,loading:r.isPending,onClick:_,children:t(`common.save`)})]})})]})}function bn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=O(),[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)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(R,{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)(M,{label:r(`providers.protocol`),children:(0,$.jsx)(q,{value:i,onChange:a,options:Y})}),(0,$.jsx)(M,{label:r(`providers.baseUrl`),hint:r(c?`providers.fullUrlHint`:`providers.baseUrlHint`),children:(0,$.jsx)(k,{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)(U,{checked:c,onChange:l,label:r(`providers.fullUrl`)}),r(`providers.fullUrl`)]})]})})}function xn({open:e,onOpenChange:t,onAdd:n}){let{t:r}=O(),[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)(R,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,$.jsx)(R,{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)(M,{label:r(`providers.headerName`),children:(0,$.jsx)(k,{autoFocus:!0,className:`font-mono`,placeholder:`X-Custom-Header`,value:i,invalid:i!==``&&!c,onChange:e=>a(e.target.value)})}),(0,$.jsx)(M,{label:r(`providers.headerValue`),children:(0,$.jsx)(k,{className:`font-mono`,value:o,onChange:e=>s(e.target.value)})})]})})}export{on as ProviderDetailPage};